Browse Source

forgot to change ID on swap and improve test to be sure it won't happen anymore

tags/Rel25b
sebas77 6 years ago
parent
commit
5f55a22dce
4 changed files with 29 additions and 20 deletions
  1. +3
    -2
      Svelto.ECS/DataStructures/TypeSafeDictionary.cs
  2. +1
    -1
      Svelto.ECS/EnginesRoot.Engines.cs
  3. +17
    -16
      Svelto.ECS/EnginesRoot.Entities.cs
  4. +8
    -1
      Svelto.ECS/EnginesRoot.Submission.cs

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

@@ -20,7 +20,7 @@ namespace Svelto.ECS.Internal
void RemoveEntitiesFromEngines(Dictionary<Type, FasterList<IHandleEntityViewEngineAbstracted>>
entityViewEnginesDB);

void MoveEntityFromDictionaryAndEngines(EGID fromEntityGid,
void MoveEntityFromDictionaryAndEngines(EGID fromEntityGid, int toGroupID,
ITypeSafeDictionary toGroup,
Dictionary<Type, FasterList<IHandleEntityViewEngineAbstracted>>
entityViewEnginesDB);
@@ -84,7 +84,7 @@ namespace Svelto.ECS.Internal
(entityViewsEngines[i] as IHandleEntityStructEngine<TValue>).AddInternal(ref entity);
}

public void MoveEntityFromDictionaryAndEngines(EGID fromEntityGid, ITypeSafeDictionary toGroup,
public void MoveEntityFromDictionaryAndEngines(EGID fromEntityGid, int toGroupID, ITypeSafeDictionary toGroup,
Dictionary<Type, FasterList<IHandleEntityViewEngineAbstracted>>
entityViewEnginesDB)
{
@@ -97,6 +97,7 @@ namespace Svelto.ECS.Internal
if (toGroup != null)
{
var toGroupCasted = (toGroup as TypeSafeDictionary<TValue>);
fasterValuesBuffer[valueIndex].ID = new EGID(fromEntityGid.entityID, toGroupID);
toGroupCasted.Add(fromEntityGid.entityID, ref fasterValuesBuffer[valueIndex]);
if (entityViewEnginesDB != null)


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

@@ -43,7 +43,7 @@ namespace Svelto.ECS
{
[ExclusiveGroup.StandardEntitiesGroup] = new Dictionary<Type, ITypeSafeDictionary>()
};
_groupedGroups = new Dictionary<Type, FasterDictionary<int, int>>();
//_groupedGroups = new Dictionary<Type, FasterDictionary<int, int>>();
_groupedEntityToAdd = new DoubleBufferedEntityViews<Dictionary<int, Dictionary<Type, ITypeSafeDictionary>>>();

_DB = new entitiesDB(_groupEntityDB);


+ 17
- 16
Svelto.ECS/EnginesRoot.Entities.cs View File

@@ -108,28 +108,28 @@ namespace Svelto.ECS
///--------------------------------------------
///
void MoveEntity(EGID entityGID, Dictionary<Type, ITypeSafeDictionary> toGroup = null)
void MoveEntity(EGID entityGID, int toGroupID = -1, Dictionary<Type, ITypeSafeDictionary> toGroup = null)
{
var entityViewInfoDictionary = _groupEntityDB[entityGID.groupID][_typeEntityInfoView] as TypeSafeDictionary<EntityInfoView>;
var entityBuilders = entityViewInfoDictionary[entityGID.entityID].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();

MoveEntity(entityGID, toGroup, @group, entityType);
MoveEntity(entityGID, toGroupID, toGroup, entityType);
}

MoveEntity(entityGID, toGroup, @group, _typeEntityInfoView);
MoveEntity(entityGID, toGroupID, toGroup, _typeEntityInfoView);
}

void MoveEntity(EGID entityGID, Dictionary<Type, ITypeSafeDictionary> toGroup, Dictionary<Type, ITypeSafeDictionary> @group, Type entityType)
void MoveEntity(EGID fromEntityGID, int toGroupID, Dictionary<Type, ITypeSafeDictionary> toGroup, Type entityType)
{
var fromTypeSafeDictionary = @group[entityType];
var fromGroup = _groupEntityDB[fromEntityGID.groupID];

var fromTypeSafeDictionary = fromGroup[entityType];
ITypeSafeDictionary safeDictionary = null;

if (toGroup != null)
@@ -138,17 +138,18 @@ namespace Svelto.ECS
{
safeDictionary = fromTypeSafeDictionary.Create();
toGroup.Add(entityType, safeDictionary);
//_groupedGroups[entityType] = new FasterDictionary<int, ITypeSafeDictionary>();
}
}

fromTypeSafeDictionary.MoveEntityFromDictionaryAndEngines(entityGID, safeDictionary, _entityEngines);
fromTypeSafeDictionary.MoveEntityFromDictionaryAndEngines(fromEntityGID, toGroupID, safeDictionary, _entityEngines);

if (fromTypeSafeDictionary.Count == 0) //clean up
{
@group.Remove(entityType);
fromGroup.Remove(entityType);
}
//it doesn't eliminate the group itself on purpose
//it doesn't eliminate the fromGroup itself on purpose
}

void RemoveGroupAndEntitiesFromDB(int groupID)
@@ -164,14 +165,14 @@ namespace Svelto.ECS
void SwapEntityGroup(int entityID, int fromGroupID, int toGroupID)
{
DBC.ECS.Check.Require(fromGroupID != toGroupID,
"can't move an entity to the same group where it already belongs to");
"can't move an entity to the same fromGroup where it already belongs to");

Dictionary<Type, ITypeSafeDictionary> toGroup;
if (_groupEntityDB.TryGetValue(toGroupID, out toGroup) == false)
toGroup = _groupEntityDB[toGroupID] = new Dictionary<Type, ITypeSafeDictionary>();

MoveEntity(new EGID(entityID, fromGroupID), toGroup);
MoveEntity(new EGID(entityID, fromGroupID), toGroupID, toGroup);
}
EGID SwapFirstEntityGroup(int fromGroupID, int toGroupId)
@@ -185,8 +186,8 @@ namespace Svelto.ECS
}

