diff --git a/src/Debug/EcsDebugUtility.cs b/src/Debug/EcsDebugUtility.cs index 803c9b6..937a838 100644 --- a/src/Debug/EcsDebugUtility.cs +++ b/src/Debug/EcsDebugUtility.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Reflection; +using System.Runtime.CompilerServices; namespace DCFApixels.DragonECS { @@ -57,8 +58,24 @@ namespace DCFApixels.DragonECS #endregion #region GetName + public static string GetNameForObject(IEcsDebugName obj) => obj.DebugName; + public static string GetNameForObject(object obj) => obj is IEcsDebugName dn ? dn.DebugName : GetName(obj.GetType()); public static string GetName() => GetName(typeof(T)); public static string GetName(Type type) => type.TryGetCustomAttribute(out DebugNameAttribute atr) ? atr.name : GetGenericTypeName(type); + public static bool TryGetCustomNameForObject(IEcsDebugName obj, out string name) + { + name = obj.DebugName; + return true; + } + public static bool TryGetCustomNameForObject(object obj, out string name) + { + if (obj is IEcsDebugName dn) + { + name = dn.DebugName; + return true; + } + return TryGetCustomName(obj.GetType(), out name); + } public static bool TryGetCustomName(out string name) => TryGetCustomName(typeof(T), out name); public static bool TryGetCustomName(Type type, out string name) { @@ -230,11 +247,13 @@ namespace DCFApixels.DragonECS #endregion #region ReflectionExtensions + [MethodImpl(MethodImplOptions.AggressiveInlining)] internal static bool TryGetCustomAttribute(this Type self, out T attribute) where T : Attribute { attribute = self.GetCustomAttribute(); return attribute != null; } + [MethodImpl(MethodImplOptions.AggressiveInlining)] internal static bool TryGetCustomAttribute(this MemberInfo self, out T attribute) where T : Attribute { attribute = self.GetCustomAttribute(); diff --git a/src/Debug/Interfaces.meta b/src/Debug/Interfaces.meta new file mode 100644 index 0000000..50388c5 --- /dev/null +++ b/src/Debug/Interfaces.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 50bc53c3762bf6b4ea127004a89a894e +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/src/Debug/Interfaces/IEcsDebugName.cs b/src/Debug/Interfaces/IEcsDebugName.cs new file mode 100644 index 0000000..90431f4 --- /dev/null +++ b/src/Debug/Interfaces/IEcsDebugName.cs @@ -0,0 +1,7 @@ +namespace DCFApixels.DragonECS +{ + public interface IEcsDebugName + { + string DebugName { get; } + } +} diff --git a/src/Debug/Interfaces/IEcsDebugName.cs.meta b/src/Debug/Interfaces/IEcsDebugName.cs.meta new file mode 100644 index 0000000..cdf6285 --- /dev/null +++ b/src/Debug/Interfaces/IEcsDebugName.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 170270e2ac54ab54a9dab57f58e25a9c +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/src/EcsPipeline.cs b/src/EcsPipeline.cs index 6c39ded..7d7bb35 100644 --- a/src/EcsPipeline.cs +++ b/src/EcsPipeline.cs @@ -75,6 +75,7 @@ namespace DCFApixels.DragonECS _runRunnerCache = GetRunner(); _isInit = true; + GC.Collect(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/src/EcsRunner.cs b/src/EcsRunner.cs index 7e30725..be990fd 100644 --- a/src/EcsRunner.cs +++ b/src/EcsRunner.cs @@ -71,6 +71,7 @@ namespace DCFApixels.DragonECS Type interfaceType = item.BaseType.GenericTypeArguments[0]; _runnerHandlerTypes.Add(interfaceType.IsGenericType ? interfaceType.GetGenericTypeDefinition() : interfaceType, item); } + if (delayedExceptions.Count > 0) { throw new AggregateException(delayedExceptions); diff --git a/src/EcsWorld.cs b/src/EcsWorld.cs index c2bc05d..9bb781e 100644 --- a/src/EcsWorld.cs +++ b/src/EcsWorld.cs @@ -181,7 +181,7 @@ namespace DCFApixels.DragonECS [MethodImpl(MethodImplOptions.AggressiveInlining)] public unsafe entlong GetEntityLong(int entityID) { - long x = ((long)id << 48 | (long)_gens[entityID] << 32 | entityID); + long x = (long)id << 48 | (long)_gens[entityID] << 32 | (long)entityID; return *(entlong*)&x; } [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/src/Pools/EcsHybridPool.cs b/src/Pools/EcsHybridPool.cs index 8a68145..df47d53 100644 --- a/src/Pools/EcsHybridPool.cs +++ b/src/Pools/EcsHybridPool.cs @@ -1,3 +1,4 @@ +using DCFApixels.DragonECS.Utils; using System; using System.Collections; using System.Collections.Generic; @@ -5,7 +6,7 @@ using System.Runtime.CompilerServices; namespace DCFApixels.DragonECS { - /// Pool for IEcsComponent components + /// Pool for IEcsHybridComponent components public sealed class EcsHybridPool : IEcsPoolImplementation, IEcsHybridPool, IEnumerable //IEnumerable - IntelliSense hack where T : IEcsHybridComponent { @@ -217,6 +218,11 @@ namespace DCFApixels.DragonECS void OnAddToPool(entlong entity); void OnDelFromPool(entlong entity); } + public static class IEcsHybridComponentExtensions + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static bool IsNullOrNotAlive(this IEcsHybridComponent self) => self == null || self.IsAlive; + } public static class EcsHybridPoolExt { [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/src/Utils/SparseArray.cs b/src/Utils/SparseArray.cs index 9d83ae1..23fed2d 100644 --- a/src/Utils/SparseArray.cs +++ b/src/Utils/SparseArray.cs @@ -27,8 +27,8 @@ namespace DCFApixels.DragonECS.Utils #region Properties public TValue this[int keyX, int keyY] { - get => _entries[FindEntry((keyX << 32) | keyY)].value; - set => Insert(keyX + (keyY << 32), value); + get => _entries[FindEntry((keyX << 16) | keyY)].value; + set => Insert(keyX + (keyY << 16), value); } public TValue this[int key] { @@ -52,7 +52,7 @@ namespace DCFApixels.DragonECS.Utils #region Add/Contains/Remove [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void Add(int keyX, int keyY, TValue value) => Add((keyX << 32) | keyY, value); + public void Add(int keyX, int keyY, TValue value) => Add((keyX << 16) | keyY, value); [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Add(int key, TValue value) { @@ -63,11 +63,11 @@ namespace DCFApixels.DragonECS.Utils Insert(key, value); } - public bool Contains(int keyX, int keyY) => FindEntry((keyX << 32) | keyY) >= 0; + public bool Contains(int keyX, int keyY) => FindEntry((keyX << 16) | keyY) >= 0; public bool Contains(int key) => FindEntry(key) >= 0; [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Remove(int keyX, int keyY) => Remove((keyX << 32) | keyY); + public bool Remove(int keyX, int keyY) => Remove((keyX << 16) | keyY); public bool Remove(int key) { int bucket = key & _modBitMask; @@ -144,7 +144,7 @@ namespace DCFApixels.DragonECS.Utils #region TryGetValue public bool TryGetValue(int keyX, int keyY, out TValue value) { - int index = FindEntry((keyX << 32) | keyY); + int index = FindEntry((keyX << 16) | keyY); if (index < 0) { value = default;