now pretends gfx.wad pics are in the gfx/ directory, this changes the override path...
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Tue, 24 Sep 2002 07:05:13 +0000 (07:05 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Tue, 24 Sep 2002 07:05:13 +0000 (07:05 +0000)
Sbar_Init now called from Render_Init instead of Host_Init (it was being called before the texture system was started...)
Sbar_Init now registers an sbar module, with corresponding start/shutdown/newmap functions, so when the renderer is restarted, the pics are precached again

git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@2426 d7cf8633-e32d-0410-b094-e92efae38249

gl_draw.c
gl_rmain.c
host.c
sbar.c

index 73b3f40..eec5a4c 100644 (file)
--- a/gl_draw.c
+++ b/gl_draw.c
@@ -224,20 +224,26 @@ cachepic_t        *Draw_CachePic (char *path)
 
        // load the pic from disk
        pic->tex = loadtextureimage(drawtexturepool, path, 0, 0, false, false, true);
-       if (pic->tex == NULL && (p = W_GetLumpName (path)))
+       if (pic->tex == NULL && !strncmp(path, "gfx/", 4))
        {
-               if (!strcmp(path, "conchars"))
+               // compatibility with older versions
+               pic->tex = loadtextureimage(drawtexturepool, path + 4, 0, 0, false, false, true);
+               // failed to find gfx/whatever.tga or similar, try the wad
+               if (pic->tex == NULL && (p = W_GetLumpName (path + 4)))
                {
-                       qbyte *pix;
-                       // conchars is a raw image and with the wrong transparent color
-                       pix = (qbyte *)p;
-                       for (i = 0;i < 128 * 128;i++)
-                               if (pix[i] == 0)
-                                       pix[i] = 255;
-                       pic->tex = R_LoadTexture (drawtexturepool, path, 128, 128, pix, TEXTYPE_QPALETTE, TEXF_ALPHA | TEXF_PRECACHE);
+                       if (!strcmp(path, "gfx/conchars"))
+                       {
+                               qbyte *pix;
+                               // conchars is a raw image and with the wrong transparent color
+                               pix = (qbyte *)p;
+                               for (i = 0;i < 128 * 128;i++)
+                                       if (pix[i] == 0)
+                                               pix[i] = 255;
+                               pic->tex = R_LoadTexture (drawtexturepool, path, 128, 128, pix, TEXTYPE_QPALETTE, TEXF_ALPHA | TEXF_PRECACHE);
+                       }
+                       else
+                               pic->tex = R_LoadTexture (drawtexturepool, path, p->width, p->height, p->data, TEXTYPE_QPALETTE, TEXF_ALPHA | TEXF_PRECACHE);
                }
-               else
-                       pic->tex = R_LoadTexture (drawtexturepool, path, p->width, p->height, p->data, TEXTYPE_QPALETTE, TEXF_ALPHA | TEXF_PRECACHE);
        }
        if (pic->tex == NULL && !strcmp(path, "ui/mousepointer.tga"))
                pic->tex = draw_generatemousepointer();
@@ -252,7 +258,10 @@ cachepic_t *Draw_CachePic (char *path)
        if (pic->tex == NULL && !strcmp(path, "gfx/crosshair5.tga"))
                pic->tex = draw_generatecrosshair(4);
        if (pic->tex == NULL)
-               Sys_Error ("Draw_CachePic: failed to load %s", path);
+       {
+               Con_Printf ("Draw_CachePic: failed to load %s", path);
+               pic->tex = r_notexture;
+       }
 
        pic->width = R_TextureWidth(pic->tex);
        pic->height = R_TextureHeight(pic->tex);
@@ -332,7 +341,7 @@ static void gl_draw_start(void)
        numcachepics = 0;
        memset(cachepichash, 0, sizeof(cachepichash));
 
-       char_texture = Draw_CachePic("conchars")->tex;
+       char_texture = Draw_CachePic("gfx/conchars")->tex;
 }
 
 static void gl_draw_shutdown(void)
@@ -452,14 +461,14 @@ void R_DrawQueue(void)
                        break;
                case DRAWQUEUE_STRING:
                        str = (char *)(dq + 1);
