Added DoFrame to AchievementManager
DoFrame is a function called every frame by the emulator so that rcheevos can be properly updated and processed. It requires a memory peeker and an event handler to be passed in; the memory peeker is called repeatedly each frame to measure what's in memory and compare to achievement definitions, and any events thrown by that comparison are sent to the event handler. Also, DoFrame checks for the current system time to determine when to ping rich presence. Rich Presence on the RetroAchievements website updates every two minutes, so if two minutes have elapsed since the previous ping, another ping is sent.
This commit is contained in:
parent
22ee729055
commit
c9c2e17e5a
|
@ -14,6 +14,7 @@
|
||||||
#include "Core/PowerPC/MMU.h"
|
#include "Core/PowerPC/MMU.h"
|
||||||
#include "Core/System.h"
|
#include "Core/System.h"
|
||||||
#include "DiscIO/Volume.h"
|
#include "DiscIO/Volume.h"
|
||||||
|
#include "VideoCommon/VideoEvents.h"
|
||||||
|
|
||||||
static constexpr bool hardcore_mode_enabled = false;
|
static constexpr bool hardcore_mode_enabled = false;
|
||||||
|
|
||||||
|
@ -205,6 +206,28 @@ void AchievementManager::ActivateDeactivateRichPresence()
|
||||||
nullptr, 0);
|
nullptr, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AchievementManager::DoFrame()
|
||||||
|
{
|
||||||
|
if (!m_is_game_loaded)
|
||||||
|
return;
|
||||||
|
Core::RunAsCPUThread([&] {
|
||||||
|
rc_runtime_do_frame(
|
||||||
|
&m_runtime,
|
||||||
|
[](const rc_runtime_event_t* runtime_event) {
|
||||||
|
AchievementManager::GetInstance()->AchievementEventHandler(runtime_event);
|
||||||
|
},
|
||||||
|
[](unsigned address, unsigned num_bytes, void* ud) {
|
||||||
|
return static_cast<AchievementManager*>(ud)->MemoryPeeker(address, num_bytes, ud);
|
||||||
|
},
|
||||||
|
this, nullptr);
|
||||||
|
});
|
||||||
|
if (!m_system)
|
||||||
|
return;
|
||||||
|
u64 current_time = m_system->GetCoreTiming().GetTicks();
|
||||||
|
if (current_time - m_last_ping_time > SystemTimers::GetTicksPerSecond() * 120)
|
||||||
|
m_queue.EmplaceItem([this] { PingRichPresence(GenerateRichPresence()); });
|
||||||
|
}
|
||||||
|
|
||||||
u32 AchievementManager::MemoryPeeker(u32 address, u32 num_bytes, void* ud)
|
u32 AchievementManager::MemoryPeeker(u32 address, u32 num_bytes, void* ud)
|
||||||
{
|
{
|
||||||
if (!m_system)
|
if (!m_system)
|
||||||
|
|
|
@ -53,6 +53,7 @@ public:
|
||||||
void ActivateDeactivateLeaderboards();
|
void ActivateDeactivateLeaderboards();
|
||||||
void ActivateDeactivateRichPresence();
|
void ActivateDeactivateRichPresence();
|
||||||
|
|
||||||
|
void DoFrame();
|
||||||
u32 MemoryPeeker(u32 address, u32 num_bytes, void* ud);
|
u32 MemoryPeeker(u32 address, u32 num_bytes, void* ud);
|
||||||
void AchievementEventHandler(const rc_runtime_event_t* runtime_event);
|
void AchievementEventHandler(const rc_runtime_event_t* runtime_event);
|
||||||
|
|
||||||
|
@ -93,6 +94,7 @@ private:
|
||||||
u32 m_game_id = 0;
|
u32 m_game_id = 0;
|
||||||
rc_api_fetch_game_data_response_t m_game_data{};
|
rc_api_fetch_game_data_response_t m_game_data{};
|
||||||
bool m_is_game_loaded = false;
|
bool m_is_game_loaded = false;
|
||||||
|
u64 m_last_ping_time = 0;
|
||||||
|
|
||||||
struct UnlockStatus
|
struct UnlockStatus
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue