From 14cfc3aadb44f0fd72a3367551c458a36eaa49a9 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Tue, 11 Apr 2023 22:48:28 +1000 Subject: [PATCH] Settings: Add netplay config overlay --- src/common/layered_settings_interface.h | 3 ++- src/core/host_settings.h | 3 +++ src/core/netplay.cpp | 34 +++++++++++++++++++++++++ src/frontend-common/host_settings.cpp | 6 +++++ 4 files changed, 45 insertions(+), 1 deletion(-) diff --git a/src/common/layered_settings_interface.h b/src/common/layered_settings_interface.h index ec46ca56a..32bc94704 100644 --- a/src/common/layered_settings_interface.h +++ b/src/common/layered_settings_interface.h @@ -10,6 +10,7 @@ class LayeredSettingsInterface final : public SettingsInterface public: enum Layer : u32 { + LAYER_NETPLAY, LAYER_CMDLINE, LAYER_GAME, LAYER_INPUT, @@ -61,7 +62,7 @@ public: using SettingsInterface::GetUIntValue; private: - static constexpr Layer FIRST_LAYER = LAYER_CMDLINE; + static constexpr Layer FIRST_LAYER = LAYER_NETPLAY; static constexpr Layer LAST_LAYER = LAYER_BASE; std::array m_layers{}; diff --git a/src/core/host_settings.h b/src/core/host_settings.h index 384a98ab6..18e34cf1b 100644 --- a/src/core/host_settings.h +++ b/src/core/host_settings.h @@ -69,5 +69,8 @@ void SetGameSettingsLayer(SettingsInterface* sif); /// Sets the input profile settings layer. Called by VMManager when the game changes. void SetInputSettingsLayer(SettingsInterface* sif); + +/// Sets the netplay settings layer. Use once a session is established. +void SetNetplaySettingsLayer(SettingsInterface* sif); } // namespace Internal } // namespace Host \ No newline at end of file diff --git a/src/core/netplay.cpp b/src/core/netplay.cpp index 3781954fa..76da83e82 100644 --- a/src/core/netplay.cpp +++ b/src/core/netplay.cpp @@ -2,11 +2,13 @@ #include "common/byte_stream.h" #include "common/gpu_texture.h" #include "common/log.h" +#include "common/memory_settings_interface.h" #include "digital_controller.h" #include "ggponet.h" #include "pad.h" #include "spu.h" #include "system.h" +#include "host_settings.h" #include #include Log_SetChannel(Netplay); @@ -53,6 +55,8 @@ static void SetInputs(Input inputs[2]); static LoopTimer* GetTimer(); +static void SetSettings(); + // l = local, r = remote static s32 Start(s32 lhandle, u16 lport, std::string& raddr, u16 rport, s32 ldelay, u32 pred); static void Close(); @@ -63,6 +67,12 @@ static void RunFrame(s32& waitTime); static void NetplayAdvanceFrame(Netplay::Input inputs[], int disconnect_flags); +////////////////////////////////////////////////////////////////////////// +// Variables +////////////////////////////////////////////////////////////////////////// + +static MemorySettingsInterface s_settings_overlay; + static LoopTimer s_timer; static std::string s_game_path; static u32 s_max_pred = 0; @@ -79,8 +89,29 @@ static std::array, NUM_CONTROLLER_AND_CARD_PORTS> s_net_in // 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) { + SetSettings(); + s_max_pred = pred; /* 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_local_handle = GGPO_INVALID_HANDLE; s_max_pred = 0; + + // Restore original settings. + Host::Internal::SetNetplaySettingsLayer(nullptr); } bool Netplay::IsActive() diff --git a/src/frontend-common/host_settings.cpp b/src/frontend-common/host_settings.cpp index c342174e2..46df5b203 100644 --- a/src/frontend-common/host_settings.cpp +++ b/src/frontend-common/host_settings.cpp @@ -190,3 +190,9 @@ void Host::Internal::SetInputSettingsLayer(SettingsInterface* sif) std::unique_lock lock(s_settings_mutex); 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); +}