Browse Source

working on use just one data structure, still WIP and a lot of work to do

tags/Rel25a
sebas77 6 years ago
parent
commit
70344dbe13
20 changed files with 357 additions and 116 deletions
  1. +25
    -9
      Svelto.ECS/DataStructures/TypeSafeDictionary.cs
  2. +18
    -8
      Svelto.ECS/EnginesRoot.GenericEntityFactory.cs
  3. +12
    -14
      Svelto.ECS/EnginesRootEntities.cs
  4. +10
    -21
      Svelto.ECS/EnginesRootSubmission.cs
  5. +3
    -3
      Svelto.ECS/EntityDescriptor.cs
  6. +4
    -4
      Svelto.ECS/EntityFactory.cs
  7. +2
    -20
      Svelto.ECS/EntityViewBuilder.cs
  8. +57
    -0
      Svelto.ECS/EntityViewStructBuilder.cs
  9. +4
    -4
      Svelto.ECS/EntityViewUtility.cs
  10. +2
    -2
      Svelto.ECS/EntityViewsDB.cs
  11. +1
    -1
      Svelto.ECS/Extensions/Unity/GenericEntityDescriptorHolder.cs
  12. +2
    -2
      Svelto.ECS/IEngine.cs
  13. +18
    -12
      Svelto.ECS/IEntityFactory.cs
  14. +4
    -4
      Svelto.ECS/IEntityView.cs
  15. +2
    -2
      Svelto.ECS/IEntityViewsDB.cs
  16. +107
    -0
      Svelto.ECS/MixedEntityDescriptor.cs
  17. +43
    -0
      Svelto.ECS/MultiEntityStructsEngine.cs
  18. +21
    -6
      Svelto.ECS/MultiEntityViewsEngine.cs
  19. +2
    -2
      Svelto.ECS/Profiler/EngineProfiler.cs
  20. +20
    -2
      Svelto.ECS/SingleEntityViewEngine.cs

+ 25
- 9
Svelto.ECS/DataStructures/TypeSafeDictionary.cs View File

@@ -23,7 +23,7 @@ namespace Svelto.ECS.Internal
ITypeSafeDictionary Create();
int Count { get; }
void FillWithIndexedEntityViews(ITypeSafeDictionary entityViews);
void AddEntityViewsToEngines(FasterList<IHandleEntityViewEngineAbstracted> enginesForEntityView);
void AddEntityViewsToEngines(Dictionary<Type, FasterList<IHandleEntityViewEngineAbstracted>> entityViewEnginesDB);
}

class TypeSafeDictionary<TValue> : FasterDictionary<long, TValue>, ITypeSafeDictionary where TValue : IEntityData
@@ -54,9 +54,25 @@ namespace Svelto.ECS.Internal
}
}

public void AddEntityViewsToEngines(FasterList<IHandleEntityViewEngineAbstracted> enginesForEntityView)
public void AddEntityViewsToEngines(Dictionary<Type, FasterList<IHandleEntityViewEngineAbstracted>> entityViewEnginesDB)
{
throw new NotImplementedException();
int count;
TValue[] values = GetFasterValuesBuffer(out count);

for (int i = 0; i < count; i++)
{
TValue entity = values[i];

AddEntityViewFromEngines(entityViewEnginesDB, ref entity);
}
}

void AddEntityViewFromEngines(Dictionary<Type, FasterList<IHandleEntityViewEngineAbstracted>> entityViewEnginesDB, ref TValue entity)
{
FasterList<IHandleEntityViewEngineAbstracted> entityViewsEngines;
if (entityViewEnginesDB.TryGetValue(typeof(TValue), out entityViewsEngines))
for (int i = 0; i < entityViewsEngines.Count; i++)
(entityViewsEngines[i] as IHandleEntityStructEngine<TValue>).AddInternal(ref entity);
}

public void RemoveEntityFromDicAndEngines(EGID entityGid,
@@ -67,29 +83,29 @@ namespace Svelto.ECS.Internal
TValue entity = this[entityGid.GID];

RemoveEntityViewsFromEngines(entityViewEnginesDB, ref entity);
RemoveEntityViewFromEngines(entityViewEnginesDB, ref entity);

Remove(entityGid.GID);
}

