**Friflo.Engine.ECS

July 28, 2024 · View on GitHub

logo        SPLASH

Github Repo Demos Wiki

Friflo.Engine.ECS  ·  API Reference

This project contains the C# API reference of Friflo Engine ECS - GitHub.

NamespaceDescription
Friflo.Engine.ECSContains types and methods to query, add, remove or change Entity's in an EntityStore.
Friflo.Engine.ECS.CollectionsContains types to enable data binding for common .NET applications.
Friflo.Engine.ECS.IndexEnables search for indexed component values in O(1) for types: string, int, enum, float, Guid, DateTime, ....
Support efficient entity relationships like entity links (foreign keys) and back links (JOIN's).
Friflo.Engine.ECS.SerializeContains types and methods to serialize / deserialize Entity's as JSON.
Friflo.Engine.ECS.SystemsUsed to organize and execute a set of systems within a SystemRoot.
Friflo.Engine.ECS.UtilsUtility types and methods typically used by generic libraries.

Common used structs and classes.

TypeDescription
EntityStoreclassContainer of entities. Typically called World in other implementations.
EntitystructAn object in an EntityStore. Contains components, tags, scripts and child entities.
IComponentinterfaceAttribute structs as component types.
ITaginterfaceAttribute structs as tags.
ScriptclassBase class of scripts that can be added to entities.
ArchetypeQueryclassUsed to return components and entities matching the assigned query filter.
QueryJobclassEnables parallel query execution.
ParallelJobRunnerclassRequired for parallel (multi threaded) query execution.
CommandBufferclassRecord entity changes on arbitrary threads and Playback() them on the main thread.
EventFilterclassUsed to filter structural changes made to entities like added/removed components/tags.
EventRecorderclassRecord entity changes like adding/removing commands/tags. Required for EventFilter's.
EntityBatchclassUsed to optimize adding/removing components/tags to entities via a fluent API.
CreateEntityBatchclassUsed to optimize entity creation via a fluent API.
EntitySerializerclassEnables serialization of entities to / from JSON.

Hello World

The hello world examples demonstrates the creation of some entities
and their movement using a simple ForEachEntity() call.

Much more examples at Friflo.Engine.ECS · Examples

public struct Velocity : IComponent { public Vector3 value; }

public static void HelloWorld()
{
    var store = new EntityStore();
    for (int n = 0; n < 10; n++) {
        store.CreateEntity(new Position(n, 0, 0), new Velocity{ value = new Vector3(0, n, 0)});
    }
    var query = store.Query<Position, Velocity>();
    query.ForEachEntity((ref Position position, ref Velocity velocity, Entity entity) => {
        position.value += velocity.value;
    });
}

Interactive Browser Demo showing MonoGame WebAssembly integration. Try out Demo.
Note: WebGL rendering performance cannot compete with Desktop build.