diff --git a/Editor/Coral.Managed.runtimeconfig.json b/Editor/Coral.Managed.runtimeconfig.json new file mode 100644 index 00000000..a6633daf --- /dev/null +++ b/Editor/Coral.Managed.runtimeconfig.json @@ -0,0 +1,10 @@ +{ + "runtimeOptions": { + "tfm": "net7.0", + "rollForward": "LatestMinor", + "framework": { + "name": "Microsoft.NETCore.App", + "version": "7.0.0" + } + } + } \ No newline at end of file diff --git a/Nuake/dependencies/Coral b/Nuake/dependencies/Coral index 62ab7c64..96c08dde 160000 --- a/Nuake/dependencies/Coral +++ b/Nuake/dependencies/Coral @@ -1 +1 @@ -Subproject commit 62ab7c6498dc234892f73e63636cf7836d302768 +Subproject commit 96c08dde2258ba5938a96fe78f169f1938b97f83 diff --git a/Nuake/src/Scripting/ScriptingEngineNet.cpp b/Nuake/src/Scripting/ScriptingEngineNet.cpp index fbbffd41..67d098a2 100644 --- a/Nuake/src/Scripting/ScriptingEngineNet.cpp +++ b/Nuake/src/Scripting/ScriptingEngineNet.cpp @@ -3,7 +3,6 @@ #include "src/Core/Logger.h" #include "src/Core/FileSystem.h" - #include #include #include @@ -26,15 +25,14 @@ namespace Nuake .CoralDirectory = coralDir, .ExceptionCallback = ExceptionCallback }; - m_HostInstance = CreateScope(); + m_HostInstance = new Coral::HostInstance(); m_HostInstance->Initialize(settings); - m_LoadContext = CreateScope(m_HostInstance->CreateAssemblyLoadContext("NuakeEngineContext")); + } ScriptingEngineNet::~ScriptingEngineNet() { - m_HostInstance->UnloadAssemblyLoadContext(*m_LoadContext); m_HostInstance->Shutdown(); } @@ -51,9 +49,9 @@ namespace Nuake void ScriptingEngineNet::Initialize() { - - auto& assembly = m_LoadContext->LoadAssembly("NuakeNet.dll"); + auto loadContext = m_HostInstance->CreateAssemblyLoadContext("NuakeEngineContext"); + auto& assembly = loadContext.LoadAssembly("NuakeNet.dll"); assembly.AddInternalCall("Nuake.Net.Engine", "LoggerLogIcall", reinterpret_cast(&Log)); assembly.UploadInternalCalls(); @@ -61,9 +59,13 @@ namespace Nuake auto engineInstance = engineType.CreateInstance(); Coral::NativeString param1 = Coral::NativeString::FromUTF8("Hello from CPP");; - engineInstance.InvokeMethod("Log", param1); + engineInstance.InvokeMethod("Log", std::string("Hello from CPP")); engineInstance.Destroy(); + Coral::GC::Collect(); + Coral::GC::WaitForPendingFinalizers(); + + m_HostInstance->UnloadAssemblyLoadContext(loadContext); } } \ No newline at end of file diff --git a/Nuake/src/Scripting/ScriptingEngineNet.h b/Nuake/src/Scripting/ScriptingEngineNet.h index 01f854cb..f05e2e0b 100644 --- a/Nuake/src/Scripting/ScriptingEngineNet.h +++ b/Nuake/src/Scripting/ScriptingEngineNet.h @@ -1,6 +1,9 @@ #pragma once #include "src/Core/Core.h" + + + namespace Coral { class HostInstance; @@ -12,8 +15,8 @@ namespace Nuake class ScriptingEngineNet { private: - Scope m_HostInstance; - Scope m_LoadContext; + Coral::HostInstance* m_HostInstance; + Coral::AssemblyLoadContext* m_LoadContext; ScriptingEngineNet(); ~ScriptingEngineNet(); diff --git a/NuakeNet/src/main.cs b/NuakeNet/src/main.cs index 62363051..9affc8f4 100644 --- a/NuakeNet/src/main.cs +++ b/NuakeNet/src/main.cs @@ -1,6 +1,7 @@ using Coral.Managed.Interop; using System; +using System.Collections.Generic; namespace Nuake.Net { @@ -12,6 +13,7 @@ namespace Nuake.Net public class Engine { internal static unsafe delegate* LoggerLogIcall; + public Engine() { } @@ -24,4 +26,86 @@ namespace Nuake.Net unsafe { LoggerLogIcall(input + " - hello from c# man"); } } } + + public class IComponent + { + public UInt32 EntityID { get; protected set; } + } + + public class LightComponent : IComponent + { + public LightComponent(UInt32 entityId) + { + EntityID = entityId; + } + + public float Intensity { get; set; } + } + + public class TransformComponent : IComponent + { + public TransformComponent(UInt32 entityId) + { + EntityID = entityId; + } + + public int LocalPosition { get; set; } + public int GlobalPosition { get; set; } + + + public void SetGlobalPosition() { } + public void GetGlobalPosition() { } + } + + + public class Entity + { + internal static unsafe delegate* EntityHasComponentIcall; + + public UInt32 ID { get; private set; } + + Entity(UInt32 id) + { + ID = id; + } + + public virtual void OnInit() { } + public virtual void OnUpdate(float dt) { } + public virtual void OnFixedUpdate(float dt) { } + public virtual void OnDestroy() { } + + bool HasComponent() + { + if (typeof(T) == typeof(TransformComponent)) + { + unsafe { return EntityHasComponentIcall(ID, typeof(TransformComponent).GetType().Name); }; + } + else if (typeof(T) == typeof(LightComponent)) + { + return true; + } + + return false; + } + + T GetComponent() + { + if (typeof(T) == typeof(TransformComponent)) + { + return (T)(object)new TransformComponent(ID); + } + else + { + throw new InvalidOperationException("Component not found"); + } + } + } + + public class Scene + { + public UInt32 GetEntityIDByName(string name) + { + return 0; + } + } } \ No newline at end of file