Skip to content
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/workflows/vcpkg_restore.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,10 @@ jobs:

- name: Install nethost
run: vcpkg install nethost:x64-windows-release

- name: Install scintilla
run: vcpkg install scintilla:x64-windows-release

- name: Install lexilla
run: vcpkg install lexilla:x64-windows-release

8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -392,3 +392,11 @@ desktop.ini
out/
3DRadSpace/Data/RecentProjects.txt
3DRadSpace/3DRadSpace_Editor_WindowsDX11/RCa07792
/3DRadSpace/3DRadSpace_Editor_WindowsDX11/RCa05476
/3DRadSpace/3DRadSpace_Editor_WindowsDX11/RCa10992
/3DRadSpace/3DRadSpace_Editor_WindowsDX11/RCb05476
/3DRadSpace/3DRadSpace_Editor_WindowsDX11/RCb10992
/3DRadSpace/3DRadSpace_Editor_WindowsDX11/RCc05476
/3DRadSpace/3DRadSpace_Editor_WindowsDX11/RCd05476
/3DRadSpace/3DRadSpace_Editor_WindowsDX11/RCe05476
/3DRadSpace/3DRadSpace_Editor_WindowsDX11/RCf05476
7 changes: 6 additions & 1 deletion 3DRadSpace/3DRadSpace.slnx
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
<Solution />
<Solution>
<Configurations>
<Platform Name="x64" />
</Configurations>
<Project Path="Dummy/Dummy.vcxproj" Id="d87f5240-7a4a-fb1f-f513-330b76252c7e" />
</Solution>
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ using namespace Engine3DRadSpace::Math;
void AngelScriptWrapper_MessageCallback(const asSMessageInfo* msg, void* param)
{
if(msg->type == asMSGTYPE_WARNING)
SetLastWarning(std::format("({}, {}) : Warning {}", msg->section, msg->row, msg->col, msg->message));
PrintWarning(std::format("({}, {}) : Warning {}", msg->section, msg->row, msg->col, msg->message));
else if(msg->type == asMSGTYPE_INFORMATION)
SetLastMessage(std::format("({}, {}) : Information {}", msg->section, msg->row, msg->col, msg->message));
PrintMessage(std::format("({}, {}) : Information {}", msg->section, msg->row, msg->col, msg->message));
if(msg->type == asMSGTYPE_ERROR)
SetLastWarning(std::format("({}, {}) : Error {}", msg->section, msg->row, msg->col, msg->message));
PrintWarning(std::format("({}, {}) : Error {}", msg->section, msg->row, msg->col, msg->message));
}

static void v2ctor_def(Vector2* self)
Expand Down
3 changes: 3 additions & 0 deletions 3DRadSpace/3DRadSpace_CSharp/3DRadSpace_CSharp.slnx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<Solution>
<Project Path="3DRadSpace_CSharp.csproj" />
</Solution>
79 changes: 67 additions & 12 deletions 3DRadSpace/3DRadSpace_CSharp/Internal/ScriptManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static int LoadScript(IntPtr scriptPath, IntPtr className, IntPtr ownerOb

if (string.IsNullOrEmpty(path) || string.IsNullOrEmpty(classNameStr))
{
SetWarning("Invalid script path or class name");
PrintWarning("Invalid script path or class name");
return -1;
}

Expand All @@ -38,7 +38,7 @@ public static int LoadScript(IntPtr scriptPath, IntPtr className, IntPtr ownerOb
if (!result.Success)
{
string errors = string.Join("\n", result.Errors);
SetWarning($"Script compilation failed:\n{errors}");
PrintWarning($"Script compilation failed:\n{errors}");
return -1;
}

Expand All @@ -50,14 +50,14 @@ public static int LoadScript(IntPtr scriptPath, IntPtr className, IntPtr ownerOb
}
catch (Exception ex)
{
SetWarning($"Failed to create instance: {ex.Message}");
PrintWarning($"Failed to create instance: {ex.Message}");
result.Unload();
return -1;
}

if (instance == null)
{
SetWarning("Failed to create script instance");
PrintWarning("Failed to create script instance");
result.Unload();
return -1;
}
Expand All @@ -82,7 +82,7 @@ public static int LoadScript(IntPtr scriptPath, IntPtr className, IntPtr ownerOb
}
catch (Exception ex)
{
SetWarning($"Exception in LoadScript: {ex.Message}");
PrintWarning($"Exception in LoadScript: {ex.Message}");
return -1;
}
}
Expand All @@ -105,7 +105,7 @@ public static byte UpdateScript(int scriptId)
}
catch(Exception ex)
{
SetWarning($"Exception in UpdateScript: {ex.Message}");
PrintWarning($"Exception in UpdateScript: {ex.Message}");
return 0;
}
}
Expand Down Expand Up @@ -167,10 +167,10 @@ public static byte InvokeScriptMethod(int scriptId, IntPtr methodName)
/// <summary>
/// Sets a warning message in the engine's logging system.
/// </summary>
private static void SetWarning(string message)
private static void PrintWarning(string message)
{
var warning = new Warning(message, 0, 1, IntPtr.Zero);
Warning.SetLastWarning(ref warning);
Warning.PrintWarning(ref warning);
}

