boytacean icon indicating copy to clipboard operation
boytacean copied to clipboard

Implement netplay functionality for multiplayer gaming over TCP

Open joamag opened this issue 2 months ago • 1 comments

This pull request introduces netplay (network multiplayer) support to the emulator, allowing two instances to synchronize serial communication over a network. The main changes include adding a new NetworkDevice for serial communication, updating the SDL frontend to handle netplay sessions, and refactoring serial device handling to support dynamic device types. Additionally, new CLI options allow users to host or join netplay sessions, and the emulator window title reflects the netplay role.

Netplay Multiplayer Support

  • Added netplay functionality to the SDL frontend, including support for hosting and joining sessions, serial byte synchronization, and startup delay for clients. [1] [2] [3] [4] [5] [6] [7] [8] [9]
  • Introduced the NetworkDevice serial device and integrated it into the emulator's device system for netplay.

Serial Device Refactoring

  • Refactored serial devices (BufferDevice, PrinterDevice, StdoutDevice) to implement as_any and as_any_mut methods, enabling dynamic downcasting and flexible device handling. [1] [2] [3] [4] [5] [6]

CLI and User Experience

  • Added new CLI arguments for netplay: --netplay-host, --netplay-join, and --netplay-start-delay. The emulator window title now displays the netplay role (Host/Client) for clarity. [1] [2]

Documentation

  • Updated module documentation to describe the new network serial device and its role in multiplayer netplay.

Changelog

  • Documented the refactoring of NetworkDevice to use configurable byte transforms and the addition of netplay support.

Summary by CodeRabbit

  • New Features

    • Full netplay (host/client) with CLI options, window role indicator, and a network-backed link-cable device and session flow.
  • Build

    • Silent build mode to suppress informational logs.
  • Input

    • Packed controller input: pack, unpack, and apply with interrupt behavior.
  • Refactor

    • Redesigned serial/device API to support network emulation and runtime device downcasting.
  • Documentation

    • Netplay docs and "Build Features" section added to README.
  • Tests

    • New unit/integration tests covering netplay, networking device, protocol, and input packing.

✏️ Tip: You can customize this high-level summary in your review settings.


[!NOTE] Enables multiplayer over network by emulating Link Cable across two instances and wiring it into the SDL frontend.

  • New netplay stack: src/netplay/{protocol,connection,session}.rs plus devices/network.rs implementing SerialDevice with sync queues and events
  • SDL integration: CLI flags --netplay-host, --netplay-join, --netplay-start-delay, role in window title, main loop polling to forward SerialByte/SyncByte/SyncRequest
  • Serial subsystem refactor: SerialDevice adds sync(), is_ready(), awaiting_sync(), as_any/as_any_mut; serial.rs reworks master/slave (clock_mode), transfer enabling, optional delay, and adds save-state support
  • Existing devices (buffer, printer, stdout) updated for downcasting; core exports netplay in lib.rs
  • Input helpers: Pad::pack_input, unpack_input, apply_packed_input
  • Logging: silent feature mutes infoln!; wired into root and frontends; README "Build Features" updated
  • Docs/tests/changelog: added netplay docs (CLAUDE.md), README section, unit tests for netplay/network device/protocol, and CHANGELOG entries

Written by Cursor Bugbot for commit b13da007fbc14e9de23db1259b08887260237f5b. This will update automatically on new commits. Configure here.

joamag avatar Jan 01 '26 07:01 joamag