Made by Borgar Barland and Anders Noël Lothe Morille
This project aims to implement a simple 2D game to showcase/learn netcode functionality. The game consists of a client side application written in Rust with the Macroquad minimal game engine. Players can join the game and move/jump around, seeing the other player's position in realtime. The server-side application - also written in Rust - exposes a SocketIO (WebSocket) API to handle realtime-connections with the client and global state updates.
- Graphical client-side game with movement and jumping
- Toggleable netcode functionality, namely interpolation, reconciliation and prediction
- Adjustable ping that is simulated on the client for both sending and receiving packets.
- Sound effects for joining the game and adjusting ping
- Server-side application that provides a SocketIO API, and can handle multiple client connections simultaneously
- Physics simulation; currently has constant movement speed in the X axis and virtual and jumping where height is calculated based on the time of the jump.
- Collisions; currently no collisions. Contact with ground based solely on min Y coordinates
Packages used in the project. The project is divided into 3 crates (rust packages): client, server and netcode. Dependencies that are shared between the three reside in the workspace dependencies.
- serde: Generic serialization/deserialization library
- serde_json: Serialization of JSON values
- anyhow: Thin-pointer error types for coercible error fallback
- chrono: Date/time/duration handling with Timezone
- thiserror: Library error handling using enums
- axum: Web-API server library. Bindings for TCP/HTTP
- socketioxide: SocketIO library. Bindings for SocketIO/WebSocket
- tokio: Asynchronous runtime for async/await
macroquad: Minimal game engine for audio, graphics and game loop rust_socketio: SocketIO client
This project requires Rust. The project was written in with rustc v1.87.0. Rust can be installed using Rustup. The latest stable release should suffice.
- Run the server
cargo run --release --bin server- Run the client (must run the server first)
cargo run --release --bin clientYou can omit the release flag to compile in debug mode, but this might affect performance.
Space- Join the gameW- JumpA- Move leftD- Move rightJ- Reduce pingK- Increase pingI- Toggle interpolationR- Toggle reconciliationP- Toggle prediction
The server's update rate can be changed by increasing or decreasing the STATE_UPDATE_INTERVAL constant at the top of the server/src/main.rs file, and restarting the server.
This constant represents how many milliseconds the server waits before sending a new state update to the clients. It is recommended to keep this value above 15ms.
Tests can be run with
cargo test