Exemple #1
0
void Com_Frame( void ) {
	try 
	{
		int		timeBeforeFirstEvents = 0, timeBeforeServer = 0, timeBeforeEvents = 0, timeBeforeClient = 0, timeAfter = 0;
		int		msec, minMsec;
		static int	lastTime = 0;

		// write config file if anything changed
		Com_WriteConfiguration(); 

		//
		// main event loop
		//
		if ( com_speeds->integer ) {
			timeBeforeFirstEvents = Sys_Milliseconds ();
		}

		// we may want to spin here if things are going too fast
		if ( com_maxfps->integer > 0 ) {
			minMsec = 1000 / com_maxfps->integer;
		} else {
			minMsec = 1;
		}
		do {
			com_frameTime = Com_EventLoop();
			if ( lastTime > com_frameTime ) {
				lastTime = com_frameTime;		// possible on first frame
			}
			msec = com_frameTime - lastTime;
		} while ( msec < minMsec );
		Cbuf_Execute ();

		lastTime = com_frameTime;

		// mess with msec if needed
		com_frameMsec = msec;
		float fractionMsec=0.0f;
		msec = Com_ModifyMsec( msec, fractionMsec);
	
		//
		// server side
		//
		if ( com_speeds->integer ) {
			timeBeforeServer = Sys_Milliseconds ();
		}

		SV_Frame (msec, fractionMsec);


		//
		// client system
		//


	//	if ( !com_dedicated->integer ) 
		{
			//
			// run event loop a second time to get server to client packets
			// without a frame of latency
			//
			if ( com_speeds->integer ) {
				timeBeforeEvents = Sys_Milliseconds ();
			}
			Com_EventLoop();
			Cbuf_Execute ();


			//
			// client side
			//
			if ( com_speeds->integer ) {
				timeBeforeClient = Sys_Milliseconds ();
			}

			CL_Frame (msec, fractionMsec);

			if ( com_speeds->integer ) {
				timeAfter = Sys_Milliseconds ();
			}
		}


		//
		// report timing information
		//
		if ( com_speeds->integer ) {
			int			all, sv, ev, cl;

			all = timeAfter - timeBeforeServer;
			sv = timeBeforeEvents - timeBeforeServer;
			ev = timeBeforeServer - timeBeforeFirstEvents + timeBeforeClient - timeBeforeEvents;
			cl = timeAfter - timeBeforeClient;
			sv -= time_game;
			cl -= time_frontend + time_backend;

			Com_Printf("fr:%i all:%3i sv:%3i ev:%3i cl:%3i gm:%3i tr:%3i pvs:%3i rf:%3i bk:%3i\n", 
						com_frameNumber, all, sv, ev, cl, time_game, timeInTrace, timeInPVSCheck, time_frontend, time_backend);

			// speedslog
			if ( com_speedslog && com_speedslog->integer )
			{
				if(!speedslog)
				{
					speedslog = FS_FOpenFileWrite("speeds.log");
					FS_Write("data={\n", strlen("data={\n"), speedslog);
					bComma=false;
					if ( com_speedslog->integer > 1 ) 
					{
						// force it to not buffer so we get valid
						// data even if we are crashing
						FS_ForceFlush(logfile);
					}
				}
				if (speedslog)
				{
					char		msg[MAXPRINTMSG];

					if(bComma)
					{
						FS_Write(",\n", strlen(",\n"), speedslog);
						bComma=false;
					}
					FS_Write("{", strlen("{"), speedslog);
					Com_sprintf(msg,sizeof(msg),
								"%8.4f,%8.4f,%8.4f,%8.4f,%8.4f,%8.4f,",corg[0],corg[1],corg[2],cangles[0],cangles[1],cangles[2]);
					FS_Write(msg, strlen(msg), speedslog);
					Com_sprintf(msg,sizeof(msg),
						"%i,%3i,%3i,%3i,%3i,%3i,%3i,%3i,%3i,%3i}", 
						com_frameNumber, all, sv, ev, cl, time_game, timeInTrace, timeInPVSCheck, time_frontend, time_backend);
					FS_Write(msg, strlen(msg), speedslog);
					bComma=true;
				}
			}

			timeInTrace = timeInPVSCheck = 0;
		}

		//
		// trace optimization tracking
		//
		if ( com_showtrace->integer ) {
			extern	int c_traces, c_brush_traces, c_patch_traces;
			extern	int	c_pointcontents;

			/*
			Com_Printf( "%4i non-sv_traces, %4i sv_traces, %4i ms, ave %4.2f ms\n", c_traces - numTraces, numTraces, timeInTrace, (float)timeInTrace/(float)numTraces );
			timeInTrace = numTraces = 0;
			c_traces = 0;
			*/
		
			Com_Printf ("%4i traces  (%ib %ip) %4i points\n", c_traces,
				c_brush_traces, c_patch_traces, c_pointcontents);
			c_traces = 0;
			c_brush_traces = 0;
			c_patch_traces = 0;
			c_pointcontents = 0;
		}

		if ( com_affinity->modified )
		{
			com_affinity->modified = qfalse;
			Sys_SetProcessorAffinity();
		}

		com_frameNumber++;
	}
	catch ( int code )
	{
		Com_CatchError (code);
		Com_Printf ("%s\n", Com_ErrorString (code));
		return;
	}

#ifdef G2_PERFORMANCE_ANALYSIS
	if (com_G2Report && com_G2Report->integer)
	{
		re.G2Time_ReportTimers();
	}

	re.G2Time_ResetTimers();
#endif
}
Exemple #2
0
static void CLQW_ParseServerData( QMsg& message ) {
	common->DPrintf( "Serverdata packet received.\n" );

	Cbuf_Execute();			// make sure any stuffed commands are done

	R_Shutdown( false );
	CL_InitRenderer();

	//
	// wipe the clientActive_t struct
	//
	CL_ClearState();

	// parse protocol version number
	// allow 2.2 and 2.29 demos to play
	int protover = message.ReadLong();
	if ( protover != QWPROTOCOL_VERSION &&
		 !( clc.demoplaying && ( protover == 26 || protover == 27 || protover == 28 ) ) ) {
		common->Error( "Server returned version %i, not %i\nYou probably need to upgrade.\nCheck http://www.quakeworld.net/", protover, QWPROTOCOL_VERSION );
	}

	cl.servercount = message.ReadLong();

	// game directory
	const char* str = message.ReadString2();

	bool cflag = false;
	if ( String::ICmp( fsqhw_gamedirfile, str ) ) {
		// save current config
		Com_WriteConfiguration();
		cflag = true;
	}

	FS_SetGamedirQHW( str );

	//ZOID--run the autoexec.cfg in the gamedir
	//if it exists
	if ( cflag ) {
		if ( FS_FileExists( "config.cfg" ) ) {
			Cbuf_AddText( "cl_warncmd 0\n" );
			Cbuf_AddText( "exec config.cfg\n" );
			Cbuf_AddText( "exec frontend.cfg\n" );
			Cbuf_AddText( "cl_warncmd 1\n" );
		}
	}

	// parse player slot, high bit means spectator
	cl.playernum = message.ReadByte();
	if ( cl.playernum & 128 ) {
		cl.qh_spectator = true;
		cl.playernum &= ~128;
	}
	cl.viewentity = cl.playernum + 1;

	// get the full level name
	str = const_cast<char*>( message.ReadString2() );
	String::NCpy( cl.qh_levelname, str, sizeof ( cl.qh_levelname ) - 1 );

	// get the movevars
	movevars.gravity            = message.ReadFloat();
	movevars.stopspeed          = message.ReadFloat();
	movevars.maxspeed           = message.ReadFloat();
	movevars.spectatormaxspeed  = message.ReadFloat();
	movevars.accelerate         = message.ReadFloat();
	movevars.airaccelerate      = message.ReadFloat();
	movevars.wateraccelerate    = message.ReadFloat();
	movevars.friction           = message.ReadFloat();
	movevars.waterfriction      = message.ReadFloat();
	movevars.entgravity         = message.ReadFloat();

	// seperate the printfs so the server message can have a color
	common->Printf( "\n\n\35\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\37\n\n" );
	common->Printf( S_COLOR_ORANGE "%s" S_COLOR_WHITE "\n", str );

	// ask for the sound list next
	Com_Memset( cl.qh_sound_name, 0, sizeof ( cl.qh_sound_name ) );
	CL_AddReliableCommand( va( "soundlist %i %i", cl.servercount, 0 ) );

	// now waiting for downloads, etc
	cls.state = CA_LOADING;
}