You need to manually register components now, otherwise all components would be stored internally as 8 bytes instead of their actual size.
This commit is contained in:
33
ecs.odin
33
ecs.odin
@@ -37,7 +37,7 @@ Component_Storage :: struct {
|
|||||||
}
|
}
|
||||||
Component_Registry :: map[typeid]Component_Storage
|
Component_Registry :: map[typeid]Component_Storage
|
||||||
|
|
||||||
get_addr_of_component_for_entity_id_from_storage :: proc(storage: ^Component_Storage, entity_id: Entity_ID) -> rawptr {
|
@(private="file") get_addr_of_component_for_entity_id_from_storage :: proc(storage: ^Component_Storage, entity_id: Entity_ID) -> rawptr {
|
||||||
return rawptr(uintptr(storage.data) + uintptr((u32(entity_id) * storage.elem_size)))
|
return rawptr(uintptr(storage.data) + uintptr((u32(entity_id) * storage.elem_size)))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,31 +68,6 @@ create_world :: proc(name: string, max_entities: u32, systems: []System) -> (^Wo
|
|||||||
|
|
||||||
world.component_registry = registry
|
world.component_registry = registry
|
||||||
|
|
||||||
// for c in components_to_register {
|
|
||||||
// log.infof("Registering component '%v' (size: %v).", c, size_of(c))
|
|
||||||
|
|
||||||
// if c in world.component_registry {
|
|
||||||
// log.warnf("Component '%v' already registered.", c)
|
|
||||||
// continue
|
|
||||||
// }
|
|
||||||
|
|
||||||
// // register_component(world, c)
|
|
||||||
// // id := typeid_of(type_of(c))
|
|
||||||
// // info: ^runtime.Type_Info
|
|
||||||
// // info = type_info_of(id)
|
|
||||||
|
|
||||||
// // fmt.printfln("Runtime info about component: %v", c)
|
|
||||||
|
|
||||||
// // world.component_registry[c] = Component_Storage {
|
|
||||||
// // data = make([]type_of(c), max_entities),
|
|
||||||
// // alive = make([]bool, max_entities)
|
|
||||||
// // }
|
|
||||||
|
|
||||||
// // for i in 0..<10 {
|
|
||||||
// // fmt.printfln("ADDR %v: %v", i, &world.component_registry[c].data[i])
|
|
||||||
// // }
|
|
||||||
// }
|
|
||||||
|
|
||||||
{ // Set up the world's queue of available entity-ids.
|
{ // Set up the world's queue of available entity-ids.
|
||||||
assert(u64(max_entities) <= u64(max(int)))
|
assert(u64(max_entities) <= u64(max(int)))
|
||||||
queue.init(&world.entity_id_queue, capacity = int(max_entities))
|
queue.init(&world.entity_id_queue, capacity = int(max_entities))
|
||||||
@@ -120,7 +95,7 @@ create_world :: proc(name: string, max_entities: u32, systems: []System) -> (^Wo
|
|||||||
}
|
}
|
||||||
|
|
||||||
register_component :: proc(world: ^World, $A: typeid) -> bool {
|
register_component :: proc(world: ^World, $A: typeid) -> bool {
|
||||||
log.infof("Registering component '%v' (size: %v).", typeid_of(A), size_of(A))
|
log.infof("Registering component '%v' (size: %v) in world '%v'.", typeid_of(A), size_of(A), world.name)
|
||||||
if A in world.component_registry {
|
if A in world.component_registry {
|
||||||
log.warnf("Component '%v' already registered.", typeid_of(A))
|
log.warnf("Component '%v' already registered.", typeid_of(A))
|
||||||
return false
|
return false
|
||||||
@@ -226,7 +201,7 @@ add_component :: proc(entity: Entity, world: ^World, component: $T, loc := #call
|
|||||||
|
|
||||||
component_storage := &world.component_registry[T]
|
component_storage := &world.component_registry[T]
|
||||||
if component_storage == nil {
|
if component_storage == nil {
|
||||||
log.warnf("Failed to add component %v - component does not exist in the registry. Location: %v", typeid_of(T), loc)
|
log.warnf("Failed to add component %v - component does not exist in the world '%v's component-registry. Location: %v", typeid_of(T), world.name, loc)
|
||||||
return nil, false
|
return nil, false
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -251,7 +226,7 @@ has_component :: proc(t: typeid, entity: Entity, world: ^World, loc := #caller_l
|
|||||||
|
|
||||||
component_storage := &world.component_registry[t]
|
component_storage := &world.component_registry[t]
|
||||||
if component_storage == nil {
|
if component_storage == nil {
|
||||||
log.warnf("Failed to get component %v - component does not exist in the registry. Location: %v", t, loc)
|
log.warnf("Failed to get component %v - component does not exist in the world '%v's component-registry. Location: %v", t, world.name, loc)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user