From e5026b6eb290b2098c6ce92ae7b777fb4457227b Mon Sep 17 00:00:00 2001 From: black Date: Thu, 14 Apr 2005 20:45:08 +0000 Subject: [PATCH] -Added the parameter 'persistent'(naming?) to Draw_CachePic, which decides whether the texture is loaded in texture memory directly or only on demand. -Adapted all Draw_CachePic calls (I'll do some corrections, atm most of them pass persistent := false) git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@5180 d7cf8633-e32d-0410-b094-e92efae38249 --- cl_screen.c | 4 ++-- draw.h | 2 +- gl_backend.c | 2 +- gl_draw.c | 21 ++++++++++++++------- menu.c | 42 +++++++++++++++++++++--------------------- netconn.h | 2 +- prvm_cmds.c | 4 ++-- r_crosshairs.c | 4 ++-- r_shadow.c | 2 +- sbar.c | 6 +++--- 10 files changed, 48 insertions(+), 41 deletions(-) diff --git a/cl_screen.c b/cl_screen.c index dc0418a1..392feb94 100644 --- a/cl_screen.c +++ b/cl_screen.c @@ -215,7 +215,7 @@ void SCR_DrawPause (void) if (!cl.paused) return; - pic = Draw_CachePic ("gfx/pause.lmp"); + pic = Draw_CachePic ("gfx/pause.lmp", true); DrawQ_Pic ((vid.conwidth - pic->width)/2, (vid.conheight - pic->height)/2, "gfx/pause.lmp", 0, 0, 1, 1, 1, 1, 0); } @@ -551,7 +551,7 @@ void DrawQ_SuperPic(float x, float y, char *picname, float width, float height, memset(&mesh, 0, sizeof(mesh)); if (picname && picname[0]) { - pic = Draw_CachePic(picname); + pic = Draw_CachePic(picname, false); if (width == 0) width = pic->width; if (height == 0) diff --git a/draw.h b/draw.h index bbf5a21b..4c507883 100644 --- a/draw.h +++ b/draw.h @@ -39,7 +39,7 @@ typedef struct cachepic_s cachepic_t; void Draw_Init (void); -cachepic_t *Draw_CachePic (char *path); +cachepic_t *Draw_CachePic (char *path, qboolean persistent); // create or update a pic's image cachepic_t *Draw_NewPic(char *picname, int width, int height, int alpha, qbyte *pixels); // free the texture memory used by a pic diff --git a/gl_backend.c b/gl_backend.c index 15bf23f9..d56bc790 100644 --- a/gl_backend.c +++ b/gl_backend.c @@ -1793,7 +1793,7 @@ void SCR_UpdateLoadingScreen (void) R_Mesh_Start(); R_Mesh_Matrix(&r_identitymatrix); // draw the loading plaque - pic = Draw_CachePic("gfx/loading.lmp"); + pic = Draw_CachePic("gfx/loading.lmp", false); x = (vid_conwidth.integer - pic->width)/2; y = (vid_conheight.integer - pic->height)/2; GL_Color(1,1,1,1); diff --git a/gl_draw.c b/gl_draw.c index 0ab9c19d..f0b1d405 100644 --- a/gl_draw.c +++ b/gl_draw.c @@ -262,13 +262,14 @@ Draw_CachePic ================ */ // FIXME: move this to client somehow -cachepic_t *Draw_CachePic (char *path) +cachepic_t *Draw_CachePic (char *path, qboolean persistent) { int i, crc, hashkey; cachepic_t *pic; qpic_t *p; + int persistentflag; - if (!strncmp(CLVIDEOPREFIX, path, sizeof(CLVIDEOPREFIX) - 1)) { + if (!strncmp(CLVIDEOPREFIX, path, sizeof(CLVIDEOPREFIX) - 1)) { clvideo_t *video; video = CL_GetVideo(path); @@ -276,6 +277,12 @@ cachepic_t *Draw_CachePic (char *path) return &video->cpif; } + if (persistent) { + persistentflag = TEXF_PRECACHE; + } else { + persistentflag = 0; + } + crc = CRC_Block(path, strlen(path)); hashkey = ((crc >> 8) ^ crc) % CACHEPICHASHSIZE; for (pic = cachepichash[hashkey];pic;pic = pic->chain) @@ -291,11 +298,11 @@ cachepic_t *Draw_CachePic (char *path) cachepichash[hashkey] = pic; // load the pic from disk - pic->tex = loadtextureimage(drawtexturepool, path, 0, 0, false, TEXF_ALPHA | TEXF_PRECACHE); + pic->tex = loadtextureimage(drawtexturepool, path, 0, 0, false, TEXF_ALPHA | persistentflag); if (pic->tex == NULL && !strncmp(path, "gfx/", 4)) { // compatibility with older versions - pic->tex = loadtextureimage(drawtexturepool, path + 4, 0, 0, false, TEXF_ALPHA | TEXF_PRECACHE); + pic->tex = loadtextureimage(drawtexturepool, path + 4, 0, 0, false, TEXF_ALPHA | persistentflag); // failed to find gfx/whatever.tga or similar, try the wad if (pic->tex == NULL && (p = W_GetLumpName (path + 4))) { @@ -307,10 +314,10 @@ cachepic_t *Draw_CachePic (char *path) for (i = 0;i < 128 * 128;i++) if (pix[i] == 0) pix[i] = 255; - pic->tex = R_LoadTexture2D(drawtexturepool, path, 128, 128, pix, TEXTYPE_PALETTE, TEXF_ALPHA | TEXF_PRECACHE, palette_complete); + pic->tex = R_LoadTexture2D(drawtexturepool, path, 128, 128, pix, TEXTYPE_PALETTE, TEXF_ALPHA | persistentflag, palette_complete); } else - pic->tex = R_LoadTexture2D(drawtexturepool, path, p->width, p->height, p->data, TEXTYPE_PALETTE, TEXF_ALPHA | TEXF_PRECACHE, palette_complete); + pic->tex = R_LoadTexture2D(drawtexturepool, path, p->width, p->height, p->data, TEXTYPE_PALETTE, TEXF_ALPHA | persistentflag, palette_complete); } } @@ -416,7 +423,7 @@ static void gl_draw_start(void) numcachepics = 0; memset(cachepichash, 0, sizeof(cachepichash)); - char_texture = Draw_CachePic("gfx/conchars")->tex; + char_texture = Draw_CachePic("gfx/conchars", true)->tex; } static void gl_draw_shutdown(void) diff --git a/menu.c b/menu.c index 3c84478b..59138175 100644 --- a/menu.c +++ b/menu.c @@ -413,7 +413,7 @@ void M_Main_Draw (void) if (gamemode == GAME_TRANSFUSION) { int y1, y2, y3; M_Background(640, 480); - p = Draw_CachePic ("gfx/tb-transfusion"); + p = Draw_CachePic ("gfx/tb-transfusion", false); M_DrawPic (640/2 - p->width/2, 40, "gfx/tb-transfusion"); y2 = 120; // 8 rather than MAIN_ITEMS to skip a number and not miss the last option @@ -434,7 +434,7 @@ void M_Main_Draw (void) M_Background(320, 200); M_DrawPic (16, 4, "gfx/qplaque.lmp"); - p = Draw_CachePic ("gfx/ttl_main.lmp"); + p = Draw_CachePic ("gfx/ttl_main.lmp", false); M_DrawPic ( (320-p->width)/2, 4, "gfx/ttl_main.lmp"); // Nehahra if (gamemode == GAME_NEHAHRA) @@ -719,7 +719,7 @@ void M_SinglePlayer_Draw (void) M_Background(320, 200); M_DrawPic (16, 4, "gfx/qplaque.lmp"); - p = Draw_CachePic ("gfx/ttl_sgl.lmp"); + p = Draw_CachePic ("gfx/ttl_sgl.lmp", false); // Some mods don't have a single player mode if (gamemode == GAME_NEXUIZ || gamemode == GAME_GOODVSBAD2 || gamemode == GAME_BATTLEMECH) @@ -885,8 +885,8 @@ void M_Load_Draw (void) M_Background(320, 200); - p = Draw_CachePic ("gfx/p_load.lmp"); - M_DrawPic ( (320-p->width)/2, 4, "gfx/p_load.lmp"); + p = Draw_CachePic ("gfx/p_load.lmp", false); + M_DrawPic ( (320-p->width)/2, 4, "gfx/p_load.lmp" ); for (i=0 ; i< MAX_SAVEGAMES; i++) M_Print(16, 32 + 8*i, m_filenames[i]); @@ -903,7 +903,7 @@ void M_Save_Draw (void) M_Background(320, 200); - p = Draw_CachePic ("gfx/p_save.lmp"); + p = Draw_CachePic ("gfx/p_save.lmp", false); M_DrawPic ( (320-p->width)/2, 4, "gfx/p_save.lmp"); for (i=0 ; iwidth/2, 40, "gfx/tb-episodes"); for (y = 0; y < EPISODE_ITEMS; y++){ M_DrawPic (0, 160 + y * 40, va("gfx/episode%i", y+1)); @@ -1066,7 +1066,7 @@ void M_Transfusion_Skill_Draw (void) cachepic_t *p; M_Background(640, 480); - p = Draw_CachePic ("gfx/tb-difficulty"); + p = Draw_CachePic ("gfx/tb-difficulty", false); M_DrawPic(640/2 - p->width/2, 40, "gfx/tb-difficulty"); for (y = 0; y < SKILL_ITEMS; y++) @@ -1170,7 +1170,7 @@ void M_MultiPlayer_Draw (void) if (gamemode == GAME_TRANSFUSION) { M_Background(640, 480); - p = Draw_CachePic ("gfx/tb-online"); + p = Draw_CachePic ("gfx/tb-online", false); M_DrawPic (640/2 - p->width/2, 140, "gfx/tb-online"); for (f = 1; f <= MULTIPLAYER_ITEMS; f++) M_DrawPic (0, 180 + f*40, va("gfx/online%i", f)); @@ -1180,7 +1180,7 @@ void M_MultiPlayer_Draw (void) M_Background(320, 200); M_DrawPic (16, 4, "gfx/qplaque.lmp"); - p = Draw_CachePic ("gfx/p_multi.lmp"); + p = Draw_CachePic ("gfx/p_multi.lmp", false); M_DrawPic ( (320-p->width)/2, 4, "gfx/p_multi.lmp"); M_DrawPic (72, 32, "gfx/mp_menu.lmp"); @@ -1298,7 +1298,7 @@ void M_Setup_Draw (void) M_Background(320, 200); M_DrawPic (16, 4, "gfx/qplaque.lmp"); - p = Draw_CachePic ("gfx/p_multi.lmp"); + p = Draw_CachePic ("gfx/p_multi.lmp", false); M_DrawPic ( (320-p->width)/2, 4, "gfx/p_multi.lmp"); M_Print(64, 40, "Your name"); @@ -1648,7 +1648,7 @@ void M_Options_Draw (void) M_Background(320, bound(200, 32 + OPTIONS_ITEMS * 8, vid.conheight)); M_DrawPic(16, 4, "gfx/qplaque.lmp"); - p = Draw_CachePic("gfx/p_option.lmp"); + p = Draw_CachePic("gfx/p_option.lmp", false); M_DrawPic((320-p->width)/2, 4, "gfx/p_option.lmp"); optnum = 0; @@ -1847,7 +1847,7 @@ void M_Options_Effects_Draw (void) M_Background(320, bound(200, 32 + OPTIONS_EFFECTS_ITEMS * 8, vid.conheight)); M_DrawPic(16, 4, "gfx/qplaque.lmp"); - p = Draw_CachePic("gfx/p_option.lmp"); + p = Draw_CachePic("gfx/p_option.lmp", false); M_DrawPic((320-p->width)/2, 4, "gfx/p_option.lmp"); optcursor = options_effects_cursor; @@ -1986,7 +1986,7 @@ void M_Options_Graphics_Draw (void) M_Background(320, bound(200, 32 + OPTIONS_GRAPHICS_ITEMS * 8, vid.conheight)); M_DrawPic(16, 4, "gfx/qplaque.lmp"); - p = Draw_CachePic("gfx/p_option.lmp"); + p = Draw_CachePic("gfx/p_option.lmp", false); M_DrawPic((320-p->width)/2, 4, "gfx/p_option.lmp"); optcursor = options_graphics_cursor; @@ -2169,7 +2169,7 @@ void M_Options_ColorControl_Draw (void) M_Background(320, 256); M_DrawPic(16, 4, "gfx/qplaque.lmp"); - p = Draw_CachePic("gfx/p_option.lmp"); + p = Draw_CachePic("gfx/p_option.lmp", false); M_DrawPic((320-p->width)/2, 4, "gfx/p_option.lmp"); optcursor = options_colorcontrol_cursor; @@ -2557,7 +2557,7 @@ void M_Keys_Draw (void) M_Background(320, 48 + 8 * numcommands); - p = Draw_CachePic ("gfx/ttl_cstm.lmp"); + p = Draw_CachePic ("gfx/ttl_cstm.lmp", false); M_DrawPic ( (320-p->width)/2, 4, "gfx/ttl_cstm.lmp"); if (bind_grab) @@ -2768,7 +2768,7 @@ void M_Video_Draw (void) M_Background(320, 200); M_DrawPic(16, 4, "gfx/qplaque.lmp"); - p = Draw_CachePic("gfx/vidmodes.lmp"); + p = Draw_CachePic("gfx/vidmodes.lmp", false); M_DrawPic((320-p->width)/2, 4, "gfx/vidmodes.lmp"); // Resolution @@ -3147,7 +3147,7 @@ void M_LanConfig_Draw (void) M_Background(320, 200); M_DrawPic (16, 4, "gfx/qplaque.lmp"); - p = Draw_CachePic ("gfx/p_multi.lmp"); + p = Draw_CachePic ("gfx/p_multi.lmp", false); basex = (320-p->width)/2; M_DrawPic (basex, 4, "gfx/p_multi.lmp"); @@ -3736,7 +3736,7 @@ void M_GameOptions_Draw (void) M_Background(320, 200); M_DrawPic (16, 4, "gfx/qplaque.lmp"); - p = Draw_CachePic ("gfx/p_multi.lmp"); + p = Draw_CachePic ("gfx/p_multi.lmp", false); M_DrawPic ( (320-p->width)/2, 4, "gfx/p_multi.lmp"); M_DrawTextBox (152, 32, 10, 1); @@ -4180,7 +4180,7 @@ void M_ServerList_Draw (void) start = bound(0, slist_cursor - (visible >> 1), serverlist_viewcount - visible); end = min(start + visible, serverlist_viewcount); - p = Draw_CachePic("gfx/p_multi.lmp"); + p = Draw_CachePic("gfx/p_multi.lmp", false); M_DrawPic((640 - p->width) / 2, 4, "gfx/p_multi.lmp"); if (end > start) { @@ -4444,7 +4444,7 @@ void M_Draw (void) g = (int)(realtime * 64)%96; scale_y_rate = (float)(g+1) / 96; top_offset = (g+12)/12; - p = Draw_CachePic (va("gfx/blooddrip%i", top_offset)); + p = Draw_CachePic (va("gfx/blooddrip%i", top_offset), false); for (scale_x = 0; scale_x <= vid.conwidth; scale_x += p->width) { for (scale_y = -scale_y_repeat; scale_y <= vid.conheight; scale_y += scale_y_repeat) { DrawQ_Pic (scale_x + 21, scale_y_repeat * .5 + scale_y + scale_y_rate * scale_y_repeat, "gfx/blooddrop3", 0, 0, 1, 1, 1, 1, 0); diff --git a/netconn.h b/netconn.h index c12d2bab..d958db4d 100755 --- a/netconn.h +++ b/netconn.h @@ -150,7 +150,7 @@ extern cvar_t developer_networking; extern char playername[]; extern int playercolor; -#define SERVERLIST_TOTALSIZE 2048 +#define SERVERLIST_TOTALSIZE 2048 #define SERVERLIST_VIEWLISTSIZE 128 #define SERVERLIST_ANDMASKCOUNT 5 #define SERVERLIST_ORMASKCOUNT 5 diff --git a/prvm_cmds.c b/prvm_cmds.c index e306d917..82006d38 100644 --- a/prvm_cmds.c +++ b/prvm_cmds.c @@ -2576,7 +2576,7 @@ void VM_precache_pic(void) VM_CheckEmptyString (s); - if(!Draw_CachePic(s)) + if(!Draw_CachePic(s, false)) PRVM_G_INT(OFS_RETURN) = PRVM_SetString(""); } @@ -2842,7 +2842,7 @@ void VM_getimagesize(void) VM_CheckEmptyString (p); - pic = Draw_CachePic (p); + pic = Draw_CachePic (p, false); PRVM_G_VECTOR(OFS_RETURN)[0] = pic->width; PRVM_G_VECTOR(OFS_RETURN)[1] = pic->height; diff --git a/r_crosshairs.c b/r_crosshairs.c index bf5018bb..2b61af10 100644 --- a/r_crosshairs.c +++ b/r_crosshairs.c @@ -71,7 +71,7 @@ void R_DrawWorldCrosshair(void) return; if (!cl.viewentity || !cl_entities[cl.viewentity].state_current.active) return; - pic = Draw_CachePic(va("gfx/crosshair%i.tga", num)); + pic = Draw_CachePic(va("gfx/crosshair%i.tga", num), true); if (!pic) return; R_GetCrosshairColor(color); @@ -104,7 +104,7 @@ void R_Draw2DCrosshair(void) return; if (!cl.viewentity || !cl_entities[cl.viewentity].state_current.active) return; - pic = Draw_CachePic(va("gfx/crosshair%i.tga", num)); + pic = Draw_CachePic(va("gfx/crosshair%i.tga", num), true); if (pic) { R_GetCrosshairColor(color); diff --git a/r_shadow.c b/r_shadow.c index 1ff13a64..49d09796 100644 --- a/r_shadow.c +++ b/r_shadow.c @@ -3093,7 +3093,7 @@ void R_Shadow_DrawLightSprites(void) for (i = 0;i < 5;i++) { lighttextures[i] = NULL; - if ((pic = Draw_CachePic(va("gfx/crosshair%i.tga", i + 1)))) + if ((pic = Draw_CachePic(va("gfx/crosshair%i.tga", i + 1), true))) lighttextures[i] = pic->tex; } diff --git a/sbar.c b/sbar.c index bec97e71..e06e024f 100644 --- a/sbar.c +++ b/sbar.c @@ -35,7 +35,7 @@ static sbarpic_t *Sbar_NewPic(const char *name) strcpy(sbarpics[numsbarpics].name, name); // precache it // FIXME: precache on every renderer restart (or move this to client) - Draw_CachePic(sbarpics[numsbarpics].name); + Draw_CachePic(sbarpics[numsbarpics].name, true); return sbarpics + (numsbarpics++); } @@ -1175,7 +1175,7 @@ void Sbar_DeathmatchOverlay (void) int i, x, y; cachepic_t *pic; - pic = Draw_CachePic ("gfx/ranking.lmp"); + pic = Draw_CachePic ("gfx/ranking.lmp", true); DrawQ_Pic ((vid.conwidth - pic->width)/2, 8, "gfx/ranking.lmp", 0, 0, 1, 1, 1, 1 * sbar_alpha_fg.value, 0); // scores @@ -1284,7 +1284,7 @@ void Sbar_FinaleOverlay (void) { cachepic_t *pic; - pic = Draw_CachePic ("gfx/finale.lmp"); + pic = Draw_CachePic ("gfx/finale.lmp", true); DrawQ_Pic((vid.conwidth - pic->width)/2, 16, "gfx/finale.lmp", 0, 0, 1, 1, 1, 1 * sbar_alpha_fg.value, 0); } -- 2.39.2