add debug into runners / simple refactoring

This commit is contained in:
Mikhail 2023-03-31 14:58:50 +08:00
parent a14b058977
commit 980d7b0f6a
8 changed files with 93 additions and 60 deletions

View File

@ -124,7 +124,7 @@ namespace DCFApixels.DragonECS
Color color = (GetAttribute<DebugColorAttribute>(type) ?? _fakeDebugColorAttribute).GetUnityColor(); Color color = (GetAttribute<DebugColorAttribute>(type) ?? _fakeDebugColorAttribute).GetUnityColor();
GUILayout.BeginVertical(EcsEditor.GetStyle(color, 0.2f)); GUILayout.BeginVertical(EcsEditor.GetStyle(color, 0.2f));
GUILayout.Label(type.Name, EditorStyles.boldLabel); GUILayout.Label(type.Name, EditorStyles.boldLabel);
GUILayout.Label(string.Join(", ", runner.Targets.Cast<object>().Select(o => o.GetType().Name))); GUILayout.Label(string.Join(", ", runner.Targets.Cast<object>().Select(o => o.GetType().Name)), EditorStyles.miniLabel);
GUILayout.EndVertical(); GUILayout.EndVertical();
} }

View File

@ -16,6 +16,7 @@ namespace DCFApixels.DragonECS
_ecsWorld = ecsWorld; _ecsWorld = ecsWorld;
WorldDebugMonitor monitor = new GameObject(EcsConsts.DEBUG_PREFIX + _monitorName).AddComponent<WorldDebugMonitor>(); WorldDebugMonitor monitor = new GameObject(EcsConsts.DEBUG_PREFIX + _monitorName).AddComponent<WorldDebugMonitor>();
WorldPoolsMonitor poolsmonitor = new GameObject(EcsConsts.DEBUG_PREFIX + _monitorName).AddComponent<WorldPoolsMonitor>(); WorldPoolsMonitor poolsmonitor = new GameObject(EcsConsts.DEBUG_PREFIX + _monitorName).AddComponent<WorldPoolsMonitor>();
poolsmonitor.transform.SetParent(monitor.transform);
monitor.source = this; monitor.source = this;
monitor.world = _ecsWorld; monitor.world = _ecsWorld;
@ -23,7 +24,7 @@ namespace DCFApixels.DragonECS
poolsmonitor.source = this; poolsmonitor.source = this;
poolsmonitor.world = _ecsWorld; poolsmonitor.world = _ecsWorld;
poolsmonitor.monitorName = _monitorName; poolsmonitor.monitorName = "Pools";
} }
public void Run(EcsPipeline pipeline) public void Run(EcsPipeline pipeline)
@ -147,7 +148,7 @@ namespace DCFApixels.DragonECS
GUI.contentColor = defaultContentColor; GUI.contentColor = defaultContentColor;
GUIStyle textStyle2 = EditorStyles.miniBoldLabel; GUIStyle textStyle2 = EditorStyles.miniBoldLabel;
textStyle2.alignment = TextAnchor.LowerCenter; textStyle2.alignment = TextAnchor.LowerCenter;
GUI.Label(AddMargin(position, 3f, 3f), pool.DataType.Name, textStyle2); GUI.Label(AddMargin(position, -10f, 3f), pool.DataType.Name, textStyle2);
} }

View File

@ -1,23 +0,0 @@
namespace DCFApixels.DragonECS
{
public interface IEcsFixedRunSystem : IEcsSystem
{
public void FixedRun(EcsPipeline pipeline);
}
public class EcsFixedRunSystemRunner : EcsRunner<IEcsFixedRunSystem>, 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<IEcsFixedRunSystem>().FixedRun(pipeline);
}
}
}

View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: aff69967c9d73594283178ea5530cf71
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,23 +0,0 @@
namespace DCFApixels.DragonECS
{
public interface IEcsLateRunSystem : IEcsSystem
{
public void LateRun(EcsPipeline systems);
}
public class EcsLateRunSystemRunner : EcsRunner<IEcsLateRunSystem>, 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<IEcsLateRunSystem>().LateRun(systems);
}
}
}

89
src/Runners/Runners.cs Normal file
View File

@ -0,0 +1,89 @@
namespace DCFApixels.DragonECS
{
public interface IEcsLateRunSystem : IEcsSystem
{
public void LateRun(EcsPipeline pipeline);
}
public class EcsLateRunSystemRunner : EcsRunner<IEcsLateRunSystem>, 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<IEcsLateRunSystem>().LateRun(systems);
}
}
public interface IEcsFixedRunSystem : IEcsSystem
{
public void FixedRun(EcsPipeline pipeline);
}
public class EcsFixedRunSystemRunner : EcsRunner<IEcsFixedRunSystem>, 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<IEcsFixedRunSystem>().FixedRun(pipeline);
}
}
}