implemented snd_mutewhenidle cvar, defaults to 1, to allow people to
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Mon, 27 Aug 2007 11:12:19 +0000 (11:12 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Mon, 27 Aug 2007 11:12:19 +0000 (11:12 +0000)
reenable sound when not the active window if they wish (such as when
watching demos)

git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@7542 d7cf8633-e32d-0410-b094-e92efae38249

cl_input.c
cl_parse.c
snd_main.c
snd_main.h
sound.h
vid_glx.c
vid_sdl.c
vid_wgl.c

index a725470..a5387e0 100644 (file)
@@ -351,6 +351,7 @@ cvar_t m_filter = {CVAR_SAVE, "m_filter","0", "smoothes mouse movement, less res
 
 cvar_t cl_netinputpacketsperserverpacket = {CVAR_SAVE, "cl_netinputpacketsperserverpacket", "1.0", "send this many input packets per server packet received"};
 cvar_t cl_netinputpacketspersecond = {CVAR_SAVE, "cl_netinputpacketspersecond","20", "how many input packets to send to server each second (only used on old servers, and note this is multiplied by cl_netinputpacketsperserverpacket)"};
+cvar_t cl_netinputpacketspersecond_qw = {CVAR_SAVE, "cl_netinputpacketspersecond","72", "how many input packets to send to a qw server each second (only used on qw servers)"};
 cvar_t cl_netinputpacketlosstolerance = {CVAR_SAVE, "cl_netinputpacketlosstolerance", "1", "how many packets in a row can be lost without movement issues when using cl_movement (technically how many input messages to repeat in each packet that have not yet been acknowledged by the server), only affects DP7 and later servers (Quake uses 0, QuakeWorld uses 2, and just for comparison Quake3 uses 1)"};
 
 cvar_t cl_nodelta = {0, "cl_nodelta", "0", "disables delta compression of non-player entities in QW network protocol"};
@@ -1059,7 +1060,7 @@ extern cvar_t slowmo;
 void CL_UpdateMoveVars(void)
 {
        if (cls.protocol == PROTOCOL_QUAKEWORLD)
-               cl.movevars_ticrate = 1.0 / bound(1, cl_netinputpacketspersecond.value, 100);
+               cl.movevars_ticrate = 1.0 / bound(1, cl_netinputpacketspersecond_qw.value, 100);
        else if (cl.stats[STAT_MOVEVARS_TICRATE])
        {
                cl.movevars_ticrate = cl.statsf[STAT_MOVEVARS_TICRATE];
@@ -1271,37 +1272,29 @@ void CL_SendMove(void)
                return;
 
        // don't send too often or else network connections can get clogged by a high renderer framerate
-       packettime = cl.movevars_ticrate / (double)bound(1, cl_netinputpacketsperserverpacket.value, 10);
+       packettime = cl.movevars_ticrate;
+       if (cls.protocol != PROTOCOL_QUAKEWORLD)
+               packettime /= (double)bound(1, cl_netinputpacketsperserverpacket.value, 10);
        // send input every frame in singleplayer
        if (cl.islocalgame)
                packettime = 0;
        // quakeworld servers take only frametimes
        // predicted dp7 servers take current interpolation time
        // unpredicted servers take an echo of the latest server timestamp
+       cl.cmd.time = cl.time;
+       cl.cmd.sequence = cls.movesequence;
        if (cls.protocol == PROTOCOL_QUAKEWORLD)
        {
                if (realtime < lastsendtime + packettime)
                        return;
-               cl.cmd.time = realtime;
                cl.cmd.sequence = cls.netcon->qw.outgoing_sequence;
        }
-       else if (cl.movement_predicted)
-       {
-               if (realtime < lastsendtime + packettime)
-                       return;
-               cl.cmd.time = cl.time;
-               cl.cmd.sequence = cls.movesequence;
-       }
        else
        {
-               // unpredicted movement should be sent immediately whenever a server
+               // movement should be sent immediately whenever a server
                // packet is received, to minimize ping times
                if (!cl.movement_needupdate && realtime < lastsendtime + packettime)
                        return;
-               if (cl.mtime[0] == cl.movecmd[0].time && cl.mtime[1] != cl.mtime[0])
-                       return;
-               cl.cmd.time = cl.mtime[0];
-               cl.cmd.sequence = cls.movesequence;
        }
 
        // don't let it fall behind if CL_SendMove hasn't been called recently
@@ -1680,6 +1673,7 @@ void CL_InitInput (void)
 
        Cvar_RegisterVariable(&cl_netinputpacketsperserverpacket);
        Cvar_RegisterVariable(&cl_netinputpacketspersecond);
+       Cvar_RegisterVariable(&cl_netinputpacketspersecond_qw);
        Cvar_RegisterVariable(&cl_netinputpacketlosstolerance);
 
        Cvar_RegisterVariable(&cl_nodelta);
index 83322bd..1dd0aed 100644 (file)
@@ -2981,6 +2981,7 @@ void CL_ParseServerMessage(void)
        unsigned char           cmdlog[32];
        char            *cmdlogname[32], *temp;
        int                     cmdindex, cmdcount = 0;
+       qboolean        qwplayerupdatereceived;
 
        // LordHavoc: moved demo message writing from before the packet parse to
        // after the packet parse so that CL_Stop_f can be called by cl_autodemo
@@ -3012,10 +3013,6 @@ void CL_ParseServerMessage(void)
        {
                CL_NetworkTimeReceived(realtime); // qw has no clock
 
-               // slightly kill qw player entities each frame
-               for (i = 1;i < cl.maxclients;i++)
-                       cl.entities_active[i] = false;
-
                // kill all qw nails
                cl.qw_num_nails = 0;
 
@@ -3024,6 +3021,8 @@ void CL_ParseServerMessage(void)
 
                cls.servermovesequence = cls.netcon->qw.incoming_sequence;
 
+               qwplayerupdatereceived = false;
+
                while (1)
                {
                        if (msg_badread)
@@ -3286,6 +3285,14 @@ void CL_ParseServerMessage(void)
                                break;
 
                        case qw_svc_playerinfo:
+                               // slightly kill qw player entities now that we know there is
+                               // an update of player entities this frame...
+                               if (!qwplayerupdatereceived)
+                               {
+                                       qwplayerupdatereceived = true;
+                                       for (i = 1;i < cl.maxclients;i++)
+                                               cl.entities_active[i] = false;
+                               }
                                EntityStateQW_ReadPlayerUpdate();
                                break;
 
@@ -3343,24 +3350,13 @@ void CL_ParseServerMessage(void)
                        }
                }
 
-               // fully kill the still slightly dead qw player entities each frame,
-               // but only if a player update was received
-               for (i = 1;i <= cl.maxclients;i++)
-                       if (cl.entities_active[i])
-                               break;
-               if (i <= cl.maxclients)
+               if (qwplayerupdatereceived)
                {
-                       // kill all non-updated entities this frame
+                       // fully kill any player entities that were not updated this frame
                        for (i = 1;i <= cl.maxclients;i++)
                                if (!cl.entities_active[i])
                                        cl.entities[i].state_current.active = false;
                }
-               else
-               {
-                       // no update this frame, restore the cl.entities_active for good measure
-                       for (i = 1;i <= cl.maxclients;i++)
-                               cl.entities_active[i] = cl.entities[i].state_current.active;
-               }
        }
        else
        {
index ab69816..e1e03a5 100644 (file)
@@ -175,6 +175,7 @@ cvar_t snd_streaming = { CVAR_SAVE, "snd_streaming", "1", "enables keeping compr
 cvar_t snd_swapstereo = {CVAR_SAVE, "snd_swapstereo", "0", "swaps left/right speakers for old ISA soundblaster cards"};
 extern cvar_t v_flipped;
 cvar_t snd_channellayout = {0, "snd_channellayout", "0", "channel layout. Can be 0 (auto - snd_restart needed), 1 (standard layout), or 2 (ALSA layout)"};
+cvar_t snd_mutewhenidle = {CVAR_SAVE, "snd_mutewhenidle", "1", "whether to disable sound output when game window is inactive"};
 
 // Local cvars
 static cvar_t nosound = {0, "nosound", "0", "disables sound"};
@@ -707,6 +708,7 @@ void S_Init(void)
        Cvar_RegisterVariable(&snd_speed);
        Cvar_RegisterVariable(&snd_width);
        Cvar_RegisterVariable(&snd_channels);
+       Cvar_RegisterVariable(&snd_mutewhenidle);
 
 // COMMANDLINEOPTION: Sound: -nosound disables sound (including CD audio)
        if (COM_CheckParm("-nosound"))
index 1d6011a..2b06105 100644 (file)
@@ -129,7 +129,6 @@ extern cvar_t snd_streaming;
 #define SND_CHANNELLAYOUT_ALSA         2
 extern cvar_t snd_channellayout;
 
-
 extern int snd_blocked;                // counter. When > 0, we stop submitting sound to the audio device
 
 extern mempool_t *snd_mempool;
diff --git a/sound.h b/sound.h
index b1e0cb0..1889b87 100644 (file)
--- a/sound.h
+++ b/sound.h
@@ -49,6 +49,7 @@ extern cvar_t bgmvolume;
 extern cvar_t volume;
 extern cvar_t snd_initialized;
 extern cvar_t snd_staticvolume;
+extern cvar_t snd_mutewhenidle;
 
 
 // ====================================================================
index e755f19..0bd0351 100644 (file)
--- a/vid_glx.c
+++ b/vid_glx.c
@@ -837,15 +837,21 @@ void Sys_SendKeyEvents(void)
        static qboolean sound_active = true;
 
        // enable/disable sound on focus gain/loss
-       if (!vid_activewindow && sound_active)
+       if (!vid_hidden && (vid_activewindow || !snd_mutewhenidle.integer))
        {
-               S_BlockSound ();
-               sound_active = false;
+               if (!sound_active)
+               {
+                       S_UnblockSound ();
+                       sound_active = true;
+               }
        }
-       else if (vid_activewindow && !sound_active)
+       else
        {
-               S_UnblockSound ();
-               sound_active = true;
+               if (sound_active)
+               {
+                       S_BlockSound ();
+                       sound_active = false;
+               }
        }
 
        HandleEvents();
index 7ac1e4e..b6b0059 100644 (file)
--- a/vid_sdl.c
+++ b/vid_sdl.c
@@ -371,15 +371,21 @@ void Sys_SendKeyEvents( void )
                }
 
        // enable/disable sound on focus gain/loss
-       if (!vid_activewindow && sound_active)
+       if (!vid_hidden && (vid_activewindow || !snd_mutewhenidle.integer))
        {
-               S_BlockSound ();
-               sound_active = false;
+               if (!sound_active)
+               {
+                       S_UnblockSound ();
+                       sound_active = true;
+               }
        }
-       else if (vid_activewindow && !sound_active)
+       else
        {
-               S_UnblockSound ();
-               sound_active = true;
+               if (sound_active)
+               {
+                       S_BlockSound ();
+                       sound_active = false;
+               }
        }
 }
 
index 80c1589..616067f 100644 (file)
--- a/vid_wgl.c
+++ b/vid_wgl.c
@@ -380,16 +380,22 @@ void AppActivate(BOOL fActive, BOOL minimize)
        vid_activewindow = fActive;
        vid_hidden = minimize;
 
-// enable/disable sound on focus gain/loss
-       if (!vid_activewindow && sound_active)
+       // enable/disable sound on focus gain/loss
+       if (!vid_hidden && (vid_activewindow || !snd_mutewhenidle.integer))
        {
-               S_BlockSound ();
-               sound_active = false;
+               if (!sound_active)
+               {
+                       S_UnblockSound ();
+                       sound_active = true;
+               }
        }
-       else if (vid_activewindow && !sound_active)
+       else
        {
-               S_UnblockSound ();
-               sound_active = true;
+               if (sound_active)
+               {
+                       S_BlockSound ();
+                       sound_active = false;
+               }
        }
 
        if (fActive)