mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-11-21 00:24:57 +01:00
refactor(simulation): tidy the test mode code
The test manager is reached through simulation::test() instead of a global, the result cell is owned by a unique_ptr until the memory table takes it, the cell value is compared with a margin, strings are built with std::format and the --test settings moved to apply_test_mode_settings(). The driver's signal check is folded into UpdateSpeedPosition(), which updates a speed table entry and reports a signal at stop the head of the train just passed. The test.* keys are listed with the other settings at the start of the log.
This commit is contained in:
@@ -768,12 +768,7 @@ void TController::TableCheck(double fDistance)
|
||||
{ // aktualizacja rekordów z wyjątkiem ostatniego
|
||||
if (sSpeedTable[i].iFlags & spEnabled) // jeśli pozycja istotna
|
||||
{
|
||||
auto const waspassed { TestFlag( sSpeedTable[ i ].iFlags, spElapsed ) };
|
||||
auto const switchchanged { sSpeedTable[ i ].Update() };
|
||||
if( false == waspassed ) {
|
||||
CheckSignalPassedAtDanger( sSpeedTable[ i ] );
|
||||
}
|
||||
if (switchchanged)
|
||||
if (UpdateSpeedPosition(sSpeedTable[i]))
|
||||
{
|
||||
if( Global.iWriteLogEnabled & 8 ) {
|
||||
WriteLog( "Speed table for " + OwnerName() + " detected switch change at " + sSpeedTable[ i ].trTrack->name() + " (generating fresh trace)" );
|
||||
@@ -823,11 +818,7 @@ void TController::TableCheck(double fDistance)
|
||||
}
|
||||
}
|
||||
// aktualizacja ostatniego; a signal at stop often is the last, the scan doesn't go past it
|
||||
auto const lastwaspassed { TestFlag( sSpeedTable[ iLast ].iFlags, spElapsed ) };
|
||||
sSpeedTable[iLast].Update();
|
||||
if( false == lastwaspassed ) {
|
||||
CheckSignalPassedAtDanger( sSpeedTable[ iLast ] );
|
||||
}
|
||||
UpdateSpeedPosition(sSpeedTable[iLast]);
|
||||
// WriteLog("TableCheck: Upate last track. Dist=" + AnsiString(sSpeedTable[iLast].fDist));
|
||||
if( sSpeedTable[ iLast ].fDist < fDistance ) {
|
||||
TableTraceRoute( fDistance, pVehicles[ end::rear ] ); // doskanowanie dalszego odcinka
|
||||
@@ -838,18 +829,31 @@ void TController::TableCheck(double fDistance)
|
||||
}
|
||||
};
|
||||
|
||||
void TController::CheckSignalPassedAtDanger( TSpeedPos const &Point ) const
|
||||
namespace {
|
||||
|
||||
// the position is a signal showing stop (SetVelocity 0 0). SetVelocity 0 x on automatic block isn't: it may be passed after a stop
|
||||
bool is_signal_at_stop( TSpeedPos const &Point )
|
||||
{
|
||||
if( false == TestFlag( Point.iFlags, spElapsed )
|
||||
|| false == TestFlag( Point.iFlags, spEvent )
|
||||
|| false == TestFlag( Point.iFlags, spSemaphor )
|
||||
|| true == TestFlag( Point.iFlags, spStopOnSBL ) // SetVelocity 0 x on automatic block: may go on after a stop
|
||||
|| Point.fVelNext != 0.0
|
||||
|| Point.evEvent == nullptr
|
||||
|| ( mvOccupied->CategoryFlag & 1 ) == 0 ) { // railway only
|
||||
return;
|
||||
return TestFlag( Point.iFlags, spEvent )
|
||||
&& TestFlag( Point.iFlags, spSemaphor )
|
||||
&& false == TestFlag( Point.iFlags, spStopOnSBL )
|
||||
&& std::abs( Point.fVelNext ) <= 0.0
|
||||
&& Point.evEvent != nullptr;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
bool TController::UpdateSpeedPosition( TSpeedPos &Point ) const
|
||||
{
|
||||
auto const passedbefore { TestFlag( Point.iFlags, spElapsed ) };
|
||||
auto const switchchanged { Point.Update() };
|
||||
if( false == passedbefore
|
||||
&& TestFlag( Point.iFlags, spElapsed )
|
||||
&& is_signal_at_stop( Point )
|
||||
&& ( mvOccupied->CategoryFlag & 1 ) != 0 ) { // railway only
|
||||
simulation::test().signal_passed_at_danger( OwnerName(), Point.evEvent->m_name );
|
||||
}
|
||||
simulation::Test.signal_passed_at_danger( OwnerName(), Point.evEvent->m_name );
|
||||
return switchchanged;
|
||||
}
|
||||
|
||||
auto const passengerstopmaxdistance { 400.0 }; // maximum allowed distance between passenger stop point and consist head
|
||||
|
||||
@@ -519,8 +519,9 @@ private:
|
||||
bool TableNotFound( basic_event const *Event, double const Distance ) const;
|
||||
void TableTraceRoute( double fDistance, TDynamicObject *pVehicle );
|
||||
void TableCheck( double fDistance );
|
||||
// reports the train going past a signal showing stop (SetVelocity 0 0); called once the head passed Point
|
||||
void CheckSignalPassedAtDanger( TSpeedPos const &Point ) const;
|
||||
// updates a position of the speed table, returns true when a switch on it changed (TSpeedPos::Update).
|
||||
// reports the head of the train going past it, if it's a signal showing stop
|
||||
bool UpdateSpeedPosition( TSpeedPos &Point ) const;
|
||||
TCommandType TableUpdate( double &fVelDes, double &fDist, double &fNext, double &fAcc );
|
||||
bool TableUpdateStopPoint( TCommandType &Command, TSpeedPos &Point, double const Signaldistance );
|
||||
bool TableUpdateEvent( double &Velocity, TCommandType &Command, TSpeedPos &Point, double &Signaldistance, int const Pointindex );
|
||||
|
||||
Reference in New Issue
Block a user