mirror of
https://github.com/KartKrewDev/RingRacers.git
synced 2025-10-30 08:01:28 +00:00
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:
parent
031665cdfc
commit
9a0ab0759b
1 changed files with 115 additions and 195 deletions
310
src/s_sound.c
310
src/s_sound.c
|
|
@ -1672,223 +1672,143 @@ static UINT16 W_CheckForMusicDefInPwad(UINT16 wadid)
|
||||||
return INT16_MAX; // not found
|
return INT16_MAX; // not found
|
||||||
}
|
}
|
||||||
|
|
||||||
static boolean
|
|
||||||
ReadMusicDefFields (UINT16 wadnum, int line, boolean fields, char *stoken,
|
|
||||||
musicdef_t **defp, int *versionp)
|
|
||||||
{
|
|
||||||
musicdef_t *def;
|
|
||||||
//int version;
|
|
||||||
|
|
||||||
char *value;
|
|
||||||
char *textline;
|
|
||||||
//int i;
|
|
||||||
|
|
||||||
(void)versionp;
|
|
||||||
|
|
||||||
if (!stricmp(stoken, "lump"))
|
|
||||||
{
|
|
||||||
value = strtok(NULL, " ");
|
|
||||||
if (!value)
|
|
||||||
{
|
|
||||||
CONS_Alert(CONS_WARNING,
|
|
||||||
"MUSICDEF: Field '%s' is missing name. (file %s, line %d)\n",
|
|
||||||
stoken, wadfiles[wadnum]->filename, line);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
musicdef_t *prev = NULL;
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
(*defp) = def;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
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
|
|
||||||
{
|
|
||||||
value = strtok(NULL, " ");
|
|
||||||
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)
|
|
||||||
{
|
|
||||||
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);
|
|
||||||
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 0 // Ignore for now
|
|
||||||
STRBUFCPY(def->usage, textline);
|
|
||||||
#endif
|
|
||||||
} else if (!stricmp(stoken, "source")) {
|
|
||||||
STRBUFCPY(def->source, textline);
|
|
||||||
} else {
|
|
||||||
CONS_Alert(CONS_WARNING,
|
|
||||||
"MUSICDEF: Invalid field '%s'. (file %s, line %d)\n",
|
|
||||||
stoken, wadfiles[wadnum]->filename, line);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void S_LoadMusicDefs(UINT16 wadnum)
|
void S_LoadMusicDefs(UINT16 wadnum)
|
||||||
{
|
{
|
||||||
UINT16 lumpnum;
|
UINT16 lump;
|
||||||
char *lump;
|
char *buf;
|
||||||
char *musdeftext;
|
char *buf2;
|
||||||
size_t size;
|
|
||||||
|
|
||||||
char *lf;
|
|
||||||
char *stoken;
|
char *stoken;
|
||||||
|
char *value;
|
||||||
|
size_t size;
|
||||||
|
musicdef_t *def, *prev;
|
||||||
|
UINT16 line = 1; // for better error msgs
|
||||||
|
|
||||||
size_t nlf = 0xFFFFFFFF;
|
lump = W_CheckForMusicDefInPwad(wadnum);
|
||||||
size_t ncr;
|
if (lump == INT16_MAX)
|
||||||
|
|
||||||
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);
|
buf = W_CacheLumpNumPwad(wadnum, lump, PU_CACHE);
|
||||||
size = W_LumpLengthPwad(wadnum, lumpnum);
|
size = W_LumpLengthPwad(wadnum, lump);
|
||||||
|
|
||||||
// Null-terminated MUSICDEF lump.
|
// for strtok
|
||||||
musdeftext = malloc(size+1);
|
buf2 = malloc(size+1);
|
||||||
if (!musdeftext)
|
if (!buf2)
|
||||||
I_Error("S_LoadMusicDefs: No more free memory for the parser\n");
|
I_Error("S_LoadMusicDefs: No more free memory\n");
|
||||||
M_Memcpy(musdeftext, lump, size);
|
M_Memcpy(buf2,buf,size);
|
||||||
musdeftext[size] = '\0';
|
buf2[size] = '\0';
|
||||||
|
|
||||||
|
def = prev = NULL;
|
||||||
|
|
||||||
|
stoken = strtok (buf2, "\r\n ");
|
||||||
// Find music def
|
// Find music def
|
||||||
stoken = musdeftext;
|
while (stoken)
|
||||||
for (;;)
|
|
||||||
{
|
{
|
||||||
lf = strpbrk(stoken, "\r\n");
|
/*if ((stoken[0] == '/' && stoken[1] == '/')
|
||||||
if (lf)
|
|| (stoken[0] == '#')) // skip comments
|
||||||
{
|
{
|
||||||
if (*lf == '\n')
|
stoken = strtok(NULL, "\r\n"); // skip end of line
|
||||||
nlf = 1;
|
if (def)
|
||||||
|
stoken = strtok(NULL, "\r\n= ");
|
||||||
else
|
else
|
||||||
nlf = 0;
|
stoken = strtok(NULL, "\r\n ");
|
||||||
*lf++ = '\0';/* now we can delimit to here */
|
line++;
|
||||||
}
|
}
|
||||||
|
else*/ if (!stricmp(stoken, "lump"))
|
||||||
stoken = strtok(stoken, " ");
|
|
||||||
if (stoken)
|
|
||||||
{
|
{
|
||||||
if (! ReadMusicDefFields(wadnum, line, fields, stoken,
|
value = strtok(NULL, "\r\n ");
|
||||||
&def, &version))
|
|
||||||
break;
|
|
||||||
fields = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (lf)
|
if (!value)
|
||||||
{
|
|
||||||
do
|
|
||||||
{
|
{
|
||||||
line += nlf;
|
CONS_Alert(CONS_WARNING, "MUSICDEF: Lump '%s' is missing name. (file %s, line %d)\n", stoken, wadfiles[wadnum]->filename, line);
|
||||||
ncr = strspn(lf, "\r");/* skip CR */
|
stoken = strtok(NULL, "\r\n"); // skip end of line
|
||||||
lf += ncr;
|
goto skip_lump;
|
||||||
nlf = strspn(lf, "\n");
|
|
||||||
lf += nlf;
|
|
||||||
}
|
}
|
||||||
while (nlf || ncr) ;
|
|
||||||
|
|
||||||
stoken = lf;/* now the next nonempty line */
|
// 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
skip_lump:
|
||||||
|
stoken = strtok(NULL, "\r\n ");
|
||||||
|
line++;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
break;/* EOF */
|
{
|
||||||
|
value = strtok(NULL, "\r\n= ");
|
||||||
|
|
||||||
|
if (!value)
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!stricmp(stoken, "usage")) {
|
||||||
|
#if 0 // Ignore for now
|
||||||
|
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
|
||||||
|
} 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);
|
||||||
|
} 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++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
free(musdeftext);
|
free(buf2);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue