DragonECS/src/Builtin/BaseProcesses.cs

146 lines
4.7 KiB
C#
Raw Normal View History

2023-04-23 17:55:01 +08:00
using DCFApixels.DragonECS.RunnersCore;
2023-03-30 06:03:05 +08:00
2023-04-23 17:55:01 +08:00
namespace DCFApixels.DragonECS
{
#region Interfaces
public interface IEcsPreInitProcess : IEcsSystem
2023-03-12 02:02:39 +08:00
{
2023-05-23 02:11:00 +08:00
void PreInit(EcsPipeline pipeline);
2023-03-12 02:02:39 +08:00
}
public interface IEcsInitProcess : IEcsSystem
2023-03-12 02:02:39 +08:00
{
2023-05-23 02:11:00 +08:00
void Init(EcsPipeline pipeline);
2023-03-12 02:02:39 +08:00
}
public interface IEcsRunProcess : IEcsSystem
2023-03-12 02:02:39 +08:00
{
2023-05-23 02:11:00 +08:00
void Run(EcsPipeline pipeline);
2023-03-12 02:02:39 +08:00
}
public interface IEcsDestroyProcess : IEcsSystem
2023-03-12 02:02:39 +08:00
{
2023-05-23 02:11:00 +08:00
void Destroy(EcsPipeline pipeline);
2023-03-12 02:02:39 +08:00
}
#endregion
2023-03-12 02:02:39 +08:00
2023-04-23 18:05:27 +08:00
namespace Internal
2023-03-12 02:02:39 +08:00
{
2023-04-23 18:05:27 +08:00
[DebugColor(DebugColor.Orange)]
public sealed class EcsPreInitProcessRunner : EcsRunner<IEcsPreInitProcess>, IEcsPreInitProcess
2023-03-12 02:02:39 +08:00
{
2023-04-07 03:12:56 +08:00
#if DEBUG && !DISABLE_DEBUG
2023-04-23 18:05:27 +08:00
private EcsProfilerMarker[] _markers;
#endif
public void PreInit(EcsPipeline pipeline)
{
2023-04-23 18:05:27 +08:00
#if DEBUG && !DISABLE_DEBUG
2023-04-24 16:48:18 +08:00
for (int i = 0; i < targets.Length && targets.Length <= _markers.Length; i++)
2023-04-23 18:05:27 +08:00
{
using (_markers[i].Auto())
2023-04-24 16:48:18 +08:00
targets[i].PreInit(pipeline);
2023-04-23 18:05:27 +08:00
}
#else
2023-03-30 05:32:43 +08:00
foreach (var item in targets) item.PreInit(pipeline);
#endif
2023-04-23 18:05:27 +08:00
}
2023-04-07 03:12:56 +08:00
#if DEBUG && !DISABLE_DEBUG
2023-04-23 18:05:27 +08:00
protected override void OnSetup()
{
2023-04-24 16:48:18 +08:00
_markers = new EcsProfilerMarker[targets.Length];
for (int i = 0; i < targets.Length; i++)
2023-04-23 18:05:27 +08:00
{
2023-04-24 16:48:18 +08:00
_markers[i] = new EcsProfilerMarker(EcsDebug.RegisterMark($"EcsRunner.{targets[i].GetType().Name}.{nameof(PreInit)}"));
2023-04-23 18:05:27 +08:00
}
}
#endif
2023-04-23 18:05:27 +08:00
}
[DebugColor(DebugColor.Orange)]
public sealed class EcsInitProcessRunner : EcsRunner<IEcsInitProcess>, IEcsInitProcess
2023-03-12 02:02:39 +08:00
{
2023-04-07 03:12:56 +08:00
#if DEBUG && !DISABLE_DEBUG
2023-04-23 18:05:27 +08:00
private EcsProfilerMarker[] _markers;
#endif
public void Init(EcsPipeline pipeline)
{
2023-04-23 18:05:27 +08:00
#if DEBUG && !DISABLE_DEBUG
2023-04-24 16:48:18 +08:00
for (int i = 0; i < targets.Length && targets.Length <= _markers.Length; i++)
2023-04-23 18:05:27 +08:00
{
using (_markers[i].Auto())
2023-04-24 16:48:18 +08:00
targets[i].Init(pipeline);
2023-04-23 18:05:27 +08:00
}
#else
2023-03-30 05:32:43 +08:00
foreach (var item in targets) item.Init(pipeline);
#endif
2023-04-23 18:05:27 +08:00
}
2023-04-07 03:12:56 +08:00
#if DEBUG && !DISABLE_DEBUG
2023-04-23 18:05:27 +08:00
protected override void OnSetup()
{
2023-04-24 16:48:18 +08:00
_markers = new EcsProfilerMarker[targets.Length];
for (int i = 0; i < targets.Length; i++)
2023-04-23 18:05:27 +08:00
{
2023-04-24 16:48:18 +08:00
_markers[i] = new EcsProfilerMarker(EcsDebug.RegisterMark($"EcsRunner.{targets[i].GetType().Name}.{nameof(Init)}"));
2023-04-23 18:05:27 +08:00
}
}
#endif
2023-04-23 18:05:27 +08:00
}
[DebugColor(DebugColor.Orange)]
public sealed class EcsRunProcessRunner : EcsRunner<IEcsRunProcess>, IEcsRunProcess
2023-03-12 02:02:39 +08:00
{
2023-04-07 03:12:56 +08:00
#if DEBUG && !DISABLE_DEBUG
2023-04-23 18:05:27 +08:00
private EcsProfilerMarker[] _markers;
#endif
public void Run(EcsPipeline pipeline)
{
2023-04-23 18:05:27 +08:00
#if DEBUG && !DISABLE_DEBUG
2023-04-24 16:48:18 +08:00
for (int i = 0; i < targets.Length && targets.Length <= _markers.Length; i++)
2023-04-23 18:05:27 +08:00
{
using (_markers[i].Auto())
2023-04-24 16:48:18 +08:00
targets[i].Run(pipeline);
2023-03-30 06:03:05 +08:00
2023-04-23 18:05:27 +08:00
}
#else
2023-03-30 05:32:43 +08:00
foreach (var item in targets) item.Run(pipeline);
#endif
2023-04-23 18:05:27 +08:00
}
2023-04-07 03:12:56 +08:00
#if DEBUG && !DISABLE_DEBUG
2023-04-23 18:05:27 +08:00
protected override void OnSetup()
{
2023-04-24 16:48:18 +08:00
_markers = new EcsProfilerMarker[targets.Length];
for (int i = 0; i < targets.Length; i++)
2023-04-23 18:05:27 +08:00
{
2023-04-24 16:48:18 +08:00
_markers[i] = new EcsProfilerMarker(EcsDebug.RegisterMark($"EcsRunner.{targets[i].GetType().Name}.{nameof(Run)}"));
2023-04-23 18:05:27 +08:00
}
}
#endif
2023-04-23 18:05:27 +08:00
}
[DebugColor(DebugColor.Orange)]
public sealed class EcsDestroyProcessRunner : EcsRunner<IEcsDestroyProcess>, IEcsDestroyProcess
2023-03-12 02:02:39 +08:00
{
2023-04-07 03:12:56 +08:00
#if DEBUG && !DISABLE_DEBUG
2023-04-23 18:05:27 +08:00
private EcsProfilerMarker[] _markers;
#endif
public void Destroy(EcsPipeline pipeline)
{
2023-04-23 18:05:27 +08:00
#if DEBUG && !DISABLE_DEBUG
2023-04-24 16:48:18 +08:00
for (int i = 0; i < targets.Length && targets.Length <= _markers.Length; i++)
2023-04-23 18:05:27 +08:00
{
using (_markers[i].Auto())
2023-04-24 16:48:18 +08:00
targets[i].Destroy(pipeline);
2023-04-23 18:05:27 +08:00
}
#else
2023-03-30 05:32:43 +08:00
foreach (var item in targets) item.Destroy(pipeline);
#endif
2023-04-23 18:05:27 +08:00
}
2023-04-07 03:12:56 +08:00
#if DEBUG && !DISABLE_DEBUG
2023-04-23 18:05:27 +08:00
protected override void OnSetup()
{
2023-04-24 16:48:18 +08:00
_markers = new EcsProfilerMarker[targets.Length];
for (int i = 0; i < targets.Length; i++)
2023-04-23 18:05:27 +08:00
{
2023-04-24 16:48:18 +08:00
_markers[i] = new EcsProfilerMarker(EcsDebug.RegisterMark($"EcsRunner.{targets[i].GetType().Name}.{nameof(Destroy)}"));
2023-04-23 18:05:27 +08:00
}
}
#endif
2023-04-23 18:05:27 +08:00
}
2023-03-12 02:02:39 +08:00
}
}