[Project64] Change Speed Limitor Class to use standard types
This commit is contained in:
parent
2d16f87c7f
commit
dc2a4683da
|
@ -2014,18 +2014,18 @@ void CN64System::RefreshScreen()
|
||||||
}
|
}
|
||||||
|
|
||||||
g_MMU->UpdateFieldSerration((m_Reg.VI_STATUS_REG & 0x40) != 0);
|
g_MMU->UpdateFieldSerration((m_Reg.VI_STATUS_REG & 0x40) != 0);
|
||||||
|
|
||||||
if ((bBasicMode() || bLimitFPS() ) && !bSyncToAudio())
|
if ((bBasicMode() || bLimitFPS()) && !bSyncToAudio())
|
||||||
{
|
{
|
||||||
if (bShowCPUPer()) { m_CPU_Usage.StartTimer(Timer_Idel); }
|
if (bShowCPUPer()) { m_CPU_Usage.StartTimer(Timer_Idel); }
|
||||||
DWORD FrameRate;
|
uint32_t FrameRate;
|
||||||
if (m_Limitor.Timer_Process(&FrameRate) && bDisplayFrameRate())
|
if (m_Limitor.Timer_Process(&FrameRate) && bDisplayFrameRate())
|
||||||
{
|
{
|
||||||
m_FPS.DisplayViCounter(FrameRate);
|
m_FPS.DisplayViCounter(FrameRate);
|
||||||
m_bCleanFrameBox = true;
|
m_bCleanFrameBox = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (bDisplayFrameRate())
|
else if (bDisplayFrameRate())
|
||||||
{
|
{
|
||||||
if (bShowCPUPer()) { m_CPU_Usage.StartTimer(Timer_UpdateFPS); }
|
if (bShowCPUPer()) { m_CPU_Usage.StartTimer(Timer_UpdateFPS); }
|
||||||
m_FPS.UpdateViCounter();
|
m_FPS.UpdateViCounter();
|
||||||
|
|
|
@ -9,104 +9,116 @@
|
||||||
* *
|
* *
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
#include "stdafx.h"
|
#include "stdafx.h"
|
||||||
#pragma comment(lib, "winmm.lib")
|
#include "Speed Limitor Class.h"
|
||||||
|
#include <common/util.h>
|
||||||
|
#include <Windows.h>
|
||||||
|
#include <Mmsystem.h>
|
||||||
|
|
||||||
|
#pragma comment(lib, "winmm.lib")
|
||||||
|
|
||||||
CSpeedLimitor::CSpeedLimitor()
|
CSpeedLimitor::CSpeedLimitor()
|
||||||
{
|
{
|
||||||
m_Frames = 0;
|
m_Frames = 0;
|
||||||
m_LastTime = 0;
|
m_LastTime = 0;
|
||||||
m_Speed = 60;
|
m_Speed = 60;
|
||||||
m_BaseSpeed = 60;
|
m_BaseSpeed = 60;
|
||||||
m_Ratio = 1000.0F / (float)m_Speed;
|
m_Ratio = 1000.0F / (float)m_Speed;
|
||||||
|
|
||||||
TIMECAPS Caps;
|
TIMECAPS Caps;
|
||||||
timeGetDevCaps(&Caps, sizeof(Caps));
|
timeGetDevCaps(&Caps, sizeof(Caps));
|
||||||
if (timeBeginPeriod(Caps.wPeriodMin) == TIMERR_NOCANDO) {
|
if (timeBeginPeriod(Caps.wPeriodMin) == TIMERR_NOCANDO)
|
||||||
g_Notify->DisplayError(L"Error during timer begin");
|
{
|
||||||
}
|
g_Notify->DisplayError(L"Error during timer begin");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CSpeedLimitor::~CSpeedLimitor()
|
CSpeedLimitor::~CSpeedLimitor()
|
||||||
{
|
{
|
||||||
TIMECAPS Caps;
|
TIMECAPS Caps;
|
||||||
timeGetDevCaps(&Caps, sizeof(Caps));
|
timeGetDevCaps(&Caps, sizeof(Caps));
|
||||||
timeEndPeriod(Caps.wPeriodMin);
|
timeEndPeriod(Caps.wPeriodMin);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSpeedLimitor::SetHertz(DWORD Hertz)
|
void CSpeedLimitor::SetHertz(uint32_t Hertz)
|
||||||
{
|
{
|
||||||
m_Speed = Hertz;
|
m_Speed = Hertz;
|
||||||
m_BaseSpeed = Hertz;
|
m_BaseSpeed = Hertz;
|
||||||
FixSpeedRatio();
|
FixSpeedRatio();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSpeedLimitor::FixSpeedRatio()
|
void CSpeedLimitor::FixSpeedRatio()
|
||||||
{
|
{
|
||||||
m_Ratio = 1000.0f / static_cast<double>(m_Speed);
|
m_Ratio = 1000.0f / static_cast<double>(m_Speed);
|
||||||
m_Frames = 0;
|
m_Frames = 0;
|
||||||
m_LastTime = timeGetTime();
|
m_LastTime = timeGetTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CSpeedLimitor::Timer_Process (DWORD * FrameRate ) {
|
bool CSpeedLimitor::Timer_Process(uint32_t * FrameRate)
|
||||||
m_Frames += 1;
|
{
|
||||||
DWORD CurrentTime = timeGetTime();
|
m_Frames += 1;
|
||||||
|
uint32_t CurrentTime = timeGetTime();
|
||||||
/* Calculate time that should of elapsed for this frame */
|
|
||||||
double CalculatedTime = (double)m_LastTime + (m_Ratio * (double)m_Frames);
|
|
||||||
if ((double)CurrentTime < CalculatedTime) {
|
|
||||||
long time = (int)(CalculatedTime - (double)CurrentTime);
|
|
||||||
if (time > 0) {
|
|
||||||
Sleep(time);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Refresh current time */
|
/* Calculate time that should of elapsed for this frame */
|
||||||
CurrentTime = timeGetTime();
|
double CalculatedTime = (double)m_LastTime + (m_Ratio * (double)m_Frames);
|
||||||
}
|
if ((double)CurrentTime < CalculatedTime)
|
||||||
|
{
|
||||||
|
int32_t time = (int)(CalculatedTime - (double)CurrentTime);
|
||||||
|
if (time > 0)
|
||||||
|
{
|
||||||
|
pjutil::Sleep(time);
|
||||||
|
}
|
||||||
|
|
||||||
if (CurrentTime - m_LastTime >= 1000) {
|
/* Refresh current time */
|
||||||
/* Output FPS */
|
CurrentTime = timeGetTime();
|
||||||
if (FrameRate != NULL) { *FrameRate = m_Frames; }
|
}
|
||||||
m_Frames = 0;
|
|
||||||
m_LastTime = CurrentTime;
|
|
||||||
|
|
||||||
return true;
|
if (CurrentTime - m_LastTime >= 1000)
|
||||||
} else {
|
{
|
||||||
return false;
|
/* Output FPS */
|
||||||
}
|
if (FrameRate != NULL) { *FrameRate = m_Frames; }
|
||||||
|
m_Frames = 0;
|
||||||
|
m_LastTime = CurrentTime;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSpeedLimitor::IncreaseSpeed()
|
void CSpeedLimitor::IncreaseSpeed()
|
||||||
{
|
{
|
||||||
if (m_Speed >= 60)
|
if (m_Speed >= 60)
|
||||||
{
|
{
|
||||||
m_Speed += 10;
|
m_Speed += 10;
|
||||||
}
|
}
|
||||||
else if (m_Speed >= 15)
|
else if (m_Speed >= 15)
|
||||||
{
|
{
|
||||||
m_Speed += 5;
|
m_Speed += 5;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_Speed += 1;
|
m_Speed += 1;
|
||||||
}
|
}
|
||||||
SpeedChanged(m_Speed);
|
SpeedChanged(m_Speed);
|
||||||
FixSpeedRatio();
|
FixSpeedRatio();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSpeedLimitor::DecreaseSpeed()
|
void CSpeedLimitor::DecreaseSpeed()
|
||||||
{
|
{
|
||||||
if (m_Speed > 60)
|
if (m_Speed > 60)
|
||||||
{
|
{
|
||||||
m_Speed -= 10;
|
m_Speed -= 10;
|
||||||
}
|
}
|
||||||
else if (m_Speed > 15)
|
else if (m_Speed > 15)
|
||||||
{
|
{
|
||||||
m_Speed -= 5;
|
m_Speed -= 5;
|
||||||
}
|
}
|
||||||
else if (m_Speed > 1)
|
else if (m_Speed > 1)
|
||||||
{
|
{
|
||||||
m_Speed -= 1;
|
m_Speed -= 1;
|
||||||
}
|
}
|
||||||
SpeedChanged(m_Speed);
|
SpeedChanged(m_Speed);
|
||||||
FixSpeedRatio();
|
FixSpeedRatio();
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,23 +11,23 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
class CSpeedLimitor :
|
class CSpeedLimitor :
|
||||||
private CGameSettings
|
private CGameSettings
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CSpeedLimitor();
|
CSpeedLimitor();
|
||||||
~CSpeedLimitor();
|
~CSpeedLimitor();
|
||||||
|
|
||||||
void SetHertz(const DWORD Hertz);
|
void SetHertz(const uint32_t Hertz);
|
||||||
bool Timer_Process(DWORD* const FrameRate);
|
bool Timer_Process(uint32_t* const FrameRate);
|
||||||
void IncreaseSpeed();
|
void IncreaseSpeed();
|
||||||
void DecreaseSpeed();
|
void DecreaseSpeed();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CSpeedLimitor(const CSpeedLimitor&); // Disable copy constructor
|
CSpeedLimitor(const CSpeedLimitor&); // Disable copy constructor
|
||||||
CSpeedLimitor& operator=(const CSpeedLimitor&); // Disable assignment
|
CSpeedLimitor& operator=(const CSpeedLimitor&); // Disable assignment
|
||||||
|
|
||||||
void FixSpeedRatio();
|
void FixSpeedRatio();
|
||||||
|
|
||||||
DWORD m_Speed, m_BaseSpeed, m_Frames, m_LastTime;
|
uint32_t m_Speed, m_BaseSpeed, m_Frames, m_LastTime;
|
||||||
double m_Ratio;
|
double m_Ratio;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue