perf: vejnettets søgning før AD's pathFromTo også for markør-til-markør og frem+tilbage — 1.62.287

In-game 17/10 med 286: værste frame 858 ms fra 'rutetjek frem+tilbage'
(AD pathFromTo over 48.158 vejpunkter). graphReachesFrom(start, mål) er
BFS-kernen; hasMarkerRoute og hasRouteBothWays spørger den først, AD kun
ved nej. Vognens ben i hasRouteBothWays bruger computeRoute (noFront-vagt).
This commit is contained in:
2026-10-17 03:50:43 +02:00
parent 73ef5a45ba
commit 35409bf840
3 changed files with 18 additions and 12 deletions
+16 -11
View File
@@ -129,15 +129,10 @@ end
ADWaitPool.GRAPH_SEARCH_LIMIT = 50000
local loggedFallback = {}
local function graphReaches(adEnv, vehicle, targetId)
-- Bredde-først fra et vejpunkt til et andet (ren graf-søgning, ingen AD-opslag).
local function graphReachesFrom(adEnv, startId, targetId)
local graph = adEnv.ADGraphManager
if vehicle.getClosestWayPoint == nil or graph.getWayPointById == nil then
return false
end
local ok, startId = pcall(vehicle.getClosestWayPoint, vehicle)
if not ok or startId == nil then
return false
end
if startId == nil or targetId == nil or graph.getWayPointById == nil then return false end
local seen, queue, head = {[startId] = true}, {startId}, 1
while queue[head] ~= nil and head <= ADWaitPool.GRAPH_SEARCH_LIMIT do
local id = queue[head]
@@ -156,6 +151,13 @@ local function graphReaches(adEnv, vehicle, targetId)
return false
end
local function graphReaches(adEnv, vehicle, targetId)
if vehicle.getClosestWayPoint == nil then return false end
local ok, startId = pcall(vehicle.getClosestWayPoint, vehicle)
if not ok or startId == nil then return false end
return graphReachesFrom(adEnv, startId, targetId)
end
-- 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. 17/10: 30 s var lig ventende vognes 30 s-tjek af andre
@@ -260,7 +262,9 @@ function ADWaitPool.hasMarkerRoute(adEnv, fromWayPointId, toWayPointId)
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)
-- vejnettets egen søgning først (17/10: AD's pathFromTo tog 400-850 ms over 48.000 vejpunkter)
local result = graphReachesFrom(adEnv, fromWayPointId, toWayPointId)
or 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
@@ -306,8 +310,9 @@ function ADWaitPool.hasRouteBothWays(adEnv, vehicle, toWayPointId, homeWayPointI
if cacheFresh(cached, now) then
return cached.result
end
local result = pathReaches(graph:getPathTo(vehicle, toWayPointId), toWayPointId)
and pathReaches(graph:pathFromTo(toWayPointId, homeWayPointId), homeWayPointId)
local result = computeRoute(adEnv, vehicle, toWayPointId)
and (graphReachesFrom(adEnv, toWayPointId, homeWayPointId)
or pathReaches(graph:pathFromTo(toWayPointId, homeWayPointId), homeWayPointId))
if key ~= nil then remember(key, result, now) end
return result
end
+1 -1
View File
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<modDesc descVersion="107">
<author>masterdraco</author>
<version>1.62.286.0</version>
<version>1.62.287.0</version>
<title>
<en>AD Smart Pickup</en>
</title>