[Project64] Clean up FramePerSecondClass.cpp

This commit is contained in:
zilmar 2015-12-24 06:41:11 +11:00
parent 58c125d337
commit 6ffd1663ca
2 changed files with 149 additions and 149 deletions

View File

@ -13,179 +13,179 @@
#include <Project64-core/N64System/N64Types.h>
#include <Windows.h>
CFramePerSecond::CFramePerSecond ()
CFramePerSecond::CFramePerSecond()
{
m_iFrameRateType = g_Settings->LoadDword(UserInterface_FrameDisplayType);
m_ScreenHertz = g_Settings->LoadDword(GameRunning_ScreenHertz);
g_Settings->RegisterChangeCB(UserInterface_FrameDisplayType,this,(CSettings::SettingChangedFunc)FrameRateTypeChanged);
g_Settings->RegisterChangeCB(GameRunning_ScreenHertz,this,(CSettings::SettingChangedFunc)ScreenHertzChanged);
if (m_ScreenHertz == 0)
{
m_ScreenHertz = 60;
}
LARGE_INTEGER Freq;
QueryPerformanceFrequency(&Freq);
m_Frequency = Freq.QuadPart;
Reset(true);
m_iFrameRateType = g_Settings->LoadDword(UserInterface_FrameDisplayType);
m_ScreenHertz = g_Settings->LoadDword(GameRunning_ScreenHertz);
g_Settings->RegisterChangeCB(UserInterface_FrameDisplayType, this, (CSettings::SettingChangedFunc)FrameRateTypeChanged);
g_Settings->RegisterChangeCB(GameRunning_ScreenHertz, this, (CSettings::SettingChangedFunc)ScreenHertzChanged);
if (m_ScreenHertz == 0)
{
m_ScreenHertz = 60;
}
LARGE_INTEGER Freq;
QueryPerformanceFrequency(&Freq);
m_Frequency = Freq.QuadPart;
Reset(true);
}
CFramePerSecond::~CFramePerSecond()
{
g_Settings->UnregisterChangeCB(UserInterface_FrameDisplayType,this,(CSettings::SettingChangedFunc)FrameRateTypeChanged);
g_Settings->UnregisterChangeCB(GameRunning_ScreenHertz,this,(CSettings::SettingChangedFunc)ScreenHertzChanged);
g_Settings->UnregisterChangeCB(UserInterface_FrameDisplayType, this, (CSettings::SettingChangedFunc)FrameRateTypeChanged);
g_Settings->UnregisterChangeCB(GameRunning_ScreenHertz, this, (CSettings::SettingChangedFunc)ScreenHertzChanged);
}
void CFramePerSecond::Reset (bool ClearDisplay)
void CFramePerSecond::Reset(bool ClearDisplay)
{
m_CurrentFrame = 0;
m_LastFrame = 0;
m_CurrentFrame = 0;
m_LastFrame = 0;
for (int count = 0; count < NoOfFrames; count ++)
for (int count = 0; count < NoOfFrames; count++)
{
m_Frames[count] = 0;
}
if (ClearDisplay)
{
g_Notify->DisplayMessage2(L"");
return;
}
if (m_iFrameRateType == FR_VIs)
{
DisplayViCounter(0);
}
m_Frames[count] = 0;
}
if (ClearDisplay)
{
g_Notify->DisplayMessage2(L"");
return;
}
if (m_iFrameRateType == FR_VIs)
{
DisplayViCounter(0);
}
}
void CFramePerSecond::UpdateViCounter ( void )
void CFramePerSecond::UpdateViCounter(void)
{
if (m_iFrameRateType != FR_VIs && m_iFrameRateType != FR_PERCENT)
{
return;
}
if ((m_CurrentFrame & 7) == 0)
{
LARGE_INTEGER Time;
QueryPerformanceCounter(&Time);
m_Frames[(m_CurrentFrame >> 3) % NoOfFrames] = Time.QuadPart - m_LastFrame;
m_LastFrame = Time.QuadPart;
DisplayViCounter(0);
}
m_CurrentFrame += 1;
if (m_iFrameRateType != FR_VIs && m_iFrameRateType != FR_PERCENT)
{
return;
}
if ((m_CurrentFrame & 7) == 0)
{
LARGE_INTEGER Time;
QueryPerformanceCounter(&Time);
m_Frames[(m_CurrentFrame >> 3) % NoOfFrames] = Time.QuadPart - m_LastFrame;
m_LastFrame = Time.QuadPart;
DisplayViCounter(0);
}
m_CurrentFrame += 1;
}
void CFramePerSecond::DisplayViCounter(uint32_t FrameRate)
{
if (m_iFrameRateType == FR_VIs)
{
if (FrameRate != 0)
if (m_iFrameRateType == FR_VIs)
{
if (FrameRate != 0)
{
g_Notify->DisplayMessage2(stdstr_f("VI/s: %d.00", FrameRate).ToUTF16().c_str());
}
else
g_Notify->DisplayMessage2(stdstr_f("VI/s: %d.00", FrameRate).ToUTF16().c_str());
}
else
{
if (m_CurrentFrame > (NoOfFrames << 3))
if (m_CurrentFrame > (NoOfFrames << 3))
{
__int64 Total;
Total = 0;
for (int count = 0; count < NoOfFrames; count ++)
__int64 Total;
Total = 0;
for (int count = 0; count < NoOfFrames; count++)
{
Total += m_Frames[count];
}
g_Notify->DisplayMessage2(stdstr_f("VI/s: %.2f", m_Frequency / ((double)Total / (NoOfFrames << 3))).ToUTF16().c_str());
}
else
Total += m_Frames[count];
}
g_Notify->DisplayMessage2(stdstr_f("VI/s: %.2f", m_Frequency / ((double)Total / (NoOfFrames << 3))).ToUTF16().c_str());
}
else
{
g_Notify->DisplayMessage2(L"VI/s: -.--");
}
}
}
if (m_iFrameRateType == FR_PERCENT)
{
float Percent;
if (FrameRate != 0)
g_Notify->DisplayMessage2(L"VI/s: -.--");
}
}
}
if (m_iFrameRateType == FR_PERCENT)
{
float Percent;
if (FrameRate != 0)
{
Percent = ((float)FrameRate) / m_ScreenHertz;
}
else
Percent = ((float)FrameRate) / m_ScreenHertz;
}
else
{
if (m_CurrentFrame > (NoOfFrames << 3))
if (m_CurrentFrame > (NoOfFrames << 3))
{
__int64 Total;
Total = 0;
for (int count = 0; count < NoOfFrames; count ++)
__int64 Total;
Total = 0;
for (int count = 0; count < NoOfFrames; count++)
{
Total += m_Frames[count];
}
Percent = ((float)(m_Frequency / ((double)Total / (NoOfFrames << 3)))) / m_ScreenHertz;
}
else
Total += m_Frames[count];
}
Percent = ((float)(m_Frequency / ((double)Total / (NoOfFrames << 3)))) / m_ScreenHertz;
}
else
{
g_Notify->DisplayMessage2(L"");
return;
}
}
g_Notify->DisplayMessage2(stdstr_f("%.1f %%",Percent * 100).ToUTF16().c_str());
}
g_Notify->DisplayMessage2(L"");
return;
}
}
g_Notify->DisplayMessage2(stdstr_f("%.1f %%", Percent * 100).ToUTF16().c_str());
}
}
void CFramePerSecond::FrameRateTypeChanged (CFramePerSecond * _this)
void CFramePerSecond::FrameRateTypeChanged(CFramePerSecond * _this)
{
_this->m_iFrameRateType = g_Settings->LoadDword(UserInterface_FrameDisplayType);
_this->Reset(true);
_this->m_iFrameRateType = g_Settings->LoadDword(UserInterface_FrameDisplayType);
_this->Reset(true);
}
void CFramePerSecond::ScreenHertzChanged (CFramePerSecond * _this)
void CFramePerSecond::ScreenHertzChanged(CFramePerSecond * _this)
{
_this->m_ScreenHertz = g_Settings->LoadDword(GameRunning_ScreenHertz);
_this->Reset(true);
_this->m_ScreenHertz = g_Settings->LoadDword(GameRunning_ScreenHertz);
_this->Reset(true);
}
void CFramePerSecond::UpdateDlCounter ( void )
void CFramePerSecond::UpdateDlCounter(void)
{
if (m_iFrameRateType != FR_DLs)
{
return;
}
if ((m_CurrentFrame & 3) == 0) {
LARGE_INTEGER Time;
QueryPerformanceCounter(&Time);
m_Frames[(m_CurrentFrame >> 2) % NoOfFrames] = Time.QuadPart - m_LastFrame;
m_LastFrame = Time.QuadPart;
DisplayDlCounter(0);
}
m_CurrentFrame += 1;
if (m_iFrameRateType != FR_DLs)
{
return;
}
if ((m_CurrentFrame & 3) == 0) {
LARGE_INTEGER Time;
QueryPerformanceCounter(&Time);
m_Frames[(m_CurrentFrame >> 2) % NoOfFrames] = Time.QuadPart - m_LastFrame;
m_LastFrame = Time.QuadPart;
DisplayDlCounter(0);
}
m_CurrentFrame += 1;
}
void CFramePerSecond::DisplayDlCounter(uint32_t FrameRate)
{
if (m_iFrameRateType != FR_DLs)
{
return;
}
if (FrameRate != 0)
{
g_Notify->DisplayMessage2(stdstr_f("DL/s: %d.00", FrameRate).ToUTF16().c_str());
}
else
{
if (m_CurrentFrame > (NoOfFrames << 2))
{
__int64 Total;
Total = 0;
for (int count = 0; count < NoOfFrames; count ++)
{
Total += m_Frames[count];
}
g_Notify->DisplayMessage2(stdstr_f("DL/s: %.1f", m_Frequency / ((double)Total / (NoOfFrames << 2))).ToUTF16().c_str());
}
else
{
g_Notify->DisplayMessage2(L"DL/s: -.--");
}
}
}
if (m_iFrameRateType != FR_DLs)
{
return;
}
if (FrameRate != 0)
{
g_Notify->DisplayMessage2(stdstr_f("DL/s: %d.00", FrameRate).ToUTF16().c_str());
}
else
{
if (m_CurrentFrame > (NoOfFrames << 2))
{
__int64 Total;
Total = 0;
for (int count = 0; count < NoOfFrames; count++)
{
Total += m_Frames[count];
}
g_Notify->DisplayMessage2(stdstr_f("DL/s: %.1f", m_Frequency / ((double)Total / (NoOfFrames << 2))).ToUTF16().c_str());
}
else
{
g_Notify->DisplayMessage2(L"DL/s: -.--");
}
}
}

