summaryrefslogtreecommitdiff
path: root/Djup.Native/src
diff options
context:
space:
mode:
authorJoel Stålnacke <joel@saker.fi>2026-03-19 22:30:56 +0200
committerJoel Stålnacke <joel@saker.fi>2026-03-19 22:30:56 +0200
commit745406dc65aecc438a53f96badc387a32b7a338f (patch)
treecc597855dac943efe627fce160782585e27feadf /Djup.Native/src
parent3b60cd682120947119f442bb71ab2a5e98decccc (diff)
Add Mibo project
The Djup project is DesktopGL project
Diffstat (limited to 'Djup.Native/src')
-rw-r--r--Djup.Native/src/Constants.cs7
-rw-r--r--Djup.Native/src/Djup.Native.csproj40
-rw-r--r--Djup.Native/src/LibDjup.cs54
-rw-r--r--Djup.Native/src/Program.cs3
-rw-r--r--Djup.Native/src/Types.cs89
-rw-r--r--Djup.Native/src/packages.lock.json6
6 files changed, 199 insertions, 0 deletions
diff --git a/Djup.Native/src/Constants.cs b/Djup.Native/src/Constants.cs
new file mode 100644
index 0000000..90692be
--- /dev/null
+++ b/Djup.Native/src/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/src/Djup.Native.csproj b/Djup.Native/src/Djup.Native.csproj
new file mode 100644
index 0000000..a581a58
--- /dev/null
+++ b/Djup.Native/src/Djup.Native.csproj
@@ -0,0 +1,40 @@
+<Project Sdk="Microsoft.NET.Sdk">
+
+ <PropertyGroup>
+ <TargetFramework>net10.0</TargetFramework>
+ <ImplicitUsings>enable</ImplicitUsings>
+ <Nullable>enable</Nullable>
+ <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
+ <RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
+ </PropertyGroup>
+
+ <PropertyGroup>
+ <BuildDir>$(MSBuildThisFileDirectory)../../lib/build</BuildDir>
+ </PropertyGroup>
+
+ <ItemGroup Condition=" '$(Configuration)'=='Release' ">
+ <Content Include="$(BuildDir)/linux-x64/libdjup.so">
+ <TargetPath>runtimes/linux-x64/native/libdjup.so</TargetPath>
+ <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+ <PackagePath>runtimes/linux-x64/native/</PackagePath>
+ <Pack>true</Pack>
+ </Content>
+ </ItemGroup>
+
+ <Choose>
+ <When Condition=" '$(Configuration)'=='Debug'">
+ <PropertyGroup>
+ <Arch>$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture)</Arch>
+ <IsLinux Condition="$([MSBuild]::IsOsPlatform('Linux'))">true</IsLinux>
+ </PropertyGroup>
+
+ <ItemGroup Condition=" $(IsLinux) And '$(Arch)' == X64 ">
+ <Content Include="$(BuildDir)/linux-x64/libdjup.so">
+ <TargetPath>runtimes/linux-x64/native/libdjup.so</TargetPath>
+ <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+ </Content>
+ </ItemGroup>
+ </When>
+ </Choose>
+
+</Project>
diff --git a/Djup.Native/src/LibDjup.cs b/Djup.Native/src/LibDjup.cs
new file mode 100644
index 0000000..15dcdad
--- /dev/null
+++ b/Djup.Native/src/LibDjup.cs
@@ -0,0 +1,54 @@
+using System.Runtime.InteropServices;
+
+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 = Prefix + nameof(get_num))]
+ public static partial int get_num();
+
+ [LibraryImport(LibraryName, EntryPoint = Prefix + nameof(get_vec2))]
+ public static partial Vec2 get_vec2();
+
+ [LibraryImport(LibraryName, EntryPoint = Prefix + nameof(vec2_mul))]
+ public static partial Vec2 vec2_mul(Vec2 v, float scalar);
+
+ [LibraryImport(LibraryName, EntryPoint = Prefix + nameof(vec2_normal))]
+ public static partial Vec2 vec2_normal(Vec2 v);
+
+ [LibraryImport(LibraryName, EntryPoint = Prefix + nameof(vec2_length))]
+ public static partial float vec2_length(Vec2 v);
+
+ [LibraryImport(LibraryName, EntryPoint = Prefix + nameof(log_set_output))]
+ public static partial Vec2 log_set_output([MarshalAs(UnmanagedType.FunctionPtr)] LoggerDelegate logger);
+
+ [LibraryImport(LibraryName, EntryPoint = Prefix + nameof(log_set_level))]
+ public static partial Vec2 log_set_level(LogLevel minLevel);
+
+ [LibraryImport(LibraryName, EntryPoint = Prefix + nameof(physics_context_create))]
+ public static partial IntPtr physics_context_create(uint snapshots);
+
+ [LibraryImport(LibraryName, EntryPoint = Prefix + nameof(physics_context_free))]
+ public static partial void physics_context_free(IntPtr context);
+
+ [LibraryImport(LibraryName, EntryPoint = Prefix + nameof(physics_context_get_snapshot))]
+ public static partial IntPtr physics_context_get_snapshot(IntPtr context);
+
+ [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(physics_tick))]
+ public static partial int physics_tick(IntPtr currentSnapshot, double delta, IntPtr nextSnapshot);
+
+ [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/src/Program.cs b/Djup.Native/src/Program.cs
new file mode 100644
index 0000000..1b374b8
--- /dev/null
+++ b/Djup.Native/src/Program.cs
@@ -0,0 +1,3 @@
+/*using Djup.Native;*/
+/**/
+/*LibDjup.hello_world();*/
diff --git a/Djup.Native/src/Types.cs b/Djup.Native/src/Types.cs
new file mode 100644
index 0000000..7d9c41e
--- /dev/null
+++ b/Djup.Native/src/Types.cs
@@ -0,0 +1,89 @@
+using System.Diagnostics;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+namespace Djup.Native;
+
+[StructLayout(LayoutKind.Sequential)]
+public struct Vec2
+{
+ public float X { get; }
+ public float Y { get; }
+
+ public Vec2(float x, float y)
+ {
+ Debug.Assert(float.IsFinite(x));
+ Debug.Assert(float.IsFinite(y));
+
+ X = x;
+ Y = y;
+ }
+
+ public override string ToString() => $"({X}, {Y})";
+}
+
+public enum EntityState : byte
+{
+ Inactive = 0,
+ Active,
+ Removed,
+ Dead
+}
+
+public enum PlayerInput : byte
+{
+ Up = 1 << 0,
+ Down = 1 << 1,
+ Left = 1 << 2,
+ Right = 1 << 3
+}
+
+[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 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,
+ Debug,
+ Info,
+ Warn,
+ Error,
+ Fatal
+}
+
+public delegate void LoggerDelegate(LogLevel level, string source, int line, string message);
diff --git a/Djup.Native/src/packages.lock.json b/Djup.Native/src/packages.lock.json
new file mode 100644
index 0000000..4a91a8c
--- /dev/null
+++ b/Djup.Native/src/packages.lock.json
@@ -0,0 +1,6 @@
+{
+ "version": 1,
+ "dependencies": {
+ "net10.0": {}
+ }
+} \ No newline at end of file