private class ScriptInstance
Expand Down Expand Up @@ -216,10 +216,65 @@ public static int LoadScriptFromSource(string source, string className)
return scriptId;
}

/// <summary>
/// Gets the script instance by ID (for use from managed code).
/// </summary>
public static object? GetScriptInstance(int scriptId)
[UnmanagedCallersOnly]
public static byte CompileScript(IntPtr scriptPath, IntPtr className)
Comment thread
NicusorN5 marked this conversation as resolved.
{
try
{
string? path = Marshal.PtrToStringUTF8(scriptPath);
string? classNameStr = Marshal.PtrToStringUTF8(className);

if (string.IsNullOrEmpty(path) || string.IsNullOrEmpty(classNameStr))
{
PrintWarning("Invalid script path or class name");
return 0;
}

var result = CsCompiler.CompileFromFile(path);

if (!result.Success)
{
string errors = string.Join("\n", result.Errors);
PrintWarning($"Script compilation failed:\n{errors}");
result.Unload();
return 0;
}

// Try to create an instance
object? instance;
try
{
instance = result.CreateInstance(classNameStr);
}
catch (Exception ex)
{
PrintWarning($"Failed to create instance: {ex.Message}");
result.Unload();
return 0;
}

if (instance == null)
{
PrintWarning("Failed to create script instance");
result.Unload();
return 0;
}

result.Unload();
}
catch (Exception ex)
{
PrintWarning($"Exception in CompileScript: {ex.Message}");
return 0;
}

return 1;
Comment thread
NicusorN5 marked this conversation as resolved.
}

/// <summary>
/// Gets the script instance by ID (for use from managed code).
/// </summary>
public static object? GetScriptInstance(int scriptId)
{
return _loadedScripts.TryGetValue(scriptId, out var instance) ? instance.Instance : null;
}
Expand Down
4 changes: 2 additions & 2 deletions 3DRadSpace/3DRadSpace_CSharp/Logging/Message.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ public Message(string details, int code, IntPtr extra)
Extra = extra;
}

[DllImport("3DRadSpace.FFI.dll", CharSet = CharSet.Ansi, EntryPoint = "E3DRSP_SetLastMessage")]
public extern static void SetLastMessage(ref Message msg);
[DllImport("3DRadSpace.FFI.dll", CharSet = CharSet.Ansi, EntryPoint = "E3DRSP_PrintMessage")]
public extern static void PrintMessage(ref Message msg);
}
4 changes: 2 additions & 2 deletions 3DRadSpace/3DRadSpace_CSharp/Logging/Warning.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ public Warning(string details, int code, int severity, IntPtr extra)
Extra = extra;
}

[DllImport("3DRadSpace.FFI.dll", CharSet = CharSet.Ansi, EntryPoint = "E3DRSP_SetLastWarning")]
public extern static void SetLastWarning(ref Warning wrn);
[DllImport("3DRadSpace.FFI.dll", CharSet = CharSet.Ansi, EntryPoint = "E3DRSP_PrintWarning")]
public extern static void PrintWarning(ref Warning wrn);
}
87 changes: 87 additions & 0 deletions 3DRadSpace/3DRadSpace_CSharp/Physics/ICharacterController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
using System.Numerics;
using System.Runtime.InteropServices;

namespace Engine3DRadSpace.Physics;

