### DefaultEcs System Initialization and Game Loop Source: https://context7.com/doraku/defaultecs/llms.txt Shows how to initialize a World, set up a parallel runner, create a sequential system loop with different system types, and create entities for processing. This is a basic usage example for the DefaultEcs framework. ```csharp // Usage World world = new World(); IParallelRunner runner = new DefaultParallelRunner(Environment.ProcessorCount); ISystem gameLoop = new SequentialSystem( new MovementSystem(world, runner), // Parallel processing new DamageOverTimeSystem(world), // Sequential processing new VelocitySystem(world, runner) // Parallel processing ); // Create test entities for (int i = 0; i < 10000; i++) { Entity entity = world.CreateEntity(); entity.Set(new Position { X = i, Y = 0 }); entity.Set(new Velocity { Value = new Vector2(1, 0) }); } while (gameRunning) { gameLoop.Update(GetDeltaTime()); } ``` -------------------------------- ### Particle System Usage Example Source: https://context7.com/doraku/defaultecs/llms.txt This code demonstrates the creation of a World, a parallel runner, and the instantiation of numerous entities with ParticleData components, followed by the creation of a ParticleSystem to process them. ```csharp // Usage World world = new World(); IParallelRunner runner = new DefaultParallelRunner(Environment.ProcessorCount); // Create many particles for (int i = 0; i < 100000; { Entity particle = world.CreateEntity(); particle.Set(new ParticleData { Position = new Vector2(400, 300), Velocity = new Vector2(Random.Shared.Next(-100, 100), Random.Shared.Next(-200, 0)), Life = Random.Shared.NextSingle() * 3f, Color = Color.White }); } ISystem particleSystem = new ParticleSystem(world, runner); ``` -------------------------------- ### RenderSystem with PreUpdate/PostUpdate Overrides Source: https://context7.com/doraku/defaultecs/llms.txt Demonstrates overriding PreUpdate and PostUpdate methods for setup and cleanup operations, such as starting and ending a SpriteBatch. This system renders entities with Position and Sprite components. ```csharp // Method 4: Override PreUpdate/PostUpdate for setup/cleanup public sealed class RenderSystem : AEntitySetSystem { private SpriteBatch _currentBatch; public RenderSystem(World world) : base(world.GetEntities().With().With().AsSet()) { } protected override void PreUpdate(SpriteBatch batch) { _currentBatch = batch; batch.Begin(SpriteSortMode.BackToFront); } protected override void Update(SpriteBatch batch, in Entity entity) { Position pos = entity.Get(); Sprite sprite = entity.Get(); _currentBatch.Draw(sprite.Texture, new Vector2(pos.X, pos.Y), Color.White); } protected override void PostUpdate(SpriteBatch batch) { batch.End(); } } ``` -------------------------------- ### Initialize BinarySerializer Source: https://github.com/doraku/defaultecs/blob/master/documentation/api/BinarySerializer.BinarySerializer().md Use this constructor to create a new instance of the BinarySerializer class. No specific setup or imports are required beyond having the DefaultEcs library available. ```csharp public BinarySerializer(); ``` -------------------------------- ### Game Loop Integration with Parallel Runner Source: https://context7.com/doraku/defaultecs/llms.txt Shows the setup for a game loop utilizing a parallel runner and an EntityCommandRecorder for systems that require thread-safe operations. Ensures proper disposal of resources. ```csharp // Usage in game loop IParallelRunner runner = new DefaultParallelRunner(Environment.ProcessorCount); EntityCommandRecorder gameRecorder = new EntityCommandRecorder(4096, 65536); ISystem damageSystem = new DamageSystem(world, gameRecorder, runner); while (gameRunning) { damageSystem.Update(GetDeltaTime()); } gameRecorder.Dispose(); ``` -------------------------------- ### Custom System for Half Framerate Updates in C# Source: https://github.com/doraku/defaultecs/blob/master/documentation/FAQ.md Implement a system that updates at half the framerate using a decorator pattern. This example uses a boolean flag to alternate updates. ```csharp public sealed HalfUpdateSystem : ISystem { private readonly ISystem _system; private bool _oddUpdate; public HalfUpdateSystem(params ISystem systems) { _systems = new SequentialSystem(systems); _oddUpdate = false; } public bool IsEnabled { get; set; } = true; public void Update(T state) { if (IsEnabled && (_oddUpdate = !_oddUpdate)) { _system.Update(state); } } public void Dispose() => _system.Dispose(); } ``` -------------------------------- ### Get Entities Query Builder Source: https://github.com/doraku/defaultecs/blob/master/documentation/api/World.GetEntities().md Use this method to get an EntityQueryBuilder for creating subsets of entities. This is the starting point for querying entities based on their components. ```csharp public DefaultEcs.EntityQueryBuilder GetEntities(); ``` -------------------------------- ### Initialize and Run System with ParallelRunner Source: https://github.com/doraku/defaultecs/blob/master/README.md Demonstrates how to initialize a system with an IParallelRunner for multi-threaded execution and then run the system's update loop. ```csharp IParallelRunner runner = new DefaultParallelRunner(Environment.ProcessorCount); ISystem system = new VelocitySystem(world, runner); // this will process the update on Environment.ProcessorCount threads system.Update(elapsedTime); ``` -------------------------------- ### Constructor: AComponentSystem(DefaultEcs.World) Source: https://github.com/doraku/defaultecs/wiki/DefaultEcs-System-AComponentSystem-TState-_TComponent---ctor(DefaultEcs-World) Initializes a new instance of the AComponentSystem class using a specified DefaultEcs.World instance. ```APIDOC ## Constructor: AComponentSystem(DefaultEcs.World) ### Description Initializes a new instance of the AComponentSystem class with the provided DefaultEcs.World instance. ### Parameters #### Path Parameters - **world** (DefaultEcs.World) - Required - The DefaultEcs.World on which to process the update. ### Exceptions - **System.ArgumentNullException** - Thrown when the provided world parameter is null. ``` -------------------------------- ### Get All Components of Type T Source: https://github.com/doraku/defaultecs/blob/master/documentation/api/World.GetAll_T_().md Use this method to get a Span of all components of the specified type T. This span allows for direct editing of component values. ```csharp public System.Span GetAll(); ``` -------------------------------- ### Get Entity Predicate from QueryBuilder Source: https://github.com/doraku/defaultecs/blob/master/documentation/api/EntityQueryBuilder.AsPredicate().md Use this method to get a System.Predicate that represents the query rules defined by the EntityQueryBuilder. This predicate can be used for filtering. ```csharp public System.Predicate AsPredicate(); ``` -------------------------------- ### DefaultEcs.System.ASystem Constructor Source: https://github.com/doraku/defaultecs/wiki/DefaultEcs-System-ASystem-T---ctor() Initializes a new instance of the DefaultEcs.System.ASystem class. ```APIDOC ## DefaultEcs.System.ASystem Constructor ### Description Initialise a new instance of the [DefaultEcs.System.ASystem](./DefaultEcs-System-ASystem-T- 'DefaultEcs.System.ASystem') class. ### Method constructor ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ``` -------------------------------- ### DefaultEcs.System.AComponentSystem Constructor Source: https://github.com/doraku/defaultecs/wiki/DefaultEcs-System-AComponentSystem-TState-_TComponent---ctor(DefaultEcs-World-_DefaultEcs-System-SystemRunner-TState-) Initializes a new instance of the DefaultEcs.System.AComponentSystem class. ```APIDOC ## #ctor(DefaultEcs.World, DefaultEcs.System.SystemRunner) ### Description Initialise a new instance of the [DefaultEcs.System.AComponentSystem](./DefaultEcs-System-AComponentSystem-TState-_TComponent- 'DefaultEcs.System.AComponentSystem<TState, TComponent>') class with the given [DefaultEcs.World](./DefaultEcs-World 'DefaultEcs.World') and [DefaultEcs.System.SystemRunner](./DefaultEcs-System-SystemRunner-T- 'DefaultEcs.System.SystemRunner<T>'). ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Method Constructor ### Endpoint N/A ### Request Example None ### Response #### Success Response (200) None #### Response Example None ### Exceptions - **System.ArgumentNullException**: Thrown when the 'world' parameter is null. ``` -------------------------------- ### World.Enumerator.System.Collections.IEnumerator.Current Property Source: https://github.com/doraku/defaultecs/blob/master/documentation/api/World.Enumerator.System.Collections.IEnumerator.Current.md Gets the Entity at the current position of the enumerator. ```APIDOC ## World.Enumerator.System.Collections.IEnumerator.Current Property ### Description Gets the [Entity](Entity.md 'DefaultEcs.Entity') at the current position of the enumerator. ### Method GET ### Endpoint N/A (Property Access) ### Response #### Success Response (200) - **entity** (Entity) - The current Entity being enumerated. ``` -------------------------------- ### Create and Manage Entities Source: https://context7.com/doraku/defaultecs/llms.txt Shows how to create entities, add/set/remove components, manage entity/component enabled states, and share component values between entities. ```csharp using DefaultEcs; World world = new World(); // Create entities Entity player = world.CreateEntity(); Entity enemy = world.CreateEntity(); // Add components to entities player.Set(new Position { X = 100, Y = 200 }); player.Set(new Velocity { X = 0, Y = 0 }); player.Set(new Health { Current = 100, Max = 100 }); player.Set(); // Empty struct as a tag component enemy.Set(new Position { X = 500, Y = 200 }); enemy.Set(new Velocity { X = -50, Y = 0 }); enemy.Set(new Health { Current = 50, Max = 50 }); enemy.Set(); // Check if entity has a component if (player.Has()) { // Get component by reference for modification ref Health health = ref player.Get(); health.Current -= 10; // Notify queries of component change (required for WhenChanged queries) player.NotifyChanged(); } // Alternative: Set replaces component and auto-notifies queries player.Set(new Health { Current = 80, Max = 100 }); // Remove a component enemy.Remove(); // Disable/enable entity (temporarily removes from queries) enemy.Disable(); bool isEnabled = enemy.IsEnabled(); // false enemy.Enable(); // Disable/enable specific component player.Disable(); // Entity still has Health, but queries ignore it player.Enable(); // Check if entity is still valid if (player.IsAlive) { // Dispose entity when no longer needed player.Dispose(); } // Share component value between entities Entity template = world.CreateEntity(); template.Set(new SharedConfig { Speed = 100 }); Entity instance1 = world.CreateEntity(); Entity instance2 = world.CreateEntity(); instance1.SetSameAs(template); instance2.SetSameAs(template); // Changing template's component affects all sharing entities template.Get().Speed = 150; // instance1 and instance2 also see 150 // Share with world-level component world.Set(new GlobalSettings { Volume = 0.8f }); Entity audioEntity = world.CreateEntity(); audioEntity.SetSameAsWorld(); ``` -------------------------------- ### World.Enumerator.Current Property Source: https://github.com/doraku/defaultecs/blob/master/documentation/api/World.Enumerator.Current.md Gets the Entity at the current position of the enumerator. ```APIDOC ## World.Enumerator.Current Property ### Description Gets the [Entity](Entity.md 'DefaultEcs.Entity') at the current position of the enumerator. ### Method GET ### Endpoint N/A (Property) ### Parameters N/A ### Request Example N/A ### Response #### Success Response (200) - **Current** (Entity) - The current Entity in the enumerator. #### Response Example ```json { "Current": "[Entity Object]" } ``` ``` -------------------------------- ### GET AResourceManager.ResourceEnumerable.GetEnumerator Source: https://github.com/doraku/defaultecs/blob/master/documentation/api/AResourceManager_TInfo,TResource_.ResourceEnumerable.System.Collections.IEnumerable.GetEnumerator().md Retrieves an enumerator to iterate through the ResourceEnumerable collection. ```APIDOC ## GetEnumerator() ### Description Returns an enumerator that iterates through the collection. ### Method N/A (Class Method) ### Endpoint DefaultEcs.Resource.AResourceManager.ResourceEnumerable.System.Collections.IEnumerable.GetEnumerator() ### Response - **System.Collections.IEnumerator** - An enumerator that can be used to iterate through the collection. ``` -------------------------------- ### GET AResourceManager.ResourceEnumerator.Current Source: https://github.com/doraku/defaultecs/blob/master/documentation/api/AResourceManager_TInfo,TResource_.ResourceEnumerator.Current.md Retrieves the resource at the current position of the enumerator. ```APIDOC ## GET AResourceManager.ResourceEnumerator.Current ### Description Gets the resource at the current position of the enumerator. ### Property Value - **Current** (System.Collections.Generic.KeyValuePair) - The resource at the current position of the enumerator. ### Implementation - Implements System.Collections.Generic.IEnumerator.Current - Implements System.Collections.IEnumerator.Current ``` -------------------------------- ### Initialize ParallelSystem Source: https://github.com/doraku/defaultecs/blob/master/documentation/api/ParallelSystem_T_.ParallelSystem(IParallelRunner,IEnumerable_ISystem_T__).md Constructor for creating a new ParallelSystem instance. Throws ArgumentNullException if either the runner or systems arguments are null. ```csharp public ParallelSystem(DefaultEcs.Threading.IParallelRunner runner, System.Collections.Generic.IEnumerable> systems); ``` -------------------------------- ### IsEnabled Property Source: https://github.com/doraku/defaultecs/blob/master/documentation/api/DefaultEcs.md Gets or sets the enabled state of the AEntitySetSystem instance. ```APIDOC ## PROPERTY IsEnabled ### Description Gets or sets whether the current AEntitySetSystem instance should update or not. ### Response - **IsEnabled** (bool) - The current enabled status. ``` -------------------------------- ### Implement ActionSystem Source: https://github.com/doraku/defaultecs/blob/master/README.md Creates a system from a custom action method to be executed during updates. ```csharp private void Exit(float elapsedTime) { if (EscapedIsPressed) { // escape code } } ... ISystem system = new ActionSystem(Exit); ... // this will call the Exit method as a system system.Update(elapsedTime); ``` -------------------------------- ### World.MaxCapacity Property Source: https://github.com/doraku/defaultecs/blob/master/documentation/api/World.MaxCapacity.md Gets the maximum number of Entity this World can handle. ```APIDOC ## World.MaxCapacity Property ### Description Gets the maximum number of [Entity](Entity.md 'DefaultEcs.Entity') this [World](World.md 'DefaultEcs.World') can handle. ### Method GET ### Endpoint /doraku/defaultecs/world/maxcapacity ### Response #### Success Response (200) - **MaxCapacity** (int) - The maximum number of entities the World can handle. ``` -------------------------------- ### DefaultEcs.System.ParallelSystem Constructor Source: https://github.com/doraku/defaultecs/wiki/DefaultEcs-System-ParallelSystem-T---ctor(DefaultEcs-System-ISystem-T--_DefaultEcs-System-SystemRunner-T--_DefaultEcs-System-ISystem-T---) Initializes a new instance of the DefaultEcs.System.ParallelSystem class. ```APIDOC ## #ctor(DefaultEcs.System.ISystem, DefaultEcs.System.SystemRunner, DefaultEcs.System.ISystem[]) ParallelSystem Constructor ### Description Initialises a new instance of the [DefaultEcs.System.ParallelSystem](./DefaultEcs-System-ParallelSystem-T- 'DefaultEcs.System.ParallelSystem') class. ### Method Constructor ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **mainSystem** (DefaultEcs.System.ISystem) - Required - The [DefaultEcs.System.ISystem](./DefaultEcs-System-ISystem-T- 'DefaultEcs.System.ISystem') instance to be updated on the calling thread. - **runner** (DefaultEcs.System.SystemRunner) - Required - The [DefaultEcs.System.SystemRunner](./DefaultEcs-System-SystemRunner-T- 'DefaultEcs.System.SystemRunner') used to process the update in parallel if not null. - **systems** (DefaultEcs.System.ISystem[]) - Required - The [DefaultEcs.System.ISystem](./DefaultEcs-System-ISystem-T- 'DefaultEcs.System.ISystem') instances. ### Request Example None ### Response #### Success Response (200) None #### Response Example None ``` -------------------------------- ### DefaultEcs.System.ParallelSystem Constructors Source: https://github.com/doraku/defaultecs/wiki/DefaultEcs-System-ParallelSystem-T- Provides information on how to instantiate the ParallelSystem. ```APIDOC ## DefaultEcs.System.ParallelSystem ### Description Represents a collection of [DefaultEcs.System.ISystem](./DefaultEcs-System-ISystem-T- 'DefaultEcs.System.ISystem') to update in parallel. ### Type parameters `T` The type of the object used as state to update the systems. ### Constructors - **`#ctor(DefaultEcs.System.ISystem, DefaultEcs.System.SystemRunner, DefaultEcs.System.ISystem[])`** Initializes a new instance of the `ParallelSystem` class with a primary system, a system runner, and an array of additional systems. - **`#ctor(DefaultEcs.System.SystemRunner, DefaultEcs.System.ISystem[])`** Initializes a new instance of the `ParallelSystem` class with a system runner and an array of systems. ``` -------------------------------- ### GET IParallelRunner.DegreeOfParallelism Source: https://github.com/doraku/defaultecs/blob/master/documentation/api/IParallelRunner.DegreeOfParallelism.md Retrieves the degree of parallelism configured for the IParallelRunner instance. ```APIDOC ## GET IParallelRunner.DegreeOfParallelism ### Description Gets the degree of parallelism used to run an IParallelRunnable. ### Property Value - **DegreeOfParallelism** (System.Int32) - The number of parallel tasks or threads utilized by the runner. ### Example ```csharp int degree = runner.DegreeOfParallelism; ``` ``` -------------------------------- ### AComponentSystem Constructors Source: https://github.com/doraku/defaultecs/blob/master/documentation/api/AComponentSystem_TState,TComponent_.md Initializes a new instance of the AComponentSystem class. ```APIDOC ## AComponentSystem Constructors ### AComponentSystem(World) Initialise a new instance of the AComponentSystem class with the given World. ### AComponentSystem(World, IParallelRunner) Initialise a new instance of the AComponentSystem class with the given World and IParallelRunner. ### AComponentSystem(World, IParallelRunner, int) Initialise a new instance of the AComponentSystem class with the given World, IParallelRunner, and an integer value. ``` -------------------------------- ### GET AEntitySortedSetSystem.World Property Source: https://github.com/doraku/defaultecs/blob/master/documentation/api/AEntitySortedSetSystem_TState,TComponent_.World.md Retrieves the World instance associated with the AEntitySortedSetSystem. ```APIDOC ## GET AEntitySortedSetSystem.World ### Description Gets the World instance on which the AEntitySortedSetSystem operates. ### Method GET ### Endpoint AEntitySortedSetSystem.World ### Response #### Success Response (200) - **World** (DefaultEcs.World) - The World instance associated with the system. ``` -------------------------------- ### GET EntitySet.World Property Source: https://github.com/doraku/defaultecs/blob/master/documentation/api/EntitySet.World.md Retrieves the World instance associated with the current EntitySet. ```APIDOC ## GET EntitySet.World ### Description Gets the World instance from which the current IEntityContainer originates. ### Method GET ### Endpoint EntitySet.World ### Response #### Success Response (200) - **World** (DefaultEcs.World) - The World instance associated with the entity set. ``` -------------------------------- ### AComponentSystem Constructor Source: https://github.com/doraku/defaultecs/blob/master/documentation/api/AComponentSystem_TState,TComponent_.AComponentSystem(World,IParallelRunner,int).md Initializes a new instance of the AComponentSystem class with the given World and IParallelRunner. ```APIDOC ## AComponentSystem(World, IParallelRunner, int) ### Description Initialise a new instance of the AComponentSystem class with the given World and IParallelRunner. ### Method Constructor ### Endpoint N/A (Constructor) ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response (200) N/A (Constructor) #### Response Example N/A ### Exceptions - **System.ArgumentNullException**: Thrown when the 'world' parameter is null. ``` -------------------------------- ### EntityMultiMap.Keys Property Source: https://github.com/doraku/defaultecs/blob/master/documentation/api/EntityMultiMap_TKey_.Keys.md Gets the keys contained in the EntityMultiMap. ```APIDOC ## EntityMultiMap.Keys Property ### Description Gets the keys contained in the [EntityMultiMap](EntityMultiMap_TKey_.md 'DefaultEcs.EntityMultiMap'). ### Method GET ### Endpoint N/A (Property Access) ### Parameters None ### Request Body None ### Response #### Success Response (200) - **Keys** (DefaultEcs.EntityMultiMap.KeyEnumerable) - An enumerable collection of keys. #### Response Example ```csharp // Example of accessing the Keys property var keys = entityMultiMap.Keys; ``` ``` -------------------------------- ### Constructor DefaultEcs.World Source: https://github.com/doraku/defaultecs/wiki/DefaultEcs-World--ctor() Initializes a new instance of the DefaultEcs.World class. ```APIDOC ## Constructor DefaultEcs.World ### Description Initializes a new instance of the DefaultEcs.World class. ### Method Constructor ### Endpoint DefaultEcs.World() ``` -------------------------------- ### AComponentSystem Constructor Source: https://github.com/doraku/defaultecs/blob/master/documentation/api/AComponentSystem_TState,TComponent_.AComponentSystem(World).md Initializes a new instance of the AComponentSystem class with the given World. ```APIDOC ## protected AComponentSystem(World world) ### Description Initialise a new instance of the AComponentSystem class with the given World. ### Method protected ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response (200) N/A #### Response Example N/A ### Exceptions [System.ArgumentNullException](https://docs.microsoft.com/en-us/dotnet/api/System.ArgumentNullException 'System.ArgumentNullException') - world is null. ``` -------------------------------- ### EntityMultiMap.KeyEnumerator.Current Property Source: https://github.com/doraku/defaultecs/blob/master/documentation/api/EntityMultiMap_TKey_.KeyEnumerator.Current.md Gets the TKey at the current position of the enumerator. ```APIDOC ## EntityMultiMap.KeyEnumerator.Current Property ### Description Gets the [TKey](EntityMultiMap_TKey_.KeyEnumerator.md#DefaultEcs.EntityMultiMap_TKey_.KeyEnumerator.TKey 'DefaultEcs.EntityMultiMap.KeyEnumerator.TKey') at the current position of the enumerator. ### Property Value [TKey](EntityMultiMap_TKey_.KeyEnumerator.md#DefaultEcs.EntityMultiMap_TKey_.KeyEnumerator.TKey 'DefaultEcs.EntityMultiMap.KeyEnumerator.TKey') ``` -------------------------------- ### EntityMap.KeyEnumerator.Current Property Source: https://github.com/doraku/defaultecs/blob/master/documentation/api/EntityMap_TKey_.KeyEnumerator.Current.md Gets the TKey at the current position of the enumerator. ```APIDOC ## EntityMap.KeyEnumerator.Current Property ### Description Gets the [TKey](EntityMap_TKey_.KeyEnumerator.md#DefaultEcs.EntityMap_TKey_.KeyEnumerator.TKey 'DefaultEcs.EntityMap.KeyEnumerator.TKey') at the current position of the enumerator. ### Method GET ### Endpoint N/A (Property access) ### Parameters N/A ### Request Example N/A ### Response #### Success Response (200) - **Current** (TKey) - The key at the current position of the enumerator. #### Response Example N/A ``` -------------------------------- ### ParallelSystem Constructor Source: https://github.com/doraku/defaultecs/blob/master/documentation/api/ParallelSystem_T_.ParallelSystem(ISystem_T_,IParallelRunner,IEnumerable_ISystem_T__).md Initializes a new instance of the ParallelSystem class. ```APIDOC ## ParallelSystem(ISystem, IParallelRunner, IEnumerable>) Constructor ### Description Initialises a new instance of the [ParallelSystem](ParallelSystem_T_.md 'DefaultEcs.System.ParallelSystem') class. ### Method Constructor ### Endpoint N/A (Constructor) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (Constructor) Initializes a ParallelSystem object. #### Response Example None ### Exceptions - **System.ArgumentNullException**: Thrown if `runner` is null. - **System.ArgumentNullException**: Thrown if `systems` is null. ``` -------------------------------- ### Initialize EntityCommandRecorder Source: https://github.com/doraku/defaultecs/blob/master/documentation/api/EntityCommandRecorder.EntityCommandRecorder(int,int).md Constructor for creating an EntityCommandRecorder with specified initial and maximum capacities. ```csharp public EntityCommandRecorder(int capacity, int maxCapacity); ``` -------------------------------- ### EntityMap.KeyEnumerator.Current Property Source: https://github.com/doraku/defaultecs/blob/master/documentation/api/EntityMap_TKey_.KeyEnumerator.System.Collections.IEnumerator.Current.md Gets the key at the current position of the enumerator. ```APIDOC ## EntityMap.KeyEnumerator.Current Property ### Description Gets the [TKey](EntityMap_TKey_.KeyEnumerator.md#DefaultEcs.EntityMap_TKey_.KeyEnumerator.TKey 'DefaultEcs.EntityMap.KeyEnumerator.TKey') at the current position of the enumerator. ### Method GET ### Endpoint N/A (Property Access) ### Response #### Success Response (200) - **Current** (object) - The key at the current position of the enumerator. ### Response Example ```json { "Current": "example_key_value" } ``` ``` -------------------------------- ### AComponentSystem Constructor Source: https://github.com/doraku/defaultecs/blob/master/documentation/api/AComponentSystem_TState,TComponent_.AComponentSystem(World,IParallelRunner).md Initializes a new instance of the AComponentSystem class with the specified World and IParallelRunner. ```APIDOC ## AComponentSystem Constructor ### Description Initializes a new instance of the AComponentSystem class with the given World and IParallelRunner. ### Parameters #### Path Parameters - **world** (DefaultEcs.World) - Required - The World on which to process the update. - **runner** (DefaultEcs.Threading.IParallelRunner) - Required - The IParallelRunner used to process the update in parallel if not null. ### Exceptions - **System.ArgumentNullException** - Thrown when the world parameter is null. ``` -------------------------------- ### EntityMap.Keys Property Source: https://github.com/doraku/defaultecs/blob/master/documentation/api/EntityMap_TKey_.Keys.md Gets the keys contained in the EntityMap. ```APIDOC ## EntityMap.Keys Property ### Description Gets the keys contained in the [EntityMap](EntityMap_TKey_.md 'DefaultEcs.EntityMap'). ```csharp public DefaultEcs.EntityMap.KeyEnumerable Keys { get; } ``` ### Property Value [DefaultEcs.EntityMap.KeyEnumerable<](EntityMap_TKey_.KeyEnumerable.md 'DefaultEcs.EntityMap.KeyEnumerable')[TKey](EntityMap_TKey_.md#DefaultEcs.EntityMap_TKey_.TKey 'DefaultEcs.EntityMap.TKey')[>](EntityMap_TKey_.KeyEnumerable.md 'DefaultEcs.EntityMap.KeyEnumerable') ``` -------------------------------- ### EntityCommandRecorder.Size Property Source: https://github.com/doraku/defaultecs/blob/master/documentation/api/EntityCommandRecorder.Size.md Gets the size taken by recorded commands in the current instance. ```APIDOC ## EntityCommandRecorder.Size Property ### Description Gets the size taken by recorded commands in current instance. ### Method GET ### Endpoint /doraku/defaultecs/EntityCommandRecorder/Size ### Response #### Success Response (200) - **Size** (int) - The size taken by recorded commands. ``` -------------------------------- ### Create and Manage ECS World Source: https://context7.com/doraku/defaultecs/llms.txt Demonstrates creating a World instance with default or custom capacity, setting component capacities, managing world-level components (singletons), and optimizing/disposing the world. ```csharp using DefaultEcs; using DefaultEcs.Threading; // Create a new world with default max entity count World world = new World(); // Create a world with a specific maximum entity count for better memory control World worldWithCapacity = new World(10000); // Set max capacity for a specific component type (must be called before any Set) world.SetMaxCapacity(5000); world.SetMaxCapacity(5000); // Store world-level components (singletons) world.Set(new GameConfiguration { Gravity = 9.8f, TimeScale = 1.0f }); world.Set(new DefaultParallelRunner(Environment.ProcessorCount)); // Access world-level components ref GameConfiguration config = ref world.Get(); config.TimeScale = 0.5f; // Slow motion // Check if world has a component if (world.Has()) { // Remove world-level component world.Remove(); } // Optimize internal data structures (call after initial entity creation) world.Optimize(); // Clean up resources world.Dispose(); ``` -------------------------------- ### GET DegreeOfParallelism Property Source: https://github.com/doraku/defaultecs/blob/master/documentation/api/DefaultParallelRunner.DegreeOfParallelism.md Retrieves the degree of parallelism configured for the DefaultParallelRunner instance. ```APIDOC ## GET DegreeOfParallelism ### Description Gets the degree of parallelism used to run an IParallelRunnable. ### Property Value - **DegreeOfParallelism** (System.Int32) - The number of parallel tasks allowed. ### Implementation ```csharp public int DegreeOfParallelism { get; } ``` ``` -------------------------------- ### GET /Components[Entity] Source: https://github.com/doraku/defaultecs/blob/master/documentation/api/Components_T_.this[Entity].md Retrieves a component of type T associated with a specific entity. ```APIDOC ## GET Components[Entity] ### Description Gets the component of type T on the provided Entity. ### Method GET ### Endpoint /Components[Entity] #### Parameters ##### Path Parameters * **entity** (Entity) - Required - The Entity for which to get the component of type T. ### Response #### Success Response (200) * **T** (T) - The component of type T associated with the entity. #### Response Example { "example": "// C# code example to retrieve a component\nvar myComponent = defaultEcs.Components()[entity];" } ``` -------------------------------- ### EntityCommandRecorder Constructor Source: https://github.com/doraku/defaultecs/blob/master/documentation/api/EntityCommandRecorder.EntityCommandRecorder(int).md Creates a fixed sized EntityCommandRecorder. ```APIDOC ## EntityCommandRecorder(int) Constructor ### Description Creates a fixed sized [EntityCommandRecorder](EntityCommandRecorder.md 'DefaultEcs.Command.EntityCommandRecorder'). ### Method Constructor ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response (200) N/A #### Response Example N/A ### Exceptions - **System.ArgumentException**: `maxCapacity` cannot be negative. ``` -------------------------------- ### ISystem.IsEnabled Property Source: https://github.com/doraku/defaultecs/blob/master/documentation/api/ISystem_T_.IsEnabled.md Gets or sets whether the current ISystem instance should update or not. ```APIDOC ## ISystem.IsEnabled Property ### Description Gets or sets whether the current [ISystem](ISystem_T_.md 'DefaultEcs.System.ISystem') instance should update or not. ### Property Type [System.Boolean](https://docs.microsoft.com/en-us/dotnet/api/System.Boolean 'System.Boolean') ``` -------------------------------- ### Integrate DefaultEcs into a Game Loop Source: https://github.com/doraku/defaultecs/blob/master/documentation/FAQ.md Demonstrates basic integration of ISystem into a standard game loop. Update and render processes can be separated into distinct systems. ```csharp ISystem mainSystem; GameState state; while (true) { mainSystem.Update(state); } ``` ```csharp ISystem updateSystem; ISystem renderSystem; GameState state; while (true) { updateSystem.Update(state); renderSystem.Update(state); } ``` -------------------------------- ### Implement Parallel Execution with DefaultParallelRunner Source: https://context7.com/doraku/defaultecs/llms.txt Demonstrates initializing a runner, integrating it into a system, executing custom tasks, and managing system sequences. ```csharp using DefaultEcs; using DefaultEcs.System; using DefaultEcs.Threading; // Create runner with specific thread count IParallelRunner runner = new DefaultParallelRunner(Environment.ProcessorCount); // Alternative: Use half the processors IParallelRunner lightRunner = new DefaultParallelRunner(Environment.ProcessorCount / 2); World world = new World(); // Store runner as world component for easy access world.Set(runner); // Systems with parallel processing [With, With] public sealed class ParallelMovementSystem : AEntitySetSystem { public ParallelMovementSystem(World world) : base(world, world.Get(), minEntityCountByRunnerIndex: 100) { } protected override void Update(float deltaTime, in Entity entity) { // This runs in parallel across multiple threads ref Position pos = ref entity.Get(); Velocity vel = entity.Get(); pos.X += vel.Value.X * deltaTime; pos.Y += vel.Value.Y * deltaTime; } } // Custom IParallelRunnable implementation public class CustomParallelTask : IParallelRunnable { private readonly int[] _data; private readonly int[] _results; public CustomParallelTask(int[] data, int[] results) { _data = data; _results = results; } public void Run(int index, int maxIndex) { // Divide work based on index int itemsPerThread = _data.Length / (maxIndex + 1); int start = index * itemsPerThread; int end = index == maxIndex ? _data.Length : start + itemsPerThread; for (int i = start; i < end; i++) { _results[i] = _data[i] * 2; // Some computation } } } // Execute custom parallel work int[] data = Enumerable.Range(0, 10000).ToArray(); int[] results = new int[data.Length]; runner.Run(new CustomParallelTask(data, results)); // IMPORTANT: Don't nest parallel runners // WRONG: ISystem wrongSystem = new ParallelSystem(runner, new ParallelMovementSystem(world), // These already use the same runner! new ParallelPhysicsSystem(world) ); // CORRECT: Use SequentialSystem for systems that internally use parallel runner ISystem correctSystem = new SequentialSystem( new ParallelMovementSystem(world), new ParallelPhysicsSystem(world) ); // Dispose runner when done runner.Dispose(); ``` -------------------------------- ### Get DegreeOfParallelism Property Source: https://github.com/doraku/defaultecs/blob/master/documentation/api/IParallelRunner.DegreeOfParallelism.md Retrieves the integer value representing the degree of parallelism for the runner. ```csharp int DegreeOfParallelism { get; } ``` -------------------------------- ### EntitySortedSet.Count Property Source: https://github.com/doraku/defaultecs/blob/master/documentation/api/EntitySortedSet_TComponent_.Count.md Gets the number of Entity in the current EntitySortedSet. ```APIDOC ## EntitySortedSet.Count Property ### Description Gets the number of [Entity](Entity.md 'DefaultEcs.Entity') in the current [EntitySortedSet<TComponent>](EntitySortedSet_TComponent_.md 'DefaultEcs.EntitySortedSet'). ### Property Value [System.Int32](https://docs.microsoft.com/en-us/dotnet/api/System.Int32 'System.Int32') ``` -------------------------------- ### DefaultEcs.System.AEntitySystem Constructor Source: https://github.com/doraku/defaultecs/wiki/DefaultEcs-System-AEntitySystem-T---ctor(DefaultEcs-World-_DefaultEcs-System-SystemRunner-T-) Initializes a new instance of the DefaultEcs.System.AEntitySystem class. ```APIDOC ## #ctor(DefaultEcs.World, DefaultEcs.System.SystemRunner) `constructor` ### Description Initialise a new instance of the [DefaultEcs.System.AEntitySystem](./DefaultEcs-System-AEntitySystem-T- 'DefaultEcs.System.AEntitySystem') class with the given [DefaultEcs.World](./DefaultEcs-World 'DefaultEcs.World').
To create the inner [DefaultEcs.EntitySet](./DefaultEcs-EntitySet 'DefaultEcs.EntitySet'), [DefaultEcs.System.WithAttribute](./DefaultEcs-System-WithAttribute 'DefaultEcs.System.WithAttribute') and [DefaultEcs.System.WithoutAttribute](./DefaultEcs-System-WithoutAttribute 'DefaultEcs.System.WithoutAttribute') attributes will be used. ### Parameters #### Path Parameters - **world** (DefaultEcs.World) - Required - The [DefaultEcs.World](./DefaultEcs-World 'DefaultEcs.World') from which to get the [DefaultEcs.Entity](./DefaultEcs-Entity 'DefaultEcs.Entity') instances to process the update. - **runner** (DefaultEcs.System.SystemRunner) - Required - The [DefaultEcs.System.SystemRunner](./DefaultEcs-System-SystemRunner-T- 'DefaultEcs.System.SystemRunner') used to process the update in parallel if not null. ### Exceptions - **System.ArgumentNullException** - [world](#DefaultEcs-System-AEntitySystem-T---ctor(DefaultEcs-World-_DefaultEcs-System-SystemRunner-T-)-world 'DefaultEcs.System.AEntitySystem.#ctor(DefaultEcs.World, DefaultEcs.System.SystemRunner).world') is null. ``` -------------------------------- ### Get EntitySet Count Source: https://github.com/doraku/defaultecs/blob/master/documentation/api/EntitySet.Count.md Retrieves the number of entities in the current EntitySet. This is a read-only property. ```csharp public int Count { get; set; } ``` -------------------------------- ### Constructor: AEntitySystem(DefaultEcs.World) Source: https://github.com/doraku/defaultecs/wiki/DefaultEcs-System-AEntitySystem-T---ctor(DefaultEcs-World) Initializes a new instance of the AEntitySystem class using a specified World instance. ```APIDOC ## Constructor: AEntitySystem(DefaultEcs.World) ### Description Initializes a new instance of the AEntitySystem class with the given DefaultEcs.World. The system uses WithAttribute and WithoutAttribute to create the inner EntitySet. ### Parameters #### Path Parameters - **world** (DefaultEcs.World) - Required - The World instance from which to retrieve Entity instances for processing. ### Exceptions - **System.ArgumentNullException** - Thrown when the provided world parameter is null. ``` -------------------------------- ### Entity Comparison and String Representation Source: https://github.com/doraku/defaultecs/blob/master/documentation/api/Entity.md Methods for comparing entities and getting their string representation. ```APIDOC ## GET /api/entity/to-string ### Description Returns a string representation of this entity instance. ### Method GET ### Endpoint /api/entity/to-string ### Response #### Success Response (200) - **representation** (string) - The string representation of the entity. #### Response Example ```json { "representation": "Entity(ID: 123)" } ``` ``` ```APIDOC ## GET /api/entity/operator/equals ### Description Determines whether two specified entities are the same. ### Method GET ### Endpoint /api/entity/operator/equals ### Parameters #### Query Parameters - **entity1** (Entity) - Required - The first entity to compare. - **entity2** (Entity) - Required - The second entity to compare. ### Response #### Success Response (200) - **areEqual** (boolean) - True if the entities are the same, false otherwise. #### Response Example ```json { "areEqual": true } ``` ``` ```APIDOC ## GET /api/entity/operator/not-equals ### Description Determines whether two specified entities are not the same. ### Method GET ### Endpoint /api/entity/operator/not-equals ### Parameters #### Query Parameters - **entity1** (Entity) - Required - The first entity to compare. - **entity2** (Entity) - Required - The second entity to compare. ### Response #### Success Response (200) - **areNotEqual** (boolean) - True if the entities are not the same, false otherwise. #### Response Example ```json { "areNotEqual": false } ``` ``` -------------------------------- ### ParallelSystem Constructor Source: https://github.com/doraku/defaultecs/blob/master/documentation/api/ParallelSystem_T_.ParallelSystem(IParallelRunner,IEnumerable_ISystem_T__).md Initializes a new instance of the ParallelSystem class. ```APIDOC ## ParallelSystem(IParallelRunner, IEnumerable>) Constructor ### Description Initialises a new instance of the [ParallelSystem](ParallelSystem_T_.md 'DefaultEcs.System.ParallelSystem') class. ### Method Constructor ### Endpoint N/A (Constructor) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (Constructor) Initializes a ParallelSystem object. #### Response Example None ### Parameters - **runner** (IParallelRunner) - Required - The [IParallelRunner](IParallelRunner.md 'DefaultEcs.Threading.IParallelRunner') used to process the update in parallel if not null. - **systems** (IEnumerable>) - Required - The [ISystem](ISystem_T_.md 'DefaultEcs.System.ISystem') instances. ### Exceptions - **System.ArgumentNullException**: If `runner` is null. - **System.ArgumentNullException**: If `systems` is null. ``` -------------------------------- ### Get EntityCommandRecorder Capacity Source: https://github.com/doraku/defaultecs/blob/master/documentation/api/EntityCommandRecorder.Capacity.md Retrieves the current capacity of the EntityCommandRecorder instance. This property is read-only. ```csharp public int Capacity { get; } ``` -------------------------------- ### Save and Load World State with Text and Binary Serializers Source: https://context7.com/doraku/defaultecs/llms.txt Demonstrates saving and loading the entire world state using both human-readable TextSerializer and optimized BinarySerializer. Ensure the save files are accessible. ```csharp using DefaultEcs; using DefaultEcs.Serialization; using System.IO; World world = new World(); // Create some entities Entity player = world.CreateEntity(); player.Set(new Position { X = 100, Y = 200 }); player.Set(new Health { Current = 80, Max = 100 }); player.Set(new PlayerData { Name = "Hero", Level = 5 }); Entity enemy = world.CreateEntity(); enemy.Set(new Position { X = 500, Y = 200 }); enemy.Set(new Health { Current = 50, Max = 50 }); enemy.Set(); // Text serialization (human-readable, editable) ISerializer textSerializer = new TextSerializer(); using (Stream stream = File.Create("savegame.txt")) { textSerializer.Serialize(stream, world); } // Load from text file World loadedWorld; using (Stream stream = File.OpenRead("savegame.txt")) { loadedWorld = textSerializer.Deserialize(stream); } // Binary serialization (faster, smaller) ISerializer binarySerializer = new BinarySerializer(); using (Stream stream = File.Create("savegame.bin")) { binarySerializer.Serialize(stream, world); } using (Stream stream = File.OpenRead("savegame.bin")) { loadedWorld = binarySerializer.Deserialize(stream); } // Serialize specific entities only Entity[] entitiesToSave = new[] { player }; using (Stream stream = File.Create("player.bin")) { binarySerializer.Serialize(stream, entitiesToSave); } // Load into existing world using (Stream stream = File.OpenRead("player.bin")) { binarySerializer.Deserialize(stream, world); } // Serialization context for custom type handling using BinarySerializationContext context = new BinarySerializationContext() // Transform types during serialization .Marshal(texture => texture.Name) // Save texture name instead of texture .Marshal(sound => sound.Name) // Transform back during deserialization .Unmarshal(name => ContentManager.Load(name)) .Unmarshal(name => ContentManager.Load(name)); BinarySerializer customSerializer = new BinarySerializer(context); // Filter which component types to serialize BinarySerializer filteredSerializer = new BinarySerializer( componentType => componentType != typeof(TransientData) // Skip TransientData ); // Serialize/deserialize individual objects using (Stream stream = File.Create("config.bin")) { BinarySerializer.Write(stream, new GameConfig { Volume = 0.8f }); } GameConfig config; using (Stream stream = File.OpenRead("config.bin")) { config = BinarySerializer.Read(stream); } loadedWorld.Dispose(); ``` -------------------------------- ### AEntitySetSystem.IsEnabled Property Source: https://github.com/doraku/defaultecs/blob/master/documentation/api/AEntitySetSystem_T_.IsEnabled.md Gets or sets whether the current AEntitySetSystem instance should update or not. ```APIDOC ## AEntitySetSystem.IsEnabled Property ### Description Gets or sets whether the current [AEntitySetSystem](AEntitySetSystem_T_.md 'DefaultEcs.System.AEntitySetSystem') instance should update or not. ### Property Value [System.Boolean](https://docs.microsoft.com/en-us/dotnet/api/System.Boolean 'System.Boolean') ``` -------------------------------- ### GET /DefaultEcs.World/GetEntities Source: https://github.com/doraku/defaultecs/wiki/DefaultEcs-World-GetEntities() Retrieves an EntitySetBuilder to create a subset of entities from the current World instance. ```APIDOC ## GET /DefaultEcs.World/GetEntities ### Description Gets an EntitySetBuilder to create a subset of Entity objects from the current World instance. ### Method GET ### Endpoint /DefaultEcs.World/GetEntities ### Response #### Success Response (200) - **EntitySetBuilder** (object) - An instance of DefaultEcs.EntitySetBuilder used to define entity subsets. ``` -------------------------------- ### Initialize AEntityMultiMapSystem Source: https://github.com/doraku/defaultecs/blob/master/documentation/api/AEntityMultiMapSystem_TState,TKey_.AEntityMultiMapSystem(World,IParallelRunner,int).md Constructor signature for initializing the AEntityMultiMapSystem class. ```csharp protected AEntityMultiMapSystem(DefaultEcs.World world, DefaultEcs.Threading.IParallelRunner runner, int minEntityCountByRunnerIndex=0); ``` -------------------------------- ### GET DefaultEcs.EntitySet.Count Source: https://github.com/doraku/defaultecs/wiki/DefaultEcs-EntitySet-Count Retrieves the total number of entities currently contained within a specific EntitySet. ```APIDOC ## GET DefaultEcs.EntitySet.Count ### Description Gets the number of DefaultEcs.Entity objects currently present in the DefaultEcs.EntitySet. ### Method GET ### Endpoint DefaultEcs.EntitySet.Count ### Response #### Success Response (200) - **Count** (int) - The total number of entities in the set. ``` -------------------------------- ### Initialize World with Capacity Source: https://github.com/doraku/defaultecs/blob/master/documentation/api/World.World(int).md Constructs a new World instance with a specified maximum entity capacity. The capacity value must be a non-negative integer. ```csharp public World(int maxCapacity); ``` -------------------------------- ### Get World MaxCapacity Source: https://github.com/doraku/defaultecs/blob/master/documentation/api/World.MaxCapacity.md Retrieves the maximum number of entities a World instance can handle. This is a read-only property. ```csharp public int MaxCapacity { get; } ``` -------------------------------- ### Implement IParallelRunnable.Run Method Source: https://github.com/doraku/defaultecs/blob/master/documentation/api/IParallelRunnable.Run(int,int).md Implement this method to define the work for a specific part of a parallel process. The index indicates the current part, and maxIndex indicates the total number of parts. ```csharp void Run(int index, int maxIndex); ``` -------------------------------- ### GET EntityMultiMap.this[TKey] Source: https://github.com/doraku/defaultecs/blob/master/documentation/api/EntityMultiMap_TKey_.this[TKey].md Retrieves the Entity instances associated with the specified key from the EntityMultiMap. ```APIDOC ## GET EntityMultiMap.this[TKey] ### Description Gets the Entity instances associated with the specified key. ### Method GET ### Parameters #### Path Parameters - **key** (TKey) - Required - The key of the Entity instances to get. ### Response #### Success Response (200) - **Value** (ReadOnlySpan) - A span containing the Entity instances associated with the key. ``` -------------------------------- ### Constructor: DefaultEcs.System.ActionSystem Source: https://github.com/doraku/defaultecs/wiki/DefaultEcs-System-ActionSystem-T---ctor(System-Action-T-) Initializes a new instance of the ActionSystem class using a specified System.Action delegate. ```APIDOC ## Constructor: DefaultEcs.System.ActionSystem ### Description Initializes a new instance of the ActionSystem class with the given System.Action delegate to be called as an update. ### Parameters #### Path Parameters - **action** (System.Action) - Required - The System.Action to call as update. ### Exceptions - **System.ArgumentNullException** - Thrown when the action parameter is null. ``` -------------------------------- ### EntityCommandRecorder Constructor Source: https://github.com/doraku/defaultecs/blob/master/documentation/api/EntityCommandRecorder.EntityCommandRecorder().md Initializes a new instance of the EntityCommandRecorder class with a default capacity. ```APIDOC ## EntityCommandRecorder() ### Description Creates a default sized EntityCommandRecorder of 1ko which can grow as needed. ### Method Constructor ### Request Example ```csharp public EntityCommandRecorder(); ``` ``` -------------------------------- ### EntityMultiMap.KeyEnumerator.Current Property Source: https://github.com/doraku/defaultecs/blob/master/documentation/api/EntityMultiMap_TKey_.KeyEnumerator.System.Collections.IEnumerator.Current.md Gets the TKey at the current position of the enumerator. This property implements the System.Collections.IEnumerator.Current interface. ```APIDOC ## EntityMultiMap.KeyEnumerator.Current Property ### Description Gets the [TKey](EntityMultiMap_TKey_.KeyEnumerator.md#DefaultEcs.EntityMultiMap_TKey_.KeyEnumerator.TKey 'DefaultEcs.EntityMultiMap.KeyEnumerator.TKey') at the current position of the enumerator. ### Method GET ### Endpoint N/A (Property Access) ### Parameters N/A ### Request Example N/A ### Response #### Success Response (200) - **Current** (TKey) - The key at the current position of the enumerator. #### Response Example ```csharp object System.Collections.IEnumerator.Current { get; } ``` ``` -------------------------------- ### Get Current Key in EntityMap Source: https://github.com/doraku/defaultecs/blob/master/documentation/api/EntityMap_TKey_.KeyEnumerator.Current.md Retrieves the key of the current element in the EntityMap. This property is part of the IEnumerator interface. ```csharp public TKey Current { get; } ```