From fe9f5649c434f4c76460c6c2001147c080086fd7 Mon Sep 17 00:00:00 2001 From: sebas77 Date: Thu, 29 Nov 2018 16:17:37 +0000 Subject: [PATCH] Fixed some bugs related to the previous commit --- .../DataStructures/TypeSafeDictionary.cs | 7 ++-- Svelto.ECS/EGID.cs | 20 +++++++--- Svelto.ECS/EnginesRoot.Entities.cs | 7 ++-- .../EnginesRoot.GenericEntityFunctions.cs | 38 ++++--------------- Svelto.ECS/EnginesRoot.Submission.cs | 2 +- Svelto.ECS/EntityBuilder.cs | 2 +- 6 files changed, 33 insertions(+), 43 deletions(-) diff --git a/Svelto.ECS/DataStructures/TypeSafeDictionary.cs b/Svelto.ECS/DataStructures/TypeSafeDictionary.cs index 40affa4..d3ad973 100644 --- a/Svelto.ECS/DataStructures/TypeSafeDictionary.cs +++ b/Svelto.ECS/DataStructures/TypeSafeDictionary.cs @@ -82,7 +82,7 @@ namespace Svelto.ECS.Internal } void AddEntityViewToEngines(Dictionary> entityViewEnginesDB, - ref TValue entity) + ref TValue entity) { FasterList entityViewsEngines; //get all the engines linked to TValue @@ -106,10 +106,11 @@ namespace Svelto.ECS.Internal { var toGroupCasted = toGroup as TypeSafeDictionary; fasterValuesBuffer[valueIndex].ID = toEntityID; - toGroupCasted.Add(fromEntityGid.entityID, ref fasterValuesBuffer[valueIndex]); + toGroupCasted.Add(toEntityID.entityID, ref fasterValuesBuffer[valueIndex]); if (entityViewEnginesDB != null) - AddEntityViewToEngines(entityViewEnginesDB, ref toGroupCasted.GetValuesArray(out count)[toGroupCasted.GetValueIndex(fromEntityGid.entityID)]); + AddEntityViewToEngines(entityViewEnginesDB, ref toGroupCasted.GetValuesArray(out count) + [toGroupCasted.GetValueIndex(toEntityID.entityID)]); } Remove(fromEntityGid.entityID); diff --git a/Svelto.ECS/EGID.cs b/Svelto.ECS/EGID.cs index 4b30140..c65e36d 100644 --- a/Svelto.ECS/EGID.cs +++ b/Svelto.ECS/EGID.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; namespace Svelto.ECS { - public struct EGID:IEquatable,IEqualityComparer,IComparable + public struct EGID:IEquatable,IEqualityComparer,IComparable { readonly long _GID; @@ -21,6 +21,16 @@ namespace Svelto.ECS { _GID = MAKE_GLOBAL_ID(entityID, groupID); } + + public static bool operator ==(EGID obj1, EGID obj2) + { + return obj1._GID == obj2._GID; + } + + public static bool operator !=(EGID obj1, EGID obj2) + { + return obj1._GID != obj2._GID; + } public EGID(int entityID, ExclusiveGroup.ExclusiveGroupStruct groupID) : this() { @@ -42,22 +52,22 @@ namespace Svelto.ECS return id._GID; } - public bool Equals(long other) + public bool Equals(EGID other) { return _GID == other; } - public bool Equals(long x, long y) + public bool Equals(EGID x, EGID y) { return x == y; } - public int GetHashCode(long obj) + public int GetHashCode(EGID obj) { return _GID.GetHashCode(); } - public int CompareTo(long other) + public int CompareTo(EGID other) { return _GID.CompareTo(other); } diff --git a/Svelto.ECS/EnginesRoot.Entities.cs b/Svelto.ECS/EnginesRoot.Entities.cs index 413a068..ec707e4 100644 --- a/Svelto.ECS/EnginesRoot.Entities.cs +++ b/Svelto.ECS/EnginesRoot.Entities.cs @@ -129,7 +129,9 @@ namespace Svelto.ECS 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); + ITypeSafeDictionary entityInfoViewDic; + + EntityInfoView entityInfoView = default(EntityInfoView); //Check if there is an EntityInfoView linked to this entity, if so it's a DynamicEntityDescriptor! bool correctEntityDescriptorFound = true; @@ -226,8 +228,7 @@ namespace Svelto.ECS if (_groupEntityDB.TryGetValue(toEntityID.groupID, out toGroup) == false) toGroup = _groupEntityDB[toEntityID.groupID] = new Dictionary(); - MoveEntity(builders, fromEntityID, originalEntityDescriptor, - toEntityID, toGroup); + MoveEntity(builders, fromEntityID, originalEntityDescriptor, toEntityID, toGroup); } readonly Type _entityInfoView = typeof(EntityInfoView); diff --git a/Svelto.ECS/EnginesRoot.GenericEntityFunctions.cs b/Svelto.ECS/EnginesRoot.GenericEntityFunctions.cs index b5e8a35..d57074c 100644 --- a/Svelto.ECS/EnginesRoot.GenericEntityFunctions.cs +++ b/Svelto.ECS/EnginesRoot.GenericEntityFunctions.cs @@ -20,23 +20,13 @@ namespace Svelto.ECS public void RemoveEntity(int entityID, int groupID) where T : IEntityDescriptor, new() { - _weakReference.Target.CheckRemoveEntityID(new EGID(entityID, groupID), - EntityDescriptorTemplate.descriptor); - - _weakReference.Target.QueueEntitySubmitOperation( - new EntitySubmitOperation(EntitySubmitOperationType.Remove, entityID, entityID, groupID, -1, - EntityDescriptorTemplate.descriptor.entitiesToBuild, typeof(T))); + RemoveEntity(new EGID(entityID, groupID)); } public void RemoveEntity(int entityID, ExclusiveGroup.ExclusiveGroupStruct groupID) where T : IEntityDescriptor, new() { - _weakReference.Target.CheckRemoveEntityID(new EGID(entityID, (int)groupID), - EntityDescriptorTemplate.descriptor); - - _weakReference.Target.QueueEntitySubmitOperation( - new EntitySubmitOperation(EntitySubmitOperationType.Remove, entityID, entityID, groupID, -1, - EntityDescriptorTemplate.descriptor.entitiesToBuild, typeof(T))); + RemoveEntity(new EGID(entityID, groupID)); } public void RemoveEntity(EGID entityEGID) where T : IEntityDescriptor, new() @@ -57,25 +47,19 @@ namespace Svelto.ECS public void RemoveGroupAndEntities(ExclusiveGroup.ExclusiveGroupStruct groupID) { - _weakReference.Target.QueueEntitySubmitOperation( - new EntitySubmitOperation(EntitySubmitOperationType.RemoveGroup, -1, -1, groupID, -1, null, null)); + RemoveGroupAndEntities((int)groupID); } public void SwapEntityGroup(int entityID, ExclusiveGroup.ExclusiveGroupStruct fromGroupID, ExclusiveGroup.ExclusiveGroupStruct toGroupID) where T : IEntityDescriptor, new() { - _weakReference.Target.QueueEntitySubmitOperation( - new EntitySubmitOperation(EntitySubmitOperationType.Swap, entityID, entityID, fromGroupID, toGroupID, - EntityDescriptorTemplate.descriptor.entitiesToBuild, typeof(T))); + SwapEntityGroup(new EGID(entityID, fromGroupID), toGroupID); } public void SwapEntityGroup(EGID id, ExclusiveGroup.ExclusiveGroupStruct toGroupID) where T : IEntityDescriptor, new() { - _weakReference.Target.QueueEntitySubmitOperation( - new EntitySubmitOperation(EntitySubmitOperationType.Swap, - id.entityID, id.entityID, id.groupID, toGroupID, - EntityDescriptorTemplate.descriptor.entitiesToBuild, typeof(T))); + SwapEntityGroup(id, new EGID(id.entityID, toGroupID)); } public void SwapEntityGroup(EGID id, ExclusiveGroup.ExclusiveGroupStruct toGroupID @@ -83,11 +67,8 @@ namespace Svelto.ECS { if (id.groupID != mustBeFromGroup) throw new ECSException("Entity is not coming from the expected group"); - - _weakReference.Target.QueueEntitySubmitOperation( - new EntitySubmitOperation(EntitySubmitOperationType.Swap, - id.entityID, id.entityID, id.groupID, toGroupID, - EntityDescriptorTemplate.descriptor.entitiesToBuild, typeof(T))); + + SwapEntityGroup(id, toGroupID); } public void SwapEntityGroup(EGID id, EGID toID) @@ -105,10 +86,7 @@ namespace Svelto.ECS if (id.groupID != mustBeFromGroup) throw new ECSException("Entity is not coming from the expected group"); - _weakReference.Target.QueueEntitySubmitOperation( - new EntitySubmitOperation(EntitySubmitOperationType.Swap, - id.entityID, toID.entityID, id.groupID, toID.groupID, - EntityDescriptorTemplate.descriptor.entitiesToBuild, typeof(T))); + SwapEntityGroup(id, toID); } } diff --git a/Svelto.ECS/EnginesRoot.Submission.cs b/Svelto.ECS/EnginesRoot.Submission.cs index 6af2322..66f8fd9 100644 --- a/Svelto.ECS/EnginesRoot.Submission.cs +++ b/Svelto.ECS/EnginesRoot.Submission.cs @@ -70,7 +70,7 @@ namespace Svelto.ECS .FastConcat(entitiesOperations[i].toGroupID); Console.LogError(e.Message.FastConcat(" ", str, " ", entitiesOperations[i].trace)); -#if STRICT_ECS +#if !RELAXED_ECS throw; #endif #else diff --git a/Svelto.ECS/EntityBuilder.cs b/Svelto.ECS/EntityBuilder.cs index 0fb4667..4026dfd 100644 --- a/Svelto.ECS/EntityBuilder.cs +++ b/Svelto.ECS/EntityBuilder.cs @@ -74,7 +74,7 @@ namespace Svelto.ECS if (fields.Length < 1) -#if STRICT_ECS +#if !RELAXED_ECS throw new ECSException("Invalid entity view struct detected - EntityView:".FastConcat(typeof(T))); #else Svelto.Utilities.Console.LogError("Invalid entity view struct detected - EntityView:".FastConcat(typeof(T)));