🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Finally...multiplayer is falling into place.

Published February 01, 2006
Advertisement
Alright...whilst you're reading this, remember that I've never written a multiplayer game before [grin]

The last few days I've been doing major work on the multiplayer aspects of the game. The more packets I added to the game, the more delayed everything would get...On my LAN I was only sending 15-25 packets a second, and eventually the game would get delayed 1-2 seconds.

I had no idea what was going on...so I went through and optimized everything...wrote some crucial prediction/interpolation algorithms to blend the states of all of the actors in the world over the network, so I only had to send a few packets a second. At the same time I was optimizing the bandwidth down to the bit.

All of this optimization wasn't fixing anything, I kept working on other parts of the game. Later I noticed the code where I handle packets (client side) was NOT inside a while loop...so the client was handling only 1 packet per frame, which was causing the delays. The game logic/networking is not updated more than 30 times a second.

Once I fixed that, and changed some parameters in RakNet (the UDP netowrking library I'm using)...everything works like a charm, and all the optimizing I did earlier really just pushed it over the edge.

Everything runs 1000x better now. In my haste I must have forgotten to add the while loop. I was doing everything fine server side at least.

Anyways, that was the only barrier I was hitting, now that's out of the way...I can get trucking on other parts of the game.

The weird part is that the game was actually playable over the LAN/Internet with my client only handling 1 packet per frame.

I've still got to add some kind of post processing glow effect into the game, as well as a particle system for sparks, blood, shell casings, debris, etc.

I'm also still playing around with the user interface as well. I'm going to have a series of boxes stacked on eachother in the bottom right corner of the screen, for things like inventory, health, orders, wanted level, etc.

All else is going well...the game is starting to shape up, I'm a happy camper now that multiplayer is lookin' good [grin]

- Dan

A screenshot from my testing earlier:
Previous Entry Gang War Progress
Next Entry Yay...
0 likes 9 comments

Comments

jollyjeffers
Admittedly, I've always tried to hide from network/multiplayer programming - played with it a few years ago and decided I hated it [grin]

But wouldn't you want to have a seperate listener thread for incoming packets? Set up a producer-consumer system that the main loop can then pop entries off?

Or is that what you've done with this while loop you mention?

Jack
February 01, 2006 05:34 AM
Gaheris
Multithreading is quite a difficult subject to master. It will be very useful in games in the near feature (multicore processors) but in this case I don't see any blatant advantages compared to non-blocking sockets. One can set the maximum amount of milliseconds to use for networking each frame and use that for the while loop, à la while (timePassed < maxMilliseconds) doPollPackets. You could even scale that number according to the general performance of the PC, the bandwidth and speed of the connection.

I'm glad to hear that multiplay is finally working all right. Good luck on the interface design, not a simple job but nevertheless, important enough. I noticed you've already changed font color, good. :)
February 01, 2006 07:11 AM
DecipherOne
Phreaking sweet, I'm still waiting to hear the magic words though...

(Beta Test) [grin]
February 01, 2006 08:04 AM
dgreen02
Ah...well RakNet automatically creates seperate threads for the networking, it sends/receives the packets, re-orders them, assures delivery, and takes care of some other tasks for me as well.

All I need to do is loop through the list of received packets and update the client/server side data, with the received information. The amount of time it takes to handle 100s of received packets is negligible (now that I process more than 1 a frame [grin])

The cool part is you can send arbitrary bit streams accross the network as a single "packet", you can also turn on different types of packet compression easily.

RakNet really takes the headaches out of multiplayer (UDP) programming...I <3 it.
February 01, 2006 10:31 AM
VisualLR
I'm no arist, and I don't mean to nit-pick.. or go off-topic... BUT. The texture on the rearview mirror looks sideways to me.

Man, that got me thinking, it won't be long now (if they don't already) before all cars in games will have fully working rearview mirrors...

anyway, sorry for going off-topic... and nit-picking... haha
February 01, 2006 06:39 PM
Rob Loach
Now you can play with yourself!
February 01, 2006 07:11 PM
dgreen02
Hmmm good call on the mirror's texture, I didn't notice that. With so many car models sometimes things slip by. Thanks for pointing that out :-)

- Dan
February 01, 2006 07:58 PM
VisualLR
Hehe, I used to be in QA, so that type of thing tends to stand out for me.
February 02, 2006 08:18 AM
Drew_Benton
Sweeet!
February 06, 2006 02:10 AM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Advertisement