GPWiki.org
GPWiki.org
It is currently Wed May 22, 2013 3:01 pm

All times are UTC




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Tue Aug 23, 2011 2:03 pm 
Hey guys, im making a multiplayer game, the server is written in java, while the game runs on a 2D lua game engine some may know called 'LOVE', however i encountered problems with networking. So i will be using UDP to transfer data between server and client, tho im not sure how i should be doing it. Lets say i have 5 players in one map, the player sends a forward command, which means a player has to go 1 step forward, now i wonder whether the server should tell all the other players that Player 1 has to move 1 step further, or just tell all the other players that player 1 has changed his coordinates to [insert vector here]. However, if the player wants to move 60 steps a second, and my server broadcasts updates to players 30 times a second, wouldnt the walk look jittery?


Top
  
 
PostPosted: Tue Aug 23, 2011 4:46 pm 
Dexterous Droid
User avatar

Joined: Wed Aug 18, 2004 7:40 pm
Posts: 3735
Location: South Africa
You would want to do both and also do some hacking / magic on the client side. By magic I mean smooth out the data coming in from the server and make some assumptions about what will happen while waiting for the next packet. You'll see that in multi-player games with bad latency and network loss issues, other players will sometimes walk off in a straight line and then suddenly snap to a different position as new data comes in. In good conditions though you won't notice it.

It will use less bandwidth if you send off single packets for each player's input and let the clients recreate the other player's position based off of that input. So you send one packet for "user pressing forward key" and another for "user stopped pressing forward key". UDP doesn't have as much overhead as TCP and is ideal for that sort of thing. For this to work you need all your clients game logic to be running at a fixed frequency.

You'll probably want to send through some absolute values as well on TCP though. TCP guarantees delivery and that means you can be sure that all the clients will have the correct position even if some of the UDP packets get lost.

_________________
Whatever the mind can conceive and believe, it can achieve


Top
 Profile  
 
PostPosted: Sat Aug 27, 2011 12:27 am 
Rookie

Joined: Fri Aug 26, 2011 10:46 pm
Posts: 4
Actually sending absolute positions over udp is really nice. Since the absolute position contains all the information you need for the state, you dont need to rely on relyability. You just apply any position udp packets which are more recent than the last one applied. If a packet is lost, the next arriving packet will be able to fix any missing informtion, and old positions that come in can just be thrown out. In general I think the best is to have clients send inputs to the server, have the server do the object logic, and then send positions of the objects to connected clients at a set interval.

And then yes, you will want to do too "tricks" on the client. Incoming positions for other players need to be smoothed out. If say, you get position [5,5] at time 0 seconds, and then the next position you get is, say, [25,5] at time 3 seconds, you dont want to just warp him to 25,5. Instead you want to over, maybe, the next 1.5 seconds, move him from [5,5] to [25,5].

Finally, for the players object, you want to apply the inputs to his local object as soon as they are made. You will have to work out how to deal with the server correcting the clients position if he makes a mistake in his prediction of where he should be.

Beyond that, you will want to optimize everything to fit your game. A general rule is, if something doesn't need to be sent, don't send it, and if something doesn't need to be reliably sent, don't send it reliably. Using udp, you will want some protocol to ensure the few message types that do need to be reliable (chat messages) actually arrive.


Top
 Profile  
 
PostPosted: Sun Aug 28, 2011 11:37 am 
Dexterous Droid
User avatar

Joined: Wed Aug 18, 2004 7:40 pm
Posts: 3735
Location: South Africa
saluk's post is a much better explanation than mine. Use UDP to send the absolute positions of objects out from the server and player's input to the server.

_________________
Whatever the mind can conceive and believe, it can achieve


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group