diff --git a/cs-code/Makefile.am b/cs-code/Makefile.am index 3c14f2a75..d7e8475c1 100644 --- a/cs-code/Makefile.am +++ b/cs-code/Makefile.am @@ -11,7 +11,7 @@ QCPPFLAGS=-I. -I$(srcdir) -I$(top_builddir)/include -I$(top_srcdir)/include pkgdata_DATA= menu.dat -menu_src= menu.qc menu_pics.qc servlist.qc options.qc cbuf_def.qc cvar_def.qc draw_def.qc file_def.qc game_def.qc inputline_def.qc inputline_util.qc key_defs.qc menu_def.qc options_util.qc string_def.qc controls_o.qc stringh_def.qc +menu_src= menu.qc menu_pics.qc menu_util.qc servlist.qc options.qc cbuf_def.qc cvar_def.qc draw_def.qc file_def.qc game_def.qc inputline_def.qc inputline_util.qc key_defs.qc menu_def.qc options_util.qc string_def.qc controls_o.qc stringh_def.qc menu.dat: menu.src $(menu_src) $(QFCC) $(QCFLAGS) $(QCPPFLAGS) -P $< diff --git a/cs-code/menu.qc b/cs-code/menu.qc index ccfa4ef70..601760ca7 100644 --- a/cs-code/menu.qc +++ b/cs-code/menu.qc @@ -92,7 +92,7 @@ integer () load_draw = { local integer i; - Draw_CenterPic (160, 4, p_load_pic); + Draw_CenterPic (160, 4, Draw_CachePic ("gfx/p_load.lmp", 1)); for (i=0 ; i< MAX_SAVEGAMES; i++) Draw_String (16, 32 + 8 * i, filenames[i]); Draw_Character (8, 32 + load_cursor * 8, 12 + (integer (time * 4) & 1)); @@ -103,7 +103,7 @@ integer () save_draw = { local integer i; - Draw_CenterPic (160, 4, p_save_pic); + Draw_CenterPic (160, 4, Draw_CachePic ("p_save.lmp", 1)); for (i=0 ; i< MAX_SAVEGAMES; i++) Draw_String (16, 32 + 8 * i, filenames[i]); Draw_Character (8, 32 + save_cursor * 8, 12 + (integer (time * 4) & 1)); diff --git a/cs-code/menu_pics.qc b/cs-code/menu_pics.qc index b16955ae6..dede595ec 100644 --- a/cs-code/menu_pics.qc +++ b/cs-code/menu_pics.qc @@ -1,20 +1,3 @@ -qpic_t p_load_pic; -qpic_t p_save_pic; -qpic_t [6] dot; -qpic_t box_tl_pic; -qpic_t box_ml_pic; -qpic_t box_bl_pic; -qpic_t box_tm_pic; -qpic_t box_mm_pic; -qpic_t box_mm2_pic; -qpic_t box_bm_pic; -qpic_t box_tr_pic; -qpic_t box_mr_pic; -qpic_t box_br_pic; -qpic_t qplaque_pic; -qpic_t p_option_pic; -qpic_t p_multi_pic; - string [6] dot_name = { "gfx/menudot1.lmp", "gfx/menudot2.lmp", @@ -27,23 +10,4 @@ string [6] dot_name = { void () load_menu_pics = { - local integer i; - - for (i = 0; i < 6; i++) - dot[i] = Draw_CachePic (dot_name[i], 1); - - box_tl_pic = Draw_CachePic ("gfx/box_tl.lmp", 1); - box_ml_pic = Draw_CachePic ("gfx/box_ml.lmp", 1); - box_bl_pic = Draw_CachePic ("gfx/box_bl.lmp", 1); - box_tm_pic = Draw_CachePic ("gfx/box_tm.lmp", 1); - box_mm_pic = Draw_CachePic ("gfx/box_mm.lmp", 1); - box_mm2_pic = Draw_CachePic ("gfx/box_mm2.lmp", 1); - box_bm_pic = Draw_CachePic ("gfx/box_bm.lmp", 1); - box_tr_pic = Draw_CachePic ("gfx/box_tr.lmp", 1); - box_mr_pic = Draw_CachePic ("gfx/box_mr.lmp", 1); - box_br_pic = Draw_CachePic ("gfx/box_br.lmp", 1); - - qplaque_pic = Draw_CachePic ("gfx/qplaque.lmp", 1); - p_option_pic = Draw_CachePic ("gfx/p_option.lmp", 1); - p_option_pic = Draw_CachePic ("gfx/p_multi.lmp", 1); }; diff --git a/cs-code/menu_util.qc b/cs-code/menu_util.qc index 57b555418..6557e3566 100644 --- a/cs-code/menu_util.qc +++ b/cs-code/menu_util.qc @@ -2,7 +2,10 @@ float time; void (integer x, integer y) spinner = { - Draw_Pic (x, y, dot[integer(time * 10) % 6]); + local integer i = integer(time * 10) % 6; + local qpic_t p = Draw_CachePic (dot_name[i], 1); + + Draw_Pic (x, y, p); }; void (integer x, integer y, integer width, integer lines) text_box = @@ -12,34 +15,42 @@ void (integer x, integer y, integer width, integer lines) text_box = cx = x; cy = y; - Draw_Pic (cx, cy, box_tl_pic); + p = Draw_CachePic ("gfx/box_tl.lmp", 1); + Draw_Pic (cx, cy, p); + p = Draw_CachePic ("gfx/box_ml.lmp", 1); for (n = 0; n < lines; n++) { cy += 8; - Draw_Pic (cx, cy, box_ml_pic); + Draw_Pic (cx, cy, p); } - Draw_Pic (cx, cy + 8, box_bl_pic); + p = Draw_CachePic ("gfx/box_bl.lmp", 1); + Draw_Pic (cx, cy + 8, p); cx += 8; while (width > 0) { cy = y; - Draw_Pic (cx, cy, box_tm_pic); - p = box_mm_pic; + p = Draw_CachePic ("gfx/box_tm.lmp", 1); + Draw_Pic (cx, cy, p); + p = Draw_CachePic ("gfx/box_mm.lmp", 1); for (n = 0; n < lines; n++) { cy += 8; if (n == 1) - p = box_mm2_pic; + p = Draw_CachePic ("gfx/box_mm2.lmp", 1); Draw_Pic (cx, cy, p); } - Draw_Pic (cx, cy + 8, box_bm_pic); + p = Draw_CachePic ("gfx/box_bm.lmp", 1); + Draw_Pic (cx, cy + 8, p); width -= 2; cx += 16; } cy = y; - Draw_Pic (cx, cy, box_tr_pic); + p = Draw_CachePic ("gfx/box_tr.lmp", 1); + Draw_Pic (cx, cy, p); + p = Draw_CachePic ("gfx/box_mr.lmp", 1); for (n = 0; n < lines; n++) { cy += 8; - Draw_Pic (cx, cy, box_mr_pic); + Draw_Pic (cx, cy, p); } - Draw_Pic (cx, cy + 8, box_br_pic); + p = Draw_CachePic ("gfx/box_br.lmp", 1); + Draw_Pic (cx, cy + 8, p); }; diff --git a/cs-code/options.qc b/cs-code/options.qc index 8bd3b16bb..ff5590b4c 100644 --- a/cs-code/options.qc +++ b/cs-code/options.qc @@ -116,8 +116,8 @@ DRAW_video_options = local integer spacing = 120; local integer bar_pad; - Draw_Pic (16, 4, qplaque_pic); - Draw_CenterPic (160, 4, p_option_pic); + Draw_Pic (16, 4, Draw_CachePic ("gfx/qplaque.lmp", 1)); + Draw_CenterPic (160, 4, Draw_CachePic ("gfx/p_option.lmp", 1)); Draw_String (54, 40, "Video"); Draw_String (54, 50, "-----"); draw_val_item (70, 60, spacing, "Fullscreen", @@ -206,8 +206,8 @@ DRAW_audio_options = local integer spacing = 120; local integer bar_pad; - Draw_Pic (16, 4, qplaque_pic); - Draw_CenterPic (160, 4, p_option_pic); + Draw_Pic (16, 4, Draw_CachePic ("gfx/qplaque.lmp", 1)); + Draw_CenterPic (160, 4, Draw_CachePic ("gfx/p_option.lmp", 1)); Draw_String (54, 40, "Audio"); Draw_String (54, 50, "-----"); bar_pad = 50; @@ -315,8 +315,8 @@ DRAW_control_options = { local integer cursor_pad = 0, spacing = 120, bar_pad; - Draw_Pic (16, 4, qplaque_pic); - Draw_CenterPic (160, 4, p_option_pic); + Draw_Pic (16, 4, Draw_CachePic ("gfx/qplaque.lmp", 1)); + Draw_CenterPic (160, 4, Draw_CachePic ("gfx/p_option.lmp", 1)); Draw_String (54, 40, "Controls"); Draw_String (54, 50, "--------"); Draw_String (70, 60, "Bindings"); @@ -400,8 +400,8 @@ DRAW_feature_options = { local integer cursor_pad = 0, spacing = 120; - Draw_Pic (16, 4, qplaque_pic); - Draw_CenterPic (160,4, p_option_pic); + Draw_Pic (16, 4, Draw_CachePic ("gfx/qplaque.lmp", 1)); + Draw_CenterPic (160,4, Draw_CachePic ("gfx/p_option.lmp", 1)); Draw_String (54, 40, "Features"); Draw_String (54, 50, "--------"); @@ -545,8 +545,8 @@ DRAW_player_options = { local integer cursor_pad = 0, spacing = 120; - Draw_Pic (16, 4, qplaque_pic); - Draw_CenterPic (160,4, p_option_pic); + Draw_Pic (16, 4, Draw_CachePic ("gfx/qplaque.lmp", 1)); + Draw_CenterPic (160,4, Draw_CachePic ("gfx/p_option.lmp", 1)); Draw_String (54, 40, "Player"); Draw_String (54, 50, "--------"); @@ -710,8 +710,8 @@ DRAW_network_options = { local integer cursor_pad = 0, spacing = 120; - Draw_Pic (16, 4, qplaque_pic); - Draw_CenterPic (160,4, p_option_pic); + Draw_Pic (16, 4, Draw_CachePic ("gfx/qplaque.lmp", 1)); + Draw_CenterPic (160,4, Draw_CachePic ("gfx/p_option.lmp", 1)); Draw_String (54, 40, "Network"); Draw_String (54, 50, "--------"); diff --git a/cs-code/servlist.qc b/cs-code/servlist.qc index 3089c9473..9e5e5836a 100644 --- a/cs-code/servlist.qc +++ b/cs-code/servlist.qc @@ -2,16 +2,16 @@ void (integer x, integer y, integer width, integer lines) text_box; integer () servlist_favorates_draw = { - Draw_Pic (16, 4, qplaque_pic); - Draw_CenterPic (160, 4, p_multi_pic); + Draw_Pic (16, 4, Draw_CachePic ("gfx/qplaque.lmp", 1)); + Draw_CenterPic (160, 4, Draw_CachePic ("gfx/p_multi.lmp", 1)); Draw_String (54, 40, "Under Construction"); return 1; }; integer () servlist_all_draw = { - Draw_Pic (16, 4, qplaque_pic); - Draw_CenterPic (160, 4, p_multi_pic); + Draw_Pic (16, 4, Draw_CachePic ("gfx/qplaque.lmp", 1)); + Draw_CenterPic (160, 4, Draw_CachePic ("gfx/p_multi.lmp", 1)); Draw_String (54, 40, "Under Construction"); return 1; }; @@ -24,8 +24,8 @@ inputline_t input_active; integer () servlist_filter_draw = { - Draw_Pic (16, 4, qplaque_pic); - Draw_CenterPic (160, 4, p_multi_pic); + Draw_Pic (16, 4, Draw_CachePic ("gfx/qplaque.lmp", 1)); + Draw_CenterPic (160, 4, Draw_CachePic ("gfx/p_multi.lmp", 1)); Draw_String (62, 40, "Max Ping........:"); text_box (206, 32, 4, 1); InputLine_Draw (serv_maxping, 206, 40, 1); diff --git a/libs/video/renderer/r_progs.c b/libs/video/renderer/r_progs.c index 7d72e3a0f..707f5dfd0 100644 --- a/libs/video/renderer/r_progs.c +++ b/libs/video/renderer/r_progs.c @@ -36,43 +36,72 @@ static const char rcsid[] = #ifdef HAVE_STRINGS_H # include #endif +#include #include "QF/console.h" #include "QF/draw.h" +#include "QF/hash.h" #include "QF/progs.h" #include "QF/render.h" +typedef struct { + int width; + int height; + qpic_t *pic; +} bi_qpic_t; + +typedef struct qpic_res_s { + char *name; + bi_qpic_t *pic; +} qpic_res_t; + +typedef struct { + hashtab_t *pic_hash; +} draw_resources_t; + static qpic_t * get_qpic (progs_t *pr, int arg, const char *func) { - qpic_t *pic; + bi_qpic_t *pic; if (arg <= ((pr_type_t *) pr->zone - pr->pr_globals) - || arg >= (pr->zone_size / sizeof (pr_type_t))) - PR_RunError (pr, "%s: Invalid qpic_t", func); + || arg >= pr->globals_size) + PR_RunError (pr, "%s: Invalid qpic_t: %d %d", func, arg, pr->globals_size); - memcpy (&pic, ((qpic_t *)(pr->pr_globals + arg))->data, sizeof (qpic_t *)); - return pic; + pic = (bi_qpic_t *)(pr->pr_globals + arg); + return pic->pic; } static void bi_Draw_CachePic (progs_t *pr) { + draw_resources_t *res = PR_Resources_Find (pr, "Draw"); const char *path = G_STRING (pr, OFS_PARM0); int alpha = G_INT (pr, OFS_PARM1); qpic_t *pic = Draw_CachePic (path, alpha); - qpic_t *qpic; + bi_qpic_t *qpic; + qpic_res_t *rpic = Hash_Find (res->pic_hash, path); if (!pic) { Con_DPrintf ("can't load %s\n", path); G_INT (pr, OFS_RETURN) = 0; return; } - qpic = PR_Zone_Malloc (pr, sizeof (qpic_t) - 4 + sizeof (qpic_t *)); + if (rpic) { + qpic = rpic->pic; + qpic->pic = pic; + G_INT (pr, OFS_RETURN) = (pr_type_t *)qpic - pr->pr_globals; + return; + } + qpic = PR_Zone_Malloc (pr, sizeof (bi_qpic_t)); qpic->width = pic->width; qpic->height = pic->height; - memcpy (qpic->data, &pic, sizeof (qpic_t *)); + qpic->pic = pic; G_INT (pr, OFS_RETURN) = (pr_type_t *)qpic - pr->pr_globals; + rpic = malloc (sizeof (qpic_res_t)); + rpic->name = strdup (path); + rpic->pic = qpic; + Hash_Add (res->pic_hash, rpic); } static void @@ -154,9 +183,36 @@ bi_Draw_Fill (progs_t *pr) Draw_Fill (x, y, w, h, color); } +static const char * +bi_draw_get_key (void *p, void *unused) +{ + return ((qpic_res_t *) p)->name; +} + +static void +bi_draw_free (void *_p, void *unused) +{ + qpic_res_t *p = (qpic_res_t *) _p; + + free (p->name); + free (p); +} + +static void +bi_draw_clear (progs_t *pr, void *data) +{ + draw_resources_t *res = (draw_resources_t *) data; + + Hash_FlushTable (res->pic_hash); +} + void R_Progs_Init (progs_t *pr) { + draw_resources_t *res = malloc (sizeof (draw_resources_t)); + res->pic_hash = Hash_NewTable (61, bi_draw_get_key, bi_draw_free, 0); + + PR_Resources_Register (pr, "Draw", res, bi_draw_clear); PR_AddBuiltin (pr, "Draw_CachePic", bi_Draw_CachePic, -1); PR_AddBuiltin (pr, "Draw_Pic", bi_Draw_Pic, -1); PR_AddBuiltin (pr, "Draw_CenterPic", bi_Draw_CenterPic, -1);