added queuing push and pop logic and having fun with c# integration

This commit is contained in:
Erris
2026-01-22 09:33:35 +01:00
parent 14134c7d2f
commit 58ea4554c7
34 changed files with 338 additions and 126 deletions

View File

@@ -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";

View File

@@ -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;