summaryrefslogtreecommitdiff
path: root/src/video
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2008-11-29 01:28:13 +0000
committerrubidium <rubidium@openttd.org>2008-11-29 01:28:13 +0000
commit913f51b2fbbe80d4dffa2589bc61f86455cae5ad (patch)
tree50c93473ffa440ee0ecb2d4c25e96d27c3fed7e4 /src/video
parentbacd1d185d093d45c866bf538ac5ea9ae200d5ac (diff)
downloadopenttd-913f51b2fbbe80d4dffa2589bc61f86455cae5ad.tar.xz
(svn r14641) -Change [Allegro]: when making a debug build revert Allegro's hooks on SIGSEGV/SIGABRT so one can actually use gdb.
-Change: make it more clear that Allegro's failing to find a driver.
Diffstat (limited to 'src/video')
-rw-r--r--src/video/allegro_v.cpp49
-rw-r--r--src/video/sdl_v.cpp6
2 files changed, 41 insertions, 14 deletions
diff --git a/src/video/allegro_v.cpp b/src/video/allegro_v.cpp
index 36581bcaa..455c991d2 100644
--- a/src/video/allegro_v.cpp
+++ b/src/video/allegro_v.cpp
@@ -20,6 +20,12 @@
#include "allegro_v.h"
#include <allegro.h>
+#ifdef _DEBUG
+/* Allegro replaces SEGV/ABRT signals meaning that the debugger will never
+ * be triggered, so rereplace the signals and make the debugger userful. */
+#include <signal.h>
+#endif
+
static FVideoDriver_Allegro iFVideoDriver_Allegro;
static BITMAP *_allegro_screen;
@@ -154,6 +160,9 @@ static void GetVideoModes()
static void GetAvailableVideoMode(int *w, int *h)
{
+ /* No video modes, so just try it and see where it ends */
+ if (_num_resolutions == 0) return;
+
/* is the wanted mode among the available modes? */
for (int i = 0; i != _num_resolutions; i++) {
if (*w == _resolutions[i].width && *h == _resolutions[i].height) return;
@@ -179,21 +188,23 @@ static bool CreateMainSurface(int w, int h)
if (bpp == 0) usererror("Can't use a blitter that blits 0 bpp for normal visuals");
set_color_depth(bpp);
-#if defined(DOS)
- /* Force DOS builds to ALWAYS use full screen as
- * it can't do windowed. */
- _fullscreen = true;
-#endif
-
- GetVideoModes();
GetAvailableVideoMode(&w, &h);
- if (set_gfx_mode(_fullscreen ? GFX_AUTODETECT_FULLSCREEN : GFX_AUTODETECT_WINDOWED, w, h, 0, 0) != 0) return false;
+ if (set_gfx_mode(_fullscreen ? GFX_AUTODETECT_FULLSCREEN : GFX_AUTODETECT_WINDOWED, w, h, 0, 0) != 0) {
+ DEBUG(driver, 0, "Allegro: Couldn't allocate a window to draw on");
+ return false;
+ }
+
+ /* The size of the screen might be bigger than the part we can actually draw on!
+ * So calculate the size based on the top, bottom, left and right */
+ _allegro_screen = create_bitmap_ex(bpp, screen->cr - screen->cl, screen->cb - screen->ct);
+ _screen.width = _allegro_screen->w;
+ _screen.height = _allegro_screen->h;
+ _screen.pitch = ((byte*)screen->line[1] - (byte*)screen->line[0]) / (bpp / 8);
- _allegro_screen = create_bitmap(w, h);
- _screen.width = w;
- _screen.height = h;
- _screen.pitch = ((byte*)screen->line[1] - (byte*)screen->line[0]) / (bitmap_color_depth(screen) / 8);
+ /* Initialise the screen so we don't blit garbage to the screen */
+ memset(_allegro_screen->line[0], 0, _screen.height * _screen.pitch);
+ /* Set the mouse at the place where we expect it */
poll_mouse();
_cursor.pos.x = mouse_x;
_cursor.pos.y = mouse_y;
@@ -393,6 +404,20 @@ const char *VideoDriver_Allegro::Start(const char * const *parm)
install_mouse();
install_keyboard();
+#if defined _DEBUG
+/* Allegro replaces SEGV/ABRT signals meaning that the debugger will never
+ * be triggered, so rereplace the signals and make the debugger userful. */
+ signal(SIGABRT, NULL);
+ signal(SIGSEGV, NULL);
+#endif
+
+#if defined(DOS)
+ /* Force DOS builds to ALWAYS use full screen as
+ * it can't do windowed. */
+ _fullscreen = true;
+#endif
+
+ GetVideoModes();
CreateMainSurface(_cur_resolution.width, _cur_resolution.height);
MarkWholeScreenDirty();
set_close_button_callback(HandleExitGameRequest);
diff --git a/src/video/sdl_v.cpp b/src/video/sdl_v.cpp
index 3b38e991c..353105ea3 100644
--- a/src/video/sdl_v.cpp
+++ b/src/video/sdl_v.cpp
@@ -156,7 +156,7 @@ static void GetAvailableVideoMode(int *w, int *h)
uint delta;
// all modes available?
- if (_all_modes) return;
+ if (_all_modes || _num_resolutions == 0) return;
// is the wanted mode among the available modes?
for (i = 0; i != _num_resolutions; i++) {
@@ -213,8 +213,10 @@ static bool CreateMainSurface(int w, int h)
// DO NOT CHANGE TO HWSURFACE, IT DOES NOT WORK
newscreen = SDL_CALL SDL_SetVideoMode(w, h, bpp, SDL_SWSURFACE | SDL_HWPALETTE | (_fullscreen ? SDL_FULLSCREEN : SDL_RESIZABLE));
- if (newscreen == NULL)
+ if (newscreen == NULL) {
+ DEBUG(driver, 0, "SDL: Couldn't allocate a window to draw on");
return false;
+ }
_screen.width = newscreen->w;
_screen.height = newscreen->h;