mirror of
https://github.com/DCFApixels/DragonECS.git
synced 2025-09-19 10:34:37 +08:00
231 lines
6.2 KiB
C#
231 lines
6.2 KiB
C#
#pragma warning disable CS0162 // Обнаружен недостижимый код
|
|
using DCFApixels.DragonECS.RunnersCore;
|
|
using System;
|
|
|
|
namespace DCFApixels.DragonECS
|
|
{
|
|
[MetaName(nameof(PreInit))]
|
|
[MetaColor(MetaColor.Orange)]
|
|
public interface IEcsPreInit : IEcsProcess
|
|
{
|
|
void PreInit();
|
|
}
|
|
[MetaName(nameof(Init))]
|
|
[MetaColor(MetaColor.Orange)]
|
|
public interface IEcsInit : IEcsProcess
|
|
{
|
|
void Init();
|
|
}
|
|
[MetaName(nameof(Run))]
|
|
[MetaColor(MetaColor.Orange)]
|
|
public interface IEcsRun : IEcsProcess
|
|
{
|
|
void Run();
|
|
}
|
|
[MetaName(nameof(Destroy))]
|
|
[MetaColor(MetaColor.Orange)]
|
|
public interface IEcsDestroy : IEcsProcess
|
|
{
|
|
void Destroy();
|
|
}
|
|
}
|
|
|
|
namespace DCFApixels.DragonECS.Internal
|
|
{
|
|
[MetaColor(MetaColor.Orange)]
|
|
internal sealed class EcsPreInitRunner : EcsRunner<IEcsPreInit>, IEcsPreInit
|
|
{
|
|
#if DEBUG && !DISABLE_DEBUG
|
|
private EcsProfilerMarker[] _markers;
|
|
protected override void OnSetup()
|
|
{
|
|
_markers = new EcsProfilerMarker[Process.Length];
|
|
for (int i = 0; i < Process.Length; i++)
|
|
{
|
|
_markers[i] = new EcsProfilerMarker($"{Process[i].GetMeta().Name}.{nameof(PreInit)}");
|
|
}
|
|
}
|
|
#endif
|
|
public void PreInit()
|
|
{
|
|
#if DEBUG && !DISABLE_DEBUG
|
|
for (int i = 0, n = Process.Length < _markers.Length ? Process.Length : _markers.Length; i < n; i++)
|
|
{
|
|
_markers[i].Begin();
|
|
try
|
|
{
|
|
Process[i].PreInit();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#if DISABLE_CATH_EXCEPTIONS
|
|
throw;
|
|
#endif
|
|
EcsDebug.PrintError(e);
|
|
}
|
|
_markers[i].End();
|
|
}
|
|
#else
|
|
foreach (var item in Process)
|
|
{
|
|
try
|
|
{
|
|
item.PreInit();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#if DISABLE_CATH_EXCEPTIONS
|
|
throw;
|
|
#endif
|
|
EcsDebug.PrintError(e);
|
|
}
|
|
}
|
|
#endif
|
|
}
|
|
}
|
|
[MetaColor(MetaColor.Orange)]
|
|
internal sealed class EcsInitRunner : EcsRunner<IEcsInit>, IEcsInit
|
|
{
|
|
#if DEBUG && !DISABLE_DEBUG
|
|
private EcsProfilerMarker[] _markers;
|
|
protected override void OnSetup()
|
|
{
|
|
_markers = new EcsProfilerMarker[Process.Length];
|
|
for (int i = 0; i < Process.Length; i++)
|
|
{
|
|
_markers[i] = new EcsProfilerMarker($"{Process[i].GetMeta().Name}.{nameof(Init)}");
|
|
}
|
|
}
|
|
#endif
|
|
public void Init()
|
|
{
|
|
#if DEBUG && !DISABLE_DEBUG
|
|
for (int i = 0, n = Process.Length < _markers.Length ? Process.Length : _markers.Length; i < n; i++)
|
|
{
|
|
_markers[i].Begin();
|
|
try
|
|
{
|
|
Process[i].Init();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#if DISABLE_CATH_EXCEPTIONS
|
|
throw;
|
|
#endif
|
|
EcsDebug.PrintError(e);
|
|
}
|
|
_markers[i].End();
|
|
}
|
|
#else
|
|
foreach (var item in Process)
|
|
{
|
|
try { item.Init(); }
|
|
catch (Exception e)
|
|
{
|
|
#if DISABLE_CATH_EXCEPTIONS
|
|
throw;
|
|
#endif
|
|
EcsDebug.PrintError(e);
|
|
}
|
|
}
|
|
#endif
|
|
}
|
|
}
|
|
[MetaColor(MetaColor.Orange)]
|
|
internal sealed class EcsRunRunner : EcsRunner<IEcsRun>, IEcsRun
|
|
{
|
|
#if DEBUG && !DISABLE_DEBUG
|
|
private EcsProfilerMarker[] _markers;
|
|
protected override void OnSetup()
|
|
{
|
|
_markers = new EcsProfilerMarker[Process.Length];
|
|
for (int i = 0; i < Process.Length; i++)
|
|
{
|
|
_markers[i] = new EcsProfilerMarker($"{Process[i].GetMeta().Name}.{nameof(Run)}");
|
|
}
|
|
}
|
|
#endif
|
|
public void Run()
|
|
{
|
|
#if DEBUG && !DISABLE_DEBUG
|
|
for (int i = 0, n = Process.Length < _markers.Length ? Process.Length : _markers.Length; i < n; i++)
|
|
{
|
|
_markers[i].Begin();
|
|
try
|
|
{
|
|
Process[i].Run();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#if DISABLE_CATH_EXCEPTIONS
|
|
throw;
|
|
#endif
|
|
EcsDebug.PrintError(e);
|
|
}
|
|
_markers[i].End();
|
|
}
|
|
#else
|
|
foreach (var item in Process)
|
|
{
|
|
try { item.Run(); }
|
|
catch (Exception e)
|
|
{
|
|
#if DISABLE_CATH_EXCEPTIONS
|
|
throw;
|
|
#endif
|
|
EcsDebug.PrintError(e);
|
|
}
|
|
}
|
|
#endif
|
|
}
|
|
}
|
|
[MetaColor(MetaColor.Orange)]
|
|
internal sealed class EcsDestroyRunner : EcsRunner<IEcsDestroy>, IEcsDestroy
|
|
{
|
|
#if DEBUG && !DISABLE_DEBUG
|
|
private EcsProfilerMarker[] _markers;
|
|
protected override void OnSetup()
|
|
{
|
|
_markers = new EcsProfilerMarker[Process.Length];
|
|
for (int i = 0; i < Process.Length; i++)
|
|
{
|
|
_markers[i] = new EcsProfilerMarker($"{Process[i].GetMeta().Name}.{nameof(IEcsDestroy.Destroy)}");
|
|
}
|
|
}
|
|
#endif
|
|
public void Destroy()
|
|
{
|
|
#if DEBUG && !DISABLE_DEBUG
|
|
for (int i = 0, n = Process.Length < _markers.Length ? Process.Length : _markers.Length; i < n; i++)
|
|
{
|
|
_markers[i].Begin();
|
|
try
|
|
{
|
|
Process[i].Destroy();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#if DISABLE_CATH_EXCEPTIONS
|
|
throw;
|
|
#endif
|
|
EcsDebug.PrintError(e);
|
|
}
|
|
_markers[i].End();
|
|
}
|
|
#else
|
|
foreach (var item in Process)
|
|
{
|
|
try { item.Destroy(); }
|
|
catch (Exception e)
|
|
{
|
|
#if DISABLE_CATH_EXCEPTIONS
|
|
throw;
|
|
#endif
|
|
EcsDebug.PrintError(e);
|
|
}
|
|
}
|
|
#endif
|
|
}
|
|
}
|
|
}
|