From: Rudolf Polzer Date: Wed, 2 Oct 2013 04:33:32 +0000 (+0200) Subject: Add sorting logic to resolutions. Fixes a weird loop. X-Git-Tag: xonotic-v0.8.0~310 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=585b1ae9df68a6f530738f37b54aefb48c1d4f51;p=xonotic%2Fxonotic-data.pk3dir.git Add sorting logic to resolutions. Fixes a weird loop. --- diff --git a/qcsrc/menu/xonotic/slider_resolution.c b/qcsrc/menu/xonotic/slider_resolution.c index 998a0010e..e20c0eb9e 100644 --- a/qcsrc/menu/xonotic/slider_resolution.c +++ b/qcsrc/menu/xonotic/slider_resolution.c @@ -74,6 +74,18 @@ entity makeXonoticResolutionSlider() } void XonoticResolutionSlider_addResolution(entity me, float w, float h, float pixelheight) { + float i; + for (i = 0; i < me.nValues; ++i) + { + tokenize_console(me.valueToIdentifier(me, i)); + if (w > stof(argv(0))) continue; + if (w < stof(argv(0))) break; + if (h > stof(argv(1))) continue; + if (h < stof(argv(1))) break; + if (pixelheight > stof(argv(2)) + 0.01) continue; + if (pixelheight < stof(argv(2)) - 0.01) break; + return; // already there + } if (pixelheight != 1) { float aspect = w / (h * pixelheight); @@ -88,10 +100,10 @@ void XonoticResolutionSlider_addResolution(entity me, float w, float h, float pi bestdenom = denom; } } - me.addValue(me, strzone(sprintf(_("%dx%d (%d:%d)"), w, h, bestnum, bestdenom)), strzone(strcat(ftos(w), " ", ftos(h), " ", ftos(pixelheight)))); + me.insertValue(me, i, strzone(sprintf(_("%dx%d (%d:%d)"), w, h, bestnum, bestdenom)), strzone(strcat(ftos(w), " ", ftos(h), " ", ftos(pixelheight)))); } else - me.addValue(me, strzone(sprintf(_("%dx%d"), w, h)), strzone(strcat(ftos(w), " ", ftos(h), " ", ftos(pixelheight)))); + me.insertValue(me, i, strzone(sprintf(_("%dx%d"), w, h)), strzone(strcat(ftos(w), " ", ftos(h), " ", ftos(pixelheight)))); // FIXME (in case you ever want to dynamically instantiate this): THIS IS NEVER FREED } float autocvar_menu_vid_allowdualscreenresolution; @@ -103,38 +115,27 @@ void XonoticResolutionSlider_configureXonoticResolutionSlider(entity me) void XonoticResolutionSlider_loadResolutions(entity me, float fullscreen) { float i; - vector r0, r; + vector r; me.clearValues(me); if (fullscreen) { - r0 = '0 0 0'; for(i = 0;; ++i) { r = getresolution(i); - if(r_x == 0 && r_y == 0) - { - i = -1; - r = getresolution(i); - } if(r_x == 0 && r_y == 0) break; - if(r == r0) - continue; - r0 = r; if(r_x < 640 || r_y < 480) continue; - if(i != -1) - if(r_x > 2 * r_y) // likely dualscreen resolution, skip this one - if(autocvar_menu_vid_allowdualscreenresolution <= 0) - continue; - + if(r_x > 2 * r_y) // likely dualscreen resolution, skip this one + if(autocvar_menu_vid_allowdualscreenresolution <= 0) + continue; me.addResolution(me, r_x, r_y, r_z); - - if (i == -1) - break; } + r = getresolution(-1); + if(r_x != 0 || r_y != 0) + me.addResolution(me, r_x, r_y, r_z); } if(me.nValues == 0)