diff --git a/source/build/include/buildtypes.h b/source/build/include/buildtypes.h index ed43ff391..3485f0adc 100644 --- a/source/build/include/buildtypes.h +++ b/source/build/include/buildtypes.h @@ -115,6 +115,7 @@ enum CSTAT_SPRITE_ONE_SIDED = 1u<<6u, CSTAT_SPRITE_YCENTER = 1u<<7u, CSTAT_SPRITE_BLOCK_HITSCAN = 1u<<8u, + CSTAT_SPRITE_BLOCK_ALL = CSTAT_SPRITE_BLOCK_HITSCAN | CSTAT_SPRITE_BLOCK, CSTAT_SPRITE_TRANSLUCENT_INVERT = 1u<<9u, CSTAT_SPRITE_RESERVED1 = 1u<<10u, // used by Duke 3D (Polymost) diff --git a/source/games/duke/src/duke3d.h b/source/games/duke/src/duke3d.h index 75722865e..0e6e68bed 100644 --- a/source/games/duke/src/duke3d.h +++ b/source/games/duke/src/duke3d.h @@ -15,7 +15,6 @@ #include "funct.h" #include "gamecontrol.h" #include "game.h" -#include "gamedef.h" #include "gamevar.h" #include "global.h" #include "macros.h" diff --git a/source/games/duke/src/funct.h b/source/games/duke/src/funct.h index 0cc3e0031..c965733f1 100644 --- a/source/games/duke/src/funct.h +++ b/source/games/duke/src/funct.h @@ -236,5 +236,6 @@ void sethorizon(int snum, int sb_snum, double factor, bool frominput = false); bool movementBlocked(int snum); void GetInput(); void startmainmenu(); +void loadcons(); END_DUKE_NS diff --git a/source/games/duke/src/game.h b/source/games/duke/src/game.h index c0af896f4..f44d0adef 100644 --- a/source/games/duke/src/game.h +++ b/source/games/duke/src/game.h @@ -27,7 +27,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #endif #include "fix16.h" -#include "gamedef.h" #include "mmulti.h" #include "palette.h" #include "cmdlib.h" @@ -49,13 +48,6 @@ extern int32_t cameradist; extern int32_t g_doQuickSave; extern int32_t tempwallptr; -void G_BackToMenu(void); - -void G_UpdatePlayerFromMenu(void); - - -void G_InitTimer(int32_t ticspersec); - enum { TFLAG_WALLSWITCH = 1 @@ -78,4 +70,12 @@ extern bool sound445done; #endif + +extern intptr_t apScriptGameEvent[]; + +extern TArray ScriptCode; + + +#include "concmd.h" + END_DUKE_NS diff --git a/source/games/duke/src/gamedef.cpp b/source/games/duke/src/gamedef.cpp index b512821f1..96e3f9f6c 100644 --- a/source/games/duke/src/gamedef.cpp +++ b/source/games/duke/src/gamedef.cpp @@ -48,20 +48,38 @@ Modifications for JonoF's port by Jonathon Fowler (jf@jonof.id.au) BEGIN_DUKE_NS -// parser state: todo: turn into a class -char* textptr; -int line_number; -int errorcount, warningcount; // was named 'error' and 'warning' which is too generic for public variables and may clash with other code. -int g_currentSourceFile; -uint32_t parsing_actor, parsing_event; -int parsing_state; -int num_squigilly_brackets; -int checking_ifelse; +//--------------------------------------------------------------------------- +// +// definitions needed by the parser. +// +//--------------------------------------------------------------------------- -//G_EXTERN char tempbuf[MAXSECTORS << 1], buf[1024]; todo - move to compile state. tempbuf gets used nearly everywhere as scratchpad memory. -extern char tempbuf[]; +enum labeltypes { + LABEL_ANY = -1, + LABEL_DEFINE = 1, + LABEL_STATE = 2, + LABEL_ACTOR = 4, + LABEL_ACTION = 8, + LABEL_AI = 16, + LABEL_MOVE = 32, +}; -TArray ScriptCode; +class labelstring +{ + char text[64]; + +public: + char& operator[](size_t pos) + { + return text[pos]; + } + operator const char* () { return text; } + const char* GetChars() { return text; } + int compare(const char* c) const { return strcmp(text, c); } + int comparei(const char* c) const { return stricmp(text, c); } + labelstring& operator=(const char* c) { strncpy(text, c, 64); text[63] = 0; } + +}; struct TempMusic { @@ -69,9 +87,80 @@ struct TempMusic FString music; }; -// This is for situations where the music gets defined before the map. Since the map records do not exist yet, we need a temporary buffer. -static TArray tempMusic; +//--------------------------------------------------------------------------- +// +// the actual parser +// +//--------------------------------------------------------------------------- +class ConCompiler +{ + char* textptr = nullptr; + int line_number = 0; + int errorcount = 0, warningcount = 0; // was named 'error' and 'warning' which is too generic for public variables and may clash with other code. + int currentsourcefile = -1; + unsigned parsing_actor = 0, parsing_event = 0; + int parsing_state = 0; + int num_squigilly_brackets = 0; + int checking_ifelse = 0; + labelstring parselabel= {}; + // This is for situations where the music gets defined before the map. Since the map records do not exist yet, we need a temporary buffer. + TArray tempMusic; + char parsebuf[1024]; + TArray parsebuffer; // global so that the storage is persistent across calls. + + void ReportError(int error); + int getkeyword(const char* text); + FString translatelabeltype(int type); + bool ispecial(char c); + void skiptoendofline(); + void skipwhitespace(); + void skipblockcomment(); + bool skipcomments(); + int keyword(void); + void getlabel(void); + void appendlabelvalue(labeltypes type, int value); + void appendlabeladdress(labeltypes type, int offset = 0); + int transword(void); + int transnum(int type); + void checkforkeyword(); + int parsecommand(); + +public: + void compilecon(const char* filenam); + void setmusic(); + int getErrorCount() { return errorcount; } +}; + +//--------------------------------------------------------------------------- +// +// label data +// +//--------------------------------------------------------------------------- + +static const char* labeltypenames[] = { + "define", + "state", + "actor", + "action", + "ai", + "move" +}; + +struct labeldef +{ + labelstring name; + labeltypes type; + int value; + + int compare(const char* c) const { return name.compare(c); } + const char* GetChars() { return name.GetChars(); } + +}; + +// These arrays contain the global output from the compiler. +static TArray labels; +TArray ScriptCode; //--------------------------------------------------------------------------- // @@ -110,62 +199,6 @@ void SortCommands() qsort(cmdList, countof(cmdList), sizeof(ConCommand), cmdCmp); } -//--------------------------------------------------------------------------- -// -// label data -// -//--------------------------------------------------------------------------- - -enum labeltypes { - LABEL_ANY = -1, - LABEL_DEFINE = 1, - LABEL_STATE = 2, - LABEL_ACTOR = 4, - LABEL_ACTION = 8, - LABEL_AI = 16, - LABEL_MOVE = 32, -}; - -static const char* labeltypenames[] = { - "define", - "state", - "actor", - "action", - "ai", - "move" -}; - -class labelstring -{ - char text[64]; - -public: - char& operator[](size_t pos) - { - return text[pos]; - } - operator const char* () { return text; } - const char* GetChars() { return text; } - int compare(const char* c) const { return strcmp(text, c); } - int comparei(const char* c) const { return stricmp(text, c); } - labelstring& operator=(const char* c) { strncpy(text, c, 64); text[63] = 0; } - -}; - -struct labeldef -{ - labelstring name; - labeltypes type; - int value; - - int compare(const char* c) const { return name.compare(c); } - const char* GetChars() { return name.GetChars(); } - -}; - -TArray labels; -static labelstring parselabel; - //--------------------------------------------------------------------------- // // @@ -186,10 +219,10 @@ enum ERROR_NOENDSWITCH, }; -void ReportError(int iError) +void ConCompiler::ReportError(int error) { - const char* fn = fileSystem.GetFileFullName(g_currentSourceFile); - switch (iError) + const char* fn = fileSystem.GetFileFullName(currentsourcefile); + switch (error) { case ERROR_ISAKEYWORD: Printf(TEXTCOLOR_RED " * ERROR!(%s, line %d) Symbol '%s' is a key word.\n", @@ -197,7 +230,7 @@ void ReportError(int iError) break; case ERROR_PARMUNDEFINED: Printf(TEXTCOLOR_RED " * ERROR!(%s, line %d) Parameter '%s' is undefined.\n", - fn, line_number, tempbuf); + fn, line_number, parsebuf); break; case WARNING_DUPLICATEDEFINITION: Printf(TEXTCOLOR_YELLOW " * WARNING.(%s, line %d) Duplicate definition '%s' ignored.\n", @@ -221,15 +254,15 @@ void ReportError(int iError) break; case ERROR_OPENBRACKET: Printf(TEXTCOLOR_RED " * ERROR! (%s, line %d) Found more '{' than '}' before '%s'.\n", - fn, line_number, tempbuf); + fn, line_number, parsebuf); break; case ERROR_CLOSEBRACKET: Printf(TEXTCOLOR_RED " * ERROR!(%s, line %d) Found more '}' than '{' before '%s'.\n", - fn, line_number, tempbuf); + fn, line_number, parsebuf); break; case ERROR_NOENDSWITCH: Printf(TEXTCOLOR_RED " * ERROR!%s(%s, line %d) Did not find endswitch before '%s'.\n", - fn, line_number, tempbuf); + fn, line_number, parsebuf); break; } @@ -241,7 +274,7 @@ void ReportError(int iError) // //--------------------------------------------------------------------------- -int getkeyword(const char* text) +int ConCompiler::getkeyword(const char* text) { ptrdiff_t min = 0; ptrdiff_t max = countof(cmdList) - 1; @@ -273,7 +306,7 @@ int getkeyword(const char* text) // //--------------------------------------------------------------------------- -FString translatelabeltype(int type) +FString ConCompiler::translatelabeltype(int type) { FString buf; for (int i = 0; i < 6; i++) @@ -321,7 +354,7 @@ int getlabelvalue(const char* text) // //--------------------------------------------------------------------------- -bool ispecial(char c) +bool ConCompiler::ispecial(char c) { if (c == 0x0a) { @@ -336,7 +369,7 @@ bool ispecial(char c) return false; } -bool isaltok(char c) +static bool isaltok(char c) { // isalnum pukes on negative input. return c > 0 && (isalnum(c) || c == '{' || c == '}' || c == '/' || c == '*' || c == '-' || c == '_' || c == '.'); @@ -348,13 +381,13 @@ bool isaltok(char c) // //--------------------------------------------------------------------------- -void skiptoendofline() +void ConCompiler::skiptoendofline() { while (*textptr != 0x0a && *textptr != 0x0d && *textptr != 0) textptr++; } -void skipwhitespace() +void ConCompiler::skipwhitespace() { while (*textptr == ' ' || *textptr == '\t' || *textptr == '\r' || *textptr == '\n') { @@ -363,7 +396,7 @@ void skipwhitespace() } } -void skipblockcomment() +void ConCompiler::skipblockcomment() { while (*textptr != '*' || textptr[1] != '/') { @@ -374,7 +407,7 @@ void skipblockcomment() textptr += 2; } -bool skipcomments() +bool ConCompiler::skipcomments() { while (true) { @@ -404,7 +437,7 @@ bool skipcomments() // //--------------------------------------------------------------------------- -int keyword(void) +int ConCompiler::keyword(void) { int i; const char* temptextptr; @@ -422,12 +455,12 @@ int keyword(void) i = 0; while (isaltok(*temptextptr)) { - tempbuf[i] = *(temptextptr++); + parsebuf[i] = *(temptextptr++); i++; } - tempbuf[i] = 0; + parsebuf[i] = 0; - return getkeyword(tempbuf); + return getkeyword(parsebuf); } //--------------------------------------------------------------------------- @@ -436,7 +469,7 @@ int keyword(void) // //--------------------------------------------------------------------------- -void getlabel(void) +void ConCompiler::getlabel(void) { long i; @@ -459,8 +492,7 @@ void getlabel(void) //--------------------------------------------------------------------------- // -// script buffer access wrappers. These are here to reduce the affected code -// when the time comes to refactor the buffer into a dynamic array. +// script buffer access wrappers. // //--------------------------------------------------------------------------- @@ -469,7 +501,7 @@ static void setscriptvalue(int offset, int value) ScriptCode[offset] = value; } -int scriptpos() +static int scriptpos() { return ScriptCode.Size(); } @@ -498,7 +530,7 @@ void pushlabeladdress() } */ -void appendlabelvalue(labeltypes type, int value) +void ConCompiler::appendlabelvalue(labeltypes type, int value) { labels.Reserve(1); labels.Last().type = type; @@ -506,7 +538,7 @@ void appendlabelvalue(labeltypes type, int value) labels.Last().value = value; } -void appendlabeladdress(labeltypes type, int offset = 0) +void ConCompiler::appendlabeladdress(labeltypes type, int offset) { appendlabelvalue(type, ScriptCode.Size() + offset); } @@ -514,11 +546,11 @@ void appendlabeladdress(labeltypes type, int offset = 0) //--------------------------------------------------------------------------- // -// +//Returns its code # // //--------------------------------------------------------------------------- -int transword(void) //Returns its code # +int ConCompiler::transword(void) { int i, l; @@ -537,13 +569,13 @@ int transword(void) //Returns its code # { if (l < 31) { - tempbuf[l] = textptr[l]; + parsebuf[l] = textptr[l]; l++; } } - tempbuf[l] = 0; + parsebuf[l] = 0; - i = getkeyword(tempbuf); + i = getkeyword(parsebuf); if (i >= 0) { appendscriptvalue(i); @@ -553,19 +585,19 @@ int transword(void) //Returns its code # textptr += l; - const char* fn = fileSystem.GetFileFullName(g_currentSourceFile); - if (tempbuf[0] == '{' && tempbuf[1] != 0) - Printf(TEXTCOLOR_RED " * ERROR!(%s, line %d) Expecting a SPACE or CR between '{' and '%s'.\n", fn, line_number, tempbuf + 1); - else if (tempbuf[0] == '}' && tempbuf[1] != 0) - Printf(TEXTCOLOR_RED " * ERROR!(%s, line %d) Expecting a SPACE or CR between '}' and '%s'.\n", fn, line_number, tempbuf + 1); - else if (tempbuf[0] == '/' && tempbuf[1] == '/' && tempbuf[2] != 0) - Printf(TEXTCOLOR_RED " * ERROR!(%s, line %d) Expecting a SPACE between '//' and '%s'.\n", fn, line_number, tempbuf + 2); - else if (tempbuf[0] == '/' && tempbuf[1] == '*' && tempbuf[2] != 0) - Printf(TEXTCOLOR_RED " * ERROR!(%s, line %d) Expecting a SPACE between '/*' and '%s'.\n", fn, line_number, tempbuf + 2); - else if (tempbuf[0] == '*' && tempbuf[1] == '/' && tempbuf[2] != 0) - Printf(TEXTCOLOR_RED " * ERROR!(%s, line %d) Expecting a SPACE between '*/' and '%s'.\n", fn, line_number, tempbuf + 2); + const char* fn = fileSystem.GetFileFullName(currentsourcefile); + if (parsebuf[0] == '{' && parsebuf[1] != 0) + Printf(TEXTCOLOR_RED " * ERROR!(%s, line %d) Expecting a SPACE or CR between '{' and '%s'.\n", fn, line_number, parsebuf + 1); + else if (parsebuf[0] == '}' && parsebuf[1] != 0) + Printf(TEXTCOLOR_RED " * ERROR!(%s, line %d) Expecting a SPACE or CR between '}' and '%s'.\n", fn, line_number, parsebuf + 1); + else if (parsebuf[0] == '/' && parsebuf[1] == '/' && parsebuf[2] != 0) + Printf(TEXTCOLOR_RED " * ERROR!(%s, line %d) Expecting a SPACE between '//' and '%s'.\n", fn, line_number, parsebuf + 2); + else if (parsebuf[0] == '/' && parsebuf[1] == '*' && parsebuf[2] != 0) + Printf(TEXTCOLOR_RED " * ERROR!(%s, line %d) Expecting a SPACE between '/*' and '%s'.\n", fn, line_number, parsebuf + 2); + else if (parsebuf[0] == '*' && parsebuf[1] == '/' && parsebuf[2] != 0) + Printf(TEXTCOLOR_RED " * ERROR!(%s, line %d) Expecting a SPACE between '*/' and '%s'.\n", fn, line_number, parsebuf + 2); else - Printf(TEXTCOLOR_RED " * ERROR!(%s, line %d) Keyword expected, got '%s'.\n", fn, line_number, tempbuf + 2); + Printf(TEXTCOLOR_RED " * ERROR!(%s, line %d) Keyword expected, got '%s'.\n", fn, line_number, parsebuf + 2); errorcount++; return -1; @@ -577,7 +609,7 @@ int transword(void) //Returns its code # // //--------------------------------------------------------------------------- -int transnum(int type) +int ConCompiler::transnum(int type) { int l; @@ -595,13 +627,13 @@ int transnum(int type) { if (l < 31) { - tempbuf[l] = textptr[l]; + parsebuf[l] = textptr[l]; l++; } } - tempbuf[l] = 0; + parsebuf[l] = 0; - if (getkeyword(tempbuf) >= 0) + if (getkeyword(parsebuf) >= 0) { errorcount++; ReportError(ERROR_ISAKEYWORD); @@ -611,7 +643,7 @@ int transnum(int type) for (unsigned i = 0; i < labels.Size(); i++) { - if (labels[i].compare(tempbuf) == 0) + if (labels[i].compare(parsebuf) == 0) { // Non-values can be compared with 0. if (labels[i].type & type || (labels[i].value == 0)) @@ -624,7 +656,7 @@ int transnum(int type) textptr += l; auto el = translatelabeltype(type); auto gl = translatelabeltype(labels[i].type); - const char* fn = fileSystem.GetFileFullName(g_currentSourceFile); + const char* fn = fileSystem.GetFileFullName(currentsourcefile); Printf(TEXTCOLOR_YELLOW " * WARNING.(%s, line %d) %s: Expected a '%s' label but found a '%s' label instead.\n", fn, line_number, labels[i].GetChars(), el.GetChars(), gl.GetChars()); return -1; // valid label name, but wrong type } @@ -636,7 +668,7 @@ int transnum(int type) errorcount++; textptr += l; #ifdef FOR_LATER - if (GetDefID(tempbuf) >= 0) + if (GetDefID(parsebuf) >= 0) { Printf(TEXTCOLOR_ORANGE " Game Variable not expected\n"); } @@ -659,7 +691,7 @@ int transnum(int type) if (type != LABEL_DEFINE && value != 0) { - const char* fn = fileSystem.GetFileFullName(g_currentSourceFile); + const char* fn = fileSystem.GetFileFullName(currentsourcefile); Printf(TEXTCOLOR_YELLOW " * WARNING.(%s, line %d) Expected an identifier, got a numeric literal %d.\n", fn, line_number, (int)value); } @@ -675,7 +707,7 @@ int transnum(int type) // //--------------------------------------------------------------------------- -void checkforkeyword() +void ConCompiler::checkforkeyword() { if (getkeyword(parselabel) >= 0) { @@ -690,11 +722,10 @@ void checkforkeyword() // //--------------------------------------------------------------------------- -static TArray parsebuffer; // global so that the storage is persistent across calls. -int parsecommand() +int ConCompiler::parsecommand() { - const char* fn = fileSystem.GetFileFullName(g_currentSourceFile); + const char* fn = fileSystem.GetFileFullName(currentsourcefile); int i, j, k; int tempscrptr; uint8_t done, temp_ifelse_check;// , tw; @@ -733,6 +764,7 @@ int parsecommand() { Printf(TEXTCOLOR_RED " * ERROR!(%s, line %d) State '%s' not found.\n", fn, line_number, parselabel.GetChars()); errorcount++; + return 0; } appendscriptvalue(labels[lnum].value); return 0; @@ -760,6 +792,7 @@ int parsecommand() return 0; case concmd_gamevar: + { // syntax: gamevar // defines var1 and sets initial value. // flags are used to define usage @@ -780,9 +813,23 @@ int parsecommand() transnum(LABEL_DEFINE); // get flags lnum = popscriptvalue(); - AddGameVar(parselabel, j, lnum & (~(GAMEVAR_FLAG_DEFAULT | GAMEVAR_FLAG_SECRET))); - return 0; + if (strlen(parselabel) > (MAXVARLABEL - 1)) + { + warningcount++; + Printf(TEXTCOLOR_RED " * WARNING.(%s, line %d) Variable Name '%s' too int (max is %d)\n", fn, line_number, parselabel, MAXVARLABEL - 1); + return 0; + } + int res = AddGameVar(parselabel, j, lnum & (~(GAMEVAR_FLAG_DEFAULT | GAMEVAR_FLAG_SECRET))); + if (res < 0) + { + errorcount++; + if (res == -1) Printf(TEXTCOLOR_RED " * ERROR.(%s, line %d) Duplicate game variable definition '%s'.\n", fn, line_number, parselabel); + else if (res == -2) Printf(TEXTCOLOR_RED " * ERROR.(%s, line %d) '%s' maximum number of game variables exceeded.\n", fn, line_number, parselabel); + return 0; + } + return 0; + } case concmd_define: getlabel(); checkforkeyword(); @@ -934,8 +981,8 @@ int parsecommand() auto data = fileSystem.GetFileData(fni, 1); - temp_current_file = g_currentSourceFile; - g_currentSourceFile = fni; + temp_current_file = currentsourcefile; + currentsourcefile = fni; temp_line_number = line_number; line_number = 1; @@ -951,7 +998,7 @@ int parsecommand() textptr = origtptr; line_number = temp_line_number; checking_ifelse = temp_ifelse_check; - g_currentSourceFile = temp_current_file; + currentsourcefile = temp_current_file; if (*textptr == '"') textptr++; // needed for RR. return 0; @@ -1352,7 +1399,7 @@ int parsecommand() case concmd_addlogvar: // syntax: addlogvar - appendscriptvalue(g_currentSourceFile); + appendscriptvalue(currentsourcefile); appendscriptvalue(line_number); // get the ID of the DEF @@ -1375,7 +1422,7 @@ int parsecommand() // syntax: addlog // source file. - appendscriptvalue(g_currentSourceFile); + appendscriptvalue(currentsourcefile); // prints the line number in the log file. appendscriptvalue(line_number); @@ -1703,7 +1750,7 @@ int parsecommand() case concmd_gamestartup: { popscriptvalue(); - auto parseone = []() { transnum(LABEL_DEFINE); return popscriptvalue(); }; + auto parseone = [=]() { transnum(LABEL_DEFINE); return popscriptvalue(); }; ud.const_visibility = parseone(); impact_damage = parseone(); max_player_health = parseone(); @@ -1754,15 +1801,15 @@ int parsecommand() // //--------------------------------------------------------------------------- -void compilecon(const char *filenam) +void ConCompiler::compilecon(const char *filenam) { - g_currentSourceFile = fileSystem.FindFile(filenam); - if (g_currentSourceFile < 0) + currentsourcefile = fileSystem.FindFile(filenam); + if (currentsourcefile < 0) { I_FatalError("%s: Missing con file(s).", filenam); } Printf("Compiling: '%s'.\n", filenam); - auto data = fileSystem.GetFileData(g_currentSourceFile, 1); + auto data = fileSystem.GetFileData(currentsourcefile, 1); textptr = (char*)data.Data(); line_number = 1; @@ -1817,6 +1864,22 @@ static const char* ConFile(void) return "game.con"; } +//--------------------------------------------------------------------------- +// +// process the music definitions after all map records are set up. +// +//--------------------------------------------------------------------------- + +void ConCompiler::setmusic() +{ + for (auto& tm : tempMusic) + { + auto map = FindMapByLevelNum(tm.levnum); + if (map) map->music = tm.music; + } + tempMusic.Clear(); +} + //--------------------------------------------------------------------------- // // why was this called loadefs? @@ -1842,18 +1905,19 @@ void loadcons() auto before = I_nsTime(); ScriptCode.Push(0); - compilecon(ConFile()); //Tokenize + ConCompiler comp; + comp.compilecon(ConFile()); //Tokenize if (userConfig.AddCons) for (FString& m : *userConfig.AddCons.get()) { - compilecon(m); + comp.compilecon(m); } ScriptCode.ShrinkToFit(); labels.ShrinkToFit(); userConfig.AddCons.reset(); setscriptvalue(0, scriptpos()); - if (errorcount) + if (comp.getErrorCount()) { I_FatalError("Failed to compile CONs."); } @@ -1899,13 +1963,7 @@ void loadcons() maprec->levelNumber = levelnum(1, 7); } } - for (auto& tm : tempMusic) - { - auto map = FindMapByLevelNum(tm.levnum); - if (map) map->music = tm.music; - } - tempMusic.Clear(); - + comp.setmusic(); } END_DUKE_NS diff --git a/source/games/duke/src/gamedef.h b/source/games/duke/src/gamedef.h deleted file mode 100644 index 92f96f66e..000000000 --- a/source/games/duke/src/gamedef.h +++ /dev/null @@ -1,85 +0,0 @@ -//------------------------------------------------------------------------- -/* -Copyright (C) 2016 EDuke32 developers and contributors - -This file is part of EDuke32. - -EDuke32 is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License version 2 -as published by the Free Software Foundation. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - -See the GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -*/ -//------------------------------------------------------------------------- - -#ifndef gamedef_h_ -#define gamedef_h_ - -#include "gamevar.h" -#include "funct.h" -#include "build.h" // hashtable_t -#include "common.h" // tokenlist -#include "player.h" // projectile_t - -BEGIN_DUKE_NS - -#define LABEL_HASPARM2 1 -#define LABEL_ISSTRING 2 - -// "magic" number for { and }, overrides line number in compiled code for later detection -#define VM_IFELSE_MAGIC 31337 -#define VM_INSTMASK 0xfff -#define VM_DECODE_LINE_NUMBER(xxx) ((int)((xxx) >> 12)) - -extern intptr_t apScriptGameEvent[]; - -extern char g_scriptFileName[BMAX_PATH]; - -extern const uint32_t CheatFunctionFlags[]; -extern const uint8_t CheatFunctionIDs[]; - -extern int errorcount; -extern int32_t line_number; -extern int32_t g_totalLines; -extern int warningcount; -extern int32_t otherp; - -int32_t C_AllocQuote(int32_t qnum); -void C_InitQuotes(void); - -extern int32_t g_numProjectiles; - -void G_DoGameStartup(const int32_t *params); -void C_DefineMusic(int volumeNum, int levelNum, const char *fileName); - -void C_DefineVolumeFlags(int32_t vol, int32_t flags); -void ReportError(int32_t iError); -void loadcons(); - -extern int32_t g_errorLineNum; -extern int32_t g_tw; - -typedef struct { - const char* token; - int32_t val; -} tokenmap_t; - -extern char const * VM_GetKeywordForID(int32_t id); - -extern TArray ScriptCode; - - -#include "concmd.h" - - -END_DUKE_NS - -#endif // gamedef_h_ diff --git a/source/games/duke/src/gamevar.cpp b/source/games/duke/src/gamevar.cpp index 6d73e446a..1198f0fea 100644 --- a/source/games/duke/src/gamevar.cpp +++ b/source/games/duke/src/gamevar.cpp @@ -34,7 +34,6 @@ source as it is released. #include "ns.h" #include "global.h" -#include "gamedef.h" #include "serializer.h" #include "names.h" #include "build.h" @@ -92,7 +91,7 @@ void SerializeGameVars(FSerializer &arc) // //--------------------------------------------------------------------------- -bool AddGameVar(const char* pszLabel, intptr_t lValue, unsigned dwFlags) +int AddGameVar(const char* pszLabel, intptr_t lValue, unsigned dwFlags) { int i; @@ -103,12 +102,6 @@ bool AddGameVar(const char* pszLabel, intptr_t lValue, unsigned dwFlags) if (dwFlags & (GAMEVAR_FLAG_PLONG | GAMEVAR_FLAG_PFUNC)) dwFlags |= GAMEVAR_FLAG_SYSTEM; // force system if PLONG - if (strlen(pszLabel) > (MAXVARLABEL - 1)) - { - warningcount++; - Printf(TEXTCOLOR_RED " * WARNING.(L%ld) Variable Name '%s' too int (max is %d)\n", line_number, pszLabel, MAXVARLABEL - 1); - return 0; - } for (i = 0; i < iGameVarCount; i++) { if (strcmp(pszLabel, aGameVars[i].szLabel) == 0) @@ -121,13 +114,7 @@ bool AddGameVar(const char* pszLabel, intptr_t lValue, unsigned dwFlags) // it's OK to replace break; } - else - { - // it's a duplicate in error - errorcount++; - Printf(TEXTCOLOR_RED " * ERROR.(L%ld) Duplicate Game definition '%s' ignored.\n", line_number, pszLabel); - return 0; - } + else return -1; } } if (i < MAXGAMEVARS) @@ -191,7 +178,7 @@ bool AddGameVar(const char* pszLabel, intptr_t lValue, unsigned dwFlags) else { // no room to add... - return 0; + return -2; } } diff --git a/source/games/duke/src/gamevar.h b/source/games/duke/src/gamevar.h index 2f24fed53..47c1b68d1 100644 --- a/source/games/duke/src/gamevar.h +++ b/source/games/duke/src/gamevar.h @@ -113,16 +113,7 @@ extern int g_iZRangeVarID; // var ID of "ZRANGE" extern int g_iAngRangeVarID; // var ID of "ANGRANGE" extern int g_iAimAngleVarID; // var ID of "AUTOAIMANGLE" -#if 0 -// global crap for event management -extern int g_i, g_p; -extern int g_x; -extern int* g_t; -extern uint8_t killit_flag; -//extern sprite_ype* g_sp; -#endif - -bool AddGameVar(const char *pszLabel, intptr_t lValue, unsigned dwFlags); +int AddGameVar(const char *pszLabel, intptr_t lValue, unsigned dwFlags); int GetGameID(const char *szGameLabel); int GetDefID(const char *szGameLabel); void ClearGameVars(void); diff --git a/source/games/duke/src/global.h b/source/games/duke/src/global.h index d2dbd8d90..966c514df 100644 --- a/source/games/duke/src/global.h +++ b/source/games/duke/src/global.h @@ -221,15 +221,7 @@ extern int32_t g_cdTrack; // MSDN (https://msdn.microsoft.com/en-us/library/2e70t5y1%28VS.80%29.aspx) says: // "pack takes effect at the first struct, union, or class declaration after // the pragma is seen; pack has no effect on definitions." -#pragma pack(push,1) -#ifdef global_c_ -static playerdata_t g_player_s[1 + MAXPLAYERS]; -playerdata_t *const g_player = &g_player_s[1]; -#else -extern playerdata_t *const g_player; -#endif G_EXTERN player_orig po[MAXPLAYERS]; -#pragma pack(pop) G_EXTERN uint32_t everyothertime; G_EXTERN double g_gameUpdateTime; diff --git a/source/games/duke/src/inlines.h b/source/games/duke/src/inlines.h index d05d730e7..382b30de5 100644 --- a/source/games/duke/src/inlines.h +++ b/source/games/duke/src/inlines.h @@ -2,6 +2,7 @@ #include "mathutil.h" #include "glbackend/glbackend.h" +#include "player.h" // all inline functions. BEGIN_DUKE_NS diff --git a/source/games/duke/src/player.h b/source/games/duke/src/player.h index ee4db2714..19955dcd9 100644 --- a/source/games/duke/src/player.h +++ b/source/games/duke/src/player.h @@ -60,8 +60,7 @@ extern input_t sync[MAXPLAYERS]; # define PWEAPON(Player, Weapon, Wmember) (aplWeapon ## Wmember [Weapon][Player]) -extern playerdata_t *const g_player; - +extern playerdata_t g_player[MAXPLAYERS]; void P_GetInput(int playerNum); void P_GetInputMotorcycle(int playerNum); diff --git a/source/games/duke/src/types.h b/source/games/duke/src/types.h index 1e17e4eb7..056e15fab 100644 --- a/source/games/duke/src/types.h +++ b/source/games/duke/src/types.h @@ -1,4 +1,5 @@ #pragma once +#include "names.h" BEGIN_DUKE_NS diff --git a/source/games/duke/src/zz_game.cpp b/source/games/duke/src/zz_game.cpp index b9fec71d7..b213ef0f0 100644 --- a/source/games/duke/src/zz_game.cpp +++ b/source/games/duke/src/zz_game.cpp @@ -71,5 +71,7 @@ int32_t PHEIGHT = PHEIGHT_DUKE; int32_t lastvisinc; +playerdata_t g_player[MAXPLAYERS]; + END_DUKE_NS diff --git a/source/games/duke/src/zz_savegame.cpp b/source/games/duke/src/zz_savegame.cpp index 6112cff2a..0115ba02a 100644 --- a/source/games/duke/src/zz_savegame.cpp +++ b/source/games/duke/src/zz_savegame.cpp @@ -680,8 +680,6 @@ static uint8_t *svinitsnap; static uint32_t svdiffsiz; static uint8_t *svdiff; -#include "gamedef.h" - #define SV_SKIPMASK (GAMEVAR_READONLY | GAMEVAR_PTR_MASK) static char svgm_vars_string [] = "blK:vars";