diff --git a/src/Builtin/BaseProcesses.cs b/src/Builtin/BaseProcesses.cs index d172d1b..8f226f1 100644 --- a/src/Builtin/BaseProcesses.cs +++ b/src/Builtin/BaseProcesses.cs @@ -45,19 +45,19 @@ namespace DCFApixels.DragonECS #if DEBUG && !DISABLE_DEBUG for (int i = 0; i < targets.Length && targets.Length <= _markers.Length; i++) { + _markers[i].Begin(); try { - _markers[i].Begin(); targets[i].PreInit(pipeline); - _markers[i].End(); } catch (Exception e) { #if DISABLE_CATH_EXCEPTIONS - throw; + throw e; #endif EcsDebug.PrintError(e); } + _markers[i].End(); } #else foreach (var item in targets) @@ -66,7 +66,7 @@ namespace DCFApixels.DragonECS catch (Exception e) { #if DISABLE_CATH_EXCEPTIONS - throw; + throw e; #endif EcsDebug.PrintError(e); } @@ -93,19 +93,19 @@ namespace DCFApixels.DragonECS #if DEBUG && !DISABLE_DEBUG for (int i = 0; i < targets.Length && targets.Length <= _markers.Length; i++) { + _markers[i].Begin(); try { - _markers[i].Begin(); targets[i].Init(pipeline); - _markers[i].End(); } catch (Exception e) { #if DISABLE_CATH_EXCEPTIONS - throw; + throw e; #endif EcsDebug.PrintError(e); } + _markers[i].End(); } #else foreach (var item in targets) @@ -114,7 +114,7 @@ namespace DCFApixels.DragonECS catch (Exception e) { #if DISABLE_CATH_EXCEPTIONS - throw; + throw e; #endif EcsDebug.PrintError(e); } @@ -141,19 +141,19 @@ namespace DCFApixels.DragonECS #if DEBUG && !DISABLE_DEBUG for (int i = 0; i < targets.Length && targets.Length <= _markers.Length; i++) { + _markers[i].Begin(); try { - _markers[i].Begin(); targets[i].Run(pipeline); - _markers[i].End(); } catch (Exception e) { #if DISABLE_CATH_EXCEPTIONS - throw; + throw e; #endif EcsDebug.PrintError(e); } + _markers[i].End(); } #else foreach (var item in targets) @@ -162,7 +162,7 @@ namespace DCFApixels.DragonECS catch (Exception e) { #if DISABLE_CATH_EXCEPTIONS - throw; + throw e; #endif EcsDebug.PrintError(e); } @@ -189,19 +189,19 @@ namespace DCFApixels.DragonECS #if DEBUG && !DISABLE_DEBUG for (int i = 0; i < targets.Length && targets.Length <= _markers.Length; i++) { + _markers[i].Begin(); try { - _markers[i].Begin(); targets[i].Destroy(pipeline); - _markers[i].End(); } catch (Exception e) { #if DISABLE_CATH_EXCEPTIONS - throw; + throw e; #endif EcsDebug.PrintError(e); } + _markers[i].End(); } #else foreach (var item in targets) @@ -210,7 +210,7 @@ namespace DCFApixels.DragonECS catch (Exception e) { #if DISABLE_CATH_EXCEPTIONS - throw; + throw e; #endif EcsDebug.PrintError(e); } diff --git a/src/Debug/EcsDebugUtility.cs b/src/Debug/EcsDebugUtility.cs index 83a8541..0b2a083 100644 --- a/src/Debug/EcsDebugUtility.cs +++ b/src/Debug/EcsDebugUtility.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.Reflection; using System.Runtime.CompilerServices; -using System.Text.RegularExpressions; namespace DCFApixels.DragonECS { diff --git a/src/EcsWorld.pools.cs b/src/EcsWorld.pools.cs index c047cd2..b9d02f0 100644 --- a/src/EcsWorld.pools.cs +++ b/src/EcsWorld.pools.cs @@ -70,7 +70,8 @@ namespace DCFApixels.DragonECS } private TPool CreatePool() where TPool : IEcsPoolImplementation, new() { - if (_poolIds.Contains(EcsTypeCode.Get())) + int poolTypeCode = EcsTypeCode.Get(); + if (_poolIds.Contains(poolTypeCode)) throw new EcsFrameworkException("The pool has already been created."); Type componentType = typeof(TPool).GetInterfaces().First(o => o.IsGenericType && o.GetGenericTypeDefinition() == typeof(IEcsPoolImplementation<>)).GetGenericArguments()[0]; @@ -78,12 +79,12 @@ namespace DCFApixels.DragonECS if (_componentIds.TryGetValue(componentTypeCode, out int componentID)) { - _poolIds[componentTypeCode] = componentID; + _poolIds[poolTypeCode] = componentID; } else { componentID = _poolsCount++; - _poolIds[componentTypeCode] = componentID; + _poolIds[poolTypeCode] = componentID; _componentIds[componentTypeCode] = componentID; } diff --git a/src/Pools/EcsTagPool.cs b/src/Pools/EcsTagPool.cs index 496af44..2256c93 100644 --- a/src/Pools/EcsTagPool.cs +++ b/src/Pools/EcsTagPool.cs @@ -1,6 +1,7 @@ using System; using System.Collections; using System.Collections.Generic; +using System.Reflection; using System.Runtime.CompilerServices; namespace DCFApixels.DragonECS @@ -18,6 +19,18 @@ namespace DCFApixels.DragonECS private T _fakeComponent; + + private static bool _isInvalidType; + static EcsTagPool() + { + _isInvalidType = typeof(T).GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).Length > 0; + } + public EcsTagPool() + { + if (_isInvalidType) + throw new EcsFrameworkException($"{typeof(T).Name} type must not contain any data."); + } + #region Properites public int Count => _count; int IEcsPool.Capacity => -1; diff --git a/src/entlong.cs b/src/entlong.cs index dc1d730..ab56ba7 100644 --- a/src/entlong.cs +++ b/src/entlong.cs @@ -137,22 +137,6 @@ namespace DCFApixels.DragonECS } #endregion - #region Equals - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Equals(entlong other) => full == other.full; - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Equals(long other) => full == other; - #endregion - - #region Object - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public override int GetHashCode() => unchecked((int)full) ^ (int)(full >> 32); - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public override string ToString() => $"entity(id:{id} g:{gen} w:{world} {(IsNull ? "null" : IsAlive ? "alive" : "not alive")})"; - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public override bool Equals(object obj) => obj is entlong other && full == other.full; - #endregion - #region operators [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator ==(entlong a, entlong b) => a.full == b.full; @@ -169,7 +153,18 @@ namespace DCFApixels.DragonECS public static explicit operator int(entlong a) => a.ID; #endregion - #region DebuggerProxy + #region Other + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public override int GetHashCode() => unchecked((int)full) ^ (int)(full >> 32); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public override string ToString() => $"entity(id:{id} g:{gen} w:{world} {(IsNull ? "null" : IsAlive ? "alive" : "not alive")})"; + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public override bool Equals(object obj) => obj is entlong other && full == other.full; + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public bool Equals(entlong other) => full == other.full; + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public bool Equals(long other) => full == other; + internal class DebuggerProxy { private List _componentsList;