Fix ping recommendation (#1082)
* don't block tokio * more * more * more * more * more
This commit is contained in:
parent
4929f2cc51
commit
45963aeea5
@ -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;
|
||||
}
|
||||
|
||||
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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()
|
||||
|
||||
@ -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 => {
|
||||
|
||||
@ -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);
|
||||
|
||||
Reference in New Issue
Block a user