-                       if (strcmp("conchars", currentpic))
+                       if (strcmp("gfx/conchars", currentpic))
                        {
                                if (batch)
                                {
                                        batch = false;
                                        qglEnd();
                                }
-                               currentpic = "conchars";
+                               currentpic = "gfx/conchars";
                                qglBindTexture(GL_TEXTURE_2D, chartexnum);
                        }
                        batchcount = 0;
@@ -733,14 +742,14 @@ void R_DrawQueue(void)
                        break;
                case DRAWQUEUE_STRING:
                        str = (char *)(dq + 1);
-                       if (strcmp("conchars", currentpic))
+                       if (strcmp("gfx/conchars", currentpic))
                        {
                                if (batch)
                                {
                                        batch = false;
                                        qglEnd();
                                }
-                               currentpic = "conchars";
+                               currentpic = "gfx/conchars";
                                qglBindTexture(GL_TEXTURE_2D, chartexnum);
                        }
                        if (!batch)
index 56b902a..a0152b1 100644 (file)
@@ -289,6 +289,7 @@ extern void R_Particles_Init(void);
 extern void R_Explosion_Init(void);
 extern void ui_init(void);
 extern void gl_backend_init(void);
+extern void Sbar_Init(void);
 
 void Render_Init(void)
 {
@@ -307,6 +308,7 @@ void Render_Init(void)
        R_Particles_Init();
        R_Explosion_Init();
        ui_init();
+       Sbar_Init();
        R_Modules_Start();
 }
 
diff --git a/host.c b/host.c
index 8a290bf..9fcc9cf 100644 (file)
--- a/host.c
+++ b/host.c
@@ -901,7 +901,6 @@ void Host_Init (void)
                Render_Init();
                S_Init ();
                CDAudio_Init ();
-               Sbar_Init ();
                CL_Init ();
 #ifdef _WIN32 // on non win32, mouse comes before video for security reasons
                IN_Init ();
diff --git a/sbar.c b/sbar.c
index e14b58d..31fc000 100644 (file)
--- a/sbar.c
+++ b/sbar.c
@@ -23,19 +23,19 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
 typedef struct
 {
-       char name[16];
+       char name[32];
 }
 sbarpic_t;
 
 static sbarpic_t sbarpics[256];
 static int numsbarpics;
 
-static sbarpic_t *Sbar_NewPic(char *name)
+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(name);
+       Draw_CachePic(sbarpics[numsbarpics].name);
        return sbarpics + (numsbarpics++);
 }
 
@@ -54,9 +54,9 @@ sbarpic_t *sb_sigil[4];
 sbarpic_t *sb_armor[3];
 sbarpic_t *sb_items[32];
 
-// 0 is gibbed, 1 is dead, 2-6 are alive
+// 0-4 are based on health (in 20 increments)
 // 0 is static, 1 is temporary animation
-sbarpic_t *sb_faces[7][2];
+sbarpic_t *sb_faces[5][2];
 
 sbarpic_t *sb_face_invis;
 sbarpic_t *sb_face_quad;
@@ -114,154 +114,162 @@ void Sbar_DontShowScores (void)
        sb_showscores = false;
 }
 
