Merge branch 'musicdef-versioning' into 'next'
MUSICDEF cleanup, fixes, and VERSION directive to opt into new format See merge request STJr/SRB2!708
This commit is contained in:
commit
c7b4054a7a
299
src/s_sound.c
299
src/s_sound.c
|
@ -1441,6 +1441,12 @@ static tic_t pause_starttic;
|
||||||
/// Music Definitions
|
/// Music Definitions
|
||||||
/// ------------------------
|
/// ------------------------
|
||||||
|
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
MUSICDEF_220,
|
||||||
|
MUSICDEF_221,
|
||||||
|
};
|
||||||
|
|
||||||
musicdef_t soundtestsfx = {
|
musicdef_t soundtestsfx = {
|
||||||
"_STSFX", // prevents exactly one valid track name from being used on the sound test
|
"_STSFX", // prevents exactly one valid track name from being used on the sound test
|
||||||
"Sound Effects",
|
"Sound Effects",
|
||||||
|
@ -1472,74 +1478,39 @@ static UINT16 W_CheckForMusicDefInPwad(UINT16 wadid)
|
||||||
return INT16_MAX; // not found
|
return INT16_MAX; // not found
|
||||||
}
|
}
|
||||||
|
|
||||||
void S_LoadMusicDefs(UINT16 wadnum)
|
static void
|
||||||
|
MusicDefStrcpy (char *p, const char *s, size_t n, int version)
|
||||||
{
|
{
|
||||||
UINT16 lumpnum;
|
strlcpy(p, s, n);
|
||||||
char *lump, *buf;
|
if (version == MUSICDEF_220)
|
||||||
char *musdeftext;
|
{
|
||||||
char *stoken;
|
while (( p = strchr(p, '_') ))
|
||||||
|
*p++ = ' '; // turn _ into spaces.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static boolean
|
||||||
|
ReadMusicDefFields (UINT16 wadnum, int line, boolean fields, char *stoken,
|
||||||
|
musicdef_t **defp, int *versionp)
|
||||||
|
{
|
||||||
|
musicdef_t *def;
|
||||||
|
int version;
|
||||||
|
|
||||||
char *value;
|
char *value;
|
||||||
char *textline;
|
char *textline;
|
||||||
size_t size;
|
int i;
|
||||||
INT32 i;
|
|
||||||
musicdef_t *def = NULL;
|
|
||||||
UINT16 line = 1; // for better error msgs
|
|
||||||
|
|
||||||
lumpnum = W_CheckForMusicDefInPwad(wadnum);
|
if (!stricmp(stoken, "lump"))
|
||||||
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';
|
|
||||||
|
|
||||||
// for strtok
|
|
||||||
buf = malloc(size+1);
|
|
||||||
if (!buf)
|
|
||||||
I_Error("S_LoadMusicDefs: No more free memory for the parser\n");
|
|
||||||
M_Memcpy(buf, musdeftext, size+1);
|
|
||||||
|
|
||||||
stoken = strtok(buf, "\r\n ");
|
|
||||||
// Find music def
|
|
||||||
while (stoken)
|
|
||||||
{
|
{
|
||||||
/*if ((stoken[0] == '/' && stoken[1] == '/')
|
value = strtok(NULL, " ");
|
||||||
|| (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, "MUSICDEF: Lump '%s' is missing name. (file %s, line %d)\n", stoken, wadfiles[wadnum]->filename, line);
|
CONS_Alert(CONS_WARNING,
|
||||||
stoken = strtok(NULL, "\r\n"); // skip end of line
|
"MUSICDEF: Field '%s' is missing name. (file %s, line %d)\n",
|
||||||
goto skip_lump;
|
stoken, wadfiles[wadnum]->filename, line);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
// 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*/
|
|
||||||
{
|
{
|
||||||
musicdef_t *prev = NULL;
|
musicdef_t *prev = NULL;
|
||||||
def = musicdefstart;
|
def = musicdefstart;
|
||||||
|
@ -1569,91 +1540,102 @@ void S_LoadMusicDefs(UINT16 wadnum)
|
||||||
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);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
skip_lump:
|
(*defp) = def;
|
||||||
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
|
||||||
{
|
{
|
||||||
// If this is set true, the line was invalid.
|
value = strtok(NULL, " ");
|
||||||
boolean brokenline = false;
|
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);
|
||||||
|
|
||||||
// Delimit only by line break.
|
if (version == MUSICDEF_220)
|
||||||
value = strtok(NULL, "\r\n");
|
value = strtok(NULL, " =");
|
||||||
|
else
|
||||||
|
{
|
||||||
|
value = strtok(NULL, "");
|
||||||
|
|
||||||
|
if (value)
|
||||||
|
{
|
||||||
// Find the equals sign.
|
// Find the equals sign.
|
||||||
value = strchr(value, '=');
|
value = strchr(value, '=');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// It's not there?!
|
|
||||||
if (!value)
|
if (!value)
|
||||||
brokenline = true;
|
{
|
||||||
|
CONS_Alert(CONS_WARNING,
|
||||||
|
"MUSICDEF: Field '%s' is missing value. (file %s, line %d)\n",
|
||||||
|
stoken, wadfiles[wadnum]->filename, line);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
else
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (version != MUSICDEF_220)
|
||||||
{
|
{
|
||||||
// Skip the equals sign.
|
// Skip the equals sign.
|
||||||
value++;
|
value++;
|
||||||
|
|
||||||
// Now skip funny whitespace.
|
// Now skip funny whitespace.
|
||||||
if (value[0] == '\0') // :NOTHING:
|
|
||||||
brokenline = true;
|
|
||||||
else
|
|
||||||
value += strspn(value, "\t ");
|
value += strspn(value, "\t ");
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the line is valid, copy the text line from the lump data.
|
textline = value;
|
||||||
if (!brokenline)
|
i = atoi(value);
|
||||||
{
|
|
||||||
// strtok returns memory that already belongs to the input string.
|
|
||||||
value = musdeftext + (value - buf);
|
|
||||||
|
|
||||||
// Find the length of the line.
|
|
||||||
size = strcspn(value, "\r\n");
|
|
||||||
|
|
||||||
// Copy the line.
|
|
||||||
textline = malloc(size+1);
|
|
||||||
if (!textline)
|
|
||||||
I_Error("S_LoadMusicDefs: No more free memory for text line\n");
|
|
||||||
M_Memcpy(textline, value, size);
|
|
||||||
textline[size] = '\0';
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
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(textline);
|
|
||||||
free(buf);
|
|
||||||
free(musdeftext);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
i = atoi(textline);
|
|
||||||
|
|
||||||
|
/* 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, textline);
|
||||||
//CONS_Printf("S_LoadMusicDefs: Set usage to '%s'\n", def->usage);
|
|
||||||
#endif
|
#endif
|
||||||
} else if (!stricmp(stoken, "source")) {
|
} else if (!stricmp(stoken, "source")) {
|
||||||
#if 0 // Ignore for now
|
#if 0 // Ignore for now
|
||||||
STRBUFCPY(def->source, textline);
|
STRBUFCPY(def->source, textline);
|
||||||
//CONS_Printf("S_LoadMusicDefs: Set source to '%s'\n", def->usage);
|
|
||||||
#endif
|
#endif
|
||||||
} else if (!stricmp(stoken, "title")) {
|
} else if (!stricmp(stoken, "title")) {
|
||||||
STRBUFCPY(def->title, textline);
|
MusicDefStrcpy(def->title, textline,
|
||||||
//CONS_Printf("S_LoadMusicDefs: Set title to '%s'\n", def->source);
|
sizeof def->title, version);
|
||||||
} else if (!stricmp(stoken, "alttitle")) {
|
} else if (!stricmp(stoken, "alttitle")) {
|
||||||
STRBUFCPY(def->alttitle, textline);
|
MusicDefStrcpy(def->alttitle, textline,
|
||||||
//CONS_Printf("S_LoadMusicDefs: Set alttitle to '%s'\n", def->source);
|
sizeof def->alttitle, version);
|
||||||
} else if (!stricmp(stoken, "authors")) {
|
} else if (!stricmp(stoken, "authors")) {
|
||||||
STRBUFCPY(def->authors, textline);
|
MusicDefStrcpy(def->authors, textline,
|
||||||
//CONS_Printf("S_LoadMusicDefs: Set authors to '%s'\n", def->source);
|
sizeof def->authors, version);
|
||||||
} else if (!stricmp(stoken, "soundtestpage")) {
|
} else if (!stricmp(stoken, "soundtestpage")) {
|
||||||
def->soundtestpage = (UINT8)i;
|
def->soundtestpage = (UINT8)i;
|
||||||
} else if (!stricmp(stoken, "soundtestcond")) {
|
} else if (!stricmp(stoken, "soundtestcond")) {
|
||||||
|
@ -1670,21 +1652,90 @@ skip_lump:
|
||||||
if (bpmf > 0)
|
if (bpmf > 0)
|
||||||
def->bpm = FixedDiv((60*TICRATE)<<FRACBITS, bpmf);
|
def->bpm = FixedDiv((60*TICRATE)<<FRACBITS, bpmf);
|
||||||
} 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Free the temporary text line from memory.
|
|
||||||
free(textline);
|
|
||||||
|
|
||||||
skip_field:
|
|
||||||
stoken = strtok(NULL, "\r\n= ");
|
|
||||||
line++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
free(buf);
|
return true;
|
||||||
free(musdeftext);
|
}
|
||||||
|
|
||||||
|
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 version = MUSICDEF_220;
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
Loading…
Reference in a new issue