public void RemoveEntityViewsFromEngines(Dictionary<Type, FasterList<IHandleEntityViewEngineAbstracted>> entityViewEnginesDB, ref TValue entity)
static void RemoveEntityViewFromEngines(Dictionary<Type, FasterList<IHandleEntityViewEngineAbstracted>> entityViewEnginesDB, ref TValue entity)
{
FasterList<IHandleEntityViewEngineAbstracted> entityViewsEngines;
if (entityViewEnginesDB.TryGetValue(typeof(TValue), out entityViewsEngines))
for (int i = 0; i < entityViewEnginesDB.Count; i++)
(entityViewsEngines[i] as IHandleEntityStructEngine<TValue>).Remove(ref entity);
for (int i = 0; i < entityViewsEngines.Count; i++)
(entityViewsEngines[i] as IHandleEntityStructEngine<TValue>).RemoveInternal(ref entity);
}
public void RemoveEntityViewsFromEngines(Dictionary<Type, FasterList<IHandleEntityViewEngineAbstracted>> entityViewEnginesDB)
{
int count;
TValue[] values = this.GetFasterValuesBuffer(out count);
TValue[] values = GetFasterValuesBuffer(out count);

for (int i = 0; i < count; i++)
{
TValue entity = values[i];

RemoveEntityViewsFromEngines(entityViewEnginesDB, ref entity);
RemoveEntityViewFromEngines(entityViewEnginesDB, ref entity);
}
}



+ 18
- 8
Svelto.ECS/EnginesRoot.GenericEntityFactory.cs View File

@@ -22,23 +22,33 @@ namespace Svelto.ECS
_weakEngine.Target.BuildEntity<T>(new EGID(entityID), implementors);
}

public void BuildEntity(int entityID, EntityDescriptorInfo entityDescriptor, object[] implementors = null)
public void BuildEntity<T>(int entityID, int groupID, object[] implementors) where T : IEntityDescriptor, new()
{
_weakEngine.Target.BuildEntity(new EGID(entityID), entityDescriptor, implementors);
_weakEngine.Target.BuildEntity<T>(new EGID(entityID, groupID), implementors);
}

public void BuildEntity<T>(int entityID, int groupID, object[] implementors)
where T : IEntityDescriptor, new()
public void BuildEntity<T>(EGID egid, object[] implementors) where T : IEntityDescriptor, new()
{
_weakEngine.Target.BuildEntity<T>(new EGID(entityID, groupID), implementors);
_weakEngine.Target.BuildEntity<T>(egid, implementors);
}


public void BuildEntity(int entityID, EntityDescriptorInfo entityDescriptorInfo, object[] implementors)
{
_weakEngine.Target.BuildEntity(new EGID(entityID), entityDescriptorInfo, implementors);
}

public void BuildEntity(int entityID, int groupID, EntityDescriptorInfo entityDescriptor,
object[] implementors)
public void BuildEntity(EGID egid, EntityDescriptorInfo entityDescriptorInfo, object[] implementors)
{
_weakEngine.Target.BuildEntity(new EGID(entityID, groupID), entityDescriptor, implementors);
_weakEngine.Target.BuildEntity(egid, entityDescriptorInfo, implementors);
}

public void BuildEntity(int entityID, int groupID, EntityDescriptorInfo entityDescriptorInfo, object[] implementors)
{
_weakEngine.Target.BuildEntity(new EGID(entityID, groupID), entityDescriptorInfo, implementors);
}

