From 94dd92c408b6ff3be22d57f4cbc6cac1f3c6f3ef Mon Sep 17 00:00:00 2001 From: skyjake Date: Fri, 2 Mar 2012 17:44:59 +0200 Subject: [PATCH] SFX|Fixed: Sound priorities on the first tic The listener mobj was not updated until the end of the first frame. This meant sound priority calculations were not working correctly if the sounds were started right at the start of the map. The listener is now updated immediately after the map has been set up. --- doomsday/engine/portable/include/s_main.h | 6 ++++ doomsday/engine/portable/include/s_sfx.h | 1 + doomsday/engine/portable/src/r_world.c | 2 ++ doomsday/engine/portable/src/s_main.c | 6 ++++ doomsday/engine/portable/src/s_sfx.c | 38 +++++++++++++---------- 5 files changed, 36 insertions(+), 17 deletions(-) diff --git a/doomsday/engine/portable/include/s_main.h b/doomsday/engine/portable/include/s_main.h index 2830d4c6be..fdb9948522 100644 --- a/doomsday/engine/portable/include/s_main.h +++ b/doomsday/engine/portable/include/s_main.h @@ -48,6 +48,12 @@ void S_Register(void); boolean S_Init(void); void S_Shutdown(void); void S_MapChange(void); + +/** + * Must be called after the map has been changed. + */ +void S_SetupForChangedMap(void); + void S_Reset(void); void S_StartFrame(void); void S_EndFrame(void); diff --git a/doomsday/engine/portable/include/s_sfx.h b/doomsday/engine/portable/include/s_sfx.h index e8fb924c1f..799adc6cd5 100644 --- a/doomsday/engine/portable/include/s_sfx.h +++ b/doomsday/engine/portable/include/s_sfx.h @@ -66,6 +66,7 @@ void Sfx_Shutdown(void); void Sfx_Reset(void); void Sfx_AllowRefresh(boolean allow); void Sfx_MapChange(void); +void Sfx_SetListener(mobj_t* mobj); void Sfx_StartFrame(void); void Sfx_EndFrame(void); void Sfx_PurgeCache(void); diff --git a/doomsday/engine/portable/src/r_world.c b/doomsday/engine/portable/src/r_world.c index dadf8ff907..93703c6332 100644 --- a/doomsday/engine/portable/src/r_world.c +++ b/doomsday/engine/portable/src/r_world.c @@ -1409,6 +1409,8 @@ void R_SetupMap(int mode, int flags) Materials_ProcessCacheQueue(); VERBOSE( Con_Message("Precaching took %.2f seconds.\n", Sys_GetSeconds() - startTime) ) + S_SetupForChangedMap(); + // Map setup has been completed. // Run any commands specified in Map Info. diff --git a/doomsday/engine/portable/src/s_main.c b/doomsday/engine/portable/src/s_main.c index 799a1ff6a6..380c499db5 100644 --- a/doomsday/engine/portable/src/s_main.c +++ b/doomsday/engine/portable/src/s_main.c @@ -158,6 +158,12 @@ void S_MapChange(void) Sfx_MapChange(); } +void S_SetupForChangedMap(void) +{ + // Update who is listening now. + Sfx_SetListener(S_GetListenerMobj()); +} + /** * Stop all channels and music, delete the entire sample cache. */ diff --git a/doomsday/engine/portable/src/s_sfx.c b/doomsday/engine/portable/src/s_sfx.c index 322ec81416..216abdc14b 100644 --- a/doomsday/engine/portable/src/s_sfx.c +++ b/doomsday/engine/portable/src/s_sfx.c @@ -318,16 +318,15 @@ int Sfx_CountPlaying(int id) /** * The priority of a sound is affected by distance, volume and age. */ -float Sfx_Priority(mobj_t* emitter, float* fixPos, float volume, - int startTic) +float Sfx_Priority(mobj_t* emitter, float* fixPos, float volume, int startTic) { // In five seconds all priority of a sound is gone. - float timeoff = - 1000 * (Sys_GetTime() - startTic) / (5.0f * TICSPERSEC); - float orig[3]; + float timeoff = 1000 * (Sys_GetTime() - startTic) / (5.0f * TICSPERSEC); + float orig[3]; if(!listener || (!emitter && !fixPos)) - { // The sound does not have an origin. + { + // The sound does not have an origin. return 1000 * volume - timeoff; } @@ -342,8 +341,7 @@ float Sfx_Priority(mobj_t* emitter, float* fixPos, float volume, memcpy(orig, fixPos, sizeof(orig)); } - return 1000 * volume - P_MobjPointDistancef(listener, 0, orig) / 2 - - timeoff; + return 1000 * volume - P_MobjPointDistancef(listener, 0, orig) / 2 - timeoff; } /** @@ -511,6 +509,11 @@ void Sfx_ChannelUpdate(sfxchannel_t* ch) } } +void Sfx_SetListener(mobj_t* mobj) +{ + listener = mobj; +} + void Sfx_ListenerUpdate(void) { int i; @@ -521,7 +524,7 @@ void Sfx_ListenerUpdate(void) return; // Update the listener mobj. - listener = S_GetListenerMobj(); + Sfx_SetListener(S_GetListenerMobj()); if(listener) { @@ -680,13 +683,13 @@ int Sfx_StartSound(sfxsample_t* sample, float volume, float freq, for(selCh = NULL, i = 0, ch = channels; i < numChannels; ++i, ch++) { - if(ch->buffer && (ch->buffer->flags & SFXBF_PLAYING) && - ch->buffer->sample->id == sample->id && - myPrio >= channelPrios[i] && - (!selCh || channelPrios[i] <= lowPrio)) + if(ch->buffer && (ch->buffer->flags & SFXBF_PLAYING) && ch->buffer->sample->id == sample->id) { - selCh = ch; - lowPrio = channelPrios[i]; + if(myPrio >= channelPrios[i] && (!selCh || channelPrios[i] <= lowPrio)) + { + selCh = ch; + lowPrio = channelPrios[i]; + } } } @@ -1265,11 +1268,12 @@ void Sfx_DebugInfo(void) FR_SetColor(1, 1, 0); } - sprintf(buf, "%02i: %c%c%c v=%3.1f f=%3.3f st=%i et=%u", i, + sprintf(buf, "%02i: %c%c%c v=%3.1f f=%3.3f st=%i et=%u mobj=%i", i, !(ch->flags & SFXCF_NO_ORIGIN) ? 'O' : '.', !(ch->flags & SFXCF_NO_ATTENUATION) ? 'A' : '.', ch->emitter ? 'E' : '.', ch->volume, ch->frequency, - ch->startTime, ch->buffer ? ch->buffer->endTime : 0); + ch->startTime, ch->buffer ? ch->buffer->endTime : 0, + ch->emitter? ch->emitter->thinker.id : 0); FR_DrawTextXY(buf, 5, lh * (1 + i * 2)); if(!ch->buffer) continue;