Skip to content

Commit

Permalink
Achievements: Use rc_client for pause throttling
Browse files Browse the repository at this point in the history
  • Loading branch information
stenzek committed Nov 24, 2024
1 parent 852239e commit 9fa8fee
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 19 deletions.
9 changes: 9 additions & 0 deletions src/core/achievements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1969,6 +1969,15 @@ std::string Achievements::GetLoggedInUserBadgePath()
return badge_path;
}

u32 Achievements::GetPauseThrottleFrames()
{
if (!IsActive() || !IsHardcoreModeActive() || IsUsingRAIntegration())
return 0;

u32 frames_remaining = 0;
return rc_client_can_pause(s_client, &frames_remaining) ? 0 : frames_remaining;
}

void Achievements::Logout()
{
if (IsActive())
Expand Down
3 changes: 3 additions & 0 deletions src/core/achievements.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ const char* GetLoggedInUserName();
/// Should be called with the lock held.
std::string GetLoggedInUserBadgePath();

/// Returns 0 if pausing is allowed, otherwise the number of frames until pausing is allowed.
u32 GetPauseThrottleFrames();

/// Clears all cached state used to render the UI.
void ClearUIState();

Expand Down
27 changes: 8 additions & 19 deletions src/core/hotkeys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,27 +139,16 @@ static void HotkeyToggleOSD()

static bool CanPause()
{
static constexpr const float PAUSE_INTERVAL = 3.0f;
static Common::Timer::Value s_last_pause_time = 0;

if (!Achievements::IsHardcoreModeActive() || System::IsPaused())
const u32 frames_until_pause_allowed = Achievements::GetPauseThrottleFrames();
if (frames_until_pause_allowed == 0)
return true;

const Common::Timer::Value time = Common::Timer::GetCurrentValue();
const float delta = static_cast<float>(Common::Timer::ConvertValueToSeconds(time - s_last_pause_time));
if (delta < PAUSE_INTERVAL)
{
Host::AddIconOSDMessage("PauseCooldown", ICON_FA_CLOCK,
TRANSLATE_PLURAL_STR("Hotkeys", "You cannot pause until another %n second(s) have passed.",
"", static_cast<int>(std::ceil(PAUSE_INTERVAL - delta))),
Host::OSD_QUICK_DURATION);
return false;
}

Host::RemoveKeyedOSDMessage("PauseCooldown");
s_last_pause_time = time;

return true;
const float seconds = static_cast<float>(frames_until_pause_allowed) / System::GetVideoFrameRate();
Host::AddIconOSDMessage("PauseCooldown", ICON_FA_CLOCK,
TRANSLATE_PLURAL_STR("Hotkeys", "You cannot pause until another %n second(s) have passed.",
"", static_cast<int>(std::ceil(seconds))),
std::max(seconds, Host::OSD_QUICK_DURATION));
return false;
}

#endif
Expand Down

0 comments on commit 9fa8fee

Please sign in to comment.