public void PreallocateEntitySpace<T>(int size) where T : IEntityDescriptor, new()
{
_weakEngine.Target.Preallocate<T>(ExclusiveGroups.StandardEntity, size);


+ 12
- 14
Svelto.ECS/EnginesRootEntities.cs View File

@@ -11,6 +11,11 @@ namespace Svelto.ECS
{
public partial class EnginesRoot : IDisposable
{
/// <summary>
/// Dispose an EngineRoot once not used anymore, so that all the
/// engines are notified with the entities removed.
/// It's a clean up process.
/// </summary>
public void Dispose()
{
foreach (var groups in _groupEntityViewsDB)
@@ -32,29 +37,22 @@ namespace Svelto.ECS

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

/// <summary>
/// Build the entity using the entityID, inside the group with Id groupID, using the
/// implementors (if necessary). The entityViews generated will be stored to be
/// added later in the engines.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="entityID"></param>
/// <param name="implementors"></param>
void BuildEntity<T>(EGID entityID, object[] implementors = null)
void BuildEntity<T>(EGID entityID, object[] implementors)
where T : IEntityDescriptor, new()
{
EntityFactory.BuildGroupedEntityViews(entityID,
_groupedEntityViewsToAdd.current,
EntityDescriptorTemplate<T>.Default,
EntityDescriptorTemplate<T>.Info,
implementors);
}

void BuildEntity(EGID entityID, EntityDescriptorInfo entityDescriptor,
object[] implementors = null)
void BuildEntity(EGID entityID, EntityDescriptorInfo entityDescriptorInfo,
object[] implementors)
{
EntityFactory.BuildGroupedEntityViews(entityID,
_groupedEntityViewsToAdd.current,
entityDescriptor,
entityDescriptorInfo,
implementors);
}

@@ -68,7 +66,7 @@ namespace Svelto.ECS
/// </summary>
void Preallocate<T>(int groupID, int size) where T : IEntityDescriptor, new()
{
var entityViewsToBuild = EntityDescriptorTemplate<T>.Default.entityViewsToBuild;
var entityViewsToBuild = EntityDescriptorTemplate<T>.Info.entityViewsToBuild;
var count = entityViewsToBuild.Length;

for (var index = 0; index < count; index++)


+ 10
- 21
Svelto.ECS/EnginesRootSubmission.cs View File

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

@@ -39,22 +38,23 @@ namespace Svelto.ECS
numberOfReenteringLoops++;
}
}
//todo: can I make the entity creation less complicated?
void AddEntityViewsToTheDBAndSuitableEngines(Dictionary<int, Dictionary<Type, ITypeSafeDictionary>> groupsToSubmit)
//todo: groupsToSubmit can be semplified as data structure?
void AddEntityViewsToTheDBAndSuitableEngines(ITypeSafeDictionary<int, Dictionary<Type, ITypeSafeDictionary>> groupsOfEntitiesToSubmit)
{
//for each groups there is a dictionary of built lists of EntityView grouped by type
foreach (var groupToSubmit in groupsToSubmit)
foreach (var groupOfEntitiesToSubmit in groupsOfEntitiesToSubmit)
{
Dictionary<Type, ITypeSafeDictionary> groupDB;
int groupID = groupToSubmit.Key;
int groupID = groupOfEntitiesToSubmit.Key;

//if the group doesn't exist in the current DB let's create it frst
//if the group doesn't exist in the current DB let's create it first
if (_groupEntityViewsDB.TryGetValue(groupID, out groupDB) == false)
groupDB = _groupEntityViewsDB[groupID] = new Dictionary<Type, ITypeSafeDictionary>();

foreach (var entityViewList in groupToSubmit.Value)
//add the entity View in the group
foreach (var entityViewList in groupOfEntitiesToSubmit.Value)
{
//add the entity View in the group
ITypeSafeDictionary dbList;
if (groupDB.TryGetValue(entityViewList.Key, out dbList) == false)
dbList = groupDB[entityViewList.Key] = entityViewList.Value.Create();
@@ -65,7 +65,7 @@ namespace Svelto.ECS

//then submit everything in the engines, so that the DB is up to date
//with all the entity views and struct created by the entity built
foreach (var groupToSubmit in groupsToSubmit)
foreach (var groupToSubmit in groupsOfEntitiesToSubmit)
{
foreach (var entityViewsPerType in groupToSubmit.Value)
{
@@ -73,21 +73,10 @@ namespace Svelto.ECS
for (var current = type;
current != _entityViewType && current != _objectType && current != _valueType;
current = current.BaseType)
AddEntityViewsToTheSuitableEngines(_entityViewEngines, entityViewsPerType.Value,
current);
entityViewsPerType.Value.AddEntityViewsToEngines(_entityViewEngines);
}
}
}

static void AddEntityViewsToTheSuitableEngines( Dictionary<Type, FasterList<IHandleEntityViewEngineAbstracted>> entityViewEngines,
ITypeSafeDictionary entityViewsList,
Type entityViewType)
{
FasterList<IHandleEntityViewEngineAbstracted> enginesForEntityView;

if (entityViewEngines.TryGetValue(entityViewType, out enginesForEntityView))
entityViewsList.AddEntityViewsToEngines(enginesForEntityView);
}
readonly DoubleBufferedEntityViews<Dictionary<int, Dictionary<Type, ITypeSafeDictionary>>> _groupedEntityViewsToAdd;
readonly EntitySubmissionScheduler _scheduler;


+ 3
- 3
Svelto.ECS/EntityDescriptor.cs View File

@@ -21,7 +21,7 @@ namespace Svelto.ECS

public static class EntityDescriptorTemplate<TType> where TType : IEntityDescriptor, new()
{
public static readonly EntityDescriptorInfo Default = new EntityDescriptorInfo(new TType());
public static readonly EntityDescriptorInfo Info = new EntityDescriptorInfo(new TType());
}

public class DynamicEntityDescriptorInfo<TType> : EntityDescriptorInfo where TType : IEntityDescriptor, new()
@@ -31,7 +31,7 @@ namespace Svelto.ECS
Check.Require(extraEntityViews.Count > 0,
"don't use a DynamicEntityDescriptorInfo if you don't need to use extra EntityViews");

var defaultEntityViewsToBuild = EntityDescriptorTemplate<TType>.Default.entityViewsToBuild;
var defaultEntityViewsToBuild = EntityDescriptorTemplate<TType>.Info.entityViewsToBuild;
var length = defaultEntityViewsToBuild.Length;

entityViewsToBuild = new IEntityViewBuilder[length + extraEntityViews.Count];
@@ -39,7 +39,7 @@ namespace Svelto.ECS
Array.Copy(defaultEntityViewsToBuild, 0, entityViewsToBuild, 0, length);
Array.Copy(extraEntityViews.ToArrayFast(), 0, entityViewsToBuild, length, extraEntityViews.Count);

name = EntityDescriptorTemplate<TType>.Default.name;
name = EntityDescriptorTemplate<TType>.Info.name;
}
}



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

@@ -10,12 +10,12 @@ namespace Svelto.ECS.Internal
EntityDescriptorInfo entityViewsToBuildDescriptor,
object[] implementors)
{
var @group = FetchGroup(egid.groupID, groupEntityViewsByType);
var @group = FetchEntityViewGroup(egid.groupID, groupEntityViewsByType);

BuildEntityViewsAndAddToGroup(egid, group, entityViewsToBuildDescriptor, implementors);
}

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

@@ -44,7 +44,7 @@ namespace Svelto.ECS.Internal
BuildEntityView(entityID, entityViewsByType, entityViewType, entityViewBuilder, implementors);
}

_viewBuilder._initializer = new EntityInfoView() {entityViewsToBuild = entityViewsToBuild};
_viewBuilder._initializer = new EntityInfoView {entityViewsToBuild = entityViewsToBuild};
BuildEntityView(entityID, entityViewsByType, _viewType, _viewBuilder, null);
}

