enhanced DPS stats (backport from reimu branch)
This commit is contained in:
parent
f44e267188
commit
f3616f3496
5 changed files with 90 additions and 34 deletions
12
src/player.c
12
src/player.c
|
@ -966,6 +966,18 @@ void player_add_points(Player *plr, uint points) {
|
|||
}
|
||||
}
|
||||
|
||||
void player_register_damage(Player *plr, int damage) {
|
||||
#ifdef PLR_DPS_STATS
|
||||
while(global.frames > plr->dmglogframe) {
|
||||
memmove(plr->dmglog + 1, plr->dmglog, sizeof(plr->dmglog) - sizeof(*plr->dmglog));
|
||||
plr->dmglog[0] = 0;
|
||||
plr->dmglogframe++;
|
||||
}
|
||||
|
||||
plr->dmglog[0] += damage;
|
||||
#endif
|
||||
}
|
||||
|
||||
void player_preload(void) {
|
||||
const int flags = RESF_DEFAULT;
|
||||
|
||||
|
|
|
@ -99,7 +99,8 @@ struct Player {
|
|||
bool iddqd;
|
||||
|
||||
#ifdef PLR_DPS_STATS
|
||||
int total_dmg;
|
||||
int dmglogframe;
|
||||
int dmglog[240];
|
||||
#endif
|
||||
};
|
||||
|
||||
|
@ -154,6 +155,8 @@ void player_add_lives(Player *plr, int lives);
|
|||
void player_add_bombs(Player *plr, int bombs);
|
||||
void player_add_points(Player *plr, uint points);
|
||||
|
||||
void player_register_damage(Player *plr, int dmg);
|
||||
|
||||
void player_cancel_bomb(Player *plr, int delay);
|
||||
|
||||
// Progress is normalized from 0: bomb start to 1: bomb end
|
||||
|
|
|
@ -415,11 +415,7 @@ void apply_projectile_collision(Projectile **projlist, Projectile *p, ProjCollis
|
|||
case PCOL_ENEMY: {
|
||||
Enemy *e = col->entity;
|
||||
player_add_points(&global.plr, col->damage * 0.5);
|
||||
|
||||
#ifdef PLR_DPS_STATS
|
||||
global.plr.total_dmg += min(e->hp, col->damage);
|
||||
#endif
|
||||
|
||||
player_register_damage(&global.plr, col->damage);
|
||||
e->hp -= col->damage;
|
||||
break;
|
||||
}
|
||||
|
@ -427,10 +423,7 @@ void apply_projectile_collision(Projectile **projlist, Projectile *p, ProjCollis
|
|||
case PCOL_BOSS: {
|
||||
if(boss_damage(col->entity, col->damage)) {
|
||||
player_add_points(&global.plr, col->damage * 0.2);
|
||||
|
||||
#ifdef PLR_DPS_STATS
|
||||
global.plr.total_dmg += col->damage;
|
||||
#endif
|
||||
player_register_damage(&global.plr, col->damage);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -572,6 +572,14 @@ struct labels_s {
|
|||
} y;
|
||||
};
|
||||
|
||||
static void draw_graph(float x, float y, float w, float h) {
|
||||
r_mat_push();
|
||||
r_mat_translate(x + w/2, y + h/2, 0);
|
||||
r_mat_scale(w, h, 1);
|
||||
r_draw_quad();
|
||||
r_mat_pop();
|
||||
}
|
||||
|
||||
void stage_draw_hud_text(struct labels_s* labels) {
|
||||
char buf[64];
|
||||
|
||||
|
@ -659,23 +667,54 @@ void stage_draw_hud_text(struct labels_s* labels) {
|
|||
}
|
||||
#ifdef PLR_DPS_STATS
|
||||
else if(global.frames) {
|
||||
snprintf(buf, sizeof(buf), "Avg DPS: %.02f", global.plr.total_dmg / (global.frames / (double)FPS));
|
||||
int totaldmg = 0;
|
||||
int framespan = sizeof(global.plr.dmglog)/sizeof(*global.plr.dmglog);
|
||||
int graphspan = framespan;
|
||||
static int max = 0;
|
||||
float graph[framespan];
|
||||
|
||||
if(graphspan > 120) {
|
||||
// shader limitation
|
||||
graphspan = 120;
|
||||
}
|
||||
|
||||
// hack to update the graph every frame
|
||||
player_register_damage(&global.plr, 0);
|
||||
|
||||
for(int i = 0; i < framespan; ++i) {
|
||||
totaldmg += global.plr.dmglog[i];
|
||||
|
||||
if(global.plr.dmglog[i] > max) {
|
||||
max = global.plr.dmglog[i];
|
||||
}
|
||||
}
|
||||
|
||||
for(int i = 0; i < graphspan; ++i) {
|
||||
if(max > 0) {
|
||||
graph[i] = (float)global.plr.dmglog[i] / max;
|
||||
} else {
|
||||
graph[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
snprintf(buf, sizeof(buf), "Avg DPS: %.02f", totaldmg / (framespan / (double)FPS));
|
||||
r_uniform_ptr(stagedraw.hud_text.u_split, 1, (float[]) { 8.0 / strlen(buf) });
|
||||
draw_text(AL_Left, 0, rint(SCREEN_H - 0.5 * stringheight(buf, _fonts.monosmall)), buf, _fonts.monosmall);
|
||||
float text_h = stringheight(buf, _fonts.monosmall);
|
||||
float text_y = rint(SCREEN_H - 0.5 * text_h);
|
||||
draw_text(AL_Left, 0, text_y, buf, _fonts.monosmall);
|
||||
|
||||
r_shader("graph");
|
||||
r_uniform_vec3("color_low", 1.0, 0.0, 0.0);
|
||||
r_uniform_vec3("color_mid", 1.0, 1.0, 0.0);
|
||||
r_uniform_vec3("color_high", 0.0, 1.0, 0.0);
|
||||
r_uniform("points[0]", graphspan, graph);
|
||||
draw_graph(142, SCREEN_H - text_h, graphspan, text_h);
|
||||
}
|
||||
#endif
|
||||
|
||||
r_shader_standard();
|
||||
}
|
||||
|
||||
static void draw_graph(float x, float y, float w, float h) {
|
||||
r_mat_push();
|
||||
r_mat_translate(x + w/2, y + h/2, 0);
|
||||
r_mat_scale(w, h, 1);
|
||||
r_draw_quad();
|
||||
r_mat_pop();
|
||||
}
|
||||
|
||||
static void fill_graph(int num_samples, float *samples, FPSCounter *fps) {
|
||||
for(int i = 0; i < num_samples; ++i) {
|
||||
samples[i] = fps->frametimes[i] / (((hrtime_t)2.0)/FPS);
|
||||
|
|
|
@ -1148,6 +1148,9 @@ int stage1_tritoss(Enemy *e, int t) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
// #define DPSTEST
|
||||
// #define BULLET_TEST
|
||||
|
||||
#ifdef BULLET_TEST
|
||||
static int proj_rotate(Projectile *p, int t) {
|
||||
if(t < 0) {
|
||||
|
@ -1160,6 +1163,18 @@ static int proj_rotate(Projectile *p, int t) {
|
|||
}
|
||||
#endif
|
||||
|
||||
#ifdef DPSTEST
|
||||
static int dpsdummy(Enemy *e, int t) {
|
||||
e->hp = 9000;
|
||||
|
||||
if(t > 0) {
|
||||
e->pos += e->args[0];
|
||||
}
|
||||
|
||||
return ACTION_NONE;
|
||||
}
|
||||
#endif
|
||||
|
||||
void stage1_events(void) {
|
||||
TIMER(&global.timer);
|
||||
|
||||
|
@ -1167,21 +1182,15 @@ void stage1_events(void) {
|
|||
stage_start_bgm("stage1");
|
||||
}
|
||||
|
||||
#ifdef TASTE_THE_RAINBOW
|
||||
FROM_TO(60, 1000000000, 30) {
|
||||
int cnt = 16;
|
||||
#ifdef DPSTEST
|
||||
AT(0) {
|
||||
create_enemy1c(VIEWPORT_W/2 + VIEWPORT_H/3*I, 9000, BigFairy, dpsdummy, 0);
|
||||
create_enemy1c(-64 + VIEWPORT_W/2 + VIEWPORT_H/3*I, 9000, BigFairy, dpsdummy, 0);
|
||||
create_enemy1c(+64 + VIEWPORT_W/2 + VIEWPORT_H/3*I, 9000, BigFairy, dpsdummy, 0);
|
||||
}
|
||||
|
||||
for(int i = 0; i < cnt; ++i) {
|
||||
PROJECTILE(
|
||||
.sprite = "bigball",
|
||||
.pos = VIEWPORT_W * (i+0.5) / cnt,
|
||||
.rule = timeout_linear,
|
||||
.args = { 500, I },
|
||||
.color = hsl(i/(cnt+1.0), 1.0, 0.5),
|
||||
// .draw_rule = Fade,
|
||||
// .flags = PFLAG_DRAWADD,
|
||||
);
|
||||
}
|
||||
if(!(global.timer % 16)) {
|
||||
create_enemy1c(-16 + VIEWPORT_H/5*I, 9000, Swirl, dpsdummy, 2);
|
||||
}
|
||||
|
||||
return;
|
||||
|
|
Loading…
Reference in a new issue