Alternative to double dispatch



  • Several optimization tasks in agario are needed, a large room with several thousand different types of objects, different types interact with each other, but not all.

    1. Reduce the cost of computing the interaction of the objects.
    2. Reduce network traffic and tracking costs.

    As a solution, I chose to replace the monolithic room on the map of the sectors (a sector tract matching the two-way map). Interactions are only traced between objects within the sector. The following sector structure is requested:

    struct Sector {
      std::set<Cell*> cells;
      uint16_t id {0};
    };
    

    Interaction itself is simply to be achieved through double-dispatching. It is dismaying that, in this case, there is a need to keep track of the interaction of all (but already within the sector). Clearly, it's much more efficient than the same in one big sector. But, for example, now I have interactions only between those objects that, in principle, may be interaction.

    X. Or don't frustrate and edit double-dispatching, or while writing the message, it's only four types of objects and only the same type of objects that have yet to interact in my game.



  • Looking at the objects' interactions, I've found a somewhat different response. According to the Geimdisais, permanent bodies do not interact with each other. Therefore, a good solution, coupled with double dispatch, would be an exception to the bulkhead. impossible options for interaction.

    My decision is to create two containers:

    1. Gridmap is non-mobile bodies divided into square sectors (up to 10K objects).
    2. std::set<Cell*> - moving bodies (there are very few, less than 100).

    Each iteration processes interactions between each moving body and bodies from the sectors where the body is located, and all moving bodies are combined. Stopped bodies or, on the contrary, traffic begins to move into a suitable container.




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2