Multiplayer version of the classic game pong with a few unique tweaks!
pushpong_demo.mp4
⚠ This project is no longer maintained.
Push Pong was once available at pushpong.xyz. The site is now offline.
I started this project to get a better understanding of how to synchronize networked physics (netcode). This was my first fullstack application.
I wrote up a document about findings and lessons learned that can be found in the docs/
folder of this repository.
If I had to start this project again from scratch, here are some changes I would do.
Instead of looking for a physics engine that supports continuous collision detection to avoid situations where the ball goes through surfaces, I would at least consider the following approach.
- Set a global speed limit
- Set a high tick rate for the engine
I would avoid any form of lag compensation. This is what I tried for this project and it's simply the wrong approach for any game where multiple players have physics interactions with a shared object (in this case, the ball). Two clients that are out of sync can never perfectly get back in sync unless movement stops (which never happens for the ball, but does for players). Worse, two clients that are already in sync can be forced out of sync because of lag compensation.
Instead, we have to take an approach called deterministic lockstep. The best explanation of how this is implemented in practice is best explained by Rocket League developers in this talk.
At its core, the concept is as follows:
- Both the clients and the server run the physics engine at a fixed tick rate (independent of framerate) and are able to store the history of states at every tick.
- Clients send their inputs (controls) and the timestamp (tick number) to the server at every tick.
- Clients don't wait for the server. They continue to run the physics simulation.
- The server runs the full game as well, and receives inputs from both players.
- The server sends a (compressed) snapshot of the full state of the physics engine at every tick (which is typically 60 times per second, but can be more). The snapshot includes the timestamp.
- When the client receives a snapshot, it
- Goes back in time to that snapshot's timestamp
- Applies that snapshot
- Regenerates all the steps to catch up with its present step
- Redraws to the screen
This approach is pretty data-heavy for large simulated worlds, but it allows two clients who are in sync to remain in sync, and allows a client who is not in sync to become in sync.
If you're not already familiar with netcode challenges and deterministic lockstep, this explanation is still probably too vague. The document and video linked above will provide a much better explanation of the problem and solution.
For this project, I went with a JavaScript physics engine that doesn't come with baked in rendering. I spent way too much time tweaking things to make sure what was being rendered on the screen was an accurate representation of what the physics engine was reporting.
As stated in the collision detection part, I wouldn't limit myself to a physics engine that has continuous collision detection, so I would probably be able to find a physics engine with a built-in renderer. This would have saved me hours of work.
As stated in the lag compensation part, I would opt for an approach using deterministic lockstep. Since that approach is very data-heavy, I don't know if any web-based engines would really be appropriate. This approach is typically done using UDP rather than TCP, which is not something I can use in a web app.
Instead, I would make Push Pong a desktop app and look to send data via UDP. Then I would look for a mature physics engine that ideally has some built-in libraries for deterministic lockstep since it is quite a complex process to get right.m
⚠ This project is not actively maintained. Forks of the project are welcome, as this project is published under the MIT license.
- Docker
- Docker-compose
- Make
From the root of the repository, run the following commands
make build
make start
The webapp will then be available at localhost:3001
If there is ever an issue with a missing import, or something works with npm locally but not using docker-compose, run the following command:
make down
This project is licensed under the MIT License - see the LICENSE file for details.