using System; using System.Collections.Generic; using Svelto.DataStructures; namespace Svelto.ECS { class EngineNodeDB : IEngineNodeDB { internal EngineNodeDB( Dictionary> nodesDB, Dictionary> nodesDBdic, Dictionary> nodesDBgroups) { _nodesDB = nodesDB; _nodesDBdic = nodesDBdic; _nodesDBgroups = nodesDBgroups; } public FasterReadOnlyListCast QueryNodes() where T:INode { var type = typeof(T); if (_nodesDB.ContainsKey(type) == false) return RetrieveEmptyNodeList(); 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 T QueryNodeFromGroup(int groupID) where T : INode { return QueryNode(groupID); } public bool QueryNodeFromGroup(int groupID, out T node) where T : INode { return QueryNode(groupID, out node); } public FasterReadOnlyListCast QueryNodesFromGroups() where T : INode { var type = typeof(T); if (_nodesDBgroups.ContainsKey(type) == false) return RetrieveEmptyNodeList(); return new FasterReadOnlyListCast(_nodesDBgroups[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"); } static FasterReadOnlyListCast RetrieveEmptyNodeList() where T : INode { return new FasterReadOnlyListCast(FasterReadOnlyListCast.DefaultList); } Dictionary> _nodesDB; Dictionary> _nodesDBdic; Dictionary> _nodesDBgroups; //Dictionary> _nodesDB; //Dictionary> _nodesDBdic; // Dictionary> _nodesDBgroups; ReadOnlyDictionary _defaultEmptyNodeDict = new ReadOnlyDictionary(new Dictionary()); } }