Repository navigation
pathfinding: compute flow field once per move order, not every frame - #68
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
M_RefreshHeatmapwas called every frame fromunit_changeangle, unconditionally invokingCM_BuildHeatmap. The 4-slot LRU cache insideCM_BuildHeatmaphelped for identical goals, but with >4 concurrent move groups or attack targets it thrashed constantly — causingbake_flow_field+build_heatmapto re-run on every frame and account for ~49% of total CPU time.Changes
common/routing.c— AddedCM_ActivateCachedFlow(DWORD generation): looks up a cached flow field by generation number and setsactive_flowwithout triggering a rebuild. O(N) over 4 slots.common/common.h— DeclaredCM_ActivateCachedFlow.games/warcraft-3/game/g_monster.c—M_RefreshHeatmap: For fixed waypoints (non-SVF_MONSTERgoals), skipCM_BuildHeatmapifroute->heatmap2is already set and the generation is still cached — the full rebuild only happens once per move order. Monster targets (chased enemies) continue to rebuild every frame since their position changes.Waypoint_addalready zeroesheatmap2on allocation, so each new move order triggers exactly one rebuild and all subsequent frames hit the fast path.