From ac74993903ec47cfdb834be6b8ef0a8ecc925211 Mon Sep 17 00:00:00 2001 From: Roman Fomin Date: Fri, 16 Dec 2022 22:49:51 +0700 Subject: [PATCH 01/26] support BRGHTMPS lump from Doom Retro --- src/r_bmaps.c | 170 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 170 insertions(+) diff --git a/src/r_bmaps.c b/src/r_bmaps.c index 6375b656b..ace7014b1 100644 --- a/src/r_bmaps.c +++ b/src/r_bmaps.c @@ -23,6 +23,8 @@ #include "doomstat.h" #include "r_data.h" #include "w_wad.h" +#include "m_misc2.h" +#include "u_scanner.h" int brightmaps; @@ -817,6 +819,11 @@ static const byte *R_BrightmapForSprite_Hacx (const int type) return nobrightmap; } +static const byte *R_BrightmapForSprite_None (const int type) +{ + return nobrightmap; +} + // [crispy] brightmaps for flats static int bmapflatnum[12]; @@ -934,8 +941,171 @@ const byte *(*R_BrightmapForSprite) (const int type); const byte *(*R_BrightmapForFlatNum) (const int num); const byte *(*R_BrightmapForState) (const int state); +#define COLORMASK_SIZE 256 +typedef struct { + char *name; + byte colormask[COLORMASK_SIZE]; +} brightmap_t; + +static void ReadColormask(u_scanner_t *s, byte *colormask) +{ + memset(colormask, 0, COLORMASK_SIZE); + do + { + unsigned int color1 = 0, color2 = 0; + + if (U_CheckInteger(s)) + { + color1 = s->number; + if (color1 >= 0 && color1 < COLORMASK_SIZE) + colormask[color1] = 1; + } + + if (!U_CheckToken(s, '-')) + continue; + + if (U_CheckInteger(s)) + { + int i; + color2 = s->number; + if (color2 >= 0 && color2 < COLORMASK_SIZE) + { + for (i = color1 + 1; i <= color2; ++i) + colormask[i] = 1; + } + } + } while (U_CheckToken(s, ',')); +} + +#define BRIGHTMAPS_INITIAL_SIZE 32 +static brightmap_t *brightmaps_array; +static int num_brightmaps; + +static void AddBrightmap(brightmap_t *brightmap) +{ + static int size; + + if (num_brightmaps >= size) + { + size = (size ? size * 2 : BRIGHTMAPS_INITIAL_SIZE); + brightmaps_array = I_Realloc(brightmaps_array, + size * sizeof(brightmap_t)); + } + + memcpy(brightmaps_array + num_brightmaps, brightmap, sizeof(brightmap_t)); + num_brightmaps++; +} + +static void ScanBrightmaps(void *data, int length) +{ + u_scanner_t scanner, *s; + scanner = U_ScanOpen(data, length, "BRGHTMPS"); + s = &scanner; + brightmap_t brightmap; + while (U_HasTokensLeft(s)) + { + U_MustGetToken(s, TK_Identifier); + if (strcasecmp("BRIGHTMAP", s->string)) + { + U_GetNextLineToken(s); + continue; + } + U_MustGetToken(s, TK_Identifier); + brightmap.name = M_StringDuplicate(s->string); + ReadColormask(s, brightmap.colormask); + AddBrightmap(&brightmap); + } + U_ScanClose(s); +} + +typedef struct { + brightmap_t *brightmap; + char *name; +} texture_bm_t; + +#define TEXTURES_INITIAL_SIZE 32 +static texture_bm_t *textures; +static int num_textures; + +static void AddTexture(texture_bm_t *texture) +{ + static int size; + + if (num_textures >= size) + { + size = (size ? size * 2 : TEXTURES_INITIAL_SIZE); + textures = I_Realloc(textures, size * sizeof(texture_bm_t)); + } + + memcpy(textures + num_textures, texture, sizeof(texture_bm_t)); + num_textures++; +} + +static void ScanTextures(void *data, int length) +{ + int i; + u_scanner_t scanner, *s; + texture_bm_t texture; + + scanner = U_ScanOpen(data, length, "BRGHTMPS"); + s = &scanner; + while (U_HasTokensLeft(s)) + { + U_MustGetToken(s, TK_Identifier); + if (strcasecmp("TEXTURE", s->string)) + { + U_GetNextLineToken(s); + continue; + } + U_MustGetToken(s, TK_Identifier); + texture.name = M_StringDuplicate(s->string); + U_MustGetToken(s, TK_Identifier); + for (int i = 0; i < num_brightmaps; ++i) + { + if (!strcasecmp(brightmaps_array[i].name, s->string)) + { + texture.brightmap = &brightmaps_array[i]; + AddTexture(&texture); + break; + } + } + U_GetNextLineToken(s); // skip DOOM1|DOOM2 + } + U_ScanClose(s); +} + +static const byte *R_BrightmapForTexName_Lump(const char *texname) +{ + int i; + + for (i = 0; i < num_textures; i++) + { + if (!strncasecmp(textures[i].name, texname, 8)) + { + return textures[i].brightmap->colormask; + } + } + + return nobrightmap; +} + void R_InitBrightmaps () { + int lump = W_CheckNumForName("BRGHTMPS"); + if (lump >= 0) + { + void *data = W_CacheLumpNum(lump, PU_CACHE); + int length = W_LumpLength(lump); + ScanBrightmaps(data, length); + ScanTextures(data, length); + + R_BrightmapForTexName = R_BrightmapForTexName_Lump; + R_BrightmapForSprite = R_BrightmapForSprite_None; + R_BrightmapForFlatNum = R_BrightmapForFlatNum_None; + R_BrightmapForState = R_BrightmapForState_None; + return; + } + if (gamemission == pack_hacx) { bmapflatnum[0] = R_FlatNumForName("FLOOR1_1"); From db19de538252fd7e6ccf397b5bf74c87d12f1a66 Mon Sep 17 00:00:00 2001 From: Roman Fomin Date: Fri, 16 Dec 2022 23:01:19 +0700 Subject: [PATCH 02/26] fix gcc build --- src/r_bmaps.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/r_bmaps.c b/src/r_bmaps.c index ace7014b1..e470f61d9 100644 --- a/src/r_bmaps.c +++ b/src/r_bmaps.c @@ -999,9 +999,10 @@ static void AddBrightmap(brightmap_t *brightmap) static void ScanBrightmaps(void *data, int length) { u_scanner_t scanner, *s; + brightmap_t brightmap; + scanner = U_ScanOpen(data, length, "BRGHTMPS"); s = &scanner; - brightmap_t brightmap; while (U_HasTokensLeft(s)) { U_MustGetToken(s, TK_Identifier); @@ -1043,7 +1044,6 @@ static void AddTexture(texture_bm_t *texture) static void ScanTextures(void *data, int length) { - int i; u_scanner_t scanner, *s; texture_bm_t texture; From f53ea89c060757617417fa07044ed94ce525c639 Mon Sep 17 00:00:00 2001 From: Roman Fomin Date: Fri, 16 Dec 2022 23:33:51 +0700 Subject: [PATCH 03/26] fix declarations --- src/r_bmaps.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/r_bmaps.c b/src/r_bmaps.c index e470f61d9..d98b5888e 100644 --- a/src/r_bmaps.c +++ b/src/r_bmaps.c @@ -966,10 +966,10 @@ static void ReadColormask(u_scanner_t *s, byte *colormask) if (U_CheckInteger(s)) { - int i; color2 = s->number; if (color2 >= 0 && color2 < COLORMASK_SIZE) { + int i; for (i = color1 + 1; i <= color2; ++i) colormask[i] = 1; } @@ -1044,6 +1044,7 @@ static void AddTexture(texture_bm_t *texture) static void ScanTextures(void *data, int length) { + int i; u_scanner_t scanner, *s; texture_bm_t texture; @@ -1060,7 +1061,7 @@ static void ScanTextures(void *data, int length) U_MustGetToken(s, TK_Identifier); texture.name = M_StringDuplicate(s->string); U_MustGetToken(s, TK_Identifier); - for (int i = 0; i < num_brightmaps; ++i) + for (i = 0; i < num_brightmaps; ++i) { if (!strcasecmp(brightmaps_array[i].name, s->string)) { From e8a86c96d1bff7039b9b277d11ffb356621794cf Mon Sep 17 00:00:00 2001 From: Roman Fomin Date: Sat, 17 Dec 2022 00:06:22 +0700 Subject: [PATCH 04/26] add `const` --- src/r_bmaps.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/r_bmaps.c b/src/r_bmaps.c index d98b5888e..cfd234cec 100644 --- a/src/r_bmaps.c +++ b/src/r_bmaps.c @@ -943,7 +943,7 @@ const byte *(*R_BrightmapForState) (const int state); #define COLORMASK_SIZE 256 typedef struct { - char *name; + const char *name; byte colormask[COLORMASK_SIZE]; } brightmap_t; @@ -996,7 +996,7 @@ static void AddBrightmap(brightmap_t *brightmap) num_brightmaps++; } -static void ScanBrightmaps(void *data, int length) +static void ScanBrightmaps(const char *data, int length) { u_scanner_t scanner, *s; brightmap_t brightmap; @@ -1021,7 +1021,7 @@ static void ScanBrightmaps(void *data, int length) typedef struct { brightmap_t *brightmap; - char *name; + const char *name; } texture_bm_t; #define TEXTURES_INITIAL_SIZE 32 @@ -1042,7 +1042,7 @@ static void AddTexture(texture_bm_t *texture) num_textures++; } -static void ScanTextures(void *data, int length) +static void ScanTextures(const char *data, int length) { int i; u_scanner_t scanner, *s; @@ -1095,7 +1095,7 @@ void R_InitBrightmaps () int lump = W_CheckNumForName("BRGHTMPS"); if (lump >= 0) { - void *data = W_CacheLumpNum(lump, PU_CACHE); + const char *data = W_CacheLumpNum(lump, PU_CACHE); int length = W_LumpLength(lump); ScanBrightmaps(data, length); ScanTextures(data, length); From b694f5a685719dc1ed2bf8816dcf423fe8e8a250 Mon Sep 17 00:00:00 2001 From: Roman Fomin Date: Sun, 18 Dec 2022 23:33:57 +0700 Subject: [PATCH 05/26] fix skipping optional `DOOM1|DOOM2` flags --- src/r_bmaps.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/r_bmaps.c b/src/r_bmaps.c index cfd234cec..e3d842d1a 100644 --- a/src/r_bmaps.c +++ b/src/r_bmaps.c @@ -1052,8 +1052,7 @@ static void ScanTextures(const char *data, int length) s = &scanner; while (U_HasTokensLeft(s)) { - U_MustGetToken(s, TK_Identifier); - if (strcasecmp("TEXTURE", s->string)) + if (!U_CheckToken(s, TK_Identifier) || strcasecmp("TEXTURE", s->string)) { U_GetNextLineToken(s); continue; @@ -1070,7 +1069,7 @@ static void ScanTextures(const char *data, int length) break; } } - U_GetNextLineToken(s); // skip DOOM1|DOOM2 + // skip DOOM1|DOOM2 } U_ScanClose(s); } From 95bd8e674ad5d902e6a649145919134bcb42fe7b Mon Sep 17 00:00:00 2001 From: Roman Fomin Date: Sun, 18 Dec 2022 23:42:08 +0700 Subject: [PATCH 06/26] u_scanner: make internal functions `static` --- src/u_scanner.c | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/src/u_scanner.c b/src/u_scanner.c index 133d6bf06..c82fed1b1 100644 --- a/src/u_scanner.c +++ b/src/u_scanner.c @@ -35,7 +35,7 @@ #include "m_misc2.h" #include "u_scanner.h" -const char* U_TokenNames[TK_NumSpecialTokens] = +static const char* U_TokenNames[TK_NumSpecialTokens] = { "Identifier", // case insensitive identifier, beginning with a letter and may contain [a-z0-9_] "String Constant", @@ -52,10 +52,10 @@ const char* U_TokenNames[TK_NumSpecialTokens] = "Right Shift" }; -void U_CheckForWhitespace(u_scanner_t* scanner); -void U_ExpandState(u_scanner_t* scanner); -void U_Unescape(char *str); -void U_SetString(char **ptr, const char *start, int length); +static void U_CheckForWhitespace(u_scanner_t* scanner); +static void U_ExpandState(u_scanner_t* scanner); +static void U_Unescape(char *str); +static void U_SetString(char **ptr, const char *start, int length); u_scanner_t U_ScanOpen(const char* data, int length, const char* name) { @@ -86,13 +86,13 @@ void U_ScanClose(u_scanner_t* scanner) free(scanner->data); } -void U_IncrementLine(u_scanner_t* scanner) +static void U_IncrementLine(u_scanner_t* scanner) { scanner->line++; scanner->lineStart = scanner->scanPos; } -void U_CheckForWhitespace(u_scanner_t* scanner) +static void U_CheckForWhitespace(u_scanner_t* scanner) { int comment = 0; // 1 = till next new line, 2 = till end block while(scanner->scanPos < scanner->length) @@ -180,7 +180,7 @@ boolean U_CheckToken(u_scanner_t* s, char token) return false; } -void U_ExpandState(u_scanner_t* s) +static void U_ExpandState(u_scanner_t* s) { s->logicalPosition = s->scanPos; U_CheckForWhitespace(s); @@ -194,7 +194,7 @@ void U_ExpandState(u_scanner_t* s) s->tokenLinePosition = s->nextState.tokenLinePosition; } -void U_SaveState(u_scanner_t* s, u_scanner_t savedstate) +static void U_SaveState(u_scanner_t* s, u_scanner_t savedstate) { // This saves the entire parser state except for the data pointer. if (savedstate.string != NULL) free(savedstate.string); @@ -206,7 +206,7 @@ void U_SaveState(u_scanner_t* s, u_scanner_t savedstate) savedstate.data = NULL; } -void U_RestoreState(u_scanner_t* s, u_scanner_t savedstate) +static void U_RestoreState(u_scanner_t* s, u_scanner_t savedstate) { if (savedstate.data == NULL) { @@ -465,7 +465,7 @@ boolean U_GetNextLineToken(u_scanner_t* scanner) } -void U_ErrorToken(u_scanner_t* s, int token) +static void U_ErrorToken(u_scanner_t* s, int token) { if (token < TK_NumSpecialTokens && s->token >= TK_Identifier && s->token < TK_NumSpecialTokens) U_Error(s, "Expected %s but got %s '%s' instead.", U_TokenNames[token], U_TokenNames[(int)s->token], s->string); @@ -479,7 +479,7 @@ void U_ErrorToken(u_scanner_t* s, int token) U_Error(s, "Expected '%c' but got '%c' instead.", token, s->token); } -void U_ErrorString(u_scanner_t* s, const char *mustget) +static void U_ErrorString(u_scanner_t* s, const char *mustget) { if (s->token < TK_NumSpecialTokens) U_Error(s, "Expected '%s' but got %s '%s' instead.", mustget, U_TokenNames[(int)s->token], s->string); @@ -518,8 +518,9 @@ boolean U_MustGetIdentifier(u_scanner_t* s, const char *ident) return true; } -// Convenience helpers that parse an entire number including a leading minus or plus sign -boolean U_ScanInteger(u_scanner_t* s) +// Convenience helpers that parse an entire number including a leading minus or +// plus sign +static boolean U_ScanInteger(u_scanner_t* s) { boolean neg = false; if (!U_GetNextToken(s, true)) @@ -553,7 +554,7 @@ boolean U_ScanInteger(u_scanner_t* s) return true; } -boolean U_ScanFloat(u_scanner_t* s) +static boolean U_ScanFloat(u_scanner_t* s) { boolean neg = false; if (!U_GetNextToken(s, true)) @@ -635,7 +636,8 @@ boolean U_HasTokensLeft(u_scanner_t* s) return (s->scanPos < s->length); } -// This is taken from ZDoom's strbin function which can do a lot more than just unescaping backslashes and quotation marks. +// This is taken from ZDoom's strbin function which can do a lot more than just +// unescaping backslashes and quotation marks. void U_Unescape(char *str) { char *p = str, c; @@ -725,7 +727,7 @@ void U_Unescape(char *str) *str = 0; } -void U_SetString(char **ptr, const char *start, int length) +static void U_SetString(char **ptr, const char *start, int length) { if (length == -1) length = strlen(start); From 199850d58782218b95c951d2110b444fd901ff72 Mon Sep 17 00:00:00 2001 From: Roman Fomin Date: Sun, 18 Dec 2022 23:48:26 +0700 Subject: [PATCH 07/26] fix `static` declarations --- src/u_scanner.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/u_scanner.c b/src/u_scanner.c index c82fed1b1..b1229627b 100644 --- a/src/u_scanner.c +++ b/src/u_scanner.c @@ -465,7 +465,7 @@ boolean U_GetNextLineToken(u_scanner_t* scanner) } -static void U_ErrorToken(u_scanner_t* s, int token) +void U_ErrorToken(u_scanner_t* s, int token) { if (token < TK_NumSpecialTokens && s->token >= TK_Identifier && s->token < TK_NumSpecialTokens) U_Error(s, "Expected %s but got %s '%s' instead.", U_TokenNames[token], U_TokenNames[(int)s->token], s->string); @@ -479,7 +479,7 @@ static void U_ErrorToken(u_scanner_t* s, int token) U_Error(s, "Expected '%c' but got '%c' instead.", token, s->token); } -static void U_ErrorString(u_scanner_t* s, const char *mustget) +void U_ErrorString(u_scanner_t* s, const char *mustget) { if (s->token < TK_NumSpecialTokens) U_Error(s, "Expected '%s' but got %s '%s' instead.", mustget, U_TokenNames[(int)s->token], s->string); From ad7c367e7a08ab06224356bfb557f38ce9ecc1a9 Mon Sep 17 00:00:00 2001 From: Roman Fomin Date: Mon, 19 Dec 2022 10:53:14 +0700 Subject: [PATCH 08/26] add support for `SPRITE` and `FLAT` --- src/r_bmaps.c | 171 ++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 144 insertions(+), 27 deletions(-) diff --git a/src/r_bmaps.c b/src/r_bmaps.c index e3d842d1a..80c55992a 100644 --- a/src/r_bmaps.c +++ b/src/r_bmaps.c @@ -1025,51 +1025,138 @@ typedef struct { } texture_bm_t; #define TEXTURES_INITIAL_SIZE 32 -static texture_bm_t *textures; -static int num_textures; +static texture_bm_t *textures_bm; +static int num_textures_bm; -static void AddTexture(texture_bm_t *texture) +static void AddTexture(const char *name, brightmap_t *brightmap) { static int size; + texture_bm_t texture; + + texture.name = M_StringDuplicate(name); + texture.brightmap = brightmap; - if (num_textures >= size) + if (num_textures_bm >= size) { size = (size ? size * 2 : TEXTURES_INITIAL_SIZE); - textures = I_Realloc(textures, size * sizeof(texture_bm_t)); + textures_bm = I_Realloc(textures_bm, size * sizeof(texture_bm_t)); + } + + textures_bm[num_textures_bm++] = texture; +} + +typedef struct +{ + brightmap_t *brightmap; + int type; +} sprite_bm_t; + +#define SPRITES_INITIAL_SIZE 32 +static sprite_bm_t *sprites_bm; +static int num_sprites_bm; + +static void AddSprite(const char *name, brightmap_t *brightmap) +{ + int i; + static int size; + sprite_bm_t sprite; + + for (i = 0; i < num_sprites; ++i) + { + if (!strcasecmp(name, sprnames[i])) + break; + } + if (i == num_sprites) + return; + + sprite.type = i; + sprite.brightmap = brightmap; + + if (num_sprites_bm >= size) + { + size = (size ? size * 2 : SPRITES_INITIAL_SIZE); + sprites_bm = I_Realloc(sprites_bm, size * sizeof(sprite_bm_t)); + } + + sprites_bm[num_sprites_bm++] = sprite; +} + +typedef struct +{ + brightmap_t *brightmap; + int num; +} flat_bm_t; + +#define FLATS_INITIAL_SIZE 32 +static flat_bm_t *flats_bm; +static int num_flats_bm; + +static void AddFlat(const char *name, brightmap_t *brightmap) +{ + static int size; + flat_bm_t flat; + + flat.num = R_FlatNumForName(name); + flat.brightmap = brightmap; + + if (num_flats_bm >= size) + { + size = (size ? size * 2 : SPRITES_INITIAL_SIZE); + flats_bm = I_Realloc(flats_bm, size * sizeof(flat_bm_t)); } - memcpy(textures + num_textures, texture, sizeof(texture_bm_t)); - num_textures++; + flats_bm[num_flats_bm++] = flat; } -static void ScanTextures(const char *data, int length) +static void ScanElem(u_scanner_t *s, + void (*AddElem)(const char *name, brightmap_t *brightmap)) { int i; + char *name; + + U_MustGetToken(s, TK_Identifier); + name = M_StringDuplicate(s->string); + U_MustGetToken(s, TK_Identifier); + for (i = 0; i < num_brightmaps; ++i) + { + if (!strcasecmp(brightmaps_array[i].name, s->string)) + { + AddElem(name, &brightmaps_array[i]); + break; + } + } + free(name); +} + +static void ScanData(const char *data, int length) +{ u_scanner_t scanner, *s; - texture_bm_t texture; scanner = U_ScanOpen(data, length, "BRGHTMPS"); s = &scanner; while (U_HasTokensLeft(s)) { - if (!U_CheckToken(s, TK_Identifier) || strcasecmp("TEXTURE", s->string)) + if (!U_CheckToken(s, TK_Identifier)) { U_GetNextLineToken(s); continue; } - U_MustGetToken(s, TK_Identifier); - texture.name = M_StringDuplicate(s->string); - U_MustGetToken(s, TK_Identifier); - for (i = 0; i < num_brightmaps; ++i) + if (!strcasecmp("TEXTURE", s->string)) { - if (!strcasecmp(brightmaps_array[i].name, s->string)) - { - texture.brightmap = &brightmaps_array[i]; - AddTexture(&texture); - break; - } + ScanElem(s, AddTexture); + } + else if (!strcasecmp("SPRITE", s->string)) + { + ScanElem(s, AddSprite); + } + else if (!strcasecmp("FLAT", s->string)) + { + ScanElem(s, AddFlat); + } + else + { + U_GetNextLineToken(s); } - // skip DOOM1|DOOM2 } U_ScanClose(s); } @@ -1078,11 +1165,41 @@ static const byte *R_BrightmapForTexName_Lump(const char *texname) { int i; - for (i = 0; i < num_textures; i++) + for (i = 0; i < num_textures_bm; i++) { - if (!strncasecmp(textures[i].name, texname, 8)) + if (!strncasecmp(textures_bm[i].name, texname, 8)) { - return textures[i].brightmap->colormask; + return textures_bm[i].brightmap->colormask; + } + } + + return nobrightmap; +} + +static const byte *R_BrightmapForSprite_Lump(const int type) +{ + int i; + + for (i = 0; i < num_sprites_bm; i++) + { + if (sprites_bm[i].type == type) + { + return sprites_bm[i].brightmap->colormask; + } + } + + return nobrightmap; +} + +static const byte *R_BrightmapForFlatNum_Lump(const int num) +{ + int i; + + for (i = 0; i < num_flats_bm; i++) + { + if (flats_bm[i].num == num) + { + return flats_bm[i].brightmap->colormask; } } @@ -1097,11 +1214,11 @@ void R_InitBrightmaps () const char *data = W_CacheLumpNum(lump, PU_CACHE); int length = W_LumpLength(lump); ScanBrightmaps(data, length); - ScanTextures(data, length); + ScanData(data, length); R_BrightmapForTexName = R_BrightmapForTexName_Lump; - R_BrightmapForSprite = R_BrightmapForSprite_None; - R_BrightmapForFlatNum = R_BrightmapForFlatNum_None; + R_BrightmapForSprite = R_BrightmapForSprite_Lump; + R_BrightmapForFlatNum = R_BrightmapForFlatNum_Lump; R_BrightmapForState = R_BrightmapForState_None; return; } From ca4cf40d87406f524dcb5d3be2e5cfac19e0a103 Mon Sep 17 00:00:00 2001 From: Roman Fomin Date: Mon, 19 Dec 2022 10:59:29 +0700 Subject: [PATCH 09/26] remove unused function --- src/r_bmaps.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/r_bmaps.c b/src/r_bmaps.c index 80c55992a..384a69cc3 100644 --- a/src/r_bmaps.c +++ b/src/r_bmaps.c @@ -819,11 +819,6 @@ static const byte *R_BrightmapForSprite_Hacx (const int type) return nobrightmap; } -static const byte *R_BrightmapForSprite_None (const int type) -{ - return nobrightmap; -} - // [crispy] brightmaps for flats static int bmapflatnum[12]; From 1417bb13f6395540e8772ff8dfbcf339d24387c9 Mon Sep 17 00:00:00 2001 From: Roman Fomin Date: Mon, 19 Dec 2022 11:44:58 +0700 Subject: [PATCH 10/26] add `brightmaps` checks --- src/r_bmaps.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/r_bmaps.c b/src/r_bmaps.c index 384a69cc3..2f6a54447 100644 --- a/src/r_bmaps.c +++ b/src/r_bmaps.c @@ -1173,13 +1173,15 @@ static const byte *R_BrightmapForTexName_Lump(const char *texname) static const byte *R_BrightmapForSprite_Lump(const int type) { - int i; - - for (i = 0; i < num_sprites_bm; i++) + if (STRICTMODE(brightmaps)) { - if (sprites_bm[i].type == type) + int i; + for (i = 0; i < num_sprites_bm; i++) { - return sprites_bm[i].brightmap->colormask; + if (sprites_bm[i].type == type) + { + return sprites_bm[i].brightmap->colormask; + } } } @@ -1188,13 +1190,15 @@ static const byte *R_BrightmapForSprite_Lump(const int type) static const byte *R_BrightmapForFlatNum_Lump(const int num) { - int i; - - for (i = 0; i < num_flats_bm; i++) + if (STRICTMODE(brightmaps)) { - if (flats_bm[i].num == num) + int i; + for (i = 0; i < num_flats_bm; i++) { - return flats_bm[i].brightmap->colormask; + if (flats_bm[i].num == num) + { + return flats_bm[i].brightmap->colormask; + } } } From 22f842704cd0657ba7899bcba287a5c6e3086267 Mon Sep 17 00:00:00 2001 From: Roman Fomin Date: Mon, 19 Dec 2022 18:54:18 +0700 Subject: [PATCH 11/26] add more error reporting --- src/r_bmaps.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/r_bmaps.c b/src/r_bmaps.c index 2f6a54447..4cbadab70 100644 --- a/src/r_bmaps.c +++ b/src/r_bmaps.c @@ -1120,6 +1120,10 @@ static void ScanElem(u_scanner_t *s, break; } } + if (i == num_brightmaps) + { + U_Error(s, "brightmap '%s' not found", s->string); + } free(name); } From 98bd4ce6b68b46e8e011e3e1aab23f04567c7872 Mon Sep 17 00:00:00 2001 From: Roman Fomin Date: Sun, 8 Jan 2023 18:51:25 +0700 Subject: [PATCH 12/26] scan multiple BRGHTMPS lumps, move data to autoload directory --- autoload/chex.wad/brghtmps.lmp | 91 ++ autoload/doom-all/brghtmps.lmp | 98 +++ autoload/doom.wad/brghtmps.lmp | 1 + autoload/doom2.wad/brghtmps.lmp | 11 + autoload/hacx.wad/brghtmps.lmp | 84 ++ autoload/plutonia.wad/brghtmps.lmp | 3 + autoload/tnt.wad/brghtmps.lmp | 22 + src/d_main.c | 103 +-- src/r_bmaps.c | 1309 +++++----------------------- src/r_bmaps.h | 12 +- src/r_data.c | 2 +- src/u_mapinfo.c | 31 +- src/u_mapinfo.h | 4 +- 13 files changed, 596 insertions(+), 1175 deletions(-) create mode 100644 autoload/chex.wad/brghtmps.lmp create mode 100644 autoload/doom-all/brghtmps.lmp create mode 100644 autoload/doom.wad/brghtmps.lmp create mode 100644 autoload/doom2.wad/brghtmps.lmp create mode 100644 autoload/hacx.wad/brghtmps.lmp create mode 100644 autoload/plutonia.wad/brghtmps.lmp create mode 100644 autoload/tnt.wad/brghtmps.lmp diff --git a/autoload/chex.wad/brghtmps.lmp b/autoload/chex.wad/brghtmps.lmp new file mode 100644 index 000000000..95b8b4c50 --- /dev/null +++ b/autoload/chex.wad/brghtmps.lmp @@ -0,0 +1,91 @@ +BRIGHTMAP NOTGRAY 4,9-79,112-255 +BRIGHTMAP NOTGRAYORBROWN 4,9-63,112-125,152-255 +BRIGHTMAP NOTGRAYORBROWN2 4,9-63,112-125,152-157,160-255 +BRIGHTMAP BLUEGREENBROWNRED 43,65-68,116,121-125,164-167,172,175,205-207,240-245 +BRIGHTMAP BLUEGREENBROWN 45,65-68,70,73,76,121-124,164-167,190,206-207,240-241,243 +BRIGHTMAP BLUEANDORANGE 45,164-167,190,206-207,240-241,243 +BRIGHTMAP REDONLY 45,173-191 +BRIGHTMAP REDONLY2 173-183 +BRIGHTMAP GREENONLY1 112-127 +BRIGHTMAP GREENONLY2 112-125 +BRIGHTMAP GREENONLY3 112-123 +BRIGHTMAP YELLOWONLY 160-167,224-231,249 +BRIGHTMAP REDANDGREEN 16-47,112-127,173-191 +BRIGHTMAP BLUEANDGREEN 112-124,192-207,240-245 +BRIGHTMAP BRIGHTTAN 56,58,60-62,64-65,67,69,139,143,147-148,150 +BRIGHTMAP CHEXRED 176-177 +BRIGHTMAP CHEXGREEN 112-115 +BRIGHTMAP CHEXREDGREEN 45,112-118,174-177 + +TEXTURE BIGDOOR1 GREENONLY3 +// {"BIGDOOR4", DOOM1AND2, greenonly3}, // C1: some stray green pixels, C2: many stray green pixels +// {"BRNBIGL", DOOM1AND2, greenonly3}, +// {"BRNBIGR", DOOM1AND2, greenonly3}, // C1, C2: one stray green pixel +// {"BRNSMAL2", DOOM1AND2, greenonly3}, // C1, C2: many stray green pixels +TEXTURE COMP2 NOTGRAY +// {"COMPTALL", DOOM1ONLY, notgray}, +// {"COMPTALL", DOOM2ONLY, greenonly3}, // C2: many stray green pixels +TEXTURE COMPUTE2 NOTGRAY +TEXTURE LITE5 GREENONLY2 +TEXTURE STARTAN3 GREENONLY2 +TEXTURE SW1BRCOM CHEXRED +TEXTURE SW1BRN1 CHEXGREEN +TEXTURE SW1BRN2 CHEXRED +TEXTURE SW1BRNGN CHEXRED +TEXTURE SW1BROWN CHEXRED +TEXTURE SW1COMM CHEXRED +TEXTURE SW1COMP CHEXRED +TEXTURE SW1DIRT CHEXGREEN +TEXTURE SW1METAL CHEXREDGREEN +TEXTURE SW1PIPE CHEXGREEN +TEXTURE SW1STARG CHEXRED +TEXTURE SW1STON1 CHEXRED +TEXTURE SW1STRTN CHEXRED +TEXTURE SW2BRCOM CHEXGREEN +TEXTURE SW2BRN1 CHEXRED +TEXTURE SW2BRN2 CHEXGREEN +TEXTURE SW2BRNGN CHEXGREEN +TEXTURE SW2BROWN CHEXGREEN +TEXTURE SW2COMM CHEXGREEN +TEXTURE SW2COMP CHEXGREEN +TEXTURE SW2DIRT CHEXRED +TEXTURE SW2METAL CHEXREDGREEN +TEXTURE SW2PIPE CHEXRED +TEXTURE SW2STARG CHEXGREEN +TEXTURE SW2STON1 CHEXGREEN +TEXTURE SW2STONE CHEXGREEN +TEXTURE SW2STRTN CHEXGREEN +// {"BIGDOOR5", DOOM1AND2, greenonly1}, // C1, C2: some stray green pixels +// {"BIGDOOR6", DOOM1AND2, greenonly1}, // C1, C2: some stray green pixels +TEXTURE CEMENT3 GREENONLY3 +TEXTURE SKINFACE GREENONLY1 +TEXTURE SKINTEK1 GREENONLY1 +TEXTURE SKSPINE2 GREENONLY3 +TEXTURE SW1BLUE CHEXGREEN +TEXTURE SW1HOT CHEXGREEN +TEXTURE SW1SKIN CHEXGREEN +TEXTURE SW1VINE CHEXGREEN // C1: some stray green pixels in the vines +TEXTURE SW1WOOD CHEXGREEN +TEXTURE SW2BLUE CHEXRED +TEXTURE SW2CMT CHEXGREEN +TEXTURE SW2GSTON CHEXRED +TEXTURE SW2HOT CHEXRED +TEXTURE SW2SKIN CHEXRED +TEXTURE SW2VINE CHEXRED +TEXTURE SW2WOOD CHEXRED +TEXTURE WOOD4 CHEXREDGREEN +TEXTURE WOODGARG CHEXRED +TEXTURE WOODSKUL CHEXREDGREEN + +// Chainsaw +SPRITE CSAW REDANDGREEN +// Shotgun +SPRITE SHOT REDANDGREEN +// Chaingun +SPRITE MGUN REDANDGREEN +// Rocket launcher +SPRITE LAUN REDANDGREEN +// Plasmagun +SPRITE PLAS REDANDGREEN +// BFG9000 +SPRITE BFUG REDANDGREEN diff --git a/autoload/doom-all/brghtmps.lmp b/autoload/doom-all/brghtmps.lmp new file mode 100644 index 000000000..a3f8e5c9b --- /dev/null +++ b/autoload/doom-all/brghtmps.lmp @@ -0,0 +1,98 @@ +BRIGHTMAP NOTGRAY 4,9-79,112-255 +BRIGHTMAP NOTGRAYORBROWN 4,9-63,112-125,152-255 +BRIGHTMAP NOTGRAYORBROWN2 4,9-63,112-125,152-157,160-255 +BRIGHTMAP BLUEGREENBROWNRED 43,65-68,116,121-125,164-167,172,175,205-207,240-245 +BRIGHTMAP BLUEGREENBROWN 45,65-68,70,73,76,121-124,164-167,190,206-207,240-241,243 +BRIGHTMAP BLUEANDORANGE 45,164-167,190,206-207,240-241,243 +BRIGHTMAP REDONLY 45,173-191 +BRIGHTMAP REDONLY2 173-183 +BRIGHTMAP GREENONLY1 112-127 +BRIGHTMAP GREENONLY2 112-125 +BRIGHTMAP GREENONLY3 112-123 +BRIGHTMAP YELLOWONLY 160-167,224-231,249 +BRIGHTMAP REDANDGREEN 16-47,112-127,173-191 +BRIGHTMAP BLUEANDGREEN 112-124,192-207,240-245 +BRIGHTMAP BRIGHTTAN 56,58,60-62,64-65,67,69,139,143,147-148,150 + +TEXTURE COMP2 BLUEANDGREEN +TEXTURE COMPSTA1 NOTGRAY +TEXTURE COMPSTA2 NOTGRAY +TEXTURE COMPUTE1 BLUEGREENBROWNRED +TEXTURE COMPUTE2 BLUEGREENBROWN +TEXTURE COMPUTE3 BLUEANDORANGE +TEXTURE EXITSIGN NOTGRAY +TEXTURE EXITSTON REDONLY +TEXTURE PLANET1 NOTGRAY +TEXTURE SILVER2 NOTGRAY +TEXTURE SILVER3 NOTGRAYORBROWN2 +TEXTURE SLADSKUL REDONLY +TEXTURE SW1BRCOM REDONLY +TEXTURE SW1BRIK REDONLY + +TEXTURE SW1COMM REDONLY +TEXTURE SW1DIRT REDONLY +TEXTURE SW1MET2 REDONLY + +TEXTURE SW1STON1 REDONLY + +TEXTURE SW1STONE REDONLY +TEXTURE SW1STRTN REDONLY +TEXTURE SW2BLUE REDONLY +TEXTURE SW2BRCOM GREENONLY2 +TEXTURE SW2BRIK GREENONLY1 +TEXTURE SW2BRN1 GREENONLY2 +TEXTURE SW2BRN2 GREENONLY1 +TEXTURE SW2BRNGN GREENONLY3 +TEXTURE SW2COMM GREENONLY1 +TEXTURE SW2COMP REDONLY +TEXTURE SW2DIRT GREENONLY2 +TEXTURE SW2EXIT NOTGRAY +TEXTURE SW2GRAY NOTGRAY +TEXTURE SW2GRAY1 NOTGRAY +TEXTURE SW2GSTON REDONLY +// [crispy] Special case: fewer colors lit. +TEXTURE SW2HOT REDONLY2 + +TEXTURE SW2MET2 GREENONLY1 +TEXTURE SW2METAL GREENONLY3 +TEXTURE SW2MOD1 GREENONLY1 +TEXTURE SW2PANEL REDONLY +TEXTURE SW2ROCK REDONLY +TEXTURE SW2SLAD REDONLY + +TEXTURE SW2STON1 GREENONLY3 + +TEXTURE SW2STON6 REDONLY +TEXTURE SW2STONE GREENONLY2 +TEXTURE SW2STRTN GREENONLY1 +TEXTURE SW2TEK GREENONLY1 +TEXTURE SW2VINE GREENONLY1 +TEXTURE SW2WOOD REDONLY +TEXTURE SW2ZIM REDONLY +TEXTURE WOOD4 REDONLY +TEXTURE WOODGARG REDONLY +TEXTURE WOODSKUL REDONLY +//TEXTURE ZELDOOR REDONLY +TEXTURE LITEBLU1 NOTGRAY +TEXTURE LITEBLU2 NOTGRAY +TEXTURE SW2SATYR BRIGHTTAN +TEXTURE SW2LION BRIGHTTAN +TEXTURE SW2GARG BRIGHTTAN + +// Armor Bonus +SPRITE BON2 GREENONLY2 +// Cell Charge +SPRITE CELL GREENONLY2 +// Barrel +SPRITE BAR1 GREENONLY3 +// Cell Charge Pack +SPRITE CELP YELLOWONLY +// BFG9000 +SPRITE BFUG REDONLY +// Plasmagun +SPRITE PLAS REDONLY + +// [crispy] only three select brightmapped flats +FLAT CONS1_1 NOTGRAYORBROWN +FLAT CONS1_5 NOTGRAYORBROWN +FLAT CONS1_7 NOTGRAYORBROWN diff --git a/autoload/doom.wad/brghtmps.lmp b/autoload/doom.wad/brghtmps.lmp new file mode 100644 index 000000000..d2d8319f6 --- /dev/null +++ b/autoload/doom.wad/brghtmps.lmp @@ -0,0 +1 @@ +TEXTURE SW2STON2 REDONLY diff --git a/autoload/doom2.wad/brghtmps.lmp b/autoload/doom2.wad/brghtmps.lmp new file mode 100644 index 000000000..4e6033086 --- /dev/null +++ b/autoload/doom2.wad/brghtmps.lmp @@ -0,0 +1,11 @@ +TEXTURE SW1BRN1 REDONLY +TEXTURE SW1STARG REDONLY +TEXTURE SW1STON2 REDONLY +TEXTURE SW2MARB REDONLY +TEXTURE SW2STARG GREENONLY2 +TEXTURE SW2STON2 GREENONLY2 +TEXTURE SPCDOOR3 GREENONLY1 +TEXTURE PIPEWAL1 GREENONLY1 +TEXTURE TEKLITE2 GREENONLY1 +TEXTURE TEKBRON2 YELLOWONLY +//TEXTURE SW2SKULL GREENONLY2 diff --git a/autoload/hacx.wad/brghtmps.lmp b/autoload/hacx.wad/brghtmps.lmp new file mode 100644 index 000000000..09ea34b2b --- /dev/null +++ b/autoload/hacx.wad/brghtmps.lmp @@ -0,0 +1,84 @@ +BRIGHTMAP NOTGRAY 4,9-79,112-255 +BRIGHTMAP NOTGRAYORBROWN 4,9-63,112-125,152-255 +BRIGHTMAP NOTGRAYORBROWN2 4,9-63,112-125,152-157,160-255 +BRIGHTMAP BLUEGREENBROWNRED 43,65-68,116,121-125,164-167,172,175,205-207,240-245 +BRIGHTMAP BLUEGREENBROWN 45,65-68,70,73,76,121-124,164-167,190,206-207,240-241,243 +BRIGHTMAP BLUEANDORANGE 45,164-167,190,206-207,240-241,243 +BRIGHTMAP REDONLY 45,173-191 +BRIGHTMAP REDONLY2 173-183 +BRIGHTMAP GREENONLY1 112-127 +BRIGHTMAP GREENONLY2 112-125 +BRIGHTMAP GREENONLY3 112-123 +BRIGHTMAP YELLOWONLY 160-167,224-231,249 +BRIGHTMAP REDANDGREEN 16-47,112-127,173-191 +BRIGHTMAP BLUEANDGREEN 112-124,192-207,240-245 +BRIGHTMAP BRIGHTTAN 56,58,60-62,64-65,67,69,139,143,147-148,150 +BRIGHTMAP HACXLIGHTNING 4,168,192-199,208,224 + +// {"BFALL1", DOOM2ONLY, redandgreen}, +// {"BFALL2", DOOM2ONLY, redandgreen}, +// {"BFALL3", DOOM2ONLY, redandgreen}, +// {"BFALL4", DOOM2ONLY, redandgreen}, +TEXTURE BRNSMALR GREENONLY1 +TEXTURE DOORRED REDANDGREEN +TEXTURE SLADWALL CHEXRED +// {"SW1BRCOM", DOOM2ONLY, redonly}, +// {"SW1BRN1", DOOM2ONLY, redandgreen}, +TEXTURE SW1BRN2 NOTGRAYORBROWN +TEXTURE SW1BRNGN NOTGRAYORBROWN +// {"SW1BROWN", DOOM2ONLY, notgrayorbrown}, +// {"SW2BRCOM", DOOM2ONLY, greenonly1}, +// {"SW2BRN1", DOOM2ONLY, redandgreen}, +TEXTURE SW2BRN2 NOTGRAYORBROWN +// {"SW2BROWN", DOOM2ONLY, notgrayorbrown}, +TEXTURE COMPSPAN GREENONLY1 +TEXTURE COMPSTA1 NOTGRAYORBROWN +// {"COMPSTA2", DOOM2ONLY, notgrayorbrown}, +TEXTURE HD5 REDANDGREEN +// {"HD8", DOOM2ONLY, redandgreen}, +// {"HD9", DOOM2ONLY, redandgreen}, +TEXTURE BLAKWAL2 REDANDGREEN +TEXTURE CEMENT7 GREENONLY1 +TEXTURE ROCK4 REDONLY +// {"SLOPPY1", DOOM2ONLY, notgrayorbrown}, +// {"SPCDOOR4", DOOM2ONLY, notgrayorbrown}, +TEXTURE ZZZFACE1 GREENONLY1 +TEXTURE ZZZFACE2 REDANDGREEN +TEXTURE HW166 REDANDGREEN +TEXTURE HW510 NOTGRAYORBROWN +TEXTURE HW511 NOTGRAYORBROWN +TEXTURE HW512 NOTGRAYORBROWN + +// Chainsaw +SPRITE CSAW REDONLY +// Plasmagun +SPRITE PLAS REDONLY +// Cell Charge +SPRITE CELL REDONLY +// Cell Charge Pack +SPRITE CELP REDONLY +// Rocket launcher +SPRITE LAUN REDANDGREEN +// Medikit +SPRITE MEDI REDANDGREEN +// Rocket +SPRITE ROCK GREENONLY1 +// Box of rockets +SPRITE BROK GREENONLY1 +// Health Bonus +SPRITE BON1 NOTGRAYORBROWN +// Stimpack +SPRITE STIM NOTGRAYORBROWN + +FLAT FLOOR1_1 NOTGRAYORBROWN +FLAT FLOOR1_7 NOTGRAYORBROWN +FLAT FLOOR3_3 NOTGRAYORBROWN +FLAT NUKAGE1 NOTGRAYORBROWN +FLAT NUKAGE2 NOTGRAYORBROWN +FLAT NUKAGE3 NOTGRAYORBROWN +FLAT BLOOD1 GREENONLY1 +FLAT BLOOD2 GREENONLY1 +FLAT BLOOD3 GREENONLY1 +FLAT SLIME13 NOTGRAYORBROWN +FLAT SLIME14 NOTGRAYORBROWN +FLAT SLIME15 NOTGRAYORBROWN diff --git a/autoload/plutonia.wad/brghtmps.lmp b/autoload/plutonia.wad/brghtmps.lmp new file mode 100644 index 000000000..713b662bc --- /dev/null +++ b/autoload/plutonia.wad/brghtmps.lmp @@ -0,0 +1,3 @@ +// [crispy] Final Doom textures +// Plutonia exclusive +//TEXTURE SW2SKULL REDONLY diff --git a/autoload/tnt.wad/brghtmps.lmp b/autoload/tnt.wad/brghtmps.lmp new file mode 100644 index 000000000..35834e381 --- /dev/null +++ b/autoload/tnt.wad/brghtmps.lmp @@ -0,0 +1,22 @@ +// [crispy] Final Doom textures +// TNT - Evilution exclusive +TEXTURE PNK4EXIT REDONLY +TEXTURE SLAD2 NOTGRAYORBROWN +TEXTURE SLAD3 NOTGRAYORBROWN +TEXTURE SLAD4 NOTGRAYORBROWN +TEXTURE SLAD5 NOTGRAYORBROWN +TEXTURE SLAD6 NOTGRAYORBROWN +TEXTURE SLAD7 NOTGRAYORBROWN +TEXTURE SLAD8 NOTGRAYORBROWN +TEXTURE SLAD9 NOTGRAYORBROWN +TEXTURE SLAD10 NOTGRAYORBROWN +TEXTURE SLAD11 NOTGRAYORBROWN +TEXTURE SLADRIP1 NOTGRAYORBROWN +TEXTURE SLADRIP3 NOTGRAYORBROWN +TEXTURE M_TEC GREENONLY2 +TEXTURE LITERED2 REDONLY +TEXTURE BTNTMETL NOTGRAYORBROWN +TEXTURE BTNTSLVR NOTGRAYORBROWN +TEXTURE LITEYEL2 YELLOWONLY +TEXTURE LITEYEL3 YELLOWONLY +TEXTURE YELMETAL YELLOWONLY diff --git a/src/d_main.c b/src/d_main.c index 50cd58623..49196d59a 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -74,6 +74,7 @@ #include "p_map.h" // MELEERANGE #include "i_endoom.h" #include "d_quit.h" +#include "r_bmaps.h" #include "dsdhacked.h" @@ -116,6 +117,11 @@ static char *D_dehout(void) return s; } +static void ProcessDehLump(int lumpnum) +{ + ProcessDehFile(NULL, D_dehout(), lumpnum); +} + char **wadfiles; boolean devparm; // started game with -devparm @@ -1564,71 +1570,28 @@ static void D_AutoloadPWadDehDir() // ProcessDehFile() indicates that the data comes from the lump number // indicated by the third argument, instead of from a file. -static void D_ProcessDehInWad(int i, boolean in_iwad) -{ - //! - // @category mod - // - // Avoid loading DEHACKED lumps embedded into WAD files. - // - - if (M_CheckParm("-nodehlump")) - { - return; - } - - if (i >= 0) - { - D_ProcessDehInWad(lumpinfo[i].next, in_iwad); - if (!strncasecmp(lumpinfo[i].name, "dehacked", 8) && - lumpinfo[i].namespace == ns_global && - (in_iwad ? W_IsIWADLump(i) : !W_IsIWADLump(i))) - ProcessDehFile(NULL, D_dehout(), i); - } -} - -#define D_ProcessDehInWads() D_ProcessDehInWad(lumpinfo[W_LumpNameHash \ - ("dehacked") % (unsigned) numlumps].index, false); - -#define D_ProcessDehInIWad() D_ProcessDehInWad(lumpinfo[W_LumpNameHash \ - ("dehacked") % (unsigned) numlumps].index, true); - -// Process multiple UMAPINFO files - -static void D_ProcessUMInWad(int i) +static void D_ProcessInWad(int i, const char *name, void (*Process)(int lumpnum), + boolean iwad) { if (i >= 0) + { + D_ProcessInWad(lumpinfo[i].next, name, Process, iwad); + if (!strncasecmp(lumpinfo[i].name, name, 8) && + lumpinfo[i].namespace == ns_global && + (iwad ? W_IsIWADLump(i) : !W_IsIWADLump(i))) { - D_ProcessUMInWad(lumpinfo[i].next); - if (!strncasecmp(lumpinfo[i].name, "umapinfo", 8) && - lumpinfo[i].namespace == ns_global) - { - U_ParseMapInfo(false, (const char *)W_CacheLumpNum(i, PU_CACHE), W_LumpLength(i)); - } + Process(i); } + } } -#define D_ProcessUMInWads() D_ProcessUMInWad(lumpinfo[W_LumpNameHash \ - ("umapinfo") % (unsigned) numlumps].index); - -// Process multiple UMAPDEF files - -static void D_ProcessDefaultsInWad(int i) +static void D_ProcessInWads(const char *name, void (*Process)(int lumpnum), + boolean iwad) { - if (i >= 0) - { - D_ProcessDefaultsInWad(lumpinfo[i].next); - if (!strncasecmp(lumpinfo[i].name, "umapdef", 7) && - lumpinfo[i].namespace == ns_global) - { - U_ParseMapInfo(true, (const char *)W_CacheLumpNum(i, PU_CACHE), W_LumpLength(i)); - } - } + D_ProcessInWad(lumpinfo[W_LumpNameHash(name) % (unsigned)numlumps].index, + name, Process, iwad); } -#define D_ProcessDefaultsInWads() D_ProcessDefaultsInWad(lumpinfo[W_LumpNameHash \ - ("umapdef") % (unsigned) numlumps].index); - // mbf21: don't want to reorganize info.c structure for a few tweaks... static void D_InitTables(void) @@ -2399,20 +2362,32 @@ void D_DoomMain(void) putchar('\n'); // killough 3/6/98: add a newline, by popular demand :) // process deh in IWAD - D_ProcessDehInIWad(); + + //! + // @category mod + // + // Avoid loading DEHACKED lumps embedded into WAD files. + // + + if (!M_ParmExists("-nodehlump")) + { + D_ProcessInWads("DEHACKED", ProcessDehLump, true); + } // process .deh files specified on the command line with -deh or -bex. D_ProcessDehCommandLine(); // process deh in wads and .deh files from autoload directory // before deh in wads from -file parameter - D_AutoloadDehDir(); - D_ProcessDehInWads(); // killough 10/98: now process all deh in wads + // killough 10/98: now process all deh in wads + if (!M_ParmExists("-nodehlump")) + { + D_ProcessInWads("DEHACKED", ProcessDehLump, false); + } // process .deh files from PWADs autoload directories - D_AutoloadPWadDehDir(); PostProcessDeh(); @@ -2444,7 +2419,9 @@ void D_DoomMain(void) I_Error("\nThis is not the registered version."); } - D_ProcessDefaultsInWads(); + D_ProcessInWads("UMAPDEF", U_ParseMapDefInfo, false); + + D_ProcessInWads("BRGHTMPS", R_InitBrightmaps, false); //! // @category mod @@ -2452,9 +2429,9 @@ void D_DoomMain(void) // Disable UMAPINFO loading. // - if (!M_CheckParm("-nomapinfo")) + if (!M_ParmExists("-nomapinfo")) { - D_ProcessUMInWads(); + D_ProcessInWads("UMAPINFO", U_ParseMapInfo, false); } V_InitColorTranslation(); //jff 4/24/98 load color translation lumps diff --git a/src/r_bmaps.c b/src/r_bmaps.c index 4cbadab70..230bca1af 100644 --- a/src/r_bmaps.c +++ b/src/r_bmaps.c @@ -28,849 +28,13 @@ int brightmaps; -// [crispy] brightmap data - -static const byte nobrightmap[256] = {0}; - -static const byte notgray[256] = -{ - 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1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 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, - 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -}; +static const byte nobrightmap[COLORMASK_SIZE] = { 0 }; const byte *dc_brightmap = nobrightmap; -// [crispy] brightmaps for textures - -enum -{ - DOOM1AND2, - DOOM1ONLY, - DOOM2ONLY, -}; - -typedef struct -{ - const char *const texture; - const int game; - const byte *colormask; -} fullbright_t; - -static const fullbright_t fullbright_doom[] = { - // [crispy] common textures - {"COMP2", DOOM1AND2, blueandgreen}, - {"COMPSTA1", DOOM1AND2, notgray}, - {"COMPSTA2", DOOM1AND2, notgray}, - {"COMPUTE1", DOOM1AND2, bluegreenbrownred}, - {"COMPUTE2", DOOM1AND2, bluegreenbrown}, - {"COMPUTE3", DOOM1AND2, blueandorange}, - {"EXITSIGN", DOOM1AND2, notgray}, - {"EXITSTON", DOOM1AND2, redonly}, - {"PLANET1", DOOM1AND2, notgray}, - {"SILVER2", DOOM1AND2, notgray}, - {"SILVER3", DOOM1AND2, notgrayorbrown2}, - {"SLADSKUL", DOOM1AND2, redonly}, - {"SW1BRCOM", DOOM1AND2, redonly}, - {"SW1BRIK", DOOM1AND2, redonly}, - {"SW1BRN1", DOOM2ONLY, redonly}, - {"SW1COMM", DOOM1AND2, redonly}, - {"SW1DIRT", DOOM1AND2, redonly}, - {"SW1MET2", DOOM1AND2, redonly}, - {"SW1STARG", DOOM2ONLY, redonly}, - {"SW1STON1", DOOM1AND2, redonly}, - {"SW1STON2", DOOM2ONLY, redonly}, - {"SW1STONE", DOOM1AND2, redonly}, - {"SW1STRTN", DOOM1AND2, redonly}, - {"SW2BLUE", DOOM1AND2, redonly}, - {"SW2BRCOM", DOOM1AND2, greenonly2}, - {"SW2BRIK", DOOM1AND2, greenonly1}, - {"SW2BRN1", DOOM1AND2, greenonly2}, - {"SW2BRN2", DOOM1AND2, greenonly1}, - {"SW2BRNGN", DOOM1AND2, greenonly3}, - {"SW2COMM", DOOM1AND2, greenonly1}, - {"SW2COMP", DOOM1AND2, redonly}, - {"SW2DIRT", DOOM1AND2, greenonly2}, - {"SW2EXIT", DOOM1AND2, notgray}, - {"SW2GRAY", DOOM1AND2, notgray}, - {"SW2GRAY1", DOOM1AND2, notgray}, - {"SW2GSTON", DOOM1AND2, redonly}, - // [crispy] Special case: fewer colors lit. - {"SW2HOT", DOOM1AND2, redonly2}, - {"SW2MARB", DOOM2ONLY, redonly}, - {"SW2MET2", DOOM1AND2, greenonly1}, - {"SW2METAL", DOOM1AND2, greenonly3}, - {"SW2MOD1", DOOM1AND2, greenonly1}, - {"SW2PANEL", DOOM1AND2, redonly}, - {"SW2ROCK", DOOM1AND2, redonly}, - {"SW2SLAD", DOOM1AND2, redonly}, - {"SW2STARG", DOOM2ONLY, greenonly2}, - {"SW2STON1", DOOM1AND2, greenonly3}, - // [crispy] beware! - {"SW2STON2", DOOM1ONLY, redonly}, - {"SW2STON2", DOOM2ONLY, greenonly2}, - {"SW2STON6", DOOM1AND2, redonly}, - {"SW2STONE", DOOM1AND2, greenonly2}, - {"SW2STRTN", DOOM1AND2, greenonly1}, - {"SW2TEK", DOOM1AND2, greenonly1}, - {"SW2VINE", DOOM1AND2, greenonly1}, - {"SW2WOOD", DOOM1AND2, redonly}, - {"SW2ZIM", DOOM1AND2, redonly}, - {"WOOD4", DOOM1AND2, redonly}, - {"WOODGARG", DOOM1AND2, redonly}, - {"WOODSKUL", DOOM1AND2, redonly}, -// {"ZELDOOR", DOOM1AND2, redonly}, - {"LITEBLU1", DOOM1AND2, notgray}, - {"LITEBLU2", DOOM1AND2, notgray}, - {"SPCDOOR3", DOOM2ONLY, greenonly1}, - {"PIPEWAL1", DOOM2ONLY, greenonly1}, - {"TEKLITE2", DOOM2ONLY, greenonly1}, - {"TEKBRON2", DOOM2ONLY, yellowonly}, -// {"SW2SKULL", DOOM2ONLY, greenonly2}, - {"SW2SATYR", DOOM1AND2, brighttan}, - {"SW2LION", DOOM1AND2, brighttan}, - {"SW2GARG", DOOM1AND2, brighttan}, - // [crispy] Final Doom textures - // TNT - Evilution exclusive - {"PNK4EXIT", DOOM2ONLY, redonly}, - {"SLAD2", DOOM2ONLY, notgrayorbrown}, - {"SLAD3", DOOM2ONLY, notgrayorbrown}, - {"SLAD4", DOOM2ONLY, notgrayorbrown}, - {"SLAD5", DOOM2ONLY, notgrayorbrown}, - {"SLAD6", DOOM2ONLY, notgrayorbrown}, - {"SLAD7", DOOM2ONLY, notgrayorbrown}, - {"SLAD8", DOOM2ONLY, notgrayorbrown}, - {"SLAD9", DOOM2ONLY, notgrayorbrown}, - {"SLAD10", DOOM2ONLY, notgrayorbrown}, - {"SLAD11", DOOM2ONLY, notgrayorbrown}, - {"SLADRIP1", DOOM2ONLY, notgrayorbrown}, - {"SLADRIP3", DOOM2ONLY, notgrayorbrown}, - {"M_TEC", DOOM2ONLY, greenonly2}, - {"LITERED2", DOOM2ONLY, redonly}, - {"BTNTMETL", DOOM2ONLY, notgrayorbrown}, - {"BTNTSLVR", DOOM2ONLY, notgrayorbrown}, - {"LITEYEL2", DOOM2ONLY, yellowonly}, - {"LITEYEL3", DOOM2ONLY, yellowonly}, - {"YELMETAL", DOOM2ONLY, yellowonly}, - // Plutonia exclusive -// {"SW2SKULL", DOOM2ONLY, redonly}, -}; - -static const fullbright_t fullbright_chex[] = { - {"BIGDOOR1", DOOM1AND2, greenonly3}, -// {"BIGDOOR4", DOOM1AND2, greenonly3}, // C1: some stray green pixels, C2: many stray green pixels -// {"BRNBIGL", DOOM1AND2, greenonly3}, -// {"BRNBIGR", DOOM1AND2, greenonly3}, // C1, C2: one stray green pixel -// {"BRNSMAL2", DOOM1AND2, greenonly3}, // C1, C2: many stray green pixels - {"COMP2", DOOM1AND2, notgray}, -// {"COMPTALL", DOOM1ONLY, notgray}, -// {"COMPTALL", DOOM2ONLY, greenonly3}, // C2: many stray green pixels - {"COMPUTE2", DOOM1AND2, notgray}, - {"LITE5", DOOM1ONLY, greenonly2}, - {"STARTAN3", DOOM1AND2, greenonly2}, - {"SW1BRCOM", DOOM1AND2, chexred}, - {"SW1BRN1", DOOM1AND2, chexgreen}, - {"SW1BRN2", DOOM1AND2, chexred}, - {"SW1BRNGN", DOOM1AND2, chexred}, - {"SW1BROWN", DOOM1AND2, chexred}, - {"SW1COMM", DOOM1AND2, chexred}, - {"SW1COMP", DOOM1AND2, chexred}, - {"SW1DIRT", DOOM1AND2, chexgreen}, - {"SW1METAL", DOOM1AND2, chexredgreen}, - {"SW1PIPE", DOOM1AND2, chexgreen}, - {"SW1STARG", DOOM1AND2, chexred}, - {"SW1STON1", DOOM1AND2, chexred}, - {"SW1STRTN", DOOM1AND2, chexred}, - {"SW2BRCOM", DOOM1AND2, chexgreen}, - {"SW2BRN1", DOOM1AND2, chexred}, - {"SW2BRN2", DOOM1AND2, chexgreen}, - {"SW2BRNGN", DOOM1AND2, chexgreen}, - {"SW2BROWN", DOOM1AND2, chexgreen}, - {"SW2COMM", DOOM1AND2, chexgreen}, - {"SW2COMP", DOOM1AND2, chexgreen}, - {"SW2DIRT", DOOM1AND2, chexred}, - {"SW2METAL", DOOM1AND2, chexredgreen}, - {"SW2PIPE", DOOM1AND2, chexred}, - {"SW2STARG", DOOM1AND2, chexgreen}, - {"SW2STON1", DOOM1AND2, chexgreen}, - {"SW2STONE", DOOM1AND2, chexgreen}, - {"SW2STRTN", DOOM1AND2, chexgreen}, -// {"BIGDOOR5", DOOM1AND2, greenonly1}, // C1, C2: some stray green pixels -// {"BIGDOOR6", DOOM1AND2, greenonly1}, // C1, C2: some stray green pixels - {"CEMENT3", DOOM1AND2, greenonly3}, - {"SKINFACE", DOOM1AND2, greenonly1}, - {"SKINTEK1", DOOM1ONLY, greenonly1}, - {"SKSPINE2", DOOM1AND2, greenonly3}, - {"SW1BLUE", DOOM1AND2, chexgreen}, - {"SW1HOT", DOOM1AND2, chexgreen}, - {"SW1SKIN", DOOM1AND2, chexgreen}, - {"SW1VINE", DOOM1ONLY, chexgreen}, // C1: some stray green pixels in the vines - {"SW1WOOD", DOOM1AND2, chexgreen}, - {"SW2BLUE", DOOM1AND2, chexred}, - {"SW2CMT", DOOM1AND2, chexgreen}, - {"SW2GSTON", DOOM1AND2, chexred}, - {"SW2HOT", DOOM1AND2, chexred}, - {"SW2SKIN", DOOM1AND2, chexred}, - {"SW2VINE", DOOM1ONLY, chexred}, - {"SW2WOOD", DOOM1AND2, chexred}, - {"WOOD4", DOOM1AND2, chexredgreen}, - {"WOODGARG", DOOM1AND2, chexred}, - {"WOODSKUL", DOOM1AND2, chexredgreen}, -}; - -static const fullbright_t fullbright_hacx[] = { -// {"BFALL1", DOOM2ONLY, redandgreen}, -// {"BFALL2", DOOM2ONLY, redandgreen}, -// {"BFALL3", DOOM2ONLY, redandgreen}, -// {"BFALL4", DOOM2ONLY, redandgreen}, - {"BRNSMALR", DOOM2ONLY, greenonly1}, - {"DOORRED", DOOM2ONLY, redandgreen}, - {"SLADWALL", DOOM2ONLY, chexred}, -// {"SW1BRCOM", DOOM2ONLY, redonly}, -// {"SW1BRN1", DOOM2ONLY, redandgreen}, - {"SW1BRN2", DOOM2ONLY, notgrayorbrown}, - {"SW1BRNGN", DOOM2ONLY, notgrayorbrown}, -// {"SW1BROWN", DOOM2ONLY, notgrayorbrown}, -// {"SW2BRCOM", DOOM2ONLY, greenonly1}, -// {"SW2BRN1", DOOM2ONLY, redandgreen}, - {"SW2BRN2", DOOM2ONLY, notgrayorbrown}, -// {"SW2BROWN", DOOM2ONLY, notgrayorbrown}, - {"COMPSPAN", DOOM2ONLY, greenonly1}, - {"COMPSTA1", DOOM2ONLY, notgrayorbrown}, -// {"COMPSTA2", DOOM2ONLY, notgrayorbrown}, - {"HD5", DOOM2ONLY, redandgreen}, -// {"HD8", DOOM2ONLY, redandgreen}, -// {"HD9", DOOM2ONLY, redandgreen}, - {"BLAKWAL2", DOOM2ONLY, redandgreen}, - {"CEMENT7", DOOM2ONLY, greenonly1}, - {"ROCK4", DOOM2ONLY, redonly}, -// {"SLOPPY1", DOOM2ONLY, notgrayorbrown}, -// {"SPCDOOR4", DOOM2ONLY, notgrayorbrown}, - {"ZZZFACE1", DOOM2ONLY, greenonly1}, - {"ZZZFACE2", DOOM2ONLY, redandgreen}, - {"HW166", DOOM2ONLY, redandgreen}, - {"HW510", DOOM2ONLY, notgrayorbrown}, - {"HW511", DOOM2ONLY, notgrayorbrown}, - {"HW512", DOOM2ONLY, notgrayorbrown}, -}; - -static const byte *R_BrightmapForTexName_Doom (const char *texname) -{ - int i; - - for (i = 0; i < arrlen(fullbright_doom); i++) - { - const fullbright_t *fullbright = &fullbright_doom[i]; - - if ((gamemission == doom && fullbright->game == DOOM2ONLY) || - (gamemission != doom && fullbright->game == DOOM1ONLY)) - { - continue; - } - - if (!strncasecmp(fullbright->texture, texname, 8)) - { - return fullbright->colormask; - } - } - - return nobrightmap; -} - -static boolean chex2 = false; - -static const byte *R_BrightmapForTexName_Chex (const char *texname) -{ - int i; - - for (i = 0; i < arrlen(fullbright_chex); i++) - { - const fullbright_t *fullbright = &fullbright_chex[i]; - - if ((chex2 && fullbright->game == DOOM1ONLY) || - (!chex2 && fullbright->game == DOOM2ONLY)) - { - continue; - } - - if (!strncasecmp(fullbright->texture, texname, 8)) - { - return fullbright->colormask; - } - } - - return nobrightmap; -} - -static const byte *R_BrightmapForTexName_Hacx (const char *texname) -{ - int i; - - for (i = 0; i < arrlen(fullbright_hacx); i++) - { - const fullbright_t *fullbright = &fullbright_hacx[i]; - - if (!strncasecmp(fullbright->texture, texname, 8)) - { - return fullbright->colormask; - } - } - - return nobrightmap; -} - -// [crispy] brightmaps for sprites - -// [crispy] adapted from russian-doom/src/doom/r_things.c:617-639 -static const byte *R_BrightmapForSprite_Doom (const int type) -{ - if (STRICTMODE(brightmaps)) - { - switch (type) - { - // Armor Bonus - case SPR_BON2: - // Cell Charge - case SPR_CELL: - { - return greenonly2; - break; - } - // Barrel - case SPR_BAR1: - { - return greenonly3; - break; - } - // Cell Charge Pack - case SPR_CELP: - { - return yellowonly; - break; - } - // BFG9000 - case SPR_BFUG: - // Plasmagun - case SPR_PLAS: - { - return redonly; - break; - } - } - } - - return nobrightmap; -} - -static const byte *R_BrightmapForSprite_Chex (const int type) -{ - // [crispy] TODO - /* - if (STRICTMODE(brightmaps)) - { - switch (type) - { - // Chainsaw - case SPR_CSAW: - // Shotgun - case SPR_SHOT: - // Chaingun - case SPR_MGUN: - // Rocket launcher - case SPR_LAUN: - // Plasmagun - case SPR_PLAS: - // BFG9000 - case SPR_BFUG: - { - return redandgreen; - break; - } - } - } - */ - return nobrightmap; -} - -static const byte *R_BrightmapForSprite_Hacx (const int type) -{ - if (STRICTMODE(brightmaps)) - { - switch (type) - { - // Chainsaw - case SPR_CSAW: - // Plasmagun - case SPR_PLAS: - // Cell Charge - case SPR_CELL: - // Cell Charge Pack - case SPR_CELP: - { - return redonly; - break; - } - // Rocket launcher - case SPR_LAUN: - // Medikit - case SPR_MEDI: - { - return redandgreen; - break; - } - // Rocket - case SPR_ROCK: - // Box of rockets - case SPR_BROK: - { - return greenonly1; - break; - } - // Health Bonus - case SPR_BON1: - // Stimpack - case SPR_STIM: - { - return notgrayorbrown; - break; - } - } - } - - return nobrightmap; -} - -// [crispy] brightmaps for flats - -static int bmapflatnum[12]; - -static const byte *R_BrightmapForFlatNum_Doom (const int num) -{ - if (STRICTMODE(brightmaps)) - { - if (num == bmapflatnum[0] || - num == bmapflatnum[1] || - num == bmapflatnum[2]) - { - return notgrayorbrown; - } - } - - return nobrightmap; -} - -static const byte *R_BrightmapForFlatNum_Hacx (const int num) -{ - if (STRICTMODE(brightmaps)) - { - if (num == bmapflatnum[0] || - num == bmapflatnum[1] || - num == bmapflatnum[2] || - num == bmapflatnum[3] || - num == bmapflatnum[4] || - num == bmapflatnum[5] || - num == bmapflatnum[9] || - num == bmapflatnum[10] || - num == bmapflatnum[11]) - { - return notgrayorbrown; - } - - if (num == bmapflatnum[6] || - num == bmapflatnum[7] || - num == bmapflatnum[8]) - { - return greenonly1; - } - } - - return nobrightmap; -} - -static const byte *R_BrightmapForFlatNum_None (const int num) -{ - return nobrightmap; -} - +#if 0 // [crispy] brightmaps for states static const byte *R_BrightmapForState_Doom (const int state) @@ -928,48 +92,41 @@ static const byte *R_BrightmapForState_None (const int state) { return nobrightmap; } +#endif -// [crispy] initialize brightmaps - -const byte *(*R_BrightmapForTexName) (const char *texname); -const byte *(*R_BrightmapForSprite) (const int type); -const byte *(*R_BrightmapForFlatNum) (const int num); -const byte *(*R_BrightmapForState) (const int state); - -#define COLORMASK_SIZE 256 typedef struct { - const char *name; - byte colormask[COLORMASK_SIZE]; + const char *name; + byte colormask[COLORMASK_SIZE]; } brightmap_t; static void ReadColormask(u_scanner_t *s, byte *colormask) { - memset(colormask, 0, COLORMASK_SIZE); - do - { - unsigned int color1 = 0, color2 = 0; - - if (U_CheckInteger(s)) - { - color1 = s->number; - if (color1 >= 0 && color1 < COLORMASK_SIZE) - colormask[color1] = 1; - } - - if (!U_CheckToken(s, '-')) - continue; - - if (U_CheckInteger(s)) - { - color2 = s->number; - if (color2 >= 0 && color2 < COLORMASK_SIZE) - { - int i; - for (i = color1 + 1; i <= color2; ++i) - colormask[i] = 1; - } - } - } while (U_CheckToken(s, ',')); + memset(colormask, 0, COLORMASK_SIZE); + do + { + unsigned int color1 = 0, color2 = 0; + + if (U_CheckInteger(s)) + { + color1 = s->number; + if (color1 >= 0 && color1 < COLORMASK_SIZE) + colormask[color1] = 1; + } + + if (!U_CheckToken(s, '-')) + continue; + + if (U_CheckInteger(s)) + { + color2 = s->number; + if (color2 >= 0 && color2 < COLORMASK_SIZE) + { + int i; + for (i = color1 + 1; i <= color2; ++i) + colormask[i] = 1; + } + } + } while (U_CheckToken(s, ',')); } #define BRIGHTMAPS_INITIAL_SIZE 32 @@ -978,45 +135,45 @@ static int num_brightmaps; static void AddBrightmap(brightmap_t *brightmap) { - static int size; + static int size; - if (num_brightmaps >= size) - { - size = (size ? size * 2 : BRIGHTMAPS_INITIAL_SIZE); - brightmaps_array = I_Realloc(brightmaps_array, - size * sizeof(brightmap_t)); - } + if (num_brightmaps >= size) + { + size = (size ? size * 2 : BRIGHTMAPS_INITIAL_SIZE); + brightmaps_array = I_Realloc(brightmaps_array, + size * sizeof(brightmap_t)); + } - memcpy(brightmaps_array + num_brightmaps, brightmap, sizeof(brightmap_t)); - num_brightmaps++; + memcpy(brightmaps_array + num_brightmaps, brightmap, sizeof(brightmap_t)); + num_brightmaps++; } static void ScanBrightmaps(const char *data, int length) { - u_scanner_t scanner, *s; - brightmap_t brightmap; - - scanner = U_ScanOpen(data, length, "BRGHTMPS"); - s = &scanner; - while (U_HasTokensLeft(s)) - { - U_MustGetToken(s, TK_Identifier); - if (strcasecmp("BRIGHTMAP", s->string)) - { - U_GetNextLineToken(s); - continue; - } - U_MustGetToken(s, TK_Identifier); - brightmap.name = M_StringDuplicate(s->string); - ReadColormask(s, brightmap.colormask); - AddBrightmap(&brightmap); - } - U_ScanClose(s); + u_scanner_t scanner, *s; + brightmap_t brightmap; + + scanner = U_ScanOpen(data, length, "BRGHTMPS"); + s = &scanner; + while (U_HasTokensLeft(s)) + { + U_MustGetToken(s, TK_Identifier); + if (strcasecmp("BRIGHTMAP", s->string)) + { + U_GetNextLineToken(s); + continue; + } + U_MustGetToken(s, TK_Identifier); + brightmap.name = M_StringDuplicate(s->string); + ReadColormask(s, brightmap.colormask); + AddBrightmap(&brightmap); + } + U_ScanClose(s); } typedef struct { - brightmap_t *brightmap; - const char *name; + brightmap_t *brightmap; + const char *name; } texture_bm_t; #define TEXTURES_INITIAL_SIZE 32 @@ -1025,25 +182,25 @@ static int num_textures_bm; static void AddTexture(const char *name, brightmap_t *brightmap) { - static int size; - texture_bm_t texture; + static int size; + texture_bm_t texture; - texture.name = M_StringDuplicate(name); - texture.brightmap = brightmap; + texture.name = M_StringDuplicate(name); + texture.brightmap = brightmap; - if (num_textures_bm >= size) - { - size = (size ? size * 2 : TEXTURES_INITIAL_SIZE); - textures_bm = I_Realloc(textures_bm, size * sizeof(texture_bm_t)); - } + if (num_textures_bm >= size) + { + size = (size ? size * 2 : TEXTURES_INITIAL_SIZE); + textures_bm = I_Realloc(textures_bm, size * sizeof(texture_bm_t)); + } - textures_bm[num_textures_bm++] = texture; + textures_bm[num_textures_bm++] = texture; } typedef struct { - brightmap_t *brightmap; - int type; + brightmap_t *brightmap; + int type; } sprite_bm_t; #define SPRITES_INITIAL_SIZE 32 @@ -1052,34 +209,35 @@ static int num_sprites_bm; static void AddSprite(const char *name, brightmap_t *brightmap) { - int i; - static int size; - sprite_bm_t sprite; + int i; + static int size; + sprite_bm_t sprite; - for (i = 0; i < num_sprites; ++i) - { - if (!strcasecmp(name, sprnames[i])) - break; - } - if (i == num_sprites) - return; + for (i = 0; i < num_sprites; ++i) + { + if (!strcasecmp(name, sprnames[i])) + break; + } + if (i == num_sprites) + return; - sprite.type = i; - sprite.brightmap = brightmap; + sprite.type = i; + sprite.brightmap = brightmap; - if (num_sprites_bm >= size) - { - size = (size ? size * 2 : SPRITES_INITIAL_SIZE); - sprites_bm = I_Realloc(sprites_bm, size * sizeof(sprite_bm_t)); - } + if (num_sprites_bm >= size) + { + size = (size ? size * 2 : SPRITES_INITIAL_SIZE); + sprites_bm = I_Realloc(sprites_bm, size * sizeof(sprite_bm_t)); + } - sprites_bm[num_sprites_bm++] = sprite; + sprites_bm[num_sprites_bm++] = sprite; } typedef struct { - brightmap_t *brightmap; - int num; + brightmap_t *brightmap; + const char *name; + int num; } flat_bm_t; #define FLATS_INITIAL_SIZE 32 @@ -1088,191 +246,146 @@ static int num_flats_bm; static void AddFlat(const char *name, brightmap_t *brightmap) { - static int size; - flat_bm_t flat; + static int size; + flat_bm_t flat; - flat.num = R_FlatNumForName(name); - flat.brightmap = brightmap; + flat.name = M_StringDuplicate(name); + flat.brightmap = brightmap; - if (num_flats_bm >= size) - { - size = (size ? size * 2 : SPRITES_INITIAL_SIZE); - flats_bm = I_Realloc(flats_bm, size * sizeof(flat_bm_t)); - } + if (num_flats_bm >= size) + { + size = (size ? size * 2 : SPRITES_INITIAL_SIZE); + flats_bm = I_Realloc(flats_bm, size * sizeof(flat_bm_t)); + } - flats_bm[num_flats_bm++] = flat; + flats_bm[num_flats_bm++] = flat; } -static void ScanElem(u_scanner_t *s, - void (*AddElem)(const char *name, brightmap_t *brightmap)) +void R_InitFlatBrightmaps(void) { - int i; - char *name; + int i; + for (i = 0; i < num_flats_bm; ++i) + { + flats_bm[i].num = R_FlatNumForName(flats_bm[i].name); + } +} - U_MustGetToken(s, TK_Identifier); - name = M_StringDuplicate(s->string); - U_MustGetToken(s, TK_Identifier); - for (i = 0; i < num_brightmaps; ++i) - { - if (!strcasecmp(brightmaps_array[i].name, s->string)) - { - AddElem(name, &brightmaps_array[i]); - break; - } - } - if (i == num_brightmaps) - { - U_Error(s, "brightmap '%s' not found", s->string); - } - free(name); +static void ScanElem(u_scanner_t *s, + void (*AddElem)(const char *name, brightmap_t *brightmap)) +{ + int i; + char *name; + + U_MustGetToken(s, TK_Identifier); + name = M_StringDuplicate(s->string); + U_MustGetToken(s, TK_Identifier); + for (i = 0; i < num_brightmaps; ++i) + { + if (!strcasecmp(brightmaps_array[i].name, s->string)) + { + AddElem(name, &brightmaps_array[i]); + break; + } + } + if (i == num_brightmaps) + { + U_Error(s, "brightmap '%s' not found", s->string); + } + free(name); } static void ScanData(const char *data, int length) { - u_scanner_t scanner, *s; - - scanner = U_ScanOpen(data, length, "BRGHTMPS"); - s = &scanner; - while (U_HasTokensLeft(s)) - { - if (!U_CheckToken(s, TK_Identifier)) - { - U_GetNextLineToken(s); - continue; - } - if (!strcasecmp("TEXTURE", s->string)) - { - ScanElem(s, AddTexture); - } - else if (!strcasecmp("SPRITE", s->string)) - { - ScanElem(s, AddSprite); - } - else if (!strcasecmp("FLAT", s->string)) - { - ScanElem(s, AddFlat); - } - else - { - U_GetNextLineToken(s); - } - } - U_ScanClose(s); + u_scanner_t scanner, *s; + + scanner = U_ScanOpen(data, length, "BRGHTMPS"); + s = &scanner; + while (U_HasTokensLeft(s)) + { + if (!U_CheckToken(s, TK_Identifier)) + { + U_GetNextLineToken(s); + continue; + } + if (!strcasecmp("TEXTURE", s->string)) + { + ScanElem(s, AddTexture); + } + else if (!strcasecmp("SPRITE", s->string)) + { + ScanElem(s, AddSprite); + } + else if (!strcasecmp("FLAT", s->string)) + { + ScanElem(s, AddFlat); + } + else + { + U_GetNextLineToken(s); + } + } + U_ScanClose(s); } -static const byte *R_BrightmapForTexName_Lump(const char *texname) +const byte *R_BrightmapForTexName(const char *texname) { - int i; + int i; - for (i = 0; i < num_textures_bm; i++) - { - if (!strncasecmp(textures_bm[i].name, texname, 8)) - { - return textures_bm[i].brightmap->colormask; - } - } + for (i = 0; i < num_textures_bm; i++) + { + if (!strncasecmp(textures_bm[i].name, texname, 8)) + { + return textures_bm[i].brightmap->colormask; + } + } - return nobrightmap; + return nobrightmap; } -static const byte *R_BrightmapForSprite_Lump(const int type) -{ - if (STRICTMODE(brightmaps)) - { - int i; - for (i = 0; i < num_sprites_bm; i++) - { - if (sprites_bm[i].type == type) - { - return sprites_bm[i].brightmap->colormask; - } - } - } +const byte *R_BrightmapForSprite(const int type) +{ + if (STRICTMODE(brightmaps)) + { + int i; + for (i = 0; i < num_sprites_bm; i++) + { + if (sprites_bm[i].type == type) + { + return sprites_bm[i].brightmap->colormask; + } + } + } + + return nobrightmap; +} - return nobrightmap; +const byte *R_BrightmapForFlatNum(const int num) +{ + if (STRICTMODE(brightmaps)) + { + int i; + for (i = 0; i < num_flats_bm; i++) + { + if (flats_bm[i].num == num) + { + return flats_bm[i].brightmap->colormask; + } + } + } + + return nobrightmap; } -static const byte *R_BrightmapForFlatNum_Lump(const int num) +const byte *R_BrightmapForState(const int state) { - if (STRICTMODE(brightmaps)) - { - int i; - for (i = 0; i < num_flats_bm; i++) - { - if (flats_bm[i].num == num) - { - return flats_bm[i].brightmap->colormask; - } - } - } - - return nobrightmap; + return nobrightmap; } -void R_InitBrightmaps () +void R_InitBrightmaps(int lumpnum) { - int lump = W_CheckNumForName("BRGHTMPS"); - if (lump >= 0) - { - const char *data = W_CacheLumpNum(lump, PU_CACHE); - int length = W_LumpLength(lump); - ScanBrightmaps(data, length); - ScanData(data, length); - - R_BrightmapForTexName = R_BrightmapForTexName_Lump; - R_BrightmapForSprite = R_BrightmapForSprite_Lump; - R_BrightmapForFlatNum = R_BrightmapForFlatNum_Lump; - R_BrightmapForState = R_BrightmapForState_None; - return; - } - - if (gamemission == pack_hacx) - { - bmapflatnum[0] = R_FlatNumForName("FLOOR1_1"); - bmapflatnum[1] = R_FlatNumForName("FLOOR1_7"); - bmapflatnum[2] = R_FlatNumForName("FLOOR3_3"); - bmapflatnum[3] = R_FlatNumForName("NUKAGE1"); - bmapflatnum[4] = R_FlatNumForName("NUKAGE2"); - bmapflatnum[5] = R_FlatNumForName("NUKAGE3"); - bmapflatnum[6] = R_FlatNumForName("BLOOD1"); - bmapflatnum[7] = R_FlatNumForName("BLOOD2"); - bmapflatnum[8] = R_FlatNumForName("BLOOD3"); - bmapflatnum[9] = R_FlatNumForName("SLIME13"); - bmapflatnum[10] = R_FlatNumForName("SLIME14"); - bmapflatnum[11] = R_FlatNumForName("SLIME15"); - - R_BrightmapForTexName = R_BrightmapForTexName_Hacx; - R_BrightmapForSprite = R_BrightmapForSprite_Hacx; - R_BrightmapForFlatNum = R_BrightmapForFlatNum_Hacx; - R_BrightmapForState = R_BrightmapForState_Hacx; - } - else - if (gamemission == pack_chex) - { - int lump; - - // [crispy] detect Chex Quest 2 - lump = W_CheckNumForName("INTERPIC"); - if (!strcasecmp(W_WadNameForLump(lump), "chex2.wad")) - { - chex2 = true; - } + const char *data = W_CacheLumpNum(lumpnum, PU_CACHE); + int length = W_LumpLength(lumpnum); - R_BrightmapForTexName = R_BrightmapForTexName_Chex; - R_BrightmapForSprite = R_BrightmapForSprite_Chex; - R_BrightmapForFlatNum = R_BrightmapForFlatNum_None; - R_BrightmapForState = R_BrightmapForState_None; - } - else - { - // [crispy] only three select brightmapped flats - bmapflatnum[0] = R_FlatNumForName("CONS1_1"); - bmapflatnum[1] = R_FlatNumForName("CONS1_5"); - bmapflatnum[2] = R_FlatNumForName("CONS1_7"); - - R_BrightmapForTexName = R_BrightmapForTexName_Doom; - R_BrightmapForSprite = R_BrightmapForSprite_Doom; - R_BrightmapForFlatNum = R_BrightmapForFlatNum_Doom; - R_BrightmapForState = R_BrightmapForState_Doom; - } + ScanBrightmaps(data, length); + ScanData(data, length); } diff --git a/src/r_bmaps.h b/src/r_bmaps.h index b7b33e124..1a55ca695 100644 --- a/src/r_bmaps.h +++ b/src/r_bmaps.h @@ -24,12 +24,14 @@ extern int brightmaps; -extern void R_InitBrightmaps (); +void R_InitBrightmaps(int lumpnum); -extern const byte *(*R_BrightmapForTexName) (const char *texname); -extern const byte *(*R_BrightmapForSprite) (const int type); -extern const byte *(*R_BrightmapForFlatNum) (const int num); -extern const byte *(*R_BrightmapForState) (const int state); +void R_InitFlatBrightmaps(void); + +const byte *R_BrightmapForTexName(const char *texname); +const byte *R_BrightmapForSprite(const int type); +const byte *R_BrightmapForFlatNum(const int num); +const byte *R_BrightmapForState(const int state); extern const byte **texturebrightmap; diff --git a/src/r_data.c b/src/r_data.c index ef29df641..65130bb6b 100644 --- a/src/r_data.c +++ b/src/r_data.c @@ -1003,7 +1003,7 @@ void R_InitData(void) // R_InitBrightmaps() comes next, because it sets R_BrightmapForTexName() // to initialize brightmaps depending on gameversion in R_InitTextures(). R_InitFlats(); - R_InitBrightmaps(); + R_InitFlatBrightmaps(); R_InitTextures(); R_InitSpriteLumps(); R_InitTranMap(1); // killough 2/21/98, 3/6/98 diff --git a/src/u_mapinfo.c b/src/u_mapinfo.c index 9f0cd1f99..e3a420d4c 100644 --- a/src/u_mapinfo.c +++ b/src/u_mapinfo.c @@ -27,6 +27,7 @@ #include "i_system.h" #include "m_misc2.h" #include "u_scanner.h" +#include "w_wad.h" #include "u_mapinfo.h" @@ -727,10 +728,11 @@ static boolean UpdateDefaultMapEntry(mapentry_t *val, int num) return false; } -void U_ParseMapInfo(boolean is_default, const char *buffer, size_t length) +void U_ParseMapDefInfo(int lumpnum) { - unsigned int i; - u_scanner_t scanner = U_ScanOpen(buffer, length, "UMAPINFO"); + const char *buffer = W_CacheLumpNum(lumpnum, PU_CACHE); + size_t length = W_LumpLength(lumpnum); + u_scanner_t scanner = U_ScanOpen(buffer, length, "UMAPDEF"); while (U_HasTokensLeft(&scanner)) { @@ -741,11 +743,26 @@ void U_ParseMapInfo(boolean is_default, const char *buffer, size_t length) continue; } - if (is_default) + default_mapinfo.mapcount++; + default_mapinfo.maps = (mapentry_t*)realloc(default_mapinfo.maps, sizeof(mapentry_t)*default_mapinfo.mapcount); + default_mapinfo.maps[default_mapinfo.mapcount-1] = parsed; + } + U_ScanClose(&scanner); +} + +void U_ParseMapInfo(int lumpnum) +{ + unsigned int i; + const char *buffer = W_CacheLumpNum(lumpnum, PU_CACHE); + size_t length = W_LumpLength(lumpnum); + u_scanner_t scanner = U_ScanOpen(buffer, length, "UMAPINFO"); + + while (U_HasTokensLeft(&scanner)) + { + mapentry_t parsed = { 0 }; + if (!ParseMapEntry(&scanner, &parsed)) { - default_mapinfo.mapcount++; - default_mapinfo.maps = (mapentry_t*)realloc(default_mapinfo.maps, sizeof(mapentry_t)*default_mapinfo.mapcount); - default_mapinfo.maps[default_mapinfo.mapcount-1] = parsed; + U_Error(&scanner, "Skipping entry: %s", scanner.string); continue; } diff --git a/src/u_mapinfo.h b/src/u_mapinfo.h index a47feb73e..e7a9e1448 100644 --- a/src/u_mapinfo.h +++ b/src/u_mapinfo.h @@ -68,6 +68,8 @@ mapentry_t *G_LookupMapinfo(int episode, int map); boolean U_CheckField(char *str); -void U_ParseMapInfo(boolean is_default, const char *buffer, size_t length); +void U_ParseMapDefInfo(int lumpnum); + +void U_ParseMapInfo(int lumpnum); #endif From 550388610ffeb4c66cf84ad08e56b2752f70c885 Mon Sep 17 00:00:00 2001 From: Roman Fomin Date: Sun, 8 Jan 2023 19:04:01 +0700 Subject: [PATCH 13/26] fix cppcheck --- src/r_bmaps.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/r_bmaps.c b/src/r_bmaps.c index 230bca1af..fdc7d5f4f 100644 --- a/src/r_bmaps.c +++ b/src/r_bmaps.c @@ -250,6 +250,7 @@ static void AddFlat(const char *name, brightmap_t *brightmap) flat_bm_t flat; flat.name = M_StringDuplicate(name); + flat.num = -1; flat.brightmap = brightmap; if (num_flats_bm >= size) From e46b9e3046cd8e4b6c95bd82d663f38ff522cae9 Mon Sep 17 00:00:00 2001 From: Roman Fomin Date: Sun, 8 Jan 2023 19:43:22 +0700 Subject: [PATCH 14/26] remove unnecessary BIGHTMAP declarations, formatting --- autoload/chex.wad/brghtmps.lmp | 10 ------ autoload/doom-all/brghtmps.lmp | 64 +++++++++++++++------------------- autoload/hacx.wad/brghtmps.lmp | 11 ------ 3 files changed, 29 insertions(+), 56 deletions(-) diff --git a/autoload/chex.wad/brghtmps.lmp b/autoload/chex.wad/brghtmps.lmp index 95b8b4c50..c36c83f3b 100644 --- a/autoload/chex.wad/brghtmps.lmp +++ b/autoload/chex.wad/brghtmps.lmp @@ -1,18 +1,8 @@ BRIGHTMAP NOTGRAY 4,9-79,112-255 -BRIGHTMAP NOTGRAYORBROWN 4,9-63,112-125,152-255 -BRIGHTMAP NOTGRAYORBROWN2 4,9-63,112-125,152-157,160-255 -BRIGHTMAP BLUEGREENBROWNRED 43,65-68,116,121-125,164-167,172,175,205-207,240-245 -BRIGHTMAP BLUEGREENBROWN 45,65-68,70,73,76,121-124,164-167,190,206-207,240-241,243 -BRIGHTMAP BLUEANDORANGE 45,164-167,190,206-207,240-241,243 -BRIGHTMAP REDONLY 45,173-191 -BRIGHTMAP REDONLY2 173-183 BRIGHTMAP GREENONLY1 112-127 BRIGHTMAP GREENONLY2 112-125 BRIGHTMAP GREENONLY3 112-123 -BRIGHTMAP YELLOWONLY 160-167,224-231,249 BRIGHTMAP REDANDGREEN 16-47,112-127,173-191 -BRIGHTMAP BLUEANDGREEN 112-124,192-207,240-245 -BRIGHTMAP BRIGHTTAN 56,58,60-62,64-65,67,69,139,143,147-148,150 BRIGHTMAP CHEXRED 176-177 BRIGHTMAP CHEXGREEN 112-115 BRIGHTMAP CHEXREDGREEN 45,112-118,174-177 diff --git a/autoload/doom-all/brghtmps.lmp b/autoload/doom-all/brghtmps.lmp index a3f8e5c9b..3abf26715 100644 --- a/autoload/doom-all/brghtmps.lmp +++ b/autoload/doom-all/brghtmps.lmp @@ -14,7 +14,7 @@ BRIGHTMAP REDANDGREEN 16-47,112-127,173-191 BRIGHTMAP BLUEANDGREEN 112-124,192-207,240-245 BRIGHTMAP BRIGHTTAN 56,58,60-62,64-65,67,69,139,143,147-148,150 -TEXTURE COMP2 BLUEANDGREEN +TEXTURE COMP2 BLUEANDGREEN TEXTURE COMPSTA1 NOTGRAY TEXTURE COMPSTA2 NOTGRAY TEXTURE COMPUTE1 BLUEGREENBROWNRED @@ -22,62 +22,56 @@ TEXTURE COMPUTE2 BLUEGREENBROWN TEXTURE COMPUTE3 BLUEANDORANGE TEXTURE EXITSIGN NOTGRAY TEXTURE EXITSTON REDONLY -TEXTURE PLANET1 NOTGRAY -TEXTURE SILVER2 NOTGRAY -TEXTURE SILVER3 NOTGRAYORBROWN2 +TEXTURE PLANET1 NOTGRAY +TEXTURE SILVER2 NOTGRAY +TEXTURE SILVER3 NOTGRAYORBROWN2 TEXTURE SLADSKUL REDONLY TEXTURE SW1BRCOM REDONLY -TEXTURE SW1BRIK REDONLY - -TEXTURE SW1COMM REDONLY -TEXTURE SW1DIRT REDONLY -TEXTURE SW1MET2 REDONLY - +TEXTURE SW1BRIK REDONLY +TEXTURE SW1COMM REDONLY +TEXTURE SW1DIRT REDONLY +TEXTURE SW1MET2 REDONLY TEXTURE SW1STON1 REDONLY - TEXTURE SW1STONE REDONLY TEXTURE SW1STRTN REDONLY -TEXTURE SW2BLUE REDONLY +TEXTURE SW2BLUE REDONLY TEXTURE SW2BRCOM GREENONLY2 -TEXTURE SW2BRIK GREENONLY1 -TEXTURE SW2BRN1 GREENONLY2 -TEXTURE SW2BRN2 GREENONLY1 +TEXTURE SW2BRIK GREENONLY1 +TEXTURE SW2BRN1 GREENONLY2 +TEXTURE SW2BRN2 GREENONLY1 TEXTURE SW2BRNGN GREENONLY3 -TEXTURE SW2COMM GREENONLY1 -TEXTURE SW2COMP REDONLY -TEXTURE SW2DIRT GREENONLY2 -TEXTURE SW2EXIT NOTGRAY -TEXTURE SW2GRAY NOTGRAY +TEXTURE SW2COMM GREENONLY1 +TEXTURE SW2COMP REDONLY +TEXTURE SW2DIRT GREENONLY2 +TEXTURE SW2EXIT NOTGRAY +TEXTURE SW2GRAY NOTGRAY TEXTURE SW2GRAY1 NOTGRAY TEXTURE SW2GSTON REDONLY // [crispy] Special case: fewer colors lit. -TEXTURE SW2HOT REDONLY2 - -TEXTURE SW2MET2 GREENONLY1 +TEXTURE SW2HOT REDONLY2 +TEXTURE SW2MET2 GREENONLY1 TEXTURE SW2METAL GREENONLY3 -TEXTURE SW2MOD1 GREENONLY1 +TEXTURE SW2MOD1 GREENONLY1 TEXTURE SW2PANEL REDONLY -TEXTURE SW2ROCK REDONLY -TEXTURE SW2SLAD REDONLY - +TEXTURE SW2ROCK REDONLY +TEXTURE SW2SLAD REDONLY TEXTURE SW2STON1 GREENONLY3 - TEXTURE SW2STON6 REDONLY TEXTURE SW2STONE GREENONLY2 TEXTURE SW2STRTN GREENONLY1 -TEXTURE SW2TEK GREENONLY1 -TEXTURE SW2VINE GREENONLY1 -TEXTURE SW2WOOD REDONLY -TEXTURE SW2ZIM REDONLY -TEXTURE WOOD4 REDONLY +TEXTURE SW2TEK GREENONLY1 +TEXTURE SW2VINE GREENONLY1 +TEXTURE SW2WOOD REDONLY +TEXTURE SW2ZIM REDONLY +TEXTURE WOOD4 REDONLY TEXTURE WOODGARG REDONLY TEXTURE WOODSKUL REDONLY //TEXTURE ZELDOOR REDONLY TEXTURE LITEBLU1 NOTGRAY TEXTURE LITEBLU2 NOTGRAY TEXTURE SW2SATYR BRIGHTTAN -TEXTURE SW2LION BRIGHTTAN -TEXTURE SW2GARG BRIGHTTAN +TEXTURE SW2LION BRIGHTTAN +TEXTURE SW2GARG BRIGHTTAN // Armor Bonus SPRITE BON2 GREENONLY2 diff --git a/autoload/hacx.wad/brghtmps.lmp b/autoload/hacx.wad/brghtmps.lmp index 09ea34b2b..c3e6af7bc 100644 --- a/autoload/hacx.wad/brghtmps.lmp +++ b/autoload/hacx.wad/brghtmps.lmp @@ -1,18 +1,7 @@ -BRIGHTMAP NOTGRAY 4,9-79,112-255 BRIGHTMAP NOTGRAYORBROWN 4,9-63,112-125,152-255 -BRIGHTMAP NOTGRAYORBROWN2 4,9-63,112-125,152-157,160-255 -BRIGHTMAP BLUEGREENBROWNRED 43,65-68,116,121-125,164-167,172,175,205-207,240-245 -BRIGHTMAP BLUEGREENBROWN 45,65-68,70,73,76,121-124,164-167,190,206-207,240-241,243 -BRIGHTMAP BLUEANDORANGE 45,164-167,190,206-207,240-241,243 BRIGHTMAP REDONLY 45,173-191 -BRIGHTMAP REDONLY2 173-183 BRIGHTMAP GREENONLY1 112-127 -BRIGHTMAP GREENONLY2 112-125 -BRIGHTMAP GREENONLY3 112-123 -BRIGHTMAP YELLOWONLY 160-167,224-231,249 BRIGHTMAP REDANDGREEN 16-47,112-127,173-191 -BRIGHTMAP BLUEANDGREEN 112-124,192-207,240-245 -BRIGHTMAP BRIGHTTAN 56,58,60-62,64-65,67,69,139,143,147-148,150 BRIGHTMAP HACXLIGHTNING 4,168,192-199,208,224 // {"BFALL1", DOOM2ONLY, redandgreen}, From 3aacf2736c9dd5561e810641a38430e81011f0c5 Mon Sep 17 00:00:00 2001 From: Roman Fomin Date: Sun, 8 Jan 2023 20:06:37 +0700 Subject: [PATCH 15/26] do not scan twice (BRIGHTMAP must be defined before use) For Doom Retro compatibility --- src/r_bmaps.c | 102 ++++++++++++++++++++------------------------------ 1 file changed, 40 insertions(+), 62 deletions(-) diff --git a/src/r_bmaps.c b/src/r_bmaps.c index fdc7d5f4f..a9669fe77 100644 --- a/src/r_bmaps.c +++ b/src/r_bmaps.c @@ -148,29 +148,6 @@ static void AddBrightmap(brightmap_t *brightmap) num_brightmaps++; } -static void ScanBrightmaps(const char *data, int length) -{ - u_scanner_t scanner, *s; - brightmap_t brightmap; - - scanner = U_ScanOpen(data, length, "BRGHTMPS"); - s = &scanner; - while (U_HasTokensLeft(s)) - { - U_MustGetToken(s, TK_Identifier); - if (strcasecmp("BRIGHTMAP", s->string)) - { - U_GetNextLineToken(s); - continue; - } - U_MustGetToken(s, TK_Identifier); - brightmap.name = M_StringDuplicate(s->string); - ReadColormask(s, brightmap.colormask); - AddBrightmap(&brightmap); - } - U_ScanClose(s); -} - typedef struct { brightmap_t *brightmap; const char *name; @@ -262,15 +239,6 @@ static void AddFlat(const char *name, brightmap_t *brightmap) flats_bm[num_flats_bm++] = flat; } -void R_InitFlatBrightmaps(void) -{ - int i; - for (i = 0; i < num_flats_bm; ++i) - { - flats_bm[i].num = R_FlatNumForName(flats_bm[i].name); - } -} - static void ScanElem(u_scanner_t *s, void (*AddElem)(const char *name, brightmap_t *brightmap)) { @@ -295,37 +263,13 @@ static void ScanElem(u_scanner_t *s, free(name); } -static void ScanData(const char *data, int length) +void R_InitFlatBrightmaps(void) { - u_scanner_t scanner, *s; - - scanner = U_ScanOpen(data, length, "BRGHTMPS"); - s = &scanner; - while (U_HasTokensLeft(s)) + int i; + for (i = 0; i < num_flats_bm; ++i) { - if (!U_CheckToken(s, TK_Identifier)) - { - U_GetNextLineToken(s); - continue; - } - if (!strcasecmp("TEXTURE", s->string)) - { - ScanElem(s, AddTexture); - } - else if (!strcasecmp("SPRITE", s->string)) - { - ScanElem(s, AddSprite); - } - else if (!strcasecmp("FLAT", s->string)) - { - ScanElem(s, AddFlat); - } - else - { - U_GetNextLineToken(s); - } + flats_bm[i].num = R_FlatNumForName(flats_bm[i].name); } - U_ScanClose(s); } const byte *R_BrightmapForTexName(const char *texname) @@ -384,9 +328,43 @@ const byte *R_BrightmapForState(const int state) void R_InitBrightmaps(int lumpnum) { + u_scanner_t scanner, *s; const char *data = W_CacheLumpNum(lumpnum, PU_CACHE); int length = W_LumpLength(lumpnum); - ScanBrightmaps(data, length); - ScanData(data, length); + scanner = U_ScanOpen(data, length, "BRGHTMPS"); + s = &scanner; + while (U_HasTokensLeft(s)) + { + if (!U_CheckToken(s, TK_Identifier)) + { + U_GetNextLineToken(s); + continue; + } + if (!strcasecmp("BRIGHTMAP", s->string)) + { + brightmap_t brightmap; + U_MustGetToken(s, TK_Identifier); + brightmap.name = M_StringDuplicate(s->string); + ReadColormask(s, brightmap.colormask); + AddBrightmap(&brightmap); + } + else if (!strcasecmp("TEXTURE", s->string)) + { + ScanElem(s, AddTexture); + } + else if (!strcasecmp("SPRITE", s->string)) + { + ScanElem(s, AddSprite); + } + else if (!strcasecmp("FLAT", s->string)) + { + ScanElem(s, AddFlat); + } + else + { + U_GetNextLineToken(s); + } + } + U_ScanClose(s); } From 4541e9f083f2f2f6bcd6a9ce97fd3e4c50819a37 Mon Sep 17 00:00:00 2001 From: Roman Fomin Date: Sun, 8 Jan 2023 20:11:19 +0700 Subject: [PATCH 16/26] rename R_InitBrightmaps->R_ScanBrightmaps --- src/d_main.c | 2 +- src/r_bmaps.c | 2 +- src/r_bmaps.h | 2 +- src/r_data.c | 5 ++--- 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/d_main.c b/src/d_main.c index 49196d59a..887bea51c 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -2421,7 +2421,7 @@ void D_DoomMain(void) D_ProcessInWads("UMAPDEF", U_ParseMapDefInfo, false); - D_ProcessInWads("BRGHTMPS", R_InitBrightmaps, false); + D_ProcessInWads("BRGHTMPS", R_ScanBrightmaps, false); //! // @category mod diff --git a/src/r_bmaps.c b/src/r_bmaps.c index a9669fe77..2015b522f 100644 --- a/src/r_bmaps.c +++ b/src/r_bmaps.c @@ -326,7 +326,7 @@ const byte *R_BrightmapForState(const int state) return nobrightmap; } -void R_InitBrightmaps(int lumpnum) +void R_ScanBrightmaps(int lumpnum) { u_scanner_t scanner, *s; const char *data = W_CacheLumpNum(lumpnum, PU_CACHE); diff --git a/src/r_bmaps.h b/src/r_bmaps.h index 1a55ca695..4b54242e6 100644 --- a/src/r_bmaps.h +++ b/src/r_bmaps.h @@ -24,7 +24,7 @@ extern int brightmaps; -void R_InitBrightmaps(int lumpnum); +void R_ScanBrightmaps(int lumpnum); void R_InitFlatBrightmaps(void); diff --git a/src/r_data.c b/src/r_data.c index 65130bb6b..16fee5af2 100644 --- a/src/r_data.c +++ b/src/r_data.c @@ -999,9 +999,8 @@ void R_InitData(void) { // [crispy] Moved R_InitFlats() to the top, because it sets firstflat/lastflat // which are required by R_InitTextures() to prevent flat lumps from being - // mistaken as patches and by R_InitBrightmaps() to set brightmaps for flats. - // R_InitBrightmaps() comes next, because it sets R_BrightmapForTexName() - // to initialize brightmaps depending on gameversion in R_InitTextures(). + // mistaken as patches and by R_InitFlatBrightmaps() to set brightmaps for + // flats. R_InitFlats(); R_InitFlatBrightmaps(); R_InitTextures(); From 91ac161dcf9d05b43b6bb2943da60f57625f220b Mon Sep 17 00:00:00 2001 From: Roman Fomin Date: Sun, 8 Jan 2023 22:21:57 +0700 Subject: [PATCH 17/26] implement states --- autoload/doom-all/brghtmps.lmp | 5 ++ autoload/hacx.wad/brghtmps.lmp | 9 ++ src/d_main.c | 2 +- src/r_bmaps.c | 155 +++++++++++++++++---------------- src/r_bmaps.h | 2 +- 5 files changed, 98 insertions(+), 75 deletions(-) diff --git a/autoload/doom-all/brghtmps.lmp b/autoload/doom-all/brghtmps.lmp index 3abf26715..0cdccd844 100644 --- a/autoload/doom-all/brghtmps.lmp +++ b/autoload/doom-all/brghtmps.lmp @@ -90,3 +90,8 @@ SPRITE PLAS REDONLY FLAT CONS1_1 NOTGRAYORBROWN FLAT CONS1_5 NOTGRAYORBROWN FLAT CONS1_7 NOTGRAYORBROWN + +STATE 84 REDONLY // S_BFG1 +STATE 85 REDONLY // S_BFG2 +STATE 86 REDONLY // S_BFG3 +STATE 87 REDONLY // S_BFG4 diff --git a/autoload/hacx.wad/brghtmps.lmp b/autoload/hacx.wad/brghtmps.lmp index c3e6af7bc..723edafd5 100644 --- a/autoload/hacx.wad/brghtmps.lmp +++ b/autoload/hacx.wad/brghtmps.lmp @@ -2,6 +2,7 @@ BRIGHTMAP NOTGRAYORBROWN 4,9-63,112-125,152-255 BRIGHTMAP REDONLY 45,173-191 BRIGHTMAP GREENONLY1 112-127 BRIGHTMAP REDANDGREEN 16-47,112-127,173-191 +BRIGHTMAP CHEXRED 176-177 BRIGHTMAP HACXLIGHTNING 4,168,192-199,208,224 // {"BFALL1", DOOM2ONLY, redandgreen}, @@ -71,3 +72,11 @@ FLAT BLOOD3 GREENONLY1 FLAT SLIME13 NOTGRAYORBROWN FLAT SLIME14 NOTGRAYORBROWN FLAT SLIME15 NOTGRAYORBROWN + +STATE 72 HACXLIGHTNING // S_SAW2 +STATE 73 HACXLIGHTNING // S_SAW3 +STATE 57 REDANDGREEN // S_MISSILE +STATE 67 REDONLY // S_SAW +STATE 68 REDONLY // S_SAWB +STATE 74 REDONLY // S_PLASMA +STATE 78 REDONLY // S_PLASMA2 diff --git a/src/d_main.c b/src/d_main.c index 887bea51c..1ebaa21e3 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -2421,7 +2421,7 @@ void D_DoomMain(void) D_ProcessInWads("UMAPDEF", U_ParseMapDefInfo, false); - D_ProcessInWads("BRGHTMPS", R_ScanBrightmaps, false); + D_ProcessInWads("BRGHTMPS", R_ParseBrightmaps, false); //! // @category mod diff --git a/src/r_bmaps.c b/src/r_bmaps.c index 2015b522f..c53a5fb9b 100644 --- a/src/r_bmaps.c +++ b/src/r_bmaps.c @@ -34,66 +34,6 @@ static const byte nobrightmap[COLORMASK_SIZE] = { 0 }; const byte *dc_brightmap = nobrightmap; -#if 0 -// [crispy] brightmaps for states - -static const byte *R_BrightmapForState_Doom (const int state) -{ - if (STRICTMODE(brightmaps)) - { - switch (state) - { - case S_BFG1: - case S_BFG2: - case S_BFG3: - case S_BFG4: - { - return redonly; - break; - } - } - } - - return nobrightmap; -} - -static const byte *R_BrightmapForState_Hacx (const int state) -{ - if (STRICTMODE(brightmaps)) - { - switch (state) - { - case S_SAW2: - case S_SAW3: - { - return hacxlightning; - break; - } - case S_MISSILE: - { - return redandgreen; - break; - } - case S_SAW: - case S_SAWB: - case S_PLASMA: - case S_PLASMA2: - { - return redonly; - break; - } - } - } - - return nobrightmap; -} - -static const byte *R_BrightmapForState_None (const int state) -{ - return nobrightmap; -} -#endif - typedef struct { const char *name; byte colormask[COLORMASK_SIZE]; @@ -239,24 +179,59 @@ static void AddFlat(const char *name, brightmap_t *brightmap) flats_bm[num_flats_bm++] = flat; } -static void ScanElem(u_scanner_t *s, - void (*AddElem)(const char *name, brightmap_t *brightmap)) +typedef struct +{ + brightmap_t *brightmap; + int num; +} state_bm_t; + +#define STATES_INITIAL_SIZE 32 +static state_bm_t *states_bm; +static int num_states_bm; + +static void AddState(int num, brightmap_t *brightmap) +{ + static int size; + state_bm_t state; + + state.num = num; + state.brightmap = brightmap; + + if (num_states_bm >= size) + { + size = (size ? size * 2 : SPRITES_INITIAL_SIZE); + states_bm = I_Realloc(states_bm, size * sizeof(state_bm_t)); + } + + states_bm[num_states_bm++] = state; +} + +static brightmap_t *GetBrightmap(const char *name) { int i; + for (i = 0; i < num_brightmaps; ++i) + { + if (!strcasecmp(brightmaps_array[i].name, name)) + return &brightmaps_array[i]; + } + return NULL; +} + +static void ParseProperty(u_scanner_t *s, + void (*AddElem)(const char *name, brightmap_t *brightmap)) +{ char *name; + brightmap_t *brightmap; U_MustGetToken(s, TK_Identifier); name = M_StringDuplicate(s->string); U_MustGetToken(s, TK_Identifier); - for (i = 0; i < num_brightmaps; ++i) + brightmap = GetBrightmap(s->string); + if (brightmap) { - if (!strcasecmp(brightmaps_array[i].name, s->string)) - { - AddElem(name, &brightmaps_array[i]); - break; - } + AddElem(name, brightmap); } - if (i == num_brightmaps) + else { U_Error(s, "brightmap '%s' not found", s->string); } @@ -323,10 +298,22 @@ const byte *R_BrightmapForFlatNum(const int num) const byte *R_BrightmapForState(const int state) { + if (STRICTMODE(brightmaps)) + { + int i; + for (i = 0; i < num_states_bm; i++) + { + if (states_bm[i].num == state) + { + return states_bm[i].brightmap->colormask; + } + } + } + return nobrightmap; } -void R_ScanBrightmaps(int lumpnum) +void R_ParseBrightmaps(int lumpnum) { u_scanner_t scanner, *s; const char *data = W_CacheLumpNum(lumpnum, PU_CACHE); @@ -351,15 +338,37 @@ void R_ScanBrightmaps(int lumpnum) } else if (!strcasecmp("TEXTURE", s->string)) { - ScanElem(s, AddTexture); + ParseProperty(s, AddTexture); } else if (!strcasecmp("SPRITE", s->string)) { - ScanElem(s, AddSprite); + ParseProperty(s, AddSprite); } else if (!strcasecmp("FLAT", s->string)) { - ScanElem(s, AddFlat); + ParseProperty(s, AddFlat); + } + else if (!strcasecmp("STATE", s->string)) + { + int num; + brightmap_t *brightmap; + + U_MustGetInteger(s); + num = s->number; + if (num < 0 || num >= num_states) + { + U_Error(s, "state '%d' not found", num); + } + U_MustGetToken(s, TK_Identifier); + brightmap = GetBrightmap(s->string); + if (brightmap) + { + AddState(num, brightmap); + } + else + { + U_Error(s, "brightmap '%s' not found", s->string); + } } else { diff --git a/src/r_bmaps.h b/src/r_bmaps.h index 4b54242e6..232514575 100644 --- a/src/r_bmaps.h +++ b/src/r_bmaps.h @@ -24,7 +24,7 @@ extern int brightmaps; -void R_ScanBrightmaps(int lumpnum); +void R_ParseBrightmaps(int lumpnum); void R_InitFlatBrightmaps(void); From d76172872ebe5be86cf36f42607e53c91b335477 Mon Sep 17 00:00:00 2001 From: Roman Fomin Date: Mon, 9 Jan 2023 14:22:20 +0700 Subject: [PATCH 18/26] skip BRGHTMPS lumps in demo footer --- src/g_game.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/g_game.c b/src/g_game.c index 73eed6259..5e8ff6cac 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -3798,9 +3798,10 @@ extern char **dehfiles; static void G_AddDemoFooter(void) { - char *tmp = NULL; - size_t len = 0; int i; + size_t len = 0; + boolean has_files = false; + char *tmp; MEMFILE *stream = mem_fopen_write(); @@ -3811,10 +3812,18 @@ static void G_AddDemoFooter(void) for (i = 1; wadfiles[i]; i++) { - if (i == 1) + const char *base_name = M_BaseName(wadfiles[i]); + + if (!strcasecmp("brghtmps.lmp", base_name)) + continue; + + if (!has_files) + { mem_fputs(" -file", stream); + has_files = true; + } - tmp = M_StringJoin(" \"", M_BaseName(wadfiles[i]), "\"", NULL); + tmp = M_StringJoin(" \"", base_name, "\"", NULL); mem_fputs(tmp, stream); free(tmp); } From 7a7507855eabff8e36c37f2186788726a629fa51 Mon Sep 17 00:00:00 2001 From: Roman Fomin Date: Mon, 9 Jan 2023 14:27:32 +0700 Subject: [PATCH 19/26] must get integers in ReadColormask() --- src/r_bmaps.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/r_bmaps.c b/src/r_bmaps.c index c53a5fb9b..32f1fbbc1 100644 --- a/src/r_bmaps.c +++ b/src/r_bmaps.c @@ -46,7 +46,7 @@ static void ReadColormask(u_scanner_t *s, byte *colormask) { unsigned int color1 = 0, color2 = 0; - if (U_CheckInteger(s)) + if (U_MustGetInteger(s)) { color1 = s->number; if (color1 >= 0 && color1 < COLORMASK_SIZE) @@ -56,7 +56,7 @@ static void ReadColormask(u_scanner_t *s, byte *colormask) if (!U_CheckToken(s, '-')) continue; - if (U_CheckInteger(s)) + if (U_MustGetInteger(s)) { color2 = s->number; if (color2 >= 0 && color2 < COLORMASK_SIZE) From b31547e0be0e12b4b9dd09e057bd9a974eb0dc35 Mon Sep 17 00:00:00 2001 From: Roman Fomin Date: Mon, 9 Jan 2023 18:09:52 +0700 Subject: [PATCH 20/26] convert comments in hacx.wad/brghtmps.lmp --- autoload/hacx.wad/brghtmps.lmp | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/autoload/hacx.wad/brghtmps.lmp b/autoload/hacx.wad/brghtmps.lmp index 723edafd5..15994a890 100644 --- a/autoload/hacx.wad/brghtmps.lmp +++ b/autoload/hacx.wad/brghtmps.lmp @@ -5,33 +5,33 @@ BRIGHTMAP REDANDGREEN 16-47,112-127,173-191 BRIGHTMAP CHEXRED 176-177 BRIGHTMAP HACXLIGHTNING 4,168,192-199,208,224 -// {"BFALL1", DOOM2ONLY, redandgreen}, -// {"BFALL2", DOOM2ONLY, redandgreen}, -// {"BFALL3", DOOM2ONLY, redandgreen}, -// {"BFALL4", DOOM2ONLY, redandgreen}, +// TEXTURE BFALL1 REDANDGREEN +// TEXTURE BFALL2 REDANDGREEN +// TEXTURE BFALL3 REDANDGREEN +// TEXTURE BFALL4 REDANDGREEN TEXTURE BRNSMALR GREENONLY1 TEXTURE DOORRED REDANDGREEN TEXTURE SLADWALL CHEXRED -// {"SW1BRCOM", DOOM2ONLY, redonly}, -// {"SW1BRN1", DOOM2ONLY, redandgreen}, +// TEXTURE SW1BRCOM REDONLY +// TEXTURE SW1BRN1 REDANDGREEN TEXTURE SW1BRN2 NOTGRAYORBROWN TEXTURE SW1BRNGN NOTGRAYORBROWN -// {"SW1BROWN", DOOM2ONLY, notgrayorbrown}, -// {"SW2BRCOM", DOOM2ONLY, greenonly1}, -// {"SW2BRN1", DOOM2ONLY, redandgreen}, +// TEXTURE SW1BROWN NOTGRAYORBROWN +// TEXTURE SW2BRCOM GREENONLY1 +// TEXTURE SW2BRN1 REDANDGREEN TEXTURE SW2BRN2 NOTGRAYORBROWN -// {"SW2BROWN", DOOM2ONLY, notgrayorbrown}, +// TEXTURE SW2BROWN NOTGRAYORBROWN TEXTURE COMPSPAN GREENONLY1 TEXTURE COMPSTA1 NOTGRAYORBROWN -// {"COMPSTA2", DOOM2ONLY, notgrayorbrown}, +// TEXTURE COMPSTA2 NOTGRAYORBROWN TEXTURE HD5 REDANDGREEN -// {"HD8", DOOM2ONLY, redandgreen}, -// {"HD9", DOOM2ONLY, redandgreen}, +// TEXTURE HD8 REDANDGREEN +// TEXTURE HD9 REDANDGREEN TEXTURE BLAKWAL2 REDANDGREEN TEXTURE CEMENT7 GREENONLY1 TEXTURE ROCK4 REDONLY -// {"SLOPPY1", DOOM2ONLY, notgrayorbrown}, -// {"SPCDOOR4", DOOM2ONLY, notgrayorbrown}, +// TEXTURE SLOPPY1 NOTGRAYORBROWN +// TEXTURE SPCDOOR4 NOTGRAYORBROWN TEXTURE ZZZFACE1 GREENONLY1 TEXTURE ZZZFACE2 REDANDGREEN TEXTURE HW166 REDANDGREEN From 3c5ee4aa31cd792c7100892c5fb13eedeced64f5 Mon Sep 17 00:00:00 2001 From: Roman Fomin Date: Mon, 9 Jan 2023 19:24:16 +0700 Subject: [PATCH 21/26] add chex2.wad directory, add NOBRIGHTMAP special case --- autoload/chex.wad/brghtmps.lmp | 15 +++++++-------- autoload/chex2.wad/brghtmps.lmp | 5 +++++ autoload/doom-all/brghtmps.lmp | 3 +++ autoload/plutonia.wad/brghtmps.lmp | 3 --- src/r_bmaps.c | 8 ++++++++ 5 files changed, 23 insertions(+), 11 deletions(-) create mode 100644 autoload/chex2.wad/brghtmps.lmp delete mode 100644 autoload/plutonia.wad/brghtmps.lmp diff --git a/autoload/chex.wad/brghtmps.lmp b/autoload/chex.wad/brghtmps.lmp index c36c83f3b..ec08815d6 100644 --- a/autoload/chex.wad/brghtmps.lmp +++ b/autoload/chex.wad/brghtmps.lmp @@ -8,13 +8,12 @@ BRIGHTMAP CHEXGREEN 112-115 BRIGHTMAP CHEXREDGREEN 45,112-118,174-177 TEXTURE BIGDOOR1 GREENONLY3 -// {"BIGDOOR4", DOOM1AND2, greenonly3}, // C1: some stray green pixels, C2: many stray green pixels -// {"BRNBIGL", DOOM1AND2, greenonly3}, -// {"BRNBIGR", DOOM1AND2, greenonly3}, // C1, C2: one stray green pixel -// {"BRNSMAL2", DOOM1AND2, greenonly3}, // C1, C2: many stray green pixels +// TEXTURE BIGDOOR4 GREENONLY3 // C1: some stray green pixels, C2: many stray green pixels +// TEXTURE BRNBIGL GREENONLY3 +// TEXTURE BRNBIGR GREENONLY3 // C1, C2: one stray green pixel +// TEXTURE BRNSMAL2 GREENONLY3 // C1, C2: many stray green pixels TEXTURE COMP2 NOTGRAY -// {"COMPTALL", DOOM1ONLY, notgray}, -// {"COMPTALL", DOOM2ONLY, greenonly3}, // C2: many stray green pixels +// TEXTURE COMPTALL NOTGRAY TEXTURE COMPUTE2 NOTGRAY TEXTURE LITE5 GREENONLY2 TEXTURE STARTAN3 GREENONLY2 @@ -45,8 +44,8 @@ TEXTURE SW2STARG CHEXGREEN TEXTURE SW2STON1 CHEXGREEN TEXTURE SW2STONE CHEXGREEN TEXTURE SW2STRTN CHEXGREEN -// {"BIGDOOR5", DOOM1AND2, greenonly1}, // C1, C2: some stray green pixels -// {"BIGDOOR6", DOOM1AND2, greenonly1}, // C1, C2: some stray green pixels +// TEXTURE BIGDOOR5 GREENONLY1 // C1, C2: some stray green pixels +// TEXTURE BIGDOOR6 GREENONLY1 // C1, C2: some stray green pixels TEXTURE CEMENT3 GREENONLY3 TEXTURE SKINFACE GREENONLY1 TEXTURE SKINTEK1 GREENONLY1 diff --git a/autoload/chex2.wad/brghtmps.lmp b/autoload/chex2.wad/brghtmps.lmp new file mode 100644 index 000000000..5edd77bef --- /dev/null +++ b/autoload/chex2.wad/brghtmps.lmp @@ -0,0 +1,5 @@ +// TEXTURE COMPTALL GREENONLY3 // C2: many stray green pixels +TEXTURE LITE5 NOBRIGHTMAP +TEXTURE SKINTEK1 NOBRIGHTMAP +TEXTURE SW1VINE NOBRIGHTMAP // C1: some stray green pixels in the vines +TEXTURE SW2VINE NOBRIGHTMAP diff --git a/autoload/doom-all/brghtmps.lmp b/autoload/doom-all/brghtmps.lmp index 0cdccd844..797fcc521 100644 --- a/autoload/doom-all/brghtmps.lmp +++ b/autoload/doom-all/brghtmps.lmp @@ -72,6 +72,9 @@ TEXTURE LITEBLU2 NOTGRAY TEXTURE SW2SATYR BRIGHTTAN TEXTURE SW2LION BRIGHTTAN TEXTURE SW2GARG BRIGHTTAN +// [crispy] Final Doom textures +// Plutonia exclusive +//TEXTURE SW2SKULL REDONLY // Armor Bonus SPRITE BON2 GREENONLY2 diff --git a/autoload/plutonia.wad/brghtmps.lmp b/autoload/plutonia.wad/brghtmps.lmp deleted file mode 100644 index 713b662bc..000000000 --- a/autoload/plutonia.wad/brghtmps.lmp +++ /dev/null @@ -1,3 +0,0 @@ -// [crispy] Final Doom textures -// Plutonia exclusive -//TEXTURE SW2SKULL REDONLY diff --git a/src/r_bmaps.c b/src/r_bmaps.c index 32f1fbbc1..a2c8d6806 100644 --- a/src/r_bmaps.c +++ b/src/r_bmaps.c @@ -319,6 +319,14 @@ void R_ParseBrightmaps(int lumpnum) const char *data = W_CacheLumpNum(lumpnum, PU_CACHE); int length = W_LumpLength(lumpnum); + if (!num_brightmaps) + { + brightmap_t brightmap; + brightmap.name = "NOBRIGHTMAP"; + memset(brightmap.colormask, 0, COLORMASK_SIZE); + AddBrightmap(&brightmap); + } + scanner = U_ScanOpen(data, length, "BRGHTMPS"); s = &scanner; while (U_HasTokensLeft(s)) From c12278f231a68bd8e2680ebcce0c99d2af447002 Mon Sep 17 00:00:00 2001 From: Roman Fomin Date: Tue, 10 Jan 2023 16:51:03 +0700 Subject: [PATCH 22/26] implement optional DOOM|DOOM2 fields --- autoload/doom-all/brghtmps.lmp | 12 +++++++++ autoload/doom.wad/brghtmps.lmp | 1 - autoload/doom2.wad/brghtmps.lmp | 11 -------- src/r_bmaps.c | 47 ++++++++++++++++++++++++++------- src/u_scanner.c | 5 ++++ src/u_scanner.h | 1 + 6 files changed, 56 insertions(+), 21 deletions(-) delete mode 100644 autoload/doom.wad/brghtmps.lmp delete mode 100644 autoload/doom2.wad/brghtmps.lmp diff --git a/autoload/doom-all/brghtmps.lmp b/autoload/doom-all/brghtmps.lmp index 797fcc521..908b6179d 100644 --- a/autoload/doom-all/brghtmps.lmp +++ b/autoload/doom-all/brghtmps.lmp @@ -72,6 +72,18 @@ TEXTURE LITEBLU2 NOTGRAY TEXTURE SW2SATYR BRIGHTTAN TEXTURE SW2LION BRIGHTTAN TEXTURE SW2GARG BRIGHTTAN +TEXTURE SW2STON2 REDONLY DOOM +TEXTURE SW1BRN1 REDONLY DOOM2 +TEXTURE SW1STARG REDONLY DOOM2 +TEXTURE SW1STON2 REDONLY DOOM2 +TEXTURE SW2MARB REDONLY DOOM2 +TEXTURE SW2STARG GREENONLY2 DOOM2 +TEXTURE SW2STON2 GREENONLY2 DOOM2 +TEXTURE SPCDOOR3 GREENONLY1 DOOM2 +TEXTURE PIPEWAL1 GREENONLY1 DOOM2 +TEXTURE TEKLITE2 GREENONLY1 DOOM2 +TEXTURE TEKBRON2 YELLOWONLY DOOM2 +//TEXTURE SW2SKULL GREENONLY2 DOOM2 // [crispy] Final Doom textures // Plutonia exclusive //TEXTURE SW2SKULL REDONLY diff --git a/autoload/doom.wad/brghtmps.lmp b/autoload/doom.wad/brghtmps.lmp deleted file mode 100644 index d2d8319f6..000000000 --- a/autoload/doom.wad/brghtmps.lmp +++ /dev/null @@ -1 +0,0 @@ -TEXTURE SW2STON2 REDONLY diff --git a/autoload/doom2.wad/brghtmps.lmp b/autoload/doom2.wad/brghtmps.lmp deleted file mode 100644 index 4e6033086..000000000 --- a/autoload/doom2.wad/brghtmps.lmp +++ /dev/null @@ -1,11 +0,0 @@ -TEXTURE SW1BRN1 REDONLY -TEXTURE SW1STARG REDONLY -TEXTURE SW1STON2 REDONLY -TEXTURE SW2MARB REDONLY -TEXTURE SW2STARG GREENONLY2 -TEXTURE SW2STON2 GREENONLY2 -TEXTURE SPCDOOR3 GREENONLY1 -TEXTURE PIPEWAL1 GREENONLY1 -TEXTURE TEKLITE2 GREENONLY1 -TEXTURE TEKBRON2 YELLOWONLY -//TEXTURE SW2SKULL GREENONLY2 diff --git a/src/r_bmaps.c b/src/r_bmaps.c index a2c8d6806..3fcc8498f 100644 --- a/src/r_bmaps.c +++ b/src/r_bmaps.c @@ -217,9 +217,17 @@ static brightmap_t *GetBrightmap(const char *name) return NULL; } +enum +{ + DOOM1AND2, + DOOM1ONLY, + DOOM2ONLY +}; + static void ParseProperty(u_scanner_t *s, void (*AddElem)(const char *name, brightmap_t *brightmap)) { + int game = DOOM1AND2; char *name; brightmap_t *brightmap; @@ -227,14 +235,39 @@ static void ParseProperty(u_scanner_t *s, name = M_StringDuplicate(s->string); U_MustGetToken(s, TK_Identifier); brightmap = GetBrightmap(s->string); - if (brightmap) + if (!brightmap) { - AddElem(name, brightmap); + free(name); + U_Error(s, "brightmap '%s' not found", s->string); } - else + if (U_CheckToken(s, TK_Identifier)) { - U_Error(s, "brightmap '%s' not found", s->string); + if (!strcasecmp("DOOM", s->string) || !strcasecmp("DOOM1", s->string)) + { + game = DOOM1ONLY; + if (U_CheckToken(s, '|')) + { + if (U_MustGetIdentifier(s, "DOOM2")) + game = DOOM1AND2; + } + } + else if (!strcasecmp("DOOM2", s->string)) + { + game = DOOM2ONLY; + } + else + { + U_Unget(s); + } + } + if ((gamemission == doom && game == DOOM2ONLY) || + (gamemission == doom2 && game == DOOM1ONLY)) + { + free(name); + return; } + + AddElem(name, brightmap); free(name); } @@ -333,7 +366,7 @@ void R_ParseBrightmaps(int lumpnum) { if (!U_CheckToken(s, TK_Identifier)) { - U_GetNextLineToken(s); + U_GetNextToken(s, true); continue; } if (!strcasecmp("BRIGHTMAP", s->string)) @@ -378,10 +411,6 @@ void R_ParseBrightmaps(int lumpnum) U_Error(s, "brightmap '%s' not found", s->string); } } - else - { - U_GetNextLineToken(s); - } } U_ScanClose(s); } diff --git a/src/u_scanner.c b/src/u_scanner.c index b1229627b..b8ddc6b31 100644 --- a/src/u_scanner.c +++ b/src/u_scanner.c @@ -518,6 +518,11 @@ boolean U_MustGetIdentifier(u_scanner_t* s, const char *ident) return true; } +void U_Unget(u_scanner_t* s) +{ + s->needNext = false; +} + // Convenience helpers that parse an entire number including a leading minus or // plus sign static boolean U_ScanInteger(u_scanner_t* s) diff --git a/src/u_scanner.h b/src/u_scanner.h index 70a67a33e..83f8417d9 100644 --- a/src/u_scanner.h +++ b/src/u_scanner.h @@ -100,6 +100,7 @@ boolean U_MustGetFloat(u_scanner_t* s); boolean U_CheckToken(u_scanner_t* scanner, char token); boolean U_CheckInteger(u_scanner_t* s); boolean U_CheckFloat(u_scanner_t* s); +void U_Unget(u_scanner_t* s); void PRINTF_ATTR(2, 0) U_Error(u_scanner_t* s, const char *msg, ...); void U_ErrorToken(u_scanner_t* s, int token); From a9d8ddf82e2051e9b66b3c3acefa179ce590e56e Mon Sep 17 00:00:00 2001 From: Roman Fomin Date: Tue, 10 Jan 2023 17:18:13 +0700 Subject: [PATCH 23/26] search from the end of the array to find the latest version of the element --- src/r_bmaps.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/r_bmaps.c b/src/r_bmaps.c index 3fcc8498f..17efd94e3 100644 --- a/src/r_bmaps.c +++ b/src/r_bmaps.c @@ -284,7 +284,7 @@ const byte *R_BrightmapForTexName(const char *texname) { int i; - for (i = 0; i < num_textures_bm; i++) + for (i = num_textures_bm - 1; i >= 0; i--) { if (!strncasecmp(textures_bm[i].name, texname, 8)) { @@ -300,7 +300,7 @@ const byte *R_BrightmapForSprite(const int type) if (STRICTMODE(brightmaps)) { int i; - for (i = 0; i < num_sprites_bm; i++) + for (i = num_sprites_bm - 1; i >= 0 ; i--) { if (sprites_bm[i].type == type) { @@ -317,7 +317,7 @@ const byte *R_BrightmapForFlatNum(const int num) if (STRICTMODE(brightmaps)) { int i; - for (i = 0; i < num_flats_bm; i++) + for (i = num_flats_bm - 1; i >= 0; i--) { if (flats_bm[i].num == num) { @@ -334,7 +334,7 @@ const byte *R_BrightmapForState(const int state) if (STRICTMODE(brightmaps)) { int i; - for (i = 0; i < num_states_bm; i++) + for (i = num_states_bm - 1; i >= 0; i--) { if (states_bm[i].num == state) { From 87736484c3732cfa81ce07e56519be7beb59b1b0 Mon Sep 17 00:00:00 2001 From: Roman Fomin Date: Tue, 10 Jan 2023 17:35:59 +0700 Subject: [PATCH 24/26] fix cppcheck --- src/r_bmaps.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/r_bmaps.c b/src/r_bmaps.c index 17efd94e3..3a9b80a1d 100644 --- a/src/r_bmaps.c +++ b/src/r_bmaps.c @@ -237,7 +237,6 @@ static void ParseProperty(u_scanner_t *s, brightmap = GetBrightmap(s->string); if (!brightmap) { - free(name); U_Error(s, "brightmap '%s' not found", s->string); } if (U_CheckToken(s, TK_Identifier)) From 7122f705706a6e4b4b407e57269c47890498cd69 Mon Sep 17 00:00:00 2001 From: Roman Fomin Date: Tue, 10 Jan 2023 18:57:25 +0700 Subject: [PATCH 25/26] generalize arrays --- src/r_bmaps.c | 205 ++++++++++++++++++-------------------------------- 1 file changed, 72 insertions(+), 133 deletions(-) diff --git a/src/r_bmaps.c b/src/r_bmaps.c index 3a9b80a1d..6cdf51ac3 100644 --- a/src/r_bmaps.c +++ b/src/r_bmaps.c @@ -88,122 +88,37 @@ static void AddBrightmap(brightmap_t *brightmap) num_brightmaps++; } -typedef struct { - brightmap_t *brightmap; - const char *name; -} texture_bm_t; - -#define TEXTURES_INITIAL_SIZE 32 -static texture_bm_t *textures_bm; -static int num_textures_bm; - -static void AddTexture(const char *name, brightmap_t *brightmap) -{ - static int size; - texture_bm_t texture; - - texture.name = M_StringDuplicate(name); - texture.brightmap = brightmap; - - if (num_textures_bm >= size) - { - size = (size ? size * 2 : TEXTURES_INITIAL_SIZE); - textures_bm = I_Realloc(textures_bm, size * sizeof(texture_bm_t)); - } - - textures_bm[num_textures_bm++] = texture; -} - -typedef struct -{ - brightmap_t *brightmap; - int type; -} sprite_bm_t; - -#define SPRITES_INITIAL_SIZE 32 -static sprite_bm_t *sprites_bm; -static int num_sprites_bm; - -static void AddSprite(const char *name, brightmap_t *brightmap) -{ - int i; - static int size; - sprite_bm_t sprite; - - for (i = 0; i < num_sprites; ++i) - { - if (!strcasecmp(name, sprnames[i])) - break; - } - if (i == num_sprites) - return; - - sprite.type = i; - sprite.brightmap = brightmap; - - if (num_sprites_bm >= size) - { - size = (size ? size * 2 : SPRITES_INITIAL_SIZE); - sprites_bm = I_Realloc(sprites_bm, size * sizeof(sprite_bm_t)); - } - - sprites_bm[num_sprites_bm++] = sprite; -} - typedef struct { brightmap_t *brightmap; const char *name; int num; -} flat_bm_t; - -#define FLATS_INITIAL_SIZE 32 -static flat_bm_t *flats_bm; -static int num_flats_bm; +} elem_t; -static void AddFlat(const char *name, brightmap_t *brightmap) -{ - static int size; - flat_bm_t flat; - - flat.name = M_StringDuplicate(name); - flat.num = -1; - flat.brightmap = brightmap; - - if (num_flats_bm >= size) - { - size = (size ? size * 2 : SPRITES_INITIAL_SIZE); - flats_bm = I_Realloc(flats_bm, size * sizeof(flat_bm_t)); - } - - flats_bm[num_flats_bm++] = flat; -} +#define ELEMS_INITIAL_SIZE 32 typedef struct { - brightmap_t *brightmap; - int num; -} state_bm_t; + elem_t *elems; + int num_elems; + int size; +} array_t; -#define STATES_INITIAL_SIZE 32 -static state_bm_t *states_bm; -static int num_states_bm; +static array_t textures_bm; +static array_t flats_bm; +static array_t sprites_bm; +static array_t states_bm; -static void AddState(int num, brightmap_t *brightmap) +static void AddElem(array_t *array, elem_t *elem) { - static int size; - state_bm_t state; - - state.num = num; - state.brightmap = brightmap; - - if (num_states_bm >= size) + if (array->num_elems >= array->size) { - size = (size ? size * 2 : SPRITES_INITIAL_SIZE); - states_bm = I_Realloc(states_bm, size * sizeof(state_bm_t)); + array->size = array->size ? 2 * array->size : ELEMS_INITIAL_SIZE; + array->elems = I_Realloc(array->elems, array->size * sizeof(elem_t)); } - states_bm[num_states_bm++] = state; + memcpy(array->elems + array->num_elems, elem, sizeof(elem_t)); + array->num_elems++; } static brightmap_t *GetBrightmap(const char *name) @@ -224,13 +139,13 @@ enum DOOM2ONLY }; -static void ParseProperty(u_scanner_t *s, - void (*AddElem)(const char *name, brightmap_t *brightmap)) +static boolean ParseProperty(u_scanner_t *s, elem_t *elem) { - int game = DOOM1AND2; char *name; brightmap_t *brightmap; + int game = DOOM1AND2; + U_MustGetToken(s, TK_Identifier); name = M_StringDuplicate(s->string); U_MustGetToken(s, TK_Identifier); @@ -238,6 +153,8 @@ static void ParseProperty(u_scanner_t *s, if (!brightmap) { U_Error(s, "brightmap '%s' not found", s->string); + free(name); + return false; } if (U_CheckToken(s, TK_Identifier)) { @@ -263,19 +180,20 @@ static void ParseProperty(u_scanner_t *s, (gamemission == doom2 && game == DOOM1ONLY)) { free(name); - return; + return false; } - AddElem(name, brightmap); - free(name); + elem->name = name; + elem->brightmap = brightmap; + return true; } void R_InitFlatBrightmaps(void) { int i; - for (i = 0; i < num_flats_bm; ++i) + for (i = 0; i < flats_bm.num_elems; ++i) { - flats_bm[i].num = R_FlatNumForName(flats_bm[i].name); + flats_bm.elems[i].num = R_FlatNumForName(flats_bm.elems[i].name); } } @@ -283,11 +201,11 @@ const byte *R_BrightmapForTexName(const char *texname) { int i; - for (i = num_textures_bm - 1; i >= 0; i--) + for (i = textures_bm.num_elems - 1; i >= 0; i--) { - if (!strncasecmp(textures_bm[i].name, texname, 8)) + if (!strncasecmp(textures_bm.elems[i].name, texname, 8)) { - return textures_bm[i].brightmap->colormask; + return textures_bm.elems[i].brightmap->colormask; } } @@ -299,11 +217,11 @@ const byte *R_BrightmapForSprite(const int type) if (STRICTMODE(brightmaps)) { int i; - for (i = num_sprites_bm - 1; i >= 0 ; i--) + for (i = sprites_bm.num_elems - 1; i >= 0 ; i--) { - if (sprites_bm[i].type == type) + if (sprites_bm.elems[i].num == type) { - return sprites_bm[i].brightmap->colormask; + return sprites_bm.elems[i].brightmap->colormask; } } } @@ -316,11 +234,11 @@ const byte *R_BrightmapForFlatNum(const int num) if (STRICTMODE(brightmaps)) { int i; - for (i = num_flats_bm - 1; i >= 0; i--) + for (i = flats_bm.num_elems - 1; i >= 0; i--) { - if (flats_bm[i].num == num) + if (flats_bm.elems[i].num == num) { - return flats_bm[i].brightmap->colormask; + return flats_bm.elems[i].brightmap->colormask; } } } @@ -333,11 +251,11 @@ const byte *R_BrightmapForState(const int state) if (STRICTMODE(brightmaps)) { int i; - for (i = num_states_bm - 1; i >= 0; i--) + for (i = states_bm.num_elems - 1; i >= 0; i--) { - if (states_bm[i].num == state) + if (states_bm.elems[i].num == state) { - return states_bm[i].brightmap->colormask; + return states_bm.elems[i].brightmap->colormask; } } } @@ -378,32 +296,53 @@ void R_ParseBrightmaps(int lumpnum) } else if (!strcasecmp("TEXTURE", s->string)) { - ParseProperty(s, AddTexture); + elem_t elem; + if (ParseProperty(s, &elem)) + { + AddElem(&textures_bm, &elem); + } } else if (!strcasecmp("SPRITE", s->string)) { - ParseProperty(s, AddSprite); + elem_t elem; + if (ParseProperty(s, &elem)) + { + int i; + for (i = 0; i < num_sprites; ++i) + { + if (!strcasecmp(elem.name, sprnames[i])) + break; + } + if (i == num_sprites) + { + U_Error(s, "sprite '%s' not found", elem.name); + } + elem.num = i; + AddElem(&sprites_bm, &elem); + } } else if (!strcasecmp("FLAT", s->string)) { - ParseProperty(s, AddFlat); + elem_t elem; + if (ParseProperty(s, &elem)) + { + AddElem(&flats_bm, &elem); + } } else if (!strcasecmp("STATE", s->string)) { - int num; - brightmap_t *brightmap; - + elem_t elem; U_MustGetInteger(s); - num = s->number; - if (num < 0 || num >= num_states) + elem.num = s->number; + if (elem.num < 0 || elem.num >= num_states) { - U_Error(s, "state '%d' not found", num); + U_Error(s, "state '%d' not found", elem.num); } U_MustGetToken(s, TK_Identifier); - brightmap = GetBrightmap(s->string); - if (brightmap) + elem.brightmap = GetBrightmap(s->string); + if (elem.brightmap) { - AddState(num, brightmap); + AddElem(&states_bm, &elem); } else { From 54ea0d43f11fd88b55c2ebbd8e15f6ecf8a5b8f6 Mon Sep 17 00:00:00 2001 From: Roman Fomin Date: Tue, 10 Jan 2023 19:12:43 +0700 Subject: [PATCH 26/26] fix cppcheck --- src/r_bmaps.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/r_bmaps.c b/src/r_bmaps.c index 6cdf51ac3..d6b085e29 100644 --- a/src/r_bmaps.c +++ b/src/r_bmaps.c @@ -332,6 +332,7 @@ void R_ParseBrightmaps(int lumpnum) else if (!strcasecmp("STATE", s->string)) { elem_t elem; + elem.name = NULL; U_MustGetInteger(s); elem.num = s->number; if (elem.num < 0 || elem.num >= num_states)