polishing

This commit is contained in:
Mikhail 2024-04-28 18:36:24 +08:00
parent 32444868e1
commit bc4375808d
9 changed files with 65 additions and 20 deletions

View File

@ -3,15 +3,23 @@
namespace DCFApixels.DragonECS namespace DCFApixels.DragonECS
{ {
[DebuggerTypeProxy(typeof(DebuggerProxy))] [DebuggerTypeProxy(typeof(DebuggerProxy))]
public sealed class EcsDefaultWorld : EcsWorld public sealed class EcsDefaultWorld : EcsWorld, IInjectionUnit
{ {
public EcsDefaultWorld(EcsWorldConfig config, short worldID = -1) : base(config, worldID) { } public EcsDefaultWorld(EcsWorldConfig config, short worldID = -1) : base(config, worldID) { }
public EcsDefaultWorld(IConfigContainer configs = null, short worldID = -1) : base(configs, worldID) { } public EcsDefaultWorld(IConfigContainer configs = null, short worldID = -1) : base(configs, worldID) { }
void IInjectionUnit.OnInitInjectionBranch(InjectionBranchIniter initer)
{
initer.AddNode<EcsDefaultWorld>();
}
} }
[DebuggerTypeProxy(typeof(DebuggerProxy))] [DebuggerTypeProxy(typeof(DebuggerProxy))]
public sealed class EcsEventWorld : EcsWorld public sealed class EcsEventWorld : EcsWorld, IInjectionUnit
{ {
public EcsEventWorld(EcsWorldConfig config, short worldID = -1) : base(config, worldID) { } public EcsEventWorld(EcsWorldConfig config, short worldID = -1) : base(config, worldID) { }
public EcsEventWorld(IConfigContainer configs = null, short worldID = -1) : base(configs, worldID) { } public EcsEventWorld(IConfigContainer configs = null, short worldID = -1) : base(configs, worldID) { }
void IInjectionUnit.OnInitInjectionBranch(InjectionBranchIniter initer)
{
initer.AddNode<EcsDefaultWorld>();
}
} }
} }

View File

