summaryrefslogtreecommitdiff
path: root/Djup.Native/Types.cs
blob: 7d9c41eb2381a0e133296397f2946b0e055538ff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
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);