mirror of
https://github.com/DCFApixels/DragonECS.git
synced 2025-09-18 01:44:35 +08:00
rename EcsWorld.id to EcsWorld.ID
This commit is contained in:
parent
6ff13eaf1e
commit
02834d6826
@ -197,7 +197,7 @@ namespace DCFApixels.DragonECS
|
||||
public short WorldID
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get { return _source.id; }
|
||||
get { return _source.ID; }
|
||||
}
|
||||
public EcsWorld World
|
||||
{
|
||||
@ -477,7 +477,7 @@ namespace DCFApixels.DragonECS
|
||||
public void UnionWith(EcsSpan span)
|
||||
{
|
||||
#if (DEBUG && !DISABLE_DEBUG) || ENABLE_DRAGONECS_ASSERT_CHEKS
|
||||
if (_source.id != span.WorldID) Throw.Group_ArgumentDifferentWorldsException();
|
||||
if (_source.ID != span.WorldID) Throw.Group_ArgumentDifferentWorldsException();
|
||||
#endif
|
||||
foreach (var entityID in span) { UnionWithStep(entityID); }
|
||||
}
|
||||
@ -525,7 +525,7 @@ namespace DCFApixels.DragonECS
|
||||
public void ExceptWith(EcsSpan span)
|
||||
{
|
||||
#if (DEBUG && !DISABLE_DEBUG) || ENABLE_DRAGONECS_ASSERT_CHEKS
|
||||
if (_source.id != span.WorldID) { Throw.Group_ArgumentDifferentWorldsException(); }
|
||||
if (_source.ID != span.WorldID) { Throw.Group_ArgumentDifferentWorldsException(); }
|
||||
#endif
|
||||
foreach (var entityID in span) { ExceptWithStep_Internal(entityID); }
|
||||
}
|
||||
@ -563,10 +563,10 @@ namespace DCFApixels.DragonECS
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void IntersectWith(EcsReadonlyGroup group) { IntersectWith(group.GetSource_Internal()); }
|
||||
/// <summary>as Intersect sets</summary>
|
||||
public void IntersectWith(EcsSpan span) //TODO протестировать
|
||||
public void IntersectWith(EcsSpan span)
|
||||
{
|
||||
#if (DEBUG && !DISABLE_DEBUG) || ENABLE_DRAGONECS_ASSERT_CHEKS
|
||||
if (_source.id != span.WorldID) { Throw.Group_ArgumentDifferentWorldsException(); }
|
||||
if (_source.ID != span.WorldID) { Throw.Group_ArgumentDifferentWorldsException(); }
|
||||
#endif
|
||||
foreach (var entityID in span)
|
||||
{
|
||||
@ -621,7 +621,7 @@ namespace DCFApixels.DragonECS
|
||||
public void SymmetricExceptWith(EcsSpan span)
|
||||
{
|
||||
#if (DEBUG && !DISABLE_DEBUG) || ENABLE_DRAGONECS_ASSERT_CHEKS
|
||||
if (_source.id != span.WorldID) { Throw.Group_ArgumentDifferentWorldsException(); }
|
||||
if (_source.ID != span.WorldID) { Throw.Group_ArgumentDifferentWorldsException(); }
|
||||
#endif
|
||||
foreach (var entityID in span) { SymmetricExceptWithStep_Internal(entityID); }
|
||||
}
|
||||
@ -688,7 +688,7 @@ namespace DCFApixels.DragonECS
|
||||
public bool SetEquals(EcsSpan span)
|
||||
{
|
||||
#if (DEBUG && !DISABLE_DEBUG) || ENABLE_DRAGONECS_ASSERT_CHEKS
|
||||
if (_source.id != span.WorldID) { Throw.Group_ArgumentDifferentWorldsException(); }
|
||||
if (_source.ID != span.WorldID) { Throw.Group_ArgumentDifferentWorldsException(); }
|
||||
#endif
|
||||
if (span.Count != Count) { return false; }
|
||||
foreach (var entityID in span)
|
||||
@ -747,7 +747,7 @@ namespace DCFApixels.DragonECS
|
||||
public bool Overlaps(EcsSpan span)
|
||||
{
|
||||
#if (DEBUG && !DISABLE_DEBUG) || ENABLE_DRAGONECS_ASSERT_CHEKS
|
||||
if (_source.id != span.WorldID) Throw.Group_ArgumentDifferentWorldsException();
|
||||
if (_source.ID != span.WorldID) Throw.Group_ArgumentDifferentWorldsException();
|
||||
#endif
|
||||
foreach (var entityID in span)
|
||||
{
|
||||
@ -786,7 +786,7 @@ namespace DCFApixels.DragonECS
|
||||
public bool IsSubsetOf(EcsSpan span)
|
||||
{
|
||||
#if (DEBUG && !DISABLE_DEBUG) || ENABLE_DRAGONECS_ASSERT_CHEKS
|
||||
if (_source.id != span.WorldID) Throw.Group_ArgumentDifferentWorldsException();
|
||||
if (_source.ID != span.WorldID) Throw.Group_ArgumentDifferentWorldsException();
|
||||
#endif
|
||||
if (Count == 0) { return true; }
|
||||
if (span.Count < Count) { return false; }
|
||||
@ -815,7 +815,7 @@ namespace DCFApixels.DragonECS
|
||||
public bool IsProperSubsetOf(EcsSpan span)
|
||||
{
|
||||
#if (DEBUG && !DISABLE_DEBUG) || ENABLE_DRAGONECS_ASSERT_CHEKS
|
||||
if (_source.id != span.WorldID) Throw.Group_ArgumentDifferentWorldsException();
|
||||
if (_source.ID != span.WorldID) Throw.Group_ArgumentDifferentWorldsException();
|
||||
#endif
|
||||
if (Count == 0) { return true; }
|
||||
if (span.Count <= Count) { return false; }
|
||||
@ -884,7 +884,7 @@ namespace DCFApixels.DragonECS
|
||||
public bool IsSupersetOf(EcsSpan span)
|
||||
{
|
||||
#if (DEBUG && !DISABLE_DEBUG) || ENABLE_DRAGONECS_ASSERT_CHEKS
|
||||
if (_source.id != span.WorldID) Throw.Group_ArgumentDifferentWorldsException();
|
||||
if (_source.ID != span.WorldID) Throw.Group_ArgumentDifferentWorldsException();
|
||||
#endif
|
||||
if (span.Count > Count) { return false; }
|
||||
return IsSupersetOf_Internal(span);
|
||||
@ -910,7 +910,7 @@ namespace DCFApixels.DragonECS
|
||||
public bool IsProperSupersetOf(EcsSpan span)
|
||||
{
|
||||
#if (DEBUG && !DISABLE_DEBUG) || ENABLE_DRAGONECS_ASSERT_CHEKS
|
||||
if (_source.id != span.WorldID) Throw.Group_ArgumentDifferentWorldsException();
|
||||
if (_source.ID != span.WorldID) Throw.Group_ArgumentDifferentWorldsException();
|
||||
#endif
|
||||
if (span.Count >= Count) { return false; }
|
||||
return IsSupersetOf_Internal(span);
|
||||
@ -1030,7 +1030,7 @@ namespace DCFApixels.DragonECS
|
||||
public static EcsGroup Except(EcsSpan a, EcsGroup b)
|
||||
{
|
||||
#if (DEBUG && !DISABLE_DEBUG) || ENABLE_DRAGONECS_ASSERT_CHEKS
|
||||
if (a.WorldID != b._source.id) { Throw.Group_ArgumentDifferentWorldsException(); }
|
||||
if (a.WorldID != b._source.ID) { Throw.Group_ArgumentDifferentWorldsException(); }
|
||||
#endif
|
||||
EcsGroup result = b._source.GetFreeGroup();
|
||||
foreach (var entityID in a)
|
||||
@ -1085,7 +1085,7 @@ namespace DCFApixels.DragonECS
|
||||
public static EcsGroup Intersect(EcsSpan a, EcsGroup b)
|
||||
{
|
||||
#if (DEBUG && !DISABLE_DEBUG) || ENABLE_DRAGONECS_ASSERT_CHEKS
|
||||
if (a.WorldID != b._source.id) { Throw.Group_ArgumentDifferentWorldsException(); }
|
||||
if (a.WorldID != b._source.ID) { Throw.Group_ArgumentDifferentWorldsException(); }
|
||||
#endif
|
||||
EcsGroup result = b._source.GetFreeGroup();
|
||||
foreach (var entityID in a)
|
||||
|
@ -225,7 +225,7 @@ namespace DCFApixels.DragonECS
|
||||
|
||||
public Iterator(EcsMaskIterator iterator, EcsSpan span)
|
||||
{
|
||||
worldID = iterator.World.id;
|
||||
worldID = iterator.World.ID;
|
||||
_span = span;
|
||||
this.iterator = iterator.Iterate(span);
|
||||
}
|
||||
|
@ -379,9 +379,9 @@ namespace DCFApixels.DragonECS
|
||||
|
||||
|
||||
|
||||
EmptyMask = CreateEmpty(_staticMasks.Count, world.id);
|
||||
EmptyMask = CreateEmpty(_staticMasks.Count, world.ID);
|
||||
_staticMasks.Add(EmptyMask._staticMask.ID, EmptyMask);
|
||||
BrokenMask = CreateBroken(_staticMasks.Count, world.id);
|
||||
BrokenMask = CreateBroken(_staticMasks.Count, world.ID);
|
||||
_staticMasks.Add(BrokenMask._staticMask.ID, BrokenMask);
|
||||
}
|
||||
public void Init(ref WorldMaskComponent component, EcsWorld world)
|
||||
@ -444,7 +444,7 @@ namespace DCFApixels.DragonECS
|
||||
int[] incs = ConvertTypeCodeToComponentTypeID(staticMask.IncTypeCodes, _world);
|
||||
int[] excs = ConvertTypeCodeToComponentTypeID(staticMask.ExcTypeCodes, _world);
|
||||
|
||||
result = new EcsMask(staticMask, _staticMasks.Count, _world.id, incs, excs);
|
||||
result = new EcsMask(staticMask, _staticMasks.Count, _world.ID, incs, excs);
|
||||
|
||||
_staticMasks.Add(staticMask.ID, result);
|
||||
}
|
||||
|
@ -355,7 +355,6 @@ namespace DCFApixels.DragonECS
|
||||
return $"Inc({string.Join(", ", inc)}) Exc({string.Join(", ", exc)})"; // Release optimization
|
||||
#endif
|
||||
}
|
||||
|
||||
internal class DebuggerProxy
|
||||
{
|
||||
private EcsStaticMask _source;
|
||||
@ -388,28 +387,49 @@ namespace DCFApixels.DragonECS
|
||||
|
||||
#if DEBUG
|
||||
//TODO оптимизировать, так как списки сортированны, наверняка есть способ без хешсета пройтись и не локать треды
|
||||
private static HashSet<int> _dummyHashSet = new HashSet<int>();
|
||||
private static void CheckConstraints(int[] inc, int[] exc)
|
||||
private static void CheckConstraints(EcsTypeCode[] incs, EcsTypeCode[] excs)
|
||||
{
|
||||
lock (_dummyHashSet)
|
||||
{
|
||||
if (CheckRepeats(inc)) { throw new EcsFrameworkException("The values in the Include constraints are repeated."); }
|
||||
if (CheckRepeats(exc)) { throw new EcsFrameworkException("The values in the Exclude constraints are repeated."); }
|
||||
_dummyHashSet.Clear();
|
||||
_dummyHashSet.UnionWith(inc);
|
||||
if (_dummyHashSet.Overlaps(exc)) { throw new EcsFrameworkException("Conflicting Include and Exclude constraints."); }
|
||||
if (CheckRepeats(incs)) { throw new EcsFrameworkException("The values in the Include constraints are repeated."); }
|
||||
if (CheckRepeats(excs)) { throw new EcsFrameworkException("The values in the Exclude constraints are repeated."); }
|
||||
if (HasCommonElements(incs, excs)) { throw new EcsFrameworkException("Conflicting Include and Exclude constraints."); }
|
||||
}
|
||||
}
|
||||
private static bool CheckRepeats(int[] array)
|
||||
private static bool HasCommonElements(EcsTypeCode[] a, EcsTypeCode[] b)
|
||||
{
|
||||
_dummyHashSet.Clear();
|
||||
foreach (var item in array)
|
||||
int i = 0;
|
||||
int j = 0;
|
||||
|
||||
while (i < a.Length && j < b.Length)
|
||||
{
|
||||
if (_dummyHashSet.Contains(item))
|
||||
if (a[i] == b[j])
|
||||
{
|
||||
return true;
|
||||
}
|
||||
_dummyHashSet.Add(item);
|
||||
else if (a[i] < b[j])
|
||||
{
|
||||
i++;
|
||||
}
|
||||
else
|
||||
{
|
||||
j++;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
private static bool CheckRepeats(EcsTypeCode[] array)
|
||||
{
|
||||
if(array.Length <= 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
EcsTypeCode lastValue = array[0];
|
||||
for (int i = 1; i < array.Length; i++)
|
||||
{
|
||||
EcsTypeCode value = array[i];
|
||||
if(value == lastValue)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
lastValue = value;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -42,7 +42,7 @@ namespace DCFApixels.DragonECS
|
||||
[DebuggerTypeProxy(typeof(DebuggerProxy))]
|
||||
public partial class EcsWorld : IEntityStorage, IEcsMember
|
||||
{
|
||||
public readonly short id;
|
||||
public readonly short ID;
|
||||
private IConfigContainer _configs;
|
||||
|
||||
private bool _isDestroyed = false;
|
||||
@ -73,6 +73,12 @@ namespace DCFApixels.DragonECS
|
||||
private List<IEcsEntityEventListener> _entityListeners = new List<IEcsEntityEventListener>();
|
||||
|
||||
#region Properties
|
||||
[Obsolete("Use EcsWorld.ID")]
|
||||
public short id
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get { return ID; }
|
||||
}
|
||||
EcsWorld IEntityStorage.World
|
||||
{
|
||||
get { return this; }
|
||||
@ -119,7 +125,7 @@ namespace DCFApixels.DragonECS
|
||||
get
|
||||
{
|
||||
ReleaseDelEntityBufferAll();
|
||||
return _entityDispenser.UsedToEcsSpan(id);
|
||||
return _entityDispenser.UsedToEcsSpan(ID);
|
||||
}
|
||||
}
|
||||
public int PoolsCount
|
||||
@ -166,7 +172,7 @@ namespace DCFApixels.DragonECS
|
||||
Throw.Exception("The world with the specified ID has already been created\r\n");
|
||||
}
|
||||
}
|
||||
id = worldID;
|
||||
ID = worldID;
|
||||
_worlds[worldID] = this;
|
||||
|
||||
_poolsMediator = new PoolsMediator(this);
|
||||
@ -191,7 +197,7 @@ namespace DCFApixels.DragonECS
|
||||
EcsDebug.PrintWarning("The world is already destroyed");
|
||||
return;
|
||||
}
|
||||
if (id == NULL_WORLD_ID)
|
||||
if (ID == NULL_WORLD_ID)
|
||||
{
|
||||
#if (DEBUG && !DISABLE_DEBUG)
|
||||
Throw.World_WorldCantBeDestroyed();
|
||||
@ -202,9 +208,9 @@ namespace DCFApixels.DragonECS
|
||||
_entityDispenser = null;
|
||||
_pools = null;
|
||||
_nullPool = null;
|
||||
_worlds[id] = null;
|
||||
ReleaseData(id);
|
||||
_worldIdDispenser.Release(id);
|
||||
_worlds[ID] = null;
|
||||
ReleaseData(ID);
|
||||
_worldIdDispenser.Release(ID);
|
||||
_isDestroyed = true;
|
||||
_poolTypeCode_2_CmpTypeIDs = null;
|
||||
_cmpTypeCode_2_CmpTypeIDs = null;
|
||||
@ -241,12 +247,12 @@ namespace DCFApixels.DragonECS
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public ref T Get<T>() where T : struct
|
||||
{
|
||||
return ref WorldComponentPool<T>.GetForWorld(id);
|
||||
return ref WorldComponentPool<T>.GetForWorld(ID);
|
||||
}
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public ref T GetUnchecked<T>() where T : struct
|
||||
{
|
||||
return ref WorldComponentPool<T>.GetForWorldUnchecked(id);
|
||||
return ref WorldComponentPool<T>.GetForWorldUnchecked(ID);
|
||||
}
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static ref T Get<T>(int worldID) where T : struct
|
||||
@ -341,18 +347,18 @@ namespace DCFApixels.DragonECS
|
||||
{
|
||||
ReleaseDelEntityBufferAll();
|
||||
}
|
||||
return _entityDispenser.UsedToEcsSpan(id);
|
||||
return _entityDispenser.UsedToEcsSpan(ID);
|
||||
}
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public unsafe entlong GetEntityLong(int entityID)
|
||||
{
|
||||
long x = (long)id << 48 | (long)GetGen(entityID) << 32 | (long)entityID;
|
||||
long x = (long)ID << 48 | (long)GetGen(entityID) << 32 | (long)entityID;
|
||||
return *(entlong*)&x;
|
||||
}
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public unsafe EntitySlotInfo GetEntitySlotInfoDebug(int entityID)
|
||||
{
|
||||
return new EntitySlotInfo(entityID, _entities[entityID].gen, id);
|
||||
return new EntitySlotInfo(entityID, _entities[entityID].gen, ID);
|
||||
}
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public bool IsAlive(int entityID, short gen)
|
||||
@ -392,7 +398,7 @@ namespace DCFApixels.DragonECS
|
||||
public bool IsMatchesMask(EcsMask mask, int entityID)
|
||||
{
|
||||
#if (DEBUG && !DISABLE_DEBUG) || !DISABLE_DRAGONECS_ASSERT_CHEKS
|
||||
if (mask._worldID != id) { Throw.World_MaskDoesntBelongWorld(); }
|
||||
if (mask._worldID != ID) { Throw.World_MaskDoesntBelongWorld(); }
|
||||
#endif
|
||||
for (int i = 0, iMax = mask._inc.Length; i < iMax; i++)
|
||||
{
|
||||
@ -821,7 +827,7 @@ namespace DCFApixels.DragonECS
|
||||
#region DebuggerProxy
|
||||
private EcsSpan GetSpan_Debug()
|
||||
{
|
||||
return _entityDispenser.UsedToEcsSpan(id);
|
||||
return _entityDispenser.UsedToEcsSpan(ID);
|
||||
}
|
||||
protected class DebuggerProxy
|
||||
{
|
||||
@ -841,7 +847,7 @@ namespace DCFApixels.DragonECS
|
||||
}
|
||||
public long Version { get { return _world.Version; } }
|
||||
public IEcsPool[] Pools { get { return _world._pools; } }
|
||||
public short ID { get { return _world.id; } }
|
||||
public short ID { get { return _world.ID; } }
|
||||
public DebuggerProxy(EcsWorld world)
|
||||
{
|
||||
_world = world;
|
||||
|
@ -28,7 +28,7 @@ namespace DCFApixels.DragonECS
|
||||
public short WorldID
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get { return _source.id; }
|
||||
get { return _source.ID; }
|
||||
}
|
||||
public EcsWorld World
|
||||
{
|
||||
|
@ -58,7 +58,7 @@ namespace DCFApixels.DragonECS.Internal
|
||||
{
|
||||
#if (DEBUG && !DISABLE_DEBUG) || ENABLE_DRAGONECS_ASSERT_CHEKS
|
||||
if (span.IsNull) { Throw.ArgumentNull(nameof(span)); }
|
||||
if (span.WorldID != World.id) { Throw.Quiery_ArgumentDifferentWorldsException(); }
|
||||
if (span.WorldID != World.ID) { Throw.Quiery_ArgumentDifferentWorldsException(); }
|
||||
#endif
|
||||
if (_filteredEntities == null)
|
||||
{
|
||||
@ -71,13 +71,13 @@ namespace DCFApixels.DragonECS.Internal
|
||||
public EcsSpan Execute()
|
||||
{
|
||||
Execute_Iternal();
|
||||
return new EcsSpan(World.id, _filteredAllEntities, _filteredAllEntitiesCount);
|
||||
return new EcsSpan(World.ID, _filteredAllEntities, _filteredAllEntitiesCount);
|
||||
}
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public EcsSpan ExecuteFor(EcsSpan span)
|
||||
{
|
||||
ExecuteFor_Iternal(span);
|
||||
return new EcsSpan(World.id, _filteredEntities, _filteredEntitiesCount);
|
||||
return new EcsSpan(World.ID, _filteredEntities, _filteredEntitiesCount);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
@ -85,14 +85,14 @@ namespace DCFApixels.DragonECS.Internal
|
||||
{
|
||||
Execute_Iternal();
|
||||
ArraySortHalperX<int>.Sort(_filteredAllEntities, comparison, _filteredAllEntitiesCount);
|
||||
return new EcsSpan(World.id, _filteredAllEntities, _filteredAllEntitiesCount);
|
||||
return new EcsSpan(World.ID, _filteredAllEntities, _filteredAllEntitiesCount);
|
||||
}
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public EcsSpan ExecuteFor(EcsSpan span, Comparison<int> comparison)
|
||||
{
|
||||
ExecuteFor_Iternal(span);
|
||||
ArraySortHalperX<int>.Sort(_filteredEntities, comparison, _filteredEntitiesCount);
|
||||
return new EcsSpan(World.id, _filteredEntities, _filteredEntitiesCount);
|
||||
return new EcsSpan(World.ID, _filteredEntities, _filteredEntitiesCount);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ namespace DCFApixels.DragonECS.Internal
|
||||
{
|
||||
#if (DEBUG && !DISABLE_DEBUG) || ENABLE_DRAGONECS_ASSERT_CHEKS
|
||||
if (span.IsNull) { Throw.ArgumentNull(nameof(span)); }
|
||||
if (span.WorldID != World.id) { Throw.Quiery_ArgumentDifferentWorldsException(); }
|
||||
if (span.WorldID != World.ID) { Throw.Quiery_ArgumentDifferentWorldsException(); }
|
||||
#endif
|
||||
if (_filteredGroup == null)
|
||||
{
|
||||
|
@ -1,4 +1,7 @@
|
||||
namespace DCFApixels.DragonECS
|
||||
{
|
||||
public enum EcsTypeCode : int { }
|
||||
public enum EcsTypeCode : int
|
||||
{
|
||||
NULL = 0,
|
||||
}
|
||||
}
|
||||
|
@ -9,13 +9,13 @@ namespace DCFApixels.DragonECS
|
||||
public static int NewEntity(this EcsWorld world, ITemplateNode template)
|
||||
{
|
||||
int e = world.NewEntity();
|
||||
template.Apply(world.id, e);
|
||||
template.Apply(world.ID, e);
|
||||
return e;
|
||||
}
|
||||
public static entlong NewEntityLong(this EcsWorld world, ITemplateNode template)
|
||||
{
|
||||
entlong e = world.NewEntityLong();
|
||||
template.Apply(world.id, e.ID);
|
||||
template.Apply(world.ID, e.ID);
|
||||
return e;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user