- 
                Notifications
    
You must be signed in to change notification settings  - Fork 2
 
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:
- 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. All queries run some code against all entities which match a query, but differ in details:
- Query (+Parallel version): Write query code as a struct.
 - Chunk Query (+Parallel version): Returns results as entire chunks of entities, instead of one by one.
 - Delegate Query: Write query code as a delegate.
 - Enumerable Query: Returns an enumerable of entities+components.
 - SIMD Chunk Query: Converts components into SIMD vectors.
 - Map/Reduce Query: Map entities to values, and reduce to one singular value.
 - Cursor Query: Runs the query until a limit is hit, returns a handle allowing the query to be resumed.
 - Collect Query: Collect entities which match the query filter into a collection.
 
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.