Skip to content
This repository was archived by the owner on Mar 29, 2025. It is now read-only.

Commit f14dd9e

Browse files
committed
Ensure the server controller is correctly spawned on the clients.
1 parent cda5a02 commit f14dd9e

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

core/peer_data.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ void NS::PeerData::set_out_packet_loss_percentage(float p_packet_loss) {
1616
}
1717

1818
void NS::PeerData::make_controller(SceneSynchronizerBase &p_scene_synchronizer) {
19-
controller = std::make_unique<NS::PeerNetworkedController>(p_scene_synchronizer);
19+
controller = std::make_unique<PeerNetworkedController>(p_scene_synchronizer);
2020
}

scene_synchronizer.cpp

+11-3
Original file line numberDiff line numberDiff line change
@@ -1136,6 +1136,14 @@ void SceneSynchronizerBase::init_synchronizer(bool p_was_generating_ids) {
11361136
// This is good to have here because the local peer may have changed.
11371137
on_peer_connected(get_network_interface().get_local_peer_id());
11381138

1139+
// Ensure the server peer is also spawned for the client.
1140+
if (is_client()) {
1141+
PeerData *server_peer_data = MapFunc::get_or_null(peer_data, get_network_interface().get_server_peer());
1142+
if (!server_peer_data) {
1143+
on_peer_connected(get_network_interface().get_server_peer());
1144+
}
1145+
}
1146+
11391147
// Reset the controllers.
11401148
reset_controllers();
11411149

@@ -1388,9 +1396,9 @@ void SceneSynchronizerBase::call_rpc_receive_inputs(int p_recipient, int p_peer,
13881396

13891397
void SceneSynchronizerBase::rpc_receive_inputs(int p_peer, const std::vector<std::uint8_t> &p_data) {
13901398
PeerData *pd = MapFunc::get_or_null(peer_data, p_peer);
1391-
if (pd && pd->get_controller()) {
1392-
pd->get_controller()->notify_receive_inputs(p_data);
1393-
}
1399+
NS_ENSURE_MSG(pd, "The PeerData was not found during `rpc_receive_inputs` for peer " + std::to_string(p_peer));
1400+
NS_ENSURE_MSG(pd->get_controller(), "The PeerData doesn't have an associated controller and `rpc_receive_inputs` failed for peer " + std::to_string(p_peer));
1401+
pd->get_controller()->notify_receive_inputs(p_data);
13941402
}
13951403

13961404

0 commit comments

Comments
 (0)