mirror of
https://github.com/DCFApixels/DragonECS.git
synced 2025-09-18 09:54:35 +08:00
refactoring
This commit is contained in:
parent
ed30d58614
commit
79238733d7
@ -21,121 +21,128 @@ namespace DCFApixels.DragonECS
|
|||||||
|
|
||||||
public interface IEcsBaseSystem : IEcsInitSystem, IEcsRunSystem, IEcsDestroySystem { }
|
public interface IEcsBaseSystem : IEcsInitSystem, IEcsRunSystem, IEcsDestroySystem { }
|
||||||
|
|
||||||
public sealed class EcsPreInitRunner : EcsRunner<IEcsPreInitSystem>, IEcsPreInitSystem
|
namespace Internal
|
||||||
{
|
{
|
||||||
#if DEBUG && !DISABLE_DEBUG
|
[DebugColor(DebugColor.Orange)]
|
||||||
private EcsProfilerMarker[] _markers;
|
public sealed class EcsPreInitRunner : EcsRunner<IEcsPreInitSystem>, IEcsPreInitSystem
|
||||||
#endif
|
|
||||||
public void PreInit(EcsPipeline pipeline)
|
|
||||||
{
|
{
|
||||||
#if DEBUG && !DISABLE_DEBUG
|
#if DEBUG && !DISABLE_DEBUG
|
||||||
for (int i = 0; i < targets.Length && targets.Length <= _markers.Length; i++)
|
private EcsProfilerMarker[] _markers;
|
||||||
|
#endif
|
||||||
|
public void PreInit(EcsPipeline pipeline)
|
||||||
{
|
{
|
||||||
using (_markers[i].Auto())
|
#if DEBUG && !DISABLE_DEBUG
|
||||||
targets[i].PreInit(pipeline);
|
for (int i = 0; i < targets.Length && targets.Length <= _markers.Length; i++)
|
||||||
}
|
{
|
||||||
|
using (_markers[i].Auto())
|
||||||
|
targets[i].PreInit(pipeline);
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
foreach (var item in targets) item.PreInit(pipeline);
|
foreach (var item in targets) item.PreInit(pipeline);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#if DEBUG && !DISABLE_DEBUG
|
#if DEBUG && !DISABLE_DEBUG
|
||||||
protected override void OnSetup()
|
protected override void OnSetup()
|
||||||
{
|
|
||||||
_markers = new EcsProfilerMarker[targets.Length];
|
|
||||||
for (int i = 0; i < targets.Length; i++)
|
|
||||||
{
|
{
|
||||||
_markers[i] = new EcsProfilerMarker(EcsDebug.RegisterMark($"EcsRunner.{targets[i].GetType().Name}.{nameof(PreInit)}"));
|
_markers = new EcsProfilerMarker[targets.Length];
|
||||||
|
for (int i = 0; i < targets.Length; i++)
|
||||||
|
{
|
||||||
|
_markers[i] = new EcsProfilerMarker(EcsDebug.RegisterMark($"EcsRunner.{targets[i].GetType().Name}.{nameof(PreInit)}"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
#endif
|
[DebugColor(DebugColor.Orange)]
|
||||||
}
|
public sealed class EcsInitRunner : EcsRunner<IEcsInitSystem>, IEcsInitSystem
|
||||||
public sealed class EcsInitRunner : EcsRunner<IEcsInitSystem>, IEcsInitSystem
|
|
||||||
{
|
|
||||||
#if DEBUG && !DISABLE_DEBUG
|
|
||||||
private EcsProfilerMarker[] _markers;
|
|
||||||
#endif
|
|
||||||
public void Init(EcsPipeline pipeline)
|
|
||||||
{
|
{
|
||||||
#if DEBUG && !DISABLE_DEBUG
|
#if DEBUG && !DISABLE_DEBUG
|
||||||
for (int i = 0; i < targets.Length && targets.Length <= _markers.Length; i++)
|
private EcsProfilerMarker[] _markers;
|
||||||
|
#endif
|
||||||
|
public void Init(EcsPipeline pipeline)
|
||||||
{
|
{
|
||||||
using (_markers[i].Auto())
|
#if DEBUG && !DISABLE_DEBUG
|
||||||
targets[i].Init(pipeline);
|
for (int i = 0; i < targets.Length && targets.Length <= _markers.Length; i++)
|
||||||
}
|
{
|
||||||
|
using (_markers[i].Auto())
|
||||||
|
targets[i].Init(pipeline);
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
foreach (var item in targets) item.Init(pipeline);
|
foreach (var item in targets) item.Init(pipeline);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#if DEBUG && !DISABLE_DEBUG
|
#if DEBUG && !DISABLE_DEBUG
|
||||||
protected override void OnSetup()
|
protected override void OnSetup()
|
||||||
{
|
|
||||||
_markers = new EcsProfilerMarker[targets.Length];
|
|
||||||
for (int i = 0; i < targets.Length; i++)
|
|
||||||
{
|
{
|
||||||
_markers[i] = new EcsProfilerMarker(EcsDebug.RegisterMark($"EcsRunner.{targets[i].GetType().Name}.{nameof(Init)}"));
|
_markers = new EcsProfilerMarker[targets.Length];
|
||||||
|
for (int i = 0; i < targets.Length; i++)
|
||||||
|
{
|
||||||
|
_markers[i] = new EcsProfilerMarker(EcsDebug.RegisterMark($"EcsRunner.{targets[i].GetType().Name}.{nameof(Init)}"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
#endif
|
[DebugColor(DebugColor.Orange)]
|
||||||
}
|
public sealed class EcsRunRunner : EcsRunner<IEcsRunSystem>, IEcsRunSystem
|
||||||
public sealed class EcsRunRunner : EcsRunner<IEcsRunSystem>, IEcsRunSystem
|
|
||||||
{
|
|
||||||
#if DEBUG && !DISABLE_DEBUG
|
|
||||||
private EcsProfilerMarker[] _markers;
|
|
||||||
#endif
|
|
||||||
public void Run(EcsPipeline pipeline)
|
|
||||||
{
|
{
|
||||||
#if DEBUG && !DISABLE_DEBUG
|
#if DEBUG && !DISABLE_DEBUG
|
||||||
for (int i = 0; i < targets.Length && targets.Length <= _markers.Length; i++)
|
private EcsProfilerMarker[] _markers;
|
||||||
|
#endif
|
||||||
|
public void Run(EcsPipeline pipeline)
|
||||||
{
|
{
|
||||||
using (_markers[i].Auto())
|
#if DEBUG && !DISABLE_DEBUG
|
||||||
targets[i].Run(pipeline);
|
for (int i = 0; i < targets.Length && targets.Length <= _markers.Length; i++)
|
||||||
|
{
|
||||||
|
using (_markers[i].Auto())
|
||||||
|
targets[i].Run(pipeline);
|
||||||
|
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
foreach (var item in targets) item.Run(pipeline);
|
foreach (var item in targets) item.Run(pipeline);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#if DEBUG && !DISABLE_DEBUG
|
#if DEBUG && !DISABLE_DEBUG
|
||||||
protected override void OnSetup()
|
protected override void OnSetup()
|
||||||
{
|
|
||||||
_markers = new EcsProfilerMarker[targets.Length];
|
|
||||||
for (int i = 0; i < targets.Length; i++)
|
|
||||||
{
|
{
|
||||||
_markers[i] = new EcsProfilerMarker(EcsDebug.RegisterMark($"EcsRunner.{targets[i].GetType().Name}.{nameof(Run)}"));
|
_markers = new EcsProfilerMarker[targets.Length];
|
||||||
|
for (int i = 0; i < targets.Length; i++)
|
||||||
|
{
|
||||||
|
_markers[i] = new EcsProfilerMarker(EcsDebug.RegisterMark($"EcsRunner.{targets[i].GetType().Name}.{nameof(Run)}"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
#endif
|
[DebugColor(DebugColor.Orange)]
|
||||||
}
|
public sealed class EcsDestroyRunner : EcsRunner<IEcsDestroySystem>, IEcsDestroySystem
|
||||||
public sealed class EcsDestroyRunner : EcsRunner<IEcsDestroySystem>, IEcsDestroySystem
|
|
||||||
{
|
|
||||||
#if DEBUG && !DISABLE_DEBUG
|
|
||||||
private EcsProfilerMarker[] _markers;
|
|
||||||
#endif
|
|
||||||
public void Destroy(EcsPipeline pipeline)
|
|
||||||
{
|
{
|
||||||
#if DEBUG && !DISABLE_DEBUG
|
#if DEBUG && !DISABLE_DEBUG
|
||||||
for (int i = 0; i < targets.Length && targets.Length <= _markers.Length; i++)
|
private EcsProfilerMarker[] _markers;
|
||||||
|
#endif
|
||||||
|
public void Destroy(EcsPipeline pipeline)
|
||||||
{
|
{
|
||||||
using (_markers[i].Auto())
|
#if DEBUG && !DISABLE_DEBUG
|
||||||
targets[i].Destroy(pipeline);
|
for (int i = 0; i < targets.Length && targets.Length <= _markers.Length; i++)
|
||||||
}
|
{
|
||||||
|
using (_markers[i].Auto())
|
||||||
|
targets[i].Destroy(pipeline);
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
foreach (var item in targets) item.Destroy(pipeline);
|
foreach (var item in targets) item.Destroy(pipeline);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#if DEBUG && !DISABLE_DEBUG
|
#if DEBUG && !DISABLE_DEBUG
|
||||||
protected override void OnSetup()
|
protected override void OnSetup()
|
||||||
{
|
|
||||||
_markers = new EcsProfilerMarker[targets.Length];
|
|
||||||
for (int i = 0; i < targets.Length; i++)
|
|
||||||
{
|
{
|
||||||
_markers[i] = new EcsProfilerMarker(EcsDebug.RegisterMark($"EcsRunner.{targets[i].GetType().Name}.{nameof(Destroy)}"));
|
_markers = new EcsProfilerMarker[targets.Length];
|
||||||
|
for (int i = 0; i < targets.Length; i++)
|
||||||
|
{
|
||||||
|
_markers[i] = new EcsProfilerMarker(EcsDebug.RegisterMark($"EcsRunner.{targets[i].GetType().Name}.{nameof(Destroy)}"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,52 +39,52 @@ namespace DCFApixels.DragonECS
|
|||||||
{
|
{
|
||||||
public void PreInject(object obj);
|
public void PreInject(object obj);
|
||||||
}
|
}
|
||||||
[DebugHide, DebugColor(DebugColor.Gray)]
|
|
||||||
public sealed class PreInjectRunner : EcsRunner<IEcsPreInject>, IEcsPreInject
|
|
||||||
{
|
|
||||||
void IEcsPreInject.PreInject(object obj)
|
|
||||||
{
|
|
||||||
foreach (var item in targets) item.PreInject(obj);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public interface IEcsInject<T> : IEcsSystem
|
public interface IEcsInject<T> : IEcsSystem
|
||||||
{
|
{
|
||||||
public void Inject(T obj);
|
public void Inject(T obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
[DebugHide, DebugColor(DebugColor.Gray)]
|
|
||||||
public sealed class InjectRunner<T> : EcsRunner<IEcsInject<T>>, IEcsInject<T>
|
|
||||||
{
|
|
||||||
private IEcsPreInject _preInjectchache;
|
|
||||||
void IEcsInject<T>.Inject(T obj)
|
|
||||||
{
|
|
||||||
_preInjectchache.PreInject(obj);
|
|
||||||
foreach (var item in targets) item.Inject(obj);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void OnSetup()
|
|
||||||
{
|
|
||||||
_preInjectchache = Source.GetRunner<IEcsPreInject>();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public interface IEcsPreInitInjectCallbacks : IEcsSystem
|
public interface IEcsPreInitInjectCallbacks : IEcsSystem
|
||||||
{
|
{
|
||||||
public void OnPreInitInjectionBefore();
|
public void OnPreInitInjectionBefore();
|
||||||
public void OnPreInitInjectionAfter();
|
public void OnPreInitInjectionAfter();
|
||||||
}
|
}
|
||||||
|
|
||||||
[DebugHide, DebugColor(DebugColor.Gray)]
|
namespace Internal
|
||||||
public sealed class InjectCallbacksRunner : EcsRunner<IEcsPreInitInjectCallbacks>, IEcsPreInitInjectCallbacks
|
|
||||||
{
|
{
|
||||||
public void OnPreInitInjectionAfter()
|
[DebugHide, DebugColor(DebugColor.Gray)]
|
||||||
|
public sealed class PreInjectRunner : EcsRunner<IEcsPreInject>, IEcsPreInject
|
||||||
{
|
{
|
||||||
foreach (var item in targets) item.OnPreInitInjectionAfter();
|
void IEcsPreInject.PreInject(object obj)
|
||||||
|
{
|
||||||
|
foreach (var item in targets) item.PreInject(obj);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
public void OnPreInitInjectionBefore()
|
[DebugHide, DebugColor(DebugColor.Gray)]
|
||||||
|
public sealed class InjectRunner<T> : EcsRunner<IEcsInject<T>>, IEcsInject<T>
|
||||||
{
|
{
|
||||||
foreach (var item in targets) item.OnPreInitInjectionBefore();
|
private IEcsPreInject _preInjectchache;
|
||||||
|
void IEcsInject<T>.Inject(T obj)
|
||||||
|
{
|
||||||
|
_preInjectchache.PreInject(obj);
|
||||||
|
foreach (var item in targets) item.Inject(obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnSetup()
|
||||||
|
{
|
||||||
|
_preInjectchache = Source.GetRunner<IEcsPreInject>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
[DebugHide, DebugColor(DebugColor.Gray)]
|
||||||
|
public sealed class InjectCallbacksRunner : EcsRunner<IEcsPreInitInjectCallbacks>, IEcsPreInitInjectCallbacks
|
||||||
|
{
|
||||||
|
public void OnPreInitInjectionAfter()
|
||||||
|
{
|
||||||
|
foreach (var item in targets) item.OnPreInitInjectionAfter();
|
||||||
|
}
|
||||||
|
public void OnPreInitInjectionBefore()
|
||||||
|
{
|
||||||
|
foreach (var item in targets) item.OnPreInitInjectionBefore();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,28 +15,34 @@ namespace DCFApixels.DragonECS
|
|||||||
public void OnComponentDel<T>(int entityID);
|
public void OnComponentDel<T>(int entityID);
|
||||||
}
|
}
|
||||||
public interface IEcsComponentLifecycle : IEcsComponentAdd, IEcsComponentWrite, IEcsComponentDel { }
|
public interface IEcsComponentLifecycle : IEcsComponentAdd, IEcsComponentWrite, IEcsComponentDel { }
|
||||||
public sealed class EcsEntityAddComponentRunner : EcsRunner<IEcsComponentAdd>, IEcsComponentAdd
|
|
||||||
{
|
|
||||||
public void OnComponentAdd<T>(int entityID)
|
|
||||||
{
|
|
||||||
foreach (var item in targets) item.OnComponentAdd<T>(entityID);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public sealed class EcsEntityChangeComponentRunner : EcsRunner<IEcsComponentWrite>, IEcsComponentWrite
|
|
||||||
{
|
|
||||||
public void OnComponentWrite<T>(int entityID)
|
|
||||||
{
|
|
||||||
foreach (var item in targets) item.OnComponentWrite<T>(entityID);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public sealed class EcsEntityDelComponentRunner : EcsRunner<IEcsComponentDel>, IEcsComponentDel
|
|
||||||
{
|
|
||||||
public void OnComponentDel<T>(int entityID)
|
|
||||||
{
|
|
||||||
foreach (var item in targets) item.OnComponentDel<T>(entityID);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
namespace Internal
|
||||||
|
{
|
||||||
|
[DebugColor(DebugColor.Orange)]
|
||||||
|
public sealed class EcsEntityAddComponentRunner : EcsRunner<IEcsComponentAdd>, IEcsComponentAdd
|
||||||
|
{
|
||||||
|
public void OnComponentAdd<T>(int entityID)
|
||||||
|
{
|
||||||
|
foreach (var item in targets) item.OnComponentAdd<T>(entityID);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
[DebugColor(DebugColor.Orange)]
|
||||||
|
public sealed class EcsEntityChangeComponentRunner : EcsRunner<IEcsComponentWrite>, IEcsComponentWrite
|
||||||
|
{
|
||||||
|
public void OnComponentWrite<T>(int entityID)
|
||||||
|
{
|
||||||
|
foreach (var item in targets) item.OnComponentWrite<T>(entityID);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
[DebugColor(DebugColor.Orange)]
|
||||||
|
public sealed class EcsEntityDelComponentRunner : EcsRunner<IEcsComponentDel>, IEcsComponentDel
|
||||||
|
{
|
||||||
|
public void OnComponentDel<T>(int entityID)
|
||||||
|
{
|
||||||
|
foreach (var item in targets) item.OnComponentDel<T>(entityID);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public interface IEcsEntityCreate : IEcsSystem
|
public interface IEcsEntityCreate : IEcsSystem
|
||||||
{
|
{
|
||||||
@ -47,21 +53,26 @@ namespace DCFApixels.DragonECS
|
|||||||
public void OnEntityDestroy(EcsEntity entity);
|
public void OnEntityDestroy(EcsEntity entity);
|
||||||
}
|
}
|
||||||
public interface IEcsEntityLifecycle : IEcsEntityCreate, IEcsEntityDestroy { }
|
public interface IEcsEntityLifecycle : IEcsEntityCreate, IEcsEntityDestroy { }
|
||||||
public sealed class EcsEntityCreateRunner : EcsRunner<IEcsEntityCreate>, IEcsEntityCreate
|
|
||||||
{
|
|
||||||
public void OnEntityCreate(EcsEntity entity)
|
|
||||||
{
|
|
||||||
foreach (var item in targets) item.OnEntityCreate(entity);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public sealed class EcsEntityDestroyRunner : EcsRunner<IEcsEntityDestroy>, IEcsEntityDestroy
|
|
||||||
{
|
|
||||||
public void OnEntityDestroy(EcsEntity entity)
|
|
||||||
{
|
|
||||||
foreach (var item in targets) item.OnEntityDestroy(entity);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
namespace Internal
|
||||||
|
{
|
||||||
|
[DebugColor(DebugColor.Orange)]
|
||||||
|
public sealed class EcsEntityCreateRunner : EcsRunner<IEcsEntityCreate>, IEcsEntityCreate
|
||||||
|
{
|
||||||
|
public void OnEntityCreate(EcsEntity entity)
|
||||||
|
{
|
||||||
|
foreach (var item in targets) item.OnEntityCreate(entity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
[DebugColor(DebugColor.Orange)]
|
||||||
|
public sealed class EcsEntityDestroyRunner : EcsRunner<IEcsEntityDestroy>, IEcsEntityDestroy
|
||||||
|
{
|
||||||
|
public void OnEntityDestroy(EcsEntity entity)
|
||||||
|
{
|
||||||
|
foreach (var item in targets) item.OnEntityDestroy(entity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public interface IEcsWorldCreate : IEcsSystem
|
public interface IEcsWorldCreate : IEcsSystem
|
||||||
{
|
{
|
||||||
@ -72,18 +83,24 @@ namespace DCFApixels.DragonECS
|
|||||||
public void OnWorldDestroy(EcsWorld world);
|
public void OnWorldDestroy(EcsWorld world);
|
||||||
}
|
}
|
||||||
public interface IEcsWorldLifecycle : IEcsWorldCreate, IEcsWorldDestroy { }
|
public interface IEcsWorldLifecycle : IEcsWorldCreate, IEcsWorldDestroy { }
|
||||||
public sealed class EcsWorldCreateRunner : EcsRunner<IEcsWorldCreate>, IEcsWorldCreate
|
|
||||||
|
namespace Internal
|
||||||
{
|
{
|
||||||
public void OnWorldCreate(EcsWorld world)
|
[DebugColor(DebugColor.Orange)]
|
||||||
|
public sealed class EcsWorldCreateRunner : EcsRunner<IEcsWorldCreate>, IEcsWorldCreate
|
||||||
{
|
{
|
||||||
foreach (var item in targets) item.OnWorldCreate(world);
|
public void OnWorldCreate(EcsWorld world)
|
||||||
|
{
|
||||||
|
foreach (var item in targets) item.OnWorldCreate(world);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
[DebugColor(DebugColor.Orange)]
|
||||||
public sealed class EcsWorldDestryRunner : EcsRunner<IEcsWorldDestroy>, IEcsWorldDestroy
|
public sealed class EcsWorldDestryRunner : EcsRunner<IEcsWorldDestroy>, IEcsWorldDestroy
|
||||||
{
|
|
||||||
public void OnWorldDestroy(EcsWorld world)
|
|
||||||
{
|
{
|
||||||
foreach (var item in targets) item.OnWorldDestroy(world);
|
public void OnWorldDestroy(EcsWorld world)
|
||||||
|
{
|
||||||
|
foreach (var item in targets) item.OnWorldDestroy(world);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user