https://github.com/glassesneo/ecslib
A nimble package for Entity Component System
https://github.com/glassesneo/ecslib
entity-component-system game-development nim
Last synced: about 2 months ago
JSON representation
A nimble package for Entity Component System
- Host: GitHub
- URL: https://github.com/glassesneo/ecslib
- Owner: glassesneo
- License: mit
- Created: 2023-10-25T16:22:15.000Z (over 1 year ago)
- Default Branch: develop
- Last Pushed: 2024-09-14T12:03:42.000Z (8 months ago)
- Last Synced: 2024-09-15T08:32:34.490Z (8 months ago)
- Topics: entity-component-system, game-development, nim
- Language: Nim
- Homepage:
- Size: 152 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: .github/README.md
- Changelog: CHANGELOG.md
- License: COPYING
Awesome Lists containing this project
README
# 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
```nim
# Components ---- No need to register!
type
Position = ref object
x, y: intVelocity = ref object
x, y: int# Resources, global data for systems
Time = ref object
deltaTime: floatlet 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.deltaTimeproc 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
```nim
nimble install ecslib
```## Documentation
See:
- [API.md](../docs/API.md) for basic usage
- [system_dsl.md](../docs/system_dsl.md) for system grammer## License
ecslib is licensed under the MIT license. See COPYING for details.