Browse Source

Fixed some bugs related to the previous commit

tags/2.7
sebas77 6 years ago
parent
commit
fe9f5649c4
6 changed files with 33 additions and 43 deletions
  1. +4
    -3
      Svelto.ECS/DataStructures/TypeSafeDictionary.cs
  2. +15
    -5
      Svelto.ECS/EGID.cs
  3. +4
    -3
      Svelto.ECS/EnginesRoot.Entities.cs
  4. +8
    -30
      Svelto.ECS/EnginesRoot.GenericEntityFunctions.cs
  5. +1
    -1
      Svelto.ECS/EnginesRoot.Submission.cs
  6. +1
    -1
      Svelto.ECS/EntityBuilder.cs

+ 4
- 3
Svelto.ECS/DataStructures/TypeSafeDictionary.cs View File

@@ -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);


+ 15
- 5
Svelto.ECS/EGID.cs View File

@@ -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);
}


+ 4
- 3
Svelto.ECS/EnginesRoot.Entities.cs View File

@@ -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);


+ 8
- 30
Svelto.ECS/EnginesRoot.GenericEntityFunctions.cs View File

@@ -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);
}
}


+ 1
- 1
Svelto.ECS/EnginesRoot.Submission.cs View File

@@ -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


+ 1
- 1
Svelto.ECS/EntityBuilder.cs View File

@@ -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)));


Loading…
Cancel
Save