From ed698fbbd8fb340afd683ac34fc2507a39eb1034 Mon Sep 17 00:00:00 2001 From: Mikhail <99481254+DCFApixels@users.noreply.github.com> Date: Fri, 8 Nov 2024 17:20:05 +0800 Subject: [PATCH] add EntitesMatrix --- src/Utils/UncheckedCoreUtility.cs | 38 +++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/src/Utils/UncheckedCoreUtility.cs b/src/Utils/UncheckedCoreUtility.cs index a85f4fc..e31b032 100644 --- a/src/Utils/UncheckedCoreUtility.cs +++ b/src/Utils/UncheckedCoreUtility.cs @@ -45,4 +45,42 @@ namespace DCFApixels.DragonECS.UncheckedCore return true; } } + + public readonly struct EntitesMatrix + { + private readonly EcsWorld _world; + public EntitesMatrix(EcsWorld world) + { + _world = world; + } + public int PoolsCount + { + get { return _world.PoolsCount; } + } + public int EntitesCount + { + get { return _world.Capacity; } + } + public int GetEntityComponentsCount(int entityID) + { + return _world.GetComponentsCount(entityID); + } + public int GetEntityGen(int entityID) + { + return _world.GetGen(entityID); + } + public bool IsEntityUsed(int entityID) + { + return _world.IsUsed(entityID); + } + public bool this[int entityID, int poolID] + { + get + { + int entityStartChunkIndex = entityID << _world._entityComponentMaskLengthBitShift; + var chunkInfo = EcsMaskChunck.FromID(poolID); + return (_world._entityComponentMasks[entityStartChunkIndex + chunkInfo.chunkIndex] & chunkInfo.mask) != 0; + } + } + } }