1
\$\begingroup\$

I'm creating a 2D Game in Java. The world is tile based with a multidimensional Array and i have the architecture for the Server-Client system. The Users/Connections to the Clients are multithreaded and i have also created the packages.

Now my question is : Should my Client send a package to the server to request the current world state(with entites etc...) in his view range or should i create another thread in my connection/user class just for sending the world every servertick? Or is there even a better solution for sending/requesting the world with his enteties ?

The Game should have less latency and is real Time with an open World.

\$\endgroup\$
0

1 Answer 1

2
\$\begingroup\$

I think the most sensible approach would be to send data that is required immediately to the player specific to their current location. From there you only send updated values when something in the players area changes. For example when the player first connects send the health values for all NPCs in their immediate area, when an NPC is damaged, send an 'update health' packet for that NPC. In the end this approach is much more efficient (and secure in terms of ESP hacks) than sending everything all the time.

\$\endgroup\$
3
  • \$\begingroup\$ But if around 20 enemys recieve damage each tick and around 15 players moving it has to send many packets over time. \$\endgroup\$
    – Jonas Re
    Nov 29, 2017 at 20:54
  • 1
    \$\begingroup\$ Networking is by no means a simple concept, especially when it comes to game development. Generally you send data at a fixed interval (20 ticks / second for Minecraft - 64 for Counter Strike), and interpolate between each tick to make a smooth experience. Additionally you should only be sending data that the player needs at the moment - don't send the player data they won't use (i.e player they cannot see). \$\endgroup\$
    – user99319
    Nov 29, 2017 at 21:01
  • \$\begingroup\$ Also I'd recommend you compress and encrypt your data in transit. \$\endgroup\$
    – user99319
    Nov 29, 2017 at 21:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .