/* ================ Sys_GetEvent ================ */ sysEvent_t Sys_GetEvent( void ) { sysEvent_t ev; char *s; msg_t netmsg; netadr_t adr; // return if we have data if ( eventHead > eventTail ) { eventTail++; return eventQue[ ( eventTail - 1 ) & MASK_QUED_EVENTS ]; } // pump the message loop // in vga this calls KBD_Update, under X, it calls GetEvent Sys_SendKeyEvents (); // check for console commands s = Sys_ConsoleInput(); if ( s ) { char *b; int len; len = strlen( s ) + 1; b = (char *)malloc( len ); strcpy( b, s ); Sys_QueEvent( 0, SE_CONSOLE, 0, 0, len, b ); } // check for other input devices IN_Frame(); // check for network packets MSG_Init( &netmsg, sys_packetReceived, sizeof( sys_packetReceived ) ); #if 0 if ( Sys_GetPacket ( &adr, &netmsg ) ) { netadr_t *buf; int len; // copy out to a seperate buffer for qeueing len = sizeof( netadr_t ) + netmsg.cursize; buf = malloc( len ); *buf = adr; memcpy( buf+1, netmsg.data, netmsg.cursize ); Sys_QueEvent( 0, SE_PACKET, 0, 0, len, buf ); } #endif // return if we have data if ( eventHead > eventTail ) { eventTail++; return eventQue[ ( eventTail - 1 ) & MASK_QUED_EVENTS ]; } // create an empty event to return memset( &ev, 0, sizeof( ev ) ); ev.evTime = Sys_Milliseconds(); return ev; }
/* ================ Sys_GenerateEvents ================ */ void Sys_GenerateEvents(void) { static int entered = false; char *s; if (entered) { return; } entered = true; // pump the message loop Sys_PumpEvents(); // make sure mouse and joystick are only called once a frame IN_Frame(); // check for console commands s = Sys_ConsoleInput(); if (s) { char *b; int len; len = strlen(s) + 1; b = (char *)Mem_Alloc(len); strcpy(b, s); Sys_QueEvent(0, SE_CONSOLE, 0, 0, len, b); } entered = false; }
/* ================ Sys_GenerateEvents ================ */ void Sys_GenerateEvents() { static int entered = false; char *s; if ( entered ) { return; } entered = true; // pump the message loop Sys_PumpEvents(); // grab or release the mouse cursor if necessary IN_Frame(); // check for console commands s = Sys_ConsoleInput(); if ( s ) { char *b; int len; len = strlen( s ) + 1; b = (char *)Mem_Alloc( len, TAG_EVENTS ); strcpy( b, s ); Sys_QueEvent( SE_CONSOLE, 0, 0, len, b, 0 ); } entered = false; }
/* ================ Sys_GenerateEvents ================ */ void Sys_GenerateEvents() { char *s = Sys_ConsoleInput(); if (s) PushConsoleEvent(s); SDL_PumpEvents(); }
/** * @sa Qcommon_Frame */ void SV_Frame (int now, void *data) { Com_ReadFromPipe(); /* change the gametype even if no server is running (e.g. the first time) */ if (sv_dedicated->integer && sv_gametype->modified) { Com_SetGameType(); sv_gametype->modified = false; } if (sv_dedicated->integer) { const char *s; do { s = Sys_ConsoleInput(); if (s) Cbuf_AddText(va("%s\n", s)); } while (s); } /* if server is not active, do nothing */ if (!svs.initialized) { #ifdef DEDICATED_ONLY Com_Printf("Starting next map from the mapcycle\n"); SV_NextMapcycle(); #endif return; } svs.realtime = now; /* keep the random time dependent */ rand(); SV_CheckSpawnSoldiers(); SV_CheckStartMatch(); SV_CheckTimeouts(); if (!sv_threads->integer) SV_RunGameFrame(); else /* signal the game frame thread to wake up */ SDL_CondSignal(svs.gameFrameCond); SV_LogHandleOutput(); /* next map in the cycle */ if (sv->endgame && sv_maxclients->integer > 1) SV_NextMapcycle(); /* send a heartbeat to the master if needed */ Master_Heartbeat(); SV_PingPlayers(); /* server is empty - so shutdown */ if (svs.abandon && svs.killserver) SV_Shutdown("Server disconnected.", false); }
/** * Add them exactly as if they had been typed at the console */ void Host_GetConsoleCommands(void) { char *cmd; while (1) { cmd = Sys_ConsoleInput(); if (!cmd) break; Cbuf_AddText(cmd); } }
/* ================ Sys_GetEvent ================ */ sysEvent_t Sys_GetEvent( void ) { MSG msg; sysEvent_t ev; char *s; msg_t netmsg; // return if we have data if ( eventHead > eventTail ) { eventTail++; return eventQue[ ( eventTail - 1 ) & MASK_QUED_EVENTS ]; } // pump the message loop while (PeekMessage (&msg, NULL, 0, 0, PM_NOREMOVE)) { if ( !GetMessage (&msg, NULL, 0, 0) ) { Com_Quit_f(); } // save the msg time, because wndprocs don't have access to the timestamp g_wv.sysMsgTime = msg.time; TranslateMessage (&msg); DispatchMessage (&msg); } // check for console commands s = Sys_ConsoleInput(); if ( s ) { char *b; int len; len = strlen( s ) + 1; b = (char *) Z_Malloc( len, TAG_EVENT, qfalse); strcpy( b, s ); Sys_QueEvent( 0, SE_CONSOLE, 0, 0, len, b ); } // check for network packets MSG_Init( &netmsg, sys_packetReceived, sizeof( sys_packetReceived ) ); // return if we have data if ( eventHead > eventTail ) { eventTail++; return eventQue[ ( eventTail - 1 ) & MASK_QUED_EVENTS ]; } // create an empty event to return memset( &ev, 0, sizeof( ev ) ); ev.evTime = timeGetTime(); return ev; }
sysEvent_t Sys_GetEvent( void ) { sysEvent_t ev; char *s; msg_t netmsg; netadr_t adr; // return if we have data if ( eventHead > eventTail ) { eventTail++; return eventQue[ ( eventTail - 1 ) & MASK_QUED_EVENTS ]; } // check for console commands s = Sys_ConsoleInput(); if ( s ) { char *b; int len; len = strlen( s ) + 1; b = (char *)Z_Malloc( len,TAG_EVENT,qfalse ); strcpy( b, s ); Sys_QueEvent( 0, SE_CONSOLE, 0, 0, len, b ); } // check for network packets MSG_Init( &netmsg, sys_packetReceived, sizeof( sys_packetReceived ) ); if ( Sys_GetPacket ( &adr, &netmsg ) ) { netadr_t *buf; int len; // copy out to a seperate buffer for qeueing len = sizeof( netadr_t ) + netmsg.cursize; buf = (netadr_t *)Z_Malloc( len,TAG_EVENT,qfalse ); *buf = adr; memcpy( buf+1, netmsg.data, netmsg.cursize ); Sys_QueEvent( 0, SE_PACKET, 0, 0, len, buf ); } // return if we have data if ( eventHead > eventTail ) { eventTail++; return eventQue[ ( eventTail - 1 ) & MASK_QUED_EVENTS ]; } // create an empty event to return memset( &ev, 0, sizeof( ev ) ); ev.evTime = Sys_Milliseconds(); return ev; }
/* =================== Host_GetConsoleCommands Add them exactly as if they had been typed at the console =================== */ void Host_GetConsoleCommands (void) { const char *cmd; if (!isDedicated) return; // no stdin necessary in graphical mode while (1) { cmd = Sys_ConsoleInput (); if (!cmd) break; Cbuf_AddText (cmd); } }
sysEvent_t Sys_GetEvent( void ) { sysEvent_t ev; char *s; msg_t netmsg; // return if we have data if ( eventHead > eventTail ) { eventTail++; return eventQue[ ( eventTail - 1 ) & MASK_QUED_EVENTS ]; } // pump the message loop // in vga this calls KBD_Update, under X, it calls GetEvent Sys_SendKeyEvents (); // check for console commands s = Sys_ConsoleInput(); if ( s ) { char *b; int len; len = strlen( s ) + 1; b = (char *)Z_Malloc( len,TAG_EVENT,qfalse ); strcpy( b, s ); Sys_QueEvent( 0, SE_CONSOLE, 0, 0, len, b ); } // check for other input devices IN_Frame(); // check for network packets MSG_Init( &netmsg, sys_packetReceived, sizeof( sys_packetReceived ) ); // return if we have data if ( eventHead > eventTail ) { eventTail++; return eventQue[ ( eventTail - 1 ) & MASK_QUED_EVENTS ]; } // create an empty event to return memset( &ev, 0, sizeof( ev ) ); ev.evTime = Sys_Milliseconds(); return ev; }
/** * @sa Qcommon_Frame */ void SV_Frame (int now, void *data) { /* change the gametype even if no server is running (e.g. the first time) */ if (sv_dedicated->integer && sv_gametype->modified) { Com_SetGameType(); sv_gametype->modified = qfalse; } if (sv_dedicated->integer) { const char *s; do { s = Sys_ConsoleInput(); if (s) Cbuf_AddText(va("%s\n", s)); } while (s); } /* if server is not active, do nothing */ if (!svs.initialized) return; svs.realtime = now; /* keep the random time dependent */ rand(); SV_CheckGameStart(); if (!sv_threads->integer) SV_RunGameFrame(); else /* signal the game frame thread to wake up */ SDL_CondSignal(svs.gameFrameCond); /* next map in the cycle */ if (sv->endgame && sv_maxclients->integer > 1) SV_NextMapcycle(); /* send a heartbeat to the master if needed */ Master_Heartbeat(); /* server is empty - so shutdown */ if (svs.abandon && svs.killserver) SV_Shutdown("Server disconnected.", qfalse); }
/* ================= Sys_PumpEvents ================= */ void Sys_PumpEvents( void ) { char *s; msg_t netmsg; netadr_t adr; // pump the message loop Sys_SendKeyEvents(); // check for console commands s = Sys_ConsoleInput(); if ( s ) { char *b; int len; len = strlen( s ) + 1; b = malloc( len ); if ( !b ) { Com_Error( ERR_FATAL, "malloc failed in Sys_PumpEvents" ); } strcpy( b, s ); Sys_QueEvent( 0, SE_CONSOLE, 0, 0, len, b ); } // check for other input devices Sys_Input(); // check for network packets MSG_Init( &netmsg, sys_packetReceived, sizeof( sys_packetReceived ) ); if ( Sys_GetPacket ( &adr, &netmsg ) ) { netadr_t *buf; int len; // copy out to a seperate buffer for qeueing len = sizeof( netadr_t ) + netmsg.cursize; buf = malloc( len ); if ( !buf ) { Com_Error( ERR_FATAL, "malloc failed in Sys_PumpEvents" ); } *buf = adr; memcpy( buf+1, netmsg.data, netmsg.cursize ); Sys_QueEvent( 0, SE_PACKET, 0, 0, len, buf ); } }
/* * 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; }
/** * @sa Qcommon_Frame */ void SV_Frame (int now, void* data) { Com_ReadFromPipe(); /* change the gametype even if no server is running (e.g. the first time) */ if (sv_dedicated->integer && sv_gametype->modified) { Com_SetGameType(); sv_gametype->modified = false; } if (sv_dedicated->integer) { const char* s; do { s = Sys_ConsoleInput(); if (s) Cbuf_AddText("%s\n", s); } while (s); } /* if server is not active, do nothing */ if (!svs.initialized) { #ifdef DEDICATED_ONLY Com_Printf("Starting next map from the mapcycle\n"); SV_NextMapcycle(); #endif return; } svs.realtime = now; /* if time is about to hit the 32nd bit, kick all clients * and clear sv.time, rather * than checking for negative time wraparound everywhere. * 2giga-milliseconds = 23 days, so it won't be too often */ if (svs.realtime > 0x70000000) { SV_Map(true, sv->name, sv->assembly); return; } /* keep the random time dependent */ rand(); SV_CheckSpawnSoldiers(); SV_CheckStartMatch(); SV_CheckTimeouts(); if (!sv_threads->integer) SV_RunGameFrame(); else /* signal the game frame thread to wake up */ SDL_CondSignal(svs.gameFrameCond); SV_LogHandleOutput(); /* next map in the cycle */ if (sv->endgame && sv_maxclients->integer > 1) SV_NextMapcycle(); /* send a heartbeat to the master if needed */ Master_Heartbeat(); SV_PingPlayers(); /* server is empty - so shutdown */ if (svs.abandon && svs.killserver) SV_Shutdown("Server disconnected.", false); }
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); } }
/* ================ Sys_GetEvent ================ */ sysEvent_t Sys_GetEvent( void ) { MSG msg; sysEvent_t ev; char *s; msg_t netmsg; netadr_t adr; // return if we have data if ( eventHead > eventTail ) { eventTail++; return eventQue[ ( eventTail - 1 ) & MASK_QUED_EVENTS ]; } // pump the message loop while (PeekMessage (&msg, NULL, 0, 0, PM_NOREMOVE)) { if ( !GetMessage (&msg, NULL, 0, 0) ) { Com_Quit_f(); } // save the msg time, because wndprocs don't have access to the timestamp g_wv.sysMsgTime = msg.time; TranslateMessage (&msg); DispatchMessage (&msg); } // check for console commands s = Sys_ConsoleInput(); if ( s ) { char *b; int len; len = strlen( s ) + 1; b = (char *)Z_Malloc( len ); Q_strncpyz( b, s, len-1 ); Sys_QueEvent( 0, SE_CONSOLE, 0, 0, len, b ); } // check for network packets MSG_Init( &netmsg, sys_packetReceived, sizeof( sys_packetReceived ) ); if ( Sys_GetPacket ( &adr, &netmsg ) ) { netadr_t *buf; int len; // copy out to a seperate buffer for qeueing // the readcount stepahead is for SOCKS support len = sizeof( netadr_t ) + netmsg.cursize - netmsg.readcount; buf = (netadr_t *)Z_Malloc( len ); *buf = adr; memcpy( buf+1, &netmsg.data[netmsg.readcount], netmsg.cursize - netmsg.readcount ); Sys_QueEvent( 0, SE_PACKET, 0, 0, len, buf ); } // return if we have data if ( eventHead > eventTail ) { eventTail++; return eventQue[ ( eventTail - 1 ) & MASK_QUED_EVENTS ]; } // create an empty event to return memset( &ev, 0, sizeof( ev ) ); ev.evTime = timeGetTime(); return ev; }