View File

@ -10,27 +10,27 @@
****************************************************************************/
#pragma once
class CFramePerSecond
class CFramePerSecond
{
public:
CFramePerSecond ( void );
~CFramePerSecond ( void );
CFramePerSecond(void);
~CFramePerSecond(void);
void Reset ( bool ClearDisplay );
void Reset(bool ClearDisplay);
void UpdateDlCounter ( void );
void UpdateViCounter ( void );
void DisplayDlCounter ( uint32_t FrameRate );
void DisplayViCounter ( uint32_t FrameRate );
void UpdateDlCounter(void);
void UpdateViCounter(void);
void DisplayDlCounter(uint32_t FrameRate);
void DisplayViCounter(uint32_t FrameRate);
private:
static void FrameRateTypeChanged(CFramePerSecond * _this);
static void ScreenHertzChanged(CFramePerSecond * _this);
static void FrameRateTypeChanged(CFramePerSecond * _this);
static void ScreenHertzChanged(CFramePerSecond * _this);
int m_iFrameRateType, m_ScreenHertz;
int m_iFrameRateType, m_ScreenHertz;
enum { NoOfFrames = 7 };
enum { NoOfFrames = 7 };
int64_t m_Frequency, m_Frames[NoOfFrames], m_LastFrame;
int m_CurrentFrame;
int m_CurrentFrame;
};