From 980d7b0f6a227e28b174948f221ca18fd4ac8d3b Mon Sep 17 00:00:00 2001 From: Mikhail <99481254+DCFApixels@users.noreply.github.com> Date: Fri, 31 Mar 2023 14:58:50 +0800 Subject: [PATCH] add debug into runners / simple refactoring --- src/Debug/Systems/PipelineDebugSystem.cs | 2 +- src/Debug/Systems/WorldDebugSystem.cs | 5 +- src/Runner/IEcsFixedRunSystem.cs | 23 ----- src/Runner/IEcsFixedRunSystem.cs.meta | 11 --- src/Runner/IEcsLateRunSystem.cs | 23 ----- src/{Runner.meta => Runners.meta} | 0 src/Runners/Runners.cs | 89 +++++++++++++++++++ .../Runners.cs.meta} | 0 8 files changed, 93 insertions(+), 60 deletions(-) delete mode 100644 src/Runner/IEcsFixedRunSystem.cs delete mode 100644 src/Runner/IEcsFixedRunSystem.cs.meta delete mode 100644 src/Runner/IEcsLateRunSystem.cs rename src/{Runner.meta => Runners.meta} (100%) create mode 100644 src/Runners/Runners.cs rename src/{Runner/IEcsLateRunSystem.cs.meta => Runners/Runners.cs.meta} (100%) diff --git a/src/Debug/Systems/PipelineDebugSystem.cs b/src/Debug/Systems/PipelineDebugSystem.cs index a0a12ee..907064a 100644 --- a/src/Debug/Systems/PipelineDebugSystem.cs +++ b/src/Debug/Systems/PipelineDebugSystem.cs @@ -124,7 +124,7 @@ namespace DCFApixels.DragonECS Color color = (GetAttribute(type) ?? _fakeDebugColorAttribute).GetUnityColor(); GUILayout.BeginVertical(EcsEditor.GetStyle(color, 0.2f)); GUILayout.Label(type.Name, EditorStyles.boldLabel); - GUILayout.Label(string.Join(", ", runner.Targets.Cast().Select(o => o.GetType().Name))); + GUILayout.Label(string.Join(", ", runner.Targets.Cast().Select(o => o.GetType().Name)), EditorStyles.miniLabel); GUILayout.EndVertical(); } diff --git a/src/Debug/Systems/WorldDebugSystem.cs b/src/Debug/Systems/WorldDebugSystem.cs index 9b02f61..fe8e483 100644 --- a/src/Debug/Systems/WorldDebugSystem.cs +++ b/src/Debug/Systems/WorldDebugSystem.cs @@ -16,6 +16,7 @@ namespace DCFApixels.DragonECS _ecsWorld = ecsWorld; WorldDebugMonitor monitor = new GameObject(EcsConsts.DEBUG_PREFIX + _monitorName).AddComponent(); WorldPoolsMonitor poolsmonitor = new GameObject(EcsConsts.DEBUG_PREFIX + _monitorName).AddComponent(); + poolsmonitor.transform.SetParent(monitor.transform); monitor.source = this; monitor.world = _ecsWorld; @@ -23,7 +24,7 @@ namespace DCFApixels.DragonECS poolsmonitor.source = this; poolsmonitor.world = _ecsWorld; - poolsmonitor.monitorName = _monitorName; + poolsmonitor.monitorName = "Pools"; } public void Run(EcsPipeline pipeline) @@ -147,7 +148,7 @@ namespace DCFApixels.DragonECS GUI.contentColor = defaultContentColor; GUIStyle textStyle2 = EditorStyles.miniBoldLabel; textStyle2.alignment = TextAnchor.LowerCenter; - GUI.Label(AddMargin(position, 3f, 3f), pool.DataType.Name, textStyle2); + GUI.Label(AddMargin(position, -10f, 3f), pool.DataType.Name, textStyle2); } diff --git a/src/Runner/IEcsFixedRunSystem.cs b/src/Runner/IEcsFixedRunSystem.cs deleted file mode 100644 index 8d0bcc8..0000000 --- a/src/Runner/IEcsFixedRunSystem.cs +++ /dev/null @@ -1,23 +0,0 @@ -namespace DCFApixels.DragonECS -{ - public interface IEcsFixedRunSystem : IEcsSystem - { - public void FixedRun(EcsPipeline pipeline); - } - - public class EcsFixedRunSystemRunner : EcsRunner, IEcsFixedRunSystem - { - void IEcsFixedRunSystem.FixedRun(EcsPipeline pipeline) - { - foreach (var item in targets) item.FixedRun(pipeline); - } - } - - public static class IEcsFixedRunSystemExtensions - { - public static void FixedRun(this EcsPipeline pipeline) - { - pipeline.GetRunner().FixedRun(pipeline); - } - } -} diff --git a/src/Runner/IEcsFixedRunSystem.cs.meta b/src/Runner/IEcsFixedRunSystem.cs.meta deleted file mode 100644 index 1f3937e..0000000 --- a/src/Runner/IEcsFixedRunSystem.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: aff69967c9d73594283178ea5530cf71 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/src/Runner/IEcsLateRunSystem.cs b/src/Runner/IEcsLateRunSystem.cs deleted file mode 100644 index bba7e52..0000000 --- a/src/Runner/IEcsLateRunSystem.cs +++ /dev/null @@ -1,23 +0,0 @@ -namespace DCFApixels.DragonECS -{ - public interface IEcsLateRunSystem : IEcsSystem - { - public void LateRun(EcsPipeline systems); - } - - public class EcsLateRunSystemRunner : EcsRunner, IEcsLateRunSystem - { - void IEcsLateRunSystem.LateRun(EcsPipeline systems) - { - foreach (var item in targets) item.LateRun(systems); - } - } - - public static class IEcsLateRunSystemExtensions - { - public static void LateRun(this EcsPipeline systems) - { - systems.GetRunner().LateRun(systems); - } - } -} diff --git a/src/Runner.meta b/src/Runners.meta similarity index 100% rename from src/Runner.meta rename to src/Runners.meta diff --git a/src/Runners/Runners.cs b/src/Runners/Runners.cs new file mode 100644 index 0000000..ecd5f50 --- /dev/null +++ b/src/Runners/Runners.cs @@ -0,0 +1,89 @@ +namespace DCFApixels.DragonECS +{ + public interface IEcsLateRunSystem : IEcsSystem + { + public void LateRun(EcsPipeline pipeline); + } + + public class EcsLateRunSystemRunner : EcsRunner, IEcsLateRunSystem + { +#if DEBUG + private EcsProfilerMarker[] _markers; +#endif + public void LateRun(EcsPipeline pipeline) + { +#if DEBUG + for (int i = 0; i < targets.Length; i++) + { + using (_markers[i].Auto()) + targets[i].LateRun(pipeline); + } +#else + foreach (var item in targets) item.LateRun(systems); +#endif + } + +#if DEBUG + protected override void OnSetup() + { + _markers = new EcsProfilerMarker[targets.Length]; + for (int i = 0; i < targets.Length; i++) + { + _markers[i] = new EcsProfilerMarker(EcsDebug.RegisterMark($"EcsRunner.{targets[i].GetType().Name}.{nameof(LateRun)}")); + } + } +#endif + } + public static class IEcsLateRunSystemExtensions + { + public static void LateRun(this EcsPipeline systems) + { + systems.GetRunner().LateRun(systems); + } + + } + + + + + public interface IEcsFixedRunSystem : IEcsSystem + { + public void FixedRun(EcsPipeline pipeline); + } + public class EcsFixedRunSystemRunner : EcsRunner, IEcsFixedRunSystem + { +#if DEBUG + private EcsProfilerMarker[] _markers; +#endif + public void FixedRun(EcsPipeline pipeline) + { +#if DEBUG + for (int i = 0; i < targets.Length; i++) + { + using (_markers[i].Auto()) + targets[i].FixedRun(pipeline); + } +#else + foreach (var item in targets) item.FixedRun(pipeline); +#endif + } + +#if DEBUG + protected override void OnSetup() + { + _markers = new EcsProfilerMarker[targets.Length]; + for (int i = 0; i < targets.Length; i++) + { + _markers[i] = new EcsProfilerMarker(EcsDebug.RegisterMark($"EcsRunner.{targets[i].GetType().Name}.{nameof(FixedRun)}")); + } + } +#endif + } + public static class IEcsFixedRunSystemExtensions + { + public static void FixedRun(this EcsPipeline pipeline) + { + pipeline.GetRunner().FixedRun(pipeline); + } + } +} diff --git a/src/Runner/IEcsLateRunSystem.cs.meta b/src/Runners/Runners.cs.meta similarity index 100% rename from src/Runner/IEcsLateRunSystem.cs.meta rename to src/Runners/Runners.cs.meta