(svn r312) -Fix: [926105] ctrl + d bug. Longest outstanding bug has been fixed \o/ 2004-03-30 (Tron)
authordarkvater
Thu, 23 Sep 2004 21:14:20 +0000
changeset 306 c44133836566
parent 305 8bf52ad6a7a4
child 307 d251be6c0d54
(svn r312) -Fix: [926105] ctrl + d bug. Longest outstanding bug has been fixed \o/ 2004-03-30 (Tron)
-Fix: [1030393] some screensizes crashes OTTD. Fix in general bug that only allows resolutions which were multiple of 8 in width and height. Also use closest possible resolution in fullscreen if window size is not a valid resolution (Tron)
gfx.c
sdl.c
settings_gui.c
win32.c
--- a/gfx.c	Thu Sep 23 20:12:51 2004 +0000
+++ b/gfx.c	Thu Sep 23 21:14:20 2004 +0000
@@ -1660,7 +1660,7 @@
 	memcpy_pitch(
 		_cursor_backup,
 		_screen.dst_ptr + _cursor.draw_pos.x + _cursor.draw_pos.y * _screen.pitch,
-		_cursor.draw_size.x, _cursor.draw_size.y, _screen.width, _cursor.draw_size.x);
+		_cursor.draw_size.x, _cursor.draw_size.y, _screen.pitch, _cursor.draw_size.x);
 
 	// Draw cursor on screen
 	_cur_dpi = &_screen;
