nr = (int)PRVM_G_FLOAT(OFS_PARM0);
- // FIXME bounds check
- PRVM_G_VECTOR(OFS_RETURN)[0] = video_resolutions[nr].width;
- PRVM_G_VECTOR(OFS_RETURN)[1] = video_resolutions[nr].height;
- PRVM_G_VECTOR(OFS_RETURN)[2] = 0;
+ if(nr < 0 || nr >= video_resolutions_count)
+ {
+ PRVM_G_VECTOR(OFS_RETURN)[0] = 0;
+ PRVM_G_VECTOR(OFS_RETURN)[1] = 0;
+ PRVM_G_VECTOR(OFS_RETURN)[2] = 0;
+ }
+ else
+ {
+ PRVM_G_VECTOR(OFS_RETURN)[0] = video_resolutions[nr].width;
+ PRVM_G_VECTOR(OFS_RETURN)[1] = video_resolutions[nr].height;
+ PRVM_G_VECTOR(OFS_RETURN)[2] = 0;
+ }
}
/*
VID_OpenSystems();
}
-int VID_SortModes_Compare(void *a_, void *b_)
+int VID_SortModes_Compare(const void *a_, const void *b_)
{
vid_mode_t *a = (vid_mode_t *) a_;
vid_mode_t *b = (vid_mode_t *) b_;
{
size_t i;
if(count == 0)
- return;
+ return 0;
// 1. sort them
qsort(modes, count, sizeof(*modes), VID_SortModes_Compare);
// 2. remove duplicates
- for(i = 1; i < count; ++i)
+ for(i = 0; 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)
+ if(modes[i].width && modes[i].height)
+ {
+ if(i == 0)
continue;
- if(usebpp)
- if(modes[i].bpp != modes[i-1].bpp)
+ if(modes[i].width != modes[i-1].width)
continue;
- if(useaspect)
- if(modes[i].pixelheight_num * modes[i-1].pixelheight_denom != modes[i].pixelheight_denom * modes[i-1].pixelheight_num)
+ if(modes[i].height != modes[i-1].height)
continue;
- // a dupe!
+ 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, or a bogus mode!
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