diff options
| -rw-r--r-- | advtrains/atc.lua | 13 | ||||
| -rw-r--r-- | advtrains/depends.txt | 3 | ||||
| -rw-r--r-- | advtrains/helpers.lua | 4 | ||||
| -rw-r--r-- | advtrains/init.lua | 11 | ||||
| -rw-r--r-- | advtrains/lzb.lua | 9 | ||||
| -rw-r--r-- | advtrains/nodedb.lua | 2 | ||||
| -rw-r--r-- | advtrains/path.lua | 9 | ||||
| -rw-r--r-- | advtrains/trainlogic.lua | 23 | ||||
| -rw-r--r-- | advtrains/wagons.lua | 10 | ||||
| -rw-r--r-- | advtrains_interlocking/depends.txt | 3 | ||||
| -rw-r--r-- | advtrains_interlocking/init.lua | 10 | ||||
| -rw-r--r-- | advtrains_interlocking/routesetting.lua | 7 | ||||
| -rw-r--r-- | advtrains_interlocking/train_sections.lua | 4 | ||||
| -rw-r--r-- | advtrains_line_automation/depends.txt | 3 | ||||
| -rw-r--r-- | advtrains_line_automation/init.lua | 10 | ||||
| -rw-r--r-- | advtrains_line_automation/scheduler.lua | 7 | ||||
| -rw-r--r-- | advtrains_luaautomation/active_common.lua | 3 | ||||
| -rw-r--r-- | advtrains_luaautomation/depends.txt | 3 | ||||
| -rw-r--r-- | advtrains_luaautomation/environment.lua | 5 | ||||
| -rw-r--r-- | advtrains_luaautomation/init.lua | 16 | ||||
| -rw-r--r-- | advtrains_luaautomation/interrupt.lua | 4 |
21 files changed, 145 insertions, 14 deletions
diff --git a/advtrains/atc.lua b/advtrains/atc.lua index fa9f097..32f8ffe 100644 --- a/advtrains/atc.lua +++ b/advtrains/atc.lua @@ -298,22 +298,29 @@ eval_conditional = function(command, arrow, speed) end function atc.execute_atc_command(id, train) + advtrains.profiler:enter("atc_execute") + --strip whitespaces local command=string.match(train.atc_command, "^%s*(.*)$") if string.match(command, "^%s*$") then train.atc_command=nil + advtrains.profiler:leave("atc_execute") return end train.atc_command = eval_conditional(command, train.atc_arrow, train.velocity) - if not train.atc_command then return end + if not train.atc_command then + advtrains.profiler:leave("atc_execute") + return + end command=string.match(train.atc_command, "^%s*(.*)$") if string.match(command, "^%s*$") then train.atc_command=nil + advtrains.profiler:leave("atc_execute") return end @@ -322,9 +329,8 @@ function atc.execute_atc_command(id, train) if match then local patlen=func(id, train, match) - atprint("Executing: "..string.sub(command, 1, patlen)) - train.atc_command=string.sub(command, patlen+1) + advtrains.profiler:leave("atc_execute") if train.atc_delay<=0 and not train.atc_wait_finish then --continue (recursive, cmds shouldn't get too long, and it's a end-recursion.) atc.execute_atc_command(id, train) @@ -332,6 +338,7 @@ function atc.execute_atc_command(id, train) return end end + advtrains.profiler:leave("atc_execute") atwarn(sid(id), attrans("ATC command parse error: Unknown command: @1", command)) atc.train_reset_command(train, true) end diff --git a/advtrains/depends.txt b/advtrains/depends.txt index 1815e54..99e1c47 100644 --- a/advtrains/depends.txt +++ b/advtrains/depends.txt @@ -1,3 +1,4 @@ default mesecons? -digtron?
\ No newline at end of file +digtron? +advprofiler?
\ No newline at end of file diff --git a/advtrains/helpers.lua b/advtrains/helpers.lua index e04991e..2b24ff7 100644 --- a/advtrains/helpers.lua +++ b/advtrains/helpers.lua @@ -307,6 +307,8 @@ function advtrains.get_adjacent_rail(this_posnr, this_conns_p, conn_idx, drives_ return nil
end
+ advtrains.profiler:enter("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);
@@ -322,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
+ advtrains.profiler:leave("get_adjacent_rail")
return nil
end
end
local adj_connid = advtrains.conn_matches_to({c=conn.c, y=conn_y}, nextconns)
+ advtrains.profiler:leave("get_adjacent_rail")
if adj_connid then
return adj_pos, adj_connid, conn_idx, nextrail_y, nextconns
end
diff --git a/advtrains/init.lua b/advtrains/init.lua index c5604fd..0111b9c 100644 --- a/advtrains/init.lua +++ b/advtrains/init.lua @@ -19,6 +19,17 @@ AT_CMAX = 16 advtrains = {trains={}, player_to_train_mapping={}} +-- Profiler boilerplate +if advprofiler then + advtrains.profiler = advprofiler.new_profiler("advtrains") +else + advtrains.profiler = { + count=function() end, + enter=function() end, + leave=function() end, + } +end + --pcall local no_action=false diff --git a/advtrains/lzb.lua b/advtrains/lzb.lua index 6cbf4ab..660efa8 100644 --- a/advtrains/lzb.lua +++ b/advtrains/lzb.lua @@ -47,6 +47,7 @@ end local function look_ahead(id, train) + advtrains.profiler:enter("lzb_look_ahead") local acc = advtrains.get_acceleration(train, 1) local vel = train.velocity @@ -80,6 +81,8 @@ local function look_ahead(id, train) lzb.trav = trav + advtrains.profiler:leave("lzb_look_ahead") + end --[[ @@ -91,6 +94,8 @@ s = v0 * ------- + - * | ------- | = ----------- ]] local function apply_control(id, train) + advtrains.profiler:enter("lzb_apply_control") + local lzb = train.lzb local i = 1 @@ -129,6 +134,7 @@ local function apply_control(id, train) -- Gotcha! Braking... train.ctrl.lzb = 1 --train.debug = train.debug .. "BRAKE!!!" + advtrains.profiler:leave("lzb_apply_control") return end @@ -136,17 +142,20 @@ local function apply_control(id, train) if i <= train.index and v0>1 then -- roll control train.ctrl.lzb = 2 + advtrains.profiler:leave("lzb_apply_control") return end i = advtrains.path_get_index_by_offset(train, i, -params.ZONE_HOLD) if i <= train.index and v0>1 then -- hold speed train.ctrl.lzb = 3 + advtrains.profiler:leave("lzb_apply_control") return end end end train.ctrl.lzb = nil + advtrains.profiler:leave("lzb_apply_control") end local function invalidate(train) diff --git a/advtrains/nodedb.lua b/advtrains/nodedb.lua index 37dc3f7..e3f5022 100644 --- a/advtrains/nodedb.lua +++ b/advtrains/nodedb.lua @@ -123,6 +123,7 @@ function ndb.get_node(pos) return n end function ndb.get_node_raw(pos) + advtrains.profiler:count("ndb_get_node") local cid=ndbget(pos.x, pos.y, pos.z) if cid then local nodeid = ndb_nodeids[u14b(cid)] @@ -135,6 +136,7 @@ end function ndb.swap_node(pos, node, no_inval) + advtrains.profiler:count("ndb_swap_node") if minetest.get_node_or_nil(pos) then minetest.swap_node(pos, node) end diff --git a/advtrains/path.lua b/advtrains/path.lua index 825e59b..1e224e4 100644 --- a/advtrains/path.lua +++ b/advtrains/path.lua @@ -156,6 +156,9 @@ function advtrains.path_get(train, index) if index ~= atfloor(index) then error("For train "..train.id..": Called path_get() but index="..index.." is not a round number") end + + advtrains.profiler:enter("path_get") + local pef = train.path_ext_f while index > pef do local pos = train.path[pef] @@ -224,6 +227,8 @@ function advtrains.path_get(train, index) train.path_req_f = index end + advtrains.profiler:leave("path_get") + return train.path[index], (index<=train.path_trk_f and index>=train.path_trk_b) end @@ -257,6 +262,8 @@ function advtrains.path_get_adjacent(train, index) end function advtrains.path_get_index_by_offset(train, index, offset) + advtrains.profiler:enter("path_get_index_by_offset") + local off = offset local idx = atfloor(index) -- go down to floor. Calculate required path_dist @@ -286,6 +293,8 @@ function advtrains.path_get_index_by_offset(train, index, offset) -- we should now be on the floor of the index we actually want. -- give them the rest! + advtrains.profiler:leave("path_get_index_by_offset") + return idx + (off / train.path_dist[idx]) end diff --git a/advtrains/trainlogic.lua b/advtrains/trainlogic.lua index bc24feb..75a1e2e 100644 --- a/advtrains/trainlogic.lua +++ b/advtrains/trainlogic.lua @@ -77,7 +77,8 @@ advtrains.mainloop_trainlogic=function(dtime) to occupation tables (b) 5. make trains do other stuff (c) ]]-- - local t=os.clock() + + advtrains.profiler:enter("train_steps") for k,v in pairs(advtrains.trains) do advtrains.atprint_context_tid=k @@ -96,12 +97,12 @@ advtrains.mainloop_trainlogic=function(dtime) advtrains.train_step_c(k, v, dtime) end + advtrains.profiler:leave("train_steps") + advtrains.lock_path_inval = false advtrains.atprint_context_tid=nil - atprintbm("trainsteps", t) - endstep() end function advtrains.tp_player_to_train(player) @@ -239,6 +240,8 @@ function advtrains.train_ensure_init(id, train) return nil end + advtrains.profiler:enter("train_ensure_init") + train.dirty = true if train.no_step then return ni
m_materials[0] = mat;
m_materials[1] = mat;
//m_materials[1].MaterialType = video::EMT_TRANSPARENT_VERTEX_ALPHA;
m_materials[1].MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
m_materials[2] = mat;
m_materials[2].setTexture(0, mgr->getVideoDriver()->getTexture(
getTexturePath("sunrisebg.png").c_str()));
m_materials[2].MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
//m_materials[2].MaterialType = video::EMT_TRANSPARENT_ADD_COLOR;
for(u32 i=0; i<SKY_STAR_COUNT; i++){
m_stars[i] = v3f(
myrand_range(-10000,10000),
myrand_range(-10000,10000),
myrand_range(-10000,10000)
);
m_stars[i].normalize();
}
m_directional_colored_fog = g_settings->getBool("directional_colored_fog");
}
void Sky::OnRegisterSceneNode()
{
if (IsVisible)
SceneManager->registerNodeForRendering(this, scene::ESNRP_SKY_BOX);
scene::ISceneNode::OnRegisterSceneNode();
}
const core::aabbox3d<f32>& Sky::getBoundingBox() const
{
return Box;
}
//! renders the node.
void Sky::render()
{
if(!m_visible +
local pos = self.object:getpos()
local data = advtrains.wagons[self.id]
if not pos then
--atdebug("["..self.id.."][fatal] missing position (object:getpos() returned nil)")
+ advtrains.profiler:leave("wagon_step")
return
end
@@ -375,9 +377,11 @@ function wagon:on_step(dtime) if not train.path or train.no_step then
self.object:setvelocity({x=0, y=0, z=0})
self.object:setacceleration({x=0, y=0, z=0})
+ advtrains.profiler:leave("wagon_step")
return
end
if not data.pos_in_train then
+ advtrains.profiler:leave("wagon_step")
return
end
@@ -538,7 +542,9 @@ function wagon:on_step(dtime) self.old_velocity = train.velocity
self.old_acceleration_vector=accelerationvec
self.old_yaw=yaw
- atprintbm("wagon step", t)
+
+ advtrains.profiler:leave("wagon_step")
+
end)
end
diff --git a/advtrains_interlocking/depends.txt b/advtrains_interlocking/depends.txt index 6f00bf6..960989c 100644 --- a/advtrains_interlocking/depends.txt +++ b/advtrains_interlocking/depends.txt @@ -1 +1,2 @@ -advtrains
\ No newline at end of file +advtrains +advprofiler?
\ No newline at end of file diff --git a/advtrains_interlocking/init.lua b/advtrains_interlocking/init.lua index a2f5882..0cdea8e 100644 --- a/advtrains_interlocking/init.lua +++ b/advtrains_interlocking/init.lua @@ -9,6 +9,16 @@ function advtrains.interlocking.sigd_equal(sigd, cmp) return vector.equals(sigd.p, cmp.p) and sigd.s==cmp.s end +-- Profiler boilerplate +if advprofiler then + advtrains.interlocking.profiler = advprofiler.new_profiler("advtrains_interlocking") +else + advtrains.interlocking.profiler = { + count=function() end, + enter=function() end, + leave=function() end, + } +end local modpath = minetest.get_modpath(minetest.get_current_modname()) .. DIR_DELIM diff --git a/advtrains_interlocking/routesetting.lua b/advtrains_interlocking/routesetting.lua index 7c4d14c..7b52902 100644 --- a/advtrains_interlocking/routesetting.lua +++ b/advtrains_interlocking/routesetting.lua @@ -224,6 +224,7 @@ end -- note that this does not clear the routesetting status from the entry signal, -- only from the ts's function ilrs.cancel_route_from(sigd) + advtrains.interlocking.profiler:enter("cancel_route_from") -- we start at the tc designated by signal local c_sigd = sigd local c_tcbs, c_ts_id, c_ts, c_rseg, c_lckp @@ -232,6 +233,7 @@ function ilrs.cancel_route_from(sigd) c_tcbs = ildb.get_tcbs(c_sigd) if not c_tcbs then atwarn("Failed to cancel route, no TCBS at",c_sigd) + advtrains.interlocking.profiler:leave("cancel_route_from") return false end @@ -248,6 +250,7 @@ function ilrs.cancel_route_from(sigd) c_ts_id = c_tcbs.ts_id if not c_tcbs then atwarn("Failed to cancel route, end of in
video::SColorf mooncolor_f(0.50, 0.57, 0.65, 1);
video::SColorf mooncolor2_f(0.85, 0.875, 0.9, 1);
float nightlength = 0.415;
float wn = nightlength / 2;
float wicked_time_of_day = 0;
if(m_time_of_day > wn && m_time_of_day < 1.0 - wn)
wicked_time_of_day = (m_time_of_day - wn)/(1.0-wn*2)*0.5 + 0.25;
else if(m_time_of_day < 0.5)
wicked_time_of_day = m_time_of_day / wn * 0.25;
else
wicked_time_of_day = 1.0 - ((1.0-m_time_of_day) / wn * 0.25);
/*std::cerr<<"time_of_day="<<m_time_of_day<<" -> "
<<"wicked_time_of_day="<<wicked_time_of_day<<std::endl;*/
video::SColor suncolor = suncolor_f.toSColor();
video::SColor suncolor2 = suncolor2_f.toSColor();
video::SColor mooncolor = mooncolor_f.toSColor();
video::SColor mooncolor2 = mooncolor2_f.toSColor();
const f32 t = 1.0f;
const f32 o = 0.0f;
static const u16 indices[4] = {0,1,2,3};
video::S3DVertex vertices[4];
driver->setMaterial(m_materials[1]);
//video::SColor cloudyfogcolor(255,255,255,255);
video::SColor cloudyfogcolor = m_bgcolor;
//video::SColor cloudyfogcolor = m_bgcolor.getInterpolated(m_skycolor, 0.5);
// Draw far cloudy fog thing
for(u32 j=0; j<4; j++)
{
video::SColor c = cloudyfogcolor.getInterpolated(m_skycolor, 0.45);
vertices[0] = video::S3DVertex(-1, 0.08,-1, 0,0,1, c, t, t);
vertices[1] = video::S3DVertex( 1, 0.08,-1, 0,0,1, c, o, t);
vertices[2] = video::S3DVertex( 1, 0.12,-1, 0,0,1, c, o, o);
vertices[3] = video::S3DVertex(-1, 0.12,-1, 0,0,1, c, t, o);
for(u32 i=0; i<4; i++){
if(j==0)
// Don't switch
{}
else if(j==1)
// Switch from -Z (south) to +X (east)
vertices[i].Pos.rotateXZBy(90);
else if(j==2)
// Switch from -Z (south) to -X (west)
vertices[i].Pos.rotateXZBy(-90);
else
// Switch from -Z (south) to -Z (north)
vertices[i].Pos.rotateXZBy(-180);
}
driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
}
for(u32 j=0; j<4; j++)
{
video::SColor c = cloudyfogcolor;
vertices[0] = video::S3DVertex(-1,-1.0,-1, 0,0,1, c, t, t);
vertices[1] = video::S3DVertex( 1,-1.0,-1, 0,0,1, c, o, t);
vertices[2] = video::S3DVertex( 1, 0.08,-1, 0,0,1, c, o, o);
vertices[3] = video::S3DVertex(-1, 0.08,-1, 0,0,1, c, t, o);
for(u32 i=0; i<4; i++){
if(j==0)
// Don't switch
{}
else if(j==1)
// Switch from -Z (south) to +X (east)
vertices[i].Pos.rotateXZBy(90);
else if(j==2)
// Switch from -Z (south) to -X (west)
vertices[i].Pos.rotateXZBy(-90);
else
// Switch from -Z (south) to -Z (north)
vertices[i].Pos.rotateXZBy(-180);
}
driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
}
driver->setMaterial(m_materials[2]);
{
float mid1 = 0.25;
float mid = (wicked_time_of_day < 0.5 ? mid1 : (1.0 - mid1));
float a_ = 1.0 - fabs(wicked_time_of_day - mid) * 35.0;
float a = easeCurve(MYMAX(0, MYMIN(1, a_)));
//std::cerr<<"a_="<<a_<<" a="<<a<<std::endl;
video::SColor c(255,255, |
