Add support for defining all sound parameters through the .def syntax, instead of just the filename

git-svn-id: https://svn.eduke32.com/eduke32@7116 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
terminx 2018-10-25 23:32:05 +00:00
parent 5c1e350d79
commit 98f42cba6f
3 changed files with 56 additions and 16 deletions

View file

@ -165,6 +165,12 @@ enum gametokens
T_ANIMSOUNDS, T_ANIMSOUNDS,
T_NOFLOORPALRANGE, T_NOFLOORPALRANGE,
T_ID, T_ID,
T_MINPITCH,
T_MAXPITCH,
T_PRIORITY,
T_TYPE,
T_DISTANCE,
T_VOLUME,
T_DELAY, T_DELAY,
T_RENAMEFILE, T_RENAMEFILE,
T_GLOBALGAMEFLAGS, T_GLOBALGAMEFLAGS,
@ -5051,12 +5057,24 @@ static int32_t S_DefineAudioIfSupported(char **fn, const char *name)
return 0; return 0;
} }
static int32_t S_DefineSound(int32_t ID, const char *name) static int32_t S_DefineSound(int sndidx, const char *name, int minpitch, int maxpitch, int priority, int type, int distance, float volume)
{ {
if ((unsigned)ID >= MAXSOUNDS) if ((unsigned)sndidx >= MAXSOUNDS || S_DefineAudioIfSupported(&g_sounds[sndidx].filename, name))
return -1; return -1;
return S_DefineAudioIfSupported(&g_sounds[ID].filename, name); auto &snd = g_sounds[sndidx];
snd.ps = clamp(minpitch, INT16_MIN, INT16_MAX);
snd.pe = clamp(maxpitch, INT16_MIN, INT16_MAX);
snd.pr = priority & 255;
snd.m = type & ~SF_ONEINST_INTERNAL;
snd.vo = clamp(distance, INT16_MIN, INT16_MAX);
snd.volume = volume;
if (snd.m & SF_LOOP)
snd.m |= SF_ONEINST_INTERNAL;
return 0;
} }
// Returns: // Returns:
@ -5229,6 +5247,12 @@ static int parsedefinitions_game(scriptfile *pScript, int firstPass)
{ {
{ "id", T_ID }, { "id", T_ID },
{ "file", T_FILE }, { "file", T_FILE },
{ "minpitch", T_MINPITCH },
{ "maxpitch", T_MAXPITCH },
{ "priority", T_PRIORITY },
{ "type", T_TYPE },
{ "distance", T_DISTANCE },
{ "volume", T_VOLUME },
}; };
static const tokenlist animTokens [] = static const tokenlist animTokens [] =
@ -5434,10 +5458,18 @@ static int parsedefinitions_game(scriptfile *pScript, int firstPass)
case T_SOUND: case T_SOUND:
{ {
char * tokenPtr = pScript->ltextptr; char *tokenPtr = pScript->ltextptr;
char * fileName = NULL; char *fileName = NULL;
char *musicEnd;
double volume = 1.0;
int32_t soundNum = -1; int32_t soundNum = -1;
char * musicEnd; int32_t maxpitch = 0;
int32_t minpitch = 0;
int32_t priority = 0;
int32_t type = 0;
int32_t distance = 0;
if (scriptfile_getbraces(pScript, &musicEnd)) if (scriptfile_getbraces(pScript, &musicEnd))
break; break;
@ -5448,6 +5480,12 @@ static int parsedefinitions_game(scriptfile *pScript, int firstPass)
{ {
case T_ID: scriptfile_getsymbol(pScript, &soundNum); break; case T_ID: scriptfile_getsymbol(pScript, &soundNum); break;
case T_FILE: scriptfile_getstring(pScript, &fileName); break; case T_FILE: scriptfile_getstring(pScript, &fileName); break;
case T_MINPITCH: scriptfile_getsymbol(pScript, &minpitch); break;
case T_MAXPITCH: scriptfile_getsymbol(pScript, &maxpitch); break;
case T_PRIORITY: scriptfile_getsymbol(pScript, &priority); break;
case T_TYPE: scriptfile_getsymbol(pScript, &type); break;
case T_DISTANCE: scriptfile_getsymbol(pScript, &distance); break;
case T_VOLUME: scriptfile_getdouble(pScript, &volume); break;
} }
} }
@ -5462,7 +5500,8 @@ static int parsedefinitions_game(scriptfile *pScript, int firstPass)
if (fileName == NULL || check_file_exist(fileName)) if (fileName == NULL || check_file_exist(fileName))
break; break;
if (S_DefineSound(soundNum,fileName) == -1) // maybe I should have just packed this into a sound_t and passed a reference...
if (S_DefineSound(soundNum, fileName, minpitch, maxpitch, priority, type, distance, volume) == -1)
initprintf("Error: invalid sound ID on line %s:%d\n", pScript->filename, scriptfile_getlinum(pScript,tokenPtr)); initprintf("Error: invalid sound ID on line %s:%d\n", pScript->filename, scriptfile_getlinum(pScript,tokenPtr));
} }
} }

View file

@ -6129,7 +6129,7 @@ repeatcase:
C_GetNextValue(LABEL_DEFINE); C_GetNextValue(LABEL_DEFINE);
g_sounds[k].m = *(g_scriptPtr-1) & ~SF_ONEINST_INTERNAL; g_sounds[k].m = *(g_scriptPtr-1) & ~SF_ONEINST_INTERNAL;
if (*(g_scriptPtr-1) & 1) if (*(g_scriptPtr-1) & SF_LOOP)
g_sounds[k].m |= SF_ONEINST_INTERNAL; g_sounds[k].m |= SF_ONEINST_INTERNAL;
C_GetNextValue(LABEL_DEFINE); C_GetNextValue(LABEL_DEFINE);

View file

@ -70,6 +70,7 @@ typedef struct
{ {
char * filename, *ptr; // 8b/16b char * filename, *ptr; // 8b/16b
int32_t length, num, soundsiz; // 12b int32_t length, num, soundsiz; // 12b
float volume; // 4b
sndinst_t instances[MAXSOUNDINSTANCES]; // 64b sndinst_t instances[MAXSOUNDINSTANCES]; // 64b
int16_t ps, pe, vo; // 6b int16_t ps, pe, vo; // 6b
char pr, m; // 2b char pr, m; // 2b