update PoolMediator

This commit is contained in:
Mikhail 2024-02-23 20:44:11 +08:00
parent 6ec4e30ccc
commit efed7dcdbd

View File

@ -202,6 +202,50 @@ namespace DCFApixels.DragonECS
if (count < 0) Throw.World_InvalidIncrementComponentsBalance();
#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)]
private bool HasEntityComponent(int entityID, EcsMaskChunck maskBit)
{
@ -217,7 +261,7 @@ namespace DCFApixels.DragonECS
{
if (world == null || world._poolsMediator._world != null)
{
throw new MethodAccessException();
throw new InvalidOperationException();
}
_world = world;
}
@ -232,6 +276,22 @@ namespace DCFApixels.DragonECS
_world.UnregisterEntityComponent(entityID, componentTypeID, maskBit);
}
[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)
{
return _world.HasEntityComponent(entityID, maskBit);