From c9224df6b5391897c23a5f1ca33714b9390e8c87 Mon Sep 17 00:00:00 2001 From: divverent Date: Wed, 30 Dec 2009 11:24:10 +0000 Subject: [PATCH] hopefully fix a race condition in S_StartSound git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@9745 d7cf8633-e32d-0410-b094-e92efae38249 --- cl_input.c | 5 +++++ snd_main.c | 47 +++++++++++++++++++++++++++-------------------- sv_user.c | 10 ++++++++++ 3 files changed, 42 insertions(+), 20 deletions(-) diff --git a/cl_input.c b/cl_input.c index f5714fa6..c792f471 100644 --- a/cl_input.c +++ b/cl_input.c @@ -1722,6 +1722,9 @@ void CL_SendMove(void) cl.lastpackettime = floor(realtime / packettime) * packettime; else cl.lastpackettime = realtime; + + if(cl.cmd.impulse) + Con_Printf("MOVEMENT DEBUGGING: Prepared impulse %d\n", cl.cmd.impulse); buf.maxsize = sizeof(data); buf.cursize = 0; @@ -1862,6 +1865,8 @@ void CL_SendMove(void) // 5 bytes MSG_WriteLong (&buf, cmd->buttons); MSG_WriteByte (&buf, cmd->impulse); + if(cmd->impulse) + Con_Printf("MOVEMENT DEBUGGING: sending impulse %d\n", cmd->impulse); // PRYDON_CLIENTCURSOR // 30 bytes MSG_WriteShort (&buf, (short)(cmd->cursor_screen[0] * 32767.0f)); diff --git a/snd_main.c b/snd_main.c index d627dc51..57ed4786 100644 --- a/snd_main.c +++ b/snd_main.c @@ -1403,7 +1403,8 @@ void SND_Spatialize(channel_t *ch, qboolean isstatic) // Start a sound effect // ======================================================================= -void S_PlaySfxOnChannel (sfx_t *sfx, channel_t *target_chan, unsigned int flags, vec3_t origin, float fvol, float attenuation, qboolean isstatic) +static void S_SetChannelVolume_WithSfx (unsigned int ch_ind, float fvol, sfx_t *sfx); +void S_PlaySfxOnChannel (sfx_t *sfx, channel_t *target_chan, unsigned int flags, vec3_t origin, float fvol, float attenuation, qboolean isstatic, int entnum, int entchannel, int startpos) { if (!sfx) { @@ -1423,7 +1424,9 @@ void S_PlaySfxOnChannel (sfx_t *sfx, channel_t *target_chan, unsigned int flags, memset (target_chan, 0, sizeof (*target_chan)); VectorCopy (origin, target_chan->origin); target_chan->flags = flags; - target_chan->pos = 0; // start of the sound + target_chan->pos = startpos; // start of the sound + target_chan->entnum = entnum; + target_chan->entchannel = entchannel; // If it's a static sound if (isstatic) @@ -1435,23 +1438,27 @@ void S_PlaySfxOnChannel (sfx_t *sfx, channel_t *target_chan, unsigned int flags, else target_chan->dist_mult = attenuation / snd_soundradius.value; + // we have to set the channel volume AFTER the sfx because the function + // needs it for replaygain support + S_SetChannelVolume_WithSfx(target_chan - channels, fvol, sfx); + + // set the listener volumes + SND_Spatialize (target_chan, isstatic); + // Lock the SFX during play S_LockSfx (sfx); // finally, set the sfx pointer, so the channel becomes valid for playback // and will be noticed by the mixer target_chan->sfx = sfx; - - // we have to set the channel volume AFTER the sfx because the function - // needs it for replaygain support - S_SetChannelVolume(target_chan - channels, fvol); + SND_Spatialize (target_chan, isstatic); } int S_StartSound (int entnum, int entchannel, sfx_t *sfx, vec3_t origin, float fvol, float attenuation) { channel_t *target_chan, *check, *ch; - int ch_idx; + int ch_idx, startpos; if (snd_renderbuffer == NULL || sfx == NULL || nosound.integer) return -1; @@ -1482,27 +1489,24 @@ int S_StartSound (int entnum, int entchannel, sfx_t *sfx, vec3_t origin, float f if (!target_chan) return -1; - S_PlaySfxOnChannel (sfx, target_chan, CHANNELFLAG_NONE, origin, fvol, attenuation, false); - target_chan->entnum = entnum; - target_chan->entchannel = entchannel; - - SND_Spatialize(target_chan, false); - // if an identical sound has also been started this frame, offset the pos // a bit to keep it from just making the first one louder check = &channels[NUM_AMBIENTS]; + startpos = 0; for (ch_idx=NUM_AMBIENTS ; ch_idx < NUM_AMBIENTS + MAX_DYNAMIC_CHANNELS ; ch_idx++, check++) { if (check == target_chan) continue; - if (check->sfx == sfx && !check->pos) + if (check->sfx == sfx && check->pos == 0) { // use negative pos offset to delay this sound effect - target_chan->pos += (int)lhrandom(0, -0.1 * snd_renderbuffer->format.speed); + startpos = (int)lhrandom(0, -0.1 * snd_renderbuffer->format.speed); break; } } + S_PlaySfxOnChannel (sfx, target_chan, CHANNELFLAG_NONE, origin, fvol, attenuation, false, entnum, entchannel, startpos); + return (target_chan - channels); } @@ -1621,9 +1625,8 @@ void S_PauseGameSounds (qboolean toggle) } } -void S_SetChannelVolume (unsigned int ch_ind, float fvol) +static void S_SetChannelVolume_WithSfx (unsigned int ch_ind, float fvol, sfx_t *sfx) { - sfx_t *sfx = channels[ch_ind].sfx; if(sfx->volume_peak > 0) { // Replaygain support @@ -1636,6 +1639,12 @@ void S_SetChannelVolume (unsigned int ch_ind, float fvol) channels[ch_ind].master_vol = (int)(fvol * 255.0f); } +void S_SetChannelVolume(unsigned int ch_ind, float fvol) +{ + sfx_t *sfx = channels[ch_ind].sfx; + S_SetChannelVolume_WithSfx(ch_ind, fvol, sfx); +} + float S_GetChannelPosition (unsigned int ch_ind) { // note: this is NOT accurate yet @@ -1677,9 +1686,7 @@ void S_StaticSound (sfx_t *sfx, vec3_t origin, float fvol, float attenuation) } target_chan = &channels[total_channels++]; - S_PlaySfxOnChannel (sfx, target_chan, CHANNELFLAG_FORCELOOP, origin, fvol, attenuation, true); - - SND_Spatialize (target_chan, true); + S_PlaySfxOnChannel (sfx, target_chan, CHANNELFLAG_FORCELOOP, origin, fvol, attenuation, true, 0, 0, 0); } diff --git a/sv_user.c b/sv_user.c index 3f68714b..294199ef 100644 --- a/sv_user.c +++ b/sv_user.c @@ -531,6 +531,9 @@ void SV_ReadClientMove (void) if (msg_badread) Con_Printf("SV_ReadClientMessage: badread at %s:%i\n", __FILE__, __LINE__); } + if(move->impulse) + Con_Printf("MOVEMENT DEBUGGING: received impulse %d\n", move->impulse); + // if the previous move has not been applied yet, we need to accumulate // the impulse/buttons from it if (!host_client->cmd.applied) @@ -629,8 +632,11 @@ void SV_ExecuteClientMoves(void) // execute it but it has higher // sequence count if(host_client->movesequence) + { if(move->sequence > host_client->movesequence) host_client->movement_count[(move->sequence) % NETGRAPH_PACKETS] = -1; + Con_Printf("MOVEMENT DEBUGGING: invalid packet timing (less than 0.5ms), discarded packet\n"); + } continue; } @@ -653,6 +659,10 @@ void SV_ExecuteClientMoves(void) // the server and qc frametime values must be changed temporarily prog->globals.server->frametime = sv.frametime = moveframetime; // if move is more than 50ms, split it into two moves (this matches QWSV behavior and the client prediction) + + if(host_client->cmd.impulse) + Con_Printf("MOVEMENT DEBUGGING: applying impulse %d\n", host_client->cmd.impulse); + if (sv.frametime > 0.05) { prog->globals.server->frametime = sv.frametime = moveframetime * 0.5f; -- 2.39.2