Skip to content

Commit

Permalink
fix: Fixup paths using NetworkInfo to use SyncingInfo + update bo…
Browse files Browse the repository at this point in the history
…nes_framework
  • Loading branch information
MaxCWhitehead committed Aug 29, 2024
1 parent d6b07ae commit c781b4e
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 32 deletions.
26 changes: 13 additions & 13 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 16 additions & 13 deletions src/core/scoring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ pub fn round_end(
mut scoring_menu: ResMut<ScoringMenuState>,
killed_players: Comp<PlayerKilled>,
player_indices: Comp<PlayerIdx>,
#[cfg(not(target_arch = "wasm32"))] network_info: Option<Res<NetworkInfo>>,
#[cfg(not(target_arch = "wasm32"))] syncing_info: Option<Res<SyncingInfo>>,
) {
// Count players so we can avoid ending round if it's a one player match
let mut player_count = 0;
Expand Down Expand Up @@ -155,15 +155,19 @@ pub fn round_end(

// Is round transition sycnrhonized on all clients in network play?
// Will evaluate to true in local play.
#[allow(unused_assignments)]
let mut round_transition_synchronized = false;

// If in network play and determined a prev frame round should end on:
#[allow(unused_variables)]
if let Some(end_net_frame) = state.network_round_end_frame {
// check if this frame is confirmed by all players.
#[cfg(not(target_arch = "wasm32"))]
if let Some(network_info) = network_info {
round_transition_synchronized = end_net_frame <= network_info.last_confirmed_frame;
{
round_transition_synchronized = match syncing_info {
Some(syncing_info) => end_net_frame <= syncing_info.last_confirmed_frame(),
None => true,
};
}
} else {
// Network frame for round end not yet recorded (or in local only)
Expand All @@ -175,21 +179,20 @@ pub fn round_end(

// Save current predicted frame for round end.
// Will not follow through with transition until this frame is confirmed
// by all players in network play. If local, safe to transition now.
// by all players in network play.
#[cfg(not(target_arch = "wasm32"))]
if let Some(network_info) = network_info {
state.network_round_end_frame = Some(network_info.current_frame);
if let Some(syncing_info) = syncing_info {
state.network_round_end_frame = Some(syncing_info.current_frame());
} else {
// `Option<Res<NetworkInfo>>` always available in network play,
// we are local and can transition now.
// No sync info - must be local and sychronized.
round_transition_synchronized = true;
}
}

// Wasm32 is always local, can transition now.
#[cfg(target_arch = "wasm32")]
{
round_transition_synchronized = true;
}
// Wasm32 is always local, can transition now.
#[cfg(target_arch = "wasm32")]
{
round_transition_synchronized = true;
}

if round_transition_synchronized {
Expand Down
6 changes: 5 additions & 1 deletion src/ui/pause_menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ fn pause_menu_system(
let pause_pressed = controls.values().any(|x| x.pause_just_pressed);

#[cfg(not(target_arch = "wasm32"))]
let is_online = session.world.get_resource::<NetworkInfo>().is_some();
let is_online = session
.world
.get_resource::<SyncingInfo>()
.map_or(false, |x| x.is_online());

#[cfg(target_arch = "wasm32")]
let is_online = false;

Expand Down
9 changes: 4 additions & 5 deletions src/ui/scoring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use std::ops::Deref;

#[cfg(not(target_arch = "wasm32"))]
use bones_framework::networking::{NetworkInfo, NetworkSocket, SocketTarget};
use bones_framework::networking::{socket::Socket, NetworkSocket, SocketTarget, SyncingInfo};

use crate::prelude::*;

Expand Down Expand Up @@ -91,11 +91,10 @@ fn scoring_menu_system(
let match_inputs = session.world.get_resource::<MatchInputs>().unwrap();

#[cfg(not(target_arch = "wasm32"))]
let network_socket = session
let network_socket: Option<Socket> = session
.world
.get_resource::<NetworkInfo>()
.as_deref()
.map(|x| x.socket.clone());
.get_resource::<SyncingInfo>()
.and_then(|x| x.socket().cloned());

// Build Vec<PlayerScoreInfo> sorted by player indices
let mut player_entities: Vec<(Entity, &PlayerIdx)> =
Expand Down

0 comments on commit c781b4e

Please sign in to comment.