WarFrontIO / client

Real-time strategy game played in the browser
https://dev.warfront.io
MIT License
20 stars 6 forks source link

Performance of player-name calculations #4

Closed platz1de closed 3 months ago

platz1de commented 3 months ago

The performance of the calculations to determine the optimal name position is still pretty bad even after a few rewrites, taking about 30% of a ticks time Link: PlayerNameRenderingManager

Current behaviour

Whenever a tile is conquered it has to be removed from the possible name area for the player who lost the tile and added to the the player who conquered the tile. This is done by keeping track of the maximum square starting at a tile going north/west. In the best case, tile updates don't affect the name position, making adding them into this datastructure very cheap (most tiles only require a few neighbor updates). In the worst case (the player expanding north/west), most of the territory needs to be updated (potentially millions of tiles).

A small example (Before adding the tile 0 and after)

0111                    1111
1122                    1222
1223                    1233
1233                    1234

Target behaviour

Possible solution