X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Flibgame%2Fsystem.c;h=1e43e0b71f8c25e772b3fb8d9fd9afb65538e486;hb=959794cfda1f83edc51512211ae5a9f6b1e0b179;hp=da3797358cb263e72ba21da1ac2205024c9d1988;hpb=3c53030b9e20c59004046274e94eff2ee90d0ab5;p=rocksndiamonds.git diff --git a/src/libgame/system.c b/src/libgame/system.c index da379735..1e43e0b7 100644 --- a/src/libgame/system.c +++ b/src/libgame/system.c @@ -16,10 +16,6 @@ #include "platform.h" -#if defined(PLATFORM_MSDOS) -#include -#endif - #include "system.h" #include "image.h" #include "sound.h" @@ -59,6 +55,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; @@ -72,9 +71,13 @@ int FrameCounter = 0; void InitProgramInfo(char *argv0, char *userdata_subdir, char *userdata_subdir_unix, - char *program_title, char *window_title, char *icon_title, + char *program_title, +#if 0 + char *window_title, +#endif + char *icon_title, char *x11_icon_filename, char *x11_iconmask_filename, - char *sdl_icon_filename, char *msdos_cursor_filename, + char *sdl_icon_filename, char *cookie_prefix, char *filename_prefix, int program_version) { @@ -86,13 +89,16 @@ void InitProgramInfo(char *argv0, program.userdata_path = getUserGameDataDir(); program.program_title = program_title; +#if 1 + program.window_title = "(undefined)"; +#else program.window_title = window_title; +#endif program.icon_title = icon_title; program.x11_icon_filename = x11_icon_filename; program.x11_iconmask_filename = x11_iconmask_filename; program.sdl_icon_filename = sdl_icon_filename; - program.msdos_cursor_filename = msdos_cursor_filename; program.cookie_prefix = cookie_prefix; program.filename_prefix = filename_prefix; @@ -105,6 +111,25 @@ void InitProgramInfo(char *argv0, program.error_file = stderr; } +void SetWindowTitle() +{ + program.window_title = program.window_title_function(); + +#if defined(TARGET_SDL) + SDLSetWindowTitle(); +#endif +} + +void InitWindowTitleFunction(char *(*window_title_function)(void)) +{ + program.window_title_function = window_title_function; +} + +void InitExitMessageFunction(void (*exit_message_function)(char *, va_list)) +{ + program.exit_message_function = exit_message_function; +} + void InitExitFunction(void (*exit_function)(int)) { program.exit_function = exit_function; @@ -121,9 +146,8 @@ void InitExitFunction(void (*exit_function)(int)) void InitPlatformDependentStuff(void) { -#if defined(PLATFORM_MSDOS) - _fmode = O_BINARY; -#endif + // this is initialized in GetOptions(), but may already be used before + options.verbose = TRUE; #if defined(PLATFORM_MACOSX) updateUserGameDataDir(); @@ -138,7 +162,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(); @@ -147,13 +177,9 @@ void InitPlatformDependentStuff(void) void ClosePlatformDependentStuff(void) { -#if defined(PLATFORM_WIN32) || defined(PLATFORM_MSDOS) +#if defined(PLATFORM_WIN32) closeErrorFile(); #endif - -#if defined(PLATFORM_MSDOS) - dumpErrorFile(); -#endif } void InitGfxFieldInfo(int sx, int sy, int sxsize, int sysize, @@ -197,6 +223,14 @@ void InitGfxDoor2Info(int vx, int vy, int vxsize, int vysize) gfx.vysize = vysize; } +void InitGfxDoor3Info(int ex, int ey, int exsize, int eysize) +{ + gfx.ex = ex; + gfx.ey = ey; + gfx.exsize = exsize; + gfx.eysize = eysize; +} + void InitGfxWindowInfo(int win_xsize, int win_ysize) { gfx.win_xsize = win_xsize; @@ -301,11 +335,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 @@ -333,10 +365,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 @@ -398,6 +428,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) @@ -421,17 +458,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 @@ -536,6 +580,19 @@ inline static boolean CheckDrawingArea(int x, int y, int width, int height, if (draw_mask & REDRAW_ALL) return TRUE; +#if 1 + if ((draw_mask & REDRAW_FIELD) && IN_GFX_FIELD_FULL(x, y)) + return TRUE; + + if ((draw_mask & REDRAW_DOOR_1) && IN_GFX_DOOR_1(x, y)) + return TRUE; + + if ((draw_mask & REDRAW_DOOR_2) && IN_GFX_DOOR_2(x, y)) + return TRUE; + + if ((draw_mask & REDRAW_DOOR_3) && IN_GFX_DOOR_3(x, y)) + return TRUE; +#else if ((draw_mask & REDRAW_FIELD) && x >= gfx.real_sx && x < gfx.real_sx + gfx.full_sxsize) return TRUE; @@ -547,6 +604,7 @@ inline static boolean CheckDrawingArea(int x, int y, int width, int height, if ((draw_mask & REDRAW_DOOR_2) && x >= gfx.dx && y >= gfx.vy) return TRUE; +#endif return FALSE; } @@ -658,6 +716,9 @@ void BlitBitmap(Bitmap *src_bitmap, Bitmap *dst_bitmap, int dst_x_unclipped = dst_x; int dst_y_unclipped = dst_y; + if (src_bitmap == NULL || dst_bitmap == NULL) + return; + if (DrawingDeactivated(dst_x, dst_y, width, height)) return; @@ -689,14 +750,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 !!! */ @@ -741,6 +805,7 @@ void BlitBitmap(Bitmap *src_bitmap, Bitmap *dst_bitmap, #endif #endif #endif +#endif #if 0 if (dst_x < gfx.sx + gfx.sxsize) @@ -1001,7 +1066,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 } @@ -1009,7 +1074,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 } @@ -1017,9 +1082,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); @@ -1029,8 +1098,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); @@ -1283,11 +1356,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 @@ -1374,11 +1447,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 @@ -1403,8 +1476,8 @@ void ScaleBitmap(Bitmap *old_bitmap, int zoom_factor) /* mouse pointer functions */ /* ------------------------------------------------------------------------- */ -#if !defined(PLATFORM_MSDOS) #define USE_ONE_PIXEL_PLAYFIELD_MOUSEPOINTER 0 + /* XPM image definitions */ static const char *cursor_image_none[] = { @@ -1437,6 +1510,7 @@ static const char *cursor_image_none[] = /* hot spot */ "0,0" }; + #if USE_ONE_PIXEL_PLAYFIELD_MOUSEPOINTER static const char *cursor_image_dot[] = { @@ -1528,11 +1602,9 @@ static struct MouseCursorInfo *get_cursor_from_image(const char **image) return cursor; } -#endif /* !PLATFORM_MSDOS */ void SetMouseCursor(int mode) { -#if !defined(PLATFORM_MSDOS) static struct MouseCursorInfo *cursor_none = NULL; static struct MouseCursorInfo *cursor_playfield = NULL; struct MouseCursorInfo *cursor_new; @@ -1552,7 +1624,6 @@ void SetMouseCursor(int mode) #elif defined(TARGET_X11_NATIVE) X11SetMouseCursor(cursor_new); #endif -#endif } @@ -1583,8 +1654,6 @@ void OpenAudio(void) SDLOpenAudio(); #elif defined(PLATFORM_UNIX) UnixOpenAudio(); -#elif defined(PLATFORM_MSDOS) - MSDOSOpenAudio(); #endif } @@ -1594,8 +1663,6 @@ void CloseAudio(void) SDLCloseAudio(); #elif defined(PLATFORM_UNIX) UnixCloseAudio(); -#elif defined(PLATFORM_MSDOS) - MSDOSCloseAudio(); #endif audio.sound_enabled = FALSE; @@ -1616,10 +1683,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) @@ -1643,7 +1714,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 @@ -1652,6 +1727,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", @@ -1667,6 +1746,7 @@ Key GetEventKey(KeyEvent *event, boolean with_modifiers) else return event->keysym.sym; +#endif #else #if 0 @@ -1787,8 +1867,6 @@ void InitJoysticks() SDLInitJoysticks(); #elif defined(PLATFORM_UNIX) UnixInitJoysticks(); -#elif defined(PLATFORM_MSDOS) - MSDOSInitJoysticks(); #endif #if 0 @@ -1803,7 +1881,5 @@ boolean ReadJoystick(int nr, int *x, int *y, boolean *b1, boolean *b2) return SDLReadJoystick(nr, x, y, b1, b2); #elif defined(PLATFORM_UNIX) return UnixReadJoystick(nr, x, y, b1, b2); -#elif defined(PLATFORM_MSDOS) - return MSDOSReadJoystick(nr, x, y, b1, b2); #endif }