NetPlay: Pass Wii FS sync data directly to game boot logic instead of indirectly through globals.

This commit is contained in:
Admiral H. Curtiss 2021-11-20 21:03:34 +01:00
parent 894773f607
commit 6350c93ae1
No known key found for this signature in database
GPG Key ID: F051B4C4044F33FB
6 changed files with 40 additions and 38 deletions

View File

@ -76,8 +76,6 @@ using namespace WiimoteCommon;
static std::mutex crit_netplay_client; static std::mutex crit_netplay_client;
static NetPlayClient* netplay_client = nullptr; static NetPlayClient* netplay_client = nullptr;
static std::unique_ptr<IOS::HLE::FS::FileSystem> s_wii_sync_fs;
static std::vector<u64> s_wii_sync_titles;
static bool s_si_poll_batching = false; static bool s_si_poll_batching = false;
// called from ---GUI--- thread // called from ---GUI--- thread
@ -1192,7 +1190,7 @@ void NetPlayClient::OnSyncSaveDataWii(sf::Packet& packet)
} }
} }
SetWiiSyncData(std::move(temp_fs), titles); SetWiiSyncData(std::move(temp_fs), std::move(titles));
SyncSaveDataResponse(true); SyncSaveDataResponse(true);
} }
@ -1722,7 +1720,14 @@ bool NetPlayClient::StartGame(const std::string& path)
} }
// boot game // boot game
m_dialog->BootGame(path, nullptr); auto boot_session_data = std::make_unique<BootSessionData>();
boot_session_data->SetWiiSyncData(std::move(m_wii_sync_fs), std::move(m_wii_sync_titles), [] {
// on emulation end clean up the Wii save sync directory -- see OnSyncSaveDataWii()
const std::string path = File::GetUserPath(D_USER_IDX) + "Wii" GC_MEMCARD_NETPLAY DIR_SEP;
if (File::Exists(path))
File::DeleteDirRecursively(path);
});
m_dialog->BootGame(path, std::move(boot_session_data));
UpdateDevices(); UpdateDevices();
@ -2252,8 +2257,6 @@ bool NetPlayClient::StopGame()
// stop game // stop game
m_dialog->StopGame(); m_dialog->StopGame();
ClearWiiSyncData();
return true; return true;
} }
@ -2497,6 +2500,13 @@ void NetPlayClient::AdjustPadBufferSize(const unsigned int size)
m_dialog->OnPadBufferChanged(size); m_dialog->OnPadBufferChanged(size);
} }
void NetPlayClient::SetWiiSyncData(std::unique_ptr<IOS::HLE::FS::FileSystem> fs,
std::vector<u64> titles)
{
m_wii_sync_fs = std::move(fs);
m_wii_sync_titles = std::move(titles);
}
SyncIdentifier NetPlayClient::GetSDCardIdentifier() SyncIdentifier NetPlayClient::GetSDCardIdentifier()
{ {
return SyncIdentifier{{}, "sd", {}, {}, {}, {}}; return SyncIdentifier{{}, "sd", {}, {}, {}, {}};
@ -2539,33 +2549,6 @@ const NetSettings& GetNetSettings()
return netplay_client->GetNetSettings(); return netplay_client->GetNetSettings();
} }
IOS::HLE::FS::FileSystem* GetWiiSyncFS()
{
return s_wii_sync_fs.get();
}
const std::vector<u64>& GetWiiSyncTitles()
{
return s_wii_sync_titles;
}
void SetWiiSyncData(std::unique_ptr<IOS::HLE::FS::FileSystem> fs, const std::vector<u64>& titles)
{
s_wii_sync_fs = std::move(fs);
s_wii_sync_titles.insert(s_wii_sync_titles.end(), titles.begin(), titles.end());
}
void ClearWiiSyncData()
{
// We're just assuming it will always be here because it is
const std::string path = File::GetUserPath(D_USER_IDX) + "Wii" GC_MEMCARD_NETPLAY DIR_SEP;
if (File::Exists(path))
File::DeleteDirRecursively(path);
s_wii_sync_fs.reset();
s_wii_sync_titles.clear();
}
void SetSIPollBatching(bool state) void SetSIPollBatching(bool state)
{ {
s_si_poll_batching = state; s_si_poll_batching = state;

View File

@ -25,6 +25,11 @@
class BootSessionData; class BootSessionData;
namespace IOS::HLE::FS
{
class FileSystem;
}
namespace UICommon namespace UICommon
{ {
class GameFile; class GameFile;
@ -80,6 +85,8 @@ public:
const std::vector<int>& players) = 0; const std::vector<int>& players) = 0;
virtual void HideChunkedProgressDialog() = 0; virtual void HideChunkedProgressDialog() = 0;
virtual void SetChunkedProgress(int pid, u64 progress) = 0; virtual void SetChunkedProgress(int pid, u64 progress) = 0;
virtual void SetHostWiiSyncTitles(std::vector<u64> titles) = 0;
}; };
class Player class Player
@ -150,6 +157,8 @@ public:
void AdjustPadBufferSize(unsigned int size); void AdjustPadBufferSize(unsigned int size);
void SetWiiSyncData(std::unique_ptr<IOS::HLE::FS::FileSystem> fs, std::vector<u64> titles);
static SyncIdentifier GetSDCardIdentifier(); static SyncIdentifier GetSDCardIdentifier();
protected: protected:
@ -316,6 +325,9 @@ private:
u64 m_initial_rtc = 0; u64 m_initial_rtc = 0;
u32 m_timebase_frame = 0; u32 m_timebase_frame = 0;
std::unique_ptr<IOS::HLE::FS::FileSystem> m_wii_sync_fs;
std::vector<u64> m_wii_sync_titles;
}; };
void NetPlay_Enable(NetPlayClient* const np); void NetPlay_Enable(NetPlayClient* const np);

