Skip to content

Commit

Permalink
- this should take care of the S_* interface.
Browse files Browse the repository at this point in the history
  • Loading branch information
coelckers committed Nov 24, 2022
1 parent 7e8de9d commit d13f12c
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 32 deletions.
4 changes: 0 additions & 4 deletions src/common/audio/sound/s_soundinternal.h
Expand Up @@ -27,10 +27,6 @@ class FSoundID
public:
FSoundID() = default;

static FSoundID byResId(int ndx)
{
return FSoundID(S_FindSoundByResID(ndx));
}
constexpr FSoundID(int id) : ID(id)
{
}
Expand Down
12 changes: 9 additions & 3 deletions src/scripting/vmthunks_actors.cpp
Expand Up @@ -208,8 +208,8 @@ void A_StartSoundIfNotSame(AActor *self, int soundid, int checksoundid, int chan
DEFINE_ACTION_FUNCTION_NATIVE(AActor, A_StartSoundIfNotSame, A_StartSoundIfNotSame)
{
PARAM_SELF_PROLOGUE(AActor);
PARAM_SOUND(soundid);
PARAM_SOUND(checksoundid);
PARAM_INT(soundid);
PARAM_INT(checksoundid);
PARAM_INT(channel);
PARAM_INT(flags);
PARAM_FLOAT(volume);
Expand All @@ -220,7 +220,13 @@ DEFINE_ACTION_FUNCTION_NATIVE(AActor, A_StartSoundIfNotSame, A_StartSoundIfNotSa
return 0;
}

DEFINE_ACTION_FUNCTION_NATIVE(AActor, IsActorPlayingSound, S_IsActorPlayingSomething)
// direct native scripting export.
static int S_IsActorPlayingSomethingID(AActor* actor, int channel, int sound_id)
{
return S_IsActorPlayingSomething(actor, channel, FSoundID::fromInt(sound_id));
}

DEFINE_ACTION_FUNCTION_NATIVE(AActor, IsActorPlayingSound, S_IsActorPlayingSomethingID)
{
PARAM_SELF_PROLOGUE(AActor);
PARAM_INT(channel);
Expand Down
21 changes: 10 additions & 11 deletions src/sound/s_advsound.cpp
Expand Up @@ -163,7 +163,7 @@ struct FSavedPlayerSoundInfo
{
FName pclass;
int gender;
int refid;
FSoundID refid;
int lumpnum;
bool alias;
};
Expand All @@ -180,8 +180,8 @@ extern bool IsFloat (const char *str);
// PRIVATE FUNCTION PROTOTYPES ---------------------------------------------

static int SortPlayerClasses (const void *a, const void *b);
static int S_DupPlayerSound (const char *pclass, int gender, int refid, int aliasref);
static void S_SavePlayerSound (const char *pclass, int gender, int refid, int lumpnum, bool alias);
static FSoundID S_DupPlayerSound (const char *pclass, int gender, FSoundID refid, FSoundID aliasref);
static void S_SavePlayerSound (const char *pclass, int gender, FSoundID refid, int lumpnum, bool alias);
static void S_RestorePlayerSounds();
static int S_AddPlayerClass (const char *name);
static int S_AddPlayerGender (int classnum, int gender);
Expand Down Expand Up @@ -468,8 +468,7 @@ static FSoundID S_AddSound (const char *logicalname, int lumpnum, FScanner *sc)
// Adds the given sound lump to the player sound lists.
//==========================================================================

int S_AddPlayerSound (const char *pclass, int gender, int refid,
const char *lumpname)
int S_AddPlayerSound (const char *pclass, int gender, FSoundID refid, const char *lumpname)
{
int lump=-1;

Expand All @@ -481,7 +480,7 @@ int S_AddPlayerSound (const char *pclass, int gender, int refid,
return S_AddPlayerSound (pclass, gender, refid, lump);
}

int S_AddPlayerSound (const char *pclass, int gender, int refid, int lumpnum, bool fromskin)
int S_AddPlayerSound (const char *pclass, int gender, FSoundID refid, int lumpnum, bool fromskin)
{
FString fakename;
int id;
Expand Down Expand Up @@ -513,7 +512,7 @@ int S_AddPlayerSound (const char *pclass, int gender, int refid, int lumpnum, bo
// Adds the player sound as an alias to an existing sound.
//==========================================================================

int S_AddPlayerSoundExisting (const char *pclass, int gender, int refid, int aliasto, bool fromskin)
int S_AddPlayerSoundExisting (const char *pclass, int gender, FSoundID refid, FSoundID aliasto, bool fromskin)
{
int classnum = S_AddPlayerClass (pclass);
int soundlist = S_AddPlayerGender (classnum, gender);
Expand All @@ -522,7 +521,7 @@ int S_AddPlayerSoundExisting (const char *pclass, int gender, int refid, int ali

PlayerSounds[soundlist].AddSound (sfx->link, aliasto);

if (fromskin) S_SavePlayerSound(pclass, gender, refid, aliasto, true);
if (fromskin) S_SavePlayerSound(pclass, gender, refid, aliasto.index(), true);

return aliasto;
}
Expand All @@ -534,7 +533,7 @@ int S_AddPlayerSoundExisting (const char *pclass, int gender, int refid, int ali
// Adds a player sound that uses the same sound as an existing player sound.
//==========================================================================

int S_DupPlayerSound (const char *pclass, int gender, int refid, int aliasref)
FSoundID S_DupPlayerSound (const char *pclass, int gender, FSoundID refid, FSoundID aliasref)
{
int aliasto = S_LookupPlayerSound (pclass, gender, aliasref);
return S_AddPlayerSoundExisting (pclass, gender, refid, aliasto);
Expand Down Expand Up @@ -1369,7 +1368,7 @@ static FSoundID S_LookupPlayerSound (int classidx, int gender, FSoundID refid)
//
//==========================================================================

static void S_SavePlayerSound (const char *pclass, int gender, int refid, int lumpnum, bool alias)
static void S_SavePlayerSound (const char *pclass, int gender, FSoundID refid, int lumpnum, bool alias)
{
FSavedPlayerSoundInfo spi;

Expand All @@ -1388,7 +1387,7 @@ static void S_RestorePlayerSounds()
FSavedPlayerSoundInfo * spi = &SavedPlayerSounds[i];
if (spi->alias)
{
S_AddPlayerSoundExisting(spi->pclass.GetChars(), spi->gender, spi->refid, spi->lumpnum);
S_AddPlayerSoundExisting(spi->pclass.GetChars(), spi->gender, spi->refid, FSoundID::fromInt(spi->lumpnum));
}
else
{
Expand Down
14 changes: 7 additions & 7 deletions src/sound/s_doomsound.cpp
Expand Up @@ -413,7 +413,7 @@ DEFINE_ACTION_FUNCTION(DObject, S_Sound)
PARAM_FLOAT(attn);
PARAM_FLOAT(pitch);
PARAM_FLOAT(startTime);
S_SoundPitch(channel & 7, EChanFlags::FromInt(channel & ~7), id, static_cast<float>(volume), static_cast<float>(attn), static_cast<float>(pitch), static_cast<float>(startTime));
S_SoundPitch(channel & 7, EChanFlags::FromInt(channel & ~7), FSoundID::fromInt(id), static_cast<float>(volume), static_cast<float>(attn), static_cast<float>(pitch), static_cast<float>(startTime));
return 0;
}

Expand All @@ -427,7 +427,7 @@ DEFINE_ACTION_FUNCTION(DObject, S_StartSound)
PARAM_FLOAT(attn);
PARAM_FLOAT(pitch);
PARAM_FLOAT(startTime);
S_SoundPitch(channel, EChanFlags::FromInt(flags), id, static_cast<float>(volume), static_cast<float>(attn), static_cast<float>(pitch), static_cast<float>(startTime));
S_SoundPitch(channel, EChanFlags::FromInt(flags), FSoundID::fromInt(id), static_cast<float>(volume), static_cast<float>(attn), static_cast<float>(pitch), static_cast<float>(startTime));
return 0;
}

Expand Down Expand Up @@ -620,7 +620,7 @@ void S_PlaySound(AActor *a, int chan, EChanFlags flags, FSoundID sid, float vol,

void A_StartSound(AActor *self, int soundid, int channel, int flags, double volume, double attenuation, double pitch, double startTime)
{
S_PlaySoundPitch(self, channel, EChanFlags::FromInt(flags), soundid, (float)volume, (float)attenuation, (float)pitch, (float)startTime);
S_PlaySoundPitch(self, channel, EChanFlags::FromInt(flags), FSoundID::fromInt(soundid), (float)volume, (float)attenuation, (float)pitch, (float)startTime);
}

void A_PlaySound(AActor* self, int soundid, int channel, double volume, int looping, double attenuation, int local, double pitch)
Expand Down Expand Up @@ -727,17 +727,17 @@ void S_ChangeActorSoundPitch(AActor *actor, int channel, double pitch)
// Is a sound being played by a specific emitter?
//==========================================================================

bool S_GetSoundPlayingInfo (const AActor *actor, int sound_id)
bool S_GetSoundPlayingInfo (const AActor *actor, FSoundID sound_id)
{
return soundEngine->GetSoundPlayingInfo(SOURCE_Actor, actor, sound_id);
}

bool S_GetSoundPlayingInfo (const sector_t *sec, int sound_id)
bool S_GetSoundPlayingInfo (const sector_t *sec, FSoundID sound_id)
{
return soundEngine->GetSoundPlayingInfo(SOURCE_Sector, sec, sound_id);
}

bool S_GetSoundPlayingInfo (const FPolyObj *poly, int sound_id)
bool S_GetSoundPlayingInfo (const FPolyObj *poly, FSoundID sound_id)
{
return soundEngine->GetSoundPlayingInfo(SOURCE_Polyobj, poly, sound_id);
}
Expand All @@ -748,7 +748,7 @@ bool S_GetSoundPlayingInfo (const FPolyObj *poly, int sound_id)
//
//==========================================================================

int S_IsActorPlayingSomething (AActor *actor, int channel, int sound_id)
bool S_IsActorPlayingSomething (AActor *actor, int channel, FSoundID sound_id)
{
if (compatflags & COMPATF_MAGICSILENCE)
{
Expand Down
9 changes: 5 additions & 4 deletions src/sound/s_doomsound.h
Expand Up @@ -40,11 +40,11 @@ void S_StopActorSounds(AActor *actor, int chanmin, int chanmax);
void S_RelinkSound (AActor *from, AActor *to);

// Is the sound playing on one of the emitter's channels?
bool S_GetSoundPlayingInfo (const AActor *actor, int sound_id);
bool S_GetSoundPlayingInfo (const sector_t *sector, int sound_id);
bool S_GetSoundPlayingInfo (const FPolyObj *poly, int sound_id);
bool S_GetSoundPlayingInfo (const AActor *actor, FSoundID sound_id = INVALID_SOUND);
bool S_GetSoundPlayingInfo (const sector_t *sector, FSoundID sound_id = INVALID_SOUND);
bool S_GetSoundPlayingInfo (const FPolyObj *poly, FSoundID sound_id = INVALID_SOUND);

int S_IsActorPlayingSomething (AActor *actor, int channel, int sound_id);
bool S_IsActorPlayingSomething (AActor *actor, int channel, FSoundID sound_id = INVALID_SOUND);

// Change a playing sound's volume
void S_ChangeActorSoundVolume(AActor *actor, int channel, double volume);
Expand All @@ -55,6 +55,7 @@ void S_ChangeActorSoundPitch(AActor *actor, int channel, double pitch);
// Stores/retrieves playing channel information in an archive.
void S_SerializeSounds(FSerializer &arc);

// these must retain their integer sound IDs because they are direct native functions for ZScript.
void A_PlaySound(AActor *self, int soundid, int channel, double volume, int looping, double attenuation, int local, double pitch);
void A_StartSound(AActor* self, int soundid, int channel, int flags, double volume, double attenuation, double pitch, double startTime = 0.);
static void S_SetListener(AActor *listenactor);
Expand Down
6 changes: 3 additions & 3 deletions src/sound/s_sound.h
Expand Up @@ -72,9 +72,9 @@ const char *S_GetSoundClass(AActor *pp);
FSoundID S_FindSkinnedSound (AActor *actor, FSoundID refid);
int S_FindSkinnedSoundEx (AActor *actor, const char *logicalname, const char *extendedname);
FSoundID S_AddSound (const char *logicalname, const char *lumpname, FScanner *sc=NULL); // Add sound by lumpname
int S_AddPlayerSound (const char *playerclass, const int gender, int refid, const char *lumpname);
int S_AddPlayerSound (const char *playerclass, const int gender, int refid, int lumpnum, bool fromskin=false);
int S_AddPlayerSoundExisting (const char *playerclass, const int gender, int refid, int aliasto, bool fromskin=false);
int S_AddPlayerSound (const char *playerclass, const int gender, FSoundID refid, const char *lumpname);
int S_AddPlayerSound (const char *playerclass, const int gender, FSoundID refid, int lumpnum, bool fromskin=false);
int S_AddPlayerSoundExisting (const char *playerclass, const int gender, FSoundID refid, FSoundID aliasto, bool fromskin=false);
void S_MarkPlayerSounds (AActor *player);
void S_ShrinkPlayerSoundLists ();
unsigned int S_GetMSLength(FSoundID sound);
Expand Down

0 comments on commit d13f12c

Please sign in to comment.