Browse Source

- some small optimizations

- clean up
- the structnode ids must be int
tags/Rel1
sebas77 7 years ago
parent
commit
018fd2cd2f
19 changed files with 63 additions and 54 deletions
  1. +19
    -21
      ECS/EngineNodeDB.cs
  2. +1
    -3
      ECS/EnginesRoot.cs
  3. +17
    -14
      ECS/EntityDescriptor.cs
  4. +1
    -1
      ECS/Extensions/Unity/UnitySumbmissionNodeScheduler.cs
  5. +1
    -1
      ECS/GenericEntityDescriptor.cs
  6. +3
    -1
      ECS/GenericEntityDescriptorHolder.cs
  7. +1
    -1
      ECS/ICallBackOnAddEngine.cs
  8. +1
    -1
      ECS/IEngineNodeDB.cs
  9. +1
    -3
      ECS/IEnginesRoot.cs
  10. +2
    -2
      ECS/INode.cs
  11. +1
    -1
      ECS/NodeSubmissionScheduler.cs
  12. +2
    -0
      ECS/Profiler/Editor/EngineProfiler/EngineProfilerInspector.cs
  13. +2
    -0
      ECS/Profiler/Editor/EngineProfiler/EngineProfilerMenuItem.cs
  14. +3
    -1
      ECS/Profiler/Editor/EngineProfiler/EnginesMonitor.cs
  15. +3
    -1
      ECS/Profiler/Editor/EngineProfiler/ProfilerEditorLayout.cs
  16. +2
    -0
      ECS/Profiler/EngineProfilerBehaviour.cs
  17. +1
    -1
      ECS/Sequencer.cs
  18. +1
    -1
      ECS/SingleNodeEngine.cs
  19. +1
    -1
      ECS/StructNodes.cs

+ 19
- 21
ECS/EngineNodeDB.cs View File

@@ -19,20 +19,24 @@ namespace Svelto.ECS
{
var type = typeof(T);

if (_nodesDB.ContainsKey(type) == false)
FasterList<INode> nodes;

if (_nodesDB.TryGetValue(type, out nodes) == false)
return RetrieveEmptyNodeList<T>();

return new FasterReadOnlyListCast<INode, T>(_nodesDB[type]);
return new FasterReadOnlyListCast<INode, T>(nodes);
}

public ReadOnlyDictionary<int, INode> QueryIndexableNodes<T>() where T:INode
{
var type = typeof(T);

if (_nodesDBdic.ContainsKey(type) == false)
Dictionary<int, INode> nodes;

if (_nodesDBdic.TryGetValue(type, out nodes) == false)
return _defaultEmptyNodeDict;

return new ReadOnlyDictionary<int, INode>(_nodesDBdic[type]);
return new ReadOnlyDictionary<int, INode>(nodes);
}

public T QueryMetaNode<T>(int metaEntityID) where T : INode
@@ -49,10 +53,12 @@ namespace Svelto.ECS
{
var type = typeof(T);

if (_metaNodesDB.ContainsKey(type) == false)
FasterList<INode> nodes;

if (_metaNodesDB.TryGetValue(type, out nodes) == false)
return RetrieveEmptyNodeList<T>();

return new FasterReadOnlyListCast<INode, T>(_metaNodesDB[type]);
return new FasterReadOnlyListCast<INode, T>(nodes);
}

public bool TryQueryNode<T>(int ID, out T node) where T:INode
@@ -61,8 +67,10 @@ namespace Svelto.ECS

INode internalNode;

if (_nodesDBdic.ContainsKey(type) &&
_nodesDBdic[type].TryGetValue(ID, out internalNode))
Dictionary<int, INode> nodes;

