Fix music credits not being shown on level music start

By pretty much restoring the old musicdef system, I tried to work with it but couldn't, if needed that can easily be brought back later on.
This commit is contained in:
SteelT 2020-09-24 15:55:37 -04:00
parent 031665cdfc
commit 9a0ab0759b

View file

@ -1672,32 +1672,69 @@ static UINT16 W_CheckForMusicDefInPwad(UINT16 wadid)
return INT16_MAX; // not found return INT16_MAX; // not found
} }
static boolean void S_LoadMusicDefs(UINT16 wadnum)
ReadMusicDefFields (UINT16 wadnum, int line, boolean fields, char *stoken,
musicdef_t **defp, int *versionp)
{ {
musicdef_t *def; UINT16 lump;
//int version; char *buf;
char *buf2;
char *stoken;
char *value; char *value;
char *textline; size_t size;
//int i; musicdef_t *def, *prev;
UINT16 line = 1; // for better error msgs
(void)versionp; lump = W_CheckForMusicDefInPwad(wadnum);
if (lump == INT16_MAX)
return;
if (!stricmp(stoken, "lump")) 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)
{ {
value = strtok(NULL, " "); /*if ((stoken[0] == '/' && stoken[1] == '/')
|| (stoken[0] == '#')) // skip comments
{
stoken = strtok(NULL, "\r\n"); // skip end of line
if (def)
stoken = strtok(NULL, "\r\n= ");
else
stoken = strtok(NULL, "\r\n ");
line++;
}
else*/ if (!stricmp(stoken, "lump"))
{
value = strtok(NULL, "\r\n ");
if (!value) if (!value)
{ {
CONS_Alert(CONS_WARNING, CONS_Alert(CONS_WARNING, "MUSICDEF: Lump '%s' is missing name. (file %s, line %d)\n", stoken, wadfiles[wadnum]->filename, line);
"MUSICDEF: Field '%s' is missing name. (file %s, line %d)\n", stoken = strtok(NULL, "\r\n"); // skip end of line
stoken, wadfiles[wadnum]->filename, line); goto skip_lump;
return false; }
// 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 else
{ {
musicdef_t *prev = NULL;
def = musicdefstart; def = musicdefstart;
// Search if this is a replacement // Search if this is a replacement
@ -1724,171 +1761,54 @@ ReadMusicDefFields (UINT16 wadnum, int line, boolean fields, char *stoken,
prev->next = def; prev->next = def;
//CONS_Printf("S_LoadMusicDefs: Added song '%s'\n", def->name); //CONS_Printf("S_LoadMusicDefs: Added song '%s'\n", def->name);
} }
}
(*defp) = def; skip_lump:
} stoken = strtok(NULL, "\r\n ");
} line++;
else if (!stricmp(stoken, "version"))
{
if (fields)/* is this not the first field? */
{
CONS_Alert(CONS_WARNING,
"MUSICDEF: Field '%s' must come first. (file %s, line %d)\n",
stoken, wadfiles[wadnum]->filename, line);
return false;
} }
else else
{ {
value = strtok(NULL, " "); value = strtok(NULL, "\r\n= ");
if (!value)
{
CONS_Alert(CONS_WARNING,
"MUSICDEF: Field '%s' is missing version. (file %s, line %d)\n",
stoken, wadfiles[wadnum]->filename, line);
return false;
}
else
{
/*
if (strcasecmp(value, "2.2.0"))
(*versionp) = MUSICDEF_221;
*/
;
}
}
}
else
{
//version = (*versionp);
value = strtok(NULL, "");
if (value)
{
// Find the equals sign.
value = strchr(value, '=');
}
if (!value) if (!value)
{ {
CONS_Alert(CONS_WARNING, CONS_Alert(CONS_WARNING, "MUSICDEF: Field '%s' is missing value. (file %s, line %d)\n", stoken, wadfiles[wadnum]->filename, line);
"MUSICDEF: Field '%s' is missing value. (file %s, line %d)\n", stoken = strtok(NULL, "\r\n"); // skip end of line
stoken, wadfiles[wadnum]->filename, line); goto skip_field;
return false;
} }
else
{
def = (*defp);
if (!def) if (!def)
{ {
CONS_Alert(CONS_ERROR, CONS_Alert(CONS_ERROR, "MUSICDEF: No music definition before field '%s'. (file %s, line %d)\n", stoken, wadfiles[wadnum]->filename, line);
"MUSICDEF: No music definition before field '%s'. (file %s, line %d)\n", free(buf2);
stoken, wadfiles[wadnum]->filename, line); return;
return false;
} }
// Skip the equals sign.
value++;
// Now skip funny whitespace.
value += strspn(value, "\t ");
textline = value;
//i = atoi(value);
/* based ignored lumps */
if (!stricmp(stoken, "usage")) { if (!stricmp(stoken, "usage")) {
#if 0 // Ignore for now #if 0 // Ignore for now
STRBUFCPY(def->usage, textline); 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);
#endif #endif
} else if (!stricmp(stoken, "source")) { } else if (!stricmp(stoken, "source")) {
STRBUFCPY(def->source, textline); 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);
} else { } else {
CONS_Alert(CONS_WARNING, CONS_Alert(CONS_WARNING, "MUSICDEF: Invalid field '%s'. (file %s, line %d)\n", stoken, wadfiles[wadnum]->filename, line);
"MUSICDEF: Invalid field '%s'. (file %s, line %d)\n",
stoken, wadfiles[wadnum]->filename, line);
}
}
} }
return true; skip_field:
stoken = strtok(NULL, "\r\n= ");
line++;
}
} }
void S_LoadMusicDefs(UINT16 wadnum) free(buf2);
{
UINT16 lumpnum;
char *lump;
char *musdeftext;
size_t size;
char *lf;
char *stoken;
size_t nlf = 0xFFFFFFFF;
size_t ncr;
musicdef_t *def = NULL;
int version = MUSICDEF_20;
int line = 1; // for better error msgs
boolean fields = false;
lumpnum = W_CheckForMusicDefInPwad(wadnum);
if (lumpnum == INT16_MAX)
return; return;
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, fields, stoken,
&def, &version))
break;
fields = true;
}
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);
} }
// //