0
\$\begingroup\$

I'm making an online RPG that could classify as an MMO, but I'm keeping the project scope very small by making the game's systems simple, and focusing mostly on what I want to learn: real-time networking.

The problem I'm facing is that that I don't want to update every player about every other player, all the time. This is a huge waste of bandwidth, and may even be impossible without a really beefy connection.

My solution is:

  • Keep track of which entities are in the client's visibility range
  • Send a "full entity state" packet when the client enters the world
  • Send a "create entity" packet for any entity that enters the visibility range
  • Send a "delete entity" packet for any entity that leaves the visibility range
  • Send a "update entity" packet for any entity that updates within the visibility range

I don't like the fact that when the client moves, I have to update the list of entities it can see, because it means I still have to loop over every entity. Is there anything better? Can this solution be improved somehow? If so, could you provide further reading, or possibly even sample implementations?

\$\endgroup\$
0

1 Answer 1

2
\$\begingroup\$

A common solution is to divide the game world into square chunks which are as large as the visibility zone of a player.

Give each chunk a list of entities which are currently in that chunk.

When something happens in a chunk (an entity enters, leaves or does something), send that event to the players who are in the same chunk or in any adjacent chunks.

Those chunks can also be used to optimize collision detection, by the way.

\$\endgroup\$
1

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