mirror of
https://github.com/DCFApixels/DragonECS.git
synced 2025-09-18 01:44:35 +08:00
update
This commit is contained in:
parent
bb35fa6150
commit
170106273f
@ -15,7 +15,8 @@ namespace DCFApixels.DragonECS
|
||||
public sealed class EcsPipeline
|
||||
{
|
||||
private readonly IEcsPipelineConfig _config;
|
||||
private readonly Injector _injector;
|
||||
private Injector.Builder _injectorBuilder;
|
||||
private Injector _injector;
|
||||
|
||||
private IEcsProcess[] _allSystems;
|
||||
private Dictionary<Type, Array> _processes = new Dictionary<Type, Array>();
|
||||
@ -25,6 +26,8 @@ namespace DCFApixels.DragonECS
|
||||
private bool _isInit = false;
|
||||
private bool _isDestoryed = false;
|
||||
|
||||
private EcsProfilerMarker _initBarker = new EcsProfilerMarker("EcsPipeline.Init");
|
||||
|
||||
#region Properties
|
||||
public IEcsPipelineConfig Config
|
||||
{
|
||||
@ -42,22 +45,22 @@ namespace DCFApixels.DragonECS
|
||||
{
|
||||
get { return _runners; }
|
||||
}
|
||||
public bool IsInit
|
||||
{
|
||||
get { return _isInit; }
|
||||
public bool IsInit
|
||||
{
|
||||
get { return _isInit; }
|
||||
}
|
||||
public bool IsDestoryed
|
||||
{
|
||||
get { return _isDestoryed; }
|
||||
public bool IsDestoryed
|
||||
{
|
||||
get { return _isDestoryed; }
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
private EcsPipeline(IEcsPipelineConfig config, Injector.Builder injector, IEcsProcess[] systems)
|
||||
private EcsPipeline(IEcsPipelineConfig config, Injector.Builder injectorBuilder, IEcsProcess[] systems)
|
||||
{
|
||||
_config = config;
|
||||
_allSystems = systems;
|
||||
_injector = injector.Build(this);
|
||||
_injectorBuilder = injectorBuilder;
|
||||
}
|
||||
#endregion
|
||||
|
||||
@ -66,7 +69,7 @@ namespace DCFApixels.DragonECS
|
||||
{
|
||||
Type type = typeof(T);
|
||||
T[] result;
|
||||
if(_processes.TryGetValue(type, out Array array))
|
||||
if (_processes.TryGetValue(type, out Array array))
|
||||
{
|
||||
result = (T[])array;
|
||||
}
|
||||
@ -120,13 +123,14 @@ namespace DCFApixels.DragonECS
|
||||
EcsDebug.PrintWarning($"This {nameof(EcsPipeline)} has already been initialized");
|
||||
return;
|
||||
}
|
||||
|
||||
_initBarker.Begin();
|
||||
EcsProcess<IEcsPipelineMember> members = GetProcess<IEcsPipelineMember>();
|
||||
foreach (var member in members)
|
||||
{
|
||||
member.Pipeline = this;
|
||||
}
|
||||
Injector.Inject(this);
|
||||
_injector = _injectorBuilder.Build(this);
|
||||
_injectorBuilder = null;
|
||||
|
||||
var preInitRunner = GetRunner<IEcsPreInit>();
|
||||
preInitRunner.PreInit();
|
||||
@ -139,6 +143,7 @@ namespace DCFApixels.DragonECS
|
||||
_isInit = true;
|
||||
|
||||
GC.Collect();
|
||||
_initBarker.End();
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
@ -179,7 +184,7 @@ namespace DCFApixels.DragonECS
|
||||
public readonly LayerList Layers;
|
||||
private readonly IEcsPipelineConfigWriter _config;
|
||||
private readonly Injector.Builder _injector;
|
||||
private EcsProfilerMarker _buildBarker = new EcsProfilerMarker("Build Marker");
|
||||
private EcsProfilerMarker _buildBarker = new EcsProfilerMarker("EcsPipeline.Build");
|
||||
|
||||
public IEcsPipelineConfigWriter Config
|
||||
{
|
||||
|
@ -173,7 +173,7 @@ namespace DCFApixels.DragonECS
|
||||
}
|
||||
public bool IsEmpty
|
||||
{
|
||||
get { return _process.IsNullOrEmpty;}
|
||||
get { return _process.IsNullOrEmpty; }
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
@ -318,7 +318,7 @@ namespace DCFApixels.DragonECS
|
||||
delCount++;
|
||||
}
|
||||
}
|
||||
if(delCount > 0)
|
||||
if (delCount > 0)
|
||||
{
|
||||
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
|
||||
{
|
||||
[MetaName(nameof(Inject))]
|
||||
[MetaColor(MetaColor.Orange)]
|
||||
public interface IEcsInject<T> : IEcsProcess
|
||||
{
|
||||
void Inject(T obj);
|
||||
}
|
||||
[MetaName(nameof(OnInitInjectionComplete))]
|
||||
[MetaColor(MetaColor.Orange)]
|
||||
public interface IOnInitInjectionComplete : IEcsProcess
|
||||
{
|
||||
void OnInitInjectionComplete();
|
||||
}
|
||||
public class Injector
|
||||
{
|
||||
private EcsPipeline _pipeline;
|
||||
@ -16,7 +23,7 @@ namespace DCFApixels.DragonECS
|
||||
private bool _isInit = false;
|
||||
|
||||
private Injector() { }
|
||||
|
||||
|
||||
public void Inject<T>(T obj)
|
||||
{
|
||||
Type type = typeof(T);
|
||||
@ -38,25 +45,25 @@ namespace DCFApixels.DragonECS
|
||||
}
|
||||
branch.Inject(obj);
|
||||
}
|
||||
// public void InjectNoBoxing<T>(T data) where T : struct
|
||||
// {
|
||||
// foreach (var system in _pipeline.GetProcess<IEcsInject<T>>())
|
||||
// {
|
||||
// system.Inject(data);
|
||||
// }
|
||||
// }
|
||||
//#if !REFLECTION_DISABLED
|
||||
// public void InjectRaw(object obj)
|
||||
// {
|
||||
// Type type = obj.GetType();
|
||||
// if (_branches.TryGetValue(type, out InjectionBranch branch) == false)
|
||||
// {
|
||||
// branch = new InjectionBranch(this, type, false);
|
||||
// InitBranch(branch);
|
||||
// }
|
||||
// branch.Inject(obj);
|
||||
// }
|
||||
//#endif
|
||||
// public void InjectNoBoxing<T>(T data) where T : struct
|
||||
// {
|
||||
// foreach (var system in _pipeline.GetProcess<IEcsInject<T>>())
|
||||
// {
|
||||
// system.Inject(data);
|
||||
// }
|
||||
// }
|
||||
//#if !REFLECTION_DISABLED
|
||||
// public void InjectRaw(object obj)
|
||||
// {
|
||||
// Type type = obj.GetType();
|
||||
// if (_branches.TryGetValue(type, out InjectionBranch branch) == false)
|
||||
// {
|
||||
// branch = new InjectionBranch(this, type, false);
|
||||
// InitBranch(branch);
|
||||
// }
|
||||
// branch.Inject(obj);
|
||||
// }
|
||||
//#endif
|
||||
|
||||
#region Internal
|
||||
private void InitBranch(InjectionBranch branch)
|
||||
@ -138,9 +145,10 @@ namespace DCFApixels.DragonECS
|
||||
_instance.TryDeclare<T>();
|
||||
return _source;
|
||||
}
|
||||
public void Inject<T>(T obj)
|
||||
public EcsPipeline.Builder Inject<T>(T obj)
|
||||
{
|
||||
_initInjections.Add(new InitInject<T>(obj));
|
||||
return _source;
|
||||
}
|
||||
public Injector Build(EcsPipeline pipeline)
|
||||
{
|
||||
@ -149,6 +157,10 @@ namespace DCFApixels.DragonECS
|
||||
{
|
||||
item.InjectTo(_instance);
|
||||
}
|
||||
foreach (var system in pipeline.GetProcess<IOnInitInjectionComplete>())
|
||||
{
|
||||
system.OnInitInjectionComplete();
|
||||
}
|
||||
return _instance;
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
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)
|
||||
{
|
||||
@ -11,7 +11,6 @@ namespace DCFApixels.DragonECS
|
||||
Throw.ArgumentNull();
|
||||
}
|
||||
self.Injector.Inject(data);
|
||||
//self.Add(new InitInjectionSystem<T>(data));
|
||||
if (data is IEcsModule module)
|
||||
{
|
||||
self.AddModule(module);
|
||||
@ -34,17 +33,17 @@ namespace DCFApixels.DragonECS
|
||||
{
|
||||
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()
|
||||
{
|
||||
throw new ArgumentNullException();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,16 +11,16 @@
|
||||
{
|
||||
_injectionGraph.Inject(obj);
|
||||
}
|
||||
// public void InjectNoBoxing<T>(T data) where T : struct
|
||||
// {
|
||||
// _injectionGraph.InjectNoBoxing(data);
|
||||
// }
|
||||
//#if !REFLECTION_DISABLED
|
||||
// public void InjectRaw(object obj)
|
||||
// {
|
||||
// _injectionGraph.InjectRaw(obj);
|
||||
// }
|
||||
//#endif
|
||||
// public void InjectNoBoxing<T>(T data) where T : struct
|
||||
// {
|
||||
// _injectionGraph.InjectNoBoxing(data);
|
||||
// }
|
||||
//#if !REFLECTION_DISABLED
|
||||
// public void InjectRaw(object obj)
|
||||
// {
|
||||
// _injectionGraph.InjectRaw(obj);
|
||||
// }
|
||||
//#endif
|
||||
}
|
||||
public interface IInjectionBlock
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user