DragonECS/src/Builtin/BaseProcesses.cs

233 lines
6.4 KiB
C#
Raw Normal View History

#pragma warning disable CS0162 // Обнаружен недостижимый код
using DCFApixels.DragonECS.Internal;
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)]
[BindWithEcsRunner(typeof(EcsPreInitRunner))]
public interface IEcsPreInit : IEcsSystem
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)]
[BindWithEcsRunner(typeof(EcsInitRunner))]
public interface IEcsInit : IEcsSystem
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)]
[BindWithEcsRunner(typeof(EcsRunRunner))]
public interface IEcsRun : IEcsSystem
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)]
[BindWithEcsRunner(typeof(EcsDestroyRunner))]
public interface IEcsDestroy : IEcsSystem
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)]
public 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++)
{
_markers[i] = new EcsProfilerMarker($"{Process[i].GetType().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)]
public 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].GetType().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)]
public 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].GetType().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)]
public 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].GetType().Name}.{nameof(IEcsDestroy.Destroy)}");
2023-04-23 18:05:27 +08:00
}
}
#endif
void IEcsDestroy.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
}
}