@@ -1 +1 @@ | |||
Subproject commit 9a74e5c70681d4f2f5156b48cdd578dfcf6cfc4e | |||
Subproject commit 114ce56f5efe5b5a2a8326ef55587ca668e72503 |
@@ -64,6 +64,8 @@ namespace Svelto.ECS | |||
new FasterDictionary<ComponentID, FasterList<ReactEngineContainer<IReactOnSwapEx>>>(); | |||
_reactiveEnginesDispose = | |||
new FasterDictionary<ComponentID, FasterList<ReactEngineContainer<IReactOnDispose>>>(); | |||
_reactiveEnginesDisposeEx = | |||
new FasterDictionary<ComponentID, FasterList<ReactEngineContainer<IReactOnDisposeEx>>>(); | |||
_reactiveEnginesSubmission = new FasterList<IReactOnSubmission>(); | |||
_reactiveEnginesSubmissionStarted = new FasterList<IReactOnSubmissionStarted>(); | |||
@@ -151,6 +153,10 @@ namespace Svelto.ECS | |||
if (engine is IReactOnDispose viewEngineDispose) | |||
CheckReactEngineComponents( | |||
typeof(IReactOnDispose<>), viewEngineDispose, _reactiveEnginesDispose, type.Name); | |||
if (engine is IReactOnDisposeEx viewEngineDisposeEx) | |||
CheckReactEngineComponents( | |||
typeof(IReactOnDisposeEx<>), viewEngineDisposeEx, _reactiveEnginesDisposeEx, type.Name); | |||
if (engine is IReactOnSwap viewEngineSwap) | |||
#pragma warning disable CS0612 | |||
@@ -263,7 +269,7 @@ namespace Svelto.ECS | |||
ITypeSafeDictionary typeSafeDictionary = entityList.value; | |||
typeSafeDictionary.ExecuteEnginesDisposeCallbacks_Group( | |||
_reactiveEnginesDispose, groups.key, | |||
_reactiveEnginesDispose, _reactiveEnginesDisposeEx, groups.key, | |||
profiler); | |||
} | |||
catch (Exception e) | |||
@@ -300,6 +306,7 @@ namespace Svelto.ECS | |||
_reactiveEnginesAdd.Clear(); | |||
_reactiveEnginesRemove.Clear(); | |||
_reactiveEnginesDispose.Clear(); | |||
_reactiveEnginesDisposeEx.Clear(); | |||
_reactiveEnginesSubmission.Clear(); | |||
_reactiveEnginesSubmissionStarted.Clear(); | |||
@@ -410,6 +417,7 @@ namespace Svelto.ECS | |||
readonly FasterDictionary<ComponentID, FasterList<ReactEngineContainer<IReactOnSwap>>> _reactiveEnginesSwap; | |||
readonly FasterDictionary<ComponentID, FasterList<ReactEngineContainer<IReactOnSwapEx>>> _reactiveEnginesSwapEx; | |||
readonly FasterDictionary<ComponentID, FasterList<ReactEngineContainer<IReactOnDispose>>> _reactiveEnginesDispose; | |||
readonly FasterDictionary<ComponentID, FasterList<ReactEngineContainer<IReactOnDisposeEx>>> _reactiveEnginesDisposeEx; | |||
readonly FasterList<IReactOnSubmission> _reactiveEnginesSubmission; | |||
readonly FasterList<IReactOnSubmissionStarted> _reactiveEnginesSubmissionStarted; | |||
@@ -40,6 +40,10 @@ namespace Svelto.ECS.Internal | |||
public interface IReactOnSwapEx : IReactEngine | |||
{ | |||
} | |||
public interface IReactOnDisposeEx : IReactEngine | |||
{ | |||
} | |||
public interface IReactOnDispose : IReactEngine | |||
{ | |||
@@ -132,6 +136,12 @@ namespace Svelto.ECS | |||
void MovedTo((uint start, uint end) rangeOfEntities, in EntityCollection<T> entities, | |||
ExclusiveGroupStruct fromGroup, ExclusiveGroupStruct toGroup); | |||
} | |||
public interface IReactOnDisposeEx<T> : IReactOnDisposeEx where T : struct, _IInternalEntityComponent | |||
{ | |||
void Remove((uint start, uint end) rangeOfEntities, in EntityCollection<T> entities, | |||
ExclusiveGroupStruct groupID); | |||
} | |||
/// <summary> | |||
/// Interface to mark an Engine as reacting after each entities submission phase | |||
@@ -76,12 +76,13 @@ namespace Svelto.ECS.Internal | |||
ITypeSafeDictionary toEntitiesDictionary, ExclusiveGroupStruct fromGroupId, ExclusiveGroupStruct toGroupId, | |||
in PlatformProfiler platformProfiler); | |||
void ExecuteEnginesRemoveCallbacks_Group( | |||
FasterDictionary<ComponentID, FasterList<ReactEngineContainer<IReactOnRemove>>> engines, | |||
FasterDictionary<ComponentID, FasterList<ReactEngineContainer<IReactOnRemove>>> reactiveEnginesRemove, | |||
FasterDictionary<ComponentID, FasterList<ReactEngineContainer<IReactOnRemoveEx>>> reactiveEnginesRemoveEx, | |||
ExclusiveGroupStruct @group, in PlatformProfiler profiler); | |||
void ExecuteEnginesDisposeCallbacks_Group | |||
(FasterDictionary<ComponentID, FasterList<ReactEngineContainer<IReactOnDispose>>> engines | |||
, ExclusiveGroupStruct group, in PlatformProfiler profiler); | |||
(FasterDictionary<ComponentID, FasterList<ReactEngineContainer<IReactOnDispose>>> reactiveEnginesDispose, | |||
FasterDictionary<ComponentID, FasterList<ReactEngineContainer<IReactOnDisposeEx>>> reactiveEnginesDisposeEx, | |||
ExclusiveGroupStruct group, in PlatformProfiler profiler); | |||
void IncreaseCapacityBy(uint size); | |||
void EnsureCapacity(uint size); | |||
@@ -263,8 +263,8 @@ namespace Svelto.ECS.Internal | |||
, in PlatformProfiler profiler) | |||
{ | |||
TypeSafeDictionaryMethods.ExecuteEnginesSwapCallbacks_Group( | |||
ref implMgd, (ITypeSafeDictionary<TValue>)toDictionary, toGroup, fromGroup, this, reactiveEnginesSwap | |||
, reactiveEnginesSwapEx, count, entityIDs, in profiler); | |||
ref implMgd, (ITypeSafeDictionary<TValue>)toDictionary, toGroup, fromGroup, reactiveEnginesSwap | |||
, reactiveEnginesSwapEx, entityIDs, in profiler); | |||
} | |||
/// <summary> | |||
@@ -278,7 +278,7 @@ namespace Svelto.ECS.Internal | |||
, ExclusiveGroupStruct group, in PlatformProfiler profiler) | |||
{ | |||
TypeSafeDictionaryMethods.ExecuteEnginesRemoveCallbacks_Group( | |||
ref implMgd, this, reactiveEnginesRemove, reactiveEnginesRemoveEx, count, entityIDs, group | |||
ref implMgd, reactiveEnginesRemove, reactiveEnginesRemoveEx, entityIDs, group | |||
, in profiler); | |||
} | |||
@@ -287,10 +287,12 @@ namespace Svelto.ECS.Internal | |||
/// </summary> | |||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | |||
public void ExecuteEnginesDisposeCallbacks_Group | |||
(FasterDictionary<ComponentID, FasterList<ReactEngineContainer<IReactOnDispose>>> engines | |||
, ExclusiveGroupStruct group, in PlatformProfiler profiler) | |||
(FasterDictionary<ComponentID, FasterList<ReactEngineContainer<IReactOnDispose>>> reactiveEnginesDispose, | |||
FasterDictionary<ComponentID, FasterList<ReactEngineContainer<IReactOnDisposeEx>>> reactiveEnginesDisposeEx, | |||
ExclusiveGroupStruct group, in PlatformProfiler profiler) | |||
{ | |||
TypeSafeDictionaryMethods.ExecuteEnginesDisposeCallbacks_Group(ref implMgd, engines, group, in profiler); | |||
TypeSafeDictionaryMethods.ExecuteEnginesDisposeCallbacks_Group( | |||
ref implMgd, reactiveEnginesDispose, reactiveEnginesDisposeEx, entityIDs, group, in profiler); | |||
} | |||
SveltoDictionary<uint, TValue, ManagedStrategy<SveltoDictionaryNode<uint>>, ManagedStrategy<TValue>, | |||
@@ -101,14 +101,15 @@ namespace Svelto.ECS.Internal | |||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | |||
public static void ExecuteEnginesDisposeCallbacks_Group<Strategy1, Strategy2, Strategy3, TValue>( | |||
ref SveltoDictionary<uint, TValue, Strategy1, Strategy2, Strategy3> fromDictionary | |||
, FasterDictionary<ComponentID, FasterList<ReactEngineContainer<IReactOnDispose>>> allEngines | |||
, ExclusiveGroupStruct inGroup, in PlatformProfiler sampler) | |||
, FasterDictionary<ComponentID, FasterList<ReactEngineContainer<IReactOnDispose>>> reactiveEnginesDispose | |||
, FasterDictionary<ComponentID, FasterList<ReactEngineContainer<IReactOnDisposeEx>>> reactiveEnginesDisposeEx | |||
, IEntityIDs entityids, ExclusiveGroupStruct group, in PlatformProfiler sampler) | |||
where Strategy1 : struct, IBufferStrategy<SveltoDictionaryNode<uint>> | |||
where Strategy2 : struct, IBufferStrategy<TValue> | |||
where Strategy3 : struct, IBufferStrategy<int> | |||
where TValue : struct, _IInternalEntityComponent | |||
{ | |||
if (allEngines.TryGetValue(ComponentTypeID<TValue>.id, out var entityComponentsEngines) | |||
if (reactiveEnginesDispose.TryGetValue(ComponentTypeID<TValue>.id, out var entityComponentsEngines) | |||
== false) | |||
return; | |||
@@ -120,7 +121,7 @@ namespace Svelto.ECS.Internal | |||
foreach (var value in fromDictionary) | |||
{ | |||
ref var entity = ref value.value; | |||
var egid = new EGID(value.key, inGroup); | |||
var egid = new EGID(value.key, group); | |||
var reactOnRemove = (IReactOnDispose<TValue>)entityComponentsEngines[i].engine; | |||
reactOnRemove.Remove(ref entity, egid); | |||
} | |||
@@ -132,6 +133,35 @@ namespace Svelto.ECS.Internal | |||
throw; | |||
} | |||
var count = fromDictionary.count; | |||
if (reactiveEnginesDisposeEx.TryGetValue( | |||
ComponentTypeID<TValue>.id | |||
, out var reactiveEnginesDisposeExPerType)) | |||
{ | |||
var enginesCount = reactiveEnginesDisposeExPerType.count; | |||
for (var i = 0; i < enginesCount; i++) | |||
try | |||
{ | |||
using (sampler.Sample(reactiveEnginesDisposeExPerType[i].name)) | |||
{ | |||
((IReactOnDisposeEx<TValue>)reactiveEnginesDisposeExPerType[i].engine).Remove( | |||
(0, (uint)count) | |||
, new EntityCollection<TValue>( | |||
fromDictionary.UnsafeGetValues(out _), entityids | |||
, (uint)count), group); | |||
} | |||
} | |||
catch | |||
{ | |||
Console.LogError("Code crashed inside Remove callback ".FastConcat(reactiveEnginesDisposeExPerType[i].name)); | |||
throw; | |||
} | |||
} | |||
} | |||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | |||
@@ -185,10 +215,9 @@ namespace Svelto.ECS.Internal | |||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | |||
public static void ExecuteEnginesRemoveCallbacks_Group<Strategy1, Strategy2, Strategy3, TValue>( | |||
ref SveltoDictionary<uint, TValue, Strategy1, Strategy2, Strategy3> fromDictionary | |||
, ITypeSafeDictionary<TValue> typeSafeDictionary | |||
, FasterDictionary<ComponentID, FasterList<ReactEngineContainer<IReactOnRemove>>> reactiveenginesremove | |||
, FasterDictionary<ComponentID, FasterList<ReactEngineContainer<IReactOnRemoveEx>>> reactiveenginesremoveex | |||
, int count, IEntityIDs entityids, ExclusiveGroupStruct group, in PlatformProfiler sampler) | |||
, IEntityIDs entityids, ExclusiveGroupStruct group, in PlatformProfiler sampler) | |||
where Strategy1 : struct, IBufferStrategy<SveltoDictionaryNode<uint>> | |||
where Strategy2 : struct, IBufferStrategy<TValue> | |||
where Strategy3 : struct, IBufferStrategy<int> | |||
@@ -229,6 +258,7 @@ namespace Svelto.ECS.Internal | |||
ComponentTypeID<TValue>.id | |||
, out var reactiveEnginesRemoveExPerType)) | |||
{ | |||
var count = fromDictionary.count; | |||
var enginesCount = reactiveEnginesRemoveExPerType.count; | |||
for (var i = 0; i < enginesCount; i++) | |||
@@ -239,7 +269,7 @@ namespace Svelto.ECS.Internal | |||
((IReactOnRemoveEx<TValue>)reactiveEnginesRemoveExPerType[i].engine).Remove( | |||
(0, (uint)count) | |||
, new EntityCollection<TValue>( | |||
typeSafeDictionary.GetValues(out _), entityids | |||
fromDictionary.UnsafeGetValues(out _), entityids | |||
, (uint)count), group); | |||
} | |||
} | |||
@@ -300,10 +330,9 @@ namespace Svelto.ECS.Internal | |||
public static void ExecuteEnginesSwapCallbacks_Group<Strategy1, Strategy2, Strategy3, TValue>( | |||
ref SveltoDictionary<uint, TValue, Strategy1, Strategy2, Strategy3> fromDictionary | |||
, ITypeSafeDictionary<TValue> toDic, ExclusiveGroupStruct togroup, ExclusiveGroupStruct fromgroup | |||
, ITypeSafeDictionary<TValue> typeSafeDictionary | |||
, FasterDictionary<ComponentID, FasterList<ReactEngineContainer<IReactOnSwap>>> reactiveenginesswap | |||
, FasterDictionary<ComponentID, FasterList<ReactEngineContainer<IReactOnSwapEx>>> reactiveenginesswapex | |||
, int count, IEntityIDs entityids, in PlatformProfiler sampler) | |||
, IEntityIDs entityids, in PlatformProfiler sampler) | |||
where Strategy1 : struct, IBufferStrategy<SveltoDictionaryNode<uint>> | |||
where Strategy2 : struct, IBufferStrategy<TValue> | |||
where Strategy3 : struct, IBufferStrategy<int> | |||
@@ -346,6 +375,7 @@ namespace Svelto.ECS.Internal | |||
, out var reactiveEnginesRemoveExPerType)) | |||
{ | |||
var enginesCount = reactiveEnginesRemoveExPerType.count; | |||
var count = fromDictionary.count; | |||
for (var i = 0; i < enginesCount; i++) | |||
try | |||
@@ -355,7 +385,7 @@ namespace Svelto.ECS.Internal | |||
((IReactOnSwapEx<TValue>)reactiveEnginesRemoveExPerType[i].engine).MovedTo( | |||
(0, (uint)count) | |||
, new EntityCollection<TValue>( | |||
typeSafeDictionary.GetValues(out _), entityids | |||
fromDictionary.UnsafeGetValues(out _), entityids | |||
, (uint)count), fromgroup, togroup); | |||
} | |||
} | |||
@@ -275,8 +275,8 @@ namespace Svelto.ECS.Internal | |||
, in PlatformProfiler profiler) | |||
{ | |||
TypeSafeDictionaryMethods.ExecuteEnginesSwapCallbacks_Group( | |||
ref implUnmgd.dictionary, (ITypeSafeDictionary<TValue>)toDictionary, toGroup, fromGroup, this | |||
, reactiveEnginesSwap, reactiveEnginesSwapEx, count, entityIDs, in profiler); | |||
ref implUnmgd.dictionary, (ITypeSafeDictionary<TValue>)toDictionary, toGroup, fromGroup | |||
, reactiveEnginesSwap, reactiveEnginesSwapEx, entityIDs, in profiler); | |||
} | |||
/// <summary> | |||
@@ -290,7 +290,7 @@ namespace Svelto.ECS.Internal | |||
, ExclusiveGroupStruct group, in PlatformProfiler profiler) | |||
{ | |||
TypeSafeDictionaryMethods.ExecuteEnginesRemoveCallbacks_Group( | |||
ref implUnmgd.dictionary, this, reactiveEnginesRemove, reactiveEnginesRemoveEx, count, entityIDs, group | |||
ref implUnmgd.dictionary, reactiveEnginesRemove, reactiveEnginesRemoveEx, entityIDs, group | |||
, in profiler); | |||
} | |||
@@ -299,11 +299,12 @@ namespace Svelto.ECS.Internal | |||
/// </summary> | |||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | |||
public void ExecuteEnginesDisposeCallbacks_Group | |||
(FasterDictionary<ComponentID, FasterList<ReactEngineContainer<IReactOnDispose>>> engines | |||
( FasterDictionary<ComponentID, FasterList<ReactEngineContainer<IReactOnDispose>>> reactiveEnginesDispose | |||
, FasterDictionary<ComponentID, FasterList<ReactEngineContainer<IReactOnDisposeEx>>> reactiveEnginesDisposeEx | |||
, ExclusiveGroupStruct group, in PlatformProfiler profiler) | |||
{ | |||
TypeSafeDictionaryMethods.ExecuteEnginesDisposeCallbacks_Group( | |||
ref implUnmgd.dictionary, engines, group, in profiler); | |||
ref implUnmgd.dictionary, reactiveEnginesDispose, reactiveEnginesDisposeEx, entityIDs, group, in profiler); | |||
} | |||
internal SharedSveltoDictionaryNative<uint, TValue> implUnmgd; | |||