fix replays
This commit is contained in:
parent
fab1eb2bc5
commit
77c6790051
4 changed files with 37 additions and 18 deletions
|
@ -77,7 +77,7 @@ int cli_args(int argc, char **argv, CLIAction *a) {
|
|||
}
|
||||
|
||||
int c;
|
||||
int stageid = -1;
|
||||
uint16_t stageid = 0;
|
||||
|
||||
#define INVALID_CHAR ((Character)-1)
|
||||
#define INVALID_SHOT ((ShotMode)-1)
|
||||
|
@ -149,7 +149,7 @@ int cli_args(int argc, char **argv, CLIAction *a) {
|
|||
}
|
||||
}
|
||||
|
||||
if(stageid != -1) {
|
||||
if(stageid) {
|
||||
if(a->type != CLI_PlayReplay && a->type != CLI_SelectStage) {
|
||||
log_warn("--sid was ignored");
|
||||
} else if(!stage_get(stageid)) {
|
||||
|
@ -167,7 +167,7 @@ int cli_args(int argc, char **argv, CLIAction *a) {
|
|||
|
||||
a->stageid = stageid;
|
||||
|
||||
if(a->type == CLI_SelectStage && stageid == -1)
|
||||
if(a->type == CLI_SelectStage && stageid)
|
||||
log_fatal("StageSelect mode, but no stage id was given");
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -111,6 +111,7 @@ int main(int argc, char **argv) {
|
|||
setlocale(LC_ALL, "C");
|
||||
|
||||
Replay replay = {0};
|
||||
int replay_idx = 0;
|
||||
|
||||
init_paths();
|
||||
init_log();
|
||||
|
@ -137,6 +138,11 @@ int main(int argc, char **argv) {
|
|||
if(!replay_load(&replay, a.filename, REPLAY_READ_ALL | REPLAY_READ_RAWPATH)) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
replay_idx = a.stageid ? replay_find_stage_idx(&replay, a.stageid) : 0;
|
||||
if(replay_idx < 0) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
log_info("Content path: %s", get_prefix());
|
||||
|
@ -175,7 +181,7 @@ int main(int argc, char **argv) {
|
|||
atexit(taisei_shutdown);
|
||||
|
||||
if(a.type == CLI_PlayReplay) {
|
||||
replay_play(&replay, a.stageid);
|
||||
replay_play(&replay, replay_idx);
|
||||
replay_destroy(&replay);
|
||||
return 0;
|
||||
}
|
||||
|
|
35
src/replay.c
35
src/replay.c
|
@ -640,20 +640,34 @@ int replay_test(void) {
|
|||
#endif
|
||||
}
|
||||
|
||||
void replay_play(Replay *rpy, int firststageid) {
|
||||
int replay_find_stage_idx(Replay *rpy, uint8_t stageid) {
|
||||
assert(rpy != NULL);
|
||||
assert(rpy->stages != NULL);
|
||||
|
||||
for(int i = 0; i < rpy->numstages; ++i) {
|
||||
if(rpy->stages[i].stage == stageid) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
log_warn("Stage %x was not found in the replay", stageid);
|
||||
return -1;
|
||||
}
|
||||
|
||||
void replay_play(Replay *rpy, int firstidx) {
|
||||
if(rpy != &global.replay) {
|
||||
replay_copy(&global.replay, rpy, true);
|
||||
}
|
||||
|
||||
if(firstidx >= global.replay.numstages || firstidx < 0) {
|
||||
log_warn("No stage #%i in the replay", firstidx);
|
||||
return;
|
||||
}
|
||||
|
||||
global.replaymode = REPLAY_PLAY;
|
||||
|
||||
bool skip = true;
|
||||
for(int i = 0; i < global.replay.numstages; ++i) {
|
||||
for(int i = firstidx; i < global.replay.numstages; ++i) {
|
||||
ReplayStage *rstg = global.replay_stage = global.replay.stages+i;
|
||||
if(rstg->stage == firststageid || firststageid == -1)
|
||||
skip = false;
|
||||
if(skip)
|
||||
continue;
|
||||
StageInfo *gstg = stage_get(rstg->stage);
|
||||
|
||||
if(!gstg) {
|
||||
|
@ -670,9 +684,6 @@ void replay_play(Replay *rpy, int firststageid) {
|
|||
global.game_over = 0;
|
||||
}
|
||||
|
||||
if(skip == true)
|
||||
log_warn("Stage %x was not found in the replay", firststageid);
|
||||
|
||||
global.game_over = 0;
|
||||
global.replaymode = REPLAY_RECORD;
|
||||
replay_destroy(&global.replay);
|
||||
|
@ -680,12 +691,12 @@ void replay_play(Replay *rpy, int firststageid) {
|
|||
free_resources(false);
|
||||
}
|
||||
|
||||
void replay_play_path(const char *path, int firststage) {
|
||||
void replay_play_path(const char *path, int firstidx) {
|
||||
replay_destroy(&global.replay);
|
||||
|
||||
if(!replay_load(&global.replay, path, REPLAY_READ_ALL | REPLAY_READ_RAWPATH)) {
|
||||
return;
|
||||
}
|
||||
|
||||
replay_play(&global.replay, firststage);
|
||||
replay_play(&global.replay, firstidx);
|
||||
}
|
||||
|
|
|
@ -162,8 +162,10 @@ void replay_copy(Replay *dst, Replay *src, bool steal_events);
|
|||
|
||||
char* replay_getpath(const char *name, bool ext); // must be freed
|
||||
|
||||
void replay_play(Replay *rpy, int firststage);
|
||||
void replay_play_path(const char *path, int firststage);
|
||||
void replay_play(Replay *rpy, int firstidx);
|
||||
void replay_play_path(const char *path, int firstidx);
|
||||
|
||||
int replay_find_stage_idx(Replay *rpy, uint8_t stageid);
|
||||
|
||||
#endif
|
||||
|
||||
|
|
Loading…
Reference in a new issue