forked from Misaki/GhostEngine
- 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.
91 lines
2.1 KiB
C#
91 lines
2.1 KiB
C#
using Ghost.Core;
|
|
using Misaki.HighPerformance.LowLevel.Collections;
|
|
|
|
namespace Ghost.Entities.Query;
|
|
|
|
[Flags]
|
|
internal enum FilterMode
|
|
{
|
|
All = 1 << 0,
|
|
Any = 1 << 1,
|
|
Absent = 1 << 2,
|
|
Disabled = 1 << 3,
|
|
}
|
|
|
|
internal readonly struct FilterEntry(TypeHandle id, FilterMode mode)
|
|
{
|
|
public readonly TypeHandle typeHandle = id;
|
|
public readonly FilterMode mode = mode;
|
|
}
|
|
|
|
internal struct QueryFilter()
|
|
{
|
|
internal List<TypeHandle> _all = new(6);
|
|
internal List<TypeHandle> _any = new(6);
|
|
internal List<TypeHandle> _absent = new(6);
|
|
internal List<TypeHandle> _disabled = new(6);
|
|
|
|
public readonly UnsafeBitSet ComputeFilterBitMask(World world)
|
|
{
|
|
UnsafeBitSet? allMask = null;
|
|
UnsafeBitSet? anyMask = null;
|
|
UnsafeBitSet? absentMask = null;
|
|
|
|
foreach (var typeHandle in _all)
|
|
{
|
|
var mask = world.ComponentStorage.GetOrCreateMask(typeHandle);
|
|
|
|
if (!allMask.HasValue)
|
|
{
|
|
allMask = new UnsafeBitSet(mask.Length);
|
|
allMask.Value.SetAll();
|
|
}
|
|
|
|
allMask &= mask;
|
|
}
|
|
|
|
foreach (var typeHandle in _any)
|
|
{
|
|
var mask = world.ComponentStorage.GetOrCreateMask(typeHandle);
|
|
|
|
if (!anyMask.HasValue)
|
|
{
|
|
anyMask = new UnsafeBitSet(mask.Length);
|
|
}
|
|
|
|
anyMask |= mask;
|
|
}
|
|
|
|
foreach (var typeHandle in _absent)
|
|
{
|
|
var mask = world.ComponentStorage.GetOrCreateMask(typeHandle);
|
|
|
|
if (!absentMask.HasValue)
|
|
{
|
|
absentMask = new UnsafeBitSet(mask.Length);
|
|
}
|
|
|
|
absentMask |= mask;
|
|
}
|
|
|
|
var result = new UnsafeBitSet(world.EntityManager.EntityCount);
|
|
result.SetAll();
|
|
|
|
if (allMask.HasValue)
|
|
{
|
|
result &= allMask.Value;
|
|
}
|
|
|
|
if (anyMask.HasValue)
|
|
{
|
|
result &= anyMask.Value;
|
|
}
|
|
|
|
if (absentMask.HasValue)
|
|
{
|
|
result &= ~absentMask.Value;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
} |