From ff84e204dde10499c64dace35dc5c4a017b70765 Mon Sep 17 00:00:00 2001 From: Holger Schemel Date: Wed, 1 Feb 2017 20:28:29 +0100 Subject: [PATCH] added headless mode (no window) for automated tape tests using 'autotest' --- src/init.c | 9 +++++++++ src/libgame/sdl.c | 35 ++++++++++++++++++++++++++++++++++- src/libgame/system.c | 8 ++++++++ src/libgame/system.h | 2 ++ src/tools.c | 3 +++ 5 files changed, 56 insertions(+), 1 deletion(-) diff --git a/src/init.c b/src/init.c index 169d0582..8d2e4a1b 100644 --- a/src/init.c +++ b/src/init.c @@ -1710,6 +1710,9 @@ static void InitGraphicInfo() src_x = graphic_info[i].src_x; src_y = graphic_info[i].src_y; + if (program.headless) + continue; + if (src_x < 0 || src_y < 0 || src_x + width > src_bitmap_width || src_y + height > src_bitmap_height) @@ -4961,6 +4964,9 @@ void Execute_Command(char *command) while (*str_ptr != ' ' && *str_ptr != '\t' && *str_ptr != '\0') str_ptr++; } + + if (global.autoplay_mode == AUTOPLAY_MODE_TEST) + program.headless = TRUE; } else if (strPrefix(command, "convert ")) { @@ -5517,6 +5523,9 @@ static void InitMusic(char *identifier) static void InitArtworkDone() { + if (program.headless) + return; + InitGlobalAnimations(); } diff --git a/src/libgame/sdl.c b/src/libgame/sdl.c index a11452bb..e275149f 100644 --- a/src/libgame/sdl.c +++ b/src/libgame/sdl.c @@ -439,6 +439,9 @@ boolean SDLSetNativeSurface(SDL_Surface **surface) #if defined(TARGET_SDL2) static SDL_Texture *SDLCreateTextureFromSurface(SDL_Surface *surface) { + if (program.headless) + return NULL; + SDL_Texture *texture = SDL_CreateTextureFromSurface(sdl_renderer, surface); if (texture == NULL) @@ -502,8 +505,11 @@ void SDLInitVideoDisplay(void) #endif } -void SDLInitVideoBuffer(boolean fullscreen) +inline static void SDLInitVideoBuffer_VideoBuffer(boolean fullscreen) { + if (program.headless) + return; + video.window_scaling_percent = setup.window_scaling_percent; video.window_scaling_quality = setup.window_scaling_quality; @@ -531,7 +537,10 @@ void SDLInitVideoBuffer(boolean fullscreen) #else SDL_WM_SetCaption(program.window_title, program.window_title); #endif +} +inline static void SDLInitVideoBuffer_DrawBuffer() +{ /* SDL cannot directly draw to the visible video framebuffer like X11, but always uses a backbuffer, which is then blitted to the visible video framebuffer with 'SDL_UpdateRect' (or replaced with the current @@ -547,6 +556,16 @@ void SDLInitVideoBuffer(boolean fullscreen) /* create additional (symbolic) buffer for double-buffering */ ReCreateBitmap(&window, video.width, video.height); + + /* create dummy drawing buffer for headless mode, if needed */ + if (program.headless) + ReCreateBitmap(&backbuffer, video.width, video.height); +} + +void SDLInitVideoBuffer(boolean fullscreen) +{ + SDLInitVideoBuffer_VideoBuffer(fullscreen); + SDLInitVideoBuffer_DrawBuffer(); } static boolean SDLCreateScreen(boolean fullscreen) @@ -983,6 +1002,9 @@ void SDLRedrawWindow() void SDLCreateBitmapContent(Bitmap *bitmap, int width, int height, int depth) { + if (program.headless) + return; + SDL_Surface *surface = SDL_CreateRGBSurface(SURFACE_FLAGS, width, height, depth, 0,0,0, 0); @@ -2367,6 +2389,14 @@ Bitmap *SDLLoadImage(char *filename) Bitmap *new_bitmap = CreateBitmapStruct(); SDL_Surface *sdl_image_tmp; + if (program.headless) + { + /* prevent sanity check warnings at later stage */ + new_bitmap->width = new_bitmap->height = 1; + + return new_bitmap; + } + print_timestamp_init("SDLLoadImage"); print_timestamp_time(getBaseNamePtr(filename)); @@ -2456,6 +2486,9 @@ void SDLSetMouseCursor(struct MouseCursorInfo *cursor_info) void SDLOpenAudio(void) { + if (program.headless) + return; + #if !defined(TARGET_SDL2) if (!strEqual(setup.system.sdl_audiodriver, ARG_DEFAULT)) SDL_putenv(getStringCat2("SDL_AUDIODRIVER=", setup.system.sdl_audiodriver)); diff --git a/src/libgame/system.c b/src/libgame/system.c index 00e9c729..b42c7e98 100644 --- a/src/libgame/system.c +++ b/src/libgame/system.c @@ -96,6 +96,8 @@ void InitProgramInfo(char *argv0, char *config_filename, char *userdata_subdir, program.log_filename[LOG_ERR_ID] = getLogFilename(LOG_ERR_BASENAME); program.log_file[LOG_OUT_ID] = program.log_file_default[LOG_OUT_ID] = stdout; program.log_file[LOG_ERR_ID] = program.log_file_default[LOG_ERR_ID] = stderr; + + program.headless = FALSE; } void InitScoresInfo() @@ -388,6 +390,9 @@ void LimitScreenUpdates(boolean enable) void InitVideoDisplay(void) { + if (program.headless) + return; + SDLInitVideoDisplay(); #if defined(TARGET_SDL2) SDLSetDisplaySize(); @@ -621,6 +626,9 @@ void BlitBitmap(Bitmap *src_bitmap, Bitmap *dst_bitmap, int dst_x_unclipped = dst_x; int dst_y_unclipped = dst_y; + if (program.headless) + return; + if (src_bitmap == NULL || dst_bitmap == NULL) return; diff --git a/src/libgame/system.h b/src/libgame/system.h index ad6976c8..dd007f7f 100644 --- a/src/libgame/system.h +++ b/src/libgame/system.h @@ -764,6 +764,8 @@ struct ProgramInfo boolean global_scores; boolean many_scores_per_name; + + boolean headless; }; struct OptionInfo diff --git a/src/tools.c b/src/tools.c index 55a28fc4..6c990cbc 100644 --- a/src/tools.c +++ b/src/tools.c @@ -3736,6 +3736,9 @@ void WaitForEventToContinue() { boolean still_wait = TRUE; + if (program.headless) + return; + /* simulate releasing mouse button over last gadget, if still pressed */ if (button_status) HandleGadgets(-1, -1, 0); -- 2.34.1