MQIW2ABTSDRARUBTCU2EIH35HNCD7HRBYZ2FEG3KADXIIVJVGTZAC package ecsimport "core:runtime"Entity :: distinct u64Container :: union($T: typeid) {T,}World :: struct {next_id: u64,}NewWorld :: proc() -> ^World {world := new(World)world.next_id = 0return world}CreateEntity :: proc(world: ^World) -> Entity {current := world.next_idworld.next_id += 1return Entity(current)}AddComponent :: proc(world: ^World, entity: Entity, component: $C) {}}if int(entity) < len(components) {} else {}}}}RemoveComponent :: proc(world: ^World, entity: Entity, $C: typeid) {assign_at(components, int(entity), nil)}}typid := typeid_of(C)if components, exists := &world.components[typid]; exists {components := cast(^[dynamic]Container(C))componentsreturn nil, falsereturn &components[entity].(C), trueif c := components[entity]; c == nil {return nil, falseGetComponent :: proc(world: ^World, entity: Entity, $C: typeid) -> (^C, bool) {typid := typeid_of(C)if components, exists := world.components[typid]; exists {components := cast(^[dynamic]Container(C))componentsm, _ := world.components[typid]assign_at(cast(^[dynamic]Container(C))m, int(entity), component)typid := typeid_of(C)if _, exists := world.components[typid]; !exists {world.components[typid] = cast(^runtime.Raw_Dynamic_Array)new([dynamic]Container(C))world.components = make(map[typeid]^runtime.Raw_Dynamic_Array)components: map[typeid]^runtime.Raw_Dynamic_Array,
package secsimport "core:runtime"Entity :: distinct u64Container :: union($T: typeid) {T,}World :: struct {next_id: u64,components: map[typeid]^runtime.Raw_Dynamic_Array,}NewWorld :: proc() -> ^World {world := new(World)world.next_id = 0world.components = make(map[typeid]^runtime.Raw_Dynamic_Array)return world}CreateEntity :: proc(world: ^World) -> Entity {current := world.next_idworld.next_id += 1return Entity(current)}AddComponent :: proc(world: ^World, entity: Entity, component: $C) {typid := typeid_of(C)if _, exists := world.components[typid]; !exists {world.components[typid] = cast(^runtime.Raw_Dynamic_Array)new([dynamic]Container(C))}m, _ := world.components[typid]assign_at(cast(^[dynamic]Container(C))m, int(entity), component)}GetComponent :: proc(world: ^World, entity: Entity, $C: typeid) -> (^C, bool) {typid := typeid_of(C)if components, exists := world.components[typid]; exists {components := cast(^[dynamic]Container(C))componentsif int(entity) < len(components) {if c := components[entity]; c == nil {return nil, false} else {return &components[entity].(C), true}}}return nil, false}RemoveComponent :: proc(world: ^World, entity: Entity, $C: typeid) {typid := typeid_of(C)if components, exists := &world.components[typid]; exists {components := cast(^[dynamic]Container(C))componentsassign_at(components, int(entity), nil)}}
.git.DS_Storebuild.pijul