diff options
author | jjanzen <jjanzen@jjanzen.ca> | 2025-01-21 19:20:50 -0600 |
---|---|---|
committer | jjanzen <jjanzen@jjanzen.ca> | 2025-01-21 19:20:50 -0600 |
commit | 8a20d05a7a8cf9f1339142240907ed158449dfa0 (patch) | |
tree | babbf74a7bea83589b05f117a795235deb0e238c /src/ecs/entity.zig | |
parent | 9f18b702b15b4a26a016170a8a2dfb216ae15810 (diff) |
add basic entity component system
Diffstat (limited to 'src/ecs/entity.zig')
-rw-r--r-- | src/ecs/entity.zig | 45 |
1 files changed, 0 insertions, 45 deletions
diff --git a/src/ecs/entity.zig b/src/ecs/entity.zig deleted file mode 100644 index 2ad8556..0000000 --- a/src/ecs/entity.zig +++ /dev/null @@ -1,45 +0,0 @@ -const std = @import("std"); - -pub const Entity = struct { - id: usize, -}; - -pub const EntityCollection = struct { - allocator: std.mem.Allocator, - next_id: usize, - entities: std.AutoHashMap(usize, Entity), - - pub fn addEntity(self: *EntityCollection) !usize { - try self.entities.put(self.next_id, .{ - .id = self.next_id, - }); - - self.next_id += 1; - - return self.next_id - 1; - } - - pub fn init(allocator: std.mem.Allocator) EntityCollection { - return .{ - .allocator = allocator, - .next_id = 0, - .entities = std.AutoHashMap(usize, Entity).init(allocator), - }; - } - - pub fn deinit(self: *EntityCollection) void { - self.entities.deinit(); - } -}; - -test "create entities" { - try std.testing.expect(true); - - var ec = EntityCollection.init(std.testing.allocator); - defer ec.deinit(); - - for (0..128) |i| { - const id = ec.addEntity(); - try std.testing.expectEqual(i, id); - } -} |