It is necessary to solve several optimization problems in agario-like game - a large room, with several thousand objects of different types, different types interact with each other, but not all with all.
- Reduce the cost of rendering the interaction of game objects.
- Reduce network traffic and change tracking costs.
As a solution, I chose to replace the monolithic room with a sector map (sector vector corresponding to a two-dimensional map). The interaction is tracked only between objects within the sector. The following sector structure suggests itself:
struct Sector { std::set<Cell*> cells; uint16_t id {0}; }; The interaction itself is simply implemented through double dispatch. It is embarrassing that in this case it is necessary to constantly monitor the interaction of everyone with everyone (but already within the sector). It is clear that this is much more efficient than the same thing in one big sector (the whole room). But, for example now, my interaction is calculated (albeit in a whole room) only between those objects between which, in principle, there can be an interaction.
Shl. Or do not bother and saw double dispatch, but while writing a message I realized that in my game only 4 types of objects and then only the same type do not interact.