@@ -65,7 +65,7 @@ namespace Svelto.ECS.Internal
entityViewsByType.Add(entityViewType, safeDictionary);
}
static readonly EntityViewBuilder<EntityInfoView> _viewBuilder = new EntityViewBuilder<EntityInfoView>();
static readonly EntityViewStructBuilder<EntityInfoView> _viewBuilder = new EntityViewStructBuilder<EntityInfoView>();
static readonly Type _viewType = typeof(EntityInfoView);
}
}

+ 2
- 20
Svelto.ECS/EntityViewBuilder.cs View File

@@ -8,14 +8,6 @@ namespace Svelto.ECS
{
public class EntityViewBuilder<EntityViewType> : IEntityViewBuilder where EntityViewType : IEntityData, new()
{
public EntityViewBuilder(ref EntityViewType initializer)
{
_initializer = initializer;
}
public EntityViewBuilder()
{}
public void BuildEntityViewAndAddToList(ref ITypeSafeDictionary list, EGID entityID, object[] implementors)
{
if (list == null)
@@ -23,7 +15,7 @@ namespace Svelto.ECS

var castedList = list as TypeSafeDictionary<EntityViewType>;

if (implementors != null)
DBC.Check.Require(implementors != null, "Implementors not found while building an EntityView");
{
EntityViewType lentityView;
@@ -36,14 +28,6 @@ namespace Svelto.ECS
castedList.Add(entityID.GID, ref lentityView);
}
else
{
DBC.Check.Require(_initializer != null, "Implementors not found on a EntityView instance");
_initializer.ID = entityID;
castedList.Add(entityID.GID, ref _initializer);
}
}

public ITypeSafeDictionary Preallocate(ref ITypeSafeDictionary list, int size)
@@ -70,13 +54,11 @@ namespace Svelto.ECS
fromCastedList.Remove(entityID.GID);
}

FasterList<KeyValuePair<Type, CastedAction<EntityViewType>>> entityViewBlazingFastReflection
FasterList<KeyValuePair<Type, ActionRef<EntityViewType>>> entityViewBlazingFastReflection
{
get { return EntityView<EntityViewType>.FieldCache.list; }
}
internal EntityViewType _initializer;
static readonly Type ENTITY_VIEW_TYPE = typeof(EntityViewType);
static string DESCRIPTOR_NAME = ENTITY_VIEW_TYPE.ToString();
}

+ 57
- 0
Svelto.ECS/EntityViewStructBuilder.cs View File

@@ -0,0 +1,57 @@
using System;
using Svelto.ECS.Internal;

