From 7bcd83f0c1c8646cecb5421b13b58d104fad1f97 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 14 Nov 2016 19:35:29 +0100 Subject: [PATCH] - parser for states flags. --- src/resourcefiles/file_zip.cpp | 82 ++++++++++++---------- src/scripting/decorate/thingdef_states.cpp | 17 +++++ src/scripting/thingdef.h | 6 -- src/scripting/zscript/ast.cpp | 1 + src/scripting/zscript/zcc-parse.lemon | 23 ++++++ src/scripting/zscript/zcc_parser.h | 1 + 6 files changed, 87 insertions(+), 43 deletions(-) diff --git a/src/resourcefiles/file_zip.cpp b/src/resourcefiles/file_zip.cpp index 8713fe554..3f4548040 100644 --- a/src/resourcefiles/file_zip.cpp +++ b/src/resourcefiles/file_zip.cpp @@ -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; diff --git a/src/scripting/decorate/thingdef_states.cpp b/src/scripting/decorate/thingdef_states.cpp index c9be2c747..db424ed44 100644 --- a/src/scripting/decorate/thingdef_states.cpp +++ b/src/scripting/decorate/thingdef_states.cpp @@ -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")) { diff --git a/src/scripting/thingdef.h b/src/scripting/thingdef.h index 3ff347ac6..eeea42f87 100644 --- a/src/scripting/thingdef.h +++ b/src/scripting/thingdef.h @@ -63,7 +63,6 @@ class FStateDefinitions FState *laststatebeforelabel; intptr_t lastlabel; TArray StateArray; - uint8_t UseType; static FStateDefine *FindStateLabelInList(TArray &list, FName name, bool create); static FStateLabels *CreateStateLabelList(TArray &statelist); @@ -75,11 +74,6 @@ class FStateDefinitions FState *ResolveGotoLabel(AActor *actor, PClassActor *mytype, char *name); static void FixStatePointers(PClassActor *actor, TArray & list); void ResolveGotoLabels(PClassActor *actor, AActor *defaults, TArray & list); - void SetUseType(int type) - { - UseType = uint8_t(type); - } - public: FStateDefinitions() diff --git a/src/scripting/zscript/ast.cpp b/src/scripting/zscript/ast.cpp index cb0240dea..c24867837 100644 --- a/src/scripting/zscript/ast.cpp +++ b/src/scripting/zscript/ast.cpp @@ -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(); } diff --git a/src/scripting/zscript/zcc-parse.lemon b/src/scripting/zscript/zcc-parse.lemon index 6caef777e..1882aa41c 100644 --- a/src/scripting/zscript/zcc-parse.lemon +++ b/src/scripting/zscript/zcc-parse.lemon @@ -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 diff --git a/src/scripting/zscript/zcc_parser.h b/src/scripting/zscript/zcc_parser.h index ec8bd956a..1a187af82 100644 --- a/src/scripting/zscript/zcc_parser.h +++ b/src/scripting/zscript/zcc_parser.h @@ -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