void Host_Frame (double time) { if (setjmp (host_abort)) return; // something bad happened, or the server disconnected curtime += time; CL_Frame (time); // will also call SV_Frame }
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 }
/* * Qcommon_Frame */ void Qcommon_Frame( unsigned int realmsec ) { static dynvar_t *frametick = NULL; static quint64 fc = 0; char *s; int time_before = 0, time_between = 0, time_after = 0; static unsigned int gamemsec; if( setjmp( abortframe ) ) return; // an ERR_DROP was thrown if( log_stats->modified ) { log_stats->modified = qfalse; if( log_stats->integer && !log_stats_file ) { if( FS_FOpenFile( "stats.log", &log_stats_file, FS_WRITE ) != -1 ) { FS_Printf( log_stats_file, "entities,dlights,parts,frame time\n" ); } else { log_stats_file = 0; } } else if( log_stats_file ) { FS_FCloseFile( log_stats_file ); log_stats_file = 0; } } if( fixedtime->integer > 0 ) { gamemsec = fixedtime->integer; } else if( timescale->value >= 0 ) { static float extratime = 0.0f; gamemsec = extratime + (float)realmsec * timescale->value; extratime = ( extratime + (float)realmsec * timescale->value ) - (float)gamemsec; } else { gamemsec = realmsec; } if( com_showtrace->integer ) { Com_Printf( "%4i traces %4i brush traces %4i points\n", c_traces, c_brush_traces, c_pointcontents ); c_traces = 0; c_brush_traces = 0; c_pointcontents = 0; } wswcurl_perform(); FS_Frame(); Steam_RunFrame(); if( dedicated->integer ) { do { s = Sys_ConsoleInput(); if( s ) Cbuf_AddText( va( "%s\n", s ) ); } while( s ); Cbuf_Execute(); } // keep the random time dependent rand(); if( host_speeds->integer ) time_before = Sys_Milliseconds(); SV_Frame( realmsec, gamemsec ); if( host_speeds->integer ) time_between = Sys_Milliseconds(); CL_Frame( realmsec, gamemsec ); if( host_speeds->integer ) time_after = Sys_Milliseconds(); if( host_speeds->integer ) { int all, sv, gm, cl, rf; all = time_after - time_before; sv = time_between - time_before; cl = time_after - time_between; gm = time_after_game - time_before_game; rf = time_after_ref - time_before_ref; sv -= gm; cl -= rf; Com_Printf( "all:%3i sv:%3i gm:%3i cl:%3i rf:%3i\n", all, sv, gm, cl, rf ); } MM_Frame( realmsec ); // wsw : aiwa : generic observer pattern to plug in arbitrary functionality if( !frametick ) frametick = Dynvar_Lookup( "frametick" ); Dynvar_CallListeners( frametick, &fc ); ++fc; }
/* ================= Qcommon_Frame ================= */ void Qcommon_Frame(void) { #if USE_CLIENT unsigned time_before, time_event, time_between, time_after; unsigned clientrem; #endif unsigned oldtime, msec; static unsigned remaining; static float frac; if (setjmp(abortframe)) { return; // an ERR_DROP was thrown } #if USE_CLIENT time_before = time_event = time_between = time_after = 0; if (host_speeds->integer) time_before = Sys_Milliseconds(); #endif // sleep on network sockets when running a dedicated server // still do a select(), but don't sleep when running a client! NET_Sleep(remaining); // calculate time spent running last frame and sleeping oldtime = com_eventTime; com_eventTime = Sys_Milliseconds(); if (oldtime > com_eventTime) { oldtime = com_eventTime; } msec = com_eventTime - oldtime; #if USE_CLIENT // spin until msec is non-zero if running a client if (!dedicated->integer && !com_timedemo->integer) { while (msec < 1) { qboolean break_now = CL_ProcessEvents(); com_eventTime = Sys_Milliseconds(); msec = com_eventTime - oldtime; if (break_now) break; } } #endif if (msec > 250) { Com_DPrintf("Hitch warning: %u msec frame time\n", msec); msec = 100; // time was unreasonable, // host OS was hibernated or something } if (fixedtime->integer) { Cvar_ClampInteger(fixedtime, 1, 1000); msec = fixedtime->integer; } else if (timescale->value > 0) { frac += msec * timescale->value; msec = frac; frac -= msec; } // run local time com_localTime += msec; com_framenum++; #if USE_CLIENT if (host_speeds->integer) time_event = Sys_Milliseconds(); #endif // run system console Sys_RunConsole(); NET_UpdateStats(); remaining = SV_Frame(msec); #if USE_CLIENT if (host_speeds->integer) time_between = Sys_Milliseconds(); clientrem = CL_Frame(msec); if (remaining > clientrem) { remaining = clientrem; } if (host_speeds->integer) time_after = Sys_Milliseconds(); if (host_speeds->integer) { int all, ev, sv, gm, cl, rf; all = time_after - time_before; ev = time_event - time_before; sv = time_between - time_event; cl = time_after - time_between; gm = time_after_game - time_before_game; rf = time_after_ref - time_before_ref; sv -= gm; cl -= rf; Com_Printf("all:%3i ev:%3i sv:%3i gm:%3i cl:%3i rf:%3i\n", all, ev, sv, gm, cl, rf); } #endif }
void Qcommon_Frame (int msec) { if (setjmp (abortframe) ) return; // an ERR_DROP was thrown #ifdef GL_QUAKE if(cl_avidemo->integer) { msec = (int)(1000 / cl_avidemo->integer * timescale->value); } else #endif { if (fixedtime->integer) msec = fixedtime->integer; msec = (int)(msec * timescale->value); } if (msec < 1) msec = 1; if (showtrace->integer) { extern int c_traces, c_brush_traces; extern int c_pointcontents; Com_Printf ("%4i traces %4i points\n", c_traces, c_pointcontents); c_traces = 0; c_brush_traces = 0; c_pointcontents = 0; } if (dedicated->integer) { char *s; do { s = Sys_ConsoleInput (); if (s) Cbuf_AddText (va("%s\n",s)); } while (s); Cbuf_Execute (); } if (!host_speeds->integer) { SV_Frame (msec); CL_Frame (msec); } else { unsigned int time_before = 0, time_between = 0, time_after = 0; unsigned int all, sv, gm, cl, rf; time_before = Sys_Milliseconds (); SV_Frame (msec); time_between = Sys_Milliseconds (); CL_Frame (msec); time_after = Sys_Milliseconds (); all = time_after - time_before; sv = time_between - time_before; cl = time_after - time_between; gm = time_after_game - time_before_game; rf = time_after_ref - time_before_ref; sv -= gm; cl -= rf; Com_Printf ("all:%3i sv:%3i gm:%3i cl:%3i rf:%3i\n", all, sv, gm, cl, rf); } }