Mesh* MeshManager::getMesh(string name){ std::map<string, Mesh*>::iterator it; it = meshMap.find(name); if(it != meshMap.end()){//mesh previament carregat LEAK! Mesh* result = new Mesh(it->second, getNewId()); result->generateVBO(); return result; } if(FileSystem::getInstance()->openFile(name) == -1){ logErr("Error TextureManager::getTexture opening %s: ", name.c_str()); return 0; } std::size_t foundMD5 = name.find(".md5"); std::size_t foundOBJ = name.find(".obj"); if (foundOBJ!=std::string::npos){ meshMap[name] = parseOBJ(name, FileSystem::getInstance()->getFileData(name), FileSystem::getInstance()->getFileSize(name)); } else if (foundMD5!=std::string::npos){ meshMap[name] = parseMD5(name, FileSystem::getInstance()->getFileData(name), FileSystem::getInstance()->getFileSize(name)); } else{ FileSystem::getInstance()->destroyFileData(name); return 0; } FileSystem::getInstance()->destroyFileData(name); // printMeshData(meshMap[name]); meshMap[name]->generateVBO(); return meshMap[name]; }
void GBUpdate::setIsUpdateEnabled(bool isEnabled, const std::string& updateUrl) { _isUpdateEnabled = isEnabled; _updateUrl = updateUrl; parseMD5(); if (_isUpdateEnabled) requestRemoteVersion(); else DIRECTOR()->getEventDispatcher()->dispatchCustomEvent(GBUPDATE_EVENT_UPDATE_FINISH, (void *)0); }
GBUpdate::GBUpdate() { _isUpdateEnabled = false; _isAutoUpdate = false; _remoteVersion = ""; _localVersion = ""; _localExternalVersion = ""; _downloader.reset(new network::Downloader()); _downloader->onFileTaskSuccess = [this](const DownloadTask& task) { onDownloadSuccess(task); }; _downloader->onTaskError = [this](const DownloadTask& task, int errorCode, int errorCodeInternal, const std::string& errorStr) {onDownloadError(task, errorCode, errorCodeInternal, errorStr); }; DIRECTOR()->getEventDispatcher()->addCustomEventListener(GBUPDATE_EVENT_UPDATE_START, [this](EventCustom * pEvent){ for (map<string, GBUpdateInfo>::iterator it = _downloadList.begin(); it != _downloadList.end(); it++) { if (it->second.location.empty()) { GBVersion version = splitVersion(_remoteVersion); _downloader->createDownloadFileTask(StringUtils::format("%s/%d.%d/%s", _updateUrl.c_str(), version.version1, version.version2, it->first.c_str()), GBUtils::getExternalPath(it->first), it->first); return; } } DIRECTOR()->getEventDispatcher()->dispatchCustomEvent(GBUPDATE_EVENT_UPDATE_FINISH, (void *)0); }); DIRECTOR()->getEventDispatcher()->addCustomEventListener(GBUPDATE_EVENT_UPDATED_ONE, [this](EventCustom * pEvent){ for (map<string, GBUpdateInfo>::iterator it = _downloadList.begin(); it != _downloadList.end(); it++) { if (it->second.location.empty()) { GBVersion version = splitVersion(_remoteVersion); _downloader->createDownloadFileTask(StringUtils::format("%s/%d.%d/%s", _updateUrl.c_str(), version.version1, version.version2, it->first.c_str()), GBUtils::getExternalPath(it->first), it->first); return; } } DIRECTOR()->getEventDispatcher()->dispatchCustomEvent(GBUPDATE_EVENT_UPDATE_FINISH, (void *)1); }); DIRECTOR()->getEventDispatcher()->addCustomEventListener(GBUPDATE_EVENT_UPDATE_FINISH, [this](EventCustom * pEvent){ long isDownloadFinish = (long)pEvent->getUserData(); if(isDownloadFinish) parseMD5(); }); }