mirror of
https://github.com/DCFApixels/DragonECS.git
synced 2025-09-18 18:14:37 +08:00
refactoring
This commit is contained in:
parent
7977f4d059
commit
c5ac114853
@ -61,9 +61,10 @@ namespace DCFApixels.DragonECS
|
|||||||
return $"{type.Name}({string.Join(", ", values)})";
|
return $"{type.Name}({string.Join(", ", values)})";
|
||||||
else
|
else
|
||||||
return $"({string.Join(", ", values)})";
|
return $"({string.Join(", ", values)})";
|
||||||
#endif
|
#else
|
||||||
EcsDebug.PrintWarning($"Reflection is not available, the {nameof(AutoToString)} method does not work.");
|
EcsDebug.PrintWarning($"Reflection is not available, the {nameof(AutoToString)} method does not work.");
|
||||||
return string.Empty;
|
return string.Empty;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
@ -207,7 +207,7 @@ namespace DCFApixels.DragonECS
|
|||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
private void CreateConcreteEntity(int entityID)
|
private void CreateConcreteEntity(int entityID)
|
||||||
{
|
{
|
||||||
unchecked { _version++; }
|
UpVersionLeaked();
|
||||||
_entitiesCount++;
|
_entitiesCount++;
|
||||||
if (_entitiesCapacity <= entityID)
|
if (_entitiesCapacity <= entityID)
|
||||||
{
|
{
|
||||||
@ -235,16 +235,9 @@ namespace DCFApixels.DragonECS
|
|||||||
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
|
||||||
if (IsUsed(entityID) == false)
|
if (IsUsed(entityID) == false) { Throw.World_EntityIsNotContained(entityID); }
|
||||||
{
|
|
||||||
Throw.World_EntityIsNotContained(entityID);
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
unchecked
|
UpVersion();
|
||||||
{
|
|
||||||
_version++;
|
|
||||||
_deleteLeakedEntitesLastVersion++;
|
|
||||||
}
|
|
||||||
_delEntBuffer[_delEntBufferCount++] = entityID;
|
_delEntBuffer[_delEntBufferCount++] = entityID;
|
||||||
_gens[entityID] |= DEATH_GEN_BIT;
|
_gens[entityID] |= DEATH_GEN_BIT;
|
||||||
_entitiesCount--;
|
_entitiesCount--;
|
||||||
@ -293,12 +286,16 @@ namespace DCFApixels.DragonECS
|
|||||||
for (int i = 0, iMax = mask.incChunckMasks.Length; i < iMax; i++)
|
for (int i = 0, iMax = mask.incChunckMasks.Length; i < iMax; i++)
|
||||||
{
|
{
|
||||||
if (!_pools[mask.inc[i]].Has(entityID))
|
if (!_pools[mask.inc[i]].Has(entityID))
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
for (int i = 0, iMax = mask.excChunckMasks.Length; i < iMax; i++)
|
for (int i = 0, iMax = mask.excChunckMasks.Length; i < iMax; i++)
|
||||||
{
|
{
|
||||||
if (_pools[mask.exc[i]].Has(entityID))
|
if (_pools[mask.exc[i]].Has(entityID))
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -333,7 +330,9 @@ namespace DCFApixels.DragonECS
|
|||||||
foreach (var pool in _pools)
|
foreach (var pool in _pools)
|
||||||
{
|
{
|
||||||
if (pool.Has(fromEntityID))
|
if (pool.Has(fromEntityID))
|
||||||
|
{
|
||||||
pool.Copy(fromEntityID, toEntityID);
|
pool.Copy(fromEntityID, toEntityID);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public void CopyEntity(int fromEntityID, EcsWorld toWorld, int toEntityID)
|
public void CopyEntity(int fromEntityID, EcsWorld toWorld, int toEntityID)
|
||||||
@ -341,7 +340,9 @@ namespace DCFApixels.DragonECS
|
|||||||
foreach (var pool in _pools)
|
foreach (var pool in _pools)
|
||||||
{
|
{
|
||||||
if (pool.Has(fromEntityID))
|
if (pool.Has(fromEntityID))
|
||||||
|
{
|
||||||
pool.Copy(fromEntityID, toWorld, toEntityID);
|
pool.Copy(fromEntityID, toWorld, toEntityID);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public int CloneEntity(int fromEntityID)
|
public int CloneEntity(int fromEntityID)
|
||||||
@ -362,7 +363,9 @@ namespace DCFApixels.DragonECS
|
|||||||
foreach (var pool in _pools)
|
foreach (var pool in _pools)
|
||||||
{
|
{
|
||||||
if (!pool.Has(fromEntityID) && pool.Has(toEntityID))
|
if (!pool.Has(fromEntityID) && pool.Has(toEntityID))
|
||||||
|
{
|
||||||
pool.Del(toEntityID);
|
pool.Del(toEntityID);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//public void CloneEntity(int fromEntityID, EcsWorld toWorld, int toEntityID)
|
//public void CloneEntity(int fromEntityID, EcsWorld toWorld, int toEntityID)
|
||||||
@ -396,7 +399,6 @@ namespace DCFApixels.DragonECS
|
|||||||
{
|
{
|
||||||
ReleaseDelEntityBuffer(_delEntBufferCount);
|
ReleaseDelEntityBuffer(_delEntBufferCount);
|
||||||
}
|
}
|
||||||
//private UnsafeArray<int> _delBufferFilter = new UnsafeArray<int>(8);
|
|
||||||
public unsafe void ReleaseDelEntityBuffer(int count)
|
public unsafe void ReleaseDelEntityBuffer(int count)
|
||||||
{
|
{
|
||||||
if (_delEntBufferCount <= 0)
|
if (_delEntBufferCount <= 0)
|
||||||
@ -501,7 +503,7 @@ namespace DCFApixels.DragonECS
|
|||||||
internal void ReleaseGroup(EcsGroup group)
|
internal void ReleaseGroup(EcsGroup group)
|
||||||
{
|
{
|
||||||
#if (DEBUG && !DISABLE_DEBUG) || !DISABLE_DRAGONECS_ASSERT_CHEKS
|
#if (DEBUG && !DISABLE_DEBUG) || !DISABLE_DRAGONECS_ASSERT_CHEKS
|
||||||
if (group.World != this) Throw.World_GroupDoesNotBelongWorld();
|
if (group.World != this) { Throw.World_GroupDoesNotBelongWorld(); }
|
||||||
#endif
|
#endif
|
||||||
group._isReleased = true;
|
group._isReleased = true;
|
||||||
group.Clear();
|
group.Clear();
|
||||||
@ -530,7 +532,18 @@ namespace DCFApixels.DragonECS
|
|||||||
|
|
||||||
#region Other
|
#region Other
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public void AggressiveUpVersion()
|
public void AggressiveUpVersion() { UpVersion(); }
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
private void UpVersion()
|
||||||
|
{
|
||||||
|
unchecked
|
||||||
|
{
|
||||||
|
_version++;
|
||||||
|
_deleteLeakedEntitesLastVersion++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
private void UpVersionLeaked()
|
||||||
{
|
{
|
||||||
unchecked
|
unchecked
|
||||||
{
|
{
|
||||||
@ -551,7 +564,9 @@ namespace DCFApixels.DragonECS
|
|||||||
itemsCount--;
|
itemsCount--;
|
||||||
list.Add(_pools[i].GetRaw(entityID));
|
list.Add(_pools[i].GetRaw(entityID));
|
||||||
if (itemsCount <= 0)
|
if (itemsCount <= 0)
|
||||||
|
{
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -566,7 +581,9 @@ namespace DCFApixels.DragonECS
|
|||||||
itemsCount--;
|
itemsCount--;
|
||||||
typeSet.Add(_pools[i].ComponentType);
|
typeSet.Add(_pools[i].ComponentType);
|
||||||
if (itemsCount <= 0)
|
if (itemsCount <= 0)
|
||||||
|
{
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -590,27 +607,42 @@ namespace DCFApixels.DragonECS
|
|||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static void InvokeOnWorldResize(this List<IEcsWorldEventListener> self, int newSize)
|
public static void InvokeOnWorldResize(this List<IEcsWorldEventListener> self, int newSize)
|
||||||
{
|
{
|
||||||
for (int i = 0, iMax = self.Count; i < iMax; i++) self[i].OnWorldResize(newSize);
|
for (int i = 0, iMax = self.Count; i < iMax; i++)
|
||||||
|
{
|
||||||
|
self[i].OnWorldResize(newSize);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static void InvokeOnReleaseDelEntityBuffer(this List<IEcsWorldEventListener> self, ReadOnlySpan<int> buffer)
|
public static void InvokeOnReleaseDelEntityBuffer(this List<IEcsWorldEventListener> self, ReadOnlySpan<int> buffer)
|
||||||
{
|
{
|
||||||
for (int i = 0, iMax = self.Count; i < iMax; i++) self[i].OnReleaseDelEntityBuffer(buffer);
|
for (int i = 0, iMax = self.Count; i < iMax; i++)
|
||||||
|
{
|
||||||
|
self[i].OnReleaseDelEntityBuffer(buffer);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static void InvokeOnWorldDestroy(this List<IEcsWorldEventListener> self)
|
public static void InvokeOnWorldDestroy(this List<IEcsWorldEventListener> self)
|
||||||
{
|
{
|
||||||
for (int i = 0, iMax = self.Count; i < iMax; i++) self[i].OnWorldDestroy();
|
for (int i = 0, iMax = self.Count; i < iMax; i++)
|
||||||
|
{
|
||||||
|
self[i].OnWorldDestroy();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static void InvokeOnNewEntity(this List<IEcsEntityEventListener> self, int entityID)
|
public static void InvokeOnNewEntity(this List<IEcsEntityEventListener> self, int entityID)
|
||||||
{
|
{
|
||||||
for (int i = 0, iMax = self.Count; i < iMax; i++) self[i].OnNewEntity(entityID);
|
for (int i = 0, iMax = self.Count; i < iMax; i++)
|
||||||
|
{
|
||||||
|
self[i].OnNewEntity(entityID);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static void InvokeOnDelEntity(this List<IEcsEntityEventListener> self, int entityID)
|
public static void InvokeOnDelEntity(this List<IEcsEntityEventListener> self, int entityID)
|
||||||
{
|
{
|
||||||
for (int i = 0, iMax = self.Count; i < iMax; i++) self[i].OnDelEntity(entityID);
|
for (int i = 0, iMax = self.Count; i < iMax; i++)
|
||||||
|
{
|
||||||
|
self[i].OnDelEntity(entityID);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
@ -619,7 +651,10 @@ namespace DCFApixels.DragonECS
|
|||||||
public static class IntExtensions
|
public static class IntExtensions
|
||||||
{
|
{
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static entlong ToEntityLong(this int self, EcsWorld world) => world.GetEntityLong(self);
|
public static entlong ToEntityLong(this int self, EcsWorld world)
|
||||||
|
{
|
||||||
|
return world.GetEntityLong(self);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user