18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-12-03 06:35:21 +01:00

perf(physics): the vehicles whose hoses exchange air taken in the update loop, not in a loop after it

update_brake_pipes() went through all the vehicles once more after the update loop to find the ones whose step left
the air of their hoses to exchange, looking at two flags of each, and the memory of each vehicle was gone from the
cache by then: 1.3 % of the main thread on Tomaszewo. The final update loop now takes each vehicle right after its
Update(), while its memory is at hand (collect_brake_pipes()), and the exchange goes on as before
(exchange_brake_pipes()). The flags are set only by the step of the vehicle itself and cleared only by the exchange,
so the vehicles taken and their order are the same. The other callers still look at all the vehicles.
This commit is contained in:
jerrrrycho
2026-12-02 07:53:39 +01:00
parent 0e3503a0ba
commit e625fa4a24
2 changed files with 28 additions and 6 deletions
+6
View File
@@ -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
+22 -6
View File
@@ -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<bool>( m_hosetrains.run ) ) {