]> git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
hopefully fix a race condition in S_StartSound
authordivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Wed, 30 Dec 2009 11:24:10 +0000 (11:24 +0000)
committerdivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Wed, 30 Dec 2009 11:24:10 +0000 (11:24 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@9745 d7cf8633-e32d-0410-b094-e92efae38249

cl_input.c
snd_main.c
sv_user.c

index f5714fa6b021c1335d1bec21fd6bb561b268c3d1..c792f471f752b35bc55b187939d8cbfc41bea523 100644 (file)
@@ -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));
index d627dc512973d88370faca901551ecc7dc7e2b3e..57ed4786521096ddc3f5a496ae7a29c266c64cc9 100644 (file)
@@ -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);
 }
 
 
index 3f68714b15eab2cecf6277a7b437b8af3c79d4ff..294199ef035eae4f061f6536a989c24b6e7575d2 100644 (file)
--- 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;