From b0f846e200e3dbd174b9fc409ba4ec1251508773 Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Tue, 30 Oct 2018 19:10:50 +0100 Subject: [PATCH] - remove the dlight config file and switch to using UDMF properties on lines, sectors and things --- CMakeLists.txt | 2 - README.md | 27 +- src/level/doomdata.h | 9 +- src/level/level.cpp | 3 +- src/level/level.h | 2 +- src/level/level_udmf.cpp | 4 + src/lightmap/kexlib/parser.cpp | 1134 -------------------------------- src/lightmap/kexlib/parser.h | 172 ----- src/lightmap/mapdata.cpp | 404 ++++-------- src/main.cpp | 2 +- 10 files changed, 172 insertions(+), 1587 deletions(-) delete mode 100644 src/lightmap/kexlib/parser.cpp delete mode 100644 src/lightmap/kexlib/parser.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 90ac474..45c9cc6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -155,7 +155,6 @@ set( SOURCES src/lightmap/kexlib/binfile.cpp src/lightmap/kexlib/kstring.cpp src/lightmap/kexlib/memheap.cpp - src/lightmap/kexlib/parser.cpp src/lightmap/kexlib/math/angle.cpp src/lightmap/kexlib/math/bounds.cpp src/lightmap/kexlib/math/mathlib.cpp @@ -199,7 +198,6 @@ set( HEADERS src/lightmap/kexlib/binfile.h src/lightmap/kexlib/kstring.h src/lightmap/kexlib/memheap.h - src/lightmap/kexlib/parser.h src/lightmap/kexlib/math/mathlib.h ) diff --git a/README.md b/README.md index f51f2f3..a5bd706 100644 --- a/README.md +++ b/README.md @@ -1 +1,26 @@ -# ZDRay \ No newline at end of file +# ZDRay UDMF properties + +linedef +{ + lightcolor = (color, default: white) + lightintensity = (default: 1) + lightdistance = (default: 0, no light) +} + +thing +{ + lightcolor = (color) + lightintensity = (default: 1) + lightdistance = (default: 0, no light) +} + +sector +{ + lightcolorfloor = (color, default: white) + lightintensityfloor = (default: 1) + lightdistancefloor = (default: 0, no light) + + lightcolorceiling = (color, default: white) + lightintensityceiling = (default: 1) + lightdistanceceiling = (default: 0, no light) +} diff --git a/src/level/doomdata.h b/src/level/doomdata.h index 2ba0408..9886eb7 100644 --- a/src/level/doomdata.h +++ b/src/level/doomdata.h @@ -217,6 +217,8 @@ struct IntThing char special; char args[5]; + float height; // UDMF + TArray props; }; @@ -374,7 +376,6 @@ struct FLevel TArray lightSurfaces; void SetupDlight(); - void ParseConfigFile(const char *file); void CreateLights(); void CleanupThingLights(); @@ -395,12 +396,6 @@ private: void BuildLeafs(); void BuildPVS(); void CheckSkySectors(); - - TArray lightDefs; - TArray surfaceLightDefs; - TArray mapDefs; - - mapDef_t *mapDef = nullptr; }; const int BLOCKSIZE = 128; diff --git a/src/level/level.cpp b/src/level/level.cpp index 21c4422..d475a78 100644 --- a/src/level/level.cpp +++ b/src/level/level.cpp @@ -597,14 +597,13 @@ void FProcessor::BuildNodes() } } -void FProcessor::BuildLightmaps(const char *configFile) +void FProcessor::BuildLightmaps() { LMBuilder.ambience = 0.0f; LMBuilder.samples = Samples; LMBuilder.textureWidth = LMDims; LMBuilder.textureHeight = LMDims; - Level.ParseConfigFile(configFile); Level.SetupDlight(); Surface_AllocateFromMap(Level); Level.CreateLights(); diff --git a/src/level/level.h b/src/level/level.h index 1a444ca..abcbf0e 100644 --- a/src/level/level.h +++ b/src/level/level.h @@ -38,7 +38,7 @@ public: FProcessor(FWadReader &inwad, int lump); void BuildNodes(); - void BuildLightmaps(const char *configFile); + void BuildLightmaps(); void Write(FWadWriter &out); private: diff --git a/src/level/level_udmf.cpp b/src/level/level_udmf.cpp index 1b66c50..5cff9c0 100644 --- a/src/level/level_udmf.cpp +++ b/src/level/level_udmf.cpp @@ -183,6 +183,10 @@ void FProcessor::ParseThing(IntThing *th) { th->type = (short)CheckInt(key); } + if (!stricmp(key, "height")) + { + th->height = CheckFloat(key); + } // now store the key in its unprocessed form UDMFKey k = {key, value}; diff --git a/src/lightmap/kexlib/parser.cpp b/src/lightmap/kexlib/parser.cpp deleted file mode 100644 index c40a2d5..0000000 --- a/src/lightmap/kexlib/parser.cpp +++ /dev/null @@ -1,1134 +0,0 @@ -//----------------------------------------------------------------------------- -// Note: this is a modified version of dlight. It is not the original software. -//----------------------------------------------------------------------------- -// -// Copyright (c) 2013-2014 Samuel Villarreal -// svkaiser@gmail.com -// -// This software is provided 'as-is', without any express or implied -// warranty. In no event will the authors be held liable for any damages -// arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it -// freely, subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; you must not -// claim that you wrote the original software. If you use this software -// in a product, an acknowledgment in the product documentation would be -// appreciated but is not required. -// -// 2. Altered source versions must be plainly marked as such, and must not be -// misrepresented as being the original software. -// -// 3. This notice may not be removed or altered from any source -// distribution. -// -//----------------------------------------------------------------------------- -// -// DESCRIPTION: Script token/parser system -// -//----------------------------------------------------------------------------- - -#include "lightmap/common.h" -#include "parser.h" - -//#define SC_DEBUG - -#define COMMENT_NONE 0 -#define COMMENT_SINGLELINE 1 -#define COMMENT_MULTILINE 2 - -enum chartype_t -{ - CHAR_NUMBER, - CHAR_LETTER, - CHAR_SYMBOL, - CHAR_QUOTE, - CHAR_SPECIAL, - CHAR_EOF -}; - -#ifdef SC_DEBUG - -// -// SC_DebugPrintf -// - -static void SC_DebugPrintf(const char *str, ...) -{ - char buf[1024]; - va_list v; - - if(!verbose) - { - return; - } - - va_start(v, str); - vsprintf(buf, str,v); - va_end(v); - - fprintf(debugfile, buf); -} -#endif - -static kexParser parserLocal; -kexParser *parser = &parserLocal; - -// -// kexLexer::kexLexer -// - -kexLexer::kexLexer(const char *filename, char *buf, int bufSize) -{ - buffer = buf; - buffsize = bufSize; - pointer_start = buffer; - pointer_end = buffer + buffsize; - linepos = 1; - rowpos = 1; - buffpos = 0; - tokentype = TK_NONE; - name = filename; -} - -// -// kexLexer::~kexLexer -// - -kexLexer::~kexLexer() -{ - if(buffer) - { - Mem_Free(buffer); - } - buffer = NULL; - buffsize = 0; - pointer_start = NULL; - pointer_end = NULL; - linepos = 0; - rowpos = 0; - buffpos = 0; -} - -// -// kexLexer::CheckState -// - -bool kexLexer::CheckState() -{ -#ifdef SC_DEBUG - SC_DebugPrintf("(%s): checking script state: %i : %i\n", - name, buffpos, buffsize); -#endif - - if(buffpos < buffsize) - { - return true; - } - - return false; -} - -// -// kexLexer::CheckKeywords -// - -void kexLexer::CheckKeywords() -{ - if(!kexStr::Compare(token, "define")) - { - tokentype = TK_DEFINE; - } - else if(!kexStr::Compare(token, "include")) - { - tokentype = TK_INCLUDE; - } - else if(!kexStr::Compare(token, "setdir")) - { - tokentype = TK_SETDIR; - } - else if(!kexStr::Compare(token, "undef")) - { - tokentype = TK_UNDEF; - } -} - -// -// kexLexer::ClearToken -// - -void kexLexer::ClearToken() -{ - tokentype = TK_NONE; - memset(token, 0, SC_TOKEN_LEN); -} - -// -// kexLexer::GetNumber -// - -int kexLexer::GetNumber() -{ -#ifdef SC_DEBUG - SC_DebugPrintf("get number (%s)\n", token); -#endif - - Find(); - - if(tokentype != TK_NUMBER) - { - parserLocal.HandleError("%s is not a number", token); - } - - return atoi(token); -} - -// -// kexLexer::GetFloat -// - -double kexLexer::GetFloat() -{ -#ifdef SC_DEBUG - SC_DebugPrintf("get float (%s)\n", token); -#endif - - Find(); - - if(tokentype != TK_NUMBER) - { - parserLocal.HandleError("%s is not a float", token); - } - - return atof(token); -} - -// -// kexLexer::GetVector3 -// - -kexVec3 kexLexer::GetVector3() -{ -#ifdef SC_DEBUG - SC_DebugPrintf("get vector3 (%s)\n", token); -#endif - - float x, y, z; - - ExpectNextToken(TK_LBRACK); - x = (float)GetFloat(); - y = (float)GetFloat(); - z = (float)GetFloat(); - ExpectNextToken(TK_RBRACK); - - return kexVec3(x, y, z); -} - -// -// kexLexer::GetVector4 -// - -kexVec4 kexLexer::GetVector4() -{ -#ifdef SC_DEBUG - SC_DebugPrintf("get vector4 (%s)\n", token); -#endif - - float x, y, z, w; - - ExpectNextToken(TK_LBRACK); - x = (float)GetFloat(); - y = (float)GetFloat(); - z = (float)GetFloat(); - w = (float)GetFloat(); - ExpectNextToken(TK_RBRACK); - - return kexVec4(x, y, z, w); -} - -// -// kexLexer::GetVectorString3 -// - -kexVec3 kexLexer::GetVectorString3() -{ - kexVec3 vec; - - GetString(); - sscanf(StringToken(), "%f %f %f", &vec.x, &vec.y, &vec.z); - - return vec; -} - -// -// kexLexer::GetVectorString4 -// - -kexVec4 kexLexer::GetVectorString4() -{ - kexVec4 vec; - - GetString(); - sscanf(StringToken(), "%f %f %f %f", &vec.x, &vec.y, &vec.z, &vec.w); - - return vec; -} - -// -// kexLexer::GetString -// - -void kexLexer::GetString() -{ - ExpectNextToken(TK_STRING); - strcpy(stringToken, token); -} - -// -// kexLexer::MustMatchToken -// - -void kexLexer::MustMatchToken(int type) -{ -#ifdef SC_DEBUG - SC_DebugPrintf("must match %i\n", type); - SC_DebugPrintf("tokentype %i\n", tokentype); -#endif - - if(tokentype != type) - { - const char *string; - - switch(type) - { - case TK_NUMBER: - string = "a number"; - break; - case TK_STRING: - string = "a string"; - break; - case TK_POUND: - string = "a pound sign"; - break; - case TK_COLON: - string = "a colon"; - break; - case TK_SEMICOLON: - string = "a semicolon"; - break; - case TK_LBRACK: - string = "{"; - break; - case TK_RBRACK: - string = "}"; - break; - case TK_LSQBRACK: - string = "["; - break; - case TK_RSQBRACK: - string = "]"; - break; - case TK_LPAREN: - string = "("; - break; - case TK_RPAREN: - string = ")"; - break; - case TK_COMMA: - string = "a comma"; - break; - default: - string = NULL; - parserLocal.HandleError("Invalid token: %s", token); - break; - } - - parserLocal.HandleError("Expected %s, but found: %s (%i : %i)", - string, token, tokentype, type); - } -} - -// -// kexLexer::ExpectNextToken -// - -void kexLexer::ExpectNextToken(int type) -{ -#ifdef SC_DEBUG - SC_DebugPrintf("expect %i\n", type); -#endif - Find(); - MustMatchToken(type); -} - -// -// kexLexer::GetNumberToken -// - -void kexLexer::GetNumberToken(char initial) -{ - int c = initial; - int i = 0; - - tokentype = TK_NUMBER; - - while(parserLocal.CharCode()[c] == CHAR_NUMBER) - { - token[i++] = c; - c = GetChar(); - } - -#ifdef SC_DEBUG - SC_DebugPrintf("get number (%s)\n", token); -#endif - - Rewind(); -} - -// -// kexLexer::GetLetterToken -// - -void kexLexer::GetLetterToken(char initial) -{ - int c = initial; - int i = 0; - bool haschar = false; - - while(parserLocal.CharCode()[c] == CHAR_LETTER || - (haschar && parserLocal.CharCode()[c] == CHAR_NUMBER)) - { - token[i++] = c; - c = GetChar(); - haschar = true; - } - - tokentype = TK_IDENIFIER; - -#ifdef SC_DEBUG - SC_DebugPrintf("get letter (%s)\n", token); -#endif - - Rewind(); - CheckKeywords(); -} - -// -// kexLexer::GetSymbolToken -// - -void kexLexer::GetSymbolToken(char c) -{ - switch(c) - { - case '#': - tokentype = TK_POUND; - token[0] = c; - break; - case ':': - tokentype = TK_COLON; - token[0] = c; - break; - case ';': - tokentype = TK_SEMICOLON; - token[0] = c; - break; - case '=': - tokentype = TK_EQUAL; - token[0] = c; - break; - case '.': - tokentype = TK_PERIOD; - token[0] = c; - break; - case '{': - tokentype = TK_LBRACK; - token[0] = c; - break; - case '}': - tokentype = TK_RBRACK; - token[0] = c; - break; - case '(': - tokentype = TK_LPAREN; - token[0] = c; - break; - case ')': - tokentype = TK_RPAREN; - token[0] = c; - break; - case '[': - tokentype = TK_LSQBRACK; - token[0] = c; - break; - case ']': - tokentype = TK_RSQBRACK; - token[0] = c; - break; - case ',': - tokentype = TK_COMMA; - token[0] = c; - break; - case '\'': - tokentype = TK_QUOTE; - token[0] = c; - break; - case '/': - tokentype = TK_FORWARDSLASH; - token[0] = c; - break; - default: - parserLocal.HandleError("Unknown symbol: %c", c); - break; - } - -#ifdef SC_DEBUG - SC_DebugPrintf("get symbol (%s)\n", token); -#endif -} - -// -// kexLexer::GetStringToken -// - -void kexLexer::GetStringToken() -{ - int i = 0; - char c = GetChar(); - - while(parserLocal.CharCode()[c] != CHAR_QUOTE) - { - token[i++] = c; - c = GetChar(); - } - - tokentype = TK_STRING; - -#ifdef SC_DEBUG - SC_DebugPrintf("get string (%s)\n", token); -#endif -} - -// -// kexLexer::Find -// - -bool kexLexer::Find() -{ - char c = 0; - int comment = COMMENT_NONE; - - ClearToken(); - - while(CheckState()) - { - c = GetChar(); - - if(comment == COMMENT_NONE) - { - if(c == '/') - { - char gc = GetChar(); - - if(gc != '/' && gc != '*') - { - Rewind(); - } - else - { - if(gc == '*') - { - comment = COMMENT_MULTILINE; - } - else - { - comment = COMMENT_SINGLELINE; - } - } - } - } - else if(comment == COMMENT_MULTILINE) - { - if(c == '*') - { - char gc = GetChar(); - - if(gc != '/') - { - Rewind(); - } - else - { - comment = COMMENT_NONE; - continue; - } - } - } - - if(comment == COMMENT_NONE) - { - byte bc = ((byte)c); - - if(parserLocal.CharCode()[bc] != CHAR_SPECIAL) - { - switch(parserLocal.CharCode()[bc]) - { - case CHAR_NUMBER: - GetNumberToken(c); - return true; - case CHAR_LETTER: - GetLetterToken(c); - return true; - case CHAR_QUOTE: - GetStringToken(); - return true; - case CHAR_SYMBOL: - GetSymbolToken(c); - return true; - case CHAR_EOF: - tokentype = TK_EOF; -#ifdef SC_DEBUG - SC_DebugPrintf("EOF token\n"); -#endif - return true; - default: - break; - } - } - } - - if(c == '\n') - { - linepos++; - rowpos = 1; - - if(comment == COMMENT_SINGLELINE) - { - comment = COMMENT_NONE; - } - } - } - - return false; -} - -// -// kexLexer::GetChar -// - -char kexLexer::GetChar() -{ - int c; - -#ifdef SC_DEBUG - SC_DebugPrintf("(%s): get char\n", name); -#endif - - rowpos++; - c = buffer[buffpos++]; - - if(parserLocal.CharCode()[c] == CHAR_EOF) - { - c = 0; - } - -#ifdef SC_DEBUG - SC_DebugPrintf("get char: %i\n", c); -#endif - - return c; -} - -// -// kexLexer::Matches -// - -bool kexLexer::Matches(const char *string) -{ - return !strcmp(token, string); -} - -// -// kexLexer::Rewind -// - -void kexLexer::Rewind() -{ -#ifdef SC_DEBUG - SC_DebugPrintf("(%s): rewind\n", name); -#endif - - rowpos--; - buffpos--; -} - -// -// kexLexer::SkipLine -// - -void kexLexer::SkipLine() -{ -#ifdef SC_DEBUG - SC_DebugPrintf("SkipLine\n"); -#endif - - int curline = linepos; - - while(CheckState()) - { - Find(); - - if(curline != linepos) - { - return; - } - } -} - -// -// kexLexer::GetIDForTokenList -// - -int kexLexer::GetIDForTokenList(const sctokens *tokenlist, const char *token) -{ - int i; - for(i = 0; tokenlist[i].id != -1; i++) - { - if(tokenlist[i].token == NULL) - { - continue; - } - - if(!strcmp(token, tokenlist[i].token)) - { - return tokenlist[i].id; - } - } - - return i; -} - -// -// kexLexer::ExpectTokenListID -// - -void kexLexer::ExpectTokenListID(const sctokens *tokenlist, int id) -{ - Find(); - if(GetIDForTokenList(tokenlist, token) != id) - { - parserLocal.HandleError("Expected \"%s\" but found %s", - tokenlist[id].token, token); - } -} - -// -// kexLexer::AssignFromTokenList -// - -void kexLexer::AssignFromTokenList(const sctokens *tokenlist, char *str, int id, bool expect) -{ - if(expect) - { - ExpectTokenListID(tokenlist, id); - } - ExpectNextToken(TK_EQUAL); - GetString(); - strcpy(str, stringToken); -} - -// -// kexLexer::AssignFromTokenList -// - -void kexLexer::AssignFromTokenList(const sctokens *tokenlist, unsigned int *var, int id, bool expect) -{ - if(expect) - { - ExpectTokenListID(tokenlist, id); - } - ExpectNextToken(TK_EQUAL); - *var = GetNumber(); -} - -// -// kexLexer::AssignFromTokenList -// - -void kexLexer::AssignFromTokenList(const sctokens *tokenlist, unsigned short *var, int id, bool expect) -{ - if(expect) - { - ExpectTokenListID(tokenlist, id); - } - ExpectNextToken(TK_EQUAL); - *var = GetNumber(); -} - -// -// kexLexer::AssignFromTokenList -// - -void kexLexer::AssignFromTokenList(const sctokens *tokenlist, float *var, int id, bool expect) -{ - if(expect) - { - ExpectTokenListID(tokenlist, id); - } - ExpectNextToken(TK_EQUAL); - *var = (float)GetFloat(); -} - -// -// kexLexer::AssignVectorFromTokenList -// - -void kexLexer::AssignVectorFromTokenList(const sctokens *tokenlist, float *var, int id, bool expect) -{ - if(expect) - { - ExpectTokenListID(tokenlist, id); - } - ExpectNextToken(TK_EQUAL); - ExpectNextToken(TK_LBRACK); - var[0] = (float)GetFloat(); - var[1] = (float)GetFloat(); - var[2] = (float)GetFloat(); - ExpectNextToken(TK_RBRACK); -} - -// -// kexLexer::AssignFromTokenList -// - -void kexLexer::AssignFromTokenList(const sctokens *tokenlist, arraytype_t type, - void **data, int count, int id, bool expect, kexHeapBlock &hb) -{ - void *buf; - - if(expect) - { - ExpectTokenListID(tokenlist, id); - } - else if(count <= 0) - { - parserLocal.HandleError("Parsing \"%s\" array with count = 0", - tokenlist[id].token); - } - - ExpectNextToken(TK_EQUAL); - ExpectNextToken(TK_LBRACK); - - buf = NULL; - - if(count <= 0) - { - // skip null arrays. note that parser will assume a -1 followed by a - // closing bracket - - Find(); // skip the -1 number - ExpectNextToken(TK_RBRACK); - } - else - { - int i; - size_t len; - - switch(type) - { - case AT_SHORT: - len = sizeof(short); - break; - case AT_INTEGER: - len = sizeof(int); - break; - case AT_FLOAT: - len = sizeof(float); - break; - case AT_DOUBLE: - len = sizeof(double); - break; - case AT_VECTOR: - len = sizeof(float) * 3; - break; - default: - break; - } - - buf = (void*)Mem_Malloc(len * count, hb); - - switch(type) - { - case AT_SHORT: - { - word *wbuf = (word*)buf; - - for(i = 0; i < count; i++) - { - wbuf[i] = GetNumber(); - } - } - break; - case AT_INTEGER: - { - int *ibuf = (int*)buf; - - for(i = 0; i < count; i++) - { - ibuf[i] = GetNumber(); - } - } - break; - case AT_FLOAT: - { - float *fbuf = (float*)buf; - - for(i = 0; i < count; i++) - { - fbuf[i] = (float)GetFloat(); - } - } - break; - case AT_DOUBLE: - { - double *dbuf = (double*)buf; - - for(i = 0; i < count; i++) - { - dbuf[i] = GetFloat(); - } - } - break; - case AT_VECTOR: - { - float *fbuf = (float*)buf; - for(i = 0; i < count; i++) - { - fbuf[i * 3 + 0] = (float)GetFloat(); - fbuf[i * 3 + 1] = (float)GetFloat(); - fbuf[i * 3 + 2] = (float)GetFloat(); - } - } - break; - default: - break; - } - - ExpectNextToken(TK_RBRACK); - } - - *data = buf; -} - -// -// kexParser::kexParser -// - -kexParser::kexParser() -{ - int i; - - numNestedFilenames = 0; - numLexers = 0; - - for(i = 0; i < 256; i++) - { - charcode[i] = CHAR_SPECIAL; - } - for(i = '!'; i <= '~'; i++) - { - charcode[i] = CHAR_SYMBOL; - } - for(i = '0'; i <= '9'; i++) - { - charcode[i] = CHAR_NUMBER; - } - for(i = 'A'; i <= 'Z'; i++) - { - charcode[i] = CHAR_LETTER; - } - for(i = 'a'; i <= 'z'; i++) - { - charcode[i] = CHAR_LETTER; - } - - charcode['"'] = CHAR_QUOTE; - charcode['_'] = CHAR_LETTER; - charcode['-'] = CHAR_NUMBER; - charcode['.'] = CHAR_NUMBER; - charcode[127] = CHAR_EOF; -} - -// -// kexParser::~kexParser -// - -kexParser::~kexParser() -{ -} - -// -// kexParser::GetNestedFileName -// - -const char *kexParser::GetNestedFileName() const -{ - if(numNestedFilenames <= 0) - { - return NULL; - } - - return nestedFilenames[numNestedFilenames-1]; -} - -// -// kexParser::PushFileName -// - -void kexParser::PushFileName(const char *name) -{ -#ifdef SC_DEBUG - SC_DebugPrintf("push nested file %s\n", name); -#endif - strcpy(nestedFilenames[numNestedFilenames++], name); -} - -// -// kexParser::PopFileName -// - -void kexParser::PopFileName() -{ -#ifdef SC_DEBUG - SC_DebugPrintf("nested file pop\n"); -#endif - memset(nestedFilenames[--numNestedFilenames], 0, 256); -} - -// -// kexParser::PushLexer -// - -void kexParser::PushLexer(const char *filename, char *buf, int bufSize) -{ - if(numLexers >= MAX_NESTED_PARSERS) - { - Error("Reached max number of nested lexers (%i)", numLexers); - } - - lexers[numLexers] = new kexLexer(filename, buf, bufSize); - currentLexer = lexers[numLexers]; - - numLexers++; -} - -// -// kexParser::PopLexer -// - -void kexParser::PopLexer() -{ - delete lexers[--numLexers]; - if(numLexers <= 0) - { - currentLexer = NULL; - } - else - { - currentLexer = lexers[numLexers - 1]; - } -} - -// -// kexParser::HandleError -// - -void kexParser::HandleError(const char *msg, ...) -{ - char buf[1024]; - va_list v; - - va_start(v,msg); - vsprintf(buf,msg,v); - va_end(v); - - Error("%s : %s\n(line = %i, pos = %i)", - GetNestedFileName(), - buf, currentLexer->LinePos(), currentLexer->RowPos()); -} - -// -// kexParser::OpenExternalFile -// - -int kexParser::OpenExternalFile(const char *name, byte **buffer) const -{ - kexStr fPath; - FILE *fp; - - fPath = name; - fPath.NormalizeSlashes(); - - if((fp = fopen(fPath.c_str(), "rb"))) - { - size_t length; - - fseek(fp, 0, SEEK_END); - length = ftell(fp); - fseek(fp, 0, SEEK_SET); - - *buffer = (byte*)Mem_Calloc(length+1, hb_file); - - if(fread(*buffer, 1, length, fp) == length) - { - fclose(fp); - return length; - } - - Mem_Free(*buffer); - *buffer = NULL; - fclose(fp); - } - - return -1; -} - -// -// kexParser::Open -// - -kexLexer *kexParser::Open(const char* filename) -{ -#ifdef SC_DEBUG - SC_DebugPrintf("opening %s\n", filename); -#endif - - int buffsize; - byte *buffer; - - buffsize = OpenExternalFile(filename, (byte**)(&buffer)); - - if(buffsize <= 0) - { - printf("kexParser::Open: %s not found\n", filename); - return NULL; - } - - // push out a new lexer - PushLexer(filename, (char*)buffer, buffsize); - PushFileName(filename); - - return currentLexer; -} - -// -// kexParser::Close -// - -void kexParser::Close() -{ - PopLexer(); - PopFileName(); -} diff --git a/src/lightmap/kexlib/parser.h b/src/lightmap/kexlib/parser.h deleted file mode 100644 index c0024d2..0000000 --- a/src/lightmap/kexlib/parser.h +++ /dev/null @@ -1,172 +0,0 @@ -//----------------------------------------------------------------------------- -// Note: this is a modified version of dlight. It is not the original software. -//----------------------------------------------------------------------------- -// -// Copyright (c) 2013-2014 Samuel Villarreal -// svkaiser@gmail.com -// -// This software is provided 'as-is', without any express or implied -// warranty. In no event will the authors be held liable for any damages -// arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it -// freely, subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; you must not -// claim that you wrote the original software. If you use this software -// in a product, an acknowledgment in the product documentation would be -// appreciated but is not required. -// -// 2. Altered source versions must be plainly marked as such, and must not be -// misrepresented as being the original software. -// -// 3. This notice may not be removed or altered from any source -// distribution. -// - -#pragma once - -#define MAX_NESTED_PARSERS 128 -#define MAX_NESTED_FILENAMES 128 - -enum tokentype_t -{ - TK_NONE, - TK_NUMBER, - TK_STRING, - TK_POUND, - TK_COLON, - TK_SEMICOLON, - TK_PERIOD, - TK_QUOTE, - TK_FORWARDSLASH, - TK_EQUAL, - TK_LBRACK, - TK_RBRACK, - TK_LPAREN, - TK_RPAREN, - TK_LSQBRACK, - TK_RSQBRACK, - TK_COMMA, - TK_IDENIFIER, - TK_DEFINE, - TK_UNDEF, - TK_INCLUDE, - TK_SETDIR, - TK_EOF -}; - -enum arraytype_t -{ - AT_SHORT, - AT_INTEGER, - AT_FLOAT, - AT_DOUBLE, - AT_VECTOR -}; - -#define SC_TOKEN_LEN 512 - -struct sctokens -{ - int id; - const char *token; -}; - -class kexLexer -{ -public: - kexLexer(const char *filename, char *buf, int bufSize); - ~kexLexer(); - - bool CheckState(); - void CheckKeywords(); - void MustMatchToken(int type); - void ExpectNextToken(int type); - bool Find(); - char GetChar(); - void Rewind(); - void SkipLine(); - bool Matches(const char *string); - int GetNumber(); - double GetFloat(); - kexVec3 GetVector3(); - kexVec4 GetVector4(); - kexVec3 GetVectorString3(); - kexVec4 GetVectorString4(); - void GetString(); - int GetIDForTokenList(const sctokens *tokenlist, const char *token); - void ExpectTokenListID(const sctokens *tokenlist, int id); - void AssignFromTokenList(const sctokens *tokenlist, - char *str, int id, bool expect); - void AssignFromTokenList(const sctokens *tokenlist, - unsigned int *var, int id, bool expect); - void AssignFromTokenList(const sctokens *tokenlist, - unsigned short *var, int id, bool expect); - void AssignFromTokenList(const sctokens *tokenlist, - float *var, int id, bool expect); - void AssignVectorFromTokenList(const sctokens *tokenlist, - float *var, int id, bool expect); - void AssignFromTokenList(const sctokens *tokenlist, - arraytype_t type, void **data, int count, - int id, bool expect, kexHeapBlock &hb); - - int LinePos() { return linepos; } - int RowPos() { return rowpos; } - int BufferPos() { return buffpos; } - int BufferSize() { return buffsize; } - char *Buffer() { return buffer; } - char *StringToken() { return stringToken; } - const char *Token() const { return token; } - const int TokenType() const { return tokentype; } - -private: - void ClearToken(); - void GetNumberToken(char initial); - void GetLetterToken(char initial); - void GetSymbolToken(char c); - void GetStringToken(); - - char token[SC_TOKEN_LEN]; - char stringToken[MAX_FILEPATH]; - char* buffer; - char* pointer_start; - char* pointer_end; - int linepos; - int rowpos; - int buffpos; - int buffsize; - int tokentype; - const char *name; -}; - -class kexParser -{ -public: - kexParser(); - ~kexParser(); - - kexLexer *Open(const char *filename); - void Close(); - void HandleError(const char *msg, ...); - void PushLexer(const char *filename, char *buf, int bufSize); - void PopLexer(); - void PushFileName(const char *name); - void PopFileName(); - byte *CharCode() { return charcode; } - const kexLexer *CurrentLexer() const { return currentLexer; } - -private: - int OpenExternalFile(const char *name, byte **buffer) const; - const char *GetNestedFileName() const; - - kexLexer *currentLexer; - kexLexer *lexers[MAX_NESTED_PARSERS]; - int numLexers; - byte charcode[256]; - char nestedFilenames[MAX_NESTED_FILENAMES][MAX_FILEPATH]; - int numNestedFilenames; -}; - -extern kexParser *parser; diff --git a/src/lightmap/mapdata.cpp b/src/lightmap/mapdata.cpp index 69ea1ac..b8451b7 100644 --- a/src/lightmap/mapdata.cpp +++ b/src/lightmap/mapdata.cpp @@ -32,7 +32,6 @@ #include "common.h" #include "wad.h" -#include "kexlib/parser.h" #include "mapdata.h" #include "lightsurface.h" @@ -41,18 +40,6 @@ static const kexVec3 defaultSunDirection(0.45f, 0.3f, 0.9f); void FLevel::SetupDlight() { - /* - for (unsigned int i = 0; i < mapDefs.Size(); ++i) - { - if (mapDefs[i].map == wadFile.currentmap) - { - mapDef = &mapDefs[i]; - break; - } - } - */ - //mapDef = &mapDefs[0]; - BuildNodeBounds(); BuildLeafs(); BuildPVS(); @@ -169,10 +156,8 @@ void FLevel::CheckSkySectors() for (int i = 0; i < (int)Sectors.Size(); ++i) { - if (mapDef && mapDef->sunIgnoreTag != 0 && Sectors[i].data.tag == mapDef->sunIgnoreTag) - { - continue; - } + //if (mapDef && mapDef->sunIgnoreTag != 0 && Sectors[i].data.tag == mapDef->sunIgnoreTag) + // continue; strncpy(name, Sectors[i].data.ceilingpic, 8); name[8] = 0; @@ -207,21 +192,11 @@ void FLevel::CheckSkySectors() const kexVec3 &FLevel::GetSunColor() const { - if (mapDef != NULL) - { - return mapDef->sunColor; - } - return defaultSunColor; } const kexVec3 &FLevel::GetSunDirection() const { - if (mapDef != NULL) - { - return mapDef->sunDir; - } - return defaultSunDirection; } @@ -458,187 +433,8 @@ bool FLevel::CheckPVS(MapSubsectorEx *s1, MapSubsectorEx *s2) return ((vis[n2 >> 3] & (1 << (n2 & 7))) != 0); } -void FLevel::ParseConfigFile(const char *file) -{ - kexLexer *lexer; - - if (!(lexer = parser->Open(file))) - { - Error("FLevel::ParseConfigFile: %s not found\n", file); - return; - } - - while (lexer->CheckState()) - { - lexer->Find(); - - // check for mapdef block - if (lexer->Matches("mapdef")) - { - mapDef_t mapDef; - - mapDef.map = -1; - mapDef.sunIgnoreTag = 0; - - lexer->ExpectNextToken(TK_LBRACK); - lexer->Find(); - - while (lexer->TokenType() != TK_RBRACK) - { - if (lexer->Matches("map")) - { - mapDef.map = lexer->GetNumber(); - } - else if (lexer->Matches("sun_ignore_tag")) - { - mapDef.sunIgnoreTag = lexer->GetNumber(); - } - else if (lexer->Matches("sun_direction")) - { - mapDef.sunDir = lexer->GetVectorString3(); - } - else if (lexer->Matches("sun_color")) - { - mapDef.sunColor = lexer->GetVectorString3(); - mapDef.sunColor /= 255.0f; - } - - lexer->Find(); - } - - mapDefs.Push(mapDef); - } - - // check for lightdef block - if (lexer->Matches("lightdef")) - { - lightDef_t lightDef; - - lightDef.doomednum = -1; - lightDef.height = 0; - lightDef.intensity = 2; - lightDef.falloff = 1; - lightDef.bCeiling = false; - - lexer->ExpectNextToken(TK_LBRACK); - lexer->Find(); - - while (lexer->TokenType() != TK_RBRACK) - { - if (lexer->Matches("doomednum")) - { - lightDef.doomednum = lexer->GetNumber(); - } - else if (lexer->Matches("rgb")) - { - lightDef.rgb = lexer->GetVectorString3(); - lightDef.rgb /= 255.0f; - } - else if (lexer->Matches("height")) - { - lightDef.height = (float)lexer->GetFloat(); - } - else if (lexer->Matches("radius")) - { - lightDef.radius = (float)lexer->GetFloat(); - } - else if (lexer->Matches("intensity")) - { - lightDef.intensity = (float)lexer->GetFloat(); - } - else if (lexer->Matches("falloff")) - { - lightDef.falloff = (float)lexer->GetFloat(); - } - else if (lexer->Matches("ceiling")) - { - lightDef.bCeiling = true; - } - - lexer->Find(); - } - - lightDefs.Push(lightDef); - } - - if (lexer->Matches("surfaceLight")) - { - surfaceLightDef surfaceLight; - - surfaceLight.tag = 0; - surfaceLight.outerCone = 0.0f; - surfaceLight.innerCone = 0.0f; - surfaceLight.falloff = 1.0f; - surfaceLight.intensity = 1.0f; - surfaceLight.distance = 400.0f; - surfaceLight.bIgnoreCeiling = false; - surfaceLight.bIgnoreFloor = false; - surfaceLight.bNoCenterPoint = false; - surfaceLight.rgb.x = 1.0f; - surfaceLight.rgb.y = 1.0f; - surfaceLight.rgb.z = 1.0f; - - lexer->ExpectNextToken(TK_LBRACK); - lexer->Find(); - - while (lexer->TokenType() != TK_RBRACK) - { - if (lexer->Matches("tag")) - { - surfaceLight.tag = lexer->GetNumber(); - } - else if (lexer->Matches("rgb")) - { - surfaceLight.rgb = lexer->GetVectorString3(); - surfaceLight.rgb /= 255.0f; - } - else if (lexer->Matches("cone_outer")) - { - surfaceLight.outerCone = (float)lexer->GetFloat() / 180.0f; - } - else if (lexer->Matches("cone_inner")) - { - surfaceLight.innerCone = (float)lexer->GetFloat() / 180.0f; - } - else if (lexer->Matches("falloff")) - { - surfaceLight.falloff = (float)lexer->GetFloat(); - } - else if (lexer->Matches("intensity")) - { - surfaceLight.intensity = (float)lexer->GetFloat(); - } - else if (lexer->Matches("distance")) - { - surfaceLight.distance = (float)lexer->GetFloat(); - } - else if (lexer->Matches("bIgnoreCeiling")) - { - surfaceLight.bIgnoreCeiling = true; - } - else if (lexer->Matches("bIgnoreFloor")) - { - surfaceLight.bIgnoreFloor = true; - } - else if (lexer->Matches("bNoCenterPoint")) - { - surfaceLight.bNoCenterPoint = true; - } - - lexer->Find(); - } - - surfaceLightDefs.Push(surfaceLight); - } - } - - // we're done with the file - parser->Close(); -} - void FLevel::CreateLights() { - IntThing *thing; thingLight_t *thingLight; unsigned int j; int numSurfLights; @@ -649,50 +445,51 @@ void FLevel::CreateLights() // for (int i = 0; i < (int)Things.Size(); ++i) { - lightDef_t *lightDef = NULL; + IntThing *thing = &Things[i]; - thing = &Things[i]; + uint32_t lightcolor = 0xffffff; + float lightintensity = 1.0f; + float lightdistance = 0.0f; - for (j = 0; j < (int)lightDefs.Size(); ++j) + for (unsigned int propIndex = 0; propIndex < thing->props.Size(); propIndex++) { - if (thing->type == lightDefs[j].doomednum) + const UDMFKey &key = thing->props[propIndex]; + if (!stricmp(key.key, "lightcolor")) { - lightDef = &lightDefs[j]; - break; + lightcolor = atoi(key.value); + } + else if (!stricmp(key.key, "lightintensity")) + { + lightintensity = atof(key.value); + } + else if (!stricmp(key.key, "lightdistance")) + { + lightdistance = atof(key.value); } } - if (!lightDef) + if (lightdistance > 0.0f && lightintensity > 0.0f && lightcolor != 0) { - continue; + int x = thing->x >> FRACBITS; + int y = thing->y >> FRACBITS; + + thingLight = new thingLight_t(); + + thingLight->mapThing = thing; + thingLight->rgb.x = ((lightcolor >> 16) & 0xff) / 255.0f; + thingLight->rgb.y = ((lightcolor >> 8) & 0xff) / 255.0f; + thingLight->rgb.z = (lightcolor & 0xff) / 255.0f; + thingLight->intensity = lightintensity; + thingLight->falloff = 1.0f; + thingLight->radius = lightdistance; + thingLight->height = thing->height; + thingLight->bCeiling = false; + thingLight->ssect = PointInSubSector(x, y); + thingLight->sector = GetSectorFromSubSector(thingLight->ssect); + + thingLight->origin.Set(x, y); + thingLights.Push(thingLight); } - - if (lightDef->radius >= 0) - { - // ignore if all skills aren't set - if (!(thing->flags & 7)) - { - continue; - } - } - - int x = thing->x >> FRACBITS; - int y = thing->y >> FRACBITS; - - thingLight = new thingLight_t; - - thingLight->mapThing = thing; - thingLight->rgb = lightDef->rgb; - thingLight->intensity = lightDef->intensity; - thingLight->falloff = lightDef->falloff; - thingLight->radius = lightDef->radius >= 0 ? lightDef->radius : thing->angle; - thingLight->height = lightDef->height; - thingLight->bCeiling = lightDef->bCeiling; - thingLight->ssect = PointInSubSector(x, y); - thingLight->sector = GetSectorFromSubSector(thingLight->ssect); - - thingLight->origin.Set(x, y); - thingLights.Push(thingLight); } printf("Thing lights: %i\n", thingLights.Size()); @@ -706,50 +503,123 @@ void FLevel::CreateLights() { surface_t *surface = surfaces[j]; - for (unsigned int k = 0; k < surfaceLightDefs.Size(); ++k) + if (surface->type >= ST_MIDDLESEG && surface->type <= ST_LOWERSEG) { - surfaceLightDef *surfaceLightDef = &surfaceLightDefs[k]; + IntLineDef *line = nullptr; + if (GLSegs[surface->typeIndex].linedef != NO_LINE_INDEX) + line = &Lines[GLSegs[surface->typeIndex].linedef]; - if (surface->type >= ST_MIDDLESEG && surface->type <= ST_LOWERSEG) + if (line) { - MapSegGLEx *seg = (MapSegGLEx*)surface->data; + uint32_t lightcolor = 0xffffff; + float lightintensity = 1.0f; + float lightdistance = 0.0f; - if (Lines[seg->linedef].args[1] == surfaceLightDef->tag) + for (unsigned int propIndex = 0; propIndex < line->props.Size(); propIndex++) { - kexLightSurface *lightSurface = new kexLightSurface; + const UDMFKey &key = line->props[propIndex]; + if (!stricmp(key.key, "lightcolor")) + { + lightcolor = atoi(key.value); + } + else if (!stricmp(key.key, "lightintensity")) + { + lightintensity = atof(key.value); + } + else if (!stricmp(key.key, "lightdistance")) + { + lightdistance = atof(key.value); + } + } - lightSurface->Init(*surfaceLightDef, surface, true, false); + if (lightdistance > 0.0f && lightintensity > 0.0f && lightcolor != 0) + { + surfaceLightDef desc; + desc.tag = 0; + desc.outerCone = 0.0f; + desc.innerCone = 0.0f; + desc.falloff = 1.0f; + desc.intensity = lightintensity; + desc.distance = lightdistance; + desc.bIgnoreCeiling = false; + desc.bIgnoreFloor = false; + desc.bNoCenterPoint = false; + desc.rgb.x = ((lightcolor >> 16) & 0xff) / 255.0f; + desc.rgb.y = ((lightcolor >> 8) & 0xff) / 255.0f; + desc.rgb.z = (lightcolor & 0xff) / 255.0f; + + kexLightSurface *lightSurface = new kexLightSurface(); + lightSurface->Init(desc, surface, true, false); lightSurface->CreateCenterOrigin(); lightSurfaces.Push(lightSurface); numSurfLights++; } } - else + } + else if (surface->type == ST_FLOOR || surface->type == ST_CEILING) + { + MapSubsectorEx *sub = surface->subSector; + IntSector *sector = GetSectorFromSubSector(sub); + + if (sector && surface->numVerts > 0) { - MapSubsectorEx *sub = surface->subSector; - IntSector *sector = GetSectorFromSubSector(sub); + uint32_t lightcolor = 0xffffff; + float lightintensity = 1.0f; + float lightdistance = 0.0f; - if (!sector || surface->numVerts <= 0) + for (unsigned int propIndex = 0; propIndex < sector->props.Size(); propIndex++) { - // eh.... - continue; + const UDMFKey &key = sector->props[propIndex]; + if (surface->type == ST_FLOOR) + { + if (!stricmp(key.key, "lightcolorfloor")) + { + lightcolor = atoi(key.value); + } + else if (!stricmp(key.key, "lightintensityfloor")) + { + lightintensity = atof(key.value); + } + else if (!stricmp(key.key, "lightdistancefloor")) + { + lightdistance = atof(key.value); + } + } + else + { + if (!stricmp(key.key, "lightcolorceiling")) + { + lightcolor = atoi(key.value); + } + else if (!stricmp(key.key, "lightintensityceiling")) + { + lightintensity = atof(key.value); + } + else if (!stricmp(key.key, "lightdistanceceiling")) + { + lightdistance = atof(key.value); + } + } } - if (surface->type == ST_CEILING && surfaceLightDef->bIgnoreCeiling) + if (lightdistance > 0.0f && lightintensity > 0.0f && lightcolor != 0) { - continue; - } + surfaceLightDef desc; + desc.tag = 0; + desc.outerCone = 0.0f; + desc.innerCone = 0.0f; + desc.falloff = 1.0f; + desc.intensity = lightintensity; + desc.distance = lightdistance; + desc.bIgnoreCeiling = false; + desc.bIgnoreFloor = false; + desc.bNoCenterPoint = false; + desc.rgb.x = ((lightcolor >> 16) & 0xff) / 255.0f; + desc.rgb.y = ((lightcolor >> 8) & 0xff) / 255.0f; + desc.rgb.z = (lightcolor & 0xff) / 255.0f; - if (surface->type == ST_FLOOR && surfaceLightDef->bIgnoreFloor) - { - continue; - } - - if (sector->data.tag == surfaceLightDef->tag) - { - kexLightSurface *lightSurface = new kexLightSurface; - - lightSurface->Init(*surfaceLightDef, surface, false, surfaceLightDef->bNoCenterPoint); + kexLightSurface *lightSurface = new kexLightSurface(); + lightSurface->Init(desc, surface, false, desc.bNoCenterPoint); lightSurface->Subdivide(16); lightSurfaces.Push(lightSurface); numSurfLights++; diff --git a/src/main.cpp b/src/main.cpp index 3d26ed5..b30bb1e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -242,7 +242,7 @@ int main(int argc, char **argv) START_COUNTER(t2a, t2b, t2c) FProcessor builder(inwad, lump); builder.BuildNodes(); - builder.BuildLightmaps("lightconfig.txt"); + builder.BuildLightmaps(); builder.Write(outwad); END_COUNTER(t2a, t2b, t2c, " %.3f seconds.\n")