bool DataSource::loadTileData(const TileID& _tileID, TileManager& _tileManager) { bool success = true; // Begin optimistically if (hasTileData(_tileID)) { _tileManager.addToWorkerQueue(m_tileStore[_tileID], _tileID, this); return success; } std::string url; constructURL(_tileID, url); success = startUrlRequest(url, [=,&_tileManager](std::vector<char>&& _rawData) { // _tileManager is captured here by reference, since its lifetime is the entire program lifetime, // but _tileID has to be captured by copy since it is a temporary stack object _tileManager.addToWorkerQueue(std::move(_rawData), _tileID, this); requestRender(); }); return success; }
Node Importer::applySceneImports(const std::string& scenePath, const std::string& resourceRoot) { std::string path; std::string fullPath = resourceRoot + scenePath; m_sceneQueue.push_back(fullPath); while (true) { { std::unique_lock<std::mutex> lock(sceneMutex); m_condition.wait(lock, [&, this]{ if (m_sceneQueue.empty()) { // Not busy at all? if (progressCounter == 0) { return true; } } else { // More work and not completely busy? if (progressCounter < MAX_SCENE_DOWNLOAD) { return true; } } return false; }); if (m_sceneQueue.empty()) { if (progressCounter == 0) { break; } continue; } path = m_sceneQueue.back(); m_sceneQueue.pop_back(); if (m_scenes.find(path) != m_scenes.end()) { continue; } } // TODO: generic handling of uri if (isUrl(path)) { progressCounter++; startUrlRequest(path, [&, p = path](std::vector<char>&& rawData) { if (!rawData.empty()) { std::unique_lock<std::mutex> lock(sceneMutex); processScene(p, std::string(rawData.data(), rawData.size())); } progressCounter--; m_condition.notify_all(); }); } else { std::unique_lock<std::mutex> lock(sceneMutex); processScene(path, getSceneString(path)); } } auto root = importScenes(fullPath); return root; }