From bf5678569a09bc3c9f9efd489c79a12794a63344 Mon Sep 17 00:00:00 2001 From: sebas77 Date: Sat, 21 May 2016 12:28:09 +0100 Subject: [PATCH] - Add Dispatcher without extra parameters --- ECS/Dispatcher/Dispatcher.cs | 20 ++++++++++++++++++++ ECS/EnginesRoot.cs | 13 +++++-------- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/ECS/Dispatcher/Dispatcher.cs b/ECS/Dispatcher/Dispatcher.cs index a0ef5f2..8682a53 100644 --- a/ECS/Dispatcher/Dispatcher.cs +++ b/ECS/Dispatcher/Dispatcher.cs @@ -17,3 +17,23 @@ public class Dispatcher readonly S _sender; } + +public class Dispatcher +{ + public event System.Action subscribers; + + private Dispatcher() { } + + public Dispatcher(S sender) + { + _sender = sender; + } + + public void Dispatch() + { + if (subscribers != null) + subscribers(_sender); + } + + readonly S _sender; +} diff --git a/ECS/EnginesRoot.cs b/ECS/EnginesRoot.cs index 4a71518..b8c8ef7 100644 --- a/ECS/EnginesRoot.cs +++ b/ECS/EnginesRoot.cs @@ -8,9 +8,6 @@ namespace Svelto.ES { public sealed class EnginesRoot: IEnginesRoot, IEndOfFrameTickable, IEntityFactory { - const int _INITIAL_SIZE = 100; - const int _INITIAL_INTERNAL_SIZE = 10; - public EnginesRoot(ITicker ticker) { ticker.Add(this); @@ -19,10 +16,10 @@ namespace Svelto.ES _engineRootWeakReference = new WeakReference(this); _otherEnginesReferences = new FasterList(); - _nodesDB = new Dictionary>(_INITIAL_SIZE); - _nodesDBdic = new Dictionary>(_INITIAL_SIZE); + _nodesDB = new Dictionary>(); + _nodesDBdic = new Dictionary>(); - _nodesToAdd = new Queue(_INITIAL_SIZE); + _nodesToAdd = new Queue(); } public void EndOfFrameTick(float deltaSec) @@ -107,7 +104,7 @@ namespace Svelto.ES { FasterList nodes; if (_nodesDB.TryGetValue(nodeType, out nodes) == false) - nodes = _nodesDB[nodeType] = new FasterList(_INITIAL_INTERNAL_SIZE); + nodes = _nodesDB[nodeType] = new FasterList(); nodes.Add(node); @@ -115,7 +112,7 @@ namespace Svelto.ES { Dictionary nodesDic; if (_nodesDBdic.TryGetValue(nodeType, out nodesDic) == false) - nodesDic = _nodesDBdic[nodeType] = new Dictionary(_INITIAL_INTERNAL_SIZE); + nodesDic = _nodesDBdic[nodeType] = new Dictionary(); nodesDic[(node as NodeWithID).ID] = node; }