Merge branch 'master' into global-anims
[rocksndiamonds.git] / src / libgame / system.c
index 5c2025b632cf141d1aefffe39820684303ca4b85..38ec0b5b2e5148a2dbf69dd2a8accc65b959b694 100644 (file)
@@ -63,8 +63,7 @@ int                   FrameCounter = 0;
 /* init/close functions                                                      */
 /* ========================================================================= */
 
-void InitProgramInfo(char *argv0, char *config_filename,
-                    char *userdata_subdir, char *userdata_subdir_unix,
+void InitProgramInfo(char *argv0, char *config_filename, char *userdata_subdir,
                     char *program_title, char *icon_title,
                     char *icon_filename, char *cookie_prefix,
                     int program_version)
@@ -75,7 +74,6 @@ void InitProgramInfo(char *argv0, char *config_filename,
   program.config_filename = config_filename;
 
   program.userdata_subdir = userdata_subdir;
-  program.userdata_subdir_unix = userdata_subdir_unix;
   program.userdata_path = getUserGameDataDir();
 
   program.program_title = program_title;
@@ -120,7 +118,7 @@ void InitExitFunction(void (*exit_function)(int))
   program.exit_function = exit_function;
 
   /* set signal handlers to custom exit function */
-  signal(SIGINT, exit_function);
+  // signal(SIGINT, exit_function);
   signal(SIGTERM, exit_function);
 
   /* set exit function to automatically cleanup SDL stuff after exit() */
@@ -132,10 +130,6 @@ void InitPlatformDependentStuff(void)
   // this is initialized in GetOptions(), but may already be used before
   options.verbose = TRUE;
 
-#if defined(PLATFORM_MACOSX)
-  updateUserGameDataDir();
-#endif
-
   OpenLogFiles();
 
 #if defined(TARGET_SDL2)
@@ -171,8 +165,6 @@ void InitGfxFieldInfo(int sx, int sy, int sxsize, int sysize,
 
   gfx.field_save_buffer = field_save_buffer;
 
-  gfx.drawing_area_changed = FALSE;
-
   SetDrawDeactivationMask(REDRAW_NONE);                /* do not deactivate drawing */
   SetDrawBackgroundMask(REDRAW_NONE);          /* deactivate masked drawing */
 }
@@ -215,6 +207,9 @@ void InitGfxWindowInfo(int win_xsize, int win_ysize)
   gfx.background_bitmap_mask = REDRAW_NONE;
 
   ReCreateBitmap(&gfx.background_bitmap, win_xsize, win_ysize, DEFAULT_DEPTH);
+#if USE_FINAL_SCREEN_BITMAP
+  ReCreateBitmap(&gfx.final_screen_bitmap, win_xsize, win_ysize, DEFAULT_DEPTH);
+#endif
 }
 
 void InitGfxScrollbufferInfo(int scrollbuffer_width, int scrollbuffer_height)
@@ -239,6 +234,16 @@ void InitGfxDrawBusyAnimFunction(void (*draw_busy_anim_function)(void))
   gfx.draw_busy_anim_function = draw_busy_anim_function;
 }
 
