refactoring

This commit is contained in:
Mikhail 2023-04-07 17:15:31 +08:00
parent 7e4a33bd4d
commit 3d6155ea80
2 changed files with 30 additions and 14 deletions

View File

@ -10,12 +10,6 @@ using System.Threading.Tasks;
namespace DCFApixels.DragonECS
{
public abstract class EcsQueryBuilder
{
public abstract inc<TComponent> Include<TComponent>() where TComponent : struct;
public abstract exc<TComponent> Exclude<TComponent>() where TComponent : struct;
public abstract opt<TComponent> Optional<TComponent>() where TComponent : struct;
}
public interface IEcsQuery
{
internal void AddEntity(int entityID);
@ -115,7 +109,6 @@ namespace DCFApixels.DragonECS
_exc.Sort();
mask = new EcsQueryMask(_world.ArchetypeType, _inc.ToArray(), _exc.ToArray());
_world = null;
_inc.Clear();
_inc = null;
@ -128,12 +121,6 @@ namespace DCFApixels.DragonECS
public class EcsQueryMask : EcsMaskBase
{
// internal readonly Type WorldArchetypeType;
// internal readonly int[] Inc;
// internal readonly int[] Exc;
//
// public int IncCount => Inc.Length;
// public int ExcCount => Exc.Length;
public EcsQueryMask(Type worldArchetypeType, int[] inc, int[] exc)
{
WorldArchetypeType = worldArchetypeType;
@ -141,5 +128,10 @@ namespace DCFApixels.DragonECS
Exc = exc;
}
}
public abstract class EcsQueryBuilder
{
public abstract inc<TComponent> Include<TComponent>() where TComponent : struct;
public abstract exc<TComponent> Exclude<TComponent>() where TComponent : struct;
public abstract opt<TComponent> Optional<TComponent>() where TComponent : struct;
}
}

View File

@ -22,12 +22,20 @@ namespace DCFApixels.DragonECS
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal inc(EcsPool<TComponent> pool) => _pool = pool;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public ref TComponent Write(ent entity) => ref _pool.Write(entity.id);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public ref TComponent Write(int entityID) => ref _pool.Write(entityID);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public ref readonly TComponent Read(ent entity) => ref _pool.Read(entity.id);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public ref readonly TComponent Read(int entityID) => ref _pool.Read(entityID);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool Has(ent entity) => _pool.Has(entity.id);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool Has(int entityID) => _pool.Has(entityID);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Del(ent entity) => _pool.Del(entity.id);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Del(int entityID) => _pool.Del(entityID);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public override string ToString() => $"{(_pool == null ? "NULL" : _pool.World.ArchetypeType.Name)}inc<{typeof(TComponent).Name}>";
@ -44,12 +52,20 @@ namespace DCFApixels.DragonECS
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal exc(EcsPool<TComponent> pool) => _pool = pool;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public ref TComponent Write(ent entity) => ref _pool.Write(entity.id);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public ref TComponent Write(int entityID) => ref _pool.Write(entityID);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public ref readonly TComponent Read(ent entity) => ref _pool.Read(entity.id);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public ref readonly TComponent Read(int entityID) => ref _pool.Read(entityID);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool Has(ent entity) => _pool.Has(entity.id);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool Has(int entityID) => _pool.Has(entityID);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Del(ent entity) => _pool.Del(entity.id);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Del(int entityID) => _pool.Del(entityID);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public override string ToString() => $"{(_pool == null ? "NULL" : _pool.World.ArchetypeType.Name)}exc<{typeof(TComponent).Name}>";
@ -66,12 +82,20 @@ namespace DCFApixels.DragonECS
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal opt(EcsPool<TComponent> pool) => _pool = pool;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public ref TComponent Write(ent entity) => ref _pool.Write(entity.id);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public ref TComponent Write(int entityID) => ref _pool.Write(entityID);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public ref readonly TComponent Read(ent entity) => ref _pool.Read(entity.id);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public ref readonly TComponent Read(int entityID) => ref _pool.Read(entityID);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool Has(ent entity) => _pool.Has(entity.id);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool Has(int entityID) => _pool.Has(entityID);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Del(ent entity) => _pool.Del(entity.id);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Del(int entityID) => _pool.Del(entityID);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public override string ToString() => $"{(_pool == null ? "NULL" : _pool.World.ArchetypeType.Name)}opt<{typeof(TComponent).Name}>";