diff --git a/Source/Project64-core/N64System/N64Class.h b/Source/Project64-core/N64System/N64Class.h index 46d8901bd..e14700966 100644 --- a/Source/Project64-core/N64System/N64Class.h +++ b/Source/Project64-core/N64System/N64Class.h @@ -67,8 +67,7 @@ public: void StartEmulation(bool NewThread); void EndEmulation(); void SyncToAudio(); - void IncreaseSpeed() { m_Limiter.IncreaseSpeed(); } - void DecreaseSpeed() { m_Limiter.DecreaseSpeed(); } + void AlterSpeed(const CSpeedLimiter::ESpeedChange SpeedChange) { m_Limiter.AlterSpeed(SpeedChange); } void Reset(bool bInitReg, bool ClearMenory); void GameReset(); void PluginReset(); diff --git a/Source/Project64-core/N64System/SpeedLimiterClass.cpp b/Source/Project64-core/N64System/SpeedLimiterClass.cpp index 1b78cee4e..6e867eaeb 100644 --- a/Source/Project64-core/N64System/SpeedLimiterClass.cpp +++ b/Source/Project64-core/N64System/SpeedLimiterClass.cpp @@ -1,6 +1,6 @@ /**************************************************************************** * * -* Project64 - A Nintendo 64 emulator. * +* Project64 - A Nintendo 64 emulator. * * http://www.pj64-emu.com/ * * Copyright (C) 2012 Project64. All rights reserved. * * * @@ -8,14 +8,23 @@ * GNU/GPLv2 http://www.gnu.org/licenses/gpl-2.0.html * * * ****************************************************************************/ + #include "stdafx.h" -#include "SpeedLimiterClass.h" +#include "Project64-Core/N64System/SpeedLimiterClass.h" + #include +// --------------------------------------------------- + +const uint32_t CSpeedLimiter::m_HighSpeed = 60; +const uint32_t CSpeedLimiter::m_MediumSpeed = 15; + +// --------------------------------------------------- + CSpeedLimiter::CSpeedLimiter() : m_Frames(0), -m_Speed(60), -m_BaseSpeed(60) +m_Speed(m_HighSpeed), +m_BaseSpeed(m_HighSpeed) { } @@ -73,38 +82,24 @@ bool CSpeedLimiter::Timer_Process(uint32_t * FrameRate) return false; } -void CSpeedLimiter::IncreaseSpeed() +void CSpeedLimiter::AlterSpeed( const ESpeedChange SpeedChange ) { - if (m_Speed >= 60) - { - m_Speed += 10; - } - else if (m_Speed >= 15) - { - m_Speed += 5; - } - else - { - m_Speed += 1; - } - SpeedChanged(m_Speed); - FixSpeedRatio(); -} + int32_t SpeedFactor = 1; + if (SpeedChange == DECREASE_SPEED) { SpeedFactor = -1; } -void CSpeedLimiter::DecreaseSpeed() -{ - if (m_Speed > 60) - { - m_Speed -= 10; - } - else if (m_Speed > 15) - { - m_Speed -= 5; - } - else if (m_Speed > 1) - { - m_Speed -= 1; - } - SpeedChanged(m_Speed); - FixSpeedRatio(); -} + if (m_Speed >= m_HighSpeed) + { + m_Speed += 10 * SpeedFactor; + } + else if (m_Speed >= m_MediumSpeed) + { + m_Speed += 5 * SpeedFactor; + } + else + { + m_Speed += 1 * SpeedFactor; + } + + SpeedChanged(m_Speed); + FixSpeedRatio(); +} \ No newline at end of file diff --git a/Source/Project64-core/N64System/SpeedLimiterClass.h b/Source/Project64-core/N64System/SpeedLimiterClass.h index e213373ae..4e38b3034 100644 --- a/Source/Project64-core/N64System/SpeedLimiterClass.h +++ b/Source/Project64-core/N64System/SpeedLimiterClass.h @@ -1,6 +1,6 @@ /**************************************************************************** * * -* Project64 - A Nintendo 64 emulator. * +* Project64 - A Nintendo 64 emulator. * * http://www.pj64-emu.com/ * * Copyright (C) 2012 Project64. All rights reserved. * * * @@ -11,19 +11,22 @@ #pragma once #include + #include class CSpeedLimiter : private CGameSettings { public: + enum ESpeedChange { INCREASE_SPEED, DECREASE_SPEED }; + CSpeedLimiter(); ~CSpeedLimiter(); void SetHertz(const uint32_t Hertz); bool Timer_Process(uint32_t* const FrameRate); - void IncreaseSpeed(); - void DecreaseSpeed(); + + void AlterSpeed(const ESpeedChange SpeedChange); private: CSpeedLimiter(const CSpeedLimiter&); // Disable copy constructor @@ -31,7 +34,10 @@ private: void FixSpeedRatio(); - uint32_t m_Speed, m_BaseSpeed, m_Frames; - HighResTimeStamp m_LastTime; - uint32_t m_MicroSecondsPerFrame; + HighResTimeStamp m_LastTime; + + uint32_t m_Speed, m_BaseSpeed, m_Frames, m_MicroSecondsPerFrame; + + static const uint32_t m_HighSpeed; + static const uint32_t m_MediumSpeed; }; diff --git a/Source/Project64/UserInterface/MainMenuClass.cpp b/Source/Project64/UserInterface/MainMenuClass.cpp index b29c518ea..8339b52a5 100644 --- a/Source/Project64/UserInterface/MainMenuClass.cpp +++ b/Source/Project64/UserInterface/MainMenuClass.cpp @@ -385,10 +385,10 @@ bool CMainMenu::ProcessMessage(HWND hWnd, DWORD /*FromAccelerator*/, DWORD MenuI } break; case ID_OPTIONS_INCREASE_SPEED: - g_BaseSystem->IncreaseSpeed(); + g_BaseSystem->AlterSpeed(CSpeedLimiter::INCREASE_SPEED); break; case ID_OPTIONS_DECREASE_SPEED: - g_BaseSystem->DecreaseSpeed(); + g_BaseSystem->AlterSpeed(CSpeedLimiter::DECREASE_SPEED); break; case ID_OPTIONS_FULLSCREEN: g_BaseSystem->ExternalEvent(SysEvent_ChangingFullScreen);