diff --git a/Svelto.Common b/Svelto.Common index 7c17734..5a7036b 160000 --- a/Svelto.Common +++ b/Svelto.Common @@ -1 +1 @@ -Subproject commit 7c17734a5f862ceb2a4c81d41ef206785cc137d8 +Subproject commit 5a7036b8d0c3a2ba7ad6046f7b284e11ae40496c diff --git a/Svelto.ECS/EnginesRoot.Engines.cs b/Svelto.ECS/EnginesRoot.Engines.cs index 144d96c..e455f6a 100644 --- a/Svelto.ECS/EnginesRoot.Engines.cs +++ b/Svelto.ECS/EnginesRoot.Engines.cs @@ -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 engine, Type[] entityViewTypes, diff --git a/Svelto.ECS/EnginesRoot.Entities.cs b/Svelto.ECS/EnginesRoot.Entities.cs index e82e69d..2001195 100644 --- a/Svelto.ECS/EnginesRoot.Entities.cs +++ b/Svelto.ECS/EnginesRoot.Entities.cs @@ -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 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).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 diff --git a/Svelto.ECS/EnginesRoot.Submission.cs b/Svelto.ECS/EnginesRoot.Submission.cs index 787dba2..4132504 100644 --- a/Svelto.ECS/EnginesRoot.Submission.cs +++ b/Svelto.ECS/EnginesRoot.Submission.cs @@ -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 diff --git a/Svelto.ECS/EntitiesDB.cs b/Svelto.ECS/EntitiesDB.cs index bb7bde8..983f3f9 100644 --- a/Svelto.ECS/EntitiesDB.cs +++ b/Svelto.ECS/EntitiesDB.cs @@ -57,7 +57,7 @@ namespace Svelto.ECS.Internal TypeSafeDictionary 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 mapper; mapper.map = typeSafeDictionary; @@ -79,7 +79,7 @@ namespace Svelto.ECS.Internal if ((array = QueryEntitiesAndIndexInternal(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(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(TypeSafeDictionary 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 RetrieveEmptyEntityViewList() diff --git a/Svelto.ECS/EntitiesDBException.cs b/Svelto.ECS/EntitiesDBException.cs deleted file mode 100644 index f75a8cf..0000000 --- a/Svelto.ECS/EntitiesDBException.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System; - -namespace Svelto.ECS -{ - public class EntitiesDBException : Exception - { - public EntitiesDBException(string message):base(message) - {} - } -} \ No newline at end of file diff --git a/Svelto.ECS/EntityBuilder.cs b/Svelto.ECS/EntityBuilder.cs index dc7a068..eb0dea4 100644 --- a/Svelto.ECS/EntityBuilder.cs +++ b/Svelto.ECS/EntityBuilder.cs @@ -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) diff --git a/Svelto.ECS/EntityGroupNotFoundException.cs b/Svelto.ECS/EntityGroupNotFoundException.cs new file mode 100644 index 0000000..8db2ecd --- /dev/null +++ b/Svelto.ECS/EntityGroupNotFoundException.cs @@ -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())) + { + } + } +} \ No newline at end of file diff --git a/Svelto.ECS/EntityNotFoundException.cs b/Svelto.ECS/EntityNotFoundException.cs new file mode 100644 index 0000000..a1d27ca --- /dev/null +++ b/Svelto.ECS/EntityNotFoundException.cs @@ -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())) + {} + } +} \ No newline at end of file diff --git a/Svelto.ECS/ExecuteOnEntitiesDB.cs b/Svelto.ECS/ExecuteOnEntitiesDB.cs index 829deb3..b3545f6 100644 --- a/Svelto.ECS/ExecuteOnEntitiesDB.cs +++ b/Svelto.ECS/ExecuteOnEntitiesDB.cs @@ -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(EGID entityGID, EntityAction 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(int id, int groupid, EntityAction action) where T : IEntityStruct