@@ -3261,7 +3261,7 @@ short display_should_be_updated_this_turn(void)
32613261 if ( (game.turns_fastforward == 0 ) && (!game.packet_loading_in_progress ) )
32623262 {
32633263 find_frame_rate ();
3264- if ( (game.frame_skip == 0 ) || ((get_gameturn () % game.frame_skip ) == 0 ))
3264+ if ( is_feature_on (Ft_DeltaTime) || (game.frame_skip == 0 ) || ((get_gameturn () % game.frame_skip ) == 0 ))
32653265 return true ;
32663266 } else
32673267 if ( ((get_gameturn () & 0x3F )==0 ) ||
@@ -3421,12 +3421,32 @@ static bool use_delta_time()
34213421 return is_feature_on (Ft_DeltaTime) || network_is_active ();
34223422}
34233423
3424+ static void update_frontend_delta_time ()
3425+ {
3426+ static int64_t prev = 0 ;
3427+ const int64_t now = get_time_tick_ns ();
3428+ const int64_t ns = now - prev;
3429+ prev = now;
3430+ const long double dt = ns / 1e9L * turns_per_second;
3431+ game.delta_time = min (max (dt, 0 .L ), 1 .L );
3432+ }
3433+
34243434static void update_gameplay_delta_time ()
34253435{
34263436 if (use_delta_time ()) {
3427- long double process_delta_time = get_delta_time () * multiplayer_clock_adjust;
3428- time_since_last_draw += process_delta_time;
3429- game.process_turn_time += process_delta_time;
3437+ static int64_t prev = 0 ;
3438+ const int64_t now = get_time_tick_ns ();
3439+ const int64_t ns = now - prev;
3440+ prev = now;
3441+
3442+ const long double dt = min (max (ns / 1e9L * turns_per_second, 0 .L ), 1 .L );
3443+
3444+ game.process_turn_time += dt * multiplayer_clock_adjust * max (game.frame_skip , 1 );
3445+
3446+ // This sets game.delta_time, which is used to pace locally-displayed
3447+ // things (eg. tooltip scroll speed). It should not be affected by
3448+ // multiplayer clock adjustment or frameskip.
3449+ time_since_last_draw += dt;
34303450 } else {
34313451 // Set to 1 so that these variables don't affect anything. (if something is multiplied by 1 it doesn't change)
34323452 time_since_last_draw = 1 ;
@@ -3437,6 +3457,11 @@ static void update_gameplay_delta_time()
34373457
34383458static void gameplay_loop_draw ()
34393459{
3460+ update_gameplay_delta_time ();
3461+
3462+ if (game.process_turn_time > 1.0 && time_since_last_draw < 1.0 )
3463+ do_draw = false ;
3464+
34403465 if (is_feature_on (Ft_DeltaTime) && ! network_is_active ())
34413466 {
34423467 frametime_start_measurement (Frametime_Sleep);
@@ -3546,8 +3571,8 @@ static void gameplay_loop_logic()
35463571 exchange_packets ();
35473572
35483573 update_gameplay_delta_time ();
3549- if (game.process_turn_time > 2.0 )
3550- game.process_turn_time = 2.0 ;
3574+ if (game.process_turn_time > turns_per_second + 1 )
3575+ game.process_turn_time = turns_per_second + 1 ;
35513576
35523577 // Adjust client time scaling
35533578 if (netstate.my_id != SERVER_ID && network_is_active ())
@@ -3619,9 +3644,11 @@ extern "C" void network_yield_waiting_gameplay_packets()
36193644{
36203645 do_draw = true ;
36213646 poll_inputs ();
3647+ gameplay_loop_draw ();
36223648 update_gameplay_delta_time ();
3623- if (game.process_turn_time <= 1.0 || time_since_last_draw > 1.0 )
3624- gameplay_loop_draw ();
3649+ // Reduce game speed during lag spikes.
3650+ if (game.process_turn_time > 2.0 )
3651+ game.process_turn_time = 2.0 ;
36253652}
36263653
36273654extern " C" void update_velocity (void );
@@ -3630,7 +3657,7 @@ extern "C" void fronttorture_update(void);
36303657
36313658extern " C" void network_yield_draw_frontend ()
36323659{
3633- game. delta_time = get_delta_time ();
3660+ update_frontend_delta_time ();
36343661 if (frontend_menu_state == FeSt_NETLAND_VIEW) {
36353662 check_mouse_scroll ();
36363663 update_velocity ();
@@ -3943,7 +3970,7 @@ static TbBool wait_at_frontend(void)
39433970 fade_palette_in = 0 ;
39443971 } else {
39453972 if (is_feature_on (Ft_DeltaTime) == true && should_use_delta_time_on_menu ()) {
3946- game. delta_time = get_delta_time ();
3973+ update_frontend_delta_time ();
39473974 } else {
39483975 int32_t frame_time;
39493976 frame_time = max (1 , 1000 / turns_per_second);
0 commit comments