@@ -141,9 +141,12 @@ namespace Svelto.ECS | |||
var entityBuildersCount = entityBuilders.Length; | |||
//for each entity view generated by the entity descriptor | |||
DBC.ECS.Check.Require(_groupEntityDB.ContainsKey(entityGID.groupID) == true, "from group not found"); | |||
var fromGroup = _groupEntityDB[entityGID.groupID]; | |||
Dictionary<Type, ITypeSafeDictionary> fromGroup; | |||
if (_groupEntityDB.TryGetValue(entityGID.groupID, out fromGroup) == false) | |||
{ | |||
throw new ECSException("from group not found eid: ".FastConcat(entityGID.entityID).FastConcat(" group: ").FastConcat(entityGID.groupID)); | |||
} | |||
ITypeSafeDictionary entityInfoViewDic; | |||
if (fromGroup.TryGetValue(_entityInfoView, out entityInfoViewDic) == true) | |||
{ | |||
@@ -167,9 +170,13 @@ namespace Svelto.ECS | |||
void MoveEntityView(EGID entityGID, int toGroupID, Dictionary<Type, ITypeSafeDictionary> toGroup, | |||
Dictionary<Type, ITypeSafeDictionary> fromGroup, Type entityType) | |||
{ | |||
DBC.ECS.Check.Require(fromGroup.ContainsKey(entityType) == true, "from group not found"); | |||
var fromTypeSafeDictionary = fromGroup[entityType]; | |||
ITypeSafeDictionary dictionaryOfEntities = null; | |||
ITypeSafeDictionary fromTypeSafeDictionary; | |||
if (fromGroup.TryGetValue(entityType, out fromTypeSafeDictionary) == false) | |||
{ | |||
throw new ECSException("no entities in from group eid: ".FastConcat(entityGID.entityID).FastConcat(" group: ").FastConcat(entityGID.groupID)); | |||
} | |||
ITypeSafeDictionary dictionaryOfEntities = null; | |||
//in case we want to move to a new group, otherwise is just a remove | |||
if (toGroup != null) | |||
@@ -187,7 +194,10 @@ namespace Svelto.ECS | |||
groupedGroup[toGroupID] = dictionaryOfEntities; | |||
} | |||
DBC.ECS.Check.Assert(fromTypeSafeDictionary.Has(entityGID.entityID), "entity not found"); | |||
if (fromTypeSafeDictionary.Has(entityGID.entityID) == false) | |||
{ | |||
throw new ECSException("entity not found eid: ".FastConcat(entityGID.entityID).FastConcat(" group: ").FastConcat(entityGID.groupID)); | |||
} | |||
fromTypeSafeDictionary.MoveEntityFromDictionaryAndEngines(entityGID, toGroupID, dictionaryOfEntities, _entityEngines); | |||
if (fromTypeSafeDictionary.Count == 0) //clean up | |||
@@ -1,4 +1,4 @@ | |||
using Svelto.ECS.Internal; | |||
using System; | |||
#if ENGINE_PROFILER_ENABLED && UNITY_EDITOR | |||
using Svelto.ECS.Profiler; | |||
@@ -73,6 +73,9 @@ namespace Svelto.ECS | |||
void QueueEntitySubmitOperation(EntitySubmitOperation entitySubmitOperation) | |||
{ | |||
#if DEBUG | |||
entitySubmitOperation.trace = Environment.StackTrace; | |||
#endif | |||
_entitiesOperations.AddRef(ref entitySubmitOperation); | |||
} | |||
} |
@@ -1,8 +1,7 @@ | |||
using System; | |||
using System.Collections; | |||
using System.Collections.Generic; | |||
using Svelto.DataStructures; | |||
using Svelto.DataStructures.Experimental; | |||
using System.Collections.Generic; | |||
using Svelto.DataStructures; | |||
using Svelto.DataStructures.Experimental; | |||
using Svelto.ECS.Internal; | |||
using Svelto.ECS.Schedulers; | |||
@@ -19,18 +18,31 @@ namespace Svelto.ECS | |||
var entitiesOperations = _entitiesOperations.ToArrayFast(); | |||
for (int i = 0; i < _entitiesOperations.Count; i++) | |||
{ | |||
switch (entitiesOperations[i].type) | |||
#if DEBUG | |||
try | |||
{ | |||
case EntitySubmitOperationType.Swap: | |||
SwapEntityGroup(entitiesOperations[i].builders, entitiesOperations[i].id, entitiesOperations[i].fromGroupID, entitiesOperations[i].toGroupID); | |||
break; | |||
case EntitySubmitOperationType.Remove: | |||
MoveEntity(entitiesOperations[i].builders, new EGID(entitiesOperations[i].id, entitiesOperations[i].fromGroupID)); | |||
break; | |||
case EntitySubmitOperationType.RemoveGroup: | |||
RemoveGroupAndEntitiesFromDB(entitiesOperations[i].fromGroupID); | |||
break; | |||
#endif | |||
switch (entitiesOperations[i].type) | |||
{ | |||
case EntitySubmitOperationType.Swap: | |||
SwapEntityGroup(entitiesOperations[i].builders, entitiesOperations[i].id, | |||
entitiesOperations[i].fromGroupID, entitiesOperations[i].toGroupID); | |||
break; | |||
case EntitySubmitOperationType.Remove: | |||
MoveEntity(entitiesOperations[i].builders, | |||
new EGID(entitiesOperations[i].id, entitiesOperations[i].fromGroupID)); | |||
break; | |||
case EntitySubmitOperationType.RemoveGroup: | |||
RemoveGroupAndEntitiesFromDB(entitiesOperations[i].fromGroupID); | |||
break; | |||
} | |||
#if DEBUG | |||
} | |||
catch (ECSException e) | |||
{ | |||
Utility.Console.LogError(e.Message.FastConcat(" ", entitiesOperations[i].trace)); | |||
} | |||
#endif | |||
} | |||
_entitiesOperations.FastClear(); | |||
@@ -1,4 +1,6 @@ | |||
namespace Svelto.ECS | |||
using System.Diagnostics; | |||
namespace Svelto.ECS | |||
{ | |||
struct EntitySubmitOperation | |||
{ | |||
@@ -7,6 +9,9 @@ | |||
public readonly int id; | |||
public readonly int toGroupID; | |||
public readonly int fromGroupID; | |||
#if DEBUG | |||
public string trace; | |||
#endif | |||
public EntitySubmitOperation(EntitySubmitOperationType operation, int entityId, int fromGroupId, int toGroupId, IEntityBuilder[] builders) | |||
{ | |||
@@ -15,6 +20,9 @@ | |||
id = entityId; | |||
toGroupID = toGroupId; | |||
fromGroupID = fromGroupId; | |||
#if DEBUG | |||
trace = string.Empty; | |||
#endif | |||
} | |||
} | |||