mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-04-04 00:10:52 +00:00
[ui] Pass a data pointer to update functions
This commit is contained in:
parent
32c65294ba
commit
2e00fd1165
8 changed files with 94 additions and 61 deletions
|
@ -81,8 +81,19 @@ typedef struct canvas_system_s {
|
|||
struct view_s;
|
||||
struct view_pos_s;
|
||||
|
||||
typedef void (*canvas_update_f) (struct view_s);
|
||||
typedef void (*canvas_func_f) (struct view_pos_s, struct view_pos_s);
|
||||
typedef void (*canvas_update_f) (struct view_s, void *data);
|
||||
typedef void (*canvas_func_f) (struct view_pos_s, struct view_pos_s,
|
||||
void *data);
|
||||
|
||||
typedef struct canvas_update_s {
|
||||
canvas_update_f update;
|
||||
void *data;
|
||||
} canvas_update_t;
|
||||
|
||||
typedef struct canvas_func_s {
|
||||
canvas_func_f func;
|
||||
void *data;
|
||||
} canvas_func_t;
|
||||
|
||||
typedef struct canvas_subpic_s {
|
||||
struct qpic_s *pic;
|
||||
|
|
|
@ -134,23 +134,24 @@ clscr_set_cachepic (view_t view, const char *name)
|
|||
static void
|
||||
clscr_set_canvas_func (view_t view, canvas_func_f func)
|
||||
{
|
||||
Ent_SetComponent (view.id, cl_canvas_sys.base + canvas_func, view.reg, &func);
|
||||
Ent_SetComponent (view.id, cl_canvas_sys.base + canvas_func, view.reg,
|
||||
&(canvas_func_t) { .func = func });
|
||||
}
|
||||
|
||||
static void
|
||||
cl_draw_crosshair (view_pos_t abs, view_pos_t len)
|
||||
cl_draw_crosshair (view_pos_t abs, view_pos_t len, void *data)
|
||||
{
|
||||
r_funcs->Draw_Crosshair ();
|
||||
}
|
||||
|
||||
static void
|
||||
cl_draw_centerprint (view_pos_t abs, view_pos_t len)
|
||||
cl_draw_centerprint (view_pos_t abs, view_pos_t len, void *data)
|
||||
{
|
||||
Sbar_DrawCenterPrint ();
|
||||
}
|
||||
|
||||
static void
|
||||
SCR_CShift (view_pos_t abs, view_pos_t len)
|
||||
SCR_CShift (view_pos_t abs, view_pos_t len, void *data)
|
||||
{
|
||||
mleaf_t *leaf;
|
||||
int contents = CONTENTS_EMPTY;
|
||||
|
@ -229,6 +230,18 @@ cl_vidsize_listener (void *data, const viddef_t *vdef)
|
|||
cl_set_size ();
|
||||
}
|
||||
|
||||
static void
|
||||
cl_timegraph (view_pos_t abs, view_pos_t len, void *data)
|
||||
{
|
||||
R_TimeGraph (abs, len);
|
||||
}
|
||||
|
||||
static void
|
||||
cl_zgraph (view_pos_t abs, view_pos_t len, void *data)
|
||||
{
|
||||
R_ZGraph (abs, len);
|
||||
}
|
||||
|
||||
static void
|
||||
cl_create_views (void)
|
||||
{
|
||||
|
@ -249,11 +262,11 @@ cl_create_views (void)
|
|||
clscr_set_pic (net_view, pic);
|
||||
|
||||
timegraph_view = clscr_view (0, 0, vid->width, 100, grav_southwest);
|
||||
clscr_set_canvas_func (timegraph_view, R_TimeGraph);
|
||||
clscr_set_canvas_func (timegraph_view, cl_timegraph);
|
||||
View_SetVisible (timegraph_view, r_timegraph);
|
||||
|
||||
zgraph_view = clscr_view (0, 0, vid->width, 100, grav_southwest);
|
||||
clscr_set_canvas_func (zgraph_view, R_ZGraph);
|
||||
clscr_set_canvas_func (zgraph_view, cl_zgraph);
|
||||
View_SetVisible (zgraph_view, r_zgraph);
|
||||
|
||||
name = "gfx/loading.lmp";
|
||||
|
|
|
@ -309,7 +309,8 @@ sbar_remcomponent (view_t view, uint32_t comp)
|
|||
static inline void
|
||||
set_update (view_t view, canvas_update_f func)
|
||||
{
|
||||
sbar_setcomponent (view, canvas_updateonce, &func);
|
||||
sbar_setcomponent (view, canvas_updateonce,
|
||||
&(canvas_update_t) { .update = func });
|
||||
}
|
||||
|
||||
#define STAT_MINUS 10 // num frame for '-' stats digit
|
||||
|
@ -585,7 +586,7 @@ draw_smallnum (view_t view, int n, int packed, int colored)
|
|||
}
|
||||
|
||||
static void
|
||||
draw_miniammo (view_t view)
|
||||
draw_miniammo (view_t view, void *data)
|
||||
{
|
||||
int i, count;
|
||||
|
||||
|
@ -598,7 +599,7 @@ draw_miniammo (view_t view)
|
|||
}
|
||||
|
||||
static void
|
||||
draw_ammo (view_t view)
|
||||
draw_ammo (view_t view, void *data)
|
||||
{
|
||||
qpic_t *pic = 0;
|
||||
if (sb_game) {
|
||||
|
@ -662,7 +663,7 @@ calc_flashon (float time, int mask, int base)
|
|||
}
|
||||
|
||||
static void
|
||||
draw_weapons (view_t view)
|
||||
draw_weapons (view_t view, void *data)
|
||||
{
|
||||
int flashon, i;
|
||||
static byte view_map[2][12] = {
|
||||
|
@ -705,7 +706,7 @@ draw_weapons (view_t view)
|
|||
}
|
||||
|
||||
static void
|
||||
draw_items (view_t view)
|
||||
draw_items (view_t view, void *data)
|
||||
{
|
||||
static byte ind_map[2][8] = {
|
||||
{ 17, 18, 19, 20, 21, 22, 25, 26 }, // id/hipnotic
|
||||
|
@ -727,7 +728,7 @@ draw_items (view_t view)
|
|||
}
|
||||
|
||||
static void
|
||||
draw_sigils (view_t view)
|
||||
draw_sigils (view_t view, void *data)
|
||||
{
|
||||
for (int i = 0; i < 4; i++) {
|
||||
view_t sigil = View_GetChild (view, i);
|
||||
|
@ -934,7 +935,8 @@ set_frags_bar (view_t view, byte top, byte bottom, draw_charbuffer_t *buff,
|
|||
sbar_setcomponent (View_GetChild (view, 1), canvas_fill, &bottom);
|
||||
sbar_setcomponent (View_GetChild (view, 2), canvas_charbuff, &buff);
|
||||
if (func) {
|
||||
sbar_setcomponent (View_GetChild (view, 3), canvas_func, &func);
|
||||
sbar_setcomponent (View_GetChild (view, 3), canvas_func,
|
||||
&(canvas_func_t) { .func = func });
|
||||
} else {
|
||||
sbar_remcomponent (View_GetChild (view, 3), canvas_func);
|
||||
}
|
||||
|
@ -958,14 +960,14 @@ set_minifrags_bar (view_t view, byte top, byte bottom, draw_charbuffer_t *buff,
|
|||
}
|
||||
|
||||
static void
|
||||
frags_marker (view_pos_t pos, view_pos_t len)
|
||||
frags_marker (view_pos_t pos, view_pos_t len, void *data)
|
||||
{
|
||||
r_funcs->Draw_Character (pos.x, pos.y, 16);
|
||||
r_funcs->Draw_Character (pos.x + len.x - 8, pos.y, 17);
|
||||
}
|
||||
|
||||
static void
|
||||
draw_frags (view_t view)
|
||||
draw_frags (view_t view, void *data)
|
||||
{
|
||||
if (sbar_maxplayers == 1) {
|
||||
return;
|
||||
|
@ -993,7 +995,7 @@ draw_frags (view_t view)
|
|||
}
|
||||
|
||||
static void
|
||||
draw_minifrags (view_t view)
|
||||
draw_minifrags (view_t view, void *data)
|
||||
{
|
||||
if (sbar_maxplayers == 1) {
|
||||
return;
|
||||
|
@ -1052,14 +1054,15 @@ set_miniteam_bar (view_t view, draw_charbuffer_t *team,
|
|||
sbar_setcomponent (View_GetChild (view, 0), canvas_charbuff, &team);
|
||||
sbar_setcomponent (View_GetChild (view, 1), canvas_charbuff, &frags);
|
||||
if (func) {
|
||||
sbar_setcomponent (View_GetChild (view, 2), canvas_func, &func);
|
||||
sbar_setcomponent (View_GetChild (view, 2), canvas_func,
|
||||
&(canvas_func_t) { .func = func });
|
||||
} else {
|
||||
sbar_remcomponent (View_GetChild (view, 2), canvas_func);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
draw_miniteam (view_t view)
|
||||
draw_miniteam (view_t view, void *data)
|
||||
{
|
||||
if (!sbar_teamplay) {
|
||||
return;
|
||||
|
@ -1091,7 +1094,7 @@ draw_miniteam (view_t view)
|
|||
}
|
||||
|
||||
static void
|
||||
draw_face (view_t view)
|
||||
draw_face (view_t view, void *data)
|
||||
{
|
||||
qpic_t *face;
|
||||
|
||||
|
@ -1132,7 +1135,7 @@ draw_face (view_t view)
|
|||
}
|
||||
|
||||
static void
|
||||
draw_spectator (view_t view)
|
||||
draw_spectator (view_t view, void *data)
|
||||
{
|
||||
view_t tracking = View_GetChild (view, 0);
|
||||
view_t back = View_GetChild (view, 1);
|
||||
|
@ -1162,7 +1165,7 @@ draw_spectator (view_t view)
|
|||
}
|
||||
|
||||
static void
|
||||
hide_spectator (view_t view)
|
||||
hide_spectator (view_t view, void *data)
|
||||
{
|
||||
for (int i = 0; i < 4; i++) {
|
||||
sbar_remcomponent (View_GetChild (view, i), canvas_charbuff);
|
||||
|
@ -1171,7 +1174,7 @@ hide_spectator (view_t view)
|
|||
}
|
||||
|
||||
static void
|
||||
draw_armor (view_t view)
|
||||
draw_armor (view_t view, void *data)
|
||||
{
|
||||
view_t armor = View_GetChild (view, 0);
|
||||
view_t num[3] = {
|
||||
|
@ -1195,7 +1198,7 @@ draw_armor (view_t view)
|
|||
}
|
||||
|
||||
static void
|
||||
draw_health (view_t view)
|
||||
draw_health (view_t view, void *data)
|
||||
{
|
||||
view_t num[3] = {
|
||||
View_GetChild (view, 0),
|
||||
|
@ -1206,7 +1209,7 @@ draw_health (view_t view)
|
|||
}
|
||||
|
||||
static void
|
||||
draw_rogue_ctf_face (view_t view)
|
||||
draw_rogue_ctf_face (view_t view, void *data)
|
||||
{
|
||||
__auto_type p = &sbar_players[sbar_viewplayer];
|
||||
byte top = Sbar_ColorForMap (p->topcolor);
|
||||
|
@ -1457,7 +1460,7 @@ dmo_line_type (void)
|
|||
}
|
||||
|
||||
static void
|
||||
draw_deathmatch (view_t view)
|
||||
draw_deathmatch (view_t view, void *data)
|
||||
{
|
||||
Sbar_SortFrags (0);
|
||||
Sbar_SortTeams ();
|
||||
|
@ -1507,7 +1510,7 @@ draw_status (void )
|
|||
|
||||
|
||||
if (sbar_gametype) {
|
||||
draw_deathmatch (deathmatch_view);
|
||||
draw_deathmatch (deathmatch_view, nullptr);
|
||||
} else {
|
||||
if (sbar_spectator) {
|
||||
if (sbar_autotrack < 0) {
|
||||
|
@ -1624,7 +1627,7 @@ Sbar_LogFrags (double completed_time)
|
|||
}
|
||||
|
||||
static void
|
||||
draw_time (view_t *view)
|
||||
draw_time (view_t view, void *data)
|
||||
{
|
||||
struct tm *local = 0;
|
||||
time_t utc = 0;
|
||||
|
@ -1652,7 +1655,7 @@ draw_time (view_t *view)
|
|||
}
|
||||
|
||||
static void
|
||||
draw_fps (view_t view)
|
||||
draw_fps (view_t view, void *data)
|
||||
{
|
||||
static char st[80];
|
||||
double t;
|
||||
|
@ -1736,20 +1739,20 @@ Sbar_DrawCenterString (view_t view, unsigned remaining)
|
|||
}
|
||||
|
||||
static void
|
||||
clear_views (view_t view)
|
||||
clear_views (view_t view, void *data)
|
||||
{
|
||||
sbar_remcomponent (view, canvas_cachepic);
|
||||
sbar_remcomponent (view, canvas_pic);
|
||||
|
||||
for (uint32_t i = 0; i < View_ChildCount (view); i++) {
|
||||
clear_views (View_GetChild (view, i));
|
||||
clear_views (View_GetChild (view, i), nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
draw_intermission (view_t view)
|
||||
draw_intermission (view_t view, void *data)
|
||||
{
|
||||
clear_views (view);
|
||||
clear_views (view, nullptr);
|
||||
const char *n;
|
||||
n = "gfx/complete.lmp";
|
||||
sbar_setcomponent (View_GetChild (view, 0), canvas_cachepic, &n);
|
||||
|
@ -1798,9 +1801,9 @@ draw_intermission (view_t view)
|
|||
}
|
||||
|
||||
static void
|
||||
draw_finale (view_t view)
|
||||
draw_finale (view_t view, void *data)
|
||||
{
|
||||
clear_views (view);
|
||||
clear_views (view, nullptr);
|
||||
|
||||
r_data->scr_copyeverything = 1;
|
||||
|
||||
|
@ -1809,9 +1812,9 @@ draw_finale (view_t view)
|
|||
}
|
||||
|
||||
static void
|
||||
draw_cutscene (view_t view)
|
||||
draw_cutscene (view_t view, void *data)
|
||||
{
|
||||
clear_views (view);
|
||||
clear_views (view, nullptr);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -1872,9 +1875,9 @@ Sbar_Update (double time)
|
|||
if (sb_updates < r_data->vid->numpages) {
|
||||
//FIXME find a better way to support animations
|
||||
sb_updates++;
|
||||
draw_weapons (sbar_weapons);
|
||||
draw_items (sbar_items);
|
||||
draw_face (sbar_face);
|
||||
draw_weapons (sbar_weapons, nullptr);
|
||||
draw_items (sbar_items, nullptr);
|
||||
draw_face (sbar_face, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2243,8 +2246,8 @@ static void
|
|||
hud_fps_f (void *data, const cvar_t *cvar)
|
||||
{
|
||||
if (hud_fps) {
|
||||
void *f = draw_fps;
|
||||
sbar_setcomponent (hud_fps_view, canvas_update, &f);
|
||||
sbar_setcomponent (hud_fps_view, canvas_update,
|
||||
&(canvas_update_t) { .update = draw_fps });
|
||||
sbar_setcomponent (hud_fps_view, canvas_charbuff, &fps_buff);
|
||||
} else {
|
||||
sbar_remcomponent (hud_fps_view, canvas_update);
|
||||
|
@ -2276,8 +2279,8 @@ static void
|
|||
hud_time_f (void *data, const cvar_t *cvar)
|
||||
{
|
||||
if (hud_time) {
|
||||
void *f = draw_time;
|
||||
sbar_setcomponent (hud_time_view, canvas_update, &f);
|
||||
sbar_setcomponent (hud_time_view, canvas_update,
|
||||
&(canvas_update_t) { .update = draw_time });
|
||||
sbar_setcomponent (hud_time_view, canvas_charbuff, &time_buff);
|
||||
} else {
|
||||
sbar_remcomponent (hud_time_view, canvas_update);
|
||||
|
|
|
@ -254,7 +254,8 @@ con_setcomponent (view_t view, uint32_t comp, void *data)
|
|||
static void
|
||||
con_setfunc (view_t view, uint32_t comp, canvas_update_f func)
|
||||
{
|
||||
con_setcomponent (view, canvas_base + comp, &func);
|
||||
con_setcomponent (view, canvas_base + comp,
|
||||
&(canvas_update_t) { .update = func });
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -712,7 +713,7 @@ draw_con_scrollback (void)
|
|||
}
|
||||
|
||||
static void
|
||||
draw_cursor (view_t view)
|
||||
draw_cursor (view_t view, void *data)
|
||||
{
|
||||
float t = *con_data.realtime * con_cursorspeed;
|
||||
int ch = 10 + ((int) (t) & 1);
|
||||
|
|
|
@ -88,12 +88,12 @@ canvas_canvas_destroy (void *_canvas, ecs_registry_t *reg)
|
|||
|
||||
const component_t canvas_components[canvas_comp_count] = {
|
||||
[canvas_update] = {
|
||||
.size = sizeof (canvas_update_f),
|
||||
.size = sizeof (canvas_update_t),
|
||||
.name = "update",
|
||||
.rangeid = canvas_update_rangeid,
|
||||
},
|
||||
[canvas_updateonce] = {
|
||||
.size = sizeof (canvas_update_f),
|
||||
.size = sizeof (canvas_update_t),
|
||||
.name = "updateonce",
|
||||
.rangeid = canvas_updateonce_rangeid,
|
||||
},
|
||||
|
@ -143,12 +143,12 @@ const component_t canvas_components[canvas_comp_count] = {
|
|||
.rangeid = canvas_glyphs_rangeid,
|
||||
},
|
||||
[canvas_func] = {
|
||||
.size = sizeof (canvas_func_f),
|
||||
.size = sizeof (canvas_func_t),
|
||||
.name = "func",
|
||||
.rangeid = canvas_func_rangeid,
|
||||
},
|
||||
[canvas_lateupdate] = {
|
||||
.size = sizeof (canvas_update_f),
|
||||
.size = sizeof (canvas_update_t),
|
||||
.name = "lateupdate",
|
||||
.rangeid = canvas_lateupdate_rangeid,
|
||||
},
|
||||
|
@ -181,9 +181,10 @@ draw_update (canvas_system_t *canvas_sys, ecs_pool_t *pool, ecs_range_t range)
|
|||
ecs_system_t viewsys = { canvas_sys->reg, canvas_sys->view_base };
|
||||
uint32_t count = range.end - range.start;
|
||||
uint32_t *ent = pool->dense + range.start;
|
||||
__auto_type func = (canvas_update_f *) pool->data + range.start;
|
||||
auto func = (canvas_update_t *) pool->data + range.start;
|
||||
while (count-- > 0) {
|
||||
(*func++) (View_FromEntity (viewsys, *ent++));
|
||||
func->update (View_FromEntity (viewsys, *ent++), func->data);
|
||||
func++;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -331,13 +332,13 @@ draw_func_views (canvas_system_t *canvas_sys, ecs_pool_t *pool,
|
|||
ecs_system_t viewsys = { canvas_sys->reg, canvas_sys->view_base };
|
||||
uint32_t count = range.end - range.start;
|
||||
uint32_t *ent = pool->dense + range.start;
|
||||
__auto_type func = (canvas_func_f *) pool->data + range.start;
|
||||
auto func = (canvas_func_t *) pool->data + range.start;
|
||||
while (count-- > 0) {
|
||||
view_t view = View_FromEntity (viewsys, *ent++);
|
||||
if (View_GetVisible (view)) {
|
||||
view_pos_t pos = View_GetAbs (view);
|
||||
view_pos_t len = View_GetLen (view);
|
||||
(*func) (pos, len);
|
||||
func->func (pos, len, func->data);
|
||||
}
|
||||
func++;
|
||||
}
|
||||
|
|
|
@ -1176,7 +1176,7 @@ IMUI_Labelf (imui_ctx_t *ctx, const char *fmt, ...)
|
|||
}
|
||||
|
||||
static void
|
||||
passage_update (view_t psgview)
|
||||
passage_update (view_t psgview, void *data)
|
||||
{
|
||||
auto reg = psgview.reg;
|
||||
auto href = View_GetRef (psgview);
|
||||
|
@ -1235,8 +1235,8 @@ IMUI_Passage (imui_ctx_t *ctx, const char *name, struct passage_s *passage)
|
|||
Ent_RemoveComponent (psg_view.id, c_updateonce, reg);
|
||||
Ent_SetComponent (psg_view.id, c_passage_glyphs, reg,
|
||||
Ent_GetComponent (psg_view.id, t_passage_glyphs, reg));
|
||||
void *update = passage_update;
|
||||
Ent_SetComponent (psg_view.id, c_updateonce, reg, &update);
|
||||
Ent_SetComponent (psg_view.id, c_updateonce, reg,
|
||||
&(canvas_update_t) { .update = passage_update });
|
||||
*View_Control (psg_view) = (viewcont_t) {
|
||||
.gravity = grav_northwest,
|
||||
.visible = 1,
|
||||
|
|
|
@ -111,7 +111,7 @@ cl_netgraph_height_f (void *data, const cvar_t *cvar)
|
|||
}
|
||||
|
||||
static void
|
||||
CL_NetGraph (view_pos_t abs, view_pos_t len)
|
||||
CL_NetGraph (view_pos_t abs, view_pos_t len, void *data)
|
||||
{
|
||||
int lost, a, l, x, y, i, o;
|
||||
int timings[NET_TIMINGS];
|
||||
|
@ -165,9 +165,9 @@ CL_NetGraph_Init (void)
|
|||
View_SetPos (cl_netgraph_view, 0, 64);
|
||||
View_SetLen (cl_netgraph_view, NET_TIMINGS + 16, cl_netgraph_height + 25);
|
||||
View_SetGravity (cl_netgraph_view, grav_southwest);
|
||||
void *f = CL_NetGraph;
|
||||
Ent_SetComponent (cl_netgraph_view.id, cl_canvas_sys.base + canvas_func,
|
||||
cl_netgraph_view.reg, &f);
|
||||
cl_netgraph_view.reg,
|
||||
&(canvas_func_t) { .func = CL_NetGraph });
|
||||
View_SetVisible (cl_netgraph_view, cl_netgraph);
|
||||
}
|
||||
|
||||
|
|
|
@ -85,6 +85,7 @@ void IMUI_EndWindow (imui_ctx_t ctx);
|
|||
int IMUI_StartScrollBox (imui_ctx_t ctx, string name);
|
||||
void IMUI_EndScrollBox (imui_ctx_t ctx);
|
||||
|
||||
void IMUI_ScrollBar (imui_ctx_t ctx, string name);
|
||||
|
||||
#define IMUI_DeferLoop(begin, end) \
|
||||
for (int _i_ = (begin); !_i_; _i_++, (end))
|
||||
|
@ -145,6 +146,9 @@ void IMUI_EndScrollBox (imui_ctx_t ctx);
|
|||
#define UI_ScrollBox(name) \
|
||||
IMUI_DeferLoop (IMUI_StartScrollBox (IMUI_context, name), \
|
||||
IMUI_EndScrollBox (IMUI_context))
|
||||
#define UI_ScrollBar(name) \
|
||||
IMUI_ScrollBar (IMUI_context, name)
|
||||
|
||||
|
||||
#define UI_Style(style) \
|
||||
IMUI_DeferLoop (IMUI_PushStyle (IMUI_context, style), \
|
||||
|
|
Loading…
Reference in a new issue