Compare commits

...

18 Commits
0.9.22 ... main

Author SHA1 Message Date
Mikhail
4f28618277 up version 1.0.1 2026-04-21 22:18:02 +08:00
Mikhail
2cca65e37e fix 2026-04-21 21:51:05 +08:00
Mikhail
b45e9ea608 Update package.json 2026-04-21 15:15:30 +08:00
Mikhail
c3ff8b0b58 update readme 2026-04-21 14:21:15 +08:00
Mikhail
a37939a620 update readme 2026-04-21 13:59:12 +08:00
Mikhail
2b50fbdb55 Update README-RU.md 2026-04-19 18:36:33 +08:00
Mikhail
acf8c7f89a up version 0.9.23 2026-04-17 17:26:39 +08:00
Mikhail
0ecf5e378f Update readme 2026-04-17 17:17:05 +08:00
Mikhail
91d196e1a9 update 2026-04-16 15:14:15 +08:00
Mikhail
0f8d619468 Update TypeMeta.cs 2026-04-15 15:38:44 +08:00
Mikhail
211f5a657c Update TypeMeta.cs 2026-04-15 15:38:01 +08:00
Mikhail
d3e77026ff fixes 2026-04-15 15:33:28 +08:00
Mikhail
87c98f708e update meta 2026-04-15 14:37:16 +08:00
Mikhail
d52c3031f2 update MetaProxy 2026-04-15 11:13:15 +08:00
Mikhail
9deb8aa3a9 rename MetaPRoxy yto MetaProxyBase 2026-04-14 15:19:26 +08:00
Mikhail
23cee3e4c7 rework namespaces/remove IEcsTypeMetaProvider 2026-04-14 12:52:18 +08:00
Mikhail
371472e851 add MetaProxyAttribute 2026-04-13 23:21:07 +08:00
Mikhail
68d3d2bc4f fix 2026-04-13 23:20:36 +08:00
43 changed files with 460 additions and 400 deletions

View File

@ -10,7 +10,7 @@
<RootNamespace>DCFApixels.DragonECS</RootNamespace> <RootNamespace>DCFApixels.DragonECS</RootNamespace>
<Title>DragonECS</Title> <Title>DragonECS</Title>
<Version>0.9.22</Version> <Version>1.0.1</Version>
<Authors>DCFApixels</Authors> <Authors>DCFApixels</Authors>
<Description>ECS Framework for Game Engines with C# and .Net Platform</Description> <Description>ECS Framework for Game Engines with C# and .Net Platform</Description>
<Copyright>DCFApixels</Copyright> <Copyright>DCFApixels</Copyright>

View File

