fix seg fault
This commit is contained in:
@@ -15,6 +15,9 @@ App :: struct {
|
|||||||
|
|
||||||
// add a new system to the app that will run based on the provided schedule
|
// add a new system to the app that will run based on the provided schedule
|
||||||
add_system :: proc(app: ^App, schedule: int, system: proc()) {
|
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)
|
append(&app.systems[schedule], system)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+7
-2
@@ -49,8 +49,13 @@ single :: proc(storage: ^Storage($T)) -> (Entity, ^T) {
|
|||||||
|
|
||||||
// get component of type from entity
|
// get component of type from entity
|
||||||
get_component :: proc(entity: Entity, storage: ^Storage($T)) -> ^T {
|
get_component :: proc(entity: Entity, storage: ^Storage($T)) -> ^T {
|
||||||
if c, exists := &storage.data[entity]; exists {
|
if _, exists := storage.data[entity]; exists {
|
||||||
return c
|
return &storage.data[entity]
|
||||||
}
|
}
|
||||||
return new(T)
|
return new(T)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// alias for direct mutation access
|
||||||
|
get_component_with_ref :: proc(entity: Entity, storage: ^Storage($T)) -> ^T {
|
||||||
|
return get_component(entity, storage)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user