# HG changeset patch # User smatz # Date 1213645121 0 # Node ID e8b86b70c5f67e28d5b3721045f73337c744646f # Parent f44ff68484af99bfe0a93e854c708614e0485673 (svn r13537) -Fix [FS#2090](r13523): QSortT won't work this way, use Dimension instead of uint16[2] for resolutions diff -r f44ff68484af -r e8b86b70c5f6 src/driver.cpp --- a/src/driver.cpp Mon Jun 16 17:28:15 2008 +0000 +++ b/src/driver.cpp Mon Jun 16 19:38:41 2008 +0000 @@ -14,8 +14,8 @@ VideoDriver *_video_driver; char _ini_videodriver[32]; int _num_resolutions; -uint16 _resolutions[32][2]; -uint16 _cur_resolution[2]; +Dimension _resolutions[32]; +Dimension _cur_resolution; SoundDriver *_sound_driver; char _ini_sounddriver[32]; diff -r f44ff68484af -r e8b86b70c5f6 src/gfx.cpp --- a/src/gfx.cpp Mon Jun 16 17:28:15 2008 +0000 +++ b/src/gfx.cpp Mon Jun 16 19:38:41 2008 +0000 @@ -1313,14 +1313,14 @@ return result; } -static int CDECL compare_res(const uint16 *pa, const uint16 *pb) +static int CDECL compare_res(const Dimension *pa, const Dimension *pb) { - int x = pa[0] - pb[0]; + int x = pa->width - pb->width; if (x != 0) return x; - return pa[1] - pb[1]; + return pa->height - pb->height; } void SortResolutions(int count) { - QSortT((uint16*)_resolutions, count, compare_res); + QSortT(_resolutions, count, &compare_res); } diff -r f44ff68484af -r e8b86b70c5f6 src/gfx_func.h --- a/src/gfx_func.h Mon Jun 16 17:28:15 2008 +0000 +++ b/src/gfx_func.h Mon Jun 16 19:38:41 2008 +0000 @@ -60,8 +60,8 @@ extern int _pal_first_dirty; extern int _pal_count_dirty; extern int _num_resolutions; -extern uint16 _resolutions[32][2]; -extern uint16 _cur_resolution[2]; +extern Dimension _resolutions[32]; +extern Dimension _cur_resolution; extern Colour _cur_palette[256]; void HandleKeypress(uint32 key); diff -r f44ff68484af -r e8b86b70c5f6 src/main_gui.cpp --- a/src/main_gui.cpp Mon Jun 16 17:28:15 2008 +0000 +++ b/src/main_gui.cpp Mon Jun 16 19:38:41 2008 +0000 @@ -446,8 +446,8 @@ */ void GameSizeChanged() { - _cur_resolution[0] = _screen.width; - _cur_resolution[1] = _screen.height; + _cur_resolution.width = _screen.width; + _cur_resolution.height = _screen.height; ScreenSizeChanged(); RelocateAllWindows(_screen.width, _screen.height); MarkWholeScreenDirty(); diff -r f44ff68484af -r e8b86b70c5f6 src/openttd.cpp --- a/src/openttd.cpp Mon Jun 16 17:28:15 2008 +0000 +++ b/src/openttd.cpp Mon Jun 16 19:38:41 2008 +0000 @@ -285,7 +285,7 @@ * @param res variable to store the resolution in. * @param s the string to decompose. */ -static void ParseResolution(int res[2], const char *s) +static void ParseResolution(Dimension *res, const char *s) { const char *t = strchr(s, 'x'); if (t == NULL) { @@ -293,8 +293,8 @@ return; } - res[0] = max(strtoul(s, NULL, 0), 64UL); - res[1] = max(strtoul(t + 1, NULL, 0), 64UL); + res->width = max(strtoul(s, NULL, 0), 64UL); + res->height = max(strtoul(t + 1, NULL, 0), 64UL); } static void InitializeDynamicVariables() @@ -379,7 +379,7 @@ int i; const char *optformat; char musicdriver[32], sounddriver[32], videodriver[32], blitter[32]; - int resolution[2] = {0, 0}; + Dimension resolution = {0, 0}; Year startyear = INVALID_YEAR; uint generation_seed = GENERATE_NEW_SEED; bool save_config = true; @@ -444,7 +444,7 @@ debuglog_conn = mgo.opt; break; #endif /* ENABLE_NETWORK */ - case 'r': ParseResolution(resolution, mgo.opt); break; + case 'r': ParseResolution(&resolution, mgo.opt); break; case 't': startyear = atoi(mgo.opt); break; case 'd': { #if defined(WIN32) @@ -497,14 +497,14 @@ if (!StrEmpty(sounddriver)) ttd_strlcpy(_ini_sounddriver, sounddriver, sizeof(_ini_sounddriver)); if (!StrEmpty(videodriver)) ttd_strlcpy(_ini_videodriver, videodriver, sizeof(_ini_videodriver)); if (!StrEmpty(blitter)) ttd_strlcpy(_ini_blitter, blitter, sizeof(_ini_blitter)); - if (resolution[0] != 0) { _cur_resolution[0] = resolution[0]; _cur_resolution[1] = resolution[1]; } + if (resolution.width != 0) { _cur_resolution = resolution; } if (startyear != INVALID_YEAR) _settings_newgame.game_creation.starting_year = startyear; if (generation_seed != GENERATE_NEW_SEED) _settings_newgame.game_creation.generation_seed = generation_seed; /* The width and height must be at least 1 pixel, this * way all internal drawing routines work correctly. */ - if (_cur_resolution[0] == 0) _cur_resolution[0] = 1; - if (_cur_resolution[1] == 0) _cur_resolution[1] = 1; + if (_cur_resolution.width <= 0) _cur_resolution.width = 1; + if (_cur_resolution.height <= 0) _cur_resolution.height = 1; #if defined(ENABLE_NETWORK) if (dedicated_host) snprintf(_settings_client.network.server_bind_ip, sizeof(_settings_client.network.server_bind_ip), "%s", dedicated_host); diff -r f44ff68484af -r e8b86b70c5f6 src/settings.cpp --- a/src/settings.cpp Mon Jun 16 17:28:15 2008 +0000 +++ b/src/settings.cpp Mon Jun 16 19:38:41 2008 +0000 @@ -1510,7 +1510,7 @@ SDTG_STR("sounddriver", SLE_STRB,C|S,0, _ini_sounddriver, NULL, STR_NULL, NULL), SDTG_STR("blitter", SLE_STRB,C|S,0, _ini_blitter, NULL, STR_NULL, NULL), SDTG_STR("language", SLE_STRB, S, 0, _dynlang.curr_file, NULL, STR_NULL, NULL), - SDTG_LIST("resolution", SLE_UINT16, S, 0, _cur_resolution, "640,480", STR_NULL, NULL), + SDTG_CONDLIST("resolution", SLE_INT, 2, S, 0, _cur_resolution, "640,480", STR_NULL, NULL, 0, SL_MAX_VERSION), // workaround for implicit lengthof() in SDTG_LIST SDTG_STR("screenshot_format",SLE_STRB, S, 0, _screenshot_format_name,NULL, STR_NULL, NULL), SDTG_STR("savegame_format", SLE_STRB, S, 0, _savegame_format, NULL, STR_NULL, NULL), SDTG_BOOL("rightclick_emulate", S, 0, _rightclick_emulate, false, STR_NULL, NULL), diff -r f44ff68484af -r e8b86b70c5f6 src/settings_gui.cpp --- a/src/settings_gui.cpp Mon Jun 16 17:28:15 2008 +0000 +++ b/src/settings_gui.cpp Mon Jun 16 19:38:41 2008 +0000 @@ -93,8 +93,8 @@ int i; for (i = 0; i != _num_resolutions; i++) { - if (_resolutions[i][0] == _screen.width && - _resolutions[i][1] == _screen.height) { + if (_resolutions[i].width == _screen.width && + _resolutions[i].height == _screen.height) { break; } } @@ -302,7 +302,7 @@ break; case GAMEOPT_RESOLUTION_BTN: // Change resolution - if (index < _num_resolutions && ChangeResInGame(_resolutions[index][0], _resolutions[index][1])) { + if (index < _num_resolutions && ChangeResInGame(_resolutions[index].width, _resolutions[index].height)) { this->SetDirty(); } break; diff -r f44ff68484af -r e8b86b70c5f6 src/strings.cpp --- a/src/strings.cpp Mon Jun 16 17:28:15 2008 +0000 +++ b/src/strings.cpp Mon Jun 16 19:38:41 2008 +0000 @@ -1213,7 +1213,7 @@ if (IsInsideMM(ind, (SPECSTR_RESOLUTION_START - 0x70E4), (SPECSTR_RESOLUTION_END - 0x70E4) + 1)) { int i = ind - (SPECSTR_RESOLUTION_START - 0x70E4); buff += snprintf( - buff, last - buff + 1, "%dx%d", _resolutions[i][0], _resolutions[i][1] + buff, last - buff + 1, "%dx%d", _resolutions[i].width, _resolutions[i].height ); return buff; } diff -r f44ff68484af -r e8b86b70c5f6 src/video/cocoa/cocoa_v.mm --- a/src/video/cocoa/cocoa_v.mm Mon Jun 16 17:28:15 2008 +0000 +++ b/src/video/cocoa/cocoa_v.mm Mon Jun 16 19:38:41 2008 +0000 @@ -206,8 +206,8 @@ count = _cocoa_subdriver->ListModes(modes, lengthof(modes)); for (i = 0; i < count; i++) { - _resolutions[i][0] = modes[i].x; - _resolutions[i][1] = modes[i].y; + _resolutions[i].width = modes[i].x; + _resolutions[i].height = modes[i].y; } _num_resolutions = count; @@ -317,8 +317,8 @@ /* Don't create a window or enter fullscreen if we're just going to show a dialog. */ if (_cocoa_video_dialog) return NULL; - width = _cur_resolution[0]; - height = _cur_resolution[1]; + width = _cur_resolution.width; + height = _cur_resolution.height; bpp = BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth(); _cocoa_subdriver = QZ_CreateSubdriver(width, height, bpp, _fullscreen, true); diff -r f44ff68484af -r e8b86b70c5f6 src/video/dedicated_v.cpp --- a/src/video/dedicated_v.cpp Mon Jun 16 17:28:15 2008 +0000 +++ b/src/video/dedicated_v.cpp Mon Jun 16 19:38:41 2008 +0000 @@ -138,10 +138,10 @@ { int bpp = BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth(); if (bpp == 0) _dedicated_video_mem = NULL; - else _dedicated_video_mem = MallocT(_cur_resolution[0] * _cur_resolution[1] * (bpp / 8)); + else _dedicated_video_mem = MallocT(_cur_resolution.width * _cur_resolution.height * (bpp / 8)); - _screen.width = _screen.pitch = _cur_resolution[0]; - _screen.height = _cur_resolution[1]; + _screen.width = _screen.pitch = _cur_resolution.width; + _screen.height = _cur_resolution.height; ScreenSizeChanged(); SetDebugString("net=6"); diff -r f44ff68484af -r e8b86b70c5f6 src/video/null_v.cpp --- a/src/video/null_v.cpp Mon Jun 16 17:28:15 2008 +0000 +++ b/src/video/null_v.cpp Mon Jun 16 19:38:41 2008 +0000 @@ -15,8 +15,8 @@ const char *VideoDriver_Null::Start(const char* const *parm) { this->ticks = GetDriverParamInt(parm, "ticks", 1000); - _screen.width = _screen.pitch = _cur_resolution[0]; - _screen.height = _cur_resolution[1]; + _screen.width = _screen.pitch = _cur_resolution.width; + _screen.height = _cur_resolution.height; ScreenSizeChanged(); /* Do not render, nor blit */ diff -r f44ff68484af -r e8b86b70c5f6 src/video/sdl_v.cpp --- a/src/video/sdl_v.cpp Mon Jun 16 17:28:15 2008 +0000 +++ b/src/video/sdl_v.cpp Mon Jun 16 19:38:41 2008 +0000 @@ -96,7 +96,7 @@ } } -static const uint16 default_resolutions[][2] = { +static const Dimension default_resolutions[] = { { 640, 480}, { 800, 600}, {1024, 768}, @@ -134,12 +134,12 @@ if (w >= 640 && h >= 480) { int j; for (j = 0; j < n; j++) { - if (_resolutions[j][0] == w && _resolutions[j][1] == h) break; + if (_resolutions[j].width == w && _resolutions[j].height == h) break; } if (j == n) { - _resolutions[j][0] = w; - _resolutions[j][1] = h; + _resolutions[j].width = w; + _resolutions[j].height = h; if (++n == lengthof(_resolutions)) break; } } @@ -160,21 +160,21 @@ // is the wanted mode among the available modes? for (i = 0; i != _num_resolutions; i++) { - if (*w == _resolutions[i][0] && *h == _resolutions[i][1]) return; + if (*w == _resolutions[i].width && *h == _resolutions[i].height) return; } // use the closest possible resolution best = 0; - delta = abs((_resolutions[0][0] - *w) * (_resolutions[0][1] - *h)); + delta = abs((_resolutions[0].width - *w) * (_resolutions[0].height - *h)); for (i = 1; i != _num_resolutions; ++i) { - uint newdelta = abs((_resolutions[i][0] - *w) * (_resolutions[i][1] - *h)); + uint newdelta = abs((_resolutions[i].width - *w) * (_resolutions[i].height - *h)); if (newdelta < delta) { best = i; delta = newdelta; } } - *w = _resolutions[best][0]; - *h = _resolutions[best][1]; + *w = _resolutions[best].width; + *h = _resolutions[best].height; } #ifndef ICON_DIR @@ -441,7 +441,7 @@ DEBUG(driver, 1, "SDL: using driver '%s'", buf); GetVideoModes(); - CreateMainSurface(_cur_resolution[0], _cur_resolution[1]); + CreateMainSurface(_cur_resolution.width, _cur_resolution.height); MarkWholeScreenDirty(); SDL_CALL SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); @@ -534,7 +534,7 @@ { _fullscreen = fullscreen; GetVideoModes(); // get the list of available video modes - if (_num_resolutions == 0 || !this->ChangeResolution(_cur_resolution[0], _cur_resolution[1])) { + if (_num_resolutions == 0 || !this->ChangeResolution(_cur_resolution.width, _cur_resolution.height)) { // switching resolution failed, put back full_screen to original status _fullscreen ^= true; return false; diff -r f44ff68484af -r e8b86b70c5f6 src/video/video_driver.hpp --- a/src/video/video_driver.hpp Mon Jun 16 17:28:15 2008 +0000 +++ b/src/video/video_driver.hpp Mon Jun 16 19:38:41 2008 +0000 @@ -6,6 +6,7 @@ #define VIDEO_VIDEO_DRIVER_HPP #include "../driver.h" +#include "../core/geometry_type.hpp" class VideoDriver: public Driver { public: @@ -35,7 +36,7 @@ extern VideoDriver *_video_driver; extern char _ini_videodriver[32]; extern int _num_resolutions; -extern uint16 _resolutions[32][2]; -extern uint16 _cur_resolution[2]; +extern Dimension _resolutions[32]; +extern Dimension _cur_resolution; #endif /* VIDEO_VIDEO_DRIVER_HPP */ diff -r f44ff68484af -r e8b86b70c5f6 src/video/win32_v.cpp --- a/src/video/win32_v.cpp Mon Jun 16 17:28:15 2008 +0000 +++ b/src/video/win32_v.cpp Mon Jun 16 19:38:41 2008 +0000 @@ -36,7 +36,7 @@ bool _window_maximize; uint _display_hz; uint _fullscreen_bpp; -static uint16 _bck_resolution[2]; +static Dimension _bck_resolution; #if !defined(UNICODE) uint _codepage; #endif @@ -371,10 +371,7 @@ return 0; case WM_DESTROY: - if (_window_maximize) { - _cur_resolution[0] = _bck_resolution[0]; - _cur_resolution[1] = _bck_resolution[1]; - } + if (_window_maximize) _cur_resolution = _bck_resolution; return 0; case WM_LBUTTONDOWN: @@ -530,10 +527,7 @@ /* Set maximized flag when we maximize (obviously), but also when we * switched to fullscreen from a maximized state */ _window_maximize = (wParam == SIZE_MAXIMIZED || (_window_maximize && _fullscreen)); - if (_window_maximize) { - _bck_resolution[0] = _cur_resolution[0]; - _bck_resolution[1] = _cur_resolution[1]; - } + if (_window_maximize) _bck_resolution = _cur_resolution; ClientSizeChanged(LOWORD(lParam), HIWORD(lParam)); } return 0; @@ -713,7 +707,7 @@ return true; } -static const uint16 default_resolutions[][2] = { +static const Dimension default_resolutions[] = { { 640, 480 }, { 800, 600 }, { 1024, 768 }, @@ -746,7 +740,7 @@ uint j; for (j = 0; j < n; j++) { - if (_resolutions[j][0] == dm.dmPelsWidth && _resolutions[j][1] == dm.dmPelsHeight) break; + if (_resolutions[j].width == dm.dmPelsWidth && _resolutions[j].height == dm.dmPelsHeight) break; } /* In the previous loop we have checked already existing/added resolutions if @@ -754,8 +748,8 @@ * looped all and found none, add the new one to the list. If we have reached the * maximum amount of resolutions, then quit querying the display */ if (j == n) { - _resolutions[j][0] = dm.dmPelsWidth; - _resolutions[j][1] = dm.dmPelsHeight; + _resolutions[j].width = dm.dmPelsWidth; + _resolutions[j].height = dm.dmPelsHeight; if (++n == lengthof(_resolutions)) break; } } @@ -784,13 +778,13 @@ FindResolutions(); - DEBUG(driver, 2, "Resolution for display: %dx%d", _cur_resolution[0], _cur_resolution[1]); + DEBUG(driver, 2, "Resolution for display: %dx%d", _cur_resolution.width, _cur_resolution.height); // fullscreen uses those - _wnd.width_org = _cur_resolution[0]; - _wnd.height_org = _cur_resolution[1]; + _wnd.width_org = _cur_resolution.width; + _wnd.height_org = _cur_resolution.height; - AllocateDibSection(_cur_resolution[0], _cur_resolution[1]); + AllocateDibSection(_cur_resolution.width, _cur_resolution.height); MakeWindow(_fullscreen); MarkWholeScreenDirty();