Browse Source

Fix bug that was preventing the adding of an entity that was deleted

tags/Rel25b
sebas77 6 years ago
parent
commit
5691f224a5
4 changed files with 33 additions and 27 deletions
  1. +3
    -3
      Svelto.ECS/DataStructures/TypeSafeDictionary.cs
  2. +15
    -11
      Svelto.ECS/EnginesRoot.Entities.cs
  3. +4
    -4
      Svelto.ECS/EnginesRoot.Submission.cs
  4. +11
    -9
      Svelto.ECS/EntityFactory.cs

+ 3
- 3
Svelto.ECS/DataStructures/TypeSafeDictionary.cs View File

@@ -24,7 +24,7 @@ namespace Svelto.ECS.Internal
Dictionary<Type, FasterList<IHandleEntityViewEngineAbstracted>>
entityViewEnginesDB);
void FillWithIndexedEntityViews(ITypeSafeDictionary entityViews);
void FillWithIndexedEntities(ITypeSafeDictionary entities);
void AddEntityViewsToEngines(Dictionary<Type, FasterList<IHandleEntityViewEngineAbstracted>> entityViewEnginesDB);
void AddCapacity(int size);
@@ -41,10 +41,10 @@ namespace Svelto.ECS.Internal
public TypeSafeDictionary()
{}

public void FillWithIndexedEntityViews(ITypeSafeDictionary entityViews)
public void FillWithIndexedEntities(ITypeSafeDictionary entities)
{
int count;
var buffer = (entityViews as TypeSafeDictionary<TValue>).GetFasterValuesBuffer(out count);
var buffer = (entities as TypeSafeDictionary<TValue>).GetFasterValuesBuffer(out count);

try
{


+ 15
- 11
Svelto.ECS/EnginesRoot.Entities.cs View File

@@ -113,26 +113,31 @@ namespace Svelto.ECS
var entityInfoView = entityViewInfoDictionary[entityGID.entityID];
var entityBuilders = entityInfoView.entityToBuild;
var entityBuildersCount = entityBuilders.Length;

var group = _groupEntityDB[entityGID.groupID];

//for each entity view generated by the entity descriptor
for (var i = 0; i < entityBuildersCount; i++)
{
var entityType = entityBuilders[i].GetEntityType();
var group = _groupEntityDB[entityGID.groupID];

var groupedEntities = _groupEntityDB[entityGID.groupID];
var typeSafeDictionary = groupedEntities[entityType];
typeSafeDictionary.RemoveEntityFromEngines(entityGID, _entityEngines);
RemoveEntityFromGroup(group, entityType, entityGID);
RemoveEntityFromSafeDictionary(group, entityType, entityGID);
}

RemoveEntityFromSafeDictionary(group, _typeEntityInfoView, entityGID);
}

static void RemoveEntityFromGroup(Dictionary<Type, ITypeSafeDictionary> @group, Type entityType, EGID id)
static void RemoveEntityFromSafeDictionary(Dictionary<Type, ITypeSafeDictionary> @group, Type entityType, EGID id)
{
var typeSafeList = @group[entityType];
if (typeSafeList.Remove(id.entityID) == false) //clean up
typeSafeList.Remove(id.entityID);
if (typeSafeList.Count == 0)//clean up
@group.Remove(entityType);
}

@@ -195,11 +200,10 @@ namespace Svelto.ECS
return new EGID(firstID, toGroupId);
}

readonly entitiesDB _DB;
//grouped set of entity views, this is the standard way to handle entity views
readonly Dictionary<int, Dictionary<Type, ITypeSafeDictionary>> _groupEntityDB;
static readonly Type _typeEntityInfoView = typeof(EntityInfoView);
readonly entitiesDB _DB;
readonly Dictionary<int, Dictionary<Type, ITypeSafeDictionary>> _groupEntityDB;

static readonly Type _typeEntityInfoView = typeof(EntityInfoView);
}

public struct EntityStructInitializer
@@ -220,6 +224,6 @@ namespace Svelto.ECS
}

readonly Dictionary<Type, ITypeSafeDictionary> _current;
readonly EGID _id;
readonly EGID _id;
}
}

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

