2023-04-07 05:08:48 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Runtime.CompilerServices;
|
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
|
|
|
|
|
namespace DCFApixels.DragonECS
|
|
|
|
|
{
|
2023-04-07 16:03:42 +08:00
|
|
|
|
public interface IEcsQueryMember<TComponent>
|
2023-04-07 05:08:48 +08:00
|
|
|
|
where TComponent : struct
|
|
|
|
|
{
|
2023-04-09 02:52:39 +08:00
|
|
|
|
public ref TComponent Add(ent entityID);
|
2023-04-08 05:50:44 +08:00
|
|
|
|
public ref TComponent Write(ent entityID);
|
|
|
|
|
public ref readonly TComponent Read(ent entityID);
|
|
|
|
|
public bool Has(ent entityID);
|
|
|
|
|
public void Del(ent entityID);
|
2023-04-07 05:08:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[StructLayout(LayoutKind.Sequential, Pack = 8, Size = 8)]
|
2023-04-07 16:03:42 +08:00
|
|
|
|
public readonly struct inc<TComponent> : IEcsQueryMember<TComponent>
|
2023-04-07 05:08:48 +08:00
|
|
|
|
where TComponent : struct
|
|
|
|
|
{
|
|
|
|
|
private readonly EcsPool<TComponent> _pool;
|
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
|
|
|
internal inc(EcsPool<TComponent> pool) => _pool = pool;
|
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
2023-04-09 02:52:39 +08:00
|
|
|
|
public ref TComponent Add(ent entityID) => ref _pool.Add(entityID.id);
|
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
2023-04-08 05:50:44 +08:00
|
|
|
|
public ref TComponent Write(ent entityID) => ref _pool.Write(entityID.id);
|
2023-04-07 17:15:31 +08:00
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
2023-04-08 05:50:44 +08:00
|
|
|
|
public ref readonly TComponent Read(ent entityID) => ref _pool.Read(entityID.id);
|
2023-04-07 05:08:48 +08:00
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
2023-04-08 05:50:44 +08:00
|
|
|
|
public bool Has(ent entityID) => _pool.Has(entityID.id);
|
2023-04-07 17:15:31 +08:00
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
2023-04-08 05:50:44 +08:00
|
|
|
|
public void Del(ent entityID) => _pool.Del(entityID.id);
|
2023-04-07 05:08:48 +08:00
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
|
|
|
public override string ToString() => $"{(_pool == null ? "NULL" : _pool.World.ArchetypeType.Name)}inc<{typeof(TComponent).Name}>";
|
|
|
|
|
|
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
2023-04-07 14:03:29 +08:00
|
|
|
|
public static implicit operator inc<TComponent>(EcsQueryBuilder buider) => buider.Include<TComponent>();
|
2023-04-07 05:08:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[StructLayout(LayoutKind.Sequential, Pack = 8, Size = 8)]
|
2023-04-07 16:03:42 +08:00
|
|
|
|
public readonly struct exc<TComponent> : IEcsQueryMember<TComponent>
|
2023-04-07 05:08:48 +08:00
|
|
|
|
where TComponent : struct
|
|
|
|
|
{
|
|
|
|
|
private readonly EcsPool<TComponent> _pool;
|
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
|
|
|
internal exc(EcsPool<TComponent> pool) => _pool = pool;
|
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
2023-04-09 02:52:39 +08:00
|
|
|
|
public ref TComponent Add(ent entityID) => ref _pool.Add(entityID.id);
|
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
2023-04-08 05:50:44 +08:00
|
|
|
|
public ref TComponent Write(ent entityID) => ref _pool.Write(entityID.id);
|
2023-04-07 17:15:31 +08:00
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
2023-04-08 05:50:44 +08:00
|
|
|
|
public ref readonly TComponent Read(ent entityID) => ref _pool.Read(entityID.id);
|
2023-04-07 05:08:48 +08:00
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
2023-04-08 05:50:44 +08:00
|
|
|
|
public bool Has(ent entityID) => _pool.Has(entityID.id);
|
2023-04-07 17:15:31 +08:00
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
2023-04-08 05:50:44 +08:00
|
|
|
|
public void Del(ent entityID) => _pool.Del(entityID.id);
|
2023-04-07 05:08:48 +08:00
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
|
|
|
public override string ToString() => $"{(_pool == null ? "NULL" : _pool.World.ArchetypeType.Name)}exc<{typeof(TComponent).Name}>";
|
|
|
|
|
|
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
2023-04-07 14:03:29 +08:00
|
|
|
|
public static implicit operator exc<TComponent>(EcsQueryBuilder buider) => buider.Exclude<TComponent>();
|
2023-04-07 05:08:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[StructLayout(LayoutKind.Sequential, Pack = 8, Size = 8)]
|
2023-04-07 16:03:42 +08:00
|
|
|
|
public readonly struct opt<TComponent> : IEcsQueryMember<TComponent>
|
2023-04-07 05:08:48 +08:00
|
|
|
|
where TComponent : struct
|
|
|
|
|
{
|
|
|
|
|
private readonly EcsPool<TComponent> _pool;
|
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
|
|
|
internal opt(EcsPool<TComponent> pool) => _pool = pool;
|
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
2023-04-09 02:52:39 +08:00
|
|
|
|
public ref TComponent Add(ent entityID) => ref _pool.Add(entityID.id);
|
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
2023-04-08 05:50:44 +08:00
|
|
|
|
public ref TComponent Write(ent entityID) => ref _pool.Write(entityID.id);
|
2023-04-07 17:15:31 +08:00
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
2023-04-08 05:50:44 +08:00
|
|
|
|
public ref readonly TComponent Read(ent entityID) => ref _pool.Read(entityID.id);
|
2023-04-07 05:08:48 +08:00
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
2023-04-08 05:50:44 +08:00
|
|
|
|
public bool Has(ent entityID) => _pool.Has(entityID.id);
|
2023-04-07 17:15:31 +08:00
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
2023-04-08 05:50:44 +08:00
|
|
|
|
public void Del(ent entityID) => _pool.Del(entityID.id);
|
2023-04-07 05:08:48 +08:00
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
|
|
|
public override string ToString() => $"{(_pool == null ? "NULL" : _pool.World.ArchetypeType.Name)}opt<{typeof(TComponent).Name}>";
|
|
|
|
|
|
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
2023-04-07 14:03:29 +08:00
|
|
|
|
public static implicit operator opt<TComponent>(EcsQueryBuilder buider) => buider.Optional<TComponent>();
|
2023-04-07 05:08:48 +08:00
|
|
|
|
}
|
|
|
|
|
}
|