mirror of
https://github.com/DCFApixels/DragonECS-ClassicThreads.git
synced 2025-09-18 03:44:34 +08:00
Compare commits
13 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
26df930329 | ||
![]() |
543534f447 | ||
![]() |
a38975cc7d | ||
![]() |
2faa845b31 | ||
![]() |
daa707ea0b | ||
![]() |
b32421ed95 | ||
![]() |
5b844a6be4 | ||
![]() |
ad9ab7baca | ||
![]() |
b05e7c7cf2 | ||
![]() |
6bde3981dd | ||
![]() |
68b5abc9ee | ||
![]() |
05fe8232f2 | ||
![]() |
0b7a6c4754 |
1
.gitignore
vendored
1
.gitignore
vendored
@ -35,6 +35,7 @@ ExportedObj/
|
||||
*.csproj
|
||||
*.unityproj
|
||||
*.sln
|
||||
*.sln.meta
|
||||
*.suo
|
||||
*.tmp
|
||||
*.user
|
||||
|
@ -1,6 +1,6 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2023 Mikhail
|
||||
Copyright (c) 2023 Mikhail(DCFApixels)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
49
README-RU.md
49
README-RU.md
@ -5,15 +5,38 @@
|
||||
<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">
|
||||
<!--<img alt="Discord" src="https://img.shields.io/discord/1111696966208999525?color=%23ff4e85&label=Discord&logo=Discord&logoColor=%23ff4e85&style=for-the-badge">-->
|
||||
<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>
|
||||
</p>
|
||||
|
||||
# Классические C# Threads для [DragonECS](https://github.com/DCFApixels/DragonECS)
|
||||
|
||||
| Languages: | [Русский](https://github.com/DCFApixels/DragonECS-ClassicThreads/blob/main/README-RU.md) | [English(WIP)](https://github.com/DCFApixels/DragonECS-ClassicThreads) |
|
||||
| :--- | :--- | :--- |
|
||||
<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/3c699094-f8e6-471d-a7c1-6d2e9530e721"></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/30528cb5-f38e-49f0-b23e-d001844ae930"></br>
|
||||
<span>English</span>
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
</br>
|
||||
|
||||
Поддержка обработки сущностей в нескольких потоках, на основе классической реализации потоков в C#. Вдохновленно аналогичным расширением для [LeoEcs Lite](https://github.com/Leopotam/ecslite-threads).
|
||||
|
||||
Поддержка обработки сущностей в нескольких потоках, на основе классической реализации потоков в C#.
|
||||
> [!WARNING]
|
||||
> Проект в стадии разработки. API может меняться.
|
||||
|
||||
@ -34,7 +57,7 @@
|
||||
+ Поддержка NativeAOT
|
||||
+ Игровые движки с C#: Unity, Godot, MonoGame и т.д.
|
||||
|
||||
Протестированно:
|
||||
Протестировано:
|
||||
+ **Unity:** Минимальная версия 2020.1.0;
|
||||
|
||||
## Установка для Unity
|
||||
@ -43,8 +66,8 @@
|
||||
```
|
||||
https://github.com/DCFApixels/DragonECS-ClassicThreads.git
|
||||
```
|
||||
* ### В виде иходников
|
||||
Фреймворк так же может быть добавлен в проект в виде исходников.
|
||||
* ### В виде исходников
|
||||
Пакет так же может быть добавлен в проект в виде исходников.
|
||||
|
||||
</br>
|
||||
|
||||
@ -53,21 +76,21 @@ https://github.com/DCFApixels/DragonECS-ClassicThreads.git
|
||||
EcsThreadHandler _handler;
|
||||
public void Run(EcsPipeline pipeline)
|
||||
{
|
||||
//Получение Аспекта и сцщностей для итерации.
|
||||
var group = _world.Where(out Aspect a);
|
||||
//Получение Аспекта и сущностей для итерации.
|
||||
var ee = _world.Where(out Aspect a);
|
||||
void Handler(ReadOnlySpan<int> entities)
|
||||
{
|
||||
foreach (var e in entities)
|
||||
{
|
||||
//Вычисления в отедльном потоке.
|
||||
//Вычисления в отдельном потоке.
|
||||
a.poses.Get(e).position += a.velocities.Read(e).value * _time.DeltaTime;
|
||||
}
|
||||
}
|
||||
// Запускает параллельную итерацию по сущностям,
|
||||
// сущности будут разбита на части с минимальным размером 1000.
|
||||
group.IterateParallel(_handler ??= Handler, 1000);
|
||||
ee.IterateParallel(_handler ??= Handler, 1000);
|
||||
}
|
||||
```
|
||||
> **NOTICE:** Чем меньше минимальный размер части группы при делении, тем больше потоков может быть задействовано, в некоторых ситуациях слишком много потоков может негативно повлиять на производительность.
|
||||
> Чем меньше минимальный размер части группы при делении, тем больше потоков может быть задействовано, в некоторых ситуациях слишком много потоков может негативно повлиять на производительность.
|
||||
|
||||
> **NOTICE:** Внутри обработчика запрещено создавать/удалять сущности, запрещено добавлять/удалять компоненты на сущности. Допускается только модификация данных внутри компонентов.
|
||||
> Внутри обработчика запрещено создавать/удалять сущности, запрещено добавлять/удалять компоненты на сущности. Допускается только модификация данных внутри компонентов.
|
||||
|
51
README.md
51
README.md
@ -5,17 +5,42 @@
|
||||
<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">
|
||||
<!--<img alt="Discord" src="https://img.shields.io/discord/1111696966208999525?color=%23ff4e85&label=Discord&logo=Discord&logoColor=%23ff4e85&style=for-the-badge">-->
|
||||
<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>
|
||||
</p>
|
||||
|
||||
# Classic C# Threads for [DragonECS](https://github.com/DCFApixels/DragonECS)
|
||||
|
||||
| Languages: | [Русский](https://github.com/DCFApixels/DragonECS-ClassicThreads/blob/main/README-RU.md) | [English(WIP)](https://github.com/DCFApixels/DragonECS-ClassicThreads) |
|
||||
| :--- | :--- | :--- |
|
||||
<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>
|
||||
|
||||
Support for processing entities in multiple threads, based on classic C# threads implementation.
|
||||
> **NOTICE:** The project is a work in progress, API may change.
|
||||
> While the English version of the README is incomplete, you can view the [Russian version](https://github.com/DCFApixels/DragonECS-ClassicThreads/blob/main/README-RU.md).
|
||||
</br>
|
||||
|
||||
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).
|
||||
|
||||
> [!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).
|
||||
|
||||
</br>
|
||||
|
||||
@ -35,12 +60,12 @@ Tested with:
|
||||
|
||||
## Unity Installation
|
||||
* ### Unity Package
|
||||
The framework 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`:
|
||||
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`:
|
||||
```
|
||||
https://github.com/DCFApixels/DragonECS-ClassicThreads.git
|
||||
```
|
||||
* ### Source Code
|
||||
The framework can also be added to the project as source code.
|
||||
The package can also be added to the project as source code.
|
||||
|
||||
</br>
|
||||
|
||||
@ -49,17 +74,23 @@ The framework can also be added to the project as source code.
|
||||
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);
|
||||
}
|
||||
```
|
||||
> **NOTICE:** 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.
|
||||
> 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.
|
||||
|
||||
> **NOTICE:** Inside the handler, creating/deleting entities, adding/removing components on entities is prohibited. Only modification of data within components is allowed.
|
||||
> Inside the handler, creating/deleting entities, adding/removing components on entities is prohibited. Only modification of data within components is allowed.
|
||||
|
@ -8,7 +8,7 @@
|
||||
"displayName": "DragonECS-ClassicThreads",
|
||||
"description": "Classic C# Multithreading for DragonECS",
|
||||
"unity": "2020.3",
|
||||
"version": "0.2.5",
|
||||
"version": "0.2.6",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/DCFApixels/DragonECS-ClassicThreads.git"
|
||||
|
@ -1,4 +1,8 @@
|
||||
namespace DCFApixels.DragonECS
|
||||
#if DISABLE_DEBUG
|
||||
#undef DEBUG
|
||||
#endif
|
||||
|
||||
namespace DCFApixels.DragonECS
|
||||
{
|
||||
public static class EcsCollectionsExtensions
|
||||
{
|
||||
|
@ -1,4 +1,7 @@
|
||||
using System;
|
||||
#if DISABLE_DEBUG
|
||||
#undef DEBUG
|
||||
#endif
|
||||
using System;
|
||||
|
||||
namespace DCFApixels.DragonECS
|
||||
{
|
||||
|
@ -1,3 +1,6 @@
|
||||
#if DISABLE_DEBUG
|
||||
#undef DEBUG
|
||||
#endif
|
||||
using DCFApixels.DragonECS.ClassicThreadsInternal;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
@ -8,7 +11,7 @@ namespace DCFApixels.DragonECS
|
||||
{
|
||||
#if ENABLE_IL2CPP
|
||||
using Unity.IL2CPP.CompilerServices;
|
||||
[Il2CppSetOption (Option.NullChecks, false)]
|
||||
[Il2CppSetOption(Option.NullChecks, false)]
|
||||
[Il2CppSetOption(Option.ArrayBoundsChecks, false)]
|
||||
#endif
|
||||
internal static class ThreadRunner
|
||||
@ -69,7 +72,7 @@ namespace DCFApixels.DragonECS
|
||||
{
|
||||
if (_isRunning)
|
||||
{
|
||||
#if (DEBUG && !DISABLE_DEBUG) || ENABLE_DRAGONECS_ASSERT_CHEKS
|
||||
#if DEBUG || DRAGONECS_STABILITY_MODE
|
||||
if (_threads.Any(o => o.thread == Thread.CurrentThread))
|
||||
{
|
||||
Throw.DoubleParallelIteration();
|
||||
@ -168,10 +171,10 @@ namespace DCFApixels.DragonECS
|
||||
|
||||
#if ENABLE_IL2CPP
|
||||
// Unity IL2CPP performance optimization attribute.
|
||||
namespace Unity.IL2CPP.CompilerServices
|
||||
namespace Unity.IL2CPP.CompilerServices
|
||||
{
|
||||
using System;
|
||||
internal enum Option
|
||||
internal enum Option
|
||||
{
|
||||
NullChecks = 1,
|
||||
ArrayBoundsChecks = 2,
|
||||
|
Loading…
Reference in New Issue
Block a user