From edf8b08386055c6f165c9080dbfc134db9610acf Mon Sep 17 00:00:00 2001 From: Holger Schemel Date: Sun, 24 Nov 2024 12:39:24 +0100 Subject: [PATCH] changed internal version number format --- src/events.c | 4 ++-- src/files.c | 31 +++++++++++++------------ src/game.c | 20 ++++++++--------- src/game.h | 2 +- src/game_mm/export_mm.h | 4 ++-- src/game_mm/mm_files.c | 20 ++++++++--------- src/init.c | 2 +- src/init.h | 2 +- src/libgame/misc.c | 23 +++++++++---------- src/libgame/misc.h | 4 ++-- src/libgame/setup.c | 4 ++-- src/libgame/setup.h | 2 +- src/libgame/system.c | 24 +++++++++++++++++++- src/libgame/system.h | 50 ++++++++++++++++++++++++++++++++--------- src/main.h | 8 +++---- src/tape.c | 4 ++-- src/tape.h | 6 ++--- 17 files changed, 131 insertions(+), 79 deletions(-) diff --git a/src/events.c b/src/events.c index b25bce3e..b6e4bc94 100644 --- a/src/events.c +++ b/src/events.c @@ -2077,8 +2077,8 @@ boolean HandleKeysDebug(Key key, int key_status) } else if (key == KSYM_v) { - Debug("event:key:debug", "currently using game engine version %d", - game.engine_version); + Debug("event:key:debug", "currently using game engine version %s", + getVersionString(game.engine_version)); return TRUE; } diff --git a/src/files.c b/src/files.c index 6ec7f0b8..c42b676d 100644 --- a/src/files.c +++ b/src/files.c @@ -3140,7 +3140,7 @@ int getMappedElement(int element) return element; } -static int getMappedElementByVersion(int element, int game_version) +static int getMappedElementByVersion(int element, VersionType game_version) { // remap some elements due to certain game version @@ -9091,8 +9091,9 @@ void DumpLevel(struct LevelInfo *level) } PrintLine("-", 79); - Print("Level xxx (file version %08d, game version %08d)\n", - level->file_version, level->game_version); + Print("Level xxx (file version %s, game version %s)\n", + getVersionString(level->file_version), + getVersionString(level->game_version)); PrintLine("-", 79); Print("Level author: '%s'\n", level->author); @@ -9299,7 +9300,7 @@ static int LoadTape_HEAD(File *file, int chunk_size, struct TapeInfo *tape) if (tape->file_version >= FILE_VERSION_1_2) { byte store_participating_players = getFile8Bit(file); - int engine_version; + VersionType engine_version; // since version 1.2, tapes store which players participate in the tape tape->num_participating_players = 0; @@ -9689,12 +9690,12 @@ void LoadTapeFromFilename(char *filename) tape.length_seconds = GetTapeLengthSeconds(); #if 0 - Debug("files:LoadTapeFromFilename", "tape file version: %d", - tape.file_version); - Debug("files:LoadTapeFromFilename", "tape game version: %d", - tape.game_version); - Debug("files:LoadTapeFromFilename", "tape engine version: %d", - tape.engine_version); + Debug("files:LoadTapeFromFilename", "tape file version: %s", + getVersionString(tape.file_version)); + Debug("files:LoadTapeFromFilename", "tape game version: %s", + getVersionString(tape.game_version)); + Debug("files:LoadTapeFromFilename", "tape engine version: %s", + getVersionString(tape.engine_version)); #endif } @@ -9948,10 +9949,12 @@ void DumpTape(struct TapeInfo *tape) PrintLine("-", 79); - Print("Tape of Level %03d (file version %08d, game version %08d)\n", - tape->level_nr, tape->file_version, tape->game_version); - Print(" (effective engine version %08d)\n", - tape->engine_version); + Print("Tape of Level %03d (file version %s, game version %s)\n", + tape->level_nr, + getVersionString(tape->file_version), + getVersionString(tape->game_version)); + Print(" (effective engine version %s)\n", + getVersionString(tape->engine_version)); Print("Level series identifier: '%s'\n", tape->level_identifier); Print("Solution tape: %s\n", diff --git a/src/game.c b/src/game.c index 0842b9d3..00a1012b 100644 --- a/src/game.c +++ b/src/game.c @@ -3032,16 +3032,16 @@ static void InitGameEngine(void) } #if 0 - Debug("game:init:level", "level %d: level.game_version == %06d", level_nr, - level.game_version); - Debug("game:init:level", " tape.file_version == %06d", - tape.file_version); - Debug("game:init:level", " tape.game_version == %06d", - tape.game_version); - Debug("game:init:level", " tape.engine_version == %06d", - tape.engine_version); - Debug("game:init:level", " => game.engine_version == %06d [tape mode: %s]", - game.engine_version, (tape.playing ? "PLAYING" : "RECORDING")); + Debug("game:init:level", "level %d: level.game_version == %s", level_nr, + getVersionString(level.game_version)); + Debug("game:init:level", " tape.file_version == %s", + getVersionString(tape.file_version)); + Debug("game:init:level", " tape.game_version == %s", + getVersionString(tape.game_version)); + Debug("game:init:level", " tape.engine_version == %s", + getVersionString(tape.engine_version)); + Debug("game:init:level", " => game.engine_version == %s [tape mode: %s]", + getVersionString(game.engine_version), (tape.playing ? "PLAYING" : "RECORDING")); #endif // -------------------------------------------------------------------------- diff --git a/src/game.h b/src/game.h index 0a5b7c26..0553d8da 100644 --- a/src/game.h +++ b/src/game.h @@ -182,7 +182,7 @@ struct GameInfo boolean use_native_bd_sound_engine; // constant within running game - int engine_version; + VersionType engine_version; int emulation; int initial_move_delay[MAX_PLAYERS]; int initial_move_delay_value[MAX_PLAYERS]; diff --git a/src/game_mm/export_mm.h b/src/game_mm/export_mm.h index 47ced95c..51b5ccec 100644 --- a/src/game_mm/export_mm.h +++ b/src/game_mm/export_mm.h @@ -172,8 +172,8 @@ struct GameInfo_MM struct LevelInfo_MM { - int file_version; // version of file the level was stored with - int game_version; // version of game engine to play this level + VersionType file_version; // version of file the level was stored with + VersionType game_version; // version of game engine to play this level boolean encoding_16bit_field; // level contains 16-bit elements int fieldx; diff --git a/src/game_mm/mm_files.c b/src/game_mm/mm_files.c index 4a853609..d56b01c0 100644 --- a/src/game_mm/mm_files.c +++ b/src/game_mm/mm_files.c @@ -44,10 +44,10 @@ int default_score[LEVEL_SCORE_ELEMENTS] = // level file functions // ============================================================================ -static void ReadChunk_MM_VERS(File *file, int *file_version, int *game_version) +static void ReadChunk_MM_VERS(File *file, VersionType *file_version, VersionType *game_version) { - int file_version_major, file_version_minor, file_version_patch; - int game_version_major, game_version_minor, game_version_patch; + VersionSubType file_version_major, file_version_minor, file_version_patch; + VersionSubType game_version_major, game_version_minor, game_version_patch; file_version_major = getFile8Bit(file); file_version_minor = getFile8Bit(file); @@ -68,14 +68,14 @@ static void ReadChunk_MM_VERS(File *file, int *file_version, int *game_version) game_version_patch); } -static void WriteChunk_MM_VERS(FILE *file, int file_version, int game_version) +static void WriteChunk_MM_VERS(FILE *file, VersionType file_version, VersionType game_version) { - int file_version_major = MM_VERSION_MAJOR(file_version); - int file_version_minor = MM_VERSION_MINOR(file_version); - int file_version_patch = MM_VERSION_PATCH(file_version); - int game_version_major = MM_VERSION_MAJOR(game_version); - int game_version_minor = MM_VERSION_MINOR(game_version); - int game_version_patch = MM_VERSION_PATCH(game_version); + VersionSubType file_version_major = MM_VERSION_MAJOR(file_version); + VersionSubType file_version_minor = MM_VERSION_MINOR(file_version); + VersionSubType file_version_patch = MM_VERSION_PATCH(file_version); + VersionSubType game_version_major = MM_VERSION_MAJOR(game_version); + VersionSubType game_version_minor = MM_VERSION_MINOR(game_version); + VersionSubType game_version_patch = MM_VERSION_PATCH(game_version); fputc(file_version_major, file); fputc(file_version_minor, file); diff --git a/src/init.c b/src/init.c index a5cce8a4..acb25874 100644 --- a/src/init.c +++ b/src/init.c @@ -4836,7 +4836,7 @@ void InitElementPropertiesStatic(void) clipboard_elements_initialized = TRUE; } -void InitElementPropertiesEngine(int engine_version) +void InitElementPropertiesEngine(VersionType engine_version) { static int no_wall_properties[] = { diff --git a/src/init.h b/src/init.h index 7fcbfcd6..9479f0f8 100644 --- a/src/init.h +++ b/src/init.h @@ -28,7 +28,7 @@ boolean getBitfieldProperty(int *, int, int); void ResolveGroupElement(int); void InitElementPropertiesStatic(void); -void InitElementPropertiesEngine(int); +void InitElementPropertiesEngine(VersionType); void InitElementPropertiesGfxElement(void); void ReloadCustomArtwork(int); diff --git a/src/libgame/misc.c b/src/libgame/misc.c index 5cc80f79..9bc779e1 100644 --- a/src/libgame/misc.c +++ b/src/libgame/misc.c @@ -2227,25 +2227,24 @@ int putFileChunk(FILE *file, char *chunk_name, int chunk_size, return num_bytes; } -int getFileVersion(File *file) +VersionType getFileVersion(File *file) { - int version_super = getByteFromFile(file); - int version_major = getByteFromFile(file); - int version_minor = getByteFromFile(file); - int version_patch = getByteFromFile(file); + VersionSubType version_super = getByteFromFile(file); + VersionSubType version_major = getByteFromFile(file); + VersionSubType version_minor = getByteFromFile(file); + VersionSubType version_patch = getByteFromFile(file); - return VERSION_IDENT(version_super, version_major, version_minor, - version_patch); + return VERSION_IDENT(version_super, version_major, version_minor, version_patch); } -int putFileVersion(FILE *file, int version) +int putFileVersion(FILE *file, VersionType version) { if (file != NULL) { - int version_super = VERSION_SUPER(version); - int version_major = VERSION_MAJOR(version); - int version_minor = VERSION_MINOR(version); - int version_patch = VERSION_PATCH(version); + VersionSubType version_super = VERSION_SUPER(version); + VersionSubType version_major = VERSION_MAJOR(version); + VersionSubType version_minor = VERSION_MINOR(version); + VersionSubType version_patch = VERSION_PATCH(version); fputc(version_super, file); fputc(version_major, file); diff --git a/src/libgame/misc.h b/src/libgame/misc.h index 2b927e57..640ef092 100644 --- a/src/libgame/misc.h +++ b/src/libgame/misc.h @@ -229,8 +229,8 @@ int putFile32BitInteger(FILE *, int, int); boolean getFileChunk(File *, char *, int *, int); int putFileChunk(FILE *, char *, int, int); -int getFileVersion(File *); -int putFileVersion(FILE *, int); +VersionType getFileVersion(File *); +int putFileVersion(FILE *, VersionType); void ReadBytesFromFile(File *, byte *, unsigned int); void WriteBytesToFile(FILE *, byte *, unsigned int); diff --git a/src/libgame/setup.c b/src/libgame/setup.c index f2680ef5..aa0a44f5 100644 --- a/src/libgame/setup.c +++ b/src/libgame/setup.c @@ -2221,7 +2221,7 @@ void fprintFileHeader(FILE *file, char *basename) fprintf(file, "\n"); } -int getFileVersionFromCookieString(const char *cookie) +VersionType getFileVersionFromCookieString(const char *cookie) { const char *ptr_cookie1, *ptr_cookie2; const char *pattern1 = "_FILE_VERSION_"; @@ -2230,7 +2230,7 @@ int getFileVersionFromCookieString(const char *cookie) const int len_pattern1 = strlen(pattern1); const int len_pattern2 = strlen(pattern2); const int len_pattern = len_pattern1 + len_pattern2; - int version_super, version_major; + VersionSubType version_super, version_major; if (len_cookie <= len_pattern) return -1; diff --git a/src/libgame/setup.h b/src/libgame/setup.h index bb0dd842..028a1142 100644 --- a/src/libgame/setup.h +++ b/src/libgame/setup.h @@ -354,7 +354,7 @@ void InitUserDataDirectory(void); void SetFilePermissions(char *, int); void fprintFileHeader(FILE *, char *); -int getFileVersionFromCookieString(const char *); +VersionType getFileVersionFromCookieString(const char *); boolean checkCookieString(const char *, const char *); char *getFormattedSetupEntry(char *, char *); diff --git a/src/libgame/system.c b/src/libgame/system.c index 4ceca3c3..7a18fcf6 100644 --- a/src/libgame/system.c +++ b/src/libgame/system.c @@ -73,7 +73,7 @@ void InitProgramInfo(char *command_filename, char *config_filename, char *userdata_subdir, char *program_basename, char *program_title, char *icon_filename, char *cookie_prefix, - char *program_version_string, int program_version) + char *program_version_string, VersionType program_version) { program.command_basepath = getBasePath(command_filename); program.command_basename = getBaseName(command_filename); @@ -1925,6 +1925,28 @@ void ClearJoystickState(void) } +// ============================================================================ +// version functions +// ============================================================================ + +char *getVersionString(VersionType version) +{ + // this function can be called up to ten times before version string gets overwritten + static char version_string_array[10][32]; + static int version_string_nr = 0; + char *version_string = version_string_array[version_string_nr]; + + version_string_nr = (version_string_nr + 1) % 10; + + sprintf(version_string, "%d.%d.%d.%d", + VERSION_PART_1(version), + VERSION_PART_2(version), + VERSION_PART_3(version), + VERSION_PART_4(version)); + + return version_string; +} + // ============================================================================ // Emscripten functions // ============================================================================ diff --git a/src/libgame/system.h b/src/libgame/system.h index 0f01fd97..7b25e15e 100644 --- a/src/libgame/system.h +++ b/src/libgame/system.h @@ -776,16 +776,20 @@ // macros for version handling -#define VERSION_PART_1(x) ((x) / 1000000) -#define VERSION_PART_2(x) (((x) % 1000000) / 10000) -#define VERSION_PART_3(x) (((x) % 10000) / 100) -#define VERSION_PART_4(x) ((x) % 100) +#define VERSION_PART_1(x) ((VersionSubType)(((x) >> 56) & 0xff)) +#define VERSION_PART_2(x) ((VersionSubType)(((x) >> 48) & 0xff)) +#define VERSION_PART_3(x) ((VersionSubType)(((x) >> 40) & 0xff)) +#define VERSION_PART_4(x) ((VersionSubType)(((x) >> 32) & 0xff)) #define VERSION_SUPER(x) VERSION_PART_1(x) #define VERSION_MAJOR(x) VERSION_PART_2(x) #define VERSION_MINOR(x) VERSION_PART_3(x) #define VERSION_PATCH(x) VERSION_PART_4(x) -#define VERSION_IDENT(a,b,c,d) ((a) * 1000000 + (b) * 10000 + (c) * 100 + (d)) + +#define VERSION_IDENT(a,b,c,d) (((VersionType)(a) << 56) | \ + ((VersionType)(b) << 48) | \ + ((VersionType)(c) << 40) | \ + ((VersionType)(d) << 32)) // macros for parent/child process identification @@ -979,8 +983,30 @@ } +// type definitions + +typedef unsigned long VersionType; +typedef unsigned char VersionSubType; + + // structure definitions +struct VersionInfo +{ + // this structure is currently only used to document the content bytes of "VersionType" + + // standard version info + VersionSubType super; // incremented for extraordinary changes (almost never) + VersionSubType major; // incremented for major changes + VersionSubType minor; // incremented for minor changes + VersionSubType patch; // incremented for bug fixes only + + // extended version info + VersionSubType stable; // set to "1" for stable versions, "0" for test versions + VersionSubType extra; // set to extra (test or pre-release) version number + unsigned short build; // set to build number +}; + struct ProgramInfo { char *command_basepath; // path to the program binary @@ -1005,11 +1031,11 @@ struct ProgramInfo FILE *log_file; // file handle for log files FILE *log_file_default; // default log file handle - int version_super; - int version_major; - int version_minor; - int version_patch; - int version_ident; + VersionSubType version_super; + VersionSubType version_major; + VersionSubType version_minor; + VersionSubType version_patch; + VersionType version_ident; char *version_string; @@ -1953,7 +1979,7 @@ extern int FrameCounter; // function definitions void InitProgramInfo(char *, char *, char *, char *, char *, char *, char *, - char *, int); + char *, VersionType); void InitNetworkInfo(boolean, boolean, boolean, char *, int); void InitRuntimeInfo(void); @@ -2081,6 +2107,8 @@ boolean ReadJoystick(int, int *, int *, boolean *, boolean *); boolean CheckJoystickOpened(int); void ClearJoystickState(void); +char *getVersionString(VersionType); + void InitEmscriptenFilesystem(void); void SyncEmscriptenFilesystem(void); diff --git a/src/main.h b/src/main.h index befd24d5..0819dd51 100644 --- a/src/main.h +++ b/src/main.h @@ -3660,8 +3660,8 @@ struct ScoreEntry struct ScoreInfo { - int file_version; // file format version the score is stored with - int game_version; // game release version the score was created with + VersionType file_version; // file format version the score is stored with + VersionType game_version; // game release version the score was created with char level_identifier[MAX_FILENAME_LEN + 1]; int level_nr; @@ -3733,8 +3733,8 @@ struct LevelInfo struct LevelInfo_SP *native_sp_level; struct LevelInfo_MM *native_mm_level; - int file_version; // file format version the level is stored with - int game_version; // game release version the level was created with + VersionType file_version; // file format version the level is stored with + VersionType game_version; // game release version the level was created with struct DateInfo creation_date; diff --git a/src/tape.c b/src/tape.c index 10e495fe..c6eeee4e 100644 --- a/src/tape.c +++ b/src/tape.c @@ -1739,7 +1739,7 @@ static int AutoPlayTapesExt(boolean initialize) NULL }; - static int patch_version_first[] = + static VersionType patch_version_first[] = { VERSION_IDENT(0,0,0,0), VERSION_IDENT(3,3,1,0), @@ -1748,7 +1748,7 @@ static int AutoPlayTapesExt(boolean initialize) -1 }; - static int patch_version_last[] = + static VersionType patch_version_last[] = { VERSION_IDENT(9,9,9,9), VERSION_IDENT(4,0,1,1), diff --git a/src/tape.h b/src/tape.h index dc10d986..1c909cd5 100644 --- a/src/tape.h +++ b/src/tape.h @@ -192,9 +192,9 @@ struct TapeTextInfo struct TapeInfo { - int file_version; // file format version the tape is stored with - int game_version; // game release version the tape was created with - int engine_version; // game engine version the tape was recorded with + VersionType file_version; // file format version the tape is stored with + VersionType game_version; // game release version the tape was created with + VersionType engine_version; // game engine version the tape was recorded with char score_tape_basename[MAX_FILENAME_LEN + 1]; char level_identifier[MAX_FILENAME_LEN + 1]; -- 2.34.1