- Improve tag support for xlat: Any combination of arguments can now be tags, and you can

add (or subtract) a constant to them. If you do wish to add a constant, tag must come first.
  e.g. tag+3 is good, but 3+tag will not work. (As a bonus, the parser is simpler, too.)

SVN r3342 (trunk)
This commit is contained in:
Randy Heit 2012-01-22 22:55:20 +00:00
parent d9713669f1
commit f28393263b
4 changed files with 72 additions and 246 deletions

View file

@ -118,11 +118,6 @@ void P_TranslateLineDef (line_t *ld, maplinedef_t *mld)
if (linetrans != NULL && linetrans->special != 0)
{
ld->special = linetrans->special;
ld->args[0] = linetrans->args[0];
ld->args[1] = linetrans->args[1];
ld->args[2] = linetrans->args[2];
ld->args[3] = linetrans->args[3];
ld->args[4] = linetrans->args[4];
ld->flags = flags | ((linetrans->flags & 0x1f) << 9);
if (linetrans->flags & 0x20) ld->flags |= ML_FIRSTSIDEONLY;
@ -134,30 +129,17 @@ void P_TranslateLineDef (line_t *ld, maplinedef_t *mld)
{
ld->activation = SPAC_UseThrough;
}
switch (linetrans->flags & LINETRANS_TAGMASK)
// Set special arguments.
for (int t = 0; t < LINETRANS_MAXARGS; ++t)
{
case LINETRANS_HAS2TAGS: // First two arguments are tags
ld->args[1] = tag;
case LINETRANS_HASTAGAT1: // First argument is a tag
ld->args[0] = tag;
break;
case LINETRANS_HASTAGAT2: // Second argument is a tag
ld->args[1] = tag;
break;
case LINETRANS_HASTAGAT3: // Third argument is a tag
ld->args[2] = tag;
break;
case LINETRANS_HASTAGAT4: // Fourth argument is a tag
ld->args[3] = tag;
break;
case LINETRANS_HASTAGAT5: // Fifth argument is a tag
ld->args[4] = tag;
break;
ld->args[t] = linetrans->args[t];
// Arguments that are tags have the tag's value added to them.
if (linetrans->flags & (1 << (LINETRANS_TAGSHIFT+t)))
{
ld->args[t] += tag;
}
}
if ((ld->flags & ML_SECRET) && ld->activation & (SPAC_Use|SPAC_UseThrough))
{
ld->flags &= ~ML_MONSTERSCANACTIVATE;

View file

@ -67,9 +67,16 @@ FLineFlagTrans LineFlagTranslations[16];
struct SpecialArgs
{
int addflags;
int argcount;
int args[5];
};
struct SpecialArg
{
int arg;
bool bIsTag;
};
struct ListFilter
{
WORD filter;

View file

@ -6,14 +6,8 @@
enum
{
LINETRANS_HASTAGAT1 = (1<<6), // (tag, x, x, x, x)
LINETRANS_HASTAGAT2 = (2<<6), // (x, tag, x, x, x)
LINETRANS_HASTAGAT3 = (3<<6), // (x, x, tag, x, x)
LINETRANS_HASTAGAT4 = (4<<6), // (x, x, x, tag, x)
LINETRANS_HASTAGAT5 = (5<<6), // (x, x, x, x, tag)
LINETRANS_HAS2TAGS = (7<<6), // (tag, tag, x, x, x)
LINETRANS_TAGMASK = (7<<6)
LINETRANS_TAGSHIFT = 24,
LINETRANS_MAXARGS = 5
};
struct FLineTrans

View file

@ -99,228 +99,71 @@ linetype_declaration ::= exp EQUALS exp COMMA SYM(S) LPAREN special_args RPAREN.
Printf ("%s, line %d: %s is undefined\n", context->SourceFile, context->SourceLine, S.sym);
}
%type special_arg {SpecialArg}
special_arg(Z) ::= exp(A).
{
Z.arg = A;
Z.bIsTag = false;
}
special_arg(Z) ::= TAG.
{
Z.arg = 0;
Z.bIsTag = true;
}
special_arg(Z) ::= TAG PLUS exp(A).
{
Z.arg = A;
Z.bIsTag = true;
}
special_arg(Z) ::= TAG MINUS exp(A).
{
Z.arg = -A;
Z.bIsTag = true;
}
%type multi_special_arg {SpecialArgs}
multi_special_arg(Z) ::= special_arg(A).
{
Z.addflags = A.bIsTag << LINETRANS_TAGSHIFT;
Z.argcount = 1;
Z.args[0] = A.arg;
Z.args[1] = 0;
Z.args[2] = 0;
Z.args[3] = 0;
Z.args[4] = 0;
}
multi_special_arg(Z) ::= multi_special_arg(A) COMMA special_arg(B).
{
Z = A;
if (Z.argcount < LINETRANS_MAXARGS)
{
Z.addflags |= B.bIsTag << (LINETRANS_TAGSHIFT + Z.argcount);
Z.args[Z.argcount] = B.arg;
Z.argcount++;
}
else if (Z.argcount++ == LINETRANS_MAXARGS)
{
context->PrintError("Line special has too many arguments\n");
}
}
%type special_args {SpecialArgs}
special_args(Z) ::= . /* empty */
{
Z.addflags = 0;
Z.argcount = 0;
Z.args[0] = 0;
Z.args[1] = 0;
Z.args[2] = 0;
Z.args[3] = 0;
Z.args[4] = 0;
}
special_args(Z) ::= TAG.
special_args(Z) ::= multi_special_arg(A).
{
Z.addflags = LINETRANS_HASTAGAT1;
Z.args[0] = 0;
Z.args[1] = 0;
Z.args[2] = 0;
Z.args[3] = 0;
Z.args[4] = 0;
}
special_args(Z) ::= TAG COMMA exp(B).
{
Z.addflags = LINETRANS_HASTAGAT1;
Z.args[0] = 0;
Z.args[1] = B;
Z.args[2] = 0;
Z.args[3] = 0;
Z.args[4] = 0;
}
special_args(Z) ::= TAG COMMA exp(B) COMMA exp(C).
{
Z.addflags = LINETRANS_HASTAGAT1;
Z.args[0] = 0;
Z.args[1] = B;
Z.args[2] = C;
Z.args[3] = 0;
Z.args[4] = 0;
}
special_args(Z) ::= TAG COMMA exp(B) COMMA exp(C) COMMA exp(D).
{
Z.addflags = LINETRANS_HASTAGAT1;
Z.args[0] = 0;
Z.args[1] = B;
Z.args[2] = C;
Z.args[3] = D;
Z.args[4] = 0;
}
special_args(Z) ::= TAG COMMA exp(B) COMMA exp(C) COMMA exp(D) COMMA exp(E).
{
Z.addflags = LINETRANS_HASTAGAT1;
Z.args[0] = 0;
Z.args[1] = B;
Z.args[2] = C;
Z.args[3] = D;
Z.args[4] = E;
}
special_args(Z) ::= TAG COMMA TAG.
{
Z.addflags = LINETRANS_HAS2TAGS;
Z.args[0] = Z.args[1] = 0;
Z.args[2] = 0;
Z.args[3] = 0;
Z.args[4] = 0;
}
special_args(Z) ::= TAG COMMA TAG COMMA exp(C).
{
Z.addflags = LINETRANS_HAS2TAGS;
Z.args[0] = Z.args[1] = 0;
Z.args[2] = C;
Z.args[3] = 0;
Z.args[4] = 0;
}
special_args(Z) ::= TAG COMMA TAG COMMA exp(C) COMMA exp(D).
{
Z.addflags = LINETRANS_HAS2TAGS;
Z.args[0] = Z.args[1] = 0;
Z.args[2] = C;
Z.args[3] = D;
Z.args[4] = 0;
}
special_args(Z) ::= TAG COMMA TAG COMMA exp(C) COMMA exp(D) COMMA exp(E).
{
Z.addflags = LINETRANS_HAS2TAGS;
Z.args[0] = Z.args[1] = 0;
Z.args[2] = C;
Z.args[3] = D;
Z.args[4] = E;
}
special_args(Z) ::= exp(A).
{
Z.addflags = 0;
Z.args[0] = A;
Z.args[1] = 0;
Z.args[2] = 0;
Z.args[3] = 0;
Z.args[4] = 0;
}
special_args(Z) ::= exp(A) COMMA exp(B).
{
Z.addflags = 0;
Z.args[0] = A;
Z.args[1] = B;
Z.args[2] = 0;
Z.args[3] = 0;
Z.args[4] = 0;
}
special_args(Z) ::= exp(A) COMMA exp(B) COMMA exp(C).
{
Z.addflags = 0;
Z.args[0] = A;
Z.args[1] = B;
Z.args[2] = C;
Z.args[3] = 0;
Z.args[4] = 0;
}
special_args(Z) ::= exp(A) COMMA exp(B) COMMA exp(C) COMMA exp(D).
{
Z.addflags = 0;
Z.args[0] = A;
Z.args[1] = B;
Z.args[2] = C;
Z.args[3] = D;
Z.args[4] = 0;
}
special_args(Z) ::= exp(A) COMMA exp(B) COMMA exp(C) COMMA exp(D) COMMA exp(E).
{
Z.addflags = 0;
Z.args[0] = A;
Z.args[1] = B;
Z.args[2] = C;
Z.args[3] = D;
Z.args[4] = E;
}
special_args(Z) ::= exp(A) COMMA TAG.
{
Z.addflags = LINETRANS_HASTAGAT2;
Z.args[0] = A;
Z.args[1] = 0;
Z.args[2] = 0;
Z.args[3] = 0;
Z.args[4] = 0;
}
special_args(Z) ::= exp(A) COMMA TAG COMMA exp(C).
{
Z.addflags = LINETRANS_HASTAGAT2;
Z.args[0] = A;
Z.args[1] = 0;
Z.args[2] = C;
Z.args[3] = 0;
Z.args[4] = 0;
}
special_args(Z) ::= exp(A) COMMA TAG COMMA exp(C) COMMA exp(D).
{
Z.addflags = LINETRANS_HASTAGAT2;
Z.args[0] = A;
Z.args[1] = 0;
Z.args[2] = C;
Z.args[3] = D;
Z.args[4] = 0;
}
special_args(Z) ::= exp(A) COMMA TAG COMMA exp(C) COMMA exp(D) COMMA exp(E).
{
Z.addflags = LINETRANS_HASTAGAT2;
Z.args[0] = A;
Z.args[1] = 0;
Z.args[2] = C;
Z.args[3] = D;
Z.args[4] = E;
}
special_args(Z) ::= exp(A) COMMA exp(B) COMMA TAG.
{
Z.addflags = LINETRANS_HASTAGAT3;
Z.args[0] = A;
Z.args[1] = B;
Z.args[2] = 0;
Z.args[3] = 0;
Z.args[4] = 0;
}
special_args(Z) ::= exp(A) COMMA exp(B) COMMA TAG COMMA exp(D).
{
Z.addflags = LINETRANS_HASTAGAT3;
Z.args[0] = A;
Z.args[1] = B;
Z.args[2] = 0;
Z.args[3] = D;
Z.args[4] = 0;
}
special_args(Z) ::= exp(A) COMMA exp(B) COMMA TAG COMMA exp(D) COMMA exp(E).
{
Z.addflags = LINETRANS_HASTAGAT3;
Z.args[0] = A;
Z.args[1] = B;
Z.args[2] = 0;
Z.args[3] = D;
Z.args[4] = E;
}
special_args(Z) ::= exp(A) COMMA exp(B) COMMA exp(C) COMMA TAG.
{
Z.addflags = LINETRANS_HASTAGAT4;
Z.args[0] = A;
Z.args[1] = B;
Z.args[2] = C;
Z.args[3] = 0;
Z.args[4] = 0;
}
special_args(Z) ::= exp(A) COMMA exp(B) COMMA exp(C) COMMA TAG COMMA exp(E).
{
Z.addflags = LINETRANS_HASTAGAT4;
Z.args[0] = A;
Z.args[1] = B;
Z.args[2] = C;
Z.args[3] = 0;
Z.args[4] = E;
}
special_args(Z) ::= exp(A) COMMA exp(B) COMMA exp(C) COMMA exp(D) COMMA TAG.
{
Z.addflags = LINETRANS_HASTAGAT5;
Z.args[0] = A;
Z.args[1] = B;
Z.args[2] = C;
Z.args[3] = D;
Z.args[4] = 0;
Z = A;
}
//==========================================================================
@ -463,7 +306,7 @@ list_val(A) ::= exp(B) COLON exp(C).
maxlinespecial_def ::= MAXLINESPECIAL EQUALS exp(mx) SEMICOLON.
{
// Just kill all specials higher than the max.
// If the translator wants to redefine some later, just let it.s
// If the translator wants to redefine some later, just let it.
SimpleLineTranslations.Resize(mx+1);
}