+void InitGfxDrawGlobalAnimFunction(void (*draw_global_anim_function)(int))
+{
+  gfx.draw_global_anim_function = draw_global_anim_function;
+}
+
+void InitGfxDrawGlobalBorderFunction(void (*draw_global_border_function)(int))
+{
+  gfx.draw_global_border_function = draw_global_border_function;
+}
+
 void InitGfxCustomArtworkInfo()
 {
   gfx.override_level_graphics = FALSE;
@@ -319,9 +324,12 @@ inline static int GetRealDepth(int depth)
 }
 
 inline static void sysFillRectangle(Bitmap *bitmap, int x, int y,
-                              int width, int height, Pixel color)
+                                   int width, int height, Pixel color)
 {
   SDLFillRectangle(bitmap, x, y, width, height, color);
+
+  if (bitmap == backbuffer)
+    SetRedrawMaskFromArea(x, y, width, height);
 }
 
 inline static void sysCopyArea(Bitmap *src_bitmap, Bitmap *dst_bitmap,
@@ -330,6 +338,9 @@ inline static void sysCopyArea(Bitmap *src_bitmap, Bitmap *dst_bitmap,
 {
   SDLCopyArea(src_bitmap, dst_bitmap, src_x, src_y, width, height,
              dst_x, dst_y, mask_mode);
+
+  if (dst_bitmap == backbuffer)
+    SetRedrawMaskFromArea(dst_x, dst_y, width, height);
 }
 
 void LimitScreenUpdates(boolean enable)
@@ -401,7 +412,7 @@ void FreeBitmap(Bitmap *bitmap)
 
 Bitmap *CreateBitmapStruct(void)
 {
-  return checked_calloc(sizeof(struct SDLSurfaceInfo));
+  return checked_calloc(sizeof(Bitmap));
 }
 
 Bitmap *CreateBitmap(int width, int height, int depth)
@@ -438,6 +449,28 @@ void CloseWindow(DrawWindow *window)
 {
 }
 
+void SetRedrawMaskFromArea(int x, int y, int width, int height)
+{
+  int x1 = x;
+  int y1 = y;
+  int x2 = x + width - 1;
+  int y2 = y + height - 1;
+
+  if (width == 0 || height == 0)
+    return;
+
+  if (IN_GFX_FIELD_FULL(x1, y1) && IN_GFX_FIELD_FULL(x2, y2))
+    redraw_mask |= REDRAW_FIELD;
+  else if (IN_GFX_DOOR_1(x1, y1) && IN_GFX_DOOR_1(x2, y2))
+    redraw_mask |= REDRAW_DOOR_1;
+  else if (IN_GFX_DOOR_2(x1, y1) && IN_GFX_DOOR_2(x2, y2))
+    redraw_mask |= REDRAW_DOOR_2;
+  else if (IN_GFX_DOOR_3(x1, y1) && IN_GFX_DOOR_3(x2, y2))
+    redraw_mask |= REDRAW_DOOR_3;
+  else
+    redraw_mask = REDRAW_ALL;
+}
+
 inline static boolean CheckDrawingArea(int x, int y, int width, int height,
                                       int draw_mask)
 {
@@ -473,16 +506,6 @@ boolean DrawingOnBackground(int x, int y)
          CheckDrawingArea(x, y, 1, 1, gfx.draw_background_mask));
 }
 
-boolean DrawingAreaChanged()
-{
-  int drawing_area_changed = gfx.drawing_area_changed;
-
-  // reset flag for change of drawing area after querying it
-  gfx.drawing_area_changed = FALSE;
-
-  return drawing_area_changed;
-}
-
 static boolean InClippedRectangle(Bitmap *bitmap, int *x, int *y,
                                  int *width, int *height, boolean is_dest)
 {
@@ -705,6 +728,58 @@ void BlitBitmapOnBackground(Bitmap *src_bitmap, Bitmap *dst_bitmap,
               dst_x, dst_y);
 }
 
+void BlitTexture(Bitmap *bitmap,
+               int src_x, int src_y, int width, int height,
+               int dst_x, int dst_y)
+{
+  if (bitmap == NULL)
+    return;
+
+  SDLBlitTexture(bitmap, src_x, src_y, width, height, dst_x, dst_y,
+                BLIT_OPAQUE);
+}
+
+void BlitTextureMasked(Bitmap *bitmap,
+                      int src_x, int src_y, int width, int height,
+                      int dst_x, int dst_y)
+{
+  if (bitmap == NULL)
+    return;
+
+  SDLBlitTexture(bitmap, src_x, src_y, width, height, dst_x, dst_y,
+                BLIT_MASKED);
+}
+
+void BlitToScreen(Bitmap *bitmap,
+                 int src_x, int src_y, int width, int height,
+                 int dst_x, int dst_y)
+{
+  if (bitmap == NULL)
+    return;
+
+#if USE_FINAL_SCREEN_BITMAP
+  BlitBitmap(bitmap, gfx.final_screen_bitmap, src_x, src_y,
+            width, height, dst_x, dst_y);
+#else
+  BlitTexture(bitmap, src_x, src_y, width, height, dst_x, dst_y);
+#endif
+}
+
+void BlitToScreenMasked(Bitmap *bitmap,
+                       int src_x, int src_y, int width, int height,
+                       int dst_x, int dst_y)
+{
+  if (bitmap == NULL)
+    return;
+
+#if USE_FINAL_SCREEN_BITMAP
+  BlitBitmapMasked(bitmap, gfx.final_screen_bitmap, src_x, src_y,
+                  width, height, dst_x, dst_y);
+#else
+  BlitTextureMasked(bitmap, src_x, src_y, width, height, dst_x, dst_y);
+#endif
+}
+
 void DrawSimpleBlackLine(Bitmap *bitmap, int from_x, int from_y,
                         int to_x, int to_y)
 {
@@ -800,11 +875,6 @@ void KeyboardAutoRepeatOff(void)
 #endif
 }
 
-boolean PointerInWindow(DrawWindow *window)
-{
-  return TRUE;
-}
-
 boolean SetVideoMode(boolean fullscreen)
 {
   return SDLSetVideoMode(&backbuffer, fullscreen);
@@ -840,7 +910,7 @@ Bitmap *LoadCustomImage(char *basename)
     Error(ERR_EXIT, "LoadCustomImage(): cannot find file '%s'", basename);
 
   if ((new_bitmap = LoadImage(filename)) == NULL)
-    Error(ERR_EXIT, "LoadImage() failed: %s", GetError());
+    Error(ERR_EXIT, "LoadImage('%s') failed: %s", basename, GetError());
 
   return new_bitmap;
 }
@@ -867,7 +937,7 @@ void ReloadCustomImage(Bitmap *bitmap, char *basename)
 
   if ((new_bitmap = LoadImage(filename)) == NULL)
   {
-    Error(ERR_WARN, "LoadImage() failed: %s", GetError());
+    Error(ERR_WARN, "LoadImage('%s') failed: %s", basename, GetError());
     return;
   }
 
@@ -1120,6 +1190,16 @@ void CreateBitmapWithSmallBitmaps(Bitmap **bitmaps, int zoom_factor,
   CreateScaledBitmaps(bitmaps, zoom_factor, tile_size, TRUE);
 }
 
+void CreateBitmapTextures(Bitmap **bitmaps)
+{
+  SDLCreateBitmapTextures(bitmaps[IMG_BITMAP_STANDARD]);
+}
+
+void FreeBitmapTextures(Bitmap **bitmaps)
+{
+  SDLFreeBitmapTextures(bitmaps[IMG_BITMAP_STANDARD]);
+}
+
 void ScaleBitmap(Bitmap **bitmaps, int zoom_factor)
 {
   CreateScaledBitmaps(bitmaps, zoom_factor, 0, FALSE);