From 9176ffb7ebba92f6b4ebb5717e5cb7626c2957dd Mon Sep 17 00:00:00 2001 From: SurFlurer <22912139+SurFlurer@users.noreply.github.com> Date: Thu, 29 Jun 2023 03:14:40 +0000 Subject: [PATCH] Move emitter processing to idle() (#66504) Co-authored-by: irwiss --- src/vehicle.cpp | 48 ++++++++++++++++++++---------------------------- 1 file changed, 20 insertions(+), 28 deletions(-) diff --git a/src/vehicle.cpp b/src/vehicle.cpp index f6cf1ef75faa0..68229e5eb098c 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -5366,6 +5366,26 @@ void vehicle::idle( bool on_map ) update_time( calendar::turn ); } + map &here = get_map(); + // Parts emitting fields + const std::pair exhaust_and_muffle = get_exhaust_part(); + for( const int emitter_idx : emitters ) { + const vehicle_part &pt = parts[emitter_idx]; + if( pt.is_unavailable() || !pt.enabled ) { + continue; + } + for( const emit_id &e : pt.info().emissions ) { + here.emit_field( global_part_pos3( pt ), e ); + } + for( const emit_id &e : pt.info().exhaust ) { + if( exhaust_and_muffle.first == -1 ) { + here.emit_field( global_part_pos3( pt ), e ); + } else { + here.emit_field( exhaust_dest( exhaust_and_muffle.first ), e ); + } + } + } + if( has_part( "STEREO", true ) ) { play_music(); } @@ -7511,34 +7531,6 @@ void vehicle::update_time( const time_point &update_to ) } map &here = get_map(); - // Parts emitting fields - const std::pair exhaust_and_muffle = get_exhaust_part(); - for( const int emitter_idx : emitters ) { - const vehicle_part &pt = parts[emitter_idx]; - if( pt.is_unavailable() || !pt.enabled ) { - continue; - } - for( const emit_id &e : pt.info().emissions ) { - here.emit_field( global_part_pos3( pt ), e ); - } - for( const emit_id &e : pt.info().exhaust ) { - if( exhaust_and_muffle.first == -1 ) { - here.emit_field( global_part_pos3( pt ), e ); - } else { - here.emit_field( exhaust_dest( exhaust_and_muffle.first ), e ); - } - } - // reduce interval of parts with VPFLAG_ENABLED_DRAINS_EPOWER, otherwise their epower - // get charged twice - once by power_parts in vehicle::idle and once here - const time_duration interval = pt.info().has_flag( VPFLAG_ENABLED_DRAINS_EPOWER ) - ? update_to - last_update - 1_seconds - : update_to - last_update; - if( interval < 0_seconds ) { - debugmsg( "emitter simulating negative time interval, something is fishy / buggy" ); - break; - } - discharge_battery( power_to_energy_bat( -pt.info().epower, interval ) ); - } if( sm_pos.z < 0 ) { last_update = update_to;