Initial commit
This commit is contained in:
commit
ac0d491786
21 changed files with 1094 additions and 0 deletions
82
ecs/coordinator.odin
Normal file
82
ecs/coordinator.odin
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
package ecs
|
||||
|
||||
Coordinator :: struct {
|
||||
component_manager: ^ComponentManager,
|
||||
entity_manager: ^EntityManager,
|
||||
system_manager: ^SystemManager,
|
||||
}
|
||||
|
||||
coordinator_create :: proc() -> Coordinator {
|
||||
coordinator := Coordinator{}
|
||||
coordinator.component_manager = new(ComponentManager, context.allocator)
|
||||
coordinator.component_manager^ = component_manager_create()
|
||||
|
||||
coordinator.entity_manager = new(EntityManager, context.allocator)
|
||||
coordinator.entity_manager^ = entity_manager_create()
|
||||
|
||||
coordinator.system_manager = new(SystemManager, context.allocator)
|
||||
coordinator.system_manager^ = system_manager_create()
|
||||
|
||||
return coordinator
|
||||
}
|
||||
|
||||
coordinator_create_entity :: proc(coordinator: ^Coordinator) -> EntityID {
|
||||
return entity_manager_create_entity(coordinator.entity_manager)
|
||||
}
|
||||
|
||||
coordinator_destroy_entity :: proc(coordinator: ^Coordinator, entity_id: EntityID) {
|
||||
component_manager_destroy_entity(coordinator.component_manager, entity_id)
|
||||
entity_manager_destroy_entity(coordinator.entity_manager, entity_id)
|
||||
system_manager_destroy_entity(coordinator.system_manager, entity_id)
|
||||
}
|
||||
|
||||
coordinator_register_component :: proc($T: typeid, coordinator: ^Coordinator) {
|
||||
component_manager_register_component(T, coordinator.component_manager)
|
||||
}
|
||||
|
||||
coordinator_add_component :: proc($T: typeid, coordinator: ^Coordinator, entity_id: EntityID, component: T) {
|
||||
component_manager_add_component(T, coordinator.component_manager, entity_id, component)
|
||||
|
||||
signature := entity_manager_get_signature(coordinator.entity_manager, entity_id)
|
||||
signature_set(&signature, component_manager_get_component_type(T, coordinator.component_manager))
|
||||
entity_manager_set_signature(coordinator.entity_manager, entity_id, signature)
|
||||
|
||||
system_manager_change_entity_signature(coordinator.system_manager, entity_id, signature)
|
||||
}
|
||||
|
||||
coordinator_remove_component :: proc($T: typeid, coordinator: ^Coordinator, entity_id: EntityID) {
|
||||
component_manager_remove_component(T, coordinator.component_manager, entity_id)
|
||||
|
||||
signature := entity_manager_get_signature(coordinator.entity_manager, entity_id)
|
||||
signature_unset(&signature, component_manager_get_component_type(T, coordinator.component_manager))
|
||||
entity_manager_set_signature(coordinator.entity_manager, entity_id, signature)
|
||||
|
||||
system_manager_change_entity_signature(coordinator.system_manager, entity_id, signature)
|
||||
}
|
||||
|
||||
coordinator_get_component :: proc($T: typeid, coordinator: ^Coordinator, entity_id: EntityID) -> ^T {
|
||||
return component_manager_get_component(T, coordinator.component_manager, entity_id)
|
||||
}
|
||||
|
||||
coordinator_get_component_type :: proc($T: typeid, coordinator: ^Coordinator) -> ComponentType {
|
||||
return component_manager_get_component_type(T, coordinator.component_manager)
|
||||
}
|
||||
|
||||
coordinator_register_system :: proc($T: typeid, coordinator: ^Coordinator) -> ^T {
|
||||
return system_manager_register_system(T, coordinator.system_manager)
|
||||
}
|
||||
|
||||
coordinator_set_system_signature :: proc($T: typeid, coordinator: ^Coordinator, signature: Signature) {
|
||||
system_manager_set_signature(T, coordinator.system_manager, signature)
|
||||
}
|
||||
|
||||
coordinator_destroy :: proc(coordinator: ^Coordinator) {
|
||||
component_manager_destroy(coordinator.component_manager)
|
||||
entity_manager_destroy(coordinator.entity_manager)
|
||||
system_manager_destroy(coordinator.system_manager)
|
||||
|
||||
free(coordinator.component_manager)
|
||||
free(coordinator.entity_manager)
|
||||
free(coordinator.system_manager)
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue