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