mirror of
https://github.com/aharabada/glitchy-engine-beef.git
synced 2026-11-04 12:51:48 +00:00
Fixed exception logging and entity id of messages
This commit is contained in:
@@ -14,6 +14,7 @@ using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Runtime.Loader;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
|
||||
namespace GlitchyEngine;
|
||||
|
||||
@@ -272,11 +273,16 @@ internal static unsafe partial class ScriptGlue
|
||||
_unsafeClasses = null;
|
||||
}
|
||||
|
||||
private static readonly AsyncLocal<UUID> _currentEntityId = new ();
|
||||
|
||||
internal static UUID CurrentEntityId => _currentEntityId.Value;
|
||||
|
||||
[UnmanagedCallersOnly]
|
||||
public static void ShowEntityEditor(UUID entityId)
|
||||
{
|
||||
try
|
||||
{
|
||||
_currentEntityId.Value = entityId;
|
||||
(Entity entity, Type type) = EntityScriptInstances[entityId];
|
||||
EntityEditor.ShowEntityEditor(entity);
|
||||
}
|
||||
@@ -284,6 +290,10 @@ internal static unsafe partial class ScriptGlue
|
||||
{
|
||||
Log.Exception(e);
|
||||
}
|
||||
finally
|
||||
{
|
||||
_currentEntityId.Value = UUID.Zero;
|
||||
}
|
||||
}
|
||||
|
||||
[UnmanagedCallersOnly]
|
||||
@@ -291,6 +301,7 @@ internal static unsafe partial class ScriptGlue
|
||||
{
|
||||
try
|
||||
{
|
||||
_currentEntityId.Value = entityId;
|
||||
(Entity entity, Type type) = EntityScriptInstances[entityId];
|
||||
entity.OnCreate();
|
||||
}
|
||||
@@ -298,6 +309,10 @@ internal static unsafe partial class ScriptGlue
|
||||
{
|
||||
Log.Exception(e);
|
||||
}
|
||||
finally
|
||||
{
|
||||
_currentEntityId.Value = UUID.Zero;
|
||||
}
|
||||
}
|
||||
|
||||
[UnmanagedCallersOnly(CallConvs = [typeof(CallConvCdecl)])]
|
||||
@@ -305,6 +320,7 @@ internal static unsafe partial class ScriptGlue
|
||||
{
|
||||
try
|
||||
{
|
||||
_currentEntityId.Value = entityId;
|
||||
(Entity entity, Type type) = EntityScriptInstances[entityId];
|
||||
entity.OnUpdate(deltaTime);
|
||||
}
|
||||
@@ -312,6 +328,10 @@ internal static unsafe partial class ScriptGlue
|
||||
{
|
||||
Log.Exception(e);
|
||||
}
|
||||
finally
|
||||
{
|
||||
_currentEntityId.Value = UUID.Zero;
|
||||
}
|
||||
}
|
||||
|
||||
[UnmanagedCallersOnly(CallConvs = [typeof(CallConvCdecl)])]
|
||||
@@ -319,6 +339,7 @@ internal static unsafe partial class ScriptGlue
|
||||
{
|
||||
try
|
||||
{
|
||||
_currentEntityId.Value = entityId;
|
||||
(Entity entity, Type type) = EntityScriptInstances[entityId];
|
||||
entity.OnCollisionEnter2D(collision);
|
||||
}
|
||||
@@ -326,6 +347,10 @@ internal static unsafe partial class ScriptGlue
|
||||
{
|
||||
Log.Exception(e);
|
||||
}
|
||||
finally
|
||||
{
|
||||
_currentEntityId.Value = UUID.Zero;
|
||||
}
|
||||
}
|
||||
|
||||
[UnmanagedCallersOnly]
|
||||
@@ -333,6 +358,7 @@ internal static unsafe partial class ScriptGlue
|
||||
{
|
||||
try
|
||||
{
|
||||
_currentEntityId.Value = entityId;
|
||||
if (EntityScriptInstances.Remove(entityId, out var match) && callDestroy > 0)
|
||||
{
|
||||
match.Entity.OnDestroy();
|
||||
@@ -342,6 +368,10 @@ internal static unsafe partial class ScriptGlue
|
||||
{
|
||||
Log.Exception(e);
|
||||
}
|
||||
finally
|
||||
{
|
||||
_currentEntityId.Value = UUID.Zero;
|
||||
}
|
||||
}
|
||||
|
||||
internal static Type? GetTypeFromNativeString(byte* fullTypeName)
|
||||
@@ -365,6 +395,7 @@ internal static unsafe partial class ScriptGlue
|
||||
{
|
||||
try
|
||||
{
|
||||
_currentEntityId.Value = entityId;
|
||||
Type? scriptType = GetTypeFromNativeString(scriptClassName);
|
||||
|
||||
Debug.Assert(scriptType != null, "Script class Type not found.");
|
||||
@@ -379,6 +410,10 @@ internal static unsafe partial class ScriptGlue
|
||||
{
|
||||
Log.Exception(e);
|
||||
}
|
||||
finally
|
||||
{
|
||||
_currentEntityId.Value = UUID.Zero;
|
||||
}
|
||||
}
|
||||
|
||||
struct ComponentFunctionPointers
|
||||
@@ -459,6 +494,7 @@ internal static unsafe partial class ScriptGlue
|
||||
{
|
||||
try
|
||||
{
|
||||
_currentEntityId.Value = entityId;
|
||||
if (!EntityScriptInstances.TryGetValue(entityId, out var match))
|
||||
return;
|
||||
|
||||
@@ -468,6 +504,10 @@ internal static unsafe partial class ScriptGlue
|
||||
{
|
||||
Log.Exception(e);
|
||||
}
|
||||
finally
|
||||
{
|
||||
_currentEntityId.Value = UUID.Zero;
|
||||
}
|
||||
}
|
||||
|
||||
[UnmanagedCallersOnly]
|
||||
@@ -475,6 +515,7 @@ internal static unsafe partial class ScriptGlue
|
||||
{
|
||||
try
|
||||
{
|
||||
_currentEntityId.Value = entityId;
|
||||
if (!EntityScriptInstances.TryGetValue(entityId, out var match))
|
||||
return;
|
||||
|
||||
@@ -484,6 +525,10 @@ internal static unsafe partial class ScriptGlue
|
||||
{
|
||||
Log.Exception(e);
|
||||
}
|
||||
finally
|
||||
{
|
||||
_currentEntityId.Value = UUID.Zero;
|
||||
}
|
||||
}
|
||||
|
||||
[UnmanagedCallersOnly]
|
||||
|
||||
Reference in New Issue
Block a user