diff --git a/src/Debug/EcsDebugUtility.cs b/src/Debug/EcsDebugUtility.cs index 82a36f3..03f2511 100644 --- a/src/Debug/EcsDebugUtility.cs +++ b/src/Debug/EcsDebugUtility.cs @@ -305,7 +305,6 @@ namespace DCFApixels.DragonECS return obj is IEcsTypeMetaProvider intr ? intr.MetaSource : obj; } #endregion - } public interface ITypeMeta diff --git a/src/Debug/MetaAttributes/MetaGroupAttribute.cs b/src/Debug/MetaAttributes/MetaGroupAttribute.cs index 0e693d1..332ab92 100644 --- a/src/Debug/MetaAttributes/MetaGroupAttribute.cs +++ b/src/Debug/MetaAttributes/MetaGroupAttribute.cs @@ -33,7 +33,7 @@ namespace DCFApixels.DragonECS { if (string.IsNullOrEmpty(name)) { - Name = string.Empty; + Name = string.Empty; return; } name = name.Replace('\\', '/'); diff --git a/src/EcsWorld.cs b/src/EcsWorld.cs index ebe9438..3e1ebf2 100644 --- a/src/EcsWorld.cs +++ b/src/EcsWorld.cs @@ -8,25 +8,6 @@ namespace DCFApixels.DragonECS { public partial class EcsWorld : IEntityStorage { - [StructLayout(LayoutKind.Explicit, Pack = 4, Size = 4 * 3)] - private struct EntitySlot - { - public static readonly EntitySlot Empty = new EntitySlot(SLEEPING_GEN_FLAG, 0, false); - [FieldOffset(0)] - public short gen; - [FieldOffset(2)] - public short componentsCount; - [FieldOffset(4)] - public bool isUsed; - //[FieldOffset(5)] - //public bool isLocked; - public EntitySlot(short gen, short componentsCount, bool isUsed) - { - this.gen = gen; - this.componentsCount = componentsCount; - this.isUsed = isUsed; - } - } public readonly short id; private IEcsWorldConfig _config; @@ -120,9 +101,14 @@ namespace DCFApixels.DragonECS { config = EcsWorldConfig.Empty; } + bool nullWorld = this is NullWorld; + if(nullWorld == false && worldID == NULL_WORLD_ID) + { + EcsDebug.PrintWarning($"The world identifier cannot be {NULL_WORLD_ID}"); + } _config = config; - if (worldID < 0) + if (worldID < 0 || (worldID == NULL_WORLD_ID && nullWorld == false)) { worldID = (short)_worldIdDispenser.UseFree(); } @@ -686,6 +672,28 @@ namespace DCFApixels.DragonECS return count; } #endregion + + #region EntitySlot + [StructLayout(LayoutKind.Explicit, Pack = 4, Size = 4 * 3)] + private struct EntitySlot + { + public static readonly EntitySlot Empty = new EntitySlot(SLEEPING_GEN_FLAG, 0, false); + [FieldOffset(0)] + public short gen; + [FieldOffset(2)] + public short componentsCount; + [FieldOffset(4)] + public bool isUsed; + //[FieldOffset(5)] + //public bool isLocked; + public EntitySlot(short gen, short componentsCount, bool isUsed) + { + this.gen = gen; + this.componentsCount = componentsCount; + this.isUsed = isUsed; + } + } + #endregion } #region Callbacks Interface diff --git a/src/EcsWorld.static.cs b/src/EcsWorld.static.cs index c200c99..c1145cf 100644 --- a/src/EcsWorld.static.cs +++ b/src/EcsWorld.static.cs @@ -16,6 +16,8 @@ namespace DCFApixels.DragonECS } public partial class EcsWorld { + private const short NULL_WORLD_ID = 0; + private const short GEN_MASK = 0x7fff; private const short SLEEPING_GEN_FLAG = short.MinValue; private const int DEL_ENT_BUFFER_SIZE_OFFSET = 5; @@ -29,7 +31,7 @@ namespace DCFApixels.DragonECS static EcsWorld() { - _worlds[0] = new NullWorld(); + _worlds[NULL_WORLD_ID] = new NullWorld(); } private static void ReleaseData(int worldID) { @@ -78,8 +80,7 @@ namespace DCFApixels.DragonECS public static ref T GetForWorldUnchecked(int worldID) { #if (DEBUG && !DISABLE_DEBUG) - if (_mapping[worldID] <= 0) - throw new Exception(); + if (_mapping[worldID] <= 0) { Throw.UndefinedException(); } #endif return ref _items[_mapping[worldID]]; }