Settings: Add netplay config overlay

This commit is contained in:
Stenzek 2023-04-11 22:48:28 +10:00
parent c0cfe3399c
commit 14cfc3aadb
4 changed files with 45 additions and 1 deletions

View File

@ -10,6 +10,7 @@ class LayeredSettingsInterface final : public SettingsInterface
public: public:
enum Layer : u32 enum Layer : u32
{ {
LAYER_NETPLAY,
LAYER_CMDLINE, LAYER_CMDLINE,
LAYER_GAME, LAYER_GAME,
LAYER_INPUT, LAYER_INPUT,
@ -61,7 +62,7 @@ public:
using SettingsInterface::GetUIntValue; using SettingsInterface::GetUIntValue;
private: private:
static constexpr Layer FIRST_LAYER = LAYER_CMDLINE; static constexpr Layer FIRST_LAYER = LAYER_NETPLAY;
static constexpr Layer LAST_LAYER = LAYER_BASE; static constexpr Layer LAST_LAYER = LAYER_BASE;
std::array<SettingsInterface*, NUM_LAYERS> m_layers{}; std::array<SettingsInterface*, NUM_LAYERS> m_layers{};

View File

@ -69,5 +69,8 @@ void SetGameSettingsLayer(SettingsInterface* sif);
/// Sets the input profile settings layer. Called by VMManager when the game changes. /// Sets the input profile settings layer. Called by VMManager when the game changes.
void SetInputSettingsLayer(SettingsInterface* sif); void SetInputSettingsLayer(SettingsInterface* sif);
/// Sets the netplay settings layer. Use once a session is established.
void SetNetplaySettingsLayer(SettingsInterface* sif);
} // namespace Internal } // namespace Internal
} // namespace Host } // namespace Host

View File

@ -2,11 +2,13 @@
#include "common/byte_stream.h" #include "common/byte_stream.h"
#include "common/gpu_texture.h" #include "common/gpu_texture.h"
#include "common/log.h" #include "common/log.h"
#include "common/memory_settings_interface.h"
#include "digital_controller.h" #include "digital_controller.h"
#include "ggponet.h" #include "ggponet.h"
#include "pad.h" #include "pad.h"
#include "spu.h" #include "spu.h"
#include "system.h" #include "system.h"
#include "host_settings.h"
#include <bitset> #include <bitset>
#include <deque> #include <deque>
Log_SetChannel(Netplay); Log_SetChannel(Netplay);
@ -53,6 +55,8 @@ static void SetInputs(Input inputs[2]);
static LoopTimer* GetTimer(); static LoopTimer* GetTimer();
static void SetSettings();
// l = local, r = remote // l = local, r = remote
static s32 Start(s32 lhandle, u16 lport, std::string& raddr, u16 rport, s32 ldelay, u32 pred); static s32 Start(s32 lhandle, u16 lport, std::string& raddr, u16 rport, s32 ldelay, u32 pred);
static void Close(); static void Close();
@ -63,6 +67,12 @@ static void RunFrame(s32& waitTime);
static void NetplayAdvanceFrame(Netplay::Input inputs[], int disconnect_flags); static void NetplayAdvanceFrame(Netplay::Input inputs[], int disconnect_flags);
//////////////////////////////////////////////////////////////////////////
// Variables
//////////////////////////////////////////////////////////////////////////
static MemorySettingsInterface s_settings_overlay;
static LoopTimer s_timer; static LoopTimer s_timer;
static std::string s_game_path; static std::string s_game_path;
static u32 s_max_pred = 0; static u32 s_max_pred = 0;
@ -79,8 +89,29 @@ static std::array<std::array<float, 32>, NUM_CONTROLLER_AND_CARD_PORTS> s_net_in
// Netplay Impl // Netplay Impl
void Netplay::SetSettings()
{
MemorySettingsInterface& si = s_settings_overlay;
si.Clear();
for (u32 i = 0; i < MAX_PLAYERS; i++)
{
// Only digital pads supported for now.
si.SetStringValue(Controller::GetSettingsSection(i).c_str(), "Type",
Settings::GetControllerTypeName(ControllerType::DigitalController));
}
// No runahead or rewind, that'd be a disaster.
si.SetIntValue("Main", "RunaheadFrameCount", 0);
si.SetBoolValue("Main", "RewindEnable", false);
Host::Internal::SetNetplaySettingsLayer(&si);
}
s32 Netplay::Start(s32 lhandle, u16 lport, std::string& raddr, u16 rport, s32 ldelay, u32 pred) s32 Netplay::Start(s32 lhandle, u16 lport, std::string& raddr, u16 rport, s32 ldelay, u32 pred)
{ {
SetSettings();
s_max_pred = pred; s_max_pred = pred;
/* /*
TODO: since saving every frame during rollback loses us time to do actual gamestate iterations it might be better to TODO: since saving every frame during rollback loses us time to do actual gamestate iterations it might be better to
@ -140,6 +171,9 @@ void Netplay::Close()
s_ggpo = nullptr; s_ggpo = nullptr;
s_local_handle = GGPO_INVALID_HANDLE; s_local_handle = GGPO_INVALID_HANDLE;
s_max_pred = 0; s_max_pred = 0;
// Restore original settings.
Host::Internal::SetNetplaySettingsLayer(nullptr);
} }
bool Netplay::IsActive() bool Netplay::IsActive()

View File

@ -190,3 +190,9 @@ void Host::Internal::SetInputSettingsLayer(SettingsInterface* sif)
std::unique_lock lock(s_settings_mutex); std::unique_lock lock(s_settings_mutex);
s_layered_settings_interface.SetLayer(LayeredSettingsInterface::LAYER_INPUT, sif); s_layered_settings_interface.SetLayer(LayeredSettingsInterface::LAYER_INPUT, sif);
} }
void Host::Internal::SetNetplaySettingsLayer(SettingsInterface* sif)
{
std::unique_lock lock(s_settings_mutex);
s_layered_settings_interface.SetLayer(LayeredSettingsInterface::LAYER_NETPLAY, sif);
}