mirror of
https://github.com/DCFApixels/DragonECS.git
synced 2025-09-18 01:44:35 +08:00
fix worldID
This commit is contained in:
parent
6613375779
commit
ee500fadfd
@ -150,7 +150,7 @@ namespace DCFApixels.DragonECS
|
|||||||
internal bool _isReleased = true;
|
internal bool _isReleased = true;
|
||||||
|
|
||||||
#region Properties
|
#region Properties
|
||||||
public int WorldID
|
public short WorldID
|
||||||
{
|
{
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
get { return _source.id; }
|
get { return _source.id; }
|
||||||
|
@ -9,8 +9,8 @@ namespace DCFApixels.DragonECS
|
|||||||
[DebuggerTypeProxy(typeof(DebuggerProxy))]
|
[DebuggerTypeProxy(typeof(DebuggerProxy))]
|
||||||
public readonly ref struct EcsSpan
|
public readonly ref struct EcsSpan
|
||||||
{
|
{
|
||||||
private readonly int _worldID;
|
|
||||||
private readonly ReadOnlySpan<int> _values;
|
private readonly ReadOnlySpan<int> _values;
|
||||||
|
private readonly short _worldID;
|
||||||
|
|
||||||
#region Properties
|
#region Properties
|
||||||
public bool IsNull
|
public bool IsNull
|
||||||
@ -46,24 +46,24 @@ namespace DCFApixels.DragonECS
|
|||||||
|
|
||||||
#region Constructors
|
#region Constructors
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
internal EcsSpan(int worldID, ReadOnlySpan<int> span)
|
internal EcsSpan(short worldID, ReadOnlySpan<int> span)
|
||||||
{
|
{
|
||||||
_worldID = worldID;
|
_worldID = worldID;
|
||||||
_values = span;
|
_values = span;
|
||||||
}
|
}
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
internal EcsSpan(int worldID, int[] array)
|
internal EcsSpan(short worldID, int[] array)
|
||||||
{
|
{
|
||||||
_worldID = worldID;
|
_worldID = worldID;
|
||||||
_values = new ReadOnlySpan<int>(array);
|
_values = new ReadOnlySpan<int>(array);
|
||||||
}
|
}
|
||||||
internal EcsSpan(int worldID, int[] array, int length)
|
internal EcsSpan(short worldID, int[] array, int length)
|
||||||
{
|
{
|
||||||
_worldID = worldID;
|
_worldID = worldID;
|
||||||
_values = new ReadOnlySpan<int>(array, 0, length);
|
_values = new ReadOnlySpan<int>(array, 0, length);
|
||||||
}
|
}
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
internal EcsSpan(int worldID, int[] array, int start, int length)
|
internal EcsSpan(short worldID, int[] array, int start, int length)
|
||||||
{
|
{
|
||||||
_worldID = worldID;
|
_worldID = worldID;
|
||||||
_values = new ReadOnlySpan<int>(array, start, length);
|
_values = new ReadOnlySpan<int>(array, start, length);
|
||||||
@ -110,7 +110,7 @@ namespace DCFApixels.DragonECS
|
|||||||
internal class DebuggerProxy
|
internal class DebuggerProxy
|
||||||
{
|
{
|
||||||
private int[] _values;
|
private int[] _values;
|
||||||
private int _worldID;
|
private short _worldID;
|
||||||
public EcsWorld World { get { return EcsWorld.GetWorld(_worldID); } }
|
public EcsWorld World { get { return EcsWorld.GetWorld(_worldID); } }
|
||||||
public EntitySlotInfo[] Entities
|
public EntitySlotInfo[] Entities
|
||||||
{
|
{
|
||||||
|
@ -260,7 +260,7 @@ namespace DCFApixels.DragonECS
|
|||||||
#region Iterator
|
#region Iterator
|
||||||
public ref struct Iterator
|
public ref struct Iterator
|
||||||
{
|
{
|
||||||
public readonly int worldID;
|
public readonly short worldID;
|
||||||
public readonly EcsAspect aspect;
|
public readonly EcsAspect aspect;
|
||||||
private EcsSpan _span;
|
private EcsSpan _span;
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@ namespace DCFApixels.DragonECS
|
|||||||
public sealed class EcsMask : IEquatable<EcsMask>
|
public sealed class EcsMask : IEquatable<EcsMask>
|
||||||
{
|
{
|
||||||
internal readonly int id;
|
internal readonly int id;
|
||||||
internal readonly int worldID;
|
internal readonly short worldID;
|
||||||
internal readonly EcsMaskChunck[] incChunckMasks;
|
internal readonly EcsMaskChunck[] incChunckMasks;
|
||||||
internal readonly EcsMaskChunck[] excChunckMasks;
|
internal readonly EcsMaskChunck[] excChunckMasks;
|
||||||
internal readonly int[] inc; //Sorted
|
internal readonly int[] inc; //Sorted
|
||||||
@ -22,7 +22,7 @@ namespace DCFApixels.DragonECS
|
|||||||
{
|
{
|
||||||
get { return id; }
|
get { return id; }
|
||||||
}
|
}
|
||||||
public int WorldID
|
public short WorldID
|
||||||
{
|
{
|
||||||
get { return worldID; }
|
get { return worldID; }
|
||||||
}
|
}
|
||||||
@ -51,7 +51,7 @@ namespace DCFApixels.DragonECS
|
|||||||
{
|
{
|
||||||
return new Builder(world);
|
return new Builder(world);
|
||||||
}
|
}
|
||||||
internal EcsMask(int id, int worldID, int[] inc, int[] exc)
|
internal EcsMask(int id, short worldID, int[] inc, int[] exc)
|
||||||
{
|
{
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
CheckConstraints(inc, exc);
|
CheckConstraints(inc, exc);
|
||||||
@ -223,7 +223,7 @@ namespace DCFApixels.DragonECS
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
private static string CreateLogString(int worldID, int[] inc, int[] exc)
|
private static string CreateLogString(short worldID, int[] inc, int[] exc)
|
||||||
{
|
{
|
||||||
#if (DEBUG && !DISABLE_DEBUG)
|
#if (DEBUG && !DISABLE_DEBUG)
|
||||||
string converter(int o) { return EcsDebugUtility.GetGenericTypeName(EcsWorld.GetWorld(worldID).AllPools[o].ComponentType, 1); }
|
string converter(int o) { return EcsDebugUtility.GetGenericTypeName(EcsWorld.GetWorld(worldID).AllPools[o].ComponentType, 1); }
|
||||||
@ -237,7 +237,7 @@ namespace DCFApixels.DragonECS
|
|||||||
{
|
{
|
||||||
public readonly int ID;
|
public readonly int ID;
|
||||||
public readonly EcsWorld world;
|
public readonly EcsWorld world;
|
||||||
private readonly int _worldID;
|
private readonly short _worldID;
|
||||||
public readonly EcsMaskChunck[] includedChunkMasks;
|
public readonly EcsMaskChunck[] includedChunkMasks;
|
||||||
public readonly EcsMaskChunck[] excludedChunkMasks;
|
public readonly EcsMaskChunck[] excludedChunkMasks;
|
||||||
public readonly int[] included;
|
public readonly int[] included;
|
||||||
|
@ -239,31 +239,39 @@ namespace DCFApixels.DragonECS
|
|||||||
return entityID;
|
return entityID;
|
||||||
}
|
}
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public void NewEntity(int entityID)
|
public int NewEntity(int entityID)
|
||||||
{
|
{
|
||||||
#if (DEBUG && !DISABLE_DEBUG) || !DISABLE_DRAGONECS_ASSERT_CHEKS
|
#if (DEBUG && !DISABLE_DEBUG) || !DISABLE_DRAGONECS_ASSERT_CHEKS
|
||||||
if (IsUsed(entityID)) { Throw.World_EntityIsAlreadyСontained(entityID); }
|
if (IsUsed(entityID)) { Throw.World_EntityIsAlreadyСontained(entityID); }
|
||||||
#endif
|
#endif
|
||||||
_entityDispenser.Use(entityID);
|
_entityDispenser.Use(entityID);
|
||||||
CreateConcreteEntity(entityID);
|
CreateConcreteEntity(entityID);
|
||||||
|
return entityID;
|
||||||
}
|
}
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
private void CreateConcreteEntity(int entityID)
|
private void CreateConcreteEntity(int entityID)
|
||||||
{
|
{
|
||||||
UpVersionLeaked();
|
UpVersionLeaked();
|
||||||
_entitiesCount++;
|
_entitiesCount++;
|
||||||
if (_entitiesCapacity <= entityID)
|
ref var slot = ref _entities[entityID];
|
||||||
{
|
slot.isUsed = true;
|
||||||
OnEntityDispenserResized(_entities.Length << 1);
|
if(slot.gen >= 0)
|
||||||
|
{ //если gen был пробужен у не мертвой сущности, то для отличия от мертвой, нужно инкрементировать и усыпить
|
||||||
|
slot.gen++;
|
||||||
|
slot.gen &= SLEEP_GEN_MASK;
|
||||||
}
|
}
|
||||||
_entities[entityID].isUsed = true;
|
|
||||||
_entityListeners.InvokeOnNewEntity(entityID);
|
_entityListeners.InvokeOnNewEntity(entityID);
|
||||||
}
|
}
|
||||||
|
|
||||||
public entlong NewEntityLong()
|
public entlong NewEntityLong()
|
||||||
{
|
{
|
||||||
int e = NewEntity();
|
int entityID = NewEntity();
|
||||||
return GetEntityLong(e);
|
return GetEntityLong(entityID);
|
||||||
|
}
|
||||||
|
public entlong NewEntityLong(int entityID)
|
||||||
|
{
|
||||||
|
NewEntity(entityID);
|
||||||
|
return GetEntityLong(entityID);
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
@ -275,6 +283,11 @@ namespace DCFApixels.DragonECS
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public void DelEntity(entlong entity)
|
||||||
|
{
|
||||||
|
DelEntity(entity.ID);
|
||||||
|
}
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public void DelEntity(int entityID)
|
public void DelEntity(int entityID)
|
||||||
{
|
{
|
||||||
#if (DEBUG && !DISABLE_DEBUG) || !DISABLE_DRAGONECS_ASSERT_CHEKS
|
#if (DEBUG && !DISABLE_DEBUG) || !DISABLE_DRAGONECS_ASSERT_CHEKS
|
||||||
@ -325,15 +338,14 @@ namespace DCFApixels.DragonECS
|
|||||||
{
|
{
|
||||||
unchecked
|
unchecked
|
||||||
{
|
{
|
||||||
ref short slotGen = ref _entities[entityID].gen;
|
ref var slotGen = ref _entities[entityID].gen;
|
||||||
if (slotGen < 0)
|
if (slotGen < 0)
|
||||||
{ //up gen
|
{ //если gen меньше 0 значит он спящий, спящие нужно инкремировать
|
||||||
slotGen++;
|
slotGen++;
|
||||||
slotGen &= GEN_MASK;
|
slotGen &= WAKE_UP_GEN_MASK;
|
||||||
}
|
}
|
||||||
return slotGen;
|
return slotGen;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public short GetComponentsCount(int entityID)
|
public short GetComponentsCount(int entityID)
|
||||||
|
@ -9,8 +9,8 @@ namespace DCFApixels.DragonECS
|
|||||||
[StructLayout(LayoutKind.Sequential, Pack = 4, Size = 4)]
|
[StructLayout(LayoutKind.Sequential, Pack = 4, Size = 4)]
|
||||||
public struct EcsWorldCmp<T> where T : struct
|
public struct EcsWorldCmp<T> where T : struct
|
||||||
{
|
{
|
||||||
private int _worldID;
|
private short _worldID;
|
||||||
public EcsWorldCmp(int worldID) => _worldID = worldID;
|
public EcsWorldCmp(short worldID) => _worldID = worldID;
|
||||||
public EcsWorld World => EcsWorld.GetWorld(_worldID);
|
public EcsWorld World => EcsWorld.GetWorld(_worldID);
|
||||||
public ref T Value => ref EcsWorld.GetData<T>(_worldID);
|
public ref T Value => ref EcsWorld.GetData<T>(_worldID);
|
||||||
}
|
}
|
||||||
@ -18,7 +18,9 @@ namespace DCFApixels.DragonECS
|
|||||||
{
|
{
|
||||||
private const short NULL_WORLD_ID = 0;
|
private const short NULL_WORLD_ID = 0;
|
||||||
|
|
||||||
private const short GEN_MASK = 0x7fff;
|
private const short WAKE_UP_GEN_MASK = 0x7fff;
|
||||||
|
private const short SLEEP_GEN_MASK = ~WAKE_UP_GEN_MASK;
|
||||||
|
|
||||||
private const short SLEEPING_GEN_FLAG = short.MinValue;
|
private const short SLEEPING_GEN_FLAG = short.MinValue;
|
||||||
private const int DEL_ENT_BUFFER_SIZE_OFFSET = 5;
|
private const int DEL_ENT_BUFFER_SIZE_OFFSET = 5;
|
||||||
private const int DEL_ENT_BUFFER_MIN_SIZE = 64;
|
private const int DEL_ENT_BUFFER_MIN_SIZE = 64;
|
||||||
@ -45,12 +47,21 @@ namespace DCFApixels.DragonECS
|
|||||||
Array.Resize(ref _worlds, newSize);
|
Array.Resize(ref _worlds, newSize);
|
||||||
}
|
}
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static EcsWorld GetWorld(int worldID) => _worlds[worldID];
|
public static EcsWorld GetWorld(short worldID)
|
||||||
|
{
|
||||||
|
return _worlds[worldID];
|
||||||
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static ref T GetData<T>(int worldID) => ref WorldComponentPool<T>.GetForWorld(worldID);
|
public static ref T GetData<T>(int worldID)
|
||||||
|
{
|
||||||
|
return ref WorldComponentPool<T>.GetForWorld(worldID);
|
||||||
|
}
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static ref T GetDataUnchecked<T>(int worldID) => ref WorldComponentPool<T>.GetForWorldUnchecked(worldID);
|
public static ref T GetDataUnchecked<T>(int worldID)
|
||||||
|
{
|
||||||
|
return ref WorldComponentPool<T>.GetForWorldUnchecked(worldID);
|
||||||
|
}
|
||||||
|
|
||||||
private abstract class DataReleaser
|
private abstract class DataReleaser
|
||||||
{
|
{
|
||||||
|
@ -279,7 +279,7 @@ namespace DCFApixels.DragonECS.Internal
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region UsedToEcsSpan
|
#region UsedToEcsSpan
|
||||||
public EcsSpan UsedToEcsSpan(int worldID)
|
public EcsSpan UsedToEcsSpan(short worldID)
|
||||||
{
|
{
|
||||||
return new EcsSpan(worldID, _dense, 1, _usedCount - 1);
|
return new EcsSpan(worldID, _dense, 1, _usedCount - 1);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user