Browse Source

Improve debug info

tags/2.7
sebas77 6 years ago
parent
commit
37c15fa8ae
5 changed files with 79 additions and 56 deletions
  1. +3
    -6
      Svelto.ECS/EnginesRoot.Entities.cs
  2. +15
    -16
      Svelto.ECS/EnginesRoot.Submission.cs
  3. +11
    -12
      Svelto.ECS/EntityBuilder.cs
  4. +20
    -18
      Svelto.ECS/EntityViewUtility.cs
  5. +30
    -4
      Svelto.ECS/GenericEntityDescriptor.cs

+ 3
- 6
Svelto.ECS/EnginesRoot.Entities.cs View File

@@ -61,10 +61,8 @@ namespace Svelto.ECS
CheckAddEntityID(entityID, entityDescriptor);

var dic = EntityFactory.BuildGroupedEntities(entityID,
_groupedEntityToAdd.current,
descriptorEntitiesToBuild,
implementors);
var dic = EntityFactory.BuildGroupedEntities(entityID, _groupedEntityToAdd.current,
descriptorEntitiesToBuild, implementors);
return new EntityStructInitializer(entityID, dic);
}
@@ -86,13 +84,12 @@ namespace Svelto.ECS
if (_groupedEntityToAdd.current.TryGetValue(groupID, out @groupBuffer) == false)
@groupBuffer = _groupedEntityToAdd.current[groupID] = new Dictionary<Type, ITypeSafeDictionary>();

ITypeSafeDictionary dbList;

for (var index = 0; index < count; index++)
{
var entityViewBuilder = entityViewsToBuild[index];
var entityViewType = entityViewBuilder.GetEntityType();

ITypeSafeDictionary dbList;
if (group.TryGetValue(entityViewType, out dbList) == false)
group[entityViewType] = entityViewBuilder.Preallocate(ref dbList, size);
else


+ 15
- 16
Svelto.ECS/EnginesRoot.Submission.cs View File

@@ -72,35 +72,34 @@ namespace Svelto.ECS
}
}
}
}
try
if (_groupedEntityToAdd.current.Count > 0)
{
if (_groupedEntityToAdd.current.Count > 0)
using (profiler.Sample("Add"))
{
using (profiler.Sample("Add"))
{
//use other as source from now on current will be use to write new entityViews
_groupedEntityToAdd.Swap();
//use other as source from now on current will be use to write new entityViews
_groupedEntityToAdd.Swap();

try
{
//Note: if N entity of the same type are added on the same frame the Add callback is called N
//times on the same frame. if the Add callback builds a new entity, that entity will not
//be available in the database until the N callbacks are done solving it could be complicated as
//callback and database update must be interleaved.
AddEntityViewsToTheDBAndSuitableEngines(_groupedEntityToAdd.other);
}
catch (Exception e)
{
Console.LogException(e);
}
finally
{
//other can be cleared now, but let's avoid deleting the dictionary every time
_groupedEntityToAdd.ClearOther();
}
}
}
catch (Exception e)
{
Console.LogException(e);
}
finally
{
//other can be cleared now, but let's avoid deleting the dictionary every time
_groupedEntityToAdd.ClearOther();
}
}
}


+ 11
- 12
Svelto.ECS/EntityBuilder.cs View File

@@ -91,17 +91,16 @@ namespace Svelto.ECS
{
DBC.ECS.Check.Require(implementors != null, "Implementors not found while building an EntityView");
DBC.ECS.Check.Require(castedDic.ContainsKey(entityID.entityID) == false,
"building an entity with already used entity id! id".FastConcat(entityID).FastConcat(" ", DESCRIPTOR_NAME));
"building an entity with already used entity id! id".FastConcat(entityID).FastConcat(" ", ENTITY_VIEW_NAME));

T lentityView;
EntityView<T>.BuildEntityView(entityID, out lentityView);
T entityView;
EntityView<T>.BuildEntityView(entityID, out entityView);

this.FillEntityView(ref lentityView
this.FillEntityView(ref entityView
, entityViewBlazingFastReflection
, implementors
, DESCRIPTOR_NAME);
, implementors);
castedDic.Add(entityID.entityID, ref lentityView);
castedDic.Add(entityID.entityID, ref entityView);
}
else
{
@@ -136,11 +135,11 @@ namespace Svelto.ECS
get { return EntityView<T>.cachedFields; }
}
static readonly Type ENTITY_VIEW_TYPE = typeof(T);
static readonly string DESCRIPTOR_NAME = ENTITY_VIEW_TYPE.ToString();
static readonly bool needsReflection = typeof(IEntityViewStruct).IsAssignableFrom(typeof(T));
static readonly T defaultIt = default(T);
static readonly Type EGIDType = typeof(Svelto.ECS.EGID);
static readonly Type ENTITY_VIEW_TYPE = typeof(T);
static readonly string ENTITY_VIEW_NAME = ENTITY_VIEW_TYPE.ToString();
static readonly bool needsReflection = typeof(IEntityViewStruct).IsAssignableFrom(typeof(T));
static readonly T defaultIt = default(T);
static readonly Type EGIDType = typeof(EGID);

internal T _initializer;
}


+ 20
- 18
Svelto.ECS/EntityViewUtility.cs View File

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

