mirror of
https://github.com/KartKrewDev/RingRacers.git
synced 2025-10-30 08:01:28 +00:00
Use 2.2's musicdef parser
This commit is contained in:
parent
de936f4c7f
commit
e7051737d7
1 changed files with 149 additions and 120 deletions
269
src/s_sound.c
269
src/s_sound.c
|
|
@ -1598,11 +1598,6 @@ static tic_t pause_starttic;
|
||||||
/// Music Definitions
|
/// Music Definitions
|
||||||
/// ------------------------
|
/// ------------------------
|
||||||
|
|
||||||
enum
|
|
||||||
{
|
|
||||||
MUSICDEF_20,
|
|
||||||
};
|
|
||||||
|
|
||||||
musicdef_t *musicdefstart = NULL;
|
musicdef_t *musicdefstart = NULL;
|
||||||
struct cursongcredit cursongcredit; // Currently displayed song credit info
|
struct cursongcredit cursongcredit; // Currently displayed song credit info
|
||||||
int musicdef_volume;
|
int musicdef_volume;
|
||||||
|
|
@ -1623,147 +1618,181 @@ static UINT16 W_CheckForMusicDefInPwad(UINT16 wadid)
|
||||||
return INT16_MAX; // not found
|
return INT16_MAX; // not found
|
||||||
}
|
}
|
||||||
|
|
||||||
void S_LoadMusicDefs(UINT16 wadnum)
|
static boolean
|
||||||
|
ReadMusicDefFields (UINT16 wadnum, int line, char *stoken, musicdef_t **defp)
|
||||||
{
|
{
|
||||||
UINT16 lump;
|
musicdef_t *def;
|
||||||
char *buf;
|
|
||||||
char *buf2;
|
|
||||||
char *stoken;
|
|
||||||
char *value;
|
char *value;
|
||||||
size_t size;
|
char *textline;
|
||||||
musicdef_t *def, *prev;
|
|
||||||
UINT16 line = 1; // for better error msgs
|
|
||||||
|
|
||||||
lump = W_CheckForMusicDefInPwad(wadnum);
|
if (!stricmp(stoken, "lump"))
|
||||||
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 ((stoken[0] == '/' && stoken[1] == '/')
|
value = strtok(NULL, " ");
|
||||||
|| (stoken[0] == '#')) // skip comments
|
if (!value)
|
||||||
{
|
{
|
||||||
stoken = strtok(NULL, "\r\n"); // skip end of line
|
CONS_Alert(CONS_WARNING,
|
||||||
if (def)
|
"MUSICDEF: Field '%s' is missing name. (file %s, line %d)\n",
|
||||||
stoken = strtok(NULL, "\r\n= ");
|
stoken, wadfiles[wadnum]->filename, line);
|
||||||
else
|
return false;
|
||||||
stoken = strtok(NULL, "\r\n ");
|
|
||||||
line++;
|
|
||||||
}
|
|
||||||
else*/ 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, 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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
def->volume = DEFAULT_MUSICDEF_VOLUME;
|
|
||||||
|
|
||||||
skip_lump:
|
|
||||||
stoken = strtok(NULL, "\r\n ");
|
|
||||||
line++;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
value = strtok(NULL, "\r\n= ");
|
musicdef_t **tail = &musicdefstart;
|
||||||
|
|
||||||
if (!value)
|
// Search if this is a replacement
|
||||||
|
while (*tail)
|
||||||
{
|
{
|
||||||
CONS_Alert(CONS_WARNING, "MUSICDEF: Field '%s' is missing value. (file %s, line %d)\n", stoken, wadfiles[wadnum]->filename, line);
|
if (!stricmp((*tail)->name, value))
|
||||||
stoken = strtok(NULL, "\r\n"); // skip end of line
|
{
|
||||||
goto skip_field;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
tail = &(*tail)->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Nothing found, add to the end.
|
||||||
|
if (!(*tail))
|
||||||
|
{
|
||||||
|
def = Z_Calloc(sizeof (musicdef_t), PU_STATIC, NULL);
|
||||||
|
|
||||||
|
STRBUFCPY(def->name, value);
|
||||||
|
strlwr(def->name);
|
||||||
|
def->volume = DEFAULT_MUSICDEF_VOLUME;
|
||||||
|
|
||||||
|
(*tail) = def;
|
||||||
|
}
|
||||||
|
|
||||||
|
(*defp) = (*tail);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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)
|
if (!def)
|
||||||
{
|
{
|
||||||
CONS_Alert(CONS_ERROR, "MUSICDEF: No music definition before field '%s'. (file %s, line %d)\n", stoken, wadfiles[wadnum]->filename, line);
|
CONS_Alert(CONS_ERROR,
|
||||||
free(buf2);
|
"MUSICDEF: No music definition before field '%s'. (file %s, line %d)\n",
|
||||||
return;
|
stoken, wadfiles[wadnum]->filename, line);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Skip the equals sign.
|
||||||
|
value++;
|
||||||
|
|
||||||
|
// Now skip funny whitespace.
|
||||||
|
value += strspn(value, "\t ");
|
||||||
|
|
||||||
|
textline = 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, value);
|
STRBUFCPY(def->usage, textline);
|
||||||
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, value);
|
STRBUFCPY(def->source, textline);
|
||||||
for (value = def->source; *value; value++)
|
|
||||||
if (*value == '_') *value = ' '; // turn _ into spaces.
|
|
||||||
//CONS_Printf("S_LoadMusicDefs: Set source to '%s'\n", def->source);
|
|
||||||
} else if (!stricmp(stoken, "volume")) {
|
} else if (!stricmp(stoken, "volume")) {
|
||||||
def->volume = atoi(value);
|
def->volume = atoi(textline);
|
||||||
} else {
|
} else {
|
||||||
CONS_Alert(CONS_WARNING, "MUSICDEF: Invalid field '%s'. (file %s, line %d)\n", stoken, wadfiles[wadnum]->filename, line);
|
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(buf2);
|
return true;
|
||||||
return;
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
lumpnum = W_CheckForMusicDefInPwad(wadnum);
|
||||||
|
if (lumpnum == INT16_MAX)
|
||||||
|
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, 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue