mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-06 14:27:16 +00:00
(svn r13537) -Fix [FS#2090](r13523): QSortT won't work this way, use Dimension instead of uint16[2] for resolutions
This commit is contained in:
parent
0c342f3292
commit
2299181c4b
@ -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];
|
||||
|
@ -1313,14 +1313,14 @@ bool ToggleFullScreen(bool fs)
|
||||
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);
|
||||
}
|
||||
|
@ -60,8 +60,8 @@ extern bool _screen_disable_anim; ///< Disable palette animation (important fo
|
||||
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);
|
||||
|
@ -446,8 +446,8 @@ void ShowVitalWindows()
|
||||
*/
|
||||
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();
|
||||
|
@ -285,7 +285,7 @@ md_continue_here:;
|
||||
* @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 @@ static void ParseResolution(int res[2], const char *s)
|
||||
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 ttd_main(int argc, char *argv[])
|
||||
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 @@ int ttd_main(int argc, char *argv[])
|
||||
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 @@ int ttd_main(int argc, char *argv[])
|
||||
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);
|
||||
|
@ -1510,7 +1510,7 @@ static const SettingDescGlobVarList _misc_settings[] = {
|
||||
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),
|
||||
|
@ -93,8 +93,8 @@ static int GetCurRes()
|
||||
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 @@ struct GameOptionsWindow : Window {
|
||||
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;
|
||||
|
@ -1213,7 +1213,7 @@ static char *GetSpecialPlayerNameString(char *buff, int ind, const int64 *argv,
|
||||
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;
|
||||
}
|
||||
|
@ -206,8 +206,8 @@ static void QZ_UpdateVideoModes()
|
||||
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 @@ const char *VideoDriver_Cocoa::Start(const char * const *parm)
|
||||
/* 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);
|
||||
|
@ -138,10 +138,10 @@ const char *VideoDriver_Dedicated::Start(const char * const *parm)
|
||||
{
|
||||
int bpp = BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth();
|
||||
if (bpp == 0) _dedicated_video_mem = NULL;
|
||||
else _dedicated_video_mem = MallocT<byte>(_cur_resolution[0] * _cur_resolution[1] * (bpp / 8));
|
||||
else _dedicated_video_mem = MallocT<byte>(_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");
|
||||
|
@ -15,8 +15,8 @@ static FVideoDriver_Null iFVideoDriver_Null;
|
||||
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 */
|
||||
|
@ -96,7 +96,7 @@ static void DrawSurfaceToScreen()
|
||||
}
|
||||
}
|
||||
|
||||
static const uint16 default_resolutions[][2] = {
|
||||
static const Dimension default_resolutions[] = {
|
||||
{ 640, 480},
|
||||
{ 800, 600},
|
||||
{1024, 768},
|
||||
@ -134,12 +134,12 @@ static void GetVideoModes()
|
||||
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 @@ static void GetAvailableVideoMode(int *w, int *h)
|
||||
|
||||
// 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 @@ const char *VideoDriver_SDL::Start(const char * const *parm)
|
||||
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 @@ bool VideoDriver_SDL::ToggleFullscreen(bool fullscreen)
|
||||
{
|
||||
_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;
|
||||
|
@ -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 @@ public:
|
||||
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 */
|
||||
|
@ -36,7 +36,7 @@ bool _force_full_redraw;
|
||||
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 @@ static LRESULT CALLBACK WndProcGdi(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lP
|
||||
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 @@ static LRESULT CALLBACK WndProcGdi(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lP
|
||||
/* 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 @@ static bool AllocateDibSection(int w, int h)
|
||||
return true;
|
||||
}
|
||||
|
||||
static const uint16 default_resolutions[][2] = {
|
||||
static const Dimension default_resolutions[] = {
|
||||
{ 640, 480 },
|
||||
{ 800, 600 },
|
||||
{ 1024, 768 },
|
||||
@ -746,7 +740,7 @@ static void FindResolutions()
|
||||
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 @@ static void FindResolutions()
|
||||
* 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 @@ const char *VideoDriver_Win32::Start(const char * const *parm)
|
||||
|
||||
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();
|
||||
|
Loading…
Reference in New Issue
Block a user