Browse Source

introduced deffered actions for Remove and Swap entity, they now happen during the submission and not right away. This imply a radical change of the current application made with Svelto

tags/2.7
sebas77 6 years ago
parent
commit
124c4d0e80
12 changed files with 140 additions and 87 deletions
  1. +12
    -19
      Svelto.ECS/DataStructures/TypeSafeDictionary.cs
  2. +1
    -1
      Svelto.ECS/EGIDMapper.cs
  3. +2
    -1
      Svelto.ECS/EnginesRoot.DoubleBufferedEntityViews.cs
  4. +3
    -2
      Svelto.ECS/EnginesRoot.Engines.cs
  5. +8
    -16
      Svelto.ECS/EnginesRoot.Entities.cs
  6. +33
    -18
      Svelto.ECS/EnginesRoot.GenericEntityFunctions.cs
  7. +30
    -5
      Svelto.ECS/EnginesRoot.Submission.cs
  8. +13
    -8
      Svelto.ECS/EntitiesDB.cs
  9. +4
    -5
      Svelto.ECS/EntityFactory.cs
  10. +22
    -0
      Svelto.ECS/EntitySubmitOperation.cs
  11. +6
    -6
      Svelto.ECS/ExecuteOnEntitiesDB.cs
  12. +6
    -6
      Svelto.ECS/IEntityFunctions.cs

+ 12
- 19
Svelto.ECS/DataStructures/TypeSafeDictionary.cs View File

@@ -2,17 +2,9 @@
using System.Collections.Generic;
using Svelto.DataStructures;
using Svelto.DataStructures.Experimental;
using Svelto.Utilities;

