Files
GhostEngine/Ghost.Entities/Template/QueryEnumerable.tt
Misaki a39f377533 Refactor GPU resource management and rendering pipeline
- Introduced `Handle<T>` and `Identifier<T>` for lightweight, strongly-typed resource identifiers.
- Replaced `BitSet` with `UnsafeBitSet` for improved performance and memory safety.
- Refactored `Mesh` and `Material` into `MeshClass` and `MaterialClass` for better GPU resource handling.
- Added `D3D12ResourceDatabase` to centralize GPU resource tracking and lifecycle management.
- Updated `D3D12ShaderCompiler` to load shaders from disk and dynamically populate constant buffers and textures.
- Enhanced `ICommandBuffer` with new upload operations for buffers and textures.
- Refactored `Vertex` struct for simplified memory layout and better performance.
- Updated `MeshBuilder` and rendering logic to align with new resource and shader structures.
- Added `BindlessDescriptor` support to `TextureHandle` and `BufferHandle`.
- Removed unused classes and performed general cleanup.
- Updated unit tests and demos to reflect the new architecture.
2025-09-19 23:20:15 +09:00

148 lines
4.1 KiB
Plaintext

<#@ template language="C#" #>
<#@ output extension=".cs" #>
<#@ assembly name="System.Core" #>
<#@ import namespace="System.Text" #>
<#@ import namespace="System.Linq" #>
<#@ include file="Helpers.ttinclude" #>
using Ghost.Core;
using Ghost.Entities.Components;
using Ghost.Entities.Query;
using Misaki.HighPerformance.LowLevel.Collections;
namespace Ghost.Entities;
<# for (int arity = 1; arity <= Amount; arity++) {
var generics = AppendGenerics(arity);
var restrictions = AppendGenericRestrictions(arity, "unmanaged, IComponentData");
var poolParams = Enumerable.Range(0, arity)
.Select(i => $"ComponentPool<T{i}> pool{i}")
.Aggregate((a, b) => a + ", " + b);
var constructorParams = Enumerable.Range(0, arity)
.Select(i => $"_pool{i}")
.Aggregate((a, b) => a + ", " + b);
#>
public struct QueryEnumerable<<#= generics #>>
<#= restrictions #>
{
private readonly World _world;
<# for (int i = 0; i < arity; i++){ #>
private readonly ComponentPool<T<#= i #>> _pool<#= i #>;
<# } #>
private readonly int _count;
private QueryFilter _filters;
internal readonly QueryFilter Filters => _filters;
internal QueryEnumerable(World world, <#= poolParams #>, int count)
{
_world = world;
<# for (int i = 0; i < arity; i++) { #>
_pool<#= i #> = pool<#= i #>;
<# } #>
_count = count;
_filters = new();
<# for (int i = 0; i < arity; i++) {#>
_filters._all.Add(TypeHandle.Get<T<#= i #>>());
<# } #>
}
public readonly Enumerator GetEnumerator() => new (_world, <#= constructorParams #>, _count, _filters);
public ref struct Enumerator
{
private readonly World _world;
private readonly ReadOnlySpan<Entity> _entities;
<# for (int i = 0; i < arity; i++){ #>
private readonly ComponentPool<T<#= i #>> _pool<#= i #>;
<# } #>
private int _index;
private readonly int _count;
private UnsafeBitSet _filterMask;
public QueryItem<<#= generics #>> Current
{
get;
private set;
}
internal Enumerator(World world, <#= poolParams #>, int count, QueryFilter filters)
{
_world = world;
_entities = _world.EntityManager.Entities;
<# for (int i = 0; i < arity; i++){ #>
_pool<#= i #> = pool<#= i #>;
<# } #>
_count = count;
_index = -1;
_filterMask = filters.ComputeFilterBitMask(_world);
Current = default;
}
public bool MoveNext()
{
_index = _filterMask.NextSetBit(_index + 1);
if (_index < 0 || _index >= _world.EntityManager.EntityCount)
{
return false;
}
Current = new QueryItem<<#= generics #>>(_entities[_index], <#= constructorParams #>);
return true;
}
}
<# for (int i = 1; i <= ExtensionAmount; i++) {
var compGenerics = AppendGenerics(i, "TComponent");
var compRestrictions = AppendGenericRestrictions(i, "TComponent", "unmanaged, IComponentData");
#>
public readonly QueryEnumerable<<#= generics #>> WithAll<<#= compGenerics #>>()
<#= compRestrictions #>
{
<# for (int j = 0; j < i; j++) {#>
_filters._all.Add(TypeHandle.Get<TComponent<#= j #>>());
<# } #>
return this;
}
public readonly QueryEnumerable<<#= generics #>> WithAny<<#= compGenerics #>>()
<#= compRestrictions #>
{
<# for (int j = 0; j < i; j++) {#>
_filters._any.Add(TypeHandle.Get<TComponent<#= j #>>());
<# } #>
return this;
}
public readonly QueryEnumerable<<#= generics #>> WithAbsent<<#= compGenerics #>>()
<#= compRestrictions #>
{
<# for (int j = 0; j < i; j++) {#>
_filters._absent.Add(TypeHandle.Get<TComponent<#= j #>>());
<# } #>
return this;
}
public readonly QueryEnumerable<<#= generics #>> WithDisabled<<#= compGenerics #>>()
<#= compRestrictions #>
{
<# for (int j = 0; j < i; j++) {#>
_filters._disabled.Add(TypeHandle.Get<TComponent<#= j #>>());
<# } #>
return this;
}
<# } #>
}
<# } #>