7JUEZKVFKBKEMUUWZWJO6MEW4S2GHQZMXPPQC5XB6QIUCWXVNI6AC package ecsimport "core:fmt"@(private)Position :: struct {x: f32,y: f32,}@(private)Velocity :: struct {x: f32,y: f32,}@(private)Name :: struct {name: string,}@(private)Rotation :: struct {degrees: f32,}@(private)Enemy :: struct {}@(private)main :: proc() {world := NewWorld()defer {for c in world.components {free(world.components[c])}}defer delete(world.components)defer free(world)AddComponents(world, CreateEntity(world), Position{0, 1})AddComponents(world, CreateEntity(world), Position{0, 1}, Velocity{-0, -1})AddComponents(world, CreateEntity(world), Position{0, 1}, Velocity{-0, -1}, Name{"Entity"})AddComponents(world,CreateEntity(world),Position{0, 1},Velocity{-0, -1},Name{"Entity"},Rotation{0},)AddComponents(world,CreateEntity(world),Position{0, 1},Velocity{-0, -1},Name{"Entity"},Rotation{0},Enemy{},)Work(world, proc(e: Entity, p: ^Position) {fmt.println("Work1: ", e, p)})Work(world, proc(e: Entity, p: ^Position, v: ^Velocity) {fmt.println("Work2: ", e, p, v)})Work(world, proc(e: Entity, p: ^Position, v: ^Velocity, n: ^Name) {fmt.println("Work3: ", e, p, v, n)})Work(world, proc(e: Entity, p: ^Position, v: ^Velocity, n: ^Name, r: ^Rotation) {fmt.println("Work4: ", e, p, v, n, r)})Work(world, proc(e: Entity, p: ^Position, v: ^Velocity, n: ^Name, r: ^Rotation, en: ^Enemy) {fmt.println("Work5: ", e, p, v, n, r, en)})}
Enemy :: struct {}@(private)main :: proc() {world := NewWorld()defer {for c in world.components {free(world.components[c])}}defer delete(world.components)defer free(world)AddComponents(world, CreateEntity(world), Position{0, 1})AddComponents(world, CreateEntity(world), Position{0, 1}, Velocity{-0, -1})AddComponents(world, CreateEntity(world), Position{0, 1}, Velocity{-0, -1}, Name{"Entity"})AddComponents(world,CreateEntity(world),Position{0, 1},Velocity{-0, -1},Name{"Entity"},Rotation{0},)AddComponents(world,CreateEntity(world),Position{0, 1},Velocity{-0, -1},Name{"Entity"},Rotation{0},Enemy{},)Work(world, proc(e: Entity, p: ^Position) {fmt.println("Work1: ", e, p)})Work(world, proc(e: Entity, p: ^Position, v: ^Velocity) {fmt.println("Work2: ", e, p, v)})Work(world, proc(e: Entity, p: ^Position, v: ^Velocity, n: ^Name) {fmt.println("Work3: ", e, p, v, n)})Work(world, proc(e: Entity, p: ^Position, v: ^Velocity, n: ^Name, r: ^Rotation) {fmt.println("Work4: ", e, p, v, n, r)})Work(world, proc(e: Entity, p: ^Position, v: ^Velocity, n: ^Name, r: ^Rotation, en: ^Enemy) {fmt.println("Work5: ", e, p, v, n, r, en)})}
# Small unoptimized ECS implementation in odin## Usage```odinmain :: proc() {// create a new ecs worldworld := NewWorld()// create an entity with just a positionAddComponents(world, CreateEntity(world), Position{0, 1})// create an entity with position and velocityAddComponents(world, CreateEntity(world), Position{0, 1}, Velocity{-0, -1})// create an entity with position, velocity and nameAddComponents(world, CreateEntity(world), Position{0, 1}, Velocity{-0, -1}, Name{"Entity"})// create an entity with position, velocity, name and rotationAddComponents(world,CreateEntity(world),Position{0, 1},Velocity{-0, -1},Name{"Entity"},Rotation{0},)// create an entity with position, velocity, name, rotation and enemyAddComponents(world,CreateEntity(world),Position{0, 1},Velocity{-0, -1},Name{"Entity"},Rotation{0},Enemy{},)// Iterate over all entities containing positionWork(world, proc(e: Entity, p: ^Position) {fmt.println("Work1: ", e, p)})// Iterate over all entities containing position and velocityWork(world, proc(e: Entity, p: ^Position, v: ^Velocity) {fmt.println("Work2: ", e, p, v)})// Iterate over all entities containing position, velocity and nameWork(world, proc(e: Entity, p: ^Position, v: ^Velocity, n: ^Name) {fmt.println("Work3: ", e, p, v, n)})// Iterate over all entities containing position, velocity, name and rotationWork(world, proc(e: Entity, p: ^Position, v: ^Velocity, n: ^Name, r: ^Rotation) {fmt.println("Work4: ", e, p, v, n, r)})// Iterate over all entities containing position, velocity, name, rotation and enemyWork(world, proc(e: Entity, p: ^Position, v: ^Velocity, n: ^Name, r: ^Rotation, en: ^Enemy) {fmt.println("Work5: ", e, p, v, n, r, en)})}```