Record fps stats in replays. Display the player's name and fps when watching

This commit is contained in:
Andrei "Akari" Alexeyev 2017-03-21 04:28:35 +02:00
parent 574ffefa0f
commit d8ac035f29
6 changed files with 34 additions and 11 deletions

View file

@ -331,6 +331,10 @@ void player_event(Player* plr, int type, int key) {
case EV_AXIS_UD:
plr->axis_ud = key;
break;
default:
log_warn("Unknown event type %d (value=%d)", type, key);
break;
}
}

View file

@ -87,6 +87,7 @@ enum {
EV_AXIS_LR,
EV_AXIS_UD,
EV_CHECK_DESYNC, // replay-only
EV_FPS, // replay-only
};
void init_player(Player*);

View file

@ -85,7 +85,9 @@ typedef struct ReplayStage {
// events allocated (may be higher than numevents)
int capacity;
// used during playback
int playpos;
int fps;
uint16_t desync_check;
} ReplayStage;

View file

@ -290,7 +290,7 @@ void replay_input(void) {
handle_events(stage_replay_event, EF_Game, NULL);
for(i = s->playpos; i < s->numevents; ++i) {
ReplayEvent *e = &(s->events[i]);
ReplayEvent *e = s->events + i;
if(e->frame != global.frames)
break;
@ -300,13 +300,19 @@ void replay_input(void) {
global.game_over = GAMEOVER_DEFEAT;
break;
case EV_CHECK_DESYNC:
s->desync_check = e->value;
break;
case EV_FPS:
s->fps = e->value;
break;
default:
if(global.dialog && e->type == EV_PRESS && (e->value == KEY_SHOT || e->value == KEY_BOMB))
page_dialog(&global.dialog);
else if(global.dialog && (e->type == EV_PRESS || e->type == EV_RELEASE) && e->value == KEY_SKIP)
global.dialog->skip = (e->type == EV_PRESS);
else if(e->type == EV_CHECK_DESYNC)
s->desync_check = e->value;
else
player_event(&global.plr, e->type, (int16_t)e->value);
break;
@ -377,12 +383,15 @@ void draw_hud(void) {
glPopMatrix();
#ifdef DEBUG
sprintf(buf, "%i fps / %i stgframes", global.fps.show_fps, global.timer);
#else
sprintf(buf, "%i fps", global.fps.show_fps);
#endif
draw_text(AL_Right, SCREEN_W, SCREEN_H-20, buf, _fonts.standard);
draw_text(AL_Right, SCREEN_W, SCREEN_H - 0.5 * stringheight(buf, _fonts.standard), buf, _fonts.standard);
if(global.replaymode == REPLAY_PLAY) {
sprintf(buf, "Replay: %s (%i fps)", global.replay.playername, global.replay_stage->fps);
glColor4f(0.5f, 0.5f, 0.5f, 0.5f);
draw_text(AL_Left, 0, SCREEN_H - 0.5 * stringheight(buf, _fonts.standard), buf, _fonts.standard);
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
}
if(global.boss)
draw_texture(VIEWPORT_X+creal(global.boss->pos), 590, "boss_indicator");
@ -766,7 +775,9 @@ void stage_loop(StageInfo *stage) {
continue;
}
calc_fps(&global.fps);
if(calc_fps(&global.fps) && global.replaymode == REPLAY_RECORD) {
replay_stage_event(global.replay_stage, global.frames, EV_FPS, global.fps.show_fps);
}
tsrand_lock(&global.rand_game);
tsrand_switch(&global.rand_visual);

View file

@ -188,7 +188,9 @@ void frame_rate(int *lasttime) {
*lasttime = SDL_GetTicks();
}
void calc_fps(FPSCounter *fps) {
bool calc_fps(FPSCounter *fps) {
bool updated = false;
if(!fps->stagebg_fps)
fps->stagebg_fps = FPS;
@ -196,11 +198,14 @@ void calc_fps(FPSCounter *fps) {
fps->show_fps = fps->fps;
fps->fps = 0;
fps->fpstime = SDL_GetTicks();
updated = true;
} else {
fps->fps++;
}
fps->stagebg_fps = approach(fps->stagebg_fps, fps->show_fps, 0.1);
return updated;
}
void set_ortho(void) {

View file

@ -84,7 +84,7 @@ typedef struct {
} FPSCounter;
void frame_rate(int *lasttime);
void calc_fps(FPSCounter *fps);
bool calc_fps(FPSCounter *fps);
void set_ortho(void);
void colorfill(float r, float g, float b, float a);
void fade_out(float f);