From 8299c373b9912905722f16755a40d41134b0b906 Mon Sep 17 00:00:00 2001 From: Mikhail <99481254+DCFApixels@users.noreply.github.com> Date: Thu, 15 Feb 2024 00:53:20 +0800 Subject: [PATCH] update world constructors --- src/Builtin/Worlds.cs | 6 ++---- src/EcsWorld.cs | 18 ++++++++++++------ src/EcsWorld.pools.cs | 6 ++++++ src/EcsWorld.static.cs | 6 ++++-- 4 files changed, 24 insertions(+), 12 deletions(-) diff --git a/src/Builtin/Worlds.cs b/src/Builtin/Worlds.cs index 9e7fbc0..d314039 100644 --- a/src/Builtin/Worlds.cs +++ b/src/Builtin/Worlds.cs @@ -2,12 +2,10 @@ { public sealed class EcsDefaultWorld : EcsWorld, IEntityStorage { - public EcsDefaultWorld() : base(null) { } - public EcsDefaultWorld(IEcsWorldConfig config) : base(config) { } + public EcsDefaultWorld(IEcsWorldConfig config = null, short worldID = -1) : base(config, worldID) { } } public sealed class EcsEventWorld : EcsWorld, IEntityStorage { - public EcsEventWorld() : base(null) { } - public EcsEventWorld(IEcsWorldConfig config) : base(config) { } + public EcsEventWorld(IEcsWorldConfig config = null, short worldID = -1) : base(config, worldID) { } } } diff --git a/src/EcsWorld.cs b/src/EcsWorld.cs index 333f027..eed34f4 100644 --- a/src/EcsWorld.cs +++ b/src/EcsWorld.cs @@ -92,8 +92,7 @@ namespace DCFApixels.DragonECS #endregion #region Constructors/Destroy - public EcsWorld(IEcsWorldConfig config) : this(config, true) { } - private EcsWorld(IEcsWorldConfig config, bool isIndexable) + public EcsWorld(IEcsWorldConfig config = null, short worldID = -1) { if (config == null) { @@ -101,15 +100,22 @@ namespace DCFApixels.DragonECS } _config = config; - if (isIndexable) + if (worldID < 0) { - id = (short)_worldIdDispenser.UseFree(); - if (id >= Worlds.Length) + worldID = (short)_worldIdDispenser.UseFree(); + if (worldID >= Worlds.Length) { Array.Resize(ref Worlds, Worlds.Length << 1); } - Worlds[id] = this; } + else + { + if (Worlds[worldID] != null) + { + Throw.UndefinedException(); + } + } + Worlds[worldID] = this; _poolsMediator = new PoolsMediator(this); diff --git a/src/EcsWorld.pools.cs b/src/EcsWorld.pools.cs index 8f8f74f..f4b4415 100644 --- a/src/EcsWorld.pools.cs +++ b/src/EcsWorld.pools.cs @@ -108,6 +108,12 @@ namespace DCFApixels.DragonECS TPool newPool = new TPool(); Type componentType = newPool.ComponentType; +//#if DEBUG //проверка соответсвия типов +// if(componentType != typeof(TPool).GetInterfaces().First(o => o.IsGenericType && o.GetGenericTypeDefinition() == typeof(IEcsPoolImplementation<>)).GetGenericArguments()[0]) +// { +// Throw.UndefinedException(); +// } +//#endif int componentTypeCode = EcsTypeCode.Get(componentType); if (_componentTypeCode_2_CmpTypeIDs.TryGetValue(componentTypeCode, out int componentTypeID)) diff --git a/src/EcsWorld.static.cs b/src/EcsWorld.static.cs index e715d7d..882b3ed 100644 --- a/src/EcsWorld.static.cs +++ b/src/EcsWorld.static.cs @@ -22,7 +22,7 @@ namespace DCFApixels.DragonECS private const int DEL_ENT_BUFFER_MIN_SIZE = 64; private static EcsWorld[] Worlds = new EcsWorld[4]; - private static IdDispenser _worldIdDispenser = new IdDispenser(4); + private static IdDispenser _worldIdDispenser = new IdDispenser(4, 0); private static List _dataReleaseres = new List(); //public static int Copacity => Worlds.Length; @@ -34,7 +34,9 @@ namespace DCFApixels.DragonECS private static void ReleaseData(int worldID) { for (int i = 0, iMax = _dataReleaseres.Count; i < iMax; i++) + { _dataReleaseres[i].Release(worldID); + } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static EcsWorld GetWorld(int worldID) => Worlds[worldID]; @@ -123,7 +125,7 @@ namespace DCFApixels.DragonECS } private sealed class NullWorld : EcsWorld { - internal NullWorld() : base(EcsWorldConfig.Empty, false) { } + internal NullWorld() : base(EcsWorldConfig.Empty, 0) { } } } }