using System; using System.Collections.Generic; using Svelto.DataStructures; namespace Svelto.ECS { public class EngineNodeDB : IEngineNodeDB { internal EngineNodeDB( Dictionary nodesDB, Dictionary nodesDBdic, Dictionary metaNodesDB) { _nodesDB = nodesDB; _nodesDBdic = nodesDBdic; _metaNodesDB = metaNodesDB; } public FasterReadOnlyList QueryNodes() { var type = typeof(T); ITypeSafeList nodes; if (_nodesDB.TryGetValue(type, out nodes) == false) return RetrieveEmptyNodeList(); return new FasterReadOnlyList((FasterList)nodes); } public ReadOnlyDictionary QueryIndexableNodes() { var type = typeof(T); ITypeSafeDictionary nodes; if (_nodesDBdic.TryGetValue(type, out nodes) == false) return TypeSafeDictionary.Default; return new ReadOnlyDictionary(nodes as Dictionary); } public T QueryMetaNode(int metaEntityID) { return QueryNode(metaEntityID); } public bool TryQueryMetaNode(int metaEntityID, out T node) { return TryQueryNode(metaEntityID, out node); } public FasterReadOnlyList QueryMetaNodes() { var type = typeof(T); ITypeSafeList nodes; if (_metaNodesDB.TryGetValue(type, out nodes) == false) return RetrieveEmptyNodeList(); return new FasterReadOnlyList((FasterList)nodes); } public bool TryQueryNode(int ID, out T node) { var type = typeof(T); T internalNode; ITypeSafeDictionary nodes; if (_nodesDBdic.TryGetValue(type, out nodes) && (nodes as Dictionary).TryGetValue(ID, out internalNode)) { node = internalNode; return true; } node = default(T); return false; } public T QueryNode(int ID) { var type = typeof(T); T internalNode; ITypeSafeDictionary nodes; if (_nodesDBdic.TryGetValue(type, out nodes) && (nodes as Dictionary).TryGetValue(ID, out internalNode)) return (T)internalNode; throw new Exception("Node Not Found"); } static FasterReadOnlyList RetrieveEmptyNodeList() { return FasterReadOnlyList.DefaultList; } readonly Dictionary _nodesDB; readonly Dictionary _nodesDBdic; readonly Dictionary _metaNodesDB; } }