bool IdleAnimationTask::AnimIsApplicable(idAI* owner, const idStr& animName) { int torsoAnimNum = owner->GetAnim(ANIMCHANNEL_TORSO, animName); if (torsoAnimNum == 0) { gameLocal.Warning("Could not find anim %s on entity %s", animName.c_str(), owner->name.c_str()); DM_LOG(LC_AI, LT_ERROR)LOGSTRING("Could not find anim %s on entity %s\r", animName.c_str(), owner->name.c_str()); return false; } // Check if this anim interferes with random head turning if ( owner->GetMemory().currentlyHeadTurning && AnimHasNoHeadTurnFlag(owner, torsoAnimNum) ) { // gameLocal.Printf("Inhibited idle animation %s, since random head turning is active.\n", animName.c_str()); // Cannot play this one at this point return false; } // grayman #3182 - Check if this anim plays a voice bark, which would interfere with ongoing voice barks if ( owner->GetMemory().currentlyBarking && AnimHasVoiceFlag(owner, animName) ) { // gameLocal.Printf("Inhibited idle animation %s, since barking is active.\n", animName.c_str()); // Cannot play this one at this point return false; } // OK return true; }
CZipFilePtr CZipLoader::OpenFile(const idStr& fullOSPath) { DM_LOG(LC_MAINMENU, LT_DEBUG)LOGSTRING("Attempting to open file as ZIP: %s.\r", fullOSPath.c_str()); unzFile handle = unzOpen(fullOSPath.c_str()); return (handle != NULL) ? CZipFilePtr(new CZipFile(handle)) : CZipFilePtr(); }
/* ================ Sys_DefaultBasePath Get the default base path - binary image path - current directory - hardcoded Try to be intelligent: if there is no BASE_GAMEDIR, try the next path ================ */ const char *Sys_DefaultBasePath( void ) { struct stat st; idStr testbase; basepath = Sys_EXEPath(); if( basepath.Length() ) { basepath.StripFilename(); testbase = basepath; testbase += "/"; testbase += BASE_GAMEDIR; if( stat( testbase.c_str(), &st ) != -1 && S_ISDIR( st.st_mode ) ) { return basepath.c_str(); } else { common->Printf( "no '%s' directory in exe path %s, skipping\n", BASE_GAMEDIR, basepath.c_str() ); } } if( basepath != Posix_Cwd() ) { basepath = Posix_Cwd(); testbase = basepath; testbase += "/"; testbase += BASE_GAMEDIR; if( stat( testbase.c_str(), &st ) != -1 && S_ISDIR( st.st_mode ) ) { return basepath.c_str(); } else { common->Printf( "no '%s' directory in cwd path %s, skipping\n", BASE_GAMEDIR, basepath.c_str() ); } } common->Printf( "WARNING: using hardcoded default base path\n" ); return LINUX_DEFAULT_PATH; }
/* ============ idInternalCVar::Set ============ */ void idInternalCVar::Set( const char *newValue, bool force, bool fromServer ) { if ( session && session->IsMultiplayer() && !fromServer ) { #ifndef ID_TYPEINFO if ( ( flags & CVAR_NETWORKSYNC ) && idAsyncNetwork::client.IsActive() ) { common->Printf( "%s is a synced over the network and cannot be changed on a multiplayer client.\n", nameString.c_str() ); #if ID_ALLOW_CHEATS common->Printf( "ID_ALLOW_CHEATS override!\n" ); #else return; #endif } #endif if ( ( flags & CVAR_CHEAT ) && !cvarSystem->GetCVarBool( "net_allowCheats" ) ) { common->Printf( "%s cannot be changed in multiplayer.\n", nameString.c_str() ); #if ID_ALLOW_CHEATS common->Printf( "ID_ALLOW_CHEATS override!\n" ); #else return; #endif } } if ( !newValue ) { newValue = resetString.c_str(); } if ( !force ) { if ( flags & CVAR_ROM ) { common->Printf( "%s is read only.\n", nameString.c_str() ); return; } if ( flags & CVAR_INIT ) { common->Printf( "%s is write protected.\n", nameString.c_str() ); return; } } if ( valueString.Icmp( newValue ) == 0 ) { return; } valueString = newValue; value = valueString.c_str(); UpdateValue(); SetModified(); cvarSystem->SetModifiedFlags( flags ); }
void Mind::PushState( const idStr &stateName ) { // Get a new state with the given name StatePtr newState = StateLibrary::Instance().CreateInstance( stateName.c_str() ); if( newState != NULL ) { PushState( newState ); } else { gameLocal.Error( "Mind: Could not push state %s", stateName.c_str() ); } }
/* ============ idInternalCVar::Update ============ */ void idInternalCVar::Update( const idCVar *cvar ) { // if this is a statically declared variable if ( cvar->GetFlags() & CVAR_STATIC ) { if ( flags & CVAR_STATIC ) { // the code has more than one static declaration of the same variable, make sure they have the same properties if ( resetString.Icmp( cvar->GetString() ) != 0 ) { common->Warning( "CVar '%s' declared multiple times with different initial value", nameString.c_str() ); } if ( ( flags & (CVAR_BOOL|CVAR_INTEGER|CVAR_FLOAT) ) != ( cvar->GetFlags() & (CVAR_BOOL|CVAR_INTEGER|CVAR_FLOAT) ) ) { common->Warning( "CVar '%s' declared multiple times with different type", nameString.c_str() ); } if ( valueMin != cvar->GetMinValue() || valueMax != cvar->GetMaxValue() ) { common->Warning( "CVar '%s' declared multiple times with different minimum/maximum", nameString.c_str() ); } } // the code is now specifying a variable that the user already set a value for, take the new value as the reset value resetString = cvar->GetString(); descriptionString = cvar->GetDescription(); description = descriptionString.c_str(); valueMin = cvar->GetMinValue(); valueMax = cvar->GetMaxValue(); Mem_Free( valueStrings ); valueStrings = CopyValueStrings( cvar->GetValueStrings() ); valueCompletion = cvar->GetValueCompletion(); UpdateValue(); cvarSystem->SetModifiedFlags( cvar->GetFlags() ); } flags |= cvar->GetFlags(); UpdateCheat(); // only allow one non-empty reset string without a warning if ( resetString.Length() == 0 ) { resetString = cvar->GetString(); } else if ( cvar->GetString()[0] && resetString.Cmp( cvar->GetString() ) != 0 ) { common->Warning( "cvar \"%s\" given initial values: \"%s\" and \"%s\"\n", nameString.c_str(), resetString.c_str(), cvar->GetString() ); } }
/* ======================== idMenuScreen_HUD::TriggerHitTarget ======================== */ void idMenuScreen_HUD::TriggerHitTarget( bool show, const idStr & target, int color ) { if ( !mpHitInfo ) { return; } if ( show ) { mpHitInfo->SetVisible( true ); mpHitInfo->PlayFrame( "rollOn" ); if ( menuGUI ) { menuGUI->SetGlobal( "hitTargetName", target.c_str() ); } idSWFSpriteInstance * backing = mpHitInfo->GetScriptObject()->GetNestedSprite( "bgColor" ); if ( backing ) { if ( color <= 0 || !gameLocal.mpGame.IsGametypeTeamBased() ) { color = 1; } backing->StopFrame( color ); } } else { mpHitInfo->PlayFrame( "rollOff" ); } }
idStr CZipFile::LoadTextFile(const idStr& fileName) { int result = unzLocateFile(_handle, fileName.c_str(), 0); if (result != UNZ_OK) return ""; unz_file_info info; unzGetCurrentFileInfo(_handle, &info, NULL, 0, NULL, 0, NULL, 0); unsigned long fileSize = info.uncompressed_size; int openResult = unzOpenCurrentFile(_handle); idStr returnValue; if (openResult == UNZ_OK) { char* buffer = new char[fileSize + 1]; // Read and null-terminate the string unzReadCurrentFile(_handle, buffer, fileSize); buffer[fileSize] = '\0'; returnValue = buffer; delete[] buffer; } unzCloseCurrentFile(_handle); return returnValue; }
/* ================ idCameraPosition::parseToken ================ */ bool idCameraPosition::parseToken( const idStr &key, idParser *src ) { idToken token; if ( !key.Icmp( "time" ) ) { time = src->ParseInt(); return true; } else if ( !key.Icmp( "type" ) ) { type = static_cast<idCameraPosition::positionType> ( src->ParseInt() ); return true; } else if ( !key.Icmp( "velocity" ) ) { long t = atol(token); long d = src->ParseInt(); float s = src->ParseFloat(); addVelocity(t, d, s); return true; } else if ( !key.Icmp( "baseVelocity" ) ) { baseVelocity = src->ParseFloat(); return true; } else if ( !key.Icmp( "name" ) ) { src->ReadToken( &token ); name = token; return true; } else { src->Error( "unknown camera position key: %s", key.c_str() ); return false; } }
/* ======================== Sys_SaveGameCheck ======================== */ void Sys_SaveGameCheck( bool & exists, bool & autosaveExists ) { exists = false; autosaveExists = false; const idStr autosaveFolderStr = AddSaveFolderPrefix( SAVEGAME_AUTOSAVE_FOLDER, idSaveGameManager::PACKAGE_GAME ); const char * autosaveFolder = autosaveFolderStr.c_str(); const char * saveFolder = "savegame"; if ( fileSystem->IsFolder( saveFolder, "fs_savePath" ) == FOLDER_YES ) { idFileList * files = fileSystem->ListFiles( saveFolder, "/" ); const idStrList & fileList = files->GetList(); idLib::PrintfIf( saveGame_verbose.GetBool(), "found %d savegames\n", fileList.Num() ); for ( int i = 0; i < fileList.Num(); i++ ) { const char * directory = va( "%s/%s", saveFolder, fileList[i].c_str() ); if ( fileSystem->IsFolder( directory, "fs_savePath" ) == FOLDER_YES ) { exists = true; idLib::PrintfIf( saveGame_verbose.GetBool(), "found savegame: %s\n", fileList[i].c_str() ); if ( idStr::Icmp( fileList[i].c_str(), autosaveFolder ) == 0 ) { autosaveExists = true; break; } } } fileSystem->FreeFileList( files ); } }
/* ==================== idModelExport::ExportModel ==================== */ bool idModelExport::ExportModel( const char *model ) { // RAVEN BEGIN // scork: MayaConversionCleaner _any_old_name; // RAVEN END const char *game = cvarSystem->GetCVarString( "fs_game" ); if ( strlen(game) == 0 ) { game = BASE_GAMEDIR; } Reset(); src = model; dest = model; dest.SetFileExtension( MD5_MESH_EXT ); sprintf( commandLine, "mesh %s -dest %s -game %s", src.c_str(), dest.c_str(), game ); if ( !ConvertMayaToMD5() ) { gameLocal.Printf( "Failed to export '%s' : %s", src.c_str(), Maya_Error.c_str() ); return false; } return true; }
/* ============ idAASLocal::Init ============ */ bool idAASLocal::Init( const idStr &mapName, unsigned int mapFileCRC ) { if ( file && mapName.Icmp( file->GetName() ) == 0 && mapFileCRC == file->GetCRC() ) { gameLocal.Printf( "Keeping %s\n", file->GetName() ); RemoveAllObstacles(); } else { Shutdown(); file = AASFileManager->LoadAAS( mapName, mapFileCRC ); if ( !file ) { common->DWarning( "Couldn't load AAS file: '%s'", mapName.c_str() ); return false; } // RAVEN BEGIN // rhummer: Check if this is a dummy file, since it really has no valid data dump it. else if ( file->IsDummyFile( mapFileCRC ) ) { AASFileManager->FreeAAS( file ); file = NULL; return false; } // RAVEN END SetupRouting(); } return true; }
/* ============== Sys_DefaultSavePath ============== */ const char *Sys_DefaultSavePath( void ) { #if defined( ID_DEMO_BUILD ) sprintf( savepath, "%s/.doom3-demo", getenv( "HOME" ) ); #else sprintf( savepath, "%s/.doom3", getenv( "HOME" ) ); #endif return savepath.c_str(); }
bool CZipFile::ExtractFileTo(const idStr& fileName, const idStr& destPath) { bool returnValue = true; int result = unzLocateFile(_handle, fileName.c_str(), 0); if (result != UNZ_OK) return false; // Try to open the destination path before uncompressing the file FILE* outFile = fopen(destPath.c_str(), "wb"); if (outFile == NULL) { // couldn't open file for writing DM_LOG(LC_MAINMENU, LT_ERROR)LOGSTRING("Couldn't extract %s file to %s.\r", fileName.c_str(), destPath.c_str()); return false; } unz_file_info info; unzGetCurrentFileInfo(_handle, &info, NULL, 0, NULL, 0, NULL, 0); unsigned long fileSize = info.uncompressed_size; int openResult = unzOpenCurrentFile(_handle); if (openResult == UNZ_OK) { unsigned char* buffer = new unsigned char[fileSize]; // Read and null-terminate the string unzReadCurrentFile(_handle, buffer, fileSize); fwrite(buffer, 1, fileSize, outFile); delete[] buffer; } else { returnValue = false; // fopen failed } fclose(outFile); unzCloseCurrentFile(_handle); return returnValue; }
/* ============ sdGameRulesStopWatch::GetDemoNameInfo ============ */ const char* sdGameRulesStopWatch::GetDemoNameInfo( void ) { static idStr demoNameBuffer; if ( progression == GP_FIRST_MATCH ) { demoNameBuffer = va( "stopwatch_first" ); } else { demoNameBuffer = va( "stopwatch_second" ); } return demoNameBuffer.c_str(); }
bool Sys_GetPath(sysPath_t type, idStr &path) { char buf[MAX_OSPATH]; struct _stat st; idStr s; switch(type) { case PATH_BASE: // try <path to exe>/base first if (Sys_GetPath(PATH_EXE, path)) { path.StripFilename(); s = path; s.AppendPath(BASE_GAMEDIR); if (_stat(s.c_str(), &st) != -1 && st.st_mode & _S_IFDIR) return true; common->Warning("base path '%s' does not exits", s.c_str()); } // fallback to vanilla doom3 cd install if (GetRegistryPath(buf, sizeof(buf), L"SOFTWARE\\id\\Doom 3", L"InstallPath") > 0) { path = buf; return true; } // fallback to steam doom3 install if (GetRegistryPath(buf, sizeof(buf), L"SOFTWARE\\Valve\\Steam", L"InstallPath") > 0) { path = buf; path.AppendPath("steamapps\\common\\doom 3"); if (_stat(path.c_str(), &st) != -1 && st.st_mode & _S_IFDIR) return true; } common->Warning("vanilla doom3 path not found"); return false; case PATH_CONFIG: case PATH_SAVE: if (GetHomeDir(buf, sizeof(buf)) < 1) { Sys_Error("ERROR: Couldn't get dir to home path"); return false; } path = buf; return true; case PATH_EXE: GetModuleFileName(NULL, buf, sizeof(buf) - 1); path = buf; path.BackSlashesToSlashes(); return true; } return false; }
TimerValue CStimResponseTimer::ParseTimeString( idStr &str ) { TimerValue v; int h, m, s, ms; idStr source = str; v.Time.Flags = TIMER_UNDEFINED; if( str.Length() == 0 ) { goto Quit; } h = m = s = ms = 0; // Get the first few characters that define the hours h = atoi( source.Left( source.Find( ":" ) ).c_str() ); // Strip the first few numbers plus the colon from the source string source = source.Right( source.Length() - source.Find( ":" ) - 1 ); // Parse the minutes m = atoi( source.Left( source.Find( ":" ) ).c_str() ); if( !( m >= 0 && m <= 59 ) ) { DM_LOG( LC_STIM_RESPONSE, LT_ERROR )LOGSTRING( "Invalid minute string [%s]\r", str.c_str() ); goto Quit; } // Strip the first few numbers plus the colon from the source string source = source.Right( source.Length() - source.Find( ":" ) - 1 ); // Parse the seconds s = atoi( source.Left( source.Find( ":" ) ).c_str() ); if( !( s >= 0 && s <= 59 ) ) { DM_LOG( LC_STIM_RESPONSE, LT_ERROR )LOGSTRING( "Invalid second string [%s]\r", str.c_str() ); goto Quit; } // Parse the milliseconds, this is the remaining part of the string ms = atoi( source.Right( source.Length() - source.Find( ":" ) - 1 ).c_str() ); if( !( ms >= 0 && ms <= 999 ) ) { DM_LOG( LC_STIM_RESPONSE, LT_ERROR )LOGSTRING( "Invalid millisecond string [%s]\r", str.c_str() ); goto Quit; } DM_LOG( LC_STIM_RESPONSE, LT_DEBUG )LOGSTRING( "Parsed timer string: [%s] to %d:%d:%d:%d\r", str.c_str(), h, m, s, ms ); v.Time.Hour = h; v.Time.Minute = m; v.Time.Second = s; v.Time.Millisecond = ms; Quit: return v; }
CShopItemPtr CShop::FindShopItemDefByClassName( const idStr &className ) { CShopItemPtr found = FindByID( _itemDefs, className ); if( found != NULL ) { return found; } // Check if we should run another search if( idStr::Cmpn( className.c_str(), "atdm:", 5 ) == 0 ) { return CShopItemPtr(); // atdm is already prepended, return empty } // Try again with "atdm:" prepended return FindByID( _itemDefs, "atdm:" + className ); }
/* ============== Sys_DefaultSavePath ============== */ const char* Sys_DefaultSavePath() { #if defined(__APPLE__) char* base_path = SDL_GetPrefPath( "", "RBDOOM-3-BFG" ); if( base_path ) { savepath = SDL_strdup( base_path ); SDL_free( base_path ); } #else sprintf( savepath, "%s/.rbdoom3bfg", getenv( "HOME" ) ); #endif return savepath.c_str(); }
/* ============ idAASLocal::Init ============ */ bool idAASLocal::Init( const idStr &mapName, unsigned int mapFileCRC ) { if( file && mapName.Icmp( file->GetName() ) == 0 && mapFileCRC == file->GetCRC() ) { common->Printf( "Keeping %s\n", file->GetName() ); RemoveAllObstacles(); } else { Shutdown(); file = AASFileManager->LoadAAS( mapName, mapFileCRC ); if( !file ) { common->DWarning( "Couldn't load AAS file: '%s'", mapName.c_str() ); return false; } SetupRouting(); } return true; }
/* ==================== idModelExport::ExportModel ==================== */ bool idModelExport::ExportModel( const char *model ) { const char *game = cvarSystem->GetCVarString( "fs_currentfm" ); if( strlen( game ) == 0 ) { game = BASE_TDM; } Reset(); src = model; dest = model; dest.SetFileExtension( MD5_MESH_EXT ); sprintf( commandLine, "mesh %s -dest %s -game %s", src.c_str(), dest.c_str(), game ); if( !ConvertMayaToMD5() ) { gameLocal.Printf( "Failed to export '%s' : %s", src.c_str(), Maya_Error.c_str() ); return false; } return true; }
/* ==================== idModelExport::ExportAnim ==================== */ bool idModelExport::ExportAnim( const char *anim ) { const char *game = cvarSystem->GetCVarString( "fs_game" ); if( strlen( game ) == 0 ) { game = BASE_GAMEDIR; } Reset(); src = anim; dest = anim; dest.SetFileExtension( MD5_ANIM_EXT ); sprintf( commandLine, "anim %s -dest %s -game %s", src.c_str(), dest.c_str(), game ); if( !ConvertMayaToMD5() ) { gameLocal.Printf( "Failed to export '%s' : %s", src.c_str(), Maya_Error.c_str() ); return false; } return true; }
void CInventoryItem::SetHUD(const idStr &HudName, int layer) { DM_LOG(LC_INVENTORY, LT_DEBUG)LOGSTRING("Setting hud %s on layer %d\r", HudName.c_str(), layer); if (m_Overlay == OVERLAYS_INVALID_HANDLE || m_HudName != HudName) { idEntity *owner = GetOwner(); m_Hud = true; m_HudName = HudName; m_Overlay = owner->CreateOverlay(HudName, layer); idEntity* it = m_Item.GetEntity(); if (it != NULL) { it->CallScriptFunctionArgs("inventory_item_init", true, 0, "eefs", it, owner, (float)m_Overlay, HudName.c_str()); } } NotifyItemChanged(); }
/* ==================== idModelExport::ExportAnim ==================== */ bool idModelExport::ExportAnim( const char *anim ) { // RAVEN BEGIN // scork: MayaConversionCleaner _any_old_name; // RAVEN END Reset(); src = anim; dest = anim; dest.SetFileExtension( MD5_ANIM_EXT ); sprintf( commandLine, "anim %s -dest %s -game %s", src.c_str(), dest.c_str(), CD_BASEDIR ); if ( !ConvertMayaToMD5() ) { gameLocal.Printf( "Failed to export '%s' : %s", src.c_str(), Maya_Error.c_str() ); return false; } return true; }
/* ============ idAASLocal::Init ============ */ bool idAASLocal::Init( const idStr &mapName, const unsigned int mapFileCRC ) { // Clear the elevator system before reloading elevatorSystem->Clear(); if ( file && mapName.Icmp( file->GetName() ) == 0 && mapFileCRC == file->GetCRC() ) { common->Printf( "Keeping %s\n", file->GetName() ); RemoveAllObstacles(); } else { Shutdown(); file = AASFileManager->LoadAAS( mapName, mapFileCRC ); if ( !file ) { common->DWarning( "Couldn't load AAS file: '%s'", mapName.c_str() ); return false; } mapName.ExtractFileExtension(name); SetupRouting(); } return true; }
/* ======================== idZipBuilder::GetFileTime ======================== */ bool idZipBuilder::GetFileTime( const idStr& filename, unsigned long* dostime ) const { // RB: FIXME #if defined(_WIN32) { FILETIME filetime; WIN32_FIND_DATA fileData; HANDLE findHandle = FindFirstFile( filename.c_str(), &fileData ); if( findHandle != INVALID_HANDLE_VALUE ) { FileTimeToLocalFileTime( &( fileData.ftLastWriteTime ), &filetime ); FileTimeToDosDateTime( &filetime, ( ( LPWORD )dostime ) + 1, ( ( LPWORD )dostime ) + 0 ); FindClose( findHandle ); return true; } FindClose( findHandle ); } #endif // RB end return false; }
/* ================ idCommonLocal::StartPlayingRenderDemo ================ */ void idCommonLocal::StartPlayingRenderDemo( idStr demoName ) { if ( !demoName[0] ) { common->Printf( "idCommonLocal::StartPlayingRenderDemo: no name specified\n" ); return; } // make sure localSound / GUI intro music shuts up soundWorld->StopAllSounds(); soundWorld->PlayShaderDirectly( "", 0 ); menuSoundWorld->StopAllSounds(); menuSoundWorld->PlayShaderDirectly( "", 0 ); // exit any current game Stop(); // automatically put the console away console->Close(); readDemo = new (TAG_SYSTEM) idDemoFile; demoName.DefaultFileExtension( ".demo" ); if ( !readDemo->OpenForReading( demoName ) ) { common->Printf( "couldn't open %s\n", demoName.c_str() ); delete readDemo; readDemo = NULL; Stop(); StartMenu(); return; } const bool captureToImage = false; UpdateScreen( captureToImage ); AdvanceRenderDemo( true ); numDemoFrames = 1; timeDemoStartTime = Sys_Milliseconds(); }
void Mind::PrintStateQueue( idStr string ) { DM_LOG( LC_STATE, LT_DEBUG )LOGSTRING( "%s's _stateQueue after %s:\r", _owner.GetEntity()->GetName(), string.c_str() ); DM_LOG( LC_STATE, LT_DEBUG )LOGSTRING( "%s", _stateQueue.DebuggingInfo().c_str() ); }
void Mind::SwitchState( const idStr &stateName ) { if( _stateQueue.size() > 0 ) { DM_LOG( LC_AI, LT_INFO )LOGSTRING( "Mind::SwitchState - %s switching from %s to %s\r", _owner.GetEntity()->name.c_str(), _stateQueue.front()->GetName().c_str(), stateName.c_str() ); } else { DM_LOG( LC_AI, LT_INFO )LOGSTRING( "Mind::SwitchState - %s switching to %s\r", _owner.GetEntity()->name.c_str(), stateName.c_str() ); } // greebo: Switch the state without destroying the current State object immediately if( _stateQueue.size() > 0 ) { // Store the shared_ptr in the temporary container _recycleBin = _stateQueue.front(); // Remove the first element from the queue _stateQueue.pop_front(); //PrintStateQueue("pop"); } // Add the new task PushState( stateName ); }
/* =================== GLimp_Init This is the platform specific OpenGL initialization function. It is responsible for loading OpenGL, initializing it, creating a window of the appropriate size, doing fullscreen manipulations, etc. Its overall responsibility is to make sure that a functional OpenGL subsystem is operating when it returns to the ref. If there is any failure, the renderer will revert back to safe parameters and try again. =================== */ bool GLimp_Init( glimpParms_t parms ) { const char* driverName; HDC hDC; cmdSystem->AddCommand( "testSwapBuffers", GLimp_TestSwapBuffers, CMD_FL_SYSTEM, "Times swapbuffer options" ); common->Printf( "Initializing OpenGL subsystem with multisamples:%i stereo:%i fullscreen:%i\n", parms.multiSamples, parms.stereo, parms.fullScreen ); // check our desktop attributes hDC = GetDC( GetDesktopWindow() ); win32.desktopBitsPixel = GetDeviceCaps( hDC, BITSPIXEL ); win32.desktopWidth = GetDeviceCaps( hDC, HORZRES ); win32.desktopHeight = GetDeviceCaps( hDC, VERTRES ); ReleaseDC( GetDesktopWindow(), hDC ); // we can't run in a window unless it is 32 bpp if( win32.desktopBitsPixel < 32 && parms.fullScreen <= 0 ) { common->Printf( "^3Windowed mode requires 32 bit desktop depth^0\n" ); return false; } // save the hardware gamma so it can be // restored on exit GLimp_SaveGamma(); // create our window classes if we haven't already GLW_CreateWindowClasses(); // this will load the dll and set all our qgl* function pointers, // but doesn't create a window // r_glDriver is only intended for using instrumented OpenGL // dlls. Normal users should never have to use it, and it is // not archived. driverName = r_glDriver.GetString()[0] ? r_glDriver.GetString() : "opengl32"; if( !QGL_Init( driverName ) ) { common->Printf( "^3GLimp_Init() could not load r_glDriver \"%s\"^0\n", driverName ); return false; } // getting the wgl extensions involves creating a fake window to get a context, // which is pretty disgusting, and seems to mess with the AGP VAR allocation GLW_GetWGLExtensionsWithFakeWindow(); // Optionally ChangeDisplaySettings to get a different fullscreen resolution. if( !GLW_ChangeDislaySettingsIfNeeded( parms ) ) { GLimp_Shutdown(); return false; } // try to create a window with the correct pixel format // and init the renderer context if( !GLW_CreateWindow( parms ) ) { GLimp_Shutdown(); return false; } glConfig.isFullscreen = parms.fullScreen; glConfig.isStereoPixelFormat = parms.stereo; glConfig.nativeScreenWidth = parms.width; glConfig.nativeScreenHeight = parms.height; glConfig.multisamples = parms.multiSamples; glConfig.pixelAspect = 1.0f; // FIXME: some monitor modes may be distorted // should side-by-side stereo modes be consider aspect 0.5? // get the screen size, which may not be reliable... // If we use the windowDC, I get my 30" monitor, even though the window is // on a 27" monitor, so get a dedicated DC for the full screen device name. const idStr deviceName = GetDeviceName( Max( 0, parms.fullScreen - 1 ) ); HDC deviceDC = CreateDC( deviceName.c_str(), deviceName.c_str(), NULL, NULL ); const int mmWide = GetDeviceCaps( win32.hDC, HORZSIZE ); DeleteDC( deviceDC ); if( mmWide == 0 ) { glConfig.physicalScreenWidthInCentimeters = 100.0f; } else { glConfig.physicalScreenWidthInCentimeters = 0.1f * mmWide; } // wglSwapinterval, etc GLW_CheckWGLExtensions( win32.hDC ); // check logging GLimp_EnableLogging( ( r_logFile.GetInteger() != 0 ) ); return true; }