2010-06-07 02:23:58 +00:00
|
|
|
#include "stdafx.h"
|
2008-09-18 03:15:49 +00:00
|
|
|
|
|
|
|
CFramePerSecond::CFramePerSecond (CNotification * Notification):
|
2012-11-17 00:58:31 +00:00
|
|
|
g_Notify(Notification)
|
2008-09-18 03:15:49 +00:00
|
|
|
{
|
2008-11-14 20:51:06 +00:00
|
|
|
m_iFrameRateType = _Settings->LoadDword(UserInterface_FrameDisplayType);
|
|
|
|
m_ScreenHertz = _Settings->LoadDword(GameRunning_ScreenHertz);
|
|
|
|
_Settings->RegisterChangeCB(UserInterface_FrameDisplayType,this,(CSettings::SettingChangedFunc)FrameRateTypeChanged);
|
|
|
|
_Settings->RegisterChangeCB(GameRunning_ScreenHertz,this,(CSettings::SettingChangedFunc)ScreenHertzChanged);
|
2008-09-18 03:15:49 +00:00
|
|
|
|
|
|
|
if (m_ScreenHertz == 0)
|
|
|
|
{
|
|
|
|
m_ScreenHertz = 60;
|
|
|
|
}
|
|
|
|
|
|
|
|
LARGE_INTEGER Freq;
|
|
|
|
QueryPerformanceFrequency(&Freq);
|
|
|
|
Frequency = Freq.QuadPart;
|
|
|
|
Reset(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
CFramePerSecond::~CFramePerSecond()
|
|
|
|
{
|
2008-11-14 20:51:06 +00:00
|
|
|
_Settings->UnregisterChangeCB(UserInterface_FrameDisplayType,this,(CSettings::SettingChangedFunc)FrameRateTypeChanged);
|
|
|
|
_Settings->UnregisterChangeCB(GameRunning_ScreenHertz,this,(CSettings::SettingChangedFunc)ScreenHertzChanged);
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CFramePerSecond::Reset (bool ClearDisplay) {
|
|
|
|
CurrentFrame = 0;
|
|
|
|
LastFrame = 0;
|
|
|
|
|
|
|
|
for (int count = 0; count < NoOfFrames; count ++) {
|
|
|
|
Frames[count] = 0;
|
|
|
|
}
|
|
|
|
if (ClearDisplay)
|
|
|
|
{
|
2012-11-17 00:58:31 +00:00
|
|
|
g_Notify->DisplayMessage2("");
|
2008-09-18 03:15:49 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_iFrameRateType == FR_VIs)
|
|
|
|
{
|
|
|
|
DisplayViCounter(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CFramePerSecond::UpdateViCounter ( void )
|
|
|
|
{
|
|
|
|
if (m_iFrameRateType != FR_VIs && m_iFrameRateType != FR_PERCENT)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ((CurrentFrame & 7) == 0) {
|
|
|
|
LARGE_INTEGER Time;
|
|
|
|
QueryPerformanceCounter(&Time);
|
|
|
|
Frames[(CurrentFrame >> 3) % NoOfFrames] = Time.QuadPart - LastFrame;
|
|
|
|
LastFrame = Time.QuadPart;
|
|
|
|
DisplayViCounter(0);
|
|
|
|
}
|
|
|
|
CurrentFrame += 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CFramePerSecond::DisplayViCounter(DWORD FrameRate) {
|
|
|
|
if (m_iFrameRateType == FR_VIs)
|
|
|
|
{
|
|
|
|
if (FrameRate != 0) {
|
2012-11-17 00:58:31 +00:00
|
|
|
g_Notify->DisplayMessage2("VI/s: %d.00", FrameRate);
|
2008-09-18 03:15:49 +00:00
|
|
|
} else {
|
|
|
|
if (CurrentFrame > (NoOfFrames << 3)) {
|
|
|
|
__int64 Total;
|
|
|
|
|
|
|
|
Total = 0;
|
|
|
|
for (int count = 0; count < NoOfFrames; count ++) {
|
|
|
|
Total += Frames[count];
|
|
|
|
}
|
2012-11-17 00:58:31 +00:00
|
|
|
g_Notify->DisplayMessage2("VI/s: %.2f", Frequency/ ((double)Total / (NoOfFrames << 3)));
|
2008-09-18 03:15:49 +00:00
|
|
|
} else {
|
2012-11-17 00:58:31 +00:00
|
|
|
g_Notify->DisplayMessage2("VI/s: -.--");
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (m_iFrameRateType == FR_PERCENT)
|
|
|
|
{
|
|
|
|
float Percent;
|
|
|
|
if (FrameRate != 0) {
|
|
|
|
Percent = ((float)FrameRate) / m_ScreenHertz;
|
|
|
|
} else {
|
|
|
|
if (CurrentFrame > (NoOfFrames << 3)) {
|
|
|
|
__int64 Total;
|
|
|
|
|
|
|
|
Total = 0;
|
|
|
|
for (int count = 0; count < NoOfFrames; count ++) {
|
|
|
|
Total += Frames[count];
|
|
|
|
}
|
|
|
|
Percent = ((float)(Frequency/ ((double)Total / (NoOfFrames << 3)))) / m_ScreenHertz;
|
|
|
|
} else {
|
2012-11-17 00:58:31 +00:00
|
|
|
g_Notify->DisplayMessage2("");
|
2008-09-18 03:15:49 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2012-11-17 00:58:31 +00:00
|
|
|
g_Notify->DisplayMessage2("%.1f %%",Percent * 100);
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CFramePerSecond::FrameRateTypeChanged (CFramePerSecond * _this)
|
|
|
|
{
|
2008-11-14 20:51:06 +00:00
|
|
|
_this->m_iFrameRateType = _Settings->LoadDword(UserInterface_FrameDisplayType);
|
2008-09-18 03:15:49 +00:00
|
|
|
_this->Reset(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CFramePerSecond::ScreenHertzChanged (CFramePerSecond * _this)
|
|
|
|
{
|
2008-11-14 20:51:06 +00:00
|
|
|
_this->m_ScreenHertz = _Settings->LoadDword(GameRunning_ScreenHertz);
|
2008-09-18 03:15:49 +00:00
|
|
|
_this->Reset(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CFramePerSecond::UpdateDlCounter ( void )
|
|
|
|
{
|
|
|
|
if (m_iFrameRateType != FR_DLs)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ((CurrentFrame & 3) == 0) {
|
|
|
|
LARGE_INTEGER Time;
|
|
|
|
QueryPerformanceCounter(&Time);
|
|
|
|
Frames[(CurrentFrame >> 2) % NoOfFrames] = Time.QuadPart - LastFrame;
|
|
|
|
LastFrame = Time.QuadPart;
|
|
|
|
DisplayDlCounter(0);
|
|
|
|
}
|
|
|
|
CurrentFrame += 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CFramePerSecond::DisplayDlCounter(DWORD FrameRate) {
|
|
|
|
if (m_iFrameRateType != FR_DLs)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (FrameRate != 0) {
|
2012-11-17 00:58:31 +00:00
|
|
|
g_Notify->DisplayMessage2("DL/s: %d.00", FrameRate);
|
2008-09-18 03:15:49 +00:00
|
|
|
} else {
|
|
|
|
if (CurrentFrame > (NoOfFrames << 2)) {
|
|
|
|
__int64 Total;
|
|
|
|
|
|
|
|
Total = 0;
|
|
|
|
for (int count = 0; count < NoOfFrames; count ++) {
|
|
|
|
Total += Frames[count];
|
|
|
|
}
|
2012-11-17 00:58:31 +00:00
|
|
|
g_Notify->DisplayMessage2("DL/s: %.1f", Frequency/ ((double)Total / (NoOfFrames << 2)));
|
2008-09-18 03:15:49 +00:00
|
|
|
} else {
|
2012-11-17 00:58:31 +00:00
|
|
|
g_Notify->DisplayMessage2("DL/s: -.--");
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|