@ -41,10 +41,8 @@
DragonECS - это [ECS](https://en.wikipedia.org/wiki/Entity_component_system) фреймворк, нацеленный на максимальную удобность, модульность, расширяемость и производительность динамического изменения сущностей. Разработан на чистом C#, без зависимостей и генерации кода. Вдохновлен [LeoEcs Lite](https://github.com/Leopotam/ecslite). DragonECS - это [ECS](https://en.wikipedia.org/wiki/Entity_component_system) фреймворк, нацеленный на максимальную удобность, модульность, расширяемость и производительность динамического изменения сущностей. Разработан на чистом C#, без зависимостей и генерации кода. Вдохновлен [LeoEcs Lite](https://github.com/Leopotam/ecslite).
> [!WARNING] > [!Note]
> Проект предрелизной версии, поэтому API может меняться. В ветке main актуальная и рабочая версия. > Есть вопросы или хотите быть в курсе разработки? Присоединяйтесь к нашему комьюнити! -> [Обратная связь](#обратная-связь)
>
> Если есть неясные моменты, вопросы можно задать тут [Обратная связь](#обратная-связь)
## Оглавление ## Оглавление
- [Установка](#установка) - [Установка](#установка)
@ -75,7 +73,7 @@ DragonECS - это [ECS](https://en.wikipedia.org/wiki/Entity_component_system)
- [Расширение фреймворка](#расширение-фреймворка) - [Расширение фреймворка](#расширение-фреймворка)
- [Компоненты мира](#компоненты-мира) - [Компоненты мира](#компоненты-мира)
- [Конфиги](#конфиги) - [Конфиги](#конфиги)
- [Проекты на DragonECS](#Проекты-на-DragonECS) - [Проекты на DragonECS](#проекты-на-dragonecs)
- [FAQ](#faq) - [FAQ](#faq)
- [Обратная связь](#обратная-связь) - [Обратная связь](#обратная-связь)
- [Лицензия](#лицензия) - [Лицензия](#лицензия)
@ -350,10 +348,13 @@ EcsPipeline pipeline = EcsPipeline.New()
Слой определяет место в пайплайне для вставки систем. Например, если необходимо чтобы система была вставлена в конце пайплайна, эту систему можно добавить в слой `EcsConsts.END_LAYER`. Слой определяет место в пайплайне для вставки систем. Например, если необходимо чтобы система была вставлена в конце пайплайна, эту систему можно добавить в слой `EcsConsts.END_LAYER`.
```c# ```c#
const string SOME_LAYER = nameof(SOME_LAYER); const string SOME_LAYER = nameof(SOME_LAYER);
const string SOME_LAYER_2 = nameof(SOME_LAYER_2);
EcsPipeline pipeline = EcsPipeline.New() EcsPipeline pipeline = EcsPipeline.New()
// ... // ...
// Вставляет новый слой перед конечным слоем EcsConsts.END_LAYER // Вставляет новый слой перед конечным слоем EcsConsts.END_LAYER
.Layers.Insert(EcsConsts.END_LAYER, SOME_LAYER) .Layers.Add(SOME_LAYER).Before(EcsConsts.END_LAYER)
// Вставляет SOME_LAYER_2 слой в позицию после EcsConsts.BASIC_LAYER
.Layers.Add(SOME_LAYER).After(EcsConsts.BASIC_LAYER)
// Система SomeSystem будет вставлена в слой SOME_LAYER // Система SomeSystem будет вставлена в слой SOME_LAYER
.Add(New SomeSystem(), SOME_LAYER) .Add(New SomeSystem(), SOME_LAYER)
// ... // ...
@ -912,6 +913,40 @@ var tags = typeMeta.Tags; // [MetaTags]
``` ```
> Для автоматической генерации уникальных идентификаторов MetaID есть метод `MetaID.GenerateNewUniqueID()` и [Браузерный генератор](https://dcfapixels.github.io/DragonECS-MetaID_Generator_Online/) > Для автоматической генерации уникальных идентификаторов MetaID есть метод `MetaID.GenerateNewUniqueID()` и [Браузерный генератор](https://dcfapixels.github.io/DragonECS-MetaID_Generator_Online/)
<details>
<summary>[MetaProxy]</summary>
`[MetaProxy(typeof(MetaProxyType))]` атрибут для гибкой настройки метаданных. Он позволяет обходить ограничения обычных атрибутов (например, невозможность передавать в них неконстантные данные) и задавать метаданные программно. Кроме того, метаданные, полученные через `MetaProxy`, наследуются.
API напоминает `[DebuggerTypeProxy]`, но вместо экземпляра объекта принимает тип `Type`. А класс для `MetaProxy` должен наследовать `MetaProxyBase`.
Пример использования:
``` c#
// Применение атрибута
[MetaProxy(typeof(UnityComponent<>.MetaProxy))]
// В данном примере UnityComponent оборачивает компонент Unity
public struct UnityComponent<T> where T : Component
{
// ...
// Реализация MetaProxyBase. MetaProxy копирует метаданные оборачиваемого типа,
// чтобы в инспекторе Unity отображалась его мета.
private class MetaProxy : MetaProxyBase
{
protected TypeMeta Meta = typeof(T).GetMeta();
public override string Name { get { return Meta?.Name; } }
public override MetaColor? Color { get { return Meta != null && Meta.IsCustomColor ? Meta.Color : null; } }
public override MetaGroup Group { get { return Meta?.Group; } }
public override MetaDescription Description { get { return Meta?.Description; } }
public override IEnumerable<string> Tags { get { return Meta?.Tags; } }
public MetaProxy(Type type) : base(type) { }
}
}
```
</details>
## EcsDebug ## EcsDebug
Вспомогательный тип с набором методов для отладки и логирования. Реализован как статический класс вызывающий методы Debug-сервисов. Debug-сервисы - это посредники между EcsDebug и инструментами отладки среды. Такая реализация позволяет не изменяя отладочный код, менять его поведение или переносить проект в другие среды, достаточно только реализовать соответствующий Debug-сервис. Вспомогательный тип с набором методов для отладки и логирования. Реализован как статический класс вызывающий методы Debug-сервисов. Debug-сервисы - это посредники между EcsDebug и инструментами отладки среды. Такая реализация позволяет не изменяя отладочный код, менять его поведение или переносить проект в другие среды, достаточно только реализовать соответствующий Debug-сервис.
@ -975,7 +1010,7 @@ using (_marker.Auto())
var configs = new ConfigContainer() var configs = new ConfigContainer()
.Set(new EcsWorldConfig(entitiesCapacity: 2000, poolsCapacity: 2000) .Set(new EcsWorldConfig(entitiesCapacity: 2000, poolsCapacity: 2000)
.Set(new SomeDataA(/* ... */)) .Set(new SomeDataA(/* ... */))
.Set(new SomeDataB(/* ... */))); .Set(new SomeDataB(/* ... */));
EcsDefaultWorld _world = new EcsDefaultWorld(configs); EcsDefaultWorld _world = new EcsDefaultWorld(configs);
// ... // ...
var _someDataA = _world.Configs.Get<SomeDataA>(); var _someDataA = _world.Configs.Get<SomeDataA>();

View File

@ -43,12 +43,8 @@
DragonECS 是一个[实体组件系统](https://www.imooc.com/article/331544)框架。专注于提升便利性、模块性、可扩展性和动态实体修改性能。 用纯C#开发的,没有依赖和代码生成。灵感来自于[LeoEcs Lite](https://github.com/Leopotam/ecslite)。 DragonECS 是一个[实体组件系统](https://www.imooc.com/article/331544)框架。专注于提升便利性、模块性、可扩展性和动态实体修改性能。 用纯C#开发的,没有依赖和代码生成。灵感来自于[LeoEcs Lite](https://github.com/Leopotam/ecslite)。
> [!WARNING] > [!Note]
> 该框架是预发布版本,因此 API 可能会有变化。在 `main` 分支中是当前的工作版本。 > 有疑问或想了解开发进度?欢迎加入我们的社区! -> [Feedback](#Feedback)
>
> 最新版本的 README 是[俄文版](https://github.com/DCFApixels/DragonECS/blob/main/README-RU.md)。
>
> 如果有不清楚的地方,可以在这里提问 [反馈](#反馈)。
## 目录 ## 目录
- [安装](#安装) - [安装](#安装)
@ -72,7 +68,7 @@ DragonECS 是一个[实体组件系统](https://www.imooc.com/article/331544)框
- [集合](#集合) - [集合](#集合)
- [ECS入口](#ECS入口) - [ECS入口](#ECS入口)
- [Debug](#debug) - [Debug](#debug)
- [元属性](#元属性) - [Meta Attributes](#meta-attributes)
- [EcsDebug](#ecsdebug) - [EcsDebug](#ecsdebug)
- [性能分析](#性能分析) - [性能分析](#性能分析)
- [Define Symbols](#define-symbols) - [Define Symbols](#define-symbols)
@ -312,7 +308,9 @@ const string SOME_LAYER = nameof(SOME_LAYER);
EcsPipeline pipeline = EcsPipeline.New() EcsPipeline pipeline = EcsPipeline.New()
// ... // ...
// 在最终的 EcsConsts.END_LAYER 层前面插入一个新 SOME_LAYER 层。 // 在最终的 EcsConsts.END_LAYER 层前面插入一个新 SOME_LAYER 层。
.Layers.Insert(EcsConsts.END_LAYER, SOME_LAYER) .Layers.Add(SOME_LAYER).Before(EcsConsts.END_LAYER)
// 将 SOME_LAYER_2 层级入到 EcsConsts.BASIC_LAYER 之后的位置
.Layers.Add(SOME_LAYER).After(EcsConsts.BASIC_LAYER)
// SomeSystem 系统将插入 SAME_LAYER 层。 // SomeSystem 系统将插入 SAME_LAYER 层。
.Add(New SomeSystem(), SOME_LAYER) .Add(New SomeSystem(), SOME_LAYER)
// ... // ...
@ -798,7 +796,7 @@ public class EcsRoot
# Debug # Debug
该框架提供了额外的调试和日志记录工具,不依赖于环境此外,许多类型都有自己的 DebuggerProxy以便在 IDE 中更详细地显示信息。 该框架提供了额外的调试和日志记录工具,不依赖于环境此外,许多类型都有自己的 DebuggerProxy以便在 IDE 中更详细地显示信息。
## 元属性 ## Meta Attributes
默认情况下,元属性没有用处,在与引擎集成时用于指定在调试工具和编辑器中的显示方式。还可以用于生成自动文档。 默认情况下,元属性没有用处,在与引擎集成时用于指定在调试工具和编辑器中的显示方式。还可以用于生成自动文档。
``` c# ``` c#
using DCFApixels.DragonECS; using DCFApixels.DragonECS;
@ -837,6 +835,40 @@ var tags = typeMeta.Tags; // [MetaTags]
``` ```
> 为了自动生成唯一的标识符 MetaID可以使用 `MetaID.GenerateNewUniqueID()` 方法和 [浏览器生成器](https://dcfapixels.github.io/DragonECS-MetaID_Generator_Online/)。 > 为了自动生成唯一的标识符 MetaID可以使用 `MetaID.GenerateNewUniqueID()` 方法和 [浏览器生成器](https://dcfapixels.github.io/DragonECS-MetaID_Generator_Online/)。
<details>
<summary>MetaProxy</summary>
`[MetaProxy(typeof(MetaProxyType))]` 特性用于灵活配置元数据。它允许绕过常规特性的限制(例如无法向其传递非常量数据),并以编程方式设置元数据。此外,通过 `MetaProxy` 获得的元数据是可继承的。
该 API 类似于 `[DebuggerTypeProxy]`,但不同之处在于它接受的是 `Type` 类型,而不是对象实例。`MetaProxy` 的类必须继承自 `MetaProxyBase`
使用示例:
``` c#
// 应用特性
[MetaProxy(typeof(UnityComponent<>.MetaProxy))]
// 在此示例中UnityComponent 包装了一个 Unity 组件
public struct UnityComponent<T> where T : Component
{
// ...
// MetaProxyBase 的实现。MetaProxy 复制被包装类型的元数据,
// 以便在 Unity 检查器中显示其元数据。
private class MetaProxy : MetaProxyBase
{
protected TypeMeta Meta = typeof(T).GetMeta();
public override string Name { get { return Meta?.Name; } }
public override MetaColor? Color { get { return Meta != null && Meta.IsCustomColor ? Meta.Color : null; } }
public override MetaGroup Group { get { return Meta?.Group; } }
public override MetaDescription Description { get { return Meta?.Description; } }
public override IEnumerable<string> Tags { get { return Meta?.Tags; } }
public MetaProxy(Type type) : base(type) { }
}
}
```
</details>
## EcsDebug ## EcsDebug
具有调试和日志记录方法集. 实现为一个静态类,调用 DebugService 的方法. DebugService 是环境调试系统与 EcsDebug 之间的中介. 这使得可以将项目移植到其他引擎上,而无需修改项目的调试代码,只需要实现特定的 DebugService 即可。 具有调试和日志记录方法集. 实现为一个静态类,调用 DebugService 的方法. DebugService 是环境调试系统与 EcsDebug 之间的中介. 这使得可以将项目移植到其他引擎上,而无需修改项目的调试代码,只需要实现特定的 DebugService 即可。

View File

@ -43,12 +43,8 @@
The [ECS](https://en.wikipedia.org/wiki/Entity_component_system) Framework aims to maximize usability, modularity, extensibility and performance for dynamic entity changes, without code generation or external dependencies. Inspired by [LeoEcs Lite](https://github.com/Leopotam/ecslite). The [ECS](https://en.wikipedia.org/wiki/Entity_component_system) Framework aims to maximize usability, modularity, extensibility and performance for dynamic entity changes, without code generation or external dependencies. Inspired by [LeoEcs Lite](https://github.com/Leopotam/ecslite).
> [!WARNING] > [!Note]
> The project is a work in progress; the API may change. > Have questions or want to stay updated on development? Join our community! -> [Feedback](#Feedback)
>
> The most current version of the README is in [Russian version](https://github.com/DCFApixels/DragonECS/blob/main/README-RU.md).
>
> If there are unclear points, you can ask questions here [Feedback](#Feedback)
## Table of Contents ## Table of Contents
- [Installation](#installation) - [Installation](#installation)
@ -309,7 +305,9 @@ const string SOME_LAYER = nameof(SOME_LAYER);
EcsPipeline pipeline = EcsPipeline.New() EcsPipeline pipeline = EcsPipeline.New()
// ... // ...
// Inserts a new layer before the end layer EcsConsts.END_LAYER // Inserts a new layer before the end layer EcsConsts.END_LAYER
.Layers.Insert(EcsConsts.END_LAYER, SOME_LAYER) .Layers.Add(SOME_LAYER).Before(EcsConsts.END_LAYER)
// Inserts SOME_LAYER_2 layer at the position after EcsConsts.BASIC_LAYER
.Layers.Add(SOME_LAYER).After(EcsConsts.BASIC_LAYER)
// System SomeSystem will be added to the SOME_LAYER layer // System SomeSystem will be added to the SOME_LAYER layer
.Add(new SomeSystem(), SOME_LAYER) .Add(new SomeSystem(), SOME_LAYER)
// ... // ...
@ -871,6 +869,41 @@ var tags = typeMeta.Tags; // [MetaTags]
``` ```
> To simplify generate unique MetaID values, use `MetaID.GenerateNewUniqueID()` or the [Browser Generator](https://dcfapixels.github.io/DragonECS-MetaID_Generator_Online/). > To simplify generate unique MetaID values, use `MetaID.GenerateNewUniqueID()` or the [Browser Generator](https://dcfapixels.github.io/DragonECS-MetaID_Generator_Online/).
<details>
<summary>[MetaProxy]</summary>
The `[MetaProxy(typeof(MetaProxyType))]` attribute enables flexible metadata configuration. It allows bypassing the limitations of regular attributes (for example, the inability to pass non-constant data into them) and setting metadata programmatically. Furthermore, metadata obtained via `MetaProxy` is inherited.
The API resembles `[DebuggerTypeProxy]`, but instead of an object instance, it accepts a Type. The class for `MetaProxy` must inherit from `MetaProxyBase`.
Usage example:
``` c#
// Applying the attribute
[MetaProxy(typeof(UnityComponent<>.MetaProxy))]
// In this example, UnityComponent wraps a Unity component
public struct UnityComponent<T> where T : Component
{
// ...
// Implementation of MetaProxyBase. MetaProxy copies the metadata of the wrapped type
// so that its metadata is displayed in the Unity inspector.
private class MetaProxy : MetaProxyBase
{
protected TypeMeta Meta = typeof(T).GetMeta();
public override string Name { get { return Meta?.Name; } }
public override MetaColor? Color { get { return Meta != null && Meta.IsCustomColor ? Meta.Color : null; } }
public override MetaGroup Group { get { return Meta?.Group; } }
public override MetaDescription Description { get { return Meta?.Description; } }
public override IEnumerable<string> Tags { get { return Meta?.Tags; } }
public MetaProxy(Type type) : base(type) { }
}
}
```
</details>
## EcsDebug ## EcsDebug
Provides methods for debugging and logging. Implemented as a static class that forwards calls to a Debug service. Debug services act as intermediaries between environment-specific debugging systems and EcsDebug, enabling portability. Provides methods for debugging and logging. Implemented as a static class that forwards calls to a Debug service. Debug services act as intermediaries between environment-specific debugging systems and EcsDebug, enabling portability.

View File

@ -7,8 +7,8 @@
}, },
"displayName": "DragonECS", "displayName": "DragonECS",
"description": "C# Entity Component System Framework", "description": "C# Entity Component System Framework",
"unity": "2020.3", "unity": "2021.2",
"version": "0.9.22", "version": "1.0.1",
"repository": { "repository": {
"type": "git", "type": "git",
"url": "https://github.com/DCFApixels/DragonECS.git" "url": "https://github.com/DCFApixels/DragonECS.git"

View File

@ -1,7 +1,7 @@
#if DISABLE_DEBUG #if DISABLE_DEBUG
#undef DEBUG #undef DEBUG
#endif #endif
using DCFApixels.DragonECS.PoolsCore; using DCFApixels.DragonECS.Core;
namespace DCFApixels.DragonECS namespace DCFApixels.DragonECS
{ {

View File

@ -1,7 +1,6 @@
#if DISABLE_DEBUG #if DISABLE_DEBUG
#undef DEBUG #undef DEBUG
#endif #endif
using DCFApixels.DragonECS.RunnersCore;
using System; using System;
namespace DCFApixels.DragonECS namespace DCFApixels.DragonECS
@ -60,7 +59,6 @@ namespace DCFApixels.DragonECS.Core.Internal
#endif #endif
[MetaColor(MetaColor.DragonRose)] [MetaColor(MetaColor.DragonRose)]
[MetaGroup(EcsConsts.PACK_GROUP, EcsConsts.PROCESSES_GROUP)] [MetaGroup(EcsConsts.PACK_GROUP, EcsConsts.PROCESSES_GROUP)]
[MetaDescription(EcsConsts.AUTHOR, "...")]
[MetaTags(MetaTags.HIDDEN)] [MetaTags(MetaTags.HIDDEN)]
[MetaID("DragonECS_3273527C9201285BAA0A463F700A50FB")] [MetaID("DragonECS_3273527C9201285BAA0A463F700A50FB")]
internal sealed class EcsPreInitRunner : EcsRunner<IEcsPreInit>, IEcsPreInit internal sealed class EcsPreInitRunner : EcsRunner<IEcsPreInit>, IEcsPreInit
@ -81,7 +79,6 @@ namespace DCFApixels.DragonECS.Core.Internal
#endif #endif
[MetaColor(MetaColor.DragonRose)] [MetaColor(MetaColor.DragonRose)]
[MetaGroup(EcsConsts.PACK_GROUP, EcsConsts.PROCESSES_GROUP)] [MetaGroup(EcsConsts.PACK_GROUP, EcsConsts.PROCESSES_GROUP)]
[MetaDescription(EcsConsts.AUTHOR, "...")]
[MetaTags(MetaTags.HIDDEN)] [MetaTags(MetaTags.HIDDEN)]
[MetaID("DragonECS_ED85527C9201A391AB8EC0B734917859")] [MetaID("DragonECS_ED85527C9201A391AB8EC0B734917859")]
internal sealed class EcsInitRunner : EcsRunner<IEcsInit>, IEcsInit internal sealed class EcsInitRunner : EcsRunner<IEcsInit>, IEcsInit
@ -102,7 +99,6 @@ namespace DCFApixels.DragonECS.Core.Internal
#endif #endif
[MetaColor(MetaColor.DragonRose)] [MetaColor(MetaColor.DragonRose)]
[MetaGroup(EcsConsts.PACK_GROUP, EcsConsts.PROCESSES_GROUP)] [MetaGroup(EcsConsts.PACK_GROUP, EcsConsts.PROCESSES_GROUP)]
[MetaDescription(EcsConsts.AUTHOR, "...")]
[MetaTags(MetaTags.HIDDEN)] [MetaTags(MetaTags.HIDDEN)]
[MetaID("DragonECS_2098527C9201F260C840BFD50BC7E0BA")] [MetaID("DragonECS_2098527C9201F260C840BFD50BC7E0BA")]
internal sealed class EcsRunRunner : EcsRunner<IEcsRun>, IEcsRun internal sealed class EcsRunRunner : EcsRunner<IEcsRun>, IEcsRun
@ -183,7 +179,6 @@ namespace DCFApixels.DragonECS.Core.Internal
#endif #endif
[MetaColor(MetaColor.DragonRose)] [MetaColor(MetaColor.DragonRose)]
[MetaGroup(EcsConsts.PACK_GROUP, EcsConsts.PROCESSES_GROUP)] [MetaGroup(EcsConsts.PACK_GROUP, EcsConsts.PROCESSES_GROUP)]
[MetaDescription(EcsConsts.AUTHOR, "...")]
[MetaTags(MetaTags.HIDDEN)] [MetaTags(MetaTags.HIDDEN)]
[MetaID("DragonECS_06A6527C92010430ACEB3DA520F272CC")] [MetaID("DragonECS_06A6527C92010430ACEB3DA520F272CC")]
internal sealed class EcsDestroyRunner : EcsRunner<IEcsDestroy>, IEcsDestroy internal sealed class EcsDestroyRunner : EcsRunner<IEcsDestroy>, IEcsDestroy

View File

@ -1,6 +1,4 @@
using System; namespace DCFApixels.DragonECS
namespace DCFApixels.DragonECS
{ {
public static class EcsConsts public static class EcsConsts
{ {

View File

@ -285,7 +285,7 @@ namespace DCFApixels.DragonECS
public static TypeMeta GetTypeMeta(object obj) public static TypeMeta GetTypeMeta(object obj)
{ {
if (obj == null) { return TypeMeta.NullTypeMeta; } if (obj == null) { return TypeMeta.NullTypeMeta; }
return TypeMeta.Get(Type.GetTypeHandle(GetTypeMetaSource(obj))); return TypeMeta.Get(Type.GetTypeHandle(obj));
} }
public static TypeMeta GetTypeMeta<T>() public static TypeMeta GetTypeMeta<T>()
{ {
@ -300,17 +300,6 @@ namespace DCFApixels.DragonECS
return TypeMeta.Get(typeHandle); return TypeMeta.Get(typeHandle);
} }
#endregion #endregion
#region TypeMetaProvider
public static bool IsTypeMetaProvided(object obj)
{
return obj is IEcsTypeMetaProvider;
}
public static object GetTypeMetaSource(object obj)
{
return obj is IEcsTypeMetaProvider intr ? intr.MetaSource : obj;
}
#endregion
} }
public static class TypeMetaDataCachedExtensions public static class TypeMetaDataCachedExtensions

View File

@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: 50bc53c3762bf6b4ea127004a89a894e
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,7 +0,0 @@
namespace DCFApixels.DragonECS
{
public interface IEcsTypeMetaProvider
{
object MetaSource { get; }
}
}

View File

@ -5,7 +5,7 @@ using System;
namespace DCFApixels.DragonECS.Core namespace DCFApixels.DragonECS.Core
{ {
public abstract class EcsMetaAttribute : Attribute { } public abstract class DragonMetaAttribute : Attribute { }
internal static class EcsMetaAttributeHalper internal static class EcsMetaAttributeHalper
{ {

View File

@ -1,5 +1,5 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: eb8cc656a6e80f843b8794af9f63faa8 guid: fd6afd87df377e5408428ccec3c02685
MonoImporter: MonoImporter:
externalObjects: {} externalObjects: {}
serializedVersion: 2 serializedVersion: 2

View File

@ -23,7 +23,7 @@ namespace DCFApixels.DragonECS
#endregion #endregion
} }
[AttributeUsage(AttributeTargets.Struct | AttributeTargets.Class | AttributeTargets.Interface, Inherited = false, AllowMultiple = false)] [AttributeUsage(AttributeTargets.Struct | AttributeTargets.Class | AttributeTargets.Interface, Inherited = false, AllowMultiple = false)]
public sealed class MetaColorAttribute : EcsMetaAttribute, IMetaColor public sealed class MetaColorAttribute : DragonMetaAttribute, IMetaColor
{ {
public readonly MetaColor color; public readonly MetaColor color;

View File

@ -7,7 +7,7 @@ using System;
namespace DCFApixels.DragonECS namespace DCFApixels.DragonECS
{ {
[AttributeUsage(AttributeTargets.Struct | AttributeTargets.Class | AttributeTargets.Interface, Inherited = false, AllowMultiple = false)] [AttributeUsage(AttributeTargets.Struct | AttributeTargets.Class | AttributeTargets.Interface, Inherited = false, AllowMultiple = false)]
public sealed class MetaDescriptionAttribute : EcsMetaAttribute public sealed class MetaDescriptionAttribute : DragonMetaAttribute
{ {
public readonly MetaDescription Data; public readonly MetaDescription Data;
public MetaDescriptionAttribute(string text) public MetaDescriptionAttribute(string text)

View File

@ -10,7 +10,7 @@ using System.Text.RegularExpressions;
namespace DCFApixels.DragonECS namespace DCFApixels.DragonECS
{ {
[AttributeUsage(AttributeTargets.Struct | AttributeTargets.Class | AttributeTargets.Interface, Inherited = false, AllowMultiple = false)] [AttributeUsage(AttributeTargets.Struct | AttributeTargets.Class | AttributeTargets.Interface, Inherited = false, AllowMultiple = false)]
public sealed class MetaGroupAttribute : EcsMetaAttribute public sealed class MetaGroupAttribute : DragonMetaAttribute
{ {
public const char SEPARATOR = MetaGroup.SEPARATOR; public const char SEPARATOR = MetaGroup.SEPARATOR;
public readonly string Name = string.Empty; public readonly string Name = string.Empty;
@ -73,6 +73,10 @@ namespace DCFApixels.DragonECS
} }
return new MetaGroup(name); return new MetaGroup(name);
} }
public static MetaGroup FromName(params string[] path)
{
return FromName(string.Join(SEPARATOR, path));
}
public static MetaGroup FromNameSpace(Type type) public static MetaGroup FromNameSpace(Type type)
{ {
if (string.IsNullOrWhiteSpace(type.Namespace)) if (string.IsNullOrWhiteSpace(type.Namespace))

View File

@ -14,7 +14,7 @@ using System.Text.RegularExpressions;
namespace DCFApixels.DragonECS namespace DCFApixels.DragonECS
{ {
[AttributeUsage(AttributeTargets.Struct | AttributeTargets.Class | AttributeTargets.Interface, Inherited = false, AllowMultiple = false)] [AttributeUsage(AttributeTargets.Struct | AttributeTargets.Class | AttributeTargets.Interface, Inherited = false, AllowMultiple = false)]
public sealed class MetaIDAttribute : EcsMetaAttribute public sealed class MetaIDAttribute : DragonMetaAttribute
{ {
public readonly string ID; public readonly string ID;
public MetaIDAttribute(string id) public MetaIDAttribute(string id)

View File

@ -7,7 +7,7 @@ using System;
namespace DCFApixels.DragonECS namespace DCFApixels.DragonECS
{ {
[AttributeUsage(AttributeTargets.Struct | AttributeTargets.Class | AttributeTargets.Interface, Inherited = false, AllowMultiple = false)] [AttributeUsage(AttributeTargets.Struct | AttributeTargets.Class | AttributeTargets.Interface, Inherited = false, AllowMultiple = false)]
public sealed class MetaNameAttribute : EcsMetaAttribute public sealed class MetaNameAttribute : DragonMetaAttribute
{ {
public readonly string name; public readonly string name;
public readonly bool isHideGeneric; public readonly bool isHideGeneric;

View File

@ -0,0 +1,31 @@
#if DISABLE_DEBUG
#undef DEBUG
#endif
using DCFApixels.DragonECS.Core;
using System;
using System.Collections.Generic;
namespace DCFApixels.DragonECS
{
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, AllowMultiple = false, Inherited = false)]
public sealed class MetaProxyAttribute : DragonMetaAttribute
{
public Type Type;
public bool ForDeclaringType;
public MetaProxyAttribute(Type type, bool forDeclaringType = false)
{
Type = type;
ForDeclaringType = forDeclaringType;
}
}
public class MetaProxyBase
{
public static readonly MetaProxyBase EmptyProxy = new MetaProxyBase(typeof(void));
public virtual string Name { get { return null; } }
public virtual MetaColor? Color { get { return null; } }
public virtual MetaDescription Description { get { return null; } }
public virtual MetaGroup Group { get { return null; } }
public virtual IEnumerable<string> Tags { get { return null; } }
public MetaProxyBase(Type type) { }
}
}

View File

@ -1,5 +1,5 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: 4a642dc8905124247bf83c9d13d8fb13 guid: 2ce533d3befbc0f4fb16b68a1bcce552
MonoImporter: MonoImporter:
externalObjects: {} externalObjects: {}
serializedVersion: 2 serializedVersion: 2

View File

@ -8,7 +8,7 @@ using System.Collections.Generic;
namespace DCFApixels.DragonECS namespace DCFApixels.DragonECS
{ {
[AttributeUsage(AttributeTargets.Struct | AttributeTargets.Class | AttributeTargets.Interface, Inherited = false, AllowMultiple = false)] [AttributeUsage(AttributeTargets.Struct | AttributeTargets.Class | AttributeTargets.Interface, Inherited = false, AllowMultiple = false)]
public sealed class MetaTagsAttribute : EcsMetaAttribute public sealed class MetaTagsAttribute : DragonMetaAttribute
{ {
public const char SEPARATOR = ','; public const char SEPARATOR = ',';
private readonly string[] _tags = Array.Empty<string>(); private readonly string[] _tags = Array.Empty<string>();

View File

@ -1,15 +1,17 @@
#if DISABLE_DEBUG #if DISABLE_DEBUG
#undef DEBUG #undef DEBUG
#endif #endif
#if DEBUG || !REFLECTION_DISABLED
#define REFLECTION_ENABLED
#endif
using DCFApixels.DragonECS.Core; using DCFApixels.DragonECS.Core;
using DCFApixels.DragonECS.Core.Internal; using DCFApixels.DragonECS.Core.Internal;
using DCFApixels.DragonECS.PoolsCore;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics; using System.Diagnostics;
using System.Linq; using System.Linq;
#if DEBUG || !REFLECTION_DISABLED #if REFLECTION_ENABLED
using System.Reflection; using System.Reflection;
#endif #endif
@ -51,6 +53,8 @@ namespace DCFApixels.DragonECS
private readonly int _uniqueID; private readonly int _uniqueID;
internal readonly Type _type; internal readonly Type _type;
private readonly MetaProxyBase _proxy;
private readonly bool _isSelfProxy;
private bool _isCustomName; private bool _isCustomName;
private bool _isCustomColor; private bool _isCustomColor;
@ -93,6 +97,7 @@ namespace DCFApixels.DragonECS
_initFlags = InitFlag.All, _initFlags = InitFlag.All,
}; };
_metaCache.Add(typeof(void).TypeHandle, NullTypeMeta); _metaCache.Add(typeof(void).TypeHandle, NullTypeMeta);
} }
public static TypeMeta Get(Type type) { return Get(type.TypeHandle); } public static TypeMeta Get(Type type) { return Get(type.TypeHandle); }
@ -108,12 +113,54 @@ namespace DCFApixels.DragonECS
return result; return result;
} }
} }
private static Type FindDeclaringType(Type targetPureType, Type currentType)
{
if (currentType == typeof(object)) { return null; }
var pure = currentType.GetPureType();
if (pure == targetPureType)
{
return currentType;
}
return FindDeclaringType(targetPureType, currentType.BaseType);
}
private TypeMeta(Type type) private TypeMeta(Type type)
{ {
_uniqueID = _increment++; _uniqueID = _increment++;
_type = type; _type = type;
_proxy = MetaProxyBase.EmptyProxy;
if (type.TryGetAttributeInherited<MetaProxyAttribute>(out var proxyAtr, out var declaringAtrType))
{
#if REFLECTION_ENABLED
#pragma warning disable IL3050 // Calling members annotated with 'RequiresDynamicCodeAttribute' may break functionality when AOT compiling.
#pragma warning disable IL2055 // Either the type on which the MakeGenericType is called can't be statically determined, or the type parameters to be used for generic arguments can't be statically determined.
#pragma warning disable IL2077 // Target parameter argument does not satisfy 'DynamicallyAccessedMembersAttribute' in call to target method. The source field does not have matching annotations.
Type proxyType = proxyAtr.Type;
if (proxyType.ContainsGenericParameters && proxyType.IsNested)
{
if (declaringAtrType != null && declaringAtrType.ContainsGenericParameters == false)
{
var args = declaringAtrType.GetGenericArguments();
proxyType = proxyType.MakeGenericType(args);
}
}
if (proxyType.ContainsGenericParameters == false)
{
var proxy = Activator.CreateInstance(proxyType, proxyAtr.ForDeclaringType ? declaringAtrType : type) as MetaProxyBase;
if (proxy != null)
{
_proxy = proxy;
_isSelfProxy = declaringAtrType == type;
}
}
#pragma warning restore IL2055
#pragma warning restore IL3050
#pragma warning restore IL2077
#endif
}
} }
#endregion #endregion
#region Type #region Type
public Type Type public Type Type
@ -127,7 +174,7 @@ namespace DCFApixels.DragonECS
{ {
if (_initFlags.HasFlag(InitFlag.Name) == false) if (_initFlags.HasFlag(InitFlag.Name) == false)
{ {
(_name, _isCustomName) = MetaGenerator.GetMetaName(_type); (_name, _isCustomName) = MetaGenerator.GetMetaName(this);
_typeName = _isCustomName ? MetaGenerator.GetTypeName(_type) : _name; _typeName = _isCustomName ? MetaGenerator.GetTypeName(_type) : _name;
_initFlags |= InitFlag.Name; _initFlags |= InitFlag.Name;
} }
@ -192,7 +239,7 @@ namespace DCFApixels.DragonECS
{ {
if (_initFlags.HasFlag(InitFlag.Description) == false) if (_initFlags.HasFlag(InitFlag.Description) == false)
{ {
_description = MetaGenerator.GetDescription(_type); _description = MetaGenerator.GetDescription(this);
_initFlags |= InitFlag.Description; _initFlags |= InitFlag.Description;
} }
return _description; return _description;
@ -207,7 +254,7 @@ namespace DCFApixels.DragonECS
{ {
if (_initFlags.HasFlag(InitFlag.Group) == false) if (_initFlags.HasFlag(InitFlag.Group) == false)
{ {
_group = MetaGenerator.GetGroup(_type); _group = MetaGenerator.GetGroup(this);
_initFlags |= InitFlag.Group; _initFlags |= InitFlag.Group;
} }
return _group; return _group;
@ -220,7 +267,7 @@ namespace DCFApixels.DragonECS
{ {
if (_initFlags.HasFlag(InitFlag.Tags) == false) if (_initFlags.HasFlag(InitFlag.Tags) == false)
{ {
_tags = MetaGenerator.GetTags(_type); _tags = MetaGenerator.GetTags(this);
_initFlags |= InitFlag.Tags; _initFlags |= InitFlag.Tags;
_isHidden = _tags.Contains(MetaTags.HIDDEN); _isHidden = _tags.Contains(MetaTags.HIDDEN);
_isObsolete = _tags.Contains(MetaTags.OBSOLETE); _isObsolete = _tags.Contains(MetaTags.OBSOLETE);
@ -385,7 +432,7 @@ namespace DCFApixels.DragonECS
} }
private static bool CheckEcsMemener(Type checkedType) private static bool CheckEcsMemener(Type checkedType)
{ {
#if DEBUG || !REFLECTION_DISABLED #if REFLECTION_ENABLED
return checkedType.IsInterface == false && checkedType.IsAbstract == false && typeof(IEcsMember).IsAssignableFrom(checkedType); return checkedType.IsInterface == false && checkedType.IsAbstract == false && typeof(IEcsMember).IsAssignableFrom(checkedType);
#else #else
EcsDebug.PrintWarning($"Reflection is not available, the {nameof(TypeMeta)}.{nameof(CheckEcsMemener)} method does not work."); EcsDebug.PrintWarning($"Reflection is not available, the {nameof(TypeMeta)}.{nameof(CheckEcsMemener)} method does not work.");
@ -404,16 +451,16 @@ namespace DCFApixels.DragonECS
} }
public static bool IsHasCustomMeta(Type type) public static bool IsHasCustomMeta(Type type)
{ {
#if DEBUG || !REFLECTION_DISABLED #if REFLECTION_ENABLED
return CheckEcsMemener(type) || Attribute.GetCustomAttributes(type, typeof(EcsMetaAttribute), false).Length > 0; return CheckEcsMemener(type) || Attribute.GetCustomAttributes(type, typeof(DragonMetaAttribute), false).Length > 0;
#else #else
EcsDebug.PrintWarning($"Reflection is not available, the {nameof(TypeMeta)}.{nameof(IsHasMeta)} method does not work."); EcsDebug.PrintWarning($"Reflection is not available, the {nameof(TypeMeta)}.{nameof(IsHasCustomMeta)} method does not work.");
return false; return false;
#endif #endif
} }
public static bool IsHasMetaID(Type type) public static bool IsHasMetaID(Type type)
{ {
#if DEBUG || !REFLECTION_DISABLED #if REFLECTION_ENABLED
return TryGetCustomMeta(type, out TypeMeta meta) && meta.IsHasMetaID(); return TryGetCustomMeta(type, out TypeMeta meta) && meta.IsHasMetaID();
#else #else
EcsDebug.PrintWarning($"Reflection is not available, the {nameof(TypeMeta)}.{nameof(IsHasMetaID)} method does not work."); EcsDebug.PrintWarning($"Reflection is not available, the {nameof(TypeMeta)}.{nameof(IsHasMetaID)} method does not work.");
@ -480,15 +527,20 @@ namespace DCFApixels.DragonECS
{ {
return EcsDebugUtility.GetGenericTypeName(type, GENERIC_NAME_DEPTH); return EcsDebugUtility.GetGenericTypeName(type, GENERIC_NAME_DEPTH);
} }
public static (string, bool) GetMetaName(Type type) public static (string, bool) GetMetaName(TypeMeta meta)
{ {
#if DEBUG || !REFLECTION_DISABLED //в дебажных утилитах REFLECTION_DISABLED только в релизном билде работает #if REFLECTION_ENABLED //в дебажных утилитах REFLECTION_DISABLED только в релизном билде работает
if (meta._isSelfProxy && meta._proxy.Name != null)
{
return (meta._proxy.Name, true);
}
var type = meta.Type;
bool isCustom = type.TryGetAttribute(out MetaNameAttribute atr) && string.IsNullOrEmpty(atr.name) == false; bool isCustom = type.TryGetAttribute(out MetaNameAttribute atr) && string.IsNullOrEmpty(atr.name) == false;
if (isCustom) if (isCustom)
{ {
if ((type.IsGenericType && atr.isHideGeneric == false) == false) if ((type.IsGenericType && atr.isHideGeneric == false) == false)
{ {
return (atr.name, isCustom); return (atr.name, true);
} }
string genericParams = ""; string genericParams = "";
Type[] typeParameters = type.GetGenericArguments(); Type[] typeParameters = type.GetGenericArguments();
@ -497,12 +549,16 @@ namespace DCFApixels.DragonECS
string paramTypeName = EcsDebugUtility.GetGenericTypeName(typeParameters[i], GENERIC_NAME_DEPTH); string paramTypeName = EcsDebugUtility.GetGenericTypeName(typeParameters[i], GENERIC_NAME_DEPTH);
genericParams += (i == 0 ? paramTypeName : $", {paramTypeName}"); genericParams += (i == 0 ? paramTypeName : $", {paramTypeName}");
} }
return ($"{atr.name}<{genericParams}>", isCustom); return ($"{atr.name}<{genericParams}>", true);
} }
return (EcsDebugUtility.GetGenericTypeName(type, GENERIC_NAME_DEPTH), isCustom); if (meta._proxy.Name != null)
{
return (meta._proxy.Name, true);
}
return (EcsDebugUtility.GetGenericTypeName(type, GENERIC_NAME_DEPTH), false);
#else #else
EcsDebug.PrintWarning($"Reflection is not available, the {nameof(MetaGenerator)}.{nameof(GetMetaName)} method does not work."); EcsDebug.PrintWarning($"Reflection is not available, the {nameof(MetaGenerator)}.{nameof(GetMetaName)} method does not work.");
return (type.Name, false); return (meta.Type.Name, false);
#endif #endif
} }
#endregion #endregion
@ -523,9 +579,21 @@ namespace DCFApixels.DragonECS
} }
public static (MetaColor, bool) GetColor(TypeMeta meta) public static (MetaColor, bool) GetColor(TypeMeta meta)
{ {
#if DEBUG || !REFLECTION_DISABLED //в дебажных утилитах REFLECTION_DISABLED только в релизном билде работает #if REFLECTION_ENABLED //в дебажных утилитах REFLECTION_DISABLED только в релизном билде работает
if (meta._isSelfProxy && meta._proxy.Color != null)
{
return (meta._proxy.Color.Value, true);
}
bool isCustom = meta.Type.TryGetAttribute(out MetaColorAttribute atr); bool isCustom = meta.Type.TryGetAttribute(out MetaColorAttribute atr);
return (isCustom ? atr.color : AutoColor(meta), isCustom); if (isCustom)
{
return (atr.color, true);
}
if (meta._proxy.Color != null)
{
return (meta._proxy.Color.Value, true);
}
return (AutoColor(meta), false);
#else #else
EcsDebug.PrintWarning($"Reflection is not available, the {nameof(MetaGenerator)}.{nameof(GetColor)} method does not work."); EcsDebug.PrintWarning($"Reflection is not available, the {nameof(MetaGenerator)}.{nameof(GetColor)} method does not work.");
return (MetaColor.White, false); return (MetaColor.White, false);
@ -534,17 +602,22 @@ namespace DCFApixels.DragonECS
#endregion #endregion
#region GetGroup #region GetGroup
public static MetaGroup GetGroup(Type type) public static MetaGroup GetGroup(TypeMeta meta)
{ {
#if DEBUG || !REFLECTION_DISABLED //в дебажных утилитах REFLECTION_DISABLED только в релизном билде работает #if REFLECTION_ENABLED //в дебажных утилитах REFLECTION_DISABLED только в релизном билде работает
if (type.TryGetAttribute(out MetaGroupAttribute atr)) if (meta._isSelfProxy && meta._proxy.Group != null)
{
return meta._proxy.Group;
}
if (meta.Type.TryGetAttribute(out MetaGroupAttribute atr))
{ {
return MetaGroup.FromName(atr.Name); return MetaGroup.FromName(atr.Name);
} }
else if (meta._proxy.Group != null)
{ {
return MetaGroup.FromNameSpace(type); return meta._proxy.Group;
} }
return MetaGroup.FromNameSpace(meta.Type);
#else #else
EcsDebug.PrintWarning($"Reflection is not available, the {nameof(MetaGenerator)}.{nameof(GetGroup)} method does not work."); EcsDebug.PrintWarning($"Reflection is not available, the {nameof(MetaGenerator)}.{nameof(GetGroup)} method does not work.");
return MetaGroup.Empty; return MetaGroup.Empty;
@ -553,11 +626,22 @@ namespace DCFApixels.DragonECS
#endregion #endregion
#region GetDescription #region GetDescription
public static MetaDescription GetDescription(Type type) public static MetaDescription GetDescription(TypeMeta meta)
{ {
#if DEBUG || !REFLECTION_DISABLED //в дебажных утилитах REFLECTION_DISABLED только в релизном билде работает #if REFLECTION_ENABLED //в дебажных утилитах REFLECTION_DISABLED только в релизном билде работает
bool isCustom = type.TryGetAttribute(out MetaDescriptionAttribute atr); if (meta._isSelfProxy && meta._proxy.Description != null)
return isCustom ? atr.Data : MetaDescription.Empty; {
return meta._proxy.Description;
}
if (meta.Type.TryGetAttribute(out MetaDescriptionAttribute atr))
{
return atr.Data;
}
if (meta._proxy.Description != null)
{
return meta._proxy.Description;
}
return MetaDescription.Empty;
#else #else
EcsDebug.PrintWarning($"Reflection is not available, the {nameof(MetaGenerator)}.{nameof(GetDescription)} method does not work."); EcsDebug.PrintWarning($"Reflection is not available, the {nameof(MetaGenerator)}.{nameof(GetDescription)} method does not work.");
return MetaDescription.Empty; return MetaDescription.Empty;
@ -566,11 +650,22 @@ namespace DCFApixels.DragonECS
#endregion #endregion
#region GetTags #region GetTags
public static IReadOnlyList<string> GetTags(Type type) public static IReadOnlyList<string> GetTags(TypeMeta meta)
{ {
#if DEBUG || !REFLECTION_DISABLED //в дебажных утилитах REFLECTION_DISABLED только в релизном билде работает #if REFLECTION_ENABLED //в дебажных утилитах REFLECTION_DISABLED только в релизном билде работает
var atr = type.GetCustomAttribute<MetaTagsAttribute>(); if (meta._isSelfProxy && meta._proxy.Tags != null)
return atr != null ? atr.Tags : Array.Empty<string>(); {
return meta._proxy.Tags.ToArray();
}
if (meta.Type.TryGetAttribute(out MetaTagsAttribute atr))
{
return atr.Tags;
}
if (meta._proxy.Tags != null)
{
return meta._proxy.Tags.ToArray();
}
return Array.Empty<string>();
#else #else
EcsDebug.PrintWarning($"Reflection is not available, the {nameof(MetaGenerator)}.{nameof(GetTags)} method does not work."); EcsDebug.PrintWarning($"Reflection is not available, the {nameof(MetaGenerator)}.{nameof(GetTags)} method does not work.");
return Array.Empty<string>(); return Array.Empty<string>();
@ -581,7 +676,7 @@ namespace DCFApixels.DragonECS
#region GetMetaID #region GetMetaID
public static string GetMetaID(Type type) public static string GetMetaID(Type type)
{ {
#if DEBUG || !REFLECTION_DISABLED //в дебажных утилитах REFLECTION_DISABLED только в релизном билде работает #if REFLECTION_ENABLED //в дебажных утилитах REFLECTION_DISABLED только в релизном билде работает
var atr = type.GetCustomAttribute<MetaIDAttribute>(); var atr = type.GetCustomAttribute<MetaIDAttribute>();
if (atr == null) if (atr == null)

View File

@ -3,7 +3,6 @@
#endif #endif
using DCFApixels.DragonECS.Core; using DCFApixels.DragonECS.Core;
using DCFApixels.DragonECS.Core.Internal; using DCFApixels.DragonECS.Core.Internal;
using DCFApixels.DragonECS.PoolsCore;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;

View File

@ -3,7 +3,6 @@
#endif #endif
using DCFApixels.DragonECS.Core; using DCFApixels.DragonECS.Core;
using DCFApixels.DragonECS.Core.Internal; using DCFApixels.DragonECS.Core.Internal;
using DCFApixels.DragonECS.RunnersCore;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;

View File

@ -1,8 +1,8 @@
#if DISABLE_DEBUG #if DISABLE_DEBUG
#undef DEBUG #undef DEBUG
#endif #endif
using DCFApixels.DragonECS.Core;
using DCFApixels.DragonECS.Core.Internal; using DCFApixels.DragonECS.Core.Internal;
using DCFApixels.DragonECS.RunnersCore;
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;

View File

@ -1,8 +1,8 @@
#if DISABLE_DEBUG #if DISABLE_DEBUG
#undef DEBUG #undef DEBUG
#endif #endif
using DCFApixels.DragonECS.Core;
using DCFApixels.DragonECS.Core.Internal; using DCFApixels.DragonECS.Core.Internal;
using DCFApixels.DragonECS.RunnersCore;
using System; using System;
using System.Linq; using System.Linq;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
@ -17,7 +17,7 @@ namespace DCFApixels.DragonECS
[MetaID("DragonECS_EF8A557C9201E6F04D4A76DC670BDE19")] [MetaID("DragonECS_EF8A557C9201E6F04D4A76DC670BDE19")]
public interface IEcsProcess : IEcsMember { } public interface IEcsProcess : IEcsMember { }
namespace RunnersCore namespace Core
{ {
//добавить инъекцию в раннеры //добавить инъекцию в раннеры
public abstract class EcsRunner public abstract class EcsRunner
@ -63,6 +63,23 @@ namespace DCFApixels.DragonECS
#endregion #endregion
public delegate void ActionWithData<in TProcess, T>(TProcess process, ref T Data); public delegate void ActionWithData<in TProcess, T>(TProcess process, ref T Data);
#region MetaProxy
protected class RunnerMetaProxy : MetaProxyBase
{
private TypeMeta _processMeta;
public override MetaColor? Color => MetaColor.DragonRose;
public override MetaDescription Description => new MetaDescription(EcsConsts.AUTHOR, $"Runner for {_processMeta.TypeName} process.");
public override MetaGroup Group => MetaGroup.FromName(EcsConsts.PACK_GROUP, EcsConsts.PROCESSES_GROUP);
public RunnerMetaProxy(Type type) : base(type)
{
if (type.IsGenericType)
{
_processMeta = type.GetGenericArguments()[0].GetMeta();
}
}
}
#endregion
} }
[MetaColor(MetaColor.DragonRose)] [MetaColor(MetaColor.DragonRose)]
@ -80,9 +97,9 @@ namespace DCFApixels.DragonECS
[MetaColor(MetaColor.DragonRose)] [MetaColor(MetaColor.DragonRose)]
[MetaGroup(EcsConsts.PACK_GROUP, EcsConsts.OTHER_GROUP)] [MetaGroup(EcsConsts.PACK_GROUP, EcsConsts.OTHER_GROUP)]
[MetaDescription(EcsConsts.AUTHOR, "...")]
[MetaTags(MetaTags.HIDDEN)] [MetaTags(MetaTags.HIDDEN)]
[MetaID("DragonECS_7DB3557C9201F85E0E1C17D7B19D9CEE")] [MetaID("DragonECS_7DB3557C9201F85E0E1C17D7B19D9CEE")]
[MetaProxy(typeof(RunnerMetaProxy), true)]
public abstract class EcsRunner<TProcess> : EcsRunner, IEcsRunner, IEcsProcess public abstract class EcsRunner<TProcess> : EcsRunner, IEcsRunner, IEcsProcess
where TProcess : IEcsProcess where TProcess : IEcsProcess
{ {
@ -476,8 +493,6 @@ namespace DCFApixels.DragonECS
#endregion #endregion
} }
#endregion #endregion
//----
} }
} }

View File

@ -2,7 +2,6 @@
#undef DEBUG #undef DEBUG
#endif #endif
using DCFApixels.DragonECS.Core; using DCFApixels.DragonECS.Core;
using DCFApixels.DragonECS.PoolsCore;
namespace DCFApixels.DragonECS namespace DCFApixels.DragonECS
{ {

View File

@ -4,7 +4,6 @@
using DCFApixels.DragonECS.Core; using DCFApixels.DragonECS.Core;
using DCFApixels.DragonECS.Core.Internal; using DCFApixels.DragonECS.Core.Internal;
using DCFApixels.DragonECS.Core.Unchecked; using DCFApixels.DragonECS.Core.Unchecked;
using DCFApixels.DragonECS.PoolsCore;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
@ -87,6 +86,7 @@ namespace DCFApixels.DragonECS
private StructList<IEcsWorldEventListener> _listeners = new StructList<IEcsWorldEventListener>(2); private StructList<IEcsWorldEventListener> _listeners = new StructList<IEcsWorldEventListener>(2);
private StructList<IEcsEntityEventListener> _entityListeners = new StructList<IEcsEntityEventListener>(2); private StructList<IEcsEntityEventListener> _entityListeners = new StructList<IEcsEntityEventListener>(2);
private bool _hasAnyEntityListener = false;
#region Properties #region Properties
EcsWorld IEntityStorage.World EcsWorld IEntityStorage.World
@ -395,8 +395,11 @@ namespace DCFApixels.DragonECS
{ {
slot.gen |= GEN_SLEEP_MASK; slot.gen |= GEN_SLEEP_MASK;
} }
_entityListeners.InvokeOnNewEntity(entityID); if (_hasAnyEntityListener)
MoveToEmptyEntities(entityID); {
_entityListeners.InvokeOnNewEntity(entityID);
}
MoveToEmptyEntities(entityID, false);
} }
@ -437,13 +440,24 @@ namespace DCFApixels.DragonECS
_delEntBuffer[_delEntBufferCount++] = entityID; _delEntBuffer[_delEntBufferCount++] = entityID;
_entities[entityID].isUsed = false; _entities[entityID].isUsed = false;
_entitiesCount--; _entitiesCount--;
_entityListeners.InvokeOnDelEntity(entityID); if (_hasAnyEntityListener)
{
_entityListeners.InvokeOnDelEntity(entityID);
}
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
private void MoveToEmptyEntities(int entityID) private void MoveToEmptyEntities(int entityID, bool readyToRemove)
{ {
if (readyToRemove)
{
entityID |= int.MinValue;
}
_emptyEntities[_emptyEntitiesLength++] = entityID; _emptyEntities[_emptyEntitiesLength++] = entityID;
_emptyEntitiesCount++; _emptyEntitiesCount++;
if (_emptyEntitiesLength == _emptyEntities.Length)
{
ReleaseEmptyEntitiesBuffer_OnlyReadyToRemove();
}
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
private void RemoveFromEmptyEntities(int entityID) private void RemoveFromEmptyEntities(int entityID)
@ -455,7 +469,7 @@ namespace DCFApixels.DragonECS
{ {
for (int i = _emptyEntitiesLength - 1; i >= 0; i--) for (int i = _emptyEntitiesLength - 1; i >= 0; i--)
{ {
if (_emptyEntities[i] == entityID) if ((_emptyEntities[i] & int.MaxValue) == entityID)
{ {
_emptyEntities[i] = _emptyEntities[--_emptyEntitiesLength]; _emptyEntities[i] = _emptyEntities[--_emptyEntitiesLength];
} }
@ -474,6 +488,45 @@ namespace DCFApixels.DragonECS
_emptyEntitiesLength = 0; _emptyEntitiesLength = 0;
} }
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void ReleaseEmptyEntitiesBuffer()
{
for (int i = 0; i < _emptyEntitiesLength; i++)
{
var entityID = _emptyEntities[i] & int.MaxValue;
if (IsUsed(entityID) && _entities[entityID].componentsCount == 0)
{
DelEntity(entityID);
}
}
_emptyEntitiesCount = 0;
_emptyEntitiesLength = 0;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void ReleaseEmptyEntitiesBuffer_OnlyReadyToRemove()
{
var newCount = 0;
for (int i = 0; i < _emptyEntitiesLength; i++)
{
var entityID = _emptyEntities[i];
bool isReady = entityID < 0;
entityID &= int.MaxValue;
if (IsUsed(entityID) && _entities[entityID].componentsCount == 0)
{
if (isReady)
{
DelEntity(entityID);
}
else
{
_emptyEntities[newCount++] = entityID;
}
}
}
_emptyEntitiesCount = newCount;
_emptyEntitiesLength = newCount;
}
#endregion #endregion
#region Other #region Other
@ -913,16 +966,7 @@ namespace DCFApixels.DragonECS
if (_emptyEntitiesLength <= 0 && _delEntBufferCount <= 0) { return; } if (_emptyEntitiesLength <= 0 && _delEntBufferCount <= 0) { return; }
unchecked { _version++; } unchecked { _version++; }
for (int i = 0; i < _emptyEntitiesLength; i++) ReleaseEmptyEntitiesBuffer();
{
var entityID = _emptyEntities[i];
if (IsUsed(entityID) && _entities[entityID].componentsCount == 0)
{
DelEntity(entityID);
}
}
_emptyEntitiesCount = 0;
_emptyEntitiesLength = 0;
if (count < 0) if (count < 0)
{ {
@ -1046,10 +1090,12 @@ namespace DCFApixels.DragonECS
public void AddListener(IEcsEntityEventListener entityEventListener) public void AddListener(IEcsEntityEventListener entityEventListener)
{ {
_entityListeners.Add(entityEventListener); _entityListeners.Add(entityEventListener);
_hasAnyEntityListener = _entityListeners.Count > 0;
} }
public void RemoveListener(IEcsEntityEventListener entityEventListener) public void RemoveListener(IEcsEntityEventListener entityEventListener)
{ {
_entityListeners.Remove(entityEventListener); _entityListeners.Remove(entityEventListener);
_hasAnyEntityListener = _entityListeners.Count > 0;
} }
#endregion #endregion
@ -1375,6 +1421,7 @@ namespace DCFApixels.DragonECS
public interface IEcsEntityEventListener public interface IEcsEntityEventListener
{ {
void OnNewEntity(int entityID); void OnNewEntity(int entityID);
void OnMigrateEntity(int entityID);
void OnDelEntity(int entityID); void OnDelEntity(int entityID);
} }
internal static class WorldEventListExtensions internal static class WorldEventListExtensions
@ -1412,6 +1459,14 @@ namespace DCFApixels.DragonECS
} }
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void InvokeOnMigrateEntity(this ref StructList<IEcsEntityEventListener> self, int entityID)
{
for (int i = 0, iMax = self.Count; i < iMax; i++)
{
self[i].OnMigrateEntity(entityID);
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void InvokeOnDelEntity(this ref StructList<IEcsEntityEventListener> self, int entityID) public static void InvokeOnDelEntity(this ref StructList<IEcsEntityEventListener> self, int entityID)
{ {
for (int i = 0, iMax = self.Count; i < iMax; i++) for (int i = 0, iMax = self.Count; i < iMax; i++)

View File

@ -1,8 +1,8 @@
#if DISABLE_DEBUG #if DISABLE_DEBUG
#undef DEBUG #undef DEBUG
#endif #endif
using DCFApixels.DragonECS.Core;
using DCFApixels.DragonECS.Core.Internal; using DCFApixels.DragonECS.Core.Internal;
using DCFApixels.DragonECS.PoolsCore;
using System; using System;
using System.Linq; using System.Linq;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
@ -286,6 +286,10 @@ namespace DCFApixels.DragonECS
RemoveFromEmptyEntities(entityID); RemoveFromEmptyEntities(entityID);
} }
_entityComponentMasks[(entityID << _entityComponentMaskLengthBitShift) + maskBit.chunkIndex] |= maskBit.mask; _entityComponentMasks[(entityID << _entityComponentMaskLengthBitShift) + maskBit.chunkIndex] |= maskBit.mask;
if (_hasAnyEntityListener)
{
_entityListeners.InvokeOnMigrateEntity(entityID);
}
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
private void UnregisterEntityComponent(int entityID, int componentTypeID, EcsMaskChunck maskBit) private void UnregisterEntityComponent(int entityID, int componentTypeID, EcsMaskChunck maskBit)
@ -296,12 +300,15 @@ namespace DCFApixels.DragonECS
slot.version++; slot.version++;
var count = --_entities[entityID].componentsCount; var count = --_entities[entityID].componentsCount;
_entityComponentMasks[(entityID << _entityComponentMaskLengthBitShift) + maskBit.chunkIndex] &= ~maskBit.mask; _entityComponentMasks[(entityID << _entityComponentMaskLengthBitShift) + maskBit.chunkIndex] &= ~maskBit.mask;
if (count == 0 && IsUsed(entityID)) if (count == 0 && IsUsed(entityID))
{ {
MoveToEmptyEntities(entityID); MoveToEmptyEntities(entityID, true);
} }
CheckUnregisterValid(count, entityID); CheckUnregisterValid(count, entityID);
if (_hasAnyEntityListener)
{
_entityListeners.InvokeOnMigrateEntity(entityID);
}
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
private bool TryRegisterEntityComponent(int entityID, int componentTypeID, EcsMaskChunck maskBit) private bool TryRegisterEntityComponent(int entityID, int componentTypeID, EcsMaskChunck maskBit)
@ -320,6 +327,10 @@ namespace DCFApixels.DragonECS
{ {
RemoveFromEmptyEntities(entityID); RemoveFromEmptyEntities(entityID);
} }
if (_hasAnyEntityListener)
{
_entityListeners.InvokeOnMigrateEntity(entityID);
}
return true; return true;
} }
return false; return false;
@ -340,9 +351,13 @@ namespace DCFApixels.DragonECS
if (count == 0 && IsUsed(entityID)) if (count == 0 && IsUsed(entityID))
{ {
MoveToEmptyEntities(entityID); MoveToEmptyEntities(entityID, true);
} }
CheckUnregisterValid(count, entityID); CheckUnregisterValid(count, entityID);
if (_hasAnyEntityListener)
{
_entityListeners.InvokeOnMigrateEntity(entityID);
}
return true; return true;
} }
return false; return false;

View File

@ -294,6 +294,8 @@ namespace DCFApixels.DragonECS
#endregion #endregion
#region NullWorld #region NullWorld
[MetaTags(MetaTags.HIDDEN)]
[MetaGroup(EcsConsts.PACK_GROUP, EcsConsts.OTHER_GROUP)]
private sealed class NullWorld : EcsWorld private sealed class NullWorld : EcsWorld
{ {
internal NullWorld() : base(new EcsWorldConfig(4, 4, 4, 4, 4), null, 0) { } internal NullWorld() : base(new EcsWorldConfig(4, 4, 4, 4, 4), null, 0) { }

View File

@ -160,6 +160,7 @@ namespace DCFApixels.DragonECS.Core.Internal
SortHalper.Sort(_filteredEntities.AsSpan(_filteredEntitiesCount), comparison); SortHalper.Sort(_filteredEntities.AsSpan(_filteredEntitiesCount), comparison);
return new EcsUnsafeSpan(World.ID, _filteredEntities.Ptr, _filteredEntitiesCount); return new EcsUnsafeSpan(World.ID, _filteredEntities.Ptr, _filteredEntitiesCount);
} }
public override EcsSpan Snapshot() { return Execute(); }
#endregion #endregion
} }
} }

View File

@ -117,6 +117,7 @@ namespace DCFApixels.DragonECS.Core.Internal
ExecuteFor_Iternal(span); ExecuteFor_Iternal(span);
return _filteredGroup; return _filteredGroup;
} }
public override EcsSpan Snapshot() { return Execute(); }
#endregion #endregion
} }
} }

View File

@ -105,6 +105,7 @@ namespace DCFApixels.DragonECS.Core
} }
protected abstract void OnInitialize(); protected abstract void OnInitialize();
protected abstract void OnDestroy(); protected abstract void OnDestroy();
public abstract EcsSpan Snapshot();
} }
#if ENABLE_IL2CPP #if ENABLE_IL2CPP

View File

@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: f5d8c72b3decc2b488a616932366ff0f
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -9,6 +9,33 @@ namespace DCFApixels.DragonECS.Core.Internal
{ {
internal static class ReflectionUtility internal static class ReflectionUtility
{ {
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Type GetPureType(this Type type)
{
if (type.IsGenericType)
{
return type.GetGenericTypeDefinition();
}
return type;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool TryGetAttributeInherited<T>(this Type self, out T attribute, out Type declaringAtrType) where T : Attribute
{
if (self == null || self == typeof(object))
{
attribute = null;
declaringAtrType = null;
return false;
}
attribute = self.GetCustomAttribute<T>();
if (attribute == null)
{
return self.BaseType.TryGetAttributeInherited<T>(out attribute, out declaringAtrType);
}
declaringAtrType = self;
return true;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool TryGetAttribute<T>(this MemberInfo self, out T attribute) where T : Attribute public static bool TryGetAttribute<T>(this MemberInfo self, out T attribute) where T : Attribute
{ {

View File

@ -389,253 +389,4 @@ namespace DCFApixels.DragonECS.Core.Internal
} }
} }
#endregion #endregion
} }
//namespace DCFApixels.DragonECS.Core.Internal
//{
// internal interface IStructComparer<T> : IComparer<T>
// {
// // a > b = return > 0
// // int Compare(T a, T b);
// }
//
//#if ENABLE_IL2CPP
// [Il2CppSetOption(Option.NullChecks, false)]
// [Il2CppSetOption(Option.ArrayBoundsChecks, false)]
//#endif
// internal static class ArraySortHalperX<T>
// {
// private const int IntrosortSizeThreshold = 16;
//
// #region IStructComparer
// [MethodImpl(MethodImplOptions.AggressiveInlining)]
// public static void SwapIfGreater<TComparer>(T[] items, ref TComparer comparer, int i, int j) where TComparer : IStructComparer<T>
// {
// if (comparer.Compare(items[i], items[j]) > 0)
// {
// T key = items[i];
// items[i] = items[j];
// items[j] = key;
// }
// }
// [MethodImpl(MethodImplOptions.AggressiveInlining)]
// public static void InsertionSort<TComparer>(T[] items, ref TComparer comparer) where TComparer : IStructComparer<T>
// {
// for (int i = 0; i < items.Length - 1; i++)
// {
// T t = items[i + 1];
//
// int j = i;
// while (j >= 0 && comparer.Compare(t, items[j]) < 0)
// {
// items[j + 1] = items[j];
// j--;
// }
//
// items[j + 1] = t;
// }
// }
//
// [MethodImpl(MethodImplOptions.AggressiveInlining)]
// public static void Sort<TComparer>(T[] items, ref TComparer comparer) where TComparer : IStructComparer<T>
// {
// int length = items.Length;
// if (length == 1)
// {
// return;
// }
//
// if (length <= IntrosortSizeThreshold)
// {
//
// if (length == 2)
// {
// SwapIfGreater(items, ref comparer, 0, 1);
// return;
// }
//
// if (length == 3)
// {
// SwapIfGreater(items, ref comparer, 0, 1);
// SwapIfGreater(items, ref comparer, 0, 2);
// SwapIfGreater(items, ref comparer, 1, 2);
// return;
// }
//
// InsertionSort(items, ref comparer);
// return;
// }
//
// IStructComparer<T> packed = comparer;
// Array.Sort(items, 0, items.Length, packed);
// comparer = (TComparer)packed;
// }
// #endregion
//
// #region Comparison
// [MethodImpl(MethodImplOptions.AggressiveInlining)]
// public static void SwapIfGreater(T[] items, Comparison<T> comparison, int i, int j)
// {
// if (comparison(items[i], items[j]) > 0)
// {
// T key = items[i];
// items[i] = items[j];
// items[j] = key;
// }
// }
// [MethodImpl(MethodImplOptions.AggressiveInlining)]
// public static void InsertionSort(T[] items, int length, Comparison<T> comparison)
// {
// for (int i = 0; i < length - 1; i++)
// {
// T t = items[i + 1];
//
// int j = i;
// while (j >= 0 && comparison(t, items[j]) < 0)
// {
// items[j + 1] = items[j];
// j--;
// }
//
// items[j + 1] = t;
// }
// }
//
//#if ENABLE_IL2CPP
// [Il2CppSetOption(Option.NullChecks, false)]
// [Il2CppSetOption(Option.ArrayBoundsChecks, false)]
//#endif
// private class ComparisonHach : IComparer<T>
// {
// public static readonly ComparisonHach Instance = new ComparisonHach();
// public Comparison<T> comparison;
// private ComparisonHach() { }
// public int Compare(T x, T y) { return comparison(x, y); }
// }
// [MethodImpl(MethodImplOptions.AggressiveInlining)]
// public static void Sort(T[] items, Comparison<T> comparison)
// {
// Sort(items, comparison, items.Length);
// }
// [MethodImpl(MethodImplOptions.AggressiveInlining)]
// public static void Sort(T[] items, Comparison<T> comparison, int length)
// {
// if (length <= IntrosortSizeThreshold)
// {
// if (length == 1)
// {
// return;
// }
// if (length == 2)
// {
// SwapIfGreater(items, comparison, 0, 1);
// return;
// }
// if (length == 3)
// {
// SwapIfGreater(items, comparison, 0, 1);
// SwapIfGreater(items, comparison, 0, 2);
// SwapIfGreater(items, comparison, 1, 2);
// return;
// }
// InsertionSort(items, length, comparison);
// return;
// }
// ComparisonHach.Instance.comparison = comparison;
// Array.Sort(items, 0, length, ComparisonHach.Instance);
// }
// #endregion
// }
//
//#if ENABLE_IL2CPP
// [Il2CppSetOption(Option.NullChecks, false)]
// [Il2CppSetOption(Option.ArrayBoundsChecks, false)]
//#endif
// internal static unsafe class UnsafeArraySortHalperX<T> where T : unmanaged
// {
// private const int IntrosortSizeThreshold = 16;
//
// [MethodImpl(MethodImplOptions.AggressiveInlining)]
// public static void SwapIfGreater<TComparer>(T* items, ref TComparer comparer, int i, int j) where TComparer : IStructComparer<T>
// {
// if (comparer.Compare(items[i], items[j]) > 0)
// {
// T key = items[i];
// items[i] = items[j];
// items[j] = key;
// }
// }
// [MethodImpl(MethodImplOptions.AggressiveInlining)]
// public static void InsertionSort_Unchecked<TComparer>(T* items, int length, ref TComparer comparer) where TComparer : IStructComparer<T>
// {
// for (int i = 0; i < length - 1; i++)
// {
// T t = items[i + 1];
//
// int j = i;
// while (j >= 0 && comparer.Compare(t, items[j]) < 0)
// {
// items[j + 1] = items[j];
// j--;
// }
//
// items[j + 1] = t;
// }
// }
// public static void InsertionSort<TComparer>(T* items, int length, ref TComparer comparer) where TComparer : IStructComparer<T>
// {
// if (length == 1)
// {
// return;
// }
//
// if (length == 2)
// {
// SwapIfGreater(items, ref comparer, 0, 1);
// return;
// }
//
// if (length == 3)
// {
// SwapIfGreater(items, ref comparer, 0, 1);
// SwapIfGreater(items, ref comparer, 0, 2);
// SwapIfGreater(items, ref comparer, 1, 2);
// return;
// }
//
// InsertionSort_Unchecked(items, length, ref comparer);
// }
// }
//}

View File

@ -3,7 +3,6 @@
#endif #endif
using DCFApixels.DragonECS.Core; using DCFApixels.DragonECS.Core;
using DCFApixels.DragonECS.Core.Internal; using DCFApixels.DragonECS.Core.Internal;
using DCFApixels.DragonECS.PoolsCore;
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
@ -401,6 +400,9 @@ namespace DCFApixels.DragonECS
#if ENABLE_IL2CPP #if ENABLE_IL2CPP
[Il2CppSetOption(Option.NullChecks, false)] [Il2CppSetOption(Option.NullChecks, false)]
#endif #endif
[MetaTags(MetaTags.HIDDEN)]
[MetaColor(MetaColor.DragonRose)]
[MetaGroup(EcsConsts.PACK_GROUP, EcsConsts.OTHER_GROUP)]
[EditorBrowsable(EditorBrowsableState.Never)] [EditorBrowsable(EditorBrowsableState.Never)]
public readonly struct ReadonlyEcsPool<T> : IEcsReadonlyPool //IEnumerable<T> - IntelliSense hack public readonly struct ReadonlyEcsPool<T> : IEcsReadonlyPool //IEnumerable<T> - IntelliSense hack
where T : struct, IEcsComponent where T : struct, IEcsComponent

View File

@ -8,13 +8,12 @@
#endif #endif
using DCFApixels.DragonECS.Core.Internal; using DCFApixels.DragonECS.Core.Internal;
using DCFApixels.DragonECS.PoolsCore;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
namespace DCFApixels.DragonECS.PoolsCore namespace DCFApixels.DragonECS.Core
{ {
/// <summary> Only used to implement a custom pool. In other contexts use IEcsPool or IEcsPool<T>. </summary> /// <summary> Only used to implement a custom pool. In other contexts use IEcsPool or IEcsPool<T>. </summary>
public interface IEcsPoolImplementation : IEcsPool public interface IEcsPoolImplementation : IEcsPool

View File

@ -3,7 +3,6 @@
#endif #endif
using DCFApixels.DragonECS.Core; using DCFApixels.DragonECS.Core;
using DCFApixels.DragonECS.Core.Internal; using DCFApixels.DragonECS.Core.Internal;
using DCFApixels.DragonECS.PoolsCore;
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
@ -344,6 +343,9 @@ namespace DCFApixels.DragonECS
#if ENABLE_IL2CPP #if ENABLE_IL2CPP
[Il2CppSetOption(Option.NullChecks, false)] [Il2CppSetOption(Option.NullChecks, false)]
#endif #endif
[MetaTags(MetaTags.HIDDEN)]
[MetaColor(MetaColor.DragonRose)]
[MetaGroup(EcsConsts.PACK_GROUP, EcsConsts.OTHER_GROUP)]
[EditorBrowsable(EditorBrowsableState.Never)] [EditorBrowsable(EditorBrowsableState.Never)]
public readonly struct ReadonlyEcsTagPool<T> : IEcsReadonlyPool //IEnumerable<T> - IntelliSense hack public readonly struct ReadonlyEcsTagPool<T> : IEcsReadonlyPool //IEnumerable<T> - IntelliSense hack
where T : struct, IEcsTagComponent where T : struct, IEcsTagComponent

View File

@ -3,7 +3,6 @@
#endif #endif
using DCFApixels.DragonECS.Core; using DCFApixels.DragonECS.Core;
using DCFApixels.DragonECS.Core.Internal; using DCFApixels.DragonECS.Core.Internal;
using DCFApixels.DragonECS.PoolsCore;
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
@ -37,8 +36,8 @@ namespace DCFApixels.DragonECS
public sealed unsafe class EcsValuePool<T> : IEcsPoolImplementation<T>, IEcsStructPool<T>, IEnumerable<T> //IEnumerable<T> - IntelliSense hack public sealed unsafe class EcsValuePool<T> : IEcsPoolImplementation<T>, IEcsStructPool<T>, IEnumerable<T> //IEnumerable<T> - IntelliSense hack
where T : unmanaged, IEcsValueComponent where T : unmanaged, IEcsValueComponent
{ {
private short _worldID;
private EcsWorld _world; private EcsWorld _world;
private short _worldID;
private int _componentTypeID; private int _componentTypeID;
private EcsMaskChunck _maskBit; private EcsMaskChunck _maskBit;
@ -126,6 +125,7 @@ namespace DCFApixels.DragonECS
void IEcsPoolImplementation.OnInit(EcsWorld world, EcsWorld.PoolsMediator mediator, int componentTypeID) void IEcsPoolImplementation.OnInit(EcsWorld world, EcsWorld.PoolsMediator mediator, int componentTypeID)
{ {
_world = world; _world = world;
_worldID = world.ID;
_mediator = mediator; _mediator = mediator;
_componentTypeID = componentTypeID; _componentTypeID = componentTypeID;
_maskBit = EcsMaskChunck.FromID(componentTypeID); _maskBit = EcsMaskChunck.FromID(componentTypeID);
@ -408,6 +408,9 @@ namespace DCFApixels.DragonECS
#if ENABLE_IL2CPP #if ENABLE_IL2CPP
[Il2CppSetOption(Option.NullChecks, false)] [Il2CppSetOption(Option.NullChecks, false)]
#endif #endif
[MetaTags(MetaTags.HIDDEN)]
[MetaColor(MetaColor.DragonRose)]
[MetaGroup(EcsConsts.PACK_GROUP, EcsConsts.OTHER_GROUP)]
[EditorBrowsable(EditorBrowsableState.Never)] [EditorBrowsable(EditorBrowsableState.Never)]
public readonly struct ReadonlyEcsValuePool<T> : IEcsReadonlyPool //IEnumerable<T> - IntelliSense hack public readonly struct ReadonlyEcsValuePool<T> : IEcsReadonlyPool //IEnumerable<T> - IntelliSense hack
where T : unmanaged, IEcsValueComponent where T : unmanaged, IEcsValueComponent

View File

@ -2,7 +2,7 @@
#undef DEBUG #undef DEBUG
#endif #endif
namespace DCFApixels.DragonECS.UncheckedCore namespace DCFApixels.DragonECS.Core.Unchecked
{ {
public readonly struct EntitiesMatrix public readonly struct EntitiesMatrix
{ {