• Advertisement
Sign in to follow this  

Question about listening for packets, updating world and concurrency with libgdx

This topic is 701 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

I'm writing a very basic MMO with turn based combat. It's basically Pokemon Blue/Red online...

 

Anyways, I thought of two ways I can have the client listen for packets update moving entities (players, monsters) and I don't know which would be better to use.

 

Method A

GAME RENDER LOOP
  Process any packets that have been recieved
  update world based on changes from server
  update client player(obvious)
  send changes to server
  render world
END LOOP

or

 

Method B

GAME RENDER LOOP
  update client player (obvious)
  send changes to server
  render world
END LOOP

PACKET LISTENER THREAD WHILE ALIVE LOOP
  Process any packets that have been recieved
  update world based on changes from server
END LOOP

Method B would probably include concurrency issues, but I'm new with threads and I'm not sure what would be an issue.

 

The line Process any packets that have been recieved will NOT make the program hang while waiting for bytes in the stream.

 

 

I'm leaning more towards Method A because it's simpler, but I don't know if it will be fast enough.

 

Which method is best? If any...

Share this post


Link to post
Share on other sites
Advertisement

As a start I would use Method A because as you mentioned you could run into problems with concurrency with version B.

For method A what you can do to improve performance is to let the server run at a slower refresh rate than the client. For example your server will run at 20 fps and your game loop with 60fps. In this case you would only process the server information each third frame.

Share this post


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

  • Advertisement