https://github.com/jabolopes/go-ecs
Entity component system for game development.
https://github.com/jabolopes/go-ecs
ecs entity-component-system game-development generics go golang golang-library
Last synced: 3 months ago
JSON representation
Entity component system for game development.
- Host: GitHub
- URL: https://github.com/jabolopes/go-ecs
- Owner: jabolopes
- License: bsd-3-clause
- Created: 2023-05-28T21:04:08.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-07-29T18:56:39.000Z (12 months ago)
- Last Synced: 2025-02-07T19:49:26.417Z (5 months ago)
- Topics: ecs, entity-component-system, game-development, generics, go, golang, golang-library
- Language: Go
- Homepage:
- Size: 19.5 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# go-ecs
[](https://pkg.go.dev/github.com/jabolopes/go-ecs)
This library provides a generic Entity Component System for developing
games.```go
// Construction.
e := ecs.New()// Create entities.
entity := e.Add()// Delete entities.
e.Delete(entity)// Set component in entity.
ecs.Set(e, MyComponent{value})
ecs.Set2(e, MyComponent{value1}, OtherComponent{value2})// Get component(s) given entity ID.
c, ok := ecs.Get[MyComponent](e, entityId)c1, c2, ok := ecs.Get2[MyComponent, OtherComponent](e, entityId)
// Unset (or remove) component from entity.
ecs.Unset[MyComponent](e, entityId)// Iterate all entities that have a component.
for it := ecs.Iterate[MyComponent](e); ; {
c, ok := it.Next()
if !ok {
break
}// Do something with 'c'.
}// Iterate all entities that have both components.
for it := ecs.Join[MyComponent, OtherComponent](e); ; {
c1, c2, ok := it.Next()
if !ok {
break
}// Do something with 'c1' and 'c2'.
}// Iterate all entities that have all 3 components.
for it := ecs.Join3[MyC1, MyC2, MyC3](e) ; ; { ... }// Get singleton entity with given component.
entityID, c, ok := e.IterateAny[MyComponent](e)// Get singleton entity with both components.
entityID, c1, c2, ok := e.JoinAny[MyComponent, OtherComponents](e)
```