mirror of
https://github.com/gopher64/gopher64.git
synced 2026-11-04 21:33:46 +01:00
enable rollback
This commit is contained in:
1 parent
0c863c5f70
commit
62d41cda25
1 file changed
+9
-19
+9
-19
@@ -1,7 +1,10 @@
|
||||
use crate::device;
|
||||
use crate::savestates;
|
||||
use crate::ui;
|
||||
use sha2::digest::Digest;
|
||||
|
||||
const MAX_PREDICTION_WINDOW: usize = 16;
|
||||
|
||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
||||
pub struct RtcIceServerConfig {
|
||||
pub urls: Vec<String>,
|
||||
@@ -201,7 +204,7 @@ pub fn receive_save(netplay: &mut Netplay, save_type: &str, save_data: &mut Vec<
|
||||
}
|
||||
|
||||
pub fn send_input_delay(netplay: &mut Netplay, input_delay: usize) {
|
||||
if input_delay < 1 {
|
||||
if input_delay < 1 || input_delay > MAX_PREDICTION_WINDOW {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -269,7 +272,7 @@ pub fn process_requests(
|
||||
if let Some(request) = device.netplay.as_mut().unwrap().requests.pop_front() {
|
||||
match request {
|
||||
ggrs::GgrsRequest::SaveGameState { cell, frame } => {
|
||||
//savestates::create_savestate(device, true, Some(frame));
|
||||
savestates::create_savestate(device, true, Some(frame));
|
||||
|
||||
let mut hasher = sha2::Sha256::new();
|
||||
for reg in device.cpu.cop0.regs.as_ref() {
|
||||
@@ -280,8 +283,8 @@ pub fn process_requests(
|
||||
}
|
||||
ggrs::GgrsRequest::LoadGameState { cell, frame: _ } => {
|
||||
eprintln!("attempting to load game state");
|
||||
if let Some(_frame) = cell.load() {
|
||||
// savestates::load_savestate(device, true, Some(frame));
|
||||
if let Some(frame) = cell.load() {
|
||||
savestates::load_savestate(device, true, Some(frame));
|
||||
}
|
||||
}
|
||||
ggrs::GgrsRequest::AdvanceFrame { inputs } => {
|
||||
@@ -339,26 +342,13 @@ fn process_netplay(device: &mut device::Device) {
|
||||
|
||||
fn advance_frame(device: &mut device::Device) {
|
||||
let netplay = device.netplay.as_mut().unwrap();
|
||||
let local_input = if netplay.session.current_frame() > netplay.session.max_prediction() as i32 {
|
||||
ui::input::get(&mut device.ui, 0)
|
||||
} else {
|
||||
//workaround for disabled rollback
|
||||
ui::input::InputData::default()
|
||||
};
|
||||
let local_input = ui::input::get(&mut device.ui, 0);
|
||||
let local_handle = *netplay.session.local_player_handles().first().unwrap();
|
||||
netplay
|
||||
.session
|
||||
.add_local_input(local_handle, local_input)
|
||||
.unwrap();
|
||||
|
||||
// avoid rollback
|
||||
while !netplay.disconnected
|
||||
&& netplay.session.current_frame() > netplay.session.confirmed_frame()
|
||||
&& netplay.session.confirmed_frame() != ggrs::NULL_FRAME
|
||||
{
|
||||
poll_clients(netplay);
|
||||
}
|
||||
|
||||
if netplay.disconnected {
|
||||
netplay.requests.push_back(ggrs::GgrsRequest::AdvanceFrame {
|
||||
inputs: vec![
|
||||
@@ -504,7 +494,7 @@ pub fn init(
|
||||
.with_fps(if pal { 50 } else { 60 })
|
||||
.unwrap()
|
||||
.with_desync_detection_mode(ggrs::DesyncDetection::On { interval: 60 })
|
||||
.with_max_prediction_window(16)
|
||||
.with_max_prediction_window(MAX_PREDICTION_WINDOW)
|
||||
.with_disconnect_timeout(std::time::Duration::from_secs(if cfg!(debug_assertions) {
|
||||
10
|
||||
} else {
|
||||
|
||||
Reference in new issue
Block a user