added queuing push and pop logic and having fun with c# integration
This commit is contained in:
@@ -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";
|
||||
|
||||
Reference in New Issue
Block a user