src/video/allegro_v.cpp
changeset 10390 0c2cc4c7b91f
parent 10385 4f9838649c7f
equal deleted inserted replaced
10389:05465e8a465c 10390:0c2cc4c7b91f
    18 #include "../functions.h"
    18 #include "../functions.h"
    19 #include "../texteff.hpp"
    19 #include "../texteff.hpp"
    20 #include "allegro_v.h"
    20 #include "allegro_v.h"
    21 #include <allegro.h>
    21 #include <allegro.h>
    22 
    22 
       
    23 #ifdef _DEBUG
       
    24 /* Allegro replaces SEGV/ABRT signals meaning that the debugger will never
       
    25  * be triggered, so rereplace the signals and make the debugger userful. */
       
    26 #include <signal.h>
       
    27 #endif
       
    28 
    23 static FVideoDriver_Allegro iFVideoDriver_Allegro;
    29 static FVideoDriver_Allegro iFVideoDriver_Allegro;
    24 
    30 
    25 static BITMAP *_allegro_screen;
    31 static BITMAP *_allegro_screen;
    26 
    32 
    27 #define MAX_DIRTY_RECTS 100
    33 #define MAX_DIRTY_RECTS 100
   152 	destroy_gfx_mode_list(mode_list);
   158 	destroy_gfx_mode_list(mode_list);
   153 }
   159 }
   154 
   160 
   155 static void GetAvailableVideoMode(int *w, int *h)
   161 static void GetAvailableVideoMode(int *w, int *h)
   156 {
   162 {
       
   163 	/* No video modes, so just try it and see where it ends */
       
   164 	if (_num_resolutions == 0) return;
       
   165 
   157 	/* is the wanted mode among the available modes? */
   166 	/* is the wanted mode among the available modes? */
   158 	for (int i = 0; i != _num_resolutions; i++) {
   167 	for (int i = 0; i != _num_resolutions; i++) {
   159 		if (*w == _resolutions[i].width && *h == _resolutions[i].height) return;
   168 		if (*w == _resolutions[i].width && *h == _resolutions[i].height) return;
   160 	}
   169 	}
   161 
   170 
   177 {
   186 {
   178 	int bpp = BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth();
   187 	int bpp = BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth();
   179 	if (bpp == 0) usererror("Can't use a blitter that blits 0 bpp for normal visuals");
   188 	if (bpp == 0) usererror("Can't use a blitter that blits 0 bpp for normal visuals");
   180 	set_color_depth(bpp);
   189 	set_color_depth(bpp);
   181 
   190 
   182 #if defined(DOS)
       
   183 	/* Force DOS builds to ALWAYS use full screen as
       
   184 	 * it can't do windowed. */
       
   185 	_fullscreen = true;
       
   186 #endif
       
   187 
       
   188 	GetVideoModes();
       
   189 	GetAvailableVideoMode(&w, &h);
   191 	GetAvailableVideoMode(&w, &h);
   190 	if (set_gfx_mode(_fullscreen ? GFX_AUTODETECT_FULLSCREEN : GFX_AUTODETECT_WINDOWED, w, h, 0, 0) != 0) return false;
   192 	if (set_gfx_mode(_fullscreen ? GFX_AUTODETECT_FULLSCREEN : GFX_AUTODETECT_WINDOWED, w, h, 0, 0) != 0) {
   191 
   193 		DEBUG(driver, 0, "Allegro: Couldn't allocate a window to draw on");
   192 	_allegro_screen = create_bitmap(w, h);
   194 		return false;
   193 	_screen.width = w;
   195 	}
   194 	_screen.height = h;
   196 
   195 	_screen.pitch = ((byte*)screen->line[1] - (byte*)screen->line[0]) / (bitmap_color_depth(screen) / 8);
   197 	/* The size of the screen might be bigger than the part we can actually draw on!
   196 
   198 	 * So calculate the size based on the top, bottom, left and right */
       
   199 	_allegro_screen = create_bitmap_ex(bpp, screen->cr - screen->cl, screen->cb - screen->ct);
       
   200 	_screen.width = _allegro_screen->w;
       
   201 	_screen.height = _allegro_screen->h;
       
   202 	_screen.pitch = ((byte*)screen->line[1] - (byte*)screen->line[0]) / (bpp / 8);
       
   203 
       
   204 	/* Initialise the screen so we don't blit garbage to the screen */
       
   205 	memset(_allegro_screen->line[0], 0, _screen.height * _screen.pitch);
       
   206 
       
   207 	/* Set the mouse at the place where we expect it */
   197 	poll_mouse();
   208 	poll_mouse();
   198 	_cursor.pos.x = mouse_x;
   209 	_cursor.pos.x = mouse_x;
   199 	_cursor.pos.y = mouse_y;
   210 	_cursor.pos.y = mouse_y;
   200 
   211 
   201 	InitPalette();
   212 	InitPalette();
   391 
   402 
   392 	install_timer();
   403 	install_timer();
   393 	install_mouse();
   404 	install_mouse();
   394 	install_keyboard();
   405 	install_keyboard();
   395 
   406 
       
   407 #if defined _DEBUG
       
   408 /* Allegro replaces SEGV/ABRT signals meaning that the debugger will never
       
   409  * be triggered, so rereplace the signals and make the debugger userful. */
       
   410 	signal(SIGABRT, NULL);
       
   411 	signal(SIGSEGV, NULL);
       
   412 #endif
       
   413 
       
   414 #if defined(DOS)
       
   415 	/* Force DOS builds to ALWAYS use full screen as
       
   416 	 * it can't do windowed. */
       
   417 	_fullscreen = true;
       
   418 #endif
       
   419 
       
   420 	GetVideoModes();
   396 	CreateMainSurface(_cur_resolution.width, _cur_resolution.height);
   421 	CreateMainSurface(_cur_resolution.width, _cur_resolution.height);
   397 	MarkWholeScreenDirty();
   422 	MarkWholeScreenDirty();
   398 	set_close_button_callback(HandleExitGameRequest);
   423 	set_close_button_callback(HandleExitGameRequest);
   399 
   424 
   400 	return NULL;
   425 	return NULL;