mirror of
https://github.com/DCFApixels/DragonECS.git
synced 2025-09-18 01:44:35 +08:00
update PoolMediator
This commit is contained in:
parent
6ec4e30ccc
commit
efed7dcdbd
@ -202,6 +202,50 @@ namespace DCFApixels.DragonECS
|
|||||||
if (count < 0) Throw.World_InvalidIncrementComponentsBalance();
|
if (count < 0) Throw.World_InvalidIncrementComponentsBalance();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
private bool TryRegisterEntityComponent(int entityID, int componentTypeID, EcsMaskChunck maskBit)
|
||||||
|
{
|
||||||
|
ref int chunk = ref _entityComponentMasks[entityID * _entityComponentMaskLength + maskBit.chankIndex];
|
||||||
|
int newChunk = chunk | maskBit.mask;
|
||||||
|
if (chunk != newChunk)
|
||||||
|
{
|
||||||
|
chunk = newChunk;
|
||||||
|
_poolComponentCounts[componentTypeID]++;
|
||||||
|
_componentCounts[entityID]++;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
private bool TryUnregisterEntityComponent(int entityID, int componentTypeID, EcsMaskChunck maskBit)
|
||||||
|
{
|
||||||
|
ref int chunk = ref _entityComponentMasks[entityID * _entityComponentMaskLength + maskBit.chankIndex];
|
||||||
|
int newChunk = chunk & ~maskBit.mask;
|
||||||
|
if (chunk != newChunk)
|
||||||
|
{
|
||||||
|
_poolComponentCounts[componentTypeID]--;
|
||||||
|
var count = --_componentCounts[entityID];
|
||||||
|
chunk = newChunk;
|
||||||
|
|
||||||
|
if (count == 0 && IsUsed(entityID))
|
||||||
|
{
|
||||||
|
DelEntity(entityID);
|
||||||
|
}
|
||||||
|
#if (DEBUG && !DISABLE_DEBUG) || ENABLE_DRAGONECS_ASSERT_CHEKS
|
||||||
|
if (count < 0) Throw.World_InvalidIncrementComponentsBalance();
|
||||||
|
#endif
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
private int GetPoolComponentCount(int componentTypeID)
|
||||||
|
{
|
||||||
|
return _poolComponentCounts[componentTypeID];
|
||||||
|
}
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
private bool HasEntityComponent(int entityID, EcsMaskChunck maskBit)
|
private bool HasEntityComponent(int entityID, EcsMaskChunck maskBit)
|
||||||
{
|
{
|
||||||
@ -217,7 +261,7 @@ namespace DCFApixels.DragonECS
|
|||||||
{
|
{
|
||||||
if (world == null || world._poolsMediator._world != null)
|
if (world == null || world._poolsMediator._world != null)
|
||||||
{
|
{
|
||||||
throw new MethodAccessException();
|
throw new InvalidOperationException();
|
||||||
}
|
}
|
||||||
_world = world;
|
_world = world;
|
||||||
}
|
}
|
||||||
@ -232,6 +276,22 @@ namespace DCFApixels.DragonECS
|
|||||||
_world.UnregisterEntityComponent(entityID, componentTypeID, maskBit);
|
_world.UnregisterEntityComponent(entityID, componentTypeID, maskBit);
|
||||||
}
|
}
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public bool TryRegisterComponent(int entityID, int componentTypeID, EcsMaskChunck maskBit)
|
||||||
|
{
|
||||||
|
return _world.TryRegisterEntityComponent(entityID, componentTypeID, maskBit);
|
||||||
|
}
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public bool TryUnregisterComponent(int entityID, int componentTypeID, EcsMaskChunck maskBit)
|
||||||
|
{
|
||||||
|
return _world.TryUnregisterEntityComponent(entityID, componentTypeID, maskBit);
|
||||||
|
}
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public int GetComponentCount(int componentTypeID)
|
||||||
|
{
|
||||||
|
return _world.GetPoolComponentCount(componentTypeID);
|
||||||
|
}
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public bool HasComponent(int entityID, EcsMaskChunck maskBit)
|
public bool HasComponent(int entityID, EcsMaskChunck maskBit)
|
||||||
{
|
{
|
||||||
return _world.HasEntityComponent(entityID, maskBit);
|
return _world.HasEntityComponent(entityID, maskBit);
|
||||||
|
Loading…
Reference in New Issue
Block a user