Architectural Problems so Pong

I’ve found that I’ve programmed myself into a bit of a corner.

The issue is that my game engine, despite my best efforts, is architecturally bad. I think this is probably a regular occurrence for a first-time effort of a project this large. This poor design came about despite having read Design PatternsGame Engine Architecture and Game Programming Patterns.

I think this was inevitable. Reading books such as the above, and I highly recommend them all, isn’t the same as applying the patterns in practice. There are many patterns throughout the code, don’t get me wrong, but I think the logical separation of state isn’t as logical as it should be.

So; having stepped back from the code and given it a very thorough critical review… it needs to be re-coded in large portions.

It’s not only the architecture that’s a problem, I think my build chain is poorly designed. Having known no better, I started as one large project; whereas each component likely could’ve been it’s own project, each outputting .dll files.

Further to this; I’ve just been programming and testing as I went along. Unit Testing, something I’ve never done before, is probably something I should look into. It makes complete sense, by enforcing unit tests on myself, I’d naturally enforce the decoupling of systems. I’m concerned about the amount of time and effort that needs to go into test driven development, but having never undertaken it, I’ll look into it.

Another problem I’ve found is that I didn’t architect the engine for networking. Something that I’ve learned the hard way, needs to be designed into the code up-front.

So; in order to begin applying patterns, networking, and possibly unit testing into my code; I’ve decided to make a 2D network-multiplayer Pong clone. Should be simply enough to code the actual game; but where it should get interesting is in applying network into the core of the engine.

I’ve designed it already.

Pong Architecture

Pong is probably too simple to really apply Design Patterns; however there’s the few usual patterns that you’d expect in a game, really just Update and a Game Loop. However, what I’ve done here is focused on the separation of game data from the rendering and looked heavily into Networking.

For the rendering, I’ve decided to use SFML rather than my own engine code. SFML is great, it’s quick and easy and does 2D brilliantly. The reason I’m making Pong isn’t for the graphics, so I had no desire to go that deep.

SFML also has a great networking abstraction layer which I’m using for Pong. I’m not too worried about ensuring packets are delivered correctly, so abstracting that out works well for me.

I’ll probably go back and replace SFML with my own code later.

I’ve read over the Multiplayer-Neworking information on the Valve Developer Wiki a few times to learn about how to implement my Pong game. The reason I’m looking so much into Valves information is that their networking is for fast-paced action games. My Pong game is going to use the mouse to control the paddles, therefore it is fast-paced.

This has led me to determine that a Server-Client model won’t work for Pong. I really wanted it to, as that’s the sort of common way big games do it; but I can’t see how that would work for me. One player, the Listen-Server player, would always have an advantage. In a one-on-one game, I don’t think that’s fair, sure it works for 16v16 or something, but not 1v1.

So instead, my Pong game will be a bit… funny. Whoever is currently in “possession” of the ball will be the “server”, and whoever is waiting on the ball will be the “client”. So, as soon as I hit the ball and return it, my opponent will now be deciding the game state.

This allows each player to locally control the very time sensitive hit-detection etc. For a real game, it would be disastrous. Cheating would be rampant. But no one is going to cheat at my Pong game, I’m sure.