- parseNumAlphaTabs

This commit is contained in:
Christoph Oelckers 2021-04-13 19:40:43 +02:00
parent 82a0b0502b
commit bb119fa928
2 changed files with 28 additions and 45 deletions

View file

@ -330,6 +330,9 @@ static int32_t defsparser(scriptfile *script)
case T_GLOBALFLAGS:
parseSkip<1>(*script, pos);
break;
case T_UNDEFBLENDTABLERANGE:
parseSkip<2>(*script, pos);
break;
case T_SPRITECOL:
case T_2DCOLIDXRANGE: // NOTE: takes precedence over 2dcol, see InitCustomColors()
parseSkip<3>(*script, pos);
@ -1682,34 +1685,7 @@ static int32_t defsparser(scriptfile *script)
parseBlendTable(*script, pos);
break;
case T_NUMALPHATABS:
{
int32_t value;
if (scriptfile_getnumber(script,&value)) break;
switch (value)
{
case 1: case 3: case 7: case 15: case 31: case 63: case 127:
case 2: case 4: case 8: case 16: case 32: case 64: case 128:
#ifdef USE_OPENGL
for (int32_t a = 1, value2 = value*2 + (value&1); a <= value; ++a)
{
float finv2value = 1.f/(float)value2;
glblend_t * const glb = glblend + a;
*glb = defaultglblend;
glb->def[0].alpha = (float)(value2-a) * finv2value;
glb->def[1].alpha = (float)a * finv2value;
}
fallthrough__;
#endif
case 0:
numalphatabs = value;
break;
default:
pos.Message(MSG_ERROR, "numalphatables: Invalid value");
break;
}
}
parseNumAlphaTabs(*script, pos);
break;
case T_UNDEFBASEPALETTERANGE:
{
@ -1755,22 +1731,6 @@ static int32_t defsparser(scriptfile *script)
paletteloaded &= ~PALETTE_SHADE;
}
break;
case T_UNDEFBLENDTABLERANGE:
{
int32_t id0, id1;
if (scriptfile_getsymbol(script,&id0))
break;
if (scriptfile_getsymbol(script,&id1))
break;
if (id0 > id1 || (unsigned)id0 >= MAXBLENDTABS || (unsigned)id1 >= MAXBLENDTABS)
{
pos.Message(MSG_ERROR, "undefblendtablerange: Invalid range");
break;
}
}
break;
case T_RFFDEFINEID:
parseRffDefineId(*script, pos);
break;

View file

@ -1038,3 +1038,26 @@ void parseBlendTable(FScanner& sc, FScriptPosition& pos)
}
}
}
//===========================================================================
//
// thw same note as for blendtable applies here.
//
//===========================================================================
void parseNumAlphaTabs(FScanner& sc, FScriptPosition& pos)
{
int value;
if (!sc.GetNumber(value)) return;
for (int a = 1, value2 = value * 2 + (value & 1); a <= value; ++a)
{
float finv2value = 1.f / (float)value2;
glblend_t* const glb = glblend + a;
*glb = defaultglblend;
glb->def[0].alpha = (float)(value2 - a) * finv2value;
glb->def[1].alpha = (float)a * finv2value;
}
}