I'm wondering what's the most efficient way to broadcast state changes of entities on a 2d map, to other entities. In particular, I have X players connected to a server on a 2d map and each of them has a sight radius, which defines which other players (or any abstract entities in general) can be seen. Each entity may change its state at any point in time, which needs to be broadcast to everyone who can see it. At the moment, I use a very simple approach:
- Use a quadtree to subdivide the world and assign entities to nodes.
- At each update 'tick', flag entities which has their visible state changed, and recompute their quadtree nodes.
- For each player, determine which changed entities can be seen, and send all their state. This implies any previous entity which the player doesn't see anymore is not sent, and the client can remove it from its view.
This works, but it seems a lot of computing which might be avoided somehow (the visibility determination at each tick seems awful). Does anyone have any ideas?