/* ======================== idSoundVoice_OpenAL::Create ======================== */ void idSoundVoice_OpenAL::Create( const idSoundSample* leadinSample_, const idSoundSample* loopingSample_ ) { if( IsPlaying() ) { // This should never hit Stop(); return; } triggered = true; leadinSample = ( idSoundSample_OpenAL* )leadinSample_; loopingSample = ( idSoundSample_OpenAL* )loopingSample_; if( alIsSource( openalSource ) && CompatibleFormat( leadinSample ) ) { sampleRate = leadinSample->format.basic.samplesPerSec; } else { DestroyInternal(); formatTag = leadinSample->format.basic.formatTag; numChannels = leadinSample->format.basic.numChannels; sampleRate = leadinSample->format.basic.samplesPerSec; //soundSystemLocal.hardware.pXAudio2->CreateSourceVoice( &pSourceVoice, ( const WAVEFORMATEX* )&leadinSample->format, XAUDIO2_VOICE_USEFILTER, 4.0f, &streamContext ); CheckALErrors(); alGenSources( 1, &openalSource ); if( CheckALErrors() != AL_NO_ERROR ) //if( pSourceVoice == NULL ) { // If this hits, then we are most likely passing an invalid sample format, which should have been caught by the loader (and the sample defaulted) return; } alSourcef( openalSource, AL_ROLLOFF_FACTOR, 0.0f ); //if( ( loopingSample == NULL && leadinSample->openalBuffer != 0 ) || ( loopingSample != NULL && soundShader->entries[0]->hardwareBuffer ) ) if( leadinSample->openalBuffer != 0 ) { alSourcei( openalSource, AL_BUFFER, 0 ); // handle uncompressed (non streaming) single shot and looping sounds /* if( triggered ) { alSourcei( openalSource, AL_BUFFER, looping ? chan->soundShader->entries[0]->openalBuffer : leadinSample->openalBuffer ); } */ } else { //if( triggered ) // handle streaming sounds (decode on the fly) both single shot AND looping alSourcei( openalSource, AL_BUFFER, 0 ); alDeleteBuffers( 3, &lastopenalStreamingBuffer[0] ); lastopenalStreamingBuffer[0] = openalStreamingBuffer[0]; lastopenalStreamingBuffer[1] = openalStreamingBuffer[1]; lastopenalStreamingBuffer[2] = openalStreamingBuffer[2]; alGenBuffers( 3, &openalStreamingBuffer[0] ); /* if( soundSystemLocal.alEAXSetBufferMode ) { soundSystemLocal.alEAXSetBufferMode( 3, &chan->openalStreamingBuffer[0], alGetEnumValue( ID_ALCHAR "AL_STORAGE_ACCESSIBLE" ) ); } */ openalStreamingBuffer[0]; openalStreamingBuffer[1]; openalStreamingBuffer[2]; } if( s_debugHardware.GetBool() ) { if( loopingSample == NULL || loopingSample == leadinSample ) { idLib::Printf( "%dms: %i created for %s\n", Sys_Milliseconds(), openalSource, leadinSample ? leadinSample->GetName() : "<null>" ); } else { idLib::Printf( "%dms: %i created for %s and %s\n", Sys_Milliseconds(), openalSource, leadinSample ? leadinSample->GetName() : "<null>", loopingSample ? loopingSample->GetName() : "<null>" ); } } } sourceVoiceRate = sampleRate; //pSourceVoice->SetSourceSampleRate( sampleRate ); //pSourceVoice->SetVolume( 0.0f ); alSourcei( openalSource, AL_SOURCE_RELATIVE, AL_TRUE ); alSource3f( openalSource, AL_POSITION, 0.0f, 0.0f, 0.0f ); // RB: FIXME 0.0f ? alSourcef( openalSource, AL_GAIN, 1.0f ); //OnBufferStart( leadinSample, 0 ); }
/* ================= Qcommon_Init ================= */ void Qcommon_Init(int argc, char **argv) { if (setjmp(abortframe)) Sys_Error("Error during initialization: %s", com_errorMsg); com_argc = argc; com_argv = argv; Com_SetLastError(NULL); X86_SetFPCW(); // prepare enough of the subsystems to handle // cvar and command buffer management Z_Init(); MSG_Init(); Cbuf_Init(); Cmd_Init(); Cvar_Init(); Key_Init(); Prompt_Init(); Con_Init(); // // init commands and vars // z_perturb = Cvar_Get("z_perturb", "0", 0); #if USE_CLIENT host_speeds = Cvar_Get("host_speeds", "0", 0); #endif #ifdef _DEBUG developer = Cvar_Get("developer", "0", 0); #endif timescale = Cvar_Get("timescale", "1", CVAR_CHEAT); fixedtime = Cvar_Get("fixedtime", "0", CVAR_CHEAT); logfile_enable = Cvar_Get("logfile", "0", 0); logfile_flush = Cvar_Get("logfile_flush", "0", 0); logfile_name = Cvar_Get("logfile_name", "console", 0); logfile_prefix = Cvar_Get("logfile_prefix", "[%Y-%m-%d %H:%M] ", 0); #if USE_CLIENT dedicated = Cvar_Get("dedicated", "0", CVAR_NOSET); cl_running = Cvar_Get("cl_running", "0", CVAR_ROM); cl_paused = Cvar_Get("cl_paused", "0", CVAR_ROM); #else dedicated = Cvar_Get("dedicated", "1", CVAR_ROM); #endif sv_running = Cvar_Get("sv_running", "0", CVAR_ROM); sv_paused = Cvar_Get("sv_paused", "0", CVAR_ROM); com_timedemo = Cvar_Get("timedemo", "0", CVAR_CHEAT); com_date_format = Cvar_Get("com_date_format", "%Y-%m-%d", 0); #ifdef _WIN32 com_time_format = Cvar_Get("com_time_format", "%H.%M", 0); #else com_time_format = Cvar_Get("com_time_format", "%H:%M", 0); #endif #ifdef _DEBUG com_debug_break = Cvar_Get("com_debug_break", "0", 0); #endif com_fatal_error = Cvar_Get("com_fatal_error", "0", 0); com_version = Cvar_Get("version", com_version_string, CVAR_SERVERINFO | CVAR_ROM); allow_download = Cvar_Get("allow_download", COM_DEDICATED ? "0" : "1", CVAR_ARCHIVE); allow_download_players = Cvar_Get("allow_download_players", "1", CVAR_ARCHIVE); allow_download_models = Cvar_Get("allow_download_models", "1", CVAR_ARCHIVE); allow_download_sounds = Cvar_Get("allow_download_sounds", "1", CVAR_ARCHIVE); allow_download_maps = Cvar_Get("allow_download_maps", "1", CVAR_ARCHIVE); allow_download_textures = Cvar_Get("allow_download_textures", "1", CVAR_ARCHIVE); allow_download_pics = Cvar_Get("allow_download_pics", "1", CVAR_ARCHIVE); allow_download_others = Cvar_Get("allow_download_others", "0", 0); rcon_password = Cvar_Get("rcon_password", "", CVAR_PRIVATE); Cmd_AddCommand("z_stats", Z_Stats_f); //Cmd_AddCommand("setenv", Com_Setenv_f); Cmd_AddMacro("com_date", Com_Date_m); Cmd_AddMacro("com_time", Com_Time_m); Cmd_AddMacro("com_uptime", Com_Uptime_m); Cmd_AddMacro("com_uptime_long", Com_UptimeLong_m); Cmd_AddMacro("random", Com_Random_m); Cmd_AddMacro("com_maplist", Com_MapList_m); // add any system-wide configuration files Sys_AddDefaultConfig(); // we need to add the early commands twice, because // a basedir or cddir needs to be set before execing // config files, but we want other parms to override // the settings of the config files Com_AddEarlyCommands(qfalse); Sys_Init(); Sys_RunConsole(); FS_Init(); Sys_RunConsole(); // no longer allow CVAR_NOSET modifications com_initialized = qtrue; // after FS is initialized, open logfile logfile_enable->changed = logfile_enable_changed; logfile_flush->changed = logfile_param_changed; logfile_name->changed = logfile_param_changed; logfile_enable_changed(logfile_enable); // execute configs: default.cfg may come from the packfile, but config.cfg // and autoexec.cfg must be real files within the game directory Com_AddConfigFile(COM_DEFAULT_CFG, 0); Com_AddConfigFile(COM_CONFIG_CFG, FS_TYPE_REAL | FS_PATH_GAME); Com_AddConfigFile(COM_AUTOEXEC_CFG, FS_TYPE_REAL | FS_PATH_GAME); Com_AddConfigFile(COM_POSTEXEC_CFG, FS_TYPE_REAL); Com_AddEarlyCommands(qtrue); Cmd_AddCommand("lasterror", Com_LastError_f); Cmd_AddCommand("quit", Com_Quit_f); #if !USE_CLIENT Cmd_AddCommand("recycle", Com_Recycle_f); #endif srand(Sys_Milliseconds()); Netchan_Init(); NET_Init(); BSP_Init(); CM_Init(); SV_Init(); CL_Init(); TST_Init(); Sys_RunConsole(); // add + commands from command line if (!Com_AddLateCommands()) { // if the user didn't give any commands, run default action char *cmd = COM_DEDICATED ? "dedicated_start" : "client_start"; if ((cmd = Cmd_AliasCommand(cmd)) != NULL) { Cbuf_AddText(&cmd_buffer, cmd); Cbuf_Execute(&cmd_buffer); } } else { // the user asked for something explicit // so drop the loading plaque SCR_EndLoadingPlaque(); } // even not given a starting map, dedicated server starts // listening for rcon commands (create socket after all configs // are executed to make sure port number is properly set) if (COM_DEDICATED) { NET_Config(NET_SERVER); } Com_AddConfigFile(COM_POSTINIT_CFG, FS_TYPE_REAL); Com_Printf("====== " PRODUCT " initialized ======\n\n"); Com_LPrintf(PRINT_NOTICE, APPLICATION " " VERSION ", " __DATE__ "\n"); Com_Printf("http://skuller.net/q2pro/\n\n"); time(&com_startTime); com_eventTime = Sys_Milliseconds(); }
/* ================= idSessionLocal::DownloadProgressBox ================= */ void idSessionLocal::DownloadProgressBox( backgroundDownload_t *bgl, const char *title, int progress_start, int progress_end ) { int dlnow = 0, dltotal = 0; int startTime = Sys_Milliseconds(); int lapsed; idStr sNow, sTotal, sBW, sETA, sMsg; if ( !BoxDialogSanityCheck() ) { return; } guiMsg->SetStateString( "visible_msgbox", "1" ); guiMsg->SetStateString( "visible_waitbox", "0" ); guiMsg->SetStateString( "visible_entry", "0" ); guiMsg->SetStateString( "visible_cdkey", "0" ); guiMsg->SetStateString( "mid", "Cancel" ); guiMsg->SetStateString( "visible_mid", "1" ); guiMsg->SetStateString( "visible_left", "0" ); guiMsg->SetStateString( "visible_right", "0" ); guiMsg->SetStateString( "title", title ); guiMsg->SetStateString( "message", "Connecting.." ); guiMsgRestore = guiActive; guiActive = guiMsg; msgRunning = true; while ( 1 ) { while ( msgRunning ) { common->GUIFrame( true, false ); if ( bgl->completed ) { guiActive = guiMsgRestore; guiMsgRestore = NULL; return; } else if ( bgl->url.dltotal != dltotal || bgl->url.dlnow != dlnow ) { dltotal = bgl->url.dltotal; dlnow = bgl->url.dlnow; lapsed = Sys_Milliseconds() - startTime; sNow.BestUnit( "%.2f", dlnow, MEASURE_SIZE ); if ( lapsed > 2000 ) { sBW.BestUnit( "%.1f", ( 1000.0f * dlnow ) / lapsed, MEASURE_BANDWIDTH ); } else { sBW = "-- KB/s"; } if ( dltotal ) { sTotal.BestUnit( "%.2f", dltotal, MEASURE_SIZE ); if ( lapsed < 2000 ) { sprintf( sMsg, "%s / %s", sNow.c_str(), sTotal.c_str() ); } else { sprintf( sETA, "%.0f sec", ( (float)dltotal / (float)dlnow - 1.0f ) * lapsed / 1000 ); sprintf( sMsg, "%s / %s ( %s - %s )", sNow.c_str(), sTotal.c_str(), sBW.c_str(), sETA.c_str() ); } } else { if ( lapsed < 2000 ) { sMsg = sNow; } else { sprintf( sMsg, "%s - %s", sNow.c_str(), sBW.c_str() ); } } if ( dltotal ) { guiMsg->SetStateString( "progress", va( "%d", progress_start + dlnow * ( progress_end - progress_start ) / dltotal ) ); } else { guiMsg->SetStateString( "progress", "0" ); } guiMsg->SetStateString( "message", sMsg.c_str() ); } } // abort was used - tell the downloader and wait till final stop bgl->url.status = DL_ABORTING; guiMsg->SetStateString( "title", "Aborting.." ); guiMsg->SetStateString( "visible_mid", "0" ); // continue looping guiMsgRestore = guiActive; guiActive = guiMsg; msgRunning = true; } }
/* =============== IN_ProcessEvents =============== */ static void IN_ProcessEvents( void ) { SDL_Event e; fakeAscii_t key = A_NULL; const char *character = NULL; static fakeAscii_t lastKeyDown = A_NULL; if( !SDL_WasInit( SDL_INIT_VIDEO ) ) return; while( SDL_PollEvent( &e ) ) { switch( e.type ) { case SDL_KEYDOWN: character = IN_TranslateSDLToJKKey( &e.key.keysym, &key, qtrue ); if( key != A_NULL ) Sys_QueEvent( 0, SE_KEY, key, qtrue, 0, NULL ); if( character ) Sys_QueEvent( 0, SE_CHAR, *character, qfalse, 0, NULL ); lastKeyDown = key; break; case SDL_KEYUP: IN_TranslateSDLToJKKey( &e.key.keysym, &key, qfalse ); if( key != A_NULL ) Sys_QueEvent( 0, SE_KEY, key, qfalse, 0, NULL ); lastKeyDown = A_NULL; break; case SDL_TEXTINPUT: if( lastKeyDown != A_CONSOLE ) { char *c = e.text.text; // Quick and dirty UTF-8 to UTF-32 conversion while( *c ) { int utf32 = 0; if( ( *c & 0x80 ) == 0 ) utf32 = *c++; else if( ( *c & 0xE0 ) == 0xC0 ) // 110x xxxx { utf32 |= ( *c++ & 0x1F ) << 6; utf32 |= ( *c++ & 0x3F ); } else if( ( *c & 0xF0 ) == 0xE0 ) // 1110 xxxx { utf32 |= ( *c++ & 0x0F ) << 12; utf32 |= ( *c++ & 0x3F ) << 6; utf32 |= ( *c++ & 0x3F ); } else if( ( *c & 0xF8 ) == 0xF0 ) // 1111 0xxx { utf32 |= ( *c++ & 0x07 ) << 18; utf32 |= ( *c++ & 0x3F ) << 6; utf32 |= ( *c++ & 0x3F ) << 6; utf32 |= ( *c++ & 0x3F ); } else { Com_DPrintf( "Unrecognised UTF-8 lead byte: 0x%x\n", (unsigned int)*c ); c++; } if( utf32 != 0 ) { if( IN_IsConsoleKey( A_NULL, utf32 ) ) { Sys_QueEvent( 0, SE_KEY, A_CONSOLE, qtrue, 0, NULL ); Sys_QueEvent( 0, SE_KEY, A_CONSOLE, qfalse, 0, NULL ); } else Sys_QueEvent( 0, SE_CHAR, utf32, 0, 0, NULL ); } } } break; case SDL_MOUSEMOTION: if( mouseActive ) Sys_QueEvent( 0, SE_MOUSE, e.motion.xrel, e.motion.yrel, 0, NULL ); break; case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONUP: { unsigned short b; switch( e.button.button ) { case SDL_BUTTON_LEFT: b = A_MOUSE1; break; case SDL_BUTTON_MIDDLE: b = A_MOUSE3; break; case SDL_BUTTON_RIGHT: b = A_MOUSE2; break; case SDL_BUTTON_X1: b = A_MOUSE4; break; case SDL_BUTTON_X2: b = A_MOUSE5; break; default: b = A_AUX0 + ( e.button.button - 6 ) % 32; break; } Sys_QueEvent( 0, SE_KEY, b, ( e.type == SDL_MOUSEBUTTONDOWN ? qtrue : qfalse ), 0, NULL ); } break; case SDL_MOUSEWHEEL: if( e.wheel.y > 0 ) Sys_QueEvent( 0, SE_KEY, A_MWHEELUP, qtrue, 0, NULL ); else Sys_QueEvent( 0, SE_KEY, A_MWHEELDOWN, qtrue, 0, NULL ); break; case SDL_QUIT: Cbuf_ExecuteText(EXEC_NOW, "quit Closed window\n"); break; case SDL_WINDOWEVENT: switch( e.window.event ) { case SDL_WINDOWEVENT_RESIZED: { char width[32], height[32]; if (!Cvar_VariableIntegerValue("r_restartOnResize")) break; Com_sprintf( width, sizeof( width ), "%d", e.window.data1 ); Com_sprintf( height, sizeof( height ), "%d", e.window.data2 ); Cvar_Set( "r_customwidth", width ); Cvar_Set( "r_customheight", height ); Cvar_Set( "r_mode", "-1" ); // Wait until user stops dragging for 1 second, so // we aren't constantly recreating the GL context while // he tries to drag... vidRestartTime = Sys_Milliseconds( ) + Cvar_VariableIntegerValue("r_resizeDelay"); } break; case SDL_WINDOWEVENT_MINIMIZED: Cvar_SetValue( "com_minimized", 1 ); break; case SDL_WINDOWEVENT_MAXIMIZED: Cvar_SetValue( "com_minimized", 0 ); break; case SDL_WINDOWEVENT_FOCUS_LOST: Cvar_SetValue( "com_unfocused", 1 ); break; case SDL_WINDOWEVENT_FOCUS_GAINED: Cvar_SetValue( "com_unfocused", 0 ); break; } break; default: break; } } }
/* ==================== CL_UISystemCalls The ui module is making a system call ==================== */ intptr_t CL_UISystemCalls( intptr_t *args ) { switch( args[0] ) { case UI_ERROR: Com_Error( ERR_DROP, "%s", VMA(1) ); return 0; case UI_CVAR_REGISTER: Cvar_Register( (vmCvar_t *)VMA(1),(const char *) VMA(2),(const char *) VMA(3), args[4] ); return 0; case UI_CVAR_SET: Cvar_Set( (const char *) VMA(1), (const char *) VMA(2) ); return 0; case UI_CVAR_SETVALUE: Cvar_SetValue( (const char *) VMA(1), VMF(2) ); return 0; case UI_CVAR_UPDATE: Cvar_Update( (vmCvar_t *) VMA(1) ); return 0; case UI_R_REGISTERMODEL: return re.RegisterModel((const char *) VMA(1) ); case UI_R_REGISTERSHADERNOMIP: return re.RegisterShaderNoMip((const char *) VMA(1) ); case UI_GETGLCONFIG: CL_GetGlconfig( ( glconfig_t *) VMA(1) ); return 0; case UI_CMD_EXECUTETEXT: Cbuf_ExecuteText( args[1], (const char *) VMA(2) ); return 0; case UI_CVAR_VARIABLEVALUE: return FloatAsInt( Cvar_VariableValue( (const char *) VMA(1) ) ); case UI_FS_GETFILELIST: return FS_GetFileList( (const char *) VMA(1), (const char *) VMA(2), (char *) VMA(3), args[4] ); case UI_KEY_SETCATCHER: Key_SetCatcher( args[1] ); return 0; case UI_KEY_CLEARSTATES: Key_ClearStates(); return 0; case UI_R_SETCOLOR: re.SetColor( (const float *) VMA(1) ); return 0; case UI_R_DRAWSTRETCHPIC: re.DrawStretchPic( VMF(1), VMF(2), VMF(3), VMF(4), VMF(5), VMF(6), VMF(7), VMF(8), args[9] ); return 0; case UI_CVAR_VARIABLESTRINGBUFFER: Cvar_VariableStringBuffer( (const char *) VMA(1), (char *) VMA(2), args[3] ); return 0; case UI_R_MODELBOUNDS: re.ModelBounds( args[1], (float *) VMA(2),(float *) VMA(3) ); return 0; case UI_R_CLEARSCENE: re.ClearScene(); return 0; // case UI_KEY_GETOVERSTRIKEMODE: // return Key_GetOverstrikeMode(); // return 0; // case UI_PC_READ_TOKEN: // return PC_ReadTokenHandle( args[1], VMA(2) ); // case UI_PC_SOURCE_FILE_AND_LINE: // return PC_SourceFileAndLine( args[1], VMA(2), VMA(3) ); case UI_KEY_GETCATCHER: return Key_GetCatcher(); case UI_MILLISECONDS: return Sys_Milliseconds(); case UI_S_REGISTERSOUND: return S_RegisterSound((const char *) VMA(1)); case UI_S_STARTLOCALSOUND: S_StartLocalSound( args[1], args[2] ); return 0; // case UI_R_REGISTERFONT: // re.RegisterFont( VMA(1), args[2], VMA(3)); // return 0; case UI_CIN_PLAYCINEMATIC: Com_DPrintf("UI_CIN_PlayCinematic\n"); return CIN_PlayCinematic((const char *)VMA(1), args[2], args[3], args[4], args[5], args[6], (const char *)VMA(7)); case UI_CIN_STOPCINEMATIC: return CIN_StopCinematic(args[1]); case UI_CIN_RUNCINEMATIC: return CIN_RunCinematic(args[1]); case UI_CIN_DRAWCINEMATIC: CIN_DrawCinematic(args[1]); return 0; case UI_KEY_SETBINDING: Key_SetBinding( args[1], (const char *) VMA(2) ); return 0; case UI_KEY_KEYNUMTOSTRINGBUF: Key_KeynumToStringBuf( args[1],(char *) VMA(2), args[3] ); return 0; case UI_CIN_SETEXTENTS: CIN_SetExtents(args[1], args[2], args[3], args[4], args[5]); return 0; case UI_KEY_GETBINDINGBUF: Key_GetBindingBuf( args[1], (char *) VMA(2), args[3] ); return 0; default: Com_Error( ERR_DROP, "Bad UI system trap: %i", args[0] ); } return 0; }
void CL_InitLocal(void) { cls.state = ca_disconnected; cls.realtime = Sys_Milliseconds(); CL_InitInput(); adr0 = Cvar_Get("adr0", "", CVAR_ARCHIVE); adr1 = Cvar_Get("adr1", "", CVAR_ARCHIVE); adr2 = Cvar_Get("adr2", "", CVAR_ARCHIVE); adr3 = Cvar_Get("adr3", "", CVAR_ARCHIVE); adr4 = Cvar_Get("adr4", "", CVAR_ARCHIVE); adr5 = Cvar_Get("adr5", "", CVAR_ARCHIVE); adr6 = Cvar_Get("adr6", "", CVAR_ARCHIVE); adr7 = Cvar_Get("adr7", "", CVAR_ARCHIVE); adr8 = Cvar_Get("adr8", "", CVAR_ARCHIVE); cin_force43 = Cvar_Get("cin_force43", "1", 0); /* register our variables */ cl_add_blend = Cvar_Get("cl_blend", "1", 0); cl_add_lights = Cvar_Get("cl_lights", "1", 0); cl_add_particles = Cvar_Get("cl_particles", "1", 0); cl_add_entities = Cvar_Get("cl_entities", "1", 0); cl_gun = Cvar_Get("cl_gun", "2", CVAR_ARCHIVE); cl_footsteps = Cvar_Get("cl_footsteps", "1", 0); cl_noskins = Cvar_Get("cl_noskins", "0", 0); cl_autoskins = Cvar_Get("cl_autoskins", "0", 0); cl_predict = Cvar_Get("cl_predict", "1", 0); cl_maxfps = Cvar_Get("cl_maxfps", "95", CVAR_ARCHIVE); cl_drawfps = Cvar_Get("cl_drawfps", "0", CVAR_ARCHIVE); cl_upspeed = Cvar_Get("cl_upspeed", "200", 0); cl_forwardspeed = Cvar_Get("cl_forwardspeed", "200", 0); cl_sidespeed = Cvar_Get("cl_sidespeed", "200", 0); cl_yawspeed = Cvar_Get("cl_yawspeed", "140", 0); cl_pitchspeed = Cvar_Get("cl_pitchspeed", "150", 0); cl_anglespeedkey = Cvar_Get("cl_anglespeedkey", "1.5", 0); cl_run = Cvar_Get("cl_run", "0", CVAR_ARCHIVE); freelook = Cvar_Get("freelook", "1", CVAR_ARCHIVE); lookspring = Cvar_Get("lookspring", "0", CVAR_ARCHIVE); lookstrafe = Cvar_Get("lookstrafe", "0", CVAR_ARCHIVE); sensitivity = Cvar_Get("sensitivity", "3", CVAR_ARCHIVE); m_pitch = Cvar_Get("m_pitch", "0.022", CVAR_ARCHIVE); m_yaw = Cvar_Get("m_yaw", "0.022", 0); m_forward = Cvar_Get("m_forward", "1", 0); m_side = Cvar_Get("m_side", "1", 0); cl_shownet = Cvar_Get("cl_shownet", "0", 0); cl_showmiss = Cvar_Get("cl_showmiss", "0", 0); cl_showclamp = Cvar_Get("showclamp", "0", 0); cl_timeout = Cvar_Get("cl_timeout", "120", 0); cl_paused = Cvar_Get("paused", "0", 0); cl_timedemo = Cvar_Get("timedemo", "0", 0); cl_stereo = Cvar_Get( "cl_stereo", "0", CVAR_ARCHIVE ); cl_stereo_separation = Cvar_Get( "cl_stereo_separation", "1", CVAR_ARCHIVE ); cl_stereo_convergence = Cvar_Get( "cl_stereo_convergence", "1.4", CVAR_ARCHIVE ); rcon_client_password = Cvar_Get("rcon_password", "", 0); rcon_address = Cvar_Get("rcon_address", "", 0); cl_lightlevel = Cvar_Get("gl_lightlevel", "0", 0); /* userinfo */ info_password = Cvar_Get("password", "", CVAR_USERINFO); info_spectator = Cvar_Get("spectator", "0", CVAR_USERINFO); name = Cvar_Get("name", "unnamed", CVAR_USERINFO | CVAR_ARCHIVE); skin = Cvar_Get("skin", "male/grunt", CVAR_USERINFO | CVAR_ARCHIVE); rate = Cvar_Get("rate", "8000", CVAR_USERINFO | CVAR_ARCHIVE); msg = Cvar_Get("msg", "1", CVAR_USERINFO | CVAR_ARCHIVE); hand = Cvar_Get("hand", "0", CVAR_USERINFO | CVAR_ARCHIVE); fov = Cvar_Get("fov", "90", CVAR_USERINFO | CVAR_ARCHIVE); horplus = Cvar_Get("horplus", "1", CVAR_ARCHIVE); windowed_mouse = Cvar_Get("windowed_mouse", "1", CVAR_USERINFO | CVAR_ARCHIVE); gender = Cvar_Get("gender", "male", CVAR_USERINFO | CVAR_ARCHIVE); gender_auto = Cvar_Get("gender_auto", "1", CVAR_ARCHIVE); gender->modified = false; cl_vwep = Cvar_Get("cl_vwep", "1", CVAR_ARCHIVE); /* register our commands */ Cmd_AddCommand("cmd", CL_ForwardToServer_f); Cmd_AddCommand("pause", CL_Pause_f); Cmd_AddCommand("pingservers", CL_PingServers_f); Cmd_AddCommand("skins", CL_Skins_f); Cmd_AddCommand("userinfo", CL_Userinfo_f); Cmd_AddCommand("snd_restart", CL_Snd_Restart_f); Cmd_AddCommand("changing", CL_Changing_f); Cmd_AddCommand("disconnect", CL_Disconnect_f); Cmd_AddCommand("record", CL_Record_f); Cmd_AddCommand("stop", CL_Stop_f); Cmd_AddCommand("quit", CL_Quit_f); Cmd_AddCommand("connect", CL_Connect_f); Cmd_AddCommand("reconnect", CL_Reconnect_f); Cmd_AddCommand("rcon", CL_Rcon_f); Cmd_AddCommand("setenv", CL_Setenv_f); Cmd_AddCommand("precache", CL_Precache_f); Cmd_AddCommand("download", CL_Download_f); /* forward to server commands * the only thing this does is allow command completion * to work -- all unknown commands are automatically * forwarded to the server */ Cmd_AddCommand("wave", NULL); Cmd_AddCommand("inven", NULL); Cmd_AddCommand("kill", NULL); Cmd_AddCommand("use", NULL); Cmd_AddCommand("drop", NULL); Cmd_AddCommand("say", NULL); Cmd_AddCommand("say_team", NULL); Cmd_AddCommand("info", NULL); Cmd_AddCommand("prog", NULL); Cmd_AddCommand("give", NULL); Cmd_AddCommand("god", NULL); Cmd_AddCommand("notarget", NULL); Cmd_AddCommand("noclip", NULL); Cmd_AddCommand("invuse", NULL); Cmd_AddCommand("invprev", NULL); Cmd_AddCommand("invnext", NULL); Cmd_AddCommand("invdrop", NULL); Cmd_AddCommand("weapnext", NULL); Cmd_AddCommand("weapprev", NULL); }
/* ================= idRenderModelManagerLocal::Preload ================= */ void idRenderModelManagerLocal::Preload( const idPreloadManifest& manifest ) { if( preload_MapModels.GetBool() ) { // preload this levels images int start = Sys_Milliseconds(); int numLoaded = 0; idList< preloadSort_t > preloadSort; preloadSort.Resize( manifest.NumResources() ); for( int i = 0; i < manifest.NumResources(); i++ ) { const preloadEntry_s& p = manifest.GetPreloadByIndex( i ); idResourceCacheEntry rc; idStrStatic< MAX_OSPATH > filename; if( p.resType == PRELOAD_MODEL ) { filename = "generated/rendermodels/"; filename += p.resourceName; idStrStatic< 16 > ext; filename.ExtractFileExtension( ext ); filename.SetFileExtension( va( "b%s", ext.c_str() ) ); } if( p.resType == PRELOAD_PARTICLE ) { filename = "generated/particles/"; filename += p.resourceName; filename += ".bprt"; } if( !filename.IsEmpty() ) { if( fileSystem->GetResourceCacheEntry( filename, rc ) ) { preloadSort_t ps = {}; ps.idx = i; ps.ofs = rc.offset; preloadSort.Append( ps ); } } } preloadSort.SortWithTemplate( idSort_Preload() ); for( int i = 0; i < preloadSort.Num(); i++ ) { const preloadSort_t& ps = preloadSort[ i ]; const preloadEntry_s& p = manifest.GetPreloadByIndex( ps.idx ); if( p.resType == PRELOAD_MODEL ) { idRenderModel* model = FindModel( p.resourceName ); if( model != NULL ) { model->SetLevelLoadReferenced( true ); } } else if( p.resType == PRELOAD_PARTICLE ) { declManager->FindType( DECL_PARTICLE, p.resourceName ); } numLoaded++; } int end = Sys_Milliseconds(); common->Printf( "%05d models preloaded ( or were already loaded ) in %5.1f seconds\n", numLoaded, ( end - start ) * 0.001 ); common->Printf( "----------------------------------------\n" ); } }
/* ================== WinMain ================== */ int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { char cwd[MAX_OSPATH]; // int startTime, endTime; SET_CRT_DEBUG_FIELD( _CRTDBG_LEAK_CHECK_DF ); // _CrtSetBreakAlloc(34804); // should never get a previous instance in Win32 if ( hPrevInstance ) { return 0; } g_wv.hInstance = hInstance; Q_strncpyz( sys_cmdline, lpCmdLine, sizeof( sys_cmdline ) ); // done before Com/Sys_Init since we need this for error output Sys_CreateConsole(); // no abort/retry/fail errors SetErrorMode( SEM_FAILCRITICALERRORS ); // get the initial time base Sys_Milliseconds(); Sys_InitStreamThread(); Com_Init( sys_cmdline ); QuickMemTest(); _getcwd (cwd, sizeof(cwd)); Com_Printf("Working directory: %s\n", cwd); // hide the early console since we've reached the point where we // have a working graphics subsystems if ( !com_viewlog->integer ) { Sys_ShowConsole( 0, qfalse ); } // main game loop while( 1 ) { // if not running as a game client, sleep a bit if ( g_wv.isMinimized ) { Sleep( 5 ); } #ifdef _DEBUG if (!g_wv.activeApp) { Sleep(50); } #endif // _DEBUG // set low precision every frame, because some system calls // reset it arbitrarily // _controlfp( _PC_24, _MCW_PC ); // startTime = Sys_Milliseconds(); // make sure mouse and joystick are only called once a frame IN_Frame(); // run the game Com_Frame(); // endTime = Sys_Milliseconds(); // totalMsec += endTime - startTime; // countMsec++; } // never gets here }
/** * @brief InputLineWndProc * @param[in] hWnd * @param[in] uMsg * @param[in] wParam * @param[in] lParam * @return */ LONG WINAPI InputLineWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) { case WM_KILLFOCUS: if ((HWND)wParam == s_wcd.hWnd || (HWND)wParam == s_wcd.hwndErrorBox) { SetFocus(hWnd); return 0; } break; case WM_KEYDOWN: switch (wParam) { case VK_UP: // previous history item if ((win_nextHistoryLine - win_historyLine < WIN_COMMAND_HISTORY) && win_historyLine > 0) { win_historyLine--; } win_consoleField = win_historyEditLines[win_historyLine % WIN_COMMAND_HISTORY]; SetWindowText(s_wcd.hwndInputLine, win_consoleField.buffer); SendMessage(s_wcd.hwndInputLine, EM_SETSEL, win_consoleField.cursor, win_consoleField.cursor); win_acLength = 0; return 0; case VK_DOWN: // next history item if (win_historyLine < win_nextHistoryLine) { win_historyLine++; win_consoleField = win_historyEditLines[win_historyLine % WIN_COMMAND_HISTORY]; SetWindowText(s_wcd.hwndInputLine, win_consoleField.buffer); SendMessage(s_wcd.hwndInputLine, EM_SETSEL, win_consoleField.cursor, win_consoleField.cursor); } win_acLength = 0; return 0; } break; case WM_CHAR: //GetWindowText( s_wcd.hwndInputLine, inputBuffer, sizeof( inputBuffer ) ); GetWindowText(s_wcd.hwndInputLine, win_consoleField.buffer, sizeof(win_consoleField.buffer)); SendMessage(s_wcd.hwndInputLine, EM_GETSEL, (WPARAM) NULL, (LPARAM) &win_consoleField.cursor); win_consoleField.widthInChars = strlen(win_consoleField.buffer); win_consoleField.scroll = 0; // handle enter key if (wParam == 13) { strncat(s_wcd.consoleText, win_consoleField.buffer, sizeof(s_wcd.consoleText) - strlen(s_wcd.consoleText) - 5); strcat(s_wcd.consoleText, "\n"); SetWindowText(s_wcd.hwndInputLine, ""); Sys_Print(va("]%s\n", win_consoleField.buffer)); // clear autocomplete length win_acLength = 0; // copy line to history buffer if (win_consoleField.buffer[0] != '\0') { win_historyEditLines[win_nextHistoryLine % WIN_COMMAND_HISTORY] = win_consoleField; win_nextHistoryLine++; win_historyLine = win_nextHistoryLine; } return 0; } // handle tab key (commandline completion) else if (wParam == 9) { // enable this code for tab double-tap show matching #if 0 static int win_tabTime = 0; { int tabTime = Sys_Milliseconds(); if ((tabTime - win_tabTime) < 100) { Win_CompleteCommand(qtrue); win_tabTime = 0; } else { Win_CompleteCommand(qfalse); win_tabTime = tabTime; } } #else Win_CompleteCommand(qfalse); #endif SetWindowText(s_wcd.hwndInputLine, win_consoleField.buffer); win_consoleField.widthInChars = strlen(win_consoleField.buffer); SendMessage(s_wcd.hwndInputLine, EM_SETSEL, win_consoleField.cursor, win_consoleField.cursor); return 0; } // handle everything else else { win_acLength = 0; } break; } return CallWindowProc(s_wcd.SysInputLineWndProc, hWnd, uMsg, wParam, lParam); }
int main (int argc, char **argv) { #if WRITE_LOG FILE *log = NULL; #endif u32 ticks_per_s; int oldtime; SetupCallbacks(); #if WRITE_LOG // Wipe log file. log = fopen("log.txt", "w"); if (log != NULL) { fputs("LOG START\n\n", log); fclose(log); log = NULL; } #endif // Calculate the clock resolution. sceRtcGetCurrentTick(&first_ticks); ticks_per_s = sceRtcGetTickResolution(); ticks_per_ms = ticks_per_s / 1000.0; // TODO Move elsewhere. sceCtrlSetSamplingCycle(0); sceCtrlSetSamplingMode(PSP_CTRL_MODE_ANALOG); // Initialise Quake. Qcommon_Init (argc, argv); oldtime = Sys_Milliseconds(); // Run the main loop. while (go) { SceCtrlData pad; curtime = Sys_Milliseconds(); sys_frame_time = curtime; if (curtime < oldtime) { Sys_Error("curtime (%d) < oldtime (%d)\n", curtime, oldtime); } sceCtrlPeekBufferPositive(&pad, 1); if (pad.Buttons & PSP_CTRL_CROSS) { go = false; } if (curtime != oldtime) { Qcommon_Frame(curtime - oldtime); oldtime = curtime; } } sceKernelExitGame(); return 0; }
/** * @brief The cgame module is making a system call * @param[in] args * @return */ intptr_t CL_CgameSystemCalls(intptr_t *args) { switch (args[0]) { case CG_PRINT: Com_Printf("%s", (char *)VMA(1)); return 0; case CG_ERROR: Com_Error(ERR_DROP, "%s", (char *)VMA(1)); case CG_MILLISECONDS: return Sys_Milliseconds(); case CG_CVAR_REGISTER: Cvar_Register(VMA(1), VMA(2), VMA(3), args[4]); return 0; case CG_CVAR_UPDATE: Cvar_Update(VMA(1)); return 0; case CG_CVAR_SET: Cvar_SetSafe(VMA(1), VMA(2)); return 0; case CG_CVAR_VARIABLESTRINGBUFFER: Cvar_VariableStringBuffer(VMA(1), VMA(2), args[3]); return 0; case CG_CVAR_LATCHEDVARIABLESTRINGBUFFER: Cvar_LatchedVariableStringBuffer(VMA(1), VMA(2), args[3]); return 0; case CG_ARGC: return Cmd_Argc(); case CG_ARGV: Cmd_ArgvBuffer(args[1], VMA(2), args[3]); return 0; case CG_ARGS: Cmd_ArgsBuffer(VMA(1), args[2]); return 0; case CG_FS_FOPENFILE: return FS_FOpenFileByMode(VMA(1), VMA(2), args[3]); case CG_FS_READ: FS_Read(VMA(1), args[2], args[3]); return 0; case CG_FS_WRITE: return FS_Write(VMA(1), args[2], args[3]); case CG_FS_FCLOSEFILE: FS_FCloseFile(args[1]); return 0; case CG_FS_GETFILELIST: return FS_GetFileList(VMA(1), VMA(2), VMA(3), args[4]); case CG_FS_DELETEFILE: return FS_Delete(VMA(1)); case CG_SENDCONSOLECOMMAND: Cbuf_AddText(VMA(1)); return 0; case CG_ADDCOMMAND: Cmd_AddCommand(VMA(1)); return 0; case CG_REMOVECOMMAND: Cmd_RemoveCommandSafe(VMA(1)); return 0; case CG_SENDCLIENTCOMMAND: CL_AddReliableCommand(VMA(1)); return 0; case CG_UPDATESCREEN: SCR_UpdateScreen(); return 0; case CG_CM_LOADMAP: CL_CM_LoadMap(VMA(1)); return 0; case CG_CM_NUMINLINEMODELS: return CM_NumInlineModels(); case CG_CM_INLINEMODEL: return CM_InlineModel(args[1]); case CG_CM_TEMPBOXMODEL: return CM_TempBoxModel(VMA(1), VMA(2), qfalse); case CG_CM_TEMPCAPSULEMODEL: return CM_TempBoxModel(VMA(1), VMA(2), qtrue); case CG_CM_POINTCONTENTS: return CM_PointContents(VMA(1), args[2]); case CG_CM_TRANSFORMEDPOINTCONTENTS: return CM_TransformedPointContents(VMA(1), args[2], VMA(3), VMA(4)); case CG_CM_BOXTRACE: CM_BoxTrace(VMA(1), VMA(2), VMA(3), VMA(4), VMA(5), args[6], args[7], /*int capsule*/ qfalse); return 0; case CG_CM_CAPSULETRACE: CM_BoxTrace(VMA(1), VMA(2), VMA(3), VMA(4), VMA(5), args[6], args[7], /*int capsule*/ qtrue); return 0; case CG_CM_TRANSFORMEDBOXTRACE: CM_TransformedBoxTrace(VMA(1), VMA(2), VMA(3), VMA(4), VMA(5), args[6], args[7], VMA(8), VMA(9), /*int capsule*/ qfalse); return 0; case CG_CM_TRANSFORMEDCAPSULETRACE: CM_TransformedBoxTrace(VMA(1), VMA(2), VMA(3), VMA(4), VMA(5), args[6], args[7], VMA(8), VMA(9), /*int capsule*/ qtrue); return 0; case CG_CM_MARKFRAGMENTS: return re.MarkFragments(args[1], VMA(2), VMA(3), args[4], VMA(5), args[6], VMA(7)); case CG_R_PROJECTDECAL: re.ProjectDecal(args[1], args[2], VMA(3), VMA(4), VMA(5), args[6], args[7]); return 0; case CG_R_CLEARDECALS: re.ClearDecals(); return 0; case CG_S_STARTSOUND: S_StartSound(VMA(1), args[2], args[3], args[4], args[5]); return 0; case CG_S_STARTSOUNDEX: S_StartSoundEx(VMA(1), args[2], args[3], args[4], args[5], args[6]); return 0; case CG_S_STARTLOCALSOUND: S_StartLocalSound(args[1], args[2], args[3]); return 0; case CG_S_CLEARLOOPINGSOUNDS: S_ClearLoopingSounds(); return 0; case CG_S_CLEARSOUNDS: if (args[1] == 0) { S_ClearSounds(qtrue, qfalse); } else if (args[1] == 1) { S_ClearSounds(qtrue, qtrue); } return 0; case CG_S_ADDLOOPINGSOUND: // FIXME handling of looping sounds changed S_AddLoopingSound(VMA(1), VMA(2), args[3], args[4], args[5], args[6]); return 0; case CG_S_ADDREALLOOPINGSOUND: S_AddRealLoopingSound(VMA(1), VMA(2), args[3], args[4], args[5], args[6]); return 0; case CG_S_STOPSTREAMINGSOUND: S_StopEntStreamingSound(args[1]); return 0; case CG_S_UPDATEENTITYPOSITION: S_UpdateEntityPosition(args[1], VMA(2)); return 0; // talking animations case CG_S_GETVOICEAMPLITUDE: return S_GetVoiceAmplitude(args[1]); case CG_S_GETSOUNDLENGTH: return S_GetSoundLength(args[1]); // for looped sound starts case CG_S_GETCURRENTSOUNDTIME: return S_GetCurrentSoundTime(); case CG_S_RESPATIALIZE: S_Respatialize(args[1], VMA(2), VMA(3), args[4]); return 0; case CG_S_REGISTERSOUND: return S_RegisterSound(VMA(1), args[2]); case CG_S_STARTBACKGROUNDTRACK: S_StartBackgroundTrack(VMA(1), VMA(2), args[3]); // added fadeup time return 0; case CG_S_FADESTREAMINGSOUND: S_FadeStreamingSound(VMF(1), args[2], args[3]); // added music/all-streaming options return 0; case CG_S_STARTSTREAMINGSOUND: return S_StartStreamingSound(VMA(1), VMA(2), args[3], args[4], args[5]); case CG_R_LOADWORLDMAP: re.LoadWorld(VMA(1)); return 0; case CG_R_REGISTERMODEL: return re.RegisterModel(VMA(1)); case CG_R_REGISTERSKIN: return re.RegisterSkin(VMA(1)); case CG_R_GETSKINMODEL: return re.GetSkinModel(args[1], VMA(2), VMA(3)); case CG_R_GETMODELSHADER: return re.GetShaderFromModel(args[1], args[2], args[3]); case CG_R_REGISTERSHADER: return re.RegisterShader(VMA(1)); case CG_R_REGISTERSHADERNOMIP: return re.RegisterShaderNoMip(VMA(1)); case CG_R_REGISTERFONT: re.RegisterFont(VMA(1), args[2], VMA(3), (args[4] == qtrue)); return 0; case CG_R_CLEARSCENE: re.ClearScene(); return 0; case CG_R_ADDREFENTITYTOSCENE: re.AddRefEntityToScene(VMA(1)); return 0; case CG_R_ADDPOLYTOSCENE: re.AddPolyToScene(args[1], args[2], VMA(3)); return 0; case CG_R_ADDPOLYSTOSCENE: re.AddPolysToScene(args[1], args[2], VMA(3), args[4]); return 0; case CG_R_ADDPOLYBUFFERTOSCENE: re.AddPolyBufferToScene(VMA(1)); return 0; case CG_R_ADDLIGHTTOSCENE: re.AddLightToScene(VMA(1), VMF(2), VMF(3), VMF(4), VMF(5), VMF(6), args[7], args[8]); return 0; case CG_R_ADDCORONATOSCENE: re.AddCoronaToScene(VMA(1), VMF(2), VMF(3), VMF(4), VMF(5), args[6], args[7]); return 0; case CG_R_SETFOG: re.SetFog(args[1], args[2], args[3], VMF(4), VMF(5), VMF(6), VMF(7)); return 0; case CG_R_SETGLOBALFOG: re.SetGlobalFog(args[1], args[2], VMF(3), VMF(4), VMF(5), VMF(6)); return 0; case CG_R_RENDERSCENE: re.RenderScene(VMA(1)); return 0; case CG_R_SAVEVIEWPARMS: return 0; case CG_R_RESTOREVIEWPARMS: return 0; case CG_R_SETCOLOR: re.SetColor(VMA(1)); return 0; case CG_R_DRAWSTRETCHPIC: re.DrawStretchPic(VMF(1), VMF(2), VMF(3), VMF(4), VMF(5), VMF(6), VMF(7), VMF(8), args[9]); return 0; case CG_R_DRAWROTATEDPIC: re.DrawRotatedPic(VMF(1), VMF(2), VMF(3), VMF(4), VMF(5), VMF(6), VMF(7), VMF(8), args[9], VMF(10)); return 0; case CG_R_DRAWSTRETCHPIC_GRADIENT: re.DrawStretchPicGradient(VMF(1), VMF(2), VMF(3), VMF(4), VMF(5), VMF(6), VMF(7), VMF(8), args[9], VMA(10), args[11]); return 0; case CG_R_DRAW2DPOLYS: re.Add2dPolys(VMA(1), args[2], args[3]); return 0; case CG_R_MODELBOUNDS: re.ModelBounds(args[1], VMA(2), VMA(3)); return 0; case CG_R_LERPTAG: return re.LerpTag(VMA(1), VMA(2), VMA(3), args[4]); case CG_GETGLCONFIG: CL_GetGlconfig(VMA(1)); return 0; case CG_GETGAMESTATE: CL_GetGameState(VMA(1)); return 0; case CG_GETCURRENTSNAPSHOTNUMBER: CL_GetCurrentSnapshotNumber(VMA(1), VMA(2)); return 0; case CG_GETSNAPSHOT: return CL_GetSnapshot(args[1], VMA(2)); case CG_GETSERVERCOMMAND: return CL_GetServerCommand(args[1]); case CG_GETCURRENTCMDNUMBER: return CL_GetCurrentCmdNumber(); case CG_GETUSERCMD: return CL_GetUserCmd(args[1], VMA(2)); case CG_SETUSERCMDVALUE: CL_SetUserCmdValue(args[1], args[2], VMF(3), args[4]); return 0; case CG_SETCLIENTLERPORIGIN: CL_SetClientLerpOrigin(VMF(1), VMF(2), VMF(3)); return 0; case CG_MEMORY_REMAINING: return Hunk_MemoryRemaining(); case CG_KEY_ISDOWN: return Key_IsDown(args[1]); case CG_KEY_GETCATCHER: return Key_GetCatcher(); case CG_KEY_SETCATCHER: // Don't allow the cgame module to close the console Key_SetCatcher(args[1] | (Key_GetCatcher() & KEYCATCH_CONSOLE)); return 0; case CG_KEY_GETKEY: return Key_GetKey(VMA(1)); case CG_KEY_GETOVERSTRIKEMODE: return Key_GetOverstrikeMode(); case CG_KEY_SETOVERSTRIKEMODE: Key_SetOverstrikeMode(args[1]); return 0; case CG_MEMSET: return (intptr_t)Com_Memset(VMA(1), args[2], args[3]); case CG_MEMCPY: return (intptr_t)Com_Memcpy(VMA(1), VMA(2), args[3]); case CG_STRNCPY: return (intptr_t)strncpy(VMA(1), VMA(2), args[3]); case CG_SIN: return FloatAsInt(sin(VMF(1))); case CG_COS: return FloatAsInt(cos(VMF(1))); case CG_ATAN2: return FloatAsInt(atan2(VMF(1), VMF(2))); case CG_SQRT: return FloatAsInt(sqrt(VMF(1))); case CG_FLOOR: return FloatAsInt(floor(VMF(1))); case CG_CEIL: return FloatAsInt(ceil(VMF(1))); case CG_ACOS: return FloatAsInt(Q_acos(VMF(1))); case CG_PC_ADD_GLOBAL_DEFINE: return botlib_export->PC_AddGlobalDefine(VMA(1)); case CG_PC_LOAD_SOURCE: return botlib_export->PC_LoadSourceHandle(VMA(1)); case CG_PC_FREE_SOURCE: return botlib_export->PC_FreeSourceHandle(args[1]); case CG_PC_READ_TOKEN: return botlib_export->PC_ReadTokenHandle(args[1], VMA(2)); case CG_PC_SOURCE_FILE_AND_LINE: return botlib_export->PC_SourceFileAndLine(args[1], VMA(2), VMA(3)); case CG_PC_UNREAD_TOKEN: botlib_export->PC_UnreadLastTokenHandle(args[1]); return 0; case CG_S_STOPBACKGROUNDTRACK: S_StopBackgroundTrack(); return 0; case CG_REAL_TIME: return Com_RealTime(VMA(1)); case CG_SNAPVECTOR: Sys_SnapVector(VMA(1)); return 0; case CG_CIN_PLAYCINEMATIC: return CIN_PlayCinematic(VMA(1), args[2], args[3], args[4], args[5], args[6]); case CG_CIN_STOPCINEMATIC: return CIN_StopCinematic(args[1]); case CG_CIN_RUNCINEMATIC: return CIN_RunCinematic(args[1]); case CG_CIN_DRAWCINEMATIC: CIN_DrawCinematic(args[1]); return 0; case CG_CIN_SETEXTENTS: CIN_SetExtents(args[1], args[2], args[3], args[4], args[5]); return 0; case CG_R_REMAP_SHADER: re.RemapShader(VMA(1), VMA(2), VMA(3)); return 0; case CG_TESTPRINTINT: Com_Printf("%s%li\n", (char *)VMA(1), (long)args[2]); return 0; case CG_TESTPRINTFLOAT: Com_Printf("%s%f\n", (char *)VMA(1), VMF(2)); return 0; case CG_GET_ENTITY_TOKEN: return re.GetEntityToken(VMA(1), args[2]); case CG_INGAME_POPUP: if (cls.state == CA_ACTIVE && !clc.demoplaying) { if (uivm) // can be called as the system is shutting down { VM_Call(uivm, UI_SET_ACTIVE_MENU, args[1]); } } return 0; case CG_KEY_GETBINDINGBUF: Key_GetBindingBuf(args[1], VMA(2), args[3]); return 0; case CG_KEY_SETBINDING: Key_SetBinding(args[1], VMA(2)); return 0; case CG_KEY_KEYNUMTOSTRINGBUF: Key_KeynumToStringBuf(args[1], VMA(2), args[3]); return 0; case CG_KEY_BINDINGTOKEYS: Key_GetBindingByString(VMA(1), VMA(2), VMA(3)); return 0; case CG_TRANSLATE_STRING: CL_TranslateStringMod(VMA(1), VMA(2)); return 0; case CG_S_FADEALLSOUNDS: S_FadeAllSounds(VMF(1), args[2], args[3]); return 0; case CG_R_INPVS: return re.inPVS(VMA(1), VMA(2)); case CG_GETHUNKDATA: Com_GetHunkInfo(VMA(1), VMA(2)); return 0; // binary channel case CG_SENDMESSAGE: return CL_SendBinaryMessage(VMA(1), args[2]); case CG_MESSAGESTATUS: return CL_BinaryMessageStatus(); case CG_R_LOADDYNAMICSHADER: return re.LoadDynamicShader(VMA(1), VMA(2)); case CG_R_RENDERTOTEXTURE: re.RenderToTexture(args[1], args[2], args[3], args[4], args[5]); return 0; case CG_R_GETTEXTUREID: return re.GetTextureId(VMA(1)); // flush gl rendering buffers case CG_R_FINISH: re.Finish(); return 0; case CG_LOADCAMERA: case CG_STARTCAMERA: case CG_STOPCAMERA: case CG_GETCAMERAINFO: case CG_PUMPEVENTLOOP: case CG_INGAME_CLOSEPOPUP: case CG_R_LIGHTFORPOINT: // re-added to avoid a crash when called - still in enum of cgameImport_t // This shows (developer 1) when the vanilla mod code is loaded or mods using obsolete system calls - see cases. Com_DPrintf("Obsolete cgame system trap: %ld\n", (long int) args[0]); return 0; default: Com_Error(ERR_DROP, "Bad cgame system trap: %ld", (long int) args[0]); break; } return 0; }
void Sys_SendKeyEvents (void) { // grab frame time sys_frame_time = Sys_Milliseconds(); }
void CLT3_InitCGame() { int t1 = Sys_Milliseconds(); // put away the console Con_Close(); // find the current mapname const char* info = GGameType & GAME_WolfSP ? cl.ws_gameState.stringData + cl.ws_gameState.stringOffsets[ Q3CS_SERVERINFO ] : GGameType & GAME_WolfMP ? cl.wm_gameState.stringData + cl.wm_gameState.stringOffsets[ Q3CS_SERVERINFO ] : GGameType & GAME_ET ? cl.et_gameState.stringData + cl.et_gameState.stringOffsets[ Q3CS_SERVERINFO ] : cl.q3_gameState.stringData + cl.q3_gameState.stringOffsets[ Q3CS_SERVERINFO ]; const char* mapname = Info_ValueForKey( info, "mapname" ); String::Sprintf( cl.q3_mapname, sizeof ( cl.q3_mapname ), "maps/%s.bsp", mapname ); if ( GGameType & GAME_Quake3 ) { // load the dll or bytecode vmInterpret_t interpret; if ( cl_connectedToPureServer != 0 ) { // if sv_pure is set we only allow qvms to be loaded interpret = VMI_COMPILED; } else { interpret = ( vmInterpret_t )( int )Cvar_VariableValue( "vm_cgame" ); } cgvm = VM_Create( "cgame", CLQ3_CgameSystemCalls, interpret ); } else if ( GGameType & GAME_WolfSP ) { cgvm = VM_Create( "cgame", CLWS_CgameSystemCalls, VMI_NATIVE ); } else if ( GGameType & GAME_WolfMP ) { cgvm = VM_Create( "cgame", CLWM_CgameSystemCalls, VMI_NATIVE ); } else { cgvm = VM_Create( "cgame", CLET_CgameSystemCalls, VMI_NATIVE ); } if ( !cgvm ) { common->Error( "VM_Create on cgame failed" ); } cls.state = CA_LOADING; // init for this gamestate // use the lastExecutedServerCommand instead of the serverCommandSequence // otherwise server commands sent just before a gamestate are dropped if ( GGameType & GAME_ET ) { //bani - added clc.demoplaying, since some mods need this at init time, and drawactiveframe is too late for them VM_Call( cgvm, CG_INIT, clc.q3_serverMessageSequence, clc.q3_lastExecutedServerCommand, clc.q3_clientNum, clc.demoplaying ); } else { VM_Call( cgvm, CG_INIT, clc.q3_serverMessageSequence, clc.q3_lastExecutedServerCommand, clc.q3_clientNum ); } // we will send a usercmd this frame, which // will cause the server to send us the first snapshot cls.state = CA_PRIMED; int t2 = Sys_Milliseconds(); common->Printf( "CLT3_InitCGame: %5.2f seconds\n", ( t2 - t1 ) / 1000.0 ); // have the renderer touch all its images, so they are present // on the card even if the driver does deferred loading R_EndRegistration(); // clear anything that got printed Con_ClearNotify(); }
void Menu_Draw( menuframework_s *menu ) { int i; menucommon_s *item; /* ** draw contents */ for ( i = 0; i < menu->nitems; i++ ) { switch ( ( ( menucommon_s * ) menu->items[i] )->type ) { case MTYPE_FIELD: Field_Draw( ( menufield_s * ) menu->items[i] ); break; case MTYPE_SLIDER: Slider_Draw( ( menuslider_s * ) menu->items[i] ); break; case MTYPE_LIST: MenuList_Draw( ( menulist_s * ) menu->items[i] ); break; case MTYPE_SPINCONTROL: SpinControl_Draw( ( menulist_s * ) menu->items[i] ); break; case MTYPE_ACTION: Action_Draw( ( menuaction_s * ) menu->items[i] ); break; case MTYPE_SEPARATOR: Separator_Draw( ( menuseparator_s * ) menu->items[i] ); break; } } item = (menucommon_s *) Menu_ItemAtCursor( menu ); if ( item && item->cursordraw ) { item->cursordraw( item ); } else if ( menu->cursordraw ) { menu->cursordraw( menu ); } else if ( item && item->type != MTYPE_FIELD ) { if ( item->flags & QMF_LEFT_JUSTIFY ) { Draw_Char( menu->x + item->x - 24 + item->cursor_offset, menu->y + item->y, 12 + ( ( int ) ( Sys_Milliseconds()/250 ) & 1 ) ); } else { Draw_Char( menu->x + item->cursor_offset, menu->y + item->y, 12 + ( ( int ) ( Sys_Milliseconds()/250 ) & 1 ) ); } } if ( item ) { if ( item->statusbarfunc ) item->statusbarfunc( ( void * ) item ); else if ( item->statusbar ) Menu_DrawStatusBar( item->statusbar ); else Menu_DrawStatusBar( menu->statusbar ); } else { Menu_DrawStatusBar( menu->statusbar ); } }
/* * cl_mm_login_done * callback for login post request */ static void cl_mm_login_done( stat_query_t *query, qboolean success, void *customp ) { int rstatus; unsigned int uuid; stat_query_section_t *root; stat_query_section_t *ratings_section; if( cl_mm_loginState == LOGIN_STATE_NONE ) { Com_DPrintf("cl_mm_login_done called when no login in process!\n"); return; } cl_mm_enabled = qfalse; cls.mm_session = 0; Cvar_ForceSet( cl_mm_session->name, "0" ); if( !success ) { // TODO: reset login CL_MM_ErrorMessage( qtrue, "MM Login: StatQuery error" ); cl_mm_loginState = LOGIN_STATE_NONE; return; } Com_DPrintf( "MM Login: %s\n", sq_api->GetRawResponse( query ) ); /* * ch : new JSON response looks like * { * ready: // reflects the 'state of login protocol' * -1, // for initial login - LOGIN_RESPONSE_HANDLE * 1, // for login not ready yet - LOGIN_RESPONSE_WAIT * 2, // ready - LOGIN_RESPONSE_READY * * handle: [int], // handle for login-process * id: [int], // valid when ready=2. 0 on error, > 0 otherwise * ratings: [ * { gametype: [string], rating: [float], deviation: [float] } * .. * ] * } */ root = sq_api->GetRoot( query ); if( root == NULL ) { CL_MM_ErrorMessage( qtrue, "MM Login: Failed to parse data at step %d", cl_mm_loginState ); // bail out cl_mm_loginHandle = 0; cl_mm_loginState = LOGIN_STATE_NONE; } else { rstatus = (int)sq_api->GetNumber( root, "ready" ); uuid = (unsigned int)sq_api->GetNumber( root, "id" ); Com_DPrintf( "cl_mm_login_done %d %d\n", rstatus, uuid ); // possible responses are ( -1 any ) ( 1 0 ) ( 2 any ) if( rstatus == LOGIN_RESPONSE_NONE ) { // ERROR cl_mm_loginState = LOGIN_STATE_NONE; } else if( cl_mm_loginState == LOGIN_STATE_WAITING ) { // here we are expecting a handle to the validation process if( rstatus == LOGIN_RESPONSE_HANDLE ) { // we can move to step 2 cl_mm_loginHandle = (unsigned int)sq_api->GetNumber( root, "handle" );; cl_mm_loginState = LOGIN_STATE_READY; cl_mm_loginTime = Sys_Milliseconds() /* - MM_LOGIN2_INTERVAL */; } else { // stop this madness cl_mm_loginHandle = 0; cl_mm_loginState = LOGIN_STATE_NONE; } } else if( cl_mm_loginState == LOGIN_STATE_READY && rstatus == LOGIN_RESPONSE_READY ) { // validation process is done and with got an uuid cls.mm_session = (unsigned int)sq_api->GetNumber( root, "id" ); cl_mm_loginState = LOGIN_STATE_NONE; ratings_section = sq_api->GetSection( root, "ratings" ); if( cls.mm_session != 0 && ratings_section != NULL ) { int idx = 0; stat_query_section_t *element = sq_api->GetArraySection( ratings_section, idx++ ); while( element ) { CL_AddRating( sq_api->GetString( element, "gametype" ), sq_api->GetNumber( element, "rating" ), sq_api->GetNumber( element, "deviation" ) ); element = sq_api->GetArraySection( ratings_section, idx++ ); } cl_mm_StringCopy( sq_api->GetString( root, "profile_url" ), &cl_mm_profie_url ); cl_mm_StringCopy( sq_api->GetString( root, "profile_url_rml" ), &cl_mm_profie_url_rml ); } } // else loginState == LOGIN_STATE_READY && rstatus == LOGIN_RESPONSE_WAIT : no-op } if( cl_mm_loginState == LOGIN_STATE_NONE ) { // we are done with the process, see if we got anything cl_mm_enabled = ( cls.mm_session == 0 ? qfalse : qtrue ); if( cl_mm_enabled ) { CL_MM_ErrorMessage( qfalse, "" ); Com_DPrintf( "MM Login: Success, session id %u\n", cls.mm_session ); } else CL_MM_ErrorMessage( qtrue, "MM Login: Failed, no session id" ); Cvar_ForceSet( cl_mm_session->name, va( "%d", cls.mm_session ) ); } }
static void Accelerometer_HandleEvents(void) { int dx = 0, dy = 0; int t, tmp; int x, y, z; static int jumpTime = 0; t = Sys_Milliseconds(); if (!accel_angle) { accel_angle = Cvar_Get("accel_angle", "45", CVAR_ARCHIVE); } if (!accel_debug) { accel_debug = Cvar_Get("accel_debug", "0", CVAR_ARCHIVE); } if (!accel_jump) { accel_jump = Cvar_Get("accel_jump", "-1300", CVAR_ARCHIVE); } if (!accel_epsilon_x) { accel_epsilon_x = Cvar_Get("accel_epsilon_x", "100", CVAR_ARCHIVE); } if (!accel_epsilon_y) { accel_epsilon_y = Cvar_Get("accel_epsilon_y", "100", CVAR_ARCHIVE); } Accelerometer_ReadCoords(&x, &y, &z); /* only update sin and cos if the cvar's changed */ tmp = accel_angle->value; if(tmp != accel_angle_value) { /* what happened to sincosf()? */ accel_sin = sin(DEG2RAD(tmp)); accel_cos = cos(DEG2RAD(tmp)); accel_angle_value = tmp; } tmp = y * accel_cos - z * accel_sin; z = z * accel_cos + y * accel_sin; y = tmp; if (accel_debug->integer) { Com_DPrintf("Accelerometer_HandleEvents: y = %d\n", y); } if (accel_jump->value) { float mag = sqrtf(y*y+z*z); // HACK - change the sign of jump to be +ve not -ve // HACK - z<0 means that lots of jerks will look like jumps // change it to < -500 or < accel_jump->value/2 int looks_like_a_jump = (mag > -accel_jump->value) && (z < 0); if (!jumpTime && looks_like_a_jump) { Com_QueueEvent(t, SE_KEY, K_SPACE, qtrue, 0, NULL); jumpTime = t; } else if (jumpTime && !looks_like_a_jump) { Com_QueueEvent(t, SE_KEY, K_SPACE, qfalse, 0, NULL); jumpTime = 0; } } if (x > accel_epsilon_x->integer) dx = -(x - accel_epsilon_x->integer); else if (x < -accel_epsilon_x->integer) dx = -(x + accel_epsilon_x->integer); if (y > accel_epsilon_y->integer) dy = -(y - accel_epsilon_y->integer); else if (y < -accel_epsilon_y->integer) dy = -(y + accel_epsilon_y->integer); dx *= cl_sensitivity->value; dy *= cl_sensitivity->value; Com_QueueEvent(t, SE_ACCEL, dx, dy, 0, NULL); }
/* ===================== idRenderSystemLocal::SwapCommandBuffers_FinishCommandBuffers ===================== */ const emptyCommand_t* idRenderSystemLocal::SwapCommandBuffers_FinishCommandBuffers() { if( !R_IsInitialized() ) { return NULL; } // close any gui drawing guiModel->EmitFullScreen(); guiModel->Clear(); // unmap the buffer objects so they can be used by the GPU vertexCache.BeginBackEnd(); // save off this command buffer const emptyCommand_t* commandBufferHead = frameData->cmdHead; // copy the code-used drawsurfs that were // allocated at the start of the buffer memory to the backEnd referenced locations backEnd.unitSquareSurface = tr.unitSquareSurface_; backEnd.zeroOneCubeSurface = tr.zeroOneCubeSurface_; backEnd.testImageSurface = tr.testImageSurface_; // use the other buffers next frame, because another CPU // may still be rendering into the current buffers R_ToggleSmpFrame(); // possibly change the stereo3D mode // PC if( glConfig.nativeScreenWidth == 1280 && glConfig.nativeScreenHeight == 1470 ) { glConfig.stereo3Dmode = STEREO3D_HDMI_720; } else { glConfig.stereo3Dmode = GetStereoScopicRenderingMode(); } // prepare the new command buffer guiModel->BeginFrame(); //------------------------------ // Make sure that geometry used by code is present in the buffer cache. // These use frame buffer cache (not static) because they may be used during // map loads. // // It is important to do this first, so if the buffers overflow during // scene generation, the basic surfaces needed for drawing the buffers will // always be present. //------------------------------ R_InitDrawSurfFromTri( tr.unitSquareSurface_, *tr.unitSquareTriangles ); R_InitDrawSurfFromTri( tr.zeroOneCubeSurface_, *tr.zeroOneCubeTriangles ); R_InitDrawSurfFromTri( tr.testImageSurface_, *tr.testImageTriangles ); // Reset render crop to be the full screen renderCrops[0].x1 = 0; renderCrops[0].y1 = 0; renderCrops[0].x2 = GetWidth() - 1; renderCrops[0].y2 = GetHeight() - 1; currentRenderCrop = 0; // this is the ONLY place this is modified frameCount++; // just in case we did a common->Error while this // was set guiRecursionLevel = 0; // the first rendering will be used for commands like // screenshot, rather than a possible subsequent remote // or mirror render // primaryWorld = NULL; // set the time for shader effects in 2D rendering frameShaderTime = Sys_Milliseconds() * 0.001; setBufferCommand_t* cmd2 = ( setBufferCommand_t* )R_GetCommandBuffer( sizeof( *cmd2 ) ); cmd2->commandId = RC_SET_BUFFER; cmd2->buffer = ( int )GL_BACK; // the old command buffer can now be rendered, while the new one can // be built in parallel return commandBufferHead; }
/* ================= main ================= */ int main(int argc, char **argv) { int i; char commandLine[MAX_STRING_CHARS] = { 0 }; #ifndef DEDICATED // SDL version check // Compile time # if !SDL_VERSION_ATLEAST(MINSDL_MAJOR, MINSDL_MINOR, MINSDL_PATCH) # error A more recent version of SDL is required # endif // Run time const SDL_version *ver = SDL_Linked_Version(); #define MINSDL_VERSION \ XSTRING(MINSDL_MAJOR) "." \ XSTRING(MINSDL_MINOR) "." \ XSTRING(MINSDL_PATCH) if (SDL_VERSIONNUM(ver->major, ver->minor, ver->patch) < SDL_VERSIONNUM(MINSDL_MAJOR, MINSDL_MINOR, MINSDL_PATCH)) { Sys_Dialog(DT_ERROR, va("SDL version " MINSDL_VERSION " or greater is required, " "but only version %d.%d.%d was found. You may be able to obtain a more recent copy " "from http://www.libsdl.org/.", ver->major, ver->minor, ver->patch), "SDL Library Too Old"); Sys_Exit(1); } #endif Sys_PlatformInit(); // Set the initial time base Sys_Milliseconds(); Sys_ParseArgs(argc, argv); Sys_SetBinaryPath(Sys_Dirname(argv[0])); Sys_SetDefaultInstallPath(DEFAULT_BASEDIR); // Concatenate the command line for passing to Com_Init for (i = 1; i < argc; i++) { const qboolean containsSpaces = (qboolean)(strchr(argv[i], ' ') != NULL); if (containsSpaces) { Q_strcat(commandLine, sizeof(commandLine), "\""); } Q_strcat(commandLine, sizeof(commandLine), argv[i]); if (containsSpaces) { Q_strcat(commandLine, sizeof(commandLine), "\""); } Q_strcat(commandLine, sizeof(commandLine), " "); } Com_Init(commandLine); NET_Init(); #ifdef FEATURE_CURSES if (nocurses) { CON_Init_tty(); } else { CON_Init(); } #else CON_Init(); #endif signal(SIGILL, Sys_SigHandler); signal(SIGFPE, Sys_SigHandler); signal(SIGSEGV, Sys_SigHandler); signal(SIGTERM, Sys_SigHandler); signal(SIGINT, Sys_SigHandler); while (1) { IN_Frame(); Com_Frame(); } return 0; }
void CL_Frame(int msec) { static int extratime; static int lasttimecalled; if (dedicated->value) { return; } extratime += msec; if (!cl_timedemo->value) { if ((cls.state == ca_connected) && (extratime < 100)) { return; /* don't flood packets out while connecting */ } if (extratime < 1000 / cl_maxfps->value) { return; /* framerate is too high */ } } /* decide the simulation time */ cls.frametime = extratime / 1000.0; cl.time += extratime; cls.realtime = curtime; extratime = 0; if (cls.frametime > (1.0 / 5)) { cls.frametime = (1.0 / 5); } /* if in the debugger last frame, don't timeout */ if (msec > 5000) { cls.netchan.last_received = Sys_Milliseconds(); } /* fetch results from server */ CL_ReadPackets(); /* send a new command message to the server */ CL_SendCommand(); /* predict all unacknowledged movements */ CL_PredictMovement(); /* allow renderer DLL change */ VID_CheckChanges(); if (!cl.refresh_prepped && (cls.state == ca_active)) { CL_PrepRefresh(); } /* update the screen */ if (host_speeds->value) { time_before_ref = Sys_Milliseconds(); } SCR_UpdateScreen(); if (host_speeds->value) { time_after_ref = Sys_Milliseconds(); } /* update audio */ S_Update(cl.refdef.vieworg, cl.v_forward, cl.v_right, cl.v_up); #ifdef CDA CDAudio_Update(); #endif /* advance local effects for next frame */ CL_RunDLights(); CL_RunLightStyles(); SCR_RunCinematic(); SCR_RunConsole(); cls.framecount++; if (log_stats->value) { if (cls.state == ca_active) { if (!lasttimecalled) { lasttimecalled = Sys_Milliseconds(); if (log_stats_file) { fprintf(log_stats_file, "0\n"); } } else { int now = Sys_Milliseconds(); if (log_stats_file) { fprintf(log_stats_file, "%d\n", now - lasttimecalled); } lasttimecalled = now; } } } }
/* ================ SV_SpawnServer Change the server to a new map, taking all connected clients along with it. This is NOT called for map_restart ================ */ void SV_SpawnServer( const char *server ) { int i; bool isBot; // shut down the existing game if it is running SV_ShutdownGameProgs(); PrintBanner( "Server Initialization" ) Com_Printf( "Server: %s\n", server ); // clear the whole hunk because we're (re)loading the server Hunk_Clear(); // if not running a dedicated server CL_MapLoading will connect the client to the server // also print some status stuff CL_MapLoading(); // clear collision map data CM_ClearMap(); // wipe the entire per-level structure SV_ClearServer(); // allocate empty config strings for ( i = 0; i < MAX_CONFIGSTRINGS; i++ ) { sv.configstrings[ i ] = CopyString( "" ); sv.configstringsmodified[ i ] = false; } // init client structures and svs.numSnapshotEntities if ( !Cvar_VariableValue( "sv_running" ) ) { SV_Startup(); } else { // check for maxclients change if ( sv_maxclients->modified ) { SV_ChangeMaxClients(); } } // allocate the snapshot entities on the hunk svs.snapshotEntities = ( entityState_t * ) Hunk_Alloc( sizeof( entityState_t ) * svs.numSnapshotEntities, h_high ); svs.nextSnapshotEntities = 0; // toggle the server bit so clients can detect that a // server has changed svs.snapFlagServerBit ^= SNAPFLAG_SERVERCOUNT; // set sv_nextmap to the same map, but it may be overridden // by the game startup or another console command Cvar_Set( "sv_nextmap", "map_restart 0" ); // make sure we are not paused Cvar_Set( "cl_paused", "0" ); // get a new checksum feed and restart the file system srand( Sys_Milliseconds() ); sv.checksumFeed = ( ( rand() << 16 ) ^ rand() ) ^ Sys_Milliseconds(); FS::PakPath::ClearPaks(); FS_LoadBasePak(); if (!FS_LoadPak(va("map-%s", server))) Com_Error(ERR_DROP, "Could not load map pak\n"); CM_LoadMap(server); // set serverinfo visible name Cvar_Set( "mapname", server ); // serverid should be different each time sv.serverId = com_frameTime; sv.restartedServerId = sv.serverId; Cvar_Set( "sv_serverid", va( "%i", sv.serverId ) ); // media configstring setting should be done during // the loading stage, so connected clients don't have // to load during actual gameplay sv.state = SS_LOADING; // load and spawn all other entities SV_InitGameProgs(); // run a few frames to allow everything to settle for ( i = 0; i < GAME_INIT_FRAMES; i++ ) { gvm.GameRunFrame( sv.time ); svs.time += FRAMETIME; sv.time += FRAMETIME; } // create a baseline for more efficient communications SV_CreateBaseline(); for ( i = 0; i < sv_maxclients->integer; i++ ) { // send the new gamestate to all connected clients if ( svs.clients[ i ].state >= CS_CONNECTED ) { bool denied; char reason[ MAX_STRING_CHARS ]; isBot = SV_IsBot(&svs.clients[i]); // connect the client again denied = gvm.GameClientConnect( reason, sizeof( reason ), i, false, isBot ); // firstTime = false if ( denied ) { // this generally shouldn't happen, because the client // was connected before the level change SV_DropClient( &svs.clients[ i ], reason ); } else { if ( !isBot ) { // when we get the next packet from a connected client, // the new gamestate will be sent svs.clients[ i ].state = CS_CONNECTED; } else { client_t *client; sharedEntity_t *ent; client = &svs.clients[ i ]; client->state = CS_ACTIVE; ent = SV_GentityNum( i ); ent->s.number = i; client->gentity = ent; client->deltaMessage = -1; client->nextSnapshotTime = svs.time; // generate a snapshot immediately gvm.GameClientBegin( i ); } } } } // run another frame to allow things to look at all the players gvm.GameRunFrame( sv.time ); svs.time += FRAMETIME; sv.time += FRAMETIME; // the server sends these to the clients so they can figure // out which pk3s should be auto-downloaded Cvar_Set( "sv_paks", FS_LoadedPaks() ); // save systeminfo and serverinfo strings cvar_modifiedFlags &= ~CVAR_SYSTEMINFO; SV_SetConfigstring( CS_SYSTEMINFO, Cvar_InfoString( CVAR_SYSTEMINFO, true ) ); SV_SetConfigstring( CS_SERVERINFO, Cvar_InfoString( CVAR_SERVERINFO, false ) ); cvar_modifiedFlags &= ~CVAR_SERVERINFO; // any media configstring setting now should issue a warning // and any configstring changes should be reliably transmitted // to all clients sv.state = SS_GAME; // send a heartbeat now so the master will get up to date info SV_Heartbeat_f(); Hunk_SetMark(); SV_UpdateConfigStrings(); SV_AddOperatorCommands(); Com_Printf( "-----------------------------------\n" ); }
/* ================= idRenderModelManagerLocal::EndLevelLoad ================= */ void idRenderModelManagerLocal::EndLevelLoad() { common->Printf( "----- idRenderModelManagerLocal::EndLevelLoad -----\n" ); int start = Sys_Milliseconds(); insideLevelLoad = false; int purgeCount = 0; int keepCount = 0; int loadCount = 0; // purge any models not touched for( int i = 0; i < models.Num(); i++ ) { idRenderModel* model = models[i]; if( !model->IsLevelLoadReferenced() && model->IsLoaded() && model->IsReloadable() ) { // common->Printf( "purging %s\n", model->Name() ); purgeCount++; R_CheckForEntityDefsUsingModel( model ); model->PurgeModel(); } else { // common->Printf( "keeping %s\n", model->Name() ); keepCount++; } common->UpdateLevelLoadPacifier(); } // load any new ones for( int i = 0; i < models.Num(); i++ ) { common->UpdateLevelLoadPacifier(); idRenderModel* model = models[i]; if( model->IsLevelLoadReferenced() && !model->IsLoaded() && model->IsReloadable() ) { loadCount++; model->LoadModel(); } } // create static vertex/index buffers for all models for( int i = 0; i < models.Num(); i++ ) { common->UpdateLevelLoadPacifier(); idRenderModel* model = models[i]; if( model->IsLoaded() ) { for( int j = 0; j < model->NumSurfaces(); j++ ) { R_CreateStaticBuffersForTri( *( model->Surface( j )->geometry ) ); } } } // _D3XP added this int end = Sys_Milliseconds(); common->Printf( "%5i models purged from previous level, ", purgeCount ); common->Printf( "%5i models kept.\n", keepCount ); if( loadCount ) { common->Printf( "%5i new models loaded in %5.1f seconds\n", loadCount, ( end - start ) * 0.001 ); } common->Printf( "---------------------------------------------------\n" ); }
/* ================= main ================= */ int main( int argc, char **argv ) { int i; char commandLine[ MAX_STRING_CHARS ] = { 0 }; #ifndef DEDICATED // SDL version check // Compile time # if !SDL_VERSION_ATLEAST(MINSDL_MAJOR,MINSDL_MINOR,MINSDL_PATCH) # error A more recent version of SDL is required # endif // Run time SDL_version ver; SDL_GetVersion( &ver ); #define MINSDL_VERSION \ XSTRING(MINSDL_MAJOR) "." \ XSTRING(MINSDL_MINOR) "." \ XSTRING(MINSDL_PATCH) if( SDL_VERSIONNUM( ver.major, ver.minor, ver.patch ) < SDL_VERSIONNUM( MINSDL_MAJOR, MINSDL_MINOR, MINSDL_PATCH ) ) { Sys_Dialog( DT_ERROR, va( "SDL version " MINSDL_VERSION " or greater is required, " "but only version %d.%d.%d was found. You may be able to obtain a more recent copy " "from http://www.libsdl.org/.", ver.major, ver.minor, ver.patch ), "SDL Library Too Old" ); Sys_Exit( 1 ); } #endif Sys_PlatformInit( ); // Set the initial time base Sys_Milliseconds( ); #ifdef MACOS_X // This is passed if we are launched by double-clicking if ( argc >= 2 && Q_strncmp ( argv[1], "-psn", 4 ) == 0 ) argc = 1; #endif Sys_ParseArgs( argc, argv ); Sys_SetBinaryPath( Sys_Dirname( argv[ 0 ] ) ); Sys_SetDefaultInstallPath( DEFAULT_BASEDIR ); // Concatenate the command line for passing to Com_Init for( i = 1; i < argc; i++ ) { const qboolean containsSpaces = strchr(argv[i], ' ') != NULL; if (containsSpaces) Q_strcat( commandLine, sizeof( commandLine ), "\"" ); Q_strcat( commandLine, sizeof( commandLine ), argv[ i ] ); if (containsSpaces) Q_strcat( commandLine, sizeof( commandLine ), "\"" ); Q_strcat( commandLine, sizeof( commandLine ), " " ); } Com_Init( commandLine ); NET_Init( ); CON_Init( ); signal( SIGILL, Sys_SigHandler ); signal( SIGFPE, Sys_SigHandler ); signal( SIGSEGV, Sys_SigHandler ); signal( SIGTERM, Sys_SigHandler ); signal( SIGINT, Sys_SigHandler ); while( 1 ) { IN_Frame( ); Com_Frame( ); } return 0; }
/* ================= main ================= */ int main(int argc, char **argv) { char commandLine[MAX_STRING_CHARS] = { 0 }; Sys_PlatformInit(); // Set the initial time base Sys_Milliseconds(); #ifdef __APPLE__ // This is passed if we are launched by double-clicking if (argc >= 2 && Q_strncmp(argv[1], "-psn", 4) == 0) { argc = 1; } #endif Sys_ParseArgs(argc, argv); #if defined(__APPLE__) && !defined(DEDICATED) // argv[0] would be /Users/seth/etlegacy/etl.app/Contents/MacOS // But on OS X we want to pretend the binary path is the .app's parent // So that way the base folder is right next to the .app allowing { char parentdir[1024]; CFURLRef url = CFBundleCopyBundleURL(CFBundleGetMainBundle()); if (!url) { Sys_Dialog(DT_ERROR, "A CFURL for the app bundle could not be found.", "Can't set Sys_SetBinaryPath"); Sys_Exit(1); } CFURLRef url2 = CFURLCreateCopyDeletingLastPathComponent(0, url); if (!url2 || !CFURLGetFileSystemRepresentation(url2, 1, (UInt8 *)parentdir, 1024)) { Sys_Dialog(DT_ERROR, "CFURLGetFileSystemRepresentation returned an error when finding the app bundle's parent directory.", "Can't set Sys_SetBinaryPath"); Sys_Exit(1); } Sys_SetBinaryPath(parentdir); CFRelease(url); CFRelease(url2); } #else Sys_SetBinaryPath(Sys_Dirname(argv[0])); #endif Sys_SetDefaultInstallPath(DEFAULT_BASEDIR); // Sys_BinaryPath() by default // Concatenate the command line for passing to Com_Init Sys_BuildCommandLine(argc, argv, commandLine, sizeof(commandLine)); Com_Init(commandLine); NET_Init(); Sys_SetUpConsoleAndSignals(); Sys_GameLoop(); return 0; }
/* ======================== idSoundHardware_OpenAL::Update ======================== */ void idSoundHardware_OpenAL::Update() { if( openalDevice == NULL ) { int nowTime = Sys_Milliseconds(); if( lastResetTime + 1000 < nowTime ) { lastResetTime = nowTime; Init(); } return; } if( soundSystem->IsMuted() ) { alListenerf( AL_GAIN, 0.0f ); } else { alListenerf( AL_GAIN, DBtoLinear( s_volume_dB.GetFloat() ) ); } // IXAudio2SourceVoice::Stop() has been called for every sound on the // zombie list, but it is documented as asyncronous, so we have to wait // until it actually reports that it is no longer playing. for( int i = 0; i < zombieVoices.Num(); i++ ) { zombieVoices[i]->FlushSourceBuffers(); if( !zombieVoices[i]->IsPlaying() ) { freeVoices.Append( zombieVoices[i] ); zombieVoices.RemoveIndexFast( i ); i--; } else { static int playingZombies; playingZombies++; } } /* if( s_showPerfData.GetBool() ) { XAUDIO2_PERFORMANCE_DATA perfData; pXAudio2->GetPerformanceData( &perfData ); idLib::Printf( "Voices: %d/%d CPU: %.2f%% Mem: %dkb\n", perfData.ActiveSourceVoiceCount, perfData.TotalSourceVoiceCount, perfData.AudioCyclesSinceLastQuery / ( float )perfData.TotalCyclesSinceLastQuery, perfData.MemoryUsageInBytes / 1024 ); } */ /* if( vuMeterRMS == NULL ) { // Init probably hasn't been called yet return; } vuMeterRMS->Enable( s_showLevelMeter.GetBool() ); vuMeterPeak->Enable( s_showLevelMeter.GetBool() ); if( !s_showLevelMeter.GetBool() ) { pMasterVoice->DisableEffect( 0 ); return; } else { pMasterVoice->EnableEffect( 0 ); } float peakLevels[ 8 ]; float rmsLevels[ 8 ]; XAUDIO2FX_VOLUMEMETER_LEVELS levels; levels.ChannelCount = outputChannels; levels.pPeakLevels = peakLevels; levels.pRMSLevels = rmsLevels; if( levels.ChannelCount > 8 ) { levels.ChannelCount = 8; } pMasterVoice->GetEffectParameters( 0, &levels, sizeof( levels ) ); int currentTime = Sys_Milliseconds(); for( int i = 0; i < outputChannels; i++ ) { if( vuMeterPeakTimes[i] < currentTime ) { vuMeterPeak->SetValue( i, vuMeterPeak->GetValue( i ) * 0.9f, colorRed ); } } float width = 20.0f; float height = 200.0f; float left = 100.0f; float top = 100.0f; sscanf( s_meterPosition.GetString(), "%f %f %f %f", &left, &top, &width, &height ); vuMeterRMS->SetPosition( left, top, width * levels.ChannelCount, height ); vuMeterPeak->SetPosition( left, top, width * levels.ChannelCount, height ); for( uint32 i = 0; i < levels.ChannelCount; i++ ) { vuMeterRMS->SetValue( i, rmsLevels[ i ], idVec4( 0.5f, 1.0f, 0.0f, 1.00f ) ); if( peakLevels[ i ] >= vuMeterPeak->GetValue( i ) ) { vuMeterPeak->SetValue( i, peakLevels[ i ], colorRed ); vuMeterPeakTimes[i] = currentTime + s_meterTopTime.GetInteger(); } } */ }
/* ================= 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 }
intptr_t CL_UISystemCalls( intptr_t *args ) { switch ( args[0] ) { //rww - alright, DO NOT EVER add a GAME/CGAME/UI generic call without adding a trap to match, and //all of these traps must be shared and have cases in sv_game, cl_cgame, and cl_ui. They must also //all be in the same order, and start at 100. case TRAP_MEMSET: Com_Memset( VMA(1), args[2], args[3] ); return 0; case TRAP_MEMCPY: Com_Memcpy( VMA(1), VMA(2), args[3] ); return 0; case TRAP_STRNCPY: strncpy( (char *)VMA(1), (const char *)VMA(2), args[3] ); return args[1]; case TRAP_SIN: return FloatAsInt( sin( VMF(1) ) ); case TRAP_COS: return FloatAsInt( cos( VMF(1) ) ); case TRAP_ATAN2: return FloatAsInt( atan2( VMF(1), VMF(2) ) ); case TRAP_SQRT: return FloatAsInt( sqrt( VMF(1) ) ); case TRAP_MATRIXMULTIPLY: MatrixMultiply( (vec3_t *)VMA(1), (vec3_t *)VMA(2), (vec3_t *)VMA(3) ); return 0; case TRAP_ANGLEVECTORS: AngleVectors( (const float *)VMA(1), (float *)VMA(2), (float *)VMA(3), (float *)VMA(4) ); return 0; case TRAP_PERPENDICULARVECTOR: PerpendicularVector( (float *)VMA(1), (const float *)VMA(2) ); return 0; case TRAP_FLOOR: return FloatAsInt( floor( VMF(1) ) ); case TRAP_CEIL: return FloatAsInt( ceil( VMF(1) ) ); case TRAP_TESTPRINTINT: return 0; case TRAP_TESTPRINTFLOAT: return 0; case TRAP_ACOS: return FloatAsInt( Q_acos( VMF(1) ) ); case TRAP_ASIN: return FloatAsInt( Q_asin( VMF(1) ) ); case UI_ERROR: Com_Error( ERR_DROP, "%s", VMA(1) ); return 0; case UI_PRINT: Com_Printf( "%s", VMA(1) ); return 0; case UI_MILLISECONDS: return Sys_Milliseconds(); case UI_CVAR_REGISTER: Cvar_Register( (vmCvar_t *)VMA(1), (const char *)VMA(2), (const char *)VMA(3), args[4] ); return 0; case UI_CVAR_UPDATE: Cvar_Update( (vmCvar_t *)VMA(1) ); return 0; case UI_CVAR_SET: Cvar_Set( (const char *)VMA(1), (const char *)VMA(2) ); return 0; case UI_CVAR_VARIABLEVALUE: return FloatAsInt( Cvar_VariableValue( (const char *)VMA(1) ) ); case UI_CVAR_VARIABLESTRINGBUFFER: Cvar_VariableStringBuffer( (const char *)VMA(1), (char *)VMA(2), args[3] ); return 0; case UI_CVAR_SETVALUE: Cvar_SetValue( (const char *)VMA(1), VMF(2) ); return 0; case UI_CVAR_RESET: Cvar_Reset( (const char *)VMA(1) ); return 0; case UI_CVAR_CREATE: Cvar_Get( (const char *)VMA(1), (const char *)VMA(2), args[3] ); return 0; case UI_CVAR_INFOSTRINGBUFFER: Cvar_InfoStringBuffer( args[1], (char *)VMA(2), args[3] ); return 0; case UI_ARGC: return Cmd_Argc(); case UI_ARGV: Cmd_ArgvBuffer( args[1], (char *)VMA(2), args[3] ); return 0; case UI_CMD_EXECUTETEXT: Cbuf_ExecuteText( args[1], (const char *)VMA(2) ); return 0; case UI_FS_FOPENFILE: return FS_FOpenFileByMode( (const char *)VMA(1), (int *)VMA(2), (fsMode_t)args[3] ); case UI_FS_READ: FS_Read2( VMA(1), args[2], args[3] ); return 0; case UI_FS_WRITE: FS_Write( VMA(1), args[2], args[3] ); return 0; case UI_FS_FCLOSEFILE: FS_FCloseFile( args[1] ); return 0; case UI_FS_GETFILELIST: return FS_GetFileList( (const char *)VMA(1), (const char *)VMA(2), (char *)VMA(3), args[4] ); case UI_R_REGISTERMODEL: return re->RegisterModel( (const char *)VMA(1) ); case UI_R_REGISTERSKIN: return re->RegisterSkin( (const char *)VMA(1) ); case UI_R_REGISTERSHADERNOMIP: return re->RegisterShaderNoMip( (const char *)VMA(1) ); case UI_R_SHADERNAMEFROMINDEX: CL_R_ShaderNameFromIndex( (char *)VMA(1), args[2] ); return 0; case UI_R_CLEARSCENE: re->ClearScene(); return 0; case UI_R_ADDREFENTITYTOSCENE: re->AddRefEntityToScene( (const refEntity_t *)VMA(1) ); return 0; case UI_R_ADDPOLYTOSCENE: re->AddPolyToScene( args[1], args[2], (const polyVert_t *)VMA(3), 1 ); return 0; case UI_R_ADDLIGHTTOSCENE: #ifdef VV_LIGHTING VVLightMan.RE_AddLightToScene( (const float *)VMA(1), VMF(2), VMF(3), VMF(4), VMF(5) ); #else re->AddLightToScene( (const float *)VMA(1), VMF(2), VMF(3), VMF(4), VMF(5) ); #endif return 0; case UI_R_RENDERSCENE: re->RenderScene( (const refdef_t *)VMA(1) ); return 0; case UI_R_SETCOLOR: re->SetColor( (const float *)VMA(1) ); return 0; case UI_R_DRAWSTRETCHPIC: re->DrawStretchPic( VMF(1), VMF(2), VMF(3), VMF(4), VMF(5), VMF(6), VMF(7), VMF(8), args[9] ); return 0; case UI_R_MODELBOUNDS: re->ModelBounds( args[1], (float *)VMA(2), (float *)VMA(3) ); return 0; case UI_UPDATESCREEN: SCR_UpdateScreen(); return 0; case UI_CM_LERPTAG: re->LerpTag( (orientation_t *)VMA(1), args[2], args[3], args[4], VMF(5), (const char *)VMA(6) ); return 0; case UI_S_REGISTERSOUND: return S_RegisterSound( (const char *)VMA(1) ); case UI_S_STARTLOCALSOUND: S_StartLocalSound( args[1], args[2] ); return 0; case UI_KEY_KEYNUMTOSTRINGBUF: Key_KeynumToStringBuf( args[1], (char *)VMA(2), args[3] ); return 0; case UI_KEY_GETBINDINGBUF: Key_GetBindingBuf( args[1], (char *)VMA(2), args[3] ); return 0; case UI_KEY_SETBINDING: Key_SetBinding( args[1], (const char *)VMA(2) ); return 0; case UI_KEY_ISDOWN: return Key_IsDown( args[1] ); case UI_KEY_GETOVERSTRIKEMODE: return Key_GetOverstrikeMode(); case UI_KEY_SETOVERSTRIKEMODE: Key_SetOverstrikeMode( (qboolean)args[1] ); return 0; case UI_KEY_CLEARSTATES: Key_ClearStates(); return 0; case UI_KEY_GETCATCHER: return Key_GetCatcher(); case UI_KEY_SETCATCHER: Key_SetCatcher( args[1] ); return 0; case UI_GETCLIPBOARDDATA: GetClipboardData( (char *)VMA(1), args[2] ); return 0; case UI_GETCLIENTSTATE: CL_GetClientState( (uiClientState_t *)VMA(1) ); return 0; case UI_GETGLCONFIG: CL_GetGlconfig( (glconfig_t *)VMA(1) ); return 0; case UI_GETCONFIGSTRING: return GetConfigString( args[1], (char *)VMA(2), args[3] ); case UI_LAN_LOADCACHEDSERVERS: LAN_LoadCachedServers(); return 0; case UI_LAN_SAVECACHEDSERVERS: LAN_SaveServersToCache(); return 0; case UI_LAN_ADDSERVER: return LAN_AddServer(args[1], (const char *)VMA(2), (const char *)VMA(3)); case UI_LAN_REMOVESERVER: LAN_RemoveServer(args[1], (const char *)VMA(2)); return 0; case UI_LAN_GETPINGQUEUECOUNT: return LAN_GetPingQueueCount(); case UI_LAN_CLEARPING: LAN_ClearPing( args[1] ); return 0; case UI_LAN_GETPING: LAN_GetPing( args[1], (char *)VMA(2), args[3], (int *)VMA(4) ); return 0; case UI_LAN_GETPINGINFO: LAN_GetPingInfo( args[1], (char *)VMA(2), args[3] ); return 0; case UI_LAN_GETSERVERCOUNT: return LAN_GetServerCount(args[1]); case UI_LAN_GETSERVERADDRESSSTRING: LAN_GetServerAddressString( args[1], args[2], (char *)VMA(3), args[4] ); return 0; case UI_LAN_GETSERVERINFO: LAN_GetServerInfo( args[1], args[2], (char *)VMA(3), args[4] ); return 0; case UI_LAN_GETSERVERPING: return LAN_GetServerPing( args[1], args[2] ); case UI_LAN_MARKSERVERVISIBLE: LAN_MarkServerVisible( args[1], args[2], (qboolean)args[3] ); return 0; case UI_LAN_SERVERISVISIBLE: return LAN_ServerIsVisible( args[1], args[2] ); case UI_LAN_UPDATEVISIBLEPINGS: return LAN_UpdateVisiblePings( args[1] ); case UI_LAN_RESETPINGS: LAN_ResetPings( args[1] ); return 0; case UI_LAN_SERVERSTATUS: return LAN_GetServerStatus( (char *)VMA(1), (char *)VMA(2), args[3] ); case UI_LAN_COMPARESERVERS: return LAN_CompareServers( args[1], args[2], args[3], args[4], args[5] ); case UI_MEMORY_REMAINING: return Hunk_MemoryRemaining(); case UI_R_REGISTERFONT: return re->RegisterFont( (const char *)VMA(1) ); case UI_R_FONT_STRLENPIXELS: return re->Font_StrLenPixels( (const char *)VMA(1), args[2], VMF(3) ); case UI_R_FONT_STRLENCHARS: return re->Font_StrLenChars( (const char *)VMA(1) ); case UI_R_FONT_STRHEIGHTPIXELS: return re->Font_HeightPixels( args[1], VMF(2) ); case UI_R_FONT_DRAWSTRING: re->Font_DrawString( args[1], args[2], (const char *)VMA(3), (const float *) VMA(4), args[5], args[6], VMF(7) ); return 0; case UI_LANGUAGE_ISASIAN: return re->Language_IsAsian(); case UI_LANGUAGE_USESSPACES: return re->Language_UsesSpaces(); case UI_ANYLANGUAGE_READCHARFROMSTRING: return re->AnyLanguage_ReadCharFromString( (const char *)VMA(1), (int *) VMA(2), (qboolean *) VMA(3) ); case UI_PC_ADD_GLOBAL_DEFINE: return botlib_export->PC_AddGlobalDefine( (char *)VMA(1) ); case UI_PC_LOAD_SOURCE: return botlib_export->PC_LoadSourceHandle( (const char *)VMA(1) ); case UI_PC_FREE_SOURCE: return botlib_export->PC_FreeSourceHandle( args[1] ); case UI_PC_READ_TOKEN: return botlib_export->PC_ReadTokenHandle( args[1], (struct pc_token_s *)VMA(2) ); case UI_PC_SOURCE_FILE_AND_LINE: return botlib_export->PC_SourceFileAndLine( args[1], (char *)VMA(2), (int *)VMA(3) ); case UI_PC_LOAD_GLOBAL_DEFINES: return botlib_export->PC_LoadGlobalDefines ( (char *)VMA(1) ); case UI_PC_REMOVE_ALL_GLOBAL_DEFINES: botlib_export->PC_RemoveAllGlobalDefines ( ); return 0; case UI_S_STOPBACKGROUNDTRACK: S_StopBackgroundTrack(); return 0; case UI_S_STARTBACKGROUNDTRACK: S_StartBackgroundTrack( (const char *)VMA(1), (const char *)VMA(2), qfalse ); return 0; case UI_REAL_TIME: return Com_RealTime( (struct qtime_s *)VMA(1) ); case UI_CIN_PLAYCINEMATIC: Com_DPrintf("UI_CIN_PlayCinematic\n"); return CIN_PlayCinematic((const char *)VMA(1), args[2], args[3], args[4], args[5], args[6]); case UI_CIN_STOPCINEMATIC: return CIN_StopCinematic(args[1]); case UI_CIN_RUNCINEMATIC: return CIN_RunCinematic(args[1]); case UI_CIN_DRAWCINEMATIC: CIN_DrawCinematic(args[1]); return 0; case UI_CIN_SETEXTENTS: CIN_SetExtents(args[1], args[2], args[3], args[4], args[5]); return 0; case UI_R_REMAP_SHADER: re->RemapShader( (const char *)VMA(1), (const char *)VMA(2), (const char *)VMA(3) ); return 0; case UI_SP_GETNUMLANGUAGES: return SE_GetNumLanguages(); case UI_SP_GETLANGUAGENAME: CL_SE_GetLanguageName( args[1], (char *)VMA(2) ); return 0; case UI_SP_GETSTRINGTEXTSTRING: return CL_SE_GetStringTextString( (const char *)VMA(1), (char *)VMA(2), args[3] ); case UI_G2_LISTSURFACES: re->G2API_ListSurfaces( (CGhoul2Info *) args[1] ); return 0; case UI_G2_LISTBONES: re->G2API_ListBones( (CGhoul2Info *) args[1], args[2]); return 0; case UI_G2_HAVEWEGHOULMODELS: return re->G2API_HaveWeGhoul2Models( *((CGhoul2Info_v *)args[1]) ); case UI_G2_SETMODELS: re->G2API_SetGhoul2ModelIndexes( *((CGhoul2Info_v *)args[1]),(qhandle_t *)VMA(2),(qhandle_t *)VMA(3)); return 0; case UI_G2_GETBOLT: return re->G2API_GetBoltMatrix(*((CGhoul2Info_v *)args[1]), args[2], args[3], (mdxaBone_t *)VMA(4), (const float *)VMA(5),(const float *)VMA(6), args[7], (qhandle_t *)VMA(8), (float *)VMA(9)); case UI_G2_GETBOLT_NOREC: re->G2API_BoltMatrixReconstruction( qfalse );//gG2_GBMNoReconstruct = qtrue; return re->G2API_GetBoltMatrix(*((CGhoul2Info_v *)args[1]), args[2], args[3], (mdxaBone_t *)VMA(4), (const float *)VMA(5),(const float *)VMA(6), args[7], (qhandle_t *)VMA(8), (float *)VMA(9)); case UI_G2_GETBOLT_NOREC_NOROT: //RAZFIXME: cgame reconstructs bolt matrix, why is this different? re->G2API_BoltMatrixReconstruction( qfalse );//gG2_GBMNoReconstruct = qtrue; re->G2API_BoltMatrixSPMethod( qtrue );//gG2_GBMUseSPMethod = qtrue; return re->G2API_GetBoltMatrix(*((CGhoul2Info_v *)args[1]), args[2], args[3], (mdxaBone_t *)VMA(4), (const float *)VMA(5),(const float *)VMA(6), args[7], (qhandle_t *)VMA(8), (float *)VMA(9)); case UI_G2_INITGHOUL2MODEL: #ifdef _FULL_G2_LEAK_CHECKING g_G2AllocServer = 0; #endif return re->G2API_InitGhoul2Model((CGhoul2Info_v **)VMA(1), (const char *)VMA(2), args[3], (qhandle_t) args[4], (qhandle_t) args[5], args[6], args[7]); case UI_G2_COLLISIONDETECT: case UI_G2_COLLISIONDETECTCACHE: return 0; //not supported for ui case UI_G2_ANGLEOVERRIDE: return re->G2API_SetBoneAngles(*((CGhoul2Info_v *)args[1]), args[2], (const char *)VMA(3), (float *)VMA(4), args[5], (const Eorientations) args[6], (const Eorientations) args[7], (const Eorientations) args[8], (qhandle_t *)VMA(9), args[10], args[11] ); case UI_G2_CLEANMODELS: #ifdef _FULL_G2_LEAK_CHECKING g_G2AllocServer = 0; #endif re->G2API_CleanGhoul2Models((CGhoul2Info_v **)VMA(1)); // re->G2API_CleanGhoul2Models((CGhoul2Info_v **)args[1]); return 0; case UI_G2_PLAYANIM: return re->G2API_SetBoneAnim(*((CGhoul2Info_v *)args[1]), args[2], (const char *)VMA(3), args[4], args[5], args[6], VMF(7), args[8], VMF(9), args[10]); case UI_G2_GETBONEANIM: { CGhoul2Info_v &g2 = *((CGhoul2Info_v *)args[1]); int modelIndex = args[10]; return re->G2API_GetBoneAnim(&g2[modelIndex], (const char*)VMA(2), args[3], (float *)VMA(4), (int *)VMA(5), (int *)VMA(6), (int *)VMA(7), (float *)VMA(8), (int *)VMA(9)); } case UI_G2_GETBONEFRAME: { //rwwFIXMEFIXME: Just make a G2API_GetBoneFrame func too. This is dirty. CGhoul2Info_v &g2 = *((CGhoul2Info_v *)args[1]); int modelIndex = args[6]; int iDontCare1 = 0, iDontCare2 = 0, iDontCare3 = 0; float fDontCare1 = 0; return re->G2API_GetBoneAnim(&g2[modelIndex], (const char*)VMA(2), args[3], (float *)VMA(4), &iDontCare1, &iDontCare2, &iDontCare3, &fDontCare1, (int *)VMA(5)); } case UI_G2_GETGLANAME: // return (int)G2API_GetGLAName(*((CGhoul2Info_v *)VMA(1)), args[2]); { char *point = ((char *)VMA(3)); char *local; local = re->G2API_GetGLAName(*((CGhoul2Info_v *)args[1]), args[2]); if (local) { strcpy(point, local); } } return 0; case UI_G2_COPYGHOUL2INSTANCE: return (int)re->G2API_CopyGhoul2Instance(*((CGhoul2Info_v *)args[1]), *((CGhoul2Info_v *)args[2]), args[3]); case UI_G2_COPYSPECIFICGHOUL2MODEL: re->G2API_CopySpecificG2Model(*((CGhoul2Info_v *)args[1]), args[2], *((CGhoul2Info_v *)args[3]), args[4]); return 0; case UI_G2_DUPLICATEGHOUL2INSTANCE: #ifdef _FULL_G2_LEAK_CHECKING g_G2AllocServer = 0; #endif re->G2API_DuplicateGhoul2Instance(*((CGhoul2Info_v *)args[1]), (CGhoul2Info_v **)VMA(2)); return 0; case UI_G2_HASGHOUL2MODELONINDEX: return (int)re->G2API_HasGhoul2ModelOnIndex((CGhoul2Info_v **)VMA(1), args[2]); //return (int)G2API_HasGhoul2ModelOnIndex((CGhoul2Info_v **)args[1], args[2]); case UI_G2_REMOVEGHOUL2MODEL: #ifdef _FULL_G2_LEAK_CHECKING g_G2AllocServer = 0; #endif return (int)re->G2API_RemoveGhoul2Model((CGhoul2Info_v **)VMA(1), args[2]); //return (int)G2API_RemoveGhoul2Model((CGhoul2Info_v **)args[1], args[2]); case UI_G2_ADDBOLT: return re->G2API_AddBolt(*((CGhoul2Info_v *)args[1]), args[2], (const char *)VMA(3)); case UI_G2_SETBOLTON: re->G2API_SetBoltInfo(*((CGhoul2Info_v *)args[1]), args[2], args[3]); return 0; case UI_G2_SETROOTSURFACE: return re->G2API_SetRootSurface(*((CGhoul2Info_v *)args[1]), args[2], (const char *)VMA(3)); case UI_G2_SETSURFACEONOFF: return re->G2API_SetSurfaceOnOff(*((CGhoul2Info_v *)args[1]), (const char *)VMA(2), /*(const int)VMA(3)*/args[3]); case UI_G2_SETNEWORIGIN: return re->G2API_SetNewOrigin(*((CGhoul2Info_v *)args[1]), /*(const int)VMA(2)*/args[2]); case UI_G2_GETTIME: return re->G2API_GetTime(0); case UI_G2_SETTIME: re->G2API_SetTime(args[1], args[2]); return 0; case UI_G2_SETRAGDOLL: return 0; //not supported for ui break; case UI_G2_ANIMATEG2MODELS: return 0; //not supported for ui break; case UI_G2_SETBONEIKSTATE: return re->G2API_SetBoneIKState(*((CGhoul2Info_v *)args[1]), args[2], (const char *)VMA(3), args[4], (sharedSetBoneIKStateParams_t *)VMA(5)); case UI_G2_IKMOVE: return re->G2API_IKMove(*((CGhoul2Info_v *)args[1]), args[2], (sharedIKMoveParams_t *)VMA(3)); case UI_G2_GETSURFACENAME: { //Since returning a pointer in such a way to a VM seems to cause MASSIVE FAILURE<tm>, we will shove data into the pointer the vm passes instead char *point = ((char *)VMA(4)); char *local; int modelindex = args[3]; CGhoul2Info_v &g2 = *((CGhoul2Info_v *)args[1]); local = re->G2API_GetSurfaceName(&g2[modelindex], args[2]); if (local) { strcpy(point, local); } } return 0; case UI_G2_SETSKIN: { CGhoul2Info_v &g2 = *((CGhoul2Info_v *)args[1]); int modelIndex = args[2]; return re->G2API_SetSkin(&g2[modelIndex], args[3], args[4]); } case UI_G2_ATTACHG2MODEL: { CGhoul2Info_v *g2From = ((CGhoul2Info_v *)args[1]); CGhoul2Info_v *g2To = ((CGhoul2Info_v *)args[3]); return re->G2API_AttachG2Model(*g2From, args[2], *g2To, args[4], args[5]); } default: Com_Error( ERR_DROP, "Bad UI system trap: %ld", (long int) args[0] ); } return 0; }
/** * @brief Init the game subsystem for a new map * @sa SV_ShutdownGameProgs */ void SV_InitGameProgs (void) { game_import_t import; /* unload anything we have now */ /*SV_ShutdownGameProgs();*/ /* load a new game dll */ import.BroadcastPrintf = SV_BroadcastPrintf; import.DPrintf = SV_dprintf; import.PlayerPrintf = SV_PlayerPrintf; import.Error = SV_error; import.Trace = SV_Trace; import.LinkEdict = SV_LinkEdict; import.UnlinkEdict = SV_UnlinkEdict; import.BoxEdicts = SV_AreaEdicts; import.TouchEdicts = SV_TouchEdicts; import.TestLine = SV_TestLine; import.TestLineWithEnt = SV_TestLineWithEnt; import.GrenadeTarget = Com_GrenadeTarget; import.MoveCalc = Grid_MoveCalc; import.MoveStore = Grid_MoveStore; import.MoveLength = Grid_MoveLength; import.MoveNext = Grid_MoveNext; import.GridFloor = Grid_Floor; import.GetTUsForDirection = Grid_GetTUsForDirection; import.GridFall = Grid_Fall; import.GridPosToVec = Grid_PosToVec; import.GridRecalcRouting = SV_RecalcRouting; import.ModelIndex = SV_ModelIndex; import.SetInlineModelOrientation = SV_SetInlineModelOrientation; import.SetModel = SV_SetModel; import.ConfigString = SV_Configstring; import.PositionedSound = SV_StartSound; import.PointContents = SV_PointContents; import.GetFootstepSound = SV_GetFootstepSound; import.GetBounceFraction = SV_GetBounceFraction; import.LoadModelMinsMaxs = SV_LoadModelMinsMaxs; import.FS_Gamedir = FS_Gamedir; import.FS_LoadFile = FS_LoadFile; import.FS_FreeFile = FS_FreeFile; import.WriteChar = SV_WriteChar; import.WriteByte = SV_WriteByte; import.WriteDummyByte = SV_WriteDummyByte; import.WriteShort = SV_WriteShort; import.WriteLong = SV_WriteLong; import.WriteString = SV_WriteString; import.WritePos = SV_WritePos; import.WriteGPos = SV_WriteGPos; import.WriteDir = SV_WriteDir; import.WriteAngle = SV_WriteAngle; import.WriteFormat = SV_WriteFormat; import.AbortEvents = SV_AbortEvents; import.EndEvents = SV_EndEvents; import.AddEvent = SV_AddEvent; import.GetEvent = SV_GetEvent; import.ReadChar = SV_ReadChar; import.ReadByte = SV_ReadByte; import.ReadShort = SV_ReadShort; import.ReadLong = SV_ReadLong; import.ReadString = SV_ReadString; import.ReadPos = SV_ReadPos; import.ReadGPos = SV_ReadGPos; import.ReadDir = SV_ReadDir; import.ReadAngle = SV_ReadAngle; import.ReadData = SV_ReadData; import.ReadFormat = SV_ReadFormat; import.GetConstInt = Com_GetConstInt; import.GetConstIntFromNamespace = Com_GetConstIntFromNamespace; import.GetConstVariable = Com_GetConstVariable; import.RegisterConstInt = Com_RegisterConstInt; import.UnregisterConstVariable = Com_UnregisterConstVariable; import.GetCharacterValues = Com_GetCharacterValues; import.TagMalloc = SV_TagAlloc; import.TagFree = SV_MemFree; import.FreeTags = SV_FreeTags; import.Cvar_Get = Cvar_Get; import.Cvar_Set = Cvar_Set; import.Cvar_String = Cvar_GetString; import.Cmd_Argc = Cmd_Argc; import.Cmd_Argv = Cmd_Argv; import.Cmd_Args = Cmd_Args; import.AddCommandString = Cbuf_AddText; import.seed = Sys_Milliseconds(); import.csi = &csi; /* import the server routing table */ import.routingMap = sv->mapData.map; svs.ge = SV_GetGameAPI(&import); if (!svs.ge) Com_Error(ERR_DROP, "failed to load game library"); if (svs.ge->apiversion != GAME_API_VERSION) Com_Error(ERR_DROP, "game is version %i, not %i", svs.ge->apiversion, GAME_API_VERSION); sv->gameSysPool = Mem_CreatePool("Server: Game system"); svs.ge->Init(); if (sv_threads->integer) { svs.gameFrameCond = SDL_CreateCond(); svs.gameThread = SDL_CreateThread(SV_RunGameFrameThread, NULL); } }
static int CL_Milliseconds( void ) { return Sys_Milliseconds(); }
int Sys_Milliseconds2( void ) { return Sys_Milliseconds(false); }
/* ======================== idSoundVoice_OpenAL::Start ======================== */ void idSoundVoice_OpenAL::Start( int offsetMS, int ssFlags ) { if( s_debugHardware.GetBool() ) { idLib::Printf( "%dms: %i starting %s @ %dms\n", Sys_Milliseconds(), openalSource, leadinSample ? leadinSample->GetName() : "<null>", offsetMS ); } if( !leadinSample ) { return; } if( !alIsSource( openalSource ) ) { return; } if( leadinSample->IsDefault() ) { idLib::Warning( "Starting defaulted sound sample %s", leadinSample->GetName() ); } bool flicker = ( ssFlags & SSF_NO_FLICKER ) == 0; if( flicker != hasVUMeter ) { hasVUMeter = flicker; /* if( flicker ) { IUnknown* vuMeter = NULL; if( XAudio2CreateVolumeMeter( &vuMeter, 0 ) == S_OK ) { XAUDIO2_EFFECT_DESCRIPTOR descriptor; descriptor.InitialState = true; descriptor.OutputChannels = leadinSample->NumChannels(); descriptor.pEffect = vuMeter; XAUDIO2_EFFECT_CHAIN chain; chain.EffectCount = 1; chain.pEffectDescriptors = &descriptor; pSourceVoice->SetEffectChain( &chain ); vuMeter->Release(); } } else { pSourceVoice->SetEffectChain( NULL ); } */ } assert( offsetMS >= 0 ); int offsetSamples = MsecToSamples( offsetMS, leadinSample->SampleRate() ); if( loopingSample == NULL && offsetSamples >= leadinSample->playLength ) { return; } RestartAt( offsetSamples ); Update(); UnPause(); }