using System.Diagnostics; 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 unsafe struct Snapshot { private byte active; public uint Tick { get; } private int playersLength; private Player* players; private int bulletsLength; private Bullet* bullets; public ReadOnlySpan Players => new ReadOnlySpan(players, playersLength); public ReadOnlySpan Bullets => new ReadOnlySpan(bullets, bulletsLength); } public enum LogLevel { Trace, Debug, Info, Warn, Error, Fatal } public delegate void LoggerDelegate(LogLevel level, string source, int line, string message);