perf+fix: rutetjek gemmes 30 s (hak hvert 5. s); kilde der gav lidt hviler 3 min (æg-vognen til samme hønsehus 3x) (v1.27.3.0)
In-game 26/9: hak ca. hvert 5. s efter 1.27.2 = holdende vognes genplanlægning (ADOutbound/ADLoadSwap hvert 5 s) med AD-stifinding + reserve-BFS gennem 13.550 waypoints pr. kandidat. Rutesvar caches pr. mål og 10 m- område i 30 s (max 2000 poster); langsomme rutetjek logges. Æg: 'ingen mere last' markerer nu kilden som hvilende 3 min, så runden roterer mellem hønsehusene.
This commit is contained in:
@@ -124,11 +124,42 @@ local function graphReaches(adEnv, vehicle, targetId)
|
||||
return false
|
||||
end
|
||||
|
||||
function ADWaitPool.hasRouteTo(adEnv, vehicle, wayPointId)
|
||||
local graph = adEnv.ADGraphManager
|
||||
if graph.getPathTo == nil then
|
||||
return true
|
||||
-- Rutesvar gemmes ROUTE_CACHE_MS pr. mål og 10 m-område: holdende vogne spørger hvert 5. s for hver
|
||||
-- kandidat, og AD's stifinding (+ reserve-søgningen) gennem hele vejnettet gav et hak hvert 5. s
|
||||
-- (in-game 26/9). Vejnettet ændrer sig ikke så hurtigt.
|
||||
ADWaitPool.ROUTE_CACHE_MS = 30000
|
||||
ADWaitPool.ROUTE_CELL_M = 10
|
||||
ADWaitPool.SLOW_ROUTE_MS = 3
|
||||
local routeCache = {}
|
||||
local routeCacheSize = 0
|
||||
ADWaitPool.ROUTE_CACHE_MAX = 2000
|
||||
|
||||
local function remember(key, result, at)
|
||||
if routeCache[key] == nil then
|
||||
routeCacheSize = routeCacheSize + 1
|
||||
if routeCacheSize > ADWaitPool.ROUTE_CACHE_MAX then
|
||||
routeCache, routeCacheSize = {}, 1
|
||||
end
|
||||
end
|
||||
routeCache[key] = {result = result, at = at}
|
||||
end
|
||||
|
||||
local function clockMs()
|
||||
local ok, ms = pcall(function() return netGetTime() end)
|
||||
if ok and type(ms) == "number" then return ms end
|
||||
return nil
|
||||
end
|
||||
|
||||
local function routeKey(vehicle, wayPointId)
|
||||
if vehicle.rootNode == nil or getWorldTranslation == nil then return nil end
|
||||
local ok, x, _, z = pcall(getWorldTranslation, vehicle.rootNode)
|
||||
if not ok or x == nil then return nil end
|
||||
local cell = ADWaitPool.ROUTE_CELL_M
|
||||
return string.format("%s:%d:%d", tostring(wayPointId), math.floor(x / cell), math.floor(z / cell))
|
||||
end
|
||||
|
||||
local function computeRoute(adEnv, vehicle, wayPointId)
|
||||
local graph = adEnv.ADGraphManager
|
||||
if pathReaches(graph:getPathTo(vehicle, wayPointId), wayPointId) then
|
||||
return true
|
||||
end
|
||||
@@ -142,13 +173,45 @@ function ADWaitPool.hasRouteTo(adEnv, vehicle, wayPointId)
|
||||
return false
|
||||
end
|
||||
|
||||
function ADWaitPool.hasRouteTo(adEnv, vehicle, wayPointId)
|
||||
local graph = adEnv.ADGraphManager
|
||||
if graph.getPathTo == nil then
|
||||
return true
|
||||
end
|
||||
local now = clockMs()
|
||||
local key = now ~= nil and routeKey(vehicle, wayPointId) or nil
|
||||
local cached = key ~= nil and routeCache[key] or nil
|
||||
if cached ~= nil and now - cached.at < ADWaitPool.ROUTE_CACHE_MS then
|
||||
return cached.result
|
||||
end
|
||||
local result = computeRoute(adEnv, vehicle, wayPointId)
|
||||
if key ~= nil then
|
||||
local spent = (clockMs() or now) - now
|
||||
remember(key, result, now)
|
||||
if spent > ADWaitPool.SLOW_ROUTE_MS and Logging ~= nil and Logging.info ~= nil
|
||||
and (ADWaitPool.lastSlowLog == nil or now - ADWaitPool.lastSlowLog > 60000) then
|
||||
ADWaitPool.lastSlowLog = now
|
||||
Logging.info("ADSmartPickup: rutetjek til markør %s tog %.1f ms (%s) — gemmes nu i %d s", tostring(wayPointId), spent, result and "vej" or "ingen vej", ADWaitPool.ROUTE_CACHE_MS / 1000)
|
||||
end
|
||||
end
|
||||
return result
|
||||
end
|
||||
|
||||
function ADWaitPool.hasRouteBothWays(adEnv, vehicle, toWayPointId, homeWayPointId)
|
||||
local graph = adEnv.ADGraphManager
|
||||
if graph.getPathTo == nil or graph.pathFromTo == nil then
|
||||
return true
|
||||
end
|
||||
return pathReaches(graph:getPathTo(vehicle, toWayPointId), toWayPointId)
|
||||
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
|
||||
if cached ~= nil and now - cached.at < ADWaitPool.ROUTE_CACHE_MS then
|
||||
return cached.result
|
||||
end
|
||||
local result = pathReaches(graph:getPathTo(vehicle, toWayPointId), toWayPointId)
|
||||
and pathReaches(graph:pathFromTo(toWayPointId, homeWayPointId), homeWayPointId)
|
||||
if key ~= nil then remember(key, result, now) end
|
||||
return result
|
||||
end
|
||||
|
||||
-- Står AD midt i en (blokeret) af-/pålæsning, stoppes den pænt først — ellers kører
|
||||
|
||||
Reference in New Issue
Block a user