mirror of
https://github.com/DCFApixels/DragonECS.git
synced 2025-09-19 02:24:37 +08:00
simple refactoring
This commit is contained in:
parent
4b0d188955
commit
e7c623daf8
@ -71,8 +71,8 @@ namespace DCFApixels.DragonECS
|
|||||||
public static string GetName(Type type, int maxGenericDepth = 2) => type.TryGetCustomAttribute(out MetaNameAttribute atr) ? atr.name : GetGenericTypeName(type, maxGenericDepth);
|
public static string GetName(Type type, int maxGenericDepth = 2) => type.TryGetCustomAttribute(out MetaNameAttribute atr) ? atr.name : GetGenericTypeName(type, maxGenericDepth);
|
||||||
public static bool TryGetCustomName(object obj, out string name)
|
public static bool TryGetCustomName(object obj, out string name)
|
||||||
{
|
{
|
||||||
return obj is IEcsDebugMetaProvider intr ?
|
return obj is IEcsDebugMetaProvider intr ?
|
||||||
TryGetCustomName(intr.DebugMetaSource, out name) :
|
TryGetCustomName(intr.DebugMetaSource, out name) :
|
||||||
TryGetCustomName(type: obj.GetType(), out name);
|
TryGetCustomName(type: obj.GetType(), out name);
|
||||||
}
|
}
|
||||||
public static bool TryGetCustomName<T>(out string name) => TryGetCustomName(type: typeof(T), out name);
|
public static bool TryGetCustomName<T>(out string name) => TryGetCustomName(type: typeof(T), out name);
|
||||||
|
@ -143,7 +143,7 @@ namespace DCFApixels.DragonECS
|
|||||||
foreach (var id in maskInc)
|
foreach (var id in maskInc)
|
||||||
{
|
{
|
||||||
var bit = EcsMaskBit.FromID(id);
|
var bit = EcsMaskBit.FromID(id);
|
||||||
if(!r.TryAdd(bit.chankIndex, bit.mask))
|
if (!r.TryAdd(bit.chankIndex, bit.mask))
|
||||||
r[bit.chankIndex] = r[bit.chankIndex] | bit.mask;
|
r[bit.chankIndex] = r[bit.chankIndex] | bit.mask;
|
||||||
}
|
}
|
||||||
EcsMaskBit[] incMasks = r.Select(o => new EcsMaskBit(o.Key, o.Value)).ToArray();
|
EcsMaskBit[] incMasks = r.Select(o => new EcsMaskBit(o.Key, o.Value)).ToArray();
|
||||||
@ -155,7 +155,7 @@ namespace DCFApixels.DragonECS
|
|||||||
r[bit.chankIndex] = r[bit.chankIndex] | bit.mask;
|
r[bit.chankIndex] = r[bit.chankIndex] | bit.mask;
|
||||||
}
|
}
|
||||||
EcsMaskBit[] excMasks = r.Select(o => new EcsMaskBit(o.Key, o.Value)).ToArray();
|
EcsMaskBit[] excMasks = r.Select(o => new EcsMaskBit(o.Key, o.Value)).ToArray();
|
||||||
|
|
||||||
var inc = maskInc.ToArray();
|
var inc = maskInc.ToArray();
|
||||||
Array.Sort(inc);
|
Array.Sort(inc);
|
||||||
var exc = maskExc.ToArray();
|
var exc = maskExc.ToArray();
|
||||||
|
@ -162,7 +162,7 @@ namespace DCFApixels.DragonECS
|
|||||||
|
|
||||||
private static TInterface Instantiate(EcsPipeline source, TInterface[] targets, bool isHasFilter, object filter)
|
private static TInterface Instantiate(EcsPipeline source, TInterface[] targets, bool isHasFilter, object filter)
|
||||||
{
|
{
|
||||||
if(_subclass == null)
|
if (_subclass == null)
|
||||||
{
|
{
|
||||||
Type interfaceType = typeof(TInterface);
|
Type interfaceType = typeof(TInterface);
|
||||||
if (interfaceType.TryGetCustomAttribute(out BindWithEcsRunnerAttribute atr))
|
if (interfaceType.TryGetCustomAttribute(out BindWithEcsRunnerAttribute atr))
|
||||||
@ -181,7 +181,7 @@ namespace DCFApixels.DragonECS
|
|||||||
throw new EcsFrameworkException("Процесс не связан с раннером, используйте атрибуут BindWithEcsRunner(Type runnerType)");
|
throw new EcsFrameworkException("Процесс не связан с раннером, используйте атрибуут BindWithEcsRunner(Type runnerType)");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var instance = (EcsRunner<TInterface>)Activator.CreateInstance(_subclass);
|
var instance = (EcsRunner<TInterface>)Activator.CreateInstance(_subclass);
|
||||||
return (TInterface)(IEcsProcess)instance.Set(source, targets, isHasFilter, filter);
|
return (TInterface)(IEcsProcess)instance.Set(source, targets, isHasFilter, filter);
|
||||||
}
|
}
|
||||||
@ -194,7 +194,7 @@ namespace DCFApixels.DragonECS
|
|||||||
return Instantiate(source, FilterSystems(source.AllSystems, filter), true, filter);
|
return Instantiate(source, FilterSystems(source.AllSystems, filter), true, filter);
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
private EcsPipeline _source;
|
private EcsPipeline _source;
|
||||||
protected TInterface[] targets;
|
protected TInterface[] targets;
|
||||||
private ReadOnlyCollection<TInterface> _targetsSealed;
|
private ReadOnlyCollection<TInterface> _targetsSealed;
|
||||||
@ -333,7 +333,7 @@ namespace DCFApixels.DragonECS
|
|||||||
|
|
||||||
public static IEnumerable<Type> GetEcsProcessInterfaces(this Type self)
|
public static IEnumerable<Type> GetEcsProcessInterfaces(this Type self)
|
||||||
{
|
{
|
||||||
return self.GetInterfaces().Where(o=> o.IsEcsProcessInterface());
|
return self.GetInterfaces().Where(o => o.IsEcsProcessInterface());
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
@ -1,7 +1,4 @@
|
|||||||
using DCFApixels.DragonECS.Utils;
|
namespace DCFApixels.DragonECS
|
||||||
using System;
|
|
||||||
|
|
||||||
namespace DCFApixels.DragonECS
|
|
||||||
{
|
{
|
||||||
public abstract partial class EcsWorld
|
public abstract partial class EcsWorld
|
||||||
{
|
{
|
||||||
|
@ -146,7 +146,7 @@ namespace DCFApixels.DragonECS
|
|||||||
#region Entity
|
#region Entity
|
||||||
public int NewEntity()
|
public int NewEntity()
|
||||||
{
|
{
|
||||||
if(_freeSpace <= 1 && _delEntBufferCount > _delEntBufferMinCount)
|
if (_freeSpace <= 1 && _delEntBufferCount > _delEntBufferMinCount)
|
||||||
ReleaseDelEntityBuffer();
|
ReleaseDelEntityBuffer();
|
||||||
|
|
||||||
int entityID = _entityDispenser.GetFree();
|
int entityID = _entityDispenser.GetFree();
|
||||||
@ -236,7 +236,7 @@ namespace DCFApixels.DragonECS
|
|||||||
{
|
{
|
||||||
foreach (var pool in _pools)
|
foreach (var pool in _pools)
|
||||||
{
|
{
|
||||||
if (pool.Has(fromEntityID))
|
if (pool.Has(fromEntityID))
|
||||||
pool.Copy(fromEntityID, toEntityID);
|
pool.Copy(fromEntityID, toEntityID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -285,7 +285,7 @@ namespace DCFApixels.DragonECS
|
|||||||
var count = --_componentCounts[entityID];
|
var count = --_componentCounts[entityID];
|
||||||
_entitiesComponentMasks[entityID][maskBit.chankIndex] &= ~maskBit.mask;
|
_entitiesComponentMasks[entityID][maskBit.chankIndex] &= ~maskBit.mask;
|
||||||
|
|
||||||
if (count == 0 && _allEntites.Has(entityID))
|
if (count == 0 && _allEntites.Has(entityID))
|
||||||
DelEntity(entityID);
|
DelEntity(entityID);
|
||||||
#if (DEBUG && !DISABLE_DEBUG) || ENABLE_DRAGONECS_ASSERT_CHEKS
|
#if (DEBUG && !DISABLE_DEBUG) || ENABLE_DRAGONECS_ASSERT_CHEKS
|
||||||
if (count < 0) Throw.World_InvalidIncrementComponentsBalance();
|
if (count < 0) Throw.World_InvalidIncrementComponentsBalance();
|
||||||
|
@ -70,7 +70,7 @@ namespace DCFApixels.DragonECS
|
|||||||
}
|
}
|
||||||
_mediator.RegisterComponent(entityID, _componentTypeID, _maskBit);
|
_mediator.RegisterComponent(entityID, _componentTypeID, _maskBit);
|
||||||
_listeners.InvokeOnAdd(entityID);
|
_listeners.InvokeOnAdd(entityID);
|
||||||
if(isMain)
|
if (isMain)
|
||||||
component.OnAddToPool(_source.GetEntityLong(entityID));
|
component.OnAddToPool(_source.GetEntityLong(entityID));
|
||||||
_items[itemIndex] = component;
|
_items[itemIndex] = component;
|
||||||
_entities[itemIndex] = entityID;
|
_entities[itemIndex] = entityID;
|
||||||
@ -84,7 +84,7 @@ namespace DCFApixels.DragonECS
|
|||||||
}
|
}
|
||||||
public void Set(int entityID, T component)
|
public void Set(int entityID, T component)
|
||||||
{
|
{
|
||||||
if(Has(entityID))
|
if (Has(entityID))
|
||||||
Del(entityID);
|
Del(entityID);
|
||||||
Add(entityID, component);
|
Add(entityID, component);
|
||||||
}
|
}
|
||||||
@ -121,7 +121,7 @@ namespace DCFApixels.DragonECS
|
|||||||
#endif
|
#endif
|
||||||
ref int itemIndex = ref _mapping[entityID];
|
ref int itemIndex = ref _mapping[entityID];
|
||||||
T component = _items[itemIndex];
|
T component = _items[itemIndex];
|
||||||
if(isMain)
|
if (isMain)
|
||||||
component.OnDelFromPool(_source.GetEntityLong(entityID));
|
component.OnDelFromPool(_source.GetEntityLong(entityID));
|
||||||
if (_recycledItemsCount >= _recycledItems.Length)
|
if (_recycledItemsCount >= _recycledItems.Length)
|
||||||
Array.Resize(ref _recycledItems, _recycledItems.Length << 1);
|
Array.Resize(ref _recycledItems, _recycledItems.Length << 1);
|
||||||
@ -296,7 +296,7 @@ namespace DCFApixels.DragonECS
|
|||||||
private Dictionary<Type, HybridMapping> _hybridMapping = new Dictionary<Type, HybridMapping>();
|
private Dictionary<Type, HybridMapping> _hybridMapping = new Dictionary<Type, HybridMapping>();
|
||||||
internal HybridMapping GetHybridMapping(Type type)
|
internal HybridMapping GetHybridMapping(Type type)
|
||||||
{
|
{
|
||||||
if(!_hybridMapping.TryGetValue(type, out HybridMapping mapping))
|
if (!_hybridMapping.TryGetValue(type, out HybridMapping mapping))
|
||||||
{
|
{
|
||||||
mapping = new HybridMapping(this, type);
|
mapping = new HybridMapping(this, type);
|
||||||
_hybridMapping.Add(type, mapping);
|
_hybridMapping.Add(type, mapping);
|
||||||
@ -314,7 +314,7 @@ namespace DCFApixels.DragonECS
|
|||||||
private IEcsHybridPoolInternal _targetTypePool;
|
private IEcsHybridPoolInternal _targetTypePool;
|
||||||
private List<IEcsHybridPoolInternal> _relatedPools;
|
private List<IEcsHybridPoolInternal> _relatedPools;
|
||||||
|
|
||||||
private static Type hybridPoolType = typeof(EcsHybridPool<>);
|
private static Type hybridPoolType = typeof(EcsHybridPool<>);
|
||||||
private static MethodInfo getHybridPoolMethod = typeof(EcsHybridPoolExtensions).GetMethod($"{nameof(EcsHybridPoolExtensions.GetPool)}", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
|
private static MethodInfo getHybridPoolMethod = typeof(EcsHybridPoolExtensions).GetMethod($"{nameof(EcsHybridPoolExtensions.GetPool)}", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
|
||||||
|
|
||||||
private static HashSet<Type> _hybridComponents = new HashSet<Type>();
|
private static HashSet<Type> _hybridComponents = new HashSet<Type>();
|
||||||
@ -346,17 +346,17 @@ namespace DCFApixels.DragonECS
|
|||||||
_source = source;
|
_source = source;
|
||||||
_type = type;
|
_type = type;
|
||||||
_relatedPools = new List<IEcsHybridPoolInternal>();
|
_relatedPools = new List<IEcsHybridPoolInternal>();
|
||||||
_sourceForReflection = new object[]{ source };
|
_sourceForReflection = new object[] { source };
|
||||||
_targetTypePool = CreateHybridPool(type);
|
_targetTypePool = CreateHybridPool(type);
|
||||||
foreach (var item in type.GetInterfaces())
|
foreach (var item in type.GetInterfaces())
|
||||||
{
|
{
|
||||||
if(IsEcsHybridComponentType(item))
|
if (IsEcsHybridComponentType(item))
|
||||||
{
|
{
|
||||||
_relatedPools.Add(CreateHybridPool(item));
|
_relatedPools.Add(CreateHybridPool(item));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Type baseType = type.BaseType;
|
Type baseType = type.BaseType;
|
||||||
while(baseType != typeof(object) && IsEcsHybridComponentType(baseType))
|
while (baseType != typeof(object) && IsEcsHybridComponentType(baseType))
|
||||||
{
|
{
|
||||||
_relatedPools.Add(CreateHybridPool(baseType));
|
_relatedPools.Add(CreateHybridPool(baseType));
|
||||||
baseType = baseType.BaseType;
|
baseType = baseType.BaseType;
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
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
|
||||||
|
Loading…
Reference in New Issue
Block a user