static class EntityViewUtility
@@ -9,8 +10,7 @@ static class EntityViewUtility
public static void FillEntityView<T>(this IEntityBuilder entityBuilder
, ref T entityView
, FasterList<KeyValuePair<Type, ActionCast<T>>> entityViewBlazingFastReflection
, object[] implementors
, string entityDescriptorName)
, object[] implementors)
{
int count;

@@ -35,10 +35,13 @@ static class EntityViewUtility
{
var componentType = interfaces[iindex];
#if DEBUG && !PROFILER
Tuple<object, int> implementorHolder;
Tuple<object, int> implementorData;

if (implementorsByType.TryGetValue(componentType, out implementorHolder))
implementorHolder.numberOfImplementations++;
if (implementorsByType.TryGetValue(componentType, out implementorData))
{
implementorData.numberOfImplementations++;
implementorsByType[componentType] = implementorData;
}
else
implementorsByType[componentType] = new Tuple<object, int>(implementor, 1);
#else
@@ -49,7 +52,7 @@ static class EntityViewUtility
#if DEBUG && !PROFILER
else
{
Svelto.Utilities.Console.Log(NULL_IMPLEMENTOR_ERROR.FastConcat("Type ", entityDescriptorName, " entityView ",
Svelto.Utilities.Console.Log(NULL_IMPLEMENTOR_ERROR.FastConcat(" entityView ",
entityBuilder.GetEntityType().ToString()));
}
#endif
@@ -68,20 +71,17 @@ static class EntityViewUtility

if (implementorsByType.TryGetValue(fieldType, out component) == false)
{
var e = new Exception(NOT_FOUND_EXCEPTION + " Component Type: " + fieldType.Name +
" - EntityView: " + entityBuilder.GetEntityType().Name +
" - EntityDescriptor " + entityDescriptorName);
var e = new ECSException(NOT_FOUND_EXCEPTION + " Component Type: " + fieldType.Name +
" - EntityView: " + entityBuilder.GetEntityType().Name);

throw e;
}
#if DEBUG && !PROFILER
if (component.numberOfImplementations > 1)
Svelto.Utilities.Console.LogError(DUPLICATE_IMPLEMENTOR_ERROR.FastConcat(
"Component Type: ", fieldType.Name,
" implementor: ",
component.implementorType.ToString()) +
" - EntityView: " +
entityBuilder.GetEntityType().Name + " - EntityDescriptor " + entityDescriptorName);
throw new ECSException(DUPLICATE_IMPLEMENTOR_ERROR.FastConcat(
"Component Type: ", fieldType.Name, " implementor: ",
component.implementorType.ToString()) + " - EntityView: " +
entityBuilder.GetEntityType().Name);
#endif
#if DEBUG && !PROFILER
fieldSetter.Value(ref entityView, component.implementorType);
@@ -94,7 +94,7 @@ static class EntityViewUtility
}
//this is used to avoid newing a dictionary every time, but it's used locally only and it's clearead for each use
//this is used to avoid newing a dictionary every time, but it's used locally only and it's cleared for each use
#if DEBUG && !PROFILER
static readonly Dictionary<Type, Tuple<object, int>> implementorsByType =
new Dictionary<Type, Tuple<object, int>>();
@@ -118,10 +118,12 @@ static class EntityViewUtility
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. ";
"<color=orange>Svelto.ECS</color> the same component is implemented with more than one implementor. This is " +
"considered an error and MUST be fixed. ";

const string NULL_IMPLEMENTOR_ERROR =
"<color=orange>Svelto.ECS</color> Null implementor, please be careful about the implementors passed to avoid performance loss ";
"<color=orange>Svelto.ECS</color> Null implementor, please be careful about the implementors passed to avoid " +
"performance loss ";

const string NOT_FOUND_EXCEPTION = "<color=orange>Svelto.ECS</color> Implementor not found for an EntityView. ";
}

+ 30
- 4
Svelto.ECS/GenericEntityDescriptor.cs View File

@@ -37,7 +37,12 @@
{
static GenericEntityDescriptor()
{
_entityBuilders = new IEntityBuilder[] {new EntityBuilder<T>(), new EntityBuilder<U>(), new EntityBuilder<V>()};
_entityBuilders = new IEntityBuilder[]
{
new EntityBuilder<T>(),
new EntityBuilder<U>(),
new EntityBuilder<V>()
};
}

public IEntityBuilder[] entitiesToBuild
@@ -55,7 +60,13 @@
{
static GenericEntityDescriptor()
{
_entityBuilders = new IEntityBuilder[] {new EntityBuilder<T>(), new EntityBuilder<U>(), new EntityBuilder<V>(), new EntityBuilder<W>()};
_entityBuilders = new IEntityBuilder[]
{
new EntityBuilder<T>(),
new EntityBuilder<U>(),
new EntityBuilder<V>(),
new EntityBuilder<W>()
};
}

public IEntityBuilder[] entitiesToBuild
@@ -74,7 +85,14 @@
{
static GenericEntityDescriptor()
{
_entityBuilders = new IEntityBuilder[] {new EntityBuilder<T>(), new EntityBuilder<U>(), new EntityBuilder<V>(), new EntityBuilder<W>(), new EntityBuilder<X>()};
_entityBuilders = new IEntityBuilder[]
{
new EntityBuilder<T>(),
new EntityBuilder<U>(),
new EntityBuilder<V>(),
new EntityBuilder<W>(),
new EntityBuilder<X>()
};
}

public IEntityBuilder[] entitiesToBuild
@@ -94,7 +112,15 @@
{
static GenericEntityDescriptor()
{
_entityBuilders = new IEntityBuilder[] {new EntityBuilder<T>(), new EntityBuilder<U>(), new EntityBuilder<V>(), new EntityBuilder<W>(), new EntityBuilder<X>(), new EntityBuilder<Y>()};
_entityBuilders = new IEntityBuilder[]
{
new EntityBuilder<T>(),
new EntityBuilder<U>(),
new EntityBuilder<V>(),
new EntityBuilder<W>(),
new EntityBuilder<X>(),
new EntityBuilder<Y>()
};
}

public IEntityBuilder[] entitiesToBuild


Loading…
Cancel
Save