Skip to content

Commit

Permalink
Audio|API: Sound emitters are const in APIs; fixed line side emitters
Browse files Browse the repository at this point in the history
All sound emitters are now passed as const pointers in API functions.

Line side emitters were not being initialized until the sector planes
moved.

IssueID #1029
  • Loading branch information
skyjake committed Nov 20, 2016
1 parent 9e069bb commit d125698
Show file tree
Hide file tree
Showing 13 changed files with 67 additions and 57 deletions.
1 change: 1 addition & 0 deletions doomsday/apps/api/api_map.h
Expand Up @@ -74,6 +74,7 @@
#define DMT_SIDE_SECTOR DDVT_PTR
#define DMT_SIDE_LINE DDVT_PTR
#define DMT_SIDE_FLAGS DDVT_INT
#define DMT_SIDE_EMITTER DDVT_PTR

#define DMT_LINE_SIDE DDVT_PTR
#define DMT_LINE_BOUNDS DDVT_PTR
Expand Down
16 changes: 8 additions & 8 deletions doomsday/apps/api/api_sound.h
Expand Up @@ -43,7 +43,7 @@ DENG_API_TYPEDEF(S)
*
* @return Non-zero if a sound was started.
*/
int (*LocalSoundAtVolumeFrom)(int soundIdAndFlags, struct mobj_s *emitter,
int (*LocalSoundAtVolumeFrom)(int soundIdAndFlags, struct mobj_s const *emitter,
coord_t *origin, float volume);

/**
Expand All @@ -52,15 +52,15 @@ DENG_API_TYPEDEF(S)
*
* @return Non-zero if a sound was started.
*/
int (*LocalSoundAtVolume)(int soundId, struct mobj_s *emitter, float volume);
int (*LocalSoundAtVolume)(int soundId, struct mobj_s const *emitter, float volume);

/**
* Plays a sound on the local system from the given @a emitter.
* This is a public sound interface.
*
* @return Non-zero if a sound was started.
*/
int (*LocalSound)(int soundId, struct mobj_s *emitter);
int (*LocalSound)(int soundId, struct mobj_s const *emitter);

/**
* Plays a sound on the local system at the given fixed world @a origin.
Expand All @@ -75,7 +75,7 @@ DENG_API_TYPEDEF(S)
*
* @return Non-zero if a sound was started.
*/
int (*StartSound)(int soundId, struct mobj_s *emitter);
int (*StartSound)(int soundId, struct mobj_s const *emitter);

/**
* Play a world sound. The sound is sent to all players except the one who
Expand All @@ -87,14 +87,14 @@ DENG_API_TYPEDEF(S)
*
* @return Non-zero if a sound was successfully started.
*/
int (*StartSoundEx)(int soundId, struct mobj_s *emitter);
int (*StartSoundEx)(int soundId, struct mobj_s const *emitter);

/**
* Play a world sound. All players in the game will hear it.
*
* @return Non-zero if a sound was started.
*/
int (*StartSoundAtVolume)(int soundId, struct mobj_s *emitter, float volume);
int (*StartSoundAtVolume)(int soundId, struct mobj_s const *emitter, float volume);

/**
* Play a player sound. Only the specified player will hear it.
Expand All @@ -111,13 +111,13 @@ DENG_API_TYPEDEF(S)
* @param emitter @c nullptr: stops all sounds with the ID.
* Otherwise both ID and origin must match.
*/
void (*StopSound)(int soundId, struct mobj_s *emitter/*, flags = 0*/);
void (*StopSound)(int soundId, struct mobj_s const *emitter/*, flags = 0*/);

/**
* @copydoc StopSound()
* @param flags @ref soundStopFlags
*/
void (*StopSound2)(int soundId, struct mobj_s *emitter, int flags);
void (*StopSound2)(int soundId, struct mobj_s const *emitter, int flags);

/**
* Is an instance of the sound being played using the given emitter?
Expand Down
14 changes: 7 additions & 7 deletions doomsday/apps/client/include/audio/audiosystem.h
Expand Up @@ -174,8 +174,8 @@ class AudioSystem : public de::System
bool soundIsPlaying(int soundId, struct mobj_s *emitter) const;

#ifdef __CLIENT__
void stopSoundGroup(int group, struct mobj_s *emitter);
int stopSoundWithLowerPriority(int soundId, struct mobj_s *emitter, int defPriority);
void stopSoundGroup(int group, struct mobj_s const *emitter);
int stopSoundWithLowerPriority(int soundId, struct mobj_s const *emitter, int defPriority);
#endif

/**
Expand All @@ -184,7 +184,7 @@ class AudioSystem : public de::System
* and @a emitter must match.
* @param flags @ref soundStopFlags.
*/
void stopSound(int soundId, struct mobj_s *emitter, int flags = 0);
void stopSound(int soundId, struct mobj_s const *emitter, int flags = 0);

#ifdef __CLIENT__

Expand All @@ -202,13 +202,13 @@ class AudioSystem : public de::System
*
* @return @c true, if a sound is started.
*/
int playSound(sfxsample_t *sample, float volume, float freq, struct mobj_s *emitter,
int playSound(sfxsample_t *sample, float volume, float freq, struct mobj_s const *emitter,
coord_t *fixedOrigin, int flags);

/**
* The priority of a sound is affected by distance, volume and age.
*/
float rateSoundPriority(struct mobj_s *emitter, coord_t const *point, float volume, int startTic);
float rateSoundPriority(struct mobj_s const *emitter, coord_t const *point, float volume, int startTic);

public: // Low-level driver interfaces: ---------------------------------------------

Expand Down Expand Up @@ -274,7 +274,7 @@ class AudioSystem : public de::System
#endif // __CLIENT__

/// @todo Should not be exposed to users of this class. -ds
void startLogical(int soundIdAndFlags, struct mobj_s *emitter);
void startLogical(int soundIdAndFlags, struct mobj_s const *emitter);

private:
DENG2_PRIVATE(d)
Expand Down Expand Up @@ -303,7 +303,7 @@ mobj_t *S_GetListenerMobj();
/**
* Stop all sounds of the group. If an emitter is specified, only it's sounds are checked.
*/
void S_StopSoundGroup(int group, struct mobj_s *emitter);
void S_StopSoundGroup(int group, struct mobj_s const *emitter);

/**
* Stops all channels that are playing the specified sound.
Expand Down
4 changes: 2 additions & 2 deletions doomsday/apps/client/include/audio/sfxchannel.h
Expand Up @@ -88,8 +88,8 @@ class SfxChannel
/**
* Returns the attributed sound emitter if any (may be @c nullptr).
*/
struct mobj_s *emitter() const;
void setEmitter(struct mobj_s *newEmitter);
struct mobj_s const *emitter() const;
void setEmitter(struct mobj_s const *newEmitter);

void setFixedOrigin(de::Vector3d const &newOrigin);

Expand Down
4 changes: 2 additions & 2 deletions doomsday/apps/client/src/api_map.cpp
Expand Up @@ -633,8 +633,8 @@ static void getProperty(MapElement const *elem, DmuArgs &args)
}
}

