aboutsummaryrefslogtreecommitdiff
path: root/src/ecs/component.zig
blob: 4a10172a3390d90dd0c4082704ed1cde4ebac2fe (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
const std = @import("std");

pub const ComponentStub = struct {
    pub fn init(args: ComponentStub) ComponentStub {
        _ = args;
        return .{};
    }

    pub fn deinit(self: *ComponentStub) void {
        _ = self;
    }
};

pub const ComponentType = enum(usize) {
    component_stub = 0,
};

pub const Component = union(ComponentType) {
    component_stub: ComponentStub,

    pub fn init(t: ComponentType, args: anytype) Component {
        switch (t) {
            ComponentType.component_stub => return Component{
                .component_stub = ComponentStub.init(args),
            },
        }
    }

    pub fn deinit(self: *Component) void {
        switch (self.*) {
            .component_stub => |*comp| comp.deinit(),
        }
    }
};

test "stub component" {
    var stub = Component.init(ComponentType.component_stub, .{});
    defer stub.deinit();
}