2023-06-17 19:28:06 +08:00
|
|
|
|
#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
|
|
|
|
|
{
|
2023-05-27 23:02:32 +08:00
|
|
|
|
#region Interfaces
|
2023-05-30 18:27:30 +08:00
|
|
|
|
public interface IEcsPreInitProcess : IEcsProcess
|
2023-03-12 02:02:39 +08:00
|
|
|
|
{
|
2023-12-06 18:58:06 +08:00
|
|
|
|
void PreInit();
|
2023-03-12 02:02:39 +08:00
|
|
|
|
}
|
2023-05-30 18:27:30 +08:00
|
|
|
|
public interface IEcsInitProcess : IEcsProcess
|
2023-03-12 02:02:39 +08:00
|
|
|
|
{
|
2023-12-06 18:58:06 +08:00
|
|
|
|
void Init();
|
2023-03-12 02:02:39 +08:00
|
|
|
|
}
|
2023-05-30 18:27:30 +08:00
|
|
|
|
public interface IEcsRunProcess : IEcsProcess
|
2023-03-12 02:02:39 +08:00
|
|
|
|
{
|
2023-12-06 18:58:06 +08:00
|
|
|
|
void Run();
|
2023-03-12 02:02:39 +08:00
|
|
|
|
}
|
2023-05-30 18:27:30 +08:00
|
|
|
|
public interface IEcsDestroyProcess : IEcsProcess
|
2023-03-12 02:02:39 +08:00
|
|
|
|
{
|
2023-12-06 18:58:06 +08:00
|
|
|
|
void Destroy();
|
2023-03-12 02:02:39 +08:00
|
|
|
|
}
|
2023-05-27 23:02:32 +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)]
|
2023-05-07 00:50:02 +08:00
|
|
|
|
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;
|
2023-06-17 19:28:06 +08:00
|
|
|
|
protected override void OnSetup()
|
|
|
|
|
{
|
|
|
|
|
_markers = new EcsProfilerMarker[targets.Length];
|
|
|
|
|
for (int i = 0; i < targets.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
_markers[i] = new EcsProfilerMarker($"{targets[i].GetType().Name}.{nameof(PreInit)}");
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-04-23 18:05:27 +08:00
|
|
|
|
#endif
|
2023-12-06 18:58:06 +08:00
|
|
|
|
public void PreInit()
|
2023-03-27 17:58:51 +08:00
|
|
|
|
{
|
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
|
|
|
|
{
|
2023-11-15 17:47:11 +08:00
|
|
|
|
_markers[i].Begin();
|
2023-06-17 19:28:06 +08:00
|
|
|
|
try
|
|
|
|
|
{
|
2023-12-06 18:58:06 +08:00
|
|
|
|
targets[i].PreInit();
|
2023-06-17 19:28:06 +08:00
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
#if DISABLE_CATH_EXCEPTIONS
|
2023-11-15 17:47:11 +08:00
|
|
|
|
throw e;
|
2023-06-17 19:28:06 +08:00
|
|
|
|
#endif
|
2023-06-17 19:35:40 +08:00
|
|
|
|
EcsDebug.PrintError(e);
|
2023-06-17 19:28:06 +08:00
|
|
|
|
}
|
2023-11-15 17:47:11 +08:00
|
|
|
|
_markers[i].End();
|
2023-04-23 18:05:27 +08:00
|
|
|
|
}
|
2023-03-27 17:58:51 +08:00
|
|
|
|
#else
|
2023-06-17 19:28:06 +08:00
|
|
|
|
foreach (var item in targets)
|
|
|
|
|
{
|
2023-12-06 18:58:06 +08:00
|
|
|
|
try { item.PreInit(); }
|
2023-06-17 19:28:06 +08:00
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
#if DISABLE_CATH_EXCEPTIONS
|
2023-11-15 17:47:11 +08:00
|
|
|
|
throw e;
|
2023-06-17 19:28:06 +08:00
|
|
|
|
#endif
|
2023-06-17 19:35:40 +08:00
|
|
|
|
EcsDebug.PrintError(e);
|
2023-06-17 19:28:06 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2023-03-27 17:58:51 +08:00
|
|
|
|
#endif
|
2023-04-23 18:05:27 +08:00
|
|
|
|
}
|
2023-06-17 19:28:06 +08:00
|
|
|
|
}
|
|
|
|
|
[DebugColor(DebugColor.Orange)]
|
|
|
|
|
public sealed class EcsInitProcessRunner : EcsRunner<IEcsInitProcess>, IEcsInitProcess
|
|
|
|
|
{
|
2023-04-07 03:12:56 +08:00
|
|
|
|
#if DEBUG && !DISABLE_DEBUG
|
2023-06-17 19:28:06 +08:00
|
|
|
|
private EcsProfilerMarker[] _markers;
|
2023-04-23 18:05:27 +08:00
|
|
|
|
protected override void OnSetup()
|
2023-03-27 17:58:51 +08:00
|
|
|
|
{
|
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-06-17 19:28:06 +08:00
|
|
|
|
_markers[i] = new EcsProfilerMarker($"{targets[i].GetType().Name}.{nameof(Init)}");
|
2023-04-23 18:05:27 +08:00
|
|
|
|
}
|
2023-03-27 17:58:51 +08:00
|
|
|
|
}
|
2023-04-23 18:05:27 +08:00
|
|
|
|
#endif
|
2023-12-06 18:58:06 +08:00
|
|
|
|
public void Init()
|
2023-03-27 17:58:51 +08:00
|
|
|
|
{
|
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
|
|
|
|
{
|
2023-11-15 17:47:11 +08:00
|
|
|
|
_markers[i].Begin();
|
2023-06-17 19:28:06 +08:00
|
|
|
|
try
|
|
|
|
|
{
|
2023-12-06 18:58:06 +08:00
|
|
|
|
targets[i].Init();
|
2023-06-17 19:28:06 +08:00
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
#if DISABLE_CATH_EXCEPTIONS
|
2023-11-15 17:47:11 +08:00
|
|
|
|
throw e;
|
2023-06-17 19:28:06 +08:00
|
|
|
|
#endif
|
2023-06-17 19:35:40 +08:00
|
|
|
|
EcsDebug.PrintError(e);
|
2023-06-17 19:28:06 +08:00
|
|
|
|
}
|
2023-11-15 17:47:11 +08:00
|
|
|
|
_markers[i].End();
|
2023-04-23 18:05:27 +08:00
|
|
|
|
}
|
2023-03-27 17:58:51 +08:00
|
|
|
|
#else
|
2023-06-17 19:28:06 +08:00
|
|
|
|
foreach (var item in targets)
|
|
|
|
|
{
|
2023-12-06 18:58:06 +08:00
|
|
|
|
try { item.Init(); }
|
2023-06-17 19:28:06 +08:00
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
#if DISABLE_CATH_EXCEPTIONS
|
2023-11-15 17:47:11 +08:00
|
|
|
|
throw e;
|
2023-06-17 19:28:06 +08:00
|
|
|
|
#endif
|
2023-06-17 19:35:40 +08:00
|
|
|
|
EcsDebug.PrintError(e);
|
2023-06-17 19:28:06 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2023-03-27 17:58:51 +08:00
|
|
|
|
#endif
|
2023-04-23 18:05:27 +08:00
|
|
|
|
}
|
2023-06-17 19:28:06 +08:00
|
|
|
|
}
|
|
|
|
|
[DebugColor(DebugColor.Orange)]
|
|
|
|
|
public sealed class EcsRunProcessRunner : EcsRunner<IEcsRunProcess>, IEcsRunProcess
|
|
|
|
|
{
|
2023-04-07 03:12:56 +08:00
|
|
|
|
#if DEBUG && !DISABLE_DEBUG
|
2023-06-17 19:28:06 +08:00
|
|
|
|
private EcsProfilerMarker[] _markers;
|
2023-04-23 18:05:27 +08:00
|
|
|
|
protected override void OnSetup()
|
2023-03-27 17:58:51 +08:00
|
|
|
|
{
|
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-06-17 19:28:06 +08:00
|
|
|
|
_markers[i] = new EcsProfilerMarker($"{targets[i].GetType().Name}.{nameof(Run)}");
|
2023-04-23 18:05:27 +08:00
|
|
|
|
}
|
2023-03-27 17:58:51 +08:00
|
|
|
|
}
|
2023-04-23 18:05:27 +08:00
|
|
|
|
#endif
|
2023-12-06 18:58:06 +08:00
|
|
|
|
public void Run()
|
2023-03-27 17:58:51 +08:00
|
|
|
|
{
|
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
|
|
|
|
{
|
2023-11-15 17:47:11 +08:00
|
|
|
|
_markers[i].Begin();
|
2023-06-17 19:28:06 +08:00
|
|
|
|
try
|
|
|
|
|
{
|
2023-12-06 18:58:06 +08:00
|
|
|
|
targets[i].Run();
|
2023-06-17 19:28:06 +08:00
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
#if DISABLE_CATH_EXCEPTIONS
|
2023-11-15 17:47:11 +08:00
|
|
|
|
throw e;
|
2023-06-17 19:28:06 +08:00
|
|
|
|
#endif
|
2023-06-17 19:35:40 +08:00
|
|
|
|
EcsDebug.PrintError(e);
|
2023-06-17 19:28:06 +08:00
|
|
|
|
}
|
2023-11-15 17:47:11 +08:00
|
|
|
|
_markers[i].End();
|
2023-04-23 18:05:27 +08:00
|
|
|
|
}
|
2023-03-27 17:58:51 +08:00
|
|
|
|
#else
|
2023-06-17 19:28:06 +08:00
|
|
|
|
foreach (var item in targets)
|
|
|
|
|
{
|
2023-12-06 18:58:06 +08:00
|
|
|
|
try { item.Run(); }
|
2023-06-17 19:28:06 +08:00
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
#if DISABLE_CATH_EXCEPTIONS
|
2023-11-15 17:47:11 +08:00
|
|
|
|
throw e;
|
2023-06-17 19:28:06 +08:00
|
|
|
|
#endif
|
2023-06-17 19:35:40 +08:00
|
|
|
|
EcsDebug.PrintError(e);
|
2023-06-17 19:28:06 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2023-03-27 17:58:51 +08:00
|
|
|
|
#endif
|
2023-04-23 18:05:27 +08:00
|
|
|
|
}
|
2023-06-17 19:28:06 +08:00
|
|
|
|
}
|
|
|
|
|
[DebugColor(DebugColor.Orange)]
|
|
|
|
|
public sealed class EcsDestroyProcessRunner : EcsRunner<IEcsDestroyProcess>, IEcsDestroyProcess
|
|
|
|
|
{
|
2023-04-07 03:12:56 +08:00
|
|
|
|
#if DEBUG && !DISABLE_DEBUG
|
2023-06-17 19:28:06 +08:00
|
|
|
|
private EcsProfilerMarker[] _markers;
|
2023-04-23 18:05:27 +08:00
|
|
|
|
protected override void OnSetup()
|
2023-03-27 17:58:51 +08:00
|
|
|
|
{
|
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-06-17 19:28:06 +08:00
|
|
|
|
_markers[i] = new EcsProfilerMarker($"{targets[i].GetType().Name}.{nameof(Destroy)}");
|
2023-04-23 18:05:27 +08:00
|
|
|
|
}
|
2023-03-27 17:58:51 +08:00
|
|
|
|
}
|
2023-04-23 18:05:27 +08:00
|
|
|
|
#endif
|
2023-12-06 18:58:06 +08:00
|
|
|
|
public void Destroy()
|
2023-03-27 17:58:51 +08:00
|
|
|
|
{
|
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
|
|
|
|
{
|
2023-11-15 17:47:11 +08:00
|
|
|
|
_markers[i].Begin();
|
2023-06-17 19:28:06 +08:00
|
|
|
|
try
|
|
|
|
|
{
|
2023-12-06 18:58:06 +08:00
|
|
|
|
targets[i].Destroy();
|
2023-06-17 19:28:06 +08:00
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
#if DISABLE_CATH_EXCEPTIONS
|
2023-11-15 17:47:11 +08:00
|
|
|
|
throw e;
|
2023-06-17 19:28:06 +08:00
|
|
|
|
#endif
|
2023-06-17 19:35:40 +08:00
|
|
|
|
EcsDebug.PrintError(e);
|
2023-06-17 19:28:06 +08:00
|
|
|
|
}
|
2023-11-15 17:47:11 +08:00
|
|
|
|
_markers[i].End();
|
2023-04-23 18:05:27 +08:00
|
|
|
|
}
|
2023-03-27 17:58:51 +08:00
|
|
|
|
#else
|
2023-06-17 19:28:06 +08:00
|
|
|
|
foreach (var item in targets)
|
2023-04-23 18:05:27 +08:00
|
|
|
|
{
|
2023-12-06 18:58:06 +08:00
|
|
|
|
try { item.Destroy(); }
|
2023-06-17 19:28:06 +08:00
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
#if DISABLE_CATH_EXCEPTIONS
|
2023-11-15 17:47:11 +08:00
|
|
|
|
throw e;
|
2023-06-17 19:28:06 +08:00
|
|
|
|
#endif
|
2023-06-17 19:35:40 +08:00
|
|
|
|
EcsDebug.PrintError(e);
|
2023-06-17 19:28:06 +08:00
|
|
|
|
}
|
2023-04-23 18:05:27 +08:00
|
|
|
|
}
|
2023-03-27 17:58:51 +08:00
|
|
|
|
#endif
|
2023-06-17 19:28:06 +08:00
|
|
|
|
}
|
2023-04-23 18:05:27 +08:00
|
|
|
|
}
|
2023-03-12 02:02:39 +08:00
|
|
|
|
}
|
|
|
|
|
}
|