Skip to content

Commit 3cbd9a1

Browse files
Merge pull request #4 from ilikepizza107/master
Add Spectator Checkbox
2 parents 25b1e62 + 26ace1a commit 3cbd9a1

File tree

10 files changed

+73
-16
lines changed

10 files changed

+73
-16
lines changed

Source/Core/Core/BootManager.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ bool BootCore(Core::System& system, std::unique_ptr<BootParameters> boot,
9696
Config::AddLayer(ConfigLoaders::GenerateNetPlayConfigLoader(*netplay_settings));
9797
StartUp.bCopyWiiSaveNetplay = netplay_settings->savedata_load;
9898
StartUp.bBrawlMusicOff = netplay_settings->brawlmusic_off;
99+
StartUp.bIsSpectator = netplay_settings->is_spectator;
99100
}
100101

101102
// Override out-of-region languages/countries to prevent games from crashing or behaving oddly

Source/Core/Core/Config/NetplaySettings.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ const Info<u32> NETPLAY_MINIMUM_BUFFER_SIZE{{System::Main, "NetPlay", "MinimumBu
4747
const Info<u32> NETPLAY_PLAYER_BUFFER_SIZE{{System::Main, "NetPlay", "PlayerBufferSize"}, 2};
4848
const Info<u32> NETPLAY_CLIENT_BUFFER_SIZE{{System::Main, "NetPlay", "BufferSizeClient"}, 1};
4949

50-
const Info<bool> NETPLAY_IS_SPECTATOR{{System::Main, "NetPlay", "IsSpectator"}, false};
5150
const Info<bool> NETPLAY_BRAWL_MUSIC_OFF{{System::Main, "NetPlay", "BrawlMusicOff"}, false};
51+
const Info<bool> NETPLAY_IS_SPECTATOR{{System::Main, "NetPlay", "IsSpectator"}, false};
5252

5353
const Info<bool> NETPLAY_SAVEDATA_LOAD{{System::Main, "NetPlay", "SyncSaves"}, true};
5454
const Info<bool> NETPLAY_SAVEDATA_WRITE{{System::Main, "NetPlay", "WriteSaveData"}, false};

Source/Core/Core/Config/NetplaySettings.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ extern const Info<u32> NETPLAY_MINIMUM_BUFFER_SIZE;
4343
extern const Info<u32> NETPLAY_PLAYER_BUFFER_SIZE;
4444
extern const Info<u32> NETPLAY_CLIENT_BUFFER_SIZE;
4545

46-
extern const Info<bool> NETPLAY_IS_SPECTATOR;
4746
extern const Info<bool> NETPLAY_BRAWL_MUSIC_OFF;
47+
extern const Info<bool> NETPLAY_IS_SPECTATOR;
4848

4949
extern const Info<bool> NETPLAY_SAVEDATA_LOAD;
5050
extern const Info<bool> NETPLAY_SAVEDATA_WRITE;

Source/Core/Core/ConfigManager.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ struct SConfig
5050
bool bJITNoBlockLinking = false;
5151

5252
bool bCopyWiiSaveNetplay = true;
53-
bool bIsSpectator = true;
5453
bool bBrawlMusicOff = true;
54+
bool bIsSpectator = true;
5555

5656
DiscIO::Region m_region;
5757

Source/Core/Core/NetPlayClient.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -906,8 +906,8 @@ void NetPlayClient::OnStartGame(sf::Packet& packet)
906906
packet >> m_net_settings.allow_sd_writes;
907907
packet >> m_net_settings.oc_enable;
908908
packet >> m_net_settings.oc_factor;
909-
packet >> m_net_settings.is_spectator;
910909
packet >> m_net_settings.brawlmusic_off;
910+
packet >> m_net_settings.is_spectator;
911911

912912
for (auto slot : ExpansionInterface::SLOTS)
913913
packet >> m_net_settings.exi_device[slot];

Source/Core/Core/NetPlayClient.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ class NetPlayUI
7676
virtual void OnTtlDetermined(u8 ttl) = 0;
7777

7878
virtual bool IsRecording() = 0;
79-
virtual bool IsSpectator() = 0;
8079
virtual bool IsMusicOff() = 0;
80+
virtual bool IsSpectator() = 0;
8181
virtual std::shared_ptr<const UICommon::GameFile>
8282
FindGameFile(const SyncIdentifier& sync_identifier,
8383
SyncIdentifierComparison* found = nullptr) = 0;

Source/Core/Core/NetPlayProto.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ struct NetSettings
4747
bool allow_sd_writes = false;
4848
bool oc_enable = false;
4949
float oc_factor = 0;
50-
bool is_spectator = false;
5150
bool brawlmusic_off = false;
51+
bool is_spectator = false;
5252
Common::EnumMap<ExpansionInterface::EXIDeviceType, ExpansionInterface::MAX_SLOT> exi_device{};
5353
int memcard_size_override = -1;
5454

@@ -148,6 +148,7 @@ enum class MessageID : u8
148148
ChunkedDataComplete = 0x44,
149149
ChunkedDataAbort = 0x45,
150150

151+
PadSpectator = 0x5F,
151152
PadData = 0x60,
152153
PadMapping = 0x61,
153154
PadBufferMinimum = 0x62,

Source/Core/Core/NetPlayServer.cpp

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -797,6 +797,47 @@ unsigned int NetPlayServer::OnData(sf::Packet& packet, Client& player)
797797
}
798798
break;
799799

800+
case MessageID::PadSpectator:
801+
{
802+
bool spectator;
803+
packet >> spectator;
804+
805+
auto padmap = GetPadMapping();
806+
807+
int player_port = -1;
808+
for (int i = 0; i < (int)padmap.size(); i++)
809+
{
810+
if (padmap[i] == player.pid)
811+
{
812+
player_port = i;
813+
break;
814+
}
815+
}
816+
817+
if (spectator)
818+
{
819+
if (player_port != -1)
820+
padmap[player_port] = 0;
821+
}
822+
else
823+
{
824+
bool assigned = false;
825+
for (int i = 0; i < (int)padmap.size(); i++)
826+
{
827+
if (padmap[i] == 0)
828+
{
829+
padmap[i] = player.pid;
830+
assigned = true;
831+
break;
832+
}
833+
}
834+
}
835+
836+
this->SetPadMapping(padmap);
837+
}
838+
break;
839+
840+
800841
case MessageID::PadData:
801842
{
802843
// if this is pad data from the last game still being received, ignore it
@@ -1455,8 +1496,8 @@ bool NetPlayServer::SetupNetSettings()
14551496
settings.golf_mode = Config::Get(Config::NETPLAY_NETWORK_MODE) == "golf";
14561497
settings.use_fma = DoAllPlayersHaveHardwareFMA();
14571498
settings.hide_remote_gbas = Config::Get(Config::NETPLAY_HIDE_REMOTE_GBAS);
1458-
settings.is_spectator = Config::Get(Config::NETPLAY_IS_SPECTATOR);
14591499
settings.brawlmusic_off = Config::Get(Config::NETPLAY_BRAWL_MUSIC_OFF);
1500+
settings.is_spectator = Config::Get(Config::NETPLAY_IS_SPECTATOR);
14601501

14611502
// Unload GameINI to restore things to normal
14621503
Config::RemoveLayer(Config::LayerType::GlobalGame);
@@ -1602,8 +1643,8 @@ bool NetPlayServer::StartGame()
16021643
spac << m_settings.allow_sd_writes;
16031644
spac << m_settings.oc_enable;
16041645
spac << m_settings.oc_factor;
1605-
spac << m_settings.is_spectator;
16061646
spac << m_settings.brawlmusic_off;
1647+
spac << m_settings.is_spectator;
16071648

16081649
for (auto slot : ExpansionInterface::SLOTS)
16091650
spac << static_cast<int>(m_settings.exi_device[slot]);

Source/Core/DolphinQt/NetPlay/NetPlayDialog.cpp

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@ void NetPlayDialog::CreateMainLayout()
139139
m_player_buffer_size_box = new QSpinBox;
140140
m_player_buffer_label = new QLabel(tr("Player Buffer:"));
141141
m_quit_button = new QPushButton(tr("Quit"));
142-
m_is_spectator = new QCheckBox(tr("Spectator"));
143142
m_brawlmusic_off = new QCheckBox(tr("Client Side Music Off"));
143+
m_is_spectator = new QCheckBox(tr("Spectator"));
144144
m_splitter = new QSplitter(Qt::Horizontal);
145145
m_menu_bar = new QMenuBar(this);
146146

@@ -267,10 +267,10 @@ void NetPlayDialog::CreateMainLayout()
267267
options_widget->addWidget(m_minimum_buffer_size_box, 0, 2, Qt::AlignVCenter);
268268
options_widget->addWidget(m_player_buffer_label, 0, 3, Qt::AlignVCenter);
269269
options_widget->addWidget(m_player_buffer_size_box, 0, 4, Qt::AlignVCenter);
270+
options_widget->addWidget(m_brawlmusic_off, 0, 5, Qt::AlignVCenter);
270271
options_widget->addWidget(m_is_spectator, 0, 6, Qt::AlignVCenter);
271-
options_widget->addWidget(m_brawlmusic_off, 0, 7, Qt::AlignVCenter);
272272
options_widget->addWidget(m_quit_button, 0, 8, Qt::AlignVCenter | Qt::AlignRight);
273-
options_widget->setColumnStretch(5, 1000);
273+
options_widget->setColumnStretch(7, 1000);
274274

275275
m_main_layout->addLayout(options_widget, 2, 0, 1, -1, Qt::AlignRight);
276276
m_main_layout->setRowStretch(1, 1000);
@@ -405,6 +405,8 @@ void NetPlayDialog::ConnectWidgets()
405405
connect(m_start_button, &QPushButton::clicked, this, &NetPlayDialog::OnStart);
406406
connect(m_quit_button, &QPushButton::clicked, this, &NetPlayDialog::reject);
407407

408+
connect(m_is_spectator, &QCheckBox::toggled, this, &NetPlayDialog::IsSpectatorEnabled);
409+
408410
connect(m_game_button, &QPushButton::clicked, [this] {
409411
GameListDialog gld(m_game_list_model, this);
410412
SetQWidgetWindowDecorations(&gld);
@@ -493,6 +495,17 @@ void NetPlayDialog::OnChat()
493495
});
494496
}
495497

498+
void NetPlayDialog::IsSpectatorEnabled(bool enabled)
499+
{
500+
auto client = Settings::Instance().GetNetPlayClient();
501+
if (!client)
502+
return;
503+
sf::Packet packet;
504+
packet << static_cast<u8>(NetPlay::MessageID::PadSpectator);
505+
packet << enabled;
506+
client->SendAsync(std::move(packet));
507+
}
508+
496509
void NetPlayDialog::OnIndexAdded(bool success, const std::string error)
497510
{
498511
DisplayMessage(success ? tr("Successfully added to the NetPlay index") :
@@ -913,8 +926,8 @@ void NetPlayDialog::SetOptionsEnabled(bool enabled)
913926
m_host_input_authority_action->setEnabled(enabled);
914927
m_golf_mode_action->setEnabled(enabled);
915928
m_fixed_delay_action->setEnabled(enabled);
916-
m_is_spectator->setEnabled(enabled);
917929
m_brawlmusic_off->setEnabled(enabled);
930+
m_is_spectator->setEnabled(enabled);
918931
}
919932

920933
m_record_input_action->setEnabled(enabled);
@@ -1201,8 +1214,8 @@ void NetPlayDialog::LoadSettings()
12011214
const bool strict_settings_sync = Config::Get(Config::NETPLAY_STRICT_SETTINGS_SYNC);
12021215
const bool golf_mode_overlay = Config::Get(Config::NETPLAY_GOLF_MODE_OVERLAY);
12031216
const bool hide_remote_gbas = Config::Get(Config::NETPLAY_HIDE_REMOTE_GBAS);
1204-
const bool is_spectator = Config::Get(Config::NETPLAY_IS_SPECTATOR);
12051217
const bool brawlmusic_off = Config::Get(Config::NETPLAY_BRAWL_MUSIC_OFF);
1218+
const bool is_spectator = Config::Get(Config::NETPLAY_IS_SPECTATOR);
12061219

12071220
m_minimum_buffer_size_box->setValue(minimum_buffer_size);
12081221
m_player_buffer_size_box->setValue(player_buffer_size);
@@ -1221,8 +1234,8 @@ void NetPlayDialog::LoadSettings()
12211234
m_golf_mode_overlay_action->setChecked(golf_mode_overlay);
12221235
m_hide_remote_gbas_action->setChecked(hide_remote_gbas);
12231236

1224-
m_is_spectator->setChecked(is_spectator);
12251237
m_brawlmusic_off->setChecked(brawlmusic_off);
1238+
m_is_spectator->setChecked(is_spectator);
12261239

12271240
const std::string network_mode = Config::Get(Config::NETPLAY_NETWORK_MODE);
12281241

@@ -1266,8 +1279,8 @@ void NetPlayDialog::SaveSettings()
12661279
Config::SetBase(Config::NETPLAY_STRICT_SETTINGS_SYNC, m_strict_settings_sync_action->isChecked());
12671280
Config::SetBase(Config::NETPLAY_GOLF_MODE_OVERLAY, m_golf_mode_overlay_action->isChecked());
12681281
Config::SetBase(Config::NETPLAY_HIDE_REMOTE_GBAS, m_hide_remote_gbas_action->isChecked());
1269-
Config::SetBase(Config::NETPLAY_IS_SPECTATOR, m_is_spectator->isChecked());
12701282
Config::SetBase(Config::NETPLAY_BRAWL_MUSIC_OFF, m_brawlmusic_off->isChecked());
1283+
Config::SetBase(Config::NETPLAY_IS_SPECTATOR, m_is_spectator->isChecked());
12711284

12721285
std::string network_mode;
12731286
if (m_fixed_delay_action->isChecked())

Source/Core/DolphinQt/NetPlay/NetPlayDialog.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,9 @@ class NetPlayDialog : public QDialog, public NetPlay::NetPlayUI
7979
void OnIndexRefreshFailed(const std::string error) override;
8080

8181
bool IsRecording() override;
82-
bool IsSpectator() override;
8382
bool IsMusicOff() override;
83+
bool IsSpectator() override;
84+
void IsSpectatorEnabled(bool enabled);
8485
std::shared_ptr<const UICommon::GameFile>
8586
FindGameFile(const NetPlay::SyncIdentifier& sync_identifier,
8687
NetPlay::SyncIdentifierComparison* found = nullptr) override;

0 commit comments

Comments
 (0)