Implement netplay functionality for multiplayer gaming over TCP
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
NetworkDeviceserial device and integrated it into the emulator's device system for netplay.
Serial Device Refactoring
- Refactored serial devices (
BufferDevice,PrinterDevice,StdoutDevice) to implementas_anyandas_any_mutmethods, 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
networkserial device and its role in multiplayer netplay.
Changelog
- Documented the refactoring of
NetworkDeviceto 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}.rsplusdevices/network.rsimplementingSerialDevicewith sync queues and events- SDL integration: CLI flags
--netplay-host,--netplay-join,--netplay-start-delay, role in window title, main loop polling to forwardSerialByte/SyncByte/SyncRequest- Serial subsystem refactor:
SerialDeviceaddssync(),is_ready(),awaiting_sync(),as_any/as_any_mut;serial.rsreworks master/slave (clock_mode), transfer enabling, optional delay, and adds save-state support- Existing devices (
buffer,printer,stdout) updated for downcasting; core exportsnetplayinlib.rs- Input helpers:
Pad::pack_input,unpack_input,apply_packed_input- Logging:
silentfeature mutesinfoln!; 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 entriesWritten by Cursor Bugbot for commit b13da007fbc14e9de23db1259b08887260237f5b. This will update automatically on new commits. Configure here.