mirror of
https://github.com/aharabada/glitchy-engine-beef.git
synced 2026-09-06 05:01:53 +00:00
Invoke on collision enter + start of attach child colliders to rigidbody
+ Changed default Namespace of ScriptCore to GlitchyEngine + Implicit Casts float2 <-> b2Vec2 + Entity constructor internal + Renamed RigidBody2D to Rigidbody2D (notice the B) + Basic Debug Draw actual 2D Colliders + Added Entity::GetParentWithComponent
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using GlitchyEngine.Core;
|
||||
|
||||
namespace GlitchyEngine.Scripting.Classes;
|
||||
|
||||
[Ordered, Packed]
|
||||
struct Collision2D
|
||||
{
|
||||
public UUID Entity;
|
||||
public UUID OtherEntity;
|
||||
|
||||
public UUID Rigidbody;
|
||||
public UUID OtherRigidbody;
|
||||
}
|
||||
@@ -2,6 +2,7 @@ using Mono;
|
||||
using System;
|
||||
using GlitchyEngine.Core;
|
||||
using System.Collections;
|
||||
using GlitchyEngine.Scripting.Classes;
|
||||
|
||||
namespace GlitchyEngine.Scripting;
|
||||
|
||||
@@ -287,6 +288,14 @@ class ScriptClass : SharpClass
|
||||
private OnCreateMethod _onCreate;
|
||||
private OnUpdateMethod _onUpdate;
|
||||
private OnDestroyMethod _onDestroy;
|
||||
|
||||
private function [CallingConvention(.Cdecl)] MonoObject*(MonoObject* instance, Collision2D collision, MonoException** exception) _onCollisionEnter2D;
|
||||
|
||||
//private OnCollisionEnter2DMethod _onCollisionEnter2D;
|
||||
private OnDestroyMethod _onCollisionLeave2D;
|
||||
private MonoMethod* _onCollisionEnter2DMethod;
|
||||
|
||||
public bool HasCollisionEnter2D => _onCollisionEnter2D != null;
|
||||
|
||||
/*public StringView Namespace => _namespace;
|
||||
public StringView ClassName => _className;
|
||||
@@ -303,6 +312,11 @@ class ScriptClass : SharpClass
|
||||
_onCreate = (OnCreateMethod)GetMethodThunk("OnCreate");
|
||||
_onUpdate = (OnUpdateMethod)GetMethodThunk("OnUpdate", 1);
|
||||
_onDestroy = (OnDestroyMethod)GetMethodThunk("OnDestroy");
|
||||
|
||||
_onCollisionEnter2D = (.)GetMethodThunk("OnCollisionEnter2D", 1);
|
||||
_onCollisionLeave2D = (OnDestroyMethod)GetMethodThunk("OnCollisionLeave2D");
|
||||
|
||||
_onCollisionEnter2DMethod = GetMethod("OnCollisionEnter2D", 1);
|
||||
}
|
||||
|
||||
public void OnCreate(MonoObject* instance, out MonoException* exception)
|
||||
@@ -328,6 +342,22 @@ class ScriptClass : SharpClass
|
||||
if (_onDestroy != null)
|
||||
_onDestroy(instance, &exception);
|
||||
}
|
||||
|
||||
public void OnCollisionEnter2D(MonoObject* instance, Collision2D collision, out MonoException* exception)
|
||||
{
|
||||
exception = null;
|
||||
|
||||
// TODO: use method thunk
|
||||
if (_onCollisionEnter2DMethod != null)
|
||||
{
|
||||
#unwarn
|
||||
void*[1] args = .(&collision);
|
||||
|
||||
Invoke(_onCollisionEnter2DMethod, instance, (.)&args);
|
||||
}
|
||||
// if (_onCollisionEnter2D != null)
|
||||
// _onCollisionEnter2D(instance, collision, &exception);
|
||||
}
|
||||
|
||||
public MonoObject* CreateInstance(UUID uuid, out MonoException* exception)
|
||||
{
|
||||
|
||||
@@ -64,7 +64,7 @@ static class ScriptGlue
|
||||
s_RemoveComponentMethods.Clear();
|
||||
|
||||
RegisterComponent<TransformComponent>("GlitchyEngine.Transform");
|
||||
RegisterComponent<Rigidbody2DComponent>("GlitchyEngine.RigidBody2D");
|
||||
RegisterComponent<Rigidbody2DComponent>("GlitchyEngine.Rigidbody2D");
|
||||
}
|
||||
|
||||
[RegisterMethod]
|
||||
@@ -99,7 +99,7 @@ static class ScriptGlue
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.EngineLogger.AssertDebug(managedType != null, scope $"No C# component with name \"{{className}}\" found for Beef type \"{typeof(T)}\"");
|
||||
Log.EngineLogger.AssertDebug(managedType != null, scope $"No C# component with name \"{className}\" found for Beef type \"{typeof(T)}\"");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using Mono;
|
||||
using GlitchyEngine.Core;
|
||||
using System;
|
||||
using GlitchyEngine.Scripting.Classes;
|
||||
|
||||
namespace GlitchyEngine.Scripting;
|
||||
|
||||
@@ -80,6 +81,17 @@ class ScriptInstance : RefCounter
|
||||
if (exception != null)
|
||||
ScriptEngine.HandleMonoException(exception, this);
|
||||
}
|
||||
|
||||
public void InvokeOnCollisionEnter2D(Collision2D collision)
|
||||
{
|
||||
if (!_scriptClass.HasCollisionEnter2D)
|
||||
return;
|
||||
|
||||
_scriptClass.OnCollisionEnter2D(_instance, collision, let exception);
|
||||
|
||||
if (exception != null)
|
||||
ScriptEngine.HandleMonoException(exception, this);
|
||||
}
|
||||
|
||||
public T GetFieldValue<T>(ScriptField field)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user