@@ -145,7 +145,11 @@ struct StartupParameters start_params;
145145char autostart_multiplayer_campaign[80 ] = " " ;
146146int autostart_multiplayer_level = 0 ;
147147long game_num_fps;
148- long game_num_fps_draw = 0 ;
148+
149+ long game_num_fps_draw_current = 0 ;
150+ long game_num_fps_draw_main = 0 ; // -1 if auto
151+ long game_num_fps_draw_secondary = 0 ;
152+
149153
150154unsigned char *blue_palette;
151155unsigned char *red_palette;
@@ -1122,6 +1126,7 @@ short setup_game(void)
11221126 }
11231127
11241128 game.frame_skip = start_params.frame_skip ;
1129+ redetect_screen_refresh_rate_for_draw ();
11251130
11261131 // Intro problems shouldn't force the game to quit,
11271132 // so we're re-setting the result flag
@@ -3327,10 +3332,10 @@ TbBool keeper_wait_for_next_turn(void)
33273332TbBool keeper_wait_for_next_draw (void )
33283333{
33293334 // fps.draw is currently unable to work properly with frame_skip
3330- if (game_num_fps_draw > 0 && is_feature_on (Ft_DeltaTime) == true && game.frame_skip == 0 )
3335+ if (game_num_fps_draw_current > 0 && is_feature_on (Ft_DeltaTime) == true && game.frame_skip == 0 )
33313336 {
33323337 const long double tick_ns_one_sec = 1000000000.0 ;
3333- const long double tick_ns_one_frame = tick_ns_one_sec/game_num_fps_draw ;
3338+ const long double tick_ns_one_frame = tick_ns_one_sec/game_num_fps_draw_current ;
33343339
33353340 static long double tick_ns_last_draw = 0 ;
33363341 long double tick_ns_cur = get_time_tick_ns ();
@@ -3350,6 +3355,29 @@ TbBool keeper_wait_for_next_draw(void)
33503355 return false ;
33513356}
33523357
3358+ void redetect_screen_refresh_rate_for_draw ()
3359+ {
3360+ game_num_fps_draw_current = 0 ;
3361+
3362+ if (game_num_fps_draw_main == -1 ) {
3363+ if (game_num_fps_draw_secondary > 0 )
3364+ game_num_fps_draw_current = game_num_fps_draw_secondary;
3365+
3366+ if (lbWindow != NULL ) {
3367+ int display_index = SDL_GetWindowDisplayIndex (lbWindow);
3368+ if (display_index >= 0 ) {
3369+ SDL_DisplayMode mode;
3370+ if (SDL_GetCurrentDisplayMode (display_index, &mode) == 0 && mode.refresh_rate > 0 ) {
3371+ game_num_fps_draw_current = mode.refresh_rate ;
3372+ }
3373+ }
3374+ }
3375+
3376+ } else if (game_num_fps_draw_main > 0 ) {
3377+ game_num_fps_draw_current = game_num_fps_draw_main;
3378+ }
3379+ }
3380+
33533381TbBool keeper_wait_for_screen_focus (void )
33543382{
33553383 do {
@@ -3492,7 +3520,7 @@ void gameplay_loop_timestep()
34923520 exit_keeper = 1 ;
34933521 }
34943522
3495- if (game_num_fps_draw > 0 && is_feature_on (Ft_DeltaTime) == true ) {
3523+ if (game_num_fps_draw_current > 0 && is_feature_on (Ft_DeltaTime) == true ) {
34963524 keeper_wait_for_next_draw ();
34973525
34983526 if (game.turns_packetoff == game.play_gameturn ) {
@@ -4058,8 +4086,8 @@ short process_command_line(unsigned short argc, char *argv[])
40584086 if (strcasecmp (parstr, " fps_draw" ) == 0 )
40594087 {
40604088 narg++;
4061- start_params.num_fps_draw = atoi (pr2str);
4062- start_params.overrides [Clo_FramesPerSecond] = true ;
4089+ if ( parse_draw_fps_config_val (pr2str, &start_params. num_fps_draw_main , & start_params.num_fps_draw_secondary ) > 0 )
4090+ start_params.overrides [Clo_FramesPerSecond] = true ;
40634091 } else
40644092 if (strcasecmp (parstr, " human" ) == 0 )
40654093 {
0 commit comments