store score at the end of each stage in replays

This commit is contained in:
Andrei Alexeyev 2019-04-12 00:42:47 +03:00
parent 874da52127
commit 330e259022
No known key found for this signature in database
GPG key ID: 363707CD4C7FE8A4
3 changed files with 24 additions and 1 deletions

View file

@ -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)) {

View file

@ -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;

View file

@ -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;