From 0f8328d539ebfd3c8445c300143dd1909a9c5639 Mon Sep 17 00:00:00 2001 From: sebas77 Date: Sat, 29 Dec 2018 19:25:15 +0000 Subject: [PATCH] changing the use of the platform profiler, but still not sure about it --- .../DataStructures/TypeSafeDictionary.cs | 31 ++++++++----------- Svelto.ECS/EnginesRoot.Entities.cs | 15 ++++++--- Svelto.ECS/EnginesRoot.Submission.cs | 2 +- Svelto.ECS/IEngine.cs | 5 ++- 4 files changed, 26 insertions(+), 27 deletions(-) diff --git a/Svelto.ECS/DataStructures/TypeSafeDictionary.cs b/Svelto.ECS/DataStructures/TypeSafeDictionary.cs index b607563..734e1a2 100644 --- a/Svelto.ECS/DataStructures/TypeSafeDictionary.cs +++ b/Svelto.ECS/DataStructures/TypeSafeDictionary.cs @@ -11,15 +11,15 @@ namespace Svelto.ECS.Internal ITypeSafeDictionary Create(); void RemoveEntitiesFromEngines(Dictionary> - entityViewEnginesDB, PlatformProfiler profiler); + entityViewEnginesDB, ref PlatformProfiler profiler); void MoveEntityFromDictionaryAndEngines(EGID fromEntityGid, EGID toEntityID, ITypeSafeDictionary toGroup, Dictionary> - entityViewEnginesDB, PlatformProfiler profiler); + entityViewEnginesDB, ref PlatformProfiler profiler); void FillWithIndexedEntities(ITypeSafeDictionary entities); void AddEntitiesToEngines(Dictionary> entityViewEnginesDB, - PlatformProfiler profiler); + ref PlatformProfiler profiler); void AddCapacity(int size); @@ -61,7 +61,7 @@ namespace Svelto.ECS.Internal public void AddEntitiesToEngines( Dictionary> entityViewEnginesDB, - PlatformProfiler profiler) + ref PlatformProfiler profiler) { int count; TValue[] values = GetValuesArray(out count); @@ -70,7 +70,7 @@ namespace Svelto.ECS.Internal { TValue entity = values[i]; - AddEntityViewToEngines(entityViewEnginesDB, ref entity, profiler); + AddEntityViewToEngines(entityViewEnginesDB, ref entity, ref profiler); } } @@ -79,14 +79,8 @@ namespace Svelto.ECS.Internal return ContainsKey(entityIdEntityId); } - public int GetFirstID() - { - return Values[0].ID.entityID; - } - void AddEntityViewToEngines(Dictionary> entityViewEnginesDB, - ref TValue entity, - PlatformProfiler profiler) + ref TValue entity, ref PlatformProfiler profiler) { FasterList entityViewsEngines; //get all the engines linked to TValue @@ -110,14 +104,14 @@ namespace Svelto.ECS.Internal public void MoveEntityFromDictionaryAndEngines(EGID fromEntityGid, EGID toEntityID, ITypeSafeDictionary toGroup, Dictionary> - entityViewEnginesDB, PlatformProfiler profiler) + entityViewEnginesDB, ref PlatformProfiler profiler) { int count; var fasterValuesBuffer = GetValuesArray(out count); var valueIndex = GetValueIndex(fromEntityGid.entityID); if (entityViewEnginesDB != null) - RemoveEntityViewFromEngines(entityViewEnginesDB, ref fasterValuesBuffer[valueIndex], profiler); + RemoveEntityViewFromEngines(entityViewEnginesDB, ref fasterValuesBuffer[valueIndex], ref profiler); if (toGroup != null) { @@ -127,7 +121,7 @@ namespace Svelto.ECS.Internal if (entityViewEnginesDB != null) AddEntityViewToEngines(entityViewEnginesDB, ref toGroupCasted.GetValuesArray(out count) - [toGroupCasted.GetValueIndex(toEntityID.entityID)], profiler); + [toGroupCasted.GetValueIndex(toEntityID.entityID)], ref profiler); } Remove(fromEntityGid.entityID); @@ -135,7 +129,7 @@ namespace Svelto.ECS.Internal static void RemoveEntityViewFromEngines (Dictionary> entityViewEnginesDB, ref TValue entity, - PlatformProfiler profiler) + ref PlatformProfiler profiler) { FasterList entityViewsEngines; if (entityViewEnginesDB.TryGetValue(_type, out entityViewsEngines)) @@ -154,13 +148,14 @@ namespace Svelto.ECS.Internal } } - public void RemoveEntitiesFromEngines(Dictionary> entityViewEnginesDB, PlatformProfiler profiler) + public void RemoveEntitiesFromEngines(Dictionary> entityViewEnginesDB, ref PlatformProfiler profiler) { int count; TValue[] values = GetValuesArray(out count); for (int i = 0; i < count; i++) - RemoveEntityViewFromEngines(entityViewEnginesDB, ref values[i], profiler); + RemoveEntityViewFromEngines(entityViewEnginesDB, ref values[i], ref profiler); } public ITypeSafeDictionary Create() diff --git a/Svelto.ECS/EnginesRoot.Entities.cs b/Svelto.ECS/EnginesRoot.Entities.cs index e71710c..810aa73 100644 --- a/Svelto.ECS/EnginesRoot.Entities.cs +++ b/Svelto.ECS/EnginesRoot.Entities.cs @@ -22,11 +22,12 @@ namespace Svelto.ECS { try { - entityList.Value.RemoveEntitiesFromEngines(_entityEngines, profiler); + var platformProfiler = profiler; + entityList.Value.RemoveEntitiesFromEngines(_entityEngines, ref platformProfiler); } catch (Exception e) { - Svelto.Utilities.Console.LogException(e); + Utilities.Console.LogException(e); } } @@ -37,7 +38,7 @@ namespace Svelto.ECS } catch (Exception e) { - Svelto.Utilities.Console.LogException(e); + Utilities.Console.LogException(e); } } @@ -46,6 +47,8 @@ namespace Svelto.ECS ~EnginesRoot() { + Utilities.Console.LogWarning("Engines Root has been garbage collected, don't forget to call Dispose()!"); + Dispose(); } @@ -210,7 +213,8 @@ namespace Svelto.ECS { throw new EntityNotFoundException(entityGID.entityID, entityGID.groupID, entityType); } - fromTypeSafeDictionary.MoveEntityFromDictionaryAndEngines(entityGID, toEntityGID, dictionaryOfEntities, _entityEngines, profiler); + fromTypeSafeDictionary.MoveEntityFromDictionaryAndEngines(entityGID, toEntityGID, dictionaryOfEntities, + _entityEngines, ref profiler); if (fromTypeSafeDictionary.Count == 0) //clean up { @@ -229,7 +233,8 @@ namespace Svelto.ECS var dictionariesOfEntities = _groupEntityDB[groupID]; foreach (var dictionaryOfEntities in dictionariesOfEntities) { - dictionaryOfEntities.Value.RemoveEntitiesFromEngines(_entityEngines, profiler); + var platformProfiler = profiler; + dictionaryOfEntities.Value.RemoveEntitiesFromEngines(_entityEngines, ref platformProfiler); var groupedGroupOfEntities = _groupsPerEntity[dictionaryOfEntities.Key]; groupedGroupOfEntities.Remove(groupID); } diff --git a/Svelto.ECS/EnginesRoot.Submission.cs b/Svelto.ECS/EnginesRoot.Submission.cs index 758bb07..4d47349 100644 --- a/Svelto.ECS/EnginesRoot.Submission.cs +++ b/Svelto.ECS/EnginesRoot.Submission.cs @@ -158,7 +158,7 @@ namespace Svelto.ECS { using (profiler.Sample("Add entities to engines")) { - entityViewsPerType.Value.AddEntitiesToEngines(_entityEngines, profiler); + entityViewsPerType.Value.AddEntitiesToEngines(_entityEngines, ref profiler); } } } diff --git a/Svelto.ECS/IEngine.cs b/Svelto.ECS/IEngine.cs index f8d8706..cf17f33 100644 --- a/Svelto.ECS/IEngine.cs +++ b/Svelto.ECS/IEngine.cs @@ -12,13 +12,12 @@ namespace Svelto.ECS.Internal public class EngineInfo { #if ENABLE_PLATFORM_PROFILER - public EngineInfo() + protected EngineInfo() { name = GetType().FullName; } -#else - internal string name; #endif + internal readonly string name = string.Empty; } }