@@ -1,14 +1,20 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Diagnostics; | |||
using Svelto.ECS.Internal; | |||
#if DEBUG && !PROFILER | |||
#define _USE_IT | |||
#endif | |||
namespace Svelto.ECS | |||
{ | |||
public partial class EnginesRoot | |||
{ | |||
[Conditional("_USE_IT")] | |||
void CheckRemoveEntityID(EGID entityID, IEntityDescriptor descriptorEntity) | |||
{ | |||
#if DEBUG && !PROFILER | |||
Dictionary<Type, ITypeSafeDictionary> @group; | |||
var descriptorEntitiesToBuild = descriptorEntity.entitiesToBuild; | |||
@@ -27,12 +33,11 @@ namespace Svelto.ECS | |||
.FastConcat(" groupid: ") | |||
.FastConcat(entityID.groupID)); | |||
} | |||
#endif | |||
} | |||
[Conditional("_USE_IT")] | |||
void CheckRemoveEntityID(EGID entityID, Type entityType, Dictionary<Type, ITypeSafeDictionary> @group, string name) | |||
{ | |||
#if DEBUG && !PROFILER | |||
ITypeSafeDictionary entities; | |||
if (@group.TryGetValue(entityType, out entities) == true) | |||
{ | |||
@@ -55,12 +60,11 @@ namespace Svelto.ECS | |||
.FastConcat(" groupid: ") | |||
.FastConcat(entityID.groupID)); | |||
} | |||
#endif | |||
} | |||
[Conditional("_USE_IT")] | |||
void CheckAddEntityID<T>(EGID entityID, T descriptorEntity) where T:IEntityDescriptor | |||
{ | |||
#if DEBUG && !PROFILER | |||
Dictionary<Type, ITypeSafeDictionary> @group; | |||
var descriptorEntitiesToBuild = descriptorEntity.entitiesToBuild; | |||
@@ -72,12 +76,11 @@ namespace Svelto.ECS | |||
CheckAddEntityID(entityID, descriptorEntitiesToBuild[i].GetEntityType(), @group, descriptorEntity.ToString()); | |||
} | |||
} | |||
#endif | |||
} | |||
[Conditional("_USE_IT")] | |||
static void CheckAddEntityID(EGID entityID, Type entityType, Dictionary<Type, ITypeSafeDictionary> @group, string name) | |||
{ | |||
#if DEBUG && !PROFILER | |||
ITypeSafeDictionary entities; | |||
if (@group.TryGetValue(entityType, out entities)) | |||
{ | |||
@@ -91,7 +94,6 @@ namespace Svelto.ECS | |||
.FastConcat(entityID.groupID)); | |||
} | |||
} | |||
#endif | |||
} | |||
} | |||
} |
@@ -19,9 +19,8 @@ namespace Svelto.ECS | |||
public void RemoveEntity<T>(int entityID, int groupID) where T : IEntityDescriptor, new() | |||
{ | |||
#if DEBUG && !PROFILER | |||
_weakReference.Target.CheckRemoveEntityID(new EGID(entityID, groupID), EntityDescriptorTemplate<T>.descriptor); | |||
#endif | |||
_weakReference.Target.QueueEntitySubmitOperation<T>( | |||
new EntitySubmitOperation(EntitySubmitOperationType.Remove, entityID, groupID, -1, | |||
EntityDescriptorTemplate<T>.descriptor.entitiesToBuild, typeof(T))); | |||
@@ -29,9 +28,8 @@ namespace Svelto.ECS | |||
public void RemoveEntity<T>(int entityID, ExclusiveGroup.ExclusiveGroupStruct groupID) where T : IEntityDescriptor, new() | |||
{ | |||
#if DEBUG && !PROFILER | |||
_weakReference.Target.CheckRemoveEntityID(new EGID(entityID, (int) groupID), EntityDescriptorTemplate<T>.descriptor); | |||
#endif | |||
_weakReference.Target.QueueEntitySubmitOperation<T>( | |||
new EntitySubmitOperation(EntitySubmitOperationType.Remove, entityID, (int)groupID, -1, | |||
EntityDescriptorTemplate<T>.descriptor.entitiesToBuild, typeof(T))); | |||
@@ -39,9 +37,8 @@ namespace Svelto.ECS | |||
public void RemoveEntity<T>(EGID entityEGID) where T : IEntityDescriptor, new() | |||
{ | |||
#if DEBUG && !PROFILER | |||
_weakReference.Target.CheckRemoveEntityID(entityEGID, EntityDescriptorTemplate<T>.descriptor); | |||
#endif | |||
_weakReference.Target.QueueEntitySubmitOperation<T>( | |||
new EntitySubmitOperation(EntitySubmitOperationType.Remove, entityEGID.entityID, entityEGID.groupID, | |||
-1, EntityDescriptorTemplate<T>.descriptor.entitiesToBuild, typeof(T))); | |||
@@ -1,11 +1,14 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
#if DEBUG && !PROFILER | |||
using System.Reflection; | |||
#endif | |||
using System.Diagnostics; | |||
using Svelto.DataStructures; | |||
using Svelto.ECS.Internal; | |||
using Svelto.Utilities; | |||
using System.Reflection; | |||
#if DEBUG && !PROFILER | |||
#define _USE_IT | |||
#endif | |||
namespace Svelto.ECS | |||
{ | |||
@@ -15,49 +18,49 @@ namespace Svelto.ECS | |||
{ | |||
_initializer = defaultIt; | |||
#if DEBUG && !PROFILER | |||
if (needsReflection == false && ENTITY_VIEW_TYPE != typeof(EntityInfoView) ) | |||
{ | |||
CheckFields(ENTITY_VIEW_TYPE); | |||
} | |||
#endif | |||
CheckFields(ENTITY_VIEW_TYPE); | |||
if (needsReflection == true) | |||
{ | |||
EntityView<T>.InitCache(); | |||
} | |||
} | |||
#if DEBUG && !PROFILER | |||
[Conditional("_USE_IT")] | |||
static void CheckFields(Type type) | |||
{ | |||
var fields = type.GetFields(BindingFlags.Public | | |||
BindingFlags.Instance); | |||
for (int i = fields.Length - 1; i >= 0; --i) | |||
if (needsReflection == false && ENTITY_VIEW_TYPE != typeof(EntityInfoView)) | |||
{ | |||
var field = fields[i]; | |||
var fields = type.GetFields(BindingFlags.Public | | |||
BindingFlags.Instance); | |||
var fieldFieldType = field.FieldType; | |||
SubCheckFields(fieldFieldType); | |||
} | |||
if (type.Assembly == Assembly.GetCallingAssembly() && type != EGIDType) | |||
{ | |||
var methods = type.GetMethods(BindingFlags.Public | | |||
BindingFlags.Instance | BindingFlags.DeclaredOnly); | |||
for (int i = fields.Length - 1; i >= 0; --i) | |||
{ | |||
var field = fields[i]; | |||
var properties = type.GetProperties(BindingFlags.Public | | |||
BindingFlags.Instance | BindingFlags.DeclaredOnly); | |||
var fieldFieldType = field.FieldType; | |||
if (methods.Length > properties.Length + 1) | |||
throw new EntityStructException(type); | |||
SubCheckFields(fieldFieldType); | |||
} | |||
for (int i = properties.Length - 1; i >= 0; --i) | |||
if (type.Assembly == Assembly.GetCallingAssembly() && type != EGIDType) | |||
{ | |||
var propertyInfo = properties[i]; | |||
var methods = type.GetMethods(BindingFlags.Public | | |||
BindingFlags.Instance | BindingFlags.DeclaredOnly); | |||
var fieldFieldType = propertyInfo.PropertyType; | |||
SubCheckFields(fieldFieldType); | |||
var properties = type.GetProperties(BindingFlags.Public | | |||
BindingFlags.Instance | BindingFlags.DeclaredOnly); | |||
if (methods.Length > properties.Length + 1) | |||
throw new EntityStructException(type); | |||
for (int i = properties.Length - 1; i >= 0; --i) | |||
{ | |||
var propertyInfo = properties[i]; | |||
var fieldFieldType = propertyInfo.PropertyType; | |||
SubCheckFields(fieldFieldType); | |||
} | |||
} | |||
} | |||
} | |||
@@ -76,7 +79,7 @@ namespace Svelto.ECS | |||
throw new EntityStructException(fieldFieldType); | |||
} | |||
#endif | |||
public void BuildEntityAndAddToList(ref ITypeSafeDictionary dictionary, EGID entityID, object[] implementors) | |||
{ | |||