From ab446790e858f7d9e325be32d96acd2aa509003d Mon Sep 17 00:00:00 2001 From: Misa Date: Fri, 25 Sep 2020 09:11:52 -0700 Subject: [PATCH] Axe BoolToString() in favor of int casts When I encountered this function, I asked myself, why make a dedicated function instead of casting to int? Well, as it turns out, you can't just cast to int, because you have to convert it to a string by doing help.String(number).c_str(), like all the other ints. So it's actually more wasteful to do it the normal way instead of using BoolToString(). That is, until my recent changes came along and made it so that you can just provide an int and it'll automatically be converted to a string, no questions asked. Now, it's more optimal to do a straight cast to int instead of having to go through a middleman function. So this function is getting axed in favor of casting to int instead. --- desktop_version/src/Game.cpp | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-) diff --git a/desktop_version/src/Game.cpp b/desktop_version/src/Game.cpp index 4d4dcfc6..16fee6d1 100644 --- a/desktop_version/src/Game.cpp +++ b/desktop_version/src/Game.cpp @@ -25,19 +25,6 @@ #define strcasecmp stricmp #endif -//TODO: Non Urgent code cleanup -const char* BoolToString(bool _b) -{ - if(_b) - { - return "1"; - } - else - { - return "0"; - } -} - bool GetButtonFromString(const char *pText, SDL_GameControllerButton *button) { if (*pText == '0' || @@ -5855,10 +5842,10 @@ std::string Game::writemaingamesave(tinyxml2::XMLDocument& doc) xml::update_tag(msgs, "companion", companion); xml::update_tag(msgs, "lastsaved", lastsaved); - xml::update_tag(msgs, "supercrewmate", BoolToString(supercrewmate)); + xml::update_tag(msgs, "supercrewmate", (int) supercrewmate); xml::update_tag(msgs, "scmprogress", scmprogress); - xml::update_tag(msgs, "scmmoveme", BoolToString(scmmoveme)); + xml::update_tag(msgs, "scmmoveme", (int) scmmoveme); xml::update_tag(msgs, "frames", frames); @@ -5873,8 +5860,8 @@ std::string Game::writemaingamesave(tinyxml2::XMLDocument& doc) xml::update_tag(msgs, "hardestroom", hardestroom.c_str()); xml::update_tag(msgs, "hardestroomdeaths", hardestroomdeaths); - xml::update_tag(msgs, "finalmode", BoolToString(map.finalmode)); - xml::update_tag(msgs, "finalstretch", BoolToString(map.finalstretch)); + xml::update_tag(msgs, "finalmode", (int) map.finalmode); + xml::update_tag(msgs, "finalstretch", (int) map.finalstretch); std::string summary = savearea + ", " + timestring(); @@ -5988,10 +5975,10 @@ void Game::customsavequick(std::string savfile) xml::update_tag(msgs, "companion", companion); xml::update_tag(msgs, "lastsaved", lastsaved); - xml::update_tag(msgs, "supercrewmate", BoolToString(supercrewmate)); + xml::update_tag(msgs, "supercrewmate", (int) supercrewmate); xml::update_tag(msgs, "scmprogress", scmprogress); - xml::update_tag(msgs, "scmmoveme", BoolToString(scmmoveme)); + xml::update_tag(msgs, "scmmoveme", (int) scmmoveme); xml::update_tag(msgs, "frames", frames); @@ -6006,7 +5993,7 @@ void Game::customsavequick(std::string savfile) xml::update_tag(msgs, "hardestroom", hardestroom.c_str()); xml::update_tag(msgs, "hardestroomdeaths", hardestroomdeaths); - xml::update_tag(msgs, "showminimap", BoolToString(map.customshowmm)); + xml::update_tag(msgs, "showminimap", (int) map.customshowmm); std::string summary = savearea + ", " + timestring(); xml::update_tag(msgs, "summary", summary.c_str());