diff --git a/com.sebaslab.svelto.ecs/CHANGELOG.md b/com.sebaslab.svelto.ecs/CHANGELOG.md index ed31615..3b7e050 100644 --- a/com.sebaslab.svelto.ecs/CHANGELOG.md +++ b/com.sebaslab.svelto.ecs/CHANGELOG.md @@ -1,7 +1,7 @@ -# Changelog +# Svelto.ECS Changelog All notable changes to this project will be documented in this file. Changes are listed in random order of importance. -## [3.4.0] - 03-2023 +## [3.4.1] - 03-2023 * removed static caches used in performance critical paths as they were causing unexpected performance issues (the fetching of static data is slower than i imagined) * add Native prefix in front of the native memory utilities method names diff --git a/com.sebaslab.svelto.ecs/Core/CheckEntityUtilities.cs b/com.sebaslab.svelto.ecs/Core/CheckEntityUtilities.cs index 77634a3..f32abf4 100644 --- a/com.sebaslab.svelto.ecs/Core/CheckEntityUtilities.cs +++ b/com.sebaslab.svelto.ecs/Core/CheckEntityUtilities.cs @@ -85,9 +85,9 @@ namespace Svelto.ECS #if DONT_USE [Conditional("MEANINGLESS")] #endif - void ClearDebugChecks() { _multipleOperationOnSameEGIDChecker.Clear(); } + void ClearChecksForMultipleOperationsOnTheSameEgid() { _multipleOperationOnSameEGIDChecker.Clear(); } - readonly Svelto.DataStructures.FasterDictionary _multipleOperationOnSameEGIDChecker; - readonly Svelto.DataStructures.FasterDictionary> _idChecker; + readonly DataStructures.FasterDictionary _multipleOperationOnSameEGIDChecker; + readonly DataStructures.FasterDictionary> _idChecker; } } \ No newline at end of file diff --git a/com.sebaslab.svelto.ecs/Core/ComponentBuilder.cs b/com.sebaslab.svelto.ecs/Core/ComponentBuilder.cs index b601516..3b38b38 100644 --- a/com.sebaslab.svelto.ecs/Core/ComponentBuilder.cs +++ b/com.sebaslab.svelto.ecs/Core/ComponentBuilder.cs @@ -48,7 +48,7 @@ namespace Svelto.ECS { id.Data = Interlocked.Increment(ref BurstCompatibleCounter.counter); - DBC.ECS.Check.Ensure(id.Data < ushort.MaxValue, "too many types registered, HOW :)"); + Check.Ensure(id.Data < ushort.MaxValue, "too many types registered, HOW :)"); } } diff --git a/com.sebaslab.svelto.ecs/Core/DBC.cs b/com.sebaslab.svelto.ecs/Core/DBC.cs index 97db65f..211b66c 100644 --- a/com.sebaslab.svelto.ecs/Core/DBC.cs +++ b/com.sebaslab.svelto.ecs/Core/DBC.cs @@ -224,7 +224,7 @@ namespace DBC.ECS #endregion // Implementation } // End Check - internal class Trace + class Trace { internal static void Assert(bool assertion, string v) { diff --git a/com.sebaslab.svelto.ecs/Core/EGIDMapper.cs b/com.sebaslab.svelto.ecs/Core/EGIDMapper.cs index 41305ca..4ff43bd 100644 --- a/com.sebaslab.svelto.ecs/Core/EGIDMapper.cs +++ b/com.sebaslab.svelto.ecs/Core/EGIDMapper.cs @@ -25,10 +25,10 @@ namespace Svelto.ECS { #if DEBUG && !PROFILE_SVELTO if (_map == null) - throw new System.Exception( + throw new Exception( "Not initialized EGIDMapper in this group ".FastConcat(typeof(T).ToString())); if (_map.TryFindIndex(entityID, out var findIndex) == false) - throw new System.Exception("Entity not found in this group ".FastConcat(typeof(T).ToString())); + throw new Exception("Entity not found in this group ".FastConcat(typeof(T).ToString())); #else _map.TryFindIndex(entityID, out var findIndex); #endif diff --git a/com.sebaslab.svelto.ecs/Core/EnginesGroup/SortedEnginesGroup.cs b/com.sebaslab.svelto.ecs/Core/EnginesGroup/SortedEnginesGroup.cs index 6389d8f..f9fee97 100644 --- a/com.sebaslab.svelto.ecs/Core/EnginesGroup/SortedEnginesGroup.cs +++ b/com.sebaslab.svelto.ecs/Core/EnginesGroup/SortedEnginesGroup.cs @@ -47,7 +47,7 @@ namespace Svelto.ECS { protected SortedEnginesGroup(FasterList engines) { - _name = "SortedEnginesGroup - "+this.GetType().Name; + _name = "SortedEnginesGroup - "+GetType().Name; _instancedSequence = new Sequence(engines); } @@ -80,7 +80,7 @@ namespace Svelto.ECS { protected SortedEnginesGroup(FasterList engines) { - _name = "SortedEnginesGroup - "+this.GetType().Name; + _name = "SortedEnginesGroup - "+GetType().Name; _instancedSequence = new Sequence(engines); } diff --git a/com.sebaslab.svelto.ecs/Core/EnginesGroup/UnsortedEnginesGroup.cs b/com.sebaslab.svelto.ecs/Core/EnginesGroup/UnsortedEnginesGroup.cs index c281911..f1e9bfc 100644 --- a/com.sebaslab.svelto.ecs/Core/EnginesGroup/UnsortedEnginesGroup.cs +++ b/com.sebaslab.svelto.ecs/Core/EnginesGroup/UnsortedEnginesGroup.cs @@ -15,13 +15,13 @@ namespace Svelto.ECS { protected UnsortedEnginesGroup() { - _name = "UnsortedEnginesGroup - "+this.GetType().Name; + _name = "UnsortedEnginesGroup - "+GetType().Name; _instancedSequence = new FasterList(); } protected UnsortedEnginesGroup(FasterList engines) { - _name = "UnsortedEnginesGroup - "+this.GetType().Name; + _name = "UnsortedEnginesGroup - "+GetType().Name; _instancedSequence = engines; } @@ -59,13 +59,13 @@ namespace Svelto.ECS { protected UnsortedEnginesGroup() { - _name = "UnsortedEnginesGroup - "+this.GetType().Name; + _name = "UnsortedEnginesGroup - "+GetType().Name; _instancedSequence = new FasterList(); } protected UnsortedEnginesGroup(FasterList engines) { - _name = "UnsortedEnginesGroup - "+this.GetType().Name; + _name = "UnsortedEnginesGroup - "+GetType().Name; _instancedSequence = engines; } diff --git a/com.sebaslab.svelto.ecs/Core/EnginesRoot.Engines.cs b/com.sebaslab.svelto.ecs/Core/EnginesRoot.Engines.cs index eb28e5a..3b7ba58 100644 --- a/com.sebaslab.svelto.ecs/Core/EnginesRoot.Engines.cs +++ b/com.sebaslab.svelto.ecs/Core/EnginesRoot.Engines.cs @@ -330,7 +330,7 @@ namespace Svelto.ECS { public EntitiesSubmitter(EnginesRoot enginesRoot): this() { - _enginesRoot = new Svelto.DataStructures.WeakReference(enginesRoot); + _enginesRoot = new DataStructures.WeakReference(enginesRoot); } internal void SubmitEntities() @@ -360,7 +360,6 @@ namespace Svelto.ECS #if UNITY_NATIVE enginesRootTarget.FlushNativeOperations(profiler); #endif - //todo: proper unit test structural changes made as result of add/remove callbacks while (enginesRootTarget.HasMadeNewStructuralChangesInThisIteration() && iterations++ < MAX_SUBMISSION_ITERATIONS) { @@ -385,7 +384,7 @@ namespace Svelto.ECS } } - readonly Svelto.DataStructures.WeakReference _enginesRoot; + readonly DataStructures.WeakReference _enginesRoot; } ~EnginesRoot() diff --git a/com.sebaslab.svelto.ecs/Core/EnginesRoot.GenericEntityFunctions.cs b/com.sebaslab.svelto.ecs/Core/EnginesRoot.GenericEntityFunctions.cs index 3b3fd0c..2e780c5 100644 --- a/com.sebaslab.svelto.ecs/Core/EnginesRoot.GenericEntityFunctions.cs +++ b/com.sebaslab.svelto.ecs/Core/EnginesRoot.GenericEntityFunctions.cs @@ -104,7 +104,7 @@ namespace Svelto.ECS enginesRootTarget.CheckAddEntityID(toEGID, TypeCache.type, caller); enginesRootTarget.QueueSwapEntityOperation(fromEGID, toEGID - , this._enginesRoot.Target.FindRealComponents(fromEGID) + , _enginesRoot.Target.FindRealComponents(fromEGID) , caller); } diff --git a/com.sebaslab.svelto.ecs/Core/EnginesRoot.Submission.cs b/com.sebaslab.svelto.ecs/Core/EnginesRoot.Submission.cs index bef5d1d..bf3c91a 100644 --- a/com.sebaslab.svelto.ecs/Core/EnginesRoot.Submission.cs +++ b/com.sebaslab.svelto.ecs/Core/EnginesRoot.Submission.cs @@ -11,6 +11,9 @@ namespace Svelto.ECS [MethodImpl(MethodImplOptions.AggressiveInlining)] void SingleSubmission(PlatformProfiler profiler) { + //clear the data checks before the submission. We want to allow structural changes inside the callbacks + ClearChecksForMultipleOperationsOnTheSameEgid(); + _entitiesOperations.ExecuteRemoveAndSwappingOperations( _swapEntities, _removeEntities, @@ -19,8 +22,9 @@ namespace Svelto.ECS this); AddEntities(profiler); - - ClearDebugChecks(); //this must be done first as I need the carry the last states after the submission + + //clear the data checks after the submission, so if structural changes happened inside the callback, the debug structure is reset for the next frame operations + ClearChecksForMultipleOperationsOnTheSameEgid(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -476,7 +480,7 @@ namespace Svelto.ECS fromDictionary.AddEntitiesToDictionary(toDictionary, toGroupId #if SLOW_SVELTO_SUBMISSION - , this.entityLocator + , entityLocator #endif ); } diff --git a/com.sebaslab.svelto.ecs/Core/EntitiesDB.cs b/com.sebaslab.svelto.ecs/Core/EntitiesDB.cs index 2d5eacf..7d13aa8 100644 --- a/com.sebaslab.svelto.ecs/Core/EntitiesDB.cs +++ b/com.sebaslab.svelto.ecs/Core/EntitiesDB.cs @@ -205,6 +205,9 @@ namespace Svelto.ECS return true; } + /// + /// determine if component with specific ID exists in group + /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Exists(EGID entityGID) where T : struct, _IInternalEntityComponent { @@ -214,6 +217,9 @@ namespace Svelto.ECS return casted != null && casted.ContainsKey(entityGID.entityID); } + /// + /// determine if component with specific ID exists in group + /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Exists(uint id, ExclusiveGroupStruct group) where T : struct, _IInternalEntityComponent { @@ -223,6 +229,9 @@ namespace Svelto.ECS return casted != null && casted.ContainsKey(id); } + /// + /// determine if group exists and is not empty + /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool ExistsAndIsNotEmpty(ExclusiveGroupStruct gid) { @@ -235,12 +244,18 @@ namespace Svelto.ECS return false; } + /// + /// determine if entities we specific components are found in group + /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool HasAny(ExclusiveGroupStruct groupStruct) where T : struct, _IInternalEntityComponent { return Count(groupStruct) > 0; } + /// + /// count the number of components in a group + /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public int Count(ExclusiveGroupStruct groupStruct) where T : struct, _IInternalEntityComponent { diff --git a/com.sebaslab.svelto.ecs/Core/Groups/ExclusiveGroupStruct.cs b/com.sebaslab.svelto.ecs/Core/Groups/ExclusiveGroupStruct.cs index 5f3e264..5ed895f 100644 --- a/com.sebaslab.svelto.ecs/Core/Groups/ExclusiveGroupStruct.cs +++ b/com.sebaslab.svelto.ecs/Core/Groups/ExclusiveGroupStruct.cs @@ -48,11 +48,11 @@ namespace Svelto.ECS public bool Equals(ExclusiveGroupStruct other) { #if DEBUG && !PROFILE_SVELTO - if ((other.id != this.id || other._bytemask == this._bytemask) == false) + if ((other.id != id || other._bytemask == _bytemask) == false) throw new ECSException( "if the groups are correctly initialised, two groups with the same ID and different bitmask cannot exist"); #endif - return other.id == this.id; + return other.id == id; } [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/com.sebaslab.svelto.ecs/Core/Groups/QueryGroups.cs b/com.sebaslab.svelto.ecs/Core/Groups/QueryGroups.cs index fea02ba..3ceef7c 100644 --- a/com.sebaslab.svelto.ecs/Core/Groups/QueryGroups.cs +++ b/com.sebaslab.svelto.ecs/Core/Groups/QueryGroups.cs @@ -6,7 +6,7 @@ using Svelto.ECS.Internal; namespace Svelto.ECS.Experimental { - internal struct GroupsList + struct GroupsList { public static GroupsList Init() { diff --git a/com.sebaslab.svelto.ecs/Core/Hybrid/ValueReference.cs b/com.sebaslab.svelto.ecs/Core/Hybrid/ValueReference.cs index fcc3475..c004c67 100644 --- a/com.sebaslab.svelto.ecs/Core/Hybrid/ValueReference.cs +++ b/com.sebaslab.svelto.ecs/Core/Hybrid/ValueReference.cs @@ -25,5 +25,5 @@ namespace Svelto.ECS.Hybrid } // Used to validate the use of this struct on the component builder check fields. - internal interface IValueReferenceInternal {} + interface IValueReferenceInternal {} } \ No newline at end of file diff --git a/com.sebaslab.svelto.ecs/Core/Streams/EntityStream.cs b/com.sebaslab.svelto.ecs/Core/Streams/EntityStream.cs index d8517f7..e2efa50 100644 --- a/com.sebaslab.svelto.ecs/Core/Streams/EntityStream.cs +++ b/com.sebaslab.svelto.ecs/Core/Streams/EntityStream.cs @@ -3,7 +3,7 @@ using Svelto.ECS.Internal; namespace Svelto.ECS { - internal interface ITypeSafeStream + interface ITypeSafeStream { void Dispose(); } diff --git a/com.sebaslab.svelto.ecs/DataStructures/ITypeSafeDictionary.cs b/com.sebaslab.svelto.ecs/DataStructures/ITypeSafeDictionary.cs index 9a7a9ec..2a9fb81 100644 --- a/com.sebaslab.svelto.ecs/DataStructures/ITypeSafeDictionary.cs +++ b/com.sebaslab.svelto.ecs/DataStructures/ITypeSafeDictionary.cs @@ -92,6 +92,6 @@ namespace Svelto.ECS.Internal uint GetIndex(uint valueEntityId); bool TryFindIndex(uint entityGidEntityId, out uint index); - void KeysEvaluator(System.Action action); + void KeysEvaluator(Action action); } } \ No newline at end of file diff --git a/com.sebaslab.svelto.ecs/DataStructures/TypeSafeDictionaryMethods.cs b/com.sebaslab.svelto.ecs/DataStructures/TypeSafeDictionaryMethods.cs index 7feaa44..10ccded 100644 --- a/com.sebaslab.svelto.ecs/DataStructures/TypeSafeDictionaryMethods.cs +++ b/com.sebaslab.svelto.ecs/DataStructures/TypeSafeDictionaryMethods.cs @@ -9,28 +9,30 @@ namespace Svelto.ECS.Internal public static class TypeSafeDictionaryMethods { [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void AddEntitiesToDictionary - (in SveltoDictionary fromDictionary - , ITypeSafeDictionary toDic + public static void AddEntitiesToDictionary( + in SveltoDictionary fromDictionary + , ITypeSafeDictionary toDic #if SLOW_SVELTO_SUBMISSION -, in EnginesRoot.EntityReferenceMap entityLocator + , in EnginesRoot.EntityReferenceMap entityLocator #endif - , ExclusiveGroupStruct toGroupID) where Strategy1 : struct, IBufferStrategy> - where Strategy2 : struct, IBufferStrategy - where Strategy3 : struct, IBufferStrategy - where TValue : struct, _IInternalEntityComponent + , ExclusiveGroupStruct toGroupID) + where Strategy1 : struct, IBufferStrategy> + where Strategy2 : struct, IBufferStrategy + where Strategy3 : struct, IBufferStrategy + where TValue : struct, _IInternalEntityComponent { foreach (var tuple in fromDictionary) { #if SLOW_SVELTO_SUBMISSION - var egid = new EGID(tuple.key, toGroupID); + var egid = new EGID(tuple.key, toGroupID); - if (SlowSubmissionInfo.hasEgid) - SetEGIDWithoutBoxing.SetIDWithoutBoxing(ref tuple.value, egid); + if (SlowSubmissionInfo.hasEgid) + SetEGIDWithoutBoxing.SetIDWithoutBoxing(ref tuple.value, egid); - if (SlowSubmissionInfo.hasReference) - SetEGIDWithoutBoxing.SetRefWithoutBoxing(ref tuple.value, - entityLocator.GetEntityReference(egid)); + if (SlowSubmissionInfo.hasReference) + SetEGIDWithoutBoxing.SetRefWithoutBoxing( + ref tuple.value, + entityLocator.GetEntityReference(egid)); #endif try { @@ -39,7 +41,9 @@ namespace Svelto.ECS.Internal catch (Exception e) { Console.LogException( - e, "trying to add an EntityComponent with the same ID more than once Entity: ".FastConcat(typeof(TValue).ToString()).FastConcat(", group ").FastConcat(toGroupID.ToName()).FastConcat(", id ").FastConcat(tuple.key)); + e, + "trying to add an EntityComponent with the same ID more than once Entity: ".FastConcat(typeof(TValue).ToString()) + .FastConcat(", group ").FastConcat(toGroupID.ToName()).FastConcat(", id ").FastConcat(tuple.key)); throw; } @@ -50,30 +54,32 @@ namespace Svelto.ECS.Internal } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void ExecuteEnginesAddCallbacks - (ref SveltoDictionary fromDictionary - , ITypeSafeDictionary todic, ExclusiveGroupStruct togroup - , FasterDictionary>> entitycomponentenginesdb - , in PlatformProfiler sampler) where Strategy1 : struct, IBufferStrategy> - where Strategy2 : struct, IBufferStrategy - where Strategy3 : struct, IBufferStrategy - where TValue : struct, _IInternalEntityComponent + public static void ExecuteEnginesAddCallbacks( + ref SveltoDictionary fromDictionary + , ITypeSafeDictionary todic, ExclusiveGroupStruct togroup + , FasterDictionary>> entitycomponentenginesdb + , in PlatformProfiler sampler) + where Strategy1 : struct, IBufferStrategy> + where Strategy2 : struct, IBufferStrategy + where Strategy3 : struct, IBufferStrategy + where TValue : struct, _IInternalEntityComponent { - if (entitycomponentenginesdb.TryGetValue(new RefWrapperType(TypeCache.type) - , out var entityComponentsEngines)) + if (entitycomponentenginesdb.TryGetValue( + new RefWrapperType(TypeCache.type) + , out var entityComponentsEngines)) { if (entityComponentsEngines.count == 0) return; var dictionaryKeyEnumerator = fromDictionary.unsafeKeys; - var count = fromDictionary.count; + var count = fromDictionary.count; for (var i = 0; i < count; ++i) try { - var key = dictionaryKeyEnumerator[i].key; + var key = dictionaryKeyEnumerator[i].key; ref var entity = ref todic.GetValueByRef(key); - var egid = new EGID(key, togroup); + var egid = new EGID(key, togroup); //get all the engines linked to TValue for (var j = 0; j < entityComponentsEngines.count; j++) using (sampler.Sample(entityComponentsEngines[j].name)) @@ -85,8 +91,7 @@ namespace Svelto.ECS.Internal } catch (Exception e) { - Console.LogException( - e, "Code crashed inside Add callback with Type ".FastConcat(TypeCache.name)); + Console.LogException(e, "Code crashed inside Add callback with Type ".FastConcat(TypeCache.name)); throw; } @@ -94,14 +99,14 @@ namespace Svelto.ECS.Internal } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void ExecuteEnginesDisposeCallbacks_Group - (ref SveltoDictionary fromDictionary - , FasterDictionary>> allEngines - , ExclusiveGroupStruct inGroup, in PlatformProfiler sampler) - where Strategy1 : struct, IBufferStrategy> - where Strategy2 : struct, IBufferStrategy - where Strategy3 : struct, IBufferStrategy - where TValue : struct, _IInternalEntityComponent + public static void ExecuteEnginesDisposeCallbacks_Group( + ref SveltoDictionary fromDictionary + , FasterDictionary>> allEngines + , ExclusiveGroupStruct inGroup, in PlatformProfiler sampler) + where Strategy1 : struct, IBufferStrategy> + where Strategy2 : struct, IBufferStrategy + where Strategy3 : struct, IBufferStrategy + where TValue : struct, _IInternalEntityComponent { if (allEngines.TryGetValue(new RefWrapperType(TypeCache.type), out var entityComponentsEngines) == false) @@ -114,35 +119,34 @@ namespace Svelto.ECS.Internal { foreach (var value in fromDictionary) { - ref var entity = ref value.value; - var egid = new EGID(value.key, inGroup); - var reactOnRemove = (IReactOnDispose)entityComponentsEngines[i].engine; + ref var entity = ref value.value; + var egid = new EGID(value.key, inGroup); + var reactOnRemove = (IReactOnDispose)entityComponentsEngines[i].engine; reactOnRemove.Remove(ref entity, egid); } } } catch { - Console.LogError( - "Code crashed inside Remove callback ".FastConcat(entityComponentsEngines[i].name)); + Console.LogError("Code crashed inside Remove callback ".FastConcat(entityComponentsEngines[i].name)); throw; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void ExecuteEnginesRemoveCallbacks - (FasterList<(uint, string)> infostoprocess - , ref SveltoDictionary fromDictionary - , FasterDictionary>> reactiveenginesremove - , ExclusiveGroupStruct fromgroup, in PlatformProfiler profiler) - where Strategy1 : struct, IBufferStrategy> - where Strategy2 : struct, IBufferStrategy - where Strategy3 : struct, IBufferStrategy - where TValue : struct, _IInternalEntityComponent + public static void ExecuteEnginesRemoveCallbacks(FasterList<(uint, string)> infostoprocess + , ref SveltoDictionary fromDictionary + , FasterDictionary>> reactiveenginesremove + , ExclusiveGroupStruct fromgroup, in PlatformProfiler profiler) + where Strategy1 : struct, IBufferStrategy> + where Strategy2 : struct, IBufferStrategy + where Strategy3 : struct, IBufferStrategy + where TValue : struct, _IInternalEntityComponent { - if (reactiveenginesremove.TryGetValue(new RefWrapperType(TypeCache.type) - , out var entityComponentsEngines)) + if (reactiveenginesremove.TryGetValue( + new RefWrapperType(TypeCache.type) + , out var entityComponentsEngines)) { if (entityComponentsEngines.count == 0) return; @@ -155,7 +159,7 @@ namespace Svelto.ECS.Internal try { ref var entity = ref fromDictionary.GetValueByRef(entityID); - var egid = new EGID(entityID, fromgroup); + var egid = new EGID(entityID, fromgroup); for (var j = 0; j < entityComponentsEngines.count; j++) using (profiler.Sample(entityComponentsEngines[j].name)) @@ -168,7 +172,7 @@ namespace Svelto.ECS.Internal catch { var str = "Crash while executing Remove Entity callback on ".FastConcat(TypeCache.name) - .FastConcat(" from : ", trace); + .FastConcat(" from : ", trace); Console.LogError(str); @@ -179,19 +183,20 @@ namespace Svelto.ECS.Internal } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void ExecuteEnginesRemoveCallbacks_Group - (ref SveltoDictionary fromDictionary - , ITypeSafeDictionary typeSafeDictionary - , FasterDictionary>> reactiveenginesremove - , FasterDictionary>> reactiveenginesremoveex - , int count, IEntityIDs entityids, ExclusiveGroupStruct group, in PlatformProfiler sampler) - where Strategy1 : struct, IBufferStrategy> - where Strategy2 : struct, IBufferStrategy - where Strategy3 : struct, IBufferStrategy - where TValue : struct, _IInternalEntityComponent + public static void ExecuteEnginesRemoveCallbacks_Group( + ref SveltoDictionary fromDictionary + , ITypeSafeDictionary typeSafeDictionary + , FasterDictionary>> reactiveenginesremove + , FasterDictionary>> reactiveenginesremoveex + , int count, IEntityIDs entityids, ExclusiveGroupStruct group, in PlatformProfiler sampler) + where Strategy1 : struct, IBufferStrategy> + where Strategy2 : struct, IBufferStrategy + where Strategy3 : struct, IBufferStrategy + where TValue : struct, _IInternalEntityComponent { - if (reactiveenginesremove.TryGetValue(new RefWrapperType(TypeCache.type) - , out var reactiveEnginesRemovePerType)) + if (reactiveenginesremove.TryGetValue( + new RefWrapperType(TypeCache.type) + , out var reactiveEnginesRemovePerType)) { var enginesCount = reactiveEnginesRemovePerType.count; @@ -201,7 +206,7 @@ namespace Svelto.ECS.Internal foreach (var value in fromDictionary) { ref var entity = ref value.value; - var egid = new EGID(value.key, group); + var egid = new EGID(value.key, group); using (sampler.Sample(reactiveEnginesRemovePerType[i].name)) { @@ -214,15 +219,15 @@ namespace Svelto.ECS.Internal } catch { - Console.LogError( - "Code crashed inside Remove callback ".FastConcat(reactiveEnginesRemovePerType[i].name)); + Console.LogError("Code crashed inside Remove callback ".FastConcat(reactiveEnginesRemovePerType[i].name)); throw; } } - if (reactiveenginesremoveex.TryGetValue(new RefWrapperType(TypeCache.type) - , out var reactiveEnginesRemoveExPerType)) + if (reactiveenginesremoveex.TryGetValue( + new RefWrapperType(TypeCache.type) + , out var reactiveEnginesRemoveExPerType)) { var enginesCount = reactiveEnginesRemoveExPerType.count; @@ -233,14 +238,14 @@ namespace Svelto.ECS.Internal { ((IReactOnRemoveEx)reactiveEnginesRemoveExPerType[i].engine).Remove( (0, (uint)count) - , new EntityCollection(typeSafeDictionary.GetValues(out _), entityids - , (uint)count), group); + , new EntityCollection( + typeSafeDictionary.GetValues(out _), entityids + , (uint)count), group); } } catch { - Console.LogError( - "Code crashed inside Remove callback ".FastConcat(reactiveEnginesRemoveExPerType[i].name)); + Console.LogError("Code crashed inside Remove callback ".FastConcat(reactiveEnginesRemoveExPerType[i].name)); throw; } @@ -248,15 +253,14 @@ namespace Svelto.ECS.Internal } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void ExecuteEnginesSwapCallbacks - (FasterList<(uint, uint, string)> infostoprocess - , ref SveltoDictionary fromDictionary - , FasterList> reactiveenginesswap, ExclusiveGroupStruct togroup - , ExclusiveGroupStruct fromgroup, in PlatformProfiler sampler) - where Strategy1 : struct, IBufferStrategy> - where Strategy2 : struct, IBufferStrategy - where Strategy3 : struct, IBufferStrategy - where TValue : struct, _IInternalEntityComponent + public static void ExecuteEnginesSwapCallbacks(FasterList<(uint, uint, string)> infostoprocess + , ref SveltoDictionary fromDictionary + , FasterList> reactiveenginesswap, ExclusiveGroupStruct togroup + , ExclusiveGroupStruct fromgroup, in PlatformProfiler sampler) + where Strategy1 : struct, IBufferStrategy> + where Strategy2 : struct, IBufferStrategy + where Strategy3 : struct, IBufferStrategy + where TValue : struct, _IInternalEntityComponent { if (reactiveenginesswap.count == 0) return; @@ -270,7 +274,7 @@ namespace Svelto.ECS.Internal try { ref var entityComponent = ref fromDictionary.GetValueByRef(fromEntityID); - var newEgid = new EGID(toEntityID, togroup); + var newEgid = new EGID(toEntityID, togroup); for (var j = 0; j < reactiveenginesswap.count; j++) using (sampler.Sample(reactiveenginesswap[j].name)) { @@ -283,7 +287,7 @@ namespace Svelto.ECS.Internal catch { var str = "Crash while executing Swap Entity callback on ".FastConcat(TypeCache.name) - .FastConcat(" from : ", trace); + .FastConcat(" from : ", trace); Console.LogError(str); @@ -293,21 +297,22 @@ namespace Svelto.ECS.Internal } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void ExecuteEnginesSwapCallbacks_Group - (ref SveltoDictionary fromDictionary - , ITypeSafeDictionary toDic, ExclusiveGroupStruct togroup, ExclusiveGroupStruct fromgroup - , ITypeSafeDictionary typeSafeDictionary - , FasterDictionary>> reactiveenginesswap - , FasterDictionary>> reactiveenginesswapex - , int count, IEntityIDs entityids, in PlatformProfiler sampler) - where Strategy1 : struct, IBufferStrategy> - where Strategy2 : struct, IBufferStrategy - where Strategy3 : struct, IBufferStrategy - where TValue : struct, _IInternalEntityComponent + public static void ExecuteEnginesSwapCallbacks_Group( + ref SveltoDictionary fromDictionary + , ITypeSafeDictionary toDic, ExclusiveGroupStruct togroup, ExclusiveGroupStruct fromgroup + , ITypeSafeDictionary typeSafeDictionary + , FasterDictionary>> reactiveenginesswap + , FasterDictionary>> reactiveenginesswapex + , int count, IEntityIDs entityids, in PlatformProfiler sampler) + where Strategy1 : struct, IBufferStrategy> + where Strategy2 : struct, IBufferStrategy + where Strategy3 : struct, IBufferStrategy + where TValue : struct, _IInternalEntityComponent { //get all the engines linked to TValue - if (!reactiveenginesswap.TryGetValue(new RefWrapperType(TypeCache.type) - , out var reactiveEnginesSwapPerType)) + if (!reactiveenginesswap.TryGetValue( + new RefWrapperType(TypeCache.type) + , out var reactiveEnginesSwapPerType)) return; var componentsEnginesCount = reactiveEnginesSwapPerType.count; @@ -318,7 +323,7 @@ namespace Svelto.ECS.Internal foreach (var value in fromDictionary) { ref var entityComponent = ref toDic.GetValueByRef(value.key); - var newEgid = new EGID(value.key, togroup); + var newEgid = new EGID(value.key, togroup); using (sampler.Sample(reactiveEnginesSwapPerType[i].name)) { @@ -331,14 +336,14 @@ namespace Svelto.ECS.Internal } catch (Exception) { - Console.LogError( - "Code crashed inside MoveTo callback ".FastConcat(reactiveEnginesSwapPerType[i].name)); + Console.LogError("Code crashed inside MoveTo callback ".FastConcat(reactiveEnginesSwapPerType[i].name)); throw; } - if (reactiveenginesswapex.TryGetValue(new RefWrapperType(TypeCache.type) - , out var reactiveEnginesRemoveExPerType)) + if (reactiveenginesswapex.TryGetValue( + new RefWrapperType(TypeCache.type) + , out var reactiveEnginesRemoveExPerType)) { var enginesCount = reactiveEnginesRemoveExPerType.count; @@ -349,14 +354,14 @@ namespace Svelto.ECS.Internal { ((IReactOnSwapEx)reactiveEnginesRemoveExPerType[i].engine).MovedTo( (0, (uint)count) - , new EntityCollection(typeSafeDictionary.GetValues(out _), entityids - , (uint)count), fromgroup, togroup); + , new EntityCollection( + typeSafeDictionary.GetValues(out _), entityids + , (uint)count), fromgroup, togroup); } } catch { - Console.LogError( - "Code crashed inside Remove callback ".FastConcat(reactiveEnginesRemoveExPerType[i].name)); + Console.LogError("Code crashed inside Remove callback ".FastConcat(reactiveEnginesRemoveExPerType[i].name)); throw; } @@ -364,14 +369,13 @@ namespace Svelto.ECS.Internal } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void RemoveEntitiesFromDictionary - (FasterList<(uint, string)> infostoprocess - , ref SveltoDictionary fromDictionary - , FasterList entityIDsAffectedByRemoval) - where Strategy1 : struct, IBufferStrategy> - where Strategy2 : struct, IBufferStrategy - where Strategy3 : struct, IBufferStrategy - where TValue : struct, _IInternalEntityComponent + public static void RemoveEntitiesFromDictionary(FasterList<(uint, string)> infostoprocess + , ref SveltoDictionary fromDictionary + , FasterList entityIDsAffectedByRemoval) + where Strategy1 : struct, IBufferStrategy> + where Strategy2 : struct, IBufferStrategy + where Strategy3 : struct, IBufferStrategy + where TValue : struct, _IInternalEntityComponent { var iterations = infostoprocess.count; @@ -401,7 +405,7 @@ namespace Svelto.ECS.Internal catch { var str = "Crash while executing Remove Entity operation on ".FastConcat(TypeCache.name) - .FastConcat(" from : ", trace); + .FastConcat(" from : ", trace); Console.LogError(str); @@ -411,15 +415,14 @@ namespace Svelto.ECS.Internal } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void SwapEntitiesBetweenDictionaries - (FasterList<(uint, uint, string)> infostoprocess - , ref SveltoDictionary fromDictionary - , ITypeSafeDictionary toDictionary, ExclusiveGroupStruct fromgroup, ExclusiveGroupStruct togroup - , FasterList entityIDsAffectedByRemoval) - where Strategy1 : struct, IBufferStrategy> - where Strategy2 : struct, IBufferStrategy - where Strategy3 : struct, IBufferStrategy - where TValue : struct, _IInternalEntityComponent + public static void SwapEntitiesBetweenDictionaries(FasterList<(uint, uint, string)> infostoprocess + , ref SveltoDictionary fromDictionary + , ITypeSafeDictionary toDictionary, ExclusiveGroupStruct fromgroup, ExclusiveGroupStruct togroup + , FasterList entityIDsAffectedByRemoval) + where Strategy1 : struct, IBufferStrategy> + where Strategy2 : struct, IBufferStrategy + where Strategy3 : struct, IBufferStrategy + where TValue : struct, _IInternalEntityComponent { var iterations = infostoprocess.count; @@ -430,7 +433,7 @@ namespace Svelto.ECS.Internal try { var fromEntityGid = new EGID(fromID, fromgroup); - var toEntityEgid = new EGID(toID, togroup); + var toEntityEgid = new EGID(toID, togroup); Check.Require(togroup.isInvalid == false, "Invalid To Group"); @@ -453,7 +456,7 @@ namespace Svelto.ECS.Internal catch { var str = "Crash while executing Swap Entity operation on ".FastConcat(TypeCache.name) - .FastConcat(" from : ", trace); + .FastConcat(" from : ", trace); Console.LogError(str); @@ -463,15 +466,16 @@ namespace Svelto.ECS.Internal } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void ExecuteEnginesAddEntityCallbacksFast - (FasterDictionary>> fasterDictionary - , ExclusiveGroupStruct groupId, (uint, uint) rangeTuple, IEntityIDs entityids - , ITypeSafeDictionary typeSafeDictionary, PlatformProfiler profiler) - where TValue : struct, _IInternalEntityComponent + public static void ExecuteEnginesAddEntityCallbacksFast( + FasterDictionary>> fasterDictionary + , ExclusiveGroupStruct groupId, (uint, uint) rangeTuple, IEntityIDs entityids + , ITypeSafeDictionary typeSafeDictionary, PlatformProfiler profiler) + where TValue : struct, _IInternalEntityComponent { //get all the engines linked to TValue - if (!fasterDictionary.TryGetValue(new RefWrapperType(TypeCache.type) - , out var entityComponentsEngines)) + if (!fasterDictionary.TryGetValue( + new RefWrapperType(TypeCache.type) + , out var entityComponentsEngines)) return; for (var i = 0; i < entityComponentsEngines.count; i++) @@ -487,30 +491,28 @@ namespace Svelto.ECS.Internal } catch (Exception e) { - Console.LogException( - e, "Code crashed inside Add callback ".FastConcat(entityComponentsEngines[i].name)); + Console.LogException(e, "Code crashed inside Add callback ".FastConcat(entityComponentsEngines[i].name)); throw; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void ExecuteEnginesSwapCallbacksFast - (FasterList> fasterList, ExclusiveGroupStruct fromGroup - , ExclusiveGroupStruct toGroup, IEntityIDs entityids, ITypeSafeDictionary typeSafeDictionary - , (uint, uint) rangeofsubmittedentitiesindicies, PlatformProfiler sampler) - where TValue : struct, _IInternalEntityComponent + public static void ExecuteEnginesSwapCallbacksFast(FasterList> fasterList, + ExclusiveGroupStruct fromGroup + , ExclusiveGroupStruct toGroup, IEntityIDs entityids, ITypeSafeDictionary typeSafeDictionary + , (uint, uint) rangeofsubmittedentitiesindicies, PlatformProfiler sampler) + where TValue : struct, _IInternalEntityComponent { for (var i = 0; i < fasterList.count; i++) try { using (sampler.Sample(fasterList[i].name)) { - ((IReactOnSwapEx)fasterList[i].engine).MovedTo(rangeofsubmittedentitiesindicies - , new EntityCollection( - typeSafeDictionary.GetValues( - out var count), entityids, count) - , fromGroup, toGroup); + ((IReactOnSwapEx)fasterList[i].engine).MovedTo( + rangeofsubmittedentitiesindicies + , new EntityCollection(typeSafeDictionary.GetValues(out var count), entityids, count) + , fromGroup, toGroup); } } catch (Exception e) @@ -522,10 +524,11 @@ namespace Svelto.ECS.Internal } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void ExecuteEnginesRemoveCallbacksFast - (FasterList> fasterList, ExclusiveGroupStruct exclusiveGroupStruct - , (uint, uint) valueTuple, IEntityIDs entityids, ITypeSafeDictionary typeSafeDictionary - , PlatformProfiler sampler) where TValue : struct, _IInternalEntityComponent + public static void ExecuteEnginesRemoveCallbacksFast(FasterList> fasterList, + ExclusiveGroupStruct exclusiveGroupStruct + , (uint, uint) valueTuple, IEntityIDs entityids, ITypeSafeDictionary typeSafeDictionary + , PlatformProfiler sampler) + where TValue : struct, _IInternalEntityComponent { for (var i = 0; i < fasterList.count; i++) try diff --git a/com.sebaslab.svelto.ecs/Serialization/EnginesRoot.GenericEntitySerialization.cs b/com.sebaslab.svelto.ecs/Serialization/EnginesRoot.GenericEntitySerialization.cs index 6e0820c..8e1c8d8 100644 --- a/com.sebaslab.svelto.ecs/Serialization/EnginesRoot.GenericEntitySerialization.cs +++ b/com.sebaslab.svelto.ecs/Serialization/EnginesRoot.GenericEntitySerialization.cs @@ -47,7 +47,7 @@ namespace Svelto.ECS IDeserializationFactory factory = serializationDescriptorMap.GetSerializationFactory(descriptorHash); return factory.BuildDeserializedEntity(egid, serializationData, entityDescriptor, serializationType, - this, this._enginesRoot.GenerateEntityFactory(), _enginesRoot is SerializingEnginesRoot); + this, _enginesRoot.GenerateEntityFactory(), _enginesRoot is SerializingEnginesRoot); } public void DeserializeEntity(ISerializationData serializationData, int serializationType) @@ -147,7 +147,7 @@ namespace Svelto.ECS } catch { - Svelto.Console.LogError( + Console.LogError( $"something went wrong while deserializing entity {entityDescriptor.realType}"); throw; @@ -201,7 +201,7 @@ namespace Svelto.ECS internal EntitySerialization(EnginesRoot enginesRoot) { - _root = new Svelto.DataStructures.WeakReference(enginesRoot); + _root = new DataStructures.WeakReference(enginesRoot); } void SerializeEntityComponent(EGID entityGID, ISerializableComponentBuilder componentBuilder, @@ -239,7 +239,7 @@ namespace Svelto.ECS } EnginesRoot _enginesRoot => _root.Target; - readonly Svelto.DataStructures.WeakReference _root; + readonly DataStructures.WeakReference _root; } public IEntitySerialization GenerateEntitySerializer() diff --git a/com.sebaslab.svelto.ecs/Svelto.ECS.csproj b/com.sebaslab.svelto.ecs/Svelto.ECS.csproj index f3eafd1..2b91a8b 100644 --- a/com.sebaslab.svelto.ecs/Svelto.ECS.csproj +++ b/com.sebaslab.svelto.ecs/Svelto.ECS.csproj @@ -4,8 +4,8 @@ 9 netstandard2.1 Svelto - 3.4.0 - 3.4.0 + 3.4.1 + 3.4.1 true Debug;Release;SlowSubmissionRelease;SlowSubmissionDebug AnyCPU diff --git a/com.sebaslab.svelto.ecs/package.json b/com.sebaslab.svelto.ecs/package.json index db4568e..2fcb0cb 100644 --- a/com.sebaslab.svelto.ecs/package.json +++ b/com.sebaslab.svelto.ecs/package.json @@ -19,7 +19,7 @@ "svelto.ecs" ], "name": "com.sebaslab.svelto.ecs", - "version": "3.4.0", + "version": "3.4.1", "type": "library", - "unity": "2019.3" + "unity": "2020.3" } diff --git a/com.sebaslab.svelto.ecs/version.json b/com.sebaslab.svelto.ecs/version.json index 2d946b1..a61d7a4 100644 --- a/com.sebaslab.svelto.ecs/version.json +++ b/com.sebaslab.svelto.ecs/version.json @@ -1,3 +1,3 @@ { - "version": "3.4.0" + "version": "3.4.1" }