2012-12-19 09:30:18 +00:00
|
|
|
/****************************************************************************
|
|
|
|
* *
|
2015-11-10 05:21:49 +00:00
|
|
|
* Project64 - A Nintendo 64 emulator. *
|
2012-12-19 09:30:18 +00:00
|
|
|
* http://www.pj64-emu.com/ *
|
|
|
|
* Copyright (C) 2012 Project64. All rights reserved. *
|
|
|
|
* *
|
|
|
|
* License: *
|
|
|
|
* GNU/GPLv2 http://www.gnu.org/licenses/gpl-2.0.html *
|
|
|
|
* *
|
|
|
|
****************************************************************************/
|
2010-06-07 02:23:58 +00:00
|
|
|
#include "stdafx.h"
|
2015-12-06 09:59:58 +00:00
|
|
|
#include "FramePerSecondClass.h"
|
|
|
|
#include <Project64-core/N64System/N64Types.h>
|
2016-01-18 08:51:12 +00:00
|
|
|
#ifdef _WIN32
|
2015-12-06 09:59:58 +00:00
|
|
|
#include <Windows.h>
|
2016-01-18 08:51:12 +00:00
|
|
|
#endif
|
2008-09-18 03:15:49 +00:00
|
|
|
|
2015-12-23 19:41:11 +00:00
|
|
|
CFramePerSecond::CFramePerSecond()
|
2008-09-18 03:15:49 +00:00
|
|
|
{
|
2015-12-23 19:41:11 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2016-01-18 08:51:12 +00:00
|
|
|
#ifdef _WIN32
|
2015-12-23 19:41:11 +00:00
|
|
|
LARGE_INTEGER Freq;
|
|
|
|
QueryPerformanceFrequency(&Freq);
|
|
|
|
m_Frequency = Freq.QuadPart;
|
2016-01-18 08:51:12 +00:00
|
|
|
#endif
|
2015-12-23 19:41:11 +00:00
|
|
|
Reset(true);
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CFramePerSecond::~CFramePerSecond()
|
|
|
|
{
|
2015-12-23 19:41:11 +00:00
|
|
|
g_Settings->UnregisterChangeCB(UserInterface_FrameDisplayType, this, (CSettings::SettingChangedFunc)FrameRateTypeChanged);
|
|
|
|
g_Settings->UnregisterChangeCB(GameRunning_ScreenHertz, this, (CSettings::SettingChangedFunc)ScreenHertzChanged);
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
|
2015-12-23 19:41:11 +00:00
|
|
|
void CFramePerSecond::Reset(bool ClearDisplay)
|
2015-03-04 09:36:08 +00:00
|
|
|
{
|
2015-12-23 19:41:11 +00:00
|
|
|
m_CurrentFrame = 0;
|
|
|
|
m_LastFrame = 0;
|
|
|
|
|
|
|
|
for (int count = 0; count < NoOfFrames; count++)
|
|
|
|
{
|
|
|
|
m_Frames[count] = 0;
|
|
|
|
}
|
|
|
|
if (ClearDisplay)
|
|
|
|
{
|
2016-01-18 08:51:12 +00:00
|
|
|
#ifdef _WIN32
|
2015-12-23 20:04:36 +00:00
|
|
|
g_Notify->DisplayMessage2("");
|
2016-01-18 08:51:12 +00:00
|
|
|
#endif
|
2015-12-23 19:41:11 +00:00
|
|
|
return;
|
|
|
|
}
|
2008-09-18 03:15:49 +00:00
|
|
|
|
2015-12-23 19:41:11 +00:00
|
|
|
if (m_iFrameRateType == FR_VIs)
|
2015-03-04 09:36:08 +00:00
|
|
|
{
|
2015-12-23 19:41:11 +00:00
|
|
|
DisplayViCounter(0);
|
|
|
|
}
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
|
2015-12-23 19:41:11 +00:00
|
|
|
void CFramePerSecond::UpdateViCounter(void)
|
2008-09-18 03:15:49 +00:00
|
|
|
{
|
2016-01-18 08:51:12 +00:00
|
|
|
#ifdef _WIN32
|
2015-12-23 19:41:11 +00:00
|
|
|
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;
|
2016-01-18 08:51:12 +00:00
|
|
|
#endif
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
|
2015-12-06 09:59:58 +00:00
|
|
|
void CFramePerSecond::DisplayViCounter(uint32_t FrameRate)
|
2015-03-04 09:36:08 +00:00
|
|
|
{
|
2016-01-18 08:51:12 +00:00
|
|
|
#ifdef _WIN32
|
2015-12-23 19:41:11 +00:00
|
|
|
if (m_iFrameRateType == FR_VIs)
|
|
|
|
{
|
|
|
|
if (FrameRate != 0)
|
2015-03-04 09:36:08 +00:00
|
|
|
{
|
2015-12-23 20:04:36 +00:00
|
|
|
g_Notify->DisplayMessage2(stdstr_f("VI/s: %d.00", FrameRate).c_str());
|
2015-12-23 19:41:11 +00:00
|
|
|
}
|
|
|
|
else
|
2015-03-04 09:36:08 +00:00
|
|
|
{
|
2015-12-23 19:41:11 +00:00
|
|
|
if (m_CurrentFrame > (NoOfFrames << 3))
|
2015-03-04 09:36:08 +00:00
|
|
|
{
|
2016-01-18 08:51:12 +00:00
|
|
|
int64_t Total;
|
2015-12-23 19:41:11 +00:00
|
|
|
|
|
|
|
Total = 0;
|
|
|
|
for (int count = 0; count < NoOfFrames; count++)
|
2015-03-04 09:36:08 +00:00
|
|
|
{
|
2015-12-23 19:41:11 +00:00
|
|
|
Total += m_Frames[count];
|
|
|
|
}
|
2015-12-23 20:04:36 +00:00
|
|
|
g_Notify->DisplayMessage2(stdstr_f("VI/s: %.2f", m_Frequency / ((double)Total / (NoOfFrames << 3))).c_str());
|
2015-12-23 19:41:11 +00:00
|
|
|
}
|
|
|
|
else
|
2015-03-04 09:36:08 +00:00
|
|
|
{
|
2015-12-23 20:04:36 +00:00
|
|
|
g_Notify->DisplayMessage2("VI/s: -.--");
|
2015-12-23 19:41:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (m_iFrameRateType == FR_PERCENT)
|
|
|
|
{
|
|
|
|
float Percent;
|
|
|
|
if (FrameRate != 0)
|
2015-03-04 09:36:08 +00:00
|
|
|
{
|
2015-12-23 19:41:11 +00:00
|
|
|
Percent = ((float)FrameRate) / m_ScreenHertz;
|
|
|
|
}
|
|
|
|
else
|
2015-03-04 09:36:08 +00:00
|
|
|
{
|
2015-12-23 19:41:11 +00:00
|
|
|
if (m_CurrentFrame > (NoOfFrames << 3))
|
2015-03-04 09:36:08 +00:00
|
|
|
{
|
2016-01-18 08:51:12 +00:00
|
|
|
int64_t Total;
|
2015-12-23 19:41:11 +00:00
|
|
|
|
|
|
|
Total = 0;
|
|
|
|
for (int count = 0; count < NoOfFrames; count++)
|
2015-03-04 09:36:08 +00:00
|
|
|
{
|
2015-12-23 19:41:11 +00:00
|
|
|
Total += m_Frames[count];
|
|
|
|
}
|
|
|
|
Percent = ((float)(m_Frequency / ((double)Total / (NoOfFrames << 3)))) / m_ScreenHertz;
|
|
|
|
}
|
|
|
|
else
|
2015-03-04 09:36:08 +00:00
|
|
|
{
|
2015-12-23 20:04:36 +00:00
|
|
|
g_Notify->DisplayMessage2("");
|
2015-12-23 19:41:11 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2015-12-23 20:04:36 +00:00
|
|
|
g_Notify->DisplayMessage2(stdstr_f("%.1f %%", Percent * 100).c_str());
|
2015-12-23 19:41:11 +00:00
|
|
|
}
|
2016-01-18 08:51:12 +00:00
|
|
|
#endif
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
|
2015-12-23 19:41:11 +00:00
|
|
|
void CFramePerSecond::FrameRateTypeChanged(CFramePerSecond * _this)
|
2008-09-18 03:15:49 +00:00
|
|
|
{
|
2015-12-23 19:41:11 +00:00
|
|
|
_this->m_iFrameRateType = g_Settings->LoadDword(UserInterface_FrameDisplayType);
|
|
|
|
_this->Reset(true);
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
|
2015-12-23 19:41:11 +00:00
|
|
|
void CFramePerSecond::ScreenHertzChanged(CFramePerSecond * _this)
|
2008-09-18 03:15:49 +00:00
|
|
|
{
|
2015-12-23 19:41:11 +00:00
|
|
|
_this->m_ScreenHertz = g_Settings->LoadDword(GameRunning_ScreenHertz);
|
|
|
|
_this->Reset(true);
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
|
2015-12-23 19:41:11 +00:00
|
|
|
void CFramePerSecond::UpdateDlCounter(void)
|
2008-09-18 03:15:49 +00:00
|
|
|
{
|
2016-01-18 08:51:12 +00:00
|
|
|
#ifdef _WIN32
|
2015-12-23 19:41:11 +00:00
|
|
|
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;
|
2016-01-18 08:51:12 +00:00
|
|
|
#endif
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
|
2015-12-06 09:59:58 +00:00
|
|
|
void CFramePerSecond::DisplayDlCounter(uint32_t FrameRate)
|
2015-10-25 11:40:21 +00:00
|
|
|
{
|
2016-01-18 08:51:12 +00:00
|
|
|
#ifdef _WIN32
|
2015-12-23 19:41:11 +00:00
|
|
|
if (m_iFrameRateType != FR_DLs)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (FrameRate != 0)
|
|
|
|
{
|
2015-12-23 20:04:36 +00:00
|
|
|
g_Notify->DisplayMessage2(stdstr_f("DL/s: %d.00", FrameRate).c_str());
|
2015-12-23 19:41:11 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (m_CurrentFrame > (NoOfFrames << 2))
|
|
|
|
{
|
2016-01-18 08:51:12 +00:00
|
|
|
int64_t Total;
|
2015-12-23 19:41:11 +00:00
|
|
|
|
|
|
|
Total = 0;
|
|
|
|
for (int count = 0; count < NoOfFrames; count++)
|
|
|
|
{
|
|
|
|
Total += m_Frames[count];
|
|
|
|
}
|
2015-12-23 20:04:36 +00:00
|
|
|
g_Notify->DisplayMessage2(stdstr_f("DL/s: %.1f", m_Frequency / ((double)Total / (NoOfFrames << 2))).c_str());
|
2015-12-23 19:41:11 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-12-23 20:04:36 +00:00
|
|
|
g_Notify->DisplayMessage2("DL/s: -.--");
|
2015-12-23 19:41:11 +00:00
|
|
|
}
|
|
|
|
}
|
2016-01-18 08:51:12 +00:00
|
|
|
#endif
|
2015-12-23 19:41:11 +00:00
|
|
|
}
|