Super Pong

This project was about an online multiplayer version of Pong. The 2d physics simulation was calculated on your client when the ball was on your side of the court. It turned out pretty glitchy.

Super Pong title

I originally wrote a lot about it, particularly using Box2d and learning to use the UDP and threading Boost libraries.

Here’s an excerpt from one of the original posts, day 6

For now, this will just be a bunch of floats and an int, separated by spaces. e.g. ” 20 -32.6 20.4 1.1 3.1 0.1 235″

Using the sequence number check from the last post, we can make sure that we only use packets that are newer than the last one recieved.
Instead of directly setting the ball position and velocities, they are stored in the GameModeHost object. This way, on each simulator update we can check for new data. If there is new data we’ll then set the ball and paddle properties at an appropriate time. This solves the multithreading problem, as you cannot change the properties of Box2D objects while the engine is calculating a step.

The hard part for me was getting this to actually run in another thread, and because I didn’t find much help online, I’ll share it here.

The io_service needs to be created and started in the same thread as the socket is created. If i knew that 2 weeks ago it would have been much easier.

Leave a comment

Your email address will not be published. Required fields are marked *