From 0080246ca898fa8e035b81d9248259ee98a6f27e Mon Sep 17 00:00:00 2001 From: Mikhail <99481254+DCFApixels@users.noreply.github.com> Date: Wed, 7 Jun 2023 13:58:47 +0800 Subject: [PATCH] udpate AutoDelFixed --- src/Extensions/Systems.cs | 58 +++++++++++++++------------------------ 1 file changed, 22 insertions(+), 36 deletions(-) diff --git a/src/Extensions/Systems.cs b/src/Extensions/Systems.cs index 4296026..686a940 100644 --- a/src/Extensions/Systems.cs +++ b/src/Extensions/Systems.cs @@ -1,55 +1,41 @@ -namespace DCFApixels.DragonECS +using DCFApixels.DragonECS.Internal; +using System.Collections.Generic; + +namespace DCFApixels.DragonECS { [DebugHide, DebugColor(DebugColor.Grey)] - public class DeleteOneFrameComponentFixedSystem : IEcsFixedRunProcess, IEcsInject - where TWorld : EcsWorld - where TComponent : struct, IEcsComponent + public class DeleteOneFrameComponentFixedSystem : IEcsFixedRunProcess, IEcsInject + where TComponent : struct, IEcsComponent { - private TWorld _world; - public void Inject(TWorld obj) => _world = obj; - private sealed class Subject : EcsSubject { public EcsPool pool; - public Subject(Builder b) - { - pool = b.Include(); - } + public Subject(Builder b) => pool = b.Include(); } + List _worlds = new List(); + public void Inject(EcsWorld obj) => _worlds.Add(obj); 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 - //{ - s.pool.Del(e); - //} - //catch (System.Exception) - //{ - // - // throw; - //} + EcsWorld world = _worlds[i]; + if (world.IsComponentTypeDeclared()) + { + foreach (var e in world.Where(out Subject s)) + s.pool.Del(e); + } } } } - - public static class DeleteOneFrameComponentFixedSystemExt + public static class DeleteOneFrameComponentFixedSystemExtensions { - private const string AUTO_DEL_FIXED_LAYER = nameof(AUTO_DEL_FIXED_LAYER); - public static EcsPipeline.Builder AutoDelFixed(this EcsPipeline.Builder b) - where TWorld : EcsWorld + private const string AUTO_DEL_LAYER = nameof(AUTO_DEL_LAYER); + public static EcsPipeline.Builder AutoDelFixed(this EcsPipeline.Builder b, string layerName = AUTO_DEL_LAYER) where TComponent : struct, IEcsComponent { - b.Layers.Insert(EcsConsts.POST_END_LAYER, AUTO_DEL_FIXED_LAYER); - b.AddUnique(new DeleteOneFrameComponentFixedSystem(), AUTO_DEL_FIXED_LAYER); - return b; - } - /// for EcsDefaultWorld - public static EcsPipeline.Builder AutoDelFixed(this EcsPipeline.Builder b) - where TComponent : struct, IEcsComponent - { - b.Layers.Insert(EcsConsts.POST_END_LAYER, AUTO_DEL_FIXED_LAYER); - b.AddUnique(new DeleteOneFrameComponentFixedSystem(), AUTO_DEL_FIXED_LAYER); + if (AUTO_DEL_LAYER == layerName) + b.Layers.Insert(EcsConsts.POST_END_LAYER, AUTO_DEL_LAYER); + b.AddUnique(new DeleteOneFrameComponentSystem(), layerName); return b; } }