Update version support

This commit is contained in:
2025-12-11 21:25:32 +09:00
parent 856fa4f07d
commit a3863c1263
16 changed files with 1699 additions and 332 deletions

View File

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