mirror of
https://github.com/ZDoom/raze-gles.git
synced 2024-12-27 04:00:42 +00:00
- parseMakePalookup
This commit is contained in:
parent
6fb09f36c7
commit
276fd19462
2 changed files with 75 additions and 106 deletions
|
@ -1032,112 +1032,8 @@ static int32_t defsparser(scriptfile *script)
|
|||
parseTint(*script, pos);
|
||||
break;
|
||||
case T_MAKEPALOOKUP:
|
||||
{
|
||||
int32_t red=0, green=0, blue=0, pal=-1;
|
||||
int32_t havepal=0, remappal=0;
|
||||
int32_t nofloorpal=-1;
|
||||
FScanner::SavedPos endtextptr;
|
||||
|
||||
static const tokenlist palookuptokens[] =
|
||||
{
|
||||
{ "pal", T_PAL },
|
||||
{ "red", T_RED }, { "r", T_RED },
|
||||
{ "green", T_GREEN }, { "g", T_GREEN },
|
||||
{ "blue", T_BLUE }, { "b", T_BLUE },
|
||||
{ "remappal", T_REMAPPAL },
|
||||
{ "remapself", T_REMAPSELF },
|
||||
{ "nofloorpal", T_NOFLOORPAL },
|
||||
};
|
||||
|
||||
enum {
|
||||
HAVE_PAL = 1,
|
||||
HAVE_REMAPPAL = 2,
|
||||
HAVE_REMAPSELF = 4,
|
||||
|
||||
HAVEPAL_SPECIAL = HAVE_REMAPPAL | HAVE_REMAPSELF,
|
||||
HAVEPAL_ERROR = 8,
|
||||
};
|
||||
|
||||
if (scriptfile_getbraces(script,&endtextptr)) break;
|
||||
while (!scriptfile_endofblock(script, endtextptr))
|
||||
{
|
||||
switch (getatoken(script, palookuptokens, countof(palookuptokens)))
|
||||
{
|
||||
case T_PAL:
|
||||
scriptfile_getsymbol(script, &pal);
|
||||
havepal |= HAVE_PAL;
|
||||
break;
|
||||
case T_RED:
|
||||
scriptfile_getnumber(script,&red);
|
||||
red = clamp(red, 0, 63);
|
||||
break;
|
||||
case T_GREEN:
|
||||
scriptfile_getnumber(script,&green);
|
||||
green = clamp(green, 0, 63);
|
||||
break;
|
||||
case T_BLUE:
|
||||
scriptfile_getnumber(script,&blue);
|
||||
blue = clamp(blue, 0, 63);
|
||||
break;
|
||||
case T_REMAPPAL:
|
||||
scriptfile_getsymbol(script,&remappal);
|
||||
if (havepal & HAVEPAL_SPECIAL)
|
||||
havepal |= HAVEPAL_ERROR;
|
||||
havepal |= HAVE_REMAPPAL;
|
||||
break;
|
||||
case T_REMAPSELF:
|
||||
if (havepal & HAVEPAL_SPECIAL)
|
||||
havepal |= HAVEPAL_ERROR;
|
||||
havepal |= HAVE_REMAPSELF;
|
||||
break;
|
||||
case T_NOFLOORPAL:
|
||||
scriptfile_getsymbol(script, &nofloorpal);
|
||||
nofloorpal = clamp(nofloorpal, 0, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
char msgend[BMAX_PATH+64];
|
||||
|
||||
sprintf(msgend, "for palookup definition");
|
||||
|
||||
if ((havepal & HAVE_PAL)==0)
|
||||
{
|
||||
pos.Message(MSG_ERROR, "missing 'palette number' %s\n", msgend);
|
||||
break;
|
||||
}
|
||||
else if (pal==0 || (unsigned)pal >= MAXPALOOKUPS-RESERVEDPALS)
|
||||
{
|
||||
pos.Message(MSG_ERROR, "'palette number' out of range (1 .. %d) %s\n",
|
||||
MAXPALOOKUPS-RESERVEDPALS-1, msgend);
|
||||
break;
|
||||
}
|
||||
|
||||
if (havepal & HAVEPAL_ERROR)
|
||||
{
|
||||
// will also disallow multiple remappals or remapselfs
|
||||
pos.Message(MSG_ERROR, "must have exactly one of either 'remappal' or 'remapself' %s\n", msgend);
|
||||
break;
|
||||
}
|
||||
else if ((havepal & HAVE_REMAPPAL
|
||||
&& (unsigned)remappal >= MAXPALOOKUPS-RESERVEDPALS))
|
||||
{
|
||||
pos.Message(MSG_ERROR, "'remap palette number' out of range (max=%d) %s\n",
|
||||
MAXPALOOKUPS-RESERVEDPALS-1, msgend);
|
||||
break;
|
||||
}
|
||||
|
||||
if (havepal & HAVE_REMAPSELF)
|
||||
remappal = pal;
|
||||
}
|
||||
|
||||
// NOTE: all palookups are initialized, i.e. non-NULL!
|
||||
// NOTE2: aliasing (pal==remappal) is OK
|
||||
lookups.makeTable(pal, lookups.getTable(remappal), red<<2, green<<2, blue<<2,
|
||||
remappal==0 ? 1 : (nofloorpal == -1 ? lookups.tables[remappal].noFloorPal : nofloorpal));
|
||||
}
|
||||
break;
|
||||
parseMakePalookup(*script, pos);
|
||||
break;
|
||||
case T_TEXTURE:
|
||||
parseTexture(*script, pos);
|
||||
break;
|
||||
|
|
|
@ -1263,3 +1263,76 @@ void parsePalookup(FScanner& sc, FScriptPosition& pos)
|
|||
paletteloaded |= PALETTE_SHADE;
|
||||
}
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
//
|
||||
//
|
||||
//===========================================================================
|
||||
|
||||
void parseMakePalookup(FScanner& sc, FScriptPosition& pos)
|
||||
{
|
||||
FScanner::SavedPos blockend;
|
||||
int red = 0, green = 0, blue = 0, pal = -1;
|
||||
int havepal = 0, remappal = 0;
|
||||
int nofloorpal = -1;
|
||||
|
||||
if (sc.StartBraces(&blockend)) return;
|
||||
|
||||
enum {
|
||||
HAVE_PAL = 1,
|
||||
HAVE_REMAPPAL = 2,
|
||||
HAVE_REMAPSELF = 4,
|
||||
|
||||
HAVEPAL_SPECIAL = HAVE_REMAPPAL | HAVE_REMAPSELF,
|
||||
HAVEPAL_ERROR = 8,
|
||||
};
|
||||
|
||||
while (!sc.FoundEndBrace(blockend))
|
||||
{
|
||||
sc.MustGetString();
|
||||
if (sc.Compare({ "r", "red" })) sc.GetNumber(red);
|
||||
else if (sc.Compare({ "g", "green" })) sc.GetNumber(green);
|
||||
else if (sc.Compare({ "b", "blue" })) sc.GetNumber(blue);
|
||||
else if (sc.Compare("remappal"))
|
||||
{
|
||||
sc.GetNumber(remappal, true);
|
||||
if (havepal & HAVEPAL_SPECIAL) havepal |= HAVEPAL_ERROR;
|
||||
havepal |= HAVE_REMAPPAL;
|
||||
}
|
||||
else if (sc.Compare("remapself"))
|
||||
{
|
||||
if (havepal & HAVEPAL_SPECIAL) havepal |= HAVEPAL_ERROR;
|
||||
havepal |= HAVE_REMAPSELF;
|
||||
}
|
||||
else if (sc.Compare("nofloorpal")) sc.GetNumber(nofloorpal, true);
|
||||
else if (sc.Compare("pal")) sc.GetNumber(pal, true);
|
||||
}
|
||||
red = clamp(red, 0, 63);
|
||||
green = clamp(green, 0, 63);
|
||||
blue = clamp(blue, 0, 63);
|
||||
|
||||
if ((havepal & HAVE_PAL) == 0)
|
||||
{
|
||||
pos.Message(MSG_ERROR, "makepalookup: missing 'palette number'");
|
||||
}
|
||||
else if (pal == 0 || (unsigned)pal >= MAXPALOOKUPS - RESERVEDPALS)
|
||||
{
|
||||
pos.Message(MSG_ERROR, "makepalookup: 'palette number' %d out of range (1 .. %d)\n", pal, MAXPALOOKUPS - RESERVEDPALS - 1);
|
||||
}
|
||||
else if (havepal & HAVEPAL_ERROR)
|
||||
{
|
||||
// will also disallow multiple remappals or remapselfs
|
||||
pos.Message(MSG_ERROR, "makepalookup: must have exactly one of either 'remappal' or 'remapself'\n");
|
||||
}
|
||||
else if ((havepal & HAVE_REMAPPAL && (unsigned)remappal >= MAXPALOOKUPS - RESERVEDPALS))
|
||||
{
|
||||
pos.Message(MSG_ERROR, "makepalookup: 'remap palette number' %d out of range (max=%d)\n", pal, MAXPALOOKUPS - RESERVEDPALS - 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (havepal & HAVE_REMAPSELF) remappal = pal;
|
||||
lookups.makeTable(pal, lookups.getTable(remappal), red << 2, green << 2, blue << 2,
|
||||
remappal == 0 ? 1 : (nofloorpal == -1 ? lookups.tables[remappal].noFloorPal : nofloorpal));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue