From 350f284246f183a02033c07de8c3c47810641ad0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1ty=C3=A1s=20Mustoha?= Date: Wed, 29 May 2024 21:46:58 +0200 Subject: [PATCH] Replaced the extern version comparisons with the new implementation --- src/common/GameValues.cpp | 18 ++++++----- src/common/MapList.cpp | 5 ++- src/common/global.cpp | 60 ------------------------------------ src/common/map.cpp | 23 +++++--------- src/common/map/MapReader.cpp | 23 +++++++------- src/common/map/MapReader.h | 3 +- src/smw/GSMenu.cpp | 17 +++++----- src/smw/world.cpp | 30 ++++++++---------- 8 files changed, 57 insertions(+), 122 deletions(-) diff --git a/src/common/GameValues.cpp b/src/common/GameValues.cpp index 4a80283b6..fe218f53e 100644 --- a/src/common/GameValues.cpp +++ b/src/common/GameValues.cpp @@ -5,6 +5,7 @@ #include "GameMode.h" #include "GlobalConstants.h" #include "MapList.h" // req. only by WriteConfig +#include "Version.h" #include "sfx.h" #include @@ -27,9 +28,6 @@ extern SoundsList *soundpacklist; extern short joystickcount; -extern int32_t g_iVersion[]; -extern bool VersionIsEqual(int32_t iVersion[], short iMajor, short iMinor, short iMicro, short iBuild); - //[Keyboard/Joystick][Game/Menu][NumPlayers][NumKeys] left, right, jump, down, turbo, powerup, start, cancel SDL_KEYTYPE controlkeys[2][2][4][NUM_KEYS] = { { { {SDLK_LEFT, SDLK_RIGHT, SDLK_UP, SDLK_DOWN, SDLK_RCTRL, SDLK_RSHIFT, SDLK_RETURN, SDLK_ESCAPE}, @@ -303,10 +301,13 @@ void CGameConfig::ReadBinaryConfig() { if (!options.is_open()) throw std::runtime_error("Could not open " + options_path); - int32_t version[4]; - options.read_i32_array(version, 4); + Version version; + version.major = options.read_i32(); + version.minor = options.read_i32(); + version.patch = options.read_i32(); + version.build = options.read_i32(); - if (!VersionIsEqual(g_iVersion, version[0], version[1], version[2], version[3])) { + if (GAME_VERSION != version) { printf("Old options.bin detected. Skipped reading it.\n"); return; } @@ -449,7 +450,10 @@ void CGameConfig::WriteConfig() const if (!options.is_open()) throw std::runtime_error("Could not open " + options_path); - options.write_raw(g_iVersion, sizeof(int) * 4); + options.write_i32(GAME_VERSION.major); + options.write_i32(GAME_VERSION.minor); + options.write_i32(GAME_VERSION.patch); + options.write_i32(GAME_VERSION.build); options.write_u8(static_cast(spawnstyle)); options.write_u8(static_cast(awardstyle)); diff --git a/src/common/MapList.cpp b/src/common/MapList.cpp index 66326f271..1681e6322 100644 --- a/src/common/MapList.cpp +++ b/src/common/MapList.cpp @@ -5,13 +5,12 @@ #include "GameValues.h" #include "linfunc.h" #include "map.h" +#include "Version.h" #include #include #include -extern int32_t g_iVersion[]; - extern CMap* g_map; extern FiltersList* filterslist; extern CGameValues game_values; @@ -433,7 +432,7 @@ void MapList::WriteFilters() continue; fprintf(fp, "#Version\n"); - fprintf(fp, "%d.%d.%d.%d\n\n", g_iVersion[0], g_iVersion[1], g_iVersion[2], g_iVersion[3]); + fprintf(fp, "%d.%d.%d.%d\n\n", GAME_VERSION.major, GAME_VERSION.minor, GAME_VERSION.patch, GAME_VERSION.build); fprintf(fp, "#Icon\n"); fprintf(fp, "%d\n\n", game_values.piFilterIcons[iFilter + NUM_AUTO_FILTERS]); diff --git a/src/common/global.cpp b/src/common/global.cpp index e4c21be2c..53024d234 100644 --- a/src/common/global.cpp +++ b/src/common/global.cpp @@ -1,6 +1,5 @@ #include "FileList.h" #include "GameValues.h" -#include "Game.h" #include "gfx.h" #include "map.h" #include "MapList.h" @@ -11,15 +10,6 @@ #include #include -//1.8.0.0 == Release to staff -//1.8.0.1 == Second release to staff -//1.8.0.2 == beta1 -//1.8.0.3 == beta2 -//1.8.0.4 == final -//1.9.0.0 == neagix work-in-progress, not released -//2.0.0.0 == fluffypillow netplay code -int32_t g_iVersion[] = {2, 0, 0, 0}; - // main game directory, read from command line argument #ifdef __ANDROID__ std::string RootDataDirectory = GetHomeDirectory() + "data"; @@ -28,56 +18,6 @@ std::string RootDataDirectory = GetRootDirectory() + "data"; #endif CResourceManager *rm; - -bool VersionIsEqual(int32_t iVersion[], short iMajor, short iMinor, short iMicro, short iBuild) -{ - return iVersion[0] == iMajor && iVersion[1] == iMinor && iVersion[2] == iMicro && iVersion[3] == iBuild; -} - -bool VersionIsEqualOrBefore(int32_t iVersion[], short iMajor, short iMinor, short iMicro, short iBuild) -{ - if (iVersion[0] < iMajor) - return true; - - if (iVersion[0] == iMajor) { - if (iVersion[1] < iMinor) - return true; - - if (iVersion[1] == iMinor) { - if (iVersion[2] < iMicro) - return true; - - if (iVersion[2] == iMicro) { - return iVersion[3] <= iBuild; - } - } - } - - return false; -} - -bool VersionIsEqualOrAfter(int32_t iVersion[], short iMajor, short iMinor, short iMicro, short iBuild) -{ - if (iVersion[0] > iMajor) - return true; - - if (iVersion[0] == iMajor) { - if (iVersion[1] > iMinor) - return true; - - if (iVersion[1] == iMinor) { - if (iVersion[2] > iMicro) - return true; - - if (iVersion[2] == iMicro) { - return iVersion[3] >= iBuild; - } - } - } - - return false; -} - CGameValues game_values; FiltersList *filterslist; //Filters list must be initiallized before maps list because it is used in maplist constructor diff --git a/src/common/map.cpp b/src/common/map.cpp index fd18c25f0..70946cf33 100644 --- a/src/common/map.cpp +++ b/src/common/map.cpp @@ -10,6 +10,7 @@ #include "RandomNumberGenerator.h" #include "ResourceManager.h" #include "TilesetManager.h" +#include "Version.h" #include "SDL_image.h" #include "sdl12wrapper.h" @@ -39,11 +40,6 @@ using std::endl; extern gfxSprite spr_frontmap[2]; -// extern int32_t g_iVersion[]; - -extern bool VersionIsEqual(int32_t iVersion[], short iMajor, short iMinor, short iMicro, short iBuild); -extern bool VersionIsEqualOrBefore(int32_t iVersion[], short iMajor, short iMinor, short iMicro, short iBuild); -extern bool VersionIsEqualOrAfter(int32_t iVersion[], short iMajor, short iMinor, short iMicro, short iBuild); //Converts the tile type into the flags that this tile carries (solid + ice + death, etc) short g_iTileTypeConversion[NUMTILETYPES] = {0, 1, 2, 5, 121, 9, 17, 33, 65, 6, 21, 37, 69, 3961, 265, 529, 1057, 2113, 4096}; @@ -581,13 +577,11 @@ void CMap::loadMap(const std::string& file, ReadType iReadType) return; } - //Load version number - int32_t version[4]; - //version[0] = mapfile.read_i32(); //Major - //version[1] = mapfile.read_i32(); //Minor - //version[2] = mapfile.read_i32(); //Micro - //version[3] = mapfile.read_i32(); //Build - mapfile.read_i32_array(version, 4); + Version version; + version.major = mapfile.read_i32(); + version.minor = mapfile.read_i32(); + version.patch = mapfile.read_i32(); + version.build = mapfile.read_i32(); if (iReadType != read_type_summary) { cout << "loading map " << file; @@ -595,9 +589,8 @@ void CMap::loadMap(const std::string& file, ReadType iReadType) if (iReadType == read_type_preview) cout << " (preview)"; - if (VersionIsEqualOrAfter(version, 1, 6, 0, 0)) { - cout << " [v" << version[0] << '.' << version[1] << '.' - << version[2] << '.' << version[3] << "]"; + if (version >= Version {1, 6, 0, 0}) { + printf(" [v%d.%d.%d.%d]", version.major, version.minor, version.patch, version.build); } else cout << " [v1.5]"; diff --git a/src/common/map/MapReader.cpp b/src/common/map/MapReader.cpp index fa59e6e2b..f19438aa8 100644 --- a/src/common/map/MapReader.cpp +++ b/src/common/map/MapReader.cpp @@ -1,40 +1,41 @@ #include "map/MapReader.h" -extern bool VersionIsEqualOrAfter(int32_t iVersion[], short iMajor, short iMinor, short iMicro, short iBuild); +#include "Version.h" -MapReader* MapReader::getLoaderByVersion(int32_t (&mapversion)[4]) + +MapReader* MapReader::getLoaderByVersion(const Version& mapversion) { /* v1.8.x readers */ - if (VersionIsEqualOrAfter(mapversion, 1, 8, 0, 2)) + if (mapversion >= Version {1, 8, 0, 2}) return new MapReader1802(); - if (VersionIsEqualOrAfter(mapversion, 1, 8, 0, 1)) + if (mapversion >= Version {1, 8, 0, 1}) return new MapReader1801(); - if (VersionIsEqualOrAfter(mapversion, 1, 8, 0, 0)) + if (mapversion >= Version {1, 8, 0, 0}) return new MapReader1800(); /* v1.7.x readers */ - if (VersionIsEqualOrAfter(mapversion, 1, 7, 0, 2)) + if (mapversion >= Version {1, 7, 0, 2}) return new MapReader1702(); - if (VersionIsEqualOrAfter(mapversion, 1, 7, 0, 1)) + if (mapversion >= Version {1, 7, 0, 1}) return new MapReader1701(); - if (VersionIsEqualOrAfter(mapversion, 1, 7, 0, 0)) + if (mapversion >= Version {1, 7, 0, 0}) return new MapReader1700(); /* 1.6.x readers */ - if (VersionIsEqualOrAfter(mapversion, 1, 6, 1, 0)) + if (mapversion >= Version {1, 6, 1, 0}) return new MapReader1610(); - if (VersionIsEqualOrAfter(mapversion, 1, 6, 0, 10)) + if (mapversion >= Version {1, 6, 0, 10}) return new MapReader160A(); - if (VersionIsEqualOrAfter(mapversion, 1, 6, 0, 0)) + if (mapversion >= Version {1, 6, 0, 0}) return new MapReader1600(); /* Return 1.5 reader */ diff --git a/src/common/map/MapReader.h b/src/common/map/MapReader.h index 1b07c0816..1bb487cba 100644 --- a/src/common/map/MapReader.h +++ b/src/common/map/MapReader.h @@ -7,6 +7,7 @@ class CMap; class MovingPlatformPath; struct TilesetTile; struct MapTile; +struct Version; enum ReadType: unsigned char; class MapReader { @@ -16,7 +17,7 @@ class MapReader { virtual bool load(CMap&, BinaryFile&, ReadType) = 0; - static MapReader* getLoaderByVersion(int32_t (&mapversion)[4]); + static MapReader* getLoaderByVersion(const Version& mapversion); }; /* diff --git a/src/smw/GSMenu.cpp b/src/smw/GSMenu.cpp index abf7566fb..642ff58cc 100644 --- a/src/smw/GSMenu.cpp +++ b/src/smw/GSMenu.cpp @@ -22,6 +22,7 @@ #include "ui/MI_TourStop.h" #include "ui/MI_World.h" #include "world.h" +#include "Version.h" #include "menu/BonusWheelMenu.h" #include "menu/GameSettingsMenu.h" @@ -82,7 +83,7 @@ extern WorldMap g_worldmap; extern void LoadCurrentMapBackground(); -extern TourStop * ParseTourStopLine(char * buffer, int32_t iVersion[4], bool fIsWorld); +extern TourStop * ParseTourStopLine(char * buffer, const Version& version, bool fIsWorld); extern CMap* g_map; @@ -1476,7 +1477,7 @@ bool MenuState::ReadTourFile() char buffer[256]; bool fReadVersion = false; - int32_t iVersion[4] = {0, 0, 0, 0}; + Version version {0, 0, 0, 0}; while (fgets(buffer, 256, fp) && game_values.tourstoptotal < 10) { if (strchr(ignorable_leads, buffer[0])) continue; @@ -1486,24 +1487,24 @@ bool MenuState::ReadTourFile() char * psz = strtok(buffer, ".\n"); if (psz) - iVersion[0] = atoi(psz); + version.major = atoi(psz); psz = strtok(NULL, ".\n"); if (psz) - iVersion[1] = atoi(psz); + version.minor = atoi(psz); psz = strtok(NULL, ".\n"); if (psz) - iVersion[2] = atoi(psz); + version.patch = atoi(psz); psz = strtok(NULL, ".\n"); if (psz) - iVersion[3] = atoi(psz); + version.build = atoi(psz); continue; } - TourStop * ts = ParseTourStopLine(buffer, iVersion, false); + TourStop * ts = ParseTourStopLine(buffer, version, false); game_values.tourstops.push_back(ts); game_values.tourstoptotal++; @@ -1513,7 +1514,7 @@ bool MenuState::ReadTourFile() mTourStopMenu->miTourStop->Refresh(game_values.tourstopcurrent); //For old tours, turn on the bonus wheel at the end - if (iVersion[0] == 1 && iVersion[1] == 7 && iVersion[2] == 0 && iVersion[3] <= 1) + if (version.major == 1 && version.minor == 7 && version.patch == 0 && version.build <= 1) game_values.tourstops[game_values.tourstoptotal - 1]->iBonusType = 1; } diff --git a/src/smw/world.cpp b/src/smw/world.cpp index 89edc447a..26d936063 100644 --- a/src/smw/world.cpp +++ b/src/smw/world.cpp @@ -7,6 +7,7 @@ #include "ResourceManager.h" #include "FileList.h" #include "MapList.h" +#include "Version.h" #include #include // atoi() @@ -22,18 +23,13 @@ #endif void ResetTourStops(); -TourStop * ParseTourStopLine(char * buffer, int32_t iVersion[4], bool fIsWorld); +TourStop * ParseTourStopLine(char * buffer, const Version& version, bool fIsWorld); void WriteTourStopLine(TourStop * ts, char * buffer, bool fIsWorld); WorldMap g_worldmap; extern std::string stripPathAndExtension(const std::string &path); -extern int32_t g_iVersion[]; -extern bool VersionIsEqual(int32_t iVersion[], short iMajor, short iMinor, short iMicro, short iBuild); -extern bool VersionIsEqualOrBefore(int32_t iVersion[], short iMajor, short iMinor, short iMicro, short iBuild); -extern bool VersionIsEqualOrAfter(int32_t iVersion[], short iMajor, short iMinor, short iMicro, short iBuild); - extern CGameMode * gamemodes[GAMEMODE_LAST]; extern SDL_Surface* blitdest; @@ -416,7 +412,7 @@ bool WorldMap::Load(short tilesize) std::string line; char* buffer = NULL; short iReadType = 0; - int32_t iVersion[4] = {0, 0, 0, 0}; + Version version {0, 0, 0, 0}; short iMapTileReadRow = 0; short iCurrentStage = 0; short iCurrentWarp = 0; @@ -439,19 +435,19 @@ bool WorldMap::Load(short tilesize) if (iReadType == 0) { //Read version number char * psz = strtok(buffer, ".\n"); if (psz) - iVersion[0] = atoi(psz); + version.major = atoi(psz); psz = strtok(NULL, ".\n"); if (psz) - iVersion[1] = atoi(psz); + version.minor = atoi(psz); psz = strtok(NULL, ".\n"); if (psz) - iVersion[2] = atoi(psz); + version.patch = atoi(psz); psz = strtok(NULL, ".\n"); if (psz) - iVersion[3] = atoi(psz); + version.build = atoi(psz); iReadType = 1; } else if (iReadType == 1) { //music category @@ -619,7 +615,7 @@ bool WorldMap::Load(short tilesize) iReadType = iNumStages == 0 ? 12 : 11; } else if (iReadType == 11) { //stage details - TourStop * ts = ParseTourStopLine(buffer, iVersion, true); + TourStop * ts = ParseTourStopLine(buffer, version, true); game_values.tourstops.push_back(ts); game_values.tourstoptotal++; @@ -1752,7 +1748,7 @@ short ReadTourStopSetting(T& output, T defaultVal) } } -TourStop * ParseTourStopLine(char * buffer, int32_t iVersion[4], bool fIsWorld) +TourStop * ParseTourStopLine(char * buffer, const Version& version, bool fIsWorld) { TourStop * ts = new TourStop(); ts->fUseSettings = false; @@ -1789,7 +1785,7 @@ TourStop * ParseTourStopLine(char * buffer, int32_t iVersion[4], bool fIsWorld) ts->iMode = -1; //If this is 1.8.0.2 or earlier and we are playing a minigame, use the default map - if (VersionIsEqualOrBefore(iVersion, 1, 8, 0, 2) && + if (version <= Version {1, 8, 0, 2} && (ts->iMode == game_mode_pipe_minigame || ts->iMode == game_mode_boss_minigame || ts->iMode == game_mode_boxes_minigame)) { //Get a bogus map name so the mode will know to load the default map ts->pszMapFile = maplist->GetUnknownMapName(); @@ -1819,7 +1815,7 @@ TourStop * ParseTourStopLine(char * buffer, int32_t iVersion[4], bool fIsWorld) //The pipe minigame was using the value 24 from version 1.8.0.0 to 1.8.0.2 //It was later switched to 1000 to accomodate new modes easily - if (VersionIsEqualOrBefore(iVersion, 1, 8, 0, 2)) { + if (version <= Version {1, 8, 0, 2}) { if (ts->iMode == 24) ts->iMode = game_mode_pipe_minigame; } @@ -1846,7 +1842,7 @@ TourStop * ParseTourStopLine(char * buffer, int32_t iVersion[4], bool fIsWorld) ts->iGoal = 50; } - if (VersionIsEqualOrAfter(iVersion, 1, 7, 0, 2)) { + if (version >= Version {1, 7, 0, 2}) { pszTemp = strtok(NULL, ",\n"); //Read in point value for tour stop @@ -1920,7 +1916,7 @@ TourStop * ParseTourStopLine(char * buffer, int32_t iVersion[4], bool fIsWorld) sprintf(ts->szName, "Tour Stop %d", game_values.tourstoptotal + 1); } - if (VersionIsEqualOrAfter(iVersion, 1, 8, 0, 0)) { + if (version >= Version {1, 8, 0, 0}) { if (fIsWorld) { //is this a world ending stage? pszTemp = strtok(NULL, ",\n");