diff --git a/src/EcsStaticMask.cs b/src/EcsStaticMask.cs index 1bebb15..cb07dff 100644 --- a/src/EcsStaticMask.cs +++ b/src/EcsStaticMask.cs @@ -452,7 +452,7 @@ namespace DCFApixels.DragonECS private static string CreateLogString(EcsTypeCode[] inc, EcsTypeCode[] exc) { #if (DEBUG && !DISABLE_DEBUG) - string converter(EcsTypeCode o) { return EcsDebugUtility.GetGenericTypeName(EcsTypeCodeManager.FindTypeOfCode(o), 1); } + string converter(EcsTypeCode o) { return EcsTypeCodeManager.FindTypeOfCode(o).ToString(); } return $"Inc({string.Join(", ", inc.Select(converter))}) Exc({string.Join(", ", exc.Select(converter))})"; #else return $"Inc({string.Join(", ", inc)}) Exc({string.Join(", ", exc)})"; // Release optimization @@ -478,7 +478,7 @@ namespace DCFApixels.DragonECS ID = mask.ID; included = mask._incs; excluded = mask._excs; - Type converter(EcsTypeCode o) { return EcsTypeCodeManager.FindTypeOfCode(o); } + Type converter(EcsTypeCode o) { return EcsTypeCodeManager.FindTypeOfCode(o).Type; } includedTypes = included.Select(converter).ToArray(); excludedTypes = excluded.Select(converter).ToArray(); } diff --git a/src/EcsWorld.cs b/src/EcsWorld.cs index cb6a377..b03a848 100644 --- a/src/EcsWorld.cs +++ b/src/EcsWorld.cs @@ -73,34 +73,6 @@ namespace DCFApixels.DragonECS private List _listeners = new List(); private List _entityListeners = new List(); - - private static Stack _configInitOnlynStack = new Stack(4); - protected internal static EcsWorldConfig Config_InitOnly - { - get - { - if (_configInitOnlynStack.TryPeek(out EcsWorldConfig result)) - { - return result; - } - Throw.UndefinedException(); - return null; - } - } - private readonly ref struct ConfigInitOnlyScope - { - private readonly Stack _stack; - public ConfigInitOnlyScope(Stack stack, EcsWorldConfig config) - { - _stack = stack; - _stack.Push(config); - } - public void Dispose() - { - _stack.Peek(); - } - } - #region Properties EcsWorld IEntityStorage.World { @@ -171,8 +143,6 @@ namespace DCFApixels.DragonECS lock (_worldLock) { if (configs == null) { configs = ConfigContainer.Empty; } - _configInitOnlynStack.Push(configs.GetWorldConfigOrDefault()); - bool nullWorld = this is NullWorld; if (nullWorld == false && worldID == NULL_WORLD_ID) { @@ -194,7 +164,6 @@ namespace DCFApixels.DragonECS if (_worlds[worldID] != null) { _worldIdDispenser.Release(worldID); - _configInitOnlynStack.Pop(); Throw.Exception("The world with the specified ID has already been created\r\n"); } } @@ -211,9 +180,9 @@ namespace DCFApixels.DragonECS int entitiesCapacity = ArrayUtility.NormalizeSizeToPowerOfTwo(config.EntitiesCapacity); _entityDispenser = new IdDispenser(entitiesCapacity, 0, OnEntityDispenserResized); - GetComponentTypeID(); + _executorCoures = new Dictionary<(Type, object), IQueryExecutorImplementation>(config.PoolComponentsCapacity); - _configInitOnlynStack.Pop(); + GetComponentTypeID(); } } public void Destroy() diff --git a/src/Executors/MaskQueryExecutor.cs b/src/Executors/MaskQueryExecutor.cs index 7c7998d..ffa58e0 100644 --- a/src/Executors/MaskQueryExecutor.cs +++ b/src/Executors/MaskQueryExecutor.cs @@ -8,7 +8,7 @@ namespace DCFApixels.DragonECS { public partial class EcsWorld { - private readonly Dictionary<(Type, object), IQueryExecutorImplementation> _executorCoures = new Dictionary<(Type, object), IQueryExecutorImplementation>(Config_InitOnly.PoolComponentsCapacity); + private readonly Dictionary<(Type, object), IQueryExecutorImplementation> _executorCoures; public TExecutor GetExecutorForMask(IComponentMask gmask) where TExecutor : MaskQueryExecutor, new() { diff --git a/src/Internal/EcsTypeCodeManager.cs b/src/Internal/EcsTypeCodeManager.cs index 799f5f7..4a7cfec 100644 --- a/src/Internal/EcsTypeCodeManager.cs +++ b/src/Internal/EcsTypeCodeManager.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; using System.Runtime.CompilerServices; #if ENABLE_IL2CPP @@ -8,6 +9,46 @@ using Unity.IL2CPP.CompilerServices; namespace DCFApixels.DragonECS.Internal { +#if ENABLE_IL2CPP + [Il2CppSetOption(Option.NullChecks, false)] + [Il2CppSetOption(Option.ArrayBoundsChecks, false)] +#endif + [DebuggerDisplay("{" + nameof(GetDebuggerDisplay) + "(),nq}")] + internal readonly struct EcsTypeCodeKey : IEquatable + { + public readonly Type Type; + public readonly string NameKey; + public EcsTypeCodeKey(Type type, string nameKey) + { + Type = type; + NameKey = nameKey; + } + public bool Equals(EcsTypeCodeKey other) + { + return Type == other.Type && NameKey == other.NameKey; + } + public override bool Equals(object obj) + { + return obj is EcsTypeCodeKey other && Equals(other); + } + public override int GetHashCode() + { + return HashCode.Combine(Type, NameKey); + } + public override string ToString() + { + if (string.IsNullOrEmpty(NameKey)) + { + return Type.ToString(); + } + return $"{Type} {NameKey}"; + } + public static implicit operator EcsTypeCodeKey(Type type) { return new EcsTypeCodeKey(type, string.Empty); } + private string GetDebuggerDisplay() + { + return ToString(); + } + } //TODO разработать возможность ручного устанавливания ID типам. //это может быть полезно как детерминированность для сети #if ENABLE_IL2CPP @@ -16,7 +57,7 @@ namespace DCFApixels.DragonECS.Internal #endif internal static class EcsTypeCodeManager { - private static readonly Dictionary _codes = new Dictionary(); + private static readonly Dictionary _codes = new Dictionary(); private static int _increment = 1; private static object _lock = new object(); public static int Count @@ -40,7 +81,7 @@ namespace DCFApixels.DragonECS.Internal public static EcsTypeCode Get() { return EcsTypeCodeCache.code; } public static bool Has(Type type) { return _codes.ContainsKey(type); } public static bool Has() { return _codes.ContainsKey(typeof(T)); } - public static Type FindTypeOfCode(EcsTypeCode typeCode) + public static EcsTypeCodeKey FindTypeOfCode(EcsTypeCode typeCode) { foreach (var item in _codes) { @@ -67,9 +108,9 @@ namespace DCFApixels.DragonECS.Internal #endif internal struct TypeCodeInfo { - public Type type; + public EcsTypeCodeKey type; public EcsTypeCode code; - public TypeCodeInfo(Type type, EcsTypeCode code) + public TypeCodeInfo(EcsTypeCodeKey type, EcsTypeCode code) { this.type = type; this.code = code;