if (_nodesDBdic.TryGetValue(type, out nodes) &&
nodes.TryGetValue(ID, out internalNode))
{
node = (T)internalNode;

@@ -78,25 +86,15 @@ namespace Svelto.ECS
{
var type = typeof(T);

INode internalNode;
INode internalNode; Dictionary<int, INode> nodes;

if (_nodesDBdic.ContainsKey(type) &&
_nodesDBdic[type].TryGetValue(ID, out internalNode))
if (_nodesDBdic.TryGetValue(type, out nodes) &&
nodes.TryGetValue(ID, out internalNode))
return (T)internalNode;

throw new Exception("Node Not Found");
}

public FasterReadOnlyListCast<INode, T> QueryGroupNodes<T>(int groupID) where T : INode
{
var type = typeof(T);

if (_nodesDB.ContainsKey(type) == false)
return RetrieveEmptyNodeList<T>();

return new FasterReadOnlyListCast<INode, T>(_nodesDB[type]);
}

static FasterReadOnlyListCast<INode, T> RetrieveEmptyNodeList<T>() where T : INode
{
return FasterReadOnlyListCast<INode, T>.DefaultList;


+ 1
- 3
ECS/EnginesRoot.cs View File

@@ -1,10 +1,8 @@
using System;
using System.Collections;
using System.Collections.Generic;
using Svelto.DataStructures;
using Svelto.ECS.Internal;
using Svelto.ECS.NodeSchedulers;
using UnityEngine;
using WeakReference = Svelto.DataStructures.WeakReference<Svelto.ECS.EnginesRoot>;

#if ENGINE_PROFILER_ENABLED && UNITY_EDITOR
@@ -297,7 +295,7 @@ namespace Svelto.ECS
/// <param name="entityID"></param>
/// <param name="groupID"></param>
/// <param name="ed"></param>
public void BuildEntityInGroup(short entityID, short groupID,
public void BuildEntityInGroup(int entityID, int groupID,
EntityDescriptor ed)
{
var entityNodes = ed.BuildNodes(entityID,


+ 17
- 14
ECS/EntityDescriptor.cs View File

@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Reflection;
using Svelto.DataStructures;
@@ -32,20 +32,23 @@ namespace Svelto.ECS
for (int index = 0; index < implementors.Length; index++)
{
var implementor = implementors[index];
if (implementor == null) continue;

if (implementor is IRemoveEntityComponent)
_removingImplementors.Add(implementor as IRemoveEntityComponent);
if (implementor is IDisableEntityComponent)
_disablingImplementors.Add(implementor as IDisableEntityComponent);
if (implementor is IEnableEntityComponent)
_enablingImplementors.Add(implementor as IEnableEntityComponent);

var interfaces = implementor.GetType().GetInterfaces();

for (int iindex = 0; iindex < interfaces.Length; iindex++)
if (implementor == null)
Utility.Console.LogWarning(
"Null implementor, are you using a wild GetComponents<Monobehaviour> to fetch it?");
else
{
_implementorsByType[interfaces[iindex]] = implementor;
if (implementor is IRemoveEntityComponent)
_removingImplementors.Add(implementor as IRemoveEntityComponent);
if (implementor is IDisableEntityComponent)
_disablingImplementors.Add(implementor as IDisableEntityComponent);
if (implementor is IEnableEntityComponent)
_enablingImplementors.Add(implementor as IEnableEntityComponent);

var interfaces = implementor.GetType().GetInterfaces();
for (int iindex = 0; iindex < interfaces.Length; iindex++)
{
_implementorsByType[interfaces[iindex]] = implementor;
}
}
}
}


+ 1
- 1
ECS/Extensions/Unity/UnitySumbmissionNodeScheduler.cs View File

@@ -1,4 +1,4 @@
#if UNITY_5 || UNITY_5_3_OR_NEWER
#if UNITY_5 || UNITY_5_3_OR_NEWER
using System;
using System.Collections;
using UnityEngine;


+ 1
- 1
ECS/GenericEntityDescriptor.cs View File

@@ -1,4 +1,4 @@
namespace Svelto.ECS
namespace Svelto.ECS
{
public class GenericEntityDescriptor<T> : EntityDescriptor
where T : NodeWithID, new()


+ 3
- 1
ECS/GenericEntityDescriptorHolder.cs View File

@@ -1,3 +1,4 @@
#if UNITY_5 || UNITY_5_3_OR_NEWER
using System;

namespace Svelto.ECS
@@ -25,4 +26,5 @@ namespace Svelto.ECS
return (T)Activator.CreateInstance(typeof(T), implementors);
}
}
}
}
#endif

+ 1
- 1
ECS/ICallBackOnAddEngine.cs View File

@@ -1,4 +1,4 @@
namespace Svelto.ECS
namespace Svelto.ECS
{
public interface ICallBackOnAddEngine
{


+ 1
- 1
ECS/IEngineNodeDB.cs View File

@@ -1,4 +1,4 @@
using Svelto.DataStructures;
using Svelto.DataStructures;

namespace Svelto.ECS
{


+ 1
- 3
ECS/IEnginesRoot.cs View File

@@ -1,5 +1,3 @@
using Svelto.ECS.Internal;

namespace Svelto.ECS
{
public interface IEnginesRoot
@@ -13,6 +11,6 @@ namespace Svelto.ECS

void BuildMetaEntity(int metaEntityID, EntityDescriptor ED);

void BuildEntityInGroup(short entityID, short groupID, EntityDescriptor ED);
void BuildEntityInGroup(int entityID, int groupID, EntityDescriptor ED);
}
}

+ 2
- 2
ECS/INode.cs View File

@@ -10,12 +10,12 @@ namespace Svelto.ECS

public interface IStructNodeWithID : INode
{
short ID { get; set; }
int ID { get; set; }
}

public interface IGroupedStructNodeWithID : IStructNodeWithID
{
short groupID { get; set; }
int groupID { get; set; }
}

public class NodeWithID: INodeWithID


+ 1
- 1
ECS/NodeSubmissionScheduler.cs View File

@@ -1,4 +1,4 @@
using System;
using System;

namespace Svelto.ECS.NodeSchedulers
{


+ 2
- 0
ECS/Profiler/Editor/EngineProfiler/EngineProfilerInspector.cs View File

@@ -1,3 +1,4 @@
#if UNITY_EDITOR
using System;
using System.Collections.Generic;
using UnityEditor;
@@ -239,3 +240,4 @@ namespace Svelto.ECS.Profiler
}
#endregion
}
#endif

+ 2
- 0
ECS/Profiler/Editor/EngineProfiler/EngineProfilerMenuItem.cs View File

@@ -1,3 +1,4 @@
#if UNITY_EDITOR
using UnityEditor;

//This profiler is based on the Entitas Visual Debugging tool
@@ -20,3 +21,4 @@ namespace Svelto.ECS.Profiler
}
}
}
#endif

