One of my big plans for War Worlds is that it'll be heavily multi-player based. I've recently hit a bit of a milestone to that end, and this is what I'm posting about now.
The basic architecture of the game is based on what I learnt from the "1,500 archers" post on Gamasutra some time ago. Basically, the game is "turn-based" but the turns are so fast that you don't really notice and it "feels" real-time. The "simulation", as it were, runs at a fixed 5 frames per second, and each command you issue to a unit is queued up on the simulation thread for two turns in the future. Then, at the end of the turn, it sends an update to the peers on what you're planning to do. Once all players have received notification, the two turns should be up and all players will execute the command at exactly the same time. And since all the simulations are the same, the game should (theoretically) stay in sync.
But before I got to that stage, there was a lot of ground-work that I had to lay. The first thing I did was create a simple "lobby" server, which is actually just an ASP.NET website with a database back-end.
So, when the game starts up, you get the main menu. From the main menu, if you click "New Game", you get the screen that I've shown in the following screenshot (I use CEGUI as my GUI framework - the skin is one of my own creation):
So, when you click "Login", it asks you for a username/password and once you've typed that in, it'll make a request (via cURL) to the lobby server to login and register the game.
Next, another player wishing to join your game would click on "Join Game" from the main menu, where the game asks for his username/password, and then it returns a list of all the games that are currently available to play. The following screenshot shows the game we started above as being listed:
So you click on the game you want (obviously the fields I've chosen in here are only temporary and will definitely change as the game develops!) and click "Join Game" at which point you get the "New Game", but now you can see that both "user1" and "user2" are there:
From here, you can see that you can chat with the other players. In the future, you'll be able to adjust things such as your player's colours, AI players and so on. You can also select the map (more on the maps in another post). Once you're ready, you click the "Start Game" button. Under the hood, the game communicates your readiness to the other players (you can see in the screenshot above that "user1" has clicked "Start Game" and is marked as "ready").
Once all players click "Start Game", the game starts up for real and the map is loaded.
Once in game, the simulations talk back and forth to each other about each turn and what commands the player has executed in that turn. As I mentioned, each turn lasts for 200ms (200ms = 5 turns per second) and the kinds of commands that are executed are things like "create entity" (e.g. create a new tank, new missile, new building, etc), "move", "attack" and so on. So when you click a unit and ask it to move, there'll be a 400ms (approx.) delay before it actually happens. In a real game, you don't actually really notice, because the unit will have a "moving" or a "yessir" kind of animation/sound effect.
The screenshot below is from within the game. You can see that graphically it's not that much different from the last time I posted about it, but obviously much of the work has gone into the lobby server, the UI and the underlying networking layer...
The communication layer in the game is built on top of ENet which is a pretty low-level wrapper around UDP and provides a reliabilty layer, unlimited packet sizes and a few other benefits.
Currently, the only commands that are implemented is a "chat" command (which you can see being used in the bottom of that screen shot) a "create entity" command (which is used to create the tanks initially - each player in the game creates one tank, and the "create entity" command ensures the tank is replicated to the other players. The "move" command is the most interesting at this point, because that's the main "mechanic" command that I've implemented. When you order a unit to move, it'll move towards it's goal on all player's version of the game at the same time.
It actually didn't take me as long as I thought it would to implement that feature (most of the work these last few months has gone into the UI and lobby stuff) but I'm quite proud of it. I'm sure there's plenty of edge cases and bugs (currently, the main problem it has is that if ping times climb above 400ms, the games will get out of sync, but that's something I can look into later, I think...)
Now the real fun starts and I can start implementing actual game logic. My plan first, however, is I want to port the lobby code to PHP so that I can run it on this web host (meaning the game will actually start to work over the internet, and not just on my development box...) then I can start looking at designing some buildings and unit-creation factories and stuff.
Exciting times! In the future, I'm hoping to talk a bit about the map editor that I'm creating along-side the game, a bit more about the network architecture, as well as my plans for how the game will be released (though that won't be for some time, obviously!)
This post has gotten quite long, and I guess that's my own fault for leaving things so long before I posted an update. But, as I mentioned before, I was overseas for a month (a lot of this stuff I did while I was over in Korea...) so it's been a bit tough to get online as much as I normally do.