diff --git a/GlitchyEngine/src/Scripting/ScriptGlue.bf b/GlitchyEngine/src/Scripting/ScriptGlue.bf index 0536811..5f7ad75 100644 --- a/GlitchyEngine/src/Scripting/ScriptGlue.bf +++ b/GlitchyEngine/src/Scripting/ScriptGlue.bf @@ -66,6 +66,17 @@ struct TypeTranslationTemplate } } +[AttributeUsage(.Parameter)] +struct GlueParamAttribute : Attribute +{ + public String WrapperType; + + public this(String wrapperType) + { + WrapperType = wrapperType; + } +} + [AttributeUsage(.Struct)] struct EngineFunctionsGeneratorAttribute : Attribute, IComptimeTypeApply { @@ -74,7 +85,22 @@ struct EngineFunctionsGeneratorAttribute : Attribute, IComptimeTypeApply ("int32", "int"), ("char16*", "char*"), ("char8*", "byte*"), - ("GlitchyEngine.Events.MouseButton", "GlitchyEngine.MouseButton") + ("uint8*", "byte*"), + ("GlitchyEngine.Events.MouseButton", "GlitchyEngine.MouseButton"), + ("GlitchLog.LogLevel", "Log.LogLevel"), + ("out GlitchyEngine.Content.AssetHandle", "UUID"), + ("GlitchyEngine.Content.AssetHandle", "UUID"), + ("out GlitchyEngine.Renderer.Text.FontRenderer.HorizontalTextAlignment", "HorizontalTextAlignment"), + ("GlitchyEngine.Renderer.Text.FontRenderer.HorizontalTextAlignment", "HorizontalTextAlignment"), + ("GlitchyEngine.Renderer.ShaderVariableType", "Material.ShaderVariableType"), + ("in GlitchyEngine.Math.Quaternion", "in System.Numerics.Quaternion"), + ("out GlitchyEngine.Math.Quaternion", "out System.Numerics.Quaternion"), + ("out GlitchyEngine.Scripting.ScriptGlue.AxisAngle", "out RotationAxisAngle"), + ("GlitchyEngine.Scripting.ScriptGlue.AxisAngle", "RotationAxisAngle"), + ("out GlitchyEngine.World.Rigidbody2DComponent.BodyType", "out BodyType"), + ("in GlitchyEngine.World.Rigidbody2DComponent.BodyType", "in BodyType"), + ("out GlitchyEngine.World.SceneCamera.ProjectionType", "out ProjectionType"), + ("in GlitchyEngine.World.SceneCamera.ProjectionType", "in ProjectionType"), }; // {0}... Out name, @@ -158,6 +184,12 @@ struct EngineFunctionsGeneratorAttribute : Attribute, IComptimeTypeApply TypeTranslationTemplate template = GetCSharpWrapperTemplate(beefParameterType); + // TODO: This is currently not implemented in beef. + /*if (method.GetParamCustomAttribute(i) case .Ok(let attribute)) + { + template.PrettyCSharpParamType = attribute.WrapperType; + }*/ + StringView paramName = method.GetParamName(i); // Generate the parameter for the wrapper head. @@ -202,7 +234,7 @@ struct EngineFunctionsGeneratorAttribute : Attribute, IComptimeTypeApply TypeTranslationTemplate template = GetCSharpReturnValueTemplate(csharpReturnType); outString.AppendF($""" - internal static unsafe {template.PrettyCSharpParamType} NEW_{method.Name}({wrapperParameters}) + internal static unsafe {template.PrettyCSharpParamType} {method.Name}({wrapperParameters}) {{ {translation} {template.StartCode}_engineFunctions.{method.Name}({callArguments}); @@ -215,6 +247,48 @@ struct EngineFunctionsGeneratorAttribute : Attribute, IComptimeTypeApply """); } + private static String GetTypeInfo(Type type) + { + String value = new .(); + type.ToString(value); + + if (type.IsEnum) + { + value.AppendF($" : {type.UnderlyingType}"); + } + + return value; + } + + private static void GenerateJsonInfo(MethodInfo method, String outString) + { + String parameters = new String(); + + for (int i < method.ParamCount) + { + if (i != 0) + parameters.Append(", "); + + parameters.AppendF($""" + + {{ + "name": "{method.GetParamName(i)}", + "type": "{GetTypeInfo(method.GetParamType(i))}" + }} + """); + } + + outString.AppendF($""" + + {{ + "name": "{method.Name}", + "return_type": "{GetTypeInfo(method.ReturnType)}", + "parameters": [{parameters} + ] + }}, + """); + } + [Comptime] public void ApplyToType(Type self) { @@ -223,6 +297,10 @@ struct EngineFunctionsGeneratorAttribute : Attribute, IComptimeTypeApply using System.Runtime.InteropServices; using GlitchyEngine; using GlitchyEngine.Core; + using GlitchyEngine.Math; + using GlitchyEngine.Physics; + using GlitchyEngine.Graphics; + using GlitchyEngine.Graphics.Text; namespace GlitchyEngine; @@ -239,6 +317,8 @@ struct EngineFunctionsGeneratorAttribute : Attribute, IComptimeTypeApply """); + String jsonOutput = new String("["); + for (MethodInfo methodInfo in typeof(ScriptGlue).GetMethods(.Static | .NonPublic)) { if (methodInfo.GetCustomAttribute() case .Ok(let attribute)) @@ -260,6 +340,7 @@ struct EngineFunctionsGeneratorAttribute : Attribute, IComptimeTypeApply GenerateCSharpFunctionPointer(methodInfo, csharpEngineFunctionsStruct); GenerateCSharpWrapperMethod(methodInfo, csharpScriptGlue); + GenerateJsonInfo(methodInfo, jsonOutput); } } @@ -268,7 +349,21 @@ struct EngineFunctionsGeneratorAttribute : Attribute, IComptimeTypeApply csharpEngineFunctionsStruct.Append(csharpScriptGlue); - if (File.WriteAllText("../ScriptCore/ScriptGlue.gen.cs", csharpEngineFunctionsStruct) case .Err) + /*if (File.WriteAllText("../ScriptCore/ScriptGlue.gen.cs", csharpEngineFunctionsStruct) case .Err) + { + Runtime.FatalError("Failed to write file"); + }*/ + + if (jsonOutput.EndsWith(",")) + { + jsonOutput.RemoveFromEnd(1); + } + + jsonOutput.Append(']'); + + Directory.CreateDirectory("../generated"); + + if (File.WriteAllText("../generated/ScriptGlue.json", jsonOutput) case .Err) { Runtime.FatalError("Failed to write file"); } @@ -537,7 +632,7 @@ static class ScriptGlue [RegisterCall("ScriptGlue::Log_LogMessage")] [CallingConvention(.Cdecl)] - static void Log_LogMessage(int32 logLevel, char16* messagePtr, char16* fileNamePtr, int lineNumber) + static void Log_LogMessage(LogLevel logLevel, char16* messagePtr, char16* fileNamePtr, int lineNumber) { String escapedMessage = new:ScopedAlloc! String(messagePtr); @@ -1421,14 +1516,14 @@ static class ScriptGlue } [RegisterCall("ScriptGlue::TextRenderer_GetHorizontalAlignment")] - static void TextRenderer_GetHorizontalAlignment(UUID entityId, out HorizontalTextAlignment horizontalAlignment) + static void TextRenderer_GetHorizontalAlignment(UUID entityId, [GlueParam("out HorizontalTextAlignment")] out HorizontalTextAlignment horizontalAlignment) { TextRendererComponent* textComponent = GetComponentSafe(entityId); horizontalAlignment = textComponent.HorizontalAlignment; } [RegisterCall("ScriptGlue::TextRenderer_SetHorizontalAlignment")] - static void TextRenderer_SetHorizontalAlignment(UUID entityId, HorizontalTextAlignment horizontalAlignment) + static void TextRenderer_SetHorizontalAlignment(UUID entityId, [GlueParam("HorizontalTextAlignment")] HorizontalTextAlignment horizontalAlignment) { TextRendererComponent* textComponent = GetComponentSafe(entityId); textComponent.HorizontalAlignment = horizontalAlignment; diff --git a/ScriptCore/Core/EngineClassAttribute.cs b/ScriptCore/Core/EngineClassAttribute.cs new file mode 100644 index 0000000..d291926 --- /dev/null +++ b/ScriptCore/Core/EngineClassAttribute.cs @@ -0,0 +1,14 @@ +using System; + +namespace GlitchyEngine.Core; + +[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum, AllowMultiple = true)] +public class EngineClassAttribute : Attribute +{ + public string EngineClassName { get; } + + public EngineClassAttribute(string engineClassName) + { + EngineClassName = engineClassName; + } +} \ No newline at end of file diff --git a/ScriptCore/Core/UUID.cs b/ScriptCore/Core/UUID.cs index d3e4dab..01bc07a 100644 --- a/ScriptCore/Core/UUID.cs +++ b/ScriptCore/Core/UUID.cs @@ -6,6 +6,8 @@ namespace GlitchyEngine.Core; /// Represents a universally unique identifier (UUID). /// [DebuggerDisplay("{ToString()}")] +[EngineClass("GlitchyEngine.Core.UUID")] +[EngineClass("GlitchyEngine.Core.AssetHandle")] public struct UUID { private ulong _uuid; diff --git a/ScriptCore/Graphics/Material.cs b/ScriptCore/Graphics/Material.cs index 77de02a..a5d382a 100644 --- a/ScriptCore/Graphics/Material.cs +++ b/ScriptCore/Graphics/Material.cs @@ -9,11 +9,19 @@ namespace GlitchyEngine.Graphics; /// public class Material : Asset { + internal enum ShaderVariableType : byte + { + Bool, + Float, + Int, + UInt + } + public void SetVariable(string name, float4 value) { unsafe { - ScriptGlue.Material_SetVariable(_uuid, name, ScriptGlue.ShaderVariableType.Float, 1, 4, 1, &value, sizeof(float4)); + ScriptGlue.Material_SetVariable(_uuid, name, ShaderVariableType.Float, 1, 4, 1, &value, sizeof(float4)); } } diff --git a/ScriptCore/Log.cs b/ScriptCore/Log.cs index 6d75a1d..e76db2c 100644 --- a/ScriptCore/Log.cs +++ b/ScriptCore/Log.cs @@ -1,6 +1,7 @@ using System; using System.Diagnostics; using System.Runtime.CompilerServices; +using GlitchyEngine.Core; namespace GlitchyEngine; @@ -12,7 +13,8 @@ public class Log /// /// The severity of the log message. /// - internal enum LogLevel + [EngineClass("GlitchLog.LogLevel")] + internal enum LogLevel : byte { Trace = 0, Debug, diff --git a/ScriptCore/MouseButton.cs b/ScriptCore/MouseButton.cs index ae47acd..befb0a8 100644 --- a/ScriptCore/MouseButton.cs +++ b/ScriptCore/MouseButton.cs @@ -1,8 +1,11 @@ +using GlitchyEngine.Core; + namespace GlitchyEngine; /// /// An enum of all mouse buttons that can be queried using methods in . /// +[EngineClass("GlitchyEngine.Events.MouseButton")] public enum MouseButton : byte { None = 0, diff --git a/ScriptCore/ScriptCore.csproj b/ScriptCore/ScriptCore.csproj index 2badb55..4878077 100644 --- a/ScriptCore/ScriptCore.csproj +++ b/ScriptCore/ScriptCore.csproj @@ -16,6 +16,7 @@ true + $(ProjectDir)../generated/ScriptGlue.json @@ -27,4 +28,7 @@ + + + \ No newline at end of file diff --git a/ScriptCore/ScriptGlue.cs b/ScriptCore/ScriptGlue.cs index 595d1ff..5f8993f 100644 --- a/ScriptCore/ScriptGlue.cs +++ b/ScriptCore/ScriptGlue.cs @@ -25,7 +25,7 @@ namespace GlitchyEngine; [StructLayout(LayoutKind.Sequential)] internal unsafe partial struct EngineFunctions { - public delegate* unmanaged[Cdecl] Log_LogMessage; + public delegate* unmanaged[Cdecl] Log_LogMessage; } /// @@ -471,22 +471,32 @@ internal static partial class ScriptGlue #region Log - internal static unsafe void Log_LogMessage(Log.LogLevel logLevel, string message, string filePath, int line) - { - // unsafe - // { - // byte* mess = (byte*)Marshal.StringToCoTaskMemUTF8(message); - // - // fixed (char* messagePtr = message) - // fixed (char* filePathPtr = filePath) - // { - // _engineFunctions.Log_LogMessage(logLevel, messagePtr, filePathPtr, line); - // } - // - // Marshal.FreeCoTaskMem((IntPtr)mess); - // } - } - + // public unsafe static void Log_LogMessage(GlitchyEngine.Log.LogLevel logLevel, string messagePtr, string fileNamePtr, int lineNumber) + // { + // fixed (char* messagePtrConverted = messagePtr) { + // fixed (char* fileNamePtrConverted = fileNamePtr) { + // _engineFunctions.Log_LogMessage(logLevel, messagePtrConverted, fileNamePtrConverted, lineNumber); + // } + // } + // + // + // } + //internal static unsafe void Log_LogMessage(Log.LogLevel logLevel, string message, string filePath, int line) + //{ + // // unsafe + // // { + // // byte* mess = (byte*)Marshal.StringToCoTaskMemUTF8(message); + // // + // // fixed (char* messagePtr = message) + // // fixed (char* filePathPtr = filePath) + // // { + // // _engineFunctions.Log_LogMessage(logLevel, messagePtr, filePathPtr, line); + // // } + // // + // // Marshal.FreeCoTaskMem((IntPtr)mess); + // // } + //} + [MethodImpl(MethodImplOptions.InternalCall)] public static extern void Log_LogException(Exception exception); @@ -497,13 +507,13 @@ internal static partial class ScriptGlue [MethodImpl(MethodImplOptions.InternalCall)] internal static extern void Entity_Create(object scriptInstance, string? entityName, Type[]? componentTypes, out UUID entityId); - + [MethodImpl(MethodImplOptions.InternalCall)] internal static extern void Entity_Destroy(UUID entityId); [MethodImpl(MethodImplOptions.InternalCall)] internal static extern void Entity_CreateInstance(UUID entityId, out UUID newEntityId); - + [MethodImpl(MethodImplOptions.InternalCall)] internal static extern void Entity_AddComponent(UUID entityId, Type componentType); @@ -512,34 +522,34 @@ internal static partial class ScriptGlue [MethodImpl(MethodImplOptions.InternalCall)] internal static extern bool Entity_HasComponent(UUID entityId, Type componentType); - + [MethodImpl(MethodImplOptions.InternalCall)] internal static extern void Entity_RemoveComponent(UUID entityId, Type componentType); - + [MethodImpl(MethodImplOptions.InternalCall)] internal static extern void Entity_FindEntityWithName(string name, out UUID uuid); - + [MethodImpl(MethodImplOptions.InternalCall)] internal static extern void Entity_GetScriptInstance(UUID entityId, out object? instance); - + [MethodImpl(MethodImplOptions.InternalCall)] internal static extern object Entity_SetScript(UUID entityId, Type scriptType); [MethodImpl(MethodImplOptions.InternalCall)] internal static extern void Entity_RemoveScript(UUID entityId); - + [MethodImpl(MethodImplOptions.InternalCall)] public static extern string Entity_GetName(UUID entityId); - + [MethodImpl(MethodImplOptions.InternalCall)] public static extern string Entity_SetName(UUID entityId, string name); [MethodImpl(MethodImplOptions.InternalCall)] public static extern void Entity_GetEditorFlags(UUID uuid, out EditorFlags flags); - + [MethodImpl(MethodImplOptions.InternalCall)] public static extern void Entity_SetEditorFlags(UUID uuid, EditorFlags editorFlags); - + #endregion Entity #region TransformComponent @@ -555,31 +565,31 @@ internal static partial class ScriptGlue [MethodImpl(MethodImplOptions.InternalCall)] internal static extern void Transform_SetTranslation(UUID entityId, in float3 translation); - + [MethodImpl(MethodImplOptions.InternalCall)] internal static extern void Transform_GetWorldTranslation(UUID entityId, out float3 translation); [MethodImpl(MethodImplOptions.InternalCall)] internal static extern void Transform_SetWorldTranslation(UUID entityId, in float3 translation); - + [MethodImpl(MethodImplOptions.InternalCall)] internal static extern void Transform_GetRotation(UUID entityId, out Quaternion rotation); [MethodImpl(MethodImplOptions.InternalCall)] internal static extern void Transform_SetRotation(UUID entityId, in Quaternion rotation); - + [MethodImpl(MethodImplOptions.InternalCall)] internal static extern void Transform_GetRotationEuler(UUID entityId, out float3 rotationEuler); [MethodImpl(MethodImplOptions.InternalCall)] internal static extern void Transform_SetRotationEuler(UUID entityId, in float3 rotationEuler); - + [MethodImpl(MethodImplOptions.InternalCall)] internal static extern void Transform_GetRotationAxisAngle(UUID entityId, out RotationAxisAngle translation); [MethodImpl(MethodImplOptions.InternalCall)] internal static extern void Transform_SetRotationAxisAngle(UUID entityId, RotationAxisAngle translation); - + [MethodImpl(MethodImplOptions.InternalCall)] internal static extern void Transform_GetScale(UUID entityId, out float3 scale); @@ -589,40 +599,40 @@ internal static partial class ScriptGlue #endregion TransformComponent #region RigidBody2D - + [MethodImpl(MethodImplOptions.InternalCall)] internal static extern void Rigidbody2D_ApplyForce(UUID entityId, in float2 force, float2 point, bool wakeUp); [MethodImpl(MethodImplOptions.InternalCall)] internal static extern void Rigidbody2D_ApplyForceToCenter(UUID entityId, in float2 force, bool wakeUp); - + [MethodImpl(MethodImplOptions.InternalCall)] internal static extern void Rigidbody2D_SetPosition(UUID entityId, in float2 position); [MethodImpl(MethodImplOptions.InternalCall)] internal static extern void Rigidbody2D_GetPosition(UUID entityId, out float2 position); - + [MethodImpl(MethodImplOptions.InternalCall)] internal static extern void Rigidbody2D_SetRotation(UUID entityId, in float rotation); - + [MethodImpl(MethodImplOptions.InternalCall)] internal static extern void Rigidbody2D_GetRotation(UUID entityId, out float rotation); - + [MethodImpl(MethodImplOptions.InternalCall)] internal static extern void Rigidbody2D_SetLinearVelocity(UUID entityId, in float2 velocity); [MethodImpl(MethodImplOptions.InternalCall)] internal static extern void Rigidbody2D_GetLinearVelocity(UUID entityId, out float2 velocity); - + [MethodImpl(MethodImplOptions.InternalCall)] internal static extern void Rigidbody2D_SetAngularVelocity(UUID entityId, in float velocity); [MethodImpl(MethodImplOptions.InternalCall)] internal static extern void Rigidbody2D_GetAngularVelocity(UUID entityId, out float velocity); - + [MethodImpl(MethodImplOptions.InternalCall)] internal static extern void Rigidbody2D_GetBodyType(UUID entityId, out BodyType bodyType); - + [MethodImpl(MethodImplOptions.InternalCall)] internal static extern void Rigidbody2D_SetBodyType(UUID entityId, in BodyType bodyType); @@ -631,23 +641,23 @@ internal static partial class ScriptGlue [MethodImpl(MethodImplOptions.InternalCall)] internal static extern void Rigidbody2D_SetFixedRotation(UUID entityId, in bool isFixedRotation); - + [MethodImpl(MethodImplOptions.InternalCall)] internal static extern void Rigidbody2D_GetGravityScale(UUID entityId, out float gravityScale); - + [MethodImpl(MethodImplOptions.InternalCall)] internal static extern void Rigidbody2D_SetGravityScale(UUID entityId, in float gravityScale); - + #endregion RigidBody2D #region Camera - + [MethodImpl(MethodImplOptions.InternalCall)] internal static extern void Camera_GetProjectionType(UUID entityId, out ProjectionType projectionType); [MethodImpl(MethodImplOptions.InternalCall)] internal static extern void Camera_SetProjectionType(UUID entityId, in ProjectionType projectionType); - + [MethodImpl(MethodImplOptions.InternalCall)] internal static extern void Camera_GetPerspectiveFovY(UUID entityId, out float fovY); [MethodImpl(MethodImplOptions.InternalCall)] @@ -692,7 +702,7 @@ internal static partial class ScriptGlue #endregion #region Physics2D - + [MethodImpl(MethodImplOptions.InternalCall)] internal static extern void Physics2D_GetGravity(out float2 gravity); @@ -702,13 +712,13 @@ internal static partial class ScriptGlue #endregion Physics2D #region CircleRenderer - + [MethodImpl(MethodImplOptions.InternalCall)] internal static extern void CircleRenderer_GetColor(UUID entityId, out ColorRGBA color); [MethodImpl(MethodImplOptions.InternalCall)] internal static extern void CircleRenderer_SetColor(UUID entityId, ColorRGBA color); - + [MethodImpl(MethodImplOptions.InternalCall)] internal static extern void CircleRenderer_GetUvTransform(UUID entityId, out float4 uvTransform); @@ -776,7 +786,7 @@ internal static partial class ScriptGlue [MethodImpl(MethodImplOptions.InternalCall)] internal static extern void TextRenderer_SetFontSize(UUID uuid, float fontSize); - + #endregion #region MeshRenderer @@ -793,21 +803,21 @@ internal static partial class ScriptGlue #endregion #region Math - + [MethodImpl(MethodImplOptions.InternalCall)] internal static extern float modf_float(float x, out float integerPart); - + [MethodImpl(MethodImplOptions.InternalCall)] internal static extern float2 modf_float2(float2 x, out float2 integerPart); - + [MethodImpl(MethodImplOptions.InternalCall)] internal static extern float3 modf_float3(float3 x, out float3 integerPart); - + [MethodImpl(MethodImplOptions.InternalCall)] internal static extern float4 modf_float4(float4 x, out float4 integerPart); #endregion - + [MethodImpl(MethodImplOptions.InternalCall)] internal static extern void UUID_CreateNew(out UUID uuid); @@ -834,10 +844,10 @@ internal static partial class ScriptGlue [MethodImpl(MethodImplOptions.InternalCall)] internal static extern void Serialization_CreateObject(IntPtr currentContext, bool isStatic, string fullTypeName, out IntPtr context, out UUID id); - + [MethodImpl(MethodImplOptions.InternalCall)] public static extern unsafe void Serialization_DeserializeField(IntPtr internalContext, SerializationType expectedType, string fieldName, byte* value, out SerializationType actualType); - + [MethodImpl(MethodImplOptions.InternalCall)] public static extern void Serialization_GetObject(IntPtr internalContext, UUID id, out IntPtr objectContext); @@ -858,16 +868,8 @@ internal static partial class ScriptGlue #region Material - public enum ShaderVariableType : byte - { - Bool, - Float, - Int, - UInt - } - [MethodImpl(MethodImplOptions.InternalCall)] - internal static extern unsafe bool Material_SetVariable(UUID assetId, string variableName, ShaderVariableType elementType, int rows, int columns, int arrayLength, void* rawData, int dataLength); + internal static extern unsafe bool Material_SetVariable(UUID assetId, string variableName, Material.ShaderVariableType elementType, int rows, int columns, int arrayLength, void* rawData, int dataLength); [MethodImpl(MethodImplOptions.InternalCall)] internal static extern bool Material_ResetVariable(UUID assetId, string variableName); diff --git a/ScriptCore/ScriptGlue.json b/ScriptCore/ScriptGlue.json new file mode 100644 index 0000000..954ab08 --- /dev/null +++ b/ScriptCore/ScriptGlue.json @@ -0,0 +1,1681 @@ +[ + { + "name": "Log_LogMessage", + "return_type": "void", + "parameters": [ + { + "name": "logLevel", + "type": "GlitchLog.LogLevel : int8" + }, + { + "name": "messagePtr", + "type": "char16*" + }, + { + "name": "fileNamePtr", + "type": "char16*" + }, + { + "name": "lineNumber", + "type": "int" + } + ] + }, + { + "name": "Log_LogException", + "return_type": "void", + "parameters": [ + { + "name": "exception", + "type": "Mono.MonoException*" + }, + { + "name": "entityId", + "type": "GlitchyEngine.Core.UUID" + } + ] + }, + { + "name": "Input_IsKeyPressed", + "return_type": "bool", + "parameters": [ + { + "name": "key", + "type": "GlitchyEngine.Key : int32" + } + ] + }, + { + "name": "Input_IsKeyReleased", + "return_type": "bool", + "parameters": [ + { + "name": "key", + "type": "GlitchyEngine.Key : int32" + } + ] + }, + { + "name": "Input_IsKeyToggled", + "return_type": "bool", + "parameters": [ + { + "name": "key", + "type": "GlitchyEngine.Key : int32" + } + ] + }, + { + "name": "Input_IsKeyPressing", + "return_type": "bool", + "parameters": [ + { + "name": "key", + "type": "GlitchyEngine.Key : int32" + } + ] + }, + { + "name": "Input_IsKeyReleasing", + "return_type": "bool", + "parameters": [ + { + "name": "key", + "type": "GlitchyEngine.Key : int32" + } + ] + }, + { + "name": "Input_IsMouseButtonPressed", + "return_type": "bool", + "parameters": [ + { + "name": "mouseButton", + "type": "GlitchyEngine.Events.MouseButton : int8" + } + ] + }, + { + "name": "Input_IsMouseButtonReleased", + "return_type": "bool", + "parameters": [ + { + "name": "mouseButton", + "type": "GlitchyEngine.Events.MouseButton : int8" + } + ] + }, + { + "name": "Input_IsMouseButtonPressing", + "return_type": "bool", + "parameters": [ + { + "name": "mouseButton", + "type": "GlitchyEngine.Events.MouseButton : int8" + } + ] + }, + { + "name": "Input_IsMouseButtonReleasing", + "return_type": "bool", + "parameters": [ + { + "name": "mouseButton", + "type": "GlitchyEngine.Events.MouseButton : int8" + } + ] + }, + { + "name": "Entity_Create", + "return_type": "void", + "parameters": [ + { + "name": "scriptInstance", + "type": "Mono.MonoObject*" + }, + { + "name": "monoEntityName", + "type": "Mono.MonoString*" + }, + { + "name": "componentTypes", + "type": "Mono.MonoArray*" + }, + { + "name": "entityId", + "type": "out GlitchyEngine.Core.UUID" + } + ] + }, + { + "name": "Entity_Destroy", + "return_type": "void", + "parameters": [ + { + "name": "entityId", + "type": "GlitchyEngine.Core.UUID" + } + ] + }, + { + "name": "Entity_CreateInstance", + "return_type": "void", + "parameters": [ + { + "name": "entityId", + "type": "GlitchyEngine.Core.UUID" + }, + { + "name": "newEntityId", + "type": "out GlitchyEngine.Core.UUID" + } + ] + }, + { + "name": "Entity_AddComponents", + "return_type": "void", + "parameters": [ + { + "name": "entityId", + "type": "GlitchyEngine.Core.UUID" + }, + { + "name": "componentTypes", + "type": "Mono.MonoArray*" + } + ] + }, + { + "name": "Entity_AddComponent", + "return_type": "void", + "parameters": [ + { + "name": "entityId", + "type": "GlitchyEngine.Core.UUID" + }, + { + "name": "componentType", + "type": "Mono.MonoReflectionType*" + } + ] + }, + { + "name": "Entity_HasComponent", + "return_type": "bool", + "parameters": [ + { + "name": "entityId", + "type": "GlitchyEngine.Core.UUID" + }, + { + "name": "componentType", + "type": "Mono.MonoReflectionType*" + } + ] + }, + { + "name": "Entity_RemoveComponent", + "return_type": "void", + "parameters": [ + { + "name": "entityId", + "type": "GlitchyEngine.Core.UUID" + }, + { + "name": "componentType", + "type": "Mono.MonoReflectionType*" + } + ] + }, + { + "name": "Entity_FindEntityWithName", + "return_type": "void", + "parameters": [ + { + "name": "monoName", + "type": "Mono.MonoString*" + }, + { + "name": "outUuid", + "type": "GlitchyEngine.Core.UUID*" + } + ] + }, + { + "name": "Entity_GetScriptInstance", + "return_type": "void", + "parameters": [ + { + "name": "entityId", + "type": "GlitchyEngine.Core.UUID" + }, + { + "name": "instance", + "type": "out Mono.MonoObject*" + } + ] + }, + { + "name": "Entity_SetScript", + "return_type": "Mono.MonoObject*", + "parameters": [ + { + "name": "entityId", + "type": "GlitchyEngine.Core.UUID" + }, + { + "name": "scriptType", + "type": "Mono.MonoReflectionType*" + } + ] + }, + { + "name": "Entity_RemoveScript", + "return_type": "void", + "parameters": [ + { + "name": "entityId", + "type": "GlitchyEngine.Core.UUID" + } + ] + }, + { + "name": "Entity_GetName", + "return_type": "Mono.MonoString*", + "parameters": [ + { + "name": "entityId", + "type": "GlitchyEngine.Core.UUID" + } + ] + }, + { + "name": "Entity_SetName", + "return_type": "void", + "parameters": [ + { + "name": "entityId", + "type": "GlitchyEngine.Core.UUID" + }, + { + "name": "name", + "type": "Mono.MonoString*" + } + ] + }, + { + "name": "Entity_GetEditorFlags", + "return_type": "void", + "parameters": [ + { + "name": "entityId", + "type": "GlitchyEngine.Core.UUID" + }, + { + "name": "editorFlags", + "type": "out GlitchyEngine.Editor.EditorFlags" + } + ] + }, + { + "name": "Entity_SetEditorFlags", + "return_type": "void", + "parameters": [ + { + "name": "entityId", + "type": "GlitchyEngine.Core.UUID" + }, + { + "name": "editorFlags", + "type": "GlitchyEngine.Editor.EditorFlags : int8" + } + ] + }, + { + "name": "Transform_GetParent", + "return_type": "void", + "parameters": [ + { + "name": "entityId", + "type": "GlitchyEngine.Core.UUID" + }, + { + "name": "parentId", + "type": "out GlitchyEngine.Core.UUID" + } + ] + }, + { + "name": "Transform_SetParent", + "return_type": "void", + "parameters": [ + { + "name": "entityId", + "type": "GlitchyEngine.Core.UUID" + }, + { + "name": "parentId", + "type": "in GlitchyEngine.Core.UUID" + } + ] + }, + { + "name": "Transform_GetTranslation", + "return_type": "void", + "parameters": [ + { + "name": "entityId", + "type": "GlitchyEngine.Core.UUID" + }, + { + "name": "translation", + "type": "out GlitchyEngine.Math.float3" + } + ] + }, + { + "name": "Transform_SetTranslation", + "return_type": "void", + "parameters": [ + { + "name": "entityId", + "type": "GlitchyEngine.Core.UUID" + }, + { + "name": "translation", + "type": "in GlitchyEngine.Math.float3" + } + ] + }, + { + "name": "Transform_GetWorldTranslation", + "return_type": "void", + "parameters": [ + { + "name": "entityId", + "type": "GlitchyEngine.Core.UUID" + }, + { + "name": "translationWorld", + "type": "out GlitchyEngine.Math.float3" + } + ] + }, + { + "name": "Transform_SetWorldTranslation", + "return_type": "void", + "parameters": [ + { + "name": "entityId", + "type": "GlitchyEngine.Core.UUID" + }, + { + "name": "translation", + "type": "in GlitchyEngine.Math.float3" + } + ] + }, + { + "name": "Transform_TransformPointToWorld", + "return_type": "void", + "parameters": [ + { + "name": "entityId", + "type": "GlitchyEngine.Core.UUID" + }, + { + "name": "point", + "type": "GlitchyEngine.Math.float3" + }, + { + "name": "pointWorld", + "type": "out GlitchyEngine.Math.float3" + } + ] + }, + { + "name": "Transform_GetRotation", + "return_type": "void", + "parameters": [ + { + "name": "entityId", + "type": "GlitchyEngine.Core.UUID" + }, + { + "name": "rotation", + "type": "out GlitchyEngine.Math.Quaternion" + } + ] + }, + { + "name": "Transform_SetRotation", + "return_type": "void", + "parameters": [ + { + "name": "entityId", + "type": "GlitchyEngine.Core.UUID" + }, + { + "name": "rotation", + "type": "in GlitchyEngine.Math.Quaternion" + } + ] + }, + { + "name": "Transform_GetRotationEuler", + "return_type": "void", + "parameters": [ + { + "name": "entityId", + "type": "GlitchyEngine.Core.UUID" + }, + { + "name": "rotationEuler", + "type": "out GlitchyEngine.Math.float3" + } + ] + }, + { + "name": "Transform_SetRotationEuler", + "return_type": "void", + "parameters": [ + { + "name": "entityId", + "type": "GlitchyEngine.Core.UUID" + }, + { + "name": "rotationEuler", + "type": "in GlitchyEngine.Math.float3" + } + ] + }, + { + "name": "Transform_GetRotationAxisAngle", + "return_type": "void", + "parameters": [ + { + "name": "entityId", + "type": "GlitchyEngine.Core.UUID" + }, + { + "name": "rotationAxisAngle", + "type": "out GlitchyEngine.Scripting.ScriptGlue.AxisAngle" + } + ] + }, + { + "name": "Transform_SetRotationAxisAngle", + "return_type": "void", + "parameters": [ + { + "name": "entityId", + "type": "GlitchyEngine.Core.UUID" + }, + { + "name": "rotationAxisAngle", + "type": "GlitchyEngine.Scripting.ScriptGlue.AxisAngle" + } + ] + }, + { + "name": "Transform_GetScale", + "return_type": "void", + "parameters": [ + { + "name": "entityId", + "type": "GlitchyEngine.Core.UUID" + }, + { + "name": "scale", + "type": "out GlitchyEngine.Math.float3" + } + ] + }, + { + "name": "Transform_SetScale", + "return_type": "void", + "parameters": [ + { + "name": "entityId", + "type": "GlitchyEngine.Core.UUID" + }, + { + "name": "scale", + "type": "GlitchyEngine.Math.float3" + } + ] + }, + { + "name": "Rigidbody2D_ApplyForce", + "return_type": "void", + "parameters": [ + { + "name": "entityId", + "type": "GlitchyEngine.Core.UUID" + }, + { + "name": "force", + "type": "in GlitchyEngine.Math.float2" + }, + { + "name": "point", + "type": "in GlitchyEngine.Math.float2" + }, + { + "name": "wakeUp", + "type": "bool" + } + ] + }, + { + "name": "Rigidbody2D_ApplyForceToCenter", + "return_type": "void", + "parameters": [ + { + "name": "entityId", + "type": "GlitchyEngine.Core.UUID" + }, + { + "name": "force", + "type": "in GlitchyEngine.Math.float2" + }, + { + "name": "wakeUp", + "type": "bool" + } + ] + }, + { + "name": "Rigidbody2D_SetPosition", + "return_type": "void", + "parameters": [ + { + "name": "entityId", + "type": "GlitchyEngine.Core.UUID" + }, + { + "name": "position", + "type": "in GlitchyEngine.Math.float2" + } + ] + }, + { + "name": "Rigidbody2D_GetPosition", + "return_type": "void", + "parameters": [ + { + "name": "entityId", + "type": "GlitchyEngine.Core.UUID" + }, + { + "name": "position", + "type": "out GlitchyEngine.Math.float2" + } + ] + }, + { + "name": "Rigidbody2D_SetRotation", + "return_type": "void", + "parameters": [ + { + "name": "entityId", + "type": "GlitchyEngine.Core.UUID" + }, + { + "name": "rotation", + "type": "in float" + } + ] + }, + { + "name": "Rigidbody2D_GetRotation", + "return_type": "void", + "parameters": [ + { + "name": "entityId", + "type": "GlitchyEngine.Core.UUID" + }, + { + "name": "rotation", + "type": "out float" + } + ] + }, + { + "name": "Rigidbody2D_GetLinearVelocity", + "return_type": "void", + "parameters": [ + { + "name": "entityId", + "type": "GlitchyEngine.Core.UUID" + }, + { + "name": "velocity", + "type": "out GlitchyEngine.Math.float2" + } + ] + }, + { + "name": "Rigidbody2D_SetLinearVelocity", + "return_type": "void", + "parameters": [ + { + "name": "entityId", + "type": "GlitchyEngine.Core.UUID" + }, + { + "name": "velocity", + "type": "in GlitchyEngine.Math.float2" + } + ] + }, + { + "name": "Rigidbody2D_GetAngularVelocity", + "return_type": "void", + "parameters": [ + { + "name": "entityId", + "type": "GlitchyEngine.Core.UUID" + }, + { + "name": "velocity", + "type": "out float" + } + ] + }, + { + "name": "Rigidbody2D_SetAngularVelocity", + "return_type": "void", + "parameters": [ + { + "name": "entityId", + "type": "GlitchyEngine.Core.UUID" + }, + { + "name": "velocity", + "type": "in float" + } + ] + }, + { + "name": "Rigidbody2D_GetBodyType", + "return_type": "void", + "parameters": [ + { + "name": "entityId", + "type": "GlitchyEngine.Core.UUID" + }, + { + "name": "bodyType", + "type": "out GlitchyEngine.World.Rigidbody2DComponent.BodyType" + } + ] + }, + { + "name": "Rigidbody2D_SetBodyType", + "return_type": "void", + "parameters": [ + { + "name": "entityId", + "type": "GlitchyEngine.Core.UUID" + }, + { + "name": "bodyType", + "type": "in GlitchyEngine.World.Rigidbody2DComponent.BodyType" + } + ] + }, + { + "name": "Rigidbody2D_IsFixedRotation", + "return_type": "void", + "parameters": [ + { + "name": "entityId", + "type": "GlitchyEngine.Core.UUID" + }, + { + "name": "isFixedRotation", + "type": "out bool" + } + ] + }, + { + "name": "Rigidbody2D_SetFixedRotation", + "return_type": "void", + "parameters": [ + { + "name": "entityId", + "type": "GlitchyEngine.Core.UUID" + }, + { + "name": "isFixedRotation", + "type": "in bool" + } + ] + }, + { + "name": "Rigidbody2D_GetGravityScale", + "return_type": "void", + "parameters": [ + { + "name": "entityId", + "type": "GlitchyEngine.Core.UUID" + }, + { + "name": "gravityScale", + "type": "out float" + } + ] + }, + { + "name": "Rigidbody2D_SetGravityScale", + "return_type": "void", + "parameters": [ + { + "name": "entityId", + "type": "GlitchyEngine.Core.UUID" + }, + { + "name": "gravityScale", + "type": "in float" + } + ] + }, + { + "name": "Camera_GetProjectionType", + "return_type": "void", + "parameters": [ + { + "name": "entityId", + "type": "GlitchyEngine.Core.UUID" + }, + { + "name": "projectionType", + "type": "out GlitchyEngine.World.SceneCamera.ProjectionType" + } + ] + }, + { + "name": "Camera_SetProjectionType", + "return_type": "void", + "parameters": [ + { + "name": "entityId", + "type": "GlitchyEngine.Core.UUID" + }, + { + "name": "projectionType", + "type": "in GlitchyEngine.World.SceneCamera.ProjectionType" + } + ] + }, + { + "name": "Camera_GetPerspectiveFovY", + "return_type": "void", + "parameters": [ + { + "name": "entityId", + "type": "GlitchyEngine.Core.UUID" + }, + { + "name": "fovY", + "type": "out float" + } + ] + }, + { + "name": "Camera_SetPerspectiveFovY", + "return_type": "void", + "parameters": [ + { + "name": "entityId", + "type": "GlitchyEngine.Core.UUID" + }, + { + "name": "fovY", + "type": "float" + } + ] + }, + { + "name": "Camera_GetPerspectiveNearPlane", + "return_type": "void", + "parameters": [ + { + "name": "entityId", + "type": "GlitchyEngine.Core.UUID" + }, + { + "name": "nearPlane", + "type": "out float" + } + ] + }, + { + "name": "Camera_SetPerspectiveNearPlane", + "return_type": "void", + "parameters": [ + { + "name": "entityId", + "type": "GlitchyEngine.Core.UUID" + }, + { + "name": "nearPlane", + "type": "float" + } + ] + }, + { + "name": "Camera_GetPerspectiveFarPlane", + "return_type": "void", + "parameters": [ + { + "name": "entityId", + "type": "GlitchyEngine.Core.UUID" + }, + { + "name": "farPlane", + "type": "out float" + } + ] + }, + { + "name": "Camera_SetPerspectiveFarPlane", + "return_type": "void", + "parameters": [ + { + "name": "entityId", + "type": "GlitchyEngine.Core.UUID" + }, + { + "name": "farPlane", + "type": "float" + } + ] + }, + { + "name": "Camera_GetOrthographicHeight", + "return_type": "void", + "parameters": [ + { + "name": "entityId", + "type": "GlitchyEngine.Core.UUID" + }, + { + "name": "height", + "type": "out float" + } + ] + }, + { + "name": "Camera_SetOrthographicHeight", + "return_type": "void", + "parameters": [ + { + "name": "entityId", + "type": "GlitchyEngine.Core.UUID" + }, + { + "name": "height", + "type": "float" + } + ] + }, + { + "name": "Camera_SetOrthographicNearPlane", + "return_type": "void", + "parameters": [ + { + "name": "entityId", + "type": "GlitchyEngine.Core.UUID" + }, + { + "name": "nearPlane", + "type": "float" + } + ] + }, + { + "name": "Camera_GetOrthographicNearPlane", + "return_type": "void", + "parameters": [ + { + "name": "entityId", + "type": "GlitchyEngine.Core.UUID" + }, + { + "name": "nearPlane", + "type": "out float" + } + ] + }, + { + "name": "Camera_SetOrthographicFarPlane", + "return_type": "void", + "parameters": [ + { + "name": "entityId", + "type": "GlitchyEngine.Core.UUID" + }, + { + "name": "farPlane", + "type": "float" + } + ] + }, + { + "name": "Camera_GetOrthographicFarPlane", + "return_type": "void", + "parameters": [ + { + "name": "entityId", + "type": "GlitchyEngine.Core.UUID" + }, + { + "name": "farPlane", + "type": "out float" + } + ] + }, + { + "name": "Camera_SetAspectRatio", + "return_type": "void", + "parameters": [ + { + "name": "entityId", + "type": "GlitchyEngine.Core.UUID" + }, + { + "name": "aspectRatio", + "type": "float" + } + ] + }, + { + "name": "Camera_GetAspectRatio", + "return_type": "void", + "parameters": [ + { + "name": "entityId", + "type": "GlitchyEngine.Core.UUID" + }, + { + "name": "aspectRatio", + "type": "out float" + } + ] + }, + { + "name": "Camera_SetFixedAspectRatio", + "return_type": "void", + "parameters": [ + { + "name": "entityId", + "type": "GlitchyEngine.Core.UUID" + }, + { + "name": "fixedAspectRatio", + "type": "bool" + } + ] + }, + { + "name": "Camera_GetFixedAspectRatio", + "return_type": "void", + "parameters": [ + { + "name": "entityId", + "type": "GlitchyEngine.Core.UUID" + }, + { + "name": "fixedAspectRatio", + "type": "out bool" + } + ] + }, + { + "name": "Physics2D_GetGravity", + "return_type": "void", + "parameters": [ + { + "name": "gravity", + "type": "out GlitchyEngine.Math.float2" + } + ] + }, + { + "name": "Physics2D_SetGravity", + "return_type": "void", + "parameters": [ + { + "name": "gravity", + "type": "in GlitchyEngine.Math.float2" + } + ] + }, + { + "name": "CircleRenderer_GetColor", + "return_type": "void", + "parameters": [ + { + "name": "entityId", + "type": "GlitchyEngine.Core.UUID" + }, + { + "name": "color", + "type": "out GlitchyEngine.Math.ColorRGBA" + } + ] + }, + { + "name": "CircleRenderer_SetColor", + "return_type": "void", + "parameters": [ + { + "name": "entityId", + "type": "GlitchyEngine.Core.UUID" + }, + { + "name": "color", + "type": "GlitchyEngine.Math.ColorRGBA" + } + ] + }, + { + "name": "CircleRenderer_GetUvTransform", + "return_type": "void", + "parameters": [ + { + "name": "entityId", + "type": "GlitchyEngine.Core.UUID" + }, + { + "name": "uvTransform", + "type": "out GlitchyEngine.Math.float4" + } + ] + }, + { + "name": "CircleRenderer_SetUvTransform", + "return_type": "void", + "parameters": [ + { + "name": "entityId", + "type": "GlitchyEngine.Core.UUID" + }, + { + "name": "uvTransform", + "type": "GlitchyEngine.Math.float4" + } + ] + }, + { + "name": "CircleRenderer_GetInnerRadius", + "return_type": "void", + "parameters": [ + { + "name": "entityId", + "type": "GlitchyEngine.Core.UUID" + }, + { + "name": "innerRadius", + "type": "out float" + } + ] + }, + { + "name": "CircleRenderer_SetInnerRadius", + "return_type": "void", + "parameters": [ + { + "name": "entityId", + "type": "GlitchyEngine.Core.UUID" + }, + { + "name": "innerRadius", + "type": "float" + } + ] + }, + { + "name": "SpriteRenderer_GetColor", + "return_type": "void", + "parameters": [ + { + "name": "entityId", + "type": "GlitchyEngine.Core.UUID" + }, + { + "name": "color", + "type": "out GlitchyEngine.Math.ColorRGBA" + } + ] + }, + { + "name": "SpriteRenderer_SetColor", + "return_type": "void", + "parameters": [ + { + "name": "entityId", + "type": "GlitchyEngine.Core.UUID" + }, + { + "name": "color", + "type": "GlitchyEngine.Math.ColorRGBA" + } + ] + }, + { + "name": "SpriteRenderer_GetUvTransform", + "return_type": "void", + "parameters": [ + { + "name": "entityId", + "type": "GlitchyEngine.Core.UUID" + }, + { + "name": "uvTransform", + "type": "out GlitchyEngine.Math.float4" + } + ] + }, + { + "name": "SpriteRenderer_SetUvTransform", + "return_type": "void", + "parameters": [ + { + "name": "entityId", + "type": "GlitchyEngine.Core.UUID" + }, + { + "name": "uvTransform", + "type": "GlitchyEngine.Math.float4" + } + ] + }, + { + "name": "SpriteRenderer_GetMaterial", + "return_type": "void", + "parameters": [ + { + "name": "entityId", + "type": "GlitchyEngine.Core.UUID" + }, + { + "name": "assetId", + "type": "out GlitchyEngine.Content.AssetHandle" + } + ] + }, + { + "name": "SpriteRenderer_SetMaterial", + "return_type": "void", + "parameters": [ + { + "name": "entityId", + "type": "GlitchyEngine.Core.UUID" + }, + { + "name": "assetId", + "type": "GlitchyEngine.Content.AssetHandle" + } + ] + }, + { + "name": "TextRenderer_GetIsRichText", + "return_type": "bool", + "parameters": [ + { + "name": "entityId", + "type": "GlitchyEngine.Core.UUID" + } + ] + }, + { + "name": "TextRenderer_SetIsRichText", + "return_type": "void", + "parameters": [ + { + "name": "entityId", + "type": "GlitchyEngine.Core.UUID" + }, + { + "name": "isRichText", + "type": "bool" + } + ] + }, + { + "name": "TextRenderer_GetText", + "return_type": "void", + "parameters": [ + { + "name": "entityId", + "type": "GlitchyEngine.Core.UUID" + }, + { + "name": "text", + "type": "out Mono.MonoString*" + } + ] + }, + { + "name": "TextRenderer_SetText", + "return_type": "void", + "parameters": [ + { + "name": "entityId", + "type": "GlitchyEngine.Core.UUID" + }, + { + "name": "text", + "type": "Mono.MonoString*" + } + ] + }, + { + "name": "TextRenderer_GetColor", + "return_type": "void", + "parameters": [ + { + "name": "entityId", + "type": "GlitchyEngine.Core.UUID" + }, + { + "name": "color", + "type": "out GlitchyEngine.Math.ColorRGBA" + } + ] + }, + { + "name": "TextRenderer_SetColor", + "return_type": "void", + "parameters": [ + { + "name": "entityId", + "type": "GlitchyEngine.Core.UUID" + }, + { + "name": "color", + "type": "GlitchyEngine.Math.ColorRGBA" + } + ] + }, + { + "name": "TextRenderer_GetHorizontalAlignment", + "return_type": "void", + "parameters": [ + { + "name": "entityId", + "type": "GlitchyEngine.Core.UUID" + }, + { + "name": "horizontalAlignment", + "type": "out GlitchyEngine.Renderer.Text.FontRenderer.HorizontalTextAlignment" + } + ] + }, + { + "name": "TextRenderer_SetHorizontalAlignment", + "return_type": "void", + "parameters": [ + { + "name": "entityId", + "type": "GlitchyEngine.Core.UUID" + }, + { + "name": "horizontalAlignment", + "type": "GlitchyEngine.Renderer.Text.FontRenderer.HorizontalTextAlignment : int8" + } + ] + }, + { + "name": "TextRenderer_GetFontSize", + "return_type": "void", + "parameters": [ + { + "name": "entityId", + "type": "GlitchyEngine.Core.UUID" + }, + { + "name": "fontSize", + "type": "out float" + } + ] + }, + { + "name": "TextRenderer_SetFontSize", + "return_type": "void", + "parameters": [ + { + "name": "entityId", + "type": "GlitchyEngine.Core.UUID" + }, + { + "name": "fontSize", + "type": "float" + } + ] + }, + { + "name": "MeshRenderer_GetMaterial", + "return_type": "void", + "parameters": [ + { + "name": "entityId", + "type": "GlitchyEngine.Core.UUID" + }, + { + "name": "assetId", + "type": "out GlitchyEngine.Content.AssetHandle" + } + ] + }, + { + "name": "MeshRenderer_GetSharedMaterial", + "return_type": "void", + "parameters": [ + { + "name": "entityId", + "type": "GlitchyEngine.Core.UUID" + }, + { + "name": "assetId", + "type": "out GlitchyEngine.Content.AssetHandle" + } + ] + }, + { + "name": "MeshRenderer_SetMaterial", + "return_type": "void", + "parameters": [ + { + "name": "entityId", + "type": "GlitchyEngine.Core.UUID" + }, + { + "name": "assetId", + "type": "GlitchyEngine.Content.AssetHandle" + } + ] + }, + { + "name": "UUID_Create", + "return_type": "void", + "parameters": [ + { + "name": "id", + "type": "out GlitchyEngine.Core.UUID" + } + ] + }, + { + "name": "Application_IsEditor", + "return_type": "bool", + "parameters": [ + ] + }, + { + "name": "Application_IsPlayer", + "return_type": "bool", + "parameters": [ + ] + }, + { + "name": "Application_IsInEditMode", + "return_type": "bool", + "parameters": [ + ] + }, + { + "name": "Application_IsInPlayMode", + "return_type": "bool", + "parameters": [ + ] + }, + { + "name": "Serialization_SerializeField", + "return_type": "void", + "parameters": [ + { + "name": "serializationContext", + "type": "void*" + }, + { + "name": "type", + "type": "GlitchyEngine.Serialization.SerializationType : uint32" + }, + { + "name": "nameObject", + "type": "Mono.MonoString*" + }, + { + "name": "valueObject", + "type": "Mono.MonoObject*" + }, + { + "name": "fullTypeName", + "type": "Mono.MonoString*" + } + ] + }, + { + "name": "Serialization_CreateObject", + "return_type": "void", + "parameters": [ + { + "name": "currentContext", + "type": "void*" + }, + { + "name": "isStatic", + "type": "bool" + }, + { + "name": "typeName", + "type": "Mono.MonoString*" + }, + { + "name": "newContext", + "type": "out void*" + }, + { + "name": "newId", + "type": "out GlitchyEngine.Core.UUID" + } + ] + }, + { + "name": "Serialization_DeserializeField", + "return_type": "void", + "parameters": [ + { + "name": "internalContext", + "type": "void*" + }, + { + "name": "expectedType", + "type": "GlitchyEngine.Serialization.SerializationType : uint32" + }, + { + "name": "fieldName", + "type": "Mono.MonoString*" + }, + { + "name": "target", + "type": "uint8*" + }, + { + "name": "actualType", + "type": "out GlitchyEngine.Serialization.SerializationType" + } + ] + }, + { + "name": "Serialization_GetObject", + "return_type": "void", + "parameters": [ + { + "name": "internalContext", + "type": "void*" + }, + { + "name": "id", + "type": "GlitchyEngine.Core.UUID" + }, + { + "name": "objectContext", + "type": "out void*" + } + ] + }, + { + "name": "Serialization_GetObjectTypeName", + "return_type": "void", + "parameters": [ + { + "name": "internalContext", + "type": "void*" + }, + { + "name": "fullTypeName", + "type": "out Mono.MonoString*" + } + ] + }, + { + "name": "Asset_GetIdentifier", + "return_type": "void", + "parameters": [ + { + "name": "assetId", + "type": "GlitchyEngine.Core.UUID" + }, + { + "name": "text", + "type": "out Mono.MonoString*" + } + ] + }, + { + "name": "Asset_SetIdentifier", + "return_type": "void", + "parameters": [ + { + "name": "assetId", + "type": "GlitchyEngine.Core.UUID" + }, + { + "name": "text", + "type": "Mono.MonoString*" + } + ] + }, + { + "name": "Material_SetVariable", + "return_type": "void", + "parameters": [ + { + "name": "assetHandle", + "type": "GlitchyEngine.Content.AssetHandle" + }, + { + "name": "managedVariableName", + "type": "Mono.MonoString*" + }, + { + "name": "elementType", + "type": "GlitchyEngine.Renderer.ShaderVariableType : int8" + }, + { + "name": "rows", + "type": "int32" + }, + { + "name": "columns", + "type": "int32" + }, + { + "name": "arrayLength", + "type": "int32" + }, + { + "name": "rawData", + "type": "uint8*" + }, + { + "name": "dataLength", + "type": "int32" + } + ] + }, + { + "name": "Material_ResetVariable", + "return_type": "void", + "parameters": [ + { + "name": "assetHandle", + "type": "GlitchyEngine.Content.AssetHandle" + }, + { + "name": "managedVariableName", + "type": "Mono.MonoString*" + } + ] + }, + { + "name": "Material_SetTexture", + "return_type": "void", + "parameters": [ + { + "name": "materialHandle", + "type": "GlitchyEngine.Content.AssetHandle" + }, + { + "name": "managedVariableName", + "type": "Mono.MonoString*" + }, + { + "name": "textureHandle", + "type": "GlitchyEngine.Content.AssetHandle" + } + ] + }, + { + "name": "Material_GetTexture", + "return_type": "void", + "parameters": [ + { + "name": "materialHandle", + "type": "GlitchyEngine.Content.AssetHandle" + }, + { + "name": "managedVariableName", + "type": "Mono.MonoString*" + }, + { + "name": "textureHandle", + "type": "out GlitchyEngine.Content.AssetHandle" + } + ] + }, + { + "name": "Material_ResetTexture", + "return_type": "void", + "parameters": [ + { + "name": "materialHandle", + "type": "GlitchyEngine.Content.AssetHandle" + }, + { + "name": "managedVariableName", + "type": "Mono.MonoString*" + } + ] + }, + { + "name": "ImGuiExtension_ListElementGrabber", + "return_type": "void", + "parameters": [ + ] + },] \ No newline at end of file diff --git a/ScriptCoreGenerator/ScriptCoreGenerator.csproj b/ScriptCoreGenerator/ScriptCoreGenerator.csproj index a609f1d..fce0b7f 100644 --- a/ScriptCoreGenerator/ScriptCoreGenerator.csproj +++ b/ScriptCoreGenerator/ScriptCoreGenerator.csproj @@ -4,13 +4,18 @@ netstandard2.0 latest true - true + false + true enable + + + + diff --git a/ScriptCoreGenerator/ScriptGlueGenerator.cs b/ScriptCoreGenerator/ScriptGlueGenerator.cs new file mode 100644 index 0000000..e838542 --- /dev/null +++ b/ScriptCoreGenerator/ScriptGlueGenerator.cs @@ -0,0 +1,417 @@ +using System; +using System.Collections.Generic; +using System.Collections.Immutable; +using System.IO; +using System.Linq; +using System.Reflection.Metadata; +using System.Text; +using System.Text.Json; +using System.Text.Json.Serialization; +using System.Threading; +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp.Syntax; + +namespace ScriptCoreGenerator; + +internal class GlueMethod +{ + [JsonPropertyName("name")] + public string Name { get; set; } + [JsonPropertyName("return_type")] + public string ReturnType { get; set; } + [JsonPropertyName("parameters")] + public List Parameters { get; set; } + + internal class Parameter + { + [JsonPropertyName("name")] + public string Name { get; set; } + [JsonPropertyName("type")] + public string Type { get; set; } + } +} + +[Generator] +public class ScriptGlueGenerator : IIncrementalGenerator +{ + public class GeneratorInput + { + public ImmutableArray TypeMappings; + public ImmutableArray GlueFunctionDefinitions; + public ImmutableArray ExistingScriptGlueClasses; + public ImmutableArray ExistingEngineFunctionStructs; + } + + public void Initialize(IncrementalGeneratorInitializationContext context) + { + var mappedTypes = context.SyntaxProvider + .CreateSyntaxProvider( + CouldBeMappedType, GetTypeOrNull) + .Where(type => type is not null) + .Collect(); + + var manualScriptGlueWrappers = context.SyntaxProvider + .CreateSyntaxProvider( + IsScriptGlueClass, GetSymbol) + .Where(type => type is not null) + .SelectMany((type, _) => type!.MemberNames) + .Collect(); + + var manualEngineFunctions = context.SyntaxProvider + .CreateSyntaxProvider( + IsEngineFunctionsStruct, GetSymbol) + .Where(type => type is not null) + .SelectMany((type, _) => type!.MemberNames) + .Collect(); + + var glueFunctions = context.AdditionalTextsProvider + .Where(text => text.Path.EndsWith("ScriptGlue.json", + StringComparison.OrdinalIgnoreCase)) + .Select((text, token) => text.GetText(token)?.ToString()) + .Where(text => text is not null)! + .Collect(); + + // Kombiniere zu einem sauberen Record + var combinedProvider = mappedTypes + .Combine(manualScriptGlueWrappers) + .Combine(manualEngineFunctions) + .Combine(glueFunctions) + .Select((input, _) => new GeneratorInput{ + TypeMappings = input.Left.Left.Left, + ExistingScriptGlueClasses = input.Left.Left.Right, + ExistingEngineFunctionStructs = input.Left.Right, + GlueFunctionDefinitions = input.Right + }); + + context.RegisterSourceOutput(combinedProvider, GenerateCode); + } + + public class MappedType + { + public string BeefTypeName; + public string? UnderlyingEnumTypeName; + public bool HasUnderlyingType => UnderlyingEnumTypeName is not null; + + private string _cSharpTypeName; + private string _cSharpWrapperType; + + public MappedType? CSharpUnderlyingEnumType; + + public string? WrapperConvertInput; + public string? WrapperCleanupInput; + + public string? ReturnValueConversion = "return returnValue;"; + + public string CSharpWrapperType + { + get => _cSharpWrapperType ?? CSharpTypeName; + set => _cSharpWrapperType = value; + } + + public string CSharpTypeName + { + get => _cSharpTypeName ?? BeefTypeName; + set => _cSharpTypeName = value; + } + } + + private static MappedType DecodeType(string beefType, Dictionary beefTypeToMappedType) + { + if (beefTypeToMappedType.TryGetValue(beefType, out MappedType? mappedType)) + { + return mappedType; + } + + int colonIndex = beefType.IndexOf(':'); + bool isEnum = colonIndex != -1; + + string beefTypeName = beefType; + string? underlyingEnumType = null; + + if (isEnum) + { + beefTypeName = beefType.Substring(0, colonIndex).Trim(); + underlyingEnumType = beefType.Substring(colonIndex + 1).Trim(); + + if (beefTypeToMappedType.TryGetValue(beefTypeName, out mappedType)) + { + if (mappedType.UnderlyingEnumTypeName is null) + { + mappedType.UnderlyingEnumTypeName = underlyingEnumType; + mappedType.CSharpUnderlyingEnumType = DecodeType(underlyingEnumType, beefTypeToMappedType); + } + + return mappedType; + } + } + + MappedType newMapping = new MappedType() + { + BeefTypeName = beefTypeName, + UnderlyingEnumTypeName = underlyingEnumType, + CSharpUnderlyingEnumType = underlyingEnumType == null ? null : DecodeType(underlyingEnumType,beefTypeToMappedType), + }; + + beefTypeToMappedType[beefType] = newMapping; + beefTypeToMappedType[beefTypeName] = newMapping; + + return newMapping; + } + + private static void InitializeTypes(Dictionary beefTypeToMappedType) + { + beefTypeToMappedType.Add("void", new MappedType + { + BeefTypeName = "void", + ReturnValueConversion = null + }); + + beefTypeToMappedType.Add("char16*", new MappedType + { + BeefTypeName = "char16*", + CSharpTypeName = "char*", + CSharpWrapperType = "string", + ReturnValueConversion = null, // TODO! + WrapperConvertInput = "fixed (char* {0} = {1}) {{", + WrapperCleanupInput = "}}" + }); + } + + private static void GenerateFunctionPointer(GlueMethod method, Dictionary beefTypeToMappedType, StringBuilder output) + { + MappedType returnType = DecodeType(method.ReturnType, beefTypeToMappedType); + + List parameters = new(); + StringBuilder parameterText = new(); + + foreach (var param in method.Parameters) + { + MappedType parameterType = DecodeType(param.Type, beefTypeToMappedType); + parameters.Add(parameterType); + + parameterText.Append(parameterType.CSharpTypeName); + parameterText.Append(", "); + } + + output.AppendLine($" public delegate* unmanaged[Cdecl]<{parameterText}{returnType.CSharpTypeName}> {method.Name};"); + } + + private static void GenerateWrapper(GlueMethod method, Dictionary beefTypeToMappedType, StringBuilder output) + { + // MappedType returnType = DecodeType(method.ReturnType, beefTypeToMappedType); + // + List parameters = new(); + StringBuilder parameterText = new(); + StringBuilder parameterConversion = new(); + StringBuilder cleanup = new(); + StringBuilder call = new(); + + MappedType returnType = DecodeType(method.ReturnType, beefTypeToMappedType); + + if (returnType.ReturnValueConversion is not null) + { + call.Append("var returnValue = "); + } + + call.Append($"_engineFunctions.{method.Name}("); + + foreach (var param in method.Parameters) + { + MappedType parameterType = DecodeType(param.Type, beefTypeToMappedType); + parameters.Add(parameterType); + + if (parameterText.Length > 0) + { + parameterText.Append(", "); + call.Append(", "); + } + + parameterText.Append($"{parameterType.CSharpWrapperType} {param.Name}"); + + if (parameterType.WrapperConvertInput is not null) + { + string convertedParamName = $"{param.Name}Converted"; + + parameterConversion.AppendLine(); + parameterConversion.Append("\t\t"); + parameterConversion.AppendFormat(parameterType.WrapperConvertInput, convertedParamName, param.Name); + + if (parameterType.WrapperCleanupInput is not null) + { + cleanup.Append("\t\t"); + cleanup.AppendFormat(parameterType.WrapperCleanupInput, convertedParamName); + cleanup.AppendLine(); + } + + call.Append(convertedParamName); + } + else + { + call.Append(param.Name); + } + } + + call.Append(");"); + + output.AppendLine($$""" + public static {{returnType.CSharpWrapperType}} {{method.Name}}({{parameterText}}) + {{{parameterConversion}} + {{call}} + {{cleanup}} + {{returnType.ReturnValueConversion}} + } + + """); + + + } + + private static void GenerateCode( + SourceProductionContext context, + GeneratorInput input) + { + Dictionary beefTypeToMappedType = new(); + + InitializeTypes(beefTypeToMappedType); + + foreach (ITypeSymbol? mapping in input.TypeMappings) + { + if (mapping is null) + continue; + + string csharpTypeName = mapping.ToDisplayString(); + + foreach (AttributeData attribute in mapping.GetAttributes() + .Where(attribute => attribute.AttributeClass?.Name == "EngineClassAttribute")) + { + string? beefTypeName = attribute.ConstructorArguments[0].Value?.ToString(); + + if (beefTypeName is null) + continue; + + MappedType newMapping = DecodeType(beefTypeName, beefTypeToMappedType); + newMapping.CSharpTypeName = csharpTypeName; + } + } + + StringBuilder engineFunctions = new StringBuilder(); + StringBuilder wrappers = new StringBuilder(); + + engineFunctions.Append(""" + // + using System.Collections.Generic; + + namespace GlitchyEngine; + + unsafe internal partial struct EngineFunctions + { + /* + """); + + wrappers.Append(""" + // + using System.Collections.Generic; + + namespace GlitchyEngine; + + unsafe internal partial class ScriptGlue + { + """); + + List methods = new List(); + + foreach (string glueFunctions in input.GlueFunctionDefinitions) + { + methods.AddRange(JsonSerializer.Deserialize(glueFunctions) ?? []); + } + + foreach (GlueMethod method in methods) + { + if (!input.ExistingEngineFunctionStructs.Contains(method.Name)) + { + GenerateFunctionPointer(method, beefTypeToMappedType, engineFunctions); + } + + if (!input.ExistingScriptGlueClasses.Contains(method.Name)) + { + GenerateWrapper(method, beefTypeToMappedType, wrappers); + } + } + + // + // foreach (var type in input.enumerations) + // { + // if (type is null) + // continue; + // + // GenerateCode(type, output); + // var typeNamespace = type.ContainingNamespace.IsGlobalNamespace + // ? null + // : $"{type.ContainingNamespace}."; + // + // } + + engineFunctions.Append("\n*/}"); + wrappers.Append("\n}"); + + context.AddSource("EngineFunctions.g.cs", engineFunctions.ToString()); + context.AddSource("ScriptGlue.g.cs", wrappers.ToString()); + } + + private static bool IsScriptGlueClass( + SyntaxNode syntaxNode, + CancellationToken cancellationToken) + { + return syntaxNode is ClassDeclarationSyntax { Identifier.ValueText: "ScriptGlue" }; + } + + private static bool IsEngineFunctionsStruct ( + SyntaxNode syntaxNode, + CancellationToken cancellationToken) + { + return syntaxNode is StructDeclarationSyntax { Identifier.ValueText: "EngineFunctions" }; + } + + private static INamedTypeSymbol? GetSymbol(GeneratorSyntaxContext context, + CancellationToken cancellationToken) where T : BaseTypeDeclarationSyntax + { + var classDecl = (T)context.Node; + return context.SemanticModel.GetDeclaredSymbol(classDecl) as INamedTypeSymbol; + } + + private static bool CouldBeMappedType( + SyntaxNode syntaxNode, + CancellationToken cancellationToken) + { + if (syntaxNode is not AttributeSyntax attribute) + return false; + + var name = ExtractName(attribute.Name); + + return name is "EngineClass" or "EngineClassAttribute"; + } + + private static string? ExtractName(NameSyntax? name) + { + return name switch + { + SimpleNameSyntax ins => ins.Identifier.Text, + QualifiedNameSyntax qns => qns.Right.Identifier.Text, + _ => null + }; + } + + private static ITypeSymbol? GetTypeOrNull( + GeneratorSyntaxContext context, + CancellationToken cancellationToken) + { + var attributeSyntax = (AttributeSyntax)context.Node; + + // "attribute.Parent" is "AttributeListSyntax" + // "attribute.Parent.Parent" is a C# fragment the attributes are applied to + if (attributeSyntax.Parent?.Parent is not BaseTypeDeclarationSyntax typeDeclaration) + return null; + + return context.SemanticModel.GetDeclaredSymbol(typeDeclaration) as ITypeSymbol; + } +}