//=============================================================================
/* VIDEO MENU */
-// note: if modes are added to the beginning of this list, update VID_DEFAULT
-video_resolution_t video_resolutions[] =
+static video_resolution_t video_resolutions_hardcoded[] =
{
{"Standard 4x3" , 320, 240, 320, 240, 1 },
{"Standard 4x3" , 400, 300, 400, 300, 1 },
{NULL, 0, 0, 0, 0, 0}
};
// this is the number of the default mode (640x480) in the list above
-#define VID_DEFAULT 3
-#define VID_RES_COUNT ((int)(sizeof(video_resolutions) / sizeof(video_resolutions[0])) - 1)
#define VIDEO_ITEMS 11
static int video_cursor = 0;
static int video_cursor_table[VIDEO_ITEMS] = {68, 88, 96, 104, 112, 120, 128, 136, 144, 152, 168};
static int video_resolution;
+video_resolution_t *video_resolutions;
+int video_resolutions_count;
+
void M_Menu_Video_f (void)
{
int i;
// Look for the closest match to the current resolution
video_resolution = 0;
- for (i = 1;i < VID_RES_COUNT;i++)
+ for (i = 1;i < video_resolutions_count;i++)
{
// if the new mode would be a worse match in width, skip it
if (fabs(video_resolutions[i].width - vid.width) > fabs(video_resolutions[video_resolution].width - vid.width))
{
// Resolution
int r;
- for(r = 0;r < VID_RES_COUNT;r++)
+ for(r = 0;r < video_resolutions_count;r++)
{
video_resolution += dir;
- if (video_resolution >= VID_RES_COUNT)
+ if (video_resolution >= video_resolutions_count)
video_resolution = 0;
if (video_resolution < 0)
- video_resolution = VID_RES_COUNT - 1;
+ video_resolution = video_resolutions_count - 1;
if (video_resolutions[video_resolution].width >= vid_minwidth.integer && video_resolutions[video_resolution].height >= vid_minheight.integer)
break;
}
void M_Init (void)
{
+ vid_mode_t res[1024];
+ size_t res_count, i;
+
+ res_count = VID_ListModes(res, sizeof(res) / sizeof(*res));
+ res_count = VID_SortModes(res, res_count, false, false, true);
+ if(res_count)
+ {
+ video_resolutions_count = res_count;
+ video_resolutions = (video_resolution_t *) Mem_Alloc(cls.permanentmempool, sizeof(*video_resolutions) * (video_resolutions_count + 1));
+ memset(&video_resolutions[video_resolutions_count], 0, sizeof(video_resolutions[video_resolutions_count]));
+ for(i = 0; i < res_count; ++i)
+ {
+ int n, d, t;
+ video_resolutions[i].type = "Detected mode"; // FIXME make this more dynamic
+ video_resolutions[i].width = res[i].width;
+ video_resolutions[i].height = res[i].height;
+ video_resolutions[i].pixelheight = res[i].pixelheight_num / (double) res[i].pixelheight_denom;
+ n = res[i].pixelheight_denom * video_resolutions[i].width;
+ d = res[i].pixelheight_num * video_resolutions[i].height;
+ while(d)
+ {
+ t = n;
+ n = d;
+ d = t % d;
+ }
+ d = (res[i].pixelheight_num * video_resolutions[i].height) / n;
+ n = (res[i].pixelheight_denom * video_resolutions[i].width) / n;
+ switch(n * 0x10000 | d)
+ {
+ case 0x00040003:
+ video_resolutions[i].conwidth = 640;
+ video_resolutions[i].conheight = 480;
+ video_resolutions[i].type = "Standard 4x3";
+ break;
+ case 0x00050004:
+ video_resolutions[i].conwidth = 640;
+ video_resolutions[i].conheight = 512;
+ if(res[i].pixelheight_denom == res[i].pixelheight_num)
+ video_resolutions[i].type = "Square Pixel (LCD) 5x4";
+ else
+ video_resolutions[i].type = "Short Pixel (CRT) 5x4";
+ break;
+ case 0x00080005:
+ video_resolutions[i].conwidth = 640;
+ video_resolutions[i].conheight = 400;
+ if(res[i].pixelheight_denom == res[i].pixelheight_num)
+ video_resolutions[i].type = "Widescreen 8x5";
+ else
+ video_resolutions[i].type = "Tall Pixel (CRT) 8x5";
+
+ break;
+ case 0x00050003:
+ video_resolutions[i].conwidth = 640;
+ video_resolutions[i].conheight = 384;
+ video_resolutions[i].type = "Widescreen 5x3";
+ break;
+ case 0x000D0009:
+ video_resolutions[i].conwidth = 640;
+ video_resolutions[i].conheight = 400;
+ video_resolutions[i].type = "Widescreen 14x9";
+ break;
+ case 0x00100009:
+ video_resolutions[i].conwidth = 640;
+ video_resolutions[i].conheight = 480;
+ video_resolutions[i].type = "Widescreen 16x9";
+ break;
+ case 0x00030002:
+ video_resolutions[i].conwidth = 720;
+ video_resolutions[i].conheight = 480;
+ video_resolutions[i].type = "NTSC 3x2";
+ break;
+ case 0x000D000B:
+ video_resolutions[i].conwidth = 720;
+ video_resolutions[i].conheight = 566;
+ video_resolutions[i].type = "PAL 14x11";
+ break;
+ case 0x00080007:
+ if(video_resolutions[i].width >= 512)
+ {
+ video_resolutions[i].conwidth = 512;
+ video_resolutions[i].conheight = 448;
+ video_resolutions[i].type = "SNES 8x7";
+ }
+ else
+ {
+ video_resolutions[i].conwidth = 256;
+ video_resolutions[i].conheight = 224;
+ video_resolutions[i].type = "NES 8x7";
+ }
+ break;
+ default:
+ video_resolutions[i].conwidth = 640;
+ video_resolutions[i].conheight = 640 * d / n;
+ video_resolutions[i].type = "Detected mode";
+ break;
+ }
+ if(video_resolutions[i].conwidth > video_resolutions[i].width || video_resolutions[i].conheight > video_resolutions[i].height)
+ {
+ double f1, f2;
+ f1 = video_resolutions[i].conwidth > video_resolutions[i].width;
+ f2 = video_resolutions[i].conheight > video_resolutions[i].height;
+ if(f1 > f2)
+ {
+ video_resolutions[i].conwidth = video_resolutions[i].width;
+ video_resolutions[i].conheight = video_resolutions[i].conheight / f1;
+ }
+ else
+ {
+ video_resolutions[i].conwidth = video_resolutions[i].conwidth / f2;
+ video_resolutions[i].conheight = video_resolutions[i].height;
+ }
+ }
+ }
+ }
+
menuplyr_load = true;
menuplyr_pixels = NULL;
VID_OpenSystems();
}
+int VID_SortModes_Compare(void *a_, void *b_)
+{
+ vid_mode_t *a = (vid_mode_t *) a_;
+ vid_mode_t *b = (vid_mode_t *) b_;
+ if(a->width > b->width)
+ return +1;
+ if(a->width < b->width)
+ return -1;
+ if(a->height > b->height)
+ return +1;
+ if(a->height < b->height)
+ return -1;
+ if(a->refreshrate > b->refreshrate)
+ return +1;
+ if(a->refreshrate < b->refreshrate)
+ return -1;
+ if(a->bpp > b->bpp)
+ return +1;
+ if(a->bpp < b->bpp)
+ return -1;
+ if(a->pixelheight_num * b->pixelheight_denom > a->pixelheight_denom * b->pixelheight_num)
+ return +1;
+ if(a->pixelheight_num * b->pixelheight_denom < a->pixelheight_denom * b->pixelheight_num)
+ return -1;
+ return 0;
+}
+size_t VID_SortModes(vid_mode_t *modes, size_t count, qboolean usebpp, qboolean userefreshrate, qboolean useaspect)
+{
+ size_t i;
+ if(count == 0)
+ return;
+ // 1. sort them
+ qsort(modes, count, sizeof(*modes), VID_SortModes_Compare);
+ // 2. remove duplicates
+ for(i = 1; i < count; ++i)
+ {
+ if(modes[i].width != modes[i-1].width)
+ continue;
+ if(modes[i].height != modes[i-1].height)
+ continue;
+ if(userefreshrate)
+ if(modes[i].refreshrate != modes[i-1].refreshrate)
+ continue;
+ if(usebpp)
+ if(modes[i].bpp != modes[i-1].bpp)
+ continue;
+ if(useaspect)
+ if(modes[i].pixelheight_num * modes[i-1].pixelheight_denom != modes[i].pixelheight_denom * modes[i-1].pixelheight_num)
+ continue;
+ // a dupe!
+ if(i < count-1)
+ memmove(&modes[i], &modes[i+1], sizeof(*modes) * (count-1 - i));
+ --i; // check this index again, as mode i+1 is now here
+ --count;
+ }
+ return count;
+}