From 0513c55d2cbf0d67d369c63ebc11b64018ac3b16 Mon Sep 17 00:00:00 2001 From: Mikhail <99481254+DCFApixels@users.noreply.github.com> Date: Thu, 30 Mar 2023 01:57:10 +0800 Subject: [PATCH] refactoring --- src/Consts.cs | 2 + src/EcsFilter.cs | 393 +----------------- src/EcsMask.cs | 391 +++++++++++++++++ src/EcsMask.cs.meta | 11 + src/EcsRunner.cs | 52 +-- src/EcsWorld.cs | 8 +- src/Exceptions/EcsFrameworkException.cs | 5 +- .../EcsRunnerImplementationException.cs | 15 + .../EcsRunnerImplementationException.cs.meta | 11 + src/{Entity.cs => ent.cs} | 0 src/{Entity.cs.meta => ent.cs.meta} | 0 11 files changed, 462 insertions(+), 426 deletions(-) create mode 100644 src/EcsMask.cs create mode 100644 src/EcsMask.cs.meta create mode 100644 src/Exceptions/EcsRunnerImplementationException.cs create mode 100644 src/Exceptions/EcsRunnerImplementationException.cs.meta rename src/{Entity.cs => ent.cs} (100%) rename src/{Entity.cs.meta => ent.cs.meta} (100%) diff --git a/src/Consts.cs b/src/Consts.cs index aa47446..a186a3e 100644 --- a/src/Consts.cs +++ b/src/Consts.cs @@ -4,5 +4,7 @@ { public const string EXCEPTION_MESSAGE_PREFIX = "[DragonECS] "; public const string DEBUG_PREFIX = "[DEBUG] "; + public const string DEBUG_WARNING_TAG = "WARNING"; + public const string DEBUG_ERROR_TAG = "ERROR"; } } diff --git a/src/EcsFilter.cs b/src/EcsFilter.cs index 638e679..5056930 100644 --- a/src/EcsFilter.cs +++ b/src/EcsFilter.cs @@ -1,401 +1,15 @@ -using System; -using System.Runtime.CompilerServices; -using System.Reflection; +using System.Runtime.CompilerServices; namespace DCFApixels.DragonECS { - #region Incs/Excs base - public interface IMaskCondition - { - public int[] GetComponentsIDs() where TWorldArchetype : EcsWorld; - } - #endregion - - #region Incs - public interface IInc : IMaskCondition { } - public struct Inc : IInc - { - public int[] GetComponentsIDs() where TWorldArchetype : EcsWorld => Array.Empty(); - } - public struct Inc : IInc - { - public int[] GetComponentsIDs() where TWorldArchetype : EcsWorld - { - return new int[] - { - EcsWorld.ComponentType.uniqueID, - }; - } - } - public struct Inc : IInc - { - public int[] GetComponentsIDs() where TWorldArchetype : EcsWorld - { - return new int[] - { - EcsWorld.ComponentType.uniqueID, - EcsWorld.ComponentType.uniqueID, - }; - } - } - public struct Inc : IInc - { - public int[] GetComponentsIDs() where TWorldArchetype : EcsWorld - { - return new int[] - { - EcsWorld.ComponentType.uniqueID, - EcsWorld.ComponentType.uniqueID, - EcsWorld.ComponentType.uniqueID, - }; - } - } - public struct Inc : IInc - { - public int[] GetComponentsIDs() where TWorldArchetype : EcsWorld - { - return new int[] - { - EcsWorld.ComponentType.uniqueID, - EcsWorld.ComponentType.uniqueID, - EcsWorld.ComponentType.uniqueID, - EcsWorld.ComponentType.uniqueID, - }; - } - } - public struct Inc : IInc - { - public int[] GetComponentsIDs() where TWorldArchetype : EcsWorld - { - return new int[] - { - EcsWorld.ComponentType.uniqueID, - EcsWorld.ComponentType.uniqueID, - EcsWorld.ComponentType.uniqueID, - EcsWorld.ComponentType.uniqueID, - EcsWorld.ComponentType.uniqueID, - }; - } - } - public struct Inc : IInc - { - public int[] GetComponentsIDs() where TWorldArchetype : EcsWorld - { - return new int[] - { - EcsWorld.ComponentType.uniqueID, - EcsWorld.ComponentType.uniqueID, - EcsWorld.ComponentType.uniqueID, - EcsWorld.ComponentType.uniqueID, - EcsWorld.ComponentType.uniqueID, - EcsWorld.ComponentType.uniqueID, - }; - } - } - public struct Inc : IInc - { - public int[] GetComponentsIDs() where TWorldArchetype : EcsWorld - { - return new int[] - { - EcsWorld.ComponentType.uniqueID, - EcsWorld.ComponentType.uniqueID, - EcsWorld.ComponentType.uniqueID, - EcsWorld.ComponentType.uniqueID, - EcsWorld.ComponentType.uniqueID, - EcsWorld.ComponentType.uniqueID, - EcsWorld.ComponentType.uniqueID, - }; - } - } - public struct Inc : IInc - { - public int[] GetComponentsIDs() where TWorldArchetype : EcsWorld - { - return new int[] - { - EcsWorld.ComponentType.uniqueID, - EcsWorld.ComponentType.uniqueID, - EcsWorld.ComponentType.uniqueID, - EcsWorld.ComponentType.uniqueID, - EcsWorld.ComponentType.uniqueID, - EcsWorld.ComponentType.uniqueID, - EcsWorld.ComponentType.uniqueID, - EcsWorld.ComponentType.uniqueID, - }; - } - } - public struct Inc : IInc - { - public int[] GetComponentsIDs() where TWorldArchetype : EcsWorld - { - return new int[] - { - EcsWorld.ComponentType.uniqueID, - EcsWorld.ComponentType.uniqueID, - EcsWorld.ComponentType.uniqueID, - EcsWorld.ComponentType.uniqueID, - EcsWorld.ComponentType.uniqueID, - EcsWorld.ComponentType.uniqueID, - EcsWorld.ComponentType.uniqueID, - EcsWorld.ComponentType.uniqueID, - EcsWorld.ComponentType.uniqueID, - }; - } - } - public struct Inc : IInc - { - public int[] GetComponentsIDs() where TWorldArchetype : EcsWorld - { - return new int[] - { - EcsWorld.ComponentType.uniqueID, - EcsWorld.ComponentType.uniqueID, - EcsWorld.ComponentType.uniqueID, - EcsWorld.ComponentType.uniqueID, - EcsWorld.ComponentType.uniqueID, - EcsWorld.ComponentType.uniqueID, - EcsWorld.ComponentType.uniqueID, - EcsWorld.ComponentType.uniqueID, - EcsWorld.ComponentType.uniqueID, - EcsWorld.ComponentType.uniqueID, - }; - } - } - public struct Inc : IInc - { - public int[] GetComponentsIDs() where TWorldArchetype : EcsWorld - { - return new int[] - { - EcsWorld.ComponentType.uniqueID, - EcsWorld.ComponentType.uniqueID, - EcsWorld.ComponentType.uniqueID, - EcsWorld.ComponentType.uniqueID, - EcsWorld.ComponentType.uniqueID, - EcsWorld.ComponentType.uniqueID, - EcsWorld.ComponentType.uniqueID, - EcsWorld.ComponentType.uniqueID, - EcsWorld.ComponentType.uniqueID, - EcsWorld.ComponentType.uniqueID, - EcsWorld.ComponentType.uniqueID, - }; - } - } - public struct Inc : IInc - { - public int[] GetComponentsIDs() where TWorldArchetype : EcsWorld - { - return new int[] - { - EcsWorld.ComponentType.uniqueID, - EcsWorld.ComponentType.uniqueID, - EcsWorld.ComponentType.uniqueID, - EcsWorld.ComponentType.uniqueID, - EcsWorld.ComponentType.uniqueID, - EcsWorld.ComponentType.uniqueID, - EcsWorld.ComponentType.uniqueID, - EcsWorld.ComponentType.uniqueID, - EcsWorld.ComponentType.uniqueID, - EcsWorld.ComponentType.uniqueID, - EcsWorld.ComponentType.uniqueID, - EcsWorld.ComponentType.uniqueID, - }; - } - } - #endregion - - #region Excs - public interface IExc : IMaskCondition { } - public struct Exc : IExc - { - public int[] GetComponentsIDs() where TWorldArchetype : EcsWorld => Array.Empty(); - } - public struct Exc : IExc - { - public int[] GetComponentsIDs() where TWorldArchetype : EcsWorld - { - return new int[] - { - EcsWorld.ComponentType.uniqueID, - }; - } - } - public struct Exc : IExc - { - public int[] GetComponentsIDs() where TWorldArchetype : EcsWorld - { - return new int[] - { - EcsWorld.ComponentType.uniqueID, - EcsWorld.ComponentType.uniqueID, - }; - } - } - public struct Exc : IExc - { - public int[] GetComponentsIDs() where TWorldArchetype : EcsWorld - { - return new int[] - { - EcsWorld.ComponentType.uniqueID, - EcsWorld.ComponentType.uniqueID, - EcsWorld.ComponentType.uniqueID, - }; - } - } - public struct Exc : IExc - { - public int[] GetComponentsIDs() where TWorldArchetype : EcsWorld - { - return new int[] - { - EcsWorld.ComponentType.uniqueID, - EcsWorld.ComponentType.uniqueID, - EcsWorld.ComponentType.uniqueID, - EcsWorld.ComponentType.uniqueID, - }; - } - } - public struct Exc : IExc - { - public int[] GetComponentsIDs() where TWorldArchetype : EcsWorld - { - return new int[] - { - EcsWorld.ComponentType.uniqueID, - EcsWorld.ComponentType.uniqueID, - EcsWorld.ComponentType.uniqueID, - EcsWorld.ComponentType.uniqueID, - EcsWorld.ComponentType.uniqueID, - }; - } - } - public struct Exc : IExc - { - public int[] GetComponentsIDs() where TWorldArchetype : EcsWorld - { - return new int[] - { - EcsWorld.ComponentType.uniqueID, - EcsWorld.ComponentType.uniqueID, - EcsWorld.ComponentType.uniqueID, - EcsWorld.ComponentType.uniqueID, - EcsWorld.ComponentType.uniqueID, - EcsWorld.ComponentType.uniqueID, - }; - } - } - #endregion - - #region EcsMask - public sealed class EcsMask - { - internal readonly Type WorldArchetypeType; - internal readonly int UniqueID; - internal readonly int[] Inc; - internal readonly int[] Exc; - - internal int IncCount - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => Inc.Length; - } - internal int ExcCount - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => Exc.Length; - } - internal EcsMask(Type worldArchetypeType, int uniqueID, int[] inc, int[] exc) - { - WorldArchetypeType = worldArchetypeType; - UniqueID = uniqueID; - Inc = inc; - Exc = exc; - } - } - - public static class EcsMaskMap - where TWorldArchetype : EcsWorld - { - private static int _count; - private static int _capacity; - - public static int Count - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => _count; - } - public static int Capacity - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => _capacity; - } - - public static EcsMask GetMask() - where TInc : struct, IInc - where TExc : struct, IExc - { - return Activator.instance; - } - - private class Activator - where TInc : struct, IInc - where TExc : struct, IExc - { - static Activator() - { - var inc = new TInc().GetComponentsIDs(); - var exc = new TExc().GetComponentsIDs(); - Array.Sort(inc); - Array.Sort(exc); - - Type thisType = typeof(Activator); - - Type sortedIncType = typeof(TInc); - if (sortedIncType.IsGenericType) - { - Type[] sortedInc = new Type[inc.Length]; - for (int i = 0; i < sortedInc.Length; i++) - sortedInc[i] = EcsWorld.ComponentType.types[inc[i]]; - sortedIncType = sortedIncType.GetGenericTypeDefinition().MakeGenericType(sortedInc); - } - Type sortedExcType = typeof(TExc); - if (sortedExcType.IsGenericType) - { - Type[] sortedExc = new Type[exc.Length]; - for (int i = 0; i < sortedExc.Length; i++) - sortedExc[i] = EcsWorld.ComponentType.types[exc[i]]; - sortedExcType = sortedExcType.GetGenericTypeDefinition().MakeGenericType(sortedExc); - } - - Type targetType = typeof(Activator<,>).MakeGenericType(typeof(TWorldArchetype), sortedIncType, sortedExcType); - - if (targetType != thisType) - { - instance = (EcsMask)targetType.GetField(nameof(instance), BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic).GetValue(null); - return; - } - - var id = _count++; - if (_count >= _capacity) - _capacity <<= 1; - - instance = new EcsMask(typeof(TWorldArchetype), id, inc, exc); - } - - public readonly static EcsMask instance; - } - } - #endregion - - #region Filter public interface IEcsFilter { + #region Properties public IEcsWorld World { get; } public EcsMask Mask { get; } public IEcsReadonlyGroup Entities { get; } public int EntitiesCount { get; } + #endregion } public class EcsFilter : IEcsFilter @@ -455,5 +69,4 @@ namespace DCFApixels.DragonECS public EcsGroup.Enumerator GetEnumerator() => _entities.GetEnumerator(); #endregion } - #endregion } diff --git a/src/EcsMask.cs b/src/EcsMask.cs new file mode 100644 index 0000000..64dcfd1 --- /dev/null +++ b/src/EcsMask.cs @@ -0,0 +1,391 @@ +using System; +using System.Runtime.CompilerServices; +using System.Reflection; + +namespace DCFApixels.DragonECS +{ + #region Incs/Excs base + public interface IMaskCondition + { + public int[] GetComponentsIDs() where TWorldArchetype : EcsWorld; + } + #endregion + + #region Incs + public interface IInc : IMaskCondition { } + public struct Inc : IInc + { + public int[] GetComponentsIDs() where TWorldArchetype : EcsWorld => Array.Empty(); + } + public struct Inc : IInc + { + public int[] GetComponentsIDs() where TWorldArchetype : EcsWorld + { + return new int[] + { + EcsWorld.ComponentType.uniqueID, + }; + } + } + public struct Inc : IInc + { + public int[] GetComponentsIDs() where TWorldArchetype : EcsWorld + { + return new int[] + { + EcsWorld.ComponentType.uniqueID, + EcsWorld.ComponentType.uniqueID, + }; + } + } + public struct Inc : IInc + { + public int[] GetComponentsIDs() where TWorldArchetype : EcsWorld + { + return new int[] + { + EcsWorld.ComponentType.uniqueID, + EcsWorld.ComponentType.uniqueID, + EcsWorld.ComponentType.uniqueID, + }; + } + } + public struct Inc : IInc + { + public int[] GetComponentsIDs() where TWorldArchetype : EcsWorld + { + return new int[] + { + EcsWorld.ComponentType.uniqueID, + EcsWorld.ComponentType.uniqueID, + EcsWorld.ComponentType.uniqueID, + EcsWorld.ComponentType.uniqueID, + }; + } + } + public struct Inc : IInc + { + public int[] GetComponentsIDs() where TWorldArchetype : EcsWorld + { + return new int[] + { + EcsWorld.ComponentType.uniqueID, + EcsWorld.ComponentType.uniqueID, + EcsWorld.ComponentType.uniqueID, + EcsWorld.ComponentType.uniqueID, + EcsWorld.ComponentType.uniqueID, + }; + } + } + public struct Inc : IInc + { + public int[] GetComponentsIDs() where TWorldArchetype : EcsWorld + { + return new int[] + { + EcsWorld.ComponentType.uniqueID, + EcsWorld.ComponentType.uniqueID, + EcsWorld.ComponentType.uniqueID, + EcsWorld.ComponentType.uniqueID, + EcsWorld.ComponentType.uniqueID, + EcsWorld.ComponentType.uniqueID, + }; + } + } + public struct Inc : IInc + { + public int[] GetComponentsIDs() where TWorldArchetype : EcsWorld + { + return new int[] + { + EcsWorld.ComponentType.uniqueID, + EcsWorld.ComponentType.uniqueID, + EcsWorld.ComponentType.uniqueID, + EcsWorld.ComponentType.uniqueID, + EcsWorld.ComponentType.uniqueID, + EcsWorld.ComponentType.uniqueID, + EcsWorld.ComponentType.uniqueID, + }; + } + } + public struct Inc : IInc + { + public int[] GetComponentsIDs() where TWorldArchetype : EcsWorld + { + return new int[] + { + EcsWorld.ComponentType.uniqueID, + EcsWorld.ComponentType.uniqueID, + EcsWorld.ComponentType.uniqueID, + EcsWorld.ComponentType.uniqueID, + EcsWorld.ComponentType.uniqueID, + EcsWorld.ComponentType.uniqueID, + EcsWorld.ComponentType.uniqueID, + EcsWorld.ComponentType.uniqueID, + }; + } + } + public struct Inc : IInc + { + public int[] GetComponentsIDs() where TWorldArchetype : EcsWorld + { + return new int[] + { + EcsWorld.ComponentType.uniqueID, + EcsWorld.ComponentType.uniqueID, + EcsWorld.ComponentType.uniqueID, + EcsWorld.ComponentType.uniqueID, + EcsWorld.ComponentType.uniqueID, + EcsWorld.ComponentType.uniqueID, + EcsWorld.ComponentType.uniqueID, + EcsWorld.ComponentType.uniqueID, + EcsWorld.ComponentType.uniqueID, + }; + } + } + public struct Inc : IInc + { + public int[] GetComponentsIDs() where TWorldArchetype : EcsWorld + { + return new int[] + { + EcsWorld.ComponentType.uniqueID, + EcsWorld.ComponentType.uniqueID, + EcsWorld.ComponentType.uniqueID, + EcsWorld.ComponentType.uniqueID, + EcsWorld.ComponentType.uniqueID, + EcsWorld.ComponentType.uniqueID, + EcsWorld.ComponentType.uniqueID, + EcsWorld.ComponentType.uniqueID, + EcsWorld.ComponentType.uniqueID, + EcsWorld.ComponentType.uniqueID, + }; + } + } + public struct Inc : IInc + { + public int[] GetComponentsIDs() where TWorldArchetype : EcsWorld + { + return new int[] + { + EcsWorld.ComponentType.uniqueID, + EcsWorld.ComponentType.uniqueID, + EcsWorld.ComponentType.uniqueID, + EcsWorld.ComponentType.uniqueID, + EcsWorld.ComponentType.uniqueID, + EcsWorld.ComponentType.uniqueID, + EcsWorld.ComponentType.uniqueID, + EcsWorld.ComponentType.uniqueID, + EcsWorld.ComponentType.uniqueID, + EcsWorld.ComponentType.uniqueID, + EcsWorld.ComponentType.uniqueID, + }; + } + } + public struct Inc : IInc + { + public int[] GetComponentsIDs() where TWorldArchetype : EcsWorld + { + return new int[] + { + EcsWorld.ComponentType.uniqueID, + EcsWorld.ComponentType.uniqueID, + EcsWorld.ComponentType.uniqueID, + EcsWorld.ComponentType.uniqueID, + EcsWorld.ComponentType.uniqueID, + EcsWorld.ComponentType.uniqueID, + EcsWorld.ComponentType.uniqueID, + EcsWorld.ComponentType.uniqueID, + EcsWorld.ComponentType.uniqueID, + EcsWorld.ComponentType.uniqueID, + EcsWorld.ComponentType.uniqueID, + EcsWorld.ComponentType.uniqueID, + }; + } + } + #endregion + + #region Excs + public interface IExc : IMaskCondition { } + public struct Exc : IExc + { + public int[] GetComponentsIDs() where TWorldArchetype : EcsWorld => Array.Empty(); + } + public struct Exc : IExc + { + public int[] GetComponentsIDs() where TWorldArchetype : EcsWorld + { + return new int[] + { + EcsWorld.ComponentType.uniqueID, + }; + } + } + public struct Exc : IExc + { + public int[] GetComponentsIDs() where TWorldArchetype : EcsWorld + { + return new int[] + { + EcsWorld.ComponentType.uniqueID, + EcsWorld.ComponentType.uniqueID, + }; + } + } + public struct Exc : IExc + { + public int[] GetComponentsIDs() where TWorldArchetype : EcsWorld + { + return new int[] + { + EcsWorld.ComponentType.uniqueID, + EcsWorld.ComponentType.uniqueID, + EcsWorld.ComponentType.uniqueID, + }; + } + } + public struct Exc : IExc + { + public int[] GetComponentsIDs() where TWorldArchetype : EcsWorld + { + return new int[] + { + EcsWorld.ComponentType.uniqueID, + EcsWorld.ComponentType.uniqueID, + EcsWorld.ComponentType.uniqueID, + EcsWorld.ComponentType.uniqueID, + }; + } + } + public struct Exc : IExc + { + public int[] GetComponentsIDs() where TWorldArchetype : EcsWorld + { + return new int[] + { + EcsWorld.ComponentType.uniqueID, + EcsWorld.ComponentType.uniqueID, + EcsWorld.ComponentType.uniqueID, + EcsWorld.ComponentType.uniqueID, + EcsWorld.ComponentType.uniqueID, + }; + } + } + public struct Exc : IExc + { + public int[] GetComponentsIDs() where TWorldArchetype : EcsWorld + { + return new int[] + { + EcsWorld.ComponentType.uniqueID, + EcsWorld.ComponentType.uniqueID, + EcsWorld.ComponentType.uniqueID, + EcsWorld.ComponentType.uniqueID, + EcsWorld.ComponentType.uniqueID, + EcsWorld.ComponentType.uniqueID, + }; + } + } + #endregion + + #region EcsMask + public sealed class EcsMask + { + internal readonly Type WorldArchetypeType; + internal readonly int UniqueID; + internal readonly int[] Inc; + internal readonly int[] Exc; + + internal int IncCount + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get => Inc.Length; + } + internal int ExcCount + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get => Exc.Length; + } + internal EcsMask(Type worldArchetypeType, int uniqueID, int[] inc, int[] exc) + { + WorldArchetypeType = worldArchetypeType; + UniqueID = uniqueID; + Inc = inc; + Exc = exc; + } + } + + public static class EcsMaskMap + where TWorldArchetype : EcsWorld + { + private static int _count; + private static int _capacity; + + public static int Count + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get => _count; + } + public static int Capacity + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get => _capacity; + } + + public static EcsMask GetMask() + where TInc : struct, IInc + where TExc : struct, IExc + { + return Activator.instance; + } + + private class Activator + where TInc : struct, IInc + where TExc : struct, IExc + { + static Activator() + { + var inc = new TInc().GetComponentsIDs(); + var exc = new TExc().GetComponentsIDs(); + Array.Sort(inc); + Array.Sort(exc); + + Type thisType = typeof(Activator); + + Type sortedIncType = typeof(TInc); + if (sortedIncType.IsGenericType) + { + Type[] sortedInc = new Type[inc.Length]; + for (int i = 0; i < sortedInc.Length; i++) + sortedInc[i] = EcsWorld.ComponentType.types[inc[i]]; + sortedIncType = sortedIncType.GetGenericTypeDefinition().MakeGenericType(sortedInc); + } + Type sortedExcType = typeof(TExc); + if (sortedExcType.IsGenericType) + { + Type[] sortedExc = new Type[exc.Length]; + for (int i = 0; i < sortedExc.Length; i++) + sortedExc[i] = EcsWorld.ComponentType.types[exc[i]]; + sortedExcType = sortedExcType.GetGenericTypeDefinition().MakeGenericType(sortedExc); + } + + Type targetType = typeof(Activator<,>).MakeGenericType(typeof(TWorldArchetype), sortedIncType, sortedExcType); + + if (targetType != thisType) + { + instance = (EcsMask)targetType.GetField(nameof(instance), BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic).GetValue(null); + return; + } + + var id = _count++; + if (_count >= _capacity) + _capacity <<= 1; + + instance = new EcsMask(typeof(TWorldArchetype), id, inc, exc); + } + + public readonly static EcsMask instance; + } + } + #endregion +} diff --git a/src/EcsMask.cs.meta b/src/EcsMask.cs.meta new file mode 100644 index 0000000..aac60c5 --- /dev/null +++ b/src/EcsMask.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 7fe304214160d1a49ba0acf229539df1 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/src/EcsRunner.cs b/src/EcsRunner.cs index 2b514f0..08405d7 100644 --- a/src/EcsRunner.cs +++ b/src/EcsRunner.cs @@ -2,7 +2,6 @@ using System.Collections; using System.Collections.Generic; using System.Collections.ObjectModel; -using System.Linq.Expressions; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; @@ -19,12 +18,7 @@ namespace DCFApixels.DragonECS this.interfaceType = interfaceType; this.filter = filter; } - - public EcsRunnerFilterAttribute(object filter) - { - interfaceType = null; - this.filter = filter; - } + public EcsRunnerFilterAttribute(object filter) : this(null, filter) { } } public interface IEcsSystem { } @@ -36,31 +30,19 @@ namespace DCFApixels.DragonECS public bool IsHasFilter { get; } } - - public static class IEcsProcessorExtensions - { - public static bool IsRunner(this IEcsSystem self) - { - return self is IEcsRunner; - } - } - internal static class EcsRunnerActivator { private static Dictionary _runnerHandlerTypes; //interface guid/Runner handler type pairs; static EcsRunnerActivator() { - List exceptions = new List(); - + List delayedExceptions = new List(); Type runnerBaseType = typeof(EcsRunner<>); - List runnerHandlerTypes = new List(); foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies()) { - runnerHandlerTypes.AddRange( - assembly.GetTypes() + runnerHandlerTypes.AddRange(assembly.GetTypes() .Where(type => type.BaseType != null && type.BaseType.IsGenericType && runnerBaseType == type.BaseType.GetGenericTypeDefinition())); } @@ -71,21 +53,21 @@ namespace DCFApixels.DragonECS if (e != null) { runnerHandlerTypes.RemoveAt(i--); - exceptions.Add(e); + delayedExceptions.Add(e); } } #endif _runnerHandlerTypes = new Dictionary(); foreach (var item in runnerHandlerTypes) { - //Type interfaceType = item.GetInterfaces().Where(o => o != typeof(IEcsRunner) && o != typeof(IEcsSystem)).First(); //TODO оптимизировать это место Type interfaceType = item.BaseType.GenericTypeArguments[0]; _runnerHandlerTypes.Add(interfaceType.GUID, item); } - if (exceptions.Count > 0) + if (delayedExceptions.Count > 0) { - foreach (var item in exceptions) throw item; + foreach (var item in delayedExceptions) EcsDebug.Print(EcsConsts.DEBUG_ERROR_TAG, item.Message); + throw delayedExceptions[0]; } } @@ -96,18 +78,18 @@ namespace DCFApixels.DragonECS if (type.ReflectedType != null) { - return new Exception($"{type.FullName}.ReflectedType must be Null, but equal to {type.ReflectedType.FullName}."); + return new EcsRunnerImplementationException($"{type.FullName}.ReflectedType must be Null, but equal to {type.ReflectedType.FullName}."); } if (!baseTypeArgument.IsInterface) { - return new Exception($"Argument T of class EcsRunner, can only be an inetrface.The {baseTypeArgument.FullName} type is not an interface."); + return new EcsRunnerImplementationException($"Argument T of class EcsRunner, can only be an inetrface.The {baseTypeArgument.FullName} type is not an interface."); } var interfaces = type.GetInterfaces(); if (!interfaces.Any(o => o == baseTypeArgument)) { - return new Exception($"Runner {type.FullName} does not implement interface {baseTypeArgument.FullName}."); + return new EcsRunnerImplementationException($"Runner {type.FullName} does not implement interface {baseTypeArgument.FullName}."); } return null; @@ -148,7 +130,7 @@ namespace DCFApixels.DragonECS #if DEBUG || !DRAGONECS_NO_SANITIZE_CHECKS if (_subclass != null) { - throw new ArgumentException($"The Runner<{typeof(TInterface).FullName}> can only have one subclass"); + throw new EcsRunnerImplementationException($"The Runner<{typeof(TInterface).FullName}> can have only one implementing subclass"); } Type interfaceType = typeof(TInterface); @@ -225,10 +207,12 @@ namespace DCFApixels.DragonECS private object _filter; private bool _isHasFilter; + #region Properties public EcsSystems Source => _source; public IList Targets => _targetsSealed; public object Filter => _filter; public bool IsHasFilter => _isHasFilter; + #endregion private EcsRunner Set(EcsSystems source, TInterface[] targets, bool isHasFilter, object filter) { @@ -251,4 +235,14 @@ namespace DCFApixels.DragonECS Set(_source, FilterSystems(_source.AllSystems, _filter), _isHasFilter, _filter); } } + + #region Extensions + public static class IEcsSystemExtensions + { + public static bool IsRunner(this IEcsSystem self) + { + return self is IEcsRunner; + } + } + #endregion } diff --git a/src/EcsWorld.cs b/src/EcsWorld.cs index 93e6b44..88427ba 100644 --- a/src/EcsWorld.cs +++ b/src/EcsWorld.cs @@ -351,15 +351,13 @@ namespace DCFApixels.DragonECS #endregion } - - - - - public static class IEcsWorldExt + #region Extensions + public static class IEcsWorldExtensions { public static void DelEntity(this IEcsWorld self, ent entity) { self.DelEntity(entity.id); } } + #endregion } diff --git a/src/Exceptions/EcsFrameworkException.cs b/src/Exceptions/EcsFrameworkException.cs index 3b76834..5101ee4 100644 --- a/src/Exceptions/EcsFrameworkException.cs +++ b/src/Exceptions/EcsFrameworkException.cs @@ -1,5 +1,4 @@ using System; -using System.Runtime.Serialization; namespace DCFApixels.DragonECS { @@ -9,6 +8,8 @@ namespace DCFApixels.DragonECS public EcsFrameworkException() { } public EcsFrameworkException(string message) : base(EcsConsts.EXCEPTION_MESSAGE_PREFIX + message) { } public EcsFrameworkException(string message, Exception inner) : base(EcsConsts.EXCEPTION_MESSAGE_PREFIX + message, inner) { } - protected EcsFrameworkException(SerializationInfo info, StreamingContext context) : base(info, context) { } + protected EcsFrameworkException( + System.Runtime.Serialization.SerializationInfo info, + System.Runtime.Serialization.StreamingContext context) : base(info, context) { } } } diff --git a/src/Exceptions/EcsRunnerImplementationException.cs b/src/Exceptions/EcsRunnerImplementationException.cs new file mode 100644 index 0000000..a4e64d0 --- /dev/null +++ b/src/Exceptions/EcsRunnerImplementationException.cs @@ -0,0 +1,15 @@ +using System; + +namespace DCFApixels.DragonECS +{ + [Serializable] + public class EcsRunnerImplementationException : Exception + { + public EcsRunnerImplementationException() { } + public EcsRunnerImplementationException(string message) : base(EcsConsts.EXCEPTION_MESSAGE_PREFIX + message) { } + public EcsRunnerImplementationException(string message, Exception inner) : base(EcsConsts.EXCEPTION_MESSAGE_PREFIX + message, inner) { } + protected EcsRunnerImplementationException( + System.Runtime.Serialization.SerializationInfo info, + System.Runtime.Serialization.StreamingContext context) : base(info, context) { } + } +} diff --git a/src/Exceptions/EcsRunnerImplementationException.cs.meta b/src/Exceptions/EcsRunnerImplementationException.cs.meta new file mode 100644 index 0000000..09150d7 --- /dev/null +++ b/src/Exceptions/EcsRunnerImplementationException.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c4bda71728347ce4fa0dca0555eb8c4c +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/src/Entity.cs b/src/ent.cs similarity index 100% rename from src/Entity.cs rename to src/ent.cs diff --git a/src/Entity.cs.meta b/src/ent.cs.meta similarity index 100% rename from src/Entity.cs.meta rename to src/ent.cs.meta