summaryrefslogtreecommitdiff
path: root/Djup.Native/Types.cs
blob: 478208f8a2fd8cf61f820550ffaab565deb1c166 (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
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 EntityKind
{
    None = 0,
    Ball
}

[StructLayout(LayoutKind.Explicit)]
public struct Entity
{
    [FieldOffset(0)]
    public EntityKind kind;

    [FieldOffset(4)]
    public Ball ball;
}

[StructLayout(LayoutKind.Sequential)]
public struct Ball
{
    public Vec2 Position { get; set; }
    public Vec2 Velocity { get; set; }
}

public enum LogLevel
{
    Trace,
    Debug,
    Info,
    Warn,
    Error,
    Fatal
}

public delegate void LoggerDelegate(LogLevel level, string source, int line, string message);