updateDrivabilities
Definition
-- @/lua/ge/map.lua:3547
local function updateDrivabilities(changeSet)
-- Dynamically Change edge Drivability for the Navgraph
-- changeSet format {nodeA1, nodeB1, drivability1, nodeA2, nodeB2, drivability2, ...}
if #changeSet % 3 ~= 0 then return end
local hasChanged = false
local graph = gp.graph
for i = 1, #changeSet, 3 do
if graph[changeSet[i]] then
local edge = graph[changeSet[i]][changeSet[i+1]]
local newDrivability = max(1e-30, changeSet[i+2])
if edge and edge.drivability ~= newDrivability then
edge.len = max(0, (edge.len - edge.gated) * edge.drivability / newDrivability + edge.gated)
edge.drivability = newDrivability
hasChanged = true
end
end
end
if hasChanged then -- send data if there is at least one change
be:sendToMailbox("updateDrivabilities", lpack.encodeBinWorkBuffer(changeSet)) -- mailbox is cleared when map is loaded
for objId, _ in pairs(M.objects) do
be:queueObjectLua(objId, "mapmgr.updateDrivabilities()")
end
end
end
Callers
@/lua/vehicle/mapmgr.lua
local function updateDrivabilities()
-- Dynamically Change edge Drivability for the Navgraph
mapData:import(_map.graphData)
updateDrivabilities()
M.mapData = mapData
@/lua/ge/map.lua
for objId, _ in pairs(M.objects) do
be:queueObjectLua(objId, "mapmgr.updateDrivabilities()")
end