mirror of
https://github.com/DCFApixels/DragonECS.git
synced 2025-09-18 09:54:35 +08:00
refactoring / fixes
This commit is contained in:
parent
8d6395e9d6
commit
046a560014
@ -390,7 +390,7 @@ namespace DCFApixels.DragonECS
|
|||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum EcsMemberType : byte
|
public enum EcsMemberType : byte
|
||||||
|
@ -179,7 +179,7 @@ namespace DCFApixels.DragonECS
|
|||||||
public readonly Injector.Builder Injector;
|
public readonly Injector.Builder Injector;
|
||||||
public readonly Configurator Configs;
|
public readonly Configurator Configs;
|
||||||
|
|
||||||
private AddParams _defaultAddParams;
|
private AddParams _defaultAddParams = new AddParams(BASIC_LAYER, 0, false);
|
||||||
|
|
||||||
#region Properties
|
#region Properties
|
||||||
private ReadOnlySpan<SystemRecord> SystemRecords
|
private ReadOnlySpan<SystemRecord> SystemRecords
|
||||||
@ -205,6 +205,10 @@ namespace DCFApixels.DragonECS
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Add IEcsProcess
|
#region Add IEcsProcess
|
||||||
|
public Builder Add(IEcsProcess system)
|
||||||
|
{
|
||||||
|
return AddSystem_Internal(system, AddParams.Default);
|
||||||
|
}
|
||||||
public Builder Add(IEcsProcess system, string layerName)
|
public Builder Add(IEcsProcess system, string layerName)
|
||||||
{
|
{
|
||||||
return AddSystem_Internal(system, new AddParams(layerName: layerName));
|
return AddSystem_Internal(system, new AddParams(layerName: layerName));
|
||||||
@ -266,7 +270,7 @@ namespace DCFApixels.DragonECS
|
|||||||
_moduleSystemsStack = new Stack<IEcsProcess>(4);
|
_moduleSystemsStack = new Stack<IEcsProcess>(4);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_moduleSystemsStack.Count <= 0 && system != _moduleSystemsStack.Peek())
|
if (_moduleSystemsStack.Count <= 0 || system != _moduleSystemsStack.Peek())
|
||||||
{
|
{
|
||||||
_moduleSystemsStack.Push(system);
|
_moduleSystemsStack.Push(system);
|
||||||
AddModule_Internal(module, prms);
|
AddModule_Internal(module, prms);
|
||||||
@ -296,6 +300,10 @@ namespace DCFApixels.DragonECS
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region AddModule IEcsModule
|
#region AddModule IEcsModule
|
||||||
|
public Builder AddModule(IEcsModule module)
|
||||||
|
{
|
||||||
|
return AddModule_Internal(module, AddParams.Default);
|
||||||
|
}
|
||||||
public Builder AddModule(IEcsModule module, string layerName)
|
public Builder AddModule(IEcsModule module, string layerName)
|
||||||
{
|
{
|
||||||
return AddModule_Internal(module, new AddParams(layerName: layerName));
|
return AddModule_Internal(module, new AddParams(layerName: layerName));
|
||||||
@ -347,15 +355,21 @@ namespace DCFApixels.DragonECS
|
|||||||
{
|
{
|
||||||
prms = prms.Overwrite(overrideInterface.AddParams);
|
prms = prms.Overwrite(overrideInterface.AddParams);
|
||||||
}
|
}
|
||||||
|
var oldDefaultAddParams = _defaultAddParams;
|
||||||
_defaultAddParams = prms.Overwrite(settedAddParams);
|
_defaultAddParams = prms.Overwrite(settedAddParams);
|
||||||
|
|
||||||
module.Import(this);
|
module.Import(this);
|
||||||
|
|
||||||
|
_defaultAddParams = oldDefaultAddParams;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Add Raw
|
#region Add Raw
|
||||||
|
public Builder Add(object raw)
|
||||||
|
{
|
||||||
|
return AddRaw_Internal(raw, AddParams.Default);
|
||||||
|
}
|
||||||
public Builder Add(object raw, string layerName)
|
public Builder Add(object raw, string layerName)
|
||||||
{
|
{
|
||||||
return AddRaw_Internal(raw, new AddParams(layerName: layerName));
|
return AddRaw_Internal(raw, new AddParams(layerName: layerName));
|
||||||
@ -437,7 +451,7 @@ namespace DCFApixels.DragonECS
|
|||||||
//_systemRecordsInrement + otherRecord.addOrder смещает порядок так что новые системы встают в конец очереди, но сохраняют порядок addOrder
|
//_systemRecordsInrement + otherRecord.addOrder смещает порядок так что новые системы встают в конец очереди, но сохраняют порядок addOrder
|
||||||
foreach (var otherRecord in other.SystemRecords)
|
foreach (var otherRecord in other.SystemRecords)
|
||||||
{
|
{
|
||||||
AddRecord_Internal(otherRecord.system, otherRecord.layer, otherRecord.sortOrder, otherRecord.isUnique, _systemRecordsInrement + otherRecord.addOrder);
|
AddRecord_Internal(otherRecord.system, otherRecord.layerName, otherRecord.sortOrder, otherRecord.isUnique, _systemRecordsInrement + otherRecord.addOrder);
|
||||||
}
|
}
|
||||||
_systemRecordsInrement += other._systemRecordsInrement;
|
_systemRecordsInrement += other._systemRecordsInrement;
|
||||||
}
|
}
|
||||||
@ -447,7 +461,7 @@ namespace DCFApixels.DragonECS
|
|||||||
private void RemoveAt(int index)
|
private void RemoveAt(int index)
|
||||||
{
|
{
|
||||||
ref var slot = ref _systemRecords[index];
|
ref var slot = ref _systemRecords[index];
|
||||||
_layerLists[slot.layer].lasyInitSystemsCount--;
|
_layerLists[slot.layerName].lasyInitSystemsCount--;
|
||||||
slot = _systemRecords[--_systemRecordsCount];
|
slot = _systemRecords[--_systemRecordsCount];
|
||||||
}
|
}
|
||||||
public Builder Remove<TSystem>()
|
public Builder Remove<TSystem>()
|
||||||
@ -501,7 +515,7 @@ namespace DCFApixels.DragonECS
|
|||||||
for (int i = 0, iMax = _systemRecordsCount; i < iMax; i++)
|
for (int i = 0, iMax = _systemRecordsCount; i < iMax; i++)
|
||||||
{
|
{
|
||||||
ref var record = ref _systemRecords[i];
|
ref var record = ref _systemRecords[i];
|
||||||
var list = _layerLists[record.layer];
|
var list = _layerLists[record.layerName];
|
||||||
if (list.IsInit == false)
|
if (list.IsInit == false)
|
||||||
{
|
{
|
||||||
list = basicLayerList;
|
list = basicLayerList;
|
||||||
@ -881,11 +895,11 @@ namespace DCFApixels.DragonECS
|
|||||||
var records = SystemRecords;
|
var records = SystemRecords;
|
||||||
EcsPipelineTemplate result = new EcsPipelineTemplate();
|
EcsPipelineTemplate result = new EcsPipelineTemplate();
|
||||||
result.layers = new string[Layers.Count];
|
result.layers = new string[Layers.Count];
|
||||||
result.systems = new EcsPipelineTemplate.SystemRecord[records.Length];
|
result.systems = new EcsPipelineTemplate.AddCommand[records.Length];
|
||||||
for (int i = 0; i < records.Length; i++)
|
for (int i = 0; i < records.Length; i++)
|
||||||
{
|
{
|
||||||
var r = records[i];
|
var r = records[i];
|
||||||
result.systems[i] = new EcsPipelineTemplate.SystemRecord(r.system, r.layer, r.sortOrder, r.isUnique);
|
result.systems[i] = new EcsPipelineTemplate.AddCommand(r.system, new AddParams(r.layerName, r.sortOrder, r.isUnique));
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
@ -896,14 +910,14 @@ namespace DCFApixels.DragonECS
|
|||||||
private readonly struct SystemRecord : IComparable<SystemRecord>
|
private readonly struct SystemRecord : IComparable<SystemRecord>
|
||||||
{
|
{
|
||||||
public readonly IEcsProcess system;
|
public readonly IEcsProcess system;
|
||||||
public readonly string layer;
|
public readonly string layerName;
|
||||||
public readonly int addOrder;
|
public readonly int addOrder;
|
||||||
public readonly int sortOrder;
|
public readonly int sortOrder;
|
||||||
public readonly bool isUnique;
|
public readonly bool isUnique;
|
||||||
public SystemRecord(IEcsProcess system, string layer, int addOrder, int sortOrder, bool isUnique)
|
public SystemRecord(IEcsProcess system, string layerName, int addOrder, int sortOrder, bool isUnique)
|
||||||
{
|
{
|
||||||
this.system = system;
|
this.system = system;
|
||||||
this.layer = layer;
|
this.layerName = layerName;
|
||||||
this.addOrder = addOrder;
|
this.addOrder = addOrder;
|
||||||
this.sortOrder = sortOrder;
|
this.sortOrder = sortOrder;
|
||||||
this.isUnique = isUnique;
|
this.isUnique = isUnique;
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
using DCFApixels.DragonECS.Internal;
|
using DCFApixels.DragonECS.Internal;
|
||||||
using DCFApixels.DragonECS.PoolsCore;
|
|
||||||
using DCFApixels.DragonECS.RunnersCore;
|
using DCFApixels.DragonECS.RunnersCore;
|
||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
@ -555,7 +555,7 @@ namespace DCFApixels.DragonECS
|
|||||||
{
|
{
|
||||||
if (_groups[i].TryGetTarget(out EcsGroup group))
|
if (_groups[i].TryGetTarget(out EcsGroup group))
|
||||||
{
|
{
|
||||||
if(group.IsReleased)
|
if (group.IsReleased)
|
||||||
{
|
{
|
||||||
group.OnReleaseDelEntityBuffer_Internal(buffer);
|
group.OnReleaseDelEntityBuffer_Internal(buffer);
|
||||||
}
|
}
|
||||||
|
@ -2,8 +2,10 @@ using DCFApixels.DragonECS.PoolsCore;
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Reflection;
|
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
|
#if (DEBUG && !DISABLE_DEBUG)
|
||||||
|
using System.Reflection;
|
||||||
|
#endif
|
||||||
#if ENABLE_IL2CPP
|
#if ENABLE_IL2CPP
|
||||||
using Unity.IL2CPP.CompilerServices;
|
using Unity.IL2CPP.CompilerServices;
|
||||||
#endif
|
#endif
|
||||||
@ -42,7 +44,7 @@ namespace DCFApixels.DragonECS
|
|||||||
private EcsWorld.PoolsMediator _mediator;
|
private EcsWorld.PoolsMediator _mediator;
|
||||||
|
|
||||||
#region CheckValide
|
#region CheckValide
|
||||||
#if DEBUG
|
#if (DEBUG && !DISABLE_DEBUG)
|
||||||
private static bool _isInvalidType;
|
private static bool _isInvalidType;
|
||||||
static EcsTagPool()
|
static EcsTagPool()
|
||||||
{
|
{
|
||||||
|
@ -8,43 +8,27 @@ namespace DCFApixels.DragonECS
|
|||||||
public class EcsPipelineTemplate : IEcsModule
|
public class EcsPipelineTemplate : IEcsModule
|
||||||
{
|
{
|
||||||
[DataMember] public string[] layers;
|
[DataMember] public string[] layers;
|
||||||
[DataMember] public SystemRecord[] systems;
|
[DataMember] public AddCommand[] systems;
|
||||||
void IEcsModule.Import(EcsPipeline.Builder b)
|
void IEcsModule.Import(EcsPipeline.Builder b)
|
||||||
{
|
{
|
||||||
b.Layers.MergeWith(layers);
|
b.Layers.MergeWith(layers);
|
||||||
foreach (var s in systems)
|
foreach (var s in systems)
|
||||||
{
|
{
|
||||||
if (s.system == null) { continue; }
|
if (s.target == null) { continue; }
|
||||||
|
|
||||||
int? sortOrder = s.isCustomSortOrder ? s.sortOrder : default(int?);
|
b.Add(s.target, s.parameters);
|
||||||
if (s.isUnique)
|
|
||||||
{
|
|
||||||
b.AddUnique(s.system, s.layer, sortOrder);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
b.Add(s.system, s.layer, sortOrder);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Serializable]
|
[Serializable]
|
||||||
[DataContract]
|
[DataContract]
|
||||||
public struct SystemRecord
|
public struct AddCommand
|
||||||
{
|
{
|
||||||
[DataMember] public IEcsProcess system;
|
[DataMember] public object target;
|
||||||
[DataMember] public string layer;
|
[DataMember] public AddParams parameters;
|
||||||
[DataMember] public int sortOrder;
|
public AddCommand(object target, AddParams parameters)
|
||||||
[DataMember] public bool isCustomSortOrder;
|
|
||||||
[DataMember] public bool isUnique;
|
|
||||||
public int? NullableSortOrder { get { return isCustomSortOrder ? sortOrder : default(int?); } }
|
|
||||||
public SystemRecord(IEcsProcess system, string layer, int? sortOrder, bool isUnique)
|
|
||||||
{
|
{
|
||||||
this.system = system;
|
this.target = target;
|
||||||
this.layer = layer;
|
this.parameters = parameters;
|
||||||
this.sortOrder = sortOrder.HasValue ? sortOrder.Value : 0;
|
|
||||||
isCustomSortOrder = sortOrder.HasValue;
|
|
||||||
this.isUnique = isUnique;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user