+ 3
- 1
ECS/Profiler/Editor/EngineProfiler/EnginesMonitor.cs View File

@@ -1,4 +1,5 @@
using System.Linq;
#if UNITY_EDITOR
using System.Linq;
using UnityEditor;
using UnityEngine;

@@ -130,3 +131,4 @@ namespace Svelto.ECS.Profiler
}
}
}
#endif

+ 3
- 1
ECS/Profiler/Editor/EngineProfiler/ProfilerEditorLayout.cs View File

@@ -1,4 +1,5 @@
using UnityEditor;
#if UNITY_EDITOR
using UnityEditor;
using UnityEngine;

//This profiler is based on the Entitas Visual Debugging tool
@@ -63,3 +64,4 @@ namespace Svelto.ECS.Profiler
}
}
}
#endif

+ 2
- 0
ECS/Profiler/EngineProfilerBehaviour.cs View File

@@ -1,3 +1,4 @@
#if UNITY_EDITOR
using System;
using System.Collections.Generic;
using UnityEngine;
@@ -17,3 +18,4 @@ namespace Svelto.ECS.Profiler
}
}
}
#endif

+ 1
- 1
ECS/Sequencer.cs View File

@@ -1,4 +1,4 @@
using System;
using System;
using Steps = System.Collections.Generic.Dictionary<Svelto.ECS.IEngine, System.Collections.Generic.Dictionary<System.Enum, Svelto.ECS.IStep[]>>;

namespace Svelto.ECS


+ 1
- 1
ECS/SingleNodeEngine.cs View File

@@ -1,4 +1,4 @@
using Svelto.ECS.Internal;
using Svelto.ECS.Internal;

namespace Svelto.ECS
{


+ 1
- 1
ECS/StructNodes.cs View File

@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using Svelto.DataStructures;
using Svelto.ECS.Internal;


Loading…
Cancel
Save