Jump to content
  • Advertisement
  • entries
  • comments
  • views

Finally...multiplayer is falling into place.

Sign in to follow this  


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:
Sign in to follow this  


Recommended Comments

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?


Share this comment

Link to comment
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. :)

Share this comment

Link to comment
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.

Share this comment

Link to comment
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

Share this comment

Link to comment
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

Share this comment

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!