From 57eeaf1d3a8a0fd090e2ccfc37d05131222ec37c Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Wed, 6 Feb 2008 23:55:33 +0000 Subject: Use geometric distance to find the nearest mode when autoadjusting, rather than number of pixels. Subversion-branch: /trunk/chocolate-doom Subversion-revision: 1057 --- src/i_video.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/i_video.c b/src/i_video.c index 98eb41ac..8e595c62 100644 --- a/src/i_video.c +++ b/src/i_video.c @@ -948,7 +948,7 @@ static void I_AutoAdjustSettings(void) SDL_Rect **modes; SDL_Rect *best_mode; screen_mode_t *screen_mode; - int target_pixels, num_pixels, best_num_pixels; + int target_pixels, diff, best_diff; int i; modes = SDL_ListModes(NULL, SDL_FULLSCREEN); @@ -957,7 +957,7 @@ static void I_AutoAdjustSettings(void) // configuration file best_mode = NULL; - best_num_pixels = INT_MAX; + best_diff = INT_MAX; target_pixels = screen_width * screen_height; for (i=0; modes[i] != NULL; ++i) @@ -988,14 +988,16 @@ static void I_AutoAdjustSettings(void) // Is this mode better than the current mode? - num_pixels = modes[i]->w * modes[i]->h; + diff = (screen_width - modes[i]->w) + * (screen_width - modes[i]->w) + + (screen_height - modes[i]->h) + * (screen_height - modes[i]->h); - if (abs(num_pixels - target_pixels) - < abs(best_num_pixels - target_pixels)) + if (diff < best_diff) { // printf("\tA valid mode\n"); - best_num_pixels = num_pixels; best_mode = modes[i]; + best_diff = diff; } } -- cgit v1.2.3