Commit Graph

2 Commits

Author SHA1 Message Date
Aotumuri b71acdc993 Patterned territory (#786)
## Description:
This is meant to give players more customization options.
Permission handling hasn’t really been implemented yet.
## Please complete the following:

- [x] I have added screenshots for all UI updates
- [x] I process any text displayed to the user through translateText()
and I've added it to the en.json file
- [x] I have added relevant tests to the test directory
- [x] I confirm I have thoroughly tested these changes and take full
responsibility for any bugs introduced
- [x] I understand that submitting code with bugs that could have been
caught through manual testing blocks releases and new features for all
contributors

## Please put your Discord username so you can be contacted if a bug or
regression is found:

aotumuri
2025-06-22 23:57:24 -04:00
DevelopingTom 3b9e94ddb9 Improve border drawing performances (#751)
## Description:
When drawing the border colors, the territory layer is using the generic
`nearbyUnit` function to check if any allied outpost is nearby.
But `nearbyUnit` is uselesly computing the distance with all units,
which is very costly specially in late games with plenty of units.

Early game (<1 min):


![image](https://github.com/user-attachments/assets/faa90c82-a7dd-43db-b2ff-1f6cd24b24cd)

Late game (> 10 min):


![image](https://github.com/user-attachments/assets/863d4d1a-6d5e-4971-a66c-461a876ca53f)

This PR adds another function tailored for this requirement.
## Improvements:
- New `hasNearbyUnit()` function stopping at the first correct unit,
rather than computing the distance with every unit
- Check the unit type before computing its distance
- Selecting the correct cells:
The previous algorithm was very generous and looking at cells uselessly.
Admittedly this is marginal but since it is called on every border pixel
change, we should squeeze the most performances out of it.



![overflow](https://github.com/user-attachments/assets/22b26c49-ba9d-4050-8ccd-9dde48913720)


Performances after (with bots):
Early:

![image](https://github.com/user-attachments/assets/f78d08d4-938c-466b-b8b3-9d1ad57b5dfb)

Late:

![image](https://github.com/user-attachments/assets/c12a8793-4039-4278-9413-07b2af5c8f3d)

Both Chrome and Firefox seems to benefit from it:
Previous behavior on chrome:
![Sans
titre](https://github.com/user-attachments/assets/e10256f7-dcc0-47c7-8878-fa0ce8a02b39)
After:
![Sans
titre-1](https://github.com/user-attachments/assets/15747e02-69fd-45a2-90f8-389250f261cd)


## Please complete the following:

- [x] I have added screenshots for all UI updates
- [x] I confirm I have thoroughly tested these changes and take full
responsibility for any bugs introduced
- [x] I understand that submitting code with bugs that could have been
caught through manual testing blocks releases and new features for all
contributors

## Please put your Discord username so you can be contacted if a bug or
regression is found:

IngloriousTom
2025-05-15 11:25:12 -07:00