Browse Source

changing the use of the platform profiler, but still not sure about it

tags/2.7
sebas77 5 years ago
parent
commit
0f8328d539
4 changed files with 26 additions and 27 deletions
  1. +13
    -18
      Svelto.ECS/DataStructures/TypeSafeDictionary.cs
  2. +10
    -5
      Svelto.ECS/EnginesRoot.Entities.cs
  3. +1
    -1
      Svelto.ECS/EnginesRoot.Submission.cs
  4. +2
    -3
      Svelto.ECS/IEngine.cs

+ 13
- 18
Svelto.ECS/DataStructures/TypeSafeDictionary.cs View File

@@ -11,15 +11,15 @@ namespace Svelto.ECS.Internal
ITypeSafeDictionary Create();
void RemoveEntitiesFromEngines(Dictionary<Type, FasterList<IHandleEntityViewEngineAbstracted>>
entityViewEnginesDB, PlatformProfiler profiler);
entityViewEnginesDB, ref PlatformProfiler profiler);

void MoveEntityFromDictionaryAndEngines(EGID fromEntityGid, EGID toEntityID, ITypeSafeDictionary toGroup,
Dictionary<Type, FasterList<IHandleEntityViewEngineAbstracted>>
entityViewEnginesDB, PlatformProfiler profiler);
entityViewEnginesDB, ref PlatformProfiler profiler);
void FillWithIndexedEntities(ITypeSafeDictionary entities);
void AddEntitiesToEngines(Dictionary<Type, FasterList<IHandleEntityViewEngineAbstracted>> entityViewEnginesDB,
PlatformProfiler profiler);
ref PlatformProfiler profiler);
void AddCapacity(int size);
@@ -61,7 +61,7 @@ namespace Svelto.ECS.Internal

public void AddEntitiesToEngines(
Dictionary<Type, FasterList<IHandleEntityViewEngineAbstracted>> 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<Type, FasterList<IHandleEntityViewEngineAbstracted>> entityViewEnginesDB,
ref TValue entity,
PlatformProfiler profiler)
ref TValue entity, ref PlatformProfiler profiler)
{
FasterList<IHandleEntityViewEngineAbstracted> 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<Type, FasterList<IHandleEntityViewEngineAbstracted>>
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<Type, FasterList<IHandleEntityViewEngineAbstracted>> entityViewEnginesDB, ref TValue entity,
PlatformProfiler profiler)
ref PlatformProfiler profiler)
{
FasterList<IHandleEntityViewEngineAbstracted> entityViewsEngines;
if (entityViewEnginesDB.TryGetValue(_type, out entityViewsEngines))
@@ -154,13 +148,14 @@ namespace Svelto.ECS.Internal
}
}
public void RemoveEntitiesFromEngines(Dictionary<Type, FasterList<IHandleEntityViewEngineAbstracted>> entityViewEnginesDB, PlatformProfiler profiler)
public void RemoveEntitiesFromEngines(Dictionary<Type,
FasterList<IHandleEntityViewEngineAbstracted>> 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()


+ 10
- 5
Svelto.ECS/EnginesRoot.Entities.cs View File

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


+ 1
- 1
Svelto.ECS/EnginesRoot.Submission.cs View File

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


+ 2
- 3
Svelto.ECS/IEngine.cs View File

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



Loading…
Cancel
Save