@@ -45,7 +45,7 @@ namespace Svelto.ECS
}
}
//todo: groupsToSubmit can be semplified as data structure?
//todo: groupsToSubmit can be simplified as data structure?
void AddEntityViewsToTheDBAndSuitableEngines(Dictionary<int, Dictionary<Type, ITypeSafeDictionary>> groupsOfEntitiesToSubmit)
{
//each group is indexed by entity view type. for each type there is a dictionary indexed by entityID
@@ -66,7 +66,7 @@ namespace Svelto.ECS
dbDic = groupDB[entityViewTypeSafeDictionary.Key] = entityViewTypeSafeDictionary.Value.Create();

//type safe copy
dbDic.FillWithIndexedEntityViews(entityViewTypeSafeDictionary.Value);
dbDic.FillWithIndexedEntities(entityViewTypeSafeDictionary.Value);
}
}

@@ -86,7 +86,7 @@ namespace Svelto.ECS
//split by type per group. It's possible to get all the entities of a give type T per group thanks
//to the FasterDictionary capabilitiies OR it's possible to get a specific entityView indexed by
//ID. This ID doesn't need to be the EGID, it can be just the entityID
readonly DoubleBufferedEntityViews<Dictionary<int, Dictionary<Type, ITypeSafeDictionary>>> _groupedEntityToAdd;
readonly EntitySubmissionScheduler _scheduler;
readonly DoubleBufferedEntityViews<Dictionary<int, Dictionary<Type, ITypeSafeDictionary>>> _groupedEntityToAdd;
readonly EntitySubmissionScheduler _scheduler;
}
}

+ 11
- 9
Svelto.ECS/EntityFactory.cs View File

@@ -5,10 +5,11 @@ namespace Svelto.ECS.Internal
{
static class EntityFactory
{
internal static Dictionary<Type, ITypeSafeDictionary> BuildGroupedEntityViews(EGID egid,
Dictionary<int, Dictionary<Type, ITypeSafeDictionary>> groupEntityViewsByType,
IEntityBuilder[] entityToBuild,
object[] implementors)
internal static Dictionary<Type, ITypeSafeDictionary>
BuildGroupedEntityViews(EGID egid,
Dictionary<int, Dictionary<Type, ITypeSafeDictionary>> groupEntityViewsByType,
IEntityBuilder[] entityToBuild,
object[] implementors)
{
var @group = FetchEntityViewGroup(egid.groupID, groupEntityViewsByType);

@@ -17,7 +18,8 @@ namespace Svelto.ECS.Internal
return group;
}

static Dictionary<Type, ITypeSafeDictionary> FetchEntityViewGroup(int groupID, Dictionary<int, Dictionary<Type, ITypeSafeDictionary>> groupEntityViewsByType)
static Dictionary<Type, ITypeSafeDictionary> FetchEntityViewGroup(int groupID,
Dictionary<int, Dictionary<Type, ITypeSafeDictionary>> groupEntityViewsByType)
{
Dictionary<Type, ITypeSafeDictionary> group;

@@ -45,8 +47,8 @@ namespace Svelto.ECS.Internal
BuildEntityView(entityID, @group, entityViewType, entityViewBuilder, implementors);
}

Builder._initializer = new EntityInfoView {entityToBuild = entityToBuild};
BuildEntityView(entityID, @group, _viewType, Builder, null);
_builder._initializer = new EntityInfoView {entityToBuild = entityToBuild};
BuildEntityView(entityID, @group, _viewType, _builder, null);
}

static void BuildEntityView(EGID entityID, Dictionary<Type, ITypeSafeDictionary> @group,
@@ -66,7 +68,7 @@ namespace Svelto.ECS.Internal
@group.Add(entityViewType, safeDictionary);
}
static readonly EntityBuilder<EntityInfoView> Builder = new EntityBuilder<EntityInfoView>();
static readonly Type _viewType = typeof(EntityInfoView);
static readonly EntityBuilder<EntityInfoView> _builder = new EntityBuilder<EntityInfoView>();
static readonly Type _viewType = typeof(EntityInfoView);
}
}

Loading…
Cancel
Save