X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Flibgame%2Fsystem.c;h=f08c88c762aa1519e71965eee0e58f6a2b92eb1a;hb=f6477461020eebe6489d4997ac973c985d82e4aa;hp=6d99c7c8cd11f346fb9bbe63f92cb735b114c958;hpb=4de46eb5a7645e7058bb09e1ff9b3f1e7be54b49;p=rocksndiamonds.git diff --git a/src/libgame/system.c b/src/libgame/system.c index 6d99c7c8..f08c88c7 100644 --- a/src/libgame/system.c +++ b/src/libgame/system.c @@ -59,6 +59,9 @@ DrawBuffer *drawto = NULL; int button_status = MB_NOT_PRESSED; boolean motion_status = FALSE; +#if defined(TARGET_SDL2) +boolean keyrepeat_status = TRUE; +#endif int redraw_mask = REDRAW_NONE; int redraw_tiles = 0; @@ -126,6 +129,9 @@ void InitExitFunction(void (*exit_function)(int)) void InitPlatformDependentStuff(void) { + // this is initialized in GetOptions(), but may already be used before + options.verbose = TRUE; + #if defined(PLATFORM_MSDOS) _fmode = O_BINARY; #endif @@ -143,7 +149,13 @@ void InitPlatformDependentStuff(void) #endif #if defined(TARGET_SDL) - if (SDL_Init(SDL_INIT_EVENTTHREAD | SDL_INIT_NOPARACHUTE) < 0) +#if defined(TARGET_SDL2) + int sdl_init_flags = SDL_INIT_EVENTS | SDL_INIT_NOPARACHUTE; +#else + int sdl_init_flags = SDL_INIT_EVENTTHREAD | SDL_INIT_NOPARACHUTE; +#endif + + if (SDL_Init(sdl_init_flags) < 0) Error(ERR_EXIT, "SDL_Init() failed: %s", SDL_GetError()); SDLNet_Init(); @@ -306,11 +318,9 @@ void SetBackgroundBitmap(Bitmap *background_bitmap_tile, int mask) gfx.real_sx, gfx.real_sy, gfx.full_sxsize, gfx.full_sysize); else if (mask == REDRAW_DOOR_1) - { DrawBitmapFromTile(gfx.background_bitmap, background_bitmap_tile, gfx.dx, gfx.dy, gfx.dxsize, gfx.dysize); - } } #else @@ -338,10 +348,8 @@ void SetBackgroundBitmap(Bitmap *background_bitmap_tile, int mask) BlitBitmapTiled(background_bitmap_tile, gfx.background_bitmap, 0, 0, 0, 0, gfx.real_sx, gfx.real_sy, gfx.full_sxsize, gfx.full_sysize); else if (mask == REDRAW_DOOR_1) - { BlitBitmapTiled(background_bitmap_tile, gfx.background_bitmap, 0, 0, 0, 0, gfx.dx, gfx.dy, gfx.dxsize, gfx.dysize); - } } #endif @@ -403,6 +411,13 @@ inline static void sysCopyArea(Bitmap *src_bitmap, Bitmap *dst_bitmap, #endif } +void LimitScreenUpdates(boolean enable) +{ +#if defined(TARGET_SDL) + SDLLimitScreenUpdates(enable); +#endif +} + void InitVideoDisplay(void) { #if defined(TARGET_SDL) @@ -426,17 +441,24 @@ void CloseVideoDisplay(void) void InitVideoBuffer(int width, int height, int depth, boolean fullscreen) { +#if 0 + printf("::: InitVideoBuffer\n"); +#endif + video.width = width; video.height = height; video.depth = GetRealDepth(depth); video.fullscreen_available = FULLSCREEN_STATUS; video.fullscreen_enabled = FALSE; + // video.fullscreen_initial = FALSE; #if 0 video.fullscreen_mode_current = NULL; video.fullscreen_modes = NULL; #endif + video.window_scaling_available = WINDOW_SCALING_STATUS; + #if defined(TARGET_SDL) SDLInitVideoBuffer(&backbuffer, &window, fullscreen); #else @@ -694,14 +716,17 @@ void BlitBitmap(Bitmap *src_bitmap, Bitmap *dst_bitmap, height = dst_bitmap->height - dst_y; #endif -#if 0 +#if 1 + /* !!! 2013-12-11: An "old friend" is back. Same bug in SDL2 2.0.1 !!! */ +#if 1 /* !!! 2009-03-30: Fixed by using self-compiled, patched SDL.dll !!! */ /* (This bug still exists in the actual (as of 2009-06-15) version 1.2.13, but is already fixed in SVN and should therefore finally be fixed with the next official SDL release, which is probably version 1.2.14.) */ #if 1 /* !!! 2009-03-24: It seems that this problem still exists in 1.2.12 !!! */ -#if defined(TARGET_SDL) && defined(PLATFORM_WIN32) + //#if defined(TARGET_SDL) && defined(PLATFORM_WIN32) +#if defined(TARGET_SDL2) if (src_bitmap == dst_bitmap) { /* !!! THIS IS A BUG (IN THE SDL LIBRARY?) AND SHOULD BE FIXED !!! */ @@ -746,6 +771,7 @@ void BlitBitmap(Bitmap *src_bitmap, Bitmap *dst_bitmap, #endif #endif #endif +#endif #if 0 if (dst_x < gfx.sx + gfx.sxsize) @@ -1006,7 +1032,7 @@ Pixel GetPixelFromRGBcompact(Bitmap *bitmap, unsigned int color) /* execute all pending screen drawing operations */ void FlushDisplay(void) { -#ifndef TARGET_SDL +#if !defined(TARGET_SDL) XFlush(display); #endif } @@ -1014,7 +1040,7 @@ void FlushDisplay(void) /* execute and wait for all pending screen drawing operations */ void SyncDisplay(void) { -#ifndef TARGET_SDL +#if !defined(TARGET_SDL) XSync(display, FALSE); #endif } @@ -1022,9 +1048,13 @@ void SyncDisplay(void) void KeyboardAutoRepeatOn(void) { #if defined(TARGET_SDL) +#if defined(TARGET_SDL2) + keyrepeat_status = TRUE; +#else SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY / 2, SDL_DEFAULT_REPEAT_INTERVAL / 2); SDL_EnableUNICODE(1); +#endif #else if (display) XAutoRepeatOn(display); @@ -1034,8 +1064,12 @@ void KeyboardAutoRepeatOn(void) void KeyboardAutoRepeatOff(void) { #if defined(TARGET_SDL) +#if defined(TARGET_SDL2) + keyrepeat_status = FALSE; +#else SDL_EnableKeyRepeat(0, SDL_DEFAULT_REPEAT_INTERVAL); SDL_EnableUNICODE(0); +#endif #else if (display) XAutoRepeatOff(display); @@ -1288,11 +1322,11 @@ static void CreateScaledBitmaps(Bitmap *old_bitmap, int zoom_factor, if (old_bitmap->surface_masked) SDL_FreeSurface(old_bitmap->surface_masked); - SDL_SetColorKey(tmp_surface_1, SDL_SRCCOLORKEY, + SDL_SetColorKey(tmp_surface_1, SET_TRANSPARENT_PIXEL, SDL_MapRGB(tmp_surface_1->format, 0x00, 0x00, 0x00)); if ((old_bitmap->surface_masked = SDL_DisplayFormat(tmp_surface_1)) ==NULL) Error(ERR_EXIT, "SDL_DisplayFormat() failed"); - SDL_SetColorKey(tmp_surface_1, 0, 0); /* reset transparent pixel */ + SDL_SetColorKey(tmp_surface_1, UNSET_TRANSPARENT_PIXEL, 0); #endif } #endif @@ -1379,11 +1413,11 @@ static void CreateScaledBitmaps(Bitmap *old_bitmap, int zoom_factor, if (old_bitmap->surface_masked) SDL_FreeSurface(old_bitmap->surface_masked); - SDL_SetColorKey(old_surface, SDL_SRCCOLORKEY, + SDL_SetColorKey(old_surface, SET_TRANSPARENT_PIXEL, SDL_MapRGB(old_surface->format, 0x00, 0x00, 0x00)); if ((old_bitmap->surface_masked = SDL_DisplayFormat(old_surface)) ==NULL) Error(ERR_EXIT, "SDL_DisplayFormat() failed"); - SDL_SetColorKey(old_surface, 0, 0); /* reset transparent pixel */ + SDL_SetColorKey(old_surface, UNSET_TRANSPARENT_PIXEL, 0); #endif } #endif @@ -1621,10 +1655,14 @@ void SetAudioMode(boolean enabled) void InitEventFilter(EventFilter filter_function) { -#if defined(TARGET_SDL) /* set event filter to filter out certain events */ +#if defined(TARGET_SDL) +#if defined(TARGET_SDL2) + SDL_SetEventFilter(filter_function, NULL); +#else SDL_SetEventFilter(filter_function); #endif +#endif } boolean PendingEvent(void) @@ -1648,7 +1686,11 @@ void NextEvent(Event *event) void PeekEvent(Event *event) { #if defined(TARGET_SDL) +#if defined(TARGET_SDL2) + SDL_PeepEvents(event, 1, SDL_PEEKEVENT, SDL_FIRSTEVENT, SDL_LASTEVENT); +#else SDL_PeepEvents(event, 1, SDL_PEEKEVENT, SDL_ALLEVENTS); +#endif #else XPeekEvent(display, event); #endif @@ -1657,6 +1699,10 @@ void PeekEvent(Event *event) Key GetEventKey(KeyEvent *event, boolean with_modifiers) { #if defined(TARGET_SDL) +#if defined(TARGET_SDL2) + /* key up/down events in SDL2 do not return text characters anymore */ + return event->keysym.sym; +#else #if 0 printf("unicode == '%d', sym == '%d', mod == '0x%04x'\n", @@ -1672,6 +1718,7 @@ Key GetEventKey(KeyEvent *event, boolean with_modifiers) else return event->keysym.sym; +#endif #else #if 0