netplay: session resume — reload saved state and broadcast to peers (#4) #18

Open
pbwraith wants to merge 14 commits from issue-4 into main

14 Commits

Author SHA1 Message Date
Claude
79e88dc821 tests: fix resume mock session registration and RDRAM sizing
Some checks failed
Rust / build-linux (linux-x86_64, X64, ubuntu-24.04, x86_64-unknown-linux-gnu) (pull_request) Failing after 2s
Rust / build-android (29.0.14206865, ubuntu-24.04, 33) (pull_request) Failing after 1s
Rust-lint / lint-linux (pull_request) Failing after 1s
Rust / build-linux (linux-aarch64, ARM64, ubuntu-24.04-arm, aarch64-unknown-linux-gnu) (pull_request) Has been cancelled
Rust / build-windows (windows-aarch64, woa64, windows-11-arm, aarch64-pc-windows-msvc) (pull_request) Has been cancelled
Rust / build-windows (windows-x86_64, win64, windows-2025, x86_64-pc-windows-msvc) (pull_request) Has been cancelled
Rust / build-macos (macos-aarch64, ARM64, aarch64-apple-darwin) (pull_request) Has been cancelled
Rust / Collect release artifacts (pull_request) Has been cancelled
mock_netplay built a one-player session for a local handle of 1,
which the vendored ggrs fork rejects; register every handle (the
local player at player_number, dummy Remote PeerIds elsewhere).
The resume tests loaded saved states into fresh Device::new(false)
instances whose RDRAM backing store is empty, tripping
copy_from_slice in apply_savestate; pre-size the RDRAM like a real
emulated device, matching the saved session's RDRAM.
2026-08-25 16:21:12 -05:00
Claude
79127f9240 savestates: import netplay for reset_frame call after state load
The GGRS frame-reset hook merged from issue #5 (netplay_frame field +
netplay::reset_frame in load_savestate_from_data) is missing the
crate::netplay import, so the merged tree does not compile. One-line
fix carried by the session-resume stack.
2026-08-25 15:36:09 -05:00
Claude
92a4781ce6 netplay: count same-batch peer acks in session-resume handshake
wait_for_ready_all counted acks by removing them from the by-name
messages map, which collapses every ack that arrives in the same
channel poll into one entry: with 3+ players the host could
undercount and time out a session whose peers all synced. Count the
matching messages of each decoded batch instead (process_reliable_messages
now returns the batch it decoded).
2026-08-25 15:29:40 -05:00
Claude
1bb409f085 netplay: resume both sides at the saved GGRS frame (issue #5 reset_frame) 2026-08-25 11:50:33 -05:00
Claude
412977f91d Merge remote-tracking branch 'origin/issue-5' into issue-4
# Conflicts:
#	src/device.rs
#	src/netplay.rs
#	src/savestates.rs
2026-08-25 11:31:06 -05:00
Claude
9097b455db netplay: session resume — reload saved state and broadcast to peers (#4) 2026-08-25 11:22:52 -05:00
Claude
6d6b07ae67 merge: UI session save/resume controls (#8, PR #12) — dependency for session resume 2026-08-25 05:45:00 -05:00
Claude
dab9fabc01 merge: netplay session save to disk (#3, PR #13) — dependency for session resume
# Conflicts:
#	src/netplay.rs
#	src/savestates.rs
2026-08-25 05:44:55 -05:00
Claude
858b92701b merge: in-memory netplay savestates (#2, PR #15) — dependency for session resume 2026-08-25 05:43:35 -05:00
Claude
a95315e8a9 merge: netplay state-message types (#1, PR #14) — dependency for session resume 2026-08-25 05:43:24 -05:00
Claude
891d12c08a netplay: add state-message types to reliable channel protocol (#1)
Some checks failed
Rust-lint / lint-linux (pull_request) Failing after 1s
Rust / build-linux (linux-x86_64, X64, ubuntu-24.04, x86_64-unknown-linux-gnu) (pull_request) Failing after 1s
Rust / build-android (29.0.14206865, ubuntu-24.04, 33) (pull_request) Failing after 1s
Rust / build-linux (linux-aarch64, ARM64, ubuntu-24.04-arm, aarch64-unknown-linux-gnu) (pull_request) Has been cancelled
Rust / build-windows (windows-aarch64, woa64, windows-11-arm, aarch64-pc-windows-msvc) (pull_request) Has been cancelled
Rust / build-windows (windows-x86_64, win64, windows-2025, x86_64-pc-windows-msvc) (pull_request) Has been cancelled
Rust / build-macos (macos-aarch64, ARM64, aarch64-apple-darwin) (pull_request) Has been cancelled
Rust / Collect release artifacts (pull_request) Has been cancelled
Add message-name constants and reliable-channel helpers for netplay
session state transfer:

- Message-name constants: netplay_state, netplay_state_ready,
  resync_state, resync_ready
- Chunked message codec (encode_message_chunks / decode_message /
  decode_packets) reusing the existing 16 KiB reliable-channel
  transport; send_message/process_reliable_messages refactored onto it
- send_netplay_state / receive_netplay_state for full session state
- send_ready / wait_for_ready ack helpers (10s timeout, same pattern
  as receive_message); receive_message extracted to wait_for_message
  with preserve of input_delay/disconnect side effects
- Large payloads (>1MB) accumulate into incoming_message until a full
  postcard message parses
- Unit tests: 5MB payload round-trip through the chunked codec, ack
  send/receive within timeout, missing ack times out with the standard
  panic pattern

Closes #1
2026-08-25 02:34:07 -05:00
Claude
15fc132cf2 netplay: session save to disk (host) [issue-3]
Some checks failed
Rust-lint / lint-linux (pull_request) Failing after 1s
Rust / build-linux (linux-x86_64, X64, ubuntu-24.04, x86_64-unknown-linux-gnu) (pull_request) Failing after 1s
Rust / build-android (29.0.14206865, ubuntu-24.04, 33) (pull_request) Failing after 1s
Rust / build-linux (linux-aarch64, ARM64, ubuntu-24.04-arm, aarch64-unknown-linux-gnu) (pull_request) Has been cancelled
Rust / build-windows (windows-aarch64, woa64, windows-11-arm, aarch64-pc-windows-msvc) (pull_request) Has been cancelled
Rust / build-windows (windows-x86_64, win64, windows-2025, x86_64-pc-windows-msvc) (pull_request) Has been cancelled
Rust / build-macos (macos-aarch64, ARM64, aarch64-apple-darwin) (pull_request) Has been cancelled
Rust / Collect release artifacts (pull_request) Has been cancelled
Add host-side netplay session save:
- storage::paths.netplay_state_file_path next to other state files
- savestates::create_savestate_in_memory + SavestateData::save_to_memory
  (in-memory capture, same zip layout as on-disk savestates)
- netplay::save_netplay_session(device, path): postcard-encodes
  {state, frame, input_delay, rom_hash, players}, zstd-compresses and
  writes atomically (tmp + rename); onscreen 'Session saved — safe to quit'
- only the host (player_number 0) may save; others get an onscreen notice
- configurable hotkey (emulation.netplay_save_key, default F7), edge
  triggered in ui::input::get and consumed per-frame in check_callback
- unit tests: encode/decode round-trip + file metadata verification
2026-08-25 01:11:51 -05:00
Claude
0ac1cfb679 UI: session save/resume controls + resync status (#8)
Some checks failed
Rust-lint / lint-linux (pull_request) Failing after 1s
Rust / build-linux (linux-x86_64, X64, ubuntu-24.04, x86_64-unknown-linux-gnu) (pull_request) Failing after 1s
Rust / build-android (29.0.14206865, ubuntu-24.04, 33) (pull_request) Failing after 1s
Rust / build-linux (linux-aarch64, ARM64, ubuntu-24.04-arm, aarch64-unknown-linux-gnu) (pull_request) Has been cancelled
Rust / build-windows (windows-aarch64, woa64, windows-11-arm, aarch64-pc-windows-msvc) (pull_request) Has been cancelled
Rust / build-windows (windows-x86_64, win64, windows-2025, x86_64-pc-windows-msvc) (pull_request) Has been cancelled
Rust / build-macos (macos-aarch64, ARM64, aarch64-apple-darwin) (pull_request) Has been cancelled
Rust / Collect release artifacts (pull_request) Has been cancelled
Add UI controls for the netplay session save/resume and resync
indicator features:

- netplay_create.slint: Add 'Resume Session...' button with file picker
  callback for .netplay-state files
- netplay_wait.slint: Add 'Save Session' button (host only, gated by
  is_host property), add resyncing indicator badge
- netplay_page.slint: Add resyncing property to NetplayData global
- src/ui/netplay.rs: Wire on_netplay_resume_session callback (opens
  file picker, placeholder for #3 flow), on_netplay_save_session
  callback (placeholder for #3 flow), set is_host on wait window setup

The save/resume callbacks show placeholder messages until #3 is
implemented. The resync indicator shows during ResyncState != Idle.

Closes #8
2026-08-25 00:53:52 -05:00
Claude
eb5cf56ee3 Fix GGRS frame counter reset after state load (#5)
Some checks failed
Rust / build-linux (linux-x86_64, X64, ubuntu-24.04, x86_64-unknown-linux-gnu) (pull_request) Failing after 5s
Rust / build-android (29.0.14206865, ubuntu-24.04, 33) (pull_request) Failing after 2s
Rust-lint / lint-linux (pull_request) Failing after 2s
Rust / build-linux (linux-aarch64, ARM64, ubuntu-24.04-arm, aarch64-unknown-linux-gnu) (pull_request) Has been cancelled
Rust / build-windows (windows-aarch64, woa64, windows-11-arm, aarch64-pc-windows-msvc) (pull_request) Has been cancelled
Rust / build-windows (windows-x86_64, win64, windows-2025, x86_64-pc-windows-msvc) (pull_request) Has been cancelled
Rust / build-macos (macos-aarch64, ARM64, aarch64-apple-darwin) (pull_request) Has been cancelled
Rust / Collect release artifacts (pull_request) Has been cancelled
After a netplay savestate load, the GGRS session's internal frame counter
must be reset to match the savestate's frame, or desync detection fires
immediately on resume.

Changes:
- Patch vendored ggrs 0.13.0 to expose set_current_frame(frame) on
  P2PSession and SyncTestSession, with internal SyncLayer and InputQueue
  reset methods to clear stale saved states, checksum history, and input
  queues
- Add [patch.crates-io] ggrs = { path = 'vendor/ggrs' } in Cargo.toml
- Add netplay::reset_frame(session, frame) wrapper function
- Record current GGRS frame in Savestate.netplay_frame during
  create_savestate when in netplay context
- Call reset_frame after load_savestate in netplay context
- Add tests: advance 120 frames, reset to 60, verify current_frame()==60
  and clean resume with matching inputs; reset to 0; idempotent reset

Closes #5
2026-08-25 00:37:22 -05:00