RTSS SDK help, how do I get the focus game's Framerate?

Discussion in 'Rivatuner Statistics Server (RTSS) Forum' started by gpkgpk, Aug 13, 2015.

  1. gpkgpk

    gpkgpk Guest

    Messages:
    1
    Likes Received:
    0
    GPU:
    32gb
    Hi all, I want to write a simple app to monitor a game's framerate and I need some help w/ RTSS SDK. How do I get the focus game's framerate?

    I see the fields in the mem struct etc. but how do I actually get it to detect the focused game and populate the app struct w/ the right game+framerate info?
    Not really seeing how to do this from the SDK info :bang:

    Thanks in advance, gpk

    (cannot post in the advanced sub-forum yet so please feel free to move this thread or if someone can cross-post there)
     
  2. Unwinder

    Unwinder Ancient Guru Staff Member

    Messages:
    17,193
    Likes Received:
    6,862
    Sorry for delayed reply, I just came back from vacation. That's how it is implemented in MSI Afterburner hardware monitoring graph:

    Code:
    float CMSIAfterburnerMonitoringSourceFramerate::GetData()
    {
    	float result	= FLT_MAX;
    	m_strGroup		= "";
    			
    	HANDLE hMapFile = OpenFileMapping(FILE_MAP_ALL_ACCESS, FALSE, "RTSSSharedMemoryV2");
    
    	if (hMapFile)
    	{
    		LPVOID pMapAddr = MapViewOfFile(hMapFile, FILE_MAP_ALL_ACCESS, 0, 0, 0);
    
    		LPRTSS_SHARED_MEMORY pMem = (LPRTSS_SHARED_MEMORY)pMapAddr;
    
    		if (pMem)
    		{
    			if ((pMem->dwSignature == 'RTSS') && (pMem->dwVersion >= 0x00020000))
    			{
    				HWND	hWnd		= GetForegroundWindow();
    				DWORD	dwProcessID	= 0;
    
    				if (hWnd)
    					GetWindowThreadProcessId(hWnd, &dwProcessID);
    
    
    				for (DWORD dwEntry=0; dwEntry<pMem->dwAppArrSize; dwEntry++)
    				{
    					RTSS_SHARED_MEMORY::LPRTSS_SHARED_MEMORY_APP_ENTRY pEntry = (RTSS_SHARED_MEMORY::LPRTSS_SHARED_MEMORY_APP_ENTRY)((LPBYTE)pMem + pMem->dwAppArrOffset + dwEntry * pMem->dwAppEntrySize);
    	
    					if (pEntry->dwProcessID)
    					{
    						if ((pEntry->dwProcessID == dwProcessID) || (result == FLT_MAX))
    						{
    							if (GetTickCount() - pEntry->dwTime1 <= 2000)
    							{
    								if (pMem->dwVersion >= 0x00020005)
    									result = pEntry->dwStatFrameTimeBufFramerate / 10.0f;
    								else
    									result = 1000.0f * pEntry->dwFrames / (pEntry->dwTime1 - pEntry->dwTime0);
    							}
    							else
    								result = 0;
    
    							if (pEntry->dwFlags & APPFLAG_DD)
    								m_strGroup = "DD";
    
    							if (pEntry->dwFlags & APPFLAG_D3D8)
    								m_strGroup = "D3D8";
    
    							if (pEntry->dwFlags & APPFLAG_D3D9)
    								m_strGroup = "D3D9";
    
    							if (pEntry->dwFlags & APPFLAG_D3D9EX)
    								m_strGroup = "D3D9E";
    							
    							if (pEntry->dwFlags & APPFLAG_D3D10)
    								m_strGroup = "D3D10";
    
    							if (pEntry->dwFlags & APPFLAG_D3D11)
    								m_strGroup = "D3D11";
    
    							if (pEntry->dwFlags & APPFLAG_OGL)
    								m_strGroup = "OGL";
    
    						}
    
    						if ((dwProcessID == pEntry->dwProcessID) || !dwProcessID)
    							break;
    					}
    				}
    			}
    			else
    				result = 0;
    
    			UnmapViewOfFile(pMapAddr);
    		}
    
    		CloseHandle(hMapFile);
    	}
    
    	return result;
    }
    
     

Share This Page