add HasComponent to PoolsMediator

This commit is contained in:
Mikhail 2023-12-06 20:45:32 +08:00
parent 8aae08b21e
commit 212bfa0f2a

View File

@ -2,6 +2,7 @@
using DCFApixels.DragonECS.Utils; using DCFApixels.DragonECS.Utils;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics.Metrics;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using static DCFApixels.DragonECS.EcsWorld; using static DCFApixels.DragonECS.EcsWorld;
@ -273,7 +274,7 @@ namespace DCFApixels.DragonECS
//public void CloneEntity(int fromEntityID, EcsWorld toWorld, int toEntityID) //public void CloneEntity(int fromEntityID, EcsWorld toWorld, int toEntityID)
#endregion #endregion
#region RegisterEntityComponent/UnregisterEntityComponent #region Pools mediation
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
private void RegisterEntityComponent(int entityID, int componentTypeID, EcsMaskBit maskBit) private void RegisterEntityComponent(int entityID, int componentTypeID, EcsMaskBit maskBit)
{ {
@ -292,6 +293,11 @@ namespace DCFApixels.DragonECS
if (count < 0) Throw.World_InvalidIncrementComponentsBalance(); if (count < 0) Throw.World_InvalidIncrementComponentsBalance();
#endif #endif
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private bool HasEntityComponent(int entityID, EcsMaskBit maskBit)
{
return (_entitiesComponentMasks[entityID][maskBit.chankIndex] & maskBit.mask) != maskBit.mask;
}
#endregion #endregion
#endregion #endregion
@ -389,7 +395,7 @@ namespace DCFApixels.DragonECS
public readonly struct PoolsMediator public readonly struct PoolsMediator
{ {
private readonly EcsWorld _world; private readonly EcsWorld _world;
public PoolsMediator(EcsWorld world) internal PoolsMediator(EcsWorld world)
{ {
if (world == null) if (world == null)
{ {
@ -397,21 +403,26 @@ namespace DCFApixels.DragonECS
} }
if (world._poolsMediator._world != null) if (world._poolsMediator._world != null)
{ {
throw new MethodAccessException("Нельзя создавать вручную"); throw new MethodAccessException();
} }
_world = world; _world = world;
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
internal void RegisterComponent(int entityID, int componentTypeID, EcsMaskBit maskBit) public void RegisterComponent(int entityID, int componentTypeID, EcsMaskBit maskBit)
{ {
_world.RegisterEntityComponent(entityID, componentTypeID, maskBit); _world.RegisterEntityComponent(entityID, componentTypeID, maskBit);
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
internal void UnregisterComponent(int entityID, int componentTypeID, EcsMaskBit maskBit) public void UnregisterComponent(int entityID, int componentTypeID, EcsMaskBit maskBit)
{ {
_world.UnregisterEntityComponent(entityID, componentTypeID, maskBit); _world.UnregisterEntityComponent(entityID, componentTypeID, maskBit);
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool HasComponent(int entityID, EcsMaskBit maskBit)
{
return _world.HasEntityComponent(entityID, maskBit);
}
} }
} }