namespace Svelto.ECS
{
public class EntityViewStructBuilder<EntityViewType> : IEntityViewBuilder where EntityViewType : struct, IEntityData
{
public EntityViewStructBuilder(ref EntityViewType initializer)
{
_initializer = initializer;
}
public EntityViewStructBuilder()
{
_initializer = default(EntityViewType);
}
public void BuildEntityViewAndAddToList(ref ITypeSafeDictionary list, EGID entityID, object[] implementors = null)
{
_initializer.ID = entityID;
if (list == null)
list = new TypeSafeDictionary<EntityViewType>();

var castedList = list as TypeSafeDictionary<EntityViewType>;
castedList.Add(entityID.GID, _initializer);
}

public ITypeSafeDictionary Preallocate(ref ITypeSafeDictionary list, int size)
{
if (list == null)
list = new TypeSafeDictionary<EntityViewType>(size);
else
list.AddCapacity(size);

return list;
}

public Type GetEntityViewType()
{
return ENTITY_VIEW_TYPE;
}

public void MoveEntityView(EGID entityID, ITypeSafeDictionary fromSafeList, ITypeSafeDictionary toSafeList)
{
var fromCastedList = fromSafeList as TypeSafeDictionary<EntityViewType>;
var toCastedList = toSafeList as TypeSafeDictionary<EntityViewType>;

toCastedList.Add(entityID.GID, fromCastedList[entityID.GID]);
fromCastedList.Remove(entityID.GID);
}

static readonly Type ENTITY_VIEW_TYPE = typeof(EntityViewType);
internal EntityViewType _initializer;
}
}

+ 4
- 4
Svelto.ECS/EntityViewUtility.cs View File

@@ -9,7 +9,7 @@ static class EntityViewUtility
{
public static void FillEntityView<T>(this IEntityViewBuilder entityViewBuilder
, ref T entityView
, FasterList<KeyValuePair<Type, CastedAction<T>>> entityViewBlazingFastReflection
, FasterList<KeyValuePair<Type, ActionRef<T>>> entityViewBlazingFastReflection
, object[] implementors
, string entityDescriptorName)
{
@@ -17,7 +17,7 @@ static class EntityViewUtility

//Very efficent way to collect the fields of every EntityViewType
var setters =
FasterList<KeyValuePair<Type, CastedAction<T>>>
FasterList<KeyValuePair<Type, ActionRef<T>>>
.NoVirt.ToArrayFast(entityViewBlazingFastReflection, out count);
#if DEBUG && !PROFILER
if (count == 0)
@@ -87,9 +87,9 @@ static class EntityViewUtility
entityViewBuilder.GetEntityViewType().Name + " - EntityDescriptor " + entityDescriptorName);
#endif
#if DEBUG && !PROFILER
fieldSetter.Value.Call(ref entityView, component.implementorType);
fieldSetter.Value(ref entityView, component.implementorType);
#else
fieldSetter.Value.Call(ref entityView, component);
fieldSetter.Value(ref entityView, component);
#endif
}



+ 2
- 2
Svelto.ECS/EntityViewsDB.cs View File

@@ -30,12 +30,12 @@ namespace Svelto.ECS.Internal
return (outList as TypeSafeDictionary<T>).FasterValues;
}

public T[] QueryEntityViewsCacheFriendly<T>(out int count) where T : IEntityData
public T[] QueryEntityViewsCacheFriendly<T>(out int count) where T : struct, IEntityData
{
return QueryEntityViewsCacheFriendly<T>(ExclusiveGroups.StandardEntity, out count);
}
public T[] QueryEntityViewsCacheFriendly<T>(int @group, out int count) where T : IEntityData
public T[] QueryEntityViewsCacheFriendly<T>(int @group, out int count) where T : struct, IEntityData
{
var type = typeof(T);
count = 0;


+ 1
- 1
Svelto.ECS/Extensions/Unity/GenericEntityDescriptorHolder.cs View File

@@ -7,7 +7,7 @@ namespace Svelto.ECS
{
public EntityDescriptorInfo RetrieveDescriptor()
{
return EntityDescriptorTemplate<T>.Default;
return EntityDescriptorTemplate<T>.Info;
}
}
}

+ 2
- 2
Svelto.ECS/IEngine.cs View File

@@ -13,7 +13,7 @@ namespace Svelto.ECS
public interface IHandleEntityStructEngine<T> : IHandleEntityViewEngineAbstracted
{
void Add(ref T entityView);
void Remove(ref T entityView);
void AddInternal(ref T entityView);
void RemoveInternal(ref T entityView);
}
}

+ 18
- 12
Svelto.ECS/IEntityFactory.cs View File

