Browse Source

fix debug false positive

pull/107/head
Sebastiano Mandala 1 year ago
parent
commit
30a36ae05c
21 changed files with 211 additions and 190 deletions
  1. +2
    -2
      com.sebaslab.svelto.ecs/CHANGELOG.md
  2. +3
    -3
      com.sebaslab.svelto.ecs/Core/CheckEntityUtilities.cs
  3. +1
    -1
      com.sebaslab.svelto.ecs/Core/ComponentBuilder.cs
  4. +1
    -1
      com.sebaslab.svelto.ecs/Core/DBC.cs
  5. +2
    -2
      com.sebaslab.svelto.ecs/Core/EGIDMapper.cs
  6. +2
    -2
      com.sebaslab.svelto.ecs/Core/EnginesGroup/SortedEnginesGroup.cs
  7. +4
    -4
      com.sebaslab.svelto.ecs/Core/EnginesGroup/UnsortedEnginesGroup.cs
  8. +2
    -3
      com.sebaslab.svelto.ecs/Core/EnginesRoot.Engines.cs
  9. +1
    -1
      com.sebaslab.svelto.ecs/Core/EnginesRoot.GenericEntityFunctions.cs
  10. +7
    -3
      com.sebaslab.svelto.ecs/Core/EnginesRoot.Submission.cs
  11. +15
    -0
      com.sebaslab.svelto.ecs/Core/EntitiesDB.cs
  12. +2
    -2
      com.sebaslab.svelto.ecs/Core/Groups/ExclusiveGroupStruct.cs
  13. +1
    -1
      com.sebaslab.svelto.ecs/Core/Groups/QueryGroups.cs
  14. +1
    -1
      com.sebaslab.svelto.ecs/Core/Hybrid/ValueReference.cs
  15. +1
    -1
      com.sebaslab.svelto.ecs/Core/Streams/EntityStream.cs
  16. +1
    -1
      com.sebaslab.svelto.ecs/DataStructures/ITypeSafeDictionary.cs
  17. +156
    -153
      com.sebaslab.svelto.ecs/DataStructures/TypeSafeDictionaryMethods.cs
  18. +4
    -4
      com.sebaslab.svelto.ecs/Serialization/EnginesRoot.GenericEntitySerialization.cs
  19. +2
    -2
      com.sebaslab.svelto.ecs/Svelto.ECS.csproj
  20. +2
    -2
      com.sebaslab.svelto.ecs/package.json
  21. +1
    -1
      com.sebaslab.svelto.ecs/version.json

+ 2
- 2
com.sebaslab.svelto.ecs/CHANGELOG.md View File

@@ -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


+ 3
- 3
com.sebaslab.svelto.ecs/Core/CheckEntityUtilities.cs View File

@@ -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<EGID, uint> _multipleOperationOnSameEGIDChecker;
readonly Svelto.DataStructures.FasterDictionary<ExclusiveGroupStruct, HashSet<uint>> _idChecker;
readonly DataStructures.FasterDictionary<EGID, uint> _multipleOperationOnSameEGIDChecker;
readonly DataStructures.FasterDictionary<ExclusiveGroupStruct, HashSet<uint>> _idChecker;
}
}

+ 1
- 1
com.sebaslab.svelto.ecs/Core/ComponentBuilder.cs View File

@@ -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 :)");
}
}



+ 1
- 1
com.sebaslab.svelto.ecs/Core/DBC.cs View File

@@ -224,7 +224,7 @@ namespace DBC.ECS
#endregion // Implementation
} // End Check

