From 2a1163d391c285fbc96f977eed0f7b1ddcb0296a Mon Sep 17 00:00:00 2001 From: Anonymous Maarten Date: Thu, 30 Aug 2018 02:02:02 +0200 Subject: [PATCH] rwgame: fix Visual Studio warnings --- rwengine/src/render/TextRenderer.cpp | 2 +- rwgame/DrawUI.cpp | 16 ++++++++-------- rwgame/GameConfig.cpp | 6 ++++-- rwgame/GameWindow.cpp | 2 +- rwgame/MenuSystem.hpp | 4 ++-- rwgame/RWGame.cpp | 2 +- rwgame/main.cpp | 2 +- rwgame/states/DebugState.cpp | 2 +- 8 files changed, 19 insertions(+), 17 deletions(-) diff --git a/rwengine/src/render/TextRenderer.cpp b/rwengine/src/render/TextRenderer.cpp index 6e8378bb..5ded695f 100644 --- a/rwengine/src/render/TextRenderer.cpp +++ b/rwengine/src/render/TextRenderer.cpp @@ -284,7 +284,7 @@ void TextRenderer::renderText(const TextRenderer::TextInfo& ti, // will need to be wrapped if (ti.wrapX > 0 && coord.x > 0.f && !std::isspace(c)) { auto wend = std::find_if(std::begin(text) + i, std::end(text), - [](GameStringChar c) { return std::isspace(c); }); + [](auto c) { return std::isspace(c); }); if (wend != std::end(text)) { auto word = std::distance(std::begin(text) + i, wend); if (lineLength + word >= ti.wrapX) { diff --git a/rwgame/DrawUI.cpp b/rwgame/DrawUI.cpp index cbacb079..abf6ec43 100644 --- a/rwgame/DrawUI.cpp +++ b/rwgame/DrawUI.cpp @@ -37,8 +37,8 @@ constexpr float ui_worldSizeMax = 300.f; void drawScriptTimer(GameWorld* world, GameRenderer* render) { if (world->state->scriptTimerVariable) { - float scriptTimerTextX = - render->getRenderer()->getViewport().x - ui_outerMargin; + float scriptTimerTextX = static_cast( + render->getRenderer()->getViewport().x - ui_outerMargin); float scriptTimerTextY = ui_scriptTimerHeight; TextRenderer::TextInfo ti; @@ -97,13 +97,13 @@ void drawMap(ViewCamera& currentView, PlayerController* player, void drawPlayerInfo(PlayerController* player, GameWorld* world, GameRenderer* render) { - float infoTextX = render->getRenderer()->getViewport().x - - (ui_outerMargin + ui_weaponSize + ui_infoMargin); + float infoTextX = static_cast(render->getRenderer()->getViewport().x - + (ui_outerMargin + ui_weaponSize + ui_infoMargin)); float infoTextY = 0.f + ui_outerMargin; - float iconX = render->getRenderer()->getViewport().x - - (ui_outerMargin + ui_weaponSize); + float iconX = static_cast(render->getRenderer()->getViewport().x - + (ui_outerMargin + ui_weaponSize)); float iconY = ui_outerMargin; - float wantedX = render->getRenderer()->getViewport().x - (ui_outerMargin); + float wantedX = static_cast(render->getRenderer()->getViewport().x - ui_outerMargin); float wantedY = ui_wantedLevelHeight; TextRenderer::TextInfo ti; @@ -292,7 +292,7 @@ void drawOnScreenText(GameWorld* world, GameRenderer* renderer) { for (auto& l : alltext) { for (auto& t : l) { - ti.size = t.size; + ti.size = static_cast(t.size); ti.font = t.font; ti.text = t.text; ti.wrapX = t.wrapX; diff --git a/rwgame/GameConfig.cpp b/rwgame/GameConfig.cpp index e2630d02..247f62ec 100644 --- a/rwgame/GameConfig.cpp +++ b/rwgame/GameConfig.cpp @@ -104,7 +104,7 @@ struct BoolTranslator { boost::optional res; try { res = std::stoi(stripComments(str)) != 0; - } catch (std::invalid_argument &e) { + } catch (std::invalid_argument &) { } return res; } @@ -120,7 +120,7 @@ struct IntTranslator { boost::optional res; try { res = std::stoi(stripComments(str)); - } catch (std::invalid_argument &e) { + } catch (std::invalid_argument &) { } return res; } @@ -191,6 +191,7 @@ GameConfig::ParseResult GameConfig::parseConfig(GameConfig::ParseType srcType, try { sourceValue = srcTree.get(key, translator); } catch (pt::ptree_bad_path &e) { + RW_UNUSED(e); // Catches missing key-value pairs: fail when required if (!optional) { parseResult.failRequiredMissing(key); @@ -199,6 +200,7 @@ GameConfig::ParseResult GameConfig::parseConfig(GameConfig::ParseType srcType, } sourceValue = defaultValue; } catch (pt::ptree_bad_data &e) { + RW_UNUSED(e); // Catches illegal value data: always fail parseResult.failInvalidData(key); RW_MESSAGE(e.what()); diff --git a/rwgame/GameWindow.cpp b/rwgame/GameWindow.cpp index 1267f09b..c24e5fc0 100644 --- a/rwgame/GameWindow.cpp +++ b/rwgame/GameWindow.cpp @@ -15,7 +15,7 @@ void GameWindow::create(const std::string& title, size_t w, size_t h, SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8); window = SDL_CreateWindow(title.c_str(), SDL_WINDOWPOS_CENTERED, - SDL_WINDOWPOS_CENTERED, w, h, style); + SDL_WINDOWPOS_CENTERED, static_cast(w), static_cast(h), style); if (window == nullptr) { // Window creation failure is fatal std::string sdlErrorStr = SDL_GetError(); diff --git a/rwgame/MenuSystem.hpp b/rwgame/MenuSystem.hpp index a589ef66..a11e9be2 100644 --- a/rwgame/MenuSystem.hpp +++ b/rwgame/MenuSystem.hpp @@ -116,7 +116,7 @@ public: glm::vec2 c(x - offset.x, y - offset.y); for (size_t i = 0; i < entries.size(); ++i) { if (c.y > 0.f && c.y < size) { - activeEntry = i; + activeEntry = static_cast(i); return; } else { c.y -= size; @@ -149,7 +149,7 @@ public: if (activeEntry >= static_cast(entries.size())) { activeEntry = 0; } else if (activeEntry < 0) { - activeEntry = entries.size() - 1; + activeEntry = static_cast(entries.size() - 1); } } diff --git a/rwgame/RWGame.cpp b/rwgame/RWGame.cpp index 830c49ea..8b142d77 100644 --- a/rwgame/RWGame.cpp +++ b/rwgame/RWGame.cpp @@ -224,7 +224,7 @@ void RWGame::handleCheatInput(char symbol) { 5 //sniper rifle }; for (std::array::size_type i = 0; i < ammo.size(); i++) - player->addToInventory(i+1,ammo[i]); + player->addToInventory(static_cast(i+1),ammo[i]); state.showHelpMessage("CHEAT2"); // III / VC: Inputting weapon cheats. }); diff --git a/rwgame/main.cpp b/rwgame/main.cpp index f9d04d1f..f0d4a253 100644 --- a/rwgame/main.cpp +++ b/rwgame/main.cpp @@ -15,7 +15,7 @@ int main(int argc, char* argv[]) { RWGame game(logger, argc, argv); return game.run(); - } catch (std::invalid_argument& ex) { + } catch (std::invalid_argument&) { // This exception is thrown when either an invalid command line option // or a --help is found. The RWGame constructor prints a usage message // in this case and then throws this exception. diff --git a/rwgame/states/DebugState.cpp b/rwgame/states/DebugState.cpp index be0978e0..397bffc1 100644 --- a/rwgame/states/DebugState.cpp +++ b/rwgame/states/DebugState.cpp @@ -218,7 +218,7 @@ std::shared_ptr DebugState::createWeatherMenu() { for (std::size_t i = 0; i < w.size(); ++i) { menu->lambda(w[i], - [=] { game->getWorld()->state->basic.nextWeather = i; }); + [=] { game->getWorld()->state->basic.nextWeather = static_cast(i); }); } menu->offset = kDebugMenuOffset;