diff --git a/meson.build b/meson.build index 6d7b067fd..b5989cb45 100644 --- a/meson.build +++ b/meson.build @@ -123,8 +123,6 @@ else endif conf_data = configuration_data() -conf_data.set('CURL_STATICLIB', false) -conf_data.set('ZLIB_WINAPI', false) x86_sse_level_str = get_option('x86_sse') if x86_sse_level_str == 'auto' @@ -278,13 +276,11 @@ endif if host_platform == 'windows' args_ccomp_win = [ '-D_WIN32_WINNT=0x0501' ] - project_c_args += args_ccomp_win - project_cpp_args += args_ccomp_win windows_mod = import('windows') if is_static - conf_data.set('CURL_STATICLIB', true) + args_ccomp_win += [ '-DCURL_STATICLIB' ] if host_arch == 'x86_64' - conf_data.set('ZLIB_WINAPI', true) + args_ccomp_win += [ '-DZLIB_WINAPI' ] endif else foreach input_output_condition : tpt_libs.get_variable('config_dlls') @@ -302,6 +298,8 @@ if host_platform == 'windows' endif endforeach endif + project_c_args += args_ccomp_win + project_cpp_args += args_ccomp_win endif project_inc = include_directories([ 'src', 'resources' ]) @@ -329,13 +327,9 @@ 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('X86_SSE3', x86_sse_level >= 30) -conf_data.set('X86_SSE2', x86_sse_level >= 20) -conf_data.set('X86_SSE', x86_sse_level >= 10) -conf_data.set('_64BIT', is_64bit) conf_data.set('BETA', is_beta) -conf_data.set('NO_INSTALL_CHECK', not get_option('install_check')) -conf_data.set('IGNORE_UPDATES', get_option('ignore_updates')) +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) @@ -344,11 +338,11 @@ conf_data.set('SNAPSHOT_ID', get_option('snapshot_id')) conf_data.set('SERVER', get_option('server')) conf_data.set('STATICSERVER', get_option('static_server')) conf_data.set('UPDATESERVER', update_server) -conf_data.set('USE_UPDATESERVER', update_server != '') +conf_data.set('USE_UPDATESERVER', update_server != '' ? 'true' : 'false') conf_data.set('IDENT_PLATFORM', ident_platform) conf_data.set('IDENT', '@0@-@1@-@2@'.format(host_arch, host_platform, host_libc).to_upper()) -conf_data.set('ENFORCE_HTTPS', enforce_https) -conf_data.set('ALLOW_FAKE_NEWER_VERSION', is_snapshot or is_beta or is_debug or is_mod) +conf_data.set('ENFORCE_HTTPS', enforce_https ? 'true' : 'false') +conf_data.set('ALLOW_FAKE_NEWER_VERSION', (is_snapshot or is_beta or is_debug or is_mod) ? 'true' : 'false') conf_data.set('APPNAME', get_option('app_name')) conf_data.set('APPCOMMENT', get_option('app_comment')) conf_data.set('APPEXE', app_exe) diff --git a/src/Config.template.h b/src/Config.template.h index b144539b3..59a714397 100644 --- a/src/Config.template.h +++ b/src/Config.template.h @@ -2,8 +2,6 @@ #include // Boolean macros (defined / not defined), would be great to get rid of them all. -#mesondefine CURL_STATICLIB -#mesondefine ZLIB_WINAPI #mesondefine LUACONSOLE #mesondefine NOHTTP #mesondefine GRAVFFT @@ -11,22 +9,19 @@ #mesondefine FONTEDITOR #mesondefine BETA #mesondefine DEBUG -#mesondefine IGNORE_UPDATES #mesondefine LIN #mesondefine AND -#mesondefine NO_INSTALL_CHECK #mesondefine SNAPSHOT #mesondefine MOD #mesondefine WIN #mesondefine MACOSX #mesondefine X86 -#mesondefine X86_SSE -#mesondefine X86_SSE2 -#mesondefine X86_SSE3 -#mesondefine _64BIT -#mesondefine ENFORCE_HTTPS -#mesondefine ALLOW_FAKE_NEWER_VERSION -#mesondefine USE_UPDATESERVER + +constexpr bool ALLOW_FAKE_NEWER_VERSION = @ALLOW_FAKE_NEWER_VERSION@; +constexpr bool USE_UPDATESERVER = @USE_UPDATESERVER@; +constexpr bool INSTALL_CHECK = @INSTALL_CHECK@; +constexpr bool IGNORE_UPDATES = @IGNORE_UPDATES@; +constexpr bool ENFORCE_HTTPS = @ENFORCE_HTTPS@; constexpr char SERVER[] = "@SERVER@"; constexpr char STATICSERVER[] = "@STATICSERVER@"; @@ -66,16 +61,6 @@ constexpr char IDENT_RELTYPE[] = "B"; constexpr char IDENT_RELTYPE[] = "R"; #endif -#if defined(X86_SSE3) -constexpr char IDENT_BUILD[] = "SSE3"; -#elif defined(X86_SSE2) -constexpr char IDENT_BUILD[] = "SSE2"; -#elif defined(X86_SSE) -constexpr char IDENT_BUILD[] = "SSE"; -#else -constexpr char IDENT_BUILD[] = "NO"; -#endif - constexpr char SCHEME[] = "https://"; constexpr char STATICSCHEME[] = "https://"; constexpr char LOCAL_SAVE_DIR[] = "Saves"; diff --git a/src/PowderToyFontEditor.cpp b/src/PowderToyFontEditor.cpp index c03cc5162..2d0136c9d 100644 --- a/src/PowderToyFontEditor.cpp +++ b/src/PowderToyFontEditor.cpp @@ -5,13 +5,6 @@ #include #endif -#ifdef X86_SSE -#include -#endif -#ifdef X86_SSE3 -#include -#endif - #include #if defined(LIN) # include "icon_exe.png.h" diff --git a/src/PowderToySDL.cpp b/src/PowderToySDL.cpp index 68a5153dc..3ed483397 100644 --- a/src/PowderToySDL.cpp +++ b/src/PowderToySDL.cpp @@ -11,11 +11,9 @@ #endif #include -#ifdef X86_SSE -#include -#endif -#ifdef X86_SSE3 -#include +#ifdef X86 +# include +# include #endif #include @@ -835,10 +833,8 @@ int main(int argc, char * argv[]) } #endif -#ifdef X86_SSE +#ifdef X86 _MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_ON); -#endif -#ifdef X86_SSE3 _MM_SET_DENORMALS_ZERO_MODE(_MM_DENORMALS_ZERO_ON); #endif diff --git a/src/client/Client.cpp b/src/client/Client.cpp index be1871b20..102e41a60 100644 --- a/src/client/Client.cpp +++ b/src/client/Client.cpp @@ -142,16 +142,17 @@ void Client::Initialise(ByteString proxy, ByteString cafile, ByteString capath, } versionCheckRequest->Start(); -#ifdef USE_UPDATESERVER - // use an alternate update server - alternateVersionCheckRequest = new http::Request(ByteString::Build(SCHEME, UPDATESERVER, "/Startup.json")); - usingAltUpdateServer = true; - if (authUser.UserID) + if constexpr (USE_UPDATESERVER) { - alternateVersionCheckRequest->AuthHeaders(authUser.Username, ""); + // use an alternate update server + alternateVersionCheckRequest = new http::Request(ByteString::Build(SCHEME, UPDATESERVER, "/Startup.json")); + usingAltUpdateServer = true; + if (authUser.UserID) + { + alternateVersionCheckRequest->AuthHeaders(authUser.Username, ""); + } + alternateVersionCheckRequest->Start(); } - alternateVersionCheckRequest->Start(); -#endif } bool Client::IsFirstRun() @@ -312,7 +313,8 @@ bool Client::CheckUpdate(http::Request *updateRequest, bool checkSession) this->messageOfTheDay = ByteString(objDocument["MessageOfTheDay"].asString()).FromUtf8(); notifyMessageOfTheDay(); -#ifndef IGNORE_UPDATES + if constexpr (!IGNORE_UPDATES) + { //Check for updates Json::Value versions = objDocument["Updates"]; #ifndef SNAPSHOT @@ -360,7 +362,7 @@ bool Client::CheckUpdate(http::Request *updateRequest, bool checkSession) { notifyUpdateAvailable(); } -#endif + } } } catch (std::exception & e) @@ -517,13 +519,11 @@ RequestStatus Client::UploadSave(SaveInfo & save) lastError = "Cannot serialize game save"; return RequestFailure; } -#ifdef ALLOW_FAKE_NEWER_VERSION - else if (fromNewerVersion && save.GetPublished()) + else if (ALLOW_FAKE_NEWER_VERSION && fromNewerVersion && save.GetPublished()) { lastError = "Cannot publish save, incompatible with latest release version."; return RequestFailure; } -#endif data = http::Request::SimpleAuth(ByteString::Build(SCHEME, SERVER, "/Save.api"), &dataStatus, userID, authUser.SessionID, { { "Name", save.GetName().ToUtf8() }, diff --git a/src/client/GameSave.cpp b/src/client/GameSave.cpp index 60d4a2529..e4dbbdc66 100644 --- a/src/client/GameSave.cpp +++ b/src/client/GameSave.cpp @@ -675,19 +675,17 @@ void GameSave::readOPS(const std::vector &data) minor = bson_iterator_int(&subiter); } } -#ifdef ALLOW_FAKE_NEWER_VERSION - if (major > FUTURE_SAVE_VERSION || (major == FUTURE_SAVE_VERSION && minor > FUTURE_MINOR_VERSION)) -#else - if (major > SAVE_VERSION || (major == SAVE_VERSION && minor > MINOR_VERSION)) -#endif + auto majorToCheck = ALLOW_FAKE_NEWER_VERSION ? FUTURE_SAVE_VERSION : SAVE_VERSION; + auto minorToCheck = ALLOW_FAKE_NEWER_VERSION ? FUTURE_MINOR_VERSION : MINOR_VERSION; + if (major > majorToCheck || (major == majorToCheck && minor > minorToCheck)) { String errorMessage = String::Build("Save from a newer version: Requires version ", major, ".", minor); throw ParseException(ParseException::WrongVersion, errorMessage); } -#ifdef ALLOW_FAKE_NEWER_VERSION - else if (major > SAVE_VERSION || (major == SAVE_VERSION && minor > MINOR_VERSION)) + else if (ALLOW_FAKE_NEWER_VERSION && (major > SAVE_VERSION || (major == SAVE_VERSION && minor > MINOR_VERSION))) + { fakeNewerVersion = true; -#endif + } } else { @@ -2388,12 +2386,8 @@ std::pair> GameSave::serialiseOPS() const } } - bool fakeFromNewerVersion = false; -#ifdef ALLOW_FAKE_NEWER_VERSION // Mark save as incompatible with latest release - if (minimumMajorVersion > SAVE_VERSION || (minimumMajorVersion == SAVE_VERSION && minimumMinorVersion > MINOR_VERSION)) - fakeFromNewerVersion = true; -#endif + bool fakeFromNewerVersion = ALLOW_FAKE_NEWER_VERSION && (minimumMajorVersion > SAVE_VERSION || (minimumMajorVersion == SAVE_VERSION && minimumMinorVersion > MINOR_VERSION)); bson b; b.data = NULL; @@ -2411,7 +2405,6 @@ std::pair> GameSave::serialiseOPS() const bson_append_int(&b, "modId", MOD_ID); bson_append_string(&b, "releaseType", IDENT_RELTYPE); bson_append_string(&b, "platform", IDENT_PLATFORM); - bson_append_string(&b, "builtType", IDENT_BUILD); bson_append_string(&b, "ident", IDENT); bson_append_finish_object(&b); if (gravityMode == 3) diff --git a/src/client/http/Request.cpp b/src/client/http/Request.cpp index 4ab9427ae..61cb6f82a 100644 --- a/src/client/http/Request.cpp +++ b/src/client/http/Request.cpp @@ -230,23 +230,26 @@ namespace http } curl_easy_setopt(easy, CURLOPT_FOLLOWLOCATION, 1L); + if constexpr (ENFORCE_HTTPS) + { #if defined(CURL_AT_LEAST_VERSION) && CURL_AT_LEAST_VERSION(7, 85, 0) -# ifdef ENFORCE_HTTPS - curl_easy_setopt(easy, CURLOPT_PROTOCOLS_STR, "https"); - curl_easy_setopt(easy, CURLOPT_REDIR_PROTOCOLS_STR, "https"); -# else - curl_easy_setopt(easy, CURLOPT_PROTOCOLS_STR, "https,http"); - curl_easy_setopt(easy, CURLOPT_REDIR_PROTOCOLS_STR, "https,http"); -# endif + curl_easy_setopt(easy, CURLOPT_PROTOCOLS_STR, "https"); + curl_easy_setopt(easy, CURLOPT_REDIR_PROTOCOLS_STR, "https"); #else -# ifdef ENFORCE_HTTPS - curl_easy_setopt(easy, CURLOPT_PROTOCOLS, CURLPROTO_HTTPS); - curl_easy_setopt(easy, CURLOPT_REDIR_PROTOCOLS, CURLPROTO_HTTPS); -# else - curl_easy_setopt(easy, CURLOPT_PROTOCOLS, CURLPROTO_HTTPS | CURLPROTO_HTTP); - curl_easy_setopt(easy, CURLOPT_REDIR_PROTOCOLS, CURLPROTO_HTTPS | CURLPROTO_HTTP); -# endif + curl_easy_setopt(easy, CURLOPT_PROTOCOLS, CURLPROTO_HTTPS); + curl_easy_setopt(easy, CURLOPT_REDIR_PROTOCOLS, CURLPROTO_HTTPS); #endif + } + else + { +#if defined(CURL_AT_LEAST_VERSION) && CURL_AT_LEAST_VERSION(7, 85, 0) + curl_easy_setopt(easy, CURLOPT_PROTOCOLS_STR, "https,http"); + curl_easy_setopt(easy, CURLOPT_REDIR_PROTOCOLS_STR, "https,http"); +#else + curl_easy_setopt(easy, CURLOPT_PROTOCOLS, CURLPROTO_HTTPS | CURLPROTO_HTTP); + curl_easy_setopt(easy, CURLOPT_REDIR_PROTOCOLS, CURLPROTO_HTTPS | CURLPROTO_HTTP); +#endif + } SetupCurlEasyCiphers(easy); diff --git a/src/client/http/RequestManager.cpp b/src/client/http/RequestManager.cpp index 9cccc413a..ef68c3ab4 100644 --- a/src/client/http/RequestManager.cpp +++ b/src/client/http/RequestManager.cpp @@ -55,7 +55,7 @@ namespace http user_agent = ByteString::Build( "PowderToy/", SAVE_VERSION, ".", MINOR_VERSION, " (", IDENT_PLATFORM, - "; ", IDENT_BUILD, + "; NO", // Unused, used to be SSE level. "; M", MOD_ID, "; ", IDENT, ") TPTPP/", SAVE_VERSION, ".", MINOR_VERSION, ".", BUILD_NUM, IDENT_RELTYPE, ".", SNAPSHOT_ID diff --git a/src/gui/game/GameController.cpp b/src/gui/game/GameController.cpp index 8e066f0ac..ba27f5394 100644 --- a/src/gui/game/GameController.cpp +++ b/src/gui/game/GameController.cpp @@ -744,10 +744,13 @@ void GameController::Tick() #ifdef LUACONSOLE ((LuaScriptInterface*)commandInterface)->Init(); #endif -#if !defined(MACOSX) && !defined(NO_INSTALL_CHECK) - if (Client::Ref().IsFirstRun()) +#if !defined(MACOSX) + if constexpr (INSTALL_CHECK) { - Install(); + if (Client::Ref().IsFirstRun()) + { + Install(); + } } #endif firstTick = false; @@ -1672,13 +1675,15 @@ void GameController::RunUpdater() Exit(); new UpdateActivity(); #else - -#ifdef USE_UPDATESERVER - ByteString file = ByteString::Build(SCHEME, UPDATESERVER, Client::Ref().GetUpdateInfo().File); -#else - ByteString file = ByteString::Build(SCHEME, SERVER, Client::Ref().GetUpdateInfo().File); -#endif - + ByteString file; + if constexpr (USE_UPDATESERVER) + { + file = ByteString::Build(SCHEME, UPDATESERVER, Client::Ref().GetUpdateInfo().File); + } + else + { + file = ByteString::Build(SCHEME, SERVER, Client::Ref().GetUpdateInfo().File); + } Platform::OpenURI(file); #endif // MACOSX } diff --git a/src/gui/game/IntroText.h b/src/gui/game/IntroText.h index e883edeb6..d82750414 100644 --- a/src/gui/game/IntroText.h +++ b/src/gui/game/IntroText.h @@ -41,9 +41,6 @@ inline ByteString IntroText() #elif defined(MOD) sb << " MODVER " << SNAPSHOT_ID; #endif -#if defined(X86_SSE) || defined(X86_SSE2) || defined(X86_SSE3) - sb << " " << IDENT_BUILD; -#endif #ifdef LUACONSOLE sb << " LUACONSOLE"; #endif @@ -59,8 +56,9 @@ inline ByteString IntroText() #ifdef DEBUG sb << " DEBUG"; #endif -#ifdef ENFORCE_HTTPS - sb << " HTTPS"; -#endif + if constexpr (ENFORCE_HTTPS) + { + sb << " HTTPS"; + } return sb.Build(); } diff --git a/src/gui/update/UpdateActivity.cpp b/src/gui/update/UpdateActivity.cpp index 04c02d1f6..e0426c08f 100644 --- a/src/gui/update/UpdateActivity.cpp +++ b/src/gui/update/UpdateActivity.cpp @@ -118,12 +118,7 @@ private: }; UpdateActivity::UpdateActivity() { - ByteString file; -#ifdef USE_UPDATESERVER - file = ByteString::Build(SCHEME, UPDATESERVER, Client::Ref().GetUpdateInfo().File); -#else - file = ByteString::Build(SCHEME, SERVER, Client::Ref().GetUpdateInfo().File); -#endif + ByteString file = ByteString::Build(SCHEME, USE_UPDATESERVER ? UPDATESERVER : SERVER, Client::Ref().GetUpdateInfo().File); updateDownloadTask = new UpdateDownloadTask(file, this); updateWindow = new TaskWindow("Downloading update...", updateDownloadTask, true); } @@ -145,18 +140,23 @@ void UpdateActivity::Exit() void UpdateActivity::NotifyError(Task * sender) { -#ifdef USE_UPDATESERVER -# define FIRST_LINE "Please go online to manually download a newer version.\n" -#else -# define FIRST_LINE "Please visit the website to download a newer version.\n" -#endif - new ConfirmPrompt("Autoupdate failed", FIRST_LINE "Error: " + sender->GetError(), { [this] { -#ifndef USE_UPDATESERVER - Platform::OpenURI(ByteString(SCHEME) + "powdertoy.co.uk/Download.html"); -#endif + StringBuilder sb; + if constexpr (USE_UPDATESERVER) + { + sb << "Please go online to manually download a newer version.\n"; + } + else + { + sb << "Please visit the website to download a newer version.\n"; + } + sb << "Error: " << sender->GetError(); + new ConfirmPrompt("Autoupdate failed", sb.Build(), { [this] { + if constexpr (!USE_UPDATESERVER) + { + Platform::OpenURI(ByteString(SCHEME) + "powdertoy.co.uk/Download.html"); + } Exit(); }, [this] { Exit(); } }); -#undef FIRST_LINE } diff --git a/src/lua/LuaScriptInterface.cpp b/src/lua/LuaScriptInterface.cpp index 6903ee4f7..6e569ff40 100644 --- a/src/lua/LuaScriptInterface.cpp +++ b/src/lua/LuaScriptInterface.cpp @@ -4067,7 +4067,6 @@ void LuaScriptInterface::initPlatformAPI() struct luaL_Reg platformAPIMethods [] = { {"platform", platform_platform}, {"ident", platform_ident}, - {"build", platform_build}, {"releaseType", platform_releaseType}, {"exeName", platform_exeName}, {"restart", platform_restart}, @@ -4095,12 +4094,6 @@ int LuaScriptInterface::platform_ident(lua_State * l) return 1; } -int LuaScriptInterface::platform_build(lua_State * l) -{ - tpt_lua_pushByteString(l, IDENT_BUILD); - return 1; -} - int LuaScriptInterface::platform_releaseType(lua_State * l) { tpt_lua_pushByteString(l, IDENT_RELTYPE); diff --git a/src/lua/LuaScriptInterface.h b/src/lua/LuaScriptInterface.h index 50a1e5494..ba91cd3db 100644 --- a/src/lua/LuaScriptInterface.h +++ b/src/lua/LuaScriptInterface.h @@ -174,7 +174,6 @@ class LuaScriptInterface: public CommandInterface void initPlatformAPI(); static int platform_platform(lua_State * l); static int platform_ident(lua_State * l); - static int platform_build(lua_State * l); static int platform_releaseType(lua_State * l); static int platform_exeName(lua_State * l); static int platform_restart(lua_State * l);