- removed the string constructors from FSoundID.

Due to C++ conversion rules this was a bit too volatile. There's really not enough places where being able to pass a string directly into the sound API was beneficial - the two most frequent functions now got overloaded variants.
This commit is contained in:
Christoph Oelckers 2022-11-24 16:49:04 +01:00
parent b89c4affae
commit 65a26d6779
26 changed files with 66 additions and 70 deletions

View file

@ -1463,7 +1463,7 @@ void SoundEngine::Reset()
// Given a logical name, find the sound's index in S_sfx.
//==========================================================================
int SoundEngine::GetSoundIndex(const char* logicalname)
FSoundID SoundEngine::FindSound(const char* logicalname)
{
int i;
@ -1474,11 +1474,11 @@ int SoundEngine::GetSoundIndex(const char* logicalname)
while ((i != 0) && stricmp(S_sfx[i].name, logicalname))
i = S_sfx[i].next;
return i;
return FSoundID::fromInt(i);
}
else
{
return 0;
return NO_SOUND;
}
}

View file

@ -34,14 +34,6 @@ public:
{
return FSoundID(i);
}
FSoundID(const char *name)
{
ID = GetSoundIndex(name);
}
FSoundID(const FString &name)
{
ID = GetSoundIndex(name.GetChars());
}
FSoundID(const FSoundID &other) = default;
FSoundID &operator=(const FSoundID &other) = default;
bool operator !=(FSoundID other) const
@ -63,7 +55,6 @@ public:
return ID > 0;
}
private:
static inline int GetSoundIndex(const char* name);
int ID;
};
@ -223,8 +214,6 @@ private:
// Checks if a copy of this sound is already playing.
bool CheckSingular(FSoundID sound_id);
virtual TArray<uint8_t> ReadSound(int lumpnum) = 0;
int GetSoundIndex(const char* logicalname); // this is only for setting up FSoundID
friend class FSoundID;
protected:
virtual bool CheckSoundLimit(sfxinfo_t* sfx, const FVector3& pos, int near_limit, float limit_range, int sourcetype, const void* actor, int channel, float attenuation);
@ -398,10 +387,7 @@ public:
virtual void SoundDone(FISoundChannel* ichan); // gets called when the sound has been completely taken down.
// Lookup utilities.
inline FSoundID FindSound(const char* logicalname)
{
return FSoundID::fromInt(GetSoundIndex(logicalname));
}
FSoundID FindSound(const char* logicalname);
FSoundID FindSoundByResID(int rid);
FSoundID FindSoundNoHash(const char* logicalname);
FSoundID FindSoundByLump(int lump);
@ -436,9 +422,4 @@ inline FSoundID S_FindSound(const char* name)
return soundEngine->FindSound(name);
}
inline int FSoundID::GetSoundIndex(const char* name)
{
return soundEngine->GetSoundIndex(name);
}
int SoundEnabled();

View file