public class ICharacterController : ICollider
{
[DllImport("3DRadSpace.FFI.dll", EntryPoint = "E3DRSP_ICharacterController_Move")]
private static extern void _move(IntPtr controller, ref Vector3 displacement);

[DllImport("3DRadSpace.FFI.dll", EntryPoint = "E3DRSP_ICharacterController_Jump")]
private static extern void _jump(IntPtr controller, float height);

[DllImport("3DRadSpace.FFI.dll", EntryPoint = "E3DRSP_ICharacterController_GetHeight")]
private static extern float _getHeight(IntPtr controller);

[DllImport("3DRadSpace.FFI.dll", EntryPoint = "E3DRSP_ICharacterController_SetHeight")]
private static extern void _setHeight(IntPtr controller, float height);

[DllImport("3DRadSpace.FFI.dll", EntryPoint = "E3DRSP_ICharacterController_GetRadius")]
private static extern float _getRadius(IntPtr controller);

[DllImport("3DRadSpace.FFI.dll", EntryPoint = "E3DRSP_ICharacterController_SetRadius")]
private static extern void _setRadius(IntPtr controller, float radius);

[DllImport("3DRadSpace.FFI.dll", EntryPoint = "E3DRSP_ICharacterController_SetMaxSlopeAngle")]
private static extern void _setMaxSlopeAngle(IntPtr controller, float angle);

[DllImport("3DRadSpace.FFI.dll", EntryPoint = "E3DRSP_ICharacterController_GetMaxSlopeAngle")]
private static extern float _getMaxSlopeAngle(IntPtr controller);

[DllImport("3DRadSpace.FFI.dll", EntryPoint = "E3DRSP_ICharacterController_SetGravity")]
private static extern void _setGravity(IntPtr controller, ref Vector3 gravity);

[DllImport("3DRadSpace.FFI.dll", EntryPoint = "E3DRSP_ICharacterController_GetGravity")]
private static extern Vector3 _getGravity(IntPtr controller);

[DllImport("3DRadSpace.FFI.dll", EntryPoint = "E3DRSP_ICharacterController_IsGrounded")]
[return: MarshalAs(UnmanagedType.I1)]
private static extern bool _isGrounded(IntPtr controller);

[DllImport("3DRadSpace.FFI.dll", EntryPoint = "E3DRSP_ICharacterController_Destroy")]
private static extern void _destroy(IntPtr controller);

public void Move(Vector3 displacement)
{
_move(_handle, ref displacement);
}

public void Jump(float height)
{
_jump(_handle, height);
}

public float Height
{
get => _getHeight(_handle);
set => _setHeight(_handle, value);
}

public float Radius
{
get => _getRadius(_handle);
set => _setRadius(_handle, value);
}

public float MaxSlopeAngle
{
get => _getMaxSlopeAngle(_handle);
set => _setMaxSlopeAngle(_handle, value);
}

public Vector3 Gravity
{
get => _getGravity(_handle);
set => _setGravity(_handle, ref value);
}

public bool IsGrounded()
{
return _isGrounded(_handle);
}

public ICharacterController(IntPtr natPtr) : base(natPtr, _destroy)
{
}
}
28 changes: 28 additions & 0 deletions 3DRadSpace/3DRadSpace_CSharp/Physics/ICollider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ public class ICollider : NatPtrWrapper
[DllImport("3DRadSpace.FFI.dll", EntryPoint = "E3DRSP_ICollider_Intersects")]
private static extern float _intersects(IntPtr collider, ref Ray r);

[DllImport("3DRadSpace.FFI.dll", EntryPoint = "E3DRSP_ICollider_UpdateTransform")]
private static extern void _updateTransform(IntPtr collider);

[DllImport("3DRadSpace.FFI.dll", EntryPoint = "E3DRSP_ICollider_UpdateTransform2")]
private static extern void _updateTransform2(IntPtr collider, ref Vector3 position, ref Quaternion rotation);

[DllImport("3DRadSpace.FFI.dll", EntryPoint = "E3DRSP_ICollider_Destroy")]
private static extern void _destroy(IntPtr collider);

Expand All @@ -95,6 +101,18 @@ public float Mass
set => _setMass(_handle, value);
}

public Vector3 Position
{
get => _getPosition(_handle);
set => _setPosition(_handle, ref value);
}

public Quaternion Rotation
{
get => _getRotation(_handle);
set => _setRotation(_handle, ref value);
}

public float LinearDamping
{
get => _getLinearDamping(_handle);
Expand Down Expand Up @@ -179,6 +197,16 @@ public bool ApplyAngularAcceleration(Vector3 acc)
return float.IsNaN(result) ? null : result;
}

public void UpdateTransform()
{
_updateTransform(_handle);
}

public void UpdateTransform(Vector3 position, Quaternion rotation)
{
_updateTransform2(_handle, ref position, ref rotation);
}

public ICollider(IntPtr natPtr) : base(natPtr, _destroy)
{
}
Expand Down
Loading
Loading