mirror of
https://github.com/DCFApixels/DragonECS.git
synced 2025-09-18 18:14:37 +08:00
simple refactoring/fixes
This commit is contained in:
parent
ab45c22d85
commit
0637aec1dc
@ -45,19 +45,19 @@ namespace DCFApixels.DragonECS
|
|||||||
#if DEBUG && !DISABLE_DEBUG
|
#if DEBUG && !DISABLE_DEBUG
|
||||||
for (int i = 0; i < targets.Length && targets.Length <= _markers.Length; i++)
|
for (int i = 0; i < targets.Length && targets.Length <= _markers.Length; i++)
|
||||||
{
|
{
|
||||||
|
_markers[i].Begin();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
_markers[i].Begin();
|
|
||||||
targets[i].PreInit(pipeline);
|
targets[i].PreInit(pipeline);
|
||||||
_markers[i].End();
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
#if DISABLE_CATH_EXCEPTIONS
|
#if DISABLE_CATH_EXCEPTIONS
|
||||||
throw;
|
throw e;
|
||||||
#endif
|
#endif
|
||||||
EcsDebug.PrintError(e);
|
EcsDebug.PrintError(e);
|
||||||
}
|
}
|
||||||
|
_markers[i].End();
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
foreach (var item in targets)
|
foreach (var item in targets)
|
||||||
@ -66,7 +66,7 @@ namespace DCFApixels.DragonECS
|
|||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
#if DISABLE_CATH_EXCEPTIONS
|
#if DISABLE_CATH_EXCEPTIONS
|
||||||
throw;
|
throw e;
|
||||||
#endif
|
#endif
|
||||||
EcsDebug.PrintError(e);
|
EcsDebug.PrintError(e);
|
||||||
}
|
}
|
||||||
@ -93,19 +93,19 @@ namespace DCFApixels.DragonECS
|
|||||||
#if DEBUG && !DISABLE_DEBUG
|
#if DEBUG && !DISABLE_DEBUG
|
||||||
for (int i = 0; i < targets.Length && targets.Length <= _markers.Length; i++)
|
for (int i = 0; i < targets.Length && targets.Length <= _markers.Length; i++)
|
||||||
{
|
{
|
||||||
|
_markers[i].Begin();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
_markers[i].Begin();
|
|
||||||
targets[i].Init(pipeline);
|
targets[i].Init(pipeline);
|
||||||
_markers[i].End();
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
#if DISABLE_CATH_EXCEPTIONS
|
#if DISABLE_CATH_EXCEPTIONS
|
||||||
throw;
|
throw e;
|
||||||
#endif
|
#endif
|
||||||
EcsDebug.PrintError(e);
|
EcsDebug.PrintError(e);
|
||||||
}
|
}
|
||||||
|
_markers[i].End();
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
foreach (var item in targets)
|
foreach (var item in targets)
|
||||||
@ -114,7 +114,7 @@ namespace DCFApixels.DragonECS
|
|||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
#if DISABLE_CATH_EXCEPTIONS
|
#if DISABLE_CATH_EXCEPTIONS
|
||||||
throw;
|
throw e;
|
||||||
#endif
|
#endif
|
||||||
EcsDebug.PrintError(e);
|
EcsDebug.PrintError(e);
|
||||||
}
|
}
|
||||||
@ -141,19 +141,19 @@ namespace DCFApixels.DragonECS
|
|||||||
#if DEBUG && !DISABLE_DEBUG
|
#if DEBUG && !DISABLE_DEBUG
|
||||||
for (int i = 0; i < targets.Length && targets.Length <= _markers.Length; i++)
|
for (int i = 0; i < targets.Length && targets.Length <= _markers.Length; i++)
|
||||||
{
|
{
|
||||||
|
_markers[i].Begin();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
_markers[i].Begin();
|
|
||||||
targets[i].Run(pipeline);
|
targets[i].Run(pipeline);
|
||||||
_markers[i].End();
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
#if DISABLE_CATH_EXCEPTIONS
|
#if DISABLE_CATH_EXCEPTIONS
|
||||||
throw;
|
throw e;
|
||||||
#endif
|
#endif
|
||||||
EcsDebug.PrintError(e);
|
EcsDebug.PrintError(e);
|
||||||
}
|
}
|
||||||
|
_markers[i].End();
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
foreach (var item in targets)
|
foreach (var item in targets)
|
||||||
@ -162,7 +162,7 @@ namespace DCFApixels.DragonECS
|
|||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
#if DISABLE_CATH_EXCEPTIONS
|
#if DISABLE_CATH_EXCEPTIONS
|
||||||
throw;
|
throw e;
|
||||||
#endif
|
#endif
|
||||||
EcsDebug.PrintError(e);
|
EcsDebug.PrintError(e);
|
||||||
}
|
}
|
||||||
@ -189,19 +189,19 @@ namespace DCFApixels.DragonECS
|
|||||||
#if DEBUG && !DISABLE_DEBUG
|
#if DEBUG && !DISABLE_DEBUG
|
||||||
for (int i = 0; i < targets.Length && targets.Length <= _markers.Length; i++)
|
for (int i = 0; i < targets.Length && targets.Length <= _markers.Length; i++)
|
||||||
{
|
{
|
||||||
|
_markers[i].Begin();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
_markers[i].Begin();
|
|
||||||
targets[i].Destroy(pipeline);
|
targets[i].Destroy(pipeline);
|
||||||
_markers[i].End();
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
#if DISABLE_CATH_EXCEPTIONS
|
#if DISABLE_CATH_EXCEPTIONS
|
||||||
throw;
|
throw e;
|
||||||
#endif
|
#endif
|
||||||
EcsDebug.PrintError(e);
|
EcsDebug.PrintError(e);
|
||||||
}
|
}
|
||||||
|
_markers[i].End();
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
foreach (var item in targets)
|
foreach (var item in targets)
|
||||||
@ -210,7 +210,7 @@ namespace DCFApixels.DragonECS
|
|||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
#if DISABLE_CATH_EXCEPTIONS
|
#if DISABLE_CATH_EXCEPTIONS
|
||||||
throw;
|
throw e;
|
||||||
#endif
|
#endif
|
||||||
EcsDebug.PrintError(e);
|
EcsDebug.PrintError(e);
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
using System.Text.RegularExpressions;
|
|
||||||
|
|
||||||
namespace DCFApixels.DragonECS
|
namespace DCFApixels.DragonECS
|
||||||
{
|
{
|
||||||
|
@ -70,7 +70,8 @@ namespace DCFApixels.DragonECS
|
|||||||
}
|
}
|
||||||
private TPool CreatePool<TPool>() where TPool : IEcsPoolImplementation, new()
|
private TPool CreatePool<TPool>() where TPool : IEcsPoolImplementation, new()
|
||||||
{
|
{
|
||||||
if (_poolIds.Contains(EcsTypeCode.Get<TPool>()))
|
int poolTypeCode = EcsTypeCode.Get<TPool>();
|
||||||
|
if (_poolIds.Contains(poolTypeCode))
|
||||||
throw new EcsFrameworkException("The pool has already been created.");
|
throw new EcsFrameworkException("The pool has already been created.");
|
||||||
|
|
||||||
Type componentType = typeof(TPool).GetInterfaces().First(o => o.IsGenericType && o.GetGenericTypeDefinition() == typeof(IEcsPoolImplementation<>)).GetGenericArguments()[0];
|
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))
|
if (_componentIds.TryGetValue(componentTypeCode, out int componentID))
|
||||||
{
|
{
|
||||||
_poolIds[componentTypeCode] = componentID;
|
_poolIds[poolTypeCode] = componentID;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
componentID = _poolsCount++;
|
componentID = _poolsCount++;
|
||||||
_poolIds[componentTypeCode] = componentID;
|
_poolIds[poolTypeCode] = componentID;
|
||||||
_componentIds[componentTypeCode] = componentID;
|
_componentIds[componentTypeCode] = componentID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Reflection;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
|
|
||||||
namespace DCFApixels.DragonECS
|
namespace DCFApixels.DragonECS
|
||||||
@ -18,6 +19,18 @@ namespace DCFApixels.DragonECS
|
|||||||
|
|
||||||
private T _fakeComponent;
|
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
|
#region Properites
|
||||||
public int Count => _count;
|
public int Count => _count;
|
||||||
int IEcsPool.Capacity => -1;
|
int IEcsPool.Capacity => -1;
|
||||||
|
@ -137,22 +137,6 @@ namespace DCFApixels.DragonECS
|
|||||||
}
|
}
|
||||||
#endregion
|
#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
|
#region operators
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static bool operator ==(entlong a, entlong b) => a.full == b.full;
|
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;
|
public static explicit operator int(entlong a) => a.ID;
|
||||||
#endregion
|
#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
|
internal class DebuggerProxy
|
||||||
{
|
{
|
||||||
private List<object> _componentsList;
|
private List<object> _componentsList;
|
||||||
|
Loading…
Reference in New Issue
Block a user