Go to file
2025-03-15 17:09:19 +08:00
src defines refactoring 2025-03-15 15:10:47 +08:00
.gitattributes Initial commit 2023-06-07 02:09:20 +08:00
.gitignore Update .gitignore 2025-01-06 10:51:46 +08:00
DragonECS-Threads.asmdef Initial commit 2023-06-07 21:34:12 +08:00
DragonECS-Threads.asmdef.meta Initial commit 2023-06-07 21:34:12 +08:00
LICENSE.md add .md extension for LICENSE 2025-03-14 14:24:23 +08:00
LICENSE.md.meta add .md extension for LICENSE 2025-03-14 14:24:23 +08:00
package.json up version to 0.2.6 2025-03-15 17:09:19 +08:00
package.json.meta change git ignore 2023-06-12 23:01:07 +08:00
README-RU.md update readme 2024-11-12 16:00:56 +08:00
README-RU.md.meta change git ignore 2023-06-12 23:01:07 +08:00
README.md update readme 2024-11-12 16:00:56 +08:00
README.md.meta change git ignore 2023-06-12 23:01:07 +08:00
src.meta change git ignore 2023-06-12 23:01:07 +08:00

Version License Discord QQ

Classic C# Threads for DragonECS

Readme Languages:

Русский

English

Support for processing entities in multiple threads, based on classic C# threads implementation. Inspired by a similar extension for LeoEcs Lite.

Warning

The project is a work in progress, API may change.

The most current version of the README is in Russian version.


Installation

Versioning semantics - Open

Environment

Requirements:

  • Dependency: DragonECS
  • Minimum version of C# 7.3;

Optional:

  • Support for NativeAOT
  • Game engines with C#: Unity, Godot, MonoGame, etc.

Tested with:

  • Unity: Minimum version 2020.1.0;

Unity Installation

  • Unity Package

The package can be installed as a Unity package by adding the Git URL in the PackageManager or manually adding it to Packages/manifest.json:

https://github.com/DCFApixels/DragonECS-ClassicThreads.git
  • Source Code

The package can also be added to the project as source code.


Parallel iteration

EcsThreadHandler _handler;
public void Run(EcsPipeline pipeline)
{
    // Getting the Aspect and entities for iteration.
    var group = _world.Where(out Aspect a);

    void Handler(ReadOnlySpan<int> entities)
    {
        foreach (var e in entities)
        {
            // Computations in a separate thread.
            a.poses.Get(e).position += a.velocities.Read(e).value * _time.DeltaTime;
        }
    }

    // Starts parallel iteration over entities,
    // entities will be split into parts with a minimum size of 1000.
    group.IterateParallel(_handler ??= Handler, 1000);
}

The smaller the minimum size of the group part when dividing, the more threads can be utilized. In some situations, too many threads can negatively impact performance.

Inside the handler, creating/deleting entities, adding/removing components on entities is prohibited. Only modification of data within components is allowed.