DragonECS/src/Builtin/BaseProcesses.cs

166 lines
5.2 KiB
C#
Raw Normal View History

2024-10-31 15:27:53 +08:00
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))]
2024-05-01 13:38:08 +08:00
[MetaColor(MetaColor.DragonRose)]
2024-06-13 18:04:18 +08:00
[MetaGroup(EcsConsts.PACK_GROUP, EcsConsts.PROCESSES_GROUP)]
[MetaDescription(EcsConsts.AUTHOR, "The process to run when EcsPipeline.Init() is called. Before Init")]
2024-10-12 00:08:12 +08:00
[MetaID("DE26527C92015AFDD4ECF4D81A4C946B")]
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))]
2024-05-01 13:38:08 +08:00
[MetaColor(MetaColor.DragonRose)]
2024-06-13 18:04:18 +08:00
[MetaGroup(EcsConsts.PACK_GROUP, EcsConsts.PROCESSES_GROUP)]
[MetaDescription(EcsConsts.AUTHOR, "The process to run when EcsPipeline.Init() is called. After PreInit")]
2024-10-12 00:08:12 +08:00
[MetaID("CC45527C9201DF82DCAAAEF33072F9EF")]
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))]
2024-05-01 13:38:08 +08:00
[MetaColor(MetaColor.DragonRose)]
2024-06-13 18:04:18 +08:00
[MetaGroup(EcsConsts.PACK_GROUP, EcsConsts.PROCESSES_GROUP)]
[MetaDescription(EcsConsts.AUTHOR, "The process to run when EcsPipeline.Run() is called.")]
2024-10-12 00:08:12 +08:00
[MetaID("9654527C9201BE75546322B9BB03C131")]
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))]
2024-05-01 13:38:08 +08:00
[MetaColor(MetaColor.DragonRose)]
2024-06-13 18:04:18 +08:00
[MetaGroup(EcsConsts.PACK_GROUP, EcsConsts.PROCESSES_GROUP)]
[MetaDescription(EcsConsts.AUTHOR, "The process to run when EcsPipeline.Destroy() is called.")]
2024-10-12 00:08:12 +08:00
[MetaID("4661527C9201EE669C6EB61B19899AE5")]
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
{
2024-04-28 19:43:10 +08:00
#if ENABLE_IL2CPP
using Unity.IL2CPP.CompilerServices;
[Il2CppSetOption(Option.NullChecks, false)]
[Il2CppSetOption(Option.ArrayBoundsChecks, false)]
#endif
2024-05-01 13:38:08 +08:00
[MetaColor(MetaColor.DragonRose)]
2024-06-13 18:04:18 +08:00
[MetaGroup(EcsConsts.PACK_GROUP, EcsConsts.PROCESSES_GROUP)]
2024-06-11 02:30:00 +08:00
[MetaDescription(EcsConsts.AUTHOR, "...")]
2024-06-13 18:04:18 +08:00
[MetaTags(MetaTags.HIDDEN)]
2024-10-12 00:08:12 +08:00
[MetaID("3273527C9201285BAA0A463F700A50FB")]
internal sealed class EcsPreInitRunner : EcsRunner<IEcsPreInit>, IEcsPreInit
2023-03-12 02:02:39 +08:00
{
2024-10-31 14:54:16 +08:00
private RunHelper _helper;
protected override void OnSetup()
{
2024-10-31 15:27:53 +08:00
_helper = new RunHelper(this);
}
public void PreInit()
{
2024-10-31 14:54:16 +08:00
_helper.Run(p => p.PreInit());
}
}
2024-04-28 19:43:10 +08:00
#if ENABLE_IL2CPP
[Il2CppSetOption(Option.NullChecks, false)]
[Il2CppSetOption(Option.ArrayBoundsChecks, false)]
#endif
2024-05-01 13:38:08 +08:00
[MetaColor(MetaColor.DragonRose)]
2024-06-13 18:04:18 +08:00
[MetaGroup(EcsConsts.PACK_GROUP, EcsConsts.PROCESSES_GROUP)]
2024-06-11 02:30:00 +08:00
[MetaDescription(EcsConsts.AUTHOR, "...")]
2024-06-13 18:04:18 +08:00
[MetaTags(MetaTags.HIDDEN)]
2024-10-12 00:08:12 +08:00
[MetaID("ED85527C9201A391AB8EC0B734917859")]
internal sealed class EcsInitRunner : EcsRunner<IEcsInit>, IEcsInit
{
2024-10-31 14:54:16 +08:00
private RunHelper _helper;
protected override void OnSetup()
{
2024-10-31 15:27:53 +08:00
_helper = new RunHelper(this);
}
public void Init()
{
2024-10-31 14:54:16 +08:00
_helper.Run(p => p.Init());
}
}
2024-04-28 19:43:10 +08:00
#if ENABLE_IL2CPP
[Il2CppSetOption(Option.NullChecks, false)]
[Il2CppSetOption(Option.ArrayBoundsChecks, false)]
#endif
2024-05-01 13:38:08 +08:00
[MetaColor(MetaColor.DragonRose)]
2024-06-13 18:04:18 +08:00
[MetaGroup(EcsConsts.PACK_GROUP, EcsConsts.PROCESSES_GROUP)]
2024-06-11 02:30:00 +08:00
[MetaDescription(EcsConsts.AUTHOR, "...")]
2024-06-13 18:04:18 +08:00
[MetaTags(MetaTags.HIDDEN)]
2024-10-12 00:08:12 +08:00
[MetaID("2098527C9201F260C840BFD50BC7E0BA")]
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
}
}
2024-04-28 19:43:10 +08:00
#if ENABLE_IL2CPP
[Il2CppSetOption(Option.NullChecks, false)]
[Il2CppSetOption(Option.ArrayBoundsChecks, false)]
#endif
2024-05-01 13:38:08 +08:00
[MetaColor(MetaColor.DragonRose)]
2024-06-13 18:04:18 +08:00
[MetaGroup(EcsConsts.PACK_GROUP, EcsConsts.PROCESSES_GROUP)]
2024-06-11 02:30:00 +08:00
[MetaDescription(EcsConsts.AUTHOR, "...")]
2024-06-13 18:04:18 +08:00
[MetaTags(MetaTags.HIDDEN)]
2024-10-12 00:08:12 +08:00
[MetaID("06A6527C92010430ACEB3DA520F272CC")]
internal sealed class EcsDestroyRunner : EcsRunner<IEcsDestroy>, IEcsDestroy
{
2024-10-31 14:54:16 +08:00
private RunHelper _helper;
protected override void OnSetup()
{
2024-10-31 15:27:53 +08:00
_helper = new RunHelper(this);
}
public void Destroy()
{
2024-10-31 14:54:16 +08:00
_helper.Run(p => p.Destroy());
2023-04-23 18:05:27 +08:00
}
2023-03-12 02:02:39 +08:00
}
2024-10-31 14:54:16 +08:00
}