More tracy wrappers for path/LZB-related functions

This commit is contained in:
Y. Wang 2024-09-16 00:43:27 +02:00
parent b5d2c23b32
commit c7ff2958a6
No known key found for this signature in database
GPG Key ID: 39EC2419DF97489A
5 changed files with 18 additions and 1 deletions

View File

@ -308,6 +308,7 @@ function advtrains.get_adjacent_rail(this_posnr, this_conns_p, conn_idx, drives_
return nil
end
tracy.ZoneBeginN("advtrains.get_adjacent_rail")
local conn = this_conns[conn_idx]
local conn_y = conn.y or 0
local adj_pos = advtrains.dirCoordSet(this_pos, conn.c);
@ -323,10 +324,12 @@ function advtrains.get_adjacent_rail(this_posnr, this_conns_p, conn_idx, drives_
conn_y = conn_y + 1
nextnode_ok, nextconns, nextrail_y=advtrains.get_rail_info_at(adj_pos, drives_on)
if not nextnode_ok then
tracy.ZoneEnd()
return nil
end
end
local adj_connid = advtrains.conn_matches_to({c=conn.c, y=conn_y}, nextconns)
tracy.ZoneEnd()
if adj_connid then
return adj_pos, adj_connid, conn_idx, nextrail_y, nextconns
end

View File

@ -241,6 +241,7 @@ end
-- If you DON'T modify lzbdata, you MUST pass nil as lzbdata. Always modify the lzbdata table in place, never overwrite it!
-- udata: user-defined data, do not use externally
function advtrains.lzb_add_checkpoint(train, index, speed, callback, lzbdata, udata)
tracy.ZoneBeginN("advtrains.lzb_add_checkpoint")
local lzb = train.lzb
local pos = advtrains.path_get(train, index)
local lzbdata_c = nil
@ -260,6 +261,7 @@ function advtrains.lzb_add_checkpoint(train, index, speed, callback, lzbdata, ud
table.insert(lzb.checkpoints, ckp)
apply_checkpoint_to_path(train, ckp)
tracy.ZoneEnd()
end

View File

@ -269,17 +269,23 @@ end
--nil if the node is neither loaded nor in trackdb
--the distraction between false and nil will be needed only in special cases.(train initpos)
function advtrains.get_rail_info_at(pos, drives_on)
tracy.ZoneBegin("advtrains.get_rail_info_at")
local rdp=advtrains.round_vector_floor_y(pos)
local node=ndb.get_node_or_nil(rdp)
if not node then return end
if not node then
tracy.ZoneEnd()
return
end
local nodename=node.name
if(not advtrains.is_track_and_drives_on(nodename, drives_on)) then
tracy.ZoneEnd()
return false
end
local conns, railheight, tracktype=advtrains.get_track_connections(node.name, node.param2)
tracy.ZoneEnd()
return true, conns, railheight
end

View File

@ -206,6 +206,7 @@ function advtrains.path_get(train, index)
local pef = train.path_ext_f
-- generate forward (front of train, positive)
while index > pef do
tracy.ZoneBeginN("advtrains.path_get:forward")
local pos = train.path[pef]
local connid = train.path_cn[pef]
local node_ok, this_conns, adj_pos, adj_connid, conn_idx, nextrail_y, next_conns
@ -238,6 +239,7 @@ function advtrains.path_get(train, index)
end
train.path[pef] = adj_pos
train.path_dist[pef] = train.path_dist[pef-1] + vector.distance(pos, adj_pos)
tracy.ZoneEnd()
end
train.path_ext_f = pef
@ -245,6 +247,7 @@ function advtrains.path_get(train, index)
local peb = train.path_ext_b
-- generate backward (back of train, negative)
while index < peb do
tracy.ZoneBeginN("advtrains.path_get:backward")
local pos = train.path[peb]
local connid = train.path_cp[peb]
local node_ok, this_conns, adj_pos, adj_connid, conn_idx, nextrail_y, next_conns
@ -277,6 +280,7 @@ function advtrains.path_get(train, index)
end
train.path[peb] = adj_pos
train.path_dist[peb] = train.path_dist[peb+1] - vector.distance(pos, adj_pos)
tracy.ZoneEnd()
end
train.path_ext_b = peb

View File

@ -858,9 +858,11 @@ local function mknodecallback(name)
end
end
return callt, function(pos, id, train, index, paramx1, paramx2, paramx3)
tracy.ZoneBegin("advtrains.run_callbacks_" .. name .. "node")
for _,f in ipairs(callt) do
f(pos, id, train, index, paramx1, paramx2, paramx3)
end
tracy.ZoneEnd()
end
end