Implement a function to compare lengths within a percent error to avoid overkill. #6960
Labels
No Label
Closed
Duplicate
Closed
Fixed
Closed
Invalid
Closed
Needs info
Closed
Won't fix
Closed
Works for me
Difficulty
Hard
Difficulty
Medium
Difficulty
Simple
Needed for Beta
Needs Design Input
Needs Info
Pathfinding
Priority
1: Release Blocker
Priority
2: Must Have
Priority
3: Should Have
Priority
4: Nice To Have
Priority
5: If Time Permits
Regression
Theme
AI
Theme
Art & Animation
Theme
Atlas editor
Theme
Build & Packages
Theme
Core engine
Theme
Internationalization & Localization
Theme
Maps
Theme
Multiplayer Lobby
Theme
Music & Sound FX
Theme
Network
Theme
Non-game systems
Theme
Simulation
Theme
UI & Simulation
Theme
UI – Game setup
Theme
UI – In-game
Theme
UI – Miscellaneous
Theme
Website & Forum
Type
Defect
Type
Enhancement
Type
Task
No Milestone
No project
No Assignees
3 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: 0ad/0ad#6960
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "real_tabasco_sauce/0ad:RoughSort"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
This patch implements a new comparison function to allow sorting by distance within a percent error. Each unit gets a "RangeError" value which is read in UnitAI.js and passed on when range queries are set up. The Range Error is the percent error used in CompareLengthRough(). If RangeError is undefined or set to 0, the normal sorting procedure is undertaken.
Why:
Without player input, units attack the nearest unit with huge precision. This is fine for other games where smaller armies are involved, but with the large armies and battles in 0ad, it becomes problematic: If many units attack the same unit, much damage is wasted. For example, if more than 3 crossbows (2 for a26 vanilla) hit a ranged unit, each additional hit is wasted. For melee units, this high precision means that melee units will all try to attack the first unit until they try a new range query. A video of this problem is posted here: https://wildfiregames.com/forum/topic/118677-less-precise-sorting-in-range-manager/?do=findComment&comment=578105
With less precision when sorting enemies by distance:
Battles appear more realistic/cool.
Ranged units are less likely to overkill enemies. This should decrease the need to manually distribute damage across units when the units would be expected to attack multiple units.
Melee units take different targets and path better since they don't first have to try and attack the absolute closest unit.
The template value allows the precision to be tailored as needed on a per-unit basis, for instance, crossbowmen likely need a higher P value. For the time being, I have initialized every unit to have a RangeError of 2.
On performance:
https://wildfiregames.com/forum/topic/118677-less-precise-sorting-in-range-manager/page/3/
Phabricator is still accessible for those who have an account, and it would be nice to keep track of what's been taken out of the review pile there.
So don't hesitate to
Thanks!
I'm putting phosit and Stan as reviewers since they had started looking at this diff, but it seems the review was a bit stalled. Don't hesitate to ask me to take a look and decide, preferably after next week when everything gitea-related is settled.
Sure, feel free to take a look when you have time!
c404c6d775
tof87d449d45
735a1386e6
to1425e0bc44
Any more thoughts here? @stan I'm not sure how well calling the entityDistanceOrdering in UnitAI.js would work, since I would need to avoid sorting by distance twice. So IMO, it makes sense to do the 'if (P)' in entityDistanceOrdering. Would it be much faster? I thought passing an additional parameter is in general pretty cheap.
I suppose I could also make an equivalent entityDistanceOrderingRough, which would remove the need to pass P to entityDistanceOrdering and move the if (P) check to the respective stable_sort calls within CCmpRangeManager.cpp. This would decrease the number of times we need to do if (P), but add some somewhat redundant code.
Also, I could post some more videos to the forum discussion to show the improvements to gameplay.
@Itms thoughts on the patch? I did the above and it was a disaster for performance: https://wildfiregames.com/forum/topic/118677-less-precise-sorting-in-range-manager/?do=findComment&comment=581903
1425e0bc44
toa0cca97d6f
293a038fdf
toa225cc1360
@Itms could you take a look? I suppose if there are still concerns about performance, I could just enable it for crossbows. Although an inconsistency in unit behavior like that isn't ideal.
Maybe @freagarach, could you give your thoughts on this PR?
Hi @real_tabasco_sauce ! I'm unfortunately stomped by post-migration work on the CI, but I would like this to either move forward or be plainly refused, so that you can work on other things 🙂
So from this quick look, I am in favor of getting this merged. If @phosit is strongly against, I'll let him refuse the patch, as he reviewed it in previous iterations, but if he's undecided, I'm voting for an inclusion.
For a very superficial code review,
P
as a variable name. It's fine in formulae in code comments, but bad for code readability. Use a spelled-out single word.I let someone else (if possible, @phosit or @Stan) go through the final review steps and help you squash and format your commit message.
Thanks for your work!
Great! Thanks so much!
I would think range_error could be good, but I could go with variability too. For the assertion, should I just assert for the distances not being too large for performance purposes? In other words, is it necessary to actually check that the value would overflow?
Use the
Check...Overflow
convenience functions used elsewhere in the file.Regarding the function parameter, use camelCase so rangeError instead of range_error.
Usually such a value is called epsilon i think but rangeError is nicer.
a225cc1360
to493825fb93
493825fb93
tod99f659200
d99f659200
to4fea7fe143
4fea7fe143
toadec225455
Ok, how does that look now?
Looks alright :) You can also link the forum thread in the commit message if you wish to.
I think its evolved enough that its better described in this PR anyway.
adec225455
toe90e1b119a
e90e1b119a
toec1db2a104
ec1db2a104
tofef84e145d
fef84e145d
toa4b7822715
a4b7822715
toaebb699ac7
aebb699ac7
to8c2f94a6f6
@Stan I added the forum link
Checkout
From your project repository, check out a new branch and test the changes.