Browse Source

some optimizations

tags/Rel2
sebas77 6 years ago
parent
commit
5179c885f7
4 changed files with 27 additions and 47 deletions
  1. +2
    -0
      Svelto.ECS/EnginesRootEngines.cs
  2. +18
    -23
      Svelto.ECS/EnginesRootEntities.cs
  3. +7
    -17
      Svelto.ECS/EntityFactory.cs
  4. +0
    -7
      Svelto.ECS/EntityInfoView.cs

+ 2
- 0
Svelto.ECS/EnginesRootEngines.cs View File

@@ -41,6 +41,8 @@ namespace Svelto.ECS
_groupEntityViewsDB = new Dictionary<int, Dictionary<Type, ITypeSafeList>>();
_globalEntityViewsDBDic = new Dictionary<Type, ITypeSafeDictionary>();
_entityInfos = new Dictionary<int, IEntityViewBuilder[]>();
_groupedEntityViewsToAdd = new DoubleBufferedEntityViews<Dictionary<int, Dictionary<Type, ITypeSafeList>>>();

_DB = new EntityViewsDB(_globalEntityViewsDB, _globalEntityViewsDBDic, _groupEntityViewsDB);


+ 18
- 23
Svelto.ECS/EnginesRootEntities.cs View File

@@ -61,6 +61,7 @@ namespace Svelto.ECS
EntityFactory.BuildGroupedEntityViews(entityID, groupID,
_groupedEntityViewsToAdd.current,
EntityDescriptorTemplate<T>.Default,
_entityInfos,
implementors);
}

@@ -69,7 +70,9 @@ namespace Svelto.ECS
{
EntityFactory.BuildGroupedEntityViews(entityID, groupID,
_groupedEntityViewsToAdd.current,
entityDescriptor, implementors);
entityDescriptor,
_entityInfos,
implementors);
}

///--------------------------------------------
@@ -127,28 +130,23 @@ namespace Svelto.ECS

void RemoveEntity(EGID entityGID)
{
EntityInfoView entityInfoView;
_DB.TryQueryEntityView(entityGID, out entityInfoView);

var entityViewBuilders = entityInfoView.entityViews;
EGID id = entityInfoView._ID;
var entityViewBuilders = _entityInfos[entityGID.GID];

var entityViewBuildersCount = entityViewBuilders.Length;
var group = _groupEntityViewsDB[id.group];
var group = _groupEntityViewsDB[entityGID.group];

//for each entity view generated by the entity descriptor
for (var i = 0; i < entityViewBuildersCount; i++)
{
var entityViewType = entityViewBuilders[i].GetEntityViewType();
InternalRemoveEntityViewFromDBDicAndEngines(entityViewType, id);
InternalRemoveEntityViewFromDBDicAndEngines(entityViewType, entityGID);
RemoveEntityViewFromDB(@group, entityViewType, id);
RemoveEntityViewFromDB(@_globalEntityViewsDB, entityViewType, id);
RemoveEntityViewFromDB(@group, entityViewType, entityGID);
RemoveEntityViewFromDB(@_globalEntityViewsDB, entityViewType, entityGID);
}

InternalRemoveEntityViewFromDBDicAndEngines(_entityInfoViewType, id);
_entityInfos.Remove(entityGID.GID);
}

static void RemoveEntityViewFromDB(Dictionary<Type, ITypeSafeList> @group, Type entityViewType, EGID id)
@@ -233,11 +231,8 @@ namespace Svelto.ECS
Check.Require(fromGroupID != toGroupID,
"can't move an entity to the same group where it already belongs to");

EntityInfoView entityInfoView;
_DB.TryQueryEntityView(new EGID(fromGroupID, entityID), out entityInfoView);
var entityViewBuilders = entityInfoView.entityViews;
var entityegid = new EGID(entityID, fromGroupID);
var entityViewBuilders = _entityInfos[entityegid.GID];
var entityViewBuildersCount = entityViewBuilders.Length;

