|
|
@@ -1,4 +1,5 @@ |
|
|
|
using System; |
|
|
|
using System.Collections; |
|
|
|
using System.Collections.Generic; |
|
|
|
using Svelto.Common; |
|
|
|
using Svelto.DataStructures; |
|
|
@@ -9,26 +10,38 @@ namespace Svelto.ECS |
|
|
|
{ |
|
|
|
public sealed partial class EnginesRoot |
|
|
|
{ |
|
|
|
public readonly struct EntitiesSubmitter |
|
|
|
public struct EntitiesSubmitter |
|
|
|
{ |
|
|
|
public EntitiesSubmitter(EnginesRoot enginesRoot) |
|
|
|
public EntitiesSubmitter(EnginesRoot enginesRoot) : this() |
|
|
|
{ |
|
|
|
_weakReference = new Svelto.DataStructures.WeakReference<EnginesRoot>(enginesRoot); |
|
|
|
} |
|
|
|
|
|
|
|
public bool IsUnused => _weakReference.IsValid == false; |
|
|
|
|
|
|
|
public void Invoke() |
|
|
|
public IEnumerator Invoke(uint maxNumberOfOperationsPerFrame) |
|
|
|
{ |
|
|
|
if (_weakReference.IsValid) |
|
|
|
_weakReference.Target.SubmitEntityComponents(); |
|
|
|
var entitiesSubmissionScheduler = _weakReference.Target._scheduler; |
|
|
|
if (_weakReference.IsValid && entitiesSubmissionScheduler.paused == false) |
|
|
|
{ |
|
|
|
var submitEntityComponents = |
|
|
|
_weakReference.Target.SubmitEntityComponents(maxNumberOfOperationsPerFrame); |
|
|
|
DBC.ECS.Check.Require(entitiesSubmissionScheduler.isRunning == false |
|
|
|
, "A submission started while the previous one was still flushing"); |
|
|
|
entitiesSubmissionScheduler.isRunning = true; |
|
|
|
while (submitEntityComponents.MoveNext() == true) |
|
|
|
yield return null; |
|
|
|
|
|
|
|
entitiesSubmissionScheduler.isRunning = false; |
|
|
|
++entitiesSubmissionScheduler.iteration; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
readonly Svelto.DataStructures.WeakReference<EnginesRoot> _weakReference; |
|
|
|
} |
|
|
|
|
|
|
|
readonly EntitiesSubmissionScheduler _scheduler; |
|
|
|
public IEntitiesSubmissionScheduler scheduler => _scheduler; |
|
|
|
readonly EntitiesSubmissionScheduler _scheduler; |
|
|
|
public EntitiesSubmissionScheduler scheduler => _scheduler; |
|
|
|
|
|
|
|
/// <summary> |
|
|
|
/// Engines root contextualize your engines and entities. You don't need to limit yourself to one EngineRoot |
|
|
@@ -40,15 +53,16 @@ namespace Svelto.ECS |
|
|
|
/// </summary> |
|
|
|
public EnginesRoot(EntitiesSubmissionScheduler entitiesComponentScheduler) |
|
|
|
{ |
|
|
|
_entitiesOperations = new ThreadSafeDictionary<ulong, EntitySubmitOperation>(); |
|
|
|
serializationDescriptorMap = new SerializationDescriptorMap(); |
|
|
|
_reactiveEnginesAddRemove = new FasterDictionary<RefWrapperType, FasterList<IReactEngine>>(); |
|
|
|
_reactiveEnginesSwap = new FasterDictionary<RefWrapperType, FasterList<IReactEngine>>(); |
|
|
|
_reactiveEnginesSubmission = new FasterList<IReactOnSubmission>(); |
|
|
|
_enginesSet = new FasterList<IEngine>(); |
|
|
|
_enginesTypeSet = new HashSet<Type>(); |
|
|
|
_disposableEngines = new FasterList<IDisposable>(); |
|
|
|
_transientEntitiesOperations = new FasterList<EntitySubmitOperation>(); |
|
|
|
_entitiesOperations = new FasterDictionary<ulong, EntitySubmitOperation>(); |
|
|
|
serializationDescriptorMap = new SerializationDescriptorMap(); |
|
|
|
_reactiveEnginesAddRemove = new FasterDictionary<RefWrapperType, FasterList<IReactEngine>>(); |
|
|
|
_reactiveEnginesAddRemoveOnDispose = new FasterDictionary<RefWrapperType, FasterList<IReactEngine>>(); |
|
|
|
_reactiveEnginesSwap = new FasterDictionary<RefWrapperType, FasterList<IReactEngine>>(); |
|
|
|
_reactiveEnginesSubmission = new FasterList<IReactOnSubmission>(); |
|
|
|
_enginesSet = new FasterList<IEngine>(); |
|
|
|
_enginesTypeSet = new HashSet<Type>(); |
|
|
|
_disposableEngines = new FasterList<IDisposable>(); |
|
|
|
_transientEntitiesOperations = new FasterList<EntitySubmitOperation>(); |
|
|
|
|
|
|
|
_groupEntityComponentsDB = |
|
|
|
new FasterDictionary<ExclusiveGroupStruct, FasterDictionary<RefWrapperType, ITypeSafeDictionary>>(); |
|
|
@@ -104,15 +118,13 @@ namespace Svelto.ECS |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
foreach (FasterDictionary<ExclusiveGroupStruct, FasterDictionary<RefWrapperType, ITypeSafeDictionary>>. |
|
|
|
KeyValuePairFast groups in _groupEntityComponentsDB) |
|
|
|
foreach (var groups in _groupEntityComponentsDB) |
|
|
|
{ |
|
|
|
foreach (FasterDictionary<RefWrapperType, ITypeSafeDictionary>.KeyValuePairFast entityList in groups |
|
|
|
.Value) |
|
|
|
foreach (var entityList in groups.Value) |
|
|
|
try |
|
|
|
{ |
|
|
|
entityList.Value.ExecuteEnginesRemoveCallbacks(_reactiveEnginesAddRemove, profiler |
|
|
|
, new ExclusiveGroupStruct(groups.Key)); |
|
|
|
entityList.Value.ExecuteEnginesRemoveCallbacks(_reactiveEnginesAddRemoveOnDispose, profiler |
|
|
|
, new ExclusiveGroupStruct(groups.Key)); |
|
|
|
} |
|
|
|
catch (Exception e) |
|
|
|
{ |
|
|
@@ -120,18 +132,15 @@ namespace Svelto.ECS |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
foreach (FasterDictionary<ExclusiveGroupStruct, FasterDictionary<RefWrapperType, ITypeSafeDictionary>>. |
|
|
|
KeyValuePairFast groups in _groupEntityComponentsDB) |
|
|
|
foreach (var groups in _groupEntityComponentsDB) |
|
|
|
{ |
|
|
|
foreach (FasterDictionary<RefWrapperType, ITypeSafeDictionary>.KeyValuePairFast entityList in groups |
|
|
|
.Value) |
|
|
|
foreach (var entityList in groups.Value) |
|
|
|
entityList.Value.Dispose(); |
|
|
|
} |
|
|
|
|
|
|
|
foreach (FasterDictionary<RefWrapperType, FasterDictionary<ExclusiveGroupStruct, GroupFilters>>. |
|
|
|
KeyValuePairFast type in _groupFilters) |
|
|
|
foreach (FasterDictionary<ExclusiveGroupStruct, GroupFilters>.KeyValuePairFast group in type.Value) |
|
|
|
group.Value.Dispose(); |
|
|
|
foreach (var type in _groupFilters) |
|
|
|
foreach (var group in type.Value) |
|
|
|
group.Value.Dispose(); |
|
|
|
|
|
|
|
_groupFilters.Clear(); |
|
|
|
|
|
|
@@ -148,6 +157,7 @@ namespace Svelto.ECS |
|
|
|
_enginesTypeSet.Clear(); |
|
|
|
_reactiveEnginesSwap.Clear(); |
|
|
|
_reactiveEnginesAddRemove.Clear(); |
|
|
|
_reactiveEnginesAddRemoveOnDispose.Clear(); |
|
|
|
_reactiveEnginesSubmission.Clear(); |
|
|
|
|
|
|
|
_entitiesOperations.Clear(); |
|
|
@@ -183,6 +193,9 @@ namespace Svelto.ECS |
|
|
|
if (engine is IReactOnAddAndRemove viewEngine) |
|
|
|
CheckReactEngineComponents(viewEngine, _reactiveEnginesAddRemove); |
|
|
|
|
|
|
|
if (engine is IReactOnDispose viewEngineDispose) |
|
|
|
CheckReactEngineComponents(viewEngineDispose, _reactiveEnginesAddRemoveOnDispose); |
|
|
|
|
|
|
|
if (engine is IReactOnSwap viewEngineSwap) |
|
|
|
CheckReactEngineComponents(viewEngineSwap, _reactiveEnginesSwap); |
|
|
|
|
|
|
@@ -219,12 +232,12 @@ namespace Svelto.ECS |
|
|
|
{ |
|
|
|
var genericArguments = interf.GetGenericArgumentsEx(); |
|
|
|
|
|
|
|
AddEngine(engine, genericArguments, engines); |
|
|
|
AddEngineToList(engine, genericArguments, engines); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
static void AddEngine<T> |
|
|
|
static void AddEngineToList<T> |
|
|
|
(T engine, Type[] entityComponentTypes, FasterDictionary<RefWrapperType, FasterList<IReactEngine>> engines) |
|
|
|
where T : class, IReactEngine |
|
|
|
{ |
|
|
@@ -232,29 +245,24 @@ namespace Svelto.ECS |
|
|
|
{ |
|
|
|
var type = entityComponentTypes[i]; |
|
|
|
|
|
|
|
AddEngine(engine, engines, type); |
|
|
|
} |
|
|
|
} |
|
|
|
if (engines.TryGetValue(new RefWrapperType(type), out var list) == false) |
|
|
|
{ |
|
|
|
list = new FasterList<IReactEngine>(); |
|
|
|
|
|
|
|
static void AddEngine<T>(T engine, FasterDictionary<RefWrapperType, FasterList<IReactEngine>> engines, Type type) |
|
|
|
where T : class, IReactEngine |
|
|
|
{ |
|
|
|
if (engines.TryGetValue(new RefWrapperType(type), out var list) == false) |
|
|
|
{ |
|
|
|
list = new FasterList<IReactEngine>(); |
|
|
|
engines.Add(new RefWrapperType(type), list); |
|
|
|
} |
|
|
|
|
|
|
|
engines.Add(new RefWrapperType(type), list); |
|
|
|
list.Add(engine); |
|
|
|
} |
|
|
|
|
|
|
|
list.Add(engine); |
|
|
|
} |
|
|
|
|
|
|
|
readonly FasterDictionary<RefWrapperType, FasterList<IReactEngine>> _reactiveEnginesAddRemove; |
|
|
|
readonly FasterDictionary<RefWrapperType, FasterList<IReactEngine>> _reactiveEnginesAddRemoveOnDispose; |
|
|
|
readonly FasterDictionary<RefWrapperType, FasterList<IReactEngine>> _reactiveEnginesSwap; |
|
|
|
readonly FasterList<IReactOnSubmission> _reactiveEnginesSubmission; |
|
|
|
readonly FasterList<IDisposable> _disposableEngines; |
|
|
|
readonly FasterList<IEngine> _enginesSet; |
|
|
|
readonly HashSet<Type> _enginesTypeSet; |
|
|
|
internal bool _isDisposing; |
|
|
|
readonly FasterList<IReactOnSubmission> _reactiveEnginesSubmission; |
|
|
|
readonly FasterList<IDisposable> _disposableEngines; |
|
|
|
readonly FasterList<IEngine> _enginesSet; |
|
|
|
readonly HashSet<Type> _enginesTypeSet; |
|
|
|
internal bool _isDisposing; |
|
|
|
} |
|
|
|
} |