using System; using System.Collections.Generic; using Svelto.DataStructures; namespace Svelto.ES { class EngineNodeDB : IEngineNodeDB { internal EngineNodeDB(Dictionary> nodesDB, Dictionary> nodesDBdic) { this._nodesDB = nodesDB; this._nodesDBdic = nodesDBdic; } public FasterReadOnlyList QueryNodes() where T:INode { var type = typeof(T); if (_nodesDB.ContainsKey(type) == false) return _defaultEmptyNodeList; return new FasterReadOnlyList(_nodesDB[type]); } public ReadOnlyDictionary QueryIndexableNodes() where T:INode { var type = typeof(T); if (_nodesDBdic.ContainsKey(type) == false) return _defaultEmptyNodeDict; return new ReadOnlyDictionary(_nodesDBdic[type]); } public bool QueryNode(int ID, out T node) where T:INode { var type = typeof(T); INode internalNode; if (_nodesDBdic.ContainsKey(type) && _nodesDBdic[type].TryGetValue(ID, out internalNode)) { node = (T)internalNode; return true; } node = default(T); return false; } Dictionary> _nodesDB; Dictionary> _nodesDBdic; FasterReadOnlyList _defaultEmptyNodeList = new FasterReadOnlyList(new FasterList()); ReadOnlyDictionary _defaultEmptyNodeDict = new ReadOnlyDictionary(new Dictionary()); } }