Friday, June 06, 2008

Synchronisation bug in the server...

Well well, what a surprise! More updates on Dune :).

I've coded a bit on Dune in the past few days. Not an awful lot, because I had other things aswell, but I managed to code up a few bits on the train while traveling to/from college.

Units are moving again

Yes, first thing I did was re-enable the controls to move units and scroll around the map. Sure, they don't actually send stuff over the network, but units are moving, and I found a few bugs in there related to the MCV(ie, MCV can attack, but isn't supposed to). I intend to fix this first, before actually buffering the calls to order units around.

I also need to build the turn-system for the packets. I guess I should buffer up the commands first, and then actually start working on the system that collects the packets from other sources and hands down the orders to the correct player.

DebugConsole is now a real UI object

I updated the DebugConsole, because it didn't quite behave like I wanted it to behave. It was the first 'UI' control I built, and wasn't based on the later written UI system. In other words, it was a dirty hack that rendered itself to a texture and constantly drew the texture when needed. Obviously, that was faster than the current approach, but made it more difficult to make the console support features like real UI objects, such as resizes and adding of sub-controls.

I think the next iteration of the console replaces the current code with a Textfield / Textbox in which I draw the text, and a 2nd textfield / textbox to type in. That would make it much easier to add in support for scrollbars, and other various snazzy features. But, that doesn't have an awful lot of priority at the moment.

Synchronisation bug!

And of course the bug I mentioned in the title. I have a really weird bug in the Server code related to loading. It's a few days old, and I've been trying several times to patch this up, but it didn't quite work.

The problem is as follows: When I enter the NetworkPlayState, this will create a new state called NetworkLoadingState which is responsible for loading all assets and synchronising all the clients with each other so that each game starts around the same time. However, when the server is behind on loading than the client(On my machine that is. The game having the focus will load slightly faster than the background window), it will be done loading by the time all the clients are done loading too. It will see that everyone is done, and trigger the OnStartGame event, which in that case, will report that the server hasn't completed loading yet. This will mean the client will push a new NetworkLoadingState onto the stack and voila, the game will start throwing exceptions.

I have no idea yet on how I'm going to solve this. I'm considering the just ditch the current asynch approach, get rid of the events of the events and start using blocking functions instead, to make sure things will run in proper order. Alternatively, I might just build in a 1 second delay on the server side to prevent this from happening, but that would be a dirty hack I rather avoid. First step is to figure out where it actually goes wrong, and then find a way to solve the issue neatly, without fudging up my code too much.

3 comments:

Capn_Awesome said...

Great! Stumbled upon your site by surprise - popped right up on top when I searched for Dune 2 Remake. I didn`t know there was one, or one in the making! Great!!
From time to time I revisit old amiga games, which holds fond memories for me (I had an amiga 500 when I was a kid). Man, we gamed. Dune II was a great, and solid, game in many ways. I wish you luck on your project, and hope you find joy in doing it. Ahhh.. Nostalgia bliss |-D

PS: Not to be a bummer or anything, but it SUCKS BALLS that you have to log in on those freaky sites to post (and google being megalomaniac, world-dominating succubus - kidding, don`t like to big corporations). 'Signed up.

Daniel said...

Hey there, I noticed that you're having trouble with clients loading before the server.

I'm not sure on your source code but could you just not have them wait until the server is finished?

Most modern server-client games do this.

ie. Have your clients load all the texture data, map data, start positions, initialise objects and get everything ready. Then just wait.

Once the server has finished loading, sync up the object data across network. Obviously the game isn't ticking so you can do this one at a time in a simple queuing system. Once all clients are sync'd (have them respond to the server) start the game ticking. :)

Daniel said...

Also, something I missed from my previous post. It will be useful to have a "NetworkResync" state.

If the game falls out of sync, issue this state and it will re-update the clients based on the server's knowledge. It may not be the best solution, but it's certainly better than playing a game for 2 hours only to have it crash out because one of the clients fell out of sync ;)

Also, it means you can have a loading state followed by a sync state allowing you to perform them as two steps rather than a combined single step.