summaryrefslogtreecommitdiff
path: root/Djup.Native/src/LibDjup.cs
diff options
context:
space:
mode:
authorJoel Stålnacke <joel@saker.fi>2026-03-23 19:50:18 +0200
committerJoel Stålnacke <joel@saker.fi>2026-03-23 19:50:18 +0200
commit3a1f9fe6800ef5fe7bbf1c0a5976720383ba84fe (patch)
treef1218eb4085a654f6bb70671b41b4a74e646c052 /Djup.Native/src/LibDjup.cs
parent3870982f640260822bf605e693782ce9f5d79cf6 (diff)
Rewrite native code in Odin and use ECSodin
Diffstat (limited to 'Djup.Native/src/LibDjup.cs')
-rw-r--r--Djup.Native/src/LibDjup.cs74
1 files changed, 43 insertions, 31 deletions
diff --git a/Djup.Native/src/LibDjup.cs b/Djup.Native/src/LibDjup.cs
index 4cd99f8..864f330 100644
--- a/Djup.Native/src/LibDjup.cs
+++ b/Djup.Native/src/LibDjup.cs
@@ -5,50 +5,62 @@ namespace Djup.Native;
public static partial class LibDjup
{
const string LibraryName = "djup";
- const string Prefix = "dp_";
- [LibraryImport(LibraryName, EntryPoint = Prefix + nameof(hello_world))]
- public static partial void hello_world();
+ [LibraryImport(LibraryName, EntryPoint = nameof(vec2_dot))]
+ public static partial Vec2 vec2_dot(Vec2 a, Vec2 b);
- [LibraryImport(LibraryName, EntryPoint = Prefix + nameof(get_num))]
- public static partial int get_num();
+ [LibraryImport(LibraryName, EntryPoint = nameof(vec2_length))]
+ public static partial float vec2_length(Vec2 v);
- [LibraryImport(LibraryName, EntryPoint = Prefix + nameof(get_vec2))]
- public static partial Vec2 get_vec2();
+ [LibraryImport(LibraryName, EntryPoint = nameof(vec2_normal))]
+ public static partial Vec2 vec2_normal(Vec2 v);
- [LibraryImport(LibraryName, EntryPoint = Prefix + nameof(vec2_mul))]
- public static partial Vec2 vec2_mul(Vec2 v, float scalar);
+ [LibraryImport(LibraryName, EntryPoint = nameof(sim_log_init))]
+ public static partial void sim_log_init(IntPtr simulation, [MarshalAs(UnmanagedType.FunctionPtr)] LoggerDelegate logger, [MarshalAs(UnmanagedType.FunctionPtr)] AssertDelegate assert);
- [LibraryImport(LibraryName, EntryPoint = Prefix + nameof(vec2_normal))]
- public static partial Vec2 vec2_normal(Vec2 v);
+ [LibraryImport(LibraryName, EntryPoint = nameof(sim_set_log_level))]
+ public static partial void sim_set_log_level(IntPtr simulation, LogLevel minLevel);
- [LibraryImport(LibraryName, EntryPoint = Prefix + nameof(vec2_length))]
- public static partial float vec2_length(Vec2 v);
+ [LibraryImport(LibraryName, EntryPoint = nameof(sim_create))]
+ public static partial IntPtr sim_create(int snapshots, int entities);
+
+ [LibraryImport(LibraryName, EntryPoint = nameof(sim_free))]
+ public static partial void sim_free(IntPtr simulation);
- [LibraryImport(LibraryName, EntryPoint = Prefix + nameof(log_set_output))]
- public static partial void log_set_output([MarshalAs(UnmanagedType.FunctionPtr)] LoggerDelegate logger);
+ [LibraryImport(LibraryName, EntryPoint = nameof(sim_get_snapshot))]
+ public unsafe static partial Snapshot* sim_get_snapshot(IntPtr simulation);
- [LibraryImport(LibraryName, EntryPoint = Prefix + nameof(log_set_level))]
- public static partial void log_set_level(LogLevel minLevel);
+ [LibraryImport(LibraryName, EntryPoint = nameof(sim_return_snapshot))]
+ public unsafe static partial void sim_return_snapshot(IntPtr simulation, Snapshot* snapshot);
- [LibraryImport(LibraryName, EntryPoint = Prefix + nameof(physics_context_create))]
- public static partial IntPtr physics_context_create(int snapshots, int players, int balls);
+ [LibraryImport(LibraryName, EntryPoint = nameof(sim_tick))]
+ public unsafe static partial void sim_tick(Snapshot* current, Snapshot* next);
- [LibraryImport(LibraryName, EntryPoint = Prefix + nameof(physics_context_free))]
- public static partial void physics_context_free(IntPtr context);
+ [LibraryImport(LibraryName, EntryPoint = nameof(snapshot_create_entity))]
+ public unsafe static partial EntityId snapshot_create_entity(Snapshot* snapshot);
- [LibraryImport(LibraryName, EntryPoint = Prefix + nameof(physics_context_get_snapshot))]
- public static partial IntPtr physics_context_get_snapshot(IntPtr context);
+ public enum ComponentAddError
+ {
+ None,
+ InvalidArg,
+ InvalidId,
+ EntityNotFound
+ }
- [LibraryImport(LibraryName, EntryPoint = Prefix + nameof(physics_context_return_snapshot))]
- public static partial void physics_context_return_snapshot(IntPtr context, IntPtr snapshot);
+ [LibraryImport(LibraryName, EntryPoint = nameof(snapshot_add_component))]
+ public unsafe static partial ComponentAddError snapshot_add_component(Snapshot* snapshot, EntityId entity, Component component, void* init);
- [LibraryImport(LibraryName, EntryPoint = Prefix + nameof(physics_tick))]
- public static partial int physics_tick(IntPtr currentSnapshot, double delta, IntPtr nextSnapshot);
+ public enum ComponentRemoveError
+ {
+ None,
+ InvalidArg,
+ InvalidId,
+ EntityNotFound
+ }
- [LibraryImport(LibraryName, EntryPoint = Prefix + nameof(snapshot_put_player))]
- public static unsafe partial int snapshot_put_player(IntPtr snapshot, int playerId, Player* player);
+ [LibraryImport(LibraryName, EntryPoint = nameof(snapshot_remove_components))]
+ public unsafe static partial ComponentRemoveError snapshot_remove_components(Snapshot* snapshot, EntityId entity, Components components);
- [LibraryImport(LibraryName, EntryPoint = Prefix + nameof(snapshot_set_player_input))]
- public static partial int snapshot_set_player_input(IntPtr snapshot, int playerId, byte input);
+ [LibraryImport(LibraryName, EntryPoint = nameof(snapshot_reset_entity))]
+ public unsafe static partial ComponentRemoveError snapshot_reset_entity(Snapshot* snapshot, EntityId entity);
}