From 6afcb06e088ec9d899267054af4a807214885efe Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 2 Dec 2024 20:56:21 +0100 Subject: [PATCH] forgor - refactored musicdef handling - other things --- src/hardware/hw_batching.c | 1 - src/hardware/hw_draw.c | 8 +- src/k_kart.c | 2 +- src/p_setup.c | 5 - src/p_user.c | 3 +- src/s_sound.c | 458 +++++++++++++------------------------ src/s_sound.h | 1 + 7 files changed, 164 insertions(+), 314 deletions(-) diff --git a/src/hardware/hw_batching.c b/src/hardware/hw_batching.c index 138c35a5d..e32a7162a 100644 --- a/src/hardware/hw_batching.c +++ b/src/hardware/hw_batching.c @@ -17,7 +17,6 @@ #include "../qs22j.h" - // The texture for the next polygon given to HWR_ProcessPolygon. // Set with HWR_SetCurrentTexture. GLMipmap_t *current_texture = NULL; diff --git a/src/hardware/hw_draw.c b/src/hardware/hw_draw.c index efb4eeaa3..768e523e0 100644 --- a/src/hardware/hw_draw.c +++ b/src/hardware/hw_draw.c @@ -588,9 +588,9 @@ void HWR_FadeScreenMenuBack(UINT16 color, UINT8 strength) Surf.PolyColor.s.alpha = (strength*8); poly_flags |= PF_Translucent; } - } - else // Do TRANSMAP** fade. - { + } + else // Do TRANSMAP** fade. + { RGBA_t *palette = HWR_GetTexturePalette(); Surf.PolyColor.rgba = palette[color&0xFF].rgba; @@ -600,7 +600,7 @@ void HWR_FadeScreenMenuBack(UINT16 color, UINT8 strength) Surf.PolyColor.s.alpha = (UINT8)(strength*25.5f); poly_flags |= PF_Translucent; - } + } HWD.pfnDrawPolygon(&Surf, v, 4, poly_flags); } diff --git a/src/k_kart.c b/src/k_kart.c index 9ec6f6c7b..e9becb30e 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -8834,7 +8834,7 @@ static void K_drawKartSpeedometer(void) { UINT8 *colormap = R_GetTranslationColormap(TC_DEFAULT, K_GetHudColor(), GTC_CACHE); V_DrawStretchyFixedPatch((SPDM_X-1)<pflags & PF_TAGIT))) + if (cv_seenames.value && cv_allowseenames.value) { mobj_t *mo = P_SpawnNameFinder(player->mo, MT_NAMECHECK); diff --git a/src/s_sound.c b/src/s_sound.c index 1bbe154e3..065d56082 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -1258,175 +1258,191 @@ static UINT32 queue_fadeinms; musicdef_t *musicdefstart = NULL; // First music definition struct cursongcredit cursongcredit; // Currently displayed song credit info -// -// search for music definition in wad -// -static UINT16 W_CheckForMusicDefInPwad(UINT16 wadid) +static boolean +ReadMusicDefFields (UINT16 wadnum, int line, char *stoken, musicdef_t **defp) { - UINT16 i; - lumpinfo_t *lump_p; + musicdef_t *def; - lump_p = wadfiles[wadid]->lumpinfo; - for (i = 0; i < wadfiles[wadid]->numlumps; i++, lump_p++) - if (memcmp(lump_p->name, "MUSICDEF", 8) == 0) - return i; - - return INT16_MAX; // not found -} - -void S_LoadMusicDefs(UINT16 wadnum) -{ - UINT16 lump; - char *buf; - char *buf2; - char *stoken; char *value; - size_t size; - musicdef_t *def, *prev; - UINT16 line = 1; // for better error msgs + char *textline; - lump = W_CheckForMusicDefInPwad(wadnum); - if (lump == INT16_MAX) - return; - - buf = W_CacheLumpNumPwad(wadnum, lump, PU_CACHE); - size = W_LumpLengthPwad(wadnum, lump); - - // for strtok - buf2 = malloc(size+1); - if (!buf2) - I_Error("S_LoadMusicDefs: No more free memory\n"); - M_Memcpy(buf2,buf,size); - buf2[size] = '\0'; - - def = prev = NULL; - - stoken = strtok (buf2, "\r\n "); - // Find music def - while (stoken) + if (!stricmp(stoken, "lump")) { - if (!stricmp(stoken, "lump")) + value = strtok(NULL, " "); + if (!value) { - value = strtok(NULL, "\r\n "); - - if (!value) - { - CONS_Alert(CONS_WARNING, "MUSICDEF: Lump '%s' is missing name. (file %s, line %d)\n", stoken, wadfiles[wadnum]->filename, line); - stoken = strtok(NULL, "\r\n"); // skip end of line - goto skip_lump; - } - - // No existing musicdefs - if (!musicdefstart) - { - musicdefstart = Z_Calloc(sizeof (musicdef_t), PU_STATIC, NULL); - STRBUFCPY(musicdefstart->name, value); - strlwr(musicdefstart->name); - def = musicdefstart; - //CONS_Printf("S_LoadMusicDefs: Initialized musicdef w/ song '%s'\n", def->name); - } - else - { - def = musicdefstart; - - // Search if this is a replacement - //CONS_Printf("S_LoadMusicDefs: Searching for song replacement...\n"); - while (def) - { - if (!stricmp(def->name, value)) - { - //CONS_Printf("S_LoadMusicDefs: Found song replacement '%s'\n", def->name); - break; - } - - prev = def; - def = def->next; - } - - // Nothing found, add to the end. - if (!def) - { - def = Z_Calloc(sizeof (musicdef_t), PU_STATIC, NULL); - STRBUFCPY(def->name, value); - strlwr(def->name); - if (prev != NULL) - prev->next = def; - //CONS_Printf("S_LoadMusicDefs: Added song '%s'\n", def->name); - } - } - - strncpy(def->filename, wadfiles[wadnum]->filename, 256); - def->filename[256] = '\0'; - -skip_lump: - stoken = strtok(NULL, "\r\n "); - line++; + CONS_Alert(CONS_WARNING, + "MUSICDEF: Field '%s' is missing name. (file %s, line %d)\n", + stoken, wadfiles[wadnum]->filename, line); + return false; } else { - value = strtok(NULL, "\r\n= "); + def = S_FindMusicCredit(value); - if (!value) + // Nothing found, add to the end. + if (!def) { - CONS_Alert(CONS_WARNING, "MUSICDEF: Field '%s' is missing value. (file %s, line %d)\n", stoken, wadfiles[wadnum]->filename, line); - stoken = strtok(NULL, "\r\n"); // skip end of line - goto skip_field; + def = Z_Calloc(sizeof (musicdef_t), PU_STATIC, NULL); + + STRBUFCPY(def->name, value); + strlwr(def->name); + def->hash = quickncasehash (def->name, 6); + + def->next = musicdefstart; + musicdefstart = def; } + (*defp) = def; + } + } + else + { + value = strtok(NULL, ""); + + if (value) + { + // Find the equals sign. + value = strchr(value, '='); + } + + if (!value) + { + CONS_Alert(CONS_WARNING, + "MUSICDEF: Field '%s' is missing value. (file %s, line %d)\n", + stoken, wadfiles[wadnum]->filename, line); + return false; + } + else + { + def = (*defp); + if (!def) { - CONS_Alert(CONS_ERROR, "MUSICDEF: No music definition before field '%s'. (file %s, line %d)\n", stoken, wadfiles[wadnum]->filename, line); - free(buf2); - return; + CONS_Alert(CONS_ERROR, + "MUSICDEF: No music definition before field '%s'. (file %s, line %d)\n", + stoken, wadfiles[wadnum]->filename, line); + return false; } - + + // Skip the equals sign. + value++; + + // Now skip funny whitespace. + value += strspn(value, "\t "); + + textline = value; + +// turn _ into spaces. +#define ADDDEF(field)\ + STRBUFCPY(def->field, textline);\ + for (textline = def->field; *textline; textline++)\ + if (*textline == '_') *textline = ' '; + if (!stricmp(stoken, "usage")) { - STRBUFCPY(def->usage, value); - for (value = def->usage; *value; value++) - if (*value == '_') *value = ' '; // turn _ into spaces. - //CONS_Printf("S_LoadMusicDefs: Set usage to '%s'\n", def->usage); + ADDDEF(usage); } else if (!stricmp(stoken, "source")) { - STRBUFCPY(def->source, value); - for (value = def->source; *value; value++) - if (*value == '_') *value = ' '; // turn _ into spaces. - //CONS_Printf("S_LoadMusicDefs: Set source to '%s'\n", def->source); + ADDDEF(source); } else if (!stricmp(stoken, "title")) { def->use_info = true; - STRBUFCPY(def->title, value); - for (value = def->title; *value; value++) - if (*value == '_') *value = ' '; // turn _ into spaces. - //CONS_Printf("S_LoadMusicDefs: Set source to '%s'\n", def->source); + ADDDEF(title); } else if (!stricmp(stoken, "alttitle")) { - STRBUFCPY(def->alttitle, value); - for (value = def->alttitle; *value; value++) - if (*value == '_') *value = ' '; // turn _ into spaces. - //CONS_Printf("S_LoadMusicDefs: Set source to '%s'\n", def->source); + ADDDEF(alttitle); } else if (!stricmp(stoken, "authors")) { - STRBUFCPY(def->authors, value); - for (value = def->authors; *value; value++) - if (*value == '_') *value = ' '; // turn _ into spaces. - //CONS_Printf("S_LoadMusicDefs: Set source to '%s'\n", def->source); + ADDDEF(authors); } else CONS_Alert(CONS_WARNING, "MUSICDEF: Invalid field '%s'. (file %s, line %d)\n", stoken, wadfiles[wadnum]->filename, line); - -skip_field: - stoken = strtok(NULL, "\r\n= "); - line++; +#undef ADDDEF } } - free(buf2); - return; + return true; +} + +void S_LoadMusicDefs(UINT16 wadnum) +{ + UINT16 lumpnum; + char *lump; + char *musdeftext; + size_t size; + + char *lf; + char *stoken; + + size_t nlf; + size_t ncr; + + musicdef_t *def = NULL; + int line = 1; // for better error msgs + + for (int k = 0; k < 2; k++) + { + lumpnum = W_CheckNumForNamePwad((k == 1 ? "MUSCINFO" : "MUSICDEF") , wadnum, 0); //check for MUSCINFO lump on 2nd iteration + + if (lumpnum == INT16_MAX) + continue; + + lump = W_CacheLumpNumPwad(wadnum, lumpnum, PU_CACHE); + size = W_LumpLengthPwad(wadnum, lumpnum); + + // Null-terminated MUSICDEF lump. + musdeftext = malloc(size+1); + if (!musdeftext) + I_Error("S_LoadMusicDefs: No more free memory for the parser\n"); + M_Memcpy(musdeftext, lump, size); + musdeftext[size] = '\0'; + + // Find music def + stoken = musdeftext; + for (;;) + { + lf = strpbrk(stoken, "\r\n"); + if (lf) + { + if (*lf == '\n') + nlf = 1; + else + nlf = 0; + *lf++ = '\0';/* now we can delimit to here */ + } + + stoken = strtok(stoken, " "); + if (stoken) + { + if (! ReadMusicDefFields(wadnum, line, stoken, &def)) + break; + } + + if (lf) + { + do + { + line += nlf; + ncr = strspn(lf, "\r");/* skip CR */ + lf += ncr; + nlf = strspn(lf, "\n"); + lf += nlf; + } + while (nlf || ncr) ; + + stoken = lf;/* now the next nonempty line */ + } + else + break;/* EOF */ + } + + free(musdeftext); + } } // @@ -1441,164 +1457,6 @@ void S_InitMusicDefs(void) S_LoadMusicDefs(i); } -// -// search for music definition in wad -// -static UINT16 W_CheckForMusicInfoInPwad(UINT16 wadid) -{ - UINT16 i; - lumpinfo_t *lump_p; - - lump_p = wadfiles[wadid]->lumpinfo; - for (i = 0; i < wadfiles[wadid]->numlumps; i++, lump_p++) - if (memcmp(lump_p->name, "MUSCINFO", 8) == 0) - return i; - - return INT16_MAX; // not found -} - -void S_LoadMTDefs(UINT16 wadnum) -{ - UINT16 lump; - char *buf; - char *buf2; - char *stoken; - char *value; - size_t size; - musicdef_t *def, *prev; - UINT16 line = 1; // for better error msgs - - lump = W_CheckForMusicInfoInPwad(wadnum); - if (lump == INT16_MAX) - return; - - buf = W_CacheLumpNumPwad(wadnum, lump, PU_CACHE); - size = W_LumpLengthPwad(wadnum, lump); - - // for strtok - buf2 = malloc(size+1); - if (!buf2) - I_Error("S_LoadMTDefs: No more free memory\n"); - M_Memcpy(buf2,buf,size); - buf2[size] = '\0'; - - def = prev = NULL; - - stoken = strtok (buf2, "\r\n "); - // Find music def - while (stoken) - { - if (!stricmp(stoken, "lump")) - { - value = strtok(NULL, "\r\n "); - - if (!value) - { - CONS_Alert(CONS_WARNING, "MUSICDEF: Lump '%s' is missing name. (file %s, line %d)\n", stoken, wadfiles[wadnum]->filename, line); - stoken = strtok(NULL, "\r\n"); // skip end of line - goto skip_lump; - } - - // No existing musicdefs - if (!musicdefstart) - { - musicdefstart = Z_Calloc(sizeof (musicdef_t), PU_STATIC, NULL); - STRBUFCPY(musicdefstart->name, value); - strlwr(musicdefstart->name); - def = musicdefstart; - //CONS_Printf("S_LoadMusicDefs: Initialized musicdef w/ song '%s'\n", def->name); - } - else - { - def = musicdefstart; - - // Search if this is a replacement - //CONS_Printf("S_LoadMusicDefs: Searching for song replacement...\n"); - while (def) - { - if (!stricmp(def->name, value)) - { - //CONS_Printf("S_LoadMusicDefs: Found song replacement '%s'\n", def->name); - break; - } - - prev = def; - def = def->next; - } - - // Nothing found, abort. - if (!def) - { - CONS_Alert(CONS_WARNING, "MUSCINFO: Music def for '%s' does not exist. (file %s, line %d)\n", stoken, wadfiles[wadnum]->filename, line); - free(buf2); - return; - } - } - -skip_lump: - stoken = strtok(NULL, "\r\n "); - line++; - } - else - { - value = strtok(NULL, "\r\n= "); - - if (!value) - { - CONS_Alert(CONS_WARNING, "MUSCINFO: Field '%s' is missing value. (file %s, line %d)\n", stoken, wadfiles[wadnum]->filename, line); - stoken = strtok(NULL, "\r\n"); // skip end of line - goto skip_field; - } - - if (!def) - { - CONS_Alert(CONS_ERROR, "MUSCINFO: No music definition before field '%s'. (file %s, line %d)\n", stoken, wadfiles[wadnum]->filename, line); - free(buf2); - return; - } - - if (!stricmp(stoken, "title")) - { - def->use_info = true; - STRBUFCPY(def->title, value); - for (value = def->title; *value; value++) - if (*value == '_') *value = ' '; // turn _ into spaces. - //CONS_Printf("S_LoadMusicDefs: Set source to '%s'\n", def->source); - } - else if (!stricmp(stoken, "alttitle")) - { - STRBUFCPY(def->alttitle, value); - for (value = def->alttitle; *value; value++) - if (*value == '_') *value = ' '; // turn _ into spaces. - //CONS_Printf("S_LoadMusicDefs: Set source to '%s'\n", def->source); - } - else if (!stricmp(stoken, "authors")) - { - STRBUFCPY(def->authors, value); - for (value = def->authors; *value; value++) - if (*value == '_') *value = ' '; // turn _ into spaces. - //CONS_Printf("S_LoadMusicDefs: Set source to '%s'\n", def->source); - } - else - CONS_Alert(CONS_WARNING, "MUSCINFO: Invalid field '%s'. (file %s, line %d)\n", stoken, wadfiles[wadnum]->filename, line); - -skip_field: - stoken = strtok(NULL, "\r\n= "); - line++; - } - } - - free(buf2); - return; -} - -void S_InitMTDefs(void) -{ - UINT16 i; - for (i = 0; i < numwadfiles; i++) - S_LoadMTDefs(i); -} - // // S_FindMusicCredit // @@ -1606,19 +1464,17 @@ void S_InitMTDefs(void) // musicdef_t *S_FindMusicCredit(const char *musname) { - musicdef_t *def = musicdefstart; + UINT32 hash = quickncasehash (musname, 6); + musicdef_t *def; - if (!def) // No definitions - return NULL; - - while (def) + for (def = musicdefstart; def; def = def->next) { - if (!stricmp(def->name, musname)) - { - return def; - } - else - def = def->next; + if (hash != def->hash) + continue; + if (stricmp(def->name, musname)) + continue; + + return def; } return NULL; diff --git a/src/s_sound.h b/src/s_sound.h index 887cdd878..6008cf0b4 100644 --- a/src/s_sound.h +++ b/src/s_sound.h @@ -168,6 +168,7 @@ boolean S_SpeedMusic(float speed); typedef struct musicdef_s { char name[7]; + UINT32 hash; char usage[256]; char source[256]; char filename[256+1];