diff --git a/src/ecs.odin b/src/ecs.odin index 821e8d3..9639bca 100644 --- a/src/ecs.odin +++ b/src/ecs.odin @@ -15,6 +15,9 @@ App :: struct { // add a new system to the app that will run based on the provided schedule add_system :: proc(app: ^App, schedule: int, system: proc()) { + if _, ok := app.systems[schedule]; !ok { + app.systems[schedule] = [dynamic]proc(){} + } append(&app.systems[schedule], system) } diff --git a/src/entities.odin b/src/entities.odin index a94e8cf..8e16b60 100644 --- a/src/entities.odin +++ b/src/entities.odin @@ -49,8 +49,13 @@ single :: proc(storage: ^Storage($T)) -> (Entity, ^T) { // get component of type from entity get_component :: proc(entity: Entity, storage: ^Storage($T)) -> ^T { - if c, exists := &storage.data[entity]; exists { - return c + if _, exists := storage.data[entity]; exists { + return &storage.data[entity] } return new(T) } + +// alias for direct mutation access +get_component_with_ref :: proc(entity: Entity, storage: ^Storage($T)) -> ^T { + return get_component(entity, storage) +}