Example #1
0
/*
 * ==================
 * SV_Frame
 *
 * ==================
 */
void SV_Frame(int msec)
{
    time_before_game = time_after_game = 0;

    // if server is not active, do nothing
    if (!svs.initialized)
    {
        return;
    }

    svs.realtime += msec;

    // keep the random time dependent
    rand();

    // check timeouts
    SV_CheckTimeouts();

    // get packets from clients
    SV_ReadPackets();

    // move autonomous things around if enough time has passed
    if (!sv_timedemo->value && (svs.realtime < sv.time))
    {
        // never let the time get too far off
        if (sv.time - svs.realtime > 100)
        {
            if (sv_showclamp->value)
            {
                Com_Printf("sv lowclamp\n");
            }
            svs.realtime = sv.time - 100;
        }
        NET_Sleep(sv.time - svs.realtime);
        return;
    }

    // update ping based on the last known frame from all clients
    SV_CalcPings();

    // give the clients some timeslices
    SV_GiveMsec();

    // let everything in the world think and move
    SV_RunGameFrame();

    // send messages back to the clients that had packets read this frame
    SV_SendClientMessages();

    // save the entire world state if recording a serverdemo
    SV_RecordDemoMessage();

    // send a heartbeat to the master if needed
    Master_Heartbeat();

    // clear teleport flags, etc for next frame
    SV_PrepWorldFrame();
}
Example #2
0
void SV_Frame(float msec)
{
	guard(SV_Frame);

	time_before_game = time_after_game = 0;

	// if server is not active, do nothing
	if (!svs.initialized)
		return;

//	SV_DrawTextLeft(va("time: %10d rf: %10.5f d: %10.4f ri:%10d", sv.time, svs.realtimef, msec, svs.realtime));//!!
	svs.realtimef += msec;
	svs.realtime = appFloor(svs.realtimef);

	if (!sv.attractloop)
	{
		// check timeouts
		SV_CheckTimeouts();
	}
	// get packets from clients
	SV_ReadPackets();
	if (sv.state == ss_dead) return;	// server was killed from one of packet (e.g. "rcon killserver")

	int frameTime = 100;	// (sv_fps->integer > 10) ? (1000 / sv_fps->integer) : 100;

	// move autonomous things around if enough time has passed
	if (svs.realtime < sv.time)
	{
		// never let the time get too far off
		if (sv.time - svs.realtime > frameTime)
		{
			if (sv_showclamp->integer)
				appPrintf("sv lowclamp s:%d -- r:%d -> %d\n", sv.time, svs.realtime, sv.time - frameTime);
			svs.realtime  = sv.time - frameTime;
			svs.realtimef = svs.realtime;
		}
		return;
	}

	SV_ClearTexts();

	if (!sv.attractloop)
	{
		// update ping based on the last known frame from all clients
		SV_CalcPings();
		// give the clients some timeslices
		SV_GiveMsec();
	}

	// let everything in the world think and move
	/*-------- SV_RunGameFrame() ---------------*/
	// we always need to bump framenum, even if we
	// don't run the world, otherwise the delta
	// compression can get confused when a client
	// has the "current" frame
	sv.framenum++;
	sv.time += frameTime;	//  = sv.framenum*100; ??

	// don't run if paused
	if (!sv_paused->integer || sv_maxclients->integer > 1)
	{
		time_before_game = appCycles();

		guardGame(ge.RunFrame);
		ge->RunFrame();
		unguardGame;


		// never get more than one tic behind
		if (sv.time < svs.realtime)
		{
			if (sv_showclamp->integer)
				appPrintf("sv highclamp s:%d r:%d -> %d\n", sv.time, svs.realtime, sv.time);
			svs.realtime  = sv.time;
			svs.realtimef = sv.time;
		}
		time_after_game = appCycles();
	}

	// if extended protocol used, recalculate footstep sounds, mdx/mdl/md3 frames etc.
	if (sv_extProtocol->integer && !sv.attractloop)
		SV_PostprocessFrame();

	// send messages back to the clients that had packets read this frame
	SV_SendClientMessages();

	// save the entire world state if recording a serverdemo
	SV_RecordDemoMessage();

	// send a heartbeat to the master if needed
	Master_Heartbeat();

	// clear teleport flags, etc for next frame
	SV_PrepWorldFrame();

	unguard;
}