Allow savestate creation/loading during netplay (in-memory) #2

Closed
opened 2026-08-25 06:03:44 +02:00 by pbwraith · 0 comments
Owner

Repo: gopher64-netplay (fork of https://github.com/gopher64/gopher64)
Context: Full scope doc at upstream analysis — see commit history. Netplay uses GGRS over WebRTC (matchbox_socket), reliable channel carries NetplayMessage { name, data } in 16KB chunks. Savestates serialize full Device via postcard + compress.

Goal: Enable savestate ops while a netplay session is active, without disk I/O.

Background:

  • src/savestates.rs create_savestate does disk write in a spawned tokio task; load_savestate reads compressed file
  • src/device/vi.rs:103 guards process_savestates with if device.netplay.is_none() — states are refused during netplay
  • process_requests in netplay.rs already receives GGRS SaveGameState/LoadGameState requests but stubs them (lines 271-285)

Acceptance:

  • Add SavestateData::save_to_memory() -> Vec<u8> (postcard + compress, no disk) and SavestateData::load_from_memory(&[u8]) (decompress + deserialize)
  • Add create_savestate_in_memory(device) -> Option<SavestateData> — clones device like create_savestate does, returns data instead of writing
  • Add load_savestate_from_data(device, &SavestateData) — refactor the existing std::mem::swap block in load_savestate into a shared function both paths use
  • The device-clone statics (DEVICE_CLONE, SAVES_CLONE) must be reused, not duplicated
  • Remove/bypass the vi.rs:103 guard ONLY for the netplay-savestate path (keep offline behavior identical)
  • Tests: create → load round-trip via memory, verify Device state matches (sample: cpu regs, rdram bytes, vi regs). Test during an active (mocked) netplay session.

Verification: cargo test passes. Offline savestate behavior unchanged.

**Repo:** gopher64-netplay (fork of https://github.com/gopher64/gopher64) **Context:** Full scope doc at upstream analysis — see commit history. Netplay uses GGRS over WebRTC (matchbox_socket), reliable channel carries `NetplayMessage { name, data }` in 16KB chunks. Savestates serialize full Device via postcard + compress. **Goal:** Enable savestate ops while a netplay session is active, without disk I/O. **Background:** - `src/savestates.rs` `create_savestate` does disk write in a spawned tokio task; `load_savestate` reads compressed file - `src/device/vi.rs:103` guards `process_savestates` with `if device.netplay.is_none()` — states are refused during netplay - `process_requests` in netplay.rs already receives GGRS `SaveGameState`/`LoadGameState` requests but stubs them (lines 271-285) **Acceptance:** - Add `SavestateData::save_to_memory() -> Vec<u8>` (postcard + compress, no disk) and `SavestateData::load_from_memory(&[u8])` (decompress + deserialize) - Add `create_savestate_in_memory(device) -> Option<SavestateData>` — clones device like `create_savestate` does, returns data instead of writing - Add `load_savestate_from_data(device, &SavestateData)` — refactor the existing `std::mem::swap` block in `load_savestate` into a shared function both paths use - The device-clone statics (`DEVICE_CLONE`, `SAVES_CLONE`) must be reused, not duplicated - Remove/bypass the `vi.rs:103` guard ONLY for the netplay-savestate path (keep offline behavior identical) - Tests: create → load round-trip via memory, verify `Device` state matches (sample: cpu regs, rdram bytes, vi regs). Test during an active (mocked) netplay session. **Verification:** `cargo test` passes. Offline savestate behavior unchanged.
pbwraith added the
netplay
p1
rust
labels 2026-08-25 06:04:33 +02:00
pbwraith added the
in-progress
label 2026-08-25 06:06:54 +02:00
This repo is archived. You cannot comment on issues.
No Milestone
No project
No Assignees
1 Participants
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: pbwraith/gopher64-netplay#2
No description provided.