From 3e50ea514f77cd50edcd7bfeeb8d3fd5d0dcd65f Mon Sep 17 00:00:00 2001 From: mathusummut Date: Wed, 20 Feb 2019 02:37:59 +0100 Subject: [PATCH] Added cancel load button --- source/game/facilities/logger.cpp | 49 ++-- source/game/facilities/logger.h | 1 - source/game/game/chat_manager.cpp | 82 +++--- source/game/game/commander.cpp | 100 +++---- source/game/game/game.cpp | 253 +++++++++++++----- source/game/game/script_manager.cpp | 28 +- source/game/game/stats.cpp | 4 +- source/game/graphics/renderer.cpp | 18 +- source/game/gui/gui.cpp | 4 +- source/game/main/battle_end.cpp | 3 +- source/game/main/main.cpp | 11 +- source/game/main/program.cpp | 6 + source/game/main/program.h | 8 +- source/game/network/client_interface.cpp | 4 - source/game/network/network_manager.h | 6 +- source/game/network/server_interface.cpp | 8 - source/game/type_instances/faction.cpp | 5 +- source/game/type_instances/unit.cpp | 22 +- source/game/types/faction_type.cpp | 47 +++- source/game/types/tech_tree.cpp | 7 +- source/game/types/upgrade_type.cpp | 22 +- source/game/world/map.cpp | 8 +- source/game/world/scenario.cpp | 3 +- source/game/world/unit_updater.cpp | 6 +- source/game/world/world.cpp | 35 ++- source/shared_lib/include/graphics/pixmap.h | 2 +- source/shared_lib/include/versions.h | 2 +- source/shared_lib/sources/graphics/pixmap.cpp | 8 +- source/shared_lib/sources/util/randomgen.cpp | 12 +- 29 files changed, 471 insertions(+), 293 deletions(-) diff --git a/source/game/facilities/logger.cpp b/source/game/facilities/logger.cpp index 8f5791faf..bd0668860 100644 --- a/source/game/facilities/logger.cpp +++ b/source/game/facilities/logger.cpp @@ -140,7 +140,7 @@ namespace Game { showNextHint(); Lang &lang = Lang::getInstance(); - buttonNextHint.setText(lang.getString("ShowNextHint", "")); + buttonNextHint.setText(lang.getString("ShowNextHint")); buttonCancel.setText(lang.getString("Cancel")); GraphicComponent::applyAllCustomProperties("Loading"); @@ -186,12 +186,14 @@ namespace Game { cancelSelected = true; } } - if (buttonNextHint.getEnabled() == true && buttonNextHint.mouseClick(x, y) == true) { - showNextHint(); - //buttonNextHint.setLighted(false); - SoundRenderer &soundRenderer = SoundRenderer::getInstance(); - CoreData &coreData = CoreData::getInstance(); - soundRenderer.playFx(coreData.getClickSoundC()); + if (buttonNextHint.getEnabled() == true) { + if (buttonNextHint.mouseClick(x, y) == true) { + showNextHint(); + //buttonNextHint.setLighted(false); + SoundRenderer &soundRenderer = SoundRenderer::getInstance(); + CoreData &coreData = CoreData::getInstance(); + soundRenderer.playFx(coreData.getClickSoundC()); + } } } @@ -271,13 +273,13 @@ namespace Game { } } + Lang &lang = Lang::getInstance(); if (gameHintToShow != "") { - Lang &lang = Lang::getInstance(); string hintText = lang.getString("Hint", ""); char szBuf[8096] = ""; snprintf(szBuf, 8096, hintText.c_str(), gameHintToShow.c_str()); hintText = szBuf; - + int yLocationHint = 90 * metrics.getVirtualH() / 100; if (Renderer::renderText3DEnabled) { int xLocationHint = (metrics.getVirtualW() / 2) - (coreData.getMenuFontBig3D()->getMetrics()->getTextWidth(hintText) / 2); @@ -285,7 +287,7 @@ namespace Game { hintText, coreData.getMenuFontBig3D(), displayColor, //xLocation*1.5f, xLocationHint, - 90 * metrics.getVirtualH() / 100, false); + yLocationHint, true); } else { int xLocationHint = (metrics.getVirtualW() / 2) - (coreData.getMenuFontBig()->getMetrics()->getTextWidth(hintText) / 2); @@ -293,13 +295,13 @@ namespace Game { hintText, coreData.getMenuFontBig(), displayColor, //xLocation*1.5f, xLocationHint, - 90 * metrics.getVirtualH() / 100, false); + yLocationHint, true); } //Show next Hint if (buttonNextHint.getEnabled() == false) { - buttonNextHint.init((metrics.getVirtualW() / 2) - (175 / 2), 90 * metrics.getVirtualH() / 100 + 20, 175); - buttonNextHint.setText(lang.getString("ShowNextHint", "")); + buttonNextHint.init((metrics.getVirtualW() / 2) - (175 / 2), yLocationHint + 20, 175); + buttonNextHint.setText(lang.getString("ShowNextHint")); buttonNextHint.setEnabled(true); buttonNextHint.setVisible(true); buttonNextHint.setEditable(true); @@ -331,22 +333,17 @@ namespace Game { } - if (buttonCancel.getEnabled() == true) { + if (Config::getInstance().getBool("EnableLoadCancel", "true")) { + if (buttonCancel.getEnabled() == false) { + buttonCancel.init((metrics.getVirtualW() / 2) - (125 / 2), 50 * metrics.getVirtualH() / 100, 125); + buttonCancel.setText(lang.getString("Cancel")); + buttonCancel.setEnabled(true); + buttonCancel.setVisible(true); + buttonCancel.setEditable(true); + } renderer.renderButton(&buttonCancel); } renderer.swapBuffers(); } - - void Logger::setCancelLoadingEnabled(bool value) { - Lang &lang = Lang::getInstance(); - const Metrics &metrics = Metrics::getInstance(); - //string containerName = "logger"; - //buttonCancel.registerGraphicComponent(containerName,"buttonCancel"); - buttonCancel.init((metrics.getVirtualW() / 2) - (125 / 2), 50 * metrics.getVirtualH() / 100, 125); - buttonCancel.setText(lang.getString("Cancel")); - buttonCancel.setEnabled(value); - //GraphicComponent::applyAllCustomProperties(containerName); - } - } //end namespace diff --git a/source/game/facilities/logger.h b/source/game/facilities/logger.h index 10597df43..f79dc68e4 100644 --- a/source/game/facilities/logger.h +++ b/source/game/facilities/logger.h @@ -106,7 +106,6 @@ namespace Game { void loadGameHints(string filePathEnglish, string filePathTranslation, bool clearList); void renderLoadingScreen(); - void setCancelLoadingEnabled(bool value); bool getCancelLoading() const { return cancelSelected; } diff --git a/source/game/game/chat_manager.cpp b/source/game/game/chat_manager.cpp index 48f36fcc4..e7743c0ae 100644 --- a/source/game/game/chat_manager.cpp +++ b/source/game/game/chat_manager.cpp @@ -334,44 +334,32 @@ namespace Game { GameNetworkInterface * gameNetworkInterface = NetworkManager::getInstance().getGameNetworkInterface(); - const GameSettings * - settings = gameNetworkInterface->getGameSettings(); - for (unsigned int factionIndex = 0; - factionIndex < - (unsigned int) settings->getFactionCount(); - ++factionIndex) { - string - playerName = - settings->getNetworkPlayerName(factionIndex); - if (playerName.length() > autoCompleteName.length() - && StartsWith(toLower(playerName), - toLower(autoCompleteName)) == true) { - if (toLower(playerName) == - toLower(currentAutoCompleteName)) { - replaceCurrentAutoCompleteName = factionIndex; - } else { - autoCompleteResult = - playerName.substr(autoCompleteName.length()); - matchedIndexes.push_back(factionIndex); + if (gameNetworkInterface != NULL) { + const GameSettings * + settings = gameNetworkInterface->getGameSettings(); + for (unsigned int factionIndex = 0; + factionIndex < + (unsigned int) settings->getFactionCount(); + ++factionIndex) { + string + playerName = + settings->getNetworkPlayerName(factionIndex); + if (playerName.length() > autoCompleteName.length() + && StartsWith(toLower(playerName), + toLower(autoCompleteName)) == true) { + if (toLower(playerName) == + toLower(currentAutoCompleteName)) { + replaceCurrentAutoCompleteName = factionIndex; + } else { + autoCompleteResult = + playerName.substr(autoCompleteName.length()); + matchedIndexes.push_back(factionIndex); + } } } - } - if (matchedIndexes.empty() == false) { - int - newMatchedIndex = -1; - for (unsigned int index = 0; - index < (unsigned int) matchedIndexes.size(); - ++index) { + if (matchedIndexes.empty() == false) { int - possibleMatchIndex = matchedIndexes[index]; - if (replaceCurrentAutoCompleteName < 0 - || possibleMatchIndex > - replaceCurrentAutoCompleteName) { - newMatchedIndex = possibleMatchIndex; - break; - } - } - if (newMatchedIndex < 0) { + newMatchedIndex = -1; for (unsigned int index = 0; index < (unsigned int) matchedIndexes.size(); ++index) { @@ -384,12 +372,26 @@ namespace Game { break; } } - } + if (newMatchedIndex < 0) { + for (unsigned int index = 0; + index < (unsigned int) matchedIndexes.size(); + ++index) { + int + possibleMatchIndex = matchedIndexes[index]; + if (replaceCurrentAutoCompleteName < 0 + || possibleMatchIndex > + replaceCurrentAutoCompleteName) { + newMatchedIndex = possibleMatchIndex; + break; + } + } + } - if (newMatchedIndex >= 0) { - autoCompleteResult = - settings->getNetworkPlayerName(newMatchedIndex). - substr(autoCompleteName.length()); + if (newMatchedIndex >= 0) { + autoCompleteResult = + settings->getNetworkPlayerName(newMatchedIndex). + substr(autoCompleteName.length()); + } } } diff --git a/source/game/game/commander.cpp b/source/game/game/commander.cpp index f76c2ef9a..2e973d61d 100644 --- a/source/game/game/commander.cpp +++ b/source/game/game/commander.cpp @@ -681,7 +681,8 @@ namespace Game { } //add the command to the interface - gameNetworkInterface->requestCommand(networkCommand, insertAtStart); + if (gameNetworkInterface != NULL) + gameNetworkInterface->requestCommand(networkCommand, insertAtStart); //calculate the result of the command if (unit != NULL @@ -737,7 +738,8 @@ namespace Game { GameNetworkInterface * gameNetworkInterface = NetworkManager::getInstance().getGameNetworkInterface(); - gameNetworkInterface->setKeyframe(worldFrameCount); + if (gameNetworkInterface != NULL) + gameNetworkInterface->setKeyframe(worldFrameCount); } } return haveReplyCommands; @@ -793,54 +795,56 @@ namespace Game { enabled) perfTimer.start(); //update the keyframe - gameNetworkInterface->updateKeyframe(world-> - getFrameCount()); - if (SystemFlags:: - getSystemSettingType(SystemFlags::debugPerformance). - enabled && perfTimer.getMillis() > 0) - SystemFlags::OutputDebug(SystemFlags::debugPerformance, - "In [%s::%s Line: %d] gameNetworkInterface->updateKeyframe for %d took %lld msecs\n", - extractFileFromDirectoryPath - (__FILE__).c_str(), - __FUNCTION__, __LINE__, - world->getFrameCount(), - perfTimer.getMillis()); + if (gameNetworkInterface != NULL) { + gameNetworkInterface->updateKeyframe(world-> + getFrameCount()); + if (SystemFlags:: + getSystemSettingType(SystemFlags::debugPerformance). + enabled && perfTimer.getMillis() > 0) + SystemFlags::OutputDebug(SystemFlags::debugPerformance, + "In [%s::%s Line: %d] gameNetworkInterface->updateKeyframe for %d took %lld msecs\n", + extractFileFromDirectoryPath + (__FILE__).c_str(), + __FUNCTION__, __LINE__, + world->getFrameCount(), + perfTimer.getMillis()); - if (SystemFlags:: - getSystemSettingType(SystemFlags::debugPerformance). - enabled) - perfTimer.start(); - //give pending commands - if (SystemFlags::VERBOSE_MODE_ENABLED) - printf - ("START process: %d network commands in frame: %d\n", - gameNetworkInterface->getPendingCommandCount(), - this->world->getFrameCount()); - for (int i = 0; - i < gameNetworkInterface->getPendingCommandCount(); - ++i) { - giveNetworkCommand(gameNetworkInterface-> - getPendingCommand(i)); + if (SystemFlags:: + getSystemSettingType(SystemFlags::debugPerformance). + enabled) + perfTimer.start(); + //give pending commands + if (SystemFlags::VERBOSE_MODE_ENABLED) + printf + ("START process: %d network commands in frame: %d\n", + gameNetworkInterface->getPendingCommandCount(), + this->world->getFrameCount()); + for (int i = 0; + i < gameNetworkInterface->getPendingCommandCount(); + ++i) { + giveNetworkCommand(gameNetworkInterface-> + getPendingCommand(i)); + } + if (SystemFlags::VERBOSE_MODE_ENABLED) + printf("END process: %d network commands in frame: %d\n", + gameNetworkInterface->getPendingCommandCount(), + this->world->getFrameCount()); + if (SystemFlags:: + getSystemSettingType(SystemFlags::debugPerformance). + enabled && perfTimer.getMillis() > 0) + SystemFlags::OutputDebug(SystemFlags::debugPerformance, + "In [%s::%s Line: %d] giveNetworkCommand took %lld msecs, PendingCommandCount = %d\n", + extractFileFromDirectoryPath + (__FILE__).c_str(), + __FUNCTION__, __LINE__, + perfTimer.getMillis(), + gameNetworkInterface-> + getPendingCommandCount()); + gameNetworkInterface->clearPendingCommands(); + if (SystemFlags::VERBOSE_MODE_ENABLED) + printf("Cleared network commands in frame: %d\n", + this->world->getFrameCount()); } - if (SystemFlags::VERBOSE_MODE_ENABLED) - printf("END process: %d network commands in frame: %d\n", - gameNetworkInterface->getPendingCommandCount(), - this->world->getFrameCount()); - if (SystemFlags:: - getSystemSettingType(SystemFlags::debugPerformance). - enabled && perfTimer.getMillis() > 0) - SystemFlags::OutputDebug(SystemFlags::debugPerformance, - "In [%s::%s Line: %d] giveNetworkCommand took %lld msecs, PendingCommandCount = %d\n", - extractFileFromDirectoryPath - (__FILE__).c_str(), - __FUNCTION__, __LINE__, - perfTimer.getMillis(), - gameNetworkInterface-> - getPendingCommandCount()); - gameNetworkInterface->clearPendingCommands(); - if (SystemFlags::VERBOSE_MODE_ENABLED) - printf("Cleared network commands in frame: %d\n", - this->world->getFrameCount()); } } } diff --git a/source/game/game/game.cpp b/source/game/game/game.cpp index 5a2d26564..9fcdb31cb 100644 --- a/source/game/game/game.cpp +++ b/source/game/game/game.cpp @@ -751,29 +751,29 @@ namespace Game { for (unsigned int logoIndex = 0; logoIndex < loadScreenList.size(); ++logoIndex) { string - senarioLogo = scenarioDir + loadScreenList[bestLogoIndex]; + scenarioLogo = scenarioDir + loadScreenList[bestLogoIndex]; if (SystemFlags::getSystemSettingType (SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem, "In [%s::%s Line: %d] looking for loading screen '%s'\n", extractFileFromDirectoryPath (__FILE__).c_str(), __FUNCTION__, - __LINE__, senarioLogo.c_str()); + __LINE__, scenarioLogo.c_str()); if (SystemFlags::VERBOSE_MODE_ENABLED) printf("Looking for best logo: %u [%s]\n", logoIndex, - senarioLogo.c_str()); + scenarioLogo.c_str()); - if (fileExists(senarioLogo) == true) { + if (fileExists(scenarioLogo) == true) { if (SystemFlags::getSystemSettingType (SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem, "In [%s::%s Line: %d] found loading screen '%s'\n", extractFileFromDirectoryPath (__FILE__).c_str(), __FUNCTION__, - __LINE__, senarioLogo.c_str()); + __LINE__, scenarioLogo.c_str()); - Texture2D *checkLogo = Renderer::preloadTexture(senarioLogo); + Texture2D *checkLogo = Renderer::preloadTexture(scenarioLogo); if (checkLogo != NULL) { const Metrics & metrics = Metrics::getInstance(); int @@ -797,7 +797,7 @@ namespace Game { bestLogoIndex = logoIndex; if (SystemFlags::VERBOSE_MODE_ENABLED) printf("#1 New best logo is [%s]\n", - senarioLogo.c_str()); + scenarioLogo.c_str()); } else if (minWidthDifference == bestMinWidthDiff && minHeightDifference < bestMinHeightDiff) { bestMinHeightDiff = minHeightDifference; @@ -805,7 +805,7 @@ namespace Game { bestLogoIndex = logoIndex; if (SystemFlags::VERBOSE_MODE_ENABLED) printf("#2 New best logo is [%s]\n", - senarioLogo.c_str()); + scenarioLogo.c_str()); } } } @@ -1540,6 +1540,11 @@ namespace Game { ::Shared::Platform::Window::handleEvent(); SDL_PumpEvents(); } + if (logger.getCancelLoading()) { + logger.setCancelLoading(false); + endGame(); + return; + } if ((loadTypes & lgt_FactionPreview) == lgt_FactionPreview) { if (SystemFlags:: @@ -1554,6 +1559,11 @@ namespace Game { ::Shared::Platform::Window::handleEvent(); SDL_PumpEvents(); } + if (logger.getCancelLoading()) { + logger.setCancelLoading(false); + endGame(); + return; + } if (showPerfStats) { sprintf(perfBuf, @@ -1614,6 +1624,12 @@ namespace Game { (__FILE__).c_str(), __FUNCTION__, __LINE__); + if (logger.getCancelLoading()) { + logger.setCancelLoading(false); + endGame(); + return; + } + //tileset if ((loadTypes & lgt_TileSet) == lgt_TileSet) { if (SystemFlags:: @@ -1627,6 +1643,11 @@ namespace Game { loadTileset(config.getPathListForType(ptTilesets, scenarioDir), tilesetName, &checksum, loadedFileList); } + if (logger.getCancelLoading()) { + logger.setCancelLoading(false); + endGame(); + return; + } if (showPerfStats) { sprintf(perfBuf, @@ -1641,6 +1662,12 @@ namespace Game { ::Shared::Platform::Window::handleEvent(); SDL_PumpEvents(); + if (logger.getCancelLoading()) { + logger.setCancelLoading(false); + endGame(); + return; + } + if (SystemFlags:: getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem, @@ -1699,6 +1726,12 @@ namespace Game { ::Shared::Platform::Window::handleEvent(); SDL_PumpEvents(); + if (logger.getCancelLoading()) { + logger.setCancelLoading(false); + endGame(); + return; + } + if (SystemFlags:: getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem, @@ -1719,6 +1752,12 @@ namespace Game { world.loadMap(Config::getMapPath(mapName, scenarioDir), &checksum); } + if (logger.getCancelLoading()) { + logger.setCancelLoading(false); + endGame(); + return; + } + if (showPerfStats) { sprintf(perfBuf, "In [%s::%s] Line: %d took msecs: " I64_SPECIFIER "\n", @@ -1732,6 +1771,12 @@ namespace Game { ::Shared::Platform::Window::handleEvent(); SDL_PumpEvents(); + if (logger.getCancelLoading()) { + logger.setCancelLoading(false); + endGame(); + return; + } + if (SystemFlags:: getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem, @@ -1778,6 +1823,12 @@ namespace Game { sleep(0); SDL_PumpEvents(); + if (logger.getCancelLoading()) { + logger.setCancelLoading(false); + endGame(); + return; + } + if (SystemFlags:: getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem, @@ -1868,6 +1919,12 @@ namespace Game { SDL_PumpEvents(); } + if (logger.getCancelLoading()) { + logger.setCancelLoading(false); + endGame(); + return; + } + try { world.init(this, gameSettings.getDefaultUnits()); } catch (const game_runtime_error & ex) { @@ -1918,9 +1975,9 @@ namespace Game { perfList.push_back(perfBuf); } - if (loadGameNode != NULL) { - //world.getMapPtr()->loadGame(loadGameNode,&world); - } + /*if (loadGameNode != NULL) { + world.getMapPtr()->loadGame(loadGameNode,&world); + }*/ if (SystemFlags:: getSystemSettingType(SystemFlags::debugSystem).enabled) @@ -1936,6 +1993,11 @@ namespace Game { ::Shared::Platform::Window::handleEvent(); SDL_PumpEvents(); + if (logger.getCancelLoading()) { + logger.setCancelLoading(false); + endGame(); + return; + } gui.init(this); if (SystemFlags:: @@ -1953,6 +2015,11 @@ namespace Game { chatManager.init(&console, world.getThisTeamIndex()); console.clearStoredLines(); } + if (logger.getCancelLoading()) { + logger.setCancelLoading(false); + endGame(); + return; + } if (showPerfStats) { sprintf(perfBuf, @@ -1972,6 +2039,12 @@ namespace Game { } } + if (logger.getCancelLoading()) { + logger.setCancelLoading(false); + endGame(); + return; + } + if (showPerfStats) { sprintf(perfBuf, "In [%s::%s] Line: %d took msecs: " I64_SPECIFIER "\n", @@ -2021,6 +2094,12 @@ namespace Game { std::vector < SlaveThreadControllerInterface * >slaveThreadList; aiInterfaces.resize(world.getFactionCount()); for (int i = 0; i < world.getFactionCount(); ++i) { + if (logger.getCancelLoading()) { + logger.setCancelLoading(false); + endGame(); + return; + } + Faction *faction = world.getFaction(i); //printf("Controltype = %d for index = %d\n",faction->getControlType(),i); @@ -2071,6 +2150,12 @@ namespace Game { ::Shared::Platform::Window::handleEvent(); SDL_PumpEvents(); + if (logger.getCancelLoading()) { + logger.setCancelLoading(false); + endGame(); + return; + } + if (world.getFactionCount() == 1 && world.getFaction(0)->getPersonalityType() == fpt_Observer) { withRainEffect = false; @@ -2120,10 +2205,22 @@ namespace Game { add(Lang:: getInstance().getString("LogScreenGameLoadingInitRenderer", ""), true); + if (logger.getCancelLoading()) { + logger.setCancelLoading(false); + endGame(); + return; + } + //printf("Before renderer.initGame\n"); renderer.initGame(this, this->getGameCameraPtr()); //printf("After renderer.initGame\n"); + if (logger.getCancelLoading()) { + logger.setCancelLoading(false); + endGame(); + return; + } + if (showPerfStats) { sprintf(perfBuf, "In [%s::%s] Line: %d took msecs: " I64_SPECIFIER "\n", @@ -2155,6 +2252,12 @@ namespace Game { ::Shared::Platform::Window::handleEvent(); SDL_PumpEvents(); + if (logger.getCancelLoading()) { + logger.setCancelLoading(false); + endGame(); + return; + } + if (SystemFlags:: getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem, @@ -2164,7 +2267,9 @@ namespace Game { logger. add(Lang:: getInstance().getString("LogScreenGameLoadingWaitForNetworkPlayers", ""), true); - networkManager.getGameNetworkInterface()->waitUntilReady(&checksum); + GameNetworkInterface* networkInterface = networkManager.getGameNetworkInterface(); + if (networkInterface != NULL) + networkInterface->waitUntilReady(&checksum); //std::string worldLog = world.DumpWorldToLog(true); @@ -2244,8 +2349,6 @@ namespace Game { //throw "test"; - logger.setCancelLoadingEnabled(false); - if (SystemFlags:: getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem, @@ -2257,6 +2360,12 @@ namespace Game { setupPopupMenus(false); for (int i = 0; i < world.getFactionCount(); ++i) { + if (logger.getCancelLoading()) { + logger.setCancelLoading(false); + endGame(); + return; + } + Faction *faction = world.getFaction(i); //printf("Check for team switch to observer i = %d, team = %d [%d]\n",i,faction->getTeam(),(GameConstants::maxPlayers -1 + fpt_Observer)); @@ -2346,6 +2455,11 @@ namespace Game { printf("%s", perfList[x].c_str()); } } + + if (logger.getCancelLoading()) { + logger.setCancelLoading(false); + endGame(); + } } void Game::initCamera(Map * map) { @@ -2528,30 +2642,32 @@ namespace Game { NetworkInterface *netIntf = networkManager.getGameNetworkInterface(); - for (int index = 0; index < GameConstants::maxPlayers; ++index) { - if (index < world.getFactionCount()) { - Faction *faction = world.getFaction(index); - netIntf->setNetworkPlayerFactionCRC(index, - faction->getCRC().getSum - ()); + if (netIntf != NULL) { + for (int index = 0; index < GameConstants::maxPlayers; ++index) { + if (index < world.getFactionCount()) { + Faction *faction = world.getFaction(index); + netIntf->setNetworkPlayerFactionCRC(index, + faction->getCRC().getSum + ()); - if (settings != NULL) { - if (isFlagType1BitEnabled - (ft1_network_synch_checks_verbose) == true) { - faction->addCRC_DetailsForWorldFrame(world.getFrameCount - (), - role == nrServer); - } else + if (settings != NULL) { if (isFlagType1BitEnabled - (ft1_network_synch_checks) == true - && world.getFrameCount() % 20 == 0) { + (ft1_network_synch_checks_verbose) == true) { faction->addCRC_DetailsForWorldFrame(world.getFrameCount (), role == nrServer); - } + } else + if (isFlagType1BitEnabled + (ft1_network_synch_checks) == true + && world.getFrameCount() % 20 == 0) { + faction->addCRC_DetailsForWorldFrame(world.getFrameCount + (), + role == nrServer); + } + } + } else { + netIntf->setNetworkPlayerFactionCRC(index, 0); } - } else { - netIntf->setNetworkPlayerFactionCRC(index, 0); } } } @@ -2603,14 +2719,9 @@ namespace Game { } } - bool - pendingQuitError = (quitPendingIndicator == true || - (NetworkManager:: - getInstance().getGameNetworkInterface() != - NULL - && NetworkManager:: - getInstance().getGameNetworkInterface()-> - getQuit())); + bool pendingQuitError = (quitPendingIndicator == true || + (NetworkManager::getInstance().getGameNetworkInterface() != NULL && + NetworkManager::getInstance().getGameNetworkInterface()->getQuit())); if (pendingQuitError == true && (this->masterserverMode == true || @@ -3805,7 +3916,8 @@ namespace Game { // MUST DO THIS LAST!!!! Because objects above have pointers to things like // unit particles and fade them out etc and this end method deletes the original // object pointers. - Renderer & renderer = Renderer::getInstance(); + Renderer& renderer = Renderer::getInstance(); + Logger& logger = Logger::getInstance(); renderer.endGame(true); GameConstants::updateFps = original_updateFps; @@ -3814,7 +3926,16 @@ namespace Game { this->setGameSettings(&gameSettings); this->resetMembers(); this->load(); - this->init(); + if (logger.getCancelLoading()) { + logger.setCancelLoading(false); + endGame(); + } else { + this->init(); + if (logger.getCancelLoading()) { + logger.setCancelLoading(false); + endGame(); + } + } } else { SoundRenderer & soundRenderer = SoundRenderer::getInstance(); //printf("In [%s:%s] Line: %d currentAmbientSound = [%p]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,currentAmbientSound); @@ -4944,10 +5065,12 @@ namespace Game { //printf("Adding Cell marker pos [%s] factionIndex [%d] note [%s] playerIndex = %d\n",cellData.getTargetPos().getString().c_str(),factionIndex,cellData.getNote().c_str(),playerIndex); - gameNetworkInterface->sendMarkCellMessage(cellData.getTargetPos(), - factionIndex, - cellData.getNote(), - playerIndex); + if (gameNetworkInterface != NULL) { + gameNetworkInterface->sendMarkCellMessage(cellData.getTargetPos(), + factionIndex, + cellData.getNote(), + playerIndex); + } Renderer & renderer = Renderer::getInstance(); renderer.forceQuadCacheUpdate(); @@ -4974,8 +5097,10 @@ namespace Game { //printf("Remvoing Cell marker pos [%s] factionIndex [%d] note [%s]\n",mc.getTargetPos().getString().c_str(),factionIndex,mc.getNote().c_str()); - gameNetworkInterface->sendUnMarkCellMessage(mc.getTargetPos(), - factionIndex); + if (gameNetworkInterface != NULL) { + gameNetworkInterface->sendUnMarkCellMessage(mc.getTargetPos(), + factionIndex); + } } } //printf("#1 ADDED in marked list pos [%s] markedCells.size() = " SIZE_T_SPECIFIER "\n",surfaceCellPos.getString().c_str(),mapMarkedCellList.size()); @@ -5000,10 +5125,11 @@ namespace Game { GameNetworkInterface *gameNetworkInterface = NetworkManager::getInstance().getGameNetworkInterface(); - gameNetworkInterface-> - sendHighlightCellMessage(cellData.getTargetPos(), - cellData.getFactionIndex()); - //} + if (gameNetworkInterface != NULL) { + gameNetworkInterface-> + sendHighlightCellMessage(cellData.getTargetPos(), + cellData.getFactionIndex()); + } } void Game::mouseDownLeft(int x, int y) { @@ -5460,8 +5586,8 @@ namespace Game { GameNetworkInterface *gameNetworkInterface = NetworkManager::getInstance().getGameNetworkInterface(); - gameNetworkInterface-> - sendHighlightCellMessage(mc.getTargetPos(), + if (gameNetworkInterface != NULL) + gameNetworkInterface->sendHighlightCellMessage(mc.getTargetPos(), mc.getFaction()->getIndex()); } @@ -5550,11 +5676,9 @@ namespace Game { GameNetworkInterface *gameNetworkInterface = NetworkManager::getInstance().getGameNetworkInterface(); - gameNetworkInterface->sendHighlightCellMessage(mc.getTargetPos - (), - mc.getFaction - ()->getIndex - ()); + if (gameNetworkInterface != NULL) + gameNetworkInterface->sendHighlightCellMessage(mc.getTargetPos(), + mc.getFaction()->getIndex()); } if (originalIsMarkCellEnabled == true @@ -7803,7 +7927,10 @@ namespace Game { for (int i = 0; i < world.getFactionCount(); ++i) { string factionInfo = factionDebugInfo[i]; - Vec4f playerColor = world.getFaction(i)->getTexture()->getPixmapConst()->getPixel4f(0, 0); + const Texture2D* texture = world.getFaction(i)->getTexture(); + Vec4f playerColor = Vec4f(0.f, 0.f, 0.f, 0.f); + if (texture != NULL) + playerColor = texture->getPixmapConst()->getPixel4f(0, 0, true); if (Renderer::renderText3DEnabled == true) { renderer.renderText3D(factionInfo, @@ -7851,10 +7978,8 @@ namespace Game { const Vec4f fontColor = getGui()->getDisplay()->getColor(); if (Renderer::renderText3DEnabled == true) { - renderer. - renderTextShadow3D(NetworkManager:: - getInstance().getGameNetworkInterface - ()->getNetworkStatus(), + renderer.renderTextShadow3D(NetworkManager:: + getInstance().getGameNetworkInterface()->getNetworkStatus(), coreData.getMenuFontNormal3D(), fontColor, mx + mw + 5, metrics.getVirtualH() - 30 - 20, false); diff --git a/source/game/game/script_manager.cpp b/source/game/game/script_manager.cpp index d096a9f72..b1ba55099 100644 --- a/source/game/game/script_manager.cpp +++ b/source/game/game/script_manager.cpp @@ -563,8 +563,25 @@ namespace Game { //load faction code for (int i = 0; i < world->getFactionCount(); ++i) { FactionType const* type = world->getFaction(i)->getType(); + if (type == NULL) + return; for (int j = 0; j < type->getScriptCount(); j++) { script = type->getScript(j); + if (script != NULL) { + iter = scripts.find(script->getName()); + if (iter == scripts.end()) + scripts[script->getName()] = pair>(*script, { script->getCode() }); + else if (find(iter->second.second.begin(), iter->second.second.end(), script->getCode()) == iter->second.second.end()) { + iter->second.second.push_back(script->getCode()); + iter->second.first.appendCode(script->getCode()); + } + } + } + } + //load scenario code + for (int i = 0; i < scenario->getScriptCount(); ++i) { + script = scenario->getScript(i); + if (script != NULL) { iter = scripts.find(script->getName()); if (iter == scripts.end()) scripts[script->getName()] = pair>(*script, { script->getCode() }); @@ -574,17 +591,6 @@ namespace Game { } } } - //load scenario code - for (int i = 0; i < scenario->getScriptCount(); ++i) { - script = scenario->getScript(i); - iter = scripts.find(script->getName()); - if (iter == scripts.end()) - scripts[script->getName()] = pair>(*script, { script->getCode() }); - else if (find(iter->second.second.begin(), iter->second.second.end(), script->getCode()) == iter->second.second.end()) { - iter->second.second.push_back(script->getCode()); - iter->second.first.appendCode(script->getCode()); - } - } for (iter = scripts.begin(); iter != scripts.end(); ++iter) { luaScript.loadCode("function " + iter->second.first.getName() + "()" + diff --git a/source/game/game/stats.cpp b/source/game/game/stats.cpp index edf20ed45..07bf22f48 100644 --- a/source/game/game/stats.cpp +++ b/source/game/game/stats.cpp @@ -63,8 +63,8 @@ namespace Game { break; case ctHuman:controlString = lang.getString("Human"); break; - default:printf("Error control = %d\n", control); - assert(false); + default: + controlString = lang.getString("Closed"); break; }; } diff --git a/source/game/graphics/renderer.cpp b/source/game/graphics/renderer.cpp index 7218fdfc6..1ef597303 100644 --- a/source/game/graphics/renderer.cpp +++ b/source/game/graphics/renderer.cpp @@ -2481,7 +2481,7 @@ namespace Game { //draw resource status if (localFactionResourcesOnly == true) { - Vec4f resourceFontColor = factionForResourceView->getTexture()->getPixmapConst()->getPixel4f(0, 0); + Vec4f resourceFontColor = factionForResourceView->getTexture()->getPixmapConst()->getPixel4f(0, 0, true); int resourceCol = 0; int resourceRow = startRow; @@ -5006,7 +5006,7 @@ namespace Game { visibleUnitIndex < (int) qCache.visibleQuadUnitList.size(); ++visibleUnitIndex) { Unit *unit = qCache.visibleQuadUnitList[visibleUnitIndex]; Vec3f currVec = unit->getCurrVectorFlat(); - Vec4f color = unit->getFaction()->getTexture()->getPixmapConst()->getPixel4f(0, 0); + Vec4f color = unit->getFaction()->getTexture()->getPixmapConst()->getPixel4f(0, 0, true); glColor4f(color.x, color.y, color.z, color.w * 0.7f); renderSelectionCircle(currVec, unit->getType()->getSize(), 0.8f, 0.05f); } @@ -5037,7 +5037,7 @@ namespace Game { std::map::iterator iterFindSpecialUnit = unitHighlightList.find(unit->getId()); if (iterFindSpecialUnit != unitHighlightList.end()) { - Vec4f color = unit->getFaction()->getTexture()->getPixmapConst()->getPixel4f(0, 0); + Vec4f color = unit->getFaction()->getTexture()->getPixmapConst()->getPixel4f(0, 0, true); float radius = 1.0f; float thickness = 0.1f; color.w *= 0.65f; @@ -5081,7 +5081,7 @@ namespace Game { if (unit->isAlive()) { Vec3f currVec = unit->getCurrVectorFlat(); renderTeamColorEffect(currVec, visibleUnitIndex, unit->getType()->getSize(), - unit->getFaction()->getTexture()->getPixmapConst()->getPixel4f(0, 0), texture); + unit->getFaction()->getTexture()->getPixmapConst()->getPixel4f(0, 0, true), texture); } } glDisable(GL_COLOR_MATERIAL); @@ -5290,7 +5290,7 @@ namespace Game { visibleUnitIndex < (int) qCache.visibleQuadUnitBuildList.size(); ++visibleUnitIndex) { const UnitBuildInfo &buildUnit = qCache.visibleQuadUnitBuildList[visibleUnitIndex]; //Vec4f modelColor= Vec4f(0.f, 1.f, 0.f, 0.5f); - const Vec4f teamColor = buildUnit.unit->getFaction()->getTexture()->getPixmapConst()->getPixel4f(0, 0); + const Vec4f teamColor = buildUnit.unit->getFaction()->getTexture()->getPixmapConst()->getPixel4f(0, 0, true); Vec4f modelColor = Vec4f(teamColor.x, teamColor.y, teamColor.z, teamColor.w * 0.4f); renderGhostModel(buildUnit.buildUnit, buildUnit.pos, buildUnit.facing, &modelColor); @@ -6104,7 +6104,7 @@ namespace Game { Vec2i pos = unit->getPos() / Map::cellScale; int size = unit->getType()->getSize(); - Vec4f color = unit->getFaction()->getTexture()->getPixmapConst()->getPixel4f(0, 0); + Vec4f color = unit->getFaction()->getTexture()->getPixmapConst()->getPixel4f(0, 0, true); unit_colors[unitIdx] = color; unit_vertices[unitIdx] = Vec2f(mx + pos.x*zoom.x, my + mh - (pos.y*zoom.y)); @@ -6210,7 +6210,7 @@ namespace Game { const Texture2D *texture = game->getHighlightCellTexture(); Vec4f color = MarkedCell::static_system_marker_color; if (mc->getFaction() != NULL) { - color = mc->getFaction()->getTexture()->getPixmapConst()->getPixel4f(0, 0); + color = mc->getFaction()->getTexture()->getPixmapConst()->getPixel4f(0, 0, true); } int lighting = (mc->getAliveCount() % 15); color = Vec4f(color.x / 2 + .5f / lighting, color.y / 2 + .5f / lighting, color.z / 2 + .5f / lighting, color.w); @@ -6268,7 +6268,7 @@ namespace Game { Vec4f color = MarkedCell::static_system_marker_color; if (bm.getFaction() != NULL) { - color = bm.getFaction()->getTexture()->getPixmapConst()->getPixel4f(0, 0); + color = bm.getFaction()->getTexture()->getPixmapConst()->getPixel4f(0, 0, true); } color.w *= 0.65f; @@ -6403,7 +6403,7 @@ namespace Game { Vec4f color = MarkedCell::static_system_marker_color; if (bm.getFaction() != NULL) { - color = bm.getFaction()->getTexture()->getPixmapConst()->getPixel4f(0, 0); + color = bm.getFaction()->getTexture()->getPixmapConst()->getPixel4f(0, 0, true); } color.w *= 0.8f; renderTextureQuad( diff --git a/source/game/gui/gui.cpp b/source/game/gui/gui.cpp index 8a2abbe7a..1c0b77977 100644 --- a/source/game/gui/gui.cpp +++ b/source/game/gui/gui.cpp @@ -1002,7 +1002,7 @@ namespace Game { display.setLightLevel(displayPos, 1.f); break; case RequirementsIssue::riNotEnoughResources: - display.setLightLevel(displayPos, 0.57f); + display.setLightLevel(displayPos, 0.62f); break; default: display.setLightLevel(displayPos, 0.3f); @@ -1040,7 +1040,7 @@ namespace Game { display.setLightLevel(i, 1.f); break; case RequirementsIssue::riNotEnoughResources: - display.setLightLevel(i, 0.57f); + display.setLightLevel(i, 0.62f); break; default: display.setLightLevel(i, 0.3f); diff --git a/source/game/main/battle_end.cpp b/source/game/main/battle_end.cpp index 71a68c98b..75e7d381d 100644 --- a/source/game/main/battle_end.cpp +++ b/source/game/main/battle_end.cpp @@ -686,8 +686,7 @@ namespace Game { controlString = lang.getString("Human"); break; default: - printf("Error control = %d for i = %d\n", stats.getControl(i), i); - assert(false); + controlString = lang.getString("Closed"); break; }; } diff --git a/source/game/main/main.cpp b/source/game/main/main.cpp index 9a9901483..f08b654d7 100644 --- a/source/game/main/main.cpp +++ b/source/game/main/main.cpp @@ -1186,14 +1186,14 @@ namespace Game { case mbLeft: program->mouseDownLeft(vx, vy); break; - /*case mbRight: + case mbRight: program->mouseDownRight(vx, vy); break; case mbCenter: program->mouseDownCenter(vx, vy); break; default: - break;*/ + break; } SystemFlags::OutputDebug(SystemFlags::debugSystem, @@ -7889,6 +7889,13 @@ namespace Game { try { #endif program->loop(); + if (Logger::getInstance().getCancelLoading()) { + Game* game = ::Game::World::getCurrentGame(); + if (game != NULL) { + Logger::getInstance().setCancelLoading(false); + game->endGame(); + } + } #ifndef DEBUG } catch (const std::exception &exc) { printf("\nAn unhandled error occurred: %s\nAttempting to recover...\n", exc.what()); diff --git a/source/game/main/program.cpp b/source/game/main/program.cpp index 62f1a6a27..3597ec027 100644 --- a/source/game/main/program.cpp +++ b/source/game/main/program.cpp @@ -502,6 +502,12 @@ namespace Game { } } + void Program::mouseDownRight(int x, int y) { + } + + void Program::mouseDownCenter(int x, int y) { + } + void Program::eventMouseMove(int x, int y, const MouseState * ms) { if (msgBox.getEnabled()) { diff --git a/source/game/main/program.h b/source/game/main/program.h index c1dc1b891..242cb4e6c 100644 --- a/source/game/main/program.h +++ b/source/game/main/program.h @@ -406,10 +406,10 @@ namespace Game { virtual void simpleTask(BaseThread * callingThread, void *userdata); - void - mouseDownLeft(int x, int y); - void - eventMouseMove(int x, int y, const MouseState * ms); + void mouseDownLeft(int x, int y); + void mouseDownRight(int x, int y); + void mouseDownCenter(int x, int y); + void eventMouseMove(int x, int y, const MouseState * ms); void renderProgramMsgBox(); diff --git a/source/game/network/client_interface.cpp b/source/game/network/client_interface.cpp index d338cc276..a4a09ec57 100644 --- a/source/game/network/client_interface.cpp +++ b/source/game/network/client_interface.cpp @@ -1566,10 +1566,6 @@ namespace Game { if (receiveMessage(&networkMessageQuit)) { if (SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork, "In [%s::%s] Line: %d\n", extractFileFromDirectoryPath(__FILE__).c_str(), __FUNCTION__, __LINE__); - DisplayErrorMessage(lang.getString("GameCancelledByUser")); - - if (SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork, "In [%s::%s] Line: %d\n", extractFileFromDirectoryPath(__FILE__).c_str(), __FUNCTION__, __LINE__); - setQuit(true); close(); diff --git a/source/game/network/network_manager.h b/source/game/network/network_manager.h index d546c0853..2458b64aa 100644 --- a/source/game/network/network_manager.h +++ b/source/game/network/network_manager.h @@ -52,9 +52,9 @@ namespace Game { bool isNetworkGame(); bool isNetworkGameWithConnectedClients(); - GameNetworkInterface* getGameNetworkInterface(bool throwErrorOnNull = true); - ServerInterface* getServerInterface(bool throwErrorOnNull = true); - ClientInterface* getClientInterface(bool throwErrorOnNull = true); + GameNetworkInterface* getGameNetworkInterface(bool throwErrorOnNull = false); + ServerInterface* getServerInterface(bool throwErrorOnNull = false); + ClientInterface* getClientInterface(bool throwErrorOnNull = false); NetworkRole getNetworkRole() const { return networkRole; } diff --git a/source/game/network/server_interface.cpp b/source/game/network/server_interface.cpp index a820c001b..58352ed6f 100644 --- a/source/game/network/server_interface.cpp +++ b/source/game/network/server_interface.cpp @@ -1901,10 +1901,6 @@ namespace Game { bool allReady = false; - if (Config::getInstance().getBool("EnableGameServerLoadCancel", "false") == true) { - logger.setCancelLoadingEnabled(true); - } - Lang &lang = Lang::getInstance(); uint64 waitLoopIterationCount = 0; uint64 MAX_LOOP_COUNT_BEFORE_SLEEP = 10; @@ -2115,10 +2111,6 @@ namespace Game { string sErr = lang.getString("GameCancelledByUser", languageList[langIndex]); bool localEcho = lang.isLanguageLocal(languageList[langIndex]); sendTextMessage(sErr, -1, localEcho, languageList[langIndex]); - - if (localEcho == true) { - DisplayErrorMessage(sErr); - } } quitGame(true); logger.setCancelLoading(false); diff --git a/source/game/type_instances/faction.cpp b/source/game/type_instances/faction.cpp index 7d4a7c92a..100547581 100644 --- a/source/game/type_instances/faction.cpp +++ b/source/game/type_instances/faction.cpp @@ -777,7 +777,10 @@ namespace Game { if (overridePersonalityType != fpt_EndCount) { return overridePersonalityType; } - return factionType->getPersonalityType(); + if (factionType == NULL) + return fpt_Observer; + else + return factionType->getPersonalityType(); } int Faction:: diff --git a/source/game/type_instances/unit.cpp b/source/game/type_instances/unit.cpp index 2d8947807..7eb5f7473 100644 --- a/source/game/type_instances/unit.cpp +++ b/source/game/type_instances/unit.cpp @@ -403,9 +403,7 @@ namespace Game { ups->setRotation(unit->getRotation()); unit->setMeshPosInParticleSystem(ups); if (unit->getFaction()->getTexture()) { - ups->setFactionColor(unit->getFaction()-> - getTexture()->getPixmapConst()-> - getPixel4f(0, 0)); + ups->setFactionColor(unit->getFaction()->getTexture()->getPixmapConst()->getPixel4f(0, 0, true)); } //printf("Adding attack boost particle to deferred buffer: %p\n",ups); Renderer:: @@ -1529,7 +1527,7 @@ namespace Game { ups->setRotation(getRotation()); ups->setUnitModel(getCurrentModelPtr()); if(getFaction()->getTexture()) { - ups->setFactionColor(getFaction()->getTexture()->getPixmapConst()->getPixel3f(0,0)); + ups->setFactionColor(getFaction()->getTexture()->getPixmapConst()->getPixel4f(0,0)); } unitParticleSystems.push_back(ups); Renderer::getInstance().manageParticleSystem(ups, rsGame); @@ -1706,6 +1704,8 @@ namespace Game { } void Unit::calculateFogOfWarRadius(bool forceRefresh) { + if (game == NULL) + return; if (game->getWorld()->getFogOfWar() == true) { if (forceRefresh || this->pos != this->cachedFowPos) { cachedFow = getFogOfWarRadius(false); @@ -3075,7 +3075,7 @@ namespace Game { currentAttackBoostOriginatorEffect. currentAppliedEffect->ups-> setFactionColor(getFaction()->getTexture()-> - getPixmapConst()->getPixel4f(0, 0)); + getPixmapConst()->getPixel4f(0, 0, true)); } Renderer:: getInstance().manageParticleSystem @@ -3238,7 +3238,7 @@ namespace Game { currentAppliedEffect->ups-> setFactionColor(getFaction()-> getTexture()->getPixmapConst()-> - getPixel4f(0, 0)); + getPixel4f(0, 0, true)); } Renderer:: getInstance().manageParticleSystem @@ -3580,7 +3580,7 @@ namespace Game { if (getFaction()->getTexture()) { ups->setFactionColor(getFaction()-> getTexture()->getPixmapConst()-> - getPixel4f(0, 0)); + getPixel4f(0, 0, true)); } unitParticleSystems.push_back(ups); Renderer::getInstance().manageParticleSystem(ups, rsGame); @@ -3744,7 +3744,7 @@ namespace Game { if (getFaction()->getTexture()) { effect->ups->setFactionColor(getFaction()-> getTexture()->getPixmapConst()-> - getPixel4f(0, 0)); + getPixel4f(0, 0, true)); } Renderer::getInstance().manageParticleSystem(effect->ups, rsGame); @@ -5176,7 +5176,7 @@ namespace Game { if (getFaction()->getTexture()) { ups->setFactionColor(getFaction()-> getTexture()->getPixmapConst()-> - getPixel4f(0, 0)); + getPixel4f(0, 0, true)); } unitParticleSystems.push_back(ups); Renderer::getInstance().manageParticleSystem(ups, rsGame); @@ -5365,7 +5365,7 @@ namespace Game { if (getFaction()->getTexture()) { ups->setFactionColor(getFaction()-> getTexture()->getPixmapConst()-> - getPixel4f(0, 0)); + getPixel4f(0, 0, true)); } damageParticleSystems.push_back(ups); damageParticleSystemsInUse[i] = ups; @@ -5402,7 +5402,7 @@ namespace Game { if (getFaction()->getTexture()) { ups->setFactionColor(getFaction()-> getTexture()->getPixmapConst()-> - getPixel4f(0, 0)); + getPixel4f(0, 0, true)); } damageParticleSystems.push_back(ups); damageParticleSystemsInUse[i] = ups; diff --git a/source/game/types/faction_type.cpp b/source/game/types/faction_type.cpp index d411db961..23389e32b 100644 --- a/source/game/types/faction_type.cpp +++ b/source/game/types/faction_type.cpp @@ -70,6 +70,7 @@ namespace Game { string techTreePath = techTree->getPath(); string techTreeName = techTree->getNameUntranslated(); string currentPath = ""; + Logger & logger = Logger::getInstance(); //open xml file string path = ""; @@ -78,6 +79,9 @@ namespace Game { //printf("\n>>> factionname=%s\n",factionName.c_str()); for (bool realFactionPathFound = false; realFactionPathFound == false;) { + if (logger.getCancelLoading()) { + return; + } currentPath = techTreePath + "factions/" + factionName; endPathWithSlash(currentPath); @@ -155,13 +159,16 @@ namespace Game { break; } } + SDL_PumpEvents(); + if (logger.getCancelLoading()) + return; char szBuf[8096] = ""; snprintf(szBuf, 8096, Lang::getInstance(). getString("LogScreenGameLoadingFactionType", "").c_str(), formatString(this->getName()).c_str()); - Logger::getInstance().add(szBuf, true); + logger.add(szBuf, true); if (personalityType == fpt_Normal) { if (SystemFlags::getSystemSettingType(SystemFlags::debugSystem). @@ -183,6 +190,8 @@ namespace Game { unitTypes.resize(unitFilenames.size()); for (int i = 0; i < (int) unitTypes.size(); ++i) { + if (logger.getCancelLoading()) + return; string str = currentPath + "units/" + unitFilenames[i]; unitTypes[i].preLoad(str); @@ -198,6 +207,8 @@ namespace Game { upgradeTypes.resize(upgradeFilenames.size()); for (int i = 0; i < (int) upgradeTypes.size(); ++i) { + if (logger.getCancelLoading()) + return; string str = currentPath + "upgrades/" + upgradeFilenames[i]; upgradeTypes[i].preLoad(str); @@ -206,11 +217,11 @@ namespace Game { // b1) load units try { - Logger & logger = Logger::getInstance(); int progressBaseValue = logger.getProgress(); for (int i = 0; i < (int) unitTypes.size(); ++i) { + if (logger.getCancelLoading()) + return; string str = currentPath + "units/" + unitTypes[i].getName(); - try { unitTypes[i].loadUnit(i, str, techTree, techTreePath, this, checksum, techtreeChecksum, loadedFileList, @@ -256,9 +267,10 @@ namespace Game { // b2) load upgrades try { for (int i = 0; i < (int) upgradeTypes.size(); ++i) { + if (logger.getCancelLoading()) + return; string str = currentPath + "upgrades/" + upgradeTypes[i].getName(); - try { upgradeTypes[i].load(str, techTree, this, checksum, techtreeChecksum, loadedFileList, @@ -313,6 +325,8 @@ namespace Game { startingResources.resize(startingResourcesNode->getChildCount()); for (int i = 0; i < (int) startingResources.size(); ++i) { + if (logger.getCancelLoading()) + return; const XmlNode *resourceNode = startingResourcesNode->getChild("resource", i); string name = @@ -342,6 +356,8 @@ namespace Game { const XmlNode *startingUnitsNode = factionNode->getChild("starting-units"); for (int i = 0; i < (int) startingUnitsNode->getChildCount(); ++i) { + if (logger.getCancelLoading()) + return; const XmlNode *unitNode = startingUnitsNode->getChild("unit", i); string name = unitNode->getAttribute("name")->getRestrictedValue(); @@ -352,6 +368,9 @@ namespace Game { SDL_PumpEvents(); } + if (logger.getCancelLoading()) + return; + //read music const XmlNode *musicNode = factionNode->getChild("music"); bool value = musicNode->getAttribute("value")->getBoolValue(); @@ -393,6 +412,8 @@ namespace Game { getValue(); vector < string > v = split(healthbarVisibleString, "|"); for (int i = 0; i < (int) v.size(); ++i) { + if (logger.getCancelLoading()) + return; string current = trim(v[i]); if (current == "always") { healthbarVisible = healthbarVisible | hbvAlways; @@ -403,9 +424,7 @@ namespace Game { } else if (current == "off") { healthbarVisible = healthbarVisible | hbvOff; } else { - throw - game_runtime_error - ("Unknown Healthbar Visible Option: " + current, true); + throw game_runtime_error("Unknown Healthbar Visible Option: " + current, true); } } } @@ -471,6 +490,8 @@ namespace Game { const XmlNode *scriptsNode = factionNode->getChild("scripts"); for (int i = 0; i < (int) scriptsNode->getChildCount(); ++i) { + if (logger.getCancelLoading()) + return; const XmlNode *scriptNode = scriptsNode->getChild(i); scripts.push_back(Script(getFunctionName(scriptNode), scriptNode->getText())); } @@ -488,6 +509,8 @@ namespace Game { if (aiNode->hasChild("static-values") == true) { const XmlNode *aiNodeUnits = aiNode->getChild("static-values"); for (int i = 0; i < (int) aiNodeUnits->getChildCount(); ++i) { + if (logger.getCancelLoading()) + return; const XmlNode *unitNode = aiNodeUnits->getChild("static", i); AIBehaviorStaticValueCategory type = aibsvcMaxBuildRadius; if (unitNode->hasAttribute("type") == true) { @@ -513,6 +536,8 @@ namespace Game { if (aiNode->hasChild("worker-units") == true) { const XmlNode *aiNodeUnits = aiNode->getChild("worker-units"); for (int i = 0; i < (int) aiNodeUnits->getChildCount(); ++i) { + if (logger.getCancelLoading()) + return; const XmlNode *unitNode = aiNodeUnits->getChild("unit", i); string name = unitNode->getAttribute("name")->getRestrictedValue(); @@ -526,6 +551,8 @@ namespace Game { if (aiNode->hasChild("warrior-units") == true) { const XmlNode *aiNodeUnits = aiNode->getChild("warrior-units"); for (int i = 0; i < (int) aiNodeUnits->getChildCount(); ++i) { + if (logger.getCancelLoading()) + return; const XmlNode *unitNode = aiNodeUnits->getChild("unit", i); string name = unitNode->getAttribute("name")->getRestrictedValue(); @@ -540,6 +567,8 @@ namespace Game { const XmlNode *aiNodeUnits = aiNode->getChild("resource-producer-units"); for (int i = 0; i < (int) aiNodeUnits->getChildCount(); ++i) { + if (logger.getCancelLoading()) + return; const XmlNode *unitNode = aiNodeUnits->getChild("unit", i); string name = unitNode->getAttribute("name")->getRestrictedValue(); @@ -553,6 +582,8 @@ namespace Game { if (aiNode->hasChild("building-units") == true) { const XmlNode *aiNodeUnits = aiNode->getChild("building-units"); for (int i = 0; i < (int) aiNodeUnits->getChildCount(); ++i) { + if (logger.getCancelLoading()) + return; const XmlNode *unitNode = aiNodeUnits->getChild("unit", i); string name = unitNode->getAttribute("name")->getRestrictedValue(); @@ -567,6 +598,8 @@ namespace Game { if (aiNode->hasChild("upgrades") == true) { const XmlNode *aiNodeUpgrades = aiNode->getChild("upgrades"); for (int i = 0; i < (int) aiNodeUpgrades->getChildCount(); ++i) { + if (logger.getCancelLoading()) + return; const XmlNode *upgradeNode = aiNodeUpgrades->getChild("upgrade", i); string name = diff --git a/source/game/types/tech_tree.cpp b/source/game/types/tech_tree.cpp index 9df8605b9..ac35006ef 100644 --- a/source/game/types/tech_tree.cpp +++ b/source/game/types/tech_tree.cpp @@ -566,7 +566,7 @@ namespace Game { "In [%s::%s Line: %d]\n", extractFileFromDirectoryPath(__FILE__). c_str(), __FUNCTION__, __LINE__); - throw game_runtime_error("Faction not found: " + name, true); + return NULL; } const FactionType *TechTree::getType(const string & name) const { @@ -581,16 +581,13 @@ namespace Game { "In [%s::%s Line: %d]\n", extractFileFromDirectoryPath(__FILE__). c_str(), __FUNCTION__, __LINE__); - throw game_runtime_error("Faction not found: " + name, true); + return NULL; } const ResourceType *TechTree::getTechResourceType(int i) const { for (int j = 0; j < getResourceTypeCount(); ++j) { const ResourceType *rt = getResourceType(j); assert(rt != NULL); - if (rt == NULL) { - throw game_runtime_error("rt == NULL"); - } if (rt->getResourceNumber() == i && rt->getClass() == rcTech) return getResourceType(j); } diff --git a/source/game/types/upgrade_type.cpp b/source/game/types/upgrade_type.cpp index d3b44a174..12995fd1d 100644 --- a/source/game/types/upgrade_type.cpp +++ b/source/game/types/upgrade_type.cpp @@ -1051,7 +1051,8 @@ namespace Game { Lang::getInstance(). getString("LogScreenGameLoadingUpgradeType", "").c_str(), formatString(this->getName(true)).c_str()); - Logger::getInstance().add(szBuf, true); + Logger& logger = Logger::getInstance(); + logger.add(szBuf, true); string currentPath = dir; endPathWithSlash(currentPath); @@ -1091,6 +1092,8 @@ namespace Game { const XmlNode *unitRequirementsNode = upgradeNode->getChild("unit-requirements"); for (int i = 0; i < (int) unitRequirementsNode->getChildCount(); ++i) { + if (logger.getCancelLoading()) + return; const XmlNode *unitNode = unitRequirementsNode->getChild("unit", i); string name = @@ -1111,6 +1114,8 @@ namespace Game { for (std::map < string, int >::iterator iterMap = sortedItems.begin(); iterMap != sortedItems.end(); ++iterMap) { + if (logger.getCancelLoading()) + return; unitReqs.push_back(factionType->getUnitType(iterMap->first)); } sortedItems.clear(); @@ -1119,8 +1124,9 @@ namespace Game { //upgrade requirements const XmlNode *upgradeRequirementsNode = upgradeNode->getChild("upgrade-requirements"); - for (int i = 0; i < (int) upgradeRequirementsNode->getChildCount(); - ++i) { + for (int i = 0; i < (int) upgradeRequirementsNode->getChildCount(); ++i) { + if (logger.getCancelLoading()) + return; const XmlNode *upgradeReqNode = upgradeRequirementsNode->getChild("upgrade", i); string name = @@ -1141,6 +1147,8 @@ namespace Game { for (std::map < string, int >::iterator iterMap = sortedItems.begin(); iterMap != sortedItems.end(); ++iterMap) { + if (logger.getCancelLoading()) + return; upgradeReqs.push_back(factionType-> getUpgradeType(iterMap->first)); } @@ -1154,6 +1162,8 @@ namespace Game { costs.resize(resourceRequirementsNode->getChildCount()); for (int i = 0; i < (int) costs.size(); ++i) { + if (logger.getCancelLoading()) + return; const XmlNode *resourceNode = resourceRequirementsNode->getChild("resource", i); string name = @@ -1182,6 +1192,8 @@ namespace Game { index = 0; for (std::map < string, int >::iterator iterMap = sortedItems.begin(); iterMap != sortedItems.end(); ++iterMap) { + if (logger.getCancelLoading()) + return; try { costs[index].init(techTree->getResourceType(iterMap->first), iterMap->second); @@ -1207,6 +1219,8 @@ namespace Game { const XmlNode *effectsNode = upgradeNode->getChild("effects"); vector < XmlNode * >unitNodes = effectsNode->getChildList("unit"); for (size_t i = 0; i < unitNodes.size(); ++i) { + if (logger.getCancelLoading()) + return; const XmlNode *unitNode = unitNodes.at(i); string name = unitNode->getAttribute("name")->getRestrictedValue(); @@ -1217,6 +1231,8 @@ namespace Game { //effects -- convert tags into units vector < XmlNode * >tagNodes = effectsNode->getChildList("tag"); for (size_t i = 0; i < tagNodes.size(); ++i) { + if (logger.getCancelLoading()) + return; const XmlNode *tagNode = tagNodes.at(i); string name = tagNode->getAttribute("name")->getRestrictedValue(); tags.insert(name); diff --git a/source/game/world/map.cpp b/source/game/world/map.cpp index 1186eb204..de2c242f0 100644 --- a/source/game/world/map.cpp +++ b/source/game/world/map.cpp @@ -386,18 +386,18 @@ namespace Game { Vec2i Map::getStartLocation(int locationIndex) const { if (locationIndex < hardMaxPlayers) // maxPlayers for a map, not the Game return startLocations[locationIndex]; - else if (locationIndex < maxPlayers) { + //else if (locationIndex < maxPlayers) { // needed for enhanced observer mode (issue #13) // observer may be in slot 6 of a 4-player map. Just set the // startLocation to 0 - return startLocations[0]; - } else { + return startLocations == NULL ? Vec2i() : startLocations[0]; + /*} else { char szBuf[8096] = ""; snprintf(szBuf, 8096, "locationIndex >= maxPlayers [%d] [%d]", locationIndex, maxPlayers); printf("%s\n", szBuf); throw game_runtime_error(szBuf); assert(locationIndex < GameConstants::maxPlayers); - } + }*/ } Checksum Map::load(const string &path, TechTree *techTree, Tileset *tileset) { diff --git a/source/game/world/scenario.cpp b/source/game/world/scenario.cpp index 6260d0cdd..abd207bff 100644 --- a/source/game/world/scenario.cpp +++ b/source/game/world/scenario.cpp @@ -574,8 +574,7 @@ Please contact the Glest team for more info."; controlString = lang.getString("Human"); break; default: - printf("Error control = %d\n", ct); - //assert(false); + controlString = lang.getString("Closed"); break; } diff --git a/source/game/world/unit_updater.cpp b/source/game/world/unit_updater.cpp index dcbd80309..153904e22 100644 --- a/source/game/world/unit_updater.cpp +++ b/source/game/world/unit_updater.cpp @@ -2703,7 +2703,7 @@ namespace Game { psProj->setObserver(new ParticleDamager(unit, (*pt), this, gameCamera)); psProj->setVisible(visible); if (unit->getFaction()->getTexture()) { - psProj->setFactionColor(unit->getFaction()->getTexture()->getPixmapConst()->getPixel4f(0, 0)); + psProj->setFactionColor(unit->getFaction()->getTexture()->getPixmapConst()->getPixel4f(0, 0, true)); } renderer.manageParticleSystem(psProj, rsGame); unit->addAttackParticleSystem(psProj); @@ -2713,7 +2713,7 @@ namespace Game { psSplash->setPos(endPos); psSplash->setVisible(visible); if (unit->getFaction()->getTexture()) { - psSplash->setFactionColor(unit->getFaction()->getTexture()->getPixmapConst()->getPixel4f(0, 0)); + psSplash->setFactionColor(unit->getFaction()->getTexture()->getPixmapConst()->getPixel4f(0, 0, true)); } renderer.manageParticleSystem(psSplash, rsGame); unit->addAttackParticleSystem(psSplash); @@ -2734,7 +2734,7 @@ namespace Game { psSplash->setPos(endPos); psSplash->setVisible(visible); if (unit->getFaction()->getTexture()) { - psSplash->setFactionColor(unit->getFaction()->getTexture()->getPixmapConst()->getPixel4f(0, 0)); + psSplash->setFactionColor(unit->getFaction()->getTexture()->getPixmapConst()->getPixel4f(0, 0, true)); } renderer.manageParticleSystem(psSplash, rsGame); unit->addAttackParticleSystem(psSplash); diff --git a/source/game/world/world.cpp b/source/game/world/world.cpp index a815e4271..042b3c5ef 100644 --- a/source/game/world/world.cpp +++ b/source/game/world/world.cpp @@ -2072,13 +2072,11 @@ namespace Game { for (int i = 0; i < (int) factions.size(); ++i) { FactionType *ft = techTree->getTypeByName(gs->getFactionTypeName(i)); - if (ft == NULL) { - throw game_runtime_error("ft == NULL"); - } + if (ft == NULL) + return; factions[i]->init(ft, gs->getFactionControl(i), techTree, game, i, gs->getTeam(i), gs->getStartLocationIndex(i), i == thisFactionIndex, gs->getDefaultResources(), loadWorldNode); - stats.setTeam(i, gs->getTeam(i)); stats.setFactionTypeName(i, formatString(gs->getFactionTypeName(i))); stats.setPersonalityType(i, getFaction(i)->getType()->getPersonalityType()); @@ -2086,7 +2084,7 @@ namespace Game { stats.setResourceMultiplier(i, (gs->getResourceMultiplierIndex(i) + 1) * 0.5f); stats.setPlayerName(i, gs->getNetworkPlayerName(i)); if (getFaction(i)->getTexture()) { - stats.setPlayerColor(i, getFaction(i)->getTexture()->getPixmapConst()->getPixel4f(0, 0)); + stats.setPlayerColor(i, getFaction(i)->getTexture()->getPixmapConst()->getPixel4f(0, 0, true)); } } @@ -2201,17 +2199,15 @@ namespace Game { unit->setCurrSkill(scStop); //unit->create(true); //unit->born(); + if (unit->getType()->hasSkillClass(scBeBuilt)) { + map.flatternTerrain(unit); + } + if (SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem, "In [%s::%s Line: %d] unit created for unit [%s]\n", __FILE__, __FUNCTION__, __LINE__, unit->toString().c_str()); } else { string unitName = unit->getType()->getName(false); delete unit; - unit = NULL; - throw game_runtime_error("Unit: " + unitName + " can't be placed, this error is caused because there\nis not enough room to put all units near their start location.\nmake a better/larger map. Faction: #" + intToStr(i) + " name: " + ft->getName(false)); + printf("\n%s\n", (string("Unit: ") + unitName + " can't be placed, this error is caused because there\nis not enough room to put all units near their start location.\nmake a better/larger map. Faction: #" + intToStr(i) + " name: " + ft->getName(false)).c_str()); } - - if (unit->getType()->hasSkillClass(scBeBuilt)) { - map.flatternTerrain(unit); - } - if (SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem, "In [%s::%s Line: %d] unit created for unit [%s]\n", __FILE__, __FUNCTION__, __LINE__, unit->toString().c_str()); } // Ensure Starting Resource Amount are adjusted to max store levels @@ -2226,6 +2222,10 @@ namespace Game { if (placeUnit(location, generationArea, unit, spaciated)) { unit->create(true); unit->born(NULL); + if (unit->getType()->hasSkillClass(scBeBuilt)) { + map.flatternTerrain(unit); + } + if (SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem, "In [%s::%s Line: %d] unit created for unit [%s]\n", __FILE__, __FUNCTION__, __LINE__, unit->toString().c_str()); } else { string unitName = unit->getType()->getName(false); string unitFactionName = unit->getFaction()->getType()->getName(false); @@ -2234,16 +2234,9 @@ namespace Game { delete unit; unit = NULL; - char szBuf[8096] = ""; - snprintf(szBuf, 8096, "Unit: [%s] can't be placed, this error is caused because there\nis not enough room to put all units near their start location.\nmake a better/larger map. Faction: #%d name: [%s]", + printf("\nUnit: [%s] can't be placed, this error is caused because there\nis not enough room to put all units near their start location.\nmake a better/larger map. Faction: #%d name: [%s]\n", unitName.c_str(), unitFactionIndex, unitFactionName.c_str()); - throw game_runtime_error(szBuf, false); } - if (unit->getType()->hasSkillClass(scBeBuilt)) { - map.flatternTerrain(unit); - } - if (SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem, "In [%s::%s Line: %d] unit created for unit [%s]\n", __FILE__, __FUNCTION__, __LINE__, unit->toString().c_str()); - } //place units randomly aroud start location @@ -2260,6 +2253,8 @@ namespace Game { for (int i = 0; i < getFactionCount(); ++i) { Faction *f = factions[i]; const FactionType *ft = f->getType(); + if (ft == NULL) + return; for (int j = 0; j < ft->getStartingUnitCount(); ++j) { const UnitType *ut = ft->getStartingUnit(j); int initNumber = ft->getStartingUnitAmount(j); diff --git a/source/shared_lib/include/graphics/pixmap.h b/source/shared_lib/include/graphics/pixmap.h index f6cd94a43..360c4d87d 100644 --- a/source/shared_lib/include/graphics/pixmap.h +++ b/source/shared_lib/include/graphics/pixmap.h @@ -297,7 +297,7 @@ namespace Shared { void getComponent(int x, int y, int component, float32 &value) const; //vector get - Vec4f getPixel4f(int x, int y) const; + Vec4f getPixel4f(int x, int y, bool fallback = false) const; Vec3f getPixel3f(int x, int y) const; float getPixelf(int x, int y) const; float getComponentf(int x, int y, int component) const; diff --git a/source/shared_lib/include/versions.h b/source/shared_lib/include/versions.h index bcbc04281..d77703acc 100644 --- a/source/shared_lib/include/versions.h +++ b/source/shared_lib/include/versions.h @@ -2,4 +2,4 @@ #define G3D_VIEWER_VERSION "1.0" #define MAP_EDITOR_VERSION "1.0" //Month then Day -#define GAME_BUILD_DATE "0206" +#define GAME_BUILD_DATE "0219" diff --git a/source/shared_lib/sources/graphics/pixmap.cpp b/source/shared_lib/sources/graphics/pixmap.cpp index 307746f92..d59f7a789 100644 --- a/source/shared_lib/sources/graphics/pixmap.cpp +++ b/source/shared_lib/sources/graphics/pixmap.cpp @@ -941,7 +941,7 @@ namespace Shared { this->components = components; deletePixels(); - if (getPixelByteCount() <= 0 || (h <= 0 || w <= 0 || components <= 0)) { + if (getPixelByteCount() < 0 || (h < 0 || w < 0 || components < 0)) { char szBuf[8096]; snprintf(szBuf, 8096, "Invalid pixmap dimensions for [%s], h = %d, w = %d, components = %d\n", path.c_str(), h, w, components); throw game_runtime_error(szBuf); @@ -1098,8 +1098,10 @@ namespace Shared { value = pixels[index] / 255.f; } - //vector get - Vec4f Pixmap2D::getPixel4f(int x, int y) const { + Vec4f Pixmap2D::getPixel4f(int x, int y, bool fallback) const { + if (pixels == NULL && fallback) { + return Vec4f(0.f, 0.f, 0.f, 0.f); + } Vec4f v(0.f); for (int i = 0; i < components && i < 4; ++i) { std::size_t index = (w*y + x)*components + i; diff --git a/source/shared_lib/sources/util/randomgen.cpp b/source/shared_lib/sources/util/randomgen.cpp index 8b5a2fced..a76690272 100644 --- a/source/shared_lib/sources/util/randomgen.cpp +++ b/source/shared_lib/sources/util/randomgen.cpp @@ -79,9 +79,9 @@ namespace Shared { int RandomGen::randRange(int min, int max, string lastCaller) { if (min > max) { - char szBuf[8096] = ""; - snprintf(szBuf, 8096, "In [%s::%s Line: %d] min > max, min = %d, max = %d", __FILE__, __FUNCTION__, __LINE__, min, max); - throw game_runtime_error(szBuf); + int temp = min; + min = max; + max = temp; } int diff = max - min; @@ -97,9 +97,9 @@ namespace Shared { float RandomGen::randRange(float min, float max, string lastCaller) { if (min > max) { - char szBuf[8096] = ""; - snprintf(szBuf, 8096, "In [%s::%s Line: %d] min > max, min = %f, max = %f", __FILE__, __FUNCTION__, __LINE__, min, max); - throw game_runtime_error(szBuf); + int temp = min; + min = max; + max = temp; } float rand01 = static_cast(this->rand(lastCaller)) / (m - 1);