forked from Misaki/GhostEngine
Update version support
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using Ghost.Core;
|
||||
using Misaki.HighPerformance.LowLevel;
|
||||
using Misaki.HighPerformance.LowLevel.Buffer;
|
||||
using Misaki.HighPerformance.LowLevel.Collections;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
@@ -10,7 +11,7 @@ public unsafe partial struct EntityQuery
|
||||
public readonly ref struct ComponentIterator<T0>
|
||||
where T0 : unmanaged, IComponent
|
||||
{
|
||||
public ref struct Enumerator
|
||||
public ref struct Enumerator : IDisposable
|
||||
{
|
||||
private fixed int _compTypeIDs[1];
|
||||
private fixed int _offsets[1];
|
||||
@@ -19,6 +20,10 @@ public unsafe partial struct EntityQuery
|
||||
private readonly ReadOnlyUnsafeCollection<Identifier<Archetype>> _matchingArchetypes;
|
||||
private readonly EntityQueryMask _mask;
|
||||
private readonly World _world;
|
||||
private readonly int _currentVersion;
|
||||
|
||||
private readonly Stack.Scope _scope;
|
||||
private UnsafeList<int> _changedComponentIDs;
|
||||
|
||||
private ref Archetype _currentArchetype;
|
||||
private ref Chunk _currentChunk;
|
||||
@@ -39,6 +44,22 @@ public unsafe partial struct EntityQuery
|
||||
_mask = mask;
|
||||
_world = world;
|
||||
|
||||
_scope = AllocationManager.CreateStackScope();
|
||||
_changedComponentIDs = new UnsafeList<int>(1, _scope.AllocationHandle);
|
||||
|
||||
var it = _mask.writeAccess.GetIterator();
|
||||
while (it.Next(out var id))
|
||||
{
|
||||
for (var i = 0; i < 1; i++)
|
||||
{
|
||||
if (id == _compTypeIDs[i])
|
||||
{
|
||||
_changedComponentIDs.Add(id);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reset();
|
||||
}
|
||||
|
||||
@@ -58,6 +79,11 @@ public unsafe partial struct EntityQuery
|
||||
_offsets[index] = layout.offset;
|
||||
_compBasePtrs[index] = (long)(_chunkBasePtr + _offsets[index]);
|
||||
}
|
||||
|
||||
for (var i = 0; i < _changedComponentIDs.Count; i++)
|
||||
{
|
||||
_currentArchetype.MarkChanged(_currentChunkIndex, _changedComponentIDs[i], _world.Version);
|
||||
}
|
||||
}
|
||||
|
||||
public bool MoveNext()
|
||||
@@ -124,6 +150,11 @@ public unsafe partial struct EntityQuery
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public readonly void Dispose()
|
||||
{
|
||||
_scope.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
private readonly ReadOnlyUnsafeCollection<Identifier<Archetype>> _matchingArchetypes;
|
||||
@@ -170,7 +201,7 @@ public unsafe partial struct EntityQuery
|
||||
}
|
||||
}
|
||||
|
||||
public ref struct Enumerator
|
||||
public ref struct Enumerator : IDisposable
|
||||
{
|
||||
private fixed int _compTypeIDs[2];
|
||||
private fixed int _offsets[2];
|
||||
@@ -179,6 +210,10 @@ public unsafe partial struct EntityQuery
|
||||
private readonly ReadOnlyUnsafeCollection<Identifier<Archetype>> _matchingArchetypes;
|
||||
private readonly EntityQueryMask _mask;
|
||||
private readonly World _world;
|
||||
private readonly int _currentVersion;
|
||||
|
||||
private readonly Stack.Scope _scope;
|
||||
private UnsafeList<int> _changedComponentIDs;
|
||||
|
||||
private ref Archetype _currentArchetype;
|
||||
private ref Chunk _currentChunk;
|
||||
@@ -203,6 +238,22 @@ public unsafe partial struct EntityQuery
|
||||
_mask = mask;
|
||||
_world = world;
|
||||
|
||||
_scope = AllocationManager.CreateStackScope();
|
||||
_changedComponentIDs = new UnsafeList<int>(2, _scope.AllocationHandle);
|
||||
|
||||
var it = _mask.writeAccess.GetIterator();
|
||||
while (it.Next(out var id))
|
||||
{
|
||||
for (var i = 0; i < 2; i++)
|
||||
{
|
||||
if (id == _compTypeIDs[i])
|
||||
{
|
||||
_changedComponentIDs.Add(id);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reset();
|
||||
}
|
||||
|
||||
@@ -225,6 +276,11 @@ public unsafe partial struct EntityQuery
|
||||
_offsets[index] = layout.offset;
|
||||
_compBasePtrs[index] = (long)(_chunkBasePtr + _offsets[index]);
|
||||
}
|
||||
|
||||
for (var i = 0; i < _changedComponentIDs.Count; i++)
|
||||
{
|
||||
_currentArchetype.MarkChanged(_currentChunkIndex, _changedComponentIDs[i], _world.Version);
|
||||
}
|
||||
}
|
||||
|
||||
public bool MoveNext()
|
||||
@@ -291,6 +347,11 @@ public unsafe partial struct EntityQuery
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public readonly void Dispose()
|
||||
{
|
||||
_scope.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
private readonly ReadOnlyUnsafeCollection<Identifier<Archetype>> _matchingArchetypes;
|
||||
@@ -342,7 +403,7 @@ public unsafe partial struct EntityQuery
|
||||
}
|
||||
}
|
||||
|
||||
public ref struct Enumerator
|
||||
public ref struct Enumerator : IDisposable
|
||||
{
|
||||
private fixed int _compTypeIDs[3];
|
||||
private fixed int _offsets[3];
|
||||
@@ -351,6 +412,10 @@ public unsafe partial struct EntityQuery
|
||||
private readonly ReadOnlyUnsafeCollection<Identifier<Archetype>> _matchingArchetypes;
|
||||
private readonly EntityQueryMask _mask;
|
||||
private readonly World _world;
|
||||
private readonly int _currentVersion;
|
||||
|
||||
private readonly Stack.Scope _scope;
|
||||
private UnsafeList<int> _changedComponentIDs;
|
||||
|
||||
private ref Archetype _currentArchetype;
|
||||
private ref Chunk _currentChunk;
|
||||
@@ -379,6 +444,22 @@ public unsafe partial struct EntityQuery
|
||||
_mask = mask;
|
||||
_world = world;
|
||||
|
||||
_scope = AllocationManager.CreateStackScope();
|
||||
_changedComponentIDs = new UnsafeList<int>(3, _scope.AllocationHandle);
|
||||
|
||||
var it = _mask.writeAccess.GetIterator();
|
||||
while (it.Next(out var id))
|
||||
{
|
||||
for (var i = 0; i < 3; i++)
|
||||
{
|
||||
if (id == _compTypeIDs[i])
|
||||
{
|
||||
_changedComponentIDs.Add(id);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reset();
|
||||
}
|
||||
|
||||
@@ -402,6 +483,11 @@ public unsafe partial struct EntityQuery
|
||||
_offsets[index] = layout.offset;
|
||||
_compBasePtrs[index] = (long)(_chunkBasePtr + _offsets[index]);
|
||||
}
|
||||
|
||||
for (var i = 0; i < _changedComponentIDs.Count; i++)
|
||||
{
|
||||
_currentArchetype.MarkChanged(_currentChunkIndex, _changedComponentIDs[i], _world.Version);
|
||||
}
|
||||
}
|
||||
|
||||
public bool MoveNext()
|
||||
@@ -468,6 +554,11 @@ public unsafe partial struct EntityQuery
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public readonly void Dispose()
|
||||
{
|
||||
_scope.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
private readonly ReadOnlyUnsafeCollection<Identifier<Archetype>> _matchingArchetypes;
|
||||
@@ -524,7 +615,7 @@ public unsafe partial struct EntityQuery
|
||||
}
|
||||
}
|
||||
|
||||
public ref struct Enumerator
|
||||
public ref struct Enumerator : IDisposable
|
||||
{
|
||||
private fixed int _compTypeIDs[4];
|
||||
private fixed int _offsets[4];
|
||||
@@ -533,6 +624,10 @@ public unsafe partial struct EntityQuery
|
||||
private readonly ReadOnlyUnsafeCollection<Identifier<Archetype>> _matchingArchetypes;
|
||||
private readonly EntityQueryMask _mask;
|
||||
private readonly World _world;
|
||||
private readonly int _currentVersion;
|
||||
|
||||
private readonly Stack.Scope _scope;
|
||||
private UnsafeList<int> _changedComponentIDs;
|
||||
|
||||
private ref Archetype _currentArchetype;
|
||||
private ref Chunk _currentChunk;
|
||||
@@ -565,6 +660,22 @@ public unsafe partial struct EntityQuery
|
||||
_mask = mask;
|
||||
_world = world;
|
||||
|
||||
_scope = AllocationManager.CreateStackScope();
|
||||
_changedComponentIDs = new UnsafeList<int>(4, _scope.AllocationHandle);
|
||||
|
||||
var it = _mask.writeAccess.GetIterator();
|
||||
while (it.Next(out var id))
|
||||
{
|
||||
for (var i = 0; i < 4; i++)
|
||||
{
|
||||
if (id == _compTypeIDs[i])
|
||||
{
|
||||
_changedComponentIDs.Add(id);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reset();
|
||||
}
|
||||
|
||||
@@ -589,6 +700,11 @@ public unsafe partial struct EntityQuery
|
||||
_offsets[index] = layout.offset;
|
||||
_compBasePtrs[index] = (long)(_chunkBasePtr + _offsets[index]);
|
||||
}
|
||||
|
||||
for (var i = 0; i < _changedComponentIDs.Count; i++)
|
||||
{
|
||||
_currentArchetype.MarkChanged(_currentChunkIndex, _changedComponentIDs[i], _world.Version);
|
||||
}
|
||||
}
|
||||
|
||||
public bool MoveNext()
|
||||
@@ -655,6 +771,11 @@ public unsafe partial struct EntityQuery
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public readonly void Dispose()
|
||||
{
|
||||
_scope.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
private readonly ReadOnlyUnsafeCollection<Identifier<Archetype>> _matchingArchetypes;
|
||||
@@ -716,7 +837,7 @@ public unsafe partial struct EntityQuery
|
||||
}
|
||||
}
|
||||
|
||||
public ref struct Enumerator
|
||||
public ref struct Enumerator : IDisposable
|
||||
{
|
||||
private fixed int _compTypeIDs[5];
|
||||
private fixed int _offsets[5];
|
||||
@@ -725,6 +846,10 @@ public unsafe partial struct EntityQuery
|
||||
private readonly ReadOnlyUnsafeCollection<Identifier<Archetype>> _matchingArchetypes;
|
||||
private readonly EntityQueryMask _mask;
|
||||
private readonly World _world;
|
||||
private readonly int _currentVersion;
|
||||
|
||||
private readonly Stack.Scope _scope;
|
||||
private UnsafeList<int> _changedComponentIDs;
|
||||
|
||||
private ref Archetype _currentArchetype;
|
||||
private ref Chunk _currentChunk;
|
||||
@@ -761,6 +886,22 @@ public unsafe partial struct EntityQuery
|
||||
_mask = mask;
|
||||
_world = world;
|
||||
|
||||
_scope = AllocationManager.CreateStackScope();
|
||||
_changedComponentIDs = new UnsafeList<int>(5, _scope.AllocationHandle);
|
||||
|
||||
var it = _mask.writeAccess.GetIterator();
|
||||
while (it.Next(out var id))
|
||||
{
|
||||
for (var i = 0; i < 5; i++)
|
||||
{
|
||||
if (id == _compTypeIDs[i])
|
||||
{
|
||||
_changedComponentIDs.Add(id);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reset();
|
||||
}
|
||||
|
||||
@@ -786,6 +927,11 @@ public unsafe partial struct EntityQuery
|
||||
_offsets[index] = layout.offset;
|
||||
_compBasePtrs[index] = (long)(_chunkBasePtr + _offsets[index]);
|
||||
}
|
||||
|
||||
for (var i = 0; i < _changedComponentIDs.Count; i++)
|
||||
{
|
||||
_currentArchetype.MarkChanged(_currentChunkIndex, _changedComponentIDs[i], _world.Version);
|
||||
}
|
||||
}
|
||||
|
||||
public bool MoveNext()
|
||||
@@ -852,6 +998,11 @@ public unsafe partial struct EntityQuery
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public readonly void Dispose()
|
||||
{
|
||||
_scope.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
private readonly ReadOnlyUnsafeCollection<Identifier<Archetype>> _matchingArchetypes;
|
||||
@@ -918,7 +1069,7 @@ public unsafe partial struct EntityQuery
|
||||
}
|
||||
}
|
||||
|
||||
public ref struct Enumerator
|
||||
public ref struct Enumerator : IDisposable
|
||||
{
|
||||
private fixed int _compTypeIDs[6];
|
||||
private fixed int _offsets[6];
|
||||
@@ -927,6 +1078,10 @@ public unsafe partial struct EntityQuery
|
||||
private readonly ReadOnlyUnsafeCollection<Identifier<Archetype>> _matchingArchetypes;
|
||||
private readonly EntityQueryMask _mask;
|
||||
private readonly World _world;
|
||||
private readonly int _currentVersion;
|
||||
|
||||
private readonly Stack.Scope _scope;
|
||||
private UnsafeList<int> _changedComponentIDs;
|
||||
|
||||
private ref Archetype _currentArchetype;
|
||||
private ref Chunk _currentChunk;
|
||||
@@ -967,6 +1122,22 @@ public unsafe partial struct EntityQuery
|
||||
_mask = mask;
|
||||
_world = world;
|
||||
|
||||
_scope = AllocationManager.CreateStackScope();
|
||||
_changedComponentIDs = new UnsafeList<int>(6, _scope.AllocationHandle);
|
||||
|
||||
var it = _mask.writeAccess.GetIterator();
|
||||
while (it.Next(out var id))
|
||||
{
|
||||
for (var i = 0; i < 6; i++)
|
||||
{
|
||||
if (id == _compTypeIDs[i])
|
||||
{
|
||||
_changedComponentIDs.Add(id);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reset();
|
||||
}
|
||||
|
||||
@@ -993,6 +1164,11 @@ public unsafe partial struct EntityQuery
|
||||
_offsets[index] = layout.offset;
|
||||
_compBasePtrs[index] = (long)(_chunkBasePtr + _offsets[index]);
|
||||
}
|
||||
|
||||
for (var i = 0; i < _changedComponentIDs.Count; i++)
|
||||
{
|
||||
_currentArchetype.MarkChanged(_currentChunkIndex, _changedComponentIDs[i], _world.Version);
|
||||
}
|
||||
}
|
||||
|
||||
public bool MoveNext()
|
||||
@@ -1059,6 +1235,11 @@ public unsafe partial struct EntityQuery
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public readonly void Dispose()
|
||||
{
|
||||
_scope.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
private readonly ReadOnlyUnsafeCollection<Identifier<Archetype>> _matchingArchetypes;
|
||||
@@ -1130,7 +1311,7 @@ public unsafe partial struct EntityQuery
|
||||
}
|
||||
}
|
||||
|
||||
public ref struct Enumerator
|
||||
public ref struct Enumerator : IDisposable
|
||||
{
|
||||
private fixed int _compTypeIDs[7];
|
||||
private fixed int _offsets[7];
|
||||
@@ -1139,6 +1320,10 @@ public unsafe partial struct EntityQuery
|
||||
private readonly ReadOnlyUnsafeCollection<Identifier<Archetype>> _matchingArchetypes;
|
||||
private readonly EntityQueryMask _mask;
|
||||
private readonly World _world;
|
||||
private readonly int _currentVersion;
|
||||
|
||||
private readonly Stack.Scope _scope;
|
||||
private UnsafeList<int> _changedComponentIDs;
|
||||
|
||||
private ref Archetype _currentArchetype;
|
||||
private ref Chunk _currentChunk;
|
||||
@@ -1183,6 +1368,22 @@ public unsafe partial struct EntityQuery
|
||||
_mask = mask;
|
||||
_world = world;
|
||||
|
||||
_scope = AllocationManager.CreateStackScope();
|
||||
_changedComponentIDs = new UnsafeList<int>(7, _scope.AllocationHandle);
|
||||
|
||||
var it = _mask.writeAccess.GetIterator();
|
||||
while (it.Next(out var id))
|
||||
{
|
||||
for (var i = 0; i < 7; i++)
|
||||
{
|
||||
if (id == _compTypeIDs[i])
|
||||
{
|
||||
_changedComponentIDs.Add(id);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reset();
|
||||
}
|
||||
|
||||
@@ -1210,6 +1411,11 @@ public unsafe partial struct EntityQuery
|
||||
_offsets[index] = layout.offset;
|
||||
_compBasePtrs[index] = (long)(_chunkBasePtr + _offsets[index]);
|
||||
}
|
||||
|
||||
for (var i = 0; i < _changedComponentIDs.Count; i++)
|
||||
{
|
||||
_currentArchetype.MarkChanged(_currentChunkIndex, _changedComponentIDs[i], _world.Version);
|
||||
}
|
||||
}
|
||||
|
||||
public bool MoveNext()
|
||||
@@ -1276,6 +1482,11 @@ public unsafe partial struct EntityQuery
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public readonly void Dispose()
|
||||
{
|
||||
_scope.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
private readonly ReadOnlyUnsafeCollection<Identifier<Archetype>> _matchingArchetypes;
|
||||
@@ -1352,7 +1563,7 @@ public unsafe partial struct EntityQuery
|
||||
}
|
||||
}
|
||||
|
||||
public ref struct Enumerator
|
||||
public ref struct Enumerator : IDisposable
|
||||
{
|
||||
private fixed int _compTypeIDs[8];
|
||||
private fixed int _offsets[8];
|
||||
@@ -1361,6 +1572,10 @@ public unsafe partial struct EntityQuery
|
||||
private readonly ReadOnlyUnsafeCollection<Identifier<Archetype>> _matchingArchetypes;
|
||||
private readonly EntityQueryMask _mask;
|
||||
private readonly World _world;
|
||||
private readonly int _currentVersion;
|
||||
|
||||
private readonly Stack.Scope _scope;
|
||||
private UnsafeList<int> _changedComponentIDs;
|
||||
|
||||
private ref Archetype _currentArchetype;
|
||||
private ref Chunk _currentChunk;
|
||||
@@ -1409,6 +1624,22 @@ public unsafe partial struct EntityQuery
|
||||
_mask = mask;
|
||||
_world = world;
|
||||
|
||||
_scope = AllocationManager.CreateStackScope();
|
||||
_changedComponentIDs = new UnsafeList<int>(8, _scope.AllocationHandle);
|
||||
|
||||
var it = _mask.writeAccess.GetIterator();
|
||||
while (it.Next(out var id))
|
||||
{
|
||||
for (var i = 0; i < 8; i++)
|
||||
{
|
||||
if (id == _compTypeIDs[i])
|
||||
{
|
||||
_changedComponentIDs.Add(id);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reset();
|
||||
}
|
||||
|
||||
@@ -1437,6 +1668,11 @@ public unsafe partial struct EntityQuery
|
||||
_offsets[index] = layout.offset;
|
||||
_compBasePtrs[index] = (long)(_chunkBasePtr + _offsets[index]);
|
||||
}
|
||||
|
||||
for (var i = 0; i < _changedComponentIDs.Count; i++)
|
||||
{
|
||||
_currentArchetype.MarkChanged(_currentChunkIndex, _changedComponentIDs[i], _world.Version);
|
||||
}
|
||||
}
|
||||
|
||||
public bool MoveNext()
|
||||
@@ -1503,6 +1739,11 @@ public unsafe partial struct EntityQuery
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public readonly void Dispose()
|
||||
{
|
||||
_scope.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
private readonly ReadOnlyUnsafeCollection<Identifier<Archetype>> _matchingArchetypes;
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
<#@ include file="Helpers.ttinclude" #>
|
||||
using Ghost.Core;
|
||||
using Misaki.HighPerformance.LowLevel;
|
||||
using Misaki.HighPerformance.LowLevel.Buffer;
|
||||
using Misaki.HighPerformance.LowLevel.Collections;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
@@ -45,7 +46,7 @@ public unsafe partial struct EntityQuery
|
||||
}
|
||||
|
||||
<# } #>
|
||||
public ref struct Enumerator
|
||||
public ref struct Enumerator : IDisposable
|
||||
{
|
||||
private fixed int _compTypeIDs[<#= i #>];
|
||||
private fixed int _offsets[<#= i #>];
|
||||
@@ -54,6 +55,10 @@ public unsafe partial struct EntityQuery
|
||||
private readonly ReadOnlyUnsafeCollection<Identifier<Archetype>> _matchingArchetypes;
|
||||
private readonly EntityQueryMask _mask;
|
||||
private readonly World _world;
|
||||
private readonly int _currentVersion;
|
||||
|
||||
private readonly Stack.Scope _scope;
|
||||
private UnsafeList<int> _changedComponentIDs;
|
||||
|
||||
private ref Archetype _currentArchetype;
|
||||
private ref Chunk _currentChunk;
|
||||
@@ -76,6 +81,22 @@ public unsafe partial struct EntityQuery
|
||||
_mask = mask;
|
||||
_world = world;
|
||||
|
||||
_scope = AllocationManager.CreateStackScope();
|
||||
_changedComponentIDs = new UnsafeList<int>(<#= i #>, _scope.AllocationHandle);
|
||||
|
||||
var it = _mask.writeAccess.GetIterator();
|
||||
while (it.Next(out var id))
|
||||
{
|
||||
for (var i = 0; i < <#= i #>; i++)
|
||||
{
|
||||
if (id == _compTypeIDs[i])
|
||||
{
|
||||
_changedComponentIDs.Add(id);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reset();
|
||||
}
|
||||
|
||||
@@ -103,6 +124,11 @@ public unsafe partial struct EntityQuery
|
||||
_offsets[index] = layout.offset;
|
||||
_compBasePtrs[index] = (long)(_chunkBasePtr + _offsets[index]);
|
||||
}
|
||||
|
||||
for (var i = 0; i < _changedComponentIDs.Count; i++)
|
||||
{
|
||||
_currentArchetype.MarkChanged(_currentChunkIndex, _changedComponentIDs[i], _world.Version);
|
||||
}
|
||||
}
|
||||
|
||||
public bool MoveNext()
|
||||
@@ -169,6 +195,11 @@ public unsafe partial struct EntityQuery
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public readonly void Dispose()
|
||||
{
|
||||
_scope.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
private readonly ReadOnlyUnsafeCollection<Identifier<Archetype>> _matchingArchetypes;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using Ghost.Core;
|
||||
using Misaki.HighPerformance.LowLevel;
|
||||
using Misaki.HighPerformance.LowLevel.Buffer;
|
||||
using Misaki.HighPerformance.LowLevel.Collections;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
@@ -30,7 +31,7 @@ public unsafe partial struct EntityQuery
|
||||
}
|
||||
}
|
||||
|
||||
public ref struct Enumerator
|
||||
public ref struct Enumerator : IDisposable
|
||||
{
|
||||
private fixed int _compTypeIDs[1];
|
||||
private fixed int _offsets[1];
|
||||
@@ -40,6 +41,9 @@ public unsafe partial struct EntityQuery
|
||||
private readonly EntityQueryMask _mask;
|
||||
private readonly World _world;
|
||||
|
||||
private readonly Stack.Scope _scope;
|
||||
private UnsafeList<int> _changedComponentIDs;
|
||||
|
||||
private ref Archetype _currentArchetype;
|
||||
private ref Chunk _currentChunk;
|
||||
private byte* _chunkBasePtr;
|
||||
@@ -59,6 +63,22 @@ public unsafe partial struct EntityQuery
|
||||
_mask = mask;
|
||||
_world = world;
|
||||
|
||||
_scope = AllocationManager.CreateStackScope();
|
||||
_changedComponentIDs = new UnsafeList<int>(1, _scope.AllocationHandle);
|
||||
|
||||
var it = _mask.writeAccess.GetIterator();
|
||||
while (it.Next(out var id))
|
||||
{
|
||||
for (var i = 0; i < 1; i++)
|
||||
{
|
||||
if (id == _compTypeIDs[i])
|
||||
{
|
||||
_changedComponentIDs.Add(id);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reset();
|
||||
}
|
||||
|
||||
@@ -81,6 +101,11 @@ public unsafe partial struct EntityQuery
|
||||
_offsets[index] = layout.offset;
|
||||
_compBasePtrs[index] = (long)(_chunkBasePtr + _offsets[index]);
|
||||
}
|
||||
|
||||
for (var i = 0; i < _changedComponentIDs.Count; i++)
|
||||
{
|
||||
_currentArchetype.MarkChanged(_currentChunkIndex, _changedComponentIDs[i], _world.Version);
|
||||
}
|
||||
}
|
||||
|
||||
public bool MoveNext()
|
||||
@@ -147,6 +172,11 @@ public unsafe partial struct EntityQuery
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public readonly void Dispose()
|
||||
{
|
||||
_scope.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
private readonly ReadOnlyUnsafeCollection<Identifier<Archetype>> _matchingArchetypes;
|
||||
@@ -199,7 +229,7 @@ public unsafe partial struct EntityQuery
|
||||
}
|
||||
}
|
||||
|
||||
public ref struct Enumerator
|
||||
public ref struct Enumerator : IDisposable
|
||||
{
|
||||
private fixed int _compTypeIDs[2];
|
||||
private fixed int _offsets[2];
|
||||
@@ -209,6 +239,9 @@ public unsafe partial struct EntityQuery
|
||||
private readonly EntityQueryMask _mask;
|
||||
private readonly World _world;
|
||||
|
||||
private readonly Stack.Scope _scope;
|
||||
private UnsafeList<int> _changedComponentIDs;
|
||||
|
||||
private ref Archetype _currentArchetype;
|
||||
private ref Chunk _currentChunk;
|
||||
private byte* _chunkBasePtr;
|
||||
@@ -232,6 +265,22 @@ public unsafe partial struct EntityQuery
|
||||
_mask = mask;
|
||||
_world = world;
|
||||
|
||||
_scope = AllocationManager.CreateStackScope();
|
||||
_changedComponentIDs = new UnsafeList<int>(2, _scope.AllocationHandle);
|
||||
|
||||
var it = _mask.writeAccess.GetIterator();
|
||||
while (it.Next(out var id))
|
||||
{
|
||||
for (var i = 0; i < 2; i++)
|
||||
{
|
||||
if (id == _compTypeIDs[i])
|
||||
{
|
||||
_changedComponentIDs.Add(id);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reset();
|
||||
}
|
||||
|
||||
@@ -255,6 +304,11 @@ public unsafe partial struct EntityQuery
|
||||
_offsets[index] = layout.offset;
|
||||
_compBasePtrs[index] = (long)(_chunkBasePtr + _offsets[index]);
|
||||
}
|
||||
|
||||
for (var i = 0; i < _changedComponentIDs.Count; i++)
|
||||
{
|
||||
_currentArchetype.MarkChanged(_currentChunkIndex, _changedComponentIDs[i], _world.Version);
|
||||
}
|
||||
}
|
||||
|
||||
public bool MoveNext()
|
||||
@@ -321,6 +375,11 @@ public unsafe partial struct EntityQuery
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public readonly void Dispose()
|
||||
{
|
||||
_scope.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
private readonly ReadOnlyUnsafeCollection<Identifier<Archetype>> _matchingArchetypes;
|
||||
@@ -378,7 +437,7 @@ public unsafe partial struct EntityQuery
|
||||
}
|
||||
}
|
||||
|
||||
public ref struct Enumerator
|
||||
public ref struct Enumerator : IDisposable
|
||||
{
|
||||
private fixed int _compTypeIDs[3];
|
||||
private fixed int _offsets[3];
|
||||
@@ -388,6 +447,9 @@ public unsafe partial struct EntityQuery
|
||||
private readonly EntityQueryMask _mask;
|
||||
private readonly World _world;
|
||||
|
||||
private readonly Stack.Scope _scope;
|
||||
private UnsafeList<int> _changedComponentIDs;
|
||||
|
||||
private ref Archetype _currentArchetype;
|
||||
private ref Chunk _currentChunk;
|
||||
private byte* _chunkBasePtr;
|
||||
@@ -415,6 +477,22 @@ public unsafe partial struct EntityQuery
|
||||
_mask = mask;
|
||||
_world = world;
|
||||
|
||||
_scope = AllocationManager.CreateStackScope();
|
||||
_changedComponentIDs = new UnsafeList<int>(3, _scope.AllocationHandle);
|
||||
|
||||
var it = _mask.writeAccess.GetIterator();
|
||||
while (it.Next(out var id))
|
||||
{
|
||||
for (var i = 0; i < 3; i++)
|
||||
{
|
||||
if (id == _compTypeIDs[i])
|
||||
{
|
||||
_changedComponentIDs.Add(id);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reset();
|
||||
}
|
||||
|
||||
@@ -439,6 +517,11 @@ public unsafe partial struct EntityQuery
|
||||
_offsets[index] = layout.offset;
|
||||
_compBasePtrs[index] = (long)(_chunkBasePtr + _offsets[index]);
|
||||
}
|
||||
|
||||
for (var i = 0; i < _changedComponentIDs.Count; i++)
|
||||
{
|
||||
_currentArchetype.MarkChanged(_currentChunkIndex, _changedComponentIDs[i], _world.Version);
|
||||
}
|
||||
}
|
||||
|
||||
public bool MoveNext()
|
||||
@@ -505,6 +588,11 @@ public unsafe partial struct EntityQuery
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public readonly void Dispose()
|
||||
{
|
||||
_scope.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
private readonly ReadOnlyUnsafeCollection<Identifier<Archetype>> _matchingArchetypes;
|
||||
@@ -567,7 +655,7 @@ public unsafe partial struct EntityQuery
|
||||
}
|
||||
}
|
||||
|
||||
public ref struct Enumerator
|
||||
public ref struct Enumerator : IDisposable
|
||||
{
|
||||
private fixed int _compTypeIDs[4];
|
||||
private fixed int _offsets[4];
|
||||
@@ -577,6 +665,9 @@ public unsafe partial struct EntityQuery
|
||||
private readonly EntityQueryMask _mask;
|
||||
private readonly World _world;
|
||||
|
||||
private readonly Stack.Scope _scope;
|
||||
private UnsafeList<int> _changedComponentIDs;
|
||||
|
||||
private ref Archetype _currentArchetype;
|
||||
private ref Chunk _currentChunk;
|
||||
private byte* _chunkBasePtr;
|
||||
@@ -608,6 +699,22 @@ public unsafe partial struct EntityQuery
|
||||
_mask = mask;
|
||||
_world = world;
|
||||
|
||||
_scope = AllocationManager.CreateStackScope();
|
||||
_changedComponentIDs = new UnsafeList<int>(4, _scope.AllocationHandle);
|
||||
|
||||
var it = _mask.writeAccess.GetIterator();
|
||||
while (it.Next(out var id))
|
||||
{
|
||||
for (var i = 0; i < 4; i++)
|
||||
{
|
||||
if (id == _compTypeIDs[i])
|
||||
{
|
||||
_changedComponentIDs.Add(id);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reset();
|
||||
}
|
||||
|
||||
@@ -633,6 +740,11 @@ public unsafe partial struct EntityQuery
|
||||
_offsets[index] = layout.offset;
|
||||
_compBasePtrs[index] = (long)(_chunkBasePtr + _offsets[index]);
|
||||
}
|
||||
|
||||
for (var i = 0; i < _changedComponentIDs.Count; i++)
|
||||
{
|
||||
_currentArchetype.MarkChanged(_currentChunkIndex, _changedComponentIDs[i], _world.Version);
|
||||
}
|
||||
}
|
||||
|
||||
public bool MoveNext()
|
||||
@@ -699,6 +811,11 @@ public unsafe partial struct EntityQuery
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public readonly void Dispose()
|
||||
{
|
||||
_scope.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
private readonly ReadOnlyUnsafeCollection<Identifier<Archetype>> _matchingArchetypes;
|
||||
@@ -766,7 +883,7 @@ public unsafe partial struct EntityQuery
|
||||
}
|
||||
}
|
||||
|
||||
public ref struct Enumerator
|
||||
public ref struct Enumerator : IDisposable
|
||||
{
|
||||
private fixed int _compTypeIDs[5];
|
||||
private fixed int _offsets[5];
|
||||
@@ -776,6 +893,9 @@ public unsafe partial struct EntityQuery
|
||||
private readonly EntityQueryMask _mask;
|
||||
private readonly World _world;
|
||||
|
||||
private readonly Stack.Scope _scope;
|
||||
private UnsafeList<int> _changedComponentIDs;
|
||||
|
||||
private ref Archetype _currentArchetype;
|
||||
private ref Chunk _currentChunk;
|
||||
private byte* _chunkBasePtr;
|
||||
@@ -811,6 +931,22 @@ public unsafe partial struct EntityQuery
|
||||
_mask = mask;
|
||||
_world = world;
|
||||
|
||||
_scope = AllocationManager.CreateStackScope();
|
||||
_changedComponentIDs = new UnsafeList<int>(5, _scope.AllocationHandle);
|
||||
|
||||
var it = _mask.writeAccess.GetIterator();
|
||||
while (it.Next(out var id))
|
||||
{
|
||||
for (var i = 0; i < 5; i++)
|
||||
{
|
||||
if (id == _compTypeIDs[i])
|
||||
{
|
||||
_changedComponentIDs.Add(id);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reset();
|
||||
}
|
||||
|
||||
@@ -837,6 +973,11 @@ public unsafe partial struct EntityQuery
|
||||
_offsets[index] = layout.offset;
|
||||
_compBasePtrs[index] = (long)(_chunkBasePtr + _offsets[index]);
|
||||
}
|
||||
|
||||
for (var i = 0; i < _changedComponentIDs.Count; i++)
|
||||
{
|
||||
_currentArchetype.MarkChanged(_currentChunkIndex, _changedComponentIDs[i], _world.Version);
|
||||
}
|
||||
}
|
||||
|
||||
public bool MoveNext()
|
||||
@@ -903,6 +1044,11 @@ public unsafe partial struct EntityQuery
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public readonly void Dispose()
|
||||
{
|
||||
_scope.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
private readonly ReadOnlyUnsafeCollection<Identifier<Archetype>> _matchingArchetypes;
|
||||
@@ -975,7 +1121,7 @@ public unsafe partial struct EntityQuery
|
||||
}
|
||||
}
|
||||
|
||||
public ref struct Enumerator
|
||||
public ref struct Enumerator : IDisposable
|
||||
{
|
||||
private fixed int _compTypeIDs[6];
|
||||
private fixed int _offsets[6];
|
||||
@@ -985,6 +1131,9 @@ public unsafe partial struct EntityQuery
|
||||
private readonly EntityQueryMask _mask;
|
||||
private readonly World _world;
|
||||
|
||||
private readonly Stack.Scope _scope;
|
||||
private UnsafeList<int> _changedComponentIDs;
|
||||
|
||||
private ref Archetype _currentArchetype;
|
||||
private ref Chunk _currentChunk;
|
||||
private byte* _chunkBasePtr;
|
||||
@@ -1024,6 +1173,22 @@ public unsafe partial struct EntityQuery
|
||||
_mask = mask;
|
||||
_world = world;
|
||||
|
||||
_scope = AllocationManager.CreateStackScope();
|
||||
_changedComponentIDs = new UnsafeList<int>(6, _scope.AllocationHandle);
|
||||
|
||||
var it = _mask.writeAccess.GetIterator();
|
||||
while (it.Next(out var id))
|
||||
{
|
||||
for (var i = 0; i < 6; i++)
|
||||
{
|
||||
if (id == _compTypeIDs[i])
|
||||
{
|
||||
_changedComponentIDs.Add(id);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reset();
|
||||
}
|
||||
|
||||
@@ -1051,6 +1216,11 @@ public unsafe partial struct EntityQuery
|
||||
_offsets[index] = layout.offset;
|
||||
_compBasePtrs[index] = (long)(_chunkBasePtr + _offsets[index]);
|
||||
}
|
||||
|
||||
for (var i = 0; i < _changedComponentIDs.Count; i++)
|
||||
{
|
||||
_currentArchetype.MarkChanged(_currentChunkIndex, _changedComponentIDs[i], _world.Version);
|
||||
}
|
||||
}
|
||||
|
||||
public bool MoveNext()
|
||||
@@ -1117,6 +1287,11 @@ public unsafe partial struct EntityQuery
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public readonly void Dispose()
|
||||
{
|
||||
_scope.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
private readonly ReadOnlyUnsafeCollection<Identifier<Archetype>> _matchingArchetypes;
|
||||
@@ -1194,7 +1369,7 @@ public unsafe partial struct EntityQuery
|
||||
}
|
||||
}
|
||||
|
||||
public ref struct Enumerator
|
||||
public ref struct Enumerator : IDisposable
|
||||
{
|
||||
private fixed int _compTypeIDs[7];
|
||||
private fixed int _offsets[7];
|
||||
@@ -1204,6 +1379,9 @@ public unsafe partial struct EntityQuery
|
||||
private readonly EntityQueryMask _mask;
|
||||
private readonly World _world;
|
||||
|
||||
private readonly Stack.Scope _scope;
|
||||
private UnsafeList<int> _changedComponentIDs;
|
||||
|
||||
private ref Archetype _currentArchetype;
|
||||
private ref Chunk _currentChunk;
|
||||
private byte* _chunkBasePtr;
|
||||
@@ -1247,6 +1425,22 @@ public unsafe partial struct EntityQuery
|
||||
_mask = mask;
|
||||
_world = world;
|
||||
|
||||
_scope = AllocationManager.CreateStackScope();
|
||||
_changedComponentIDs = new UnsafeList<int>(7, _scope.AllocationHandle);
|
||||
|
||||
var it = _mask.writeAccess.GetIterator();
|
||||
while (it.Next(out var id))
|
||||
{
|
||||
for (var i = 0; i < 7; i++)
|
||||
{
|
||||
if (id == _compTypeIDs[i])
|
||||
{
|
||||
_changedComponentIDs.Add(id);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reset();
|
||||
}
|
||||
|
||||
@@ -1275,6 +1469,11 @@ public unsafe partial struct EntityQuery
|
||||
_offsets[index] = layout.offset;
|
||||
_compBasePtrs[index] = (long)(_chunkBasePtr + _offsets[index]);
|
||||
}
|
||||
|
||||
for (var i = 0; i < _changedComponentIDs.Count; i++)
|
||||
{
|
||||
_currentArchetype.MarkChanged(_currentChunkIndex, _changedComponentIDs[i], _world.Version);
|
||||
}
|
||||
}
|
||||
|
||||
public bool MoveNext()
|
||||
@@ -1341,6 +1540,11 @@ public unsafe partial struct EntityQuery
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public readonly void Dispose()
|
||||
{
|
||||
_scope.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
private readonly ReadOnlyUnsafeCollection<Identifier<Archetype>> _matchingArchetypes;
|
||||
@@ -1423,7 +1627,7 @@ public unsafe partial struct EntityQuery
|
||||
}
|
||||
}
|
||||
|
||||
public ref struct Enumerator
|
||||
public ref struct Enumerator : IDisposable
|
||||
{
|
||||
private fixed int _compTypeIDs[8];
|
||||
private fixed int _offsets[8];
|
||||
@@ -1433,6 +1637,9 @@ public unsafe partial struct EntityQuery
|
||||
private readonly EntityQueryMask _mask;
|
||||
private readonly World _world;
|
||||
|
||||
private readonly Stack.Scope _scope;
|
||||
private UnsafeList<int> _changedComponentIDs;
|
||||
|
||||
private ref Archetype _currentArchetype;
|
||||
private ref Chunk _currentChunk;
|
||||
private byte* _chunkBasePtr;
|
||||
@@ -1480,6 +1687,22 @@ public unsafe partial struct EntityQuery
|
||||
_mask = mask;
|
||||
_world = world;
|
||||
|
||||
_scope = AllocationManager.CreateStackScope();
|
||||
_changedComponentIDs = new UnsafeList<int>(8, _scope.AllocationHandle);
|
||||
|
||||
var it = _mask.writeAccess.GetIterator();
|
||||
while (it.Next(out var id))
|
||||
{
|
||||
for (var i = 0; i < 8; i++)
|
||||
{
|
||||
if (id == _compTypeIDs[i])
|
||||
{
|
||||
_changedComponentIDs.Add(id);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reset();
|
||||
}
|
||||
|
||||
@@ -1509,6 +1732,11 @@ public unsafe partial struct EntityQuery
|
||||
_offsets[index] = layout.offset;
|
||||
_compBasePtrs[index] = (long)(_chunkBasePtr + _offsets[index]);
|
||||
}
|
||||
|
||||
for (var i = 0; i < _changedComponentIDs.Count; i++)
|
||||
{
|
||||
_currentArchetype.MarkChanged(_currentChunkIndex, _changedComponentIDs[i], _world.Version);
|
||||
}
|
||||
}
|
||||
|
||||
public bool MoveNext()
|
||||
@@ -1575,6 +1803,11 @@ public unsafe partial struct EntityQuery
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public readonly void Dispose()
|
||||
{
|
||||
_scope.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
private readonly ReadOnlyUnsafeCollection<Identifier<Archetype>> _matchingArchetypes;
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
<#@ include file="Helpers.ttinclude" #>
|
||||
using Ghost.Core;
|
||||
using Misaki.HighPerformance.LowLevel;
|
||||
using Misaki.HighPerformance.LowLevel.Buffer;
|
||||
using Misaki.HighPerformance.LowLevel.Collections;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
@@ -49,7 +50,7 @@ public unsafe partial struct EntityQuery
|
||||
}
|
||||
}
|
||||
|
||||
public ref struct Enumerator
|
||||
public ref struct Enumerator : IDisposable
|
||||
{
|
||||
private fixed int _compTypeIDs[<#= i #>];
|
||||
private fixed int _offsets[<#= i #>];
|
||||
@@ -59,6 +60,9 @@ public unsafe partial struct EntityQuery
|
||||
private readonly EntityQueryMask _mask;
|
||||
private readonly World _world;
|
||||
|
||||
private readonly Stack.Scope _scope;
|
||||
private UnsafeList<int> _changedComponentIDs;
|
||||
|
||||
private ref Archetype _currentArchetype;
|
||||
private ref Chunk _currentChunk;
|
||||
private byte* _chunkBasePtr;
|
||||
@@ -80,6 +84,22 @@ public unsafe partial struct EntityQuery
|
||||
_mask = mask;
|
||||
_world = world;
|
||||
|
||||
_scope = AllocationManager.CreateStackScope();
|
||||
_changedComponentIDs = new UnsafeList<int>(<#= i #>, _scope.AllocationHandle);
|
||||
|
||||
var it = _mask.writeAccess.GetIterator();
|
||||
while (it.Next(out var id))
|
||||
{
|
||||
for (var i = 0; i < <#= i #>; i++)
|
||||
{
|
||||
if (id == _compTypeIDs[i])
|
||||
{
|
||||
_changedComponentIDs.Add(id);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reset();
|
||||
}
|
||||
|
||||
@@ -104,6 +124,11 @@ public unsafe partial struct EntityQuery
|
||||
_offsets[index] = layout.offset;
|
||||
_compBasePtrs[index] = (long)(_chunkBasePtr + _offsets[index]);
|
||||
}
|
||||
|
||||
for (var i = 0; i < _changedComponentIDs.Count; i++)
|
||||
{
|
||||
_currentArchetype.MarkChanged(_currentChunkIndex, _changedComponentIDs[i], _world.Version);
|
||||
}
|
||||
}
|
||||
|
||||
public bool MoveNext()
|
||||
@@ -170,6 +195,11 @@ public unsafe partial struct EntityQuery
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public readonly void Dispose()
|
||||
{
|
||||
_scope.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
private readonly ReadOnlyUnsafeCollection<Identifier<Archetype>> _matchingArchetypes;
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
|
||||
using Ghost.Core;
|
||||
|
||||
namespace Ghost.Entities;
|
||||
|
||||
public unsafe partial struct EntityQuery
|
||||
@@ -12,7 +9,7 @@ public unsafe partial struct EntityQuery
|
||||
var globalVersion = world.Version;
|
||||
|
||||
var comp0TypeID = ComponentTypeID<T0>.value;
|
||||
|
||||
|
||||
var compTypeIDs = stackalloc int[]
|
||||
{
|
||||
comp0TypeID.value,
|
||||
@@ -31,7 +28,6 @@ public unsafe partial struct EntityQuery
|
||||
{
|
||||
if (id == compTypeIDs[i])
|
||||
{
|
||||
ComponentRegister.SetComponentLastWrite(id, globalVersion);
|
||||
changedCompIDs[changedCompCount] = id;
|
||||
changedCompCount++;
|
||||
break;
|
||||
@@ -67,7 +63,7 @@ public unsafe partial struct EntityQuery
|
||||
|
||||
for (var j = 0; j < changedCompCount; j++)
|
||||
{
|
||||
chunk.MarkChanged(changedCompIDs[i], globalVersion);
|
||||
archetype.MarkChanged(chunkIndex, changedCompIDs[j], globalVersion);
|
||||
}
|
||||
|
||||
for (var index = 0; index < 1; index++)
|
||||
@@ -99,7 +95,7 @@ public unsafe partial struct EntityQuery
|
||||
|
||||
var comp0TypeID = ComponentTypeID<T0>.value;
|
||||
var comp1TypeID = ComponentTypeID<T1>.value;
|
||||
|
||||
|
||||
var compTypeIDs = stackalloc int[]
|
||||
{
|
||||
comp0TypeID.value,
|
||||
@@ -119,7 +115,6 @@ public unsafe partial struct EntityQuery
|
||||
{
|
||||
if (id == compTypeIDs[i])
|
||||
{
|
||||
ComponentRegister.SetComponentLastWrite(id, globalVersion);
|
||||
changedCompIDs[changedCompCount] = id;
|
||||
changedCompCount++;
|
||||
break;
|
||||
@@ -155,7 +150,7 @@ public unsafe partial struct EntityQuery
|
||||
|
||||
for (var j = 0; j < changedCompCount; j++)
|
||||
{
|
||||
chunk.MarkChanged(changedCompIDs[i], globalVersion);
|
||||
archetype.MarkChanged(chunkIndex, changedCompIDs[j], globalVersion);
|
||||
}
|
||||
|
||||
for (var index = 0; index < 2; index++)
|
||||
@@ -190,7 +185,7 @@ public unsafe partial struct EntityQuery
|
||||
var comp0TypeID = ComponentTypeID<T0>.value;
|
||||
var comp1TypeID = ComponentTypeID<T1>.value;
|
||||
var comp2TypeID = ComponentTypeID<T2>.value;
|
||||
|
||||
|
||||
var compTypeIDs = stackalloc int[]
|
||||
{
|
||||
comp0TypeID.value,
|
||||
@@ -211,7 +206,6 @@ public unsafe partial struct EntityQuery
|
||||
{
|
||||
if (id == compTypeIDs[i])
|
||||
{
|
||||
ComponentRegister.SetComponentLastWrite(id, globalVersion);
|
||||
changedCompIDs[changedCompCount] = id;
|
||||
changedCompCount++;
|
||||
break;
|
||||
@@ -247,7 +241,7 @@ public unsafe partial struct EntityQuery
|
||||
|
||||
for (var j = 0; j < changedCompCount; j++)
|
||||
{
|
||||
chunk.MarkChanged(changedCompIDs[i], globalVersion);
|
||||
archetype.MarkChanged(chunkIndex, changedCompIDs[j], globalVersion);
|
||||
}
|
||||
|
||||
for (var index = 0; index < 3; index++)
|
||||
@@ -285,7 +279,7 @@ public unsafe partial struct EntityQuery
|
||||
var comp1TypeID = ComponentTypeID<T1>.value;
|
||||
var comp2TypeID = ComponentTypeID<T2>.value;
|
||||
var comp3TypeID = ComponentTypeID<T3>.value;
|
||||
|
||||
|
||||
var compTypeIDs = stackalloc int[]
|
||||
{
|
||||
comp0TypeID.value,
|
||||
@@ -307,7 +301,6 @@ public unsafe partial struct EntityQuery
|
||||
{
|
||||
if (id == compTypeIDs[i])
|
||||
{
|
||||
ComponentRegister.SetComponentLastWrite(id, globalVersion);
|
||||
changedCompIDs[changedCompCount] = id;
|
||||
changedCompCount++;
|
||||
break;
|
||||
@@ -343,7 +336,7 @@ public unsafe partial struct EntityQuery
|
||||
|
||||
for (var j = 0; j < changedCompCount; j++)
|
||||
{
|
||||
chunk.MarkChanged(changedCompIDs[i], globalVersion);
|
||||
archetype.MarkChanged(chunkIndex, changedCompIDs[j], globalVersion);
|
||||
}
|
||||
|
||||
for (var index = 0; index < 4; index++)
|
||||
@@ -384,7 +377,7 @@ public unsafe partial struct EntityQuery
|
||||
var comp2TypeID = ComponentTypeID<T2>.value;
|
||||
var comp3TypeID = ComponentTypeID<T3>.value;
|
||||
var comp4TypeID = ComponentTypeID<T4>.value;
|
||||
|
||||
|
||||
var compTypeIDs = stackalloc int[]
|
||||
{
|
||||
comp0TypeID.value,
|
||||
@@ -407,7 +400,6 @@ public unsafe partial struct EntityQuery
|
||||
{
|
||||
if (id == compTypeIDs[i])
|
||||
{
|
||||
ComponentRegister.SetComponentLastWrite(id, globalVersion);
|
||||
changedCompIDs[changedCompCount] = id;
|
||||
changedCompCount++;
|
||||
break;
|
||||
@@ -443,7 +435,7 @@ public unsafe partial struct EntityQuery
|
||||
|
||||
for (var j = 0; j < changedCompCount; j++)
|
||||
{
|
||||
chunk.MarkChanged(changedCompIDs[i], globalVersion);
|
||||
archetype.MarkChanged(chunkIndex, changedCompIDs[j], globalVersion);
|
||||
}
|
||||
|
||||
for (var index = 0; index < 5; index++)
|
||||
@@ -487,7 +479,7 @@ public unsafe partial struct EntityQuery
|
||||
var comp3TypeID = ComponentTypeID<T3>.value;
|
||||
var comp4TypeID = ComponentTypeID<T4>.value;
|
||||
var comp5TypeID = ComponentTypeID<T5>.value;
|
||||
|
||||
|
||||
var compTypeIDs = stackalloc int[]
|
||||
{
|
||||
comp0TypeID.value,
|
||||
@@ -511,7 +503,6 @@ public unsafe partial struct EntityQuery
|
||||
{
|
||||
if (id == compTypeIDs[i])
|
||||
{
|
||||
ComponentRegister.SetComponentLastWrite(id, globalVersion);
|
||||
changedCompIDs[changedCompCount] = id;
|
||||
changedCompCount++;
|
||||
break;
|
||||
@@ -547,7 +538,7 @@ public unsafe partial struct EntityQuery
|
||||
|
||||
for (var j = 0; j < changedCompCount; j++)
|
||||
{
|
||||
chunk.MarkChanged(changedCompIDs[i], globalVersion);
|
||||
archetype.MarkChanged(chunkIndex, changedCompIDs[j], globalVersion);
|
||||
}
|
||||
|
||||
for (var index = 0; index < 6; index++)
|
||||
@@ -594,7 +585,7 @@ public unsafe partial struct EntityQuery
|
||||
var comp4TypeID = ComponentTypeID<T4>.value;
|
||||
var comp5TypeID = ComponentTypeID<T5>.value;
|
||||
var comp6TypeID = ComponentTypeID<T6>.value;
|
||||
|
||||
|
||||
var compTypeIDs = stackalloc int[]
|
||||
{
|
||||
comp0TypeID.value,
|
||||
@@ -619,7 +610,6 @@ public unsafe partial struct EntityQuery
|
||||
{
|
||||
if (id == compTypeIDs[i])
|
||||
{
|
||||
ComponentRegister.SetComponentLastWrite(id, globalVersion);
|
||||
changedCompIDs[changedCompCount] = id;
|
||||
changedCompCount++;
|
||||
break;
|
||||
@@ -655,7 +645,7 @@ public unsafe partial struct EntityQuery
|
||||
|
||||
for (var j = 0; j < changedCompCount; j++)
|
||||
{
|
||||
chunk.MarkChanged(changedCompIDs[i], globalVersion);
|
||||
archetype.MarkChanged(chunkIndex, changedCompIDs[j], globalVersion);
|
||||
}
|
||||
|
||||
for (var index = 0; index < 7; index++)
|
||||
@@ -705,7 +695,7 @@ public unsafe partial struct EntityQuery
|
||||
var comp5TypeID = ComponentTypeID<T5>.value;
|
||||
var comp6TypeID = ComponentTypeID<T6>.value;
|
||||
var comp7TypeID = ComponentTypeID<T7>.value;
|
||||
|
||||
|
||||
var compTypeIDs = stackalloc int[]
|
||||
{
|
||||
comp0TypeID.value,
|
||||
@@ -731,7 +721,6 @@ public unsafe partial struct EntityQuery
|
||||
{
|
||||
if (id == compTypeIDs[i])
|
||||
{
|
||||
ComponentRegister.SetComponentLastWrite(id, globalVersion);
|
||||
changedCompIDs[changedCompCount] = id;
|
||||
changedCompCount++;
|
||||
break;
|
||||
@@ -767,7 +756,7 @@ public unsafe partial struct EntityQuery
|
||||
|
||||
for (var j = 0; j < changedCompCount; j++)
|
||||
{
|
||||
chunk.MarkChanged(changedCompIDs[i], globalVersion);
|
||||
archetype.MarkChanged(chunkIndex, changedCompIDs[j], globalVersion);
|
||||
}
|
||||
|
||||
for (var index = 0; index < 8; index++)
|
||||
@@ -804,7 +793,7 @@ public unsafe partial struct EntityQuery
|
||||
var globalVersion = world.Version;
|
||||
|
||||
var comp0TypeID = ComponentTypeID<T0>.value;
|
||||
|
||||
|
||||
var compTypeIDs = stackalloc int[]
|
||||
{
|
||||
comp0TypeID.value,
|
||||
@@ -823,7 +812,6 @@ public unsafe partial struct EntityQuery
|
||||
{
|
||||
if (id == compTypeIDs[i])
|
||||
{
|
||||
ComponentRegister.SetComponentLastWrite(id, globalVersion);
|
||||
changedCompIDs[changedCompCount] = id;
|
||||
changedCompCount++;
|
||||
break;
|
||||
@@ -859,7 +847,7 @@ public unsafe partial struct EntityQuery
|
||||
|
||||
for (var j = 0; j < changedCompCount; j++)
|
||||
{
|
||||
chunk.MarkChanged(changedCompIDs[i], globalVersion);
|
||||
archetype.MarkChanged(chunkIndex, changedCompIDs[j], globalVersion);
|
||||
}
|
||||
|
||||
for (var index = 0; index < 1; index++)
|
||||
@@ -892,7 +880,7 @@ public unsafe partial struct EntityQuery
|
||||
|
||||
var comp0TypeID = ComponentTypeID<T0>.value;
|
||||
var comp1TypeID = ComponentTypeID<T1>.value;
|
||||
|
||||
|
||||
var compTypeIDs = stackalloc int[]
|
||||
{
|
||||
comp0TypeID.value,
|
||||
@@ -912,7 +900,6 @@ public unsafe partial struct EntityQuery
|
||||
{
|
||||
if (id == compTypeIDs[i])
|
||||
{
|
||||
ComponentRegister.SetComponentLastWrite(id, globalVersion);
|
||||
changedCompIDs[changedCompCount] = id;
|
||||
changedCompCount++;
|
||||
break;
|
||||
@@ -948,7 +935,7 @@ public unsafe partial struct EntityQuery
|
||||
|
||||
for (var j = 0; j < changedCompCount; j++)
|
||||
{
|
||||
chunk.MarkChanged(changedCompIDs[i], globalVersion);
|
||||
archetype.MarkChanged(chunkIndex, changedCompIDs[j], globalVersion);
|
||||
}
|
||||
|
||||
for (var index = 0; index < 2; index++)
|
||||
@@ -984,7 +971,7 @@ public unsafe partial struct EntityQuery
|
||||
var comp0TypeID = ComponentTypeID<T0>.value;
|
||||
var comp1TypeID = ComponentTypeID<T1>.value;
|
||||
var comp2TypeID = ComponentTypeID<T2>.value;
|
||||
|
||||
|
||||
var compTypeIDs = stackalloc int[]
|
||||
{
|
||||
comp0TypeID.value,
|
||||
@@ -1005,7 +992,6 @@ public unsafe partial struct EntityQuery
|
||||
{
|
||||
if (id == compTypeIDs[i])
|
||||
{
|
||||
ComponentRegister.SetComponentLastWrite(id, globalVersion);
|
||||
changedCompIDs[changedCompCount] = id;
|
||||
changedCompCount++;
|
||||
break;
|
||||
@@ -1041,7 +1027,7 @@ public unsafe partial struct EntityQuery
|
||||
|
||||
for (var j = 0; j < changedCompCount; j++)
|
||||
{
|
||||
chunk.MarkChanged(changedCompIDs[i], globalVersion);
|
||||
archetype.MarkChanged(chunkIndex, changedCompIDs[j], globalVersion);
|
||||
}
|
||||
|
||||
for (var index = 0; index < 3; index++)
|
||||
@@ -1080,7 +1066,7 @@ public unsafe partial struct EntityQuery
|
||||
var comp1TypeID = ComponentTypeID<T1>.value;
|
||||
var comp2TypeID = ComponentTypeID<T2>.value;
|
||||
var comp3TypeID = ComponentTypeID<T3>.value;
|
||||
|
||||
|
||||
var compTypeIDs = stackalloc int[]
|
||||
{
|
||||
comp0TypeID.value,
|
||||
@@ -1102,7 +1088,6 @@ public unsafe partial struct EntityQuery
|
||||
{
|
||||
if (id == compTypeIDs[i])
|
||||
{
|
||||
ComponentRegister.SetComponentLastWrite(id, globalVersion);
|
||||
changedCompIDs[changedCompCount] = id;
|
||||
changedCompCount++;
|
||||
break;
|
||||
@@ -1138,7 +1123,7 @@ public unsafe partial struct EntityQuery
|
||||
|
||||
for (var j = 0; j < changedCompCount; j++)
|
||||
{
|
||||
chunk.MarkChanged(changedCompIDs[i], globalVersion);
|
||||
archetype.MarkChanged(chunkIndex, changedCompIDs[j], globalVersion);
|
||||
}
|
||||
|
||||
for (var index = 0; index < 4; index++)
|
||||
@@ -1180,7 +1165,7 @@ public unsafe partial struct EntityQuery
|
||||
var comp2TypeID = ComponentTypeID<T2>.value;
|
||||
var comp3TypeID = ComponentTypeID<T3>.value;
|
||||
var comp4TypeID = ComponentTypeID<T4>.value;
|
||||
|
||||
|
||||
var compTypeIDs = stackalloc int[]
|
||||
{
|
||||
comp0TypeID.value,
|
||||
@@ -1203,7 +1188,6 @@ public unsafe partial struct EntityQuery
|
||||
{
|
||||
if (id == compTypeIDs[i])
|
||||
{
|
||||
ComponentRegister.SetComponentLastWrite(id, globalVersion);
|
||||
changedCompIDs[changedCompCount] = id;
|
||||
changedCompCount++;
|
||||
break;
|
||||
@@ -1239,7 +1223,7 @@ public unsafe partial struct EntityQuery
|
||||
|
||||
for (var j = 0; j < changedCompCount; j++)
|
||||
{
|
||||
chunk.MarkChanged(changedCompIDs[i], globalVersion);
|
||||
archetype.MarkChanged(chunkIndex, changedCompIDs[j], globalVersion);
|
||||
}
|
||||
|
||||
for (var index = 0; index < 5; index++)
|
||||
@@ -1284,7 +1268,7 @@ public unsafe partial struct EntityQuery
|
||||
var comp3TypeID = ComponentTypeID<T3>.value;
|
||||
var comp4TypeID = ComponentTypeID<T4>.value;
|
||||
var comp5TypeID = ComponentTypeID<T5>.value;
|
||||
|
||||
|
||||
var compTypeIDs = stackalloc int[]
|
||||
{
|
||||
comp0TypeID.value,
|
||||
@@ -1308,7 +1292,6 @@ public unsafe partial struct EntityQuery
|
||||
{
|
||||
if (id == compTypeIDs[i])
|
||||
{
|
||||
ComponentRegister.SetComponentLastWrite(id, globalVersion);
|
||||
changedCompIDs[changedCompCount] = id;
|
||||
changedCompCount++;
|
||||
break;
|
||||
@@ -1344,7 +1327,7 @@ public unsafe partial struct EntityQuery
|
||||
|
||||
for (var j = 0; j < changedCompCount; j++)
|
||||
{
|
||||
chunk.MarkChanged(changedCompIDs[i], globalVersion);
|
||||
archetype.MarkChanged(chunkIndex, changedCompIDs[j], globalVersion);
|
||||
}
|
||||
|
||||
for (var index = 0; index < 6; index++)
|
||||
@@ -1392,7 +1375,7 @@ public unsafe partial struct EntityQuery
|
||||
var comp4TypeID = ComponentTypeID<T4>.value;
|
||||
var comp5TypeID = ComponentTypeID<T5>.value;
|
||||
var comp6TypeID = ComponentTypeID<T6>.value;
|
||||
|
||||
|
||||
var compTypeIDs = stackalloc int[]
|
||||
{
|
||||
comp0TypeID.value,
|
||||
@@ -1417,7 +1400,6 @@ public unsafe partial struct EntityQuery
|
||||
{
|
||||
if (id == compTypeIDs[i])
|
||||
{
|
||||
ComponentRegister.SetComponentLastWrite(id, globalVersion);
|
||||
changedCompIDs[changedCompCount] = id;
|
||||
changedCompCount++;
|
||||
break;
|
||||
@@ -1453,7 +1435,7 @@ public unsafe partial struct EntityQuery
|
||||
|
||||
for (var j = 0; j < changedCompCount; j++)
|
||||
{
|
||||
chunk.MarkChanged(changedCompIDs[i], globalVersion);
|
||||
archetype.MarkChanged(chunkIndex, changedCompIDs[j], globalVersion);
|
||||
}
|
||||
|
||||
for (var index = 0; index < 7; index++)
|
||||
@@ -1504,7 +1486,7 @@ public unsafe partial struct EntityQuery
|
||||
var comp5TypeID = ComponentTypeID<T5>.value;
|
||||
var comp6TypeID = ComponentTypeID<T6>.value;
|
||||
var comp7TypeID = ComponentTypeID<T7>.value;
|
||||
|
||||
|
||||
var compTypeIDs = stackalloc int[]
|
||||
{
|
||||
comp0TypeID.value,
|
||||
@@ -1530,7 +1512,6 @@ public unsafe partial struct EntityQuery
|
||||
{
|
||||
if (id == compTypeIDs[i])
|
||||
{
|
||||
ComponentRegister.SetComponentLastWrite(id, globalVersion);
|
||||
changedCompIDs[changedCompCount] = id;
|
||||
changedCompCount++;
|
||||
break;
|
||||
@@ -1566,7 +1547,7 @@ public unsafe partial struct EntityQuery
|
||||
|
||||
for (var j = 0; j < changedCompCount; j++)
|
||||
{
|
||||
chunk.MarkChanged(changedCompIDs[i], globalVersion);
|
||||
archetype.MarkChanged(chunkIndex, changedCompIDs[j], globalVersion);
|
||||
}
|
||||
|
||||
for (var index = 0; index < 8; index++)
|
||||
|
||||
@@ -4,8 +4,6 @@
|
||||
<#@ import namespace="System.Linq" #>
|
||||
<#@ import namespace="System.Text" #>
|
||||
<#@ include file="Helpers.ttinclude" #>
|
||||
using Ghost.Core;
|
||||
|
||||
namespace Ghost.Entities;
|
||||
|
||||
public unsafe partial struct EntityQuery
|
||||
@@ -30,7 +28,7 @@ public unsafe partial struct EntityQuery
|
||||
<# for (var localIndex = 0; localIndex < i; localIndex++) { #>
|
||||
var comp<#= localIndex #>TypeID = ComponentTypeID<T<#= localIndex #>>.value;
|
||||
<# } #>
|
||||
|
||||
|
||||
var compTypeIDs = stackalloc int[]
|
||||
{
|
||||
<# for (var localIndex = 0; localIndex < i; localIndex++) { #>
|
||||
@@ -51,7 +49,6 @@ public unsafe partial struct EntityQuery
|
||||
{
|
||||
if (id == compTypeIDs[i])
|
||||
{
|
||||
ComponentRegister.SetComponentLastWrite(id, globalVersion);
|
||||
changedCompIDs[changedCompCount] = id;
|
||||
changedCompCount++;
|
||||
break;
|
||||
@@ -87,7 +84,7 @@ public unsafe partial struct EntityQuery
|
||||
|
||||
for (var j = 0; j < changedCompCount; j++)
|
||||
{
|
||||
chunk.MarkChanged(changedCompIDs[i], globalVersion);
|
||||
archetype.MarkChanged(chunkIndex, changedCompIDs[j], globalVersion);
|
||||
}
|
||||
|
||||
for (var index = 0; index < <#= i #>; index++)
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -6,7 +6,6 @@
|
||||
<#@ include file="Helpers.ttinclude" #>
|
||||
using Ghost.Core;
|
||||
using Misaki.HighPerformance.Jobs;
|
||||
using Misaki.HighPerformance.LowLevel.Buffer;
|
||||
using Misaki.HighPerformance.LowLevel.Collections;
|
||||
|
||||
namespace Ghost.Entities;
|
||||
@@ -26,26 +25,35 @@ internal unsafe struct JobEntityBatch<TJob, <#= generics #>> : IJobParallelFor
|
||||
where TJob : unmanaged, IJobEntity<<#= generics #>>
|
||||
<#= restrictions #>
|
||||
{
|
||||
public fixed int componentIDs[<#= i #>];
|
||||
public fixed bool componentRW[<#= i #>];
|
||||
|
||||
public TJob userJob;
|
||||
|
||||
public UnsafeList<IntPtr> chunks;
|
||||
public UnsafeList<IntPtr> chunkVersions;
|
||||
public UnsafeList<int> chunkCount;
|
||||
public UnsafeList<int> entityOffset;
|
||||
|
||||
<# for (var j = 0; j < i; j++){ #>
|
||||
public UnsafeList<int> offsets<#= j #>;
|
||||
public UnsafeList<int> bitsOffsets<#= j #>;
|
||||
public UnsafeList<int> versionindices<#= j #>;
|
||||
|
||||
<# } #>
|
||||
public int version;
|
||||
|
||||
public void Execute(int loopIndex, int threadIndex)
|
||||
{
|
||||
// 1. Get the specific pChunk for this thread
|
||||
var pChunk = (byte*)chunks[loopIndex];
|
||||
var pVersions = (int*)chunkVersions[loopIndex];
|
||||
var count = chunkCount[loopIndex];
|
||||
|
||||
<# for (var j = 0; j < i; j++){ #>
|
||||
var off<#= j #> = offsets<#= j #>[loopIndex];
|
||||
var enableOff<#= j #> = bitsOffsets<#= j #>[loopIndex];
|
||||
var versionIndex<#= j #> = versionindices<#= j #>[loopIndex];
|
||||
|
||||
<# } #>
|
||||
var pEntity = (Entity*)(pChunk + entityOffset[loopIndex]);
|
||||
@@ -53,6 +61,15 @@ internal unsafe struct JobEntityBatch<TJob, <#= generics #>> : IJobParallelFor
|
||||
var ptr<#= j #> = (<#= "T" + j #>*)(pChunk + off<#= j #>);
|
||||
<# } #>
|
||||
|
||||
// 2. Update versions for RW components
|
||||
<# for (var j = 0; j < i; j++){ #>
|
||||
if (componentRW[<#= j #>])
|
||||
{
|
||||
pVersions[versionIndex<#= j #>] = version;
|
||||
}
|
||||
|
||||
<# } #>
|
||||
// 3. Iterate all entities in this chunk
|
||||
for (var i = 0; i < count; i++)
|
||||
{
|
||||
<# for (var j = 0; j < i; j++){ #>
|
||||
@@ -77,43 +94,49 @@ public unsafe partial struct EntityQuery
|
||||
#>
|
||||
private struct DisposeJobEntity<#= i #> : IJob
|
||||
{
|
||||
public UnsafeList<IntPtr> chunkList;
|
||||
public UnsafeList<IntPtr> chunks;
|
||||
public UnsafeList<IntPtr> chunkVersions;
|
||||
public UnsafeList<int> chunkEntityCounts;
|
||||
public UnsafeList<int> entityOffsets;
|
||||
|
||||
<# for (var j = 0; j < i; j++){ #>
|
||||
public UnsafeList<int> offsets<#= j #>;
|
||||
public UnsafeList<int> bitsOffsets<#= j #>;
|
||||
public UnsafeList<int> versionindices<#= j #>;
|
||||
|
||||
<# } #>
|
||||
public void Execute(int threadIndex)
|
||||
{
|
||||
chunkList.Dispose();
|
||||
chunks.Dispose();
|
||||
chunkVersions.Dispose();
|
||||
chunkEntityCounts.Dispose();
|
||||
entityOffsets.Dispose();
|
||||
|
||||
<# for (var j = 0; j < i; j++){ #>
|
||||
offsets<#= j #>.Dispose();
|
||||
bitsOffsets<#= j #>.Dispose();
|
||||
versionindices<#= j #>.Dispose();
|
||||
|
||||
<# } #>
|
||||
}
|
||||
}
|
||||
|
||||
public JobHandle ScheduleEntityParallel<TJob, <#= generics #>>(TJob jobData, Allocator allocator, int batchSize, JobHandle dependency)
|
||||
public JobHandle ScheduleEntityParallel<TJob, <#= generics #>>(TJob jobData, int batchSize, JobHandle dependency)
|
||||
where TJob : unmanaged, IJobEntity<<#= generics #>>
|
||||
<#= restrictions #>
|
||||
{
|
||||
var world = World.GetWorld(_worldID).GetValueOrThrow();
|
||||
|
||||
// 1. Flatten the World
|
||||
var chunkList = new UnsafeList<IntPtr>(128, allocator);
|
||||
var chunkEntityCounts = new UnsafeList<int>(128, allocator);
|
||||
var entityOffsets = new UnsafeList<int>(128, allocator);
|
||||
var chunks = new UnsafeList<IntPtr>(128, JobScheduler.TempAllocatorHandle);
|
||||
var chunkVersions = new UnsafeList<IntPtr>(128, JobScheduler.TempAllocatorHandle);
|
||||
var chunkEntityCounts = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
|
||||
var entityOffsets = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
|
||||
|
||||
<# for (var j = 0; j < i; j++){ #>
|
||||
var offsets<#= j #> = new UnsafeList<int>(128, allocator);
|
||||
var bitsOffsets<#= j #> = new UnsafeList<int>(128, allocator);
|
||||
var offsets<#= j #> = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
|
||||
var bitsOffsets<#= j #> = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
|
||||
var versionIndices<#= j #> = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
|
||||
|
||||
<# } #>
|
||||
// Iterate the Query's matching archetypes
|
||||
@@ -137,13 +160,15 @@ public unsafe partial struct EntityQuery
|
||||
{
|
||||
ref var chunkRef = ref arch.GetChunkReference(i);
|
||||
|
||||
chunkList.Add((IntPtr)chunkRef.GetUnsafePtr());
|
||||
chunks.Add((IntPtr)chunkRef.GetUnsafePtr());
|
||||
chunkVersions.Add((IntPtr)chunkRef.GetVersionUnsafePtr());
|
||||
chunkEntityCounts.Add(chunkRef._count);
|
||||
entityOffsets.Add(arch.EntityIDsOffset);
|
||||
|
||||
<# for (var j = 0; j < i; j++){ #>
|
||||
offsets<#= j #>.Add(layout<#= j #>.offset);
|
||||
bitsOffsets<#= j #>.Add(layout<#= j #>.enableBitsOffset);
|
||||
versionIndices<#= j #>.Add(layout<#= j #>.versionIndex);
|
||||
|
||||
<# } #>
|
||||
}
|
||||
@@ -153,29 +178,49 @@ public unsafe partial struct EntityQuery
|
||||
var runner = new JobEntityBatch<TJob, <#= generics #>>
|
||||
{
|
||||
userJob = jobData,
|
||||
chunks = chunkList,
|
||||
chunks = chunks,
|
||||
chunkVersions = chunkVersions,
|
||||
chunkCount = chunkEntityCounts,
|
||||
entityOffset = entityOffsets,
|
||||
|
||||
<# for (var j = 0; j < i; j++){ #>
|
||||
offsets<#= j #> = offsets<#= j #>,
|
||||
bitsOffsets<#= j #> = bitsOffsets<#= j #>,
|
||||
versionindices<#= j #> = versionIndices<#= j #>,
|
||||
|
||||
<# } #>
|
||||
version = world.Version,
|
||||
};
|
||||
|
||||
var jobHandle = world.JobScheduler.ScheduleParallel(ref runner, chunkList.Count, batchSize, dependency);
|
||||
runner.componentIDs[0] = ComponentTypeID<T0>.value;
|
||||
|
||||
var it = _mask.writeAccess.GetIterator();
|
||||
while (it.Next(out var id))
|
||||
{
|
||||
for (var i =0; i < 1; i++)
|
||||
{
|
||||
if (id == runner.componentIDs[i])
|
||||
{
|
||||
runner.componentRW[i] = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var jobHandle = world.JobScheduler.ScheduleParallel(ref runner, chunks.Count, batchSize, dependency);
|
||||
|
||||
// 3. Dispose the temp lists
|
||||
var disposeJob = new DisposeJobEntity<#= i #>
|
||||
{
|
||||
chunkList = chunkList,
|
||||
chunks = chunks,
|
||||
chunkVersions = chunkVersions,
|
||||
chunkEntityCounts = chunkEntityCounts,
|
||||
entityOffsets = entityOffsets,
|
||||
|
||||
<# for (var j = 0; j < i; j++){ #>
|
||||
offsets<#= j #> = offsets<#= j #>,
|
||||
bitsOffsets<#= j #> = bitsOffsets<#= j #>,
|
||||
versionindices<#= j #> = versionIndices<#= j #>,
|
||||
|
||||
<# } #>
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user