@@ -1711,8 +1711,8 @@
 {
 	byte *b = _dirty_blocks;
 	int x=0,y=0;
-	int w = (_screen.width + 63) & ~63;
-	int h = _screen.height;
+	const int w = (_screen.width + 63) & ~63;
+	const int h = (_screen.height + 7) & ~7;
 
 	do {
 		if (*b != 0) {
--- a/sdl.c	Thu Sep 23 20:12:51 2004 +0000
+++ b/sdl.c	Thu Sep 23 21:14:20 2004 +0000
@@ -248,9 +248,8 @@
 		for(i = 0; modes[i]; i++) {
 			int w = modes[i]->w;
 			int h = modes[i]->h;
-			if (IS_INT_INSIDE(w, 640, MAX_SCREEN_WIDTH+1) &&
-					IS_INT_INSIDE(h, 480, MAX_SCREEN_HEIGHT+1) &&
-					w%8 == 0 && h%8 == 0) { // disable screen resolutions which are not multiples of 8
+			if (IS_INT_INSIDE(w, 640, MAX_SCREEN_WIDTH + 1) &&
+					IS_INT_INSIDE(h, 480, MAX_SCREEN_HEIGHT + 1)) {
 				int j;
 				for (j = 0; j < n; ++j)
 					if (_resolutions[j][0] == w && _resolutions[j][1] == h)
@@ -270,35 +269,42 @@
 static int GetAvailableVideoMode(int *w, int *h)
 {
 	int i;
-
+	int best;
+	uint delta;
 
 	// all modes available?
 	if (_all_modes)
 		return 1;
 
 	// is the wanted mode among the available modes?
-	for(i = 0; i != _num_resolutions; i++) {
+	for (i = 0; i != _num_resolutions; i++) {
 		if(*w == _resolutions[i][0] && *h == _resolutions[i][1])
 			return 1;
 	}
 
+	// use the closest possible resolution
+	best = 0;
+	delta = abs((_resolutions[0][0] - *w) * (_resolutions[0][1] - *h));
+	for (i = 1; i != _num_resolutions; ++i) {
+		uint newdelta = abs((_resolutions[i][0] - *w) * (_resolutions[i][1] - *h));
+		if (newdelta < delta) {
+			best = i;
+			delta = newdelta;
+		}
+	}
+
 	// use the default mode
-	*w = _resolutions[0][0];
-	*h = _resolutions[0][1];
+	*w = _resolutions[best][0];
+	*h = _resolutions[best][1];
 	return 2;
 }
 
 static bool CreateMainSurface(int w, int h)
 {
 	SDL_Surface *newscreen;
-	bool sizechange;
 
 	GetAvailableVideoMode(&w, &h);
 
-	sizechange = (_screen.width != w || _screen.height != h);
-	_screen.pitch = _screen.width = w;
-	_screen.height = h;
-
 	DEBUG(misc, 0) ("sdl: using mode %dx%d", w, h);
 
 	// DO NOT CHANGE TO HWSURFACE, IT DOES NOT WORK
@@ -306,14 +312,17 @@
 	if(newscreen == NULL)
 		return false;
 
+	_screen.width = newscreen->w;
+	_screen.height = newscreen->h;
+	_screen.pitch = newscreen->pitch;
+
 	_sdl_screen = newscreen;
 	InitPalette();
 
 	SDL_CALL SDL_WM_SetCaption("OpenTTD", "OpenTTD");
 	SDL_CALL SDL_ShowCursor(0);
 
-//	if(sizechange)
-		GameSizeChanged();
+	GameSizeChanged();
 
 	return true;
 }
@@ -491,8 +500,8 @@
 			w = ev.resize.w;
 			h = ev.resize.h;
 
-			w = clamp(w & ~0x7, 64, MAX_SCREEN_WIDTH);
-			h = clamp(h & ~0x7, 64, MAX_SCREEN_HEIGHT);
+			w = clamp(w, 64, MAX_SCREEN_WIDTH);
+			h = clamp(h, 64, MAX_SCREEN_HEIGHT);
 
 			ChangeResInGame(w, h);
 
--- a/settings_gui.c	Thu Sep 23 20:12:51 2004 +0000
+++ b/settings_gui.c	Thu Sep 23 21:14:20 2004 +0000
@@ -53,8 +53,9 @@
 static int GetCurRes()
 {
 	int i;
-	for(i=0; i!=_num_resolutions; i++)
-		if (_resolutions[i][0] == _cur_resolution[0] && _resolutions[i][1] == _cur_resolution[1])
+	for(i = 0; i != _num_resolutions; i++)
+		if (_resolutions[i][0] == _screen.width &&
+				_resolutions[i][1] == _screen.height)
 			break;
 	return i;
 }
--- a/win32.c	Thu Sep 23 20:12:51 2004 +0000
+++ b/win32.c	Thu Sep 23 21:14:20 2004 +0000
@@ -340,8 +340,8 @@
 		w = r->right - r->left - (r2.right - r2.left);
 		h = r->bottom - r->top - (r2.bottom - r2.top);
 		if (_wnd.double_size) { w >>= 1; h >>= 1; }
-		w = clamp(w & ~0x7, 64, MAX_SCREEN_WIDTH);
-		h = clamp(h & ~0x7, 64, MAX_SCREEN_HEIGHT);
+		w = clamp(w, 64, MAX_SCREEN_WIDTH);
+		h = clamp(h, 64, MAX_SCREEN_HEIGHT);
 		if (_wnd.double_size) { w <<= 1; h <<= 1; }
 		SetRect(&r2, 0, 0, w, h);
 
@@ -506,13 +506,14 @@
 	BITMAPINFO *bi;
 	HDC dc;
 
-	w = clamp(w & ~7, 64, MAX_SCREEN_WIDTH);
-	h = clamp(h & ~7, 64, MAX_SCREEN_HEIGHT);
+	w = clamp(w, 64, MAX_SCREEN_WIDTH);
+	h = clamp(h, 64, MAX_SCREEN_HEIGHT);
 
 	if (w == _screen.width && h == _screen.height)
 		return false;
 
-	_screen.width = _screen.pitch = w;
+	_screen.width = w;
+	_screen.pitch = (w + 3) & ~0x3;
 	_screen.height = h;
 
 	if (_wnd.alloced_bits) {
@@ -524,16 +525,15 @@
 	memset(bi, 0, sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD)*256);
 	bi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
 
-	{
-		if (_wnd.double_size) {
-			_wnd.alloced_bits = _wnd.buffer_bits = (byte*)malloc(w * h);
-			w *= 2;
-			h *= 2;
-		}
+	if (_wnd.double_size) {
+		w = (w + 3) & ~0x3;
+		_wnd.alloced_bits = _wnd.buffer_bits = (byte*)malloc(w * h);
+		w *= 2;
+		h *= 2;
+	}
 
-		bi->bmiHeader.biWidth = _wnd.width = w;
-		bi->bmiHeader.biHeight = -(_wnd.height = h);
-	}
+	bi->bmiHeader.biWidth = _wnd.width = w;
+	bi->bmiHeader.biHeight = -(_wnd.height = h);
 
 	bi->bmiHeader.biPlanes = 1;
 	bi->bmiHeader.biBitCount = 8;