@@ -18,6 +18,18 @@ namespace Svelto.ECS
/// <param name="size"></param>
void PreallocateEntitySpace<T>(int size) where T : IEntityDescriptor, new();
void PreallocateEntitySpace<T>(int groupID, int size) where T : IEntityDescriptor, new();
/// <summary>
/// The EntityDescriptor doesn't need to be ever instantiated. It just describes the Entity
/// itself in terms of EntityViews to build. The Implementors are passed to fill the
/// references of the EntityViews components. Please read the articles on my blog
/// to understand better the terminologies
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="entityID"></param>
/// <param name="implementors"></param>
void BuildEntity<T>(int entityID, object[] implementors) where T:IEntityDescriptor, new();


/// <summary>
/// Using this function is like building a normal entity, but the entityViews
@@ -30,18 +42,9 @@ namespace Svelto.ECS
/// <param name="ed"></param>
/// <param name="implementors"></param>
void BuildEntity<T>(int entityID, int groupID, object[] implementors) where T:IEntityDescriptor, new();
void BuildEntity(int entityID, int groupID, EntityDescriptorInfo entityDescriptor, object[] implementors);

/// <summary>
/// The EntityDescriptor doesn't need to be ever instantiated. It just describes the Entity
/// itself in terms of EntityViews to build. The Implementors are passed to fill the
/// references of the EntityViews components. Please read the articles on my blog
/// to understand better the terminologies
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="entityID"></param>
/// <param name="implementors"></param>
void BuildEntity<T>(int entityID, object[] implementors) where T:IEntityDescriptor, new();
void BuildEntity<T>(EGID egid, object[] implementors) where T:IEntityDescriptor, new();

/// <summary>
/// When the type of the entity is not known (this is a special case!) an EntityDescriptorInfo
@@ -50,6 +53,9 @@ namespace Svelto.ECS
/// <param name="entityID"></param>
/// <param name="entityDescriptor"></param>
/// <param name="implementors"></param>
///
void BuildEntity(int entityID, int groupID, EntityDescriptorInfo entityDescriptor, object[] implementors);
void BuildEntity(int entityID, EntityDescriptorInfo entityDescriptorInfo, object[] implementors);
void BuildEntity(EGID egid, EntityDescriptorInfo entityDescriptorInfo, object[] implementors);
}
}

+ 4
- 4
Svelto.ECS/IEntityView.cs View File

@@ -36,7 +36,7 @@ namespace Svelto.ECS
{
if (FieldCache.list == null)
{
FieldCache.list = new FasterList<KeyValuePair<Type, CastedAction<T>>>();
FieldCache.list = new FasterList<KeyValuePair<Type, ActionRef<T>>>();
var type = typeof(T);

@@ -47,9 +47,9 @@ namespace Svelto.ECS
{
var field = fields[i];

CastedAction<T> setter = FastInvoke<T>.MakeSetter(field);
ActionRef<T> setter = FastInvoke<T>.MakeSetter(field);
FieldCache.list.Add(new KeyValuePair<Type, CastedAction<T>>(field.FieldType, setter));
FieldCache.list.Add(new KeyValuePair<Type, ActionRef<T>>(field.FieldType, setter));
}
}

@@ -58,7 +58,7 @@ namespace Svelto.ECS

public static class FieldCache
{
public static FasterList<KeyValuePair<Type, CastedAction<T>>> list;
public static FasterList<KeyValuePair<Type, ActionRef<T>>> list;
}
}
}


+ 2
- 2
Svelto.ECS/IEntityViewsDB.cs View File

@@ -7,8 +7,8 @@ namespace Svelto.ECS
ReadOnlyCollectionStruct<T> QueryEntityViews<T>() where T : IEntityData;
ReadOnlyCollectionStruct<T> QueryEntityViews<T>(int group) where T : IEntityData;

T[] QueryEntityViewsCacheFriendly<T>(out int count) where T : IEntityData;
T[] QueryEntityViewsCacheFriendly<T>(int group, out int count) where T : IEntityData;
T[] QueryEntityViewsCacheFriendly<T>(out int count) where T : struct, IEntityData;
T[] QueryEntityViewsCacheFriendly<T>(int group, out int count) where T : struct, IEntityData;

bool TryQueryEntityView<T>(EGID ID, out T entityView) where T : IEntityData;
T QueryEntityView<T>(EGID entityGID) where T : class, IEntityData;


+ 107
- 0
Svelto.ECS/MixedEntityDescriptor.cs View File