if(args.type == DMU_SIDE)
{
if(args.type == DMU_SIDE && args.prop != DMU_EMITTER) // emitter is in Line::Side,
{ // not Surface.
if(args.modifiers & DMU_TOP_OF_SIDE)
{
elem = &elem->as<LineSide>().top();
Expand Down
45 changes: 23 additions & 22 deletions doomsday/apps/client/src/audio/base/audiosystem.cpp
Expand Up @@ -607,8 +607,8 @@ DENG2_PIMPL(AudioSystem)
struct LogicSound
{
//dint soundId = 0;
mobj_t *emitter = nullptr;
duint endTime = 0;
mobj_t const *emitter = nullptr;
duint endTime = 0;
bool isRepeating = false;

bool inline isPlaying(duint nowTime) const {
Expand Down Expand Up @@ -1176,7 +1176,7 @@ DENG2_PIMPL(AudioSystem)
*
* @return Number of sounds stopped.
*/
dint sfxStopLogical(dint soundId, mobj_t *emitter)
dint sfxStopLogical(dint soundId, mobj_t const *emitter)
{
dint stopCount = 0;
MutableLogicSoundHashIterator it(sfxLogicHash);
Expand Down Expand Up @@ -1211,7 +1211,7 @@ DENG2_PIMPL(AudioSystem)
* a different set of samples so using this information on server side (for
* scheduling of remote playback events?) is not logical. -ds
*/
void sfxStartLogical(dint soundIdAndFlags, mobj_t *emitter)
void sfxStartLogical(dint soundIdAndFlags, mobj_t const *emitter)
{
if (soundIdAndFlags <= 0) return;

Expand All @@ -1221,7 +1221,8 @@ DENG2_PIMPL(AudioSystem)
// so that we can determine it's length.
if (sfxsample_t *sample = sfxSampleCache.cache(soundId))
{
bool const isRepeating = (soundIdAndFlags & DDSF_REPEAT) || Def_SoundIsRepeating(soundId);
bool const isRepeating = (soundIdAndFlags & DDSF_REPEAT) ||
Def_SoundIsRepeating(soundId);

duint length = (1000 * sample->numSamples) / sample->rate;
if (isRepeating && length > 1)
Expand Down Expand Up @@ -1953,7 +1954,7 @@ bool AudioSystem::soundIsPlaying(dint soundId, mobj_t *emitter) const

#ifdef __CLIENT__

void AudioSystem::stopSoundGroup(dint group, mobj_t *emitter)
void AudioSystem::stopSoundGroup(dint group, mobj_t const *emitter)
{
if (!d->sfxAvail) return;
LOG_AS("AudioSystem");
Expand All @@ -1973,7 +1974,7 @@ void AudioSystem::stopSoundGroup(dint group, mobj_t *emitter)
});
}

dint AudioSystem::stopSoundWithLowerPriority(dint id, mobj_t *emitter, dint defPriority)
dint AudioSystem::stopSoundWithLowerPriority(dint id, mobj_t const *emitter, dint defPriority)
{
if (!d->sfxAvail) return false;

Expand Down Expand Up @@ -2022,7 +2023,7 @@ dint AudioSystem::stopSoundWithLowerPriority(dint id, mobj_t *emitter, dint defP

#endif // __CLIENT__

void AudioSystem::stopSound(dint soundId, mobj_t *emitter, dint flags)
void AudioSystem::stopSound(dint soundId, mobj_t const *emitter, dint flags)
{
LOG_AS("AudioSystem");

Expand Down Expand Up @@ -2064,7 +2065,7 @@ void AudioSystem::stopSound(dint soundId, mobj_t *emitter, dint flags)
}

#ifdef __CLIENT__
dint AudioSystem::playSound(sfxsample_t *sample, dfloat volume, dfloat freq, mobj_t *emitter,
dint AudioSystem::playSound(sfxsample_t *sample, dfloat volume, dfloat freq, mobj_t const *emitter,
coord_t *fixedOrigin, dint flags)
{
DENG2_ASSERT(sample);
Expand Down Expand Up @@ -2325,7 +2326,7 @@ dint AudioSystem::playSound(sfxsample_t *sample, dfloat volume, dfloat freq, mob
return true;
}

dfloat AudioSystem::rateSoundPriority(mobj_t *emitter, coord_t const *point, dfloat volume,
dfloat AudioSystem::rateSoundPriority(mobj_t const *emitter, coord_t const *point, dfloat volume,
dint startTic)
{
// In five seconds all priority of a sound is gone.
Expand Down Expand Up @@ -2431,7 +2432,7 @@ void AudioSystem::requestSfxListenerUpdate()

#endif // __CLIENT__

void AudioSystem::startLogical(dint soundIdAndFlags, mobj_t *emitter)
void AudioSystem::startLogical(dint soundIdAndFlags, mobj_t const *emitter)
{
d->sfxStartLogical(soundIdAndFlags, emitter);
}
Expand Down Expand Up @@ -2753,7 +2754,7 @@ mobj_t *S_GetListenerMobj()
}

#undef S_LocalSoundAtVolumeFrom
dint S_LocalSoundAtVolumeFrom(dint soundIdAndFlags, mobj_t *origin, coord_t *point, dfloat volume)
dint S_LocalSoundAtVolumeFrom(dint soundIdAndFlags, mobj_t const *origin, coord_t *point, dfloat volume)
{
#ifdef __CLIENT__
LOG_AS("S_LocalSoundAtVolumeFrom");
Expand Down Expand Up @@ -2789,7 +2790,7 @@ dint S_LocalSoundAtVolumeFrom(dint soundIdAndFlags, mobj_t *origin, coord_t *poi
if (!(info->flags & SF_NO_ATTENUATION) && !(soundIdAndFlags & DDSF_NO_ATTENUATION))
{
// If origin is too far, don't even think about playing the sound.
coord_t *fixPoint = (origin ? origin->origin : point);
coord_t const *fixPoint = (origin ? origin->origin : point);

if (Mobj_ApproxPointDistance(S_GetListenerMobj(), fixPoint) > soundMaxDist)
return false;
Expand Down Expand Up @@ -2824,7 +2825,7 @@ dint S_LocalSoundAtVolumeFrom(dint soundIdAndFlags, mobj_t *origin, coord_t *poi
// iterations of this sound will stop.
if (info->group)
{
mobj_t *emitter = ((info->flags & SF_GLOBAL_EXCLUDE) ? nullptr : origin);
mobj_t const *emitter = ((info->flags & SF_GLOBAL_EXCLUDE) ? nullptr : origin);
S_StopSoundGroup(info->group, emitter);
}

Expand All @@ -2842,13 +2843,13 @@ dint S_LocalSoundAtVolumeFrom(dint soundIdAndFlags, mobj_t *origin, coord_t *poi
}

#undef S_LocalSoundAtVolume
dint S_LocalSoundAtVolume(dint soundIdAndFlags, mobj_t *emitter, dfloat volume)
dint S_LocalSoundAtVolume(dint soundIdAndFlags, mobj_t const *emitter, dfloat volume)
{
return S_LocalSoundAtVolumeFrom(soundIdAndFlags, emitter, nullptr, volume);
}

#undef S_LocalSound
dint S_LocalSound(dint soundIdAndFlags, mobj_t *emitter)
dint S_LocalSound(dint soundIdAndFlags, mobj_t const *emitter)
{
// Play local sound at max volume.
return S_LocalSoundAtVolumeFrom(soundIdAndFlags, emitter, nullptr, 1);
Expand All @@ -2861,7 +2862,7 @@ dint S_LocalSoundFrom(dint soundIdAndFlags, coord_t *origin)
}

#undef S_StartSound
dint S_StartSound(dint soundIdAndFlags, mobj_t *emitter)
dint S_StartSound(dint soundIdAndFlags, mobj_t const *emitter)
{
#ifdef __SERVER__
// The sound is audible to everybody.
Expand All @@ -2873,7 +2874,7 @@ dint S_StartSound(dint soundIdAndFlags, mobj_t *emitter)
}

#undef S_StartSoundEx
dint S_StartSoundEx(dint soundIdAndFlags, mobj_t *emitter)
dint S_StartSoundEx(dint soundIdAndFlags, mobj_t const *emitter)
{
#ifdef __SERVER__
Sv_Sound(soundIdAndFlags, emitter, SVSF_TO_ALL | SVSF_EXCLUDE_ORIGIN);
Expand All @@ -2884,7 +2885,7 @@ dint S_StartSoundEx(dint soundIdAndFlags, mobj_t *emitter)
}

#undef S_StartSoundAtVolume
dint S_StartSoundAtVolume(dint soundIdAndFlags, mobj_t *emitter, dfloat volume)
dint S_StartSoundAtVolume(dint soundIdAndFlags, mobj_t const *emitter, dfloat volume)
{
#ifdef __SERVER__
Sv_SoundAtVolume(soundIdAndFlags, emitter, volume, SVSF_TO_ALL);
Expand Down Expand Up @@ -2912,13 +2913,13 @@ dint S_ConsoleSound(dint soundId, mobj_t *emitter, dint targetConsole)
}

#undef S_StopSound
void S_StopSound(dint soundId, mobj_t *emitter)
void S_StopSound(dint soundId, mobj_t const *emitter)
{
App_AudioSystem().stopSound(soundId, emitter);
}

#undef S_StopSound2
void S_StopSound2(dint soundId, mobj_t *emitter, dint flags)
void S_StopSound2(dint soundId, mobj_t const *emitter, dint flags)
{
App_AudioSystem().stopSound(soundId, emitter, flags);
}
Expand All @@ -2931,7 +2932,7 @@ dint S_IsPlaying(dint soundId, mobj_t *emitter)

#ifdef __CLIENT__

void S_StopSoundGroup(dint group, mobj_t *emitter)
void S_StopSoundGroup(dint group, mobj_t const *emitter)
{
App_AudioSystem().stopSoundGroup(group, emitter);
}
Expand Down
6 changes: 3 additions & 3 deletions doomsday/apps/client/src/audio/sfxchannel.cpp
Expand Up @@ -48,7 +48,7 @@ DENG2_PIMPL_NOREF(SfxChannel)
dfloat frequency = 0; ///< Frequency adjustment: 1.0 is normal.
dfloat volume = 0; ///< Sound volume: 1.0 is max.

mobj_t *emitter = nullptr; ///< Mobj emitter for the sound, if any (not owned).
mobj_t const *emitter = nullptr;///< Mobj emitter for the sound, if any (not owned).
coord_t origin[3]; ///< Emit from here (synced with emitter).

sfxbuffer_t *buffer = nullptr; ///< Assigned sound buffer, if any (not owned).
Expand Down Expand Up @@ -153,12 +153,12 @@ void SfxChannel::setVolume(dfloat newVolume)
d->volume = newVolume;
}

mobj_t *SfxChannel::emitter() const
mobj_t const *SfxChannel::emitter() const
{
return d->emitter;
}

void SfxChannel::setEmitter(mobj_t *newEmitter)
void SfxChannel::setEmitter(mobj_t const *newEmitter)
{
d->emitter = newEmitter;
}
Expand Down
6 changes: 6 additions & 0 deletions doomsday/apps/client/src/world/base/line.cpp
Expand Up @@ -988,6 +988,12 @@ dint Line::Side::property(DmuArgs &args) const
case DMU_FLAGS:
args.setValue(DMT_SIDE_FLAGS, &d->flags, 0);
break;
case DMU_EMITTER:
args.setValue(DMT_SIDE_EMITTER,
args.modifiers & DMU_TOP_OF_SIDE? &soundEmitter(Top) :
args.modifiers & DMU_MIDDLE_OF_SIDE? &soundEmitter(Middle) :
&soundEmitter(Bottom), 0);
break;
default:
return MapElement::property(args);
}
Expand Down
2 changes: 2 additions & 0 deletions doomsday/apps/client/src/world/base/sector.cpp
Expand Up @@ -412,6 +412,8 @@ void Sector::buildSides()
}
return LoopContinue;
});

d->updateAllEmitterOrigins();
}

SoundEmitter &Sector::soundEmitter()
Expand Down

0 comments on commit d125698

Please sign in to comment.