Skip to content

Commit

Permalink
- allow setting Duke's relevant sound properties through SNDINFO.
Browse files Browse the repository at this point in the history
  • Loading branch information
coelckers committed Jan 15, 2023
1 parent 2c50622 commit ad0bff9
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 6 deletions.
69 changes: 68 additions & 1 deletion source/core/music/s_advsound.cpp
Expand Up @@ -42,9 +42,11 @@
#include "s_music.h"
#include "sc_man.h"
#include "s_soundinternal.h"
#include "gamecontrol.h"
#include <zmusic.h>

#include "raze_music.h"
#include "games/duke/src/sounds.h"

// MACROS ------------------------------------------------------------------

Expand All @@ -56,7 +58,9 @@ enum SICommands
SI_ConReserve,
SI_Alias,
SI_Limit,
SI_Singular
SI_Singular,
SI_DukePitchRange,
SI_DukeFlags,
};


Expand Down Expand Up @@ -87,6 +91,8 @@ static const char *SICommandStrings[] =
"$alias",
"$limit",
"$singular",
"$dukepitchrange",
"$dukeflags",
NULL
};

Expand Down Expand Up @@ -300,6 +306,67 @@ static void S_AddSNDINFO (int lump)
break;
}

case SI_DukePitchRange: {
// dukesound <logical name> <lower> <upper>
// Sets a pitch range for the sound.
sc.MustGetString();
auto sfxid = soundEngine->FindSoundTentative(sc.String, DEFAULT_LIMIT);
sc.MustGetNumber();
int minpitch = sc.Number;
sc.MustGetNumber();
int maxpitch = sc.Number;
if (isDukeEngine())
{
auto sfx = soundEngine->GetWritableSfx(sfxid);
if (sfx->UserData.Size() < Duke3d::kMaxUserData)
{
sfx->UserData.Resize(Duke3d::kMaxUserData);
memset(sfx->UserData.Data(), 0, Duke3d::kMaxUserData * sizeof(int));
}
sfx->UserData[Duke3d::kPitchStart] = clamp<int>(minpitch, INT16_MIN, INT16_MAX);
sfx->UserData[Duke3d::kPitchEnd] = clamp<int>(maxpitch, INT16_MIN, INT16_MAX);
}
else
{
sc.ScriptMessage("'dukepitchrange' is not available in current game and will be ignored");
}
break;

}

case SI_DukeFlags: {
static const char* dukeflags[] = { "LOOP", "MSFX", "TALK", "GLOBAL", nullptr};

// dukesound <logical name> <flag> <flag> <flag>..
// Sets a pitch range for the sound.
sc.MustGetString();
auto sfxid = soundEngine->FindSoundTentative(sc.String, DEFAULT_LIMIT);
int flags = 0;
while (sc.GetString())
{
int bit = sc.MatchString(dukeflags);
if (bit == -1) break;
flags |= 1 << bit;
}
if (isDukeEngine())
{
auto sfx = soundEngine->GetWritableSfx(sfxid);
if (sfx->UserData.Size() < Duke3d::kMaxUserData)
{
sfx->UserData.Resize(Duke3d::kMaxUserData);
memset(sfx->UserData.Data(), 0, Duke3d::kMaxUserData * sizeof(int));
}
sfx->UserData[Duke3d::kFlags] = flags;
}
else
{
sc.ScriptMessage("'dukeflags' is not available in current game and will be ignored");
}
break;

}


default:
{ // Got a logical sound mapping
FString name (sc.String);
Expand Down
6 changes: 2 additions & 4 deletions source/games/duke/src/sounds.cpp
Expand Up @@ -246,9 +246,7 @@ int S_DefineSound(unsigned index, const char *filename, int minpitch, int maxpit
sfx->ResourceId = index;
sfx->UserData.Resize(kMaxUserData);
auto& sndinf = sfx->UserData;
sndinf[kFlags] = (type & ~SF_ONEINST_INTERNAL) | SF_CONDEFINED;
if (sndinf[kFlags] & SF_LOOP)
sndinf[kFlags] |= SF_ONEINST_INTERNAL;
sndinf[kFlags] = (type & SF_CON_MASK) | SF_CONDEFINED;

// Take care of backslashes in sound names. Also double backslashes which occur in World Tour.
FString fn = filename;
Expand Down Expand Up @@ -528,7 +526,7 @@ int S_PlaySound3D(FSoundID soundid, DDukeActor* actor, const DVector3& pos, int

int const repeatp = (userflags & SF_LOOP);

if (repeatp && (userflags & SF_ONEINST_INTERNAL) && is_playing)
if (repeatp && is_playing)
{
return -1;
}
Expand Down
3 changes: 2 additions & 1 deletion source/games/duke/src/sounds.h
Expand Up @@ -18,7 +18,7 @@ enum {
SF_TALK = 4,
SF_ADULT = 8,
SF_GLOBAL = 16,
SF_ONEINST_INTERNAL = 32,
SF_CON_MASK = 31,
SF_CONDEFINED = 64,

SF_DTAG = 128,
Expand All @@ -35,6 +35,7 @@ enum esound_t
kMaxUserData
};

class DDukeActor;
int S_PlaySound(FSoundID num, int channel = CHAN_AUTO, EChanFlags flags = 0, float vol = 0.8f);
int S_PlaySound3D(FSoundID num, DDukeActor* spriteNum, const DVector3& pos, int channel = CHAN_AUTO, EChanFlags flags = 0);
int S_PlayActorSound(FSoundID soundNum, DDukeActor* spriteNum, int channel = CHAN_AUTO, EChanFlags flags = 0);
Expand Down

0 comments on commit ad0bff9

Please sign in to comment.