From 4d33c389881ebdf0b3926343d53e7d1ece654e20 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sat, 24 Apr 2010 18:04:08 +0000 Subject: [PATCH] Fix a compile error Handle a null train properly in TrainProperties constructor Print emergencies to stdout Report sensor number in unreserved sensor triggers Never update real_speed[0] Return a nonzero value if no speeds are recorded yet --- source/engineer/trainproperties.cpp | 5 ++++- source/libmarklin/layout.cpp | 4 +++- source/libmarklin/train.cpp | 16 ++++++++++++---- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/source/engineer/trainproperties.cpp b/source/engineer/trainproperties.cpp index 748b0c9..4596000 100644 --- a/source/engineer/trainproperties.cpp +++ b/source/engineer/trainproperties.cpp @@ -57,15 +57,18 @@ TrainProperties::TrainProperties(Engineer &e, const GLtk::Resources &r, Train *t drp_priority->append("Unspecified"); drp_priority->append("Standard passenger"); drp_priority->append("Express passenger"); - drp_priority->set_selected_index(train->get_priority()+2); if(train) { ent_addr->set_text(lexical_cast(train->get_address())); ent_name->set_text(train->get_name()); + drp_priority->set_selected_index(train->get_priority()+2); } else + { ent_name->set_text(format("Train %d", engineer.get_layout().get_trains().size()+1)); + drp_priority->set_selected_index(2); + } } void TrainProperties::on_ok_clicked() diff --git a/source/libmarklin/layout.cpp b/source/libmarklin/layout.cpp index e67fbc2..9729741 100644 --- a/source/libmarklin/layout.cpp +++ b/source/libmarklin/layout.cpp @@ -9,6 +9,7 @@ Distributed under the GPL #include #include #include +#include #include #include "block.h" #include "catalogue.h" @@ -216,6 +217,7 @@ void Layout::emergency(const string &msg) { if(driver) driver->halt(true); + IO::print("Emergency: %s\n", msg); signal_emergency.emit(msg); } @@ -370,7 +372,7 @@ void Layout::sensor_event(unsigned addr, bool state) if((*i)->get_sensor_id()==addr) { if(!(*i)->get_train()) - emergency("Unreserved sensor triggered"); + emergency(format("Unreserved sensor %d triggered", addr)); break; } } diff --git a/source/libmarklin/train.cpp b/source/libmarklin/train.cpp index 9f97c33..efe1a14 100644 --- a/source/libmarklin/train.cpp +++ b/source/libmarklin/train.cpp @@ -523,8 +523,11 @@ void Train::sensor_event(unsigned addr, bool state) if(pure_speed) { - RealSpeed &rs = real_speed[current_speed]; - rs.add(travel_dist/travel_time_secs, travel_time_secs); + if(current_speed) + { + RealSpeed &rs = real_speed[current_speed]; + rs.add(travel_dist/travel_time_secs, travel_time_secs); + } set_status(format("Traveling %d kmh", get_travel_speed())); } @@ -630,7 +633,7 @@ void Train::block_reserved(const Block &block, const Train *train) unsigned Train::reserve_more() { if(!active) - return; + return 0; BlockRef *last = 0; if(!rsv_blocks.empty()) @@ -834,7 +837,12 @@ unsigned Train::find_speed(float real) const if(!high) { if(!low) - return 0; + { + if(real) + return 3; + else + return 0; + } return min(static_cast(low*real/real_speed[low].speed), 14U); } -- 2.45.2