- parser for states flags.

This commit is contained in:
Christoph Oelckers 2016-11-14 19:35:29 +01:00
parent 384f4fe7ce
commit 7bcd83f0c1
6 changed files with 87 additions and 43 deletions

View file

@ -53,50 +53,58 @@
static bool UncompressZipLump(char *Cache, FileReader *Reader, int Method, int LumpSize, int CompressedSize, int GPFlags)
{
switch (Method)
try
{
case METHOD_STORED:
{
Reader->Read(Cache, LumpSize);
break;
}
switch (Method)
{
case METHOD_STORED:
{
Reader->Read(Cache, LumpSize);
break;
}
case METHOD_DEFLATE:
{
FileReaderZ frz(*Reader, true);
frz.Read(Cache, LumpSize);
break;
}
case METHOD_DEFLATE:
{
FileReaderZ frz(*Reader, true);
frz.Read(Cache, LumpSize);
break;
}
case METHOD_BZIP2:
{
FileReaderBZ2 frz(*Reader);
frz.Read(Cache, LumpSize);
break;
}
case METHOD_BZIP2:
{
FileReaderBZ2 frz(*Reader);
frz.Read(Cache, LumpSize);
break;
}
case METHOD_LZMA:
{
FileReaderLZMA frz(*Reader, LumpSize, true);
frz.Read(Cache, LumpSize);
break;
}
case METHOD_LZMA:
{
FileReaderLZMA frz(*Reader, LumpSize, true);
frz.Read(Cache, LumpSize);
break;
}
case METHOD_IMPLODE:
{
FZipExploder exploder;
exploder.Explode((unsigned char *)Cache, LumpSize, Reader, CompressedSize, GPFlags);
break;
}
case METHOD_IMPLODE:
{
FZipExploder exploder;
exploder.Explode((unsigned char *)Cache, LumpSize, Reader, CompressedSize, GPFlags);
break;
}
case METHOD_SHRINK:
{
ShrinkLoop((unsigned char *)Cache, LumpSize, Reader, CompressedSize);
break;
}
case METHOD_SHRINK:
{
ShrinkLoop((unsigned char *)Cache, LumpSize, Reader, CompressedSize);
break;
}
default:
assert(0);
default:
assert(0);
return false;
}
}
catch (CRecoverableError &err)
{
Printf("%s\n", err.GetMessage());
return false;
}
return true;

View file

@ -144,6 +144,22 @@ void ParseStates(FScanner &sc, PClassActor * actor, AActor * defaults, Baggage &
char lastsprite[5] = "";
FxExpression *ScriptCode;
FArgumentList *args = nullptr;
int flagdef = actor->DefaultStateUsage;
if (sc.CheckString("("))
{
flagdef = 0;
do
{
sc.MustGetString();
if (sc.Compare("Actor")) flagdef |= SUF_ACTOR;
else if (sc.Compare("Overlay")) flagdef |= SUF_OVERLAY;
else if (sc.Compare("Weapon")) flagdef |= SUF_WEAPON;
else if (sc.Compare("Item")) flagdef |= SUF_ITEM;
else sc.ScriptError("Unknown state block qualifier %s", sc.String);
} while (sc.CheckString(","));
sc.MustGetStringName(")");
}
sc.MustGetStringName ("{");
sc.SetEscape(false); // disable escape sequences in the state parser
@ -151,6 +167,7 @@ void ParseStates(FScanner &sc, PClassActor * actor, AActor * defaults, Baggage &
{
ScriptCode = nullptr;
memset(&state,0,sizeof(state));
state.UseFlags = (uint8_t)flagdef;
statestring = ParseStateString(sc);
if (!statestring.CompareNoCase("GOTO"))
{

View file

@ -63,7 +63,6 @@ class FStateDefinitions
FState *laststatebeforelabel;
intptr_t lastlabel;
TArray<FState> StateArray;
uint8_t UseType;
static FStateDefine *FindStateLabelInList(TArray<FStateDefine> &list, FName name, bool create);
static FStateLabels *CreateStateLabelList(TArray<FStateDefine> &statelist);
@ -75,11 +74,6 @@ class FStateDefinitions
FState *ResolveGotoLabel(AActor *actor, PClassActor *mytype, char *name);
static void FixStatePointers(PClassActor *actor, TArray<FStateDefine> & list);
void ResolveGotoLabels(PClassActor *actor, AActor *defaults, TArray<FStateDefine> & list);
void SetUseType(int type)
{
UseType = uint8_t(type);
}
public:
FStateDefinitions()

View file

@ -358,6 +358,7 @@ static void PrintStates(FLispString &out, ZCC_TreeNode *node)
ZCC_States *snode = (ZCC_States *)node;
out.Break();
out.Open("states");
PrintNodes(out, snode->Flags, false, true);
PrintNodes(out, snode->Body, false, true);
out.Close();
}

View file

@ -418,14 +418,37 @@ enumerator(X) ::= IDENTIFIER(A) EQ expr(B). /* Expression must be constant. */
%type state_call_params {ZCC_FuncParm *}
%type state_opts {StateOpts}
%type states_opts { ZCC_Identifier *}
%type states_opt { ZCC_Identifier *}
states_def(X) ::= STATES(T) scanner_mode LBRACE states_body(A) RBRACE.
states_def(X) ::= STATES(T) states_opts(B) scanner_mode LBRACE states_body(A) RBRACE.
{
NEW_AST_NODE(States,def,T);
def->Flags = B;
def->Body = A;
X = def;
}
states_opts(X) ::= . { X = nullptr; }
states_opts(X) ::= LPAREN states_opt(A) RPAREN. { X = A; /*X-overwrites-A*/ }
states_opt(X) ::= IDENTIFIER(A).
{
NEW_AST_NODE(Identifier,id,A);
id->Id = A.Name();
X = id;
}
states_opt(X) ::= states_opt(A) COMMA IDENTIFIER(B).
{
NEW_AST_NODE(Identifier,id,B);
id->Id = B.Name();
X = A; /*X-overwrites-A*/
X->AppendSibling(id);
}
/* We use a special scanner mode to allow for sprite names and frame characters
* to not be quoted even if they contain special characters. The scanner_mode
* nonterminal is used to enter this mode. The scanner automatically leaves it

View file

@ -228,6 +228,7 @@ struct ZCC_EnumTerminator : ZCC_TreeNode
struct ZCC_States : ZCC_TreeNode
{
struct ZCC_StatePart *Body;
ZCC_Identifier *Flags;
};
struct ZCC_StatePart : ZCC_TreeNode