@ -313,8 +313,8 @@ namespace DCFApixels.DragonECS
} }
public bool Equals(OpMaskKey other) public bool Equals(OpMaskKey other)
{ {
return leftMaskID == other.leftMaskID && return leftMaskID == other.leftMaskID &&
rightMaskID == other.rightMaskID && rightMaskID == other.rightMaskID &&
operation == other.operation; operation == other.operation;
} }
public override int GetHashCode() public override int GetHashCode()
@ -585,7 +585,7 @@ namespace DCFApixels.DragonECS
{ {
foreach (var item in _excepteds) foreach (var item in _excepteds)
{ {
if(combinedInc.Overlaps(item.mask._exc) || combinedExc.Overlaps(item.mask._inc)) if (combinedInc.Overlaps(item.mask._exc) || combinedExc.Overlaps(item.mask._inc))
{ {
_combineds.Clear(); _combineds.Clear();
_excepteds.Clear(); _excepteds.Clear();

36
src/EcsPreFilter.cs Normal file
View File

@ -0,0 +1,36 @@
namespace DCFApixels.DragonECS
{
public class EcsPreFilter
{
}
public class EcsPreFilterManager
{
private EcsWorld _world;
private EcsGroup _dirtyEntities;
public EcsPreFilterManager(EcsWorld world)
{
_world = world;
_dirtyEntities = EcsGroup.New(_world);
}
internal void AddDirty(int entityID)
{
_dirtyEntities.Add(entityID);
}
}
public class PoolListener : IEcsPoolEventListener
{
public void OnAdd(int entityID)
{
}
public void OnDel(int entityID)
{
}
public void OnGet(int entityID)
{
}
}
}

View File

@ -256,7 +256,7 @@ namespace DCFApixels.DragonECS
_entitiesCount++; _entitiesCount++;
ref var slot = ref _entities[entityID]; ref var slot = ref _entities[entityID];
slot.isUsed = true; slot.isUsed = true;
if(slot.gen >= 0) if (slot.gen >= 0)
{ //если gen был пробужен у не мертвой сущности, то для отличия от мертвой, нужно инкрементировать и усыпить { //если gen был пробужен у не мертвой сущности, то для отличия от мертвой, нужно инкрементировать и усыпить
slot.gen++; slot.gen++;
slot.gen &= SLEEP_GEN_MASK; slot.gen &= SLEEP_GEN_MASK;

View File

@ -6,10 +6,7 @@ namespace DCFApixels.DragonECS
{ {
public static EcsPipeline.Builder Inject<T>(this EcsPipeline.Builder self, T data) public static EcsPipeline.Builder Inject<T>(this EcsPipeline.Builder self, T data)
{ {
if (data == null) if (data == null) { Throw.ArgumentNull(); }
{
Throw.ArgumentNull();
}
self.Injector.Inject(data); self.Injector.Inject(data);
if (data is IEcsModule module) if (data is IEcsModule module)
{ {

View File

@ -5,6 +5,8 @@ using System.Runtime.CompilerServices;
namespace DCFApixels.DragonECS.Internal namespace DCFApixels.DragonECS.Internal
{ {
//TODO разработать возможность ручного устанавливания ID типам.
//это нужно для упрощения разработки сетевух
internal static class EcsTypeCode internal static class EcsTypeCode
{ {
private static readonly Dictionary<Type, int> _codes = new Dictionary<Type, int>(); private static readonly Dictionary<Type, int> _codes = new Dictionary<Type, int>();

View File

@ -229,13 +229,13 @@ namespace DCFApixels.DragonECS
#region Listeners #region Listeners
public void AddListener(IEcsPoolEventListener listener) public void AddListener(IEcsPoolEventListener listener)
{ {
if (listener == null) { throw new ArgumentNullException("listener is null"); } if (listener == null) { EcsPoolThrowHalper.ThrowNullListener(); }
_listeners.Add(listener); _listeners.Add(listener);
_listenersCachedCount++; _listenersCachedCount++;
} }
public void RemoveListener(IEcsPoolEventListener listener) public void RemoveListener(IEcsPoolEventListener listener)
{ {
if (listener == null) { throw new ArgumentNullException("listener is null"); } if (listener == null) { EcsPoolThrowHalper.ThrowNullListener(); }
if (_listeners.Remove(listener)) if (_listeners.Remove(listener))
{ {
_listenersCachedCount--; _listenersCachedCount--;

View File

@ -85,6 +85,10 @@ namespace DCFApixels.DragonECS
{ {
throw new EcsFrameworkException($"Entity({entityID}) has no component {EcsDebugUtility.GetGenericTypeName(type)}."); throw new EcsFrameworkException($"Entity({entityID}) has no component {EcsDebugUtility.GetGenericTypeName(type)}.");
} }
public static void ThrowNullListener()
{
throw new ArgumentNullException("listener is null");
}
} }
public static class IEcsPoolImplementationExtensions public static class IEcsPoolImplementationExtensions
{ {

View File

@ -97,6 +97,7 @@ namespace DCFApixels.DragonECS
_mediator.UnregisterComponent(entityID, _componentTypeID, _maskBit); _mediator.UnregisterComponent(entityID, _componentTypeID, _maskBit);
_listeners.InvokeOnDel(entityID, _listenersCachedCount); _listeners.InvokeOnDel(entityID, _listenersCachedCount);
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void TryDel(int entityID) public void TryDel(int entityID)
{ {
if (Has(entityID)) if (Has(entityID))
@ -120,16 +121,13 @@ namespace DCFApixels.DragonECS
} }
public void Set(int entityID, bool isHas) public void Set(int entityID, bool isHas)
{ {
if (isHas) if (isHas != Has(entityID))
{ {
if (!Has(entityID)) if (isHas)
{ {
Add(entityID); Add(entityID);
} }
} else
else
{
if (Has(entityID))
{ {
Del(entityID); Del(entityID);
} }
@ -228,13 +226,13 @@ namespace DCFApixels.DragonECS
#region Listeners #region Listeners
public void AddListener(IEcsPoolEventListener listener) public void AddListener(IEcsPoolEventListener listener)
{ {
if (listener == null) { throw new ArgumentNullException("listener is null"); } if (listener == null) { EcsPoolThrowHalper.ThrowNullListener(); }
_listeners.Add(listener); _listeners.Add(listener);
_listenersCachedCount++; _listenersCachedCount++;
} }
public void RemoveListener(IEcsPoolEventListener listener) public void RemoveListener(IEcsPoolEventListener listener)
{ {
if (listener == null) { throw new ArgumentNullException("listener is null"); } if (listener == null) { EcsPoolThrowHalper.ThrowNullListener(); }
if (_listeners.Remove(listener)) if (_listeners.Remove(listener))
{ {
_listenersCachedCount--; _listenersCachedCount--;