mirror of
https://github.com/aharabada/glitchy-engine-beef.git
synced 2026-09-06 05:01:53 +00:00
Cleanup + Attach scripts
This commit is contained in:
@@ -11,19 +11,6 @@ public abstract class ScriptableEntity
|
||||
protected virtual void OnDestroy() { }
|
||||
protected virtual void OnUpdate() { }
|
||||
|
||||
[UnmanagedCallersOnly]
|
||||
public static void UpdateEntity(IntPtr entityPtr)
|
||||
{
|
||||
Console.WriteLine("Trying to do stuff!");
|
||||
|
||||
GCHandle entityHandle = GCHandle.FromIntPtr(entityPtr);
|
||||
|
||||
if (entityHandle.Target is ScriptableEntity entity)
|
||||
{
|
||||
entity.OnUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
[UnmanagedCallersOnly]
|
||||
public static IntPtr CreateInstance(IntPtr typeNamePtr, int typeNameLength, EcsEntity entity)
|
||||
{
|
||||
@@ -32,14 +19,12 @@ public abstract class ScriptableEntity
|
||||
string typeName = Marshal.PtrToStringUTF8(typeNamePtr, typeNameLength);
|
||||
|
||||
Type? type = Type.GetType(typeName, true);
|
||||
|
||||
if (type == null)
|
||||
return IntPtr.Zero;
|
||||
|
||||
object? instance = Activator.CreateInstance(type);
|
||||
|
||||
if (type == null)
|
||||
return IntPtr.Zero;
|
||||
Debug.Assert(type != null, "Type not found.");
|
||||
|
||||
object? instance = Activator.CreateInstance(type);
|
||||
|
||||
Debug.Assert(instance != null, "Instance could not be created");
|
||||
|
||||
Debug.Assert(instance is ScriptableEntity, "Activated instance doesn't inherit from ScriptableEntity");
|
||||
|
||||
@@ -58,4 +43,28 @@ public abstract class ScriptableEntity
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[UnmanagedCallersOnly]
|
||||
public static void DestroyEntity(IntPtr entityPtr)
|
||||
{
|
||||
GCHandle entityHandle = GCHandle.FromIntPtr(entityPtr);
|
||||
|
||||
if (entityHandle.Target is ScriptableEntity entity)
|
||||
{
|
||||
entity.OnDestroy();
|
||||
}
|
||||
|
||||
entityHandle.Free();
|
||||
}
|
||||
|
||||
[UnmanagedCallersOnly]
|
||||
public static void UpdateEntity(IntPtr entityPtr)
|
||||
{
|
||||
GCHandle entityHandle = GCHandle.FromIntPtr(entityPtr);
|
||||
|
||||
if (entityHandle.Target is ScriptableEntity entity)
|
||||
{
|
||||
entity.OnUpdate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,12 +2,11 @@ using System;
|
||||
using System.IO;
|
||||
using System.Interop;
|
||||
using System.Diagnostics;
|
||||
|
||||
using internal GlitchyEngineHelper.DotNet;
|
||||
using GlitchyEngineHelper.DotNet;
|
||||
|
||||
namespace GlitchyEngineHelper
|
||||
{
|
||||
class DotNet
|
||||
class DotNetContext
|
||||
{
|
||||
#if BF_PLATFORM_WINDOWS
|
||||
internal typealias char = char16;
|
||||
@@ -25,8 +24,6 @@ namespace GlitchyEngineHelper
|
||||
CoreClr.LoadAssemblyAndGetFunctionPointerFn LoadAssemblyAndGetFunctionPointerFn;
|
||||
CoreClr.GetFunctionPointerFn GetFunctionPointerFn;
|
||||
|
||||
private const char* UNMANAGEDCALLERSONLY_METHOD = (char*)(void*)-1;
|
||||
|
||||
private String _configPath ~ delete _;
|
||||
|
||||
public this(String configPath)
|
||||
@@ -108,13 +105,11 @@ namespace GlitchyEngineHelper
|
||||
return SetRuntimePropertyValueFn(cxt, RawPointer!(property), RawPointer!(value));
|
||||
}
|
||||
|
||||
public int LoadAssemblyAndGetFunctionPointer<T>(String libraryPath, String typeName, String methodName, String delegateName, out T outDelegate) where T: operator explicit void*
|
||||
public int LoadAssemblyAndGetFunctionPointer<T>(StringView libraryPath, StringView typeName, StringView methodName, StringView delegateName, out T outDelegate) where T: operator explicit void*
|
||||
{
|
||||
void* funPtr = null;
|
||||
|
||||
#if BF_PLATFORM_WINDOWS
|
||||
int rc = LoadAssemblyAndGetFunctionPointerFn(libraryPath.ToScopedNativeWChar!(), typeName.ToScopedNativeWChar!(), methodName.ToScopedNativeWChar!(), delegateName.ToScopedNativeWChar!(), null, out funPtr);
|
||||
#endif
|
||||
int rc = LoadAssemblyAndGetFunctionPointerFn(RawPointer!(libraryPath), RawPointer!(typeName), RawPointer!(methodName), RawPointer!(delegateName), null, out funPtr);
|
||||
|
||||
outDelegate = (T)funPtr;
|
||||
|
||||
@@ -125,9 +120,7 @@ namespace GlitchyEngineHelper
|
||||
{
|
||||
void* funPtr = null;
|
||||
|
||||
#if BF_PLATFORM_WINDOWS
|
||||
int rc = LoadAssemblyAndGetFunctionPointerFn(libraryPath.ToScopedNativeWChar!(), typeName.ToScopedNativeWChar!(), methodName.ToScopedNativeWChar!(), UNMANAGEDCALLERSONLY_METHOD, null, out funPtr);
|
||||
#endif
|
||||
int rc = LoadAssemblyAndGetFunctionPointerFn(RawPointer!(libraryPath), RawPointer!(typeName), RawPointer!(methodName), CoreClr.UNMANAGEDCALLERSONLY_METHOD, null, out funPtr);
|
||||
|
||||
outDelegate = (T)funPtr;
|
||||
|
||||
@@ -138,9 +131,7 @@ namespace GlitchyEngineHelper
|
||||
{
|
||||
void* funPtr = null;
|
||||
|
||||
#if BF_PLATFORM_WINDOWS
|
||||
int rc = GetFunctionPointerFn(typeName.ToScopedNativeWChar!(), methodName.ToScopedNativeWChar!(), delegateName.ToScopedNativeWChar!(), null, null, out funPtr);
|
||||
#endif
|
||||
int rc = GetFunctionPointerFn(RawPointer!(typeName), RawPointer!(methodName), RawPointer!(delegateName), null, null, out funPtr);
|
||||
|
||||
outDelegate = (T)funPtr;
|
||||
|
||||
@@ -151,9 +142,7 @@ namespace GlitchyEngineHelper
|
||||
{
|
||||
void* funPtr = null;
|
||||
|
||||
#if BF_PLATFORM_WINDOWS
|
||||
int rc = GetFunctionPointerFn(typeName.ToScopedNativeWChar!(), methodName.ToScopedNativeWChar!(), UNMANAGEDCALLERSONLY_METHOD, null, null, out funPtr);
|
||||
#endif
|
||||
int rc = GetFunctionPointerFn(RawPointer!(typeName), RawPointer!(methodName), CoreClr.UNMANAGEDCALLERSONLY_METHOD, null, null, out funPtr);
|
||||
|
||||
outDelegate = (T)funPtr;
|
||||
|
||||
@@ -185,82 +174,4 @@ namespace GlitchyEngineHelper
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
static class HostFxr
|
||||
{
|
||||
#if BF_PLATFORM_WINDOWS
|
||||
internal typealias char = char16;
|
||||
#else
|
||||
internal typealias char = char8;
|
||||
#endif
|
||||
|
||||
public enum DelegateType : c_int
|
||||
{
|
||||
ComActivation,
|
||||
LoadInMemoryAssembly,
|
||||
WinrtActivation,
|
||||
ComRegister,
|
||||
ComUnregister,
|
||||
LoadAssemblyAndGetFunctionPointer,
|
||||
GetFunctionPointer,
|
||||
}
|
||||
|
||||
public typealias Handle = void*;
|
||||
|
||||
[CRepr]
|
||||
public struct InitializeParameters
|
||||
{
|
||||
public c_size Size = sizeof(InitializeParameters);
|
||||
public char* HostPath;
|
||||
public char* DotnetRoot;
|
||||
};
|
||||
|
||||
public typealias InitializeForRuntimeConfigFn = function [CallingConvention(.Cdecl)] int32(char* runtimeConfigPath, InitializeParameters* parameters, Handle* hostContextHandle);
|
||||
public typealias InitializeForDotnetCommandLineFn = function [CallingConvention(.Cdecl)] int32(c_int argc, char** argv, InitializeParameters* parameters, Handle* hostContextHandle);
|
||||
public typealias GetRuntimeDelegateFn = function [CallingConvention(.Cdecl)] int32(Handle host_context_handle, DelegateType type, void** outDelegate);
|
||||
public typealias SetRuntimePropertyValueFn = function [CallingConvention(.Cdecl)] int32(Handle host_context_handle, char* name, char* value);
|
||||
public typealias CloseFn = function [CallingConvention(.Cdecl)] int32(Handle host_context_handle);
|
||||
}
|
||||
|
||||
static class CoreClr
|
||||
{
|
||||
#if BF_PLATFORM_WINDOWS
|
||||
internal typealias char = char16;
|
||||
#else
|
||||
internal typealias char = char8;
|
||||
#endif
|
||||
|
||||
public typealias LoadAssemblyAndGetFunctionPointerFn = function [CallingConvention(.Stdcall)] c_int(
|
||||
char* assemblyPath,
|
||||
char* typeName,
|
||||
char* methodName,
|
||||
char* delegateTypeName,
|
||||
void* reserved,
|
||||
out void* outDelegate);
|
||||
|
||||
public typealias GetFunctionPointerFn = function [CallingConvention(.Stdcall)] c_int(
|
||||
char* typeName,
|
||||
char* MethodName,
|
||||
char* delegateTypeName,
|
||||
void* loadContext,
|
||||
void* reserved,
|
||||
out void* outDelegate
|
||||
);
|
||||
}
|
||||
|
||||
static class NetHost
|
||||
{
|
||||
public struct get_hostfxr_parameters
|
||||
{
|
||||
public c_size size;
|
||||
public DotNet.char* assembly_path;
|
||||
public DotNet.char* dotnet_root;
|
||||
};
|
||||
|
||||
[CallingConvention(.Stdcall), LinkName("get_hostfxr_path")]
|
||||
public static extern int get_hostfxr_path(
|
||||
DotNet.char * buffer,
|
||||
c_size * buffer_size,
|
||||
get_hostfxr_parameters *parameters);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using System.Interop;
|
||||
|
||||
using internal GlitchyEngineHelper.DotNet;
|
||||
|
||||
namespace GlitchyEngineHelper.DotNet
|
||||
{
|
||||
static
|
||||
{
|
||||
#if BF_PLATFORM_WINDOWS
|
||||
internal typealias char = char16;
|
||||
#else
|
||||
internal typealias char = char8;
|
||||
#endif
|
||||
}
|
||||
|
||||
static class CoreClr
|
||||
{
|
||||
public const char* UNMANAGEDCALLERSONLY_METHOD = (char*)(void*)-1;
|
||||
|
||||
public typealias LoadAssemblyAndGetFunctionPointerFn = function [CallingConvention(.Stdcall)] c_int(
|
||||
char* assemblyPath,
|
||||
char* typeName,
|
||||
char* methodName,
|
||||
char* delegateTypeName,
|
||||
void* reserved,
|
||||
out void* outDelegate);
|
||||
|
||||
public typealias GetFunctionPointerFn = function [CallingConvention(.Stdcall)] c_int(
|
||||
char* typeName,
|
||||
char* MethodName,
|
||||
char* delegateTypeName,
|
||||
void* loadContext,
|
||||
void* reserved,
|
||||
out void* outDelegate
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
using System;
|
||||
using System.Interop;
|
||||
|
||||
using internal GlitchyEngineHelper.DotNet;
|
||||
|
||||
namespace GlitchyEngineHelper.DotNet
|
||||
{
|
||||
static class HostFxr
|
||||
{
|
||||
public enum DelegateType : c_int
|
||||
{
|
||||
ComActivation,
|
||||
LoadInMemoryAssembly,
|
||||
WinrtActivation,
|
||||
ComRegister,
|
||||
ComUnregister,
|
||||
LoadAssemblyAndGetFunctionPointer,
|
||||
GetFunctionPointer,
|
||||
}
|
||||
|
||||
public typealias Handle = void*;
|
||||
|
||||
[CRepr]
|
||||
public struct InitializeParameters
|
||||
{
|
||||
public c_size Size = sizeof(InitializeParameters);
|
||||
public char* HostPath;
|
||||
public char* DotnetRoot;
|
||||
};
|
||||
|
||||
public typealias InitializeForRuntimeConfigFn = function [CallingConvention(.Cdecl)] int32(char* runtimeConfigPath, InitializeParameters* parameters, Handle* hostContextHandle);
|
||||
public typealias InitializeForDotnetCommandLineFn = function [CallingConvention(.Cdecl)] int32(c_int argc, char** argv, InitializeParameters* parameters, Handle* hostContextHandle);
|
||||
public typealias GetRuntimeDelegateFn = function [CallingConvention(.Cdecl)] int32(Handle host_context_handle, DelegateType type, void** outDelegate);
|
||||
public typealias SetRuntimePropertyValueFn = function [CallingConvention(.Cdecl)] int32(Handle host_context_handle, char* name, char* value);
|
||||
public typealias CloseFn = function [CallingConvention(.Cdecl)] int32(Handle host_context_handle);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using System.Interop;
|
||||
|
||||
using internal GlitchyEngineHelper.DotNet;
|
||||
|
||||
namespace GlitchyEngineHelper.DotNet
|
||||
{
|
||||
static class NetHost
|
||||
{
|
||||
public struct get_hostfxr_parameters
|
||||
{
|
||||
public c_size size;
|
||||
public char* assembly_path;
|
||||
public char* dotnet_root;
|
||||
};
|
||||
|
||||
[CallingConvention(.Stdcall), LinkName("get_hostfxr_path")]
|
||||
public static extern int get_hostfxr_path(
|
||||
DotNet.char * buffer,
|
||||
c_size * buffer_size,
|
||||
get_hostfxr_parameters *parameters);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user