mirror of
https://github.com/aharabada/glitchy-engine-beef.git
synced 2026-09-05 13:01:52 +00:00
Started reworking entity initialisation
This commit is contained in:
@@ -293,7 +293,9 @@ class ScriptClass : SharpClass
|
|||||||
typealias OnUpdateMethod = function MonoObject*(MonoObject* instance, float deltaTime, MonoException** exception);
|
typealias OnUpdateMethod = function MonoObject*(MonoObject* instance, float deltaTime, MonoException** exception);
|
||||||
typealias OnDestroyMethod = function MonoObject*(MonoObject* instance, MonoException** exception);
|
typealias OnDestroyMethod = function MonoObject*(MonoObject* instance, MonoException** exception);
|
||||||
|
|
||||||
private MonoMethod* _constructor;
|
//private MonoMethod* _constructor;
|
||||||
|
private List<MonoMethod*> _constructors ~ delete _;
|
||||||
|
|
||||||
//private ConstructorMethod _constructor;
|
//private ConstructorMethod _constructor;
|
||||||
private OnCreateMethod _onCreate;
|
private OnCreateMethod _onCreate;
|
||||||
private OnUpdateMethod _onUpdate;
|
private OnUpdateMethod _onUpdate;
|
||||||
@@ -321,7 +323,8 @@ class ScriptClass : SharpClass
|
|||||||
base(classNamespace, className, image, scriptFieldType)
|
base(classNamespace, className, image, scriptFieldType)
|
||||||
{
|
{
|
||||||
//_constructor = (ConstructorMethod)GetMethodThunk(".ctor", 1); // GetMethod(".ctor", 1);//
|
//_constructor = (ConstructorMethod)GetMethodThunk(".ctor", 1); // GetMethod(".ctor", 1);//
|
||||||
_constructor = GetMethod(".ctor", 1);
|
CreateConstructorChain();
|
||||||
|
//_constructor = GetMethod(".ctor", 1);
|
||||||
_onCreate = (OnCreateMethod)GetMethodThunk("OnCreate");
|
_onCreate = (OnCreateMethod)GetMethodThunk("OnCreate");
|
||||||
_onUpdate = (OnUpdateMethod)GetMethodThunk("OnUpdate", 1);
|
_onUpdate = (OnUpdateMethod)GetMethodThunk("OnUpdate", 1);
|
||||||
_onDestroy = (OnDestroyMethod)GetMethodThunk("OnDestroy");
|
_onDestroy = (OnDestroyMethod)GetMethodThunk("OnDestroy");
|
||||||
@@ -333,6 +336,61 @@ class ScriptClass : SharpClass
|
|||||||
_onCollisionLeave2DMethod = GetMethod("OnCollisionLeave2D", 1);
|
_onCollisionLeave2DMethod = GetMethod("OnCollisionLeave2D", 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void CreateConstructorChain()
|
||||||
|
{
|
||||||
|
_constructors = new List<MonoMethod*>();
|
||||||
|
|
||||||
|
MonoClass* @class = _monoClass;
|
||||||
|
|
||||||
|
while (@class != null)
|
||||||
|
{
|
||||||
|
void* iter = null;
|
||||||
|
MonoMethod* method = null;
|
||||||
|
|
||||||
|
while ((method = Mono.mono_class_get_methods(@class, &iter)) != null)
|
||||||
|
{
|
||||||
|
if (StringView(Mono.mono_method_get_name(method)) == ".ctor")
|
||||||
|
{
|
||||||
|
MonoMethodSignature* signature = Mono.mono_method_signature(method);
|
||||||
|
if (Mono.mono_signature_get_param_count(signature) == 1)
|
||||||
|
{
|
||||||
|
void* paramsIterator = null;
|
||||||
|
MonoType* paramType = Mono.mono_signature_get_params(signature, ¶msIterator);
|
||||||
|
|
||||||
|
let name = Mono.mono_type_get_name(paramType);
|
||||||
|
|
||||||
|
// TODO: Compare types with something stored in ScriptEngine
|
||||||
|
if (StringView(name) == "GlitchyEngine.Core.UUID")
|
||||||
|
{
|
||||||
|
_constructors.Add(method);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@class = Mono.mono_class_get_parent(@class);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CallConstructorChain(MonoObject* instance, UUID uuid, out MonoException* exception)
|
||||||
|
{
|
||||||
|
exception = null;
|
||||||
|
|
||||||
|
if (_constructors.Count == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
void*[1] args = void*[](&uuid);
|
||||||
|
|
||||||
|
for (MonoMethod* constructor in _constructors)
|
||||||
|
{
|
||||||
|
// Invoke constructor with UUID
|
||||||
|
MonoObject* result = Mono.mono_runtime_invoke(constructor, instance, &args, (.)&exception);
|
||||||
|
break;
|
||||||
|
//#unwarn
|
||||||
|
//ScriptEngine.[Friend]s_EngineObject.Invoke(constructor, instance, out exception, &uuid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void OnCreate(MonoObject* instance, out MonoException* exception)
|
public void OnCreate(MonoObject* instance, out MonoException* exception)
|
||||||
{
|
{
|
||||||
exception = null;
|
exception = null;
|
||||||
@@ -394,11 +452,14 @@ class ScriptClass : SharpClass
|
|||||||
MonoObject* instance = Mono.mono_object_new(ScriptEngine.[Friend]s_AppDomain, _monoClass);
|
MonoObject* instance = Mono.mono_object_new(ScriptEngine.[Friend]s_AppDomain, _monoClass);
|
||||||
|
|
||||||
// Invoke empty constructor to initialize fields with default values specified in the script itself
|
// Invoke empty constructor to initialize fields with default values specified in the script itself
|
||||||
Mono.mono_runtime_object_init(instance);
|
//Mono.mono_runtime_object_init(instance);
|
||||||
|
|
||||||
|
// Invoke UUID Constructors:
|
||||||
|
CallConstructorChain(instance, uuid, out exception);
|
||||||
|
|
||||||
// Invoke constructor with UUID
|
// Invoke constructor with UUID
|
||||||
#unwarn
|
//#unwarn
|
||||||
ScriptEngine.[Friend]s_EngineObject.Invoke(ScriptEngine.[Friend]s_EngineObject._constructor, instance, out exception, &uuid);
|
//ScriptEngine.[Friend]s_EngineObject.Invoke(ScriptEngine.[Friend]s_EngineObject._constructor, instance, out exception, &uuid);
|
||||||
|
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -111,6 +111,9 @@ static class Mono
|
|||||||
[LinkName(.C)]
|
[LinkName(.C)]
|
||||||
public static extern void mono_runtime_object_init(MonoObject* this_obj);
|
public static extern void mono_runtime_object_init(MonoObject* this_obj);
|
||||||
|
|
||||||
|
[LinkName(.C)]
|
||||||
|
public static extern MonoMethod* mono_class_get_methods(MonoClass* klass, gpointer* iter);
|
||||||
|
|
||||||
[LinkName(.C)]
|
[LinkName(.C)]
|
||||||
public static extern MonoMethod* mono_class_get_method_from_name(MonoClass* klass, char8* name, int param_count);
|
public static extern MonoMethod* mono_class_get_method_from_name(MonoClass* klass, char8* name, int param_count);
|
||||||
|
|
||||||
@@ -129,7 +132,19 @@ static class Mono
|
|||||||
|
|
||||||
[LinkName(.C)]
|
[LinkName(.C)]
|
||||||
public static extern gpointer mono_method_get_unmanaged_thunk(MonoMethod *method);
|
public static extern gpointer mono_method_get_unmanaged_thunk(MonoMethod *method);
|
||||||
|
|
||||||
|
[LinkName(.C)]
|
||||||
|
public static extern char8* mono_method_get_name(MonoMethod *method);
|
||||||
|
|
||||||
|
[LinkName(.C)]
|
||||||
|
public static extern MonoMethodSignature* mono_method_signature(MonoMethod *method);
|
||||||
|
|
||||||
|
[LinkName(.C)]
|
||||||
|
public static extern uint32 mono_signature_get_param_count(MonoMethodSignature *sig);
|
||||||
|
|
||||||
|
[LinkName(.C)]
|
||||||
|
public static extern MonoType* mono_signature_get_params(MonoMethodSignature *sig, gpointer *iter);
|
||||||
|
|
||||||
[LinkName(.C)]
|
[LinkName(.C)]
|
||||||
public static extern mono_bool mono_class_is_subclass_of(MonoClass *monoClass, MonoClass *parentClass,
|
public static extern mono_bool mono_class_is_subclass_of(MonoClass *monoClass, MonoClass *parentClass,
|
||||||
mono_bool check_interfaces);
|
mono_bool check_interfaces);
|
||||||
@@ -166,6 +181,9 @@ static class Mono
|
|||||||
|
|
||||||
[LinkName(.C)]
|
[LinkName(.C)]
|
||||||
public static extern MonoClassField* mono_class_get_fields(MonoClass* klass, gpointer* iter);
|
public static extern MonoClassField* mono_class_get_fields(MonoClass* klass, gpointer* iter);
|
||||||
|
|
||||||
|
[LinkName(.C)]
|
||||||
|
public static extern MonoClass* mono_class_get_parent(MonoClass* klass);
|
||||||
|
|
||||||
[LinkName(.C)]
|
[LinkName(.C)]
|
||||||
public static extern char8* mono_field_get_name(MonoClassField* field);
|
public static extern char8* mono_field_get_name(MonoClassField* field);
|
||||||
@@ -343,6 +361,8 @@ struct MonoObject;
|
|||||||
|
|
||||||
struct MonoMethod;
|
struct MonoMethod;
|
||||||
|
|
||||||
|
struct MonoMethodSignature;
|
||||||
|
|
||||||
struct MonoProperty;
|
struct MonoProperty;
|
||||||
|
|
||||||
struct MonoThread;
|
struct MonoThread;
|
||||||
|
|||||||
Reference in New Issue
Block a user