internal class Trace
class Trace
{
internal static void Assert(bool assertion, string v)
{


+ 2
- 2
com.sebaslab.svelto.ecs/Core/EGIDMapper.cs View File

@@ -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


+ 2
- 2
com.sebaslab.svelto.ecs/Core/EnginesGroup/SortedEnginesGroup.cs View File

@@ -47,7 +47,7 @@ namespace Svelto.ECS
{
protected SortedEnginesGroup(FasterList<Interface> engines)
{
_name = "SortedEnginesGroup - "+this.GetType().Name;
_name = "SortedEnginesGroup - "+GetType().Name;
_instancedSequence = new Sequence<Interface, SequenceOrder>(engines);
}

@@ -80,7 +80,7 @@ namespace Svelto.ECS
{
protected SortedEnginesGroup(FasterList<Interface> engines)
{
_name = "SortedEnginesGroup - "+this.GetType().Name;
_name = "SortedEnginesGroup - "+GetType().Name;
_instancedSequence = new Sequence<Interface, SequenceOrder>(engines);
}



+ 4
- 4
com.sebaslab.svelto.ecs/Core/EnginesGroup/UnsortedEnginesGroup.cs View File

@@ -15,13 +15,13 @@ namespace Svelto.ECS
{
protected UnsortedEnginesGroup()
{
_name = "UnsortedEnginesGroup - "+this.GetType().Name;
_name = "UnsortedEnginesGroup - "+GetType().Name;
_instancedSequence = new FasterList<Interface>();
}
protected UnsortedEnginesGroup(FasterList<Interface> 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<Interface>();
}
protected UnsortedEnginesGroup(FasterList<Interface> engines)
{
_name = "UnsortedEnginesGroup - "+this.GetType().Name;
_name = "UnsortedEnginesGroup - "+GetType().Name;
_instancedSequence = engines;
}



+ 2
- 3
com.sebaslab.svelto.ecs/Core/EnginesRoot.Engines.cs View File

@@ -330,7 +330,7 @@ namespace Svelto.ECS
{
public EntitiesSubmitter(EnginesRoot enginesRoot): this()
{
_enginesRoot = new Svelto.DataStructures.WeakReference<EnginesRoot>(enginesRoot);
_enginesRoot = new DataStructures.WeakReference<EnginesRoot>(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> _enginesRoot;
readonly DataStructures.WeakReference<EnginesRoot> _enginesRoot;
}

~EnginesRoot()


+ 1
- 1
com.sebaslab.svelto.ecs/Core/EnginesRoot.GenericEntityFunctions.cs View File

@@ -104,7 +104,7 @@ namespace Svelto.ECS
enginesRootTarget.CheckAddEntityID(toEGID, TypeCache<T>.type, caller);

enginesRootTarget.QueueSwapEntityOperation(fromEGID, toEGID
, this._enginesRoot.Target.FindRealComponents<T>(fromEGID)
, _enginesRoot.Target.FindRealComponents<T>(fromEGID)
, caller);
}



+ 7
- 3
com.sebaslab.svelto.ecs/Core/EnginesRoot.Submission.cs View File

@@ -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
);
}


+ 15
- 0
com.sebaslab.svelto.ecs/Core/EntitiesDB.cs View File

@@ -205,6 +205,9 @@ namespace Svelto.ECS
return true;
}

/// <summary>
/// determine if component with specific ID exists in group
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool Exists<T>(EGID entityGID) where T : struct, _IInternalEntityComponent
{
@@ -214,6 +217,9 @@ namespace Svelto.ECS
return casted != null && casted.ContainsKey(entityGID.entityID);
}

/// <summary>
/// determine if component with specific ID exists in group
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool Exists<T>(uint id, ExclusiveGroupStruct group) where T : struct, _IInternalEntityComponent
{
@@ -223,6 +229,9 @@ namespace Svelto.ECS
return casted != null && casted.ContainsKey(id);
}

/// <summary>
/// determine if group exists and is not empty
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool ExistsAndIsNotEmpty(ExclusiveGroupStruct gid)
{
@@ -235,12 +244,18 @@ namespace Svelto.ECS
return false;
}

/// <summary>
/// determine if entities we specific components are found in group
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool HasAny<T>(ExclusiveGroupStruct groupStruct) where T : struct, _IInternalEntityComponent
{
return Count<T>(groupStruct) > 0;
}

/// <summary>
/// count the number of components in a group
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public int Count<T>(ExclusiveGroupStruct groupStruct) where T : struct, _IInternalEntityComponent
{


+ 2
- 2
com.sebaslab.svelto.ecs/Core/Groups/ExclusiveGroupStruct.cs View File

@@ -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)]


+ 1
- 1
com.sebaslab.svelto.ecs/Core/Groups/QueryGroups.cs View File

@@ -6,7 +6,7 @@ using Svelto.ECS.Internal;

namespace Svelto.ECS.Experimental
{
internal struct GroupsList
struct GroupsList
{
public static GroupsList Init()
{


+ 1
- 1
com.sebaslab.svelto.ecs/Core/Hybrid/ValueReference.cs View File

@@ -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 {}
}

+ 1
- 1
com.sebaslab.svelto.ecs/Core/Streams/EntityStream.cs View File

@@ -3,7 +3,7 @@ using Svelto.ECS.Internal;

namespace Svelto.ECS
{
internal interface ITypeSafeStream
interface ITypeSafeStream
{
void Dispose();
}


+ 1
- 1
com.sebaslab.svelto.ecs/DataStructures/ITypeSafeDictionary.cs View File

@@ -92,6 +92,6 @@ namespace Svelto.ECS.Internal
uint GetIndex(uint valueEntityId);
bool TryFindIndex(uint entityGidEntityId, out uint index);

void KeysEvaluator(System.Action<uint> action);
void KeysEvaluator(Action<uint> action);
}
}

+ 156
- 153
com.sebaslab.svelto.ecs/DataStructures/TypeSafeDictionaryMethods.cs View File

@@ -9,28 +9,30 @@ namespace Svelto.ECS.Internal
public static class TypeSafeDictionaryMethods
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void AddEntitiesToDictionary<Strategy1, Strategy2, Strategy3, TValue>
(in SveltoDictionary<uint, TValue, Strategy1, Strategy2, Strategy3> fromDictionary
, ITypeSafeDictionary<TValue> toDic
public static void AddEntitiesToDictionary<Strategy1, Strategy2, Strategy3, TValue>(
in SveltoDictionary<uint, TValue, Strategy1, Strategy2, Strategy3> fromDictionary
, ITypeSafeDictionary<TValue> toDic
#if SLOW_SVELTO_SUBMISSION
, in EnginesRoot.EntityReferenceMap entityLocator
, in EnginesRoot.EntityReferenceMap entityLocator
#endif
, ExclusiveGroupStruct toGroupID) where Strategy1 : struct, IBufferStrategy<SveltoDictionaryNode<uint>>
where Strategy2 : struct, IBufferStrategy<TValue>
where Strategy3 : struct, IBufferStrategy<int>
where TValue : struct, _IInternalEntityComponent
, ExclusiveGroupStruct toGroupID)
where Strategy1 : struct, IBufferStrategy<SveltoDictionaryNode<uint>>
where Strategy2 : struct, IBufferStrategy<TValue>
where Strategy3 : struct, IBufferStrategy<int>
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<TValue>.hasEgid)
SetEGIDWithoutBoxing<TValue>.SetIDWithoutBoxing(ref tuple.value, egid);
if (SlowSubmissionInfo<TValue>.hasEgid)
SetEGIDWithoutBoxing<TValue>.SetIDWithoutBoxing(ref tuple.value, egid);

if (SlowSubmissionInfo<TValue>.hasReference)
SetEGIDWithoutBoxing<TValue>.SetRefWithoutBoxing(ref tuple.value,
entityLocator.GetEntityReference(egid));
if (SlowSubmissionInfo<TValue>.hasReference)
SetEGIDWithoutBoxing<TValue>.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<Strategy1, Strategy2, Strategy3, TValue>
(ref SveltoDictionary<uint, TValue, Strategy1, Strategy2, Strategy3> fromDictionary
, ITypeSafeDictionary<TValue> todic, ExclusiveGroupStruct togroup
, FasterDictionary<RefWrapperType, FasterList<ReactEngineContainer<IReactOnAdd>>> entitycomponentenginesdb
, in PlatformProfiler sampler) where Strategy1 : struct, IBufferStrategy<SveltoDictionaryNode<uint>>
where Strategy2 : struct, IBufferStrategy<TValue>
where Strategy3 : struct, IBufferStrategy<int>
where TValue : struct, _IInternalEntityComponent
public static void ExecuteEnginesAddCallbacks<Strategy1, Strategy2, Strategy3, TValue>(
ref SveltoDictionary<uint, TValue, Strategy1, Strategy2, Strategy3> fromDictionary
, ITypeSafeDictionary<TValue> todic, ExclusiveGroupStruct togroup
, FasterDictionary<RefWrapperType, FasterList<ReactEngineContainer<IReactOnAdd>>> entitycomponentenginesdb
, in PlatformProfiler sampler)
where Strategy1 : struct, IBufferStrategy<SveltoDictionaryNode<uint>>
where Strategy2 : struct, IBufferStrategy<TValue>
where Strategy3 : struct, IBufferStrategy<int>
where TValue : struct, _IInternalEntityComponent
{
if (entitycomponentenginesdb.TryGetValue(new RefWrapperType(TypeCache<TValue>.type)
, out var entityComponentsEngines))
if (entitycomponentenginesdb.TryGetValue(
new RefWrapperType(TypeCache<TValue>.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<TValue>.name));
Console.LogException(e, "Code crashed inside Add callback with Type ".FastConcat(TypeCache<TValue>.name));

throw;
}
@@ -94,14 +99,14 @@ 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<RefWrapperType, FasterList<ReactEngineContainer<IReactOnDispose>>> allEngines
, ExclusiveGroupStruct inGroup, in PlatformProfiler sampler)
where Strategy1 : struct, IBufferStrategy<SveltoDictionaryNode<uint>>
where Strategy2 : struct, IBufferStrategy<TValue>
where Strategy3 : struct, IBufferStrategy<int>
where TValue : struct, _IInternalEntityComponent
public static void ExecuteEnginesDisposeCallbacks_Group<Strategy1, Strategy2, Strategy3, TValue>(
ref SveltoDictionary<uint, TValue, Strategy1, Strategy2, Strategy3> fromDictionary
, FasterDictionary<RefWrapperType, FasterList<ReactEngineContainer<IReactOnDispose>>> allEngines
, ExclusiveGroupStruct inGroup, 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(new RefWrapperType(TypeCache<TValue>.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<TValue>)entityComponentsEngines[i].engine;
ref var entity = ref value.value;
var egid = new EGID(value.key, inGroup);
var reactOnRemove = (IReactOnDispose<TValue>)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<Strategy1, Strategy2, Strategy3, TValue>
(FasterList<(uint, string)> infostoprocess
, ref SveltoDictionary<uint, TValue, Strategy1, Strategy2, Strategy3> fromDictionary
, FasterDictionary<RefWrapperType, FasterList<ReactEngineContainer<IReactOnRemove>>> reactiveenginesremove
, ExclusiveGroupStruct fromgroup, in PlatformProfiler profiler)
where Strategy1 : struct, IBufferStrategy<SveltoDictionaryNode<uint>>
where Strategy2 : struct, IBufferStrategy<TValue>
where Strategy3 : struct, IBufferStrategy<int>
where TValue : struct, _IInternalEntityComponent
public static void ExecuteEnginesRemoveCallbacks<Strategy1, Strategy2, Strategy3, TValue>(FasterList<(uint, string)> infostoprocess
, ref SveltoDictionary<uint, TValue, Strategy1, Strategy2, Strategy3> fromDictionary
, FasterDictionary<RefWrapperType, FasterList<ReactEngineContainer<IReactOnRemove>>> reactiveenginesremove
, ExclusiveGroupStruct fromgroup, in PlatformProfiler profiler)
where Strategy1 : struct, IBufferStrategy<SveltoDictionaryNode<uint>>
where Strategy2 : struct, IBufferStrategy<TValue>
where Strategy3 : struct, IBufferStrategy<int>
where TValue : struct, _IInternalEntityComponent
{
if (reactiveenginesremove.TryGetValue(new RefWrapperType(TypeCache<TValue>.type)
, out var entityComponentsEngines))
if (reactiveenginesremove.TryGetValue(
new RefWrapperType(TypeCache<TValue>.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<TValue>.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<Strategy1, Strategy2, Strategy3, TValue>
(ref SveltoDictionary<uint, TValue, Strategy1, Strategy2, Strategy3> fromDictionary
, ITypeSafeDictionary<TValue> typeSafeDictionary
, FasterDictionary<RefWrapperType, FasterList<ReactEngineContainer<IReactOnRemove>>> reactiveenginesremove
, FasterDictionary<RefWrapperType, FasterList<ReactEngineContainer<IReactOnRemoveEx>>> reactiveenginesremoveex
, int count, 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
public static void ExecuteEnginesRemoveCallbacks_Group<Strategy1, Strategy2, Strategy3, TValue>(
ref SveltoDictionary<uint, TValue, Strategy1, Strategy2, Strategy3> fromDictionary
, ITypeSafeDictionary<TValue> typeSafeDictionary
, FasterDictionary<RefWrapperType, FasterList<ReactEngineContainer<IReactOnRemove>>> reactiveenginesremove
, FasterDictionary<RefWrapperType, FasterList<ReactEngineContainer<IReactOnRemoveEx>>> reactiveenginesremoveex
, int count, 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 (reactiveenginesremove.TryGetValue(new RefWrapperType(TypeCache<TValue>.type)
, out var reactiveEnginesRemovePerType))
if (reactiveenginesremove.TryGetValue(
new RefWrapperType(TypeCache<TValue>.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<TValue>.type)
, out var reactiveEnginesRemoveExPerType))
if (reactiveenginesremoveex.TryGetValue(
new RefWrapperType(TypeCache<TValue>.type)
, out var reactiveEnginesRemoveExPerType))
{
var enginesCount = reactiveEnginesRemoveExPerType.count;

@@ -233,14 +238,14 @@ namespace Svelto.ECS.Internal
{
((IReactOnRemoveEx<TValue>)reactiveEnginesRemoveExPerType[i].engine).Remove(
(0, (uint)count)
, new EntityCollection<TValue>(typeSafeDictionary.GetValues(out _), entityids
, (uint)count), group);
, new EntityCollection<TValue>(
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<Strategy1, Strategy2, Strategy3, TValue>
(FasterList<(uint, uint, string)> infostoprocess
, ref SveltoDictionary<uint, TValue, Strategy1, Strategy2, Strategy3> fromDictionary
, FasterList<ReactEngineContainer<IReactOnSwap>> reactiveenginesswap, ExclusiveGroupStruct togroup
, ExclusiveGroupStruct fromgroup, in PlatformProfiler sampler)
where Strategy1 : struct, IBufferStrategy<SveltoDictionaryNode<uint>>
where Strategy2 : struct, IBufferStrategy<TValue>
where Strategy3 : struct, IBufferStrategy<int>
where TValue : struct, _IInternalEntityComponent
public static void ExecuteEnginesSwapCallbacks<Strategy1, Strategy2, Strategy3, TValue>(FasterList<(uint, uint, string)> infostoprocess
, ref SveltoDictionary<uint, TValue, Strategy1, Strategy2, Strategy3> fromDictionary
, FasterList<ReactEngineContainer<IReactOnSwap>> reactiveenginesswap, ExclusiveGroupStruct togroup
, ExclusiveGroupStruct fromgroup, in PlatformProfiler sampler)
where Strategy1 : struct, IBufferStrategy<SveltoDictionaryNode<uint>>
where Strategy2 : struct, IBufferStrategy<TValue>
where Strategy3 : struct, IBufferStrategy<int>
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<TValue>.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<Strategy1, Strategy2, Strategy3, TValue>
(ref SveltoDictionary<uint, TValue, Strategy1, Strategy2, Strategy3> fromDictionary
, ITypeSafeDictionary<TValue> toDic, ExclusiveGroupStruct togroup, ExclusiveGroupStruct fromgroup
, ITypeSafeDictionary<TValue> typeSafeDictionary
, FasterDictionary<RefWrapperType, FasterList<ReactEngineContainer<IReactOnSwap>>> reactiveenginesswap
, FasterDictionary<RefWrapperType, FasterList<ReactEngineContainer<IReactOnSwapEx>>> reactiveenginesswapex
, int count, IEntityIDs entityids, in PlatformProfiler sampler)
where Strategy1 : struct, IBufferStrategy<SveltoDictionaryNode<uint>>
where Strategy2 : struct, IBufferStrategy<TValue>
where Strategy3 : struct, IBufferStrategy<int>
where TValue : struct, _IInternalEntityComponent
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<RefWrapperType, FasterList<ReactEngineContainer<IReactOnSwap>>> reactiveenginesswap
, FasterDictionary<RefWrapperType, FasterList<ReactEngineContainer<IReactOnSwapEx>>> reactiveenginesswapex
, int count, IEntityIDs entityids, in PlatformProfiler sampler)
where Strategy1 : struct, IBufferStrategy<SveltoDictionaryNode<uint>>
where Strategy2 : struct, IBufferStrategy<TValue>
where Strategy3 : struct, IBufferStrategy<int>
where TValue : struct, _IInternalEntityComponent
{
//get all the engines linked to TValue
if (!reactiveenginesswap.TryGetValue(new RefWrapperType(TypeCache<TValue>.type)
, out var reactiveEnginesSwapPerType))
if (!reactiveenginesswap.TryGetValue(
new RefWrapperType(TypeCache<TValue>.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<TValue>.type)
, out var reactiveEnginesRemoveExPerType))
if (reactiveenginesswapex.TryGetValue(
new RefWrapperType(TypeCache<TValue>.type)
, out var reactiveEnginesRemoveExPerType))
{
var enginesCount = reactiveEnginesRemoveExPerType.count;

@@ -349,14 +354,14 @@ namespace Svelto.ECS.Internal
{
((IReactOnSwapEx<TValue>)reactiveEnginesRemoveExPerType[i].engine).MovedTo(
(0, (uint)count)
, new EntityCollection<TValue>(typeSafeDictionary.GetValues(out _), entityids
, (uint)count), fromgroup, togroup);
, new EntityCollection<TValue>(
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<Strategy1, Strategy2, Strategy3, TValue>
(FasterList<(uint, string)> infostoprocess
, ref SveltoDictionary<uint, TValue, Strategy1, Strategy2, Strategy3> fromDictionary
, FasterList<uint> entityIDsAffectedByRemoval)
where Strategy1 : struct, IBufferStrategy<SveltoDictionaryNode<uint>>
where Strategy2 : struct, IBufferStrategy<TValue>
where Strategy3 : struct, IBufferStrategy<int>
where TValue : struct, _IInternalEntityComponent
public static void RemoveEntitiesFromDictionary<Strategy1, Strategy2, Strategy3, TValue>(FasterList<(uint, string)> infostoprocess
, ref SveltoDictionary<uint, TValue, Strategy1, Strategy2, Strategy3> fromDictionary
, FasterList<uint> entityIDsAffectedByRemoval)
where Strategy1 : struct, IBufferStrategy<SveltoDictionaryNode<uint>>
where Strategy2 : struct, IBufferStrategy<TValue>
where Strategy3 : struct, IBufferStrategy<int>
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<TValue>.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<Strategy1, Strategy2, Strategy3, TValue>
(FasterList<(uint, uint, string)> infostoprocess
, ref SveltoDictionary<uint, TValue, Strategy1, Strategy2, Strategy3> fromDictionary
, ITypeSafeDictionary<TValue> toDictionary, ExclusiveGroupStruct fromgroup, ExclusiveGroupStruct togroup
, FasterList<uint> entityIDsAffectedByRemoval)
where Strategy1 : struct, IBufferStrategy<SveltoDictionaryNode<uint>>
where Strategy2 : struct, IBufferStrategy<TValue>
where Strategy3 : struct, IBufferStrategy<int>
where TValue : struct, _IInternalEntityComponent
public static void SwapEntitiesBetweenDictionaries<Strategy1, Strategy2, Strategy3, TValue>(FasterList<(uint, uint, string)> infostoprocess
, ref SveltoDictionary<uint, TValue, Strategy1, Strategy2, Strategy3> fromDictionary
, ITypeSafeDictionary<TValue> toDictionary, ExclusiveGroupStruct fromgroup, ExclusiveGroupStruct togroup
, FasterList<uint> entityIDsAffectedByRemoval)
where Strategy1 : struct, IBufferStrategy<SveltoDictionaryNode<uint>>
where Strategy2 : struct, IBufferStrategy<TValue>
where Strategy3 : struct, IBufferStrategy<int>
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<TValue>.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<TValue>
(FasterDictionary<RefWrapperType, FasterList<ReactEngineContainer<IReactOnAddEx>>> fasterDictionary
, ExclusiveGroupStruct groupId, (uint, uint) rangeTuple, IEntityIDs entityids
, ITypeSafeDictionary<TValue> typeSafeDictionary, PlatformProfiler profiler)
where TValue : struct, _IInternalEntityComponent
public static void ExecuteEnginesAddEntityCallbacksFast<TValue>(
FasterDictionary<RefWrapperType, FasterList<ReactEngineContainer<IReactOnAddEx>>> fasterDictionary
, ExclusiveGroupStruct groupId, (uint, uint) rangeTuple, IEntityIDs entityids
, ITypeSafeDictionary<TValue> typeSafeDictionary, PlatformProfiler profiler)
where TValue : struct, _IInternalEntityComponent
{
//get all the engines linked to TValue
if (!fasterDictionary.TryGetValue(new RefWrapperType(TypeCache<TValue>.type)
, out var entityComponentsEngines))
if (!fasterDictionary.TryGetValue(
new RefWrapperType(TypeCache<TValue>.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<TValue>
(FasterList<ReactEngineContainer<IReactOnSwapEx>> fasterList, ExclusiveGroupStruct fromGroup
, ExclusiveGroupStruct toGroup, IEntityIDs entityids, ITypeSafeDictionary<TValue> typeSafeDictionary
, (uint, uint) rangeofsubmittedentitiesindicies, PlatformProfiler sampler)
where TValue : struct, _IInternalEntityComponent
public static void ExecuteEnginesSwapCallbacksFast<TValue>(FasterList<ReactEngineContainer<IReactOnSwapEx>> fasterList,
ExclusiveGroupStruct fromGroup
, ExclusiveGroupStruct toGroup, IEntityIDs entityids, ITypeSafeDictionary<TValue> 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<TValue>)fasterList[i].engine).MovedTo(rangeofsubmittedentitiesindicies
, new EntityCollection<TValue>(
typeSafeDictionary.GetValues(
out var count), entityids, count)
, fromGroup, toGroup);
((IReactOnSwapEx<TValue>)fasterList[i].engine).MovedTo(
rangeofsubmittedentitiesindicies
, new EntityCollection<TValue>(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<TValue>
(FasterList<ReactEngineContainer<IReactOnRemoveEx>> fasterList, ExclusiveGroupStruct exclusiveGroupStruct
, (uint, uint) valueTuple, IEntityIDs entityids, ITypeSafeDictionary<TValue> typeSafeDictionary
, PlatformProfiler sampler) where TValue : struct, _IInternalEntityComponent
public static void ExecuteEnginesRemoveCallbacksFast<TValue>(FasterList<ReactEngineContainer<IReactOnRemoveEx>> fasterList,
ExclusiveGroupStruct exclusiveGroupStruct
, (uint, uint) valueTuple, IEntityIDs entityids, ITypeSafeDictionary<TValue> typeSafeDictionary
, PlatformProfiler sampler)
where TValue : struct, _IInternalEntityComponent
{
for (var i = 0; i < fasterList.count; i++)
try


+ 4
- 4
com.sebaslab.svelto.ecs/Serialization/EnginesRoot.GenericEntitySerialization.cs View File

@@ -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>(enginesRoot);
_root = new DataStructures.WeakReference<EnginesRoot>(enginesRoot);
}

void SerializeEntityComponent(EGID entityGID, ISerializableComponentBuilder componentBuilder,
@@ -239,7 +239,7 @@ namespace Svelto.ECS
}

EnginesRoot _enginesRoot => _root.Target;
readonly Svelto.DataStructures.WeakReference<EnginesRoot> _root;
readonly DataStructures.WeakReference<EnginesRoot> _root;
}

public IEntitySerialization GenerateEntitySerializer()


+ 2
- 2
com.sebaslab.svelto.ecs/Svelto.ECS.csproj View File

@@ -4,8 +4,8 @@
<LangVersion>9</LangVersion>
<TargetFramework>netstandard2.1</TargetFramework>
<Company>Svelto</Company>
<AssemblyVersion>3.4.0</AssemblyVersion>
<PackageVersion>3.4.0</PackageVersion>
<AssemblyVersion>3.4.1</AssemblyVersion>
<PackageVersion>3.4.1</PackageVersion>
<IsPackable>true</IsPackable>
<Configurations>Debug;Release;SlowSubmissionRelease;SlowSubmissionDebug</Configurations>
<Platforms>AnyCPU</Platforms>


+ 2
- 2
com.sebaslab.svelto.ecs/package.json View File

@@ -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"
}

+ 1
- 1
com.sebaslab.svelto.ecs/version.json View File

@@ -1,3 +1,3 @@
{
"version": "3.4.0"
"version": "3.4.1"
}

Loading…
Cancel
Save