ref: 57eeaf1d3a8a0fd090e2ccfc37d05131222ec37c
parent: 631baaaa1a91181ed96030ad4d965133228df535
author: Simon Howard <[email protected]>
date: Wed Feb 6 18:55:33 EST 2008
Use geometric distance to find the nearest mode when autoadjusting, rather than number of pixels. Subversion-branch: /trunk/chocolate-doom Subversion-revision: 1057
--- a/src/i_video.c
+++ b/src/i_video.c
@@ -948,7 +948,7 @@
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 @@
// 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 @@
// 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;
}
}