- // execute one or more server frames, with an upper limit on how much
- // execution time to spend on server frames to avoid freezing the game if
- // the server is overloaded, this execution time limit means the game will
- // slow down if the server is taking too long.
- int framecount, framelimit = 1;
- double advancetime, aborttime = 0;
-
- // receive server packets now, which might contain rcon commands, which
- // may change level or other such things we don't want to have happen in
- // the middle of Host_Frame
- NetConn_ServerFrame();
-
- // check for commands typed to the host
- Host_GetConsoleCommands();
-
- // run the world state
- // don't allow simulation to run too fast or too slow or logic glitches can occur
-
- // stop running server frames if the wall time reaches this value
- if (sys_ticrate.value <= 0 || (cl.islocalgame && !sv_fixedframeratesingleplayer.integer))
- advancetime = sv_timer;
- else
- {
- advancetime = sys_ticrate.value;
- // listen servers can run multiple server frames per client frame
- if (cls.state == ca_connected)
- {
- framelimit = 10;
- aborttime = Sys_DoubleTime() + 0.1;
- }
- }
- advancetime = min(advancetime, 0.1);
-
- // only advance time if not paused
- // the game also pauses in singleplayer when menu or console is used
- sv.frametime = advancetime * slowmo.value;
- if (host_framerate.value)
- sv.frametime = host_framerate.value;
- if (sv.paused || (cl.islocalgame && (key_dest != key_game || key_consoleactive)))
- sv.frametime = 0;
-
- // setup the VM frame
- SV_VM_Begin();
-
- for (framecount = 0;framecount < framelimit && sv_timer > 0;framecount++)
- {
- sv_timer -= advancetime;
-
- // move things around and think unless paused
- if (sv.frametime)
- SV_Physics();
-
- // send all messages to the clients
- SV_SendClientMessages();
-
- // clear the general datagram
- SV_ClearDatagram();
-
- // if this server frame took too long, break out of the loop
- if (framelimit > 1 && Sys_DoubleTime() >= aborttime)
- break;
- }
-
- // end the server VM frame
- SV_VM_End();
-
- // send an heartbeat if enough time has passed since the last one
- NetConn_Heartbeat(0);
- }
- }
-
- //-------------------
- //
- // client operations
- //
- //-------------------
-
- if (cl_timer > 0 || cls.timedemo)
- {
- if (cls.state == ca_dedicated)
- {
- // if there is no client, run client timing at 10fps
- cl_timer -= 0.1;
- if (host_speeds.integer)
- time1 = time2 = Sys_DoubleTime();
- }
- else
- {
- double frametime;
- frametime = cl.realframetime = min(cl_timer, 1);
-
- // decide the simulation time
- if (!cls.timedemo)
- {
- if (cls.capturevideo_active && !cls.capturevideo_soundfile)
- {
- frametime = 1.0 / cls.capturevideo_framerate;
- cl.realframetime = max(cl.realframetime, frametime);
- }
- else if (vid_activewindow)
- frametime = cl.realframetime = max(cl.realframetime, 1.0 / cl_maxfps.value);
- else
- frametime = cl.realframetime = 0.1;
-
- // deduct the frame time from the accumulator
- cl_timer -= cl.realframetime;
-
- // apply slowmo scaling
- frametime *= slowmo.value;
-
- // host_framerate overrides all else
- if (host_framerate.value)
- frametime = host_framerate.value;
- }
-
- cl.oldtime = cl.time;
- cl.time += frametime;
-
- // Collect input into cmd
- CL_Move();
-
- NetConn_ClientFrame();
-
- if (cls.state == ca_connected)
- {
- CL_ReadFromServer();
- // if running the server remotely, send intentions now after
- // the incoming messages have been read
- //if (!cl.islocalgame)
- // CL_SendCmd();
- }
-
- // update video
- if (host_speeds.integer)
- time1 = Sys_DoubleTime();
-
- //ui_update();
-
- CL_VideoFrame();
-
- CL_UpdateScreen();
-
- if (host_speeds.integer)
- time2 = Sys_DoubleTime();
-
- // update audio
- if(csqc_usecsqclistener)
- {
- S_Update(&csqc_listenermatrix);
- csqc_usecsqclistener = false;
- }
- else
- S_Update(&r_refdef.viewentitymatrix);
-
- CDAudio_Update();
- }
-
- if (host_speeds.integer)
- {
- int pass1, pass2, pass3;
- pass1 = (int)((time1 - time3)*1000000);
- time3 = Sys_DoubleTime();
- 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);