DragonECS/src/Builtin/Runners.cs

147 lines
4.0 KiB
C#
Raw Normal View History

2023-03-12 02:02:39 +08:00
namespace DCFApixels.DragonECS
{
2023-03-12 20:45:18 +08:00
public interface IEcsPreInitSystem : IEcsSystem
2023-03-12 02:02:39 +08:00
{
2023-03-30 05:32:43 +08:00
public void PreInit(EcsPipeline pipeline);
2023-03-12 02:02:39 +08:00
}
2023-03-12 20:45:18 +08:00
public interface IEcsInitSystem : IEcsSystem
2023-03-12 02:02:39 +08:00
{
2023-03-30 05:32:43 +08:00
public void Init(EcsPipeline pipeline);
2023-03-12 02:02:39 +08:00
}
2023-03-12 20:45:18 +08:00
public interface IEcsRunSystem : IEcsSystem
2023-03-12 02:02:39 +08:00
{
2023-03-30 05:32:43 +08:00
public void Run(EcsPipeline pipeline);
2023-03-12 02:02:39 +08:00
}
2023-03-12 20:45:18 +08:00
public interface IEcsDestroySystem : IEcsSystem
2023-03-12 02:02:39 +08:00
{
2023-03-30 05:32:43 +08:00
public void Destroy(EcsPipeline pipeline);
2023-03-12 02:02:39 +08:00
}
2023-03-26 11:19:03 +08:00
public interface IEcsBaseSystem : IEcsInitSystem, IEcsRunSystem, IEcsDestroySystem { }
2023-03-12 02:02:39 +08:00
public sealed class EcsPreInitRunner : EcsRunner<IEcsPreInitSystem>, IEcsPreInitSystem
{
#if DEBUG
private int[] _targetIds;
#endif
2023-03-30 05:32:43 +08:00
public void PreInit(EcsPipeline pipeline)
2023-03-12 02:02:39 +08:00
{
#if DEBUG
for (int i = 0; i < targets.Length; i++)
{
int id = _targetIds[i];
EcsDebug.ProfileMarkBegin(id);
2023-03-30 05:32:43 +08:00
targets[i].PreInit(pipeline);
EcsDebug.ProfileMarkEnd(id);
}
#else
2023-03-30 05:32:43 +08:00
foreach (var item in targets) item.PreInit(pipeline);
#endif
2023-03-12 02:02:39 +08:00
}
#if DEBUG
protected override void OnSetup()
{
_targetIds = new int[targets.Length];
for (int i = 0; i < targets.Length; i++)
{
_targetIds[i] = EcsDebug.RegisterMark($"EcsRunner.{targets[i].GetType().Name}.{nameof(PreInit)}");
}
}
#endif
2023-03-12 02:02:39 +08:00
}
public sealed class EcsInitRunner : EcsRunner<IEcsInitSystem>, IEcsInitSystem
{
#if DEBUG
private int[] _targetIds;
#endif
2023-03-30 05:32:43 +08:00
public void Init(EcsPipeline pipeline)
2023-03-12 02:02:39 +08:00
{
#if DEBUG
for (int i = 0; i < targets.Length; i++)
{
int id = _targetIds[i];
EcsDebug.ProfileMarkBegin(id);
2023-03-30 05:32:43 +08:00
targets[i].Init(pipeline);
EcsDebug.ProfileMarkEnd(id);
}
#else
2023-03-30 05:32:43 +08:00
foreach (var item in targets) item.Init(pipeline);
#endif
}
#if DEBUG
protected override void OnSetup()
{
_targetIds = new int[targets.Length];
for (int i = 0; i < targets.Length; i++)
{
_targetIds[i] = EcsDebug.RegisterMark($"EcsRunner.{targets[i].GetType().Name}.{nameof(Init)}");
}
2023-03-12 02:02:39 +08:00
}
#endif
2023-03-12 02:02:39 +08:00
}
public sealed class EcsRunRunner : EcsRunner<IEcsRunSystem>, IEcsRunSystem
{
#if DEBUG
private int[] _targetIds;
#endif
2023-03-30 05:32:43 +08:00
public void Run(EcsPipeline pipeline)
2023-03-12 02:02:39 +08:00
{
#if DEBUG
for (int i = 0; i < targets.Length; i++)
{
int id = _targetIds[i];
EcsDebug.ProfileMarkBegin(id);
2023-03-30 05:32:43 +08:00
targets[i].Run(pipeline);
EcsDebug.ProfileMarkEnd(id);
}
#else
2023-03-30 05:32:43 +08:00
foreach (var item in targets) item.Run(pipeline);
#endif
2023-03-12 02:02:39 +08:00
}
#if DEBUG
protected override void OnSetup()
{
_targetIds = new int[targets.Length];
for (int i = 0; i < targets.Length; i++)
{
_targetIds[i] = EcsDebug.RegisterMark($"EcsRunner.{targets[i].GetType().Name}.{nameof(Run)}");
}
}
#endif
2023-03-12 02:02:39 +08:00
}
public sealed class EcsDestroyRunner : EcsRunner<IEcsDestroySystem>, IEcsDestroySystem
{
#if DEBUG
private int[] _targetIds;
#endif
2023-03-30 05:32:43 +08:00
public void Destroy(EcsPipeline pipeline)
2023-03-12 02:02:39 +08:00
{
#if DEBUG
for (int i = 0; i < targets.Length; i++)
{
int id = _targetIds[i];
EcsDebug.ProfileMarkBegin(id);
2023-03-30 05:32:43 +08:00
targets[i].Destroy(pipeline);
EcsDebug.ProfileMarkEnd(id);
}
#else
2023-03-30 05:32:43 +08:00
foreach (var item in targets) item.Destroy(pipeline);
#endif
}
#if DEBUG
protected override void OnSetup()
{
_targetIds = new int[targets.Length];
for (int i = 0; i < targets.Length; i++)
{
_targetIds[i] = EcsDebug.RegisterMark($"EcsRunner.{targets[i].GetType().Name}.{nameof(Destroy)}");
}
2023-03-12 02:02:39 +08:00
}
#endif
2023-03-12 02:02:39 +08:00
}
}