Good practice in mmo - need help.

9 posts (showing 1-9)
DonReptile

Market Level 0Community Level 0
6 posts

Hello,
I am building game based on box2d and node.js, and communicate with html using socket.io. So far i had not many problems, but now I am fighting with big bandwidth usage. Correct me whenever I am wrong. From client I send only controls change, so "up start", and "up stop" etc. So server download shouldnt be too big. But from server I send to all players coordinates of all others with 30fps. Right now data I send with 15 players weights about 2kB. 2kB * 15 players * 30 frames gives me 7.2kk bps , It's quite a lot I guess. And it is about 3.5MB/minute for one player to download data about 15 others, it can ruin budget of mobile players (: I am sure I can trim data from 2kB to about 500 B, and not send data, that aint changed. But still it will be about 1-2kk bps with 15 active users, but 2 times more players means 4 times more bandwidth usage.
So my main questions are:
Are my calculations are correct?
Is my method of synchronizing is correct?
Maybe I have to read, and send controls information to all players instead of their position, and embed box2d in client, calculate game on every player client, and synchronize with server once for second?

Thank you for any help.
Maciej

posted 2015-07-14T10:26:29-07:00
SoulStudio

Market Level 2Community Level 2
145 posts

You should send every frame each player position.

Try to broadcast every input.

posted 2015-07-14T15:04:03-07:00
FGL_Aaron

FGL AdminCommunity Level 7
1060 posts

Ahh, multiplayer optimization... good times... It sounds like you're off to a good start. Smile

I don't have a ton of experience with this, but I have done a bit of research on multiplayer games and have even been working on one of my own as a hobby.

So let's break down the responsibilities:

Client: Gather user input, validate move is legal (to avoid sending unnecessary invalid requests), send user input to server for validation, wait for confirmation, make move

Server: Validate move, broadcast move to all players if valid

Of course either could do more, but keeping it simple for this conversation. The piece that matters most right now is whatever is being sent over the network. It sounds like you've already figured out how to trim it down to 500B, but can you get it lower than that? Or can you perhaps trim it down even further?

I'm sure there are shortcuts you can use to assume certain things in mmo's to optimize further, but I'm not certain what those things might be. 

Another thing to consider, some things may not need to be updated on every frame (for example, the health of your enemies could probably be updated every 2-5 frames with little noticeable difference).

Good luck with your game!

posted 2015-07-14T16:22:22-07:00
DonReptile

Market Level 0Community Level 0
6 posts

Thank you very much. I found good way to minimize to minimum data transfer, and it worked pretty well :) I send now all most important data in 30 fps like player id, position x, position y, and angle (8 steps 45 degree). Changed it to bits, 17 for id, 14 for x and y, and 3 for angle. It gives me 48 bits when combined. I change it to 5 chars ASCII, and send as string. I will try to move enemies in 10 fps or even lower with transitions between steps if needed ;) Later when ill make scrollable screen ill be checking if user is visible for me, and if his state has changed. I hope, that maybe someone will have use of my response and question ;)

Ps. I will tell you in secret. I am building mmoba (:

posted 2015-07-15T07:36:06-07:00 | edited 2015-07-15T08:21:05-07:00
b10b

Market Level 4Community Level 7
971 posts

Yeah socket.io, that stuff is awesome!

If wanting to compress further I'd optimize based on these assumptions:

  • Every player does not need to know about every other player at the same frequency.
  • Most players do not change their movement each frame.
  • Each movement is represented by a finite controller change.

I'd move that towards a controller state packet expressed in ~6 bits that uses run length encoding and variable packet exchange based on distance from observer.  I'd probably include a full state validation checksum every 5-10 seconds, all logic would be server authoritative (and matched on client) so the check could be reduced to 2 or 3 bits.  I'd send any non-controller messages (e.g. user chat) separately.

posted 2015-07-15T17:13:31-07:00 | edited 2015-07-15T17:14:29-07:00
FGL_Aaron

FGL AdminCommunity Level 7
1060 posts
  • Every player does not need to know about every other player at the same frequency.

b10b

Good point! Proximity to each other may determine how much data the players need to know about each other. For example, the player's health (potentially 5+ digits) could be replaced with a single alive/dead boolean for enemies outside of the set threshold.

There are probably a lot of tricks you could find to further reduce how much and when data is being sent over the network. Smile

posted 2015-07-15T20:46:27-07:00
LordSharpe

Market Level 0Community Level 1
40 posts

You could consider dead reckoning as well, depending on how accurate you need to be: add velocity to the packet, and cut the update frequency by a third (or something), and let clients extrapolate where they WOULD be, assuming they haven't changed velocity in the meantime. Or, if they do change velocity, update then. If its not an accuracy based twitch shooter, that may be close enough.

posted 2015-07-16T13:07:55-07:00
DonReptile

Market Level 0Community Level 0
6 posts

Thank You guys for your advices, each one were very usefull. 2 days ago I was testing game after changing data from JSON to binary transformed to Ascii. And with big succes, about 14 times less bandwidth usage. Now after few optimizations it's hard for me to test effect, because even if I run game at 20 windows, no data will be sent from idling player, and usage would be 0 :D now will be most fun part, building world, enemies, embedding render engine (guess pixi). I guess enemy frequency change I will add with checking if enemy is close enough to render him. Anyway, so far so good. Wish me luck, and thank you again ;)

posted 2015-07-16T17:51:43-07:00
FGL_Aaron

FGL AdminCommunity Level 7
1060 posts

That's awesome, congrats! Laughing

Good luck!

posted 2015-07-17T00:41:42-07:00