diff --git a/vehicle/DynObj.h b/vehicle/DynObj.h index 08f8f7e3e..f22ca687c 100644 --- a/vehicle/DynObj.h +++ b/vehicle/DynObj.h @@ -1157,6 +1157,12 @@ private: // the air exchange through the brake and main reservoir hoses of the vehicles which stepped their physics, after all of them did void update_brake_pipes( double const Deltatime ); + // the vehicle goes into m_brakepipes if its step of the physics left the air of its hoses to exchange + void + collect_brake_pipes( TDynamicObject const *Vehicle ); + // the exchange of update_brake_pipes() for the vehicles in m_brakepipes + void + exchange_brake_pipes( double const Deltatime ); // physics.derailment new: the bodies of the vehicles off the track and those near them run into each other instead // of into one another: the impulses of the hits, the bodies moved apart, a vehicle on the rails pushed off them; // what the bodies overlap by goes to the log every second diff --git a/vehicle/dynamic/vehicletable.cpp b/vehicle/dynamic/vehicletable.cpp index ff9af245e..797b3ef3f 100644 --- a/vehicle/dynamic/vehicletable.cpp +++ b/vehicle/dynamic/vehicletable.cpp @@ -400,14 +400,18 @@ vehicle_table::update( double Deltatime, int Iterationcount ) { { std::size_t index { 0 }; auto mark { counted ? std::chrono::steady_clock::now() : std::chrono::steady_clock::time_point {} }; + // the vehicles whose hoses exchange their air after the loop are taken right after their update, while their memory + // is at hand: only the step of a vehicle itself leaves its hoses to exchange, and nothing else in the loop clears them + m_brakepipes.clear(); for( auto *vehicle : m_items ) { auto const coarsestep { ( index < coarse.size() ) && ( coarse[ index ] != 0 ) }; // Ra 2015-01: tylko tu przelicza sieć trakcyjną vehicle->Update( coarsestep ? totaltime : Deltatime, totaltime ); + collect_brake_pipes( vehicle ); lap( index++, Timer::subsystem.vehicles_update_kind, mark ); } } - update_brake_pipes( Deltatime ); + exchange_brake_pipes( Deltatime ); Timer::subsystem.vehicles_update.stop(); // jeśli jest coś do usunięcia z listy, to trzeba na końcu @@ -636,12 +640,24 @@ void vehicle_table::update_brake_pipes( double const Deltatime ) { m_brakepipes.clear(); - for( auto *vehicle : m_items ) { - if( ( true == vehicle->physics->brakePipe.CouplersPending() ) - || ( true == vehicle->physics->mainPipe.CouplersPending() ) ) { - m_brakepipes.push_back( vehicle->physics ); - } + for( auto const *vehicle : m_items ) { + collect_brake_pipes( vehicle ); } + exchange_brake_pipes( Deltatime ); +} + +void +vehicle_table::collect_brake_pipes( TDynamicObject const *Vehicle ) { + + if( ( true == Vehicle->physics->brakePipe.CouplersPending() ) + || ( true == Vehicle->physics->mainPipe.CouplersPending() ) ) { + m_brakepipes.push_back( Vehicle->physics ); + } +} + +void +vehicle_table::exchange_brake_pipes( double const Deltatime ) { + // the clusters of the trains at once, on the threads of worker_pool: a thread for each MEMBERS_PER_THREAD vehicles // exchanged, up to all the cores. with fewer, waking the threads takes longer than the work, so they go one after another if( false == static_cast( m_hosetrains.run ) ) {