@@ -1 +1 @@ | |||
Subproject commit 7c17734a5f862ceb2a4c81d41ef206785cc137d8 | |||
Subproject commit 5a7036b8d0c3a2ba7ad6046f7b284e11ae40496c |
@@ -100,7 +100,7 @@ namespace Svelto.ECS | |||
baseType = baseType.GetBaseType(); | |||
} | |||
throw new ArgumentException("Not Supported Engine " + engine.ToString()); | |||
throw new ArgumentException("Not Supported Engine " + engine); | |||
} | |||
static void AddEngine<T>(T engine, Type[] entityViewTypes, | |||
@@ -20,11 +20,27 @@ namespace Svelto.ECS | |||
{ | |||
foreach (var groups in _groupEntityDB) | |||
foreach (var entityList in groups.Value) | |||
entityList.Value.RemoveEntitiesFromEngines(_entityEngines); | |||
{ | |||
try | |||
{ | |||
entityList.Value.RemoveEntitiesFromEngines(_entityEngines); | |||
} | |||
catch (Exception e) | |||
{ | |||
Svelto.Utilities.Console.LogException(e); | |||
} | |||
} | |||
foreach (var engine in _disposableEngines) | |||
engine.Dispose(); | |||
try | |||
{ | |||
engine.Dispose(); | |||
} | |||
catch (Exception e) | |||
{ | |||
Svelto.Utilities.Console.LogException(e); | |||
} | |||
GC.SuppressFinalize(this); | |||
} | |||
@@ -109,10 +125,9 @@ namespace Svelto.ECS | |||
{ | |||
//for each entity view generated by the entity descriptor | |||
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; EntityInfoView entityInfoView = default(EntityInfoView); | |||
@@ -121,7 +136,6 @@ namespace Svelto.ECS | |||
if (fromGroup.TryGetValue(_entityInfoView, out entityInfoViewDic) == true | |||
&& (entityInfoViewDic as TypeSafeDictionary<EntityInfoView>).TryGetValue | |||
(entityGID.entityID, out entityInfoView) == true && | |||
//I really need to improve this: | |||
(correctEntityDescriptorFound = entityInfoView.type == originalDescriptorType) == true) | |||
{ | |||
var entitiesToMove = entityInfoView.entitiesToBuild; | |||
@@ -133,7 +147,7 @@ namespace Svelto.ECS | |||
else | |||
{ | |||
if (correctEntityDescriptorFound == false) | |||
Utilities.Console.LogError(INVALID_DYNAMIC_DESCRIPTOR_ERROR.FastConcat(entityGID.entityID) | |||
Utilities.Console.LogError(INVALID_DYNAMIC_DESCRIPTOR_ERROR.FastConcat(" ID ").FastConcat(entityGID.entityID) | |||
.FastConcat(" group ID ").FastConcat(entityGID.groupID).FastConcat( | |||
" descriptor found: ", entityInfoView.type.Name, " descriptor Excepted ", | |||
originalDescriptorType.Name)); | |||
@@ -172,7 +186,7 @@ namespace Svelto.ECS | |||
if (fromTypeSafeDictionary.Has(entityGID.entityID) == false) | |||
{ | |||
throw new ECSException("entity not found eid: ".FastConcat(entityGID.entityID).FastConcat(" group: ").FastConcat(entityGID.groupID)); | |||
throw new EntityNotFoundException(entityGID.entityID, entityGID.groupID, entityType); | |||
} | |||
fromTypeSafeDictionary.MoveEntityFromDictionaryAndEngines(entityGID, toGroupID, dictionaryOfEntities, _entityEngines); | |||
@@ -218,7 +232,8 @@ namespace Svelto.ECS | |||
readonly Type _entityInfoView = typeof(EntityInfoView); | |||
const string INVALID_DYNAMIC_DESCRIPTOR_ERROR = "Found an entity requesting an invalid dynamic descriptor, this " + | |||
"can happen only if you are building different entities with the " + | |||
"same ID in the same group! id: "; | |||
"same ID in the same group! The operation will continue using" + | |||
"the base descriptor only "; | |||
} | |||
public struct EntityStructInitializer | |||
@@ -66,8 +66,18 @@ namespace Svelto.ECS | |||
.FastConcat(entitiesOperations[i].toGroupID); | |||
Console.LogError(e.Message.FastConcat(" ", str, " ", entitiesOperations[i].trace)); | |||
throw; | |||
#else | |||
Console.LogException(e); | |||
var str = "Entity Operation is ".FastConcat(entitiesOperations[i].type.ToString()) | |||
.FastConcat(" id: ") | |||
.FastConcat(entitiesOperations[i].id) | |||
.FastConcat(" from groupid: ") | |||
.FastConcat(entitiesOperations[i].fromGroupID) | |||
.FastConcat(" to groupid: ") | |||
.FastConcat(entitiesOperations[i].toGroupID); | |||
Console.LogError(e.Message.FastConcat(" ", str)); | |||
#endif | |||
} | |||
} | |||
@@ -89,10 +99,12 @@ namespace Svelto.ECS | |||
//callback and database update must be interleaved. | |||
AddEntityViewsToTheDBAndSuitableEngines(_groupedEntityToAdd.other); | |||
} | |||
#if !DEBUG | |||
catch (Exception e) | |||
{ | |||
Console.LogException(e); | |||
} | |||
#endif | |||
finally | |||
{ | |||
//other can be cleared now, but let's avoid deleting the dictionary every time | |||
@@ -57,7 +57,7 @@ namespace Svelto.ECS.Internal | |||
TypeSafeDictionary<T> typeSafeDictionary; | |||
if (QueryEntitySafeDictionary(groupID, out typeSafeDictionary) == false) | |||
throw new EntitiesDBException("Entity group not found type: ".FastConcat(typeof(T)).FastConcat(" groupID: ").FastConcat(groupID)); | |||
throw new EntityGroupNotFoundException(groupID, typeof(T)); | |||
EGIDMapper<T> mapper; | |||
mapper.map = typeSafeDictionary; | |||
@@ -79,7 +79,7 @@ namespace Svelto.ECS.Internal | |||
if ((array = QueryEntitiesAndIndexInternal<T>(entityGID, out index)) != null) | |||
return array; | |||
throw new EntitiesDBException("Entity not found id: ".FastConcat(entityGID.entityID).FastConcat(" groupID: ").FastConcat(entityGID.groupID)); | |||
throw new EntityNotFoundException(entityGID.entityID, entityGID.groupID, typeof(T)); | |||
} | |||
public bool TryQueryEntitiesAndIndex<T>(EGID entityGid, out uint index, out T[] array) where T : IEntityStruct | |||
@@ -105,7 +105,7 @@ namespace Svelto.ECS.Internal | |||
T entityView; | |||
if (TryQueryEntityViewInGroupInternal(entityGID, out entityView) == false) | |||
throw new EntitiesDBException("Entity not found id: ".FastConcat(entityGID.entityID).FastConcat(" groupID: ").FastConcat(entityGID.groupID)); | |||
throw new EntityNotFoundException(entityGID.entityID, entityGID.groupID, typeof(T)); | |||
return entityView; | |||
} | |||
@@ -193,7 +193,7 @@ namespace Svelto.ECS.Internal | |||
static void SafetyChecks<T>(TypeSafeDictionary<T> typeSafeDictionary, int count) where T : IEntityStruct | |||
{ | |||
if (typeSafeDictionary.Count != count) | |||
throw new EntitiesDBException("Entities cannot be swapped or removed during an iteration"); | |||
throw new ECSException("Entities cannot be swapped or removed during an iteration"); | |||
} | |||
static ReadOnlyCollectionStruct<T> RetrieveEmptyEntityViewList<T>() | |||
@@ -1,10 +0,0 @@ | |||
using System; | |||
namespace Svelto.ECS | |||
{ | |||
public class EntitiesDBException : Exception | |||
{ | |||
public EntitiesDBException(string message):base(message) | |||
{} | |||
} | |||
} |
@@ -28,8 +28,13 @@ namespace Svelto.ECS | |||
#endif | |||
static void CheckFields(Type type) | |||
{ | |||
if (needsReflection == false && ENTITY_VIEW_TYPE != typeof(EntityInfoView)) | |||
if (ENTITY_VIEW_TYPE == typeof(EntityInfoView)) return; | |||
if (needsReflection == false ) | |||
{ | |||
if (type.IsClass) | |||
throw new ECSException("IEntityStructs must be structs"); | |||
var fields = type.GetFields(BindingFlags.Public | | |||
BindingFlags.Instance); | |||
@@ -62,6 +67,14 @@ namespace Svelto.ECS | |||
} | |||
} | |||
} | |||
else | |||
{ | |||
var fields = type.GetFields(BindingFlags.Public | | |||
BindingFlags.Instance); | |||
if (fields.Length < 1) | |||
throw new ECSException("Invalid entity view struct detected"); | |||
} | |||
} | |||
static void SubCheckFields(Type fieldFieldType) | |||
@@ -0,0 +1,12 @@ | |||
using System; | |||
namespace Svelto.ECS.Internal | |||
{ | |||
class EntityGroupNotFoundException : Exception | |||
{ | |||
public EntityGroupNotFoundException(int groupId, Type type) | |||
: base("entity group not found ".FastConcat(type.ToString())) | |||
{ | |||
} | |||
} | |||
} |
@@ -0,0 +1,11 @@ | |||
using System; | |||
namespace Svelto.ECS | |||
{ | |||
public class EntityNotFoundException : Exception | |||
{ | |||
public EntityNotFoundException(int entityGidEntityId, int entityGidGroupId, Type type) | |||
: base("entity not found ".FastConcat(type.ToString())) | |||
{} | |||
} | |||
} |
@@ -19,9 +19,7 @@ namespace Svelto.ECS.Internal | |||
return; | |||
} | |||
throw new EntitiesDBException("Entity not found id: " | |||
.FastConcat(entityGID.entityID).FastConcat(" groupID: ") | |||
.FastConcat(entityGID.groupID)); | |||
throw new EntityNotFoundException(entityGID.entityID, entityGID.groupID, typeof(T)); | |||
} | |||
public void ExecuteOnEntity<T>(EGID entityGID, EntityAction<T> action) where T : IEntityStruct | |||
@@ -34,9 +32,7 @@ namespace Svelto.ECS.Internal | |||
return; | |||
} | |||
throw new EntitiesDBException("Entity not found id: " | |||
.FastConcat(entityGID.entityID).FastConcat(" groupID: ") | |||
.FastConcat(entityGID.groupID)); | |||
throw new EntityNotFoundException(entityGID.entityID, entityGID.groupID, typeof(T)); | |||
} | |||
public void ExecuteOnEntity<T>(int id, int groupid, EntityAction<T> action) where T : IEntityStruct | |||