Check if sound is currently playing in a channel
Moderator: GZDoom Developers
-
- Posts: 3886
- Joined: Fri Feb 08, 2008 9:15 am
- Preferred Pronouns: She/Her
- Operating System Version (Optional): (btw I use) Arch
- Graphics Processor: nVidia with Vulkan support
- Location: Vigo, Galicia
Check if sound is currently playing in a channel
I'm interested in having a way to check in ZScript whether or not an actor is playing sound in a specific channel.
I have a system where this would be very useful. Basically, I spawn actors that attach to players with a specific offset in order to play some ambient noises that seem to come from a fixed direction. At the moment I hardcode their lifespan, which is rather time consuming since I have to go through so many different sound effects, and also it wouldn't take into account pitch shift.
I have a system where this would be very useful. Basically, I spawn actors that attach to players with a specific offset in order to play some ambient noises that seem to come from a fixed direction. At the moment I hardcode their lifespan, which is rather time consuming since I have to go through so many different sound effects, and also it wouldn't take into account pitch shift.
-
-
- Posts: 3814
- Joined: Sun Aug 07, 2011 4:32 am
Re: Check if sound is currently playing in a channel
Do you need some like this?
Or maybe this?
Code: Select all
bool S_IsChannelPlaying (int channel)
Code: Select all
bool S_IsActorPlaying(Actor source, int channel, Sound id)
-
- Posts: 3886
- Joined: Fri Feb 08, 2008 9:15 am
- Preferred Pronouns: She/Her
- Operating System Version (Optional): (btw I use) Arch
- Graphics Processor: nVidia with Vulkan support
- Location: Vigo, Galicia
Re: Check if sound is currently playing in a channel
If the first function can be called from within the playing actor, then yes, that one would be handy.
-
-
- Posts: 3814
- Joined: Sun Aug 07, 2011 4:32 am
Re: Check if sound is currently playing in a channel
No, both are static functions in Object class. I assume you need the latter, scriptified S_IsActorPlayingSomething() function in other words.
EDIT: Or even better like this
EDIT: Or even better like this
Code: Select all
class Actor
{
// ...
native bool A_IsPlayingSound(int channel, sound sound_id = "");
// ...
}
-
- Posts: 3886
- Joined: Fri Feb 08, 2008 9:15 am
- Preferred Pronouns: She/Her
- Operating System Version (Optional): (btw I use) Arch
- Graphics Processor: nVidia with Vulkan support
- Location: Vigo, Galicia
Re: Check if sound is currently playing in a channel
Oh, that one would do it, yes.
-
- Posts: 186
- Joined: Fri Apr 12, 2013 10:51 am
Re: Check if sound is currently playing in a channel
Isn't this feature going to cause an issue with multiplayer and demos?
Or am I missing something?
Or am I missing something?
-
- Posts: 3886
- Joined: Fri Feb 08, 2008 9:15 am
- Preferred Pronouns: She/Her
- Operating System Version (Optional): (btw I use) Arch
- Graphics Processor: nVidia with Vulkan support
- Location: Vigo, Galicia
Re: Check if sound is currently playing in a channel
Actually I was wondering about that too. How would this be implemented in a way that wouldn't desync? Is it even possible to have "clientside" actors or something that wouldn't get synced?
-
-
- Posts: 3814
- Joined: Sun Aug 07, 2011 4:32 am
Re: Check if sound is currently playing in a channel
It depends on what you about to do with information returned from this function.
If you will use it for some game logic decisions, it may cause problems in MP.
If you plan to just stop this sound and play that one, everything will be fine.
If you will use it for some game logic decisions, it may cause problems in MP.
If you plan to just stop this sound and play that one, everything will be fine.
-
- Posts: 3886
- Joined: Fri Feb 08, 2008 9:15 am
- Preferred Pronouns: She/Her
- Operating System Version (Optional): (btw I use) Arch
- Graphics Processor: nVidia with Vulkan support
- Location: Vigo, Galicia
Re: Check if sound is currently playing in a channel
Oh, then I can see it causing problems, since it would be used for deleting a sound playing actor.
Edit: I talked about this with Rachael and it seems that within my use case it might not desync, actually, since the actors have no other interaction with the game at all beyond warping to the player and playing sound.
Edit: I talked about this with Rachael and it seems that within my use case it might not desync, actually, since the actors have no other interaction with the game at all beyond warping to the player and playing sound.
-
- Posts: 186
- Joined: Fri Apr 12, 2013 10:51 am
Re: Check if sound is currently playing in a channel
It shouldn't desync as long as you avoid using random number generators.
From my experience, if done well, you can spawn actors just on one peer without causing desync if they don't interact with the game and if they have specific flags and properties set.
From my experience, if done well, you can spawn actors just on one peer without causing desync if they don't interact with the game and if they have specific flags and properties set.
-
- Posts: 3886
- Joined: Fri Feb 08, 2008 9:15 am
- Preferred Pronouns: She/Her
- Operating System Version (Optional): (btw I use) Arch
- Graphics Processor: nVidia with Vulkan support
- Location: Vigo, Galicia
Re: Check if sound is currently playing in a channel
The flags for this actor are +NOGRAVITY, +NOBLOCKMAP, +NOSECTOR and +DONTSPLASH (because it's used on Heretic). Is that enough?
-
- Posts: 186
- Joined: Fri Apr 12, 2013 10:51 am
Re: Check if sound is currently playing in a channel
Instead of +NOSECTOR you can use +NOINTERACTION and thus keep the actor visible (for other purposes if need be).
Don't forget to set "FloatBobPhase" to something else than -1 (See here why: https://github.com/coelckers/gzdoom/blo ... .cpp#L5065 )
Don't forget to set "FloatBobPhase" to something else than -1 (See here why: https://github.com/coelckers/gzdoom/blo ... .cpp#L5065 )
-
- Posts: 3886
- Joined: Fri Feb 08, 2008 9:15 am
- Preferred Pronouns: She/Her
- Operating System Version (Optional): (btw I use) Arch
- Graphics Processor: nVidia with Vulkan support
- Location: Vigo, Galicia
Re: Check if sound is currently playing in a channel
Oh, I see. Although visibility isn't really important at all since it's just a sound effect. No need to be seen or anything.
I'm a bit confused about the FloatBobPhase part, though. The actor doesn't even have floatbob or anything.
Oh wait, it would screw the RNG seed, I see.
Edit: I was digging through the sources a little bit ago and I came across the S_GetMSLength() function, for getting the duration of a sound. Looking at it, I think this one might be a better choice (would even add some parity with unrealscript).
Edit 2: I opened a pull request on qzdoom for both functions.
I'm a bit confused about the FloatBobPhase part, though. The actor doesn't even have floatbob or anything.
Oh wait, it would screw the RNG seed, I see.
Edit: I was digging through the sources a little bit ago and I came across the S_GetMSLength() function, for getting the duration of a sound. Looking at it, I think this one might be a better choice (would even add some parity with unrealscript).
Edit 2: I opened a pull request on qzdoom for both functions.
-
- Lead GZDoom+Raze Developer
- Posts: 49141
- Joined: Sat Jul 19, 2003 10:19 am
- Location: Germany
Re: Check if sound is currently playing in a channel
So, S_GetMSLength was exported, but S_IsActorPlayingSomething was not. So I just added that export, too.
Regarding desyncs, yes, if you make any gameplay related decisions on sounds it will desync. On the other hand, there's no way to design sound without some tools to query the state.
This is a case where trying to make it foolproof is not the best solution, at some point it is the modder's responsibility to use those functions properly.
Regarding desyncs, yes, if you make any gameplay related decisions on sounds it will desync. On the other hand, there's no way to design sound without some tools to query the state.
This is a case where trying to make it foolproof is not the best solution, at some point it is the modder's responsibility to use those functions properly.
-
- Posts: 3886
- Joined: Fri Feb 08, 2008 9:15 am
- Preferred Pronouns: She/Her
- Operating System Version (Optional): (btw I use) Arch
- Graphics Processor: nVidia with Vulkan support
- Location: Vigo, Galicia
Re: Check if sound is currently playing in a channel
Well, ever since the time I made this suggestion I've gotten quite proficient at making non-deterministic gameplay scripting that doesn't cause desyncs.