Skip to content

Commit

Permalink
Remove static method for awarding achievements
Browse files Browse the repository at this point in the history
  • Loading branch information
NikosSiak committed Nov 2, 2021
1 parent 214cf1b commit db76e2e
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 23 deletions.
16 changes: 6 additions & 10 deletions src/cheevos/Cheevos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/

#include "Cheevos.h"
#include "libretro/FrontendBridge.h"
#include "libretro/libretro.h"
#include "libretro/LibretroEnvironment.h"
#include "libretro/MemoryMap.h"
Expand Down Expand Up @@ -116,19 +117,14 @@ bool CCheevos::AwardAchievement(
game_hash) >= 0;
}

void CCheevos::GetCheevo_URL_ID(void (*Callback)(const char* achievement_url, unsigned cheevo_id))
void CCheevos::DeactivateTriggeredAchievement(unsigned cheevoId)
{
this->Callback = Callback;
}

void CCheevos::DeactivateTriggeredAchievement(unsigned cheevo_id)
{
rc_runtime_deactivate_achievement(&m_runtime, cheevo_id);
rc_runtime_deactivate_achievement(&m_runtime, cheevoId);
char url[URL_SIZE];
if (AwardAchievement(url, URL_SIZE, cheevo_id, 0, m_hash.c_str()))
if (AwardAchievement(url, URL_SIZE, cheevoId, 0, m_hash.c_str()))
{
std::string achievement_url = url;
this->Callback(url, cheevo_id);
std::string achievementUrl = url;
CFrontendBridge::AwardAchievement(achievementUrl.c_str(), cheevoId);
}
}

Expand Down
5 changes: 1 addition & 4 deletions src/cheevos/Cheevos.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,9 @@ class CCheevos
void ActivateAchievement(unsigned cheevo_id, const char* memaddr);
bool AwardAchievement(
char* url, size_t size, unsigned cheevo_id, int hardcore, const char* game_hash);
void DeactivateTriggeredAchievement(unsigned cheevo_id);
void DeactivateTriggeredAchievement(unsigned cheevoId);
void TestCheevoStatusPerFrame();
unsigned int Peek(unsigned int address, unsigned int numBytes);
void GetCheevo_URL_ID(void (*Callback)(const char* achievement_url, unsigned cheevo_id));

private:
const uint8_t* FixupFind(unsigned address, CMemoryMap& mmap, int consolecheevos);
Expand All @@ -60,8 +59,6 @@ class CCheevos
static unsigned int PeekInternal(unsigned address, unsigned num_bytes, void* ud);
static void RuntimeEventHandler(const rc_runtime_event_t* runtime_event);

void (*Callback)(const char* achievement_url, unsigned cheevo_id);

rc_runtime_t m_runtime;
std::unordered_map<unsigned, const uint8_t*> m_addressFixups;

Expand Down
7 changes: 0 additions & 7 deletions src/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -538,13 +538,6 @@ GAME_ERROR CGameLibRetro::ActivateAchievement(unsigned cheevo_id, const char* me
return GAME_ERROR_NO_ERROR;
}

GAME_ERROR CGameLibRetro::GetCheevo_URL_ID(void (*Callback)(const char* achievement_url,
unsigned cheevo_id))
{
CCheevos::Get().GetCheevo_URL_ID(Callback);
return GAME_ERROR_NO_ERROR;
}

GAME_ERROR CGameLibRetro::RCResetRuntime()
{
CCheevos::Get().ResetRuntime();
Expand Down
2 changes: 0 additions & 2 deletions src/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,6 @@ class ATTRIBUTE_HIDDEN CGameLibRetro
GAME_ERROR GetRichPresenceEvaluation(char* evaluation, size_t size) override;
GAME_ERROR ActivateAchievement(unsigned cheevo_id, const char* memaddr) override;
GAME_ERROR RCResetRuntime() override;
GAME_ERROR GetCheevo_URL_ID(void (*Callback)(const char* achievement_url,
unsigned cheevo_id)) override;

private:
GAME_ERROR AudioAvailable();
Expand Down
8 changes: 8 additions & 0 deletions src/libretro/FrontendBridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,14 @@ float CFrontendBridge::SensorGetInput(unsigned port, unsigned id)
return axisState;
}

void CFrontendBridge::AwardAchievement(const char* achievementUrl, unsigned cheevoId)
{
if (!CLibretroEnvironment::Get().GetAddon())
return;

CLibretroEnvironment::Get().GetAddon()->AwardAchievement(achievementUrl, cheevoId);
}

bool CFrontendBridge::StartCamera(void)
{
return false; // Not implemented
Expand Down
1 change: 1 addition & 0 deletions src/libretro/FrontendBridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ namespace LIBRETRO
static bool RumbleSetState(unsigned port, retro_rumble_effect effect, uint16_t strength);
static bool SensorSetState(unsigned port, retro_sensor_action action, unsigned rate);
static float SensorGetInput(unsigned port, unsigned id);
static void AwardAchievement(const char* achievementUrl, unsigned cheevoId);
static bool StartCamera(void);
static void StopCamera(void);
static retro_time_t PerfGetTimeUsec(void);
Expand Down

0 comments on commit db76e2e

Please sign in to comment.