From b16cbf86fcf8ef86de48a0589590fa987016555a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tam=C3=A1s=20B=C3=A1lint=20Misius?= Date: Mon, 9 Jan 2023 21:26:56 +0100 Subject: [PATCH] Preprocessor purge round 12: BETA, SNAPSHOT, MOD --- meson.build | 6 +- src/Config.template.h | 14 ++--- src/client/Client.cpp | 88 +++++++++++++++--------------- src/client/GameSave.cpp | 2 +- src/client/http/RequestManager.cpp | 2 +- src/gui/game/GameController.cpp | 57 ++++++++++++------- src/gui/game/IntroText.h | 28 ++++++---- src/gui/interface/Border.h | 6 +- src/gui/interface/Point.h | 6 +- src/lua/LuaScriptInterface.cpp | 15 +++-- 10 files changed, 120 insertions(+), 104 deletions(-) diff --git a/meson.build b/meson.build index bbc3a7016..49f2db343 100644 --- a/meson.build +++ b/meson.build @@ -327,13 +327,13 @@ conf_data.set('AND', host_platform == 'android') conf_data.set('WIN', host_platform == 'windows') conf_data.set('MACOSX', host_platform == 'darwin') conf_data.set('X86', is_x86) -conf_data.set('BETA', is_beta) +conf_data.set('BETA', is_beta ? 'true' : 'false') conf_data.set('INSTALL_CHECK', get_option('install_check') ? 'true' : 'false') conf_data.set('IGNORE_UPDATES', get_option('ignore_updates') ? 'true' : 'false') conf_data.set('MOD_ID', mod_id) conf_data.set('DEBUG', is_debug) -conf_data.set('SNAPSHOT', is_snapshot) -conf_data.set('MOD', is_mod) +conf_data.set('SNAPSHOT', is_snapshot ? 'true' : 'false') +conf_data.set('MOD', is_mod ? 'true' : 'false') conf_data.set('SNAPSHOT_ID', get_option('snapshot_id')) conf_data.set('SERVER', get_option('server')) conf_data.set('STATICSERVER', get_option('static_server')) diff --git a/src/Config.template.h b/src/Config.template.h index 9a4df1616..dc0da43b2 100644 --- a/src/Config.template.h +++ b/src/Config.template.h @@ -5,16 +5,16 @@ #mesondefine NOHTTP #mesondefine RENDERER #mesondefine FONTEDITOR -#mesondefine BETA #mesondefine DEBUG #mesondefine LIN #mesondefine AND -#mesondefine SNAPSHOT -#mesondefine MOD #mesondefine WIN #mesondefine MACOSX #mesondefine X86 +constexpr bool BETA = @BETA@; +constexpr bool SNAPSHOT = @SNAPSHOT@; +constexpr bool MOD = @MOD@; constexpr bool GRAVFFT = @GRAVFFT@; constexpr bool LUACONSOLE = @LUACONSOLE@; constexpr bool ALLOW_FAKE_NEWER_VERSION = @ALLOW_FAKE_NEWER_VERSION@; @@ -53,13 +53,7 @@ constexpr int FUTURE_SAVE_VERSION = 97; constexpr int FUTURE_MINOR_VERSION = 0; //VersionInfoEnd -#if defined(SNAPSHOT) -constexpr char IDENT_RELTYPE[] = "S"; -#elif defined(BETA) -constexpr char IDENT_RELTYPE[] = "B"; -#else -constexpr char IDENT_RELTYPE[] = "R"; -#endif +constexpr char IDENT_RELTYPE = SNAPSHOT ? 'S' : (BETA ? 'B' : 'R'); constexpr char SCHEME[] = "https://"; constexpr char STATICSCHEME[] = "https://"; diff --git a/src/client/Client.cpp b/src/client/Client.cpp index da21bfca3..ad0667e48 100644 --- a/src/client/Client.cpp +++ b/src/client/Client.cpp @@ -313,53 +313,55 @@ bool Client::CheckUpdate(http::Request *updateRequest, bool checkSession) if constexpr (!IGNORE_UPDATES) { - //Check for updates - Json::Value versions = objDocument["Updates"]; -#ifndef SNAPSHOT - Json::Value stableVersion = versions["Stable"]; - int stableMajor = stableVersion["Major"].asInt(); - int stableMinor = stableVersion["Minor"].asInt(); - int stableBuild = stableVersion["Build"].asInt(); - ByteString stableFile = stableVersion["File"].asString(); - String stableChangelog = ByteString(stableVersion["Changelog"].asString()).FromUtf8(); - if (stableBuild > BUILD_NUM) - { - updateAvailable = true; - updateInfo = UpdateInfo(stableMajor, stableMinor, stableBuild, stableFile, stableChangelog, UpdateInfo::Stable); - } -#endif - - if (!updateAvailable) - { - Json::Value betaVersion = versions["Beta"]; - int betaMajor = betaVersion["Major"].asInt(); - int betaMinor = betaVersion["Minor"].asInt(); - int betaBuild = betaVersion["Build"].asInt(); - ByteString betaFile = betaVersion["File"].asString(); - String betaChangelog = ByteString(betaVersion["Changelog"].asString()).FromUtf8(); - if (betaBuild > BUILD_NUM) + //Check for updates + Json::Value versions = objDocument["Updates"]; + if constexpr (!SNAPSHOT) { - updateAvailable = true; - updateInfo = UpdateInfo(betaMajor, betaMinor, betaBuild, betaFile, betaChangelog, UpdateInfo::Beta); + Json::Value stableVersion = versions["Stable"]; + int stableMajor = stableVersion["Major"].asInt(); + int stableMinor = stableVersion["Minor"].asInt(); + int stableBuild = stableVersion["Build"].asInt(); + ByteString stableFile = stableVersion["File"].asString(); + String stableChangelog = ByteString(stableVersion["Changelog"].asString()).FromUtf8(); + if (stableBuild > BUILD_NUM) + { + updateAvailable = true; + updateInfo = UpdateInfo(stableMajor, stableMinor, stableBuild, stableFile, stableChangelog, UpdateInfo::Stable); + } } - } -#if defined(SNAPSHOT) || defined(MOD) - Json::Value snapshotVersion = versions["Snapshot"]; - int snapshotSnapshot = snapshotVersion["Snapshot"].asInt(); - ByteString snapshotFile = snapshotVersion["File"].asString(); - String snapshotChangelog = ByteString(snapshotVersion["Changelog"].asString()).FromUtf8(); - if (snapshotSnapshot > SNAPSHOT_ID) - { - updateAvailable = true; - updateInfo = UpdateInfo(snapshotSnapshot, snapshotFile, snapshotChangelog, UpdateInfo::Snapshot); - } -#endif + if (!updateAvailable) + { + Json::Value betaVersion = versions["Beta"]; + int betaMajor = betaVersion["Major"].asInt(); + int betaMinor = betaVersion["Minor"].asInt(); + int betaBuild = betaVersion["Build"].asInt(); + ByteString betaFile = betaVersion["File"].asString(); + String betaChangelog = ByteString(betaVersion["Changelog"].asString()).FromUtf8(); + if (betaBuild > BUILD_NUM) + { + updateAvailable = true; + updateInfo = UpdateInfo(betaMajor, betaMinor, betaBuild, betaFile, betaChangelog, UpdateInfo::Beta); + } + } - if(updateAvailable) - { - notifyUpdateAvailable(); - } + if constexpr (SNAPSHOT || MOD) + { + Json::Value snapshotVersion = versions["Snapshot"]; + int snapshotSnapshot = snapshotVersion["Snapshot"].asInt(); + ByteString snapshotFile = snapshotVersion["File"].asString(); + String snapshotChangelog = ByteString(snapshotVersion["Changelog"].asString()).FromUtf8(); + if (snapshotSnapshot > SNAPSHOT_ID) + { + updateAvailable = true; + updateInfo = UpdateInfo(snapshotSnapshot, snapshotFile, snapshotChangelog, UpdateInfo::Snapshot); + } + } + + if(updateAvailable) + { + notifyUpdateAvailable(); + } } } } diff --git a/src/client/GameSave.cpp b/src/client/GameSave.cpp index 309330e02..be1e24673 100644 --- a/src/client/GameSave.cpp +++ b/src/client/GameSave.cpp @@ -2403,7 +2403,7 @@ std::pair> GameSave::serialiseOPS() const bson_append_int(&b, "buildNum", BUILD_NUM); bson_append_int(&b, "snapshotId", SNAPSHOT_ID); bson_append_int(&b, "modId", MOD_ID); - bson_append_string(&b, "releaseType", IDENT_RELTYPE); + bson_append_string(&b, "releaseType", ByteString(1, IDENT_RELTYPE).c_str()); bson_append_string(&b, "platform", IDENT_PLATFORM); bson_append_string(&b, "ident", IDENT); bson_append_finish_object(&b); diff --git a/src/client/http/RequestManager.cpp b/src/client/http/RequestManager.cpp index ef68c3ab4..2407501fe 100644 --- a/src/client/http/RequestManager.cpp +++ b/src/client/http/RequestManager.cpp @@ -58,7 +58,7 @@ namespace http "; NO", // Unused, used to be SSE level. "; M", MOD_ID, "; ", IDENT, - ") TPTPP/", SAVE_VERSION, ".", MINOR_VERSION, ".", BUILD_NUM, IDENT_RELTYPE, ".", SNAPSHOT_ID + ") TPTPP/", SAVE_VERSION, ".", MINOR_VERSION, ".", BUILD_NUM, ByteString(1, IDENT_RELTYPE), ".", SNAPSHOT_ID ); worker_thread = std::thread([this]() { Worker(); }); diff --git a/src/gui/game/GameController.cpp b/src/gui/game/GameController.cpp index f2f147610..b74a4dc90 100644 --- a/src/gui/game/GameController.cpp +++ b/src/gui/game/GameController.cpp @@ -1599,27 +1599,43 @@ void GameController::NotifyUpdateAvailable(Client * sender) updateMessage << "Click \"Continue\" to download the latest version from our website.\n\nCurrent version:\n "; #endif -#ifdef SNAPSHOT - updateMessage << "Snapshot " << SNAPSHOT_ID; -#elif defined(MOD) - updateMessage << "Mod version " << SNAPSHOT_ID; -#elif defined(BETA) - updateMessage << SAVE_VERSION << "." << MINOR_VERSION << " Beta, Build " << BUILD_NUM; -#else - updateMessage << SAVE_VERSION << "." << MINOR_VERSION << " Stable, Build " << BUILD_NUM; -#endif + if constexpr (SNAPSHOT) + { + updateMessage << "Snapshot " << SNAPSHOT_ID; + } + else if constexpr (MOD) + { + updateMessage << "Mod version " << SNAPSHOT_ID; + } + else if constexpr (BETA) + { + updateMessage << SAVE_VERSION << "." << MINOR_VERSION << " Beta, Build " << BUILD_NUM; + } + else + { + updateMessage << SAVE_VERSION << "." << MINOR_VERSION << " Stable, Build " << BUILD_NUM; + } updateMessage << "\nNew version:\n "; if (info.Type == UpdateInfo::Beta) + { updateMessage << info.Major << "." << info.Minor << " Beta, Build " << info.Build; + } else if (info.Type == UpdateInfo::Snapshot) -#if defined(MOD) - updateMessage << "Mod version " << info.Time; -#else - updateMessage << "Snapshot " << info.Time; -#endif + { + if constexpr (MOD) + { + updateMessage << "Mod version " << info.Time; + } + else + { + updateMessage << "Snapshot " << info.Time; + } + } else if(info.Type == UpdateInfo::Stable) + { updateMessage << info.Major << "." << info.Minor << " Stable, Build " << info.Build; + } if (info.Changelog.length()) updateMessage << "\n\nChangelog:\n" << info.Changelog; @@ -1631,11 +1647,14 @@ void GameController::NotifyUpdateAvailable(Client * sender) switch(sender->GetUpdateInfo().Type) { case UpdateInfo::Snapshot: -#if defined(MOD) - gameModel->AddNotification(new UpdateNotification(this, "A new mod update is available - click here to update")); -#else - gameModel->AddNotification(new UpdateNotification(this, "A new snapshot is available - click here to update")); -#endif + if constexpr (MOD) + { + gameModel->AddNotification(new UpdateNotification(this, "A new mod update is available - click here to update")); + } + else + { + gameModel->AddNotification(new UpdateNotification(this, "A new snapshot is available - click here to update")); + } break; case UpdateInfo::Stable: gameModel->AddNotification(new UpdateNotification(this, "A new version is available - click here to update")); diff --git a/src/gui/game/IntroText.h b/src/gui/game/IntroText.h index 99b3758d6..13bb4cbb4 100644 --- a/src/gui/game/IntroText.h +++ b/src/gui/game/IntroText.h @@ -28,19 +28,25 @@ inline ByteString IntroText() "\bgSimon Robertshaw, Skresanov Savely, cracker64, Catelite, Bryan Hoyle, Nathan Cousins, jacksonmj,\n" "\bgFelix Wallin, Lieuwe Mosch, Anthony Boot, Me4502, MaksProg, jacob1, mniip, LBPHacker\n" "\n"; -#ifndef BETA - sb << "\bgTo use online features such as saving, you need to register at: \brhttps://powdertoy.co.uk/Register.html\n"; -#else - sb << "\brThis is a BETA, you cannot save things publicly, nor open local saves and stamps made with it in older versions.\n" - "\brIf you are planning on publishing any saves, use the release version.\n"; -#endif + if constexpr (BETA) + { + sb << "\brThis is a BETA, you cannot save things publicly, nor open local saves and stamps made with it in older versions.\n" + "\brIf you are planning on publishing any saves, use the release version.\n"; + } + else + { + sb << "\bgTo use online features such as saving, you need to register at: \brhttps://powdertoy.co.uk/Register.html\n"; + } sb << "\n" << "\bt" << SAVE_VERSION << "." << MINOR_VERSION << "." << BUILD_NUM << " " << IDENT; -#ifdef SNAPSHOT - sb << " SNAPSHOT " << SNAPSHOT_ID; -#elif defined(MOD) - sb << " MODVER " << SNAPSHOT_ID; -#endif + if constexpr (SNAPSHOT) + { + sb << " SNAPSHOT " << SNAPSHOT_ID; + } + else if constexpr (MOD) + { + sb << " MODVER " << SNAPSHOT_ID; + } if constexpr (LUACONSOLE) { sb << " LUACONSOLE"; diff --git a/src/gui/interface/Border.h b/src/gui/interface/Border.h index ff55e1a03..39ed05d33 100644 --- a/src/gui/interface/Border.h +++ b/src/gui/interface/Border.h @@ -5,11 +5,7 @@ namespace ui struct Border { -#if ENABLE_FLOAT_UI -# define BORDER_T float -#else -# define BORDER_T int -#endif + using BORDER_T = int; BORDER_T Top; BORDER_T Right; diff --git a/src/gui/interface/Point.h b/src/gui/interface/Point.h index 0976162d2..9d44c207d 100644 --- a/src/gui/interface/Point.h +++ b/src/gui/interface/Point.h @@ -6,11 +6,7 @@ namespace ui //Lightweight 2D Int32/Float32 Point struct for UI struct Point { -#if ENABLE_FLOAT_UI -# define POINT_T float -#else -# define POINT_T int -#endif + using POINT_T = int; POINT_T X; POINT_T Y; diff --git a/src/lua/LuaScriptInterface.cpp b/src/lua/LuaScriptInterface.cpp index 4f356d191..b702df4e0 100644 --- a/src/lua/LuaScriptInterface.cpp +++ b/src/lua/LuaScriptInterface.cpp @@ -314,11 +314,14 @@ LuaScriptInterface::LuaScriptInterface(GameController * c, GameModel * m): lua_setfield(l, tptPropertiesVersion, "minor"); lua_pushinteger(l, BUILD_NUM); lua_setfield(l, tptPropertiesVersion, "build"); -#if defined(SNAPSHOT) || defined(MOD) - lua_pushinteger(l, SNAPSHOT_ID); -#else - lua_pushinteger(l, 0); -#endif + if constexpr (SNAPSHOT || MOD) + { + lua_pushinteger(l, SNAPSHOT_ID); + } + else + { + lua_pushinteger(l, 0); + } lua_setfield(l, tptPropertiesVersion, "snapshot"); lua_pushinteger(l, MOD_ID); lua_setfield(l, tptPropertiesVersion, "modid"); @@ -4100,7 +4103,7 @@ int LuaScriptInterface::platform_ident(lua_State * l) int LuaScriptInterface::platform_releaseType(lua_State * l) { - tpt_lua_pushByteString(l, IDENT_RELTYPE); + tpt_lua_pushByteString(l, ByteString(1, IDENT_RELTYPE)); return 1; }