-
Notifications
You must be signed in to change notification settings - Fork 1
Home
Myriad.ECS is a high performance Entity Component System (ECS) for C#.
Entities are just IDs, associated with a set of components. A component can be any type (managed or unmanaged) that implements IComponent.
public record struct Position(Vector2 Value) : IComponent;
public record struct Velocity(Vector2 Value) : IComponent;
IComponent
is simply a tag that ensures you cannot accidentally attach something to an entity that you didn't mean to. For example adding a Vector2
directly, instead of a Position
or Velocity
component.
There are some special components:
The only way to make structural changes to the world (creating or destroying entities, adding or removing components) is through a CommandBuffer
. A CommandBuffer
allows you to queue multiple commands, the world is only modified when the buffered is executed.
var buffer = new CommandBuffer(world);
// Create an entity. This returns a "buffered entity" object that can be used to resolve the real Entity when it is eventually created
var bufferedEntity = buffer.Create()
.Set(new Position(new Vector3(1, 2, 3)))
.Set(new Velocity(new Vector3(0, 1, 0)))
.Set(new Mass(1));
// Execute the buffer, receive a "resolver". You can call `Resolve` on entities until this resolve is disposed.
using var resolver = buffer.Playback();
// Resolve the buffered entity into a real Entity
var entity = bufferedEntity.Resolve();
Queries can be filtered based on the components an Entity has. This is done with a QueryDescription
. There are 4 types filtering a query can do:
- Include: Entities must include this component.
- Exclude: Entities must not include this component.
- At Least One: Entities must contain one or more of the listed components.
- Exactly One: Entities must contain exactly one of the listed components.
Myriad.ECS has several different querying systems:
- Query (+Parallel version)
- Chunk Query (+Parallel version)
- Delegate Query
- Enumerable Query
- SIMD Chunk Query
- Map/Reduce Query
A Myriad World
can be used without any systems, as a very specialised type of in-memroy database. However, if you're building a game with a large set of systems which need to "tick" every frame Myriad does contain a set of systems.