added first version of simple click events for global animations
[rocksndiamonds.git] / src / libgame / sdl.c
index 7221c7afeede8e9655e005b63d98bb8c4e1b51e0..e275149fea202b723e4348394568394fc294f0d7 100644 (file)
@@ -37,8 +37,10 @@ static boolean limit_screen_updates = FALSE;
 /* functions from SGE library */
 void sge_Line(SDL_Surface *, Sint16, Sint16, Sint16, Sint16, Uint32);
 
+#if defined(USE_TOUCH_INPUT_OVERLAY)
 /* functions to draw overlay graphics for touch device input */
 static void DrawTouchInputOverlay();
+#endif
 
 void SDLLimitScreenUpdates(boolean enable)
 {
@@ -205,8 +207,11 @@ static void UpdateScreenExt(SDL_Rect *rect, boolean with_frame_delay)
     SDL_RenderCopy(sdl_renderer, sdl_texture_target, src_rect2, dst_rect2);
   }
 
+#if defined(USE_TOUCH_INPUT_OVERLAY)
   // draw overlay graphics for touch device input, if needed
   DrawTouchInputOverlay();
+#endif
+
 #endif
 
   // global synchronization point of the game to align video frame delay
@@ -434,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)
@@ -497,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;
 
@@ -526,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
@@ -542,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)
@@ -565,10 +589,10 @@ static boolean SDLCreateScreen(boolean fullscreen)
      it will crash if flags are *not* set to SDL_RENDERER_SOFTWARE (because
      it will try to use accelerated graphics and apparently fails miserably) */
   int renderer_flags = SDL_RENDERER_SOFTWARE;
-#endif
 #endif
 
   SDLSetScreenSizeAndOffsets(video.width, video.height);
+#endif
 
   int width  = video.width;
   int height = video.height;
@@ -978,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);
 
@@ -2362,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));
@@ -2451,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));
@@ -2685,9 +2723,9 @@ boolean SDLReadJoystick(int nr, int *x, int *y, boolean *b1, boolean *b2)
   return TRUE;
 }
 
+#if defined(USE_TOUCH_INPUT_OVERLAY)
 static void DrawTouchInputOverlay()
 {
-#if defined(USE_TOUCH_INPUT_OVERLAY)
   static SDL_Texture *texture = NULL;
   static boolean initialized = FALSE;
   static boolean deactivated = TRUE;
@@ -2777,5 +2815,5 @@ static void DrawTouchInputOverlay()
   SDL_Rect dst_rect = { xpos, ypos, width_scaled, height_scaled };
 
   SDL_RenderCopy(sdl_renderer, texture, &src_rect, &dst_rect);
-#endif
 }
+#endif