From 1626224dc804f576d1300f15ef30211983653f25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kr=C3=B3lik=20Uszasty?= Date: Sun, 12 May 2019 23:38:40 +0200 Subject: [PATCH] departure/arrival time in timetable can be a fraction of minute --- Driver.cpp | 2 +- driveruipanels.cpp | 2 +- mtable.cpp | 24 ++++++++++++------------ mtable.h | 4 ++-- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/Driver.cpp b/Driver.cpp index 82af9898..52a62e7b 100644 --- a/Driver.cpp +++ b/Driver.cpp @@ -1024,7 +1024,7 @@ TCommandType TController::TableUpdate(double &fVelDes, double &fDist, double &fN if (TrainParams->StationIndex < TrainParams->StationCount) { // jeśli są dalsze stacje, czekamy do godziny odjazdu - if (TrainParams->IsTimeToGo(simulation::Time.data().wHour, simulation::Time.data().wMinute)) { + if (TrainParams->IsTimeToGo(simulation::Time.data().wHour, simulation::Time.data().wMinute + simulation::Time.data().wSecond*0.0167 )) { // z dalszą akcją czekamy do godziny odjazdu IsAtPassengerStop = false; // przy jakim dystansie (stanie licznika) ma przesunąć na następny postój diff --git a/driveruipanels.cpp b/driveruipanels.cpp index b278f53f..03d44f38 100644 --- a/driveruipanels.cpp +++ b/driveruipanels.cpp @@ -353,7 +353,7 @@ timetable_panel::update() { ( owner->iStationStart < table->StationIndex ) && ( i < table->StationIndex ) && ( ( tableline->Ah < 0 ) // pass-through, always valid - || ( time.wHour * 60 + time.wMinute >= tableline->Dh * 60 + tableline->Dm ) ) ); + || ( time.wHour * 60 + time.wMinute + time.wSecond * 0.0167 >= tableline->Dh * 60 + tableline->Dm ) ) ); auto traveltime = " " + ( i < 2 ? "" : diff --git a/mtable.cpp b/mtable.cpp index 6aed55d0..3d207cdb 100644 --- a/mtable.cpp +++ b/mtable.cpp @@ -52,7 +52,7 @@ bool TTrainParameters::IsStop() const bool TTrainParameters::UpdateMTable( scenario_time const &Time, std::string const &NewName ) { - return UpdateMTable( Time.data().wHour, Time.data().wMinute, NewName ); + return UpdateMTable( Time.data().wHour, Time.data().wMinute + Time.data().wSecond * 0.0167, NewName ); } bool TTrainParameters::UpdateMTable(double hh, double mm, std::string const &NewName) @@ -358,12 +358,12 @@ bool TTrainParameters::LoadTTfile(std::string scnpath, int iPlus, double vmax) if (s.find(hrsd) != std::string::npos) { record->Ah = atoi( s.substr(0, s.find(hrsd)).c_str()); // godzina przyjazdu - record->Am = atoi(s.substr(s.find(hrsd) + 1, s.length()).c_str()); // minuta przyjazdu + record->Am = atof(s.substr(s.find(hrsd) + 1, s.length()).c_str()); // minuta przyjazdu } else { record->Ah = TimeTable[StationCount - 1].Ah; // godzina z poprzedniej pozycji - record->Am = atoi(s.c_str()); // bo tylko minuty podane + record->Am = atof(s.c_str()); // bo tylko minuty podane } } do @@ -408,12 +408,12 @@ bool TTrainParameters::LoadTTfile(std::string scnpath, int iPlus, double vmax) if (s.find(hrsd) != std::string::npos) { record->Dh = atoi(s.substr(0, s.find(hrsd)).c_str()); // godzina odjazdu - record->Dm = atoi(s.substr(s.find(hrsd) + 1, s.length()).c_str()); // minuta odjazdu + record->Dm = atof(s.substr(s.find(hrsd) + 1, s.length()).c_str()); // minuta odjazdu } else { record->Dh = TimeTable[StationCount - 1].Dh; // godzina z poprzedniej pozycji - record->Dm = atoi(s.c_str()); // bo tylko minuty podane + record->Dm = atof(s.c_str()); // bo tylko minuty podane } } else @@ -475,20 +475,20 @@ bool TTrainParameters::LoadTTfile(std::string scnpath, int iPlus, double vmax) if( timeoffset != 0 ) // jeżeli jest przesunięcie rozkładu { long i_end = StationCount + 1; - int adjustedtime; // do zwiększania czasu + float adjustedtime; // do zwiększania czasu for (auto i = 1; i < i_end; ++i) // bez with, bo ciężko się przenosi na C++ { if ((TimeTable[i].Ah >= 0)) { - adjustedtime = clamp_circular( TimeTable[i].Ah * 60 + TimeTable[i].Am + timeoffset, 24 * 60 ); // nowe minuty - TimeTable[i].Am = adjustedtime % 60; - TimeTable[i].Ah = (adjustedtime / 60) % 24; + adjustedtime = clamp_circular( TimeTable[i].Ah * 60 + TimeTable[i].Am + timeoffset, 24.0 * 60.0 ); // nowe minuty + TimeTable[i].Am = (int(60 * adjustedtime) % 3600) / 60.0; + TimeTable[i].Ah = int((adjustedtime) / 60) % 24; } if ((TimeTable[i].Dh >= 0)) { - adjustedtime = clamp_circular( TimeTable[i].Dh * 60 + TimeTable[i].Dm + timeoffset, 24 * 60 ); // nowe minuty - TimeTable[i].Dm = adjustedtime % 60; - TimeTable[i].Dh = (adjustedtime / 60) % 24; + adjustedtime = clamp_circular( TimeTable[i].Dh * 60 + TimeTable[i].Dm + timeoffset, 24.0 * 60.0 ); // nowe minuty + TimeTable[i].Dm = (int(60 * adjustedtime) % 3600) / 60.0; + TimeTable[i].Dh = int((adjustedtime) / 60) % 24; } } } diff --git a/mtable.h b/mtable.h index 78816aaa..17191ff1 100644 --- a/mtable.h +++ b/mtable.h @@ -32,9 +32,9 @@ struct TMTableLine std::string StationWare; // typ i wyposazenie stacji, oddz. przecinkami} int TrackNo; // ilosc torow szlakowych int Ah; - int Am; // godz. i min. przyjazdu, -1 gdy bez postoju + double Am; // godz. i min. przyjazdu, -1 gdy bez postoju int Dh; - int Dm; // godz. i min. odjazdu + double Dm; // godz. i min. odjazdu double tm; // czas jazdy do tej stacji w min. (z kolumny) TMTableLine() {