namespace Svelto.ECS.Internal
{
/// <summary>
/// This is just a place holder at the moment
/// I always wanted to create my own Dictionary
/// data structure as excercise, but never had the
/// time to. At the moment I need the custom interface
/// wrapped though.
/// </summary>
public interface ITypeSafeDictionary
{
ITypeSafeDictionary Create();
@@ -20,12 +12,11 @@ namespace Svelto.ECS.Internal
void RemoveEntitiesFromEngines(Dictionary<Type, FasterList<IHandleEntityViewEngineAbstracted>>
entityViewEnginesDB);

void MoveEntityFromDictionaryAndEngines(EGID fromEntityGid, int toGroupID,
ITypeSafeDictionary toGroup,
void MoveEntityFromDictionaryAndEngines(EGID fromEntityGid, int toGroupID, ITypeSafeDictionary toGroup,
Dictionary<Type, FasterList<IHandleEntityViewEngineAbstracted>>
entityViewEnginesDB);
void FillWithIndexedEntities(ITypeSafeDictionary entities);
void FillWithIndexedEntities(ITypeSafeDictionary entities);
void AddEntitiesToEngines(Dictionary<Type, FasterList<IHandleEntityViewEngineAbstracted>> entityViewEnginesDB);
void AddCapacity(int size);
@@ -48,7 +39,7 @@ namespace Svelto.ECS.Internal
public void FillWithIndexedEntities(ITypeSafeDictionary entities)
{
int count;
var buffer = (entities as TypeSafeDictionary<TValue>).GetFasterValuesBuffer(out count);
var buffer = (entities as TypeSafeDictionary<TValue>).GetValuesArray(out count);

try
{
@@ -63,10 +54,11 @@ namespace Svelto.ECS.Internal
}
}

public void AddEntitiesToEngines(Dictionary<Type, FasterList<IHandleEntityViewEngineAbstracted>> entityViewEnginesDB)
public void AddEntitiesToEngines(
Dictionary<Type, FasterList<IHandleEntityViewEngineAbstracted>> entityViewEnginesDB)
{
int count;
TValue[] values = GetFasterValuesBuffer(out count);
TValue[] values = GetValuesArray(out count);

for (int i = 0; i < count; i++)
{
@@ -83,10 +75,11 @@ namespace Svelto.ECS.Internal

public int GetFirstID()
{
return FasterValues[0].ID.entityID;
return Values[0].ID.entityID;
}

void AddEntityViewToEngines(Dictionary<Type, FasterList<IHandleEntityViewEngineAbstracted>> entityViewEnginesDB, ref TValue entity)
void AddEntityViewToEngines(Dictionary<Type, FasterList<IHandleEntityViewEngineAbstracted>> entityViewEnginesDB,
ref TValue entity)
{
FasterList<IHandleEntityViewEngineAbstracted> entityViewsEngines;
//get all the engines linked to TValue
@@ -100,7 +93,7 @@ namespace Svelto.ECS.Internal
entityViewEnginesDB)
{
int count;
var fasterValuesBuffer = GetFasterValuesBuffer(out count);
var fasterValuesBuffer = GetValuesArray(out count);
var valueIndex = GetValueIndex(fromEntityGid.entityID);

if (entityViewEnginesDB != null)
@@ -113,7 +106,7 @@ namespace Svelto.ECS.Internal
toGroupCasted.Add(fromEntityGid.entityID, ref fasterValuesBuffer[valueIndex]);
if (entityViewEnginesDB != null)
AddEntityViewToEngines(entityViewEnginesDB, ref toGroupCasted.GetFasterValuesBuffer(out count)[toGroupCasted.GetValueIndex(fromEntityGid.entityID)]);
AddEntityViewToEngines(entityViewEnginesDB, ref toGroupCasted.GetValuesArray(out count)[toGroupCasted.GetValueIndex(fromEntityGid.entityID)]);
}

Remove(fromEntityGid.entityID);
@@ -131,7 +124,7 @@ namespace Svelto.ECS.Internal
public void RemoveEntitiesFromEngines(Dictionary<Type, FasterList<IHandleEntityViewEngineAbstracted>> entityViewEnginesDB)
{
int count;
TValue[] values = GetFasterValuesBuffer(out count);
TValue[] values = GetValuesArray(out count);

for (int i = 0; i < count; i++)
{


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

@@ -10,7 +10,7 @@ namespace Svelto.ECS
{
int count;
index = map.FindElementIndex(id.entityID);
return map.GetFasterValuesBuffer(out count);
return map.GetValuesArray(out count);
}
}
}

+ 2
- 1
Svelto.ECS/EnginesRoot.DoubleBufferedEntityViews.cs View File

@@ -1,6 +1,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using Svelto.DataStructures.Experimental;
using Svelto.ECS.Internal;

#if ENGINE_PROFILER_ENABLED && UNITY_EDITOR
@@ -11,7 +12,7 @@ namespace Svelto.ECS
{
public partial class EnginesRoot
{
class DoubleBufferedEntitiesToAdd<T> where T : Dictionary<int, Dictionary<Type, ITypeSafeDictionary>>, new()
class DoubleBufferedEntitiesToAdd<T> where T : FasterDictionary<int, Dictionary<Type, ITypeSafeDictionary>>, new()
{
readonly T _entityViewsToAddBufferA = new T();
readonly T _entityViewsToAddBufferB = new T();


+ 3
- 2
Svelto.ECS/EnginesRoot.Engines.cs View File

@@ -36,12 +36,13 @@ namespace Svelto.ECS
/// </summary>
public EnginesRoot(EntitySubmissionScheduler entityViewScheduler)
{
_entitiesOperations = new FasterList<EntitySubmitOperation>();
_entityEngines = new Dictionary<Type, FasterList<IHandleEntityViewEngineAbstracted>>();
_otherEngines = new FasterList<IEngine>();

_groupEntityDB = new Dictionary<int, Dictionary<Type, ITypeSafeDictionary>>();
_groupEntityDB = new FasterDictionary<int, Dictionary<Type, ITypeSafeDictionary>>();
_groupedGroups = new Dictionary<Type, FasterDictionary<int, ITypeSafeDictionary>>();
_groupedEntityToAdd = new DoubleBufferedEntitiesToAdd<Dictionary<int, Dictionary<Type, ITypeSafeDictionary>>>();
_groupedEntityToAdd = new DoubleBufferedEntitiesToAdd<FasterDictionary<int, Dictionary<Type, ITypeSafeDictionary>>>();

_DB = new EntitiesDB(_groupEntityDB, _groupedGroups);



+ 8
- 16
Svelto.ECS/EnginesRoot.Entities.cs View File

@@ -132,9 +132,8 @@ namespace Svelto.ECS
///--------------------------------------------
///
void MoveEntity<T>(EGID entityGID, int toGroupID = -1, Dictionary<Type, ITypeSafeDictionary> toGroup = null) where T:IEntityDescriptor, new ()
void MoveEntity(IEntityBuilder[] entityBuilders, EGID entityGID, int toGroupID = -1, Dictionary<Type, ITypeSafeDictionary> toGroup = null)
{
var entityBuilders = EntityDescriptorTemplate<T>.descriptor.entitiesToBuild;
var entityBuildersCount = entityBuilders.Length;
//for each entity view generated by the entity descriptor
@@ -189,33 +188,26 @@ namespace Svelto.ECS

///--------------------------------------------

EGID SwapEntityGroup<T>(int entityID, int fromGroupID, int toGroupID) where T:IEntityDescriptor, new ()
void SwapEntityGroup(IEntityBuilder[] builders, int entityID, int fromGroupID, int toGroupID)
{
DBC.ECS.Check.Require(fromGroupID != toGroupID,
"the entity is already in this group");
DBC.ECS.Check.Require(fromGroupID != toGroupID, "the entity is already in this group");

Dictionary<Type, ITypeSafeDictionary> toGroup;

if (_groupEntityDB.TryGetValue(toGroupID, out toGroup) == false)
toGroup = _groupEntityDB[toGroupID] = new Dictionary<Type, ITypeSafeDictionary>();

MoveEntity<T>(new EGID(entityID, fromGroupID), toGroupID, toGroup);
return new EGID(entityID, toGroupID);
MoveEntity(builders, new EGID(entityID, fromGroupID), toGroupID, toGroup);
}
EGID SwapFirstEntityInGroup<T>(int fromGroupID, int toGroupId) where T:IEntityDescriptor, new()
void SwapFirstEntityInGroup(IEntityBuilder[] builders, int fromGroupID, int toGroupId)
{
var firstID = _groupEntityDB[fromGroupID][EntityDescriptorTemplate<T>.descriptor.entitiesToBuild[0]
.GetEntityType()].GetFirstID();
SwapEntityGroup<T>(firstID, fromGroupID, toGroupId);
var firstID = _groupEntityDB[fromGroupID][builders[0].GetEntityType()].GetFirstID();
return new EGID(firstID, toGroupId);
SwapEntityGroup(builders, firstID, fromGroupID, toGroupId);
}

readonly EntitiesDB _DB;
int _newEntitiesBuiltToProcess;
}

@@ -234,7 +226,7 @@ namespace Svelto.ECS
initializer.ID = _id;

int count;
typeSafeDictionary.GetFasterValuesBuffer(out count)[typeSafeDictionary.FindElementIndex(_id.entityID)] = initializer;
typeSafeDictionary.GetValuesArray(out count)[typeSafeDictionary.FindElementIndex(_id.entityID)] = initializer;
}

readonly Dictionary<Type, ITypeSafeDictionary> _current;


+ 33
- 18
Svelto.ECS/EnginesRoot.GenericEntityFunctions.cs View File

@@ -19,58 +19,73 @@ namespace Svelto.ECS

public void RemoveEntity<T>(int entityID, int groupID) where T : IEntityDescriptor, new()
{
_weakReference.Target.MoveEntity<T>(new EGID(entityID, groupID));
_weakReference.Target.QueueEntitySubmitOperation(new EntitySubmitOperation(EntitySubmitOperationType.Remove, entityID, groupID, -1, EntityDescriptorTemplate<T>.descriptor.entitiesToBuild));
}

public void RemoveEntity<T>(int entityID, ExclusiveGroup groupID) where T : IEntityDescriptor, new()
{
_weakReference.Target.MoveEntity<T>(new EGID(entityID, (int) groupID));
_weakReference.Target.QueueEntitySubmitOperation(
new EntitySubmitOperation(EntitySubmitOperationType.Remove, entityID, (int)groupID, -1, EntityDescriptorTemplate<T>.descriptor.entitiesToBuild));
}

public void RemoveEntity<T>(EGID entityEGID) where T : IEntityDescriptor, new()
{
_weakReference.Target.MoveEntity<T>(entityEGID);
_weakReference.Target.QueueEntitySubmitOperation(
new EntitySubmitOperation(EntitySubmitOperationType.Remove, entityEGID.entityID, entityEGID.groupID, -1, EntityDescriptorTemplate<T>.descriptor.entitiesToBuild));
}

public void RemoveGroupAndEntities(int groupID)
{
_weakReference.Target.RemoveGroupAndEntitiesFromDB(groupID);
_weakReference.Target.QueueEntitySubmitOperation(
new EntitySubmitOperation(EntitySubmitOperationType.RemoveGroup, -1, groupID, -1, null));
}

public void RemoveGroupAndEntities(ExclusiveGroup groupID)
{
_weakReference.Target.RemoveGroupAndEntitiesFromDB((int) groupID);
_weakReference.Target.QueueEntitySubmitOperation(
new EntitySubmitOperation(EntitySubmitOperationType.RemoveGroup, -1, (int)groupID, -1, null));
}

public EGID SwapEntityGroup<T>(int entityID, int fromGroupID, int toGroupID) where T : IEntityDescriptor, new()
public void SwapEntityGroup<T>(int entityID, int fromGroupID, int toGroupID) where T : IEntityDescriptor, new()
{
return _weakReference.Target.SwapEntityGroup<T>(entityID, fromGroupID, toGroupID);
_weakReference.Target.QueueEntitySubmitOperation(
new EntitySubmitOperation(EntitySubmitOperationType.Swap, entityID, fromGroupID, toGroupID, EntityDescriptorTemplate<T>.descriptor.entitiesToBuild));
}

public EGID SwapEntityGroup<T>(int entityID, ExclusiveGroup fromGroupID, ExclusiveGroup toGroupID) where T : IEntityDescriptor, new()
public void SwapEntityGroup<T>(int entityID, ExclusiveGroup fromGroupID, ExclusiveGroup toGroupID) where T : IEntityDescriptor, new()
{
return _weakReference.Target.SwapEntityGroup<T>(entityID, (int) fromGroupID, (int) toGroupID);
_weakReference.Target.QueueEntitySubmitOperation(
new EntitySubmitOperation(EntitySubmitOperationType.Swap, entityID, (int) fromGroupID, (int) toGroupID, EntityDescriptorTemplate<T>.descriptor.entitiesToBuild));
}

public EGID SwapEntityGroup<T>(EGID id, int toGroupID) where T : IEntityDescriptor, new()
public void SwapEntityGroup<T>(EGID id, int toGroupID) where T : IEntityDescriptor, new()
{
return _weakReference.Target.SwapEntityGroup<T>(id.entityID, id.groupID, toGroupID);
_weakReference.Target.QueueEntitySubmitOperation(
new EntitySubmitOperation(EntitySubmitOperationType.Swap, id.entityID, id.groupID, toGroupID, EntityDescriptorTemplate<T>.descriptor.entitiesToBuild));
}

public EGID SwapEntityGroup<T>(EGID id, ExclusiveGroup toGroupID) where T : IEntityDescriptor, new()
public void SwapEntityGroup<T>(EGID id, ExclusiveGroup toGroupID) where T : IEntityDescriptor, new()
{
return _weakReference.Target.SwapEntityGroup<T>(id.entityID, id.groupID, (int) toGroupID);
_weakReference.Target.QueueEntitySubmitOperation(
new EntitySubmitOperation(EntitySubmitOperationType.Swap, id.entityID, id.groupID, (int)toGroupID, EntityDescriptorTemplate<T>.descriptor.entitiesToBuild));
}
public EGID SwapFirstEntityGroup<T>(int fromGroupID, int toGroupID) where T : IEntityDescriptor, new()
public void SwapFirstEntityGroup<T>(int fromGroupID, int toGroupID) where T : IEntityDescriptor, new()
{
return _weakReference.Target.SwapFirstEntityInGroup<T>( fromGroupID, toGroupID);
_weakReference.Target.QueueEntitySubmitOperation(
new EntitySubmitOperation(EntitySubmitOperationType.FirstSwap, -1, fromGroupID, toGroupID, EntityDescriptorTemplate<T>.descriptor.entitiesToBuild));
}

public EGID SwapFirstEntityGroup<T>(ExclusiveGroup fromGroupID, ExclusiveGroup toGroupID) where T : IEntityDescriptor, new()
public void SwapFirstEntityGroup<T>(ExclusiveGroup fromGroupID, ExclusiveGroup toGroupID) where T : IEntityDescriptor, new()
{
return _weakReference.Target.SwapFirstEntityInGroup<T>( (int) fromGroupID, (int) toGroupID);
_weakReference.Target.QueueEntitySubmitOperation(
new EntitySubmitOperation(EntitySubmitOperationType.FirstSwap, -1, (int)fromGroupID, (int)toGroupID, EntityDescriptorTemplate<T>.descriptor.entitiesToBuild));
}
}

void QueueEntitySubmitOperation(EntitySubmitOperation entitySubmitOperation)
{
_entitiesOperations.AddRef(ref entitySubmitOperation);
}
}
}

+ 30
- 5
Svelto.ECS/EnginesRoot.Submission.cs View File

@@ -1,6 +1,8 @@
using System;
using System.Collections.Generic;
using Svelto.DataStructures.Experimental;
using System.Collections;
using System.Collections.Generic;
using Svelto.DataStructures;
using Svelto.DataStructures.Experimental;
using Svelto.ECS.Internal;
using Svelto.ECS.Schedulers;

@@ -14,6 +16,28 @@ namespace Svelto.ECS
{
void SubmitEntityViews()
{
var entitiesOperations = _entitiesOperations.ToArrayFast();
for (int i = 0; i < _entitiesOperations.Count; i++)
{
switch (entitiesOperations[i].type)
{
case EntitySubmitOperationType.Swap:
SwapEntityGroup(entitiesOperations[i].builders, entitiesOperations[i].id, entitiesOperations[i].fromGroupID, entitiesOperations[i].toGroupID);
break;
case EntitySubmitOperationType.Remove:
MoveEntity(entitiesOperations[i].builders, new EGID(entitiesOperations[i].id, entitiesOperations[i].fromGroupID));
break;
case EntitySubmitOperationType.FirstSwap:
SwapFirstEntityInGroup(entitiesOperations[i].builders, entitiesOperations[i].fromGroupID, entitiesOperations[i].toGroupID);
break;
case EntitySubmitOperationType.RemoveGroup:
RemoveGroupAndEntitiesFromDB(entitiesOperations[i].fromGroupID);
break;
}
}
_entitiesOperations.FastClear();
int numberOfReenteringLoops = 0;

//are there new entities built to process?
@@ -44,7 +68,7 @@ namespace Svelto.ECS
}
//todo: groupsToSubmit can be simplified as data structure?
void AddEntityViewsToTheDBAndSuitableEngines(Dictionary<int, Dictionary<Type, ITypeSafeDictionary>> groupsOfEntitiesToSubmit)
void AddEntityViewsToTheDBAndSuitableEngines(FasterDictionary<int, Dictionary<Type, ITypeSafeDictionary>> groupsOfEntitiesToSubmit)
{
//each group is indexed by entity view type. for each type there is a dictionary indexed by entityID
foreach (var groupOfEntitiesToSubmit in groupsOfEntitiesToSubmit)
@@ -90,9 +114,10 @@ namespace Svelto.ECS
//to the FasterDictionary capabilities OR it's possible to get a specific entityView indexed by
//ID. This ID doesn't need to be the EGID, it can be just the entityID
readonly Dictionary<int, Dictionary<Type, ITypeSafeDictionary>> _groupEntityDB;
readonly FasterDictionary<int, Dictionary<Type, ITypeSafeDictionary>> _groupEntityDB;
readonly Dictionary<Type, FasterDictionary<int, ITypeSafeDictionary>> _groupedGroups; //yes I am being sarcastic
readonly DoubleBufferedEntitiesToAdd<Dictionary<int, Dictionary<Type, ITypeSafeDictionary>>> _groupedEntityToAdd;
readonly DoubleBufferedEntitiesToAdd<FasterDictionary<int, Dictionary<Type, ITypeSafeDictionary>>> _groupedEntityToAdd;
readonly EntitySubmissionScheduler _scheduler;
readonly FasterList<EntitySubmitOperation> _entitiesOperations;
}
}

+ 13
- 8
Svelto.ECS/EntitiesDB.cs View File

@@ -7,7 +7,7 @@ namespace Svelto.ECS.Internal
{
partial class EntitiesDB : IEntitiesDB
{
internal EntitiesDB(Dictionary<int, Dictionary<Type, ITypeSafeDictionary>> groupEntityViewsDB,
internal EntitiesDB(FasterDictionary<int, Dictionary<Type, ITypeSafeDictionary>> groupEntityViewsDB,
Dictionary<Type, FasterDictionary<int, ITypeSafeDictionary>> groupedGroups)
{
_groupEntityViewsDB = groupEntityViewsDB;
@@ -19,7 +19,7 @@ namespace Svelto.ECS.Internal
TypeSafeDictionary<T> typeSafeDictionary;
if (QueryEntitySafeDictionary(@group, out typeSafeDictionary) == false) return RetrieveEmptyEntityViewList<T>();

return typeSafeDictionary.FasterValues;
return typeSafeDictionary.Values;
}

public T[] QueryEntities<T>(int @group, out int count) where T : IEntityStruct
@@ -28,7 +28,7 @@ namespace Svelto.ECS.Internal
count = 0;
if (QueryEntitySafeDictionary(@group, out typeSafeDictionary) == false) return RetrieveEmptyEntityViewArray<T>();

return typeSafeDictionary.GetFasterValuesBuffer(out count);
return typeSafeDictionary.GetValuesArray(out count);
}

public T[] QueryEntities<T>(ExclusiveGroup @group, out int targetsCount) where T : IEntityStruct
@@ -47,7 +47,7 @@ namespace Svelto.ECS.Internal
mapper.map = typeSafeDictionary;

int count;
typeSafeDictionary.GetFasterValuesBuffer(out count);
typeSafeDictionary.GetValuesArray(out count);

return mapper;
}
@@ -121,14 +121,15 @@ namespace Svelto.ECS.Internal
T[] QueryEntitiesAndIndexInternal<T>(EGID entityGID, out uint index) where T : IEntityStruct
{
TypeSafeDictionary<T> safeDictionary;
index = 0;
if (QueryEntitySafeDictionary(entityGID.groupID, out safeDictionary) == false)
throw new EntitiesDBException("Entity not found, type: ".FastConcat(typeof(T)).FastConcat(" groupID: ").FastConcat(entityGID.entityID));
return null;

if (safeDictionary.TryFindElementIndex(entityGID.entityID, out index) == false)
throw new EntitiesDBException("Entity not found, type: ".FastConcat(typeof(T)).FastConcat(" groupID: ").FastConcat(entityGID.entityID));
return null;

int count;
return safeDictionary.GetFasterValuesBuffer(out count);
return safeDictionary.GetValuesArray(out count);
}
bool QueryEntitySafeDictionary<T>(int @group, out TypeSafeDictionary<T> typeSafeDictionary) where T : IEntityStruct
@@ -170,7 +171,11 @@ namespace Svelto.ECS.Internal
}
//grouped set of entity views, this is the standard way to handle entity views
readonly Dictionary<int, Dictionary<Type, ITypeSafeDictionary>> _groupEntityViewsDB;
//entity views are grouped per group, then indexable per type, then indexable per EGID.
//however the TypeSafeDictionary can return an array of values directly, that can be
//iterated over, so that is possible to iterate over all the entity views of
//a specific type inside a specific group.
readonly FasterDictionary<int, Dictionary<Type, ITypeSafeDictionary>> _groupEntityViewsDB;
//needed to be able to iterate over all the entities of the same type regardless the group
//may change in future
readonly Dictionary<Type, FasterDictionary<int, ITypeSafeDictionary>> _groupedGroups;


+ 4
- 5
Svelto.ECS/EntityFactory.cs View File

@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using Svelto.DataStructures.Experimental;

namespace Svelto.ECS.Internal
{
@@ -7,7 +8,7 @@ namespace Svelto.ECS.Internal
{
internal static Dictionary<Type, ITypeSafeDictionary>
BuildGroupedEntityViews(EGID egid,
Dictionary<int, Dictionary<Type, ITypeSafeDictionary>> groupEntityViewsByType,
FasterDictionary<int, Dictionary<Type, ITypeSafeDictionary>> groupEntityViewsByType,
IEntityBuilder[] entityToBuild,
object[] implementors)
{
@@ -19,7 +20,7 @@ namespace Svelto.ECS.Internal
}

static Dictionary<Type, ITypeSafeDictionary> FetchEntityViewGroup(int groupID,
Dictionary<int, Dictionary<Type, ITypeSafeDictionary>> groupEntityViewsByType)
FasterDictionary<int, Dictionary<Type, ITypeSafeDictionary>> groupEntityViewsByType)
{
Dictionary<Type, ITypeSafeDictionary> group;

@@ -53,13 +54,11 @@ namespace Svelto.ECS.Internal
{
ITypeSafeDictionary safeDictionary;

var entityViewsPoolWillBeCreated =
@group.TryGetValue(entityViewType, out safeDictionary) == false;
var entityViewsPoolWillBeCreated = @group.TryGetValue(entityViewType, out safeDictionary) == false;

//passing the undefined entityViewsByType inside the entityViewBuilder will allow
//it to be created with the correct type and casted back to the undefined list.
//that's how the list will be eventually of the target type.
entityBuilder.BuildEntityViewAndAddToList(ref safeDictionary, entityID, implementors);

if (entityViewsPoolWillBeCreated)


+ 22
- 0
Svelto.ECS/EntitySubmitOperation.cs View File

@@ -2,5 +2,27 @@
{
struct EntitySubmitOperation
{
public readonly EntitySubmitOperationType type;
public readonly IEntityBuilder[] builders;
public readonly int id;
public readonly int toGroupID;
public readonly int fromGroupID;

public EntitySubmitOperation(EntitySubmitOperationType operation, int entityId, int fromGroupId, int toGroupId, IEntityBuilder[] builders)
{
type = operation;
this.builders = builders;
id = entityId;
toGroupID = toGroupId;
fromGroupID = fromGroupId;
}
}

enum EntitySubmitOperationType
{
Swap,
Remove,
FirstSwap,
RemoveGroup
}
}

+ 6
- 6
Svelto.ECS/ExecuteOnEntitiesDB.cs View File

@@ -63,7 +63,7 @@ namespace Svelto.ECS.Internal
TypeSafeDictionary<T> typeSafeDictionary;
if (QueryEntitySafeDictionary(@groupID, out typeSafeDictionary) == false) return;

var entities = typeSafeDictionary.GetFasterValuesBuffer(out count);
var entities = typeSafeDictionary.GetValuesArray(out count);

for (var i = 0; i < count; i++)
action(ref entities[i], this, i);
@@ -82,7 +82,7 @@ namespace Svelto.ECS.Internal
TypeSafeDictionary<T> typeSafeDictionary;
if (QueryEntitySafeDictionary(@groupID, out typeSafeDictionary) == false) return;

var entities = typeSafeDictionary.GetFasterValuesBuffer(out count);
var entities = typeSafeDictionary.GetValuesArray(out count);

for (var i = 0; i < count; i++)
action(ref entities[i], ref value, this, i);
@@ -105,7 +105,7 @@ namespace Svelto.ECS.Internal
if (_groupedGroups.TryGetValue(type, out dic))
{
int count;
var typeSafeDictionaries = dic.GetFasterValuesBuffer(out count);
var typeSafeDictionaries = dic.GetValuesArray(out count);

for (int j = 0; j < count; j++)
{
@@ -113,7 +113,7 @@ namespace Svelto.ECS.Internal
var typeSafeDictionary = typeSafeDictionaries[j];
var casted = typeSafeDictionary as TypeSafeDictionary<T>;

var entities = casted.GetFasterValuesBuffer(out innerCount);
var entities = casted.GetValuesArray(out innerCount);

for (int i = 0; i < innerCount; i++)
action(ref entities[i], this);
@@ -131,7 +131,7 @@ namespace Svelto.ECS.Internal
if (_groupedGroups.TryGetValue(type, out dic))
{
int count;
var typeSafeDictionaries = dic.GetFasterValuesBuffer(out count);
var typeSafeDictionaries = dic.GetValuesArray(out count);

for (int j = 0; j < count; j++)
{
@@ -139,7 +139,7 @@ namespace Svelto.ECS.Internal
var typeSafeDictionary = typeSafeDictionaries[j];
var casted = typeSafeDictionary as TypeSafeDictionary<T>;

var entities = casted.GetFasterValuesBuffer(out innerCount);
var entities = casted.GetValuesArray(out innerCount);

for (int i = 0; i < innerCount; i++)
action(ref entities[i], ref value, this);


+ 6
- 6
Svelto.ECS/IEntityFunctions.cs View File

@@ -14,11 +14,11 @@ namespace Svelto.ECS
void RemoveGroupAndEntities(int groupID);
void RemoveGroupAndEntities(ExclusiveGroup groupID);
EGID SwapEntityGroup<T>(int entityID, int fromGroupID, int toGroupID) where T : IEntityDescriptor, new();
EGID SwapEntityGroup<T>(int entityID, ExclusiveGroup fromGroupID, ExclusiveGroup toGroupID) where T : IEntityDescriptor, new();
EGID SwapEntityGroup<T>(EGID id, int toGroupID) where T : IEntityDescriptor, new();
EGID SwapEntityGroup<T>(EGID id, ExclusiveGroup toGroupID) where T : IEntityDescriptor, new();
EGID SwapFirstEntityGroup<T>(int fromGroupID, int toGroupID) where T : IEntityDescriptor, new();
EGID SwapFirstEntityGroup<T>(ExclusiveGroup fromGroupID, ExclusiveGroup toGroupID) where T : IEntityDescriptor, new();
void SwapEntityGroup<T>(int entityID, int fromGroupID, int toGroupID) where T : IEntityDescriptor, new();
void SwapEntityGroup<T>(int entityID, ExclusiveGroup fromGroupID, ExclusiveGroup toGroupID) where T : IEntityDescriptor, new();
void SwapEntityGroup<T>(EGID id, int toGroupID) where T : IEntityDescriptor, new();
void SwapEntityGroup<T>(EGID id, ExclusiveGroup toGroupID) where T : IEntityDescriptor, new();
void SwapFirstEntityGroup<T>(int fromGroupID, int toGroupID) where T : IEntityDescriptor, new();
void SwapFirstEntityGroup<T>(ExclusiveGroup fromGroupID, ExclusiveGroup toGroupID) where T : IEntityDescriptor, new();
}
}

Loading…
Cancel
Save