perf: rutetjek frem+tilbage går markør->markør og gemmes 5 min (var 30-39 ms pr. kald, genberegnet hver 10 m); bygningsliste 30 s — hak på 44-67 ms (v1.33.4.0)
This commit is contained in:
@@ -219,11 +219,39 @@ function ADWaitPool.hasRouteTo(adEnv, vehicle, wayPointId)
|
||||
return result
|
||||
end
|
||||
|
||||
-- Rute mellem to markører: afhænger ikke af vognens position, så svaret gemmes længe (5 min). Profiler
|
||||
-- 26/9: "rutetjek frem+tilbage" tog 30-39 ms pr. kald og blev regnet igen hver gang vognen havde flyttet sig
|
||||
-- 10 m — det gav hak på 44-67 ms hvert minut.
|
||||
ADWaitPool.MARKER_ROUTE_MS = 300000
|
||||
local markerRoutes = {}
|
||||
function ADWaitPool.hasMarkerRoute(adEnv, fromWayPointId, toWayPointId)
|
||||
local graph = adEnv.ADGraphManager
|
||||
if graph.pathFromTo == nil then return true end
|
||||
local key = tostring(fromWayPointId) .. ">" .. tostring(toWayPointId)
|
||||
local now = clockMs()
|
||||
local cached = markerRoutes[key]
|
||||
if cached ~= nil and now ~= nil and now - cached.at < ADWaitPool.MARKER_ROUTE_MS then
|
||||
return cached.result
|
||||
end
|
||||
local result = pathReaches(graph:pathFromTo(fromWayPointId, toWayPointId), toWayPointId)
|
||||
if now ~= nil then markerRoutes[key] = {result = result, at = now + math.random() * ADWaitPool.MARKER_ROUTE_MS * 0.5} end
|
||||
return result
|
||||
end
|
||||
|
||||
function ADWaitPool.resetMarkerRoutes()
|
||||
markerRoutes = {}
|
||||
end
|
||||
|
||||
function ADWaitPool.hasRouteBothWays(adEnv, vehicle, toWayPointId, homeWayPointId)
|
||||
local graph = adEnv.ADGraphManager
|
||||
if graph.getPathTo == nil or graph.pathFromTo == nil then
|
||||
return true
|
||||
end
|
||||
-- kendt hjem (kilden): vognen kører hjem -> mål -> hjem; markør til markør, gemt længe
|
||||
if homeWayPointId ~= nil then
|
||||
return ADWaitPool.hasMarkerRoute(adEnv, homeWayPointId, toWayPointId)
|
||||
and ADWaitPool.hasMarkerRoute(adEnv, toWayPointId, homeWayPointId)
|
||||
end
|
||||
local now = clockMs()
|
||||
local key = now ~= nil and routeKey(vehicle, tostring(toWayPointId) .. ">" .. tostring(homeWayPointId)) or nil
|
||||
local cached = key ~= nil and routeCache[key] or nil
|
||||
|
||||
Reference in New Issue
Block a user