allow shirt/pants/scoreboard colors to be pulled from an extra palette file (r_colorm...
authordivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Fri, 10 Aug 2007 10:34:06 +0000 (10:34 +0000)
committerdivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Fri, 10 Aug 2007 10:34:06 +0000 (10:34 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@7515 d7cf8633-e32d-0410-b094-e92efae38249

cl_main.c
csprogs.c
palette.c
palette.h
sbar.c

index e1172e5..5f80993 100644 (file)
--- a/cl_main.c
+++ b/cl_main.c
@@ -853,32 +853,26 @@ void CL_UpdateNetworkEntity(entity_t *e, int recursionlimit, qboolean interpolat
        e->render.entitynumber = e - cl.entities;
        if (e->state_current.flags & RENDER_COLORMAPPED)
        {
-               int cb;
                unsigned char *cbcolor;
                e->render.colormap = e->state_current.colormap;
-               cb = (e->render.colormap & 0xF) << 4;cb += (cb >= 128 && cb < 224) ? 4 : 12;
-               cbcolor = (unsigned char *) (&palette_complete[cb]);
+               cbcolor = (unsigned char *) (&palette_pantscolormap[e->render.colormap & 0xF]);
                e->render.colormap_pantscolor[0] = cbcolor[0] * (1.0f / 255.0f);
                e->render.colormap_pantscolor[1] = cbcolor[1] * (1.0f / 255.0f);
                e->render.colormap_pantscolor[2] = cbcolor[2] * (1.0f / 255.0f);
-               cb = (e->render.colormap & 0xF0);cb += (cb >= 128 && cb < 224) ? 4 : 12;
-               cbcolor = (unsigned char *) (&palette_complete[cb]);
+               cbcolor = (unsigned char *) (&palette_shirtcolormap[(e->render.colormap & 0xF0) >> 4]);
                e->render.colormap_shirtcolor[0] = cbcolor[0] * (1.0f / 255.0f);
                e->render.colormap_shirtcolor[1] = cbcolor[1] * (1.0f / 255.0f);
                e->render.colormap_shirtcolor[2] = cbcolor[2] * (1.0f / 255.0f);
        }
        else if (e->state_current.colormap && cl.scores != NULL && e->state_current.colormap <= cl.maxclients)
        {
-               int cb;
                unsigned char *cbcolor;
                e->render.colormap = cl.scores[e->state_current.colormap - 1].colors; // color it
-               cb = (e->render.colormap & 0xF) << 4;cb += (cb >= 128 && cb < 224) ? 4 : 12;
-               cbcolor = (unsigned char *) (&palette_complete[cb]);
+               cbcolor = (unsigned char *) (&palette_pantscolormap[e->render.colormap & 0xF]);
                e->render.colormap_pantscolor[0] = cbcolor[0] * (1.0f / 255.0f);
                e->render.colormap_pantscolor[1] = cbcolor[1] * (1.0f / 255.0f);
                e->render.colormap_pantscolor[2] = cbcolor[2] * (1.0f / 255.0f);
-               cb = (e->render.colormap & 0xF0);cb += (cb >= 128 && cb < 224) ? 4 : 12;
-               cbcolor = (unsigned char *) (&palette_complete[cb]);
+               cbcolor = (unsigned char *) (&palette_shirtcolormap[(e->render.colormap & 0xF0) >> 4]);
                e->render.colormap_shirtcolor[0] = cbcolor[0] * (1.0f / 255.0f);
                e->render.colormap_shirtcolor[1] = cbcolor[1] * (1.0f / 255.0f);
                e->render.colormap_shirtcolor[2] = cbcolor[2] * (1.0f / 255.0f);
index 7f063c9..06e1a33 100644 (file)
--- a/csprogs.c
+++ b/csprogs.c
@@ -178,7 +178,6 @@ qboolean CSQC_AddRenderEdict(prvm_edict_t *ed)
 
        if ((e->render.colormap > 0 && e->render.colormap <= cl.maxclients) || e->render.colormap >= 1024)
        {
-               int cb;
                unsigned char *cbcolor;
                int palcol;
                if (e->render.colormap >= 1024)
@@ -186,13 +185,11 @@ qboolean CSQC_AddRenderEdict(prvm_edict_t *ed)
                else
                        palcol = cl.scores[e->render.colormap-1].colors;
 
-               cb = (palcol & 0xF) << 4;cb += (cb >= 128 && cb < 224) ? 4 : 12;
-               cbcolor = (unsigned char *) (&palette_complete[cb]);
+               cbcolor = (unsigned char *) (&palette_pantscolormap[palcol & 0xF]);
                e->render.colormap_pantscolor[0] = cbcolor[0] * (1.0f / 255.0f);
                e->render.colormap_pantscolor[1] = cbcolor[1] * (1.0f / 255.0f);
                e->render.colormap_pantscolor[2] = cbcolor[2] * (1.0f / 255.0f);
-               cb = (palcol & 0xF0);cb += (cb >= 128 && cb < 224) ? 4 : 12;
-               cbcolor = (unsigned char *) (&palette_complete[cb]);
+               cbcolor = (unsigned char *) (&palette_shirtcolormap[(palcol & 0xF0) >> 4]);
                e->render.colormap_shirtcolor[0] = cbcolor[0] * (1.0f / 255.0f);
                e->render.colormap_shirtcolor[1] = cbcolor[1] * (1.0f / 255.0f);
                e->render.colormap_shirtcolor[2] = cbcolor[2] * (1.0f / 255.0f);
index f87a834..fc6dbcb 100644 (file)
--- a/palette.c
+++ b/palette.c
@@ -1,6 +1,8 @@
 
 #include "quakedef.h"
 
+cvar_t r_colormap_palette = {0, "r_colormap_palette", "gfx/colormap_palette.lmp", "name of a palette lmp file to override the shirt/pants colors of player models. It consists of 16 shirt colors, 16 scoreboard shirt colors, 16 pants colors and 16 scoreboard pants colors"};
+
 unsigned int palette_complete[256];
 unsigned int palette_font[256];
 unsigned int palette_alpha[256];
@@ -11,6 +13,10 @@ unsigned int palette_onlyfullbrights[256];
 unsigned int palette_pantsaswhite[256];
 unsigned int palette_shirtaswhite[256];
 unsigned int palette_transparent[256];
+unsigned int palette_pantscolormap[16];
+unsigned int palette_shirtcolormap[16];
+unsigned int palette_pantsscoreboard[16];
+unsigned int palette_shirtscoreboard[16];
 
 // John Carmack said the quake palette.lmp can be considered public domain because it is not an important asset to id, so I include it here as a fallback if no external palette file is found.
 unsigned char host_quakepal[768] =
@@ -180,7 +186,15 @@ void BuildGammaTable16(float prescale, float gamma, float scale, float base, uns
        }
 }
 
-void Palette_Init(void)
+void Palette_Shutdown(void)
+{
+}
+
+void Palette_NewMap(void)
+{
+}
+
+void Palette_Load(void)
 {
        int i;
        float gamma, scale, base;
@@ -228,6 +242,79 @@ void Palette_Init(void)
        if (palfile)
                Mem_Free(palfile);
 
+if(*r_colormap_palette.string)
+       palfile = (unsigned char *)FS_LoadFile (r_colormap_palette.string, tempmempool, false, &filesize);
+else
+       palfile = NULL;
+
+in = palfile;
+if (palfile && filesize >= 48)
+{
+       out = (unsigned char *) palette_shirtcolormap;
+       for (i = 0;i < 16;i++)
+       {
+               *out++ = texturegammaramp[*in++];
+               *out++ = texturegammaramp[*in++];
+               *out++ = texturegammaramp[*in++];
+               *out++ = 255;
+       }
+}
+else
+       for(i = 0; i < 16; ++i)
+               palette_shirtcolormap[i] = palette_complete[(i << 4) | ((i >= 8 && i <= 13) ? 0x04 : 0x0C)];
+
+if(palfile && filesize >= 48 + 48)
+{
+       out = (unsigned char *) palette_shirtscoreboard;
+       for (i = 0;i < 16;i++)
+       {
+               *out++ = texturegammaramp[*in++];
+               *out++ = texturegammaramp[*in++];
+               *out++ = texturegammaramp[*in++];
+               *out++ = 255;
+       }
+}
+else
+       for(i = 0; i < 16; ++i)
+               palette_shirtscoreboard[i] = palette_complete[(i << 4) | 0x08];
+
+if (palfile && filesize >= 48 + 48 + 48)
+{
+       out = (unsigned char *) palette_pantscolormap;
+       for (i = 0;i < 16;i++)
+       {
+               *out++ = texturegammaramp[*in++];
+               *out++ = texturegammaramp[*in++];
+               *out++ = texturegammaramp[*in++];
+               *out++ = 255;
+       }
+}
+else
+       memcpy(palette_pantscolormap, palette_shirtcolormap, sizeof(palette_pantscolormap));
+
+if (palfile && filesize >= 48 + 48 + 48 + 48)
+{
+       out = (unsigned char *) palette_pantsscoreboard;
+       for (i = 0;i < 16;i++)
+       {
+               *out++ = texturegammaramp[*in++];
+               *out++ = texturegammaramp[*in++];
+               *out++ = texturegammaramp[*in++];
+               *out++ = 255;
+       }
+}
+else
+       memcpy(palette_pantsscoreboard, palette_shirtscoreboard, sizeof(palette_pantsscoreboard));
+
+if(palfile)
+       Mem_Free(palfile);
+
        Palette_SetupSpecialPalettes();
 }
 
+void Palette_Init(void)
+{
+       R_RegisterModule("Palette", Palette_Load, Palette_Shutdown, Palette_NewMap);
+       Cvar_RegisterVariable(&r_colormap_palette);
+       Palette_Load();
+}
index 53281e0..4a8fc0a 100644 (file)
--- a/palette.h
+++ b/palette.h
@@ -12,6 +12,10 @@ extern unsigned int palette_onlyfullbrights[256];
 extern unsigned int palette_pantsaswhite[256];
 extern unsigned int palette_shirtaswhite[256];
 extern unsigned int palette_transparent[256];
+extern unsigned int palette_pantscolormap[16];
+extern unsigned int palette_shirtcolormap[16];
+extern unsigned int palette_pantsscoreboard[16];
+extern unsigned int palette_shirtscoreboard[16];
 
 // used by hardware gamma functions in vid_* files
 void BuildGammaTable8(float prescale, float gamma, float scale, float base, unsigned char *out, int rampsize);
diff --git a/sbar.c b/sbar.c
index bc14b38..f28fd46 100644 (file)
--- a/sbar.c
+++ b/sbar.c
@@ -935,9 +935,9 @@ void Sbar_DrawFrags (void)
                s = &cl.scores[k];
 
                // draw background
-               c = (unsigned char *)&palette_complete[(s->colors & 0xf0) + 8];
+               c = (unsigned char *)&palette_pantsscoreboard[(s->colors & 0xf0) >> 4];
                DrawQ_Fill (sbar_x + x + 10, sbar_y     - 23, 28, 4, c[0] * (1.0f / 255.0f), c[1] * (1.0f / 255.0f), c[2] * (1.0f / 255.0f), c[3] * (1.0f / 255.0f) * sbar_alpha_fg.value, 0);
-               c = (unsigned char *)&palette_complete[((s->colors & 15)<<4) + 8];
+               c = (unsigned char *)&palette_shirtscoreboard[s->colors & 0xf];
                DrawQ_Fill (sbar_x + x + 10, sbar_y + 4 - 23, 28, 3, c[0] * (1.0f / 255.0f), c[1] * (1.0f / 255.0f), c[2] * (1.0f / 255.0f), c[3] * (1.0f / 255.0f) * sbar_alpha_fg.value, 0);
 
                // draw number
@@ -979,9 +979,9 @@ void Sbar_DrawFace (void)
                s = &cl.scores[cl.viewentity - 1];
                // draw background
                Sbar_DrawPic (112, 0, rsb_teambord);
-               c = (unsigned char *)&palette_complete[(s->colors & 0xf0) + 8];
+               c = (unsigned char *)&palette_pantsscoreboard[(s->colors & 0xf0) >> 4];
                DrawQ_Fill (sbar_x + 113, vid_conheight.integer-SBAR_HEIGHT+3, 22, 9, c[0] * (1.0f / 255.0f), c[1] * (1.0f / 255.0f), c[2] * (1.0f / 255.0f), c[3] * (1.0f / 255.0f) * sbar_alpha_fg.value, 0);
-               c = (unsigned char *)&palette_complete[((s->colors & 15)<<4) + 8];
+               c = (unsigned char *)&palette_shirtscoreboard[s->colors & 0xf];
                DrawQ_Fill (sbar_x + 113, vid_conheight.integer-SBAR_HEIGHT+12, 22, 9, c[0] * (1.0f / 255.0f), c[1] * (1.0f / 255.0f), c[2] * (1.0f / 255.0f), c[3] * (1.0f / 255.0f) * sbar_alpha_fg.value, 0);
 
                // draw number
@@ -1599,9 +1599,14 @@ float Sbar_PrintScoreboardItem(scoreboard_t *s, float x, float y)
                else
                {
                        // draw colors behind score
-                       c = (unsigned char *)&palette_complete[(s->colors & 0xf0) + 8];
+                       //
+                       //
+                       //
+                       //
+                       //
+                       c = (unsigned char *)&palette_pantsscoreboard[(s->colors & 0xf0) >> 4];
                        DrawQ_Fill(x + 14*8, y+1, 40, 3, c[0] * (1.0f / 255.0f), c[1] * (1.0f / 255.0f), c[2] * (1.0f / 255.0f), c[3] * (1.0f / 255.0f) * sbar_alpha_fg.value, 0);
-                       c = (unsigned char *)&palette_complete[((s->colors & 15)<<4) + 8];
+                       c = (unsigned char *)&palette_shirtscoreboard[s->colors & 0xf];
                        DrawQ_Fill(x + 14*8, y+4, 40, 3, c[0] * (1.0f / 255.0f), c[1] * (1.0f / 255.0f), c[2] * (1.0f / 255.0f), c[3] * (1.0f / 255.0f) * sbar_alpha_fg.value, 0);
                        // print the text
                        //DrawQ_String(x, y, va("%c%4i %s", myself ? 13 : ' ', (int) s->frags, s->name), 0, 8, 8, 1, 1, 1, 1 * sbar_alpha_fg.value, 0, NULL, true);
@@ -1623,9 +1628,9 @@ float Sbar_PrintScoreboardItem(scoreboard_t *s, float x, float y)
                else
                {
                        // draw colors behind score
-                       c = (unsigned char *)&palette_complete[(s->colors & 0xf0) + 8];
+                       c = (unsigned char *)&palette_pantsscoreboard[(s->colors & 0xf0) >> 4];
                        DrawQ_Fill(x + 9*8, y+1, 40, 3, c[0] * (1.0f / 255.0f), c[1] * (1.0f / 255.0f), c[2] * (1.0f / 255.0f), c[3] * (1.0f / 255.0f) * sbar_alpha_fg.value, 0);
-                       c = (unsigned char *)&palette_complete[((s->colors & 15)<<4) + 8];
+                       c = (unsigned char *)&palette_shirtscoreboard[s->colors & 0xf];
                        DrawQ_Fill(x + 9*8, y+4, 40, 3, c[0] * (1.0f / 255.0f), c[1] * (1.0f / 255.0f), c[2] * (1.0f / 255.0f), c[3] * (1.0f / 255.0f) * sbar_alpha_fg.value, 0);
                        // print the text
                        //DrawQ_String(x, y, va("%c%4i %s", myself ? 13 : ' ', (int) s->frags, s->name), 0, 8, 8, 1, 1, 1, 1 * sbar_alpha_fg.value, 0, NULL, true);
@@ -1856,7 +1861,7 @@ void Sbar_Score (int margin)
                        for(i = 0; i < teamlines; ++i)
                        {
                                int cindex = teamcolorsort[i]->colors & 15;
-                               unsigned char *c = (unsigned char *)&palette_complete[(cindex << 4) + 8];
+                               unsigned char *c = (unsigned char *)&palette_shirtscoreboard[cindex];
                                float cm = max(max(c[0], c[1]), c[2]);
                                float cr = c[0] / cm;
                                float cg = c[1] / cm;