update EcsWorldCmp

This commit is contained in:
Mikhail 2023-06-22 02:02:43 +08:00
parent aea6c75ad6
commit 110cb45887
3 changed files with 13 additions and 9 deletions

View File

@ -108,6 +108,11 @@ namespace DCFApixels.DragonECS
} }
#endregion #endregion
public EcsWorldCmp<T> GetWorldData<T>() where T : struct
{
return new EcsWorldCmp<T>(_world.id);
}
private void End(out EcsMask mask) private void End(out EcsMask mask)
{ {
HashSet<int> maskInc; HashSet<int> maskInc;

View File

@ -9,12 +9,12 @@ using System.Runtime.InteropServices;
namespace DCFApixels.DragonECS namespace DCFApixels.DragonECS
{ {
[StructLayout(LayoutKind.Sequential, Pack = 4, Size = 4)] [StructLayout(LayoutKind.Sequential, Pack = 4, Size = 4)]
public struct EcsWorldDataRef<T> where T : struct public struct EcsWorldCmp<T> where T : struct
{ {
private int _worldID; private int _worldID;
public EcsWorldDataRef(int worldID) => _worldID = worldID; public EcsWorldCmp(int worldID) => _worldID = worldID;
public EcsWorld World => EcsWorld.GetWorld(_worldID); public EcsWorld World => EcsWorld.GetWorld(_worldID);
public ref T Inst => ref EcsWorld.GetData<T>(_worldID); public ref T Value => ref EcsWorld.GetData<T>(_worldID);
} }
public abstract partial class EcsWorld public abstract partial class EcsWorld
{ {
@ -22,12 +22,11 @@ namespace DCFApixels.DragonECS
private const short DEATH_GEN_BIT = short.MinValue; private const short DEATH_GEN_BIT = short.MinValue;
private const int DEL_ENT_BUFFER_SIZE_OFFSET = 2; private const int DEL_ENT_BUFFER_SIZE_OFFSET = 2;
internal static EcsWorld[] Worlds = new EcsWorld[4]; private static EcsWorld[] Worlds = new EcsWorld[4];
private static IntDispenser _worldIdDispenser = new IntDispenser(0); private static IntDispenser _worldIdDispenser = new IntDispenser(0);
private static List<DataReleaser> _dataReleaseres = new List<DataReleaser>(); private static List<DataReleaser> _dataReleaseres = new List<DataReleaser>();
static EcsWorld() static EcsWorld()
{ {
Worlds[0] = new EcsNullWorld(); Worlds[0] = new EcsNullWorld();

View File

@ -28,7 +28,7 @@ namespace DCFApixels.DragonECS
public bool IsAlive public bool IsAlive
{ {
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
get => EcsWorld.Worlds[world].IsAlive(id, gen); get => EcsWorld.GetWorld(world).IsAlive(id, gen);
} }
public bool IsNull public bool IsNull
{ {
@ -65,7 +65,7 @@ namespace DCFApixels.DragonECS
#if (DEBUG && !DISABLE_DEBUG) || ENABLE_DRAGONECS_ASSERT_CHEKS #if (DEBUG && !DISABLE_DEBUG) || ENABLE_DRAGONECS_ASSERT_CHEKS
if (!IsAlive) ThrowIsNotAlive(this); if (!IsAlive) ThrowIsNotAlive(this);
#endif #endif
return EcsWorld.Worlds[world]; return EcsWorld.GetWorld(world);
} }
} }
public short WorldID public short WorldID
@ -104,12 +104,12 @@ namespace DCFApixels.DragonECS
} }
public bool TryGetWorld(out EcsWorld world) public bool TryGetWorld(out EcsWorld world)
{ {
world = EcsWorld.Worlds[this.world]; world = EcsWorld.GetWorld(this.world);
return IsAlive; return IsAlive;
} }
public bool TryUnpack(out EcsWorld world, out int id) public bool TryUnpack(out EcsWorld world, out int id)
{ {
world = EcsWorld.Worlds[this.world]; world = EcsWorld.GetWorld(this.world);
id = this.id; id = this.id;
return IsAlive; return IsAlive;
} }