mirror of
https://github.com/DCFApixels/DragonECS.git
synced 2025-09-18 18:14:37 +08:00
simple refactoring
This commit is contained in:
parent
4b0d188955
commit
e7c623daf8
@ -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();
|
||||||
|
@ -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))
|
||||||
@ -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();
|
||||||
|
@ -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);
|
||||||
@ -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