diff --git a/CMakeLists.txt b/CMakeLists.txt index dec2015a2..85349d888 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -121,7 +121,7 @@ if( MSVC ) set( ALL_C_FLAGS "/GF /Gy /GR-" ) if( CMAKE_SIZEOF_VOID_P MATCHES "4") - # SSE2 option (mostly to switch it off in VC2012 and later where it's the default + # SSE2 option (to allow x87 in 32 bit and disallow extended feature sets which have not yet been checked for precision) option (ZDOOM_USE_SSE2 "Use SSE2 instruction set") if (ZDOOM_USE_SSE2) set( ALL_C_FLAGS "${ALL_C_FLAGS} /arch:SSE2") @@ -131,6 +131,8 @@ if( MSVC ) set( ALL_C_FLAGS "${ALL_C_FLAGS} /arch:IA32") endif () endif () + else() + set( ALL_C_FLAGS "${ALL_C_FLAGS} /arch:SSE2") endif() # Avoid CRT DLL dependancies in release builds, optionally generate assembly output for checking crash locations. diff --git a/src/portal.cpp b/src/portal.cpp index 49a1592a3..6f0baeaea 100644 --- a/src/portal.cpp +++ b/src/portal.cpp @@ -224,6 +224,23 @@ static line_t *FindDestination(line_t *src, int tag) return NULL; } + +//============================================================================ +// +// +// +//============================================================================ + +static void SetRotation(FLinePortal *port) +{ + line_t *dst = port->mDestination; + line_t *line = port->mOrigin; + double angle = atan2(dst->dy, dst->dx) - atan2(line->dy, line->dx) + M_PI; + port->mSinRot = FLOAT2FIXED(sin(angle)); + port->mCosRot = FLOAT2FIXED(cos(angle)); + port->mAngleDiff = RAD2ANGLE(angle); +} + //============================================================================ // // Spawns a single line portal @@ -270,12 +287,7 @@ void P_SpawnLinePortal(line_t* line) // Get the angle between the two linedefs, for rotating // orientation and velocity. Rotate 180 degrees, and flip // the position across the exit linedef, if reversed. - - double angle = atan2(dst->dy, dst->dx) - atan2(line->dy, line->dx) + M_PI; - port->mSinRot = FLOAT2FIXED(sin(angle)); - port->mCosRot = FLOAT2FIXED(cos(angle)); - port->mAngleDiff = RAD2ANGLE(angle); - + SetRotation(port); } else if (line->args[2] == PORTT_LINKEDEE && line->args[0] == 0) { @@ -296,6 +308,7 @@ void P_SpawnLinePortal(line_t* line) port->mType = PORTT_LINKED; port->mAlign = PORG_ABSOLUTE; port->mDefFlags = PORTF_TYPEINTERACTIVE; + SetRotation(port); // we need to create the backlink here, too. lines[i].portalindex = linePortals.Reserve(1); @@ -308,6 +321,7 @@ void P_SpawnLinePortal(line_t* line) port->mAlign = PORG_ABSOLUTE; port->mDefFlags = PORTF_TYPEINTERACTIVE; + SetRotation(port); } } } @@ -427,9 +441,10 @@ static bool ChangePortalLine(line_t *line, int destid) else { port->mFlags = port->mDefFlags; - portd->mFlags = portd->mDefFlags; } + SetRotation(portd); } + SetRotation(port); return true; } diff --git a/src/resourcefiles/file_wad.cpp b/src/resourcefiles/file_wad.cpp index 0bdc0a736..0732d4c11 100644 --- a/src/resourcefiles/file_wad.cpp +++ b/src/resourcefiles/file_wad.cpp @@ -39,6 +39,7 @@ #include "v_text.h" #include "w_wad.h" #include "gi.h" +#include "i_system.h" // Console Doom LZSS wrapper. class FileReaderLZSS : public FileReaderBase @@ -343,6 +344,12 @@ bool FWadFile::Open(bool quiet) NumLumps = BigLong(header.NumLumps); InfoTableOfs = BigLong(header.InfoTableOfs); isBigEndian = true; + + // Check again to detect broken wads + if (InfoTableOfs + NumLumps*sizeof(wadlump_t) > (unsigned)wadSize) + { + I_Error("Cannot load broken WAD file %s\n", Filename); + } } wadlump_t *fileinfo = new wadlump_t[NumLumps]; diff --git a/src/sc_man.cpp b/src/sc_man.cpp index 9c65ddc66..50ec1214e 100644 --- a/src/sc_man.cpp +++ b/src/sc_man.cpp @@ -120,6 +120,7 @@ FScanner &FScanner::operator=(const FScanner &other) CMode = other.CMode; Escape = other.Escape; StateMode = other.StateMode; + StateOptions = other.StateOptions; // Copy public members if (other.String == other.StringBuffer) @@ -277,6 +278,7 @@ void FScanner::PrepareScript () CMode = false; Escape = true; StateMode = 0; + StateOptions = false; StringBuffer[0] = '\0'; BigStringBuffer = ""; } @@ -409,15 +411,19 @@ void FScanner::SetEscape (bool esc) // * ; // * } - Automatically exits state mode after it's seen. // -// Quoted strings are returned as TOK_NonWhitespace, minus the quotes. In -// addition, any two consecutive sequences of TOK_NonWhitespace also exit -// state mode. +// Quoted strings are returned as TOK_NonWhitespace, minus the quotes. Once +// two consecutive sequences of TOK_NonWhitespace have been encountered +// (which would be the state's sprite and frame specifiers), nearly normal +// processing resumes, with the exception that various identifiers +// used for state options will be returned as tokens and not identifiers. +// This ends once a ';' or '{' character is encountered. // //========================================================================== void FScanner::SetStateMode(bool stately) { StateMode = stately ? 2 : 0; + StateOptions = stately; } //========================================================================== diff --git a/src/sc_man.h b/src/sc_man.h index 04de9539f..b1231e547 100644 --- a/src/sc_man.h +++ b/src/sc_man.h @@ -28,6 +28,7 @@ public: void SetCMode(bool cmode); void SetEscape(bool esc); void SetStateMode(bool stately); + void DisableStateOptions(); const SavedPos SavePos(); void RestorePos(const SavedPos &pos); @@ -99,6 +100,7 @@ protected: int LastGotLine; bool CMode; BYTE StateMode; + bool StateOptions; bool Escape; }; diff --git a/src/sc_man_scanner.re b/src/sc_man_scanner.re index ae322488e..7e82f19c1 100644 --- a/src/sc_man_scanner.re +++ b/src/sc_man_scanner.re @@ -49,7 +49,7 @@ std2: TOK2 = (NWS\STOP1); TOKC2 = (NWS\STOPC); */ -#define RET(x) TokenType = x; goto normal_token; +#define RET(x) TokenType = (x); goto normal_token; if (tokens && StateMode != 0) { /*!re2c @@ -63,10 +63,10 @@ std2: 'wait' { RET(TK_Wait); } 'fail' { RET(TK_Fail); } 'loop' { RET(TK_Loop); } - 'goto' { StateMode = 0; RET(TK_Goto); } + 'goto' { StateMode = 0; StateOptions = false; RET(TK_Goto); } ":" { RET(':'); } ";" { RET(';'); } - "}" { StateMode = 0; RET('}'); } + "}" { StateMode = 0; StateOptions = false; RET('}'); } WSP+ { goto std1; } "\n" { goto newline; } @@ -181,6 +181,15 @@ std2: 'action' { RET(TK_Action); } 'readonly' { RET(TK_ReadOnly); } + /* Actor state options */ + 'bright' { RET(StateOptions ? TK_Bright : TK_Identifier); } + 'fast' { RET(StateOptions ? TK_Fast : TK_Identifier); } + 'slow' { RET(StateOptions ? TK_Slow : TK_Identifier); } + 'nodelay' { RET(StateOptions ? TK_NoDelay : TK_Identifier); } + 'canraise' { RET(StateOptions ? TK_CanRaise : TK_Identifier); } + 'offset' { RET(StateOptions ? TK_Offset : TK_Identifier); } + 'light' { RET(StateOptions ? TK_Light : TK_Identifier); } + /* other DECORATE top level keywords */ '#include' { RET(TK_Include); } 'fixed_t' { RET(TK_Fixed_t); } @@ -228,8 +237,8 @@ std2: "<>=" { RET(TK_LtGtEq); } "**" { RET(TK_MulMul); } "::" { RET(TK_ColonColon); } - ";" { RET(';'); } - "{" { RET('{'); } + ";" { StateOptions = false; RET(';'); } + "{" { StateOptions = false; RET('{'); } "}" { RET('}'); } "," { RET(','); } ":" { RET(':'); } diff --git a/src/sc_man_tokens.h b/src/sc_man_tokens.h index 49444c7fa..7fda91330 100644 --- a/src/sc_man_tokens.h +++ b/src/sc_man_tokens.h @@ -129,4 +129,12 @@ xx(TK_Wait, "'wait'") xx(TK_Meta, "'meta'") xx(TK_Deprecated, "'deprecated'") xx(TK_ReadOnly, "'readonly'") + +xx(TK_CanRaise, "'canraise'") +xx(TK_Fast, "'fast'") +xx(TK_Light, "'light'") +xx(TK_NoDelay, "'nodelay'") +xx(TK_Offset, "'offset'") +xx(TK_Slow, "'slow'") +xx(TK_Bright, "'bright'") #undef xx diff --git a/src/zscript/ast.cpp b/src/zscript/ast.cpp index 94d8de511..a59a656af 100644 --- a/src/zscript/ast.cpp +++ b/src/zscript/ast.cpp @@ -377,10 +377,11 @@ static void PrintStateLine(FLispString &out, ZCC_TreeNode *node) ZCC_StateLine *snode = (ZCC_StateLine *)node; out.Open("state-line"); out.Add(snode->Sprite, 4); - if (snode->bBright) - { - out.Add("bright", 6); - } + if (snode->bNoDelay) out.Add("nodelay", 7); + if (snode->bBright) out.Add("bright", 6); + if (snode->bFast) out.Add("fast", 4); + if (snode->bSlow) out.Add("slow", 4); + if (snode->bCanRaise) out.Add("canraise", 8); out.Add(*(snode->Frames)); PrintNodes(out, snode->Offset); PrintNodes(out, snode->Action, false); diff --git a/src/zscript/zcc-parse.lemon b/src/zscript/zcc-parse.lemon index 2b0ca7633..1e574299f 100644 --- a/src/zscript/zcc-parse.lemon +++ b/src/zscript/zcc-parse.lemon @@ -41,6 +41,19 @@ static void SetNodeLine(ZCC_TreeNode *name, int line) struct StateOpts { ZCC_Expression *Offset; bool Bright; + bool Fast; + bool Slow; + bool NoDelay; + bool CanRaise; + + void Zero() { + Offset = NULL; + Bright = false; + Fast = false; + Slow = false; + NoDelay = false; + CanRaise = false; + } }; struct VarOrFun @@ -433,15 +446,23 @@ state_line(X) ::= NWS(A) NWS(B) expr state_opts(C) state_action(D). } line->Frames = stat->Strings.Alloc(FName(B.Name()).GetChars()); line->bBright = C.Bright; + line->bFast = C.Fast; + line->bSlow = C.Slow; + line->bNoDelay = C.NoDelay; + line->bCanRaise = C.CanRaise; line->Offset = C.Offset; line->Action = D; X = line; } -state_opts(X) ::= . { StateOpts opts; opts.Offset = NULL; opts.Bright = false; X = opts; } +state_opts(X) ::= . { StateOpts opts; opts.Zero(); X = opts; } state_opts(X) ::= state_opts(A) BRIGHT. { A.Bright = true; X = A; } +state_opts(X) ::= state_opts(A) FAST. { A.Fast = true; X = A; } +state_opts(X) ::= state_opts(A) SLOW. { A.Slow = true; X = A; } +state_opts(X) ::= state_opts(A) NODELAY. { A.NoDelay = true; X = A; } +state_opts(X) ::= state_opts(A) CANRAISE. { A.CanRaise = true; X = A; } state_opts(X) ::= state_opts(A) OFFSET LPAREN expr(B) COMMA expr(C) RPAREN. { A.Offset = B; B->AppendSibling(C); X = A; } -state_opts(X) ::= state_opts(A) LIGHT LPAREN light_list RPAREN. { X = A; } +state_opts(X) ::= state_opts(A) LIGHT LPAREN light_list RPAREN. { X = A; } ///FIXME: GZDoom would want to know this light_list ::= STRCONST. light_list ::= light_list COMMA STRCONST. diff --git a/src/zscript/zcc_expr.cpp b/src/zscript/zcc_expr.cpp index 69a25970b..644a122a5 100644 --- a/src/zscript/zcc_expr.cpp +++ b/src/zscript/zcc_expr.cpp @@ -33,6 +33,27 @@ struct OpProto2 EvalConst2op EvalConst; }; +static struct FreeOpInfoProtos +{ + ~FreeOpInfoProtos() + { + for (size_t i = 0; i < countof(ZCC_OpInfo); ++i) + { + ZCC_OpInfo[i].FreeAllProtos(); + } + } +} ProtoFreeer; + +void ZCC_OpInfoType::FreeAllProtos() +{ + for (ZCC_OpProto *proto = Protos, *next = NULL; proto != NULL; proto = next) + { + next = proto->Next; + delete proto; + } + Protos = NULL; +} + void ZCC_OpInfoType::AddProto(PType *res, PType *optype, EvalConst1op evalconst) { ZCC_OpProto *proto = new ZCC_OpProto(res, optype, NULL); diff --git a/src/zscript/zcc_parser.cpp b/src/zscript/zcc_parser.cpp index b8e7f0ea0..2b914d033 100644 --- a/src/zscript/zcc_parser.cpp +++ b/src/zscript/zcc_parser.cpp @@ -147,6 +147,14 @@ static void InitTokenMap() TOKENDEF (TK_FloatConst, ZCC_FLOATCONST); TOKENDEF (TK_NonWhitespace, ZCC_NWS); + TOKENDEF (TK_Bright, ZCC_BRIGHT); + TOKENDEF (TK_Slow, ZCC_SLOW); + TOKENDEF (TK_Fast, ZCC_FAST); + TOKENDEF (TK_NoDelay, ZCC_NODELAY); + TOKENDEF (TK_Offset, ZCC_OFFSET); + TOKENDEF (TK_CanRaise, ZCC_CANRAISE); + TOKENDEF (TK_Light, ZCC_CANRAISE); + ZCC_InitOperators(); ZCC_InitConversions(); } @@ -194,43 +202,44 @@ static void DoParse(const char *filename) while (sc.GetToken()) { value.SourceLoc = sc.GetMessageLine(); - if (sc.TokenType == TK_StringConst) + switch (sc.TokenType) { + case TK_StringConst: value.String = state.Strings.Alloc(sc.String, sc.StringLen); tokentype = ZCC_STRCONST; - } - else if (sc.TokenType == TK_NameConst) - { + break; + + case TK_NameConst: value.Int = sc.Name; tokentype = ZCC_NAMECONST; - } - else if (sc.TokenType == TK_IntConst) - { + break; + + case TK_IntConst: value.Int = sc.Number; tokentype = ZCC_INTCONST; - } - else if (sc.TokenType == TK_UIntConst) - { + break; + + case TK_UIntConst: value.Int = sc.Number; tokentype = ZCC_UINTCONST; - } - else if (sc.TokenType == TK_FloatConst) - { + break; + + case TK_FloatConst: value.Float = sc.Float; tokentype = ZCC_FLOATCONST; - } - else if (sc.TokenType == TK_Identifier) - { + break; + + case TK_Identifier: value.Int = FName(sc.String); tokentype = ZCC_IDENTIFIER; - } - else if (sc.TokenType == TK_NonWhitespace) - { + break; + + case TK_NonWhitespace: value.Int = FName(sc.String); tokentype = ZCC_NWS; - } - else - { + break; + + default: TokenMapEntry *zcctoken = TokenMap.CheckKey(sc.TokenType); if (zcctoken != NULL) { @@ -240,16 +249,18 @@ static void DoParse(const char *filename) else { sc.ScriptMessage("Unexpected token %s.\n", sc.TokenName(sc.TokenType).GetChars()); - break; + goto parse_end; } + break; } ZCCParse(parser, tokentype, value, &state); if (failed) { sc.ScriptMessage("Parse failed\n"); - break; + goto parse_end; } } +parse_end: value.Int = -1; ZCCParse(parser, ZCC_EOF, value, &state); ZCCParse(parser, 0, value, &state); diff --git a/src/zscript/zcc_parser.h b/src/zscript/zcc_parser.h index 0f4b0573c..cf51ff765 100644 --- a/src/zscript/zcc_parser.h +++ b/src/zscript/zcc_parser.h @@ -158,8 +158,8 @@ struct ZCC_TreeNode assert(SiblingNext->SiblingPrev == this); // Check integrity of new sibling list. - assert(sibling->SiblingPrev->SiblingNext = sibling); - assert(sibling->SiblingNext->SiblingPrev = sibling); + assert(sibling->SiblingPrev->SiblingNext == sibling); + assert(sibling->SiblingNext->SiblingPrev == sibling); ZCC_TreeNode *siblingend = sibling->SiblingPrev; SiblingPrev->SiblingNext = sibling; @@ -253,7 +253,11 @@ struct ZCC_StateGoto : ZCC_StatePart struct ZCC_StateLine : ZCC_StatePart { char Sprite[4]; - BITFIELD bBright:1; + BITFIELD bBright : 1; + BITFIELD bFast : 1; + BITFIELD bSlow : 1; + BITFIELD bNoDelay : 1; + BITFIELD bCanRaise : 1; FString *Frames; ZCC_Expression *Offset; ZCC_TreeNode *Action; @@ -485,6 +489,8 @@ struct ZCC_OpInfoType ZCC_OpProto *FindBestProto(PType *optype, const PType::Conversion **route, int &numslots); ZCC_OpProto *FindBestProto(PType *left, const PType::Conversion **route1, int &numslots, PType *right, const PType::Conversion **route2, int &numslots2); + + void FreeAllProtos(); }; #define CONVERSION_ROUTE_SIZE 8