New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve performance of navigational functions #5861
Conversation
local current = 1 | ||
local stack = { sectionOrigin } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of creating new tables for each function call we use a cache that is provided to us by the function parameters.
This is an internal function (note the 'local' keyword). Therefore we have full control over the cache.
-- if neighbor exceeds the distance then we pick the neighbor | ||
local dx = ox - neighbor.Center[1] | ||
local dz = oz - neighbor.Center[3] | ||
if MathSqrt(dx * dx + dz * dz) < distance then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can skip the square root by squaring the distance.
local msg = count --[[@as string]] | ||
return nil, msg | ||
end | ||
|
||
-- only keep those at the edge |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add the possibility for the user to provide a cache to prevent table allocations.
|
||
---@type Vector[] | ||
local points = { } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be cacheable via a parameter too, but we'll keep that for the next pull request 😃
Reduces the table trashing that occurs when retrieving nearby sections. The improvements applies to:
GetPositionsInRadius
DirectionsFrom
DirectionsFromWithThreatThreshold