Make makepalookup() accept NULL for 'remapbuf', meaning "use identity mapping".

Also,
 - use this in game.c and astub.c palookup loading code
 - when makepalookup() is passed a 0 palnum, return early.  This means that
   'fogpal' will silently fail when attempting to change pal 0.
 - in 'makepalookup' DEF command, error out if passed a pal of 0.

git-svn-id: https://svn.eduke32.com/eduke32@2569 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
helixhorned 2012-03-29 21:17:03 +00:00
parent a7eb29027f
commit 0be9b7e568
4 changed files with 29 additions and 31 deletions

View file

@ -342,8 +342,7 @@ static int32_t defsparser(scriptfile *script)
break; break;
case T_FOGPAL: case T_FOGPAL:
{ {
int32_t p,r,g,b,j; int32_t p,r,g,b;
char tempbuf[256];
if (scriptfile_getnumber(script,&p)) break; if (scriptfile_getnumber(script,&p)) break;
if (scriptfile_getnumber(script,&r)) break; if (scriptfile_getnumber(script,&r)) break;
@ -354,9 +353,7 @@ static int32_t defsparser(scriptfile *script)
g = clamp(g, 0, 63); g = clamp(g, 0, 63);
b = clamp(b, 0, 63); b = clamp(b, 0, 63);
for (j = 0; j < 256; j++) makepalookup(p, NULL, r, g, b, 1);
tempbuf[j] = j;
makepalookup(p, tempbuf, r, g, b, 1);
} }
break; break;
case T_LOADGRP: case T_LOADGRP:
@ -1655,9 +1652,9 @@ static int32_t defsparser(scriptfile *script)
initprintf("Error: missing 'palette number' %s\n", msgend); initprintf("Error: missing 'palette number' %s\n", msgend);
break; break;
} }
else if ((unsigned)pal >= MAXPALOOKUPS-RESERVEDPALS) else if (pal==0 || (unsigned)pal >= MAXPALOOKUPS-RESERVEDPALS)
{ {
initprintf("Error: 'palette number' out of range (max=%d) %s\n", initprintf("Error: 'palette number' out of range (1 .. %d) %s\n",
MAXPALOOKUPS-RESERVEDPALS-1, msgend); MAXPALOOKUPS-RESERVEDPALS-1, msgend);
break; break;
} }

View file

@ -13414,11 +13414,23 @@ void makepalookup(int32_t palnum, const char *remapbuf, int8_t r, int8_t g, int8
const char *ptr; const char *ptr;
char *ptr2; char *ptr2;
if (paletteloaded == 0) return; static char idmap[256] = {1};
if ((unsigned)palnum >= MAXPALOOKUPS) if (paletteloaded == 0)
return; return;
if (palnum==0 || (unsigned)palnum >= MAXPALOOKUPS)
return;
if (remapbuf==NULL)
{
if (idmap[0]==1) // init identity map
for (i=0; i<256; i++)
idmap[i] = i;
remapbuf = idmap;
}
if (palookup[palnum] == NULL) if (palookup[palnum] == NULL)
{ {
//Allocate palookup buffer //Allocate palookup buffer

View file

@ -2975,11 +2975,8 @@ static void ReadPaletteTable(void)
int32_t i,j,fp; int32_t i,j,fp;
char lookup_num; char lookup_num;
for (j = 0; j < 256; j++)
tempbuf[j] = j;
for (i=1; i<MAXPALOOKUPS; i++) for (i=1; i<MAXPALOOKUPS; i++)
makepalookup(i,tempbuf,0,0,0,1); makepalookup(i,NULL,0,0,0,1);
if ((fp=kopen4load("lookup.dat",0)) == -1) if ((fp=kopen4load("lookup.dat",0)) == -1)
{ {
@ -3001,10 +2998,10 @@ static void ReadPaletteTable(void)
tempbuf[j] = j; tempbuf[j] = j;
num_tables++; num_tables++;
makepalookup(num_tables, tempbuf, 15, 15, 15, 1); makepalookup(num_tables, NULL, 15, 15, 15, 1);
makepalookup(num_tables + 1, tempbuf, 15, 0, 0, 1); makepalookup(num_tables + 1, NULL, 15, 0, 0, 1);
makepalookup(num_tables + 2, tempbuf, 0, 15, 0, 1); makepalookup(num_tables + 2, NULL, 0, 15, 0, 1);
makepalookup(num_tables + 3, tempbuf, 0, 0, 15, 1); makepalookup(num_tables + 3, NULL, 0, 0, 15, 1);
kread(fp,WATERpalette,768); kread(fp,WATERpalette,768);
kread(fp,SLIMEpalette,768); kread(fp,SLIMEpalette,768);

View file

@ -2579,10 +2579,7 @@ void G_SetCrosshairColor(int32_t r, int32_t g, int32_t b)
} }
while (--ii); while (--ii);
for (i = 255; i >= 0; i--) makepalookup(CROSSHAIR_PAL, NULL, CrosshairColors.r>>2, CrosshairColors.g>>2, CrosshairColors.b>>2,1);
tempbuf[i] = i;
makepalookup(CROSSHAIR_PAL,tempbuf,CrosshairColors.r>>2, CrosshairColors.g>>2, CrosshairColors.b>>2,1);
#ifdef USE_OPENGL #ifdef USE_OPENGL
// XXX: this makes us also load all hightile textures tinted with the crosshair color! // XXX: this makes us also load all hightile textures tinted with the crosshair color!
@ -9457,11 +9454,8 @@ static void G_LoadExtraPalettes(void)
// g_numRealPalettes = ((g_numRealPalettes * 0x80200802ULL) & 0x0884422110ULL) * 0x0101010101ULL >> 32; // g_numRealPalettes = ((g_numRealPalettes * 0x80200802ULL) & 0x0884422110ULL) * 0x0101010101ULL >> 32;
#endif #endif
for (j = 0; j < 256; j++)
tempbuf[j] = j;
for (j=g_numRealPalettes+1; j<MAXPALOOKUPS; j++) for (j=g_numRealPalettes+1; j<MAXPALOOKUPS; j++)
makepalookup(j,tempbuf,0,0,0,1); makepalookup(j, NULL ,0,0,0, 1);
for (j=g_numRealPalettes-1; j>=0; j--) for (j=g_numRealPalettes-1; j>=0; j--)
{ {
@ -9472,13 +9466,11 @@ static void G_LoadExtraPalettes(void)
makepalookup(look_pos, tempbuf, 0,0,0, 1); makepalookup(look_pos, tempbuf, 0,0,0, 1);
} }
for (j = 255; j>=0; j--)
tempbuf[j] = j;
g_numRealPalettes++; g_numRealPalettes++;
makepalookup(g_numRealPalettes, tempbuf, 15, 15, 15, 1); makepalookup(g_numRealPalettes, NULL, 15, 15, 15, 1);
makepalookup(g_numRealPalettes + 1, tempbuf, 15, 0, 0, 1); makepalookup(g_numRealPalettes + 1, NULL, 15, 0, 0, 1);
makepalookup(g_numRealPalettes + 2, tempbuf, 0, 15, 0, 1); makepalookup(g_numRealPalettes + 2, NULL, 0, 15, 0, 1);
makepalookup(g_numRealPalettes + 3, tempbuf, 0, 0, 15, 1); makepalookup(g_numRealPalettes + 3, NULL, 0, 0, 15, 1);
kread(fp,&water_pal[0],768); kread(fp,&water_pal[0],768);
kread(fp,&slime_pal[0],768); kread(fp,&slime_pal[0],768);