MapleServer2
MapleServer2 copied to clipboard
Stat computation & packet sending refactor
Currently stat computations trigger a packet send immediately, and systems that touch stats to make changes trigger stat computations. This can be incredibly wasteful if there are multiple batched changes that are really all part of one change, like items that have multiple additional effects. Here is a proposed solution for batching packet send requests to reduce network traffic:
On the stats object:
- add a bool to say stats need recomputing
- add a bool to say dispatch a stat packet
- add a container to mark which stats are dirty
- a func to mark stats as stale. calling this adds the stats object to a global queue of stale stats objects. add an option to mark which specific stats were changed in case only one stat is needed in the packet
- a func to refresh stats only if stale, but dont send packet. calling this marks stats as not needing computation
- and a func to refresh stats if stale, and send a packet if needed. calling this marks stats as not stale and not needing a packet
In a global service:
- add a container to hold references to the stats objects that were marked stale in the last frame
- add a flush function to refresh stats and dispatch packets, clearing the queue
- call flush once a frame or so