fixed small bug with wrong video state definition
[rocksndiamonds.git] / src / tools.c
index 6dc9129afa775e788a8f9bbefc36dafef01f8fd5..7ec68260c039aa73114f50eda882f07dd1884c1b 100644 (file)
@@ -528,6 +528,22 @@ static void PrintFrameTimeDebugging()
 }
 #endif
 
+static int unifiedRedrawMask(int mask)
+{
+  if (mask & REDRAW_ALL)
+    return REDRAW_ALL;
+
+  if (mask & REDRAW_FIELD && mask & REDRAW_DOORS)
+    return REDRAW_ALL;
+
+  return mask;
+}
+
+static boolean equalRedrawMasks(int mask_1, int mask_2)
+{
+  return unifiedRedrawMask(mask_1) == unifiedRedrawMask(mask_2);
+}
+
 void BackToFront()
 {
   static int last_redraw_mask = REDRAW_NONE;
@@ -550,6 +566,10 @@ void BackToFront()
   if (redraw_mask & REDRAW_FPS)
     DrawFramesPerSecond();
 
+  // remove playfield redraw before potentially merging with doors redraw
+  if (DrawingDeactivated(REAL_SX, REAL_SY, FULL_SXSIZE, FULL_SYSIZE))
+    redraw_mask &= ~REDRAW_FIELD;
+
   // redraw complete window if both playfield and (some) doors need redraw
   if (redraw_mask & REDRAW_FIELD && redraw_mask & REDRAW_DOORS)
     redraw_mask = REDRAW_ALL;
@@ -583,14 +603,16 @@ void BackToFront()
       x2 = MAX(x2, DX + DXSIZE);
       y2 = MAX(y2, DY + DYSIZE);
     }
-    else if (redraw_mask & REDRAW_DOOR_2)
+
+    if (redraw_mask & REDRAW_DOOR_2)
     {
       x1 = MIN(x1, VX);
       y1 = MIN(y1, VY);
       x2 = MAX(x2, VX + VXSIZE);
       y2 = MAX(y2, VY + VYSIZE);
     }
-    else if (redraw_mask & REDRAW_DOOR_3)
+
+    if (redraw_mask & REDRAW_DOOR_3)
     {
       x1 = MIN(x1, EX);
       y1 = MIN(y1, EY);
@@ -725,10 +747,6 @@ static void SetScreenStates_AfterFadingIn()
   gfx.fade_border_source_status = global.border_status;
 
   global.anim_status = global.anim_status_next;
-
-  // force update of global animation status in case of rapid screen changes
-  redraw_mask = REDRAW_ALL;
-  BackToFront();
 }
 
 static void SetScreenStates_BeforeFadingOut()
@@ -767,10 +785,18 @@ void FadeIn(int fade_mask)
   FADE_SYSIZE = FULL_SYSIZE;
 
   SetScreenStates_AfterFadingIn();
+
+  // force update of global animation status in case of rapid screen changes
+  redraw_mask = REDRAW_ALL;
+  BackToFront();
 }
 
 void FadeOut(int fade_mask)
 {
+  // update screen if areas covered by "fade_mask" and "redraw_mask" differ
+  if (!equalRedrawMasks(fade_mask, redraw_mask))
+    BackToFront();
+
   SetScreenStates_BeforeFadingOut();
 
 #if 0