[nq] Get hud time and fps displays working

This includes moving the related cvars from botn nq and qw into the
client hud code. In addition, the hud code supports update and
update-once function components. The update component is for updates
that occur every frame, but update-once components (not used yet) are
for one-shot updates (eg, when a value updates very infrequently).
This commit is contained in:
Bill Currie 2022-11-03 14:46:44 +09:00
parent 0626ec6469
commit 82d407e3c2
7 changed files with 135 additions and 94 deletions

View file

@ -46,8 +46,6 @@ void SCR_SetBottomMargin (int lines);
void SCR_NewScene (struct scene_s *scene); void SCR_NewScene (struct scene_s *scene);
extern int hud_fps;
extern int hud_time;
extern int r_timegraph; extern int r_timegraph;
extern int r_zgraph; extern int r_zgraph;
extern int scr_copytop; extern int scr_copytop;

View file

@ -30,6 +30,8 @@
enum { enum {
hud_href, hud_href,
hud_update,
hud_updateonce,
hud_tile, hud_tile,
hud_pic, hud_pic,
hud_subpic, hud_subpic,
@ -53,6 +55,10 @@ extern int hud_sb_lines;
extern int hud_sbar; extern int hud_sbar;
extern int hud_swap; extern int hud_swap;
extern int hud_fps;
extern int hud_pl;
extern int hud_ping;
extern int hud_time;
//extern struct view_s sbar_view; //extern struct view_s sbar_view;
//extern struct view_s sbar_inventory_view; //extern struct view_s sbar_inventory_view;
@ -65,6 +71,8 @@ extern struct view_s hud_frags_view;
extern struct view_s hud_overlay_view; extern struct view_s hud_overlay_view;
extern struct view_s hud_stuff_view; extern struct view_s hud_stuff_view;
extern struct view_s hud_time_view;
extern struct view_s hud_fps_view;
extern struct view_s hud_main_view; extern struct view_s hud_main_view;
void HUD_Init (void); void HUD_Init (void);

View file

@ -46,6 +46,14 @@ static const component_t hud_components[hud_comp_count] = {
.size = sizeof (hierref_t), .size = sizeof (hierref_t),
.name = "href", .name = "href",
}, },
[hud_update] = {
.size = sizeof (void (*)(view_t)),
.name = "update",
},
[hud_updateonce] = {
.size = sizeof (void (*)(view_t)),
.name = "updateonce",
},
[hud_tile] = { [hud_tile] = {
.size = sizeof (byte), .size = sizeof (byte),
.name = "pic", .name = "pic",
@ -107,6 +115,42 @@ static cvar_t hud_swap_cvar = {
.flags = CVAR_ARCHIVE, .flags = CVAR_ARCHIVE,
.value = { .type = &cexpr_int, .value = &hud_swap }, .value = { .type = &cexpr_int, .value = &hud_swap },
}; };
int hud_fps;
static cvar_t hud_fps_cvar = {
.name = "hud_fps",
.description =
"display realtime frames per second",
.default_value = "0",
.flags = CVAR_ARCHIVE,
.value = { .type = &cexpr_int, .value = &hud_fps },
};
int hud_ping;
static cvar_t hud_ping_cvar = {
.name = "hud_ping",
.description =
"display current ping to server",
.default_value = "0",
.flags = CVAR_ARCHIVE,
.value = { .type = &cexpr_int, .value = &hud_ping },
};
int hud_pl;
static cvar_t hud_pl_cvar = {
.name = "hud_pl",
.description =
"display current packet loss to server",
.default_value = "0",
.flags = CVAR_ARCHIVE,
.value = { .type = &cexpr_int, .value = &hud_pl },
};
int hud_time;
static cvar_t hud_time_cvar = {
.name = "hud_time",
.description =
"display the current time",
.default_value = "0",
.flags = CVAR_ARCHIVE,
.value = { .type = &cexpr_int, .value = &hud_time },
};
view_t sbar_view; view_t sbar_view;
view_t sbar_inventory_view; view_t sbar_inventory_view;
@ -119,6 +163,8 @@ view_t hud_frags_view;
view_t hud_overlay_view; view_t hud_overlay_view;
view_t hud_stuff_view; view_t hud_stuff_view;
view_t hud_time_view;
view_t hud_fps_view;
view_t hud_main_view; view_t hud_main_view;
static void static void
@ -181,6 +227,12 @@ HUD_Init (void)
void void
HUD_Init_Cvars (void) HUD_Init_Cvars (void)
{ {
Cvar_Register (&hud_fps_cvar, 0, 0);
Cvar_MakeAlias ("show_fps", &hud_fps_cvar);
Cvar_Register (&hud_ping_cvar, 0, 0);
Cvar_Register (&hud_pl_cvar, 0, 0);
Cvar_Register (&hud_time_cvar, 0, 0);
Cvar_Register (&hud_sbar_cvar, hud_sbar_f, 0); Cvar_Register (&hud_sbar_cvar, hud_sbar_f, 0);
Cvar_Register (&hud_swap_cvar, hud_swap_f, 0); Cvar_Register (&hud_swap_cvar, hud_swap_f, 0);
Cvar_Register (&hud_scoreboard_gravity_cvar, hud_scoreboard_gravity_f, 0); Cvar_Register (&hud_scoreboard_gravity_cvar, hud_scoreboard_gravity_f, 0);
@ -221,6 +273,25 @@ HUD_Calc_sb_lines (int view_size)
#endif #endif
} }
static void
draw_update (ecs_pool_t *pool)
{
uint32_t count = pool->count;
uint32_t *ent = pool->dense;
void (**func) (view_t) = pool->data;
while (count-- > 0) {
view_t view = { .id = *ent++, .reg = hud_registry };
(*func++) (view);
}
}
static void
draw_updateonce (ecs_pool_t *pool)
{
draw_update (pool);
pool->count = 0;
}
static void static void
draw_tile_views (ecs_pool_t *pool) draw_tile_views (ecs_pool_t *pool)
{ {
@ -340,6 +411,8 @@ void
HUD_Draw_Views (void) HUD_Draw_Views (void)
{ {
static void (*draw_func[hud_comp_count]) (ecs_pool_t *) = { static void (*draw_func[hud_comp_count]) (ecs_pool_t *) = {
[hud_update] = draw_update,
[hud_updateonce] = draw_updateonce,
[hud_tile] = draw_tile_views, [hud_tile] = draw_tile_views,
[hud_pic] = draw_pic_views, [hud_pic] = draw_pic_views,
[hud_subpic] = draw_subpic_views, [hud_subpic] = draw_subpic_views,

View file

@ -122,25 +122,6 @@ static cvar_t cl_nolerp_cvar = {
.value = { .type = &cexpr_int, .value = &cl_nolerp }, .value = { .type = &cexpr_int, .value = &cl_nolerp },
}; };
int hud_fps;
static cvar_t hud_fps_cvar = {
.name = "hud_fps",
.description =
"display realtime frames per second",
.default_value = "0",
.flags = CVAR_ARCHIVE,
.value = { .type = &cexpr_int, .value = &hud_fps },
};
int hud_time;
static cvar_t hud_time_cvar = {
.name = "hud_time",
.description =
"display the current time",
.default_value = "0",
.flags = CVAR_ARCHIVE,
.value = { .type = &cexpr_int, .value = &hud_time },
};
static int r_ambient; static int r_ambient;
static cvar_t r_ambient_cvar = { static cvar_t r_ambient_cvar = {
.name = "r_ambient", .name = "r_ambient",
@ -277,9 +258,6 @@ CL_InitCvars (void)
Cvar_Register (&cl_writecfg_cvar, 0, 0); Cvar_Register (&cl_writecfg_cvar, 0, 0);
Cvar_Register (&cl_shownet_cvar, 0, 0); Cvar_Register (&cl_shownet_cvar, 0, 0);
Cvar_Register (&cl_nolerp_cvar, 0, 0); Cvar_Register (&cl_nolerp_cvar, 0, 0);
Cvar_Register (&hud_fps_cvar, 0, 0);
Cvar_MakeAlias ("show_fps", &hud_fps_cvar);
Cvar_Register (&hud_time_cvar, 0, 0);
//FIXME not hooked up (don't do anything), but should not work in //FIXME not hooked up (don't do anything), but should not work in
//multi-player //multi-player

View file

@ -89,6 +89,9 @@ static view_t sbar_solo_anchor;
static view_t sbar_solo_name; static view_t sbar_solo_name;
static view_t sbar_tile[2]; static view_t sbar_tile[2];
static draw_charbuffer_t *time_buff;
static draw_charbuffer_t *fps_buff;
static draw_charbuffer_t *solo_monsters; static draw_charbuffer_t *solo_monsters;
static draw_charbuffer_t *solo_secrets; static draw_charbuffer_t *solo_secrets;
static draw_charbuffer_t *solo_time; static draw_charbuffer_t *solo_time;
@ -1078,7 +1081,6 @@ draw_overlay (view_t *view)
static void static void
draw_time (view_t *view) draw_time (view_t *view)
{ {
#if 0
struct tm *local = 0; struct tm *local = 0;
time_t utc = 0; time_t utc = 0;
char st[80]; //FIXME: overflow char st[80]; //FIXME: overflow
@ -1098,18 +1100,15 @@ draw_time (view_t *view)
#endif #endif
if (hud_time == 1) { // Use international format if (hud_time == 1) { // Use international format
strftime (st, sizeof (st), HOUR24":%M", local); strftime (st, sizeof (st), HOUR24":%M", local);
draw_string (view, 8, 0, st);
} else if (hud_time >= 2) { // US AM/PM display } else if (hud_time >= 2) { // US AM/PM display
strftime (st, sizeof (st), HOUR12":%M "PM, local); strftime (st, sizeof (st), HOUR12":%M "PM, local);
draw_string (view, 8, 0, st);
} }
#endif write_charbuff (time_buff, 0, 0, st);
} }
static void static void
draw_fps (view_t *view) draw_fps (view_t view)
{ {
#if 0
static char st[80]; static char st[80];
double t; double t;
static double lastframetime; static double lastframetime;
@ -1120,19 +1119,10 @@ draw_fps (view_t *view)
lastfps = fps_count / (t - lastframetime); lastfps = fps_count / (t - lastframetime);
fps_count = 0; fps_count = 0;
lastframetime = t; lastframetime = t;
snprintf (st, sizeof (st), "%5.1f FPS", lastfps); int prec = lastfps < 1000 ? 1 : 0;
snprintf (st, sizeof (st), "%5.*f FPS", prec, lastfps);
} }
draw_string (view, 80, 8, st); write_charbuff (fps_buff, 0, 0, st);
#endif
}
static void
draw_stuff (view_t *view)
{
if (hud_time > 0)
draw_time (view);
if (hud_fps > 0)
draw_fps (view);
} }
static void static void
@ -1414,7 +1404,6 @@ Sbar_Draw (void)
if (sb_update_flags & (1 << sbc_info)) { if (sb_update_flags & (1 << sbc_info)) {
draw_miniteam (0); draw_miniteam (0);
draw_minifrags (0); draw_minifrags (0);
draw_stuff (0);
draw_overlay (0); draw_overlay (0);
draw_intermission (0); draw_intermission (0);
Sbar_DeathmatchOverlay (0); Sbar_DeathmatchOverlay (0);
@ -1509,6 +1498,32 @@ sbar_hud_sbar_f (void *data, const cvar_t *cvar)
} }
} }
static void
sbar_hud_fps_f (void *data, const cvar_t *cvar)
{
if (hud_fps) {
void *f = draw_fps;
sbar_setcomponent (hud_fps_view, hud_update, &f);
sbar_setcomponent (hud_fps_view, hud_charbuff, &fps_buff);
} else {
sbar_remcomponent (hud_fps_view, hud_update);
sbar_remcomponent (hud_fps_view, hud_charbuff);
}
}
static void
sbar_hud_time_f (void *data, const cvar_t *cvar)
{
if (hud_time) {
void *f = draw_time;
sbar_setcomponent (hud_time_view, hud_update, &f);
sbar_setcomponent (hud_time_view, hud_charbuff, &time_buff);
} else {
sbar_remcomponent (hud_time_view, hud_update);
sbar_remcomponent (hud_time_view, hud_charbuff);
}
}
static void static void
init_sbar_views (void) init_sbar_views (void)
{ {
@ -1892,6 +1907,13 @@ init_views (void)
view_insert (hud_main_view, hud_overlay_view, 0); view_insert (hud_main_view, hud_overlay_view, 0);
view_insert (hud_main_view, hud_stuff_view, 0); view_insert (hud_main_view, hud_stuff_view, 0);
#endif #endif
hud_stuff_view = sbar_view (0, 48, 152, 16, grav_southwest, cl_screen_view);
hud_time_view = sbar_view (8, 0, 64, 8, grav_northwest, hud_stuff_view);
hud_fps_view = sbar_view (80, 0, 72, 8, grav_northwest, hud_stuff_view);
time_buff = Draw_CreateBuffer (8, 1);
fps_buff = Draw_CreateBuffer (11, 1);
if (!strcmp (qfs_gamedir->hudtype, "hipnotic")) { if (!strcmp (qfs_gamedir->hudtype, "hipnotic")) {
init_hipnotic_sbar_views (); init_hipnotic_sbar_views ();
init_hipnotic_hud_views (); init_hipnotic_hud_views ();
@ -2097,11 +2119,17 @@ Sbar_Init (void)
HUD_Init_Cvars (); HUD_Init_Cvars ();
Cvar_AddListener (Cvar_FindVar ("hud_sbar"), sbar_hud_sbar_f, 0); Cvar_AddListener (Cvar_FindVar ("hud_sbar"), sbar_hud_sbar_f, 0);
Cvar_AddListener (Cvar_FindVar ("hud_swap"), sbar_hud_swap_f, 0); Cvar_AddListener (Cvar_FindVar ("hud_swap"), sbar_hud_swap_f, 0);
Cvar_AddListener (Cvar_FindVar ("hud_fps"), sbar_hud_fps_f, 0);
Cvar_AddListener (Cvar_FindVar ("hud_time"), sbar_hud_time_f, 0);
load_pics (); load_pics ();
init_views (); init_views ();
View_UpdateHierarchy (sbar_main); View_UpdateHierarchy (sbar_main);
sbar_hud_fps_f (0, 0);
sbar_hud_time_f (0, 0);
Cmd_AddCommand ("+showscores", Sbar_ShowScores, Cmd_AddCommand ("+showscores", Sbar_ShowScores,
"Display information on everyone playing"); "Display information on everyone playing");
Cmd_AddCommand ("-showscores", Sbar_DontShowScores, Cmd_AddCommand ("-showscores", Sbar_DontShowScores,

View file

@ -267,9 +267,6 @@ extern int cl_model_crcs;
extern float rate; extern float rate;
extern int hud_ping;
extern int hud_pl;
extern char *skin; extern char *skin;
extern float cl_fb_players; extern float cl_fb_players;

View file

@ -445,42 +445,6 @@ static cvar_t host_speeds_cvar = {
.flags = CVAR_NONE, .flags = CVAR_NONE,
.value = { .type = &cexpr_int, .value = &host_speeds }, .value = { .type = &cexpr_int, .value = &host_speeds },
}; };
int hud_fps;
static cvar_t hud_fps_cvar = {
.name = "hud_fps",
.description =
"display realtime frames per second",
.default_value = "0",
.flags = CVAR_ARCHIVE,
.value = { .type = &cexpr_int, .value = &hud_fps },
};
int hud_ping;
static cvar_t hud_ping_cvar = {
.name = "hud_ping",
.description =
"display current ping to server",
.default_value = "0",
.flags = CVAR_ARCHIVE,
.value = { .type = &cexpr_int, .value = &hud_ping },
};
int hud_pl;
static cvar_t hud_pl_cvar = {
.name = "hud_pl",
.description =
"display current packet loss to server",
.default_value = "0",
.flags = CVAR_ARCHIVE,
.value = { .type = &cexpr_int, .value = &hud_pl },
};
int hud_time;
static cvar_t hud_time_cvar = {
.name = "hud_time",
.description =
"display the current time",
.default_value = "0",
.flags = CVAR_ARCHIVE,
.value = { .type = &cexpr_int, .value = &hud_time },
};
int fps_count; int fps_count;
@ -1676,11 +1640,6 @@ CL_Init_Cvars (void)
Cvar_Register (&host_speeds_cvar, 0, 0); Cvar_Register (&host_speeds_cvar, 0, 0);
Cvar_Register (&rcon_password_cvar, 0, 0); Cvar_Register (&rcon_password_cvar, 0, 0);
Cvar_Register (&rcon_address_cvar, 0, 0); Cvar_Register (&rcon_address_cvar, 0, 0);
Cvar_Register (&hud_fps_cvar, 0, 0);
Cvar_MakeAlias ("show_fps", &hud_fps_cvar);
Cvar_Register (&hud_ping_cvar, 0, 0);
Cvar_Register (&hud_pl_cvar, 0, 0);
Cvar_Register (&hud_time_cvar, 0, 0);
Cvar_Register (&cl_predict_players_cvar, 0, 0); Cvar_Register (&cl_predict_players_cvar, 0, 0);
Cvar_Register (&cl_solid_players_cvar, 0, 0); Cvar_Register (&cl_solid_players_cvar, 0, 0);
Cvar_Register (&localid_cvar, 0, 0); Cvar_Register (&localid_cvar, 0, 0);