rename IEcsSystem to IEcsProcess

This commit is contained in:
Mikhail 2023-05-30 18:27:30 +08:00
parent 9d35096f09
commit 5661d1e6d9
5 changed files with 37 additions and 37 deletions

View File

@ -3,19 +3,19 @@
namespace DCFApixels.DragonECS
{
#region Interfaces
public interface IEcsPreInitProcess : IEcsSystem
public interface IEcsPreInitProcess : IEcsProcess
{
void PreInit(EcsPipeline pipeline);
}
public interface IEcsInitProcess : IEcsSystem
public interface IEcsInitProcess : IEcsProcess
{
void Init(EcsPipeline pipeline);
}
public interface IEcsRunProcess : IEcsSystem
public interface IEcsRunProcess : IEcsProcess
{
void Run(EcsPipeline pipeline);
}
public interface IEcsDestroyProcess : IEcsSystem
public interface IEcsDestroyProcess : IEcsProcess
{
void Destroy(EcsPipeline pipeline);
}

View File

@ -5,15 +5,15 @@ using System.Linq;
namespace DCFApixels.DragonECS
{
public interface IEcsPreInject : IEcsSystem
public interface IEcsPreInject : IEcsProcess
{
void PreInject(object obj);
}
public interface IEcsInject<T> : IEcsSystem
public interface IEcsInject<T> : IEcsProcess
{
void Inject(T obj);
}
public interface IEcsPreInitInjectProcess : IEcsSystem
public interface IEcsPreInitInjectProcess : IEcsProcess
{
void OnPreInitInjectionBefore();
void OnPreInitInjectionAfter();

View File

@ -6,7 +6,7 @@ namespace DCFApixels.DragonECS
namespace Internal
{
[DebugHide, DebugColor(DebugColor.Black)]
public class SystemsLayerMarkerSystem : IEcsSystem
public class SystemsLayerMarkerSystem : IEcsProcess
{
public readonly string name;
public SystemsLayerMarkerSystem(string name) => this.name = name;

View File

@ -11,30 +11,30 @@ namespace DCFApixels.DragonECS
{
public sealed class EcsPipeline
{
private IEcsSystem[] _allSystems;
private IEcsProcess[] _allSystems;
private Dictionary<Type, IEcsRunner> _runners;
private IEcsRunProcess _runRunnerCache;
private ReadOnlyCollection<IEcsSystem> _allSystemsSealed;
private ReadOnlyCollection<IEcsProcess> _allSystemsSealed;
private ReadOnlyDictionary<Type, IEcsRunner> _allRunnersSealed;
private bool _isInit;
private bool _isDestoryed;
#region Properties
public ReadOnlyCollection<IEcsSystem> AllSystems => _allSystemsSealed;
public ReadOnlyCollection<IEcsProcess> AllSystems => _allSystemsSealed;
public ReadOnlyDictionary<Type, IEcsRunner> AllRunners => _allRunnersSealed;
public bool IsInit => _isInit;
public bool IsDestoryed => _isDestoryed;
#endregion
#region Constructors
private EcsPipeline(IEcsSystem[] systems)
private EcsPipeline(IEcsProcess[] systems)
{
_allSystems = systems;
_runners = new Dictionary<Type, IEcsRunner>();
_allSystemsSealed = new ReadOnlyCollection<IEcsSystem>(_allSystems);
_allSystemsSealed = new ReadOnlyCollection<IEcsProcess>(_allSystems);
_allRunnersSealed = new ReadOnlyDictionary<Type, IEcsRunner>(_runners);
_isInit = false;
@ -43,7 +43,7 @@ namespace DCFApixels.DragonECS
#endregion
#region Runners
public T GetRunner<T>() where T : IEcsSystem
public T GetRunner<T>() where T : IEcsProcess
{
Type type = typeof(T);
if (_runners.TryGetValue(type, out IEcsRunner result))
@ -132,7 +132,7 @@ namespace DCFApixels.DragonECS
{
private const int KEYS_CAPACITY = 4;
private HashSet<Type> _uniqueTypes;
private readonly Dictionary<string, List<IEcsSystem>> _systems;
private readonly Dictionary<string, List<IEcsProcess>> _systems;
private readonly string _basicLayer;
public readonly LayerList Layers;
public Builder()
@ -142,14 +142,14 @@ namespace DCFApixels.DragonECS
Layers.Insert(EcsConsts.BASIC_LAYER, EcsConsts.PRE_BEGIN_LAYER, EcsConsts.BEGIN_LAYER);
Layers.InsertAfter(EcsConsts.BASIC_LAYER, EcsConsts.END_LAYER, EcsConsts.POST_END_LAYER);
_uniqueTypes = new HashSet<Type>();
_systems = new Dictionary<string, List<IEcsSystem>>(KEYS_CAPACITY);
_systems = new Dictionary<string, List<IEcsProcess>>(KEYS_CAPACITY);
}
public Builder Add(IEcsSystem system, string layerName = null)
public Builder Add(IEcsProcess system, string layerName = null)
{
AddInternal(system, layerName, false);
return this;
}
public Builder AddUnique(IEcsSystem system, string layerName = null)
public Builder AddUnique(IEcsProcess system, string layerName = null)
{
AddInternal(system, layerName, true);
return this;
@ -161,13 +161,13 @@ namespace DCFApixels.DragonECS
list.RemoveAll(o => o is TSystem);
return this;
}
private void AddInternal(IEcsSystem system, string layerName, bool isUnique)
private void AddInternal(IEcsProcess system, string layerName, bool isUnique)
{
if (layerName == null) layerName = _basicLayer;
List<IEcsSystem> list;
List<IEcsProcess> list;
if (!_systems.TryGetValue(layerName, out list))
{
list = new List<IEcsSystem> { new SystemsLayerMarkerSystem(layerName.ToString()) };
list = new List<IEcsProcess> { new SystemsLayerMarkerSystem(layerName.ToString()) };
_systems.Add(layerName, list);
}
if ((_uniqueTypes.Add(system.GetType()) == false && isUnique))
@ -185,8 +185,8 @@ namespace DCFApixels.DragonECS
public EcsPipeline Build()
{
Add(new DeleteEmptyEntitesSystem(), EcsConsts.POST_END_LAYER);
List<IEcsSystem> result = new List<IEcsSystem>(32);
List<IEcsSystem> basicBlockList = _systems[_basicLayer];
List<IEcsProcess> result = new List<IEcsProcess>(32);
List<IEcsProcess> basicBlockList = _systems[_basicLayer];
foreach (var item in _systems)
{
if (!Layers.Contains(item.Key))
@ -315,12 +315,12 @@ namespace DCFApixels.DragonECS
public static class EcsPipelineExtensions
{
public static bool IsNullOrDestroyed(this EcsPipeline self) => self == null || self.IsDestoryed;
public static EcsPipeline.Builder Add(this EcsPipeline.Builder self, IEnumerable<IEcsSystem> range, string layerName = null)
public static EcsPipeline.Builder Add(this EcsPipeline.Builder self, IEnumerable<IEcsProcess> range, string layerName = null)
{
foreach (var item in range) self.Add(item, layerName);
return self;
}
public static EcsPipeline.Builder AddUnique(this EcsPipeline.Builder self, IEnumerable<IEcsSystem> range, string layerName = null)
public static EcsPipeline.Builder AddUnique(this EcsPipeline.Builder self, IEnumerable<IEcsProcess> range, string layerName = null)
{
foreach (var item in range) self.AddUnique(item, layerName);
return self;

View File

@ -23,7 +23,7 @@ namespace DCFApixels.DragonECS
public EcsRunnerFilterAttribute(object filter) : this(null, filter) { }
}
public interface IEcsSystem { }
public interface IEcsProcess { }
namespace RunnersCore
{
@ -103,7 +103,7 @@ namespace DCFApixels.DragonECS
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static void InitFor<TInterface>() where TInterface : IEcsSystem
internal static void InitFor<TInterface>() where TInterface : IEcsProcess
{
Type interfaceType = typeof(TInterface);
@ -122,8 +122,8 @@ namespace DCFApixels.DragonECS
#if UNITY_2020_3_OR_NEWER
[UnityEngine.Scripting.RequireDerived, UnityEngine.Scripting.Preserve]
#endif
public abstract class EcsRunner<TInterface> : IEcsSystem, IEcsRunner
where TInterface : IEcsSystem
public abstract class EcsRunner<TInterface> : IEcsProcess, IEcsRunner
where TInterface : IEcsProcess
{
#region Register
private static Type _subclass;
@ -142,9 +142,9 @@ namespace DCFApixels.DragonECS
{
throw new ArgumentException($"{typeof(TInterface).FullName} is not interface");
}
if (interfaces.Length != 1 || interfaces[0] != typeof(IEcsSystem))
if (interfaces.Length != 1 || interfaces[0] != typeof(IEcsProcess))
{
throw new ArgumentException($"{typeof(TInterface).FullName} does not directly inherit the {nameof(IEcsSystem)} interface");
throw new ArgumentException($"{typeof(TInterface).FullName} does not directly inherit the {nameof(IEcsProcess)} interface");
}
#endif
_subclass = subclass;
@ -152,15 +152,15 @@ namespace DCFApixels.DragonECS
#endregion
#region FilterSystems
private static TInterface[] FilterSystems(IEnumerable<IEcsSystem> targets)
private static TInterface[] FilterSystems(IEnumerable<IEcsProcess> targets)
{
return targets.Where(o => o is TInterface).Select(o => (TInterface)o).ToArray();
}
private static TInterface[] FilterSystems(IEnumerable<IEcsSystem> targets, object filter)
private static TInterface[] FilterSystems(IEnumerable<IEcsProcess> targets, object filter)
{
Type interfaceType = typeof(TInterface);
IEnumerable<IEcsSystem> newTargets;
IEnumerable<IEcsProcess> newTargets;
if (filter != null)
{
@ -189,7 +189,7 @@ namespace DCFApixels.DragonECS
{
if (_subclass == null) EcsRunnerActivator.InitFor<TInterface>();
var instance = (EcsRunner<TInterface>)Activator.CreateInstance(_subclass);
return (TInterface)(IEcsSystem)instance.Set(source, targets, isHasFilter, filter);
return (TInterface)(IEcsProcess)instance.Set(source, targets, isHasFilter, filter);
}
public static TInterface Instantiate(EcsPipeline source)
{
@ -253,11 +253,11 @@ namespace DCFApixels.DragonECS
#region Extensions
public static class EcsRunner
{
public static void Destroy(IEcsSystem runner) => ((IEcsRunner)runner).Destroy();
public static void Destroy(IEcsProcess runner) => ((IEcsRunner)runner).Destroy();
}
public static class IEcsSystemExtensions
{
public static bool IsRunner(this IEcsSystem self)
public static bool IsRunner(this IEcsProcess self)
{
return self is IEcsRunner;
}