diff --git a/Svelto.ECS/DataStructures/TypeSafeDictionary.cs b/Svelto.ECS/DataStructures/TypeSafeDictionary.cs index 0015195..9149c71 100644 --- a/Svelto.ECS/DataStructures/TypeSafeDictionary.cs +++ b/Svelto.ECS/DataStructures/TypeSafeDictionary.cs @@ -20,7 +20,7 @@ namespace Svelto.ECS.Internal void RemoveEntitiesFromEngines(Dictionary> entityViewEnginesDB); - void MoveEntityFromDictionaryAndEngines(EGID fromEntityGid, + void MoveEntityFromDictionaryAndEngines(EGID fromEntityGid, int toGroupID, ITypeSafeDictionary toGroup, Dictionary> entityViewEnginesDB); @@ -84,7 +84,7 @@ namespace Svelto.ECS.Internal (entityViewsEngines[i] as IHandleEntityStructEngine).AddInternal(ref entity); } - public void MoveEntityFromDictionaryAndEngines(EGID fromEntityGid, ITypeSafeDictionary toGroup, + public void MoveEntityFromDictionaryAndEngines(EGID fromEntityGid, int toGroupID, ITypeSafeDictionary toGroup, Dictionary> entityViewEnginesDB) { @@ -97,6 +97,7 @@ namespace Svelto.ECS.Internal if (toGroup != null) { var toGroupCasted = (toGroup as TypeSafeDictionary); + fasterValuesBuffer[valueIndex].ID = new EGID(fromEntityGid.entityID, toGroupID); toGroupCasted.Add(fromEntityGid.entityID, ref fasterValuesBuffer[valueIndex]); if (entityViewEnginesDB != null) diff --git a/Svelto.ECS/EnginesRoot.Engines.cs b/Svelto.ECS/EnginesRoot.Engines.cs index b7f666a..e2b9f4a 100644 --- a/Svelto.ECS/EnginesRoot.Engines.cs +++ b/Svelto.ECS/EnginesRoot.Engines.cs @@ -43,7 +43,7 @@ namespace Svelto.ECS { [ExclusiveGroup.StandardEntitiesGroup] = new Dictionary() }; - _groupedGroups = new Dictionary>(); + //_groupedGroups = new Dictionary>(); _groupedEntityToAdd = new DoubleBufferedEntityViews>>(); _DB = new entitiesDB(_groupEntityDB); diff --git a/Svelto.ECS/EnginesRoot.Entities.cs b/Svelto.ECS/EnginesRoot.Entities.cs index be9d6e1..05122d2 100644 --- a/Svelto.ECS/EnginesRoot.Entities.cs +++ b/Svelto.ECS/EnginesRoot.Entities.cs @@ -108,28 +108,28 @@ namespace Svelto.ECS ///-------------------------------------------- /// - void MoveEntity(EGID entityGID, Dictionary toGroup = null) + void MoveEntity(EGID entityGID, int toGroupID = -1, Dictionary toGroup = null) { var entityViewInfoDictionary = _groupEntityDB[entityGID.groupID][_typeEntityInfoView] as TypeSafeDictionary; 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 toGroup, Dictionary @group, Type entityType) + void MoveEntity(EGID fromEntityGID, int toGroupID, Dictionary 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(); } } - 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 toGroup; - + if (_groupEntityDB.TryGetValue(toGroupID, out toGroup) == false) toGroup = _groupEntityDB[toGroupID] = new Dictionary(); - 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> _groupEntityDB; - readonly Dictionary> _groupedGroups; //yes I am being sarcastic + readonly DoubleBufferedEntityViews>> _groupedEntityToAdd; + static readonly Type _typeEntityInfoView = typeof(EntityInfoView); } diff --git a/Svelto.ECS/EnginesRoot.Submission.cs b/Svelto.ECS/EnginesRoot.Submission.cs index f0c510f..52f7572 100644 --- a/Svelto.ECS/EnginesRoot.Submission.cs +++ b/Svelto.ECS/EnginesRoot.Submission.cs @@ -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(); + } //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>> _groupedEntityToAdd; + + readonly Dictionary> _groupEntityDB; +// readonly Dictionary> _groupedGroups; //yes I am being sarcastic readonly EntitySubmissionScheduler _scheduler; } } \ No newline at end of file