-/*
-===============
-Sbar_Init
-===============
-*/
-void Sbar_Init (void)
+void sbar_start(void)
 {
        int i;
 
-       Cmd_AddCommand ("+showscores", Sbar_ShowScores);
-       Cmd_AddCommand ("-showscores", Sbar_DontShowScores);
-       Cvar_RegisterVariable (&showfps);
-
        numsbarpics = 0;
 
-       sb_disc = Sbar_NewPic("disc");
+       sb_disc = Sbar_NewPic("gfx/disc");
 
-       for (i=0 ; i<10 ; i++)
+       for (i = 0;i < 10;i++)
        {
-               sb_nums[0][i] = Sbar_NewPic (va("num_%i",i));
-               sb_nums[1][i] = Sbar_NewPic (va("anum_%i",i));
+               sb_nums[0][i] = Sbar_NewPic (va("gfx/num_%i",i));
+               sb_nums[1][i] = Sbar_NewPic (va("gfx/anum_%i",i));
        }
 
-       sb_nums[0][10] = Sbar_NewPic ("num_minus");
-       sb_nums[1][10] = Sbar_NewPic ("anum_minus");
-
-       sb_colon = Sbar_NewPic ("num_colon");
-       sb_slash = Sbar_NewPic ("num_slash");
-
-       sb_weapons[0][0] = Sbar_NewPic ("inv_shotgun");
-       sb_weapons[0][1] = Sbar_NewPic ("inv_sshotgun");
-       sb_weapons[0][2] = Sbar_NewPic ("inv_nailgun");
-       sb_weapons[0][3] = Sbar_NewPic ("inv_snailgun");
-       sb_weapons[0][4] = Sbar_NewPic ("inv_rlaunch");
-       sb_weapons[0][5] = Sbar_NewPic ("inv_srlaunch");
-       sb_weapons[0][6] = Sbar_NewPic ("inv_lightng");
-
-       sb_weapons[1][0] = Sbar_NewPic ("inv2_shotgun");
-       sb_weapons[1][1] = Sbar_NewPic ("inv2_sshotgun");
-       sb_weapons[1][2] = Sbar_NewPic ("inv2_nailgun");
-       sb_weapons[1][3] = Sbar_NewPic ("inv2_snailgun");
-       sb_weapons[1][4] = Sbar_NewPic ("inv2_rlaunch");
-       sb_weapons[1][5] = Sbar_NewPic ("inv2_srlaunch");
-       sb_weapons[1][6] = Sbar_NewPic ("inv2_lightng");
-
-       for (i=0 ; i<5 ; i++)
+       sb_nums[0][10] = Sbar_NewPic ("gfx/num_minus");
+       sb_nums[1][10] = Sbar_NewPic ("gfx/anum_minus");
+
+       sb_colon = Sbar_NewPic ("gfx/num_colon");
+       sb_slash = Sbar_NewPic ("gfx/num_slash");
+
+       sb_weapons[0][0] = Sbar_NewPic ("gfx/inv_shotgun");
+       sb_weapons[0][1] = Sbar_NewPic ("gfx/inv_sshotgun");
+       sb_weapons[0][2] = Sbar_NewPic ("gfx/inv_nailgun");
+       sb_weapons[0][3] = Sbar_NewPic ("gfx/inv_snailgun");
+       sb_weapons[0][4] = Sbar_NewPic ("gfx/inv_rlaunch");
+       sb_weapons[0][5] = Sbar_NewPic ("gfx/inv_srlaunch");
+       sb_weapons[0][6] = Sbar_NewPic ("gfx/inv_lightng");
+
+       sb_weapons[1][0] = Sbar_NewPic ("gfx/inv2_shotgun");
+       sb_weapons[1][1] = Sbar_NewPic ("gfx/inv2_sshotgun");
+       sb_weapons[1][2] = Sbar_NewPic ("gfx/inv2_nailgun");
+       sb_weapons[1][3] = Sbar_NewPic ("gfx/inv2_snailgun");
+       sb_weapons[1][4] = Sbar_NewPic ("gfx/inv2_rlaunch");
+       sb_weapons[1][5] = Sbar_NewPic ("gfx/inv2_srlaunch");
+       sb_weapons[1][6] = Sbar_NewPic ("gfx/inv2_lightng");
+
+       for (i = 0;i < 5;i++)
        {
-               sb_weapons[2+i][0] = Sbar_NewPic (va("inva%i_shotgun",i+1));
-               sb_weapons[2+i][1] = Sbar_NewPic (va("inva%i_sshotgun",i+1));
-               sb_weapons[2+i][2] = Sbar_NewPic (va("inva%i_nailgun",i+1));
-               sb_weapons[2+i][3] = Sbar_NewPic (va("inva%i_snailgun",i+1));
-               sb_weapons[2+i][4] = Sbar_NewPic (va("inva%i_rlaunch",i+1));
-               sb_weapons[2+i][5] = Sbar_NewPic (va("inva%i_srlaunch",i+1));
-               sb_weapons[2+i][6] = Sbar_NewPic (va("inva%i_lightng",i+1));
+               sb_weapons[2+i][0] = Sbar_NewPic (va("gfx/inva%i_shotgun",i+1));
+               sb_weapons[2+i][1] = Sbar_NewPic (va("gfx/inva%i_sshotgun",i+1));
+               sb_weapons[2+i][2] = Sbar_NewPic (va("gfx/inva%i_nailgun",i+1));
+               sb_weapons[2+i][3] = Sbar_NewPic (va("gfx/inva%i_snailgun",i+1));
+               sb_weapons[2+i][4] = Sbar_NewPic (va("gfx/inva%i_rlaunch",i+1));
+               sb_weapons[2+i][5] = Sbar_NewPic (va("gfx/inva%i_srlaunch",i+1));
+               sb_weapons[2+i][6] = Sbar_NewPic (va("gfx/inva%i_lightng",i+1));
        }
 
-       sb_ammo[0] = Sbar_NewPic ("sb_shells");
-       sb_ammo[1] = Sbar_NewPic ("sb_nails");
-       sb_ammo[2] = Sbar_NewPic ("sb_rocket");
-       sb_ammo[3] = Sbar_NewPic ("sb_cells");
-
-       sb_armor[0] = Sbar_NewPic ("sb_armor1");
-       sb_armor[1] = Sbar_NewPic ("sb_armor2");
-       sb_armor[2] = Sbar_NewPic ("sb_armor3");
-
-       sb_items[0] = Sbar_NewPic ("sb_key1");
-       sb_items[1] = Sbar_NewPic ("sb_key2");
-       sb_items[2] = Sbar_NewPic ("sb_invis");
-       sb_items[3] = Sbar_NewPic ("sb_invuln");
-       sb_items[4] = Sbar_NewPic ("sb_suit");
-       sb_items[5] = Sbar_NewPic ("sb_quad");
-
-       sb_sigil[0] = Sbar_NewPic ("sb_sigil1");
-       sb_sigil[1] = Sbar_NewPic ("sb_sigil2");
-       sb_sigil[2] = Sbar_NewPic ("sb_sigil3");
-       sb_sigil[3] = Sbar_NewPic ("sb_sigil4");
-
-       sb_faces[4][0] = Sbar_NewPic ("face1");
-       sb_faces[4][1] = Sbar_NewPic ("face_p1");
-       sb_faces[3][0] = Sbar_NewPic ("face2");
-       sb_faces[3][1] = Sbar_NewPic ("face_p2");
-       sb_faces[2][0] = Sbar_NewPic ("face3");
-       sb_faces[2][1] = Sbar_NewPic ("face_p3");
-       sb_faces[1][0] = Sbar_NewPic ("face4");
-       sb_faces[1][1] = Sbar_NewPic ("face_p4");
-       sb_faces[0][0] = Sbar_NewPic ("face5");
-       sb_faces[0][1] = Sbar_NewPic ("face_p5");
-
-       sb_face_invis = Sbar_NewPic ("face_invis");
-       sb_face_invuln = Sbar_NewPic ("face_invul2");
-       sb_face_invis_invuln = Sbar_NewPic ("face_inv2");
-       sb_face_quad = Sbar_NewPic ("face_quad");
-
-       sb_sbar = Sbar_NewPic ("sbar");
-       sb_ibar = Sbar_NewPic ("ibar");
-       sb_scorebar = Sbar_NewPic ("scorebar");
+       sb_ammo[0] = Sbar_NewPic ("gfx/sb_shells");
+       sb_ammo[1] = Sbar_NewPic ("gfx/sb_nails");
+       sb_ammo[2] = Sbar_NewPic ("gfx/sb_rocket");
+       sb_ammo[3] = Sbar_NewPic ("gfx/sb_cells");
+
+       sb_armor[0] = Sbar_NewPic ("gfx/sb_armor1");
+       sb_armor[1] = Sbar_NewPic ("gfx/sb_armor2");
+       sb_armor[2] = Sbar_NewPic ("gfx/sb_armor3");
+
+       sb_items[0] = Sbar_NewPic ("gfx/sb_key1");
+       sb_items[1] = Sbar_NewPic ("gfx/sb_key2");
+       sb_items[2] = Sbar_NewPic ("gfx/sb_invis");
+       sb_items[3] = Sbar_NewPic ("gfx/sb_invuln");
+       sb_items[4] = Sbar_NewPic ("gfx/sb_suit");
+       sb_items[5] = Sbar_NewPic ("gfx/sb_quad");
+
+       sb_sigil[0] = Sbar_NewPic ("gfx/sb_sigil1");
+       sb_sigil[1] = Sbar_NewPic ("gfx/sb_sigil2");
+       sb_sigil[2] = Sbar_NewPic ("gfx/sb_sigil3");
+       sb_sigil[3] = Sbar_NewPic ("gfx/sb_sigil4");
+
+       sb_faces[4][0] = Sbar_NewPic ("gfx/face1");
+       sb_faces[4][1] = Sbar_NewPic ("gfx/face_p1");
+       sb_faces[3][0] = Sbar_NewPic ("gfx/face2");
+       sb_faces[3][1] = Sbar_NewPic ("gfx/face_p2");
+       sb_faces[2][0] = Sbar_NewPic ("gfx/face3");
+       sb_faces[2][1] = Sbar_NewPic ("gfx/face_p3");
+       sb_faces[1][0] = Sbar_NewPic ("gfx/face4");
+       sb_faces[1][1] = Sbar_NewPic ("gfx/face_p4");
+       sb_faces[0][0] = Sbar_NewPic ("gfx/face5");
+       sb_faces[0][1] = Sbar_NewPic ("gfx/face_p5");
+
+       sb_face_invis = Sbar_NewPic ("gfx/face_invis");
+       sb_face_invuln = Sbar_NewPic ("gfx/face_invul2");
+       sb_face_invis_invuln = Sbar_NewPic ("gfx/face_inv2");
+       sb_face_quad = Sbar_NewPic ("gfx/face_quad");
+
+       sb_sbar = Sbar_NewPic ("gfx/sbar");
+       sb_ibar = Sbar_NewPic ("gfx/ibar");
+       sb_scorebar = Sbar_NewPic ("gfx/scorebar");
 
 //MED 01/04/97 added new hipnotic weapons
        if (gamemode == GAME_HIPNOTIC)
        {
-               hsb_weapons[0][0] = Sbar_NewPic ("inv_laser");
-               hsb_weapons[0][1] = Sbar_NewPic ("inv_mjolnir");
-               hsb_weapons[0][2] = Sbar_NewPic ("inv_gren_prox");
-               hsb_weapons[0][3] = Sbar_NewPic ("inv_prox_gren");
-               hsb_weapons[0][4] = Sbar_NewPic ("inv_prox");
-
-               hsb_weapons[1][0] = Sbar_NewPic ("inv2_laser");
-               hsb_weapons[1][1] = Sbar_NewPic ("inv2_mjolnir");
-               hsb_weapons[1][2] = Sbar_NewPic ("inv2_gren_prox");
-               hsb_weapons[1][3] = Sbar_NewPic ("inv2_prox_gren");
-               hsb_weapons[1][4] = Sbar_NewPic ("inv2_prox");
-
-               for (i=0 ; i<5 ; i++)
+               hsb_weapons[0][0] = Sbar_NewPic ("gfx/inv_laser");
+               hsb_weapons[0][1] = Sbar_NewPic ("gfx/inv_mjolnir");
+               hsb_weapons[0][2] = Sbar_NewPic ("gfx/inv_gren_prox");
+               hsb_weapons[0][3] = Sbar_NewPic ("gfx/inv_prox_gren");
+               hsb_weapons[0][4] = Sbar_NewPic ("gfx/inv_prox");
+
+               hsb_weapons[1][0] = Sbar_NewPic ("gfx/inv2_laser");
+               hsb_weapons[1][1] = Sbar_NewPic ("gfx/inv2_mjolnir");
+               hsb_weapons[1][2] = Sbar_NewPic ("gfx/inv2_gren_prox");
+               hsb_weapons[1][3] = Sbar_NewPic ("gfx/inv2_prox_gren");
+               hsb_weapons[1][4] = Sbar_NewPic ("gfx/inv2_prox");
+
+               for (i = 0;i < 5;i++)
                {
-                       hsb_weapons[2+i][0] = Sbar_NewPic (va("inva%i_laser",i+1));
-                       hsb_weapons[2+i][1] = Sbar_NewPic (va("inva%i_mjolnir",i+1));
-                       hsb_weapons[2+i][2] = Sbar_NewPic (va("inva%i_gren_prox",i+1));
-                       hsb_weapons[2+i][3] = Sbar_NewPic (va("inva%i_prox_gren",i+1));
-                       hsb_weapons[2+i][4] = Sbar_NewPic (va("inva%i_prox",i+1));
+                       hsb_weapons[2+i][0] = Sbar_NewPic (va("gfx/inva%i_laser",i+1));
+                       hsb_weapons[2+i][1] = Sbar_NewPic (va("gfx/inva%i_mjolnir",i+1));
+                       hsb_weapons[2+i][2] = Sbar_NewPic (va("gfx/inva%i_gren_prox",i+1));
+                       hsb_weapons[2+i][3] = Sbar_NewPic (va("gfx/inva%i_prox_gren",i+1));
+                       hsb_weapons[2+i][4] = Sbar_NewPic (va("gfx/inva%i_prox",i+1));
                }
 
-               hsb_items[0] = Sbar_NewPic ("sb_wsuit");
-               hsb_items[1] = Sbar_NewPic ("sb_eshld");
+               hsb_items[0] = Sbar_NewPic ("gfx/sb_wsuit");
+               hsb_items[1] = Sbar_NewPic ("gfx/sb_eshld");
        }
        else if (gamemode == GAME_ROGUE)
        {
-               rsb_invbar[0] = Sbar_NewPic ("r_invbar1");
-               rsb_invbar[1] = Sbar_NewPic ("r_invbar2");
+               rsb_invbar[0] = Sbar_NewPic ("gfx/r_invbar1");
+               rsb_invbar[1] = Sbar_NewPic ("gfx/r_invbar2");
 
-               rsb_weapons[0] = Sbar_NewPic ("r_lava");
-               rsb_weapons[1] = Sbar_NewPic ("r_superlava");
-               rsb_weapons[2] = Sbar_NewPic ("r_gren");
-               rsb_weapons[3] = Sbar_NewPic ("r_multirock");
-               rsb_weapons[4] = Sbar_NewPic ("r_plasma");
+               rsb_weapons[0] = Sbar_NewPic ("gfx/r_lava");
+               rsb_weapons[1] = Sbar_NewPic ("gfx/r_superlava");
+               rsb_weapons[2] = Sbar_NewPic ("gfx/r_gren");
+               rsb_weapons[3] = Sbar_NewPic ("gfx/r_multirock");
+               rsb_weapons[4] = Sbar_NewPic ("gfx/r_plasma");
 
-               rsb_items[0] = Sbar_NewPic ("r_shield1");
-               rsb_items[1] = Sbar_NewPic ("r_agrav1");
+               rsb_items[0] = Sbar_NewPic ("gfx/r_shield1");
+               rsb_items[1] = Sbar_NewPic ("gfx/r_agrav1");
 
 // PGM 01/19/97 - team color border
-               rsb_teambord = Sbar_NewPic ("r_teambord");
+               rsb_teambord = Sbar_NewPic ("gfx/r_teambord");
 // PGM 01/19/97 - team color border
 
-               rsb_ammo[0] = Sbar_NewPic ("r_ammolava");
-               rsb_ammo[1] = Sbar_NewPic ("r_ammomulti");
-               rsb_ammo[2] = Sbar_NewPic ("r_ammoplasma");
+               rsb_ammo[0] = Sbar_NewPic ("gfx/r_ammolava");
+               rsb_ammo[1] = Sbar_NewPic ("gfx/r_ammomulti");
+               rsb_ammo[2] = Sbar_NewPic ("gfx/r_ammoplasma");
        }
 }
 
+void sbar_shutdown(void)
+{
+}
+
+void sbar_newmap(void)
+{
+}
+
+void Sbar_Init (void)
+{
+       Cmd_AddCommand ("+showscores", Sbar_ShowScores);
+       Cmd_AddCommand ("-showscores", Sbar_DontShowScores);
+       Cvar_RegisterVariable (&showfps);
+
+       R_RegisterModule("sbar", sbar_start, sbar_shutdown, sbar_newmap);
+}
+
 
 //=============================================================================