From 018fd2cd2f75d8ebeb8988793fbfc0c1cfc0530a Mon Sep 17 00:00:00 2001 From: sebas77 Date: Wed, 25 Oct 2017 17:31:51 +0100 Subject: [PATCH] - some small optimizations - clean up - the structnode ids must be int --- ECS/EngineNodeDB.cs | 40 +++++++++---------- ECS/EnginesRoot.cs | 4 +- ECS/EntityDescriptor.cs | 31 +++++++------- .../Unity/UnitySumbmissionNodeScheduler.cs | 2 +- ECS/GenericEntityDescriptor.cs | 2 +- ECS/GenericEntityDescriptorHolder.cs | 4 +- ECS/ICallBackOnAddEngine.cs | 2 +- ECS/IEngineNodeDB.cs | 2 +- ECS/IEnginesRoot.cs | 4 +- ECS/INode.cs | 4 +- ECS/NodeSubmissionScheduler.cs | 2 +- .../EngineProfiler/EngineProfilerInspector.cs | 2 + .../EngineProfiler/EngineProfilerMenuItem.cs | 2 + .../Editor/EngineProfiler/EnginesMonitor.cs | 4 +- .../EngineProfiler/ProfilerEditorLayout.cs | 4 +- ECS/Profiler/EngineProfilerBehaviour.cs | 2 + ECS/Sequencer.cs | 2 +- ECS/SingleNodeEngine.cs | 2 +- ECS/StructNodes.cs | 2 +- 19 files changed, 63 insertions(+), 54 deletions(-) diff --git a/ECS/EngineNodeDB.cs b/ECS/EngineNodeDB.cs index c10540f..0bb5bb8 100644 --- a/ECS/EngineNodeDB.cs +++ b/ECS/EngineNodeDB.cs @@ -19,20 +19,24 @@ namespace Svelto.ECS { var type = typeof(T); - if (_nodesDB.ContainsKey(type) == false) + FasterList nodes; + + if (_nodesDB.TryGetValue(type, out nodes) == false) return RetrieveEmptyNodeList(); - return new FasterReadOnlyListCast(_nodesDB[type]); + return new FasterReadOnlyListCast(nodes); } public ReadOnlyDictionary QueryIndexableNodes() where T:INode { var type = typeof(T); - if (_nodesDBdic.ContainsKey(type) == false) + Dictionary nodes; + + if (_nodesDBdic.TryGetValue(type, out nodes) == false) return _defaultEmptyNodeDict; - return new ReadOnlyDictionary(_nodesDBdic[type]); + return new ReadOnlyDictionary(nodes); } public T QueryMetaNode(int metaEntityID) where T : INode @@ -49,10 +53,12 @@ namespace Svelto.ECS { var type = typeof(T); - if (_metaNodesDB.ContainsKey(type) == false) + FasterList nodes; + + if (_metaNodesDB.TryGetValue(type, out nodes) == false) return RetrieveEmptyNodeList(); - return new FasterReadOnlyListCast(_metaNodesDB[type]); + return new FasterReadOnlyListCast(nodes); } public bool TryQueryNode(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 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 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 QueryGroupNodes(int groupID) where T : INode - { - var type = typeof(T); - - if (_nodesDB.ContainsKey(type) == false) - return RetrieveEmptyNodeList(); - - return new FasterReadOnlyListCast(_nodesDB[type]); - } - static FasterReadOnlyListCast RetrieveEmptyNodeList() where T : INode { return FasterReadOnlyListCast.DefaultList; diff --git a/ECS/EnginesRoot.cs b/ECS/EnginesRoot.cs index ad0769c..22dd0f7 100644 --- a/ECS/EnginesRoot.cs +++ b/ECS/EnginesRoot.cs @@ -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; #if ENGINE_PROFILER_ENABLED && UNITY_EDITOR @@ -297,7 +295,7 @@ namespace Svelto.ECS /// /// /// - public void BuildEntityInGroup(short entityID, short groupID, + public void BuildEntityInGroup(int entityID, int groupID, EntityDescriptor ed) { var entityNodes = ed.BuildNodes(entityID, diff --git a/ECS/EntityDescriptor.cs b/ECS/EntityDescriptor.cs index 4f09db1..2cfd757 100644 --- a/ECS/EntityDescriptor.cs +++ b/ECS/EntityDescriptor.cs @@ -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 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; + } } } } diff --git a/ECS/Extensions/Unity/UnitySumbmissionNodeScheduler.cs b/ECS/Extensions/Unity/UnitySumbmissionNodeScheduler.cs index c211f73..9241fdf 100644 --- a/ECS/Extensions/Unity/UnitySumbmissionNodeScheduler.cs +++ b/ECS/Extensions/Unity/UnitySumbmissionNodeScheduler.cs @@ -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; diff --git a/ECS/GenericEntityDescriptor.cs b/ECS/GenericEntityDescriptor.cs index 1be1793..472cdff 100644 --- a/ECS/GenericEntityDescriptor.cs +++ b/ECS/GenericEntityDescriptor.cs @@ -1,4 +1,4 @@ -namespace Svelto.ECS +namespace Svelto.ECS { public class GenericEntityDescriptor : EntityDescriptor where T : NodeWithID, new() diff --git a/ECS/GenericEntityDescriptorHolder.cs b/ECS/GenericEntityDescriptorHolder.cs index 4758fa2..4e51570 100644 --- a/ECS/GenericEntityDescriptorHolder.cs +++ b/ECS/GenericEntityDescriptorHolder.cs @@ -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); } } -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/ECS/ICallBackOnAddEngine.cs b/ECS/ICallBackOnAddEngine.cs index 815d59d..e77bf6a 100644 --- a/ECS/ICallBackOnAddEngine.cs +++ b/ECS/ICallBackOnAddEngine.cs @@ -1,4 +1,4 @@ -namespace Svelto.ECS +namespace Svelto.ECS { public interface ICallBackOnAddEngine { diff --git a/ECS/IEngineNodeDB.cs b/ECS/IEngineNodeDB.cs index 5e8a154..e2ee74f 100644 --- a/ECS/IEngineNodeDB.cs +++ b/ECS/IEngineNodeDB.cs @@ -1,4 +1,4 @@ -using Svelto.DataStructures; +using Svelto.DataStructures; namespace Svelto.ECS { diff --git a/ECS/IEnginesRoot.cs b/ECS/IEnginesRoot.cs index 544fbc6..14f5957 100644 --- a/ECS/IEnginesRoot.cs +++ b/ECS/IEnginesRoot.cs @@ -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); } } diff --git a/ECS/INode.cs b/ECS/INode.cs index 3f3999c..f9b0c81 100644 --- a/ECS/INode.cs +++ b/ECS/INode.cs @@ -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 diff --git a/ECS/NodeSubmissionScheduler.cs b/ECS/NodeSubmissionScheduler.cs index 7f04648..dc86bf2 100644 --- a/ECS/NodeSubmissionScheduler.cs +++ b/ECS/NodeSubmissionScheduler.cs @@ -1,4 +1,4 @@ -using System; +using System; namespace Svelto.ECS.NodeSchedulers { diff --git a/ECS/Profiler/Editor/EngineProfiler/EngineProfilerInspector.cs b/ECS/Profiler/Editor/EngineProfiler/EngineProfilerInspector.cs index a691298..b1fb2da 100644 --- a/ECS/Profiler/Editor/EngineProfiler/EngineProfilerInspector.cs +++ b/ECS/Profiler/Editor/EngineProfiler/EngineProfilerInspector.cs @@ -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 \ No newline at end of file diff --git a/ECS/Profiler/Editor/EngineProfiler/EngineProfilerMenuItem.cs b/ECS/Profiler/Editor/EngineProfiler/EngineProfilerMenuItem.cs index d7c6b93..c733c48 100644 --- a/ECS/Profiler/Editor/EngineProfiler/EngineProfilerMenuItem.cs +++ b/ECS/Profiler/Editor/EngineProfiler/EngineProfilerMenuItem.cs @@ -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 \ No newline at end of file diff --git a/ECS/Profiler/Editor/EngineProfiler/EnginesMonitor.cs b/ECS/Profiler/Editor/EngineProfiler/EnginesMonitor.cs index 0d568a4..48ba030 100644 --- a/ECS/Profiler/Editor/EngineProfiler/EnginesMonitor.cs +++ b/ECS/Profiler/Editor/EngineProfiler/EnginesMonitor.cs @@ -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 \ No newline at end of file diff --git a/ECS/Profiler/Editor/EngineProfiler/ProfilerEditorLayout.cs b/ECS/Profiler/Editor/EngineProfiler/ProfilerEditorLayout.cs index d012cac..e9b2044 100644 --- a/ECS/Profiler/Editor/EngineProfiler/ProfilerEditorLayout.cs +++ b/ECS/Profiler/Editor/EngineProfiler/ProfilerEditorLayout.cs @@ -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 \ No newline at end of file diff --git a/ECS/Profiler/EngineProfilerBehaviour.cs b/ECS/Profiler/EngineProfilerBehaviour.cs index c924d6c..a350ae7 100644 --- a/ECS/Profiler/EngineProfilerBehaviour.cs +++ b/ECS/Profiler/EngineProfilerBehaviour.cs @@ -1,3 +1,4 @@ +#if UNITY_EDITOR using System; using System.Collections.Generic; using UnityEngine; @@ -17,3 +18,4 @@ namespace Svelto.ECS.Profiler } } } +#endif \ No newline at end of file diff --git a/ECS/Sequencer.cs b/ECS/Sequencer.cs index f9d0efd..90256a0 100644 --- a/ECS/Sequencer.cs +++ b/ECS/Sequencer.cs @@ -1,4 +1,4 @@ -using System; +using System; using Steps = System.Collections.Generic.Dictionary>; namespace Svelto.ECS diff --git a/ECS/SingleNodeEngine.cs b/ECS/SingleNodeEngine.cs index e641f32..f4c58a1 100644 --- a/ECS/SingleNodeEngine.cs +++ b/ECS/SingleNodeEngine.cs @@ -1,4 +1,4 @@ -using Svelto.ECS.Internal; +using Svelto.ECS.Internal; namespace Svelto.ECS { diff --git a/ECS/StructNodes.cs b/ECS/StructNodes.cs index 582abab..85ca30d 100644 --- a/ECS/StructNodes.cs +++ b/ECS/StructNodes.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using Svelto.DataStructures; using Svelto.ECS.Internal;