//----------------------------------------------------------------------------- // Purpose: Called to Shutdown the game UI system //----------------------------------------------------------------------------- void CGameUI::Shutdown() { // notify all the modules of Shutdown g_VModuleLoader.ShutdownPlatformModules(); // unload the modules them from memory g_VModuleLoader.UnloadPlatformModules(); ModInfo().FreeModInfo(); // release platform mutex // close the mutex if (g_hMutex) { Sys_ReleaseMutex(g_hMutex); } if (g_hWaitMutex) { Sys_ReleaseMutex(g_hWaitMutex); } steamapicontext->Clear(); #ifndef _X360 // SteamAPI_Shutdown(); << Steam shutdown is controlled by engine #endif ConVar_Unregister(); DisconnectTier3Libraries(); DisconnectTier2Libraries(); DisconnectTier1Libraries(); }
BOOL Mutex::unlock() { g_DebugMutex[counter_] = 1; BOOL rc = Sys_ReleaseMutex(hObject_); g_DebugMutex[counter_] = 0; return rc; }
//----------------------------------------------------------------------------- // Purpose: Called to Shutdown the game UI system //----------------------------------------------------------------------------- void CGameUI::Shutdown() { // notify all the modules of Shutdown g_VModuleLoader.ShutdownPlatformModules(); // unload the modules them from memory g_VModuleLoader.UnloadPlatformModules(); // free mod info ModInfo().FreeModInfo(); // release platform mutex // close the mutex if (g_hMutex) { Sys_ReleaseMutex(g_hMutex); } if (g_hWaitMutex) { Sys_ReleaseMutex(g_hWaitMutex); } }
BOOL Mutex::unlock() { #ifdef DEBUG_MUTEXES_ g_DebugMutex[counter_] = 1; #endif BOOL rc = Sys_ReleaseMutex(hObject_); #ifdef DEBUG_MUTEXES_ g_DebugMutex[counter_] = 0; #endif return rc; }
//----------------------------------------------------------------------------- // Purpose: paints all the vgui elements //----------------------------------------------------------------------------- void CGameUI::RunFrame() { if ( IsX360() && m_bOpenProgressOnStart ) { StartProgressBar(); m_bOpenProgressOnStart = false; } int wide, tall; #if defined( TOOLFRAMEWORK_VGUI_REFACTOR ) // resize the background panel to the screen size vgui::VPANEL clientDllPanel = enginevguifuncs->GetPanel( PANEL_ROOT ); int x, y; vgui::ipanel()->GetPos( clientDllPanel, x, y ); vgui::ipanel()->GetSize( clientDllPanel, wide, tall ); staticPanel->SetBounds( x, y, wide,tall ); #else vgui::surface()->GetScreenSize(wide, tall); GetUiBaseModPanelClass().SetSize(wide, tall); #endif // Run frames g_VModuleLoader.RunFrame(); GetUiBaseModPanelClass().RunFrame(); // Play the start-up music the first time we run frame if ( IsPC() && m_iPlayGameStartupSound > 0 ) { m_iPlayGameStartupSound--; if ( !m_iPlayGameStartupSound ) { PlayGameStartupSound(); } } if ( IsPC() && m_bTryingToLoadFriends && m_iFriendsLoadPauseFrames-- < 1 && g_hMutex && g_hWaitMutex ) { // try and load Steam platform files unsigned int waitResult = Sys_WaitForSingleObject(g_hMutex, 0); if (waitResult == SYS_WAIT_OBJECT_0 || waitResult == SYS_WAIT_ABANDONED) { // we got the mutex, so load Friends/Serverbrowser // clear the loading flag m_bTryingToLoadFriends = false; g_VModuleLoader.LoadPlatformModules(&m_GameFactory, 1, false); // release the wait mutex Sys_ReleaseMutex(g_hWaitMutex); // notify the game of our game name const char *fullGamePath = engine->GetGameDirectory(); const char *pathSep = strrchr( fullGamePath, '/' ); if ( !pathSep ) { pathSep = strrchr( fullGamePath, '\\' ); } if ( pathSep ) { KeyValues *pKV = new KeyValues("ActiveGameName" ); pKV->SetString( "name", pathSep + 1 ); pKV->SetInt( "appid", engine->GetAppID() ); KeyValues *modinfo = new KeyValues("ModInfo"); if ( modinfo->LoadFromFile( g_pFullFileSystem, "gameinfo.txt" ) ) { pKV->SetString( "game", modinfo->GetString( "game", "" ) ); } modinfo->deleteThis(); g_VModuleLoader.PostMessageToAllModules( pKV ); } // notify the ui of a game connect if we're already in a game if (m_iGameIP) { SendConnectedToGameMessage(); } } } }
//----------------------------------------------------------------------------- // Purpose: Called to setup the game UI //----------------------------------------------------------------------------- void CGameUI::Start() { // determine Steam location for configuration if ( !FindPlatformDirectory( m_szPlatformDir, sizeof( m_szPlatformDir ) ) ) return; if ( IsPC() ) { // setup config file directory char szConfigDir[512]; Q_strncpy( szConfigDir, m_szPlatformDir, sizeof( szConfigDir ) ); Q_strncat( szConfigDir, "config", sizeof( szConfigDir ), COPY_ALL_CHARACTERS ); Msg( "Steam config directory: %s\n", szConfigDir ); g_pFullFileSystem->AddSearchPath(szConfigDir, "CONFIG"); g_pFullFileSystem->CreateDirHierarchy("", "CONFIG"); // user dialog configuration vgui::system()->SetUserConfigFile("InGameDialogConfig.vdf", "CONFIG"); g_pFullFileSystem->AddSearchPath( "platform", "PLATFORM" ); } // localization g_pVGuiLocalize->AddFile( "Resource/platform_%language%.txt"); g_pVGuiLocalize->AddFile( "Resource/vgui_%language%.txt"); Sys_SetLastError( SYS_NO_ERROR ); if ( IsPC() ) { g_hMutex = Sys_CreateMutex( "ValvePlatformUIMutex" ); g_hWaitMutex = Sys_CreateMutex( "ValvePlatformWaitMutex" ); if ( g_hMutex == NULL || g_hWaitMutex == NULL || Sys_GetLastError() == SYS_ERROR_INVALID_HANDLE ) { // error, can't get handle to mutex if (g_hMutex) { Sys_ReleaseMutex(g_hMutex); } if (g_hWaitMutex) { Sys_ReleaseMutex(g_hWaitMutex); } g_hMutex = NULL; g_hWaitMutex = NULL; Error("Steam Error: Could not access Steam, bad mutex\n"); return; } unsigned int waitResult = Sys_WaitForSingleObject(g_hMutex, 0); if (!(waitResult == SYS_WAIT_OBJECT_0 || waitResult == SYS_WAIT_ABANDONED)) { // mutex locked, need to deactivate Steam (so we have the Friends/ServerBrowser data files) // get the wait mutex, so that Steam.exe knows that we're trying to acquire ValveTrackerMutex waitResult = Sys_WaitForSingleObject(g_hWaitMutex, 0); if (waitResult == SYS_WAIT_OBJECT_0 || waitResult == SYS_WAIT_ABANDONED) { Sys_EnumWindows(SendShutdownMsgFunc, 1); } } // Delay playing the startup music until two frames // this allows cbuf commands that occur on the first frame that may start a map m_iPlayGameStartupSound = 2; // now we are set up to check every frame to see if we can friends/server browser m_bTryingToLoadFriends = true; m_iFriendsLoadPauseFrames = 1; } }
//----------------------------------------------------------------------------- // Purpose: paints all the vgui elements //----------------------------------------------------------------------------- void CGameUI::RunFrame() { // resize the background panel to the screen size int wide, tall; vgui::surface()->GetScreenSize(wide, tall); staticPanel->SetSize(wide,tall); // Run frames g_VModuleLoader.RunFrame(); if (g_pTaskbar) { g_pTaskbar->RunFrame(); } if (m_bTryingToLoadTracker && g_hMutex && g_hWaitMutex) { // try and load tracker unsigned int waitResult = Sys_WaitForSingleObject(g_hMutex, 0); if (waitResult == SYS_WAIT_OBJECT_0 || waitResult == SYS_WAIT_ABANDONED) { // we got the tracker mutex, so load tracker // clear the loading flag m_bTryingToLoadTracker = false; g_VModuleLoader.LoadPlatformModules(m_FactoryList, m_iNumFactories, false); // get our own interfaces for (int i = 0; i < g_VModuleLoader.GetModuleCount(); i++) { if (!g_pFriendsUser && g_VModuleLoader.GetModuleFactory(i) ) { g_pFriendsUser = (IFriendsUser *)(g_VModuleLoader.GetModuleFactory(i))(FRIENDSUSER_INTERFACE_VERSION, NULL); } } // release the wait mutex Sys_ReleaseMutex(g_hWaitMutex); // notify the game of our game name const char *fullGamePath = engine->GetGameDirectory(); const char *pathSep = strrchr( fullGamePath, '/' ); if ( !pathSep ) { pathSep = strrchr( fullGamePath, '\\' ); } if ( pathSep ) { g_VModuleLoader.PostMessageToAllModules(new KeyValues("ActiveGameName", "name", pathSep + 1)); } // notify the ui of a game connect if we're already in a game if (m_iGameIP) { g_VModuleLoader.PostMessageToAllModules(new KeyValues("ConnectedToGame", "ip", m_iGameIP, "port", m_iGamePort)); } } } /* if( m_pMaster ) { m_pMaster->Frame(); } */ if( vgui::surface()->GetModalPanel() ) { vgui::surface()->PaintTraverse( staticPanel->GetVPanel()); } }
//----------------------------------------------------------------------------- // Purpose: Called to setup the game UI //----------------------------------------------------------------------------- void CGameUI::Start(struct cl_enginefuncs_s *engineFuncs, int interfaceVersion, IBaseSystem *system) { // TRACE_FUNCTION("CGameUI::Start"); // m_pMaster = NULL; // copy the engine interface // memcpy(&gEngfuncs, engineFuncs, sizeof(gEngfuncs)); // engine = &gEngfuncs; // set SystemWrapper for demo player // g_pSystemWrapper = system; // load mod info ModInfo().LoadCurrentGameInfo(); // Determine Tracker location. // ...If running with Steam, Tracker is in a well defined location relative to the game dir. Use it if there. // ...Otherwise get the tracker location from the registry key if (FindPlatformDirectory(m_szPlatformDir, sizeof(m_szPlatformDir))) { // add the tracker directory to the search path // add localized version first if we're not in english char language[128]; if (vgui::system()->GetRegistryString("HKEY_LOCAL_MACHINE\\Software\\Valve\\Steam\\Language", language, sizeof(language))) { if (strlen(language) > 0 && stricmp(language, "english")) { char path[256]; sprintf(path, "platform_%s", language); vgui::filesystem()->AddSearchPath(path, "PLATFORM"); } } vgui::filesystem()->AddSearchPath("platform", "PLATFORM"); // setup config file directory char szConfigDir[512]; strcpy(szConfigDir, m_szPlatformDir); strcat(szConfigDir, "config"); /* // make sure the path exists _finddata_t findData; long findHandle = _findfirst(steamPath, &findData); if (steamPath && findHandle != -1) { // put the config dir directly under steam _snprintf(szConfigDir, sizeof(szConfigDir), "%s/config", steamPath); _findclose(findHandle); } else { // we're not running steam, so just put the config dir under the platform _snprintf(szConfigDir, sizeof(szConfigDir), "%sconfig", m_szPlatformDir); } */ // add the path vgui::filesystem()->AddSearchPath(szConfigDir, "CONFIG"); // make sure the config directory has been created _mkdir(szConfigDir); vgui::ivgui()->DPrintf("Platform config directory: %s\n", szConfigDir); // user dialog configuration vgui::system()->SetUserConfigFile("InGameDialogConfig.vdf", "CONFIG"); // localization vgui::localize()->AddFile(vgui::filesystem(), "Resource/platform_%language%.txt"); vgui::localize()->AddFile(vgui::filesystem(), "Resource/vgui_%language%.txt"); //!! hack to work around problem with userinfo not being uploaded (and therefore *Tracker field) //!! this is done to make sure the *tracker userinfo field is set before we connect so that it //!! will get communicated to the server //!! this needs to be changed to a system where it is communicated to server when known but not before //!! addendum: this may very happen now with the platform changes; needs to be tested before this code //!! can be removed { // get the last known userID from the registry and set it in our userinfo string HKEY key; DWORD bufSize = sizeof(m_szPlatformDir); unsigned int lastUserID = 0; bufSize = sizeof(lastUserID); if (ERROR_SUCCESS == g_pVCR->Hook_RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\Valve\\Tracker", 0, KEY_READ, &key)) { g_pVCR->Hook_RegQueryValueEx(key, "LastUserID", NULL, NULL, (unsigned char *)&lastUserID, &bufSize); // close the registry key g_pVCR->Hook_RegCloseKey(key); } if (lastUserID) { char buf[32]; sprintf(buf, "%d", lastUserID); engine->PlayerInfo_SetValueForKey("*tracker", buf); } } } // task bar - needs to be first thing created g_pTaskbar = new CTaskbar(staticPanel,"TaskBar"); g_pTaskbar->SetVisible(false); // FOR SRC // vgui::surface()->SetWorkspaceInsets( 0, 0, 0, g_pTaskbar->GetTall() ); // Start loading tracker if (m_szPlatformDir[0] != 0) { vgui::ivgui()->DPrintf2("Initializing platform...\n"); // open a mutex Sys_SetLastError(SYS_NO_ERROR); // primary mutex is the platform.exe name char szExeName[sizeof(m_szPlatformDir) + 32]; sprintf(szExeName, "%splatform.exe", m_szPlatformDir); // convert the backslashes in the path string to be forward slashes so it can be used as a mutex name for (char *ch = szExeName; *ch != 0; ch++) { *ch = tolower(*ch); if (*ch == '\\') { *ch = '/'; } } g_hMutex = Sys_CreateMutex("ValvePlatformUIMutex"); g_hWaitMutex = Sys_CreateMutex("ValvePlatformWaitMutex"); if (g_hMutex == NULL || g_hWaitMutex == NULL || Sys_GetLastError() == SYS_ERROR_INVALID_HANDLE) { // error, can't get handle to mutex if (g_hMutex) { Sys_ReleaseMutex(g_hMutex); } if (g_hWaitMutex) { Sys_ReleaseMutex(g_hWaitMutex); } g_hMutex = NULL; g_hWaitMutex = NULL; Error("Tracker Error: Could not access Tracker, bad mutex\n"); return; } unsigned int waitResult = Sys_WaitForSingleObject(g_hMutex, 0); if (!(waitResult == SYS_WAIT_OBJECT_0 || waitResult == SYS_WAIT_ABANDONED)) { // mutex locked, need to close other tracker // get the wait mutex, so that tracker.exe knows that we're trying to acquire ValveTrackerMutex waitResult = Sys_WaitForSingleObject(g_hWaitMutex, 0); if (waitResult == SYS_WAIT_OBJECT_0 || waitResult == SYS_WAIT_ABANDONED) { Sys_EnumWindows(SendShutdownMsgFunc, 1); } } m_bTryingToLoadTracker = true; // now we are set up to check every frame to see if we can Start tracker } staticPanel->SetBackgroundRenderState(CBasePanel::BACKGROUND_DESKTOPIMAGE); // start mp3 playing //engine->pfnClientCmd("mp3 loop media/gamestartup.mp3\n"); // SRC version //engine->ClientCmd("loop media/gamestartup.mp3\n"); }