@ -72,6 +72,12 @@ public:
return Buttons[x].bWentUp;
}
void ButtonSet(int x) const
{
Buttons[x].bDown = Buttons[x].bWentDown = true;
Buttons[x].bWentUp = false;
}
void ClearButton(int x)
{
Buttons[x].Reset();

View file

@ -1354,7 +1354,7 @@ FSerializer &Serialize(FSerializer &arc, const char *key, FSoundID &sid, FSoundI
assert(val->IsString() || val->IsNull());
if (val->IsString())
{
sid = UnicodeToString(val->GetString());
sid = S_FindSound(UnicodeToString(val->GetString()));
}
else if (val->IsNull())
{

View file

@ -1475,7 +1475,7 @@ FxExpression *FxSoundCast::Resolve(FCompileContext &ctx)
if (basex->isConstant())
{
ExpVal constval = static_cast<FxConstant *>(basex)->GetValue();
FxExpression *x = new FxConstant(FSoundID(constval.GetString()), ScriptPosition);
FxExpression *x = new FxConstant(S_FindSound(constval.GetString()), ScriptPosition);
delete this;
return x;
}

View file

@ -1351,7 +1351,7 @@ bool PSound::ReadValue(FSerializer &ar, const char *key, void *addr) const
}
else
{
*(FSoundID *)addr = FSoundID(cptr);
*(FSoundID *)addr = S_FindSound(cptr);
return true;
}
}

View file

@ -254,8 +254,8 @@ static void ParseLock(FScanner &sc, int &currentnumber)
auto lock = keynum == -1? &sink : &Locks.InsertNew(keynum);
lock->locksound.Push("*keytry");
lock->locksound.Push("misc/keytry");
lock->locksound.Push(S_FindSound("*keytry"));
lock->locksound.Push(S_FindSound("misc/keytry"));
while (!sc.CheckString("}"))
{
@ -298,7 +298,7 @@ static void ParseLock(FScanner &sc, int &currentnumber)
for (;;)
{
sc.MustGetString();
lock->locksound.Push(sc.String);
lock->locksound.Push(S_FindSound(sc.String));
if (!sc.GetString())
{
break;
@ -469,7 +469,7 @@ int P_CheckKeys (AActor *owner, int keynum, bool remote, bool quiet)
// Just a safety precaution. The messages should have been initialized upon game start.
if (!keysdone) P_InitKeyMessages();
FSoundID failage[2] = { "*keytry", "misc/keytry" };
FSoundID failage[2] = { S_FindSound("*keytry"), S_FindSound("misc/keytry") };
auto lock = Locks.CheckKey(keynum);
if (!lock)

View file

@ -1394,7 +1394,7 @@ static int PatchThing (int thingy)
{ // Sound was not a (valid) number,
// so treat it as an actual sound name.
stripwhite (Line2);
snd = Line2;
snd = S_FindSound(Line2);
}
}
else

View file

@ -1242,7 +1242,7 @@ DEFINE_MAP_OPTION(PrecacheSounds, true)
do
{
parse.sc.MustGetString();
FSoundID snd = parse.sc.String;
FSoundID snd = S_FindSound(parse.sc.String);
if (snd == NO_SOUND)
{
parse.sc.ScriptMessage("Unknown sound \"%s\"", parse.sc.String);

View file

@ -537,7 +537,7 @@ static void GenericParse (FScanner &sc, FGenericParse *parser, const char **keyw
case GEN_Sound:
sc.MustGetString ();
SET_FIELD (FSoundID, FSoundID(sc.String));
SET_FIELD (FSoundID, S_FindSound(sc.String));
/* unknown sounds never produce errors anywhere else so they shouldn't here either.
if (val == 0)
{

View file

@ -242,7 +242,7 @@ FSwitchDef *FTextureAnimator::ParseSwitchDef (FScanner &sc, bool ignoreBad)
sc.ScriptError ("Switch state already has a sound");
}
sc.MustGetString ();
sound = sc.String;
sound = S_FindSound(sc.String);
}
else if (sc.Compare ("pic"))
{

View file

@ -503,7 +503,7 @@ void DIntermissionScreenCast::Init(FIntermissionAction *desc, bool first)
{
mCastSounds[i].mSequence = static_cast<FIntermissionActionCast*>(desc)->mCastSounds[i].mSequence;
mCastSounds[i].mIndex = static_cast<FIntermissionActionCast*>(desc)->mCastSounds[i].mIndex;
mCastSounds[i].mSound = static_cast<FIntermissionActionCast*>(desc)->mCastSounds[i].mSound;
mCastSounds[i].mSound = S_FindSound(static_cast<FIntermissionActionCast*>(desc)->mCastSounds[i].mSound);
}
caststate = mDefaults->SeeState;
if (mClass->IsDescendantOf(NAME_PlayerPawn))
@ -551,7 +551,7 @@ int DIntermissionScreenCast::Responder (FInputEvent *ev)
if (mClass->IsDescendantOf(NAME_PlayerPawn))
{
auto snd = S_FindSkinnedSound(players[consoleplayer].mo, "*death");
auto snd = S_FindSkinnedSound(players[consoleplayer].mo, S_FindSound("*death"));
if (snd != NO_SOUND) S_Sound (CHAN_VOICE, CHANF_UI, snd, 1, ATTN_NONE);
}
else if (mDefaults->DeathSound.isvalid())

View file

@ -319,7 +319,7 @@ FStrifeDialogueNode *MapLoader::ReadRetailNode (const char *name, FileReader &lu
// The speaker's voice for this node, if any.
speech.Backdrop[0] = 0; //speech.Sound[8] = 0;
mysnprintf (fullsound, countof(fullsound), "svox/%s", speech.Sound);
node->SpeakerVoice = fullsound;
node->SpeakerVoice = S_FindSound(fullsound);
// The speaker's name, if any.
speech.Sound[0] = 0; //speech.Name[16] = 0;
@ -415,7 +415,7 @@ FStrifeDialogueNode *MapLoader::ReadTeaserNode (const char *name, FileReader &lu
if (speech.VoiceNumber != 0)
{
mysnprintf (fullsound, countof(fullsound), "svox/voc%u", speech.VoiceNumber);
node->SpeakerVoice = fullsound;
node->SpeakerVoice = S_FindSound(fullsound);
}
else
{

View file

@ -4200,23 +4200,23 @@ void DLevelScript::DoSetActorProperty (AActor *actor, int property, int value)
break;
case APROP_SeeSound:
actor->SeeSound = Level->Behaviors.LookupString(value);
actor->SeeSound = S_FindSound(Level->Behaviors.LookupString(value));
break;
case APROP_AttackSound:
actor->AttackSound = Level->Behaviors.LookupString(value);
actor->AttackSound = S_FindSound(Level->Behaviors.LookupString(value));
break;
case APROP_PainSound:
actor->PainSound = Level->Behaviors.LookupString(value);
actor->PainSound = S_FindSound(Level->Behaviors.LookupString(value));
break;
case APROP_DeathSound:
actor->DeathSound = Level->Behaviors.LookupString(value);
actor->DeathSound = S_FindSound(Level->Behaviors.LookupString(value));
break;
case APROP_ActiveSound:
actor->ActiveSound = Level->Behaviors.LookupString(value);
actor->ActiveSound = S_FindSound(Level->Behaviors.LookupString(value));
break;
case APROP_Species:
@ -5623,7 +5623,7 @@ int DLevelScript::CallFunction(int argCount, int funcIndex, int32_t *args)
}
case ACSF_Radius_Quake2:
P_StartQuake(Level, activator, args[0], args[1], args[2], args[3], args[4], Level->Behaviors.LookupString(args[5]));
P_StartQuake(Level, activator, args[0], args[1], args[2], args[3], args[4], S_FindSound(Level->Behaviors.LookupString(args[5])));
break;
case ACSF_CheckActorClass:
@ -5910,7 +5910,7 @@ int DLevelScript::CallFunction(int argCount, int funcIndex, int32_t *args)
const char *lookup = Level->Behaviors.LookupString(args[1]);
if (lookup != NULL)
{
sid = lookup;
sid = S_FindSound(lookup);
}
}
if (sid != NO_SOUND || funcIndex == ACSF_PlayActorSound)
@ -6196,7 +6196,7 @@ doplaysound: if (funcIndex == ACSF_PlayActorSound)
case ACSF_QuakeEx:
{
return P_StartQuakeXYZ(Level, activator, args[0], args[1], args[2], args[3], args[4], args[5], args[6], Level->Behaviors.LookupString(args[7]),
return P_StartQuakeXYZ(Level, activator, args[0], args[1], args[2], args[3], args[4], args[5], args[6], S_FindSound(Level->Behaviors.LookupString(args[7])),
argCount > 8 ? args[8] : 0,
argCount > 9 ? ACSToDouble(args[9]) : 1.0,
argCount > 10 ? ACSToDouble(args[10]) : 1.0,
@ -6737,7 +6737,7 @@ doplaysound: if (funcIndex == ACSF_PlayActorSound)
const char* lookup = Level->Behaviors.LookupString(args[1]);
if (lookup != nullptr)
{
sid = lookup;
sid = S_FindSound(lookup);
}
activator->player->SetSubtitle(logNum, sid);
@ -8871,7 +8871,7 @@ scriptwait:
S_Sound (
activationline->frontsector,
CHAN_AUTO, 0, // Not CHAN_AREA, because that'd probably break existing scripts.
lookup,
S_FindSound(lookup),
(float)(STACK(1)) / 127.f,
ATTN_NORM);
}

View file

@ -720,7 +720,7 @@ void P_DrawRailTrail(AActor *source, TArray<SPortalHit> &portalhits, int color1,
if (!source->player) sound = source->AttackSound;
else if (source->player->ReadyWeapon) sound = source->player->ReadyWeapon->AttackSound;
else sound = NO_SOUND;
if (!sound.isvalid()) sound = "weapons/railgf";
if (!sound.isvalid()) sound = S_FindSound("weapons/railgf");
// The railgun's sound is special. It gets played from the
// point on the slug's trail that is closest to the hearing player.

View file

@ -2836,7 +2836,7 @@ bool P_CheckForResurrection(AActor* self, bool usevilestates, FState* state = nu
self->SetState(archvile->FindState(NAME_Heal));
}
}
if (sound == NO_SOUND) sound = "vile/raise";
if (sound == NO_SOUND) sound = S_FindSound("vile/raise");
S_Sound(corpsehit, CHAN_BODY, 0, sound, 1, ATTN_IDLE);
info = corpsehit->GetDefault();
@ -3131,18 +3131,18 @@ DEFINE_ACTION_FUNCTION(AActor, A_Pain)
FString pain_sound = pain_amount;
pain_sound += '-';
pain_sound += self->player->LastDamageType.GetChars();
sfx_id = pain_sound;
sfx_id = S_FindSound(pain_sound);
if (sfx_id == NO_SOUND)
{
// Try again without a specific pain amount.
pain_sound = "*pain-";
pain_sound += self->player->LastDamageType.GetChars();
sfx_id = pain_sound;
sfx_id = S_FindSound(pain_sound);
}
}
if (sfx_id == NO_SOUND)
{
sfx_id = pain_amount;
sfx_id = S_FindSound(pain_amount);
}
S_Sound (self, CHAN_VOICE, 0, sfx_id, 1, ATTN_NORM);

View file

@ -2161,7 +2161,7 @@ FUNC(LS_Light_Stop)
FUNC(LS_Radius_Quake)
// Radius_Quake (intensity, duration, damrad, tremrad, tid)
{
return P_StartQuake (Level, it, arg4, arg0, arg1, arg2*64, arg3*64, "world/quake");
return P_StartQuake (Level, it, arg4, arg0, arg1, arg2*64, arg3*64, S_FindSound("world/quake"));
}
FUNC(LS_UsePuzzleItem)
@ -3218,8 +3218,9 @@ FUNC(LS_SendToCommunicator)
if (it->CheckLocalView())
{
S_StopSound (CHAN_VOICE);
it->player->SetSubtitle(arg0, name);
S_Sound (CHAN_VOICE, 0, name, 1, ATTN_NORM);
auto snd = S_FindSound(name);
it->player->SetSubtitle(arg0, snd);
S_Sound (CHAN_VOICE, 0, snd, 1, ATTN_NORM);
// Get the message from the LANGUAGE lump.
FString msg;

View file

@ -404,7 +404,7 @@ void DActiveButton::Tick ()
{
m_Frame = -1;
S_Sound (Level, DVector3(m_Pos, 0), CHAN_VOICE, CHANF_LISTENERZ,
def->Sound != NO_SOUND ? FSoundID(def->Sound) : FSoundID("switches/normbutn"),
def->Sound != NO_SOUND ? FSoundID(def->Sound) : S_FindSound("switches/normbutn"),
1, ATTN_STATIC);
bFlippable = false;
}

View file

@ -908,7 +908,7 @@ DEFINE_ACTION_FUNCTION(AActor, A_PlayerScream)
(DF_FORCE_FALLINGZD | DF_FORCE_FALLINGHX)) &&
self->Vel.Z <= -39)
{
sound = S_FindSkinnedSound (self, "*splat");
sound = S_FindSkinnedSound (self, S_FindSound("*splat"));
chan = CHAN_BODY;
}
@ -1169,7 +1169,7 @@ void P_CheckEnvironment(player_t *player)
player->mo->Vel.Z >= -player->mo->FloatVar(NAME_FallingScreamMaxSpeed) && !player->morphTics &&
player->mo->waterlevel == 0)
{
auto id = S_FindSkinnedSound(player->mo, "*falling");
auto id = S_FindSkinnedSound(player->mo, S_FindSound("*falling"));
if (id != NO_SOUND && !S_IsActorPlayingSomething(player->mo, CHAN_VOICE, id))
{
S_Sound(player->mo, CHAN_VOICE, 0, id, 1, ATTN_NORM);

View file

@ -583,7 +583,7 @@ void R_InitSkins (void)
for (j = 0; j < NUMSKINSOUNDS; ++j)
{
playersoundrefs[j] = skinsoundnames[j][1];
playersoundrefs[j] = S_FindSound(skinsoundnames[j][1]);
}
while ((base = fileSystem.FindLump ("S_SKIN", &lastlump, true)) != -1)

View file

@ -504,17 +504,17 @@ static void ParseInsideDecoration (Baggage &bag, AActor *defaults,
sc.Compare ("DeathSound"))
{
sc.MustGetString ();
defaults->DeathSound = sc.String;
defaults->DeathSound = S_FindSound(sc.String);
}
else if (def == DEF_BreakableDecoration && sc.Compare ("BurnDeathSound"))
{
sc.MustGetString ();
defaults->ActiveSound = sc.String;
defaults->ActiveSound = S_FindSound(sc.String);
}
else if (def == DEF_Projectile && sc.Compare ("SpawnSound"))
{
sc.MustGetString ();
defaults->SeeSound = sc.String;
defaults->SeeSound = S_FindSound(sc.String);
}
else if (def == DEF_Projectile && sc.Compare ("DoomBounce"))
{

View file

@ -144,7 +144,7 @@ FxExpression *ParseParameter(FScanner &sc, PClassActor *cls, PType *type)
if (type == TypeSound)
{
sc.MustGetString();
x = new FxConstant(FSoundID(sc.String), sc);
x = new FxConstant(S_FindSound(sc.String), sc);
}
else if (type == TypeBool || type == TypeSInt32 || type == TypeFloat64)
{
@ -879,7 +879,7 @@ static void DispatchScriptProperty(FScanner &sc, PProperty *prop, AActor *defaul
else if (f->Type == TypeSound)
{
sc.MustGetString();
*(FSoundID*)addr = sc.String;
*(FSoundID*)addr = S_FindSound(sc.String);
}
else if (f->Type == TypeColor)
{

View file

@ -467,7 +467,7 @@ void ZCCDoomCompiler::DispatchScriptProperty(PProperty *prop, ZCC_PropertyStmt *
}
else if (f->Type == TypeSound)
{
*(FSoundID*)addr = GetStringConst(ex, ctx);
*(FSoundID*)addr = S_FindSound(GetStringConst(ex, ctx));
}
else if (f->Type == TypeColor && ex->ValueType == TypeString) // colors can also be specified as ints.
{

View file

@ -1514,11 +1514,11 @@ FSoundID S_FindSkinnedSoundEx (AActor *actor, const char *name, const char *exte
fullname = name;
fullname += '-';
fullname += extendedname;
FSoundID id = fullname;
FSoundID id = S_FindSound(fullname);
if (!id.isvalid())
{ // Look for "name"
id = name;
id = S_FindSound(name);
}
return S_FindSkinnedSound (actor, id);
}

View file

@ -1386,7 +1386,7 @@ CCMD (playsound)
{
if (argv.argc() > 1)
{
FSoundID id = argv[1];
FSoundID id = S_FindSound(argv[1]);
if (!id.isvalid())
{
Printf("'%s' is not a sound\n", argv[1]);
@ -1408,7 +1408,7 @@ CCMD (loopsound)
{
if (players[consoleplayer].mo != nullptr && !netgame && argv.argc() > 1)
{
FSoundID id = argv[1];
FSoundID id = S_FindSound(argv[1]);
if (!id.isvalid())
{
Printf("'%s' is not a sound\n", argv[1]);

View file

@ -16,10 +16,18 @@ void S_PrecacheLevel(FLevelLocals* l);
// Start sound for thing at <ent>
void S_Sound(int channel, EChanFlags flags, FSoundID sfxid, float volume, float attenuation);
inline void S_Sound(int channel, EChanFlags flags, const char* sfxid, float volume, float attenuation)
{
S_Sound(channel, flags, S_FindSound(sfxid), volume, attenuation);
}
void S_SoundPitch(int channel, EChanFlags flags, FSoundID sfxid, float volume, float attenuation, float pitch, float startTime = 0.f);
void S_Sound (AActor *ent, int channel, EChanFlags flags, FSoundID sfxid, float volume, float attenuation);
inline void S_Sound(AActor* ent, int channel, EChanFlags flags, const char* sfxid, float volume, float attenuation)
{
S_Sound(ent, channel, flags, S_FindSound(sfxid), volume, attenuation);
}
void S_SoundMinMaxDist (AActor *ent, int channel, EChanFlags flags, FSoundID sfxid, float volume, float mindist, float maxdist);
void S_Sound (const FPolyObj *poly, int channel, EChanFlags flags, FSoundID sfxid, float volume, float attenuation);
void S_Sound (const sector_t *sec, int channel, EChanFlags flags, FSoundID sfxid, float volume, float attenuation);