View File

@ -257,10 +257,6 @@ bool IsNetPlayRunning();
// Precondition: A netplay client instance must be present. In other words, // Precondition: A netplay client instance must be present. In other words,
// IsNetPlayRunning() must be true before calling this. // IsNetPlayRunning() must be true before calling this.
const NetSettings& GetNetSettings(); const NetSettings& GetNetSettings();
IOS::HLE::FS::FileSystem* GetWiiSyncFS();
const std::vector<u64>& GetWiiSyncTitles();
void SetWiiSyncData(std::unique_ptr<IOS::HLE::FS::FileSystem> fs, const std::vector<u64>& titles);
void ClearWiiSyncData();
void SetSIPollBatching(bool state); void SetSIPollBatching(bool state);
void SendPowerButtonEvent(); void SendPowerButtonEvent();
bool IsSyncingAllWiiSaves(); bool IsSyncingAllWiiSaves();

View File

@ -1819,7 +1819,7 @@ bool NetPlayServer::SyncSaveData()
} }
// Set titles for host-side loading in WiiRoot // Set titles for host-side loading in WiiRoot
SetWiiSyncData(nullptr, titles); m_dialog->SetHostWiiSyncTitles(std::move(titles));
SendChunkedToClients(std::move(pac), 1, "Wii Save Synchronization"); SendChunkedToClients(std::move(pac), 1, "Wii Save Synchronization");
} }

View File

@ -40,6 +40,7 @@
#ifdef HAS_LIBMGBA #ifdef HAS_LIBMGBA
#include "Core/HW/GBACore.h" #include "Core/HW/GBACore.h"
#endif #endif
#include "Core/IOS/FS/FileSystem.h"
#include "Core/NetPlayServer.h" #include "Core/NetPlayServer.h"
#include "Core/SyncIdentifier.h" #include "Core/SyncIdentifier.h"
@ -1177,3 +1178,10 @@ void NetPlayDialog::SetChunkedProgress(const int pid, const u64 progress)
m_chunked_progress_dialog->SetProgress(pid, progress); m_chunked_progress_dialog->SetProgress(pid, progress);
}); });
} }
void NetPlayDialog::SetHostWiiSyncTitles(std::vector<u64> titles)
{
auto client = Settings::Instance().GetNetPlayClient();
if (client)
client->SetWiiSyncData(nullptr, std::move(titles));
}

View File

@ -94,6 +94,9 @@ public:
const std::vector<int>& players) override; const std::vector<int>& players) override;
void HideChunkedProgressDialog() override; void HideChunkedProgressDialog() override;
void SetChunkedProgress(int pid, u64 progress) override; void SetChunkedProgress(int pid, u64 progress) override;
void SetHostWiiSyncTitles(std::vector<u64> titles) override;
signals: signals:
void Stop(); void Stop();