2023-06-12 15:09:53 +08:00
< p align = "center" >
2023-06-12 15:13:07 +08:00
< img width = "400" src = "https://github.com/DCFApixels/DragonECS-ClassicThreads/assets/99481254/fe788eb4-dcb5-40a9-b25f-4094753bc021.png" >
2023-06-12 15:09:53 +08:00
< / p >
< p align = "center" >
< img alt = "Version" src = "https://img.shields.io/github/package-json/v/DCFApixels/DragonECS-ClassicThreads?color=%23ff4e85&style=for-the-badge" >
< img alt = "License" src = "https://img.shields.io/github/license/DCFApixels/DragonECS-ClassicThreads?color=ff4e85&style=for-the-badge" >
2024-06-16 01:11:33 +08:00
< a href = "https://discord.gg/kqmJjExuCf" > < img alt = "Discord" src = "https://img.shields.io/badge/Discord-JOIN-00b269?logo=discord&logoColor=%23ffffff&style=for-the-badge" > < / a >
< a href = "http://qm.qq.com/cgi-bin/qm/qr?_wv=1027&k=IbDcH43vhfArb30luGMP1TMXB3GCHzxm&authKey=s%2FJfqvv46PswFq68irnGhkLrMR6y9tf%2FUn2mogYizSOGiS%2BmB%2B8Ar9I%2Fnr%2Bs4oS%2B&noverify=0&group_code=949562781" > < img alt = "QQ" src = "https://img.shields.io/badge/QQ-JOIN-00b269?logo=tencentqq&logoColor=%23ffffff&style=for-the-badge" > < / a >
2023-06-12 15:09:53 +08:00
< / p >
# Classic C# Threads for [DragonECS](https://github.com/DCFApixels/DragonECS)
2024-11-12 13:01:37 +08:00
< table >
< tr > < / tr >
< tr >
< td colspan = "3" > Readme Languages:< / td >
< / tr >
< tr > < / tr >
< tr >
< td nowrap width = "100" >
< a href = "https://github.com/DCFApixels/DragonECS-ClassicThreads/blob/main/README-RU.md" >
< img src = "https://github.com/user-attachments/assets/7bc29394-46d6-44a3-bace-0a3bae65d755" > < / br >
< span > Русский< / span >
< / a >
< / td >
< td nowrap width = "100" >
< a href = "https://github.com/DCFApixels/DragonECS-ClassicThreads" >
< img src = "https://github.com/user-attachments/assets/3c699094-f8e6-471d-a7c1-6d2e9530e721" > < / br >
< span > English< / span >
< / a >
< / td >
< / tr >
< / table >
< / br >
2023-06-12 15:09:53 +08:00
2024-11-12 16:00:56 +08:00
Support for processing entities in multiple threads, based on classic C# threads implementation. Inspired by a similar extension for [LeoEcs Lite ](https://github.com/Leopotam/ecslite-threads ).
2024-11-12 13:19:38 +08:00
> [!WARNING]
> The project is a work in progress, API may change.
>
> The most current version of the README is in [Russian version](https://github.com/DCFApixels/DragonECS-ClassicThreads/blob/main/README-RU.md).
2023-06-12 15:09:53 +08:00
2024-03-11 00:12:09 +08:00
< / br >
# Installation
Versioning semantics - [Open ](https://gist.github.com/DCFApixels/e53281d4628b19fe5278f3e77a7da9e8#file-dcfapixels_versioning_ru-md )
## Environment
Requirements:
+ Dependency: [DragonECS ](https://github.com/DCFApixels/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
2024-11-12 13:01:37 +08:00
The package can be installed as a Unity package by adding the Git URL [in the PackageManager ](https://docs.unity3d.com/2023.2/Documentation/Manual/upm-ui-giturl.html ) or manually adding it to `Packages/manifest.json` :
2024-03-11 00:12:09 +08:00
```
https://github.com/DCFApixels/DragonECS-ClassicThreads.git
```
* ### Source Code
2024-11-12 13:01:37 +08:00
The package can also be added to the project as source code.
2024-03-11 00:12:09 +08:00
< / br >
# Parallel iteration
``` csharp
EcsThreadHandler _handler;
public void Run(EcsPipeline pipeline)
{
2024-11-12 13:01:37 +08:00
// Getting the Aspect and entities for iteration.
2024-03-11 00:12:09 +08:00
var group = _world.Where(out Aspect a);
2024-11-12 13:01:37 +08:00
2024-03-11 00:12:09 +08:00
void Handler(ReadOnlySpan< int > entities)
{
foreach (var e in entities)
{
2024-11-12 13:01:37 +08:00
// Computations in a separate thread.
2024-03-11 00:12:09 +08:00
a.poses.Get(e).position += a.velocities.Read(e).value * _time.DeltaTime;
}
}
2024-11-12 13:01:37 +08:00
// Starts parallel iteration over entities,
// entities will be split into parts with a minimum size of 1000.
2024-03-11 00:12:09 +08:00
group.IterateParallel(_handler ??= Handler, 1000);
}
```
2024-11-12 13:01:37 +08:00
> 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.
2024-03-11 00:12:09 +08:00
2024-11-12 13:01:37 +08:00
> Inside the handler, creating/deleting entities, adding/removing components on entities is prohibited. Only modification of data within components is allowed.