Preprocessor purge round 12: BETA, SNAPSHOT, MOD

This commit is contained in:
Tamás Bálint Misius 2023-01-09 21:26:56 +01:00
parent 9068920de3
commit b16cbf86fc
No known key found for this signature in database
GPG Key ID: 5B472A12F6ECA9F2
10 changed files with 120 additions and 104 deletions

View File

@ -327,13 +327,13 @@ conf_data.set('AND', host_platform == 'android')
conf_data.set('WIN', host_platform == 'windows') conf_data.set('WIN', host_platform == 'windows')
conf_data.set('MACOSX', host_platform == 'darwin') conf_data.set('MACOSX', host_platform == 'darwin')
conf_data.set('X86', is_x86) 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('INSTALL_CHECK', get_option('install_check') ? 'true' : 'false')
conf_data.set('IGNORE_UPDATES', get_option('ignore_updates') ? 'true' : 'false') conf_data.set('IGNORE_UPDATES', get_option('ignore_updates') ? 'true' : 'false')
conf_data.set('MOD_ID', mod_id) conf_data.set('MOD_ID', mod_id)
conf_data.set('DEBUG', is_debug) conf_data.set('DEBUG', is_debug)
conf_data.set('SNAPSHOT', is_snapshot) conf_data.set('SNAPSHOT', is_snapshot ? 'true' : 'false')
conf_data.set('MOD', is_mod) conf_data.set('MOD', is_mod ? 'true' : 'false')
conf_data.set('SNAPSHOT_ID', get_option('snapshot_id')) conf_data.set('SNAPSHOT_ID', get_option('snapshot_id'))
conf_data.set('SERVER', get_option('server')) conf_data.set('SERVER', get_option('server'))
conf_data.set('STATICSERVER', get_option('static_server')) conf_data.set('STATICSERVER', get_option('static_server'))

View File

@ -5,16 +5,16 @@
#mesondefine NOHTTP #mesondefine NOHTTP
#mesondefine RENDERER #mesondefine RENDERER
#mesondefine FONTEDITOR #mesondefine FONTEDITOR
#mesondefine BETA
#mesondefine DEBUG #mesondefine DEBUG
#mesondefine LIN #mesondefine LIN
#mesondefine AND #mesondefine AND
#mesondefine SNAPSHOT
#mesondefine MOD
#mesondefine WIN #mesondefine WIN
#mesondefine MACOSX #mesondefine MACOSX
#mesondefine X86 #mesondefine X86
constexpr bool BETA = @BETA@;
constexpr bool SNAPSHOT = @SNAPSHOT@;
constexpr bool MOD = @MOD@;
constexpr bool GRAVFFT = @GRAVFFT@; constexpr bool GRAVFFT = @GRAVFFT@;
constexpr bool LUACONSOLE = @LUACONSOLE@; constexpr bool LUACONSOLE = @LUACONSOLE@;
constexpr bool ALLOW_FAKE_NEWER_VERSION = @ALLOW_FAKE_NEWER_VERSION@; 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; constexpr int FUTURE_MINOR_VERSION = 0;
//VersionInfoEnd //VersionInfoEnd
#if defined(SNAPSHOT) constexpr char IDENT_RELTYPE = SNAPSHOT ? 'S' : (BETA ? 'B' : 'R');
constexpr char IDENT_RELTYPE[] = "S";
#elif defined(BETA)
constexpr char IDENT_RELTYPE[] = "B";
#else
constexpr char IDENT_RELTYPE[] = "R";
#endif
constexpr char SCHEME[] = "https://"; constexpr char SCHEME[] = "https://";
constexpr char STATICSCHEME[] = "https://"; constexpr char STATICSCHEME[] = "https://";

View File

