DragonECS/src/Builtin/BaseProcesses.cs

231 lines
6.2 KiB
C#
Raw Normal View History

#pragma warning disable CS0162 // Обнаружен недостижимый код
using DCFApixels.DragonECS.RunnersCore;
2023-06-18 00:41:44 +08:00
using System;
2023-03-30 06:03:05 +08:00
2023-04-23 17:55:01 +08:00
namespace DCFApixels.DragonECS
{
[MetaName(nameof(PreInit))]
2023-12-24 15:40:19 +08:00
[MetaColor(MetaColor.Orange)]
public interface IEcsPreInit : IEcsProcess
2023-03-12 02:02:39 +08:00
{
void PreInit();
2023-03-12 02:02:39 +08:00
}
[MetaName(nameof(Init))]
2023-12-24 15:40:19 +08:00
[MetaColor(MetaColor.Orange)]
public interface IEcsInit : IEcsProcess
2023-03-12 02:02:39 +08:00
{
void Init();
2023-03-12 02:02:39 +08:00
}
[MetaName(nameof(Run))]
2023-12-24 15:40:19 +08:00
[MetaColor(MetaColor.Orange)]
public interface IEcsRun : IEcsProcess
2023-03-12 02:02:39 +08:00
{
void Run();
2023-03-12 02:02:39 +08:00
}
[MetaName(nameof(Destroy))]
2023-12-24 15:40:19 +08:00
[MetaColor(MetaColor.Orange)]
public interface IEcsDestroy : IEcsProcess
2023-03-12 02:02:39 +08:00
{
void Destroy();
2023-03-12 02:02:39 +08:00
}
}
namespace DCFApixels.DragonECS.Internal
{
[MetaColor(MetaColor.Orange)]
internal sealed class EcsPreInitRunner : EcsRunner<IEcsPreInit>, IEcsPreInit
2023-03-12 02:02:39 +08:00
{
2023-04-07 03:12:56 +08:00
#if DEBUG && !DISABLE_DEBUG
private EcsProfilerMarker[] _markers;
protected override void OnSetup()
{
_markers = new EcsProfilerMarker[Process.Length];
for (int i = 0; i < Process.Length; i++)
{
2024-03-13 01:53:23 +08:00
_markers[i] = new EcsProfilerMarker($"{Process[i].GetMeta().Name}.{nameof(PreInit)}");
}
}
2023-04-23 18:05:27 +08:00
#endif
public void PreInit()
{
2023-04-23 18:05:27 +08:00
#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)
2023-04-23 18:05:27 +08:00
{
#if DISABLE_CATH_EXCEPTIONS
throw;
#endif
EcsDebug.PrintError(e);
2023-04-23 18:05:27 +08:00
}
_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++)
{
2024-03-13 01:53:23 +08:00
_markers[i] = new EcsProfilerMarker($"{Process[i].GetMeta().Name}.{nameof(Init)}");
2023-04-23 18:05:27 +08:00
}
}
#endif
public void Init()
{
2023-04-07 03:12:56 +08:00
#if DEBUG && !DISABLE_DEBUG
for (int i = 0, n = Process.Length < _markers.Length ? Process.Length : _markers.Length; i < n; i++)
{
_markers[i].Begin();
try
2023-04-23 18:05:27 +08:00
{
Process[i].Init();
2023-04-23 18:05:27 +08:00
}
catch (Exception e)
2023-04-23 18:05:27 +08:00
{
#if DISABLE_CATH_EXCEPTIONS
throw;
#endif
EcsDebug.PrintError(e);
2023-04-23 18:05:27 +08:00
}
_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++)
{
2024-03-13 01:53:23 +08:00
_markers[i] = new EcsProfilerMarker($"{Process[i].GetMeta().Name}.{nameof(Run)}");
2023-04-23 18:05:27 +08:00
}
}
#endif
public void Run()
{
2023-04-07 03:12:56 +08:00
#if DEBUG && !DISABLE_DEBUG
for (int i = 0, n = Process.Length < _markers.Length ? Process.Length : _markers.Length; i < n; i++)
{
_markers[i].Begin();
try
2023-04-23 18:05:27 +08:00
{
Process[i].Run();
2023-04-23 18:05:27 +08:00
}
catch (Exception e)
2023-04-23 18:05:27 +08:00
{
#if DISABLE_CATH_EXCEPTIONS
throw;
#endif
EcsDebug.PrintError(e);
2023-04-23 18:05:27 +08:00
}
_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++)
{
2024-03-13 01:53:23 +08:00
_markers[i] = new EcsProfilerMarker($"{Process[i].GetMeta().Name}.{nameof(IEcsDestroy.Destroy)}");
2023-04-23 18:05:27 +08:00
}
}
#endif
public void Destroy()
{
2023-04-07 03:12:56 +08:00
#if DEBUG && !DISABLE_DEBUG
for (int i = 0, n = Process.Length < _markers.Length ? Process.Length : _markers.Length; i < n; i++)
{
_markers[i].Begin();
try
2023-04-23 18:05:27 +08:00
{
Process[i].Destroy();
2023-04-23 18:05:27 +08:00
}
catch (Exception e)
2023-04-23 18:05:27 +08:00
{
#if DISABLE_CATH_EXCEPTIONS
throw;
#endif
EcsDebug.PrintError(e);
2023-04-23 18:05:27 +08:00
}
_markers[i].End();
}
#else
foreach (var item in Process)
{
try { item.Destroy(); }
catch (Exception e)
2023-04-23 18:05:27 +08:00
{
#if DISABLE_CATH_EXCEPTIONS
throw;
#endif
EcsDebug.PrintError(e);
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
}
}