Advertisement

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

Started by May 24, 2016 08:52 PM
0 comments, last by DaSutt 8 years, 7 months ago

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...

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.

This topic is closed to new replies.

Advertisement