@@ -0,0 +1,107 @@
namespace Svelto.ECS
{
public abstract class MixedEntityDescriptor<T>:IEntityDescriptor where T : class, IEntityViewBuilder, new()
{
static MixedEntityDescriptor()
{
_entityViewsToBuild = new IEntityViewBuilder[] {new T()};
}
public IEntityViewBuilder[] entityViewsToBuild
{
get { return _entityViewsToBuild; }
}
static readonly IEntityViewBuilder[] _entityViewsToBuild;
}

public abstract class MixedEntityDescriptor<T, U> : IEntityDescriptor where T : class, IEntityViewBuilder, new()
where U : class, IEntityViewBuilder, new()
{
static MixedEntityDescriptor()
{
_entityViewsToBuild = new IEntityViewBuilder[] {new T(), new U()};
}

public IEntityViewBuilder[] entityViewsToBuild
{
get { return _entityViewsToBuild; }
}
static readonly IEntityViewBuilder[] _entityViewsToBuild;
}

public abstract class MixedEntityDescriptor<T, U, V> : IEntityDescriptor where T : class, IEntityViewBuilder, new()
where U : class, IEntityViewBuilder, new()
where V : class, IEntityViewBuilder, new()
{
static MixedEntityDescriptor()
{
_entityViewsToBuild = new IEntityViewBuilder[] {new T(), new U(), new V()};
}

public IEntityViewBuilder[] entityViewsToBuild
{
get { return _entityViewsToBuild; }
}
static readonly IEntityViewBuilder[] _entityViewsToBuild;
}

public abstract class MixedEntityDescriptor<T, U, V, W> : IEntityDescriptor where T : class, IEntityViewBuilder, new()
where U : class, IEntityViewBuilder, new()
where V : class, IEntityViewBuilder, new()
where W : class, IEntityViewBuilder, new()
{
static MixedEntityDescriptor()
{
_entityViewsToBuild = new IEntityViewBuilder[] {new T(), new U(), new V(), new W()};
}

public IEntityViewBuilder[] entityViewsToBuild
{
get { return _entityViewsToBuild; }
}
static readonly IEntityViewBuilder[] _entityViewsToBuild;
}

public abstract class MixedEntityDescriptor<T, U, V, W, X> : IEntityDescriptor where T : class, IEntityViewBuilder, new()
where U : class, IEntityViewBuilder, new()
where V : class, IEntityViewBuilder, new()
where W : class, IEntityViewBuilder, new()
where X : class, IEntityViewBuilder, new()
{
static MixedEntityDescriptor()
{
_entityViewsToBuild = new IEntityViewBuilder[] {new T(), new U(), new V(), new W(), new X()};
}

public IEntityViewBuilder[] entityViewsToBuild
{
get { return _entityViewsToBuild; }
}
static readonly IEntityViewBuilder[] _entityViewsToBuild;
}

public abstract class MixedEntityDescriptor<T, U, V, W, X, Y> : IEntityDescriptor where T : class, IEntityViewBuilder, new()
where U : class, IEntityViewBuilder, new()
where V : class, IEntityViewBuilder, new()
where W : class, IEntityViewBuilder, new()
where X : class, IEntityViewBuilder, new()
where Y : class, IEntityViewBuilder, new()
{
static MixedEntityDescriptor()
{
_entityViewsToBuild = new IEntityViewBuilder[] {new T(), new U(), new V(), new W(), new X(), new Y()};
}

public IEntityViewBuilder[] entityViewsToBuild
{
get { return _entityViewsToBuild; }
}
static readonly IEntityViewBuilder[] _entityViewsToBuild;
}
}

+ 43
- 0
Svelto.ECS/MultiEntityStructsEngine.cs View File

@@ -0,0 +1,43 @@
namespace Svelto.ECS
{
public abstract class MultiEntityStructsEngine<T, U> : SingleEntityViewEngine<T>, IHandleEntityStructEngine<U>
where U : IEntityData where T : IEntityData
{
public void AddInternal(ref U entityView)
{ Add(ref entityView); }
public void RemoveInternal(ref U entityView)
{ Remove(ref entityView); }
protected abstract void Add(ref U entityView);
protected abstract void Remove(ref U entityView);
}
public abstract class MultiEntityStructsEngine<T, U, V> : MultiEntityViewsEngine<T, U>, IHandleEntityStructEngine<V>
where V : IEntityData where U : IEntityData where T : IEntityData
{
public void AddInternal(ref V entityView)
{ Add(ref entityView); }
public void RemoveInternal(ref V entityView)
{ Remove(ref entityView); }
protected abstract void Add(ref V entityView);
protected abstract void Remove(ref V entityView);
}

/// <summary>
/// Please do not add more MultiEntityViewsEngine
/// if you use more than 4 nodes, your engine has
/// already too many responsabilities.
/// </summary>
public abstract class MultiEntityStructsEngine<T, U, V, W> : MultiEntityViewsEngine<T, U, V>, IHandleEntityStructEngine<W>
where W : IEntityData where V : IEntityData where U : IEntityData where T : IEntityData
{
public void AddInternal(ref W entityView)
{ Add(ref entityView); }
public void RemoveInternal(ref W entityView)
{ Remove(ref entityView); }
protected abstract void Add(ref W entityView);
protected abstract void Remove(ref W entityView);
}
}

+ 21
- 6
Svelto.ECS/MultiEntityViewsEngine.cs View File

@@ -3,15 +3,25 @@ namespace Svelto.ECS
public abstract class MultiEntityViewsEngine<T, U> : SingleEntityViewEngine<T>, IHandleEntityStructEngine<U>
where U : IEntityData where T : IEntityData
{
public abstract void Add(ref U entityView);
public abstract void Remove(ref U entityView);
public void AddInternal(ref U entityView)
{ Add(entityView); }
public void RemoveInternal(ref U entityView)
{ Remove(entityView); }
protected abstract void Add(U entityView);
protected abstract void Remove(U entityView);
}

public abstract class MultiEntityViewsEngine<T, U, V> : MultiEntityViewsEngine<T, U>, IHandleEntityStructEngine<V>
where V : IEntityData where U : IEntityData where T : IEntityData
{
public abstract void Add(ref V entityView);
public abstract void Remove(ref V entityView);
public void AddInternal(ref V entityView)
{ Add(entityView); }
public void RemoveInternal(ref V entityView)
{ Remove(entityView); }
protected abstract void Add(V entityView);
protected abstract void Remove(V entityView);
}

/// <summary>
@@ -22,7 +32,12 @@ namespace Svelto.ECS
public abstract class MultiEntityViewsEngine<T, U, V, W> : MultiEntityViewsEngine<T, U, V>, IHandleEntityStructEngine<W>
where W : IEntityData where V : IEntityData where U : IEntityData where T : IEntityData
{
public abstract void Add(ref W entityView);
public abstract void Remove(ref W entityView);
public void AddInternal(ref W entityView)
{ Add(entityView); }
public void RemoveInternal(ref W entityView)
{ Remove(entityView); }
protected abstract void Add(W entityView);
protected abstract void Remove(W entityView);
}
}

+ 2
- 2
Svelto.ECS/Profiler/EngineProfiler.cs View File

@@ -18,7 +18,7 @@ namespace Svelto.ECS.Profiler
if (engineInfos.TryGetValue(engine.GetType(), out info))
{
_stopwatch.Start();
(engine as IHandleEntityStructEngine<T>).Add(ref entityView);
(engine as IHandleEntityStructEngine<T>).AddInternal(ref entityView);
_stopwatch.Stop();
info.AddAddDuration(_stopwatch.Elapsed.TotalMilliseconds);
_stopwatch.Reset();
@@ -31,7 +31,7 @@ namespace Svelto.ECS.Profiler
if (engineInfos.TryGetValue(engine.GetType(), out info))
{
_stopwatch.Start();
(engine as IHandleEntityStructEngine<T>).Remove(ref entityView);
(engine as IHandleEntityStructEngine<T>).RemoveInternal(ref entityView);
_stopwatch.Stop();

info.AddRemoveDuration(_stopwatch.Elapsed.TotalMilliseconds);


+ 20
- 2
Svelto.ECS/SingleEntityViewEngine.cs View File

@@ -2,7 +2,25 @@ namespace Svelto.ECS
{
public abstract class SingleEntityViewEngine<T> : IHandleEntityStructEngine<T> where T : IEntityData
{
public abstract void Add(ref T entityView);
public abstract void Remove(ref T entityView);
public void AddInternal(ref T entityView)
{ Add(entityView); }

public void RemoveInternal(ref T entityView)
{ Remove(entityView); }

protected abstract void Add(T entityView);
protected abstract void Remove(T entityView);
}
public abstract class SingleEntityStructEngine<T> : IHandleEntityStructEngine<T> where T : IEntityData
{
public void AddInternal(ref T entityView)
{ Add(ref entityView); }

public void RemoveInternal(ref T entityView)
{ Remove(ref entityView); }

protected abstract void Add(ref T entityView);
protected abstract void Remove(ref T entityView);
}
}

Loading…
Cancel
Save