Skip to content

Commit 6489c57

Browse files
committed
fix: revert input serialization change, as it broke run-ahead
1 parent 02b7a24 commit 6489c57

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

tetanes-core/src/control_deck.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,10 @@ impl ControlDeck {
568568
if fs::exists(path) {
569569
fs::load::<Cpu>(path)
570570
.map_err(Error::SaveState)
571-
.map(|cpu| self.load_cpu(cpu))
571+
.map(|mut cpu| {
572+
cpu.bus.input.clear(); // Discard inputs from save states
573+
self.load_cpu(cpu)
574+
})
572575
} else {
573576
Err(Error::NoSaveStateFound)
574577
}

tetanes-core/src/input.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,6 @@ impl From<JoypadBtn> for JoypadBtnState {
373373
#[derive(Default, Debug, Copy, Clone, Serialize, Deserialize)]
374374
#[must_use]
375375
pub struct Joypad {
376-
#[serde(skip)] // Don't save button states
377376
pub buttons: JoypadBtnState,
378377
pub concurrent_dpad: bool,
379378
pub index: u8,
@@ -383,7 +382,7 @@ pub struct Joypad {
383382
impl Joypad {
384383
pub const fn new() -> Self {
385384
Self {
386-
buttons: JoypadBtnState::from_bits_truncate(0),
385+
buttons: JoypadBtnState::empty(),
387386
concurrent_dpad: false,
388387
index: 0,
389388
strobe: false,

tetanes/src/nes/emulation/rewind.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ impl Rewind {
103103
let frame = self.frames[self.index].take()?;
104104
bincode::deserialize::<Cpu>(&frame.state)
105105
.map(|mut cpu| {
106+
cpu.bus.input.clear(); // Discard inputs while rewinding
106107
cpu.bus.ppu.frame.buffer = frame.buffer;
107108
cpu
108109
})
@@ -135,7 +136,8 @@ impl State {
135136
}
136137
// ~2 seconds worth of frames @ 60 FPS
137138
let mut rewind_frames = 120 / self.rewind.interval;
138-
while let Some(cpu) = self.rewind.pop() {
139+
while let Some(mut cpu) = self.rewind.pop() {
140+
cpu.bus.input.clear(); // Discard inputs while rewinding
139141
self.control_deck.load_cpu(cpu);
140142
rewind_frames -= 1;
141143
if rewind_frames == 0 {

0 commit comments

Comments
 (0)