chore(prototype): try timeToIgnore via debug component exchange
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
58fe0d2986
commit
f9bc0e79fc
1 file changed
+37
-25
@@ -25,32 +25,27 @@ local function turnaround(edge : EdgeId) : integer
|
|||||||
return tn.turnaroundEdges[edge.index + 1]
|
return tn.turnaroundEdges[edge.index + 1]
|
||||||
end
|
end
|
||||||
|
|
||||||
local function modes(m : {TransportMode : boolean}) : string
|
-- EXPERIMENT: does api.cmd.debug.makeComponentExchangeCmd accept a MovePath, and does a positive
|
||||||
local out : {string} = {}
|
-- dyn.timeToIgnore make the follower ignore the vehicle ahead? Hypothesis only; nothing documents either.
|
||||||
for k, v in pairs(m or {}) do
|
local IGNORE_SECONDS = 10.0
|
||||||
if v then table.insert(out, tostring(k)) end
|
local MAX_GAP = 40.0
|
||||||
end
|
|
||||||
return table.concat(out, ",")
|
local record Car
|
||||||
|
v : integer
|
||||||
|
pos : number
|
||||||
|
speed : number
|
||||||
|
dir : boolean
|
||||||
|
mp : Engine.Component.MovePath
|
||||||
end
|
end
|
||||||
|
|
||||||
-- per street segment: BaseEdge lane layout + TransportNetwork lanes (modes, speed, opposite lane)
|
local function tryIgnore(follower : Car, leader : Car)
|
||||||
local function segmentInfo(seg : integer) : string
|
local mp = follower.mp
|
||||||
local be = api.engine.getComponent(seg, api.type.ComponentType.BASE_EDGE) as Engine.Component.BaseEdge
|
mp.dyn.timeToIgnore = IGNORE_SECONDS
|
||||||
local tn = api.engine.getComponent(seg, api.type.ComponentType.TRANSPORT_NETWORK) as Engine.Component.TransportNetwork
|
p(string.format("IGNORE_TEST send veh=%d leader=%d gap=%.1f v=%.2f leaderV=%.2f", follower.v, leader.v, math.abs(leader.pos - follower.pos), follower.speed, leader.speed))
|
||||||
local parts : {string} = {}
|
local cmd = api.cmd.debug.makeComponentExchangeCmd(follower.v, mp as Engine.Component)
|
||||||
if be ~= nil then
|
api.cmd.sendCommand(cmd, function(_data : any, success : boolean)
|
||||||
table.insert(parts, string.format("roadType=%s template=%s laneConfigs=%d", tostring(be.roadType), tostring(be.roadTemplate), #be.laneConfigs))
|
p(string.format("IGNORE_TEST result veh=%d success=%s", follower.v, tostring(success)))
|
||||||
for i, lc in ipairs(be.laneConfigs) do
|
end)
|
||||||
table.insert(parts, string.format(" lc%d fwd=%s off=%.1f w=%.1f modes=[%s]", i, tostring(lc.forward), lc.offset, lc.width, modes(lc.transportModes)))
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if tn ~= nil then
|
|
||||||
table.insert(parts, string.format("tnEdges=%d", #tn.edges))
|
|
||||||
for i, e in ipairs(tn.edges) do
|
|
||||||
table.insert(parts, string.format(" tn%d modes=[%s] speedLimit=%.1f curSpeed=%.1f turnaround=%s", i - 1, modes(e.transportModes), e.speedLimit, e.curSpeed, tostring(tn.turnaroundEdges[i])))
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return table.concat(parts, "\n" .. TAG .. " ")
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local function dump(dt : number)
|
local function dump(dt : number)
|
||||||
@@ -59,6 +54,7 @@ local function dump(dt : number)
|
|||||||
p(string.format("tick=%d dt=%s playerVehicles=%d", ticks, tostring(dt), #vehicles))
|
p(string.format("tick=%d dt=%s playerVehicles=%d", ticks, tostring(dt), #vehicles))
|
||||||
|
|
||||||
local bySegment : {integer : {string}} = {}
|
local bySegment : {integer : {string}} = {}
|
||||||
|
local byLane : {string : {Car}} = {}
|
||||||
for _, v in ipairs(vehicles) do
|
for _, v in ipairs(vehicles) do
|
||||||
local lv = api.engine.getComponent(v, api.type.ComponentType.LAND_VEHICLE) as Engine.Component.LandVehicle
|
local lv = api.engine.getComponent(v, api.type.ComponentType.LAND_VEHICLE) as Engine.Component.LandVehicle
|
||||||
local mp = api.engine.getComponent(v, api.type.ComponentType.MOVE_PATH) as Engine.Component.MovePath
|
local mp = api.engine.getComponent(v, api.type.ComponentType.MOVE_PATH) as Engine.Component.MovePath
|
||||||
@@ -74,6 +70,11 @@ local function dump(dt : number)
|
|||||||
tostring(mp.occupiedBackIndex), tostring(mp.occupiedFrontIndex), lv.dyn.brakingTimer,
|
tostring(mp.occupiedBackIndex), tostring(mp.occupiedFrontIndex), lv.dyn.brakingTimer,
|
||||||
tostring(info and info.availPower), tostring(info and info.traction))
|
tostring(info and info.availPower), tostring(info and info.traction))
|
||||||
p(line)
|
p(line)
|
||||||
|
if edge ~= nil then
|
||||||
|
local key = seg .. ":" .. edge.index
|
||||||
|
byLane[key] = byLane[key] or {}
|
||||||
|
table.insert(byLane[key], { v = v, pos = mp.dyn.pathPos.pos, speed = mp.dyn.speed, dir = dir, mp = mp })
|
||||||
|
end
|
||||||
bySegment[seg] = bySegment[seg] or {}
|
bySegment[seg] = bySegment[seg] or {}
|
||||||
table.insert(bySegment[seg], string.format("%d(lane=%s,dir=%s,v=%.1f,blk=%s)", v, tostring(edge and edge.index), tostring(dir), mp.dyn.speed, tostring(mp.blocked)))
|
table.insert(bySegment[seg], string.format("%d(lane=%s,dir=%s,v=%.1f,blk=%s)", v, tostring(edge and edge.index), tostring(dir), mp.dyn.speed, tostring(mp.blocked)))
|
||||||
end
|
end
|
||||||
@@ -81,7 +82,18 @@ local function dump(dt : number)
|
|||||||
for seg, list in pairs(bySegment) do
|
for seg, list in pairs(bySegment) do
|
||||||
if #list > 1 then
|
if #list > 1 then
|
||||||
p(string.format("SHARED seg=%d: %s", seg, table.concat(list, " ")))
|
p(string.format("SHARED seg=%d: %s", seg, table.concat(list, " ")))
|
||||||
p(" SEGMENT " .. seg .. " " .. segmentInfo(seg))
|
end
|
||||||
|
end
|
||||||
|
for _, cars in pairs(byLane) do
|
||||||
|
for i = 1, #cars do
|
||||||
|
for j = 1, #cars do
|
||||||
|
local a, b = cars[i], cars[j]
|
||||||
|
-- ponytail: assumes pos grows in driving direction when dir=true; the log shows whether that holds
|
||||||
|
local ahead = (a.dir and b.pos > a.pos) or (not a.dir and b.pos < a.pos)
|
||||||
|
if i ~= j and ahead and math.abs(b.pos - a.pos) < MAX_GAP then
|
||||||
|
tryIgnore(a, b)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in new issue
Block a user