From 176da5de6870f62d79245d625486f0eb30b59428 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 25 Nov 2018 18:40:26 +0100 Subject: [PATCH] - added a direct native variant for A_PlaySound because this function is relatively easy to test. --- src/p_actionfunctions.cpp | 27 --------------------------- src/s_sound.cpp | 18 ++++++++++++++++++ src/s_sound.h | 1 + src/scripting/vmthunks.cpp | 12 ++++++++++++ 4 files changed, 31 insertions(+), 27 deletions(-) diff --git a/src/p_actionfunctions.cpp b/src/p_actionfunctions.cpp index 93a521a25f..4bb7ade7eb 100644 --- a/src/p_actionfunctions.cpp +++ b/src/p_actionfunctions.cpp @@ -958,33 +958,6 @@ DEFINE_ACTION_FUNCTION(AActor, A_CopyFriendliness) // //========================================================================== -DEFINE_ACTION_FUNCTION(AActor, A_PlaySound) -{ - PARAM_SELF_PROLOGUE(AActor); - PARAM_SOUND (soundid); - PARAM_INT (channel); - PARAM_FLOAT (volume); - PARAM_BOOL (looping); - PARAM_FLOAT (attenuation); - PARAM_BOOL (local); - - if (!looping) - { - if (!(channel & CHAN_NOSTOP) || !S_IsActorPlayingSomething(self, channel & 7, soundid)) - { - S_PlaySound(self, channel, soundid, (float)volume, (float)attenuation, local); - } - } - else - { - if (!S_IsActorPlayingSomething (self, channel&7, soundid)) - { - S_PlaySound(self, channel | CHAN_LOOP, soundid, (float)volume, (float)attenuation, local); - } - } - return 0; -} - DEFINE_ACTION_FUNCTION(AActor, A_StopSound) { PARAM_SELF_PROLOGUE(AActor); diff --git a/src/s_sound.cpp b/src/s_sound.cpp index 4ba1d476e7..fc2d0031d7 100644 --- a/src/s_sound.cpp +++ b/src/s_sound.cpp @@ -1443,6 +1443,24 @@ void S_PlaySound(AActor *a, int chan, FSoundID sid, float vol, float atten, bool } } +void A_PlaySound(AActor *self, int soundid, int channel, double volume, int looping, double attenuation, int local) +{ + if (!looping) + { + if (!(channel & CHAN_NOSTOP) || !S_IsActorPlayingSomething(self, channel & 7, soundid)) + { + S_PlaySound(self, channel, soundid, (float)volume, (float)attenuation, local); + } + } + else + { + if (!S_IsActorPlayingSomething(self, channel & 7, soundid)) + { + S_PlaySound(self, channel | CHAN_LOOP, soundid, (float)volume, (float)attenuation, local); + } + } +} + //========================================================================== // // S_LoadSound diff --git a/src/s_sound.h b/src/s_sound.h index 1d42cb2aed..bf937e893e 100644 --- a/src/s_sound.h +++ b/src/s_sound.h @@ -371,6 +371,7 @@ sfxinfo_t *S_LoadSound(sfxinfo_t *sfx, FSoundLoadBuffer *pBuffer = nullptr); unsigned int S_GetMSLength(FSoundID sound); void S_ParseMusInfo(); bool S_ParseTimeTag(const char *tag, bool *as_samples, unsigned int *time); +void A_PlaySound(AActor *self, int soundid, int channel, double volume, int looping, double attenuation, int local); // [RH] Prints sound debug info to the screen. // Modelled after Hexen's noise cheat. diff --git a/src/scripting/vmthunks.cpp b/src/scripting/vmthunks.cpp index 1e92a886b8..65953ec91f 100644 --- a/src/scripting/vmthunks.cpp +++ b/src/scripting/vmthunks.cpp @@ -1253,3 +1253,15 @@ DEFINE_ACTION_FUNCTION_NATIVE(_Secplane, PointToDist, PointToDist) ACTION_RETURN_FLOAT(self->PointToDist(DVector2(x, y), z)); } +DEFINE_ACTION_FUNCTION_NATIVE(AActor, A_PlaySound, A_PlaySound) +{ + PARAM_SELF_PROLOGUE(AActor); + PARAM_SOUND(soundid); + PARAM_INT(channel); + PARAM_FLOAT(volume); + PARAM_BOOL(looping); + PARAM_FLOAT(attenuation); + PARAM_BOOL(local); + A_PlaySound(self, soundid, channel, volume, looping, attenuation, local); + return 0; +}