-// run the world state
- sv.frametime = pr_global_struct->frametime = frametimetotal;
- frametimetotal = 0;
- lastservertime = realtime;
-// pr_global_struct->frametime = host_frametime;
-
-// set the time and clear the general datagram
- SV_ClearDatagram ();
-
-// check for new clients
- SV_CheckForNewClients ();
-
-// read client messages
- SV_RunClients ();
-
-// move things around and think
-// always pause in single player if in console or menus
- if (!sv.paused && (svs.maxclients > 1 || key_dest == key_game) )
- SV_Physics ();
-
-// send all messages to the clients
- SV_SendClientMessages ();
+ }
+ sv.timer += host_realframetime;
+
+ // run the world state
+ // don't allow simulation to run too fast or too slow or logic glitches can occur
+
+ // setup the VM frame
+ SV_VM_Begin();
+ // stop running server frames if the wall time reaches this value
+ aborttime = Sys_DoubleTime() + 0.05;
+ for (framecount = 0;framecount < framelimit && sv.timer > 0;framecount++)
+ {
+ if (sys_ticrate.value <= 0)
+ advancetime = sv.timer;
+ else if (cl.islocalgame && !sv_fixedframeratesingleplayer.integer)
+ advancetime = min(sv.timer, sys_ticrate.value);
+ else
+ advancetime = sys_ticrate.value;
+ advancetime = min(advancetime, 0.1);
+ sv.timer -= advancetime;
+
+ // 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;
+
+
+ // 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 (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);
+
+ // if we fell behind too many frames just don't worry about it
+ if (sv.timer > 0)
+ sv.timer = 0;