From f7c830dcb81264be4bd210a9bb89727e9536c72a Mon Sep 17 00:00:00 2001 From: harper Date: Fri, 2 Oct 2026 15:07:20 -0700 Subject: [PATCH] query start --- ecs.odin | 10 ++-------- entities.odin | 19 +++++++++++-------- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/ecs.odin b/ecs.odin index 272192e..f7621bc 100644 --- a/ecs.odin +++ b/ecs.odin @@ -11,7 +11,8 @@ App :: struct { update_systems: [dynamic]proc(), draw_systems: [dynamic]proc(), plugins: [dynamic]proc(app: ^App), - entities: map[int][dynamic]struct{}, + entities: map[u32][dynamic]struct{}, + storages: map[typeid]rawptr, } add_system :: proc(app: ^App, schedule: int, system: proc()) { @@ -29,13 +30,6 @@ add_plugin :: proc(app: ^App, plugin: proc(app: ^App)) { append(&app.plugins, plugin) } -spawn_entity :: proc(app: ^App, components: [dynamic]struct{}) { - entity_len := len(&app.entities) - - app.entities[entity_len] = components - -} - run :: proc(app: ^App) { rl.InitWindow(800, 600, "shoal window") defer rl.CloseWindow() diff --git a/entities.odin b/entities.odin index 6bc0ed4..8563f08 100644 --- a/entities.odin +++ b/entities.odin @@ -1,18 +1,21 @@ package shoal -Entity :: struct { - id: int, - components: [dynamic]struct{}, +Entity :: distinct u32 + +Storage :: struct($T: typeid) { + data: map[Entity]T, } -spawn_entity :: proc(app: ^App) -> Entity { +spawn_entity :: proc(app: ^App, $T: typeid) -> Entity { entity: Entity - entity_len := len(&app.entities) - entity.id = entity_len - return entity } -add_collection :: proc(app: ^App, component: $T) { +add_collection :: proc(app: ^App, $T: typeid) { + storage: ^Storage(T) + app.storages[T] = storage +} + +query :: proc(app: ^App, $T: typeid) { }