update world constructors

This commit is contained in:
Mikhail 2024-02-15 00:53:20 +08:00
parent d7b40e33b1
commit 8299c373b9
4 changed files with 24 additions and 12 deletions

View File

@ -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) { }
}
}

View File

@ -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);

View File

@ -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))

View File

@ -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<DataReleaser> _dataReleaseres = new List<DataReleaser>();
//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) { }
}
}
}