udpate AutoDelFixed

This commit is contained in:
Mikhail 2023-06-07 13:58:47 +08:00
parent 45cbf45d13
commit 0080246ca8

View File

@ -1,55 +1,41 @@
namespace DCFApixels.DragonECS using DCFApixels.DragonECS.Internal;
using System.Collections.Generic;
namespace DCFApixels.DragonECS
{ {
[DebugHide, DebugColor(DebugColor.Grey)] [DebugHide, DebugColor(DebugColor.Grey)]
public class DeleteOneFrameComponentFixedSystem<TWorld, TComponent> : IEcsFixedRunProcess, IEcsInject<TWorld> public class DeleteOneFrameComponentFixedSystem<TComponent> : IEcsFixedRunProcess, IEcsInject<EcsWorld>
where TWorld : EcsWorld<TWorld> where TComponent : struct, IEcsComponent
where TComponent : struct, IEcsComponent
{ {
private TWorld _world;
public void Inject(TWorld obj) => _world = obj;
private sealed class Subject : EcsSubject private sealed class Subject : EcsSubject
{ {
public EcsPool<TComponent> pool; public EcsPool<TComponent> pool;
public Subject(Builder b) public Subject(Builder b) => pool = b.Include<TComponent>();
{
pool = b.Include<TComponent>();
}
} }
List<EcsWorld> _worlds = new List<EcsWorld>();
public void Inject(EcsWorld obj) => _worlds.Add(obj);
public void FixedRun(EcsPipeline pipeline) public void FixedRun(EcsPipeline pipeline)
{ {
foreach (var e in _world.Where(out Subject s)) for (int i = 0, iMax = _worlds.Count; i < iMax; i++)
{ {
//try EcsWorld world = _worlds[i];
//{ if (world.IsComponentTypeDeclared<TComponent>())
s.pool.Del(e); {
//} foreach (var e in world.Where(out Subject s))
//catch (System.Exception) s.pool.Del(e);
//{ }
//
// throw;
//}
} }
} }
} }
public static class DeleteOneFrameComponentFixedSystemExtensions
public static class DeleteOneFrameComponentFixedSystemExt
{ {
private const string AUTO_DEL_FIXED_LAYER = nameof(AUTO_DEL_FIXED_LAYER); private const string AUTO_DEL_LAYER = nameof(AUTO_DEL_LAYER);
public static EcsPipeline.Builder AutoDelFixed<TWorld, TComponent>(this EcsPipeline.Builder b) public static EcsPipeline.Builder AutoDelFixed<TComponent>(this EcsPipeline.Builder b, string layerName = AUTO_DEL_LAYER)
where TWorld : EcsWorld<TWorld>
where TComponent : struct, IEcsComponent where TComponent : struct, IEcsComponent
{ {
b.Layers.Insert(EcsConsts.POST_END_LAYER, AUTO_DEL_FIXED_LAYER); if (AUTO_DEL_LAYER == layerName)
b.AddUnique(new DeleteOneFrameComponentFixedSystem<TWorld, TComponent>(), AUTO_DEL_FIXED_LAYER); b.Layers.Insert(EcsConsts.POST_END_LAYER, AUTO_DEL_LAYER);
return b; b.AddUnique(new DeleteOneFrameComponentSystem<TComponent>(), layerName);
}
/// <summary> for EcsDefaultWorld </summary>
public static EcsPipeline.Builder AutoDelFixed<TComponent>(this EcsPipeline.Builder b)
where TComponent : struct, IEcsComponent
{
b.Layers.Insert(EcsConsts.POST_END_LAYER, AUTO_DEL_FIXED_LAYER);
b.AddUnique(new DeleteOneFrameComponentFixedSystem<EcsDefaultWorld, TComponent>(), AUTO_DEL_FIXED_LAYER);
return b; return b;
} }
} }