Fix ping recommendation (#1082)

* don't block tokio

* more

* more

* more

* more

* more
This commit is contained in:
Logan McNaughton 2026-06-15 17:29:51 +02:00 committed by GitHub
parent 4929f2cc51
commit 45963aeea5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 10 additions and 3 deletions

View File

@ -221,6 +221,7 @@ fn speed_limiter(device: &mut device::Device) {
if now < deadline {
let dur = deadline - now;
spin_sleep::sleep(dur);
if dur < device.speed_limiter.min_wait_time {
device.speed_limiter.min_wait_time = dur;
}

View File

@ -294,6 +294,9 @@ pub fn process_requests(
} else {
// unsafe { sdl3_sys::events::SDL_PumpEvents() }; // so the screen doesn't freeze
process_netplay(device);
if device.netplay.as_ref().unwrap().requests.is_empty() {
std::thread::sleep(std::time::Duration::from_millis(1));
}
}
}
}

View File

@ -237,6 +237,7 @@ pub fn load_savestate(device: &mut device::Device, rewind: bool, rewind_frame: O
if now.elapsed() > timeout {
break None;
}
std::thread::sleep(std::time::Duration::from_millis(1));
}
} else if let Ok(mut pool) = device.savestate.rewind_pool.lock()
&& let Some((_key, state)) = pool.pop_last()

View File

@ -105,7 +105,7 @@ export component NetplayWait inherits Page {
SpinBox {
minimum: 0;
maximum: 16;
maximum: 32;
value: NetplayWaitData.input_delay;
enabled: NetplayWaitData.recommended_delay != 0;
edited => {

View File

@ -649,7 +649,9 @@ fn update_ping(
.duration_since(std::time::UNIX_EPOCH)
.unwrap()
.as_millis();
let ping = (now - message.timestamp) as f64 / 2.0; // calculate one-way latency
// for lockstep, we need to calculate the two-way latency
// for rollback, this would be the one-way latency (divide by 2)
let ping = (now - message.timestamp) as f64;
pings.push(ping);
if pings.len() > message.num_of_peers * 4 {
// once we have enough samples, average the 3 highest values
@ -666,7 +668,7 @@ fn update_ping(
};
let latency_frames = (ping_avg / (1000.0 / refresh_rate)).ceil() as i32;
let recommendation =
(latency_frames + 1).min(16);
(latency_frames + 1).min(32);
if handle.get_netplay_recommended_delay() == 0 {
handle.set_netplay_input_delay(recommendation);