From 63850e78b500900d64ef3e5a83634106818a47ea Mon Sep 17 00:00:00 2001 From: Holger Schemel Date: Sun, 15 Sep 2024 14:13:06 +0200 Subject: [PATCH] changed tape flag for solved level to tape property bit This change has the advantage that some more property bits can be stored in tape files. It has the disadvantage that previous program versions may treat a tape as a solution tape when it really isn't (but instead has other property bits set). As this is only used for the "dump tape" command on the command line, this potential problem can safely be ignored. --- src/files.c | 13 +++++++++---- src/game.c | 4 ++-- src/tape.c | 6 +++--- src/tape.h | 26 +++++++++++++++++--------- 4 files changed, 31 insertions(+), 18 deletions(-) diff --git a/src/files.c b/src/files.c index 102753dd..9089e9a0 100644 --- a/src/files.c +++ b/src/files.c @@ -9266,8 +9266,10 @@ static int LoadTape_HEAD(File *file, int chunk_size, struct TapeInfo *tape) setTapeActionFlags(tape, getFile8Bit(file)); - tape->property_bits = getFile8Bit(file); - tape->solved = getFile8Bit(file); + tape->property_bits = getFile16BitBE(file); + + // set flag for marking if this tape solves the level or not + tape->solved = (tape->property_bits & TAPE_PROPERTY_LEVEL_SOLVED) != 0; engine_version = getFileVersion(file); if (engine_version > 0) @@ -9708,6 +9710,10 @@ static void SaveTape_HEAD(FILE *file, struct TapeInfo *tape) if (tape->player_participates[i]) store_participating_players |= (1 << i); + // if this tape solves the level, set corresponding tape property bit + if (tape->solved) + tape->property_bits |= TAPE_PROPERTY_LEVEL_SOLVED; + putFile32BitBE(file, tape->random_seed); putFile32BitBE(file, tape->date); putFile32BitBE(file, tape->length); @@ -9716,8 +9722,7 @@ static void SaveTape_HEAD(FILE *file, struct TapeInfo *tape) putFile8Bit(file, getTapeActionValue(tape)); - putFile8Bit(file, tape->property_bits); - putFile8Bit(file, tape->solved); + putFile16BitBE(file, tape->property_bits); putFileVersion(file, tape->engine_version); } diff --git a/src/game.c b/src/game.c index c813f823..c8989ce3 100644 --- a/src/game.c +++ b/src/game.c @@ -17238,7 +17238,7 @@ static void GameUndo(int steps) if (!CheckEngineSnapshotList()) return; - int tape_property_bits = tape.property_bits; + unsigned short tape_property_bits = tape.property_bits; LoadEngineSnapshot_Undo(steps); @@ -17252,7 +17252,7 @@ static void GameRedo(int steps) if (!CheckEngineSnapshotList()) return; - int tape_property_bits = tape.property_bits; + unsigned short tape_property_bits = tape.property_bits; LoadEngineSnapshot_Redo(steps); diff --git a/src/tape.c b/src/tape.c index 7eb09f26..ae1dae6b 100644 --- a/src/tape.c +++ b/src/tape.c @@ -1754,7 +1754,7 @@ static int AutoPlayTapesExt(boolean initialize) -1 }; - static byte patch_property_bit[] = + static unsigned short patch_property_bit[] = { TAPE_PROPERTY_NONE, TAPE_PROPERTY_EM_RANDOM_BUG, @@ -2280,14 +2280,14 @@ static boolean PatchTape(struct TapeInfo *tape, char *mode) if (strEqual(mode, "info")) { - Print("property bits == 0x%02x\n", tape->property_bits); + Print("property bits == 0x%04x\n", tape->property_bits); return FALSE; } boolean unpatch_tape = FALSE; boolean use_property_bit = FALSE; - byte property_bitmask = 0; + unsigned short property_bitmask = 0; if (strSuffix(mode, ":0") || strSuffix(mode, ":off") || diff --git a/src/tape.h b/src/tape.h index 361806ad..1b67f8dc 100644 --- a/src/tape.h +++ b/src/tape.h @@ -37,14 +37,22 @@ // values for tape properties stored in tape file #define TAPE_PROPERTY_NONE 0 -#define TAPE_PROPERTY_EM_RANDOM_BUG (1 << 0) -#define TAPE_PROPERTY_GAME_SPEED (1 << 1) -#define TAPE_PROPERTY_PAUSE_MODE (1 << 2) -#define TAPE_PROPERTY_SINGLE_STEP (1 << 3) -#define TAPE_PROPERTY_SNAPSHOT (1 << 4) -#define TAPE_PROPERTY_REPLAYED (1 << 5) -#define TAPE_PROPERTY_TAS_KEYS (1 << 6) -#define TAPE_PROPERTY_SMALL_GRAPHICS (1 << 7) +#define TAPE_PROPERTY_LEVEL_SOLVED (1 << 0) +#define TAPE_PROPERTY_UNUSED_BIT_1 (1 << 1) +#define TAPE_PROPERTY_UNUSED_BIT_2 (1 << 2) +#define TAPE_PROPERTY_UNUSED_BIT_3 (1 << 3) +#define TAPE_PROPERTY_UNUSED_BIT_4 (1 << 4) +#define TAPE_PROPERTY_UNUSED_BIT_5 (1 << 5) +#define TAPE_PROPERTY_UNUSED_BIT_6 (1 << 6) +#define TAPE_PROPERTY_UNUSED_BIT_7 (1 << 7) +#define TAPE_PROPERTY_EM_RANDOM_BUG (1 << 8) +#define TAPE_PROPERTY_GAME_SPEED (1 << 9) +#define TAPE_PROPERTY_PAUSE_MODE (1 << 10) +#define TAPE_PROPERTY_SINGLE_STEP (1 << 11) +#define TAPE_PROPERTY_SNAPSHOT (1 << 12) +#define TAPE_PROPERTY_REPLAYED (1 << 13) +#define TAPE_PROPERTY_TAS_KEYS (1 << 14) +#define TAPE_PROPERTY_SMALL_GRAPHICS (1 << 15) // values for score tape basename length (date, time, name hash, no extension) #define MAX_SCORE_TAPE_BASENAME_LEN 24 @@ -221,7 +229,7 @@ struct TapeInfo boolean use_mouse_actions; // bits to indicate which tape properties are stored in this tape - byte property_bits; + unsigned short property_bits; // special game_engine_flags; boolean bd_replay; -- 2.34.1