From 1904fc4b8639d3be5e450841f9f0a3c3d2d13d25 Mon Sep 17 00:00:00 2001 From: Mikhail <99481254+DCFApixels@users.noreply.github.com> Date: Sat, 16 Mar 2024 14:21:38 +0800 Subject: [PATCH 1/7] Update Exceptions.cs --- src/Utils/Exceptions.cs | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/src/Utils/Exceptions.cs b/src/Utils/Exceptions.cs index 1697774..824dbe3 100644 --- a/src/Utils/Exceptions.cs +++ b/src/Utils/Exceptions.cs @@ -30,29 +30,11 @@ namespace DCFApixels.DragonECS.Internal { internal static class Throw { - [MethodImpl(MethodImplOptions.NoInlining)] - internal static void ArgumentNull() - { - throw new ArgumentNullException(); - } - [MethodImpl(MethodImplOptions.NoInlining)] internal static void ConstraintIsAlreadyContainedInMask(Type type) { throw new EcsFrameworkException($"The {EcsDebugUtility.GetGenericTypeName(type)} constraint is already contained in the mask."); } - - //[MethodImpl(MethodImplOptions.NoInlining)] - //public static void ArgumentDifferentWorldsException() - //{ - // throw new ArgumentException("The groups belong to different worlds."); - //} - [MethodImpl(MethodImplOptions.NoInlining)] - internal static void ArgumentOutOfRange() - { - throw new ArgumentOutOfRangeException($"index is less than 0 or is equal to or greater than Count."); - } - [MethodImpl(MethodImplOptions.NoInlining)] internal static void Group_AlreadyContains(int entityID) { @@ -128,6 +110,18 @@ namespace DCFApixels.DragonECS.Internal else throw new EcsFrameworkException($"The {entity} is not alive."); } + + + [MethodImpl(MethodImplOptions.NoInlining)] + internal static void ArgumentNull() + { + throw new ArgumentNullException(); + } + [MethodImpl(MethodImplOptions.NoInlining)] + internal static void ArgumentOutOfRange() + { + throw new ArgumentOutOfRangeException($"index is less than 0 or is equal to or greater than Count."); + } [MethodImpl(MethodImplOptions.NoInlining)] internal static void UndefinedException() { From f1c8b6e39facb9c5c58ff5f6a7cadfbc446cc9c8 Mon Sep 17 00:00:00 2001 From: Mikhail <99481254+DCFApixels@users.noreply.github.com> Date: Sun, 17 Mar 2024 05:22:33 +0800 Subject: [PATCH 2/7] Create UncheckedCoreUtility.cs --- src/Utils/UncheckedCoreUtility.cs | 42 +++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/Utils/UncheckedCoreUtility.cs diff --git a/src/Utils/UncheckedCoreUtility.cs b/src/Utils/UncheckedCoreUtility.cs new file mode 100644 index 0000000..4112dfe --- /dev/null +++ b/src/Utils/UncheckedCoreUtility.cs @@ -0,0 +1,42 @@ +using System; +using System.Collections.Generic; +using System.Runtime.CompilerServices; + +namespace DCFApixels.DragonECS.UncheckedCore +{ + public static class UncheckedCoreUtility + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static EcsSpan CreateSpan(short worldID, int[] entitesArray, int startIndex, int length) + { + return new EcsSpan(worldID, entitesArray, startIndex, length); + } + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static EcsSpan CreateSpan(short worldID, int[] entitesArray, int length) + { + return new EcsSpan(worldID, entitesArray, length); + } + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static EcsSpan CreateSpan(short worldID, int[] entitesArray) + { + return new EcsSpan(worldID, entitesArray); + } + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static EcsSpan CreateEmptySpan(short worldID) + { + return new EcsSpan(worldID, Array.Empty()); + } + public static bool CheckSpanValideDebug(EcsSpan span) + { + HashSet set = new HashSet(span.Count); + foreach (var e in span) + { + if (set.Add(e) == false) + { + return false; + } + } + return true; + } + } +} From 0cf215223af20cb107914de6bdc0def5ef3dd0c8 Mon Sep 17 00:00:00 2001 From: Mikhail <99481254+DCFApixels@users.noreply.github.com> Date: Sun, 17 Mar 2024 05:22:36 +0800 Subject: [PATCH 3/7] Update EcsQueryExecutor.cs --- src/Executors/EcsQueryExecutor.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Executors/EcsQueryExecutor.cs b/src/Executors/EcsQueryExecutor.cs index fdbf56a..5d4a036 100644 --- a/src/Executors/EcsQueryExecutor.cs +++ b/src/Executors/EcsQueryExecutor.cs @@ -5,15 +5,15 @@ namespace DCFApixels.DragonECS public abstract class EcsQueryExecutor { private EcsWorld _source; - public int WorldID + public short WorldID { [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => _source.id; + get { return _source.id; } } public EcsWorld World { [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => _source; + get { return _source; } } public abstract long Version { get; } internal void Initialize(EcsWorld world) From 4937abb2a6c778a54d51007f2f33e17ffb3645b1 Mon Sep 17 00:00:00 2001 From: Mikhail <99481254+DCFApixels@users.noreply.github.com> Date: Sun, 17 Mar 2024 10:18:16 +0800 Subject: [PATCH 4/7] add EcsMask.IsEmpty --- src/EcsMask.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/EcsMask.cs b/src/EcsMask.cs index fb22afa..f49160b 100644 --- a/src/EcsMask.cs +++ b/src/EcsMask.cs @@ -40,6 +40,10 @@ namespace DCFApixels.DragonECS { get { return exc; } } + public bool IsEmpty + { + get { return inc.Length == 0 && exc.Length == 0; } + } #endregion #region Constructors From a4bf37677a5d87994b94e10d5294d9b43aeb891a Mon Sep 17 00:00:00 2001 From: Mikhail <99481254+DCFApixels@users.noreply.github.com> Date: Sun, 17 Mar 2024 10:27:44 +0800 Subject: [PATCH 5/7] Create UncheckedCoreUtility.cs.meta --- src/Utils/UncheckedCoreUtility.cs.meta | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 src/Utils/UncheckedCoreUtility.cs.meta diff --git a/src/Utils/UncheckedCoreUtility.cs.meta b/src/Utils/UncheckedCoreUtility.cs.meta new file mode 100644 index 0000000..6526373 --- /dev/null +++ b/src/Utils/UncheckedCoreUtility.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 9d505e05a1757344fa2237b4b9be4409 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: From 83ea1d470cb2a840775d8534f699877aa5ae595e Mon Sep 17 00:00:00 2001 From: Mikhail <99481254+DCFApixels@users.noreply.github.com> Date: Mon, 25 Mar 2024 21:02:45 +0800 Subject: [PATCH 6/7] Update UncheckedCoreUtility.cs --- src/Utils/UncheckedCoreUtility.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Utils/UncheckedCoreUtility.cs b/src/Utils/UncheckedCoreUtility.cs index 4112dfe..5538d81 100644 --- a/src/Utils/UncheckedCoreUtility.cs +++ b/src/Utils/UncheckedCoreUtility.cs @@ -6,6 +6,12 @@ namespace DCFApixels.DragonECS.UncheckedCore { public static class UncheckedCoreUtility { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static EcsSpan CreateSpan(short worldID, ReadOnlySpan entitesArray) + { + return new EcsSpan(worldID, entitesArray); + } + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static EcsSpan CreateSpan(short worldID, int[] entitesArray, int startIndex, int length) { From 9876f882d79c29ac5862deb35b3c853ebb801dc9 Mon Sep 17 00:00:00 2001 From: Mikhail <99481254+DCFApixels@users.noreply.github.com> Date: Tue, 26 Mar 2024 16:06:03 +0800 Subject: [PATCH 7/7] simplify aspect builder syntax --- src/EcsAspect.cs | 58 +++++++++++++++++++++++++++++++++++++++++++--- src/EcsPipeline.cs | 17 +++++++++++--- 2 files changed, 69 insertions(+), 6 deletions(-) diff --git a/src/EcsAspect.cs b/src/EcsAspect.cs index 5aa3595..cb6f8f6 100644 --- a/src/EcsAspect.cs +++ b/src/EcsAspect.cs @@ -10,7 +10,46 @@ namespace DCFApixels.DragonECS { internal EcsWorld _source; internal EcsMask _mask; - private bool _isInit = false; + private bool _isBuilt = false; + + [ThreadStatic] + private static bool _isConstructorStream; + [ThreadStatic] + private static Builder _constructorStreamBuilder; + + protected static IncludeMarker Inc + { + get + { + if(_isConstructorStream == false) + { //TODO перевести + throw new InvalidOperationException($"{nameof(Inc)} можно использовать только во время инициализации полей и в конструкторе");//TODO Перевести + } + return _constructorStreamBuilder.Inc; + } + } + protected static ExcludeMarker Exc + { + get + { + if (_isConstructorStream == false) + { //TODO перевести + throw new InvalidOperationException($"{nameof(Exc)} можно использовать только во время инициализации полей и в конструкторе");//TODO Перевести + } + return _constructorStreamBuilder.Exc; + } + } + protected static OptionalMarker Opt + { + get + { + if (_isConstructorStream == false) + { //TODO перевести + throw new InvalidOperationException($"{nameof(Opt)} можно использовать только во время инициализации полей и в конструкторе");//TODO Перевести + } + return _constructorStreamBuilder.Opt; + } + } private UnsafeArray _sortIncBuffer; private UnsafeArray _sortExcBuffer; @@ -28,7 +67,7 @@ namespace DCFApixels.DragonECS } public bool IsInit { - get { return _isInit; } + get { return _isBuilt; } } #endregion @@ -45,6 +84,7 @@ namespace DCFApixels.DragonECS { private EcsWorld _world; private EcsMask.Builder _maskBuilder; + private bool _isBuilt = false; public IncludeMarker Inc { @@ -74,9 +114,18 @@ namespace DCFApixels.DragonECS //TODO добавить оповещение что инициализация через конструктор не работает #if !REFLECTION_DISABLED ConstructorInfo constructorInfo = aspectType.GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[] { typeof(Builder) }, null); + + if (_isConstructorStream == true) + { + throw new InvalidOperationException("Нельзя рекурсивно вызывать конструктор аспекта");//TODO Перевести + } + _constructorStreamBuilder = builder; + _isConstructorStream = true; if (constructorInfo != null) { newAspect = (EcsAspect)constructorInfo.Invoke(new object[] { builder }); + _constructorStreamBuilder = null; + _isConstructorStream = false; } else #endif @@ -84,11 +133,13 @@ namespace DCFApixels.DragonECS #pragma warning disable IL2091 // Target generic argument does not satisfy 'DynamicallyAccessedMembersAttribute' in target method or type. The generic parameter of the source method or type does not have matching annotations. newAspect = Activator.CreateInstance(); #pragma warning restore IL2091 + _constructorStreamBuilder = null; + _isConstructorStream = false; newAspect.Init(builder); } newAspect._source = world; builder.Build(out newAspect._mask); - newAspect._isInit = true; + newAspect._isBuilt = true; newAspect._sortIncBuffer = new UnsafeArray(newAspect._mask.inc.Length, true); newAspect._sortExcBuffer = new UnsafeArray(newAspect._mask.exc.Length, true); @@ -152,6 +203,7 @@ namespace DCFApixels.DragonECS private void Build(out EcsMask mask) { mask = _maskBuilder.Build(); + _isBuilt = true; } #region SupportReflectionHack diff --git a/src/EcsPipeline.cs b/src/EcsPipeline.cs index 9baba80..084665c 100644 --- a/src/EcsPipeline.cs +++ b/src/EcsPipeline.cs @@ -13,6 +13,10 @@ namespace DCFApixels.DragonECS { EcsPipeline Pipeline { get; set; } } + public interface IEcsSystemDefaultLayer : IEcsProcess + { + string Layer { get; } + } public sealed class EcsPipeline { private readonly IConfigContainer _configs; @@ -261,19 +265,26 @@ namespace DCFApixels.DragonECS } private void AddInternal(IEcsProcess system, string layerName, bool isUnique) { - if (layerName == null) layerName = _basicLayer; + if (string.IsNullOrEmpty(layerName)) + { + layerName = system is IEcsSystemDefaultLayer defaultLayer ? defaultLayer.Layer : _basicLayer; + } List list; if (!_systems.TryGetValue(layerName, out list)) { - list = new List { new SystemsLayerMarkerSystem(layerName.ToString()) }; + list = new List { new SystemsLayerMarkerSystem(layerName) }; _systems.Add(layerName, list); } - if ((_uniqueTypes.Add(system.GetType()) == false && isUnique)) + if (_uniqueTypes.Add(system.GetType()) == false && isUnique) + { return; + } list.Add(system); if (system is IEcsModule module)//если система одновременно явялется и системой и модулем то за один Add будет вызван Add и AddModule + { AddModule(module); + } } public Builder AddModule(IEcsModule module) {