Merge pull request #13675 from LillyJadeKatrin/retroachievements-close-deadlock
AchievementManager - LoadGameCallback
This commit is contained in:
commit
1dc4dc6b6d
|
@ -58,14 +58,13 @@ AchievementManager& AchievementManager::GetInstance()
|
||||||
return s_instance;
|
return s_instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AchievementManager::Init(void* hwnd, AsyncCallbackHandler async_callback_handler)
|
void AchievementManager::Init(void* hwnd)
|
||||||
{
|
{
|
||||||
LoadDefaultBadges();
|
LoadDefaultBadges();
|
||||||
if (!m_client && Config::Get(Config::RA_ENABLED))
|
if (!m_client && Config::Get(Config::RA_ENABLED))
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
std::lock_guard lg{m_lock};
|
std::lock_guard lg{m_lock};
|
||||||
m_async_callback_handler = std::move(async_callback_handler);
|
|
||||||
m_client = rc_client_create(MemoryVerifier, Request);
|
m_client = rc_client_create(MemoryVerifier, Request);
|
||||||
}
|
}
|
||||||
std::string host_url = Config::Get(Config::RA_HOST_URL);
|
std::string host_url = Config::Get(Config::RA_HOST_URL);
|
||||||
|
@ -994,22 +993,22 @@ void AchievementManager::LoadGameCallback(int result, const char* error_message,
|
||||||
OSD::Duration::VERY_LONG, OSD::Color::RED);
|
OSD::Duration::VERY_LONG, OSD::Color::RED);
|
||||||
OSD::AddMessage("Please update Dolphin to a newer version.", OSD::Duration::VERY_LONG,
|
OSD::AddMessage("Please update Dolphin to a newer version.", OSD::Duration::VERY_LONG,
|
||||||
OSD::Color::RED);
|
OSD::Color::RED);
|
||||||
instance.CloseGame();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (result == RC_NO_GAME_LOADED && instance.m_dll_found)
|
||||||
|
{
|
||||||
|
// Allow developer tools for unidentified games
|
||||||
|
rc_client_set_read_memory_function(instance.m_client, MemoryPeeker);
|
||||||
|
instance.m_system.store(&Core::System::GetInstance(), std::memory_order_release);
|
||||||
|
WARN_LOG_FMT(ACHIEVEMENTS, "Unrecognized title ready for development.");
|
||||||
|
OSD::AddMessage("Unrecognized title loaded for development.", OSD::Duration::VERY_LONG,
|
||||||
|
OSD::Color::YELLOW);
|
||||||
|
}
|
||||||
if (result != RC_OK)
|
if (result != RC_OK)
|
||||||
{
|
{
|
||||||
WARN_LOG_FMT(ACHIEVEMENTS, "Failed to load data for current game.");
|
WARN_LOG_FMT(ACHIEVEMENTS, "Failed to load data for current game.");
|
||||||
OSD::AddMessage("Achievements are not supported for this title.", OSD::Duration::VERY_LONG,
|
OSD::AddMessage("Achievements are not supported for this title.", OSD::Duration::VERY_LONG,
|
||||||
OSD::Color::RED);
|
OSD::Color::RED);
|
||||||
if (instance.m_dll_found && result == RC_NO_GAME_LOADED)
|
|
||||||
{
|
|
||||||
// Allow developer tools for unidentified games
|
|
||||||
rc_client_set_read_memory_function(instance.m_client, MemoryPeeker);
|
|
||||||
instance.m_system.store(&Core::System::GetInstance(), std::memory_order_release);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
instance.CloseGame();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1284,18 +1283,12 @@ void AchievementManager::Request(const rc_api_request_t* request,
|
||||||
Common::HttpRequest::AllowedReturnCodes::All);
|
Common::HttpRequest::AllowedReturnCodes::All);
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto response_code = http_request.GetLastResponseCode();
|
|
||||||
|
|
||||||
// The callback needs to be invoked inside our async callback handler
|
|
||||||
// as it may trigger a shutdown which will wait on this very job to complete.
|
|
||||||
AchievementManager::GetInstance().m_async_callback_handler(
|
|
||||||
[callback, callback_data, http_response = std::move(http_response), response_code] {
|
|
||||||
rc_api_server_response_t server_response;
|
rc_api_server_response_t server_response;
|
||||||
if (http_response.has_value() && http_response->size() > 0)
|
if (http_response.has_value() && http_response->size() > 0)
|
||||||
{
|
{
|
||||||
server_response.body = reinterpret_cast<const char*>(http_response->data());
|
server_response.body = reinterpret_cast<const char*>(http_response->data());
|
||||||
server_response.body_length = http_response->size();
|
server_response.body_length = http_response->size();
|
||||||
server_response.http_status_code = response_code;
|
server_response.http_status_code = http_request.GetLastResponseCode();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -1304,9 +1297,9 @@ void AchievementManager::Request(const rc_api_request_t* request,
|
||||||
server_response.body_length = sizeof(error_message);
|
server_response.body_length = sizeof(error_message);
|
||||||
server_response.http_status_code = RC_API_SERVER_RESPONSE_RETRYABLE_CLIENT_ERROR;
|
server_response.http_status_code = RC_API_SERVER_RESPONSE_RETRYABLE_CLIENT_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
callback(&server_response, callback_data);
|
callback(&server_response, callback_data);
|
||||||
});
|
});
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Currently, when rc_client calls the memory peek method provided in its constructor (or in
|
// Currently, when rc_client calls the memory peek method provided in its constructor (or in
|
||||||
|
|
|
@ -29,7 +29,6 @@
|
||||||
#include "Common/CommonTypes.h"
|
#include "Common/CommonTypes.h"
|
||||||
#include "Common/Config/Config.h"
|
#include "Common/Config/Config.h"
|
||||||
#include "Common/Event.h"
|
#include "Common/Event.h"
|
||||||
#include "Common/Functional.h"
|
|
||||||
#include "Common/HttpRequest.h"
|
#include "Common/HttpRequest.h"
|
||||||
#include "Common/JsonUtil.h"
|
#include "Common/JsonUtil.h"
|
||||||
#include "Common/Lazy.h"
|
#include "Common/Lazy.h"
|
||||||
|
@ -122,12 +121,8 @@ public:
|
||||||
};
|
};
|
||||||
using UpdateCallback = std::function<void(const UpdatedItems&)>;
|
using UpdateCallback = std::function<void(const UpdatedItems&)>;
|
||||||
|
|
||||||
using AsyncCallback = Common::MoveOnlyFunction<void()>;
|
|
||||||
using AsyncCallbackHandler = Common::MoveOnlyFunction<void(AsyncCallback)>;
|
|
||||||
|
|
||||||
static AchievementManager& GetInstance();
|
static AchievementManager& GetInstance();
|
||||||
|
void Init(void* hwnd);
|
||||||
void Init(void* hwnd, AsyncCallbackHandler async_callback_handler);
|
|
||||||
void SetUpdateCallback(UpdateCallback callback);
|
void SetUpdateCallback(UpdateCallback callback);
|
||||||
void Login(const std::string& password);
|
void Login(const std::string& password);
|
||||||
bool HasAPIToken() const;
|
bool HasAPIToken() const;
|
||||||
|
@ -313,8 +308,6 @@ private:
|
||||||
Common::AsyncWorkThread m_image_queue;
|
Common::AsyncWorkThread m_image_queue;
|
||||||
mutable std::recursive_mutex m_lock;
|
mutable std::recursive_mutex m_lock;
|
||||||
std::recursive_mutex m_filereader_lock;
|
std::recursive_mutex m_filereader_lock;
|
||||||
|
|
||||||
AsyncCallbackHandler m_async_callback_handler;
|
|
||||||
}; // class AchievementManager
|
}; // class AchievementManager
|
||||||
|
|
||||||
#else // USE_RETRO_ACHIEVEMENTS
|
#else // USE_RETRO_ACHIEVEMENTS
|
||||||
|
|
|
@ -6,12 +6,13 @@
|
||||||
|
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QLineEdit>
|
#include <QLineEdit>
|
||||||
#include <QPushButton>
|
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
|
|
||||||
#include "Core/AchievementManager.h"
|
#include "Core/AchievementManager.h"
|
||||||
#include "Core/Config/AchievementSettings.h"
|
#include "Core/Config/AchievementSettings.h"
|
||||||
|
#include "Core/Config/FreeLookSettings.h"
|
||||||
|
#include "Core/Config/MainSettings.h"
|
||||||
#include "Core/Config/UISettings.h"
|
#include "Core/Config/UISettings.h"
|
||||||
#include "Core/Core.h"
|
#include "Core/Core.h"
|
||||||
#include "Core/Movie.h"
|
#include "Core/Movie.h"
|
||||||
|
@ -21,7 +22,7 @@
|
||||||
#include "DolphinQt/Config/ControllerInterface/ControllerInterfaceWindow.h"
|
#include "DolphinQt/Config/ControllerInterface/ControllerInterfaceWindow.h"
|
||||||
#include "DolphinQt/Config/ToolTipControls/ToolTipCheckBox.h"
|
#include "DolphinQt/Config/ToolTipControls/ToolTipCheckBox.h"
|
||||||
#include "DolphinQt/QtUtils/ModalMessageBox.h"
|
#include "DolphinQt/QtUtils/ModalMessageBox.h"
|
||||||
#include "DolphinQt/QtUtils/QueueOnObject.h"
|
#include "DolphinQt/QtUtils/NonDefaultQPushButton.h"
|
||||||
#include "DolphinQt/QtUtils/SignalBlocking.h"
|
#include "DolphinQt/QtUtils/SignalBlocking.h"
|
||||||
#include "DolphinQt/Settings.h"
|
#include "DolphinQt/Settings.h"
|
||||||
|
|
||||||
|
@ -251,14 +252,9 @@ void AchievementSettingsWidget::ToggleRAIntegration()
|
||||||
|
|
||||||
auto& instance = AchievementManager::GetInstance();
|
auto& instance = AchievementManager::GetInstance();
|
||||||
if (Config::Get(Config::RA_ENABLED))
|
if (Config::Get(Config::RA_ENABLED))
|
||||||
{
|
instance.Init(reinterpret_cast<void*>(winId()));
|
||||||
instance.Init(reinterpret_cast<void*>(winId()),
|
|
||||||
[this](auto func) { QueueOnObject(this, std::move(func)); });
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
|
||||||
instance.Shutdown();
|
instance.Shutdown();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AchievementSettingsWidget::Login()
|
void AchievementSettingsWidget::Login()
|
||||||
|
|
|
@ -274,9 +274,7 @@ MainWindow::MainWindow(Core::System& system, std::unique_ptr<BootParameters> boo
|
||||||
NetPlayInit();
|
NetPlayInit();
|
||||||
|
|
||||||
#ifdef USE_RETRO_ACHIEVEMENTS
|
#ifdef USE_RETRO_ACHIEVEMENTS
|
||||||
AchievementManager::GetInstance().Init(reinterpret_cast<void*>(winId()), [this](auto func) {
|
AchievementManager::GetInstance().Init(reinterpret_cast<void*>(winId()));
|
||||||
QueueOnObject(this, std::move(func));
|
|
||||||
});
|
|
||||||
if (AchievementManager::GetInstance().IsHardcoreModeActive())
|
if (AchievementManager::GetInstance().IsHardcoreModeActive())
|
||||||
Settings::Instance().SetDebugModeEnabled(false);
|
Settings::Instance().SetDebugModeEnabled(false);
|
||||||
// This needs to trigger on both RA_HARDCORE_ENABLED and RA_ENABLED
|
// This needs to trigger on both RA_HARDCORE_ENABLED and RA_ENABLED
|
||||||
|
|
Loading…
Reference in New Issue