Codechange: Use vehicle viewport hash to find clicked vehicle. #11675
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation / Problem
Clicking on a vehicle in a viewport needs to find the which vehicle was clicked on. This is done by iterating through all vehicles that exist to find the nearest one.
On a game with a lot of vehicles this can take some time (but only in the order of milliseconds.)
Description
Use the existing vehicle viewport hash instead.
This avoids having to iterate all vehicles, which can be a minor performance improvement when there are many vehicles.
Performance measurements with the old stalwart wentbourne game:
Limitations
The code is more complex as it duplicates the viewport hash loop from
ViewportAddVehicles()
. While that could be abstracted out to allow reuse, it would then be slightly detrimental to viewport drawing performance.This is a fairly unnecessary performance change, as a user cannot click on vehicles fast enough to notice an issue.
Checklist for review
Some things are not automated, and forgotten often. This list is a reminder for the reviewers.