From 330e25902265951c755e05ef08a9e3b650f55794 Mon Sep 17 00:00:00 2001 From: Andrei Alexeyev <0x416b617269@gmail.com> Date: Fri, 12 Apr 2019 00:42:47 +0300 Subject: [PATCH] store score at the end of each stage in replays --- src/replay.c | 14 ++++++++++++++ src/replay.h | 10 +++++++++- src/stage.c | 1 + 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/replay.c b/src/replay.c index 05c1eade..62878e23 100644 --- a/src/replay.c +++ b/src/replay.c @@ -193,6 +193,10 @@ static uint32_t replay_calc_stageinfo_checksum(ReplayStage *stg, uint16_t versio cs += stg->plr_point_item_value; } + if(version >= REPLAY_STRUCT_VERSION_TS103000_REV3) { + cs += stg->plr_points_final; + } + log_debug("%08x", cs); return cs; } @@ -220,6 +224,11 @@ static bool replay_write_stage(ReplayStage *stg, SDL_RWops *file, uint16_t versi SDL_WriteU8(file, stg->plr_inputflags); SDL_WriteLE32(file, stg->plr_graze); SDL_WriteLE32(file, stg->plr_point_item_value); + + if(version >= REPLAY_STRUCT_VERSION_TS103000_REV3) { + SDL_WriteLE64(file, stg->plr_points_final); + } + SDL_WriteLE16(file, stg->numevents); SDL_WriteLE32(file, 1 + ~replay_calc_stageinfo_checksum(stg, version)); @@ -359,6 +368,7 @@ static bool replay_read_header(Replay *rpy, SDL_RWops *file, int64_t filesize, s case REPLAY_STRUCT_VERSION_TS103000_REV0: case REPLAY_STRUCT_VERSION_TS103000_REV1: case REPLAY_STRUCT_VERSION_TS103000_REV2: + case REPLAY_STRUCT_VERSION_TS103000_REV3: { if(taisei_version_read(file, &rpy->game_version) != TAISEI_VERSION_SIZE) { log_error("%s: Failed to read game version", source); @@ -469,6 +479,10 @@ static bool replay_read_meta(Replay *rpy, SDL_RWops *file, int64_t filesize, con stg->plr_point_item_value = PLR_START_PIV; } + if(version >= REPLAY_STRUCT_VERSION_TS103000_REV3) { + CHECKPROP(stg->plr_points_final = SDL_ReadLE64(file), zu); + } + CHECKPROP(stg->numevents = SDL_ReadLE16(file), u); if(replay_calc_stageinfo_checksum(stg, version) + SDL_ReadLE32(file)) { diff --git a/src/replay.h b/src/replay.h index f09d0e7f..d7c0b26d 100644 --- a/src/replay.h +++ b/src/replay.h @@ -49,13 +49,16 @@ // Taisei v1.3 revision 2: RNG changed; seed separated from start time; time expanded to 64bit #define REPLAY_STRUCT_VERSION_TS103000_REV2 11 + + // Taisei v1.3 revision 3: add final score at the end of each stage + #define REPLAY_STRUCT_VERSION_TS103000_REV3 12 /* END supported struct versions */ #define REPLAY_VERSION_COMPRESSION_BIT 0x8000 #define REPLAY_COMPRESSION_CHUNK_SIZE 4096 // What struct version to use when saving recorded replays -#define REPLAY_STRUCT_VERSION_WRITE (REPLAY_STRUCT_VERSION_TS103000_REV2 | REPLAY_VERSION_COMPRESSION_BIT) +#define REPLAY_STRUCT_VERSION_WRITE (REPLAY_STRUCT_VERSION_TS103000_REV3 | REPLAY_VERSION_COMPRESSION_BIT) #define REPLAY_ALLOC_INITIAL 256 @@ -120,6 +123,11 @@ typedef struct ReplayStage { uint32_t plr_point_item_value; /* END REPLAY_STRUCT_VERSION_TS103000_REV0 and above */ + /* BEGIN REPLAY_STRUCT_VERSION_TS102000_REV3 and above */ + // player score at the end of the stage + uint64_t plr_points_final; + /* END REPLAY_STRUCT_VERSION_TS102000_REV3 and above */ + // player input uint16_t numevents; diff --git a/src/stage.c b/src/stage.c index fee8076a..5a23d709 100644 --- a/src/stage.c +++ b/src/stage.c @@ -893,6 +893,7 @@ void stage_end_loop(void* ctx) { if(global.replaymode == REPLAY_RECORD) { replay_stage_event(global.replay_stage, global.frames, EV_OVER, 0); + global.replay_stage->plr_points_final = global.plr.points; if(global.gameover == GAMEOVER_WIN) { global.replay_stage->flags |= REPLAY_SFLAG_CLEAR;