mirror of
https://github.com/DCFApixels/DragonECS.git
synced 2025-09-17 17:34:36 +08:00
update aspects
This commit is contained in:
parent
491fa69f7b
commit
13d0d41966
@ -6,14 +6,14 @@ namespace DCFApixels.DragonECS
|
||||
|
||||
public sealed class SingleAspect<TPool> : EcsAspect where TPool : IEcsPoolImplementation, new()
|
||||
{
|
||||
public readonly TPool pool = CurrentBuilder.IncludePool<TPool>();
|
||||
public readonly TPool pool = B.IncludePool<TPool>();
|
||||
}
|
||||
public sealed class CombinedAspect<A0, A1> : EcsAspect
|
||||
where A0 : EcsAspect, new()
|
||||
where A1 : EcsAspect, new()
|
||||
{
|
||||
public readonly A0 a0 = CurrentBuilder.Combine<A0>();
|
||||
public readonly A1 a1 = CurrentBuilder.Combine<A1>();
|
||||
public readonly A0 a0 = B.Combine<A0>();
|
||||
public readonly A1 a1 = B.Combine<A1>();
|
||||
public void Deconstruct(out A0 a0, out A1 a1)
|
||||
{
|
||||
a0 = this.a0;
|
||||
@ -26,9 +26,9 @@ namespace DCFApixels.DragonECS
|
||||
where A1 : EcsAspect, new()
|
||||
where A2 : EcsAspect, new()
|
||||
{
|
||||
public readonly A0 a0 = CurrentBuilder.Combine<A0>();
|
||||
public readonly A1 a1 = CurrentBuilder.Combine<A1>();
|
||||
public readonly A2 a2 = CurrentBuilder.Combine<A2>();
|
||||
public readonly A0 a0 = B.Combine<A0>();
|
||||
public readonly A1 a1 = B.Combine<A1>();
|
||||
public readonly A2 a2 = B.Combine<A2>();
|
||||
public void Deconstruct(out A0 a0, out A1 a1, out A2 a2)
|
||||
{
|
||||
a0 = this.a0;
|
||||
@ -43,10 +43,10 @@ namespace DCFApixels.DragonECS
|
||||
where A2 : EcsAspect, new()
|
||||
where A3 : EcsAspect, new()
|
||||
{
|
||||
public readonly A0 a0 = CurrentBuilder.Combine<A0>();
|
||||
public readonly A1 a1 = CurrentBuilder.Combine<A1>();
|
||||
public readonly A2 a2 = CurrentBuilder.Combine<A2>();
|
||||
public readonly A3 a3 = CurrentBuilder.Combine<A3>();
|
||||
public readonly A0 a0 = B.Combine<A0>();
|
||||
public readonly A1 a1 = B.Combine<A1>();
|
||||
public readonly A2 a2 = B.Combine<A2>();
|
||||
public readonly A3 a3 = B.Combine<A3>();
|
||||
public void Deconstruct(out A0 a0, out A1 a1, out A2 a2, out A3 a3)
|
||||
{
|
||||
a0 = this.a0;
|
||||
@ -63,11 +63,11 @@ namespace DCFApixels.DragonECS
|
||||
where A3 : EcsAspect, new()
|
||||
where A4 : EcsAspect, new()
|
||||
{
|
||||
public readonly A0 a0 = CurrentBuilder.Combine<A0>();
|
||||
public readonly A1 a1 = CurrentBuilder.Combine<A1>();
|
||||
public readonly A2 a2 = CurrentBuilder.Combine<A2>();
|
||||
public readonly A3 a3 = CurrentBuilder.Combine<A3>();
|
||||
public readonly A4 a4 = CurrentBuilder.Combine<A4>();
|
||||
public readonly A0 a0 = B.Combine<A0>();
|
||||
public readonly A1 a1 = B.Combine<A1>();
|
||||
public readonly A2 a2 = B.Combine<A2>();
|
||||
public readonly A3 a3 = B.Combine<A3>();
|
||||
public readonly A4 a4 = B.Combine<A4>();
|
||||
public void Deconstruct(out A0 a0, out A1 a1, out A2 a2, out A3 a3, out A4 a4)
|
||||
{
|
||||
a0 = this.a0;
|
||||
@ -86,12 +86,12 @@ namespace DCFApixels.DragonECS
|
||||
where A4 : EcsAspect, new()
|
||||
where A5 : EcsAspect, new()
|
||||
{
|
||||
public readonly A0 a0 = CurrentBuilder.Combine<A0>();
|
||||
public readonly A1 a1 = CurrentBuilder.Combine<A1>();
|
||||
public readonly A2 a2 = CurrentBuilder.Combine<A2>();
|
||||
public readonly A3 a3 = CurrentBuilder.Combine<A3>();
|
||||
public readonly A4 a4 = CurrentBuilder.Combine<A4>();
|
||||
public readonly A5 a5 = CurrentBuilder.Combine<A5>();
|
||||
public readonly A0 a0 = B.Combine<A0>();
|
||||
public readonly A1 a1 = B.Combine<A1>();
|
||||
public readonly A2 a2 = B.Combine<A2>();
|
||||
public readonly A3 a3 = B.Combine<A3>();
|
||||
public readonly A4 a4 = B.Combine<A4>();
|
||||
public readonly A5 a5 = B.Combine<A5>();
|
||||
public void Deconstruct(out A0 a0, out A1 a1, out A2 a2, out A3 a3, out A4 a4, out A5 a5)
|
||||
{
|
||||
a0 = this.a0;
|
||||
|
@ -6,6 +6,25 @@ using System.Collections.Generic;
|
||||
|
||||
namespace DCFApixels.DragonECS
|
||||
{
|
||||
public readonly struct Singleton<T> where T : struct
|
||||
{
|
||||
public readonly short WorldID;
|
||||
public Singleton(short worldID)
|
||||
{
|
||||
WorldID = worldID;
|
||||
EcsWorld.GetData<T>(worldID);
|
||||
}
|
||||
public EcsWorld World
|
||||
{
|
||||
get { return EcsWorld.GetWorld(WorldID); }
|
||||
}
|
||||
public ref T Value
|
||||
{
|
||||
get { return ref EcsWorld.GetDataUnchecked<T>(WorldID); }
|
||||
}
|
||||
|
||||
public static implicit operator Singleton<T>(SingletonMarker a) { return new Singleton<T>(a.Builder.World.ID); }
|
||||
}
|
||||
public abstract class EcsAspect : ITemplateNode, IComponentMask
|
||||
{
|
||||
#region Initialization Halpers
|
||||
@ -13,7 +32,7 @@ namespace DCFApixels.DragonECS
|
||||
private static Builder[] _constructorBuildersStack;
|
||||
[ThreadStatic]
|
||||
private static int _constructorBuildersStackIndex;
|
||||
protected static Builder CurrentBuilder
|
||||
protected static Builder B
|
||||
{
|
||||
get
|
||||
{
|
||||
@ -24,17 +43,25 @@ namespace DCFApixels.DragonECS
|
||||
return _constructorBuildersStack[_constructorBuildersStackIndex];
|
||||
}
|
||||
}
|
||||
protected static Builder CurrentBuilder
|
||||
{
|
||||
get { return B; }
|
||||
}
|
||||
protected static IncludeMarker Inc
|
||||
{
|
||||
get { return CurrentBuilder.Inc; }
|
||||
get { return B.Inc; }
|
||||
}
|
||||
protected static ExcludeMarker Exc
|
||||
{
|
||||
get { return CurrentBuilder.Exc; }
|
||||
get { return B.Exc; }
|
||||
}
|
||||
protected static OptionalMarker Opt
|
||||
{
|
||||
get { return CurrentBuilder.Opt; }
|
||||
get { return B.Opt; }
|
||||
}
|
||||
protected static SingletonMarker Singleton
|
||||
{
|
||||
get { return B.Singleton; }
|
||||
}
|
||||
#endregion
|
||||
|
||||
@ -102,6 +129,10 @@ namespace DCFApixels.DragonECS
|
||||
{
|
||||
get { return new OptionalMarker(this); }
|
||||
}
|
||||
public SingletonMarker Singleton
|
||||
{
|
||||
get { return new SingletonMarker(this); }
|
||||
}
|
||||
public EcsWorld World
|
||||
{
|
||||
get { return _world; }
|
||||
@ -164,6 +195,10 @@ namespace DCFApixels.DragonECS
|
||||
#endregion
|
||||
|
||||
#region Include/Exclude/Optional/Combine/Except
|
||||
public Singleton<T> Get<T>() where T : struct
|
||||
{
|
||||
return new Singleton<T>(_world.ID);
|
||||
}
|
||||
public TPool IncludePool<TPool>() where TPool : IEcsPoolImplementation, new()
|
||||
{
|
||||
var pool = CachePool<TPool>();
|
||||
@ -397,5 +432,17 @@ namespace DCFApixels.DragonECS
|
||||
return _builder.OptionalPool<T>();
|
||||
}
|
||||
}
|
||||
public readonly ref struct SingletonMarker
|
||||
{
|
||||
public readonly EcsAspect.Builder Builder;
|
||||
public SingletonMarker(EcsAspect.Builder builder)
|
||||
{
|
||||
Builder = builder;
|
||||
}
|
||||
public T Get<T>() where T : struct
|
||||
{
|
||||
return Builder.World.Get<T>();
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
Loading…
Reference in New Issue
Block a user