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 FasterReadOnlyListCast QueryNodes() where T:INode { var type = typeof(T); if (_nodesDB.ContainsKey(type) == false) return new FasterReadOnlyListCast(FasterReadOnlyListCast.DefaultList); return new FasterReadOnlyListCast(_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; } public T QueryNode(int ID) where T:INode { var type = typeof(T); INode internalNode; if (_nodesDBdic.ContainsKey(type) && _nodesDBdic[type].TryGetValue(ID, out internalNode)) return (T)internalNode; throw new Exception("Node Not Found"); } Dictionary> _nodesDB; Dictionary> _nodesDBdic; ReadOnlyDictionary _defaultEmptyNodeDict = new ReadOnlyDictionary(new Dictionary()); } }