[Project64] Change Speed Limitor Class to use standard types

This commit is contained in:
zilmar 2015-11-09 05:53:05 +11:00
parent 2d16f87c7f
commit dc2a4683da
3 changed files with 102 additions and 90 deletions

View File

@ -2015,10 +2015,10 @@ void CN64System::RefreshScreen()
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); }
DWORD FrameRate;
uint32_t FrameRate;
if (m_Limitor.Timer_Process(&FrameRate) && bDisplayFrameRate())
{
m_FPS.DisplayViCounter(FrameRate);

View File

@ -9,6 +9,11 @@
* *
****************************************************************************/
#include "stdafx.h"
#include "Speed Limitor Class.h"
#include <common/util.h>
#include <Windows.h>
#include <Mmsystem.h>
#pragma comment(lib, "winmm.lib")
CSpeedLimitor::CSpeedLimitor()
@ -21,7 +26,8 @@ CSpeedLimitor::CSpeedLimitor()
TIMECAPS 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");
}
}
@ -33,7 +39,7 @@ CSpeedLimitor::~CSpeedLimitor()
timeEndPeriod(Caps.wPeriodMin);
}
void CSpeedLimitor::SetHertz(DWORD Hertz)
void CSpeedLimitor::SetHertz(uint32_t Hertz)
{
m_Speed = Hertz;
m_BaseSpeed = Hertz;
@ -47,30 +53,36 @@ void CSpeedLimitor::FixSpeedRatio()
m_LastTime = timeGetTime();
}
bool CSpeedLimitor::Timer_Process (DWORD * FrameRate ) {
bool CSpeedLimitor::Timer_Process(uint32_t * FrameRate)
{
m_Frames += 1;
DWORD CurrentTime = timeGetTime();
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);
if ((double)CurrentTime < CalculatedTime)
{
int32_t time = (int)(CalculatedTime - (double)CurrentTime);
if (time > 0)
{
pjutil::Sleep(time);
}
/* Refresh current time */
CurrentTime = timeGetTime();
}
if (CurrentTime - m_LastTime >= 1000) {
if (CurrentTime - m_LastTime >= 1000)
{
/* Output FPS */
if (FrameRate != NULL) { *FrameRate = m_Frames; }
m_Frames = 0;
m_LastTime = CurrentTime;
return true;
} else {
}
else
{
return false;
}
}

View File

@ -17,8 +17,8 @@ public:
CSpeedLimitor();
~CSpeedLimitor();
void SetHertz(const DWORD Hertz);
bool Timer_Process(DWORD* const FrameRate);
void SetHertz(const uint32_t Hertz);
bool Timer_Process(uint32_t* const FrameRate);
void IncreaseSpeed();
void DecreaseSpeed();
@ -28,6 +28,6 @@ private:
void FixSpeedRatio();
DWORD m_Speed, m_BaseSpeed, m_Frames, m_LastTime;
uint32_t m_Speed, m_BaseSpeed, m_Frames, m_LastTime;
double m_Ratio;
};