added queuing push and pop logic and having fun with c# integration
This commit is contained in:
@@ -24,8 +24,11 @@ target_link_libraries(${PROJECT_EXECUTABLE_NAME} PRIVATE
|
||||
spdlog::spdlog
|
||||
imgui::imgui
|
||||
open_engine
|
||||
dl
|
||||
nethost
|
||||
)
|
||||
|
||||
target_link_directories(${PROJECT_EXECUTABLE_NAME} PRIVATE
|
||||
${PROJECT_SOURCE_DIR}/lib
|
||||
/usr/share/dotnet/packs/Microsoft.NETCore.App.Host.arch-x64/10.0.0/runtimes/arch-x64/native
|
||||
)
|
||||
|
||||
@@ -3,10 +3,13 @@
|
||||
|
||||
#include <dlfcn.h>
|
||||
#include <open_engine.hpp>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "/usr/share/dotnet/packs/Microsoft.NETCore.App.Host.arch-x64/10.0.0/runtimes/arch-x64/native/nethost.h"
|
||||
#include "/usr/share/dotnet/packs/Microsoft.NETCore.App.Host.arch-x64/10.0.0/runtimes/arch-x64/native/hostfxr.h"
|
||||
#include "/usr/share/dotnet/packs/Microsoft.NETCore.App.Host.arch-x64/10.0.0/runtimes/arch-x64/native/coreclr_delegates.h"
|
||||
#include "open_engine/core/time.hpp"
|
||||
#include "open_engine/logging.hpp"
|
||||
|
||||
class Modding : public OpenEngine::Layer
|
||||
{
|
||||
@@ -74,6 +77,7 @@ class Modding : public OpenEngine::Layer
|
||||
void OnAttach() override
|
||||
{
|
||||
load_hostfxr();
|
||||
|
||||
auto load_assembly_and_get_function_pointer = get_dotnet_load_assembly("assets/scripts/mod_loader.runtimeconfig.json");
|
||||
component_entry_point_fn init = nullptr;
|
||||
int rc = load_assembly_and_get_function_pointer(
|
||||
@@ -85,6 +89,14 @@ class Modding : public OpenEngine::Layer
|
||||
(void**)&init);
|
||||
|
||||
init(nullptr, 1);
|
||||
|
||||
rc = load_assembly_and_get_function_pointer(
|
||||
dotnet_lib_path,
|
||||
dotnet_type,
|
||||
"Hello",
|
||||
UNMANAGEDCALLERSONLY_METHOD /*delegate_type_name*/,
|
||||
nullptr,
|
||||
(void**)&hello);
|
||||
}
|
||||
|
||||
void OnDetach() override
|
||||
@@ -93,6 +105,14 @@ class Modding : public OpenEngine::Layer
|
||||
|
||||
void OnUpdate() override
|
||||
{
|
||||
static float time = 0;
|
||||
|
||||
time += OpenEngine::Time::Get().DeltaTime();
|
||||
|
||||
if (time >= 1) {
|
||||
hello(nullptr, 1);
|
||||
time = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void OnEvent(OpenEngine::Event& event) override
|
||||
@@ -111,6 +131,8 @@ class Modding : public OpenEngine::Layer
|
||||
hostfxr_get_runtime_delegate_fn get_delegate_fptr;
|
||||
hostfxr_close_fn close_fptr;
|
||||
|
||||
component_entry_point_fn hello = nullptr;
|
||||
|
||||
const char_t* dotnet_lib_path = "assets/scripts/mod_loader.dll";
|
||||
const char_t* dotnet_type = "OpenEngine.ModLoader, mod_loader";
|
||||
const char_t* dotnet_type_method = "Init";
|
||||
|
||||
@@ -47,8 +47,15 @@ class SandboxLayer : public OpenEngine::Layer
|
||||
return square_vertex_array;
|
||||
}
|
||||
|
||||
void OnDetach() override
|
||||
{
|
||||
OE_DEBUG("OnDetach {}", __PRETTY_FUNCTION__);
|
||||
}
|
||||
|
||||
SandboxLayer()
|
||||
: Layer("Sandbox")
|
||||
: Layer("sandbox"),
|
||||
camera((float)OpenEngine::Application::Get().GetWindow().GetWidth() /
|
||||
OpenEngine::Application::Get().GetWindow().GetHeight(), 1.0f)
|
||||
{
|
||||
//vertex_array.reset(OpenEngine::VertexArray::Create());
|
||||
square = CreateSquare();
|
||||
@@ -82,11 +89,11 @@ class SandboxLayer : public OpenEngine::Layer
|
||||
texture = OpenEngine::Texture2D::Create("./assets/textures/container.jpg");
|
||||
face = OpenEngine::Texture2D::Create("./assets/textures/awesomeface.png");
|
||||
|
||||
std::dynamic_pointer_cast<OpenEngine::OpenGLShader>(texture_shader)->Bind();
|
||||
std::dynamic_pointer_cast<OpenEngine::OpenGLShader>(texture_shader)->SetInt("u_Texture", 0);
|
||||
texture_shader->Bind();
|
||||
texture_shader->SetInt("u_Texture", 0);
|
||||
|
||||
for (auto joystick : OpenEngine::Input::GetJoystickList())
|
||||
OE_TRACE("Joystick {}: {}", joystick.first, joystick.second);
|
||||
OE_DEBUG("Joystick {}: {}", joystick.first, joystick.second);
|
||||
|
||||
bindings = {
|
||||
{"fwd/bckwd", 1},
|
||||
@@ -155,9 +162,9 @@ class SandboxLayer : public OpenEngine::Layer
|
||||
auto texture_shader = shader_library.Get("texture");
|
||||
|
||||
texture_shader->Bind();
|
||||
texture->Bind();
|
||||
//texture->Bind();
|
||||
glm::mat4 square_transform = glm::translate(glm::mat4(1.0f), square_pos) * scale;
|
||||
OpenEngine::Renderer::Submit(texture_shader, square, square_transform);
|
||||
//OpenEngine::Renderer::Submit(texture_shader, square, square_transform);
|
||||
moveSquare(square_pos);
|
||||
moveSquareF(square_pos);
|
||||
|
||||
@@ -174,21 +181,10 @@ class SandboxLayer : public OpenEngine::Layer
|
||||
void OnEvent(OpenEngine::Event& event) override
|
||||
{
|
||||
OpenEngine::EventDispatcher dispatcher(event);
|
||||
dispatcher.Dispatch<OpenEngine::KeyPressedEvent>(BIND_EVENT_FN(SandboxLayer::QuitRunning));
|
||||
|
||||
camera.OnEvent(event);
|
||||
}
|
||||
|
||||
bool QuitRunning(OpenEngine::KeyPressedEvent& event)
|
||||
{
|
||||
if (event.GetKeyCode() == OE_KEY_ESCAPE) {
|
||||
OpenEngine::Application::Get().StopRunning();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void OnImGuiRender() override
|
||||
{
|
||||
static std::vector<std::string> axis_labels;
|
||||
|
||||
@@ -21,8 +21,8 @@ bool ControlLayer::SwitchLayer(OpenEngine::KeyPressedEvent& event)
|
||||
OE_DEBUG("Sandbox2D Layer");
|
||||
layer = OpenEngine::CreateRef<Sandbox2DLayer>();
|
||||
|
||||
app.PushLayer(layer);
|
||||
app.PopLayer(active_layer);
|
||||
app.QueueLayerPush(layer);
|
||||
app.QueueLayerPop(active_layer);
|
||||
active_layer = layer;
|
||||
|
||||
return true;
|
||||
@@ -30,8 +30,8 @@ bool ControlLayer::SwitchLayer(OpenEngine::KeyPressedEvent& event)
|
||||
OE_DEBUG("Sandbox Layer");
|
||||
layer = OpenEngine::CreateRef<SandboxLayer>();
|
||||
|
||||
app.PushLayer(layer);
|
||||
app.PopLayer(active_layer);
|
||||
app.QueueLayerPush(layer);
|
||||
app.QueueLayerPop(active_layer);
|
||||
active_layer = layer;
|
||||
|
||||
return true;
|
||||
|
||||
@@ -1,8 +1,20 @@
|
||||
#include <memory>
|
||||
#include <sandbox2d.hpp>
|
||||
#include <sandbox.hpp>
|
||||
#include <control_layer.hpp>
|
||||
#include <modding.hpp>
|
||||
|
||||
#include <open_engine/entry_point.hpp>
|
||||
|
||||
Sandbox::Sandbox()
|
||||
{
|
||||
PushLayer(new SandboxLayer());
|
||||
OpenEngine::Ref<Sandbox2DLayer> initial_layer = std::make_shared<Sandbox2DLayer>();
|
||||
OpenEngine::Ref<ControlLayer> control_layer = std::make_shared<ControlLayer>(initial_layer);
|
||||
OpenEngine::Ref<Modding> modding_layer = std::make_shared<Modding>();
|
||||
|
||||
QueueLayerPush(modding_layer);
|
||||
QueueLayerPush(control_layer);
|
||||
QueueLayerPush(initial_layer);
|
||||
}
|
||||
|
||||
Sandbox::~Sandbox()
|
||||
|
||||
Reference in New Issue
Block a user