12 Commits
21 changed files with 374 additions and 837 deletions
+19
View File
@@ -0,0 +1,19 @@
name: Trigger docs build
# Rebuilds the documentation website (aharabada/glitchy-engine-docs) whenever main changes
on:
push:
branches: [main]
workflow_dispatch:
permissions: {}
jobs:
dispatch:
runs-on: ubuntu-latest
steps:
- name: Notify docs repository
env:
# Fine-grained PAT, only for glitchy-engine-docs, permission "Contents: Read and write"
GH_TOKEN: ${{ secrets.DOCS_DISPATCH_TOKEN }}
run: gh api repos/aharabada/glitchy-engine-docs/dispatches -f event_type=engine-updated
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<!-- General configuration --> <!-- General configuration -->
<AssemblyTitle>[ProjectName]</AssemblyTitle> <AssemblyTitle>[ProjectName]</AssemblyTitle>
@@ -10,6 +10,7 @@
<OutputPath>./.cache/bin/</OutputPath> <OutputPath>./.cache/bin/</OutputPath>
<!-- Generates a runtimeconfig-file and copies nuget references to the output --> <!-- Generates a runtimeconfig-file and copies nuget references to the output -->
<EnableDynamicLoading>true</EnableDynamicLoading> <EnableDynamicLoading>true</EnableDynamicLoading>
<DefaultItemExcludes>$(DefaultItemExcludes);**/*.ass</DefaultItemExcludes>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="ScriptCore" OutputItemType="Analyzer" ReferenceOutputAssembly="true"> <Reference Include="ScriptCore" OutputItemType="Analyzer" ReferenceOutputAssembly="true">
@@ -8,7 +8,6 @@ using GlitchyEngine;
using GlitchyEngine.Content; using GlitchyEngine.Content;
using GlitchyEngine.Scripting; using GlitchyEngine.Scripting;
using GlitchyEngine.Core; using GlitchyEngine.Core;
using Mono;
using GlitchyEngine.World.Components; using GlitchyEngine.World.Components;
namespace GlitchyEditor.EditWindows namespace GlitchyEditor.EditWindows
@@ -604,7 +604,7 @@ namespace GlitchyEditor.EditWindows
if (ImGui.MenuItem("Open C# Project...")) if (ImGui.MenuItem("Open C# Project..."))
{ {
Editor.Instance.IdeAdapter.OpenScriptProject(); Editor.Instance.OpenScriptProject();
} }
ImGui.AttachTooltip("Opens the C# Solution of this project."); ImGui.AttachTooltip("Opens the C# Solution of this project.");
@@ -1434,7 +1434,7 @@ namespace GlitchyEditor.EditWindows
// Special treatment for scripts, open them in Visual Studio. // Special treatment for scripts, open them in Visual Studio.
if (entry->Path.EndsWith(".cs")) if (entry->Path.EndsWith(".cs"))
{ {
Editor.Instance.IdeAdapter.OpenScript(entry->Path); Editor.Instance.OpenScript(entry->Path);
} }
else if (Path.OpenFolder(entry->Path) case .Err) else if (Path.OpenFolder(entry->Path) case .Err)
Log.EngineLogger.Error("Failed to open file."); Log.EngineLogger.Error("Failed to open file.");
+4 -4
View File
@@ -9,6 +9,7 @@ using GlitchyEngine.Renderer;
using GlitchyEngine; using GlitchyEngine;
using GlitchyEditor.CodeEditors; using GlitchyEditor.CodeEditors;
using System.IO; using System.IO;
using GlitchyEditor.Settings;
namespace GlitchyEditor.EditWindows; namespace GlitchyEditor.EditWindows;
@@ -316,8 +317,7 @@ class LogWindow : EditorWindow
float width = ImGui.CalcTextSize(lineBuffer.CStr()).x; float width = ImGui.CalcTextSize(lineBuffer.CStr()).x;
if (ImGui.Selectable(lineBuffer, false, .None, .(width, 0))) if (ImGui.Selectable(lineBuffer, false, .None, .(width, 0)))
{ {
// TODO: Columns? Editor.Instance.OpenScript(frameInfo.FileName, frameInfo.Line, frameInfo.Column);
Editor.Instance.IdeAdapter.OpenScript(frameInfo.FileName, frameInfo.Line, frameInfo.Column);
} }
} }
@@ -336,13 +336,13 @@ class LogWindow : EditorWindow
{ {
if (message.Source.MessageOrigin != null) if (message.Source.MessageOrigin != null)
{ {
Editor.Instance.IdeAdapter.OpenScript(message.Source.MessageOrigin.FileName, message.Source.MessageOrigin.LineNumber); Editor.Instance.OpenScript(message.Source.MessageOrigin.FileName, message.Source.MessageOrigin.LineNumber);
} }
else if (message.Source.Exception != null) else if (message.Source.Exception != null)
{ {
// TODO: Column? // TODO: Column?
let firstFrame = message.Source.Exception.StackTrace.Frames[0]; let firstFrame = message.Source.Exception.StackTrace.Frames[0];
Editor.Instance.IdeAdapter.OpenScript(firstFrame.FileName, firstFrame.Line); Editor.Instance.OpenScript(firstFrame.FileName, firstFrame.Line);
//message.Source.Exception.StackTrace //message.Source.Exception.StackTrace
} }
} }
+50
View File
@@ -177,5 +177,55 @@ namespace GlitchyEditor
{ {
_settingsWindow.Open = true; _settingsWindow.Open = true;
} }
private void OpenIdeConfigurationPopup() {
PopupService.Instance.OpenPopup("No IDE configured.", new (close) => {
close = false;
ImGui.TextUnformatted("In order to open a source file or the script project you need to configure an IDE to use.");
if (ImGui.Button("Go to settings..."))
{
ShowSettings();
SettingsWindow.HighlightSetting("Tools", "ide");
close = true;
}
ImGui.SameLine();
if (ImGui.Button("Cancel"))
{
close = true;
}
});
}
/// Wrapper for IdeAdapter.OpenScript that check whether or not an IDE Adapter is configured.
/// If not, a popup will be show.
public void OpenScript(StringView fileName, int lineNumber = 0, int columnNumber = 0)
{
if (IdeAdapter == null)
{
OpenIdeConfigurationPopup();
}
else
{
IdeAdapter.OpenScript(fileName, lineNumber, columnNumber);
}
}
/// Wrapper for IdeAdapter.OpenScript that check whether or not an IDE Adapter is configured.
/// If not, a popup will be show.
public void OpenScriptProject()
{
if (IdeAdapter == null)
{
OpenIdeConfigurationPopup();
}
else
{
IdeAdapter.OpenScriptProject();
}
}
} }
} }
@@ -1,11 +1,28 @@
// Based on the Decimal implementation from the Mono Runtime: https://github.com/mono/mono/blob/0f53e9e151d92944cacab3e24ac359410c606df6/mcs/class/referencesource/mscorlib/system/decimal.cs
// Originally licensed under the MIT license.
using System; using System;
using Bon.Integrated;
using Bon; using Bon;
using Bon.Integrated;
namespace GlitchyEngine.Scripting; namespace GlitchyEngine.Scripting;
/// A struct providing access to the components of a mono decimal. /// A struct compatible with the Decimal type form the .Net Runtime.
struct MonoDecimal struct Decimal
{ {
// Sign mask for the flags field. A value of zero in this bit indicates a
// positive Decimal value, and a value of one in this bit indicates a
// negative Decimal value.
//
// Look at OleAut's DECIMAL_NEG constant to check for negative values
// in native code.
private const uint32 SignMask = 0x80000000u;
// Scale mask for the flags field. This byte in the flags field contains
// the power of 10 to divide the Decimal value by. The scale byte must
// contain a value between 0 and 28 inclusive.
private const uint32 ScaleMask = 0x00FF0000u;
[Bitfield<uint16>(.Private, .BitsAt(16, 0), "_dontUse", .Read)] [Bitfield<uint16>(.Private, .BitsAt(16, 0), "_dontUse", .Read)]
[Bitfield<uint8>(.Public, .BitsAt(8, 16), "Exponent")] [Bitfield<uint8>(.Public, .BitsAt(8, 16), "Exponent")]
[Bitfield<uint8>(.Private, .BitsAt(7, 24), "_dontUse2")] [Bitfield<uint8>(.Private, .BitsAt(7, 24), "_dontUse2")]
@@ -20,15 +37,48 @@ struct MonoDecimal
static this static this
{ {
gBonEnv.typeHandlers.Add(typeof(MonoDecimal), gBonEnv.typeHandlers.Add(typeof(Decimal),
((.)new => AssetSerialize, new => AssetDeserialize)); ((.)new => AssetSerialize, new => AssetDeserialize));
} }
public this()
{
_high = 0;
_low = 0;
_mid = 0;
_flags = 0;
}
public this(int value)
{
var value;
if (value >= 0)
{
_flags = 0;
}
else
{
_flags = SignMask;
value = -value;
}
_low = (uint32)value;
_mid = (uint32)(value >> 32);
_high = 0;
}
public this(uint value)
{
_flags = 0;
_low = (uint32)value;
_mid = (uint32)(value >> 32);
_high = 0;
}
static void AssetSerialize(BonWriter writer, ValueView value, BonEnvironment environment, SerializeValueState state) static void AssetSerialize(BonWriter writer, ValueView value, BonEnvironment environment, SerializeValueState state)
{ {
Log.EngineLogger.Assert(value.type == typeof(Self)); Log.EngineLogger.Assert(value.type == typeof(Self));
MonoDecimal decimal = value.Get<MonoDecimal>(); Decimal decimal = value.Get<Decimal>();
decimal.ToString(writer.outStr); decimal.ToString(writer.outStr);
} }
@@ -86,11 +136,11 @@ struct MonoDecimal
strBuffer.Append('m'); strBuffer.Append('m');
} }
public static Result<MonoDecimal> Parse(StringView strBuffer) public static Result<Decimal> Parse(StringView strBuffer)
{ {
var strBuffer; var strBuffer;
MonoDecimal result = .(); Decimal result = .();
if (strBuffer.StartsWith('-')) if (strBuffer.StartsWith('-'))
{ {
@@ -1,5 +1,4 @@
using System; using System;
using Mono;
using GlitchyEngine.Core; using GlitchyEngine.Core;
using System.Diagnostics; using System.Diagnostics;
@@ -48,17 +48,6 @@ class EntitySerializerWrapper : NewScriptClass
_createSerializationContextMethod(serializerPtr); _createSerializationContextMethod(serializerPtr);
} }
/*public void ClearSerializationContext(ScriptInstanceSerializer serializer)
{
void* serializerPtr = Internal.UnsafeCastToPtr(serializer);
MonoException* exception = null;
_clearSerializationContextMethod(serializerPtr, &exception);
if (exception != null)
ScriptEngine.[Friend]HandleMonoException(exception, null);
}*/
public void DestroySerializationContext(ScriptInstanceSerializer serializer) public void DestroySerializationContext(ScriptInstanceSerializer serializer)
{ {
void* serializerPtr = Internal.UnsafeCastToPtr(serializer); void* serializerPtr = Internal.UnsafeCastToPtr(serializer);
@@ -186,7 +186,6 @@ static class ScriptEngine
public static void Init() public static void Init()
{ {
InitRuntime(); InitRuntime();
//InitMono();
LoadScriptAssemblies(); LoadScriptAssemblies();
} }
+88 -82
View File
@@ -59,6 +59,12 @@ struct RegisterCallAttribute : Attribute
{ {
public bool EngineResultAsBool { get; set mut; } public bool EngineResultAsBool { get; set mut; }
public bool IsExtension { get; set mut; } public bool IsExtension { get; set mut; }
/**
* If true, marks the method as guaranteed short running.
* A GuaranteedShortRunning function should have a VERY short runtime (< 1μs), must NEVER block, and NEVER call back into managed code!
* This allows the script glue infrastructure to apply some optimizations (i.e. SuppressGCTransition in C#)
*/
public bool GuaranteedShortRunning {get; set mut; }
} }
struct TypeTranslationTemplate struct TypeTranslationTemplate
@@ -147,6 +153,7 @@ struct EngineFunctionsGeneratorAttribute : Attribute, IComptimeTypeApply
{{ {{
"name": "{method.Name}", "name": "{method.Name}",
"return_type": "{GetTypeInfo(method.ReturnType, registerCallAttribute)}", "return_type": "{GetTypeInfo(method.ReturnType, registerCallAttribute)}",
"guaranteed_short_running": {registerCallAttribute.GuaranteedShortRunning ? "true" : "false"},
"parameters": [{parameters} "parameters": [{parameters}
] ]
}}, }},
@@ -337,7 +344,7 @@ static class ScriptGlue
}); });
} }
/// Gets the entity with the given id. Throws a mono exception, if the entity doesn't exist. /// Gets the entity with the given id. Returns an .Err if it doesn't exist.
static Result<Entity> GetEntitySafe(UUID entityId) static Result<Entity> GetEntitySafe(UUID entityId)
{ {
if (ScriptEngine.Context.GetEntityByID(entityId) case .Ok(let entity)) if (ScriptEngine.Context.GetEntityByID(entityId) case .Ok(let entity))
@@ -453,7 +460,7 @@ static class ScriptGlue
} }
} }
[RegisterCall, CallingConvention(.Cdecl)] [RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
static StringView GetLastExceptionMessage() static StringView GetLastExceptionMessage()
{ {
return _lastExceptionMessage; return _lastExceptionMessage;
@@ -509,32 +516,32 @@ static class ScriptGlue
#region Input #region Input
[RegisterCall, CallingConvention(.Cdecl)] [RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
static bool Input_IsKeyPressed(Key key) => Input.IsKeyPressed(key); static bool Input_IsKeyPressed(Key key) => Input.IsKeyPressed(key);
[RegisterCall, CallingConvention(.Cdecl)] [RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
static bool Input_IsKeyReleased(Key key) => Input.IsKeyReleased(key); static bool Input_IsKeyReleased(Key key) => Input.IsKeyReleased(key);
[RegisterCall, CallingConvention(.Cdecl)] [RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
static bool Input_IsKeyToggled(Key key) => Input.IsKeyToggled(key); static bool Input_IsKeyToggled(Key key) => Input.IsKeyToggled(key);
[RegisterCall, CallingConvention(.Cdecl)] [RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
static bool Input_IsKeyPressing(Key key) => Input.IsKeyPressing(key); static bool Input_IsKeyPressing(Key key) => Input.IsKeyPressing(key);
[RegisterCall, CallingConvention(.Cdecl)] [RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
static bool Input_IsKeyReleasing(Key key) => Input.IsKeyReleasing(key); static bool Input_IsKeyReleasing(Key key) => Input.IsKeyReleasing(key);
[RegisterCall, CallingConvention(.Cdecl)] [RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
static bool Input_IsMouseButtonPressed(MouseButton mouseButton) => Input.IsMouseButtonPressed(mouseButton); static bool Input_IsMouseButtonPressed(MouseButton mouseButton) => Input.IsMouseButtonPressed(mouseButton);
[RegisterCall, CallingConvention(.Cdecl)] [RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
static bool Input_IsMouseButtonReleased(MouseButton mouseButton) => Input.IsMouseButtonReleased(mouseButton); static bool Input_IsMouseButtonReleased(MouseButton mouseButton) => Input.IsMouseButtonReleased(mouseButton);
[RegisterCall, CallingConvention(.Cdecl)] [RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
static bool Input_IsMouseButtonPressing(MouseButton mouseButton) => Input.IsMouseButtonPressing(mouseButton); static bool Input_IsMouseButtonPressing(MouseButton mouseButton) => Input.IsMouseButtonPressing(mouseButton);
[RegisterCall, CallingConvention(.Cdecl)] [RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
static bool Input_IsMouseButtonReleasing(MouseButton mouseButton) => Input.IsMouseButtonReleasing(mouseButton); static bool Input_IsMouseButtonReleasing(MouseButton mouseButton) => Input.IsMouseButtonReleasing(mouseButton);
#endregion Input #endregion Input
@@ -618,7 +625,6 @@ static class ScriptGlue
return .ArgumentError; return .ArgumentError;
} }
//return scriptComponent.Instance.MonoInstance;
return .Ok; return .Ok;
} }
@@ -632,7 +638,7 @@ static class ScriptGlue
return .Ok; return .Ok;
} }
[RegisterCall, CallingConvention(.Cdecl)] [RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
static StringView Entity_GetName(UUID entityId) static StringView Entity_GetName(UUID entityId)
{ {
Result<Entity> foundEntity = ScriptEngine.Context.GetEntityByID(entityId); Result<Entity> foundEntity = ScriptEngine.Context.GetEntityByID(entityId);
@@ -675,7 +681,7 @@ static class ScriptGlue
#region TransformComponent #region TransformComponent
[RegisterCall, CallingConvention(.Cdecl)] [RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
static EngineResult Transform_GetParent(UUID entityId, out UUID parentId) static EngineResult Transform_GetParent(UUID entityId, out UUID parentId)
{ {
parentId = .Zero; parentId = .Zero;
@@ -702,7 +708,7 @@ static class ScriptGlue
return .Ok; return .Ok;
} }
[RegisterCall, CallingConvention(.Cdecl)] [RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
static EngineResult Transform_GetTranslation(UUID entityId, out float3 translation) static EngineResult Transform_GetTranslation(UUID entityId, out float3 translation)
{ {
translation = ?; translation = ?;
@@ -727,7 +733,7 @@ static class ScriptGlue
return .Ok; return .Ok;
} }
[RegisterCall, CallingConvention(.Cdecl)] [RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
static EngineResult Transform_GetWorldTranslation(UUID entityId, out float3 translationWorld) static EngineResult Transform_GetWorldTranslation(UUID entityId, out float3 translationWorld)
{ {
translationWorld = ?; translationWorld = ?;
@@ -757,7 +763,7 @@ static class ScriptGlue
// TODO: we need to handle repositioning of colliders that are children of the entity with rigidbody... // TODO: we need to handle repositioning of colliders that are children of the entity with rigidbody...
} }
[RegisterCall, CallingConvention(.Cdecl)] [RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
static EngineResult Transform_TransformPointToWorld(UUID entityId, float3 point, out float3 pointWorld) static EngineResult Transform_TransformPointToWorld(UUID entityId, float3 point, out float3 pointWorld)
{ {
pointWorld = ?; pointWorld = ?;
@@ -769,7 +775,7 @@ static class ScriptGlue
return .Ok; return .Ok;
} }
[RegisterCall, CallingConvention(.Cdecl)] [RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
static EngineResult Transform_GetRotation(UUID entityId, out Quaternion rotation) static EngineResult Transform_GetRotation(UUID entityId, out Quaternion rotation)
{ {
rotation = ?; rotation = ?;
@@ -794,7 +800,7 @@ static class ScriptGlue
return .Ok; return .Ok;
} }
[RegisterCall, CallingConvention(.Cdecl)] [RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
static EngineResult Transform_GetRotationEuler(UUID entityId, out float3 rotationEuler) static EngineResult Transform_GetRotationEuler(UUID entityId, out float3 rotationEuler)
{ {
rotationEuler = ?; rotationEuler = ?;
@@ -831,7 +837,7 @@ static class ScriptGlue
} }
} }
[RegisterCall, CallingConvention(.Cdecl)] [RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
static EngineResult Transform_GetRotationAxisAngle(UUID entityId, out AxisAngle rotationAxisAngle) static EngineResult Transform_GetRotationAxisAngle(UUID entityId, out AxisAngle rotationAxisAngle)
{ {
rotationAxisAngle = ?; rotationAxisAngle = ?;
@@ -855,7 +861,7 @@ static class ScriptGlue
return .Ok; return .Ok;
} }
[RegisterCall, CallingConvention(.Cdecl)] [RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
static EngineResult Transform_GetScale(UUID entityId, out float3 scale) static EngineResult Transform_GetScale(UUID entityId, out float3 scale)
{ {
scale = ?; scale = ?;
@@ -865,7 +871,7 @@ static class ScriptGlue
return .Ok; return .Ok;
} }
[RegisterCall, CallingConvention(.Cdecl)] [RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
static EngineResult Transform_SetScale(UUID entityId, float3 scale) static EngineResult Transform_SetScale(UUID entityId, float3 scale)
{ {
Entity entity = GetEntityOrReturnError!(entityId); Entity entity = GetEntityOrReturnError!(entityId);
@@ -883,14 +889,14 @@ static class ScriptGlue
#region Rigidbody2 #region Rigidbody2
[RegisterCall, CallingConvention(.Cdecl)] [RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
static void Rigidbody2D_ApplyForce(UUID entityId, in float2 force, in float2 point, bool wakeUp) static void Rigidbody2D_ApplyForce(UUID entityId, in float2 force, in float2 point, bool wakeUp)
{ {
Rigidbody2DComponent* rigidBody = GetComponentSafe<Rigidbody2DComponent>(entityId); Rigidbody2DComponent* rigidBody = GetComponentSafe<Rigidbody2DComponent>(entityId);
Box2D.Body.ApplyForce(rigidBody.[Friend]RuntimeBody, force, point, wakeUp); Box2D.Body.ApplyForce(rigidBody.[Friend]RuntimeBody, force, point, wakeUp);
} }
[RegisterCall, CallingConvention(.Cdecl)] [RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
static void Rigidbody2D_ApplyForceToCenter(UUID entityId, in float2 force, bool wakeUp) static void Rigidbody2D_ApplyForceToCenter(UUID entityId, in float2 force, bool wakeUp)
{ {
Rigidbody2DComponent* rigidBody = GetComponentSafe<Rigidbody2DComponent>(entityId); Rigidbody2DComponent* rigidBody = GetComponentSafe<Rigidbody2DComponent>(entityId);
@@ -904,7 +910,7 @@ static class ScriptGlue
rigidBody.SetPosition(position); rigidBody.SetPosition(position);
} }
[RegisterCall, CallingConvention(.Cdecl)] [RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
static void Rigidbody2D_GetPosition(UUID entityId, out float2 position) static void Rigidbody2D_GetPosition(UUID entityId, out float2 position)
{ {
Rigidbody2DComponent* rigidBody = GetComponentSafe<Rigidbody2DComponent>(entityId); Rigidbody2DComponent* rigidBody = GetComponentSafe<Rigidbody2DComponent>(entityId);
@@ -918,42 +924,42 @@ static class ScriptGlue
rigidBody.SetAngle(rotation); rigidBody.SetAngle(rotation);
} }
[RegisterCall, CallingConvention(.Cdecl)] [RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
static void Rigidbody2D_GetRotation(UUID entityId, out float rotation) static void Rigidbody2D_GetRotation(UUID entityId, out float rotation)
{ {
Rigidbody2DComponent* rigidBody = GetComponentSafe<Rigidbody2DComponent>(entityId); Rigidbody2DComponent* rigidBody = GetComponentSafe<Rigidbody2DComponent>(entityId);
rotation = rigidBody.GetAngle(); rotation = rigidBody.GetAngle();
} }
[RegisterCall, CallingConvention(.Cdecl)] [RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
static void Rigidbody2D_GetLinearVelocity(UUID entityId, out float2 velocity) static void Rigidbody2D_GetLinearVelocity(UUID entityId, out float2 velocity)
{ {
Rigidbody2DComponent* rigidBody = GetComponentSafe<Rigidbody2DComponent>(entityId); Rigidbody2DComponent* rigidBody = GetComponentSafe<Rigidbody2DComponent>(entityId);
velocity = rigidBody.GetLinearVelocity(); velocity = rigidBody.GetLinearVelocity();
} }
[RegisterCall, CallingConvention(.Cdecl)] [RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
static void Rigidbody2D_SetLinearVelocity(UUID entityId, in float2 velocity) static void Rigidbody2D_SetLinearVelocity(UUID entityId, in float2 velocity)
{ {
Rigidbody2DComponent* rigidBody = GetComponentSafe<Rigidbody2DComponent>(entityId); Rigidbody2DComponent* rigidBody = GetComponentSafe<Rigidbody2DComponent>(entityId);
rigidBody.SetLinearVelocity(velocity); rigidBody.SetLinearVelocity(velocity);
} }
[RegisterCall, CallingConvention(.Cdecl)] [RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
static void Rigidbody2D_GetAngularVelocity(UUID entityId, out float velocity) static void Rigidbody2D_GetAngularVelocity(UUID entityId, out float velocity)
{ {
Rigidbody2DComponent* rigidBody = GetComponentSafe<Rigidbody2DComponent>(entityId); Rigidbody2DComponent* rigidBody = GetComponentSafe<Rigidbody2DComponent>(entityId);
velocity = rigidBody.GetAngularVelocity(); velocity = rigidBody.GetAngularVelocity();
} }
[RegisterCall, CallingConvention(.Cdecl)] [RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
static void Rigidbody2D_SetAngularVelocity(UUID entityId, float velocity) static void Rigidbody2D_SetAngularVelocity(UUID entityId, float velocity)
{ {
Rigidbody2DComponent* rigidBody = GetComponentSafe<Rigidbody2DComponent>(entityId); Rigidbody2DComponent* rigidBody = GetComponentSafe<Rigidbody2DComponent>(entityId);
rigidBody.SetAngularVelocity(velocity); rigidBody.SetAngularVelocity(velocity);
} }
[RegisterCall, CallingConvention(.Cdecl)] [RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
static void Rigidbody2D_GetBodyType(UUID entityId, out Rigidbody2DComponent.BodyType bodyType) static void Rigidbody2D_GetBodyType(UUID entityId, out Rigidbody2DComponent.BodyType bodyType)
{ {
Rigidbody2DComponent* rigidBody = GetComponentSafe<Rigidbody2DComponent>(entityId); Rigidbody2DComponent* rigidBody = GetComponentSafe<Rigidbody2DComponent>(entityId);
@@ -967,7 +973,7 @@ static class ScriptGlue
rigidBody.BodyType = bodyType; rigidBody.BodyType = bodyType;
} }
[RegisterCall, CallingConvention(.Cdecl)] [RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
static void Rigidbody2D_IsFixedRotation(UUID entityId, out bool isFixedRotation) static void Rigidbody2D_IsFixedRotation(UUID entityId, out bool isFixedRotation)
{ {
Rigidbody2DComponent* rigidBody = GetComponentSafe<Rigidbody2DComponent>(entityId); Rigidbody2DComponent* rigidBody = GetComponentSafe<Rigidbody2DComponent>(entityId);
@@ -981,14 +987,14 @@ static class ScriptGlue
rigidBody.FixedRotation = isFixedRotation; rigidBody.FixedRotation = isFixedRotation;
} }
[RegisterCall, CallingConvention(.Cdecl)] [RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
static void Rigidbody2D_GetGravityScale(UUID entityId, out float gravityScale) static void Rigidbody2D_GetGravityScale(UUID entityId, out float gravityScale)
{ {
Rigidbody2DComponent* rigidBody = GetComponentSafe<Rigidbody2DComponent>(entityId); Rigidbody2DComponent* rigidBody = GetComponentSafe<Rigidbody2DComponent>(entityId);
gravityScale = rigidBody.GravityScale; gravityScale = rigidBody.GravityScale;
} }
[RegisterCall, CallingConvention(.Cdecl)] [RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
static void Rigidbody2D_SetGravityScale(UUID entityId, float gravityScale) static void Rigidbody2D_SetGravityScale(UUID entityId, float gravityScale)
{ {
Rigidbody2DComponent* rigidBody = GetComponentSafe<Rigidbody2DComponent>(entityId); Rigidbody2DComponent* rigidBody = GetComponentSafe<Rigidbody2DComponent>(entityId);
@@ -999,126 +1005,126 @@ static class ScriptGlue
#region Camera #region Camera
[RegisterCall, CallingConvention(.Cdecl)] [RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
static void Camera_GetProjectionType(UUID entityId, out SceneCamera.ProjectionType projectionType) static void Camera_GetProjectionType(UUID entityId, out SceneCamera.ProjectionType projectionType)
{ {
CameraComponent* camera = GetComponentSafe<CameraComponent>(entityId); CameraComponent* camera = GetComponentSafe<CameraComponent>(entityId);
projectionType = camera.Camera.ProjectionType; projectionType = camera.Camera.ProjectionType;
} }
[RegisterCall, CallingConvention(.Cdecl)] [RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
static void Camera_SetProjectionType(UUID entityId, SceneCamera.ProjectionType projectionType) static void Camera_SetProjectionType(UUID entityId, SceneCamera.ProjectionType projectionType)
{ {
CameraComponent* camera = GetComponentSafe<CameraComponent>(entityId); CameraComponent* camera = GetComponentSafe<CameraComponent>(entityId);
camera.Camera.ProjectionType = projectionType; camera.Camera.ProjectionType = projectionType;
} }
[RegisterCall, CallingConvention(.Cdecl)] [RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
static void Camera_GetPerspectiveFovY(UUID entityId, out float fovY) static void Camera_GetPerspectiveFovY(UUID entityId, out float fovY)
{ {
CameraComponent* camera = GetComponentSafe<CameraComponent>(entityId); CameraComponent* camera = GetComponentSafe<CameraComponent>(entityId);
fovY = camera.Camera.PerspectiveFovY; fovY = camera.Camera.PerspectiveFovY;
} }
[RegisterCall, CallingConvention(.Cdecl)] [RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
static void Camera_SetPerspectiveFovY(UUID entityId, float fovY) static void Camera_SetPerspectiveFovY(UUID entityId, float fovY)
{ {
CameraComponent* camera = GetComponentSafe<CameraComponent>(entityId); CameraComponent* camera = GetComponentSafe<CameraComponent>(entityId);
camera.Camera.PerspectiveFovY = fovY; camera.Camera.PerspectiveFovY = fovY;
} }
[RegisterCall, CallingConvention(.Cdecl)] [RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
static void Camera_GetPerspectiveNearPlane(UUID entityId, out float nearPlane) static void Camera_GetPerspectiveNearPlane(UUID entityId, out float nearPlane)
{ {
CameraComponent* camera = GetComponentSafe<CameraComponent>(entityId); CameraComponent* camera = GetComponentSafe<CameraComponent>(entityId);
nearPlane = camera.Camera.PerspectiveNearPlane; nearPlane = camera.Camera.PerspectiveNearPlane;
} }
[RegisterCall, CallingConvention(.Cdecl)] [RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
static void Camera_SetPerspectiveNearPlane(UUID entityId, float nearPlane) static void Camera_SetPerspectiveNearPlane(UUID entityId, float nearPlane)
{ {
CameraComponent* camera = GetComponentSafe<CameraComponent>(entityId); CameraComponent* camera = GetComponentSafe<CameraComponent>(entityId);
camera.Camera.PerspectiveNearPlane = nearPlane; camera.Camera.PerspectiveNearPlane = nearPlane;
} }
[RegisterCall, CallingConvention(.Cdecl)] [RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
static void Camera_GetPerspectiveFarPlane(UUID entityId, out float farPlane) static void Camera_GetPerspectiveFarPlane(UUID entityId, out float farPlane)
{ {
CameraComponent* camera = GetComponentSafe<CameraComponent>(entityId); CameraComponent* camera = GetComponentSafe<CameraComponent>(entityId);
farPlane = camera.Camera.PerspectiveFarPlane; farPlane = camera.Camera.PerspectiveFarPlane;
} }
[RegisterCall, CallingConvention(.Cdecl)] [RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
static void Camera_SetPerspectiveFarPlane(UUID entityId, float farPlane) static void Camera_SetPerspectiveFarPlane(UUID entityId, float farPlane)
{ {
CameraComponent* camera = GetComponentSafe<CameraComponent>(entityId); CameraComponent* camera = GetComponentSafe<CameraComponent>(entityId);
camera.Camera.PerspectiveFarPlane = farPlane; camera.Camera.PerspectiveFarPlane = farPlane;
} }
[RegisterCall, CallingConvention(.Cdecl)] [RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
static void Camera_GetOrthographicHeight(UUID entityId, out float height) static void Camera_GetOrthographicHeight(UUID entityId, out float height)
{ {
CameraComponent* camera = GetComponentSafe<CameraComponent>(entityId); CameraComponent* camera = GetComponentSafe<CameraComponent>(entityId);
height = camera.Camera.OrthographicHeight; height = camera.Camera.OrthographicHeight;
} }
[RegisterCall, CallingConvention(.Cdecl)] [RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
static void Camera_SetOrthographicHeight(UUID entityId, float height) static void Camera_SetOrthographicHeight(UUID entityId, float height)
{ {
CameraComponent* camera = GetComponentSafe<CameraComponent>(entityId); CameraComponent* camera = GetComponentSafe<CameraComponent>(entityId);
camera.Camera.OrthographicHeight = height; camera.Camera.OrthographicHeight = height;
} }
[RegisterCall, CallingConvention(.Cdecl)] [RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
static void Camera_SetOrthographicNearPlane(UUID entityId, float nearPlane) static void Camera_SetOrthographicNearPlane(UUID entityId, float nearPlane)
{ {
CameraComponent* camera = GetComponentSafe<CameraComponent>(entityId); CameraComponent* camera = GetComponentSafe<CameraComponent>(entityId);
camera.Camera.OrthographicNearPlane = nearPlane; camera.Camera.OrthographicNearPlane = nearPlane;
} }
[RegisterCall, CallingConvention(.Cdecl)] [RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
static void Camera_GetOrthographicNearPlane(UUID entityId, out float nearPlane) static void Camera_GetOrthographicNearPlane(UUID entityId, out float nearPlane)
{ {
CameraComponent* camera = GetComponentSafe<CameraComponent>(entityId); CameraComponent* camera = GetComponentSafe<CameraComponent>(entityId);
nearPlane = camera.Camera.OrthographicNearPlane; nearPlane = camera.Camera.OrthographicNearPlane;
} }
[RegisterCall, CallingConvention(.Cdecl)] [RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
static void Camera_SetOrthographicFarPlane(UUID entityId, float farPlane) static void Camera_SetOrthographicFarPlane(UUID entityId, float farPlane)
{ {
CameraComponent* camera = GetComponentSafe<CameraComponent>(entityId); CameraComponent* camera = GetComponentSafe<CameraComponent>(entityId);
camera.Camera.OrthographicFarPlane = farPlane; camera.Camera.OrthographicFarPlane = farPlane;
} }
[RegisterCall, CallingConvention(.Cdecl)] [RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
static void Camera_GetOrthographicFarPlane(UUID entityId, out float farPlane) static void Camera_GetOrthographicFarPlane(UUID entityId, out float farPlane)
{ {
CameraComponent* camera = GetComponentSafe<CameraComponent>(entityId); CameraComponent* camera = GetComponentSafe<CameraComponent>(entityId);
farPlane = camera.Camera.OrthographicFarPlane; farPlane = camera.Camera.OrthographicFarPlane;
} }
[RegisterCall, CallingConvention(.Cdecl)] [RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
static void Camera_SetAspectRatio(UUID entityId, float aspectRatio) static void Camera_SetAspectRatio(UUID entityId, float aspectRatio)
{ {
CameraComponent* camera = GetComponentSafe<CameraComponent>(entityId); CameraComponent* camera = GetComponentSafe<CameraComponent>(entityId);
camera.Camera.AspectRatio = aspectRatio; camera.Camera.AspectRatio = aspectRatio;
} }
[RegisterCall, CallingConvention(.Cdecl)] [RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
static void Camera_GetAspectRatio(UUID entityId, out float aspectRatio) static void Camera_GetAspectRatio(UUID entityId, out float aspectRatio)
{ {
CameraComponent* camera = GetComponentSafe<CameraComponent>(entityId); CameraComponent* camera = GetComponentSafe<CameraComponent>(entityId);
aspectRatio = camera.Camera.AspectRatio; aspectRatio = camera.Camera.AspectRatio;
} }
[RegisterCall, CallingConvention(.Cdecl)] [RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
static void Camera_SetFixedAspectRatio(UUID entityId, bool fixedAspectRatio) static void Camera_SetFixedAspectRatio(UUID entityId, bool fixedAspectRatio)
{ {
CameraComponent* camera = GetComponentSafe<CameraComponent>(entityId); CameraComponent* camera = GetComponentSafe<CameraComponent>(entityId);
camera.Camera.FixedAspectRatio = fixedAspectRatio; camera.Camera.FixedAspectRatio = fixedAspectRatio;
} }
[RegisterCall, CallingConvention(.Cdecl)] [RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
static void Camera_GetFixedAspectRatio(UUID entityId, out bool fixedAspectRatio) static void Camera_GetFixedAspectRatio(UUID entityId, out bool fixedAspectRatio)
{ {
CameraComponent* camera = GetComponentSafe<CameraComponent>(entityId); CameraComponent* camera = GetComponentSafe<CameraComponent>(entityId);
@@ -1131,7 +1137,7 @@ static class ScriptGlue
// TODO: We need a wrapper class! // TODO: We need a wrapper class!
[RegisterCall, CallingConvention(.Cdecl)] [RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
static void Physics2D_GetGravity(out float2 gravity) static void Physics2D_GetGravity(out float2 gravity)
{ {
Scene scene = ScriptEngine.Context; Scene scene = ScriptEngine.Context;
@@ -1139,7 +1145,7 @@ static class ScriptGlue
gravity = scene.Physics2DSettings.Gravity; gravity = scene.Physics2DSettings.Gravity;
} }
[RegisterCall, CallingConvention(.Cdecl)] [RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
static void Physics2D_SetGravity(in float2 gravity) static void Physics2D_SetGravity(in float2 gravity)
{ {
Scene scene = ScriptEngine.Context; Scene scene = ScriptEngine.Context;
@@ -1152,42 +1158,42 @@ static class ScriptGlue
// TODO: Do we even need the circle renderer? // TODO: Do we even need the circle renderer?
#region CircleRenderer #region CircleRenderer
[RegisterCall, CallingConvention(.Cdecl)] [RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
static void CircleRenderer_GetColor(UUID entityId, out ColorRGBA color) static void CircleRenderer_GetColor(UUID entityId, out ColorRGBA color)
{ {
CircleRendererComponent* circleRenderer = GetComponentSafe<CircleRendererComponent>(entityId); CircleRendererComponent* circleRenderer = GetComponentSafe<CircleRendererComponent>(entityId);
color = circleRenderer.Color; color = circleRenderer.Color;
} }
[RegisterCall, CallingConvention(.Cdecl)] [RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
static void CircleRenderer_SetColor(UUID entityId, ColorRGBA color) static void CircleRenderer_SetColor(UUID entityId, ColorRGBA color)
{ {
CircleRendererComponent* circleRenderer = GetComponentSafe<CircleRendererComponent>(entityId); CircleRendererComponent* circleRenderer = GetComponentSafe<CircleRendererComponent>(entityId);
circleRenderer.Color = color; circleRenderer.Color = color;
} }
[RegisterCall, CallingConvention(.Cdecl)] [RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
static void CircleRenderer_GetUvTransform(UUID entityId, out float4 uvTransform) static void CircleRenderer_GetUvTransform(UUID entityId, out float4 uvTransform)
{ {
CircleRendererComponent* circleRenderer = GetComponentSafe<CircleRendererComponent>(entityId); CircleRendererComponent* circleRenderer = GetComponentSafe<CircleRendererComponent>(entityId);
uvTransform = circleRenderer.UvTransform; uvTransform = circleRenderer.UvTransform;
} }
[RegisterCall, CallingConvention(.Cdecl)] [RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
static void CircleRenderer_SetUvTransform(UUID entityId, float4 uvTransform) static void CircleRenderer_SetUvTransform(UUID entityId, float4 uvTransform)
{ {
CircleRendererComponent* circleRenderer = GetComponentSafe<CircleRendererComponent>(entityId); CircleRendererComponent* circleRenderer = GetComponentSafe<CircleRendererComponent>(entityId);
circleRenderer.UvTransform = uvTransform; circleRenderer.UvTransform = uvTransform;
} }
[RegisterCall, CallingConvention(.Cdecl)] [RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
static void CircleRenderer_GetInnerRadius(UUID entityId, out float innerRadius) static void CircleRenderer_GetInnerRadius(UUID entityId, out float innerRadius)
{ {
CircleRendererComponent* circleRenderer = GetComponentSafe<CircleRendererComponent>(entityId); CircleRendererComponent* circleRenderer = GetComponentSafe<CircleRendererComponent>(entityId);
innerRadius = circleRenderer.InnerRadius; innerRadius = circleRenderer.InnerRadius;
} }
[RegisterCall, CallingConvention(.Cdecl)] [RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
static void CircleRenderer_SetInnerRadius(UUID entityId, float innerRadius) static void CircleRenderer_SetInnerRadius(UUID entityId, float innerRadius)
{ {
CircleRendererComponent* circleRenderer = GetComponentSafe<CircleRendererComponent>(entityId); CircleRendererComponent* circleRenderer = GetComponentSafe<CircleRendererComponent>(entityId);
@@ -1198,7 +1204,7 @@ static class ScriptGlue
#region SpriteRenderer #region SpriteRenderer
[RegisterCall, CallingConvention(.Cdecl)] [RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
static EngineResult SpriteRenderer_GetColor(UUID entityId, out ColorRGBA color) static EngineResult SpriteRenderer_GetColor(UUID entityId, out ColorRGBA color)
{ {
color = ?; color = ?;
@@ -1207,7 +1213,7 @@ static class ScriptGlue
return .Ok; return .Ok;
} }
[RegisterCall, CallingConvention(.Cdecl)] [RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
static EngineResult SpriteRenderer_SetColor(UUID entityId, ColorRGBA color) static EngineResult SpriteRenderer_SetColor(UUID entityId, ColorRGBA color)
{ {
SpriteRendererComponent* spriteRenderer = GetComponentOrReturn!<SpriteRendererComponent>(entityId); SpriteRendererComponent* spriteRenderer = GetComponentOrReturn!<SpriteRendererComponent>(entityId);
@@ -1215,7 +1221,7 @@ static class ScriptGlue
return .Ok; return .Ok;
} }
[RegisterCall, CallingConvention(.Cdecl)] [RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
static EngineResult SpriteRenderer_GetUvTransform(UUID entityId, out float4 uvTransform) static EngineResult SpriteRenderer_GetUvTransform(UUID entityId, out float4 uvTransform)
{ {
uvTransform = ?; uvTransform = ?;
@@ -1224,7 +1230,7 @@ static class ScriptGlue
return .Ok; return .Ok;
} }
[RegisterCall, CallingConvention(.Cdecl)] [RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
static EngineResult SpriteRenderer_SetUvTransform(UUID entityId, float4 uvTransform) static EngineResult SpriteRenderer_SetUvTransform(UUID entityId, float4 uvTransform)
{ {
SpriteRendererComponent* spriteRenderer = GetComponentOrReturn!<SpriteRendererComponent>(entityId); SpriteRendererComponent* spriteRenderer = GetComponentOrReturn!<SpriteRendererComponent>(entityId);
@@ -1267,14 +1273,14 @@ static class ScriptGlue
#region TextRenderer #region TextRenderer
[RegisterCall(EngineResultAsBool = true), CallingConvention(.Cdecl)] [RegisterCall(EngineResultAsBool = true, GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
static EngineResult TextRenderer_GetIsRichText(UUID entityId) static EngineResult TextRenderer_GetIsRichText(UUID entityId)
{ {
TextRendererComponent* textComponent = GetComponentOrReturn!<TextRendererComponent>(entityId); TextRendererComponent* textComponent = GetComponentOrReturn!<TextRendererComponent>(entityId);
return textComponent.IsRichText ? .Ok : .False; return textComponent.IsRichText ? .Ok : .False;
} }
[RegisterCall, CallingConvention(.Cdecl)] [RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
static EngineResult TextRenderer_SetIsRichText(UUID entityId, bool isRichText) static EngineResult TextRenderer_SetIsRichText(UUID entityId, bool isRichText)
{ {
TextRendererComponent* textComponent = GetComponentOrReturn!<TextRendererComponent>(entityId); TextRendererComponent* textComponent = GetComponentOrReturn!<TextRendererComponent>(entityId);
@@ -1285,7 +1291,7 @@ static class ScriptGlue
return .Ok; return .Ok;
} }
[RegisterCall, CallingConvention(.Cdecl)] [RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
static EngineResult TextRenderer_GetText(UUID entityId, out StringView text) static EngineResult TextRenderer_GetText(UUID entityId, out StringView text)
{ {
text = ?; text = ?;
@@ -1306,7 +1312,7 @@ static class ScriptGlue
return .Ok; return .Ok;
} }
[RegisterCall, CallingConvention(.Cdecl)] [RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
static EngineResult TextRenderer_GetColor(UUID entityId, out ColorRGBA color) static EngineResult TextRenderer_GetColor(UUID entityId, out ColorRGBA color)
{ {
color = ?; color = ?;
@@ -1316,7 +1322,7 @@ static class ScriptGlue
return .Ok; return .Ok;
} }
[RegisterCall, CallingConvention(.Cdecl)] [RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
static EngineResult TextRenderer_SetColor(UUID entityId, ColorRGBA color) static EngineResult TextRenderer_SetColor(UUID entityId, ColorRGBA color)
{ {
TextRendererComponent* textComponent = GetComponentOrReturn!<TextRendererComponent>(entityId); TextRendererComponent* textComponent = GetComponentOrReturn!<TextRendererComponent>(entityId);
@@ -1326,7 +1332,7 @@ static class ScriptGlue
return .Ok; return .Ok;
} }
[RegisterCall, CallingConvention(.Cdecl)] [RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
static EngineResult TextRenderer_GetHorizontalAlignment(UUID entityId, [GlueParam("out HorizontalTextAlignment")] out HorizontalTextAlignment horizontalAlignment) static EngineResult TextRenderer_GetHorizontalAlignment(UUID entityId, [GlueParam("out HorizontalTextAlignment")] out HorizontalTextAlignment horizontalAlignment)
{ {
horizontalAlignment = ?; horizontalAlignment = ?;
@@ -1335,7 +1341,7 @@ static class ScriptGlue
return .Ok; return .Ok;
} }
[RegisterCall, CallingConvention(.Cdecl)] [RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
static EngineResult TextRenderer_SetHorizontalAlignment(UUID entityId, [GlueParam("HorizontalTextAlignment")] HorizontalTextAlignment horizontalAlignment) static EngineResult TextRenderer_SetHorizontalAlignment(UUID entityId, [GlueParam("HorizontalTextAlignment")] HorizontalTextAlignment horizontalAlignment)
{ {
TextRendererComponent* textComponent = GetComponentOrReturn!<TextRendererComponent>(entityId); TextRendererComponent* textComponent = GetComponentOrReturn!<TextRendererComponent>(entityId);
@@ -1344,7 +1350,7 @@ static class ScriptGlue
return .Ok; return .Ok;
} }
[RegisterCall, CallingConvention(.Cdecl)] [RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
static EngineResult TextRenderer_GetFontSize(UUID entityId, out float fontSize) static EngineResult TextRenderer_GetFontSize(UUID entityId, out float fontSize)
{ {
fontSize = ?; fontSize = ?;
@@ -1353,7 +1359,7 @@ static class ScriptGlue
return .Ok; return .Ok;
} }
[RegisterCall, CallingConvention(.Cdecl)] [RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
static EngineResult TextRenderer_SetFontSize(UUID entityId, float fontSize) static EngineResult TextRenderer_SetFontSize(UUID entityId, float fontSize)
{ {
TextRendererComponent* textComponent = GetComponentOrReturn!<TextRendererComponent>(entityId); TextRendererComponent* textComponent = GetComponentOrReturn!<TextRendererComponent>(entityId);
@@ -1422,25 +1428,25 @@ static class ScriptGlue
#region Math #region Math
[RegisterCall, CallingConvention(.Cdecl)] [RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
static float Math_ModfFloat(float x, out float integerPart) static float Math_ModfFloat(float x, out float integerPart)
{ {
return modf(x, out integerPart); return modf(x, out integerPart);
} }
[RegisterCall, CallingConvention(.Cdecl)] [RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
static float2 Math_ModfFloat2(float2 x, out float2 integerPart) static float2 Math_ModfFloat2(float2 x, out float2 integerPart)
{ {
return modf(x, out integerPart); return modf(x, out integerPart);
} }
[RegisterCall, CallingConvention(.Cdecl)] [RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
static float3 Math_ModfFloat3(float3 x, out float3 integerPart) static float3 Math_ModfFloat3(float3 x, out float3 integerPart)
{ {
return modf(x, out integerPart); return modf(x, out integerPart);
} }
[RegisterCall, CallingConvention(.Cdecl)] [RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
static float4 Math_ModfFloat4(float4 x, out float4 integerPart) static float4 Math_ModfFloat4(float4 x, out float4 integerPart)
{ {
return modf(x, out integerPart); return modf(x, out integerPart);
@@ -1448,7 +1454,7 @@ static class ScriptGlue
#endregion #endregion
[RegisterCall, CallingConvention(.Cdecl)] [RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
static void UUID_Create(out UUID id) static void UUID_Create(out UUID id)
{ {
id = UUID.Create(); id = UUID.Create();
@@ -1456,25 +1462,25 @@ static class ScriptGlue
#region Application #region Application
[RegisterCall, CallingConvention(.Cdecl)] [RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
static bool Application_IsEditor() static bool Application_IsEditor()
{ {
return ScriptEngine.ApplicationInfo.IsEditor; return ScriptEngine.ApplicationInfo.IsEditor;
} }
[RegisterCall, CallingConvention(.Cdecl)] [RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
static bool Application_IsPlayer() static bool Application_IsPlayer()
{ {
return ScriptEngine.ApplicationInfo.IsPlayer; return ScriptEngine.ApplicationInfo.IsPlayer;
} }
[RegisterCall, CallingConvention(.Cdecl)] [RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
static bool Application_IsInEditMode() static bool Application_IsInEditMode()
{ {
return ScriptEngine.ApplicationInfo.IsInEditMode; return ScriptEngine.ApplicationInfo.IsInEditMode;
} }
[RegisterCall, CallingConvention(.Cdecl)] [RegisterCall(GuaranteedShortRunning = true), CallingConvention(.Cdecl)]
static bool Application_IsInPlayMode() static bool Application_IsInPlayMode()
{ {
return ScriptEngine.ApplicationInfo.IsInPlayMode; return ScriptEngine.ApplicationInfo.IsInPlayMode;
@@ -1,6 +1,5 @@
using GlitchyEngine.Core; using GlitchyEngine.Core;
using GlitchyEngine.Scripting; using GlitchyEngine.Scripting;
using Mono;
using System; using System;
using System.Collections; using System.Collections;
using Bon.Integrated; using Bon.Integrated;
@@ -315,7 +314,7 @@ class SerializedObject
Serialize.Value(writer, GetFieldDataAs<double>(field.Data), environment); Serialize.Value(writer, GetFieldDataAs<double>(field.Data), environment);
case .Decimal: case .Decimal:
writer.Type("decimal"); writer.Type("decimal");
Serialize.Value(writer, GetFieldDataAs<MonoDecimal>(field.Data), environment); Serialize.Value(writer, GetFieldDataAs<Decimal>(field.Data), environment);
case .Enum: case .Enum:
writer.Type("Enum"); writer.Type("Enum");
@@ -499,7 +498,7 @@ class SerializedObject
if (reader.inStr.StartsWith('m')) if (reader.inStr.StartsWith('m'))
reader.inStr.RemoveFromStart(1); reader.inStr.RemoveFromStart(1);
MonoDecimal decimalValue = Try!(MonoDecimal.Parse(numberView)); Decimal decimalValue = Try!(Decimal.Parse(numberView));
fieldType = .Decimal; fieldType = .Decimal;
object.SetRawData(fieldType, decimalValue, ref fieldData); object.SetRawData(fieldType, decimalValue, ref fieldData);
@@ -5,7 +5,6 @@ using GlitchyEngine.Core;
using Box2D; using Box2D;
using GlitchyEngine.Content; using GlitchyEngine.Content;
using GlitchyEngine.Scripting; using GlitchyEngine.Scripting;
using Mono;
namespace GlitchyEngine.World namespace GlitchyEngine.World
{ {
-5
View File
@@ -1,5 +0,0 @@
namespace Mono;
class Jit
{
}
@@ -1,9 +0,0 @@
using System;
namespace Mono.Metadata;
class Assembly
{
[LinkName(.C)]
public static extern void mono_set_assemblies_path(char8* path);
}
-601
View File
@@ -1,601 +0,0 @@
using System;
namespace Mono;
static class Mono
{
typealias mono_bool = System.Windows.IntBool;
[LinkName(.C)]
public static extern void mono_set_assemblies_path(char8* path);
[LinkName(.C)]
public static extern MonoDomain* mono_jit_init(char8* file);
[LinkName(.C)]
public static extern void mono_jit_parse_options(int32 argc, char8** argv);
[LinkName(.C)]
public static extern void mono_jit_cleanup(MonoDomain* domain);
[LinkName(.C)]
public static extern MonoDomain* mono_domain_create_appdomain(char8* friendly_name, char8* configuration_file);
[LinkName(.C)]
public static extern mono_bool mono_domain_set(MonoDomain* domain, mono_bool force);
[LinkName(.C)]
public static extern MonoImage* mono_image_open_from_data_full(uint8* data, uint32 data_len,
mono_bool need_copy, MonoImageOpenStatus* status, mono_bool refonly);
[LinkName(.C)]
public static extern MonoImage* mono_assembly_get_image(MonoAssembly* assembly);
[LinkName(.C)]
public static extern void mono_assembly_close(MonoAssembly* assembly);
[LinkName(.C)]
public static extern void mono_image_close(MonoImage* image);
[LinkName(.C)]
public static extern char8* mono_image_strerror(MonoImageOpenStatus status);
[LinkName(.C)]
public static extern MonoAssembly* mono_assembly_load_from_full(MonoImage* image, char8* fileName,
MonoImageOpenStatus* status, mono_bool refonly);
[LinkName(.C)]
public static extern MonoTableInfo* mono_image_get_table_info(MonoImage* image, MonoMetaTableEnum table_id);
[LinkName(.C)]
public static extern int32 mono_image_get_table_rows(MonoImage *image, MonoMetaTableEnum table_id);
[LinkName(.C)]
public static extern int32 mono_table_info_get_rows(MonoTableInfo* table);
[LinkName(.C)]
public static extern void mono_metadata_decode_row (MonoTableInfo* t,
int32 idx,
uint32* res,
int32 res_size);
[LinkName(.C)]
public static extern char8* mono_metadata_string_heap(MonoImage* meta, uint32 table_index);
[LinkName(.C)]
public static extern uint8* mono_metadata_blob_heap(MonoImage* meta, uint32 index);
[LinkName(.C)]
public static extern uint32 mono_metadata_decode_blob_size(uint8* xptr, out uint8* newPosition);
typealias gconstpointer = void*;
typealias gpointer = void*;
[LinkName(.C)]
public static extern void mono_add_internal_call(char8* name, gconstpointer method);
[LinkName(.C)]
public static extern MonoString* mono_string_new(MonoDomain* domain, char8* text);
[LinkName(.C)]
public static extern MonoString* mono_string_new_len(MonoDomain* domain, char8* text, uint32 length);
[LinkName(.C)]
public static extern MonoDomain* mono_domain_get();
[LinkName(.C)]
public static extern MonoClass* mono_class_from_name(MonoImage* image, char8* name_space,
char8* name);
[LinkName(.C)]
public static extern MonoClass* mono_class_from_mono_type(MonoType* type);
[LinkName(.C)]
public static extern char8* mono_class_get_name(MonoClass* monoClass);
[LinkName(.C)]
public static extern MonoType* mono_class_get_type(MonoClass* monoClass);
[LinkName(.C)]
public static extern int32 mono_class_instance_size(MonoClass* @class);
[LinkName(.C)]
public static extern char8* mono_class_get_namespace(MonoClass* monoClass);
[LinkName(.C)]
public static extern MonoImage* mono_class_get_image(MonoClass* monoClass);
[LinkName(.C)]
public static extern MonoClass* mono_class_load_from_name(MonoImage* image, char8* name_space,
char8* name);
[LinkName(.C)]
public static extern MonoObject* mono_object_new(MonoDomain* domain, MonoClass* klass);
[LinkName(.C)]
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)]
public static extern MonoMethod* mono_class_get_method_from_name(MonoClass* klass, char8* name, int param_count);
[LinkName(.C)]
public static extern MonoObject* mono_runtime_invoke(MonoMethod* method, void* obj, void** param, MonoObject** exc);
[LinkName(.C)]
public static extern MonoMethod* mono_object_get_virtual_method(MonoObject* obj, MonoMethod* method);
[LinkName(.C)]
public static extern void* mono_object_unbox(MonoObject* obj);
[LinkName(.C)]
public static extern void* mono_domain_unload(MonoDomain* domain);
[LinkName(.C)]
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)]
public static extern mono_bool mono_class_is_subclass_of(MonoClass *monoClass, MonoClass *parentClass,
mono_bool check_interfaces);
[LinkName(.C)]
public static extern uint32 mono_gchandle_new(MonoObject* obj, mono_bool pinned);
[LinkName(.C)]
public static extern void mono_gchandle_free(uint32 gchandle);
[LinkName(.C)]
public static extern char8* mono_string_to_utf8(MonoString *s);
[LinkName(.C)]
public static extern char8* mono_string_to_utf8_checked(MonoString *s, MonoError* error);
[LinkName(.C)]
public static extern void mono_free(void* ptr);
[LinkName(.C)]
public static extern MonoClassField* mono_class_get_field_from_name(MonoClass* monoClass, char8* name);
[LinkName(.C)]
public static extern void mono_field_set_value(MonoObject* obj, MonoClassField* field, void* value);
[LinkName(.C)]
public static extern MonoType* mono_reflection_type_from_name(char8* name, MonoImage* image);
[LinkName(.C)]
public static extern MonoType* mono_reflection_type_get_type(MonoReflectionType* reflectionType);
[LinkName(.C)]
public static extern MonoReflectionType* mono_type_get_object(MonoDomain *domain, MonoType *type);
[LinkName(.C)]
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)]
public static extern char8* mono_field_get_name(MonoClassField* field);
[LinkName(.C)]
public static extern MonoType* mono_field_get_type(MonoClassField* field);
[LinkName(.C)]
public static extern MonoClass* mono_field_get_parent(MonoClassField* field);
[LinkName(.C)]
public static extern uint32 mono_field_get_flags(MonoClassField* field);
[LinkName(.C)]
public static extern uint8* mono_field_get_data(MonoClassField* field);
[LinkName(.C)]
public static extern void mono_field_get_value(MonoObject* object, MonoClassField* field, void* value);
[LinkName(.C)]
public static extern void mono_field_static_get_value(MonoVTable* vt, MonoClassField* field, void* value);
/// Gets the field as object, boxes the value if it is a valuetype.
[LinkName(.C)]
public static extern MonoObject* mono_field_get_value_object(MonoDomain* domain, MonoClassField* field, MonoObject* obj);
[LinkName(.C)]
public static extern MonoCustomAttrInfo* mono_custom_attrs_from_class(MonoClass *klass);
[LinkName(.C)]
public static extern MonoCustomAttrInfo* mono_custom_attrs_from_field(MonoClass* monoClass, MonoClassField* field);
[LinkName(.C)]
public static extern mono_bool mono_custom_attrs_has_attr(MonoCustomAttrInfo* attributeInfo, MonoClass* attributeClass);
[LinkName(.C)]
public static extern MonoObject* mono_custom_attrs_get_attr(MonoCustomAttrInfo* attributeInfo, MonoClass* attributeClass);
[LinkName(.C)]
public static extern Mono.MonoTypeEnum mono_type_get_type(MonoType* type);
[LinkName(.C)]
public static extern char8* mono_type_get_name(MonoType* type);
[LinkName(.C)]
public static extern char8* mono_type_full_name(MonoType* type);
[LinkName(.C)]
public static extern MonoClass* mono_type_get_class(MonoType* type);
/// MonoError
[LinkName(.C)]
public static extern void mono_error_cleanup(MonoError* error);
[LinkName(.C)]
public static extern mono_bool mono_error_ok(MonoError* error);
[LinkName(.C)]
public static extern char8* mono_error_get_message(MonoError* error);
[LinkName(.C)]
public static extern void mono_debug_init(DebugFormat debugFormat);
[LinkName(.C)]
public static extern void mono_debug_domain_create(MonoDomain* domain);
[LinkName(.C)]
public static extern void mono_debug_domain_unload(MonoDomain* domain);
[LinkName(.C)]
public static extern void mono_debug_open_image_from_memory(MonoImage *image, uint8* raw_contents, int32 size);
[LinkName(.C)]
public static extern void mono_thread_set_main(MonoThread* thread);
[LinkName(.C)]
public static extern MonoThread* mono_thread_current();
#region Property
[LinkName(.C)]
public static extern MonoProperty* mono_class_get_property_from_name(MonoClass *klass, char8* name);
[LinkName(.C)]
public static extern void mono_property_set_value(MonoProperty *prop, void *obj, void **@params, MonoObject **exc);
[LinkName(.C)]
public static extern MonoObject* mono_property_get_value(MonoProperty *prop, void *obj, void** @params, MonoObject** exc);
#endregion
#region Exception
[LinkName(.C), NoReturn]
public static extern void mono_raise_exception(MonoException *ex);
[LinkName(.C)]
public static extern char8* mono_exception_get_managed_backtrace(MonoException* exc);
[LinkName(.C)]
public static extern MonoException* mono_exception_from_name_msg(MonoImage *image, char8* name_space, char8* name, char8* msg);
[LinkName(.C)]
public static extern MonoException* mono_get_exception_argument(char8* arg, char8* msg);
[LinkName(.C)]
public static extern MonoException* mono_get_exception_invalid_operation(char8* msg);
[LinkName(.C)]
public static extern MonoException* mono_get_exception_not_implemented(char8* msg);
#endregion
[LinkName(.C)]
public static extern MonoClass* mono_object_get_class(MonoObject* obj);
[LinkName(.C)]
public static extern mono_bool mono_class_is_enum(MonoClass* @class);
[LinkName(.C)]
public static extern MonoVTable* mono_class_vtable(MonoDomain* domain, MonoClass* @class);
[LinkName(.C)]
public static extern MonoObject* mono_value_box(MonoDomain* domain, MonoClass* klass, gpointer value);
#region MonoArray
typealias uintptr_t = uint;
typealias intptr_t = int;
[LinkName(.C)]
public static extern MonoArray* mono_array_new(MonoDomain *domain, MonoClass *eclass, uintptr_t length);
[LinkName(.C)]
public static extern MonoArray* mono_array_new_checked(MonoDomain *domain, MonoClass *eclass, uintptr_t length, MonoError *error);
[LinkName(.C)]
public static extern MonoArray* mono_array_new_full(MonoDomain *domain, MonoClass *array_class, uintptr_t* lengths, uintptr_t* lower_bounds);
[LinkName(.C)]
public static extern MonoArray* mono_array_new_full_checked(MonoDomain *domain, MonoClass *array_class, uintptr_t* lengths, uintptr_t* lower_bounds, MonoError *error);
[LinkName(.C)]
public static extern void mono_array_full_copy(MonoArray* src, MonoArray* dest);
[LinkName(.C)]
public static extern MonoArray* mono_array_clone(MonoArray* array);
[LinkName(.C)]
public static extern MonoArray* mono_array_clone_checked(MonoArray* array, MonoError* error);
[LinkName(.C)]
public static extern void* mono_array_addr_with_size(MonoArray *array, int32 size, uintptr_t idx);
[LinkName(.C)]
public static extern uintptr_t mono_array_length(MonoArray *array);
[Inline]
public static T* mono_array_addr<T>(MonoArray* array, uintptr_t index)
{
return (T*)mono_array_addr_with_size(array, sizeof(T), index);
}
[Inline]
public static T mono_array_get<T>(MonoArray* array, uintptr_t index)
{
return *mono_array_addr<T>(array, index);
}
[Inline]
public static void mono_array_set<T>(MonoArray* array, uintptr_t index, T value)
{
T* entryPtr = mono_array_addr<T>(array, index);
*entryPtr = value;
}
#endregion
#region DebugHelpers
[LinkName(.C)]
public static extern MonoMethod* mono_method_desc_search_in_class(MonoMethodDesc* desc, MonoClass* klass);
[LinkName(.C)]
public static extern MonoMethodDesc* mono_method_desc_new(char8* name, mono_bool include_namespace);
[LinkName(.C)]
public static extern void mono_method_desc_free(MonoMethodDesc* decs);
#endregion
}
struct MonoMethodDesc;
struct MonoDomain;
struct MonoAssembly;
struct MonoImage;
struct MonoTableInfo;
struct MonoString;
struct MonoClass;
struct MonoObject;
struct MonoMethod;
struct MonoMethodSignature;
struct MonoProperty;
struct MonoThread;
struct MonoVTable;
struct MonoArray;
struct MonoException
{
void* _bla;
void* _bla2;
void* _bla3;
public MonoString* Message;
}
struct MonoClassField;
struct MonoType;
struct MonoError
{
private uint32 bla;
private void*[12] bla2;
}
struct MonoReflectionType;
struct MonoCustomAttrInfo;
enum MonoImageOpenStatus
{
Ok,
Error_Errno,
MissingAssemblyRef,
ImageInvalid
}
enum SOME_RANDOM_ENUM{
MONO_TYPEDEF_FLAGS,
MONO_TYPEDEF_NAME,
MONO_TYPEDEF_NAMESPACE,
MONO_TYPEDEF_EXTENDS,
MONO_TYPEDEF_FIELD_LIST,
MONO_TYPEDEF_METHOD_LIST,
MONO_TYPEDEF_SIZE
}
enum FIELD_TABLE_FLAGS : uint32
{
MONO_FIELD_FLAGS,
MONO_FIELD_NAME,
MONO_FIELD_SIGNATURE,
MONO_FIELD_SIZE
}
enum MonoMetaTableEnum : int32
{
MONO_TABLE_MODULE,
MONO_TABLE_TYPEREF,
MONO_TABLE_TYPEDEF,
MONO_TABLE_FIELD_POINTER,
MONO_TABLE_FIELD,
MONO_TABLE_METHOD_POINTER,
MONO_TABLE_METHOD,
MONO_TABLE_PARAM_POINTER,
MONO_TABLE_PARAM,
MONO_TABLE_INTERFACEIMPL,
MONO_TABLE_MEMBERREF, /* 0xa */
MONO_TABLE_CONSTANT,
MONO_TABLE_CUSTOMATTRIBUTE,
MONO_TABLE_FIELDMARSHAL,
MONO_TABLE_DECLSECURITY,
MONO_TABLE_CLASSLAYOUT,
MONO_TABLE_FIELDLAYOUT, /* 0x10 */
MONO_TABLE_STANDALONESIG,
MONO_TABLE_EVENTMAP,
MONO_TABLE_EVENT_POINTER,
MONO_TABLE_EVENT,
MONO_TABLE_PROPERTYMAP,
MONO_TABLE_PROPERTY_POINTER,
MONO_TABLE_PROPERTY,
MONO_TABLE_METHODSEMANTICS,
MONO_TABLE_METHODIMPL,
MONO_TABLE_MODULEREF, /* 0x1a */
MONO_TABLE_TYPESPEC,
MONO_TABLE_IMPLMAP,
MONO_TABLE_FIELDRVA,
MONO_TABLE_ENCLOG,
MONO_TABLE_ENCMAP,
MONO_TABLE_ASSEMBLY, /* 0x20 */
MONO_TABLE_ASSEMBLYPROCESSOR,
MONO_TABLE_ASSEMBLYOS,
MONO_TABLE_ASSEMBLYREF,
MONO_TABLE_ASSEMBLYREFPROCESSOR,
MONO_TABLE_ASSEMBLYREFOS,
MONO_TABLE_FILE,
MONO_TABLE_EXPORTEDTYPE,
MONO_TABLE_MANIFESTRESOURCE,
MONO_TABLE_NESTEDCLASS,
MONO_TABLE_GENERICPARAM, /* 0x2a */
MONO_TABLE_METHODSPEC,
MONO_TABLE_GENERICPARAMCONSTRAINT,
MONO_TABLE_UNUSED8,
MONO_TABLE_UNUSED9,
MONO_TABLE_UNUSED10,
/* Portable PDB tables */
MONO_TABLE_DOCUMENT, /* 0x30 */
MONO_TABLE_METHODBODY,
MONO_TABLE_LOCALSCOPE,
MONO_TABLE_LOCALVARIABLE,
MONO_TABLE_LOCALCONSTANT,
MONO_TABLE_IMPORTSCOPE,
MONO_TABLE_STATEMACHINEMETHOD,
MONO_TABLE_CUSTOMDEBUGINFORMATION
//#define MONO_TABLE_LAST MONO_TABLE_CUSTOMDEBUGINFORMATION
//#define MONO_TABLE_NUM (MONO_TABLE_LAST + 1)
}
enum DebugFormat : uint32
{
None,
Mono,
/** Deprecated, the mdb debugger is not longer supported. */
Debugger
}
enum FieldAttribute
{
FieldAccessMask = 0x0007,
CompilerControlled = 0x0000,
Private = 0x0001,
FamAndAssem = 0x0002,
Assembly = 0x0003,
Family = 0x0004,
FamOrAssem = 0x0005,
Public = 0x0006,
Static = 0x0010,
InitOnly = 0x0020,
Literal = 0x0040,
NotSerialized = 0x0080,
SpecialName = 0x0200,
PinvokeImpl = 0x2000,
/** For runtime use only */
ReservedMask = 0x9500,
/** For runtime use only */
RtSpecialName = 0x0400,
/** For runtime use only */
HasFieldMarshal = 0x1000,
/** For runtime use only */
HasDefault = 0x8000,
/** For runtime use only */
HasFieldRva = 0x0100
}
enum MonoTypeEnum : int32
{
End = 0x00, /* End of List */
Void = 0x01,
Boolean = 0x02,
Char = 0x03,
I1 = 0x04,
U1 = 0x05,
I2 = 0x06,
U2 = 0x07,
I4 = 0x08,
U4 = 0x09,
I8 = 0x0a,
U8 = 0x0b,
R4 = 0x0c,
R8 = 0x0d,
String = 0x0e,
Ptr = 0x0f, /* arg: <type> token */
Byref = 0x10, /* arg: <type> token */
Valuetype = 0x11, /* arg: <type> token */
Class = 0x12, /* arg: <type> token */
Var = 0x13, /* number */
Array = 0x14, /* type, rank, boundsCount, bound1, loCount, lo1 */
Genericinst = 0x15, /* <type> <type-arg-count> <type-1> \x{2026} <type-n> */
Typedbyref = 0x16,
I = 0x18,
U = 0x19,
Fnptr = 0x1b, /* arg: full method signature */
Object = 0x1c,
SzArray = 0x1d, /* 0-based one-dim-array */
Mvar = 0x1e, /* number */
CmodReqd = 0x1f, /* arg: typedef or typeref token */
CmodOpt = 0x20, /* optional arg: typedef or typref token */
Internal = 0x21, /* CLR internal type */
Modifier = 0x40, /* Or with the following types */
Sentinel = 0x41, /* Sentinel for varargs method signature */
Pinned = 0x45, /* Local var that points to pinned object */
Enum = 0x55 /* an enumeration */
}
+1 -1
View File
@@ -21,7 +21,7 @@ public partial class Entity : EngineObject
/// </summary> /// </summary>
public string Name public string Name
{ {
get => "TODO!";//ScriptGlue.Entity_GetName(_uuid); get => ScriptGlue.Entity_GetName(_uuid);
set => ScriptGlue.Entity_SetName(_uuid, value); set => ScriptGlue.Entity_SetName(_uuid, value);
} }
+24 -18
View File
@@ -18,6 +18,12 @@ using System.Text;
using System.Threading; using System.Threading;
using System.Xml.Linq; using System.Xml.Linq;
// This attribute is NOT optional, removing it silently breaks every engine function that takes or returns a bool!
// With runtime marshalling enabled the CLR treats bool in an unmanaged function pointer as a 4-byte Win32 BOOL and checks all of eax,
// but Beef only writes al (1 byte). The upper bytes are garbage, so the result is (almost) always true. Everything would still compile.
// The price: in/ref/out are not allowed in unmanaged signatures of this assembly, which is why the generator emits raw pointers and pins with fixed.
[assembly: DisableRuntimeMarshalling]
namespace GlitchyEngine; namespace GlitchyEngine;
/// <summary> /// <summary>
@@ -679,6 +685,15 @@ internal static unsafe partial class ScriptGlue
} }
} }
/// <summary>
/// Layout stand-in to get a reference to the contents of a boxed value type via <see cref="Unsafe.As{T}(object)"/>.
/// Never instantiated.
/// </summary>
private sealed class RawData
{
public byte Data;
}
public static void Serialization_SerializeField(IntPtr serializationContext, SerializationType type, string fieldName, object? valueObject, string? fullTypeName) public static void Serialization_SerializeField(IntPtr serializationContext, SerializationType type, string fieldName, object? valueObject, string? fullTypeName)
{ {
StringView fieldNameConverted; StringView fieldNameConverted;
@@ -730,7 +745,7 @@ internal static unsafe partial class ScriptGlue
nativeString = new StringView(pointer, bytes); nativeString = new StringView(pointer, bytes);
} }
_engineFunctions.Serialization_SerializeField((void*)serializationContext, type, fieldNameConverted, &nativeString, fullTypeNameConverted); _engineFunctions.Serialization_SerializeField((void*)serializationContext, type, &fieldNameConverted, &nativeString, &fullTypeNameConverted);
if (onHeap) if (onHeap)
StringView.FreeNativeMemory(nativeString); StringView.FreeNativeMemory(nativeString);
@@ -738,25 +753,16 @@ internal static unsafe partial class ScriptGlue
default: default:
if (valueObject is not null) if (valueObject is not null)
{ {
// This is probably the dirtiest piece of C# Code, that I have ever seen. // valueObject is a boxed value type. An object reference points to the method table pointer, the boxed value starts right behind it.
// We first take a pointer the Object (which itself is a reference type -> object* is a double pointer!) // That's exactly where the first field of RawData lives, so reinterpreting the box gives us a reference to the first byte of the value.
// We then dereference this double pointer, which gives us a pointer to the objects internals. // We have to pin it: During the native call this thread is in preemptive mode and a GC is free to move the box.
// These are Header (64bit), Method Table (64bit), and the objects content (at least another 64bit) fixed (byte* valueRef = &Unsafe.As<RawData>(valueObject).Data)
// I believe, that the actual reference points to the method table however and not the header (compare gcenv.object.h) {
// Below we calculate a pointer to the objects contents by adding the size of a pointer. _engineFunctions.Serialization_SerializeField((void*)serializationContext, type, &fieldNameConverted, valueRef, &fullTypeNameConverted);
}
#pragma warning disable CS8500 // This takes the address of, gets the size of, or declares a pointer to a managed type
object?* objectRef = &valueObject;
// Skip Object Header (IntPtr) + Method Table (IntPtr)
byte* valueRef = (byte*)*(IntPtr*)objectRef + sizeof(IntPtr);
float* fRef = (float*)(void*)valueRef;
_engineFunctions.Serialization_SerializeField((void*)serializationContext, type, fieldNameConverted, valueRef, fullTypeNameConverted);
} }
break; break;
} }
//StringView.FreeNativeMemory(fieldNameConverted);
//StringView.FreeNativeMemory(fullTypeNameConverted);
} }
public static void Serialization_SerializeValueType<T>(IntPtr serializationContext, SerializationType type, string fieldName, in T value, string? fullTypeName) where T : unmanaged public static void Serialization_SerializeValueType<T>(IntPtr serializationContext, SerializationType type, string fieldName, in T value, string? fullTypeName) where T : unmanaged
@@ -782,7 +788,7 @@ internal static unsafe partial class ScriptGlue
fixed (T* valuePtr = &value) fixed (T* valuePtr = &value)
{ {
_engineFunctions.Serialization_SerializeField((void*)serializationContext, type, fieldNameConverted, valuePtr, fullTypeNameConverted); _engineFunctions.Serialization_SerializeField((void*)serializationContext, type, &fieldNameConverted, valuePtr, &fullTypeNameConverted);
} }
} }
@@ -324,7 +324,9 @@ public class DeserializationObject
return deserializedValue; return deserializedValue;
} }
if (fieldType.IsPrimitive) // Decimals are not actually primitives, but we treat them as if they were, because they are a built-in type
// and it makes more sense to send them over to the engine as a binary type than to serialize their underlying fields (which would happen when we treated them as a struct).
if (fieldType.IsPrimitive || fieldType == typeof(decimal))
{ {
return DeserializePrimitive(fieldName, fieldType); return DeserializePrimitive(fieldName, fieldType);
} }
@@ -364,7 +366,7 @@ public class DeserializationObject
public object? DeserializePrimitive(string fieldName, Type fieldType) public object? DeserializePrimitive(string fieldName, Type fieldType)
{ {
Debug.Assert(fieldType.IsPrimitive, $"{fieldType} is not a primitive type."); Debug.Assert(fieldType.IsPrimitive || fieldType == typeof(decimal), $"{fieldType} is not a primitive type.");
SerializationType expectedType = SerializationType.None; SerializationType expectedType = SerializationType.None;
@@ -176,6 +176,8 @@ public class SerializedObject
public void SerializeField(string fieldName, object? fieldValue, Type fieldType) public void SerializeField(string fieldName, object? fieldValue, Type fieldType)
{ {
// Decimals are not actually primitives, but we treat them as if they were, because they are a built-in type
// and it makes more sense to send them over to the engine as a binary type than to serialize their underlying fields (which would happen when we treated them as a struct).
if (fieldType.IsPrimitive || fieldType == typeof(decimal)) if (fieldType.IsPrimitive || fieldType == typeof(decimal))
{ {
// Primitives can't be null // Primitives can't be null
+74 -42
View File
@@ -9,8 +9,11 @@ using System.Text.Json;
using System.Text.Json.Serialization; using System.Text.Json.Serialization;
using System.Threading; using System.Threading;
using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.CSharp.Syntax;
using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory;
namespace ScriptCoreGenerator; namespace ScriptCoreGenerator;
internal class GlueMethod internal class GlueMethod
@@ -19,6 +22,8 @@ internal class GlueMethod
public string Name { get; set; } public string Name { get; set; }
[JsonPropertyName("return_type")] [JsonPropertyName("return_type")]
public string ReturnType { get; set; } public string ReturnType { get; set; }
[JsonPropertyName("guaranteed_short_running")]
public bool GuaranteedShortRunning { get; set; }
[JsonPropertyName("parameters")] [JsonPropertyName("parameters")]
public List<Parameter> Parameters { get; set; } public List<Parameter> Parameters { get; set; }
@@ -292,23 +297,13 @@ public class ScriptGlueGenerator : IIncrementalGenerator
var (parameterType, parameterModifier) = DecodeType(param.Type, beefTypeToMappedType); var (parameterType, parameterModifier) = DecodeType(param.Type, beefTypeToMappedType);
parameters.Add(parameterType); parameters.Add(parameterType);
switch (parameterModifier)
{
case TypeModifier.In:
parameterText.Append("in ");
break;
case TypeModifier.Out:
parameterText.Append("out ");
break;
case TypeModifier.Ref:
parameterText.Append("ref ");
break;
}
parameterText.Append(parameterType.CSharpTypeName); parameterText.Append(parameterType.CSharpTypeName);
switch (parameterModifier) switch (parameterModifier)
{ {
case TypeModifier.In:
case TypeModifier.Out:
case TypeModifier.Ref:
case TypeModifier.Pointer: case TypeModifier.Pointer:
parameterText.Append("*"); parameterText.Append("*");
break; break;
@@ -317,17 +312,35 @@ public class ScriptGlueGenerator : IIncrementalGenerator
parameterText.Append(", "); parameterText.Append(", ");
} }
output.AppendLine($" public delegate* unmanaged[Cdecl]<{parameterText}{returnType.CSharpTypeName}> {method.Name};"); string callingConvention = "Cdecl";
#if !DEBUG
// Normally when calling into unmanaged code the current thread transitions
// from cooperative GC mode (all threads block for GC collection) to preemtive (other threads can gc independently from us).
// This is done to prevent long running native code (e.g. native code opens a message box) from blocking all threads because
// they wait for GC to happen, which can lead to problems. If we know however that the called native function is very short
// (short than the GC transition itself) then we can explicitly prevent the suppression.
// We rely on the engine (ScriptGlue.bf) to tell us that information.
//
// A GuaranteedShortRunning function should have a VERY short runtime (< 1μs), must NEVER block, and NEVER call back into managed code!
//
// We only enable it in release builds, as it will prevent the mixed mode debugger from stepping over the managed-native-border.
if (method.GuaranteedShortRunning)
{
callingConvention += ", SuppressGCTransition";
}
#endif
output.AppendLine($" public delegate* unmanaged[{callingConvention}]<{parameterText}{returnType.CSharpTypeName}> {method.Name};");
} }
private static void GenerateWrapper(GlueMethod method, Dictionary<string, MappedType> beefTypeToMappedType, StringBuilder output) private static void GenerateWrapper(GlueMethod method, Dictionary<string, MappedType> beefTypeToMappedType, StringBuilder output)
{ {
// MappedType returnType = DecodeType(method.ReturnType, beefTypeToMappedType);
//
List<MappedType> parameters = new(); List<MappedType> parameters = new();
StringBuilder parameterText = new(); StringBuilder parameterText = new();
StringBuilder parameterConversion = new(); List<string> parameterConversions = new();
StringBuilder cleanup = new(); List<string> cleanups = new();
List<string> afterReturnCleanups = new();
StringBuilder call = new(); StringBuilder call = new();
var (returnType, _) = DecodeType(method.ReturnType, beefTypeToMappedType); var (returnType, _) = DecodeType(method.ReturnType, beefTypeToMappedType);
@@ -370,33 +383,31 @@ public class ScriptGlueGenerator : IIncrementalGenerator
parameterText.Append($" {param.Name}"); parameterText.Append($" {param.Name}");
switch (parameterModifier)
{
case TypeModifier.In:
call.Append("in ");
break;
case TypeModifier.Out:
call.Append("out ");
break;
case TypeModifier.Ref:
call.Append("ref ");
break;
}
if (parameterModifier == TypeModifier.Out && parameterType.WrapperOutConversion is not null) if (parameterModifier == TypeModifier.Out && parameterType.WrapperOutConversion is not null)
{ {
string tmpArgName = $"{param.Name}Tmp"; string tmpArgName = $"{param.Name}Tmp";
call.Append($"var {tmpArgName}"); call.Append($"&{tmpArgName}");
cleanup.Append("\t\t"); parameterConversions.Add($"{parameterType.CSharpTypeName} {tmpArgName} = default;");
cleanup.AppendFormat(parameterType.WrapperOutConversion, tmpArgName, param.Name); cleanups.Add(string.Format(parameterType.WrapperOutConversion, tmpArgName, param.Name));
cleanup.AppendLine();
} }
else if (parameterType.WrapperConvertInput is not null) else if (parameterType.WrapperConvertInput is not null)
{ {
switch (parameterModifier)
{
case TypeModifier.In:
case TypeModifier.Out:
case TypeModifier.Ref:
case TypeModifier.Pointer:
call.Append("&");
break;
}
string convertedParamName = $"{param.Name}Converted"; string convertedParamName = $"{param.Name}Converted";
StringBuilder parameterConversion = new();
StringBuilder cleanup = new();
parameterConversion.AppendLine(); parameterConversion.AppendLine();
parameterConversion.Append("\t\t"); parameterConversion.Append("\t\t");
parameterConversion.AppendFormat(parameterType.WrapperConvertInput, convertedParamName, param.Name); parameterConversion.AppendFormat(parameterType.WrapperConvertInput, convertedParamName, param.Name);
@@ -409,23 +420,40 @@ public class ScriptGlueGenerator : IIncrementalGenerator
} }
call.Append(convertedParamName); call.Append(convertedParamName);
parameterConversions.Add(parameterConversion.ToString());
cleanups.Add(cleanup.ToString());
} }
else else
{ {
call.Append(param.Name); string paramName = param.Name;
switch (parameterModifier)
{
case TypeModifier.In:
case TypeModifier.Out:
case TypeModifier.Ref:
paramName = "__" + param.Name + "FixedPtr";
parameterConversions.Add($"fixed ({parameterType.CSharpTypeName}* {paramName} = &{param.Name}) {{");
afterReturnCleanups.Add("}");
break;
}
call.Append(paramName);
} }
} }
call.Append(");"); call.Append(");");
output.AppendLine($$""" output.AppendLine(
$$"""
public static {{returnType.CSharpWrapperType}} {{method.Name}}({{parameterText}}) public static {{returnType.CSharpWrapperType}} {{method.Name}}({{parameterText}})
{{{parameterConversion}} {
{{string.Join("\n", parameterConversions)}}
{{call}} {{call}}
{{cleanup}} {{string.Join("\n", Enumerable.Reverse(cleanups))}}
{{returnType.ReturnValueConversion}} {{returnType.ReturnValueConversion}}
{{string.Join("\n", afterReturnCleanups)}}
} }
"""); """);
@@ -470,6 +498,7 @@ public class ScriptGlueGenerator : IIncrementalGenerator
unsafe internal partial struct EngineFunctions unsafe internal partial struct EngineFunctions
{ {
"""); """);
wrappers.Append(""" wrappers.Append("""
@@ -483,6 +512,7 @@ public class ScriptGlueGenerator : IIncrementalGenerator
internal static unsafe partial class ScriptGlue internal static unsafe partial class ScriptGlue
{ {
"""); """);
List<GlueMethod> methods = new List<GlueMethod>(); List<GlueMethod> methods = new List<GlueMethod>();
@@ -505,11 +535,13 @@ public class ScriptGlueGenerator : IIncrementalGenerator
} }
} }
engineFunctions.Append("\n}"); engineFunctions.Append("}");
wrappers.Append("\n}"); wrappers.Append("\n}");
var parsedWrappers = ParseCompilationUnit(wrappers.ToString());
context.AddSource("EngineFunctions.g.cs", engineFunctions.ToString()); context.AddSource("EngineFunctions.g.cs", engineFunctions.ToString());
context.AddSource("ScriptGlue.g.cs", wrappers.ToString()); context.AddSource("ScriptGlue.g.cs", parsedWrappers.NormalizeWhitespace().ToFullString());
} }
private static bool IsScriptGlueClass( private static bool IsScriptGlueClass(