mirror of
https://github.com/DCFApixels/DragonECS.git
synced 2025-09-19 02:24:37 +08:00
update
This commit is contained in:
parent
bb35fa6150
commit
170106273f
@ -15,7 +15,8 @@ namespace DCFApixels.DragonECS
|
|||||||
public sealed class EcsPipeline
|
public sealed class EcsPipeline
|
||||||
{
|
{
|
||||||
private readonly IEcsPipelineConfig _config;
|
private readonly IEcsPipelineConfig _config;
|
||||||
private readonly Injector _injector;
|
private Injector.Builder _injectorBuilder;
|
||||||
|
private Injector _injector;
|
||||||
|
|
||||||
private IEcsProcess[] _allSystems;
|
private IEcsProcess[] _allSystems;
|
||||||
private Dictionary<Type, Array> _processes = new Dictionary<Type, Array>();
|
private Dictionary<Type, Array> _processes = new Dictionary<Type, Array>();
|
||||||
@ -25,6 +26,8 @@ namespace DCFApixels.DragonECS
|
|||||||
private bool _isInit = false;
|
private bool _isInit = false;
|
||||||
private bool _isDestoryed = false;
|
private bool _isDestoryed = false;
|
||||||
|
|
||||||
|
private EcsProfilerMarker _initBarker = new EcsProfilerMarker("EcsPipeline.Init");
|
||||||
|
|
||||||
#region Properties
|
#region Properties
|
||||||
public IEcsPipelineConfig Config
|
public IEcsPipelineConfig Config
|
||||||
{
|
{
|
||||||
@ -42,22 +45,22 @@ namespace DCFApixels.DragonECS
|
|||||||
{
|
{
|
||||||
get { return _runners; }
|
get { return _runners; }
|
||||||
}
|
}
|
||||||
public bool IsInit
|
public bool IsInit
|
||||||
{
|
{
|
||||||
get { return _isInit; }
|
get { return _isInit; }
|
||||||
}
|
}
|
||||||
public bool IsDestoryed
|
public bool IsDestoryed
|
||||||
{
|
{
|
||||||
get { return _isDestoryed; }
|
get { return _isDestoryed; }
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Constructors
|
#region Constructors
|
||||||
private EcsPipeline(IEcsPipelineConfig config, Injector.Builder injector, IEcsProcess[] systems)
|
private EcsPipeline(IEcsPipelineConfig config, Injector.Builder injectorBuilder, IEcsProcess[] systems)
|
||||||
{
|
{
|
||||||
_config = config;
|
_config = config;
|
||||||
_allSystems = systems;
|
_allSystems = systems;
|
||||||
_injector = injector.Build(this);
|
_injectorBuilder = injectorBuilder;
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -66,7 +69,7 @@ namespace DCFApixels.DragonECS
|
|||||||
{
|
{
|
||||||
Type type = typeof(T);
|
Type type = typeof(T);
|
||||||
T[] result;
|
T[] result;
|
||||||
if(_processes.TryGetValue(type, out Array array))
|
if (_processes.TryGetValue(type, out Array array))
|
||||||
{
|
{
|
||||||
result = (T[])array;
|
result = (T[])array;
|
||||||
}
|
}
|
||||||
@ -120,13 +123,14 @@ namespace DCFApixels.DragonECS
|
|||||||
EcsDebug.PrintWarning($"This {nameof(EcsPipeline)} has already been initialized");
|
EcsDebug.PrintWarning($"This {nameof(EcsPipeline)} has already been initialized");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
_initBarker.Begin();
|
||||||
EcsProcess<IEcsPipelineMember> members = GetProcess<IEcsPipelineMember>();
|
EcsProcess<IEcsPipelineMember> members = GetProcess<IEcsPipelineMember>();
|
||||||
foreach (var member in members)
|
foreach (var member in members)
|
||||||
{
|
{
|
||||||
member.Pipeline = this;
|
member.Pipeline = this;
|
||||||
}
|
}
|
||||||
Injector.Inject(this);
|
_injector = _injectorBuilder.Build(this);
|
||||||
|
_injectorBuilder = null;
|
||||||
|
|
||||||
var preInitRunner = GetRunner<IEcsPreInit>();
|
var preInitRunner = GetRunner<IEcsPreInit>();
|
||||||
preInitRunner.PreInit();
|
preInitRunner.PreInit();
|
||||||
@ -139,6 +143,7 @@ namespace DCFApixels.DragonECS
|
|||||||
_isInit = true;
|
_isInit = true;
|
||||||
|
|
||||||
GC.Collect();
|
GC.Collect();
|
||||||
|
_initBarker.End();
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
@ -179,7 +184,7 @@ namespace DCFApixels.DragonECS
|
|||||||
public readonly LayerList Layers;
|
public readonly LayerList Layers;
|
||||||
private readonly IEcsPipelineConfigWriter _config;
|
private readonly IEcsPipelineConfigWriter _config;
|
||||||
private readonly Injector.Builder _injector;
|
private readonly Injector.Builder _injector;
|
||||||
private EcsProfilerMarker _buildBarker = new EcsProfilerMarker("Build Marker");
|
private EcsProfilerMarker _buildBarker = new EcsProfilerMarker("EcsPipeline.Build");
|
||||||
|
|
||||||
public IEcsPipelineConfigWriter Config
|
public IEcsPipelineConfigWriter Config
|
||||||
{
|
{
|
||||||
|
@ -173,7 +173,7 @@ namespace DCFApixels.DragonECS
|
|||||||
}
|
}
|
||||||
public bool IsEmpty
|
public bool IsEmpty
|
||||||
{
|
{
|
||||||
get { return _process.IsNullOrEmpty;}
|
get { return _process.IsNullOrEmpty; }
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
@ -318,7 +318,7 @@ namespace DCFApixels.DragonECS
|
|||||||
delCount++;
|
delCount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(delCount > 0)
|
if (delCount > 0)
|
||||||
{
|
{
|
||||||
EcsDebug.PrintWarning($"Detected and deleted {delCount} leaking entities.");
|
EcsDebug.PrintWarning($"Detected and deleted {delCount} leaking entities.");
|
||||||
}
|
}
|
||||||
|
@ -1,54 +0,0 @@
|
|||||||
using System.Collections.Generic;
|
|
||||||
|
|
||||||
namespace DCFApixels.DragonECS.Internal
|
|
||||||
{
|
|
||||||
public abstract class InitInjectSystemBase : IEcsProcess { }
|
|
||||||
|
|
||||||
[MetaTags(MetaTags.HIDDEN)]
|
|
||||||
[MetaColor(MetaColor.Gray)]
|
|
||||||
public class InitInjectionSystem<T> : InitInjectSystemBase, IEcsPipelineMember, IEcsInject<InitInjectController>, IEcsPreInitInjectProcess
|
|
||||||
{
|
|
||||||
private EcsPipeline _pipeline;
|
|
||||||
public EcsPipeline Pipeline
|
|
||||||
{
|
|
||||||
get { return Pipeline; }
|
|
||||||
set { _pipeline = value; Init(); }
|
|
||||||
}
|
|
||||||
private InitInjectController _injectController;
|
|
||||||
void IEcsInject<InitInjectController>.Inject(InitInjectController obj) { _injectController = obj; }
|
|
||||||
|
|
||||||
private T _injectedData;
|
|
||||||
internal InitInjectionSystem(T injectedData)
|
|
||||||
{
|
|
||||||
if (injectedData == null)
|
|
||||||
{
|
|
||||||
Throw.ArgumentNull();
|
|
||||||
}
|
|
||||||
_injectedData = injectedData;
|
|
||||||
}
|
|
||||||
private void Init()
|
|
||||||
{
|
|
||||||
if (_injectedData == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (_injectController == null)
|
|
||||||
{
|
|
||||||
_injectController = new InitInjectController(_pipeline);
|
|
||||||
_pipeline.GetRunner<IEcsPreInitInjectProcess>().OnPreInitInjectionBefore(_pipeline);
|
|
||||||
_pipeline.Injector.Inject(_injectController);
|
|
||||||
}
|
|
||||||
_pipeline.Injector.Inject(_injectedData);
|
|
||||||
if (_injectController.OnInject())
|
|
||||||
{
|
|
||||||
_injectController.Destroy();
|
|
||||||
var injectCallbacksRunner = _pipeline.GetRunner<IEcsPreInitInjectProcess>();
|
|
||||||
injectCallbacksRunner.OnPreInitInjectionAfter();
|
|
||||||
EcsRunner.Destroy(injectCallbacksRunner);
|
|
||||||
}
|
|
||||||
_injectedData = default;
|
|
||||||
}
|
|
||||||
void IEcsPreInitInjectProcess.OnPreInitInjectionBefore(EcsPipeline pipeline) { }
|
|
||||||
void IEcsPreInitInjectProcess.OnPreInitInjectionAfter() { _injectController = null; }
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,11 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: ca86cb991f1d9204d98af8ff27199b70
|
|
||||||
MonoImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
@ -4,10 +4,17 @@ using System.Collections.Generic;
|
|||||||
namespace DCFApixels.DragonECS
|
namespace DCFApixels.DragonECS
|
||||||
{
|
{
|
||||||
[MetaName(nameof(Inject))]
|
[MetaName(nameof(Inject))]
|
||||||
|
[MetaColor(MetaColor.Orange)]
|
||||||
public interface IEcsInject<T> : IEcsProcess
|
public interface IEcsInject<T> : IEcsProcess
|
||||||
{
|
{
|
||||||
void Inject(T obj);
|
void Inject(T obj);
|
||||||
}
|
}
|
||||||
|
[MetaName(nameof(OnInitInjectionComplete))]
|
||||||
|
[MetaColor(MetaColor.Orange)]
|
||||||
|
public interface IOnInitInjectionComplete : IEcsProcess
|
||||||
|
{
|
||||||
|
void OnInitInjectionComplete();
|
||||||
|
}
|
||||||
public class Injector
|
public class Injector
|
||||||
{
|
{
|
||||||
private EcsPipeline _pipeline;
|
private EcsPipeline _pipeline;
|
||||||
@ -16,7 +23,7 @@ namespace DCFApixels.DragonECS
|
|||||||
private bool _isInit = false;
|
private bool _isInit = false;
|
||||||
|
|
||||||
private Injector() { }
|
private Injector() { }
|
||||||
|
|
||||||
public void Inject<T>(T obj)
|
public void Inject<T>(T obj)
|
||||||
{
|
{
|
||||||
Type type = typeof(T);
|
Type type = typeof(T);
|
||||||
@ -38,25 +45,25 @@ namespace DCFApixels.DragonECS
|
|||||||
}
|
}
|
||||||
branch.Inject(obj);
|
branch.Inject(obj);
|
||||||
}
|
}
|
||||||
// public void InjectNoBoxing<T>(T data) where T : struct
|
// public void InjectNoBoxing<T>(T data) where T : struct
|
||||||
// {
|
// {
|
||||||
// foreach (var system in _pipeline.GetProcess<IEcsInject<T>>())
|
// foreach (var system in _pipeline.GetProcess<IEcsInject<T>>())
|
||||||
// {
|
// {
|
||||||
// system.Inject(data);
|
// system.Inject(data);
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
//#if !REFLECTION_DISABLED
|
//#if !REFLECTION_DISABLED
|
||||||
// public void InjectRaw(object obj)
|
// public void InjectRaw(object obj)
|
||||||
// {
|
// {
|
||||||
// Type type = obj.GetType();
|
// Type type = obj.GetType();
|
||||||
// if (_branches.TryGetValue(type, out InjectionBranch branch) == false)
|
// if (_branches.TryGetValue(type, out InjectionBranch branch) == false)
|
||||||
// {
|
// {
|
||||||
// branch = new InjectionBranch(this, type, false);
|
// branch = new InjectionBranch(this, type, false);
|
||||||
// InitBranch(branch);
|
// InitBranch(branch);
|
||||||
// }
|
// }
|
||||||
// branch.Inject(obj);
|
// branch.Inject(obj);
|
||||||
// }
|
// }
|
||||||
//#endif
|
//#endif
|
||||||
|
|
||||||
#region Internal
|
#region Internal
|
||||||
private void InitBranch(InjectionBranch branch)
|
private void InitBranch(InjectionBranch branch)
|
||||||
@ -138,9 +145,10 @@ namespace DCFApixels.DragonECS
|
|||||||
_instance.TryDeclare<T>();
|
_instance.TryDeclare<T>();
|
||||||
return _source;
|
return _source;
|
||||||
}
|
}
|
||||||
public void Inject<T>(T obj)
|
public EcsPipeline.Builder Inject<T>(T obj)
|
||||||
{
|
{
|
||||||
_initInjections.Add(new InitInject<T>(obj));
|
_initInjections.Add(new InitInject<T>(obj));
|
||||||
|
return _source;
|
||||||
}
|
}
|
||||||
public Injector Build(EcsPipeline pipeline)
|
public Injector Build(EcsPipeline pipeline)
|
||||||
{
|
{
|
||||||
@ -149,6 +157,10 @@ namespace DCFApixels.DragonECS
|
|||||||
{
|
{
|
||||||
item.InjectTo(_instance);
|
item.InjectTo(_instance);
|
||||||
}
|
}
|
||||||
|
foreach (var system in pipeline.GetProcess<IOnInitInjectionComplete>())
|
||||||
|
{
|
||||||
|
system.OnInitInjectionComplete();
|
||||||
|
}
|
||||||
return _instance;
|
return _instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
namespace DCFApixels.DragonECS
|
namespace DCFApixels.DragonECS
|
||||||
{
|
{
|
||||||
public static partial class EcsPipelineBuilderExtensions
|
public static partial class InjectorBuilderExtensions
|
||||||
{
|
{
|
||||||
public static EcsPipeline.Builder Inject<T>(this EcsPipeline.Builder self, T data)
|
public static EcsPipeline.Builder Inject<T>(this EcsPipeline.Builder self, T data)
|
||||||
{
|
{
|
||||||
@ -11,7 +11,6 @@ namespace DCFApixels.DragonECS
|
|||||||
Throw.ArgumentNull();
|
Throw.ArgumentNull();
|
||||||
}
|
}
|
||||||
self.Injector.Inject(data);
|
self.Injector.Inject(data);
|
||||||
//self.Add(new InitInjectionSystem<T>(data));
|
|
||||||
if (data is IEcsModule module)
|
if (data is IEcsModule module)
|
||||||
{
|
{
|
||||||
self.AddModule(module);
|
self.AddModule(module);
|
||||||
@ -34,17 +33,17 @@ namespace DCFApixels.DragonECS
|
|||||||
{
|
{
|
||||||
return self.Inject(d0).Inject(d1).Inject(d2).Inject(d3).Inject(d4);
|
return self.Inject(d0).Inject(d1).Inject(d2).Inject(d3).Inject(d4);
|
||||||
}
|
}
|
||||||
public static EcsPipeline.Builder Inject<T0, T1, T2, T3, T4, T5>(this EcsPipeline.Builder self, T0 d0, T1 d1, T2 d2, T3 d3, T4 d4, T5 f)
|
public static EcsPipeline.Builder Inject<T0, T1, T2, T3, T4, T5>(this EcsPipeline.Builder self, T0 d0, T1 d1, T2 d2, T3 d3, T4 d4, T5 d5)
|
||||||
{
|
{
|
||||||
return self.Inject(d0).Inject(d1).Inject(d2).Inject(d3).Inject(d4).Inject(f);
|
return self.Inject(d0).Inject(d1).Inject(d2).Inject(d3).Inject(d4).Inject(d5);
|
||||||
}
|
}
|
||||||
public static EcsPipeline.Builder Inject<T0, T1, T2, T3, T4, T5, T6>(this EcsPipeline.Builder self, T0 d0, T1 d1, T2 d2, T3 d3, T4 d4, T5 f, T6 d6)
|
public static EcsPipeline.Builder Inject<T0, T1, T2, T3, T4, T5, T6>(this EcsPipeline.Builder self, T0 d0, T1 d1, T2 d2, T3 d3, T4 d4, T5 d5, T6 d6)
|
||||||
{
|
{
|
||||||
return self.Inject(d0).Inject(d1).Inject(d2).Inject(d3).Inject(d4).Inject(f).Inject(d6);
|
return self.Inject(d0).Inject(d1).Inject(d2).Inject(d3).Inject(d4).Inject(d5).Inject(d6);
|
||||||
}
|
}
|
||||||
public static EcsPipeline.Builder Inject<T0, T1, T2, T3, T4, T5, T6, T7>(this EcsPipeline.Builder self, T0 d0, T1 d1, T2 d2, T3 d3, T4 d4, T5 f, T6 d6, T7 d7)
|
public static EcsPipeline.Builder Inject<T0, T1, T2, T3, T4, T5, T6, T7>(this EcsPipeline.Builder self, T0 d0, T1 d1, T2 d2, T3 d3, T4 d4, T5 d5, T6 d6, T7 d7)
|
||||||
{
|
{
|
||||||
return self.Inject(d0).Inject(d1).Inject(d2).Inject(d3).Inject(d4).Inject(f).Inject(d6).Inject(d7);
|
return self.Inject(d0).Inject(d1).Inject(d2).Inject(d3).Inject(d4).Inject(d5).Inject(d6).Inject(d7);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,61 +0,0 @@
|
|||||||
using DCFApixels.DragonECS.Internal;
|
|
||||||
using DCFApixels.DragonECS.RunnersCore;
|
|
||||||
|
|
||||||
namespace DCFApixels.DragonECS
|
|
||||||
{
|
|
||||||
[MetaName("PreInitInject")]
|
|
||||||
[BindWithEcsRunner(typeof(EcsInitInjectProcessRunner))]
|
|
||||||
public interface IEcsPreInitInjectProcess : IEcsProcess
|
|
||||||
{
|
|
||||||
void OnPreInitInjectionBefore(EcsPipeline pipeline);
|
|
||||||
void OnPreInitInjectionAfter();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
namespace DCFApixels.DragonECS.Internal
|
|
||||||
{
|
|
||||||
internal class InitInjectController
|
|
||||||
{
|
|
||||||
private EcsPipeline _source;
|
|
||||||
private EcsProcess<InitInjectSystemBase> _injectSystems;
|
|
||||||
private int _injectCount;
|
|
||||||
public bool IsInjectionEnd
|
|
||||||
{
|
|
||||||
get { return _injectCount >= _injectSystems.Length; }
|
|
||||||
}
|
|
||||||
public InitInjectController(EcsPipeline source)
|
|
||||||
{
|
|
||||||
_injectCount = 0;
|
|
||||||
_source = source;
|
|
||||||
_injectSystems = _source.GetProcess<InitInjectSystemBase>();
|
|
||||||
}
|
|
||||||
public bool OnInject()
|
|
||||||
{
|
|
||||||
_injectCount++;
|
|
||||||
return IsInjectionEnd;
|
|
||||||
}
|
|
||||||
public void Destroy()
|
|
||||||
{
|
|
||||||
_source = null;
|
|
||||||
_injectSystems = EcsProcess<InitInjectSystemBase>.Empty;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
[MetaTags(MetaTags.HIDDEN)]
|
|
||||||
[MetaColor(MetaColor.Gray)]
|
|
||||||
public sealed class EcsInitInjectProcessRunner : EcsRunner<IEcsPreInitInjectProcess>, IEcsPreInitInjectProcess
|
|
||||||
{
|
|
||||||
public void OnPreInitInjectionAfter()
|
|
||||||
{
|
|
||||||
foreach (var item in Process)
|
|
||||||
{
|
|
||||||
item.OnPreInitInjectionAfter();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public void OnPreInitInjectionBefore(EcsPipeline pipeline)
|
|
||||||
{
|
|
||||||
foreach (var item in Process)
|
|
||||||
{
|
|
||||||
item.OnPreInitInjectionBefore(pipeline);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,11 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: 37d3cc800496c9442ad9f81bc94e94ee
|
|
||||||
MonoImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
@ -7,6 +7,6 @@ namespace DCFApixels.DragonECS.DI.Internal
|
|||||||
public static void ArgumentNull()
|
public static void ArgumentNull()
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException();
|
throw new ArgumentNullException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,16 +11,16 @@
|
|||||||
{
|
{
|
||||||
_injectionGraph.Inject(obj);
|
_injectionGraph.Inject(obj);
|
||||||
}
|
}
|
||||||
// public void InjectNoBoxing<T>(T data) where T : struct
|
// public void InjectNoBoxing<T>(T data) where T : struct
|
||||||
// {
|
// {
|
||||||
// _injectionGraph.InjectNoBoxing(data);
|
// _injectionGraph.InjectNoBoxing(data);
|
||||||
// }
|
// }
|
||||||
//#if !REFLECTION_DISABLED
|
//#if !REFLECTION_DISABLED
|
||||||
// public void InjectRaw(object obj)
|
// public void InjectRaw(object obj)
|
||||||
// {
|
// {
|
||||||
// _injectionGraph.InjectRaw(obj);
|
// _injectionGraph.InjectRaw(obj);
|
||||||
// }
|
// }
|
||||||
//#endif
|
//#endif
|
||||||
}
|
}
|
||||||
public interface IInjectionBlock
|
public interface IInjectionBlock
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user