@@ -82,7 +82,7 @@ namespace Svelto.ECS.Internal | |||
} | |||
void AddEntityViewToEngines(Dictionary<Type, FasterList<IHandleEntityViewEngineAbstracted>> entityViewEnginesDB, | |||
ref TValue entity) | |||
ref TValue entity) | |||
{ | |||
FasterList<IHandleEntityViewEngineAbstracted> entityViewsEngines; | |||
//get all the engines linked to TValue | |||
@@ -106,10 +106,11 @@ namespace Svelto.ECS.Internal | |||
{ | |||
var toGroupCasted = toGroup as TypeSafeDictionary<TValue>; | |||
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); | |||
@@ -3,7 +3,7 @@ using System.Collections.Generic; | |||
namespace Svelto.ECS | |||
{ | |||
public struct EGID:IEquatable<long>,IEqualityComparer<long>,IComparable<long> | |||
public struct EGID:IEquatable<EGID>,IEqualityComparer<EGID>,IComparable<EGID> | |||
{ | |||
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); | |||
} | |||
@@ -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<Type, ITypeSafeDictionary>(); | |||
MoveEntity(builders, fromEntityID, originalEntityDescriptor, | |||
toEntityID, toGroup); | |||
MoveEntity(builders, fromEntityID, originalEntityDescriptor, toEntityID, toGroup); | |||
} | |||
readonly Type _entityInfoView = typeof(EntityInfoView); | |||
@@ -20,23 +20,13 @@ namespace Svelto.ECS | |||
public void RemoveEntity<T>(int entityID, int groupID) where T : IEntityDescriptor, new() | |||
{ | |||
_weakReference.Target.CheckRemoveEntityID(new EGID(entityID, groupID), | |||
EntityDescriptorTemplate<T>.descriptor); | |||
_weakReference.Target.QueueEntitySubmitOperation<T>( | |||
new EntitySubmitOperation(EntitySubmitOperationType.Remove, entityID, entityID, groupID, -1, | |||
EntityDescriptorTemplate<T>.descriptor.entitiesToBuild, typeof(T))); | |||
RemoveEntity<T>(new EGID(entityID, groupID)); | |||
} | |||
public void RemoveEntity<T>(int entityID, ExclusiveGroup.ExclusiveGroupStruct groupID) where T : | |||
IEntityDescriptor, new() | |||
{ | |||
_weakReference.Target.CheckRemoveEntityID(new EGID(entityID, (int)groupID), | |||
EntityDescriptorTemplate<T>.descriptor); | |||
_weakReference.Target.QueueEntitySubmitOperation<T>( | |||
new EntitySubmitOperation(EntitySubmitOperationType.Remove, entityID, entityID, groupID, -1, | |||
EntityDescriptorTemplate<T>.descriptor.entitiesToBuild, typeof(T))); | |||
RemoveEntity<T>(new EGID(entityID, groupID)); | |||
} | |||
public void RemoveEntity<T>(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<T>(int entityID, ExclusiveGroup.ExclusiveGroupStruct fromGroupID, | |||
ExclusiveGroup.ExclusiveGroupStruct toGroupID) where T : IEntityDescriptor, new() | |||
{ | |||
_weakReference.Target.QueueEntitySubmitOperation<T>( | |||
new EntitySubmitOperation(EntitySubmitOperationType.Swap, entityID, entityID, fromGroupID, toGroupID, | |||
EntityDescriptorTemplate<T>.descriptor.entitiesToBuild, typeof(T))); | |||
SwapEntityGroup<T>(new EGID(entityID, fromGroupID), toGroupID); | |||
} | |||
public void SwapEntityGroup<T>(EGID id, ExclusiveGroup.ExclusiveGroupStruct toGroupID) | |||
where T : IEntityDescriptor, new() | |||
{ | |||
_weakReference.Target.QueueEntitySubmitOperation<T>( | |||
new EntitySubmitOperation(EntitySubmitOperationType.Swap, | |||
id.entityID, id.entityID, id.groupID, toGroupID, | |||
EntityDescriptorTemplate<T>.descriptor.entitiesToBuild, typeof(T))); | |||
SwapEntityGroup<T>(id, new EGID(id.entityID, toGroupID)); | |||
} | |||
public void SwapEntityGroup<T>(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<T>( | |||
new EntitySubmitOperation(EntitySubmitOperationType.Swap, | |||
id.entityID, id.entityID, id.groupID, toGroupID, | |||
EntityDescriptorTemplate<T>.descriptor.entitiesToBuild, typeof(T))); | |||
SwapEntityGroup<T>(id, toGroupID); | |||
} | |||
public void SwapEntityGroup<T>(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<T>( | |||
new EntitySubmitOperation(EntitySubmitOperationType.Swap, | |||
id.entityID, toID.entityID, id.groupID, toID.groupID, | |||
EntityDescriptorTemplate<T>.descriptor.entitiesToBuild, typeof(T))); | |||
SwapEntityGroup<T>(id, toID); | |||
} | |||
} | |||
@@ -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 | |||
@@ -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))); | |||