summaryrefslogtreecommitdiff
path: root/Djup.Native
diff options
context:
space:
mode:
Diffstat (limited to 'Djup.Native')
-rw-r--r--Djup.Native/Constants.cs7
-rw-r--r--Djup.Native/LibDjup.cs27
-rw-r--r--Djup.Native/Types.cs52
3 files changed, 64 insertions, 22 deletions
diff --git a/Djup.Native/Constants.cs b/Djup.Native/Constants.cs
new file mode 100644
index 0000000..90692be
--- /dev/null
+++ b/Djup.Native/Constants.cs
@@ -0,0 +1,7 @@
+namespace Djup.Native;
+
+public static class Constants
+{
+ public const int WorldMaxPlayers = 5;
+ public const int WorldMaxBullets = 5000;
+}
diff --git a/Djup.Native/LibDjup.cs b/Djup.Native/LibDjup.cs
index 0b4a3db..15dcdad 100644
--- a/Djup.Native/LibDjup.cs
+++ b/Djup.Native/LibDjup.cs
@@ -31,21 +31,24 @@ public static partial class LibDjup
[LibraryImport(LibraryName, EntryPoint = Prefix + nameof(log_set_level))]
public static partial Vec2 log_set_level(LogLevel minLevel);
- [LibraryImport(LibraryName, EntryPoint = Prefix + nameof(world_create))]
- public static partial IntPtr world_create();
+ [LibraryImport(LibraryName, EntryPoint = Prefix + nameof(physics_context_create))]
+ public static partial IntPtr physics_context_create(uint snapshots);
- [LibraryImport(LibraryName, EntryPoint = Prefix + nameof(world_free))]
- public static partial void world_free(IntPtr world);
+ [LibraryImport(LibraryName, EntryPoint = Prefix + nameof(physics_context_free))]
+ public static partial void physics_context_free(IntPtr context);
- [LibraryImport(LibraryName, EntryPoint = Prefix + nameof(world_create_entity))]
- public static partial int world_create_entity(IntPtr world, EntityKind kind);
+ [LibraryImport(LibraryName, EntryPoint = Prefix + nameof(physics_context_get_snapshot))]
+ public static partial IntPtr physics_context_get_snapshot(IntPtr context);
- [LibraryImport(LibraryName, EntryPoint = Prefix + nameof(world_find_entity))]
- public static unsafe partial Entity* world_find_entity(IntPtr world, int entityId);
+ [LibraryImport(LibraryName, EntryPoint = Prefix + nameof(physics_context_return_snapshot))]
+ public static partial void physics_context_return_snapshot(IntPtr context, IntPtr snapshot);
- [LibraryImport(LibraryName, EntryPoint = Prefix + nameof(world_remove_entity))]
- public static partial void world_remove_entity(IntPtr world, int entityId);
+ [LibraryImport(LibraryName, EntryPoint = Prefix + nameof(physics_tick))]
+ public static partial int physics_tick(IntPtr currentSnapshot, double delta, IntPtr nextSnapshot);
- [LibraryImport(LibraryName, EntryPoint = Prefix + nameof(world_tick))]
- public static partial int world_tick(IntPtr world, double delta);
+ [LibraryImport(LibraryName, EntryPoint = Prefix + nameof(snapshot_put_player))]
+ public static unsafe partial int snapshot_put_player(IntPtr snapshot, uint playerId, Player *player);
+
+ [LibraryImport(LibraryName, EntryPoint = Prefix + nameof(snapshot_set_player_input))]
+ public static partial int snapshot_set_player_input(IntPtr snapshot, uint playerId, byte input);
}
diff --git a/Djup.Native/Types.cs b/Djup.Native/Types.cs
index 478208f..7d9c41e 100644
--- a/Djup.Native/Types.cs
+++ b/Djup.Native/Types.cs
@@ -1,4 +1,5 @@
using System.Diagnostics;
+using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace Djup.Native;
@@ -21,29 +22,60 @@ public struct Vec2
public override string ToString() => $"({X}, {Y})";
}
-public enum EntityKind
+public enum EntityState : byte
{
- None = 0,
- Ball
+ Inactive = 0,
+ Active,
+ Removed,
+ Dead
}
-[StructLayout(LayoutKind.Explicit)]
-public struct Entity
+public enum PlayerInput : byte
{
- [FieldOffset(0)]
- public EntityKind kind;
+ Up = 1 << 0,
+ Down = 1 << 1,
+ Left = 1 << 2,
+ Right = 1 << 3
+}
- [FieldOffset(4)]
- public Ball ball;
+[StructLayout(LayoutKind.Sequential)]
+public struct Player
+{
+ public EntityState State { get; }
+ private byte input;
+ public Vec2 Position { get; set; }
+ public Vec2 Velocity { get; set; }
}
[StructLayout(LayoutKind.Sequential)]
-public struct Ball
+public struct Bullet
{
+ public EntityState State { get; set; }
public Vec2 Position { get; set; }
public Vec2 Velocity { get; set; }
}
+[StructLayout(LayoutKind.Sequential)]
+public struct Snapshot
+{
+ [InlineArray(Constants.WorldMaxPlayers)]
+ public struct PlayerArray
+ {
+ private Player _element0;
+ }
+
+ [InlineArray(Constants.WorldMaxBullets)]
+ public struct BallArray
+ {
+ private Bullet _element0;
+ }
+
+ private byte active;
+ public uint Tick { get; }
+ public PlayerArray Players { get; }
+ public BallArray Bullets { get; }
+}
+
public enum LogLevel
{
Trace,