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