+extern cvar_t host_framerate;
+extern cvar_t host_speeds;
+
+double CL_Frame (double time)
+{
+ static double clframetime;
+ static double cl_timer = 0;
+ static double time1 = 0, time2 = 0, time3 = 0;
+ static double wait;
+ int pass1, pass2, pass3;
+
+ CL_VM_PreventInformationLeaks();
+
+ // get new key events
+ Key_EventQueue_Unblock();
+ SndSys_SendKeyEvents();
+ Sys_SendKeyEvents();
+
+ if((cl_timer += time) < 0)
+ return cl_timer;
+
+ // limit the frametime steps to no more than 100ms each
+ if (cl_timer > 0.1)
+ cl_timer = 0.1;
+
+ if (cls.state != ca_dedicated && (cl_timer > 0 || cls.timedemo || ((vid_activewindow ? cl_maxfps : cl_maxidlefps).value < 1)))
+ {
+ R_TimeReport("---");
+ Collision_Cache_NewFrame();
+ R_TimeReport("photoncache");
+#ifdef CONFIG_VIDEO_CAPTURE
+ // decide the simulation time
+ if (cls.capturevideo.active)
+ {
+ //***
+ if (cls.capturevideo.realtime)
+ clframetime = cl.realframetime = max(time, 1.0 / cls.capturevideo.framerate);
+ else
+ {
+ clframetime = 1.0 / cls.capturevideo.framerate;
+ cl.realframetime = max(time, clframetime);
+ }
+ }
+ else if (vid_activewindow && cl_maxfps.value >= 1 && !cls.timedemo)
+
+#else
+ if (vid_activewindow && cl_maxfps.value >= 1 && !cls.timedemo)
+#endif
+ {
+ clframetime = cl.realframetime = max(cl_timer, 1.0 / cl_maxfps.value);
+ // when running slow, we need to sleep to keep input responsive
+ wait = bound(0, cl_maxfps_alwayssleep.value * 1000, 100000);
+ if (wait > 0)
+ Sys_Sleep((int)wait);
+ }
+ else if (!vid_activewindow && cl_maxidlefps.value >= 1 && !cls.timedemo)
+ clframetime = cl.realframetime = max(cl_timer, 1.0 / cl_maxidlefps.value);
+ else
+ clframetime = cl.realframetime = cl_timer;
+
+ // apply slowmo scaling
+ clframetime *= cl.movevars_timescale;
+ // scale playback speed of demos by slowmo cvar
+ if (cls.demoplayback)
+ {
+ clframetime *= host_timescale.value;
+ // if demo playback is paused, don't advance time at all
+ if (cls.demopaused)
+ clframetime = 0;
+ }
+ else
+ {
+ // host_framerate overrides all else
+ if (host_framerate.value)
+ clframetime = host_framerate.value;
+
+ if (cl.paused || host.paused)
+ clframetime = 0;
+ }
+
+ if (cls.timedemo)
+ clframetime = cl.realframetime = cl_timer;
+
+ // deduct the frame time from the accumulator
+ cl_timer -= cl.realframetime;
+
+ cl.oldtime = cl.time;
+ cl.time += clframetime;
+
+ // update video
+ if (host_speeds.integer)
+ time1 = Sys_DirtyTime();
+ R_TimeReport("pre-input");
+
+ // Collect input into cmd
+ CL_Input();
+
+ R_TimeReport("input");
+
+ // check for new packets
+ NetConn_ClientFrame();
+
+ // read a new frame from a demo if needed
+ CL_ReadDemoMessage();
+ R_TimeReport("clientnetwork");
+
+ // now that packets have been read, send input to server
+ CL_SendMove();
+ R_TimeReport("sendmove");
+
+ // update client world (interpolate entities, create trails, etc)
+ CL_UpdateWorld();
+ R_TimeReport("lerpworld");
+
+ CL_Video_Frame();
+
+ R_TimeReport("client");
+
+ CL_UpdateScreen();
+ R_TimeReport("render");
+
+ if (host_speeds.integer)
+ time2 = Sys_DirtyTime();
+
+ // update audio
+ if(cl.csqc_usecsqclistener)
+ {
+ S_Update(&cl.csqc_listenermatrix);
+ cl.csqc_usecsqclistener = false;
+ }
+ else
+ S_Update(&r_refdef.view.matrix);
+
+ CDAudio_Update();
+ R_TimeReport("audio");
+
+ // reset gathering of mouse input
+ in_mouse_x = in_mouse_y = 0;
+
+ if (host_speeds.integer)
+ {
+ pass1 = (int)((time1 - time3)*1000000);
+ time3 = Sys_DirtyTime();
+ pass2 = (int)((time2 - time1)*1000000);
+ pass3 = (int)((time3 - time2)*1000000);
+ Con_Printf("%6ius total %6ius server %6ius gfx %6ius snd\n",
+ pass1+pass2+pass3, pass1, pass2, pass3);
+ }
+ }
+ // if there is some time remaining from this frame, reset the timer
+ return cl_timer >= 0 ? 0 : cl_timer;
+}
+