int main(int ac, char *av[]) { double newtime, time, oldtime; int sleep_msec; ParseCommandLine (ac, av); COM_InitArgv (argc, argv); GetConsoleTitle(title, sizeof(title)); Host_Init(argc, argv, DEFAULT_MEM_SIZE); // run one frame immediately for first heartbeat SV_Frame (0.1); // // main loop // oldtime = Sys_DoubleTime () - 0.1; while (1) { sleep_msec = (int)sys_sleep.value; if (sleep_msec > 0) { if (sleep_msec > 13) sleep_msec = 13; Sleep (sleep_msec); } // select on the net socket and stdin // the only reason we have a timeout at all is so that if the last // connected client times out, the message would not otherwise // be printed until the next event. if (!sys_simulation.value) { NET_Sleep((int)sys_select_timeout.value / 1000, false); } // find time passed since last cycle newtime = Sys_DoubleTime (); time = newtime - oldtime; oldtime = newtime; curtime = newtime; SV_Frame (time); } return true; }
/* =============== Host_Frame =============== */ void Host_Frame (double time) { if (setjmp (host_abort)) return; // something bad happened, or the server disconnected curtime += time; if (dedicated) SV_Frame (time); else CL_Frame (time); // will also call SV_Frame }
/* ============= main ============= */ int main (int argc, char *argv[]) { double time1, oldtime, newtime; // Without signal(SIGPIPE, SIG_IGN); MVDSV crashes on *nix when qtvproxy will be disconnect. signal(SIGPIPE, SIG_IGN); COM_InitArgv (argc, argv); SV_System_Init(); // daemonize and so... Host_Init(argc, argv, DEFAULT_MEM_SIZE); // run one frame immediately for first heartbeat SV_Frame (0.1); // main loop oldtime = Sys_DoubleTime () - 0.1; while (1) { // select on the net socket and stdin // the only reason we have a timeout at all is so that if the last // connected client times out, the message would not otherwise // be printed until the next event. stdin_ready = NET_Sleep ((int)sys_select_timeout.value / 1000, do_stdin); // find time passed since last cycle newtime = Sys_DoubleTime (); time1 = newtime - oldtime; oldtime = newtime; curtime = newtime; SV_Frame (time1); // extrasleep is just a way to generate a f****d up connection on purpose if ((int)sys_extrasleep.value) usleep ((unsigned long)sys_extrasleep.value); } return 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 }
/* * 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; }
int main (int argc, char **argv) { quakeparms_t parms; double newtime, time, oldtime; static char cwd[1024]; struct timeval timeout; fd_set fdset; int t; COM_InitArgv (argc, argv); parms.argc = com_argc; parms.argv = com_argv; parms.memsize = 16*1024*1024; if ((t = COM_CheckParm ("-heapsize")) != 0 && t + 1 < com_argc) parms.memsize = atoi (com_argv[t + 1]) * 1024; if ((t = COM_CheckParm ("-mem")) != 0 && t + 1 < com_argc) parms.memsize = atoi (com_argv[t + 1]) * 1024 * 1024; parms.membase = malloc (parms.memsize); if (!parms.membase) Sys_Error("Insufficient memory.\n"); parms.basedir = "."; parms.cachedir = NULL; SV_Init (&parms); // run one frame immediately for first heartbeat SV_Frame (HX_FRAME_TIME); // // main loop // oldtime = Sys_DoubleTime () - HX_FRAME_TIME; while (1) { // select on the net socket and stdin // the only reason we have a timeout at all is so that if the last // connected client times out, the message would not otherwise // be printed until the next event. FD_ZERO(&fdset); FD_SET(net_socket, &fdset); timeout.tv_sec = 0; timeout.tv_usec = 10000; if (select (net_socket+1, &fdset, NULL, NULL, &timeout) == -1) continue; // find time passed since last cycle newtime = Sys_DoubleTime (); time = newtime - oldtime; oldtime = newtime; SV_Frame (time); } return true; }
/* ================= 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 CL_GetAutoUpdate(void) { #ifdef FEATURE_AUTOUPDATE // Don't try and get an update if we haven't checked for one if (!autoupdate.updateChecked) { return; } // Make sure there's a valid update file to request if (strlen(com_updatefiles->string) < 5) { return; } Com_DPrintf("Connecting to auto-update server...\n"); S_StopAllSounds(); // starting to load a map so we get out of full screen ui mode Cvar_Set("r_uiFullScreen", "0"); // toggle on all the download related cvars Cvar_Set("cl_allowDownload", "1"); // general flag Cvar_Set("cl_wwwDownload", "1"); // ftp/http support // clear any previous "server full" type messages clc.serverMessage[0] = 0; if (com_sv_running->integer) { // if running a local server, kill it SV_Shutdown("Server quit\n"); } // make sure a local server is killed Cvar_Set("sv_killserver", "1"); SV_Frame(0); CL_Disconnect(qtrue); Con_Close(); Q_strncpyz(cls.servername, "ET:L Update Server", sizeof(cls.servername)); if (autoupdate.autoupdateServer.type == NA_BAD) { Com_Printf("Bad server address\n"); cls.state = CA_DISCONNECTED; Cvar_Set("ui_connecting", "0"); return; } // Copy auto-update server address to Server connect address memcpy(&clc.serverAddress, &autoupdate.autoupdateServer, sizeof(netadr_t)); Com_DPrintf("%s resolved to %s\n", cls.servername, NET_AdrToString(clc.serverAddress)); cls.state = CA_CONNECTING; cls.keyCatchers = 0; clc.connectTime = -99999; // CL_CheckForResend() will fire immediately clc.connectPacketCount = 0; // server connection string Cvar_Set("cl_currentServerAddress", "ET:L Update Server"); #endif /* FEATURE_AUTOUPDATE */ }
int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { static MSG msg; static double newtime, time, oldtime; register int sleep_msec; static qbool disable_gpf = false; ParseCommandLine(lpCmdLine); COM_InitArgv (argc, argv); // create main window if (!CreateMainWindow(hInstance, nCmdShow)) return 1; if (COM_CheckParm("-noerrormsgbox")) disable_gpf = true; if (COM_CheckParm ("-d")) { isdaemon = disable_gpf = true; //close(0); close(1); close(2); } if (disable_gpf) { DWORD dwMode = SetErrorMode(SEM_NOGPFAULTERRORBOX); SetErrorMode(dwMode | SEM_NOGPFAULTERRORBOX); } Host_Init(argc, argv, DEFAULT_MEM_SIZE); // if stared miminize update notify icon message (with correct port) if (minimized) UpdateNotifyIconMessage(va(SERVER_NAME ":%d", NET_UDPSVPort())); // run one frame immediately for first heartbeat SV_Frame (0.1); // // main loop // oldtime = Sys_DoubleTime () - 0.1; while(1) { // get messeges sent to windows if( PeekMessage( &msg, NULL, 0, 0, PM_NOREMOVE ) ) { if( !GetMessage( &msg, NULL, 0, 0 ) ) break; if(!IsDialogMessage(DlgHwnd, &msg)) { TranslateMessage(&msg); DispatchMessage(&msg); } } CheckIdle(); // server frame sleep_msec = (int)sys_sleep.value; if (sleep_msec > 0) { if (sleep_msec > 13) sleep_msec = 13; Sleep (sleep_msec); } // select on the net socket and stdin // the only reason we have a timeout at all is so that if the last // connected client times out, the message would not otherwise // be printed until the next event. if (!sys_simulation.value) { NET_Sleep((int)sys_select_timeout.value / 1000, false); } // find time passed since last cycle newtime = Sys_DoubleTime (); time = newtime - oldtime; oldtime = newtime; curtime = newtime; SV_Frame (time); } Sys_Exit(msg.wParam); return msg.wParam; }
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); } }
/* ============= main ============= */ int main ( int argc, char *argv[] ) { double time, oldtime, newtime; quakeparms_t parms; fd_set fdset; extern int net_socket; struct timeval timeout; int j; memset (&parms, 0, sizeof(parms)); COM_InitArgv (argc, argv); parms.argc = com_argc; parms.argv = com_argv; parms.memsize = 16*1024*1024; j = COM_CheckParm("-mem"); if (j) parms.memsize = (int) (Q_atof(com_argv[j+1]) * 1024 * 1024); if ((parms.membase = malloc (parms.memsize)) == NULL) Sys_Error("Can't allocate %ld\n", parms.memsize); parms.basedir = "."; SV_Init (&parms); // run one frame immediately for first heartbeat SV_Frame (0.1); // // main loop // oldtime = Sys_DoubleTime () - 0.1; while (1) { // select on the net socket and stdin // the only reason we have a timeout at all is so that if the last // connected client times out, the message would not otherwise // be printed until the next event. FD_ZERO(&fdset); if (do_stdin) FD_SET(0, &fdset); FD_SET(net_socket, &fdset); timeout.tv_sec = 1; timeout.tv_usec = 0; if (select (net_socket+1, &fdset, NULL, NULL, &timeout) == -1) continue; stdin_ready = FD_ISSET(0, &fdset); // find time passed since last cycle newtime = Sys_DoubleTime (); time = newtime - oldtime; oldtime = newtime; SV_Frame (time); // extrasleep is just a way to generate a f****d up connection on purpose if (sys_extrasleep->value) usleep (sys_extrasleep->value); } exit(0); }