var groupedEntities = _groupEntityViewsDB[fromGroupID];
@@ -261,13 +256,13 @@ namespace Svelto.ECS
if (groupedEntityViewsTyped.TryGetValue(entityViewType, out toSafeList) == false)
groupedEntityViewsTyped[entityViewType] = toSafeList = fromSafeList.Create();

entityViewBuilder.MoveEntityView(entityInfoView._ID, fromSafeList, toSafeList);
fromSafeList.MappedRemove(entityInfoView._ID);
entityInfoView._ID = new EGID(entityID, toGroupID);
entityViewBuilder.MoveEntityView(entityegid, fromSafeList, toSafeList);
fromSafeList.MappedRemove(entityegid);
}
}

readonly Type _entityInfoViewType = typeof(EntityInfoView);
_entityInfos.Remove(entityegid.GID);
_entityInfos.Add(new EGID(entityID, toGroupID).GID, entityViewBuilders);
}

readonly EntityViewsDB _DB;
@@ -283,6 +278,6 @@ namespace Svelto.ECS
//indexable entity views when the entity ID is known. Usually useful to handle
//event based logic.
readonly Dictionary<Type, ITypeSafeDictionary> _globalEntityViewsDBDic;
Dictionary<int, IEntityViewBuilder[]> _entityInfos;
}
}

+ 7
- 17
Svelto.ECS/EntityFactory.cs View File

@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Xml;
using Svelto.DataStructures;
using Svelto.Utilities;
using Console = Utility.Console;
@@ -11,31 +12,20 @@ namespace Svelto.ECS.Internal
internal static void BuildGroupedEntityViews(int entityID, int groupID,
Dictionary<int, Dictionary<Type, ITypeSafeList>> groupEntityViewsByType,
EntityDescriptorInfo entityViewsToBuildDescriptor,
Dictionary<int, IEntityViewBuilder[]> entityInfos,
object[] implementors)
{
var @group = FetchGroup(groupID, groupEntityViewsByType);

BuildEntityViewsAndAddToGroup(new EGID(entityID, groupID), group, entityViewsToBuildDescriptor, implementors);

AddEntityInfoView(new EGID(entityID, groupID), entityViewsToBuildDescriptor, @group);
AddEntityInfoView(new EGID(entityID, groupID), entityViewsToBuildDescriptor, entityInfos);
}

static void AddEntityInfoView(EGID entityID, EntityDescriptorInfo entityViewsToBuildDescriptor,
Dictionary<Type, ITypeSafeList> @group)
static void AddEntityInfoView(EGID entityID, EntityDescriptorInfo entityViewsToBuildDescriptor,
Dictionary<int, IEntityViewBuilder[]> entityInfos)
{
//should be a struct?
var removeEntityView = new EntityInfoView();

removeEntityView._ID = entityID;
removeEntityView.entityViews = entityViewsToBuildDescriptor.entityViewsToBuild;

ITypeSafeList list;

if (group.TryGetValue(typeof(EntityInfoView), out list) == false)
list = group[typeof(EntityInfoView)] =
new TypeSafeFasterListForECSForClasses<EntityInfoView>();

((TypeSafeFasterListForECSForClasses<EntityInfoView>) list).Add(removeEntityView);
entityInfos.Add(entityID.GID, entityViewsToBuildDescriptor.entityViewsToBuild);
}

static Dictionary<Type, ITypeSafeList> FetchGroup(int groupID, Dictionary<int, Dictionary<Type, ITypeSafeList>> groupEntityViewsByType)
@@ -202,7 +192,7 @@ namespace Svelto.ECS.Internal
}
#endif
static readonly Dictionary<Type, Type[]> _cachedTypes = new Dictionary<Type, Type[]>();
const string DUPLICATE_IMPLEMENTOR_ERROR =
"<color=orange>Svelto.ECS</color> the same component is implemented with more than one implementor. This is considered an error and MUST be fixed. ";



+ 0
- 7
Svelto.ECS/EntityInfoView.cs View File

@@ -1,7 +0,0 @@
namespace Svelto.ECS.Internal
{
class EntityInfoView : EntityView
{
internal IEntityViewBuilder[] entityViews;
}
}

Loading…
Cancel
Save