diff options
author | Tim Angus <tim@ngus.net> | 2007-09-05 22:05:32 +0000 |
---|---|---|
committer | Tim Angus <tim@ngus.net> | 2007-09-05 22:05:32 +0000 |
commit | c99975c73ae2941751d86d3b8466454c5ad122c0 (patch) | |
tree | b5bb65655fbdbc22201426046092939bcf696abe /src/qcommon/common.c | |
parent | 27ad2c0e19891f7f2454c9eedf76878dc1942ba6 (diff) |
* Merge of ioq3-r1163
+ SDL everywhere
+ New R_LoadImage
+ net_ip.c
+ Window icon
+ GUI based dedicated server support
+ Compile time linked OpenGL
* Remove ui_menuFiles cvar
Diffstat (limited to 'src/qcommon/common.c')
-rw-r--r-- | src/qcommon/common.c | 253 |
1 files changed, 165 insertions, 88 deletions
diff --git a/src/qcommon/common.c b/src/qcommon/common.c index be4eafd1..083a7d18 100644 --- a/src/qcommon/common.c +++ b/src/qcommon/common.c @@ -57,7 +57,6 @@ static fileHandle_t logfile; fileHandle_t com_journalFile; // events are written here fileHandle_t com_journalDataFile; // config files are written here -cvar_t *com_viewlog; cvar_t *com_speeds; cvar_t *com_developer; cvar_t *com_dedicated; @@ -80,9 +79,9 @@ cvar_t *sv_paused; cvar_t *cl_packetdelay; cvar_t *sv_packetdelay; cvar_t *com_cameraMode; -#if defined(_WIN32) && defined(_DEBUG) -cvar_t *com_noErrorInterrupt; -#endif +cvar_t *com_ansiColor; +cvar_t *com_unfocused; +cvar_t *com_minimized; // com_speeds times int time_game; @@ -161,10 +160,9 @@ void QDECL Com_Printf( const char *fmt, ... ) { return; } - // echo to console if we're not a dedicated server - if ( com_dedicated && !com_dedicated->integer ) { - CL_ConsolePrint( msg ); - } +#ifndef DEDICATED + CL_ConsolePrint( msg ); +#endif // echo to dedicated console and early console Sys_Print( msg ); @@ -246,17 +244,6 @@ void QDECL Com_Error( int code, const char *fmt, ... ) { static int errorCount; int currentTime; -#if defined(_WIN32) && defined(_DEBUG) - if ( code != ERR_DISCONNECT && code != ERR_NEED_CD ) { - if (!com_noErrorInterrupt->integer) { - __asm { - int 0x03 - } - } - } -#endif - Cvar_Set("com_errorCode", va("%i", code)); - // when we are running automated scripts, make sure we // know if anything failed if ( com_buildScript && com_buildScript->integer ) { @@ -1127,7 +1114,6 @@ typedef struct memstatic_s { byte mem[2]; } memstatic_t; -// bk001204 - initializer brackets memstatic_t emptystring = { {(sizeof(memblock_t)+2 + 3) & ~3, TAG_STATIC, NULL, NULL, ZONEID}, {'\0', '\0'} }; memstatic_t numberstring[] = { @@ -1386,7 +1372,6 @@ Com_InitZoneMemory */ void Com_InitSmallZoneMemory( void ) { s_smallZoneTotal = 512 * 1024; - // bk001205 - was malloc smallzone = calloc( s_smallZoneTotal, 1 ); if ( !smallzone ) { Com_Error( ERR_FATAL, "Small zone data failed to allocate %1.1f megs", (float)s_smallZoneTotal / (1024*1024) ); @@ -1412,7 +1397,6 @@ void Com_InitZoneMemory( void ) { s_zoneTotal = cv->integer * 1024 * 1024; } - // bk001205 - was malloc mainzone = calloc( s_zoneTotal, 1 ); if ( !mainzone ) { Com_Error( ERR_FATAL, "Zone data failed to allocate %i megs", s_zoneTotal / (1024*1024) ); @@ -1537,8 +1521,6 @@ void Com_InitHunkMemory( void ) { s_hunkTotal = cv->integer * 1024 * 1024; } - - // bk001205 - was malloc s_hunkData = calloc( s_hunkTotal + 31, 1 ); if ( !s_hunkData ) { Com_Error( ERR_FATAL, "Hunk data failed to allocate %i megs", s_hunkTotal / (1024*1024) ); @@ -1902,14 +1884,9 @@ journaled file =================================================================== */ -// bk001129 - here we go again: upped from 64 -// FIXME TTimo blunt upping from 256 to 1024 -// https://zerowing.idsoftware.com/bugzilla/show_bug.cgi?id=5 #define MAX_PUSHED_EVENTS 1024 -// bk001129 - init, also static static int com_pushedEventsHead = 0; static int com_pushedEventsTail = 0; -// bk001129 - static static sysEvent_t com_pushedEvents[MAX_PUSHED_EVENTS]; /* @@ -1943,6 +1920,125 @@ void Com_InitJournaling( void ) { } /* +======================================================================== + +EVENT LOOP + +======================================================================== +*/ + +#define MAX_QUEUED_EVENTS 256 +#define MASK_QUEUED_EVENTS ( MAX_QUEUED_EVENTS - 1 ) + +static sysEvent_t eventQueue[ MAX_QUEUED_EVENTS ]; +static int eventHead = 0; +static int eventTail = 0; +static byte sys_packetReceived[ MAX_MSGLEN ]; + +/* +================ +Com_QueueEvent + +A time of 0 will get the current time +Ptr should either be null, or point to a block of data that can +be freed by the game later. +================ +*/ +void Com_QueueEvent( int time, sysEventType_t type, int value, int value2, int ptrLength, void *ptr ) +{ + sysEvent_t *ev; + + ev = &eventQueue[ eventHead & MASK_QUEUED_EVENTS ]; + + if ( eventHead - eventTail >= MAX_QUEUED_EVENTS ) + { + Com_Printf("Com_QueueEvent: overflow\n"); + // we are discarding an event, but don't leak memory + if ( ev->evPtr ) + { + Z_Free( ev->evPtr ); + } + eventTail++; + } + + eventHead++; + + if ( time == 0 ) + { + time = Sys_Milliseconds(); + } + + ev->evTime = time; + ev->evType = type; + ev->evValue = value; + ev->evValue2 = value2; + ev->evPtrLength = ptrLength; + ev->evPtr = ptr; +} + +/* +================ +Com_GetSystemEvent + +================ +*/ +sysEvent_t Com_GetSystemEvent( void ) +{ + sysEvent_t ev; + char *s; + msg_t netmsg; + netadr_t adr; + + // return if we have data + if ( eventHead > eventTail ) + { + eventTail++; + return eventQueue[ ( eventTail - 1 ) & MASK_QUEUED_EVENTS ]; + } + + // check for console commands + s = Sys_ConsoleInput(); + if ( s ) + { + char *b; + int len; + + len = strlen( s ) + 1; + b = Z_Malloc( len ); + strcpy( b, s ); + Com_QueueEvent( 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 = Z_Malloc( len ); + *buf = adr; + memcpy( buf+1, netmsg.data, netmsg.cursize ); + Com_QueueEvent( 0, SE_PACKET, 0, 0, len, buf ); + } + + // return if we have data + if ( eventHead > eventTail ) + { + eventTail++; + return eventQueue[ ( eventTail - 1 ) & MASK_QUEUED_EVENTS ]; + } + + // create an empty event to return + memset( &ev, 0, sizeof( ev ) ); + ev.evTime = Sys_Milliseconds(); + + return ev; +} + +/* ================= Com_GetRealEvent ================= @@ -1965,7 +2061,7 @@ sysEvent_t Com_GetRealEvent( void ) { } } } else { - ev = Sys_GetEvent(); + ev = Com_GetSystemEvent(); // write the journal value out if needed if ( com_journal->integer == 1 ) { @@ -1991,7 +2087,6 @@ sysEvent_t Com_GetRealEvent( void ) { Com_InitPushEvent ================= */ -// bk001129 - added void Com_InitPushEvent( void ) { // clear the static buffer array // this requires SE_NONE to be accepted as a valid but NOP event @@ -2010,7 +2105,7 @@ Com_PushEvent */ void Com_PushEvent( sysEvent_t *event ) { sysEvent_t *ev; - static int printedWarning = 0; // bk001129 - init, bk001204 - explicit int + static int printedWarning = 0; ev = &com_pushedEvents[ com_pushedEventsHead & (MAX_PUSHED_EVENTS-1) ]; @@ -2111,7 +2206,6 @@ int Com_EventLoop( void ) { switch ( ev.evType ) { default: - // bk001129 - was ev.evTime Com_Error( ERR_FATAL, "Com_EventLoop: bad event type %i", ev.evType ); break; case SE_NONE: @@ -2260,7 +2354,7 @@ static void Com_DetectAltivec(void) static qboolean altivec = qfalse; static qboolean detected = qfalse; if (!detected) { - altivec = Sys_DetectAltivec(); + altivec = ( Sys_GetProcessorFeatures( ) & CF_ALTIVEC ); detected = qtrue; } @@ -2279,13 +2373,17 @@ Com_Init void Com_Init( char *commandLine ) { char *s; - Com_Printf( "%s %s %s\n", SVN_VERSION, PLATFORM_STRING, __DATE__ ); + Com_Printf( "%s %s %s\n", Q3_VERSION, PLATFORM_STRING, __DATE__ ); if ( setjmp (abortframe) ) { Sys_Error ("Error during initialization"); } - // bk001129 - do this before anything else decides to push events + // Clear queues + Com_Memset( &eventQueue[ 0 ], 0, MAX_QUEUED_EVENTS * sizeof( sysEvent_t ) ); + Com_Memset( &sys_packetReceived[ 0 ], 0, MAX_MSGLEN * sizeof( byte ) ); + + // do this before anything else decides to push events Com_InitPushEvent(); Com_InitSmallZoneMemory(); @@ -2355,7 +2453,6 @@ void Com_Init( char *commandLine ) { com_fixedtime = Cvar_Get ("fixedtime", "0", CVAR_CHEAT); com_showtrace = Cvar_Get ("com_showtrace", "0", CVAR_CHEAT); com_dropsim = Cvar_Get ("com_dropsim", "0", CVAR_CHEAT); - com_viewlog = Cvar_Get( "viewlog", "0", CVAR_CHEAT ); com_speeds = Cvar_Get ("com_speeds", "0", 0); com_timedemo = Cvar_Get ("timedemo", "0", CVAR_CHEAT); com_cameraMode = Cvar_Get ("com_cameraMode", "0", CVAR_CHEAT); @@ -2367,16 +2464,10 @@ void Com_Init( char *commandLine ) { com_sv_running = Cvar_Get ("sv_running", "0", CVAR_ROM); com_cl_running = Cvar_Get ("cl_running", "0", CVAR_ROM); com_buildScript = Cvar_Get( "com_buildScript", "0", 0 ); + com_ansiColor = Cvar_Get( "com_ansiColor", "0", CVAR_ARCHIVE ); -#if defined(_WIN32) && defined(_DEBUG) - com_noErrorInterrupt = Cvar_Get( "com_noErrorInterrupt", "0", 0 ); -#endif - - if ( com_dedicated->integer ) { - if ( !com_viewlog->integer ) { - Cvar_Set( "viewlog", "1" ); - } - } + com_unfocused = Cvar_Get( "com_unfocused", "0", CVAR_ROM ); + com_minimized = Cvar_Get( "com_minimized", "0", CVAR_ROM ); if ( com_developer && com_developer->integer ) { Cmd_AddCommand ("error", Com_Error_f); @@ -2396,10 +2487,9 @@ void Com_Init( char *commandLine ) { SV_Init(); com_dedicated->modified = qfalse; - if ( !com_dedicated->integer ) { - CL_Init(); - Sys_ShowConsole( com_viewlog->integer, qfalse ); - } +#ifndef DEDICATED + CL_Init(); +#endif // set com_frameTime so that if a map is started on the // command line it will still be able to count on com_frameTime @@ -2417,7 +2507,7 @@ void Com_Init( char *commandLine ) { // start in full screen ui mode Cvar_Set("r_uiFullScreen", "1"); - CL_StartHunkUsers(); + CL_StartHunkUsers( qfalse ); // make sure single player is off by default Cvar_Set("ui_singlePlayerActive", "0"); @@ -2426,9 +2516,9 @@ void Com_Init( char *commandLine ) { // always set the cvar, but only print the info if it makes sense. Com_DetectAltivec(); - #if idppc +#if idppc Com_Printf ("Altivec support is %s\n", com_altivec->integer ? "enabled" : "disabled"); - #endif +#endif Com_Printf ("--- Common Initialization Complete ---\n"); } @@ -2571,8 +2661,6 @@ void Com_Frame( void ) { return; // an ERR_DROP was thrown } - // bk001204 - init to zero. - // also: might be clobbered by `longjmp' or `vfork' timeBeforeFirstEvents =0; timeBeforeServer =0; timeBeforeEvents =0; @@ -2586,14 +2674,6 @@ void Com_Frame( void ) { // write config file if anything changed Com_WriteConfiguration(); - // if "viewlog" has been modified, show or hide the log console - if ( com_viewlog->modified ) { - if ( !com_dedicated->value ) { - Sys_ShowConsole( com_viewlog->integer, qfalse ); - } - com_viewlog->modified = qfalse; - } - // // main event loop // @@ -2646,42 +2726,39 @@ void Com_Frame( void ) { Cvar_Get( "dedicated", "0", 0 ); com_dedicated->modified = qfalse; if ( !com_dedicated->integer ) { - CL_Init(); - Sys_ShowConsole( com_viewlog->integer, qfalse ); - } else { - CL_Shutdown(); - Sys_ShowConsole( 1, qtrue ); + SV_Shutdown( "dedicated set to 0" ); + CL_FlushMemory(); } } +#ifndef DEDICATED // // 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 (); + // + // 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 (); - } + // + // client side + // + if ( com_speeds->integer ) { + timeBeforeClient = Sys_Milliseconds (); + } - CL_Frame( msec ); + CL_Frame( msec ); - if ( com_speeds->integer ) { - timeAfter = Sys_Milliseconds (); - } + if ( com_speeds->integer ) { + timeAfter = Sys_Milliseconds (); } +#endif // // report timing information |