Minimap Roads
Renders navgraph road segments on the minimap with spatial culling.
Renders navgraph road segments on the minimap with spatial culling.
Overview
ui_apps_minimap_roads draws navgraph road links as colored line segments on the minimap. It builds a kd-tree spatial index on first call, then queries visible roads each frame for efficient rendering.
Extension path: lua/ge/extensions/ui/apps/minimap/roads.lua
Exports (M)
| Function | Signature | Description |
|---|---|---|
drawRoads | (p, radius, td, debugSettings, camPos, scale, dpi) | Main draw function - builds cache on first call, then renders visible roads. |
reset | () | Clears cached kd-tree and road data (call on map change). |
Internals
First-Call Initialization
On the first call to drawRoads, the module:
- Iterates all
map.getMap().nodesand their links - Skips links with
hiddenInNavi = true - Stores link data in a flat array:
[x1, y1, x2, y2, color]per link - Builds a
kdtreebox2dspatial index with bounding boxes per link - Colors roads by drivability:
≥ 0.9→ main road color> 0.25→ low drivability color≤ 0.25→ lowest drivability color
Per-Frame Rendering
After initialization, each frame:
for lIdx in kdNodes:queryNotNested(camPos.x-radius, camPos.y-radius, camPos.x+radius, camPos.y+radius) do
local s1X, s1Y = worldToMapXY(links[lIdx], links[lIdx+1])
local s2X, s2Y = worldToMapXY(links[lIdx+2], links[lIdx+3])
-- Draw background stroke (dark outline)
td:lineRoundEnd(s1X, s1Y, s2X, s2Y, bgWidth, bgWidth, 0, bgColor, bgColor, 0, 0, 0, layers.ROADS_BG)
-- Draw foreground (colored road)
td:lineRoundEnd(s1X, s1Y, s2X, s2Y, fgWidth, fgWidth, 0, color, color, 0, 0, 0, layers.ROADS_FG)
endRoad Styling
Roads use constant-width rendering (not scaled to road radius):
- Background width:
2 * scaleInverse * dpi + 2 * dpi- dark outline - Foreground width:
2 * scaleInverse * dpi- colored fill
Color sets come from ui_apps_minimap_utils.getStyleColorSet().
Fallback Grid
If no roads exist and grid drawing is disabled, the module calls ui_apps_minimap_utils.drawGrid() as a fallback visual reference.
How It Works
- First
drawRoadscall builds a kd-tree from all navgraph links - Each frame, queries the kd-tree for links within the visible radius
- Draws each visible link as a two-layer line (outline + fill)
reset()clears the cache for map transitions
Additional Exports
The following exports are available but not yet documented in detail:
M.drawRoadsM.reset