lowkey im high rn

This commit is contained in:
harper
2026-10-08 21:54:21 -07:00
parent e5067f4e4a
commit b884b2bced
4 changed files with 43 additions and 8 deletions
+17 -1
View File
@@ -15,14 +15,30 @@ spawn_entity :: proc(app: ^App) -> Entity {
return entity
}
add_component :: proc(entity: Entity, storage: ^Storage($T)) {
add_component :: proc {
add_fresh_component,
add_component_with_data,
}
add_fresh_component :: proc(entity: Entity, storage: ^Storage($T)) {
storage.data[entity] = T{}
}
add_component_with_data :: proc(entity: Entity, storage: ^Storage($T), component: T) {
storage.data[entity] = component
}
slice :: proc(storage: ^Storage($T)) -> map[Entity]T {
return storage.data
}
single :: proc(storage: ^Storage($T)) -> (Entity, ^T) {
for i, &v in slice(storage) {
return i, &v
}
return Entity{}, new(T)
}
get_component :: proc(entity: Entity, storage: ^Storage($T)) -> ^T {
if c, exists := &storage.data[entity]; exists {
return c