Added EngineResult glue type, some cleanup

This commit is contained in:
Simon Lübeß
2025-07-26 21:03:10 +02:00
parent c41425ad36
commit 08846a0c0b
10 changed files with 391 additions and 1881 deletions
+64
View File
@@ -0,0 +1,64 @@
using System;
using System.Runtime.CompilerServices;
using System.Security.Cryptography.X509Certificates;
namespace GlitchyEngine.Core;
[EngineClass("GlitchyEngine.Scripting.ScriptGlue.EngineResult")]
internal enum EngineResult
{
Ok = 0, // Success, can mean True
False = 1, // Success, can mean False
Error = -1,
NotImplemented = -2,
ArgumentError = -3,
// Entity Errors:
EntityNotFound = -4, // The entity doesn't exist or was deleted.
EntityDoesntHaveComponent = -5, // The entity has no component of type {typeof(T)} or it was deleted.
AssetNotFound = -6, // No asset exists for AssetHandle \"{assetId}\".
}
public class EngineException(string message) : Exception(message);
public class EntityNotFoundException : Exception
{
}
public class ComponentNotFoundException : Exception
{
}
public class AssetNotFoundException : Exception
{
}
internal static class EngineErrors
{
public static void ThrowIfError(EngineResult result, [CallerMemberName]string callerName = "")
{
if (result >= 0)
return;
switch (result)
{
case EngineResult.Error:
throw new EngineException($"Unspecified engine excepiton in {callerName}");
case EngineResult.NotImplemented:
throw new NotImplementedException($"Function {callerName} is not implemented in the engine.");
case EngineResult.ArgumentError:
throw new ArgumentException($"An argument passed to {callerName} is invalid.");
case EngineResult.EntityNotFound:
throw new EntityNotFoundException();
case EngineResult.EntityDoesntHaveComponent:
throw new ComponentNotFoundException();
case EngineResult.AssetNotFound:
throw new AssetNotFoundException();
default:
throw new EngineException($"Unknown engine excepiton in {callerName}");
}
}
}
-2
View File
@@ -305,8 +305,6 @@ internal static unsafe partial class ScriptGlue
[UnmanagedCallersOnly]
public static void CreateScriptInstance(UUID entityId, byte* scriptClassName)
{
Log.Info("Exception");
Type? scriptType = GetTypeFromNativeString(scriptClassName);
Debug.Assert(scriptType != null, "Script class Type not found.");
File diff suppressed because it is too large Load Diff