readonly entitiesDB _DB;
readonly Dictionary<int, Dictionary<Type, ITypeSafeDictionary>> _groupEntityDB;
readonly Dictionary<Type, FasterDictionary<int, int>> _groupedGroups; //yes I am being sarcastic
readonly DoubleBufferedEntityViews<Dictionary<int, Dictionary<Type, ITypeSafeDictionary>>> _groupedEntityToAdd;

static readonly Type _typeEntityInfoView = typeof(EntityInfoView);
}


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

@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using Svelto.DataStructures.Experimental;
using Svelto.ECS.Internal;
using Svelto.ECS.Schedulers;

@@ -63,10 +64,14 @@ namespace Svelto.ECS
{
ITypeSafeDictionary dbDic;
if (groupDB.TryGetValue(entityViewTypeSafeDictionary.Key, out dbDic) == false)
{
dbDic = groupDB[entityViewTypeSafeDictionary.Key] = entityViewTypeSafeDictionary.Value.Create();
//_groupedGroups[entityViewTypeSafeDictionary.Key] = new FasterDictionary<int, ITypeSafeDictionary>();
}

//type safe copy
dbDic.FillWithIndexedEntities(entityViewTypeSafeDictionary.Value);
// _groupedGroups[entityViewTypeSafeDictionary.Key][groupID] = dbDic;
}
}

@@ -86,7 +91,9 @@ 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 Dictionary<int, Dictionary<Type, ITypeSafeDictionary>> _groupEntityDB;
// readonly Dictionary<Type, FasterDictionary<int, ITypeSafeDictionary>> _groupedGroups; //yes I am being sarcastic
readonly EntitySubmissionScheduler _scheduler;
}
}

Loading…
Cancel
Save