2010-06-07 02:23:58 +00:00
|
|
|
#include "stdafx.h"
|
2022-10-10 00:22:17 +00:00
|
|
|
|
2021-04-14 05:34:15 +00:00
|
|
|
#include "FramePerSecond.h"
|
2015-12-06 09:59:58 +00:00
|
|
|
#include <Project64-core/N64System/N64Types.h>
|
2008-09-18 03:15:49 +00:00
|
|
|
|
2016-08-10 10:03:25 +00:00
|
|
|
CFramePerSecond::CFramePerSecond() :
|
2022-08-22 03:17:44 +00:00
|
|
|
m_CurrentViFrame(0),
|
|
|
|
m_CurrentDlistFrame(0),
|
|
|
|
m_iFrameRateType(g_Settings->LoadDword(UserInterface_FrameDisplayType)),
|
|
|
|
m_ScreenHertz(g_Settings->LoadDword(GameRunning_ScreenHertz)),
|
|
|
|
m_ViFrameRateWhole(0),
|
|
|
|
m_ViFrameRateFraction(0)
|
2008-09-18 03:15:49 +00:00
|
|
|
{
|
2015-12-23 19:41:11 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
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
|
|
|
{
|
2016-08-10 10:03:25 +00:00
|
|
|
m_CurrentDlistFrame = 0;
|
|
|
|
m_CurrentViFrame = 0;
|
2016-09-16 21:37:27 +00:00
|
|
|
m_LastViFrame.SetMicroSeconds(0);
|
2015-12-23 19:41:11 +00:00
|
|
|
|
|
|
|
for (int count = 0; count < NoOfFrames; count++)
|
|
|
|
{
|
2016-08-10 10:03:25 +00:00
|
|
|
m_ViFrames[count] = 0;
|
|
|
|
m_FramesDlist[count] = 0;
|
2015-12-23 19:41:11 +00:00
|
|
|
}
|
|
|
|
if (ClearDisplay)
|
|
|
|
{
|
2015-12-23 20:04:36 +00:00
|
|
|
g_Notify->DisplayMessage2("");
|
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
|
|
|
{
|
2016-09-16 21:37:27 +00:00
|
|
|
DisplayViCounter(-1, 0);
|
2015-12-23 19:41:11 +00:00
|
|
|
}
|
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
|
|
|
{
|
2019-01-15 08:10:11 +00:00
|
|
|
if (!bDisplayFrameRate())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (m_iFrameRateType != FR_VIs && m_iFrameRateType != FR_VIs_DLs && m_iFrameRateType != FR_PERCENT)
|
2015-12-23 19:41:11 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2016-08-10 10:03:25 +00:00
|
|
|
if ((m_CurrentViFrame & 7) == 0)
|
2015-12-23 19:41:11 +00:00
|
|
|
{
|
2016-09-16 21:37:27 +00:00
|
|
|
HighResTimeStamp Time;
|
2016-08-10 10:03:25 +00:00
|
|
|
Time.SetToNow();
|
2016-09-16 21:37:27 +00:00
|
|
|
|
|
|
|
uint64_t time_diff = Time.GetMicroSeconds() - m_LastViFrame.GetMicroSeconds();
|
|
|
|
m_ViFrames[(m_CurrentViFrame >> 3) % NoOfFrames] = time_diff;
|
2016-08-10 10:03:25 +00:00
|
|
|
m_LastViFrame = Time;
|
2016-09-16 21:37:27 +00:00
|
|
|
DisplayViCounter(-1, 0);
|
2015-12-23 19:41:11 +00:00
|
|
|
}
|
2016-08-10 10:03:25 +00:00
|
|
|
m_CurrentViFrame += 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CFramePerSecond::UpdateDisplay(void)
|
|
|
|
{
|
|
|
|
std::string DisplayString;
|
|
|
|
if (m_iFrameRateType == FR_VIs || m_iFrameRateType == FR_VIs_DLs)
|
|
|
|
{
|
2016-09-16 21:37:27 +00:00
|
|
|
DisplayString = stdstr_f(m_ViFrameRateWhole >= 0 ? "VI/s: %d.%d" : "VI/s: -.--", m_ViFrameRateWhole, m_ViFrameRateFraction);
|
2016-08-10 10:03:25 +00:00
|
|
|
}
|
2016-09-16 21:37:27 +00:00
|
|
|
if (m_iFrameRateType == FR_PERCENT && m_ViFrameRateWhole > 0)
|
2016-08-10 10:03:25 +00:00
|
|
|
{
|
2016-09-16 21:37:27 +00:00
|
|
|
float Percent = ((float)m_ViFrameRateWhole + ((float)m_ViFrameRateFraction / 100)) / m_ScreenHertz;
|
2016-08-10 10:03:25 +00:00
|
|
|
DisplayString = stdstr_f("%.1f %%", Percent * 100).c_str();
|
|
|
|
}
|
|
|
|
if (m_iFrameRateType == FR_DLs || m_iFrameRateType == FR_VIs_DLs)
|
|
|
|
{
|
2022-10-10 00:22:17 +00:00
|
|
|
if (DisplayString.length() > 0)
|
|
|
|
{
|
|
|
|
DisplayString += " ";
|
|
|
|
}
|
2016-08-10 10:03:25 +00:00
|
|
|
DisplayString += stdstr_f(m_DlistFrameRate >= 0 ? "DL/s: %.1f" : "DL/s: -.--", m_DlistFrameRate);
|
|
|
|
}
|
|
|
|
g_Notify->DisplayMessage2(DisplayString.c_str());
|
2008-09-18 03:15:49 +00:00
|
|
|
}
|
|
|
|
|
2016-09-16 21:37:27 +00:00
|
|
|
void CFramePerSecond::DisplayViCounter(int32_t FrameRateWhole, uint32_t FrameRateFraction)
|
2015-03-04 09:36:08 +00:00
|
|
|
{
|
2016-08-10 10:03:25 +00:00
|
|
|
if (m_iFrameRateType != FR_VIs && m_iFrameRateType != FR_VIs_DLs && m_iFrameRateType != FR_PERCENT)
|
2015-12-23 19:41:11 +00:00
|
|
|
{
|
2016-08-10 10:03:25 +00:00
|
|
|
return;
|
|
|
|
}
|
2016-09-16 21:37:27 +00:00
|
|
|
if (FrameRateWhole >= 0)
|
2016-08-10 10:03:25 +00:00
|
|
|
{
|
2016-09-16 21:37:27 +00:00
|
|
|
m_ViFrameRateWhole = FrameRateWhole;
|
|
|
|
m_ViFrameRateFraction = FrameRateFraction;
|
2016-08-10 10:03:25 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (m_CurrentViFrame > (NoOfFrames << 3))
|
2015-03-04 09:36:08 +00:00
|
|
|
{
|
2016-08-10 10:03:25 +00:00
|
|
|
uint64_t Total;
|
2015-12-23 19:41:11 +00:00
|
|
|
|
2016-08-10 10:03:25 +00:00
|
|
|
Total = 0;
|
|
|
|
for (int count = 0; count < NoOfFrames; count++)
|
2015-03-04 09:36:08 +00:00
|
|
|
{
|
2016-08-10 10:03:25 +00:00
|
|
|
Total += m_ViFrames[count];
|
2015-12-23 19:41:11 +00:00
|
|
|
}
|
2016-09-16 21:37:27 +00:00
|
|
|
int baseFPS = (uint32_t)(((uint64_t)NoOfFrames << 3) * 100000000 / Total);
|
|
|
|
m_ViFrameRateWhole = baseFPS / 100;
|
|
|
|
m_ViFrameRateFraction = baseFPS % 100;
|
2015-12-23 19:41:11 +00:00
|
|
|
}
|
|
|
|
else
|
2015-03-04 09:36:08 +00:00
|
|
|
{
|
2016-09-16 21:37:27 +00:00
|
|
|
m_ViFrameRateWhole = -1;
|
|
|
|
m_ViFrameRateFraction = 0;
|
2015-12-23 19:41:11 +00:00
|
|
|
}
|
|
|
|
}
|
2016-08-10 10:03:25 +00:00
|
|
|
UpdateDisplay();
|
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
|
|
|
{
|
2019-01-15 08:10:11 +00:00
|
|
|
if (!bDisplayFrameRate())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2016-08-10 10:03:25 +00:00
|
|
|
if (m_iFrameRateType != FR_DLs && m_iFrameRateType != FR_VIs_DLs)
|
2015-12-23 19:41:11 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2016-08-10 10:03:25 +00:00
|
|
|
if ((m_CurrentDlistFrame & 3) == 0)
|
2015-12-23 19:41:11 +00:00
|
|
|
{
|
2016-09-16 21:37:27 +00:00
|
|
|
HighResTimeStamp Now;
|
|
|
|
Now.SetToNow();
|
|
|
|
m_FramesDlist[(m_CurrentDlistFrame >> 2) % NoOfFrames] = Now.GetMicroSeconds() - m_LastDlistFrame.GetMicroSeconds();
|
|
|
|
m_LastDlistFrame = Now;
|
2016-08-10 10:03:25 +00:00
|
|
|
if (m_CurrentDlistFrame > (NoOfFrames << 2))
|
2015-12-23 19:41:11 +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++)
|
|
|
|
{
|
2016-08-10 10:03:25 +00:00
|
|
|
Total += m_FramesDlist[count];
|
2015-12-23 19:41:11 +00:00
|
|
|
}
|
2016-09-16 21:37:27 +00:00
|
|
|
m_DlistFrameRate = ((NoOfFrames << 2) / ((float)Total / 1000000));
|
2015-12-23 19:41:11 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-08-10 10:03:25 +00:00
|
|
|
m_DlistFrameRate = -1.0;
|
2015-12-23 19:41:11 +00:00
|
|
|
}
|
2016-08-10 10:03:25 +00:00
|
|
|
UpdateDisplay();
|
2015-12-23 19:41:11 +00:00
|
|
|
}
|
2016-08-10 10:03:25 +00:00
|
|
|
m_CurrentDlistFrame += 1;
|
2015-12-23 19:41:11 +00:00
|
|
|
}
|