2005-07-24 16:12:37 +02:00
/* $Id$ */
2005-07-25 09:16:10 +02:00
# include "../stdafx.h"
# ifdef WITH_SDL
# include "../openttd.h"
# include "../debug.h"
# include "../functions.h"
# include "../gfx.h"
# include "../macros.h"
# include "../sdl.h"
# include "../window.h"
2007-01-02 18:34:03 +01:00
# include "../network/network.h"
2005-07-25 09:16:10 +02:00
# include "../variables.h"
2007-06-12 22:24:12 +02:00
# include "../blitter/blitter.hpp"
# include "../renderer/renderer.hpp"
2005-07-25 09:16:10 +02:00
# include "sdl_v.h"
2005-07-23 17:16:57 +02:00
# include <SDL.h>
static SDL_Surface * _sdl_screen ;
static bool _all_modes ;
# define MAX_DIRTY_RECTS 100
static SDL_Rect _dirty_rects [ MAX_DIRTY_RECTS ] ;
static int _num_dirty_rects ;
static void SdlVideoMakeDirty ( int left , int top , int width , int height )
{
if ( _num_dirty_rects < MAX_DIRTY_RECTS ) {
_dirty_rects [ _num_dirty_rects ] . x = left ;
_dirty_rects [ _num_dirty_rects ] . y = top ;
_dirty_rects [ _num_dirty_rects ] . w = width ;
_dirty_rects [ _num_dirty_rects ] . h = height ;
}
_num_dirty_rects + + ;
}
2005-07-29 12:16:49 +02:00
static void UpdatePalette ( uint start , uint count )
2005-07-23 17:16:57 +02:00
{
2007-06-12 22:24:12 +02:00
/* We can only update the palette in 8bpp for now */
/* TODO -- We need support for other bpps too! */
if ( BlitterFactoryBase : : GetCurrentBlitter ( ) - > GetScreenDepth ( ) ! = 8 ) return ;
2005-07-29 12:16:49 +02:00
SDL_Color pal [ 256 ] ;
2005-07-23 17:16:57 +02:00
uint i ;
2005-07-29 12:16:49 +02:00
for ( i = 0 ; i ! = count ; i + + ) {
pal [ i ] . r = _cur_palette [ start + i ] . r ;
pal [ i ] . g = _cur_palette [ start + i ] . g ;
pal [ i ] . b = _cur_palette [ start + i ] . b ;
2005-07-23 17:16:57 +02:00
pal [ i ] . unused = 0 ;
}
2005-07-29 12:16:49 +02:00
SDL_CALL SDL_SetColors ( _sdl_screen , pal , start , count ) ;
2005-07-23 17:16:57 +02:00
}
2007-03-07 12:47:46 +01:00
static void InitPalette ( )
2005-07-23 17:16:57 +02:00
{
UpdatePalette ( 0 , 256 ) ;
}
2007-03-07 12:47:46 +01:00
static void CheckPaletteAnim ( )
2005-07-23 17:16:57 +02:00
{
2005-07-29 12:16:49 +02:00
if ( _pal_last_dirty ! = - 1 ) {
UpdatePalette ( _pal_first_dirty , _pal_last_dirty - _pal_first_dirty + 1 ) ;
2005-07-23 17:16:57 +02:00
_pal_last_dirty = - 1 ;
}
}
2007-03-07 12:47:46 +01:00
static void DrawSurfaceToScreen ( )
2005-07-23 17:16:57 +02:00
{
int n = _num_dirty_rects ;
if ( n ! = 0 ) {
_num_dirty_rects = 0 ;
if ( n > MAX_DIRTY_RECTS )
SDL_CALL SDL_UpdateRect ( _sdl_screen , 0 , 0 , 0 , 0 ) ;
else
SDL_CALL SDL_UpdateRects ( _sdl_screen , n , _dirty_rects ) ;
}
}
static const uint16 default_resolutions [ ] [ 2 ] = {
{ 640 , 480 } ,
{ 800 , 600 } ,
{ 1024 , 768 } ,
{ 1152 , 864 } ,
{ 1280 , 800 } ,
{ 1280 , 960 } ,
{ 1280 , 1024 } ,
{ 1400 , 1050 } ,
{ 1600 , 1200 } ,
{ 1680 , 1050 } ,
{ 1920 , 1200 }
} ;
2007-03-07 12:47:46 +01:00
static void GetVideoModes ( )
2005-07-23 17:16:57 +02:00
{
int i ;
SDL_Rect * * modes ;
modes = SDL_CALL SDL_ListModes ( NULL , SDL_SWSURFACE + ( _fullscreen ? SDL_FULLSCREEN : 0 ) ) ;
if ( modes = = NULL )
error ( " sdl: no modes available " ) ;
_all_modes = ( modes = = ( void * ) - 1 ) ;
if ( _all_modes ) {
// all modes available, put some default ones here
memcpy ( _resolutions , default_resolutions , sizeof ( default_resolutions ) ) ;
_num_resolutions = lengthof ( default_resolutions ) ;
} else {
int n = 0 ;
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 ) ) {
int j ;
for ( j = 0 ; j < n ; j + + ) {
if ( _resolutions [ j ] [ 0 ] = = w & & _resolutions [ j ] [ 1 ] = = h ) break ;
}
if ( j = = n ) {
_resolutions [ j ] [ 0 ] = w ;
_resolutions [ j ] [ 1 ] = h ;
if ( + + n = = lengthof ( _resolutions ) ) break ;
}
}
}
_num_resolutions = n ;
SortResolutions ( _num_resolutions ) ;
}
}
2006-08-31 22:06:31 +02:00
static void GetAvailableVideoMode ( int * w , int * h )
2005-07-23 17:16:57 +02:00
{
int i ;
int best ;
uint delta ;
// all modes available?
2006-08-31 22:06:31 +02:00
if ( _all_modes ) return ;
2005-07-23 17:16:57 +02:00
// is the wanted mode among the available modes?
for ( i = 0 ; i ! = _num_resolutions ; i + + ) {
2006-08-31 22:06:31 +02:00
if ( * w = = _resolutions [ i ] [ 0 ] & & * h = = _resolutions [ i ] [ 1 ] ) return ;
2005-07-23 17:16:57 +02:00
}
// 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 ;
}
}
* w = _resolutions [ best ] [ 0 ] ;
* h = _resolutions [ best ] [ 1 ] ;
}
2006-08-13 10:18:11 +02:00
# ifndef ICON_DIR
# define ICON_DIR "media"
# endif
# ifdef WIN32
/* Let's redefine the LoadBMP macro with because we are dynamically
* loading SDL and need to ' SDL_CALL ' all functions */
# undef SDL_LoadBMP
# define SDL_LoadBMP(file) SDL_LoadBMP_RW(SDL_CALL SDL_RWFromFile(file, "rb"), 1)
# endif
2005-07-23 17:16:57 +02:00
static bool CreateMainSurface ( int w , int h )
{
2006-10-13 17:52:22 +02:00
extern const char _openttd_revision [ ] ;
2006-08-13 10:18:11 +02:00
SDL_Surface * newscreen , * icon ;
2005-07-23 17:16:57 +02:00
char caption [ 50 ] ;
2007-06-12 22:24:12 +02:00
int bpp = BlitterFactoryBase : : GetCurrentBlitter ( ) - > GetScreenDepth ( ) ;
2005-07-23 17:16:57 +02:00
GetAvailableVideoMode ( & w , & h ) ;
2007-06-12 22:24:12 +02:00
DEBUG ( driver , 1 , " SDL: using mode %dx%dx%d " , w , h , bpp ) ;
if ( bpp = = 0 ) error ( " Can't use a blitter that blits 0 bpp for normal visuals " ) ;
2005-07-23 17:16:57 +02:00
2006-08-13 10:18:11 +02:00
/* Give the application an icon */
icon = SDL_CALL SDL_LoadBMP ( ICON_DIR PATHSEP " openttd.32.bmp " ) ;
if ( icon ! = NULL ) {
/* Get the colourkey, which will be magenta */
uint32 rgbmap = SDL_CALL SDL_MapRGB ( icon - > format , 255 , 0 , 255 ) ;
2006-09-01 12:29:40 +02:00
2006-08-13 10:18:11 +02:00
SDL_CALL SDL_SetColorKey ( icon , SDL_SRCCOLORKEY , rgbmap ) ;
SDL_CALL SDL_WM_SetIcon ( icon , NULL ) ;
SDL_CALL SDL_FreeSurface ( icon ) ;
}
2005-07-23 17:16:57 +02:00
// DO NOT CHANGE TO HWSURFACE, IT DOES NOT WORK
2007-06-12 22:24:12 +02:00
newscreen = SDL_CALL SDL_SetVideoMode ( w , h , bpp , SDL_SWSURFACE | SDL_HWPALETTE | ( _fullscreen ? SDL_FULLSCREEN : SDL_RESIZABLE ) ) ;
2005-07-23 17:16:57 +02:00
if ( newscreen = = NULL )
return false ;
_screen . width = newscreen - > w ;
_screen . height = newscreen - > h ;
2007-06-12 22:24:12 +02:00
_screen . pitch = newscreen - > pitch / ( bpp / 8 ) ;
_screen . renderer = RendererFactoryBase : : SelectRenderer ( BlitterFactoryBase : : GetCurrentBlitter ( ) - > GetRenderer ( ) ) ;
if ( _screen . renderer = = NULL ) error ( " Couldn't load the renderer '%s' the selected blitter depends on " , BlitterFactoryBase : : GetCurrentBlitter ( ) - > GetRenderer ( ) ) ;
2005-07-23 17:16:57 +02:00
_sdl_screen = newscreen ;
InitPalette ( ) ;
snprintf ( caption , sizeof ( caption ) , " OpenTTD %s " , _openttd_revision ) ;
SDL_CALL SDL_WM_SetCaption ( caption , caption ) ;
SDL_CALL SDL_ShowCursor ( 0 ) ;
GameSizeChanged ( ) ;
return true ;
}
2007-03-07 13:11:48 +01:00
struct VkMapping {
2005-07-23 17:16:57 +02:00
uint16 vk_from ;
byte vk_count ;
byte map_to ;
2007-03-07 13:11:48 +01:00
} ;
2005-07-23 17:16:57 +02:00
# define AS(x, z) {x, 0, z}
# define AM(x, y, z, w) {x, y - x, z}
static const VkMapping _vk_mapping [ ] = {
// Pageup stuff + up/down
AM ( SDLK_PAGEUP , SDLK_PAGEDOWN , WKC_PAGEUP , WKC_PAGEDOWN ) ,
2006-08-28 20:53:03 +02:00
AS ( SDLK_UP , WKC_UP ) ,
AS ( SDLK_DOWN , WKC_DOWN ) ,
AS ( SDLK_LEFT , WKC_LEFT ) ,
AS ( SDLK_RIGHT , WKC_RIGHT ) ,
2005-07-23 17:16:57 +02:00
2006-08-28 20:53:03 +02:00
AS ( SDLK_HOME , WKC_HOME ) ,
AS ( SDLK_END , WKC_END ) ,
2005-07-23 17:16:57 +02:00
2006-08-28 20:53:03 +02:00
AS ( SDLK_INSERT , WKC_INSERT ) ,
AS ( SDLK_DELETE , WKC_DELETE ) ,
2005-07-23 17:16:57 +02:00
// Map letters & digits
AM ( SDLK_a , SDLK_z , ' A ' , ' Z ' ) ,
AM ( SDLK_0 , SDLK_9 , ' 0 ' , ' 9 ' ) ,
2006-08-28 20:53:03 +02:00
AS ( SDLK_ESCAPE , WKC_ESC ) ,
AS ( SDLK_PAUSE , WKC_PAUSE ) ,
AS ( SDLK_BACKSPACE , WKC_BACKSPACE ) ,
2005-07-23 17:16:57 +02:00
2006-08-28 20:53:03 +02:00
AS ( SDLK_SPACE , WKC_SPACE ) ,
AS ( SDLK_RETURN , WKC_RETURN ) ,
AS ( SDLK_TAB , WKC_TAB ) ,
2005-07-23 17:16:57 +02:00
// Function keys
AM ( SDLK_F1 , SDLK_F12 , WKC_F1 , WKC_F12 ) ,
// Numeric part.
// What is the virtual keycode for numeric enter??
AM ( SDLK_KP0 , SDLK_KP9 , WKC_NUM_0 , WKC_NUM_9 ) ,
2006-08-28 20:53:03 +02:00
AS ( SDLK_KP_DIVIDE , WKC_NUM_DIV ) ,
AS ( SDLK_KP_MULTIPLY , WKC_NUM_MUL ) ,
AS ( SDLK_KP_MINUS , WKC_NUM_MINUS ) ,
AS ( SDLK_KP_PLUS , WKC_NUM_PLUS ) ,
AS ( SDLK_KP_ENTER , WKC_NUM_ENTER ) ,
AS ( SDLK_KP_PERIOD , WKC_NUM_DECIMAL )
2005-07-23 17:16:57 +02:00
} ;
static uint32 ConvertSdlKeyIntoMy ( SDL_keysym * sym )
{
const VkMapping * map ;
uint key = 0 ;
2006-09-01 12:29:40 +02:00
2005-07-23 17:16:57 +02:00
for ( map = _vk_mapping ; map ! = endof ( _vk_mapping ) ; + + map ) {
if ( ( uint ) ( sym - > sym - map - > vk_from ) < = map - > vk_count ) {
key = sym - > sym - map - > vk_from + map - > map_to ;
break ;
}
}
// check scancode for BACKQUOTE key, because we want the key left of "1", not anything else (on non-US keyboards)
# if defined(WIN32) || defined(__OS2__)
2006-11-16 17:50:54 +01:00
if ( sym - > scancode = = 41 ) key = WKC_BACKQUOTE ;
2005-07-23 17:16:57 +02:00
# elif defined(__APPLE__)
2006-11-16 17:50:54 +01:00
if ( sym - > scancode = = 10 ) key = WKC_BACKQUOTE ;
2005-07-23 17:16:57 +02:00
# elif defined(__MORPHOS__)
2006-11-16 17:50:54 +01:00
if ( sym - > scancode = = 0 ) key = WKC_BACKQUOTE ; // yes, that key is code '0' under MorphOS :)
2005-07-23 17:16:57 +02:00
# elif defined(__BEOS__)
2006-11-16 17:50:54 +01:00
if ( sym - > scancode = = 17 ) key = WKC_BACKQUOTE ;
2005-07-23 17:16:57 +02:00
# elif defined(__SVR4) && defined(__sun)
2006-11-16 17:50:54 +01:00
if ( sym - > scancode = = 60 ) key = WKC_BACKQUOTE ;
if ( sym - > scancode = = 49 ) key = WKC_BACKSPACE ;
2005-07-23 17:16:57 +02:00
# elif defined(__sgi__)
2006-11-16 17:50:54 +01:00
if ( sym - > scancode = = 22 ) key = WKC_BACKQUOTE ;
2005-07-23 17:16:57 +02:00
# else
2006-11-16 17:50:54 +01:00
if ( sym - > scancode = = 49 ) key = WKC_BACKQUOTE ;
2005-07-23 17:16:57 +02:00
# endif
// META are the command keys on mac
2006-09-01 12:29:40 +02:00
if ( sym - > mod & KMOD_META ) key | = WKC_META ;
2005-07-23 17:16:57 +02:00
if ( sym - > mod & KMOD_SHIFT ) key | = WKC_SHIFT ;
2006-09-01 12:29:40 +02:00
if ( sym - > mod & KMOD_CTRL ) key | = WKC_CTRL ;
if ( sym - > mod & KMOD_ALT ) key | = WKC_ALT ;
2005-07-23 17:16:57 +02:00
// these two lines really help porting hotkey combos. Uncomment to use -- Bjarni
2006-09-01 12:29:40 +02:00
#if 0
2006-12-26 18:36:18 +01:00
DEBUG ( driver , 0 , " Scancode character pressed %u " , sym - > scancode ) ;
DEBUG ( driver , 0 , " Unicode character pressed %u " , sym - > unicode ) ;
2006-09-01 12:29:40 +02:00
# endif
2005-07-23 17:16:57 +02:00
return ( key < < 16 ) + sym - > unicode ;
}
2007-03-07 12:47:46 +01:00
static int PollEvent ( )
2005-07-23 17:16:57 +02:00
{
SDL_Event ev ;
2006-09-01 12:29:40 +02:00
if ( ! SDL_CALL SDL_PollEvent ( & ev ) ) return - 2 ;
2005-07-23 17:16:57 +02:00
switch ( ev . type ) {
2006-09-01 12:29:40 +02:00
case SDL_MOUSEMOTION :
if ( _cursor . fix_at ) {
int dx = ev . motion . x - _cursor . pos . x ;
int dy = ev . motion . y - _cursor . pos . y ;
if ( dx ! = 0 | | dy ! = 0 ) {
_cursor . delta . x + = dx ;
_cursor . delta . y + = dy ;
SDL_CALL SDL_WarpMouse ( _cursor . pos . x , _cursor . pos . y ) ;
}
} else {
_cursor . delta . x = ev . motion . x - _cursor . pos . x ;
_cursor . delta . y = ev . motion . y - _cursor . pos . y ;
_cursor . pos . x = ev . motion . x ;
_cursor . pos . y = ev . motion . y ;
_cursor . dirty = true ;
2005-07-23 17:16:57 +02:00
}
2006-11-15 22:01:19 +01:00
HandleMouseEvents ( ) ;
2006-09-01 12:29:40 +02:00
break ;
2005-07-23 17:16:57 +02:00
2006-09-01 12:29:40 +02:00
case SDL_MOUSEBUTTONDOWN :
2006-09-01 12:37:27 +02:00
if ( _rightclick_emulate & & SDL_CALL SDL_GetModState ( ) & KMOD_CTRL ) {
2006-09-01 12:29:40 +02:00
ev . button . button = SDL_BUTTON_RIGHT ;
}
2006-03-24 18:00:55 +01:00
2006-09-01 12:29:40 +02:00
switch ( ev . button . button ) {
case SDL_BUTTON_LEFT :
_left_button_down = true ;
break ;
2006-03-24 01:42:35 +01:00
2006-09-01 12:29:40 +02:00
case SDL_BUTTON_RIGHT :
_right_button_down = true ;
_right_button_clicked = true ;
break ;
case SDL_BUTTON_WHEELUP : _cursor . wheel - - ; break ;
case SDL_BUTTON_WHEELDOWN : _cursor . wheel + + ; break ;
default : break ;
}
2006-11-15 22:01:19 +01:00
HandleMouseEvents ( ) ;
2006-09-01 12:29:40 +02:00
break ;
case SDL_MOUSEBUTTONUP :
if ( _rightclick_emulate ) {
_right_button_down = false ;
_left_button_down = false ;
_left_button_clicked = false ;
} else if ( ev . button . button = = SDL_BUTTON_LEFT ) {
_left_button_down = false ;
_left_button_clicked = false ;
} else if ( ev . button . button = = SDL_BUTTON_RIGHT ) {
_right_button_down = false ;
}
2006-11-15 22:01:19 +01:00
HandleMouseEvents ( ) ;
2006-09-01 12:29:40 +02:00
break ;
case SDL_ACTIVEEVENT :
if ( ! ( ev . active . state & SDL_APPMOUSEFOCUS ) ) break ;
if ( ev . active . gain ) { // mouse entered the window, enable cursor
_cursor . in_window = true ;
2006-06-27 23:25:53 +02:00
} else {
2006-09-01 12:29:40 +02:00
UndrawMouseCursor ( ) ; // mouse left the window, undraw cursor
_cursor . in_window = false ;
2006-06-27 23:25:53 +02:00
}
2006-09-01 12:29:40 +02:00
break ;
2005-07-23 17:16:57 +02:00
2006-09-04 19:30:30 +02:00
case SDL_QUIT : HandleExitGameRequest ( ) ; break ;
2005-07-23 17:16:57 +02:00
2006-09-04 19:30:30 +02:00
case SDL_KEYDOWN : /* Toggle full-screen on ALT + ENTER/F */
2006-09-01 12:29:40 +02:00
if ( ( ev . key . keysym . mod & ( KMOD_ALT | KMOD_META ) ) & &
( ev . key . keysym . sym = = SDLK_RETURN | | ev . key . keysym . sym = = SDLK_f ) ) {
ToggleFullScreen ( ! _fullscreen ) ;
} else {
2006-11-15 20:35:52 +01:00
HandleKeypress ( ConvertSdlKeyIntoMy ( & ev . key . keysym ) ) ;
2006-09-01 12:29:40 +02:00
}
break ;
case SDL_VIDEORESIZE : {
int w = clamp ( ev . resize . w , 64 , MAX_SCREEN_WIDTH ) ;
int h = clamp ( ev . resize . h , 64 , MAX_SCREEN_HEIGHT ) ;
ChangeResInGame ( w , h ) ;
break ;
}
2005-07-23 17:16:57 +02:00
}
return - 1 ;
}
static const char * SdlVideoStart ( const char * const * parm )
{
char buf [ 30 ] ;
const char * s = SdlOpen ( SDL_INIT_VIDEO ) ;
if ( s ! = NULL ) return s ;
SDL_CALL SDL_VideoDriverName ( buf , 30 ) ;
2006-12-26 18:36:18 +01:00
DEBUG ( driver , 1 , " SDL: using driver '%s' " , buf ) ;
2005-07-23 17:16:57 +02:00
GetVideoModes ( ) ;
CreateMainSurface ( _cur_resolution [ 0 ] , _cur_resolution [ 1 ] ) ;
MarkWholeScreenDirty ( ) ;
SDL_CALL SDL_EnableKeyRepeat ( SDL_DEFAULT_REPEAT_DELAY , SDL_DEFAULT_REPEAT_INTERVAL ) ;
SDL_CALL SDL_EnableUNICODE ( 1 ) ;
return NULL ;
}
2007-03-07 12:47:46 +01:00
static void SdlVideoStop ( )
2005-07-23 17:16:57 +02:00
{
SdlClose ( SDL_INIT_VIDEO ) ;
}
2007-03-07 12:47:46 +01:00
static void SdlVideoMainLoop ( )
2005-07-23 17:16:57 +02:00
{
2007-01-10 16:00:20 +01:00
uint32 cur_ticks = SDL_CALL SDL_GetTicks ( ) ;
uint32 next_tick = cur_ticks + 30 ;
2005-07-23 17:16:57 +02:00
uint32 pal_tick = 0 ;
uint32 mod ;
int numkeys ;
Uint8 * keys ;
for ( ; ; ) {
2007-01-10 16:00:20 +01:00
uint32 prev_cur_ticks = cur_ticks ; // to check for wrapping
2005-07-23 17:16:57 +02:00
InteractiveRandom ( ) ; // randomness
2006-11-15 20:49:16 +01:00
while ( PollEvent ( ) = = - 1 ) { }
2005-07-29 18:40:29 +02:00
if ( _exit_game ) return ;
2005-07-23 17:16:57 +02:00
mod = SDL_CALL SDL_GetModState ( ) ;
keys = SDL_CALL SDL_GetKeyState ( & numkeys ) ;
# if defined(_DEBUG)
if ( _shift_pressed )
# else
2007-01-01 20:37:53 +01:00
/* Speedup when pressing tab, except when using ALT+TAB
* to switch to another application */
if ( keys [ SDLK_TAB ] & & ( mod & KMOD_ALT ) = = 0 )
2005-07-23 17:16:57 +02:00
# endif
{
2006-09-04 00:07:28 +02:00
if ( ! _networking & & _game_mode ! = GM_MENU ) _fast_forward | = 2 ;
2005-07-23 17:16:57 +02:00
} else if ( _fast_forward & 2 ) {
_fast_forward = 0 ;
}
cur_ticks = SDL_CALL SDL_GetTicks ( ) ;
2007-03-06 21:59:52 +01:00
if ( cur_ticks > = next_tick | | ( _fast_forward & & ! _pause_game ) | | cur_ticks < prev_cur_ticks ) {
2007-01-10 16:00:20 +01:00
next_tick = cur_ticks + 30 ;
2005-07-23 17:16:57 +02:00
2006-09-01 12:37:27 +02:00
_ctrl_pressed = ! ! ( mod & KMOD_CTRL ) ;
_shift_pressed = ! ! ( mod & KMOD_SHIFT ) ;
2005-11-16 14:45:04 +01:00
# ifdef _DEBUG
2005-07-23 17:16:57 +02:00
_dbg_screen_rect = ! ! ( mod & KMOD_CAPS ) ;
2005-11-16 14:45:04 +01:00
# endif
2005-07-23 17:16:57 +02:00
// determine which directional keys are down
_dirkeys =
( keys [ SDLK_LEFT ] ? 1 : 0 ) |
( keys [ SDLK_UP ] ? 2 : 0 ) |
( keys [ SDLK_RIGHT ] ? 4 : 0 ) |
( keys [ SDLK_DOWN ] ? 8 : 0 ) ;
GameLoop ( ) ;
2007-06-12 22:24:12 +02:00
_screen . dst_ptr = _sdl_screen - > pixels ;
2005-07-23 17:16:57 +02:00
UpdateWindows ( ) ;
if ( + + pal_tick > 4 ) {
CheckPaletteAnim ( ) ;
pal_tick = 1 ;
}
DrawSurfaceToScreen ( ) ;
} else {
SDL_CALL SDL_Delay ( 1 ) ;
2007-06-12 22:24:12 +02:00
_screen . dst_ptr = _sdl_screen - > pixels ;
2005-07-23 17:16:57 +02:00
DrawTextMessage ( ) ;
DrawMouseCursor ( ) ;
DrawSurfaceToScreen ( ) ;
}
}
}
static bool SdlVideoChangeRes ( int w , int h )
{
return CreateMainSurface ( w , h ) ;
}
static void SdlVideoFullScreen ( bool full_screen )
{
_fullscreen = full_screen ;
GetVideoModes ( ) ; // get the list of available video modes
2006-12-03 18:42:56 +01:00
if ( _num_resolutions = = 0 | | ! _video_driver - > change_resolution ( _cur_resolution [ 0 ] , _cur_resolution [ 1 ] ) ) {
2006-09-01 12:29:40 +02:00
// switching resolution failed, put back full_screen to original status
_fullscreen ^ = true ;
}
2005-07-23 17:16:57 +02:00
}
const HalVideoDriver _sdl_video_driver = {
SdlVideoStart ,
SdlVideoStop ,
SdlVideoMakeDirty ,
SdlVideoMainLoop ,
SdlVideoChangeRes ,
SdlVideoFullScreen ,
} ;
2005-07-25 09:16:10 +02:00
2007-02-12 22:55:10 +01:00
# endif /* WITH_SDL */