Jump to content
  • Advertisement
Sign in to follow this  
graveyard filla

help designing network architecture for pong game (which will be expanded)

This topic is 5405 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hi, im currently in the process of networking my old pong clone. however, this is only practise so that i can learn the basics of networking, so i can go on to network my 2d RPG. no, dont worry, i dont want to make a MMORPG, or even anything that complicated. i only want to allow around 8 people to connect to death match each other. no NPC's needed. however, i do have a goal in the future to expand it to allow interaction with NPC's, so that the players can connect and kill NPC's togeather in a more traditional style online RPG (ie Diablo). anyway, the point is, id like to get good architecture in now, so that expanding the client / server wont be as hard or sloppy when switching from pong to RPG. currently i have it set up like this: - every 20 MS, the player sends the server his Y coord (if there is a game actively going on) - the server bounces this back, so every 20 MS, the client also recieves the other guy's Y position and updates his enemy accordingly ok, this is working good. i can connect and have 2 paddles moving around on 2 seperate machines. but i havent added the logic for the ball and collisions and stuff yet, and im not sure how to do this. my plan was this: - on the client, have the ball only be a "dummy", just like the enemy paddle. the server will send us the position of the ball every 20 MS, and thats it. we just render the ball at this position, and apply no logic to it. - the server does all the logic. he checks for collisions, and moves the ball appropriately. every 20 MS, he broadcast's the ball's position to the clients. how does this sound? theres one flaw ive already noticed with having the server do the logic. for example, what happends when a ball hits another paddle/ wall / whatever? it *should* make a sound. but since the player doesn't even know how to detect collisions, this isnt possible. i *could* have the server send out messages like PLAY_SOUND_BALL_HIT_WALL, or PLAY_SOUND_BALL_HIT_PADDLE, but this is sloppy. again, another problem is that how does the player know which image of the ball to draw? in my pong clone, the ball isn't a regular ball, and has 2 seperate images, one for going left, and one for going right. i figured when the server detected a collision, i could send a packet containing the X velocity to the clients, and the clients could use this velocity to determine which ball image to draw. so im confused though. this seems like a sloppy way to handle it. also, i cant do this same thing in my RPG. for example, its an action RPG with guns and stuff and real time combat. i guess i need to put more logic into the client side, but i just dont know how to exactly do that and make it all synchronize. any help, links to articles, whatever, is greatly appreciated.

Share this post


Link to post
Share on other sites
Advertisement
A simple way to resolve this would be to send both the x,y coords of the ball and the x,y velocity. This will allow you to do two things: dead reckoning and quasi-collision detection.

If you have the x,y velocities you can compensate for dropped packets by simply drawing the ball based on the last packet recieved. Once you get the next packet the ball can be updated properly.

Second, since a collison with a paddle will change the x velocity you can make a check each time you get a new ball update. If the x velocity has changed signs then the ball has collided with a paddle and you can play the BALL_HIT_PADDLE sound. This will work for wall collision as well, just check for a change in the sign of the y velocity.

Hope that helps.

Share this post


Link to post
Share on other sites
It is a general rule when network programming to send as little data as possible. Unless the ball changes velocity mid-flight in an unpredictable fashion there is no need to constantly send its position. Here is what I suggest:
The ball on the client’s side should be a ‘dummy’ in the sense that if it goes out the game does not end. But the ball’s position should be updated each frame based upon its x and y velocity and it should bounce off the walls and paddle. This is prediction – it helps keep things smooth and enjoyable.
When should you send information about the ball to the client? I’d say when the ball has hit a paddle – this is the only place where things can really go wrong on the client if the paddle update message has, for some reason, not been received and the paddle is not where it should be. Therefore, the server needs to tell the client when the ball hits a paddle. It needs to tell the client where the ball hit and, upon receiving the ball hit message, the client needs to determine where the ball should be now, given that the message was sent a short time ago, and the move ball there (setting the velocity as well). The ‘determine where the ball should be’ can be done roughly by applying an average ping or *gasp* time stamping and synchronization (two computers have different clocks).
This is not to say that the ball should not automatically bounce off paddles on the client side – it should still do this to give the user the best possible idea of what is actually going on (prediction).
The server should also control such things as score, begin and end of games, etc.

Anyhow, that is what I might do – but I’m not very experienced in network programming so don’t take what I say as the way things are.

Jackson Allan

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!