No description
Find a file
2024-09-22 19:52:51 +09:00
.github feat: introduce seiryu 2024-09-04 18:45:30 +09:00
docs feat: add component utilities and delete each macro 2024-09-14 01:38:36 +09:00
src feat: add deleteResource() for Commands 2024-09-22 19:52:51 +09:00
tests 🔥 revert: revert 2024-09-20 16:38:47 +09:00
.gitignore 🔧 config: remove nim.cfg 2024-09-14 21:03:22 +09:00
CHANGELOG.md 📝 doc: update CHANGELOG.md 2024-09-09 16:12:01 +09:00
config.nims 🔧 config: introduce atlas 2024-09-11 00:20:44 +09:00
COPYING 📚 Add README and COPYING 2024-07-09 22:33:46 +09:00
ecslib.nimble 🔧 config: introduce atlas 2024-09-11 00:20:44 +09:00

ecslib

Easier and simpler game development with ECS

ecslib is a nimble package that implements a sparse set-based Entity Component System.

Example

Create an ECS program

# Components ---- No need to register!
type
  Position = ref object
    x, y: int

  Velocity = ref object
    x, y: int

# Resources, global data for systems
  Time = ref object
    deltaTime: float

let world = World.new()

# Entity
let
  ball = world.create()

# Attaching components
ball
  .attach(
    Position(x: 0, y: 0)
  ).attach(
    Velocity(x: 5, y: 2)
  )

# You can define system using procedure syntax
proc moveSystem(
    # Querying targeted entities by `All`, `Any`, and `None` args
    entities: [All[Position, Velocity]],
    # Get the resource of type `T`
    time: Resource[Time]
) {.system.} =
  # specifying components that will be used in the system
  for pos, vel in each(entities, [Position, Velocity]):
    pos.x += vel.x * time.deltaTime
    pos.y += vel.y * time.deltaTime

proc showPositionSystem(entities: [All[Position]]) {.system.} =
  for pos in each(entities, [Position]):
    echo "x: ", pos.x
    echo "y: ", pos.y

# Add resources to world
world.addResource(Time(deltaTime: 30))

# Register systems to world
world.registerSystem(moveSystem)
world.registerSystem(showPositionSystem)

while true:
  world.runSystems()

Note

This project adopts Design by Contract for implementation. Please build your app with --assertions:off to run without assertions.

Installation

nimble install ecslib

Documentation

See:

License

ecslib is licensed under the MIT license. See COPYING for details.