@@ -65,7 +65,7 @@ namespace Svelto.ECS.Internal | |||
entityViewsByType.Add(entityViewType, safeDictionary); | |||
} | |||
static readonly EntityViewStructBuilder<EntityInfoView> _viewBuilder = new EntityViewStructBuilder<EntityInfoView>(); | |||
static readonly Type _viewType = typeof(EntityInfoView); | |||
static readonly EntityViewBuilder<EntityInfoView> _viewBuilder = new EntityViewBuilder<EntityInfoView>(); | |||
static readonly Type _viewType = typeof(EntityInfoView); | |||
} | |||
} |
@@ -6,38 +6,55 @@ using Svelto.Utilities; | |||
namespace Svelto.ECS | |||
{ | |||
public class EntityViewBuilder<EntityViewType> : IEntityViewBuilder where EntityViewType : IEntityData, new() | |||
public class EntityViewBuilder<T> : IEntityViewBuilder where T : IEntityData, new() | |||
{ | |||
public void BuildEntityViewAndAddToList(ref ITypeSafeDictionary list, EGID entityID, object[] implementors) | |||
public EntityViewBuilder(ref T initializer) | |||
{ | |||
if (list == null) | |||
list = new TypeSafeDictionary<EntityViewType>(); | |||
_initializer = initializer; | |||
} | |||
public EntityViewBuilder() | |||
{ | |||
_initializer = default(T); | |||
} | |||
public void BuildEntityViewAndAddToList(ref ITypeSafeDictionary dictionary, EGID entityID, object[] implementors) | |||
{ | |||
if (dictionary == null) | |||
dictionary = new TypeSafeDictionary<T>(); | |||
var castedDic = list as TypeSafeDictionary<EntityViewType>; | |||
var castedDic = dictionary as TypeSafeDictionary<T>; | |||
DBC.Check.Require(implementors != null, "Implementors not found while building an EntityView"); | |||
if (needsReflection == true) | |||
{ | |||
EntityViewType lentityView; | |||
EntityView<EntityViewType>.BuildEntityView(entityID, out lentityView); | |||
DBC.Check.Require(implementors != null, "Implementors not found while building an EntityView"); | |||
T lentityView; | |||
EntityView<T>.BuildEntityView(entityID, out lentityView); | |||
this.FillEntityView(ref lentityView | |||
, entityViewBlazingFastReflection | |||
, implementors | |||
, DESCRIPTOR_NAME); | |||
castedDic.Add(entityID.entityID, ref lentityView); | |||
} | |||
else | |||
{ | |||
_initializer.ID = entityID; | |||
castedDic.Add(entityID.entityID, _initializer); | |||
} | |||
} | |||
public ITypeSafeDictionary Preallocate(ref ITypeSafeDictionary list, int size) | |||
public ITypeSafeDictionary Preallocate(ref ITypeSafeDictionary dictionary, int size) | |||
{ | |||
if (list == null) | |||
list = new TypeSafeDictionary<EntityViewType>(size); | |||
if (dictionary == null) | |||
dictionary = new TypeSafeDictionary<T>(size); | |||
else | |||
list.AddCapacity(size); | |||
dictionary.AddCapacity(size); | |||
return list; | |||
return dictionary; | |||
} | |||
public Type GetEntityType() | |||
@@ -45,21 +62,24 @@ namespace Svelto.ECS | |||
return ENTITY_VIEW_TYPE; | |||
} | |||
public void MoveEntityView(EGID entityID, ITypeSafeDictionary fromSafeList, ITypeSafeDictionary toSafeList) | |||
public void MoveEntityView(EGID entityID, ITypeSafeDictionary fromSafeDic, ITypeSafeDictionary toSafeDic) | |||
{ | |||
var fromCastedDic = fromSafeList as TypeSafeDictionary<EntityViewType>; | |||
var toCastedDic = toSafeList as TypeSafeDictionary<EntityViewType>; | |||
var fromCastedDic = fromSafeDic as TypeSafeDictionary<T>; | |||
var toCastedDic = toSafeDic as TypeSafeDictionary<T>; | |||
toCastedDic.Add(entityID.entityID, fromCastedDic[entityID.entityID]); | |||
fromCastedDic.Remove(entityID.entityID); | |||
} | |||
FasterList<KeyValuePair<Type, ActionRef<EntityViewType>>> entityViewBlazingFastReflection | |||
FasterList<KeyValuePair<Type, ActionRef<T>>> entityViewBlazingFastReflection | |||
{ | |||
get { return EntityView<EntityViewType>.FieldCache.list; } | |||
get { return EntityView<T>.FieldCache.list; } | |||
} | |||
static readonly Type ENTITY_VIEW_TYPE = typeof(EntityViewType); | |||
static readonly Type ENTITY_VIEW_TYPE = typeof(T); | |||
static string DESCRIPTOR_NAME = ENTITY_VIEW_TYPE.ToString(); | |||
internal T _initializer; | |||
readonly bool needsReflection = typeof(IEntityView).IsAssignableFrom(typeof(T)); | |||
} | |||
} |
@@ -1,57 +0,0 @@ | |||
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 castedDic = list as TypeSafeDictionary<EntityViewType>; | |||
castedDic.Add(entityID.entityID, _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 GetEntityType() | |||
{ | |||
return ENTITY_VIEW_TYPE; | |||
} | |||
public void MoveEntityView(EGID entityID, ITypeSafeDictionary fromSafeList, ITypeSafeDictionary toSafeList) | |||
{ | |||
var fromCastedDic = fromSafeList as TypeSafeDictionary<EntityViewType>; | |||
var toCastedDic = toSafeList as TypeSafeDictionary<EntityViewType>; | |||
toCastedDic.Add(entityID.entityID, fromCastedDic[entityID.entityID]); | |||
fromCastedDic.Remove(entityID.entityID); | |||
} | |||
static readonly Type ENTITY_VIEW_TYPE = typeof(EntityViewType); | |||
internal EntityViewType _initializer; | |||
} | |||
} |
@@ -12,7 +12,10 @@ namespace Svelto.ECS | |||
EGID ID { get; set; } | |||
} | |||
public class EntityView : IEntityData | |||
public interface IEntityView:IEntityData | |||
{} | |||
public class EntityView : IEntityView | |||
{ | |||
public EGID ID | |||
{ | |||
@@ -5,10 +5,10 @@ namespace Svelto.ECS | |||
{ | |||
public interface IEntityViewBuilder | |||
{ | |||
void BuildEntityViewAndAddToList(ref ITypeSafeDictionary list, EGID entityID, object[] implementors); | |||
ITypeSafeDictionary Preallocate(ref ITypeSafeDictionary list, int size); | |||
void BuildEntityViewAndAddToList(ref ITypeSafeDictionary dictionary, EGID entityID, object[] implementors); | |||
ITypeSafeDictionary Preallocate(ref ITypeSafeDictionary dictionary, int size); | |||
Type GetEntityType(); | |||
void MoveEntityView(EGID entityID, ITypeSafeDictionary fromSafeList, ITypeSafeDictionary toSafeList); | |||
void MoveEntityView(EGID entityID, ITypeSafeDictionary fromSafeDic, ITypeSafeDictionary toSafeDic); | |||
} | |||
} |
@@ -1,107 +0,0 @@ | |||
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; | |||
} | |||
} |