@ -313,53 +313,55 @@ bool Client::CheckUpdate(http::Request *updateRequest, bool checkSession)
if constexpr (!IGNORE_UPDATES) if constexpr (!IGNORE_UPDATES)
{ {
//Check for updates //Check for updates
Json::Value versions = objDocument["Updates"]; Json::Value versions = objDocument["Updates"];
#ifndef SNAPSHOT if constexpr (!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)
{ {
updateAvailable = true; Json::Value stableVersion = versions["Stable"];
updateInfo = UpdateInfo(betaMajor, betaMinor, betaBuild, betaFile, betaChangelog, UpdateInfo::Beta); 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) if (!updateAvailable)
Json::Value snapshotVersion = versions["Snapshot"]; {
int snapshotSnapshot = snapshotVersion["Snapshot"].asInt(); Json::Value betaVersion = versions["Beta"];
ByteString snapshotFile = snapshotVersion["File"].asString(); int betaMajor = betaVersion["Major"].asInt();
String snapshotChangelog = ByteString(snapshotVersion["Changelog"].asString()).FromUtf8(); int betaMinor = betaVersion["Minor"].asInt();
if (snapshotSnapshot > SNAPSHOT_ID) int betaBuild = betaVersion["Build"].asInt();
{ ByteString betaFile = betaVersion["File"].asString();
updateAvailable = true; String betaChangelog = ByteString(betaVersion["Changelog"].asString()).FromUtf8();
updateInfo = UpdateInfo(snapshotSnapshot, snapshotFile, snapshotChangelog, UpdateInfo::Snapshot); if (betaBuild > BUILD_NUM)
} {
#endif updateAvailable = true;
updateInfo = UpdateInfo(betaMajor, betaMinor, betaBuild, betaFile, betaChangelog, UpdateInfo::Beta);
}
}
if(updateAvailable) if constexpr (SNAPSHOT || MOD)
{ {
notifyUpdateAvailable(); 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();
}
} }
} }
} }

View File

@ -2403,7 +2403,7 @@ std::pair<bool, std::vector<char>> GameSave::serialiseOPS() const
bson_append_int(&b, "buildNum", BUILD_NUM); bson_append_int(&b, "buildNum", BUILD_NUM);
bson_append_int(&b, "snapshotId", SNAPSHOT_ID); bson_append_int(&b, "snapshotId", SNAPSHOT_ID);
bson_append_int(&b, "modId", MOD_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, "platform", IDENT_PLATFORM);
bson_append_string(&b, "ident", IDENT); bson_append_string(&b, "ident", IDENT);
bson_append_finish_object(&b); bson_append_finish_object(&b);

View File

@ -58,7 +58,7 @@ namespace http
"; NO", // Unused, used to be SSE level. "; NO", // Unused, used to be SSE level.
"; M", MOD_ID, "; M", MOD_ID,
"; ", IDENT, "; ", 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(); }); worker_thread = std::thread([this]() { Worker(); });

View File

@ -1599,27 +1599,43 @@ void GameController::NotifyUpdateAvailable(Client * sender)
updateMessage << "Click \"Continue\" to download the latest version from our website.\n\nCurrent version:\n "; updateMessage << "Click \"Continue\" to download the latest version from our website.\n\nCurrent version:\n ";
#endif #endif
#ifdef SNAPSHOT if constexpr (SNAPSHOT)
updateMessage << "Snapshot " << SNAPSHOT_ID; {
#elif defined(MOD) updateMessage << "Snapshot " << SNAPSHOT_ID;
updateMessage << "Mod version " << SNAPSHOT_ID; }
#elif defined(BETA) else if constexpr (MOD)
updateMessage << SAVE_VERSION << "." << MINOR_VERSION << " Beta, Build " << BUILD_NUM; {
#else updateMessage << "Mod version " << SNAPSHOT_ID;
updateMessage << SAVE_VERSION << "." << MINOR_VERSION << " Stable, Build " << BUILD_NUM; }
#endif 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 "; updateMessage << "\nNew version:\n ";
if (info.Type == UpdateInfo::Beta) if (info.Type == UpdateInfo::Beta)
{
updateMessage << info.Major << "." << info.Minor << " Beta, Build " << info.Build; updateMessage << info.Major << "." << info.Minor << " Beta, Build " << info.Build;
}
else if (info.Type == UpdateInfo::Snapshot) else if (info.Type == UpdateInfo::Snapshot)
#if defined(MOD) {
updateMessage << "Mod version " << info.Time; if constexpr (MOD)
#else {
updateMessage << "Snapshot " << info.Time; updateMessage << "Mod version " << info.Time;
#endif }
else
{
updateMessage << "Snapshot " << info.Time;
}
}
else if(info.Type == UpdateInfo::Stable) else if(info.Type == UpdateInfo::Stable)
{
updateMessage << info.Major << "." << info.Minor << " Stable, Build " << info.Build; updateMessage << info.Major << "." << info.Minor << " Stable, Build " << info.Build;
}
if (info.Changelog.length()) if (info.Changelog.length())
updateMessage << "\n\nChangelog:\n" << info.Changelog; updateMessage << "\n\nChangelog:\n" << info.Changelog;
@ -1631,11 +1647,14 @@ void GameController::NotifyUpdateAvailable(Client * sender)
switch(sender->GetUpdateInfo().Type) switch(sender->GetUpdateInfo().Type)
{ {
case UpdateInfo::Snapshot: case UpdateInfo::Snapshot:
#if defined(MOD) 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 mod update is available - click here to update"));
gameModel->AddNotification(new UpdateNotification(this, "A new snapshot is available - click here to update")); }
#endif else
{
gameModel->AddNotification(new UpdateNotification(this, "A new snapshot is available - click here to update"));
}
break; break;
case UpdateInfo::Stable: case UpdateInfo::Stable:
gameModel->AddNotification(new UpdateNotification(this, "A new version is available - click here to update")); gameModel->AddNotification(new UpdateNotification(this, "A new version is available - click here to update"));

View File

@ -28,19 +28,25 @@ inline ByteString IntroText()
"\bgSimon Robertshaw, Skresanov Savely, cracker64, Catelite, Bryan Hoyle, Nathan Cousins, jacksonmj,\n" "\bgSimon Robertshaw, Skresanov Savely, cracker64, Catelite, Bryan Hoyle, Nathan Cousins, jacksonmj,\n"
"\bgFelix Wallin, Lieuwe Mosch, Anthony Boot, Me4502, MaksProg, jacob1, mniip, LBPHacker\n" "\bgFelix Wallin, Lieuwe Mosch, Anthony Boot, Me4502, MaksProg, jacob1, mniip, LBPHacker\n"
"\n"; "\n";
#ifndef BETA if constexpr (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"
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";
"\brIf you are planning on publishing any saves, use the release version.\n"; }
#endif else
{
sb << "\bgTo use online features such as saving, you need to register at: \brhttps://powdertoy.co.uk/Register.html\n";
}
sb << "\n" sb << "\n"
<< "\bt" << SAVE_VERSION << "." << MINOR_VERSION << "." << BUILD_NUM << " " << IDENT; << "\bt" << SAVE_VERSION << "." << MINOR_VERSION << "." << BUILD_NUM << " " << IDENT;
#ifdef SNAPSHOT if constexpr (SNAPSHOT)
sb << " SNAPSHOT " << SNAPSHOT_ID; {
#elif defined(MOD) sb << " SNAPSHOT " << SNAPSHOT_ID;
sb << " MODVER " << SNAPSHOT_ID; }
#endif else if constexpr (MOD)
{
sb << " MODVER " << SNAPSHOT_ID;
}
if constexpr (LUACONSOLE) if constexpr (LUACONSOLE)
{ {
sb << " LUACONSOLE"; sb << " LUACONSOLE";

View File

@ -5,11 +5,7 @@ namespace ui
struct Border struct Border
{ {
#if ENABLE_FLOAT_UI using BORDER_T = int;
# define BORDER_T float
#else
# define BORDER_T int
#endif
BORDER_T Top; BORDER_T Top;
BORDER_T Right; BORDER_T Right;

View File

@ -6,11 +6,7 @@ namespace ui
//Lightweight 2D Int32/Float32 Point struct for UI //Lightweight 2D Int32/Float32 Point struct for UI
struct Point struct Point
{ {
#if ENABLE_FLOAT_UI using POINT_T = int;
# define POINT_T float
#else
# define POINT_T int
#endif
POINT_T X; POINT_T X;
POINT_T Y; POINT_T Y;

View File

@ -314,11 +314,14 @@ LuaScriptInterface::LuaScriptInterface(GameController * c, GameModel * m):
lua_setfield(l, tptPropertiesVersion, "minor"); lua_setfield(l, tptPropertiesVersion, "minor");
lua_pushinteger(l, BUILD_NUM); lua_pushinteger(l, BUILD_NUM);
lua_setfield(l, tptPropertiesVersion, "build"); lua_setfield(l, tptPropertiesVersion, "build");
#if defined(SNAPSHOT) || defined(MOD) if constexpr (SNAPSHOT || MOD)
lua_pushinteger(l, SNAPSHOT_ID); {
#else lua_pushinteger(l, SNAPSHOT_ID);
lua_pushinteger(l, 0); }
#endif else
{
lua_pushinteger(l, 0);
}
lua_setfield(l, tptPropertiesVersion, "snapshot"); lua_setfield(l, tptPropertiesVersion, "snapshot");
lua_pushinteger(l, MOD_ID); lua_pushinteger(l, MOD_ID);
lua_setfield(l, tptPropertiesVersion, "modid"); lua_setfield(l, tptPropertiesVersion, "modid");
@ -4100,7 +4103,7 @@ int LuaScriptInterface::platform_ident(lua_State * l)
int LuaScriptInterface::platform_releaseType(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; return 1;
} }