moved code to draw envelope request over global animations
[rocksndiamonds.git] / src / anim.c
index de94b17f88abb50a3a3fc41ce4e0c4e1c27accde..5e3a896ecc9ff2d1b9f909f388d7842338e8aefa 100644 (file)
@@ -857,6 +857,10 @@ static void DrawGlobalAnimationsExt(int drawing_target, int drawing_stage)
     }
   }
 
+  // when restarting global animations, do not redraw them, but stop here
+  if (drawing_stage == DRAW_GLOBAL_ANIM_STAGE_RESTART)
+    return;
+
   if (global.anim_status == GAME_MODE_LOADING)
     return;
 
@@ -970,8 +974,6 @@ void DrawGlobalAnimations(int drawing_target, int drawing_stage)
     ResetGlobalAnim_Clicked();
   }
 
-  DrawEnvelopeRequestToScreen(drawing_target, drawing_stage);
-
   if (gfx.cursor_mode_override != last_cursor_mode_override)
     SetMouseCursor(gfx.cursor_mode);
 }
@@ -1596,12 +1598,7 @@ static int HandleGlobalAnim_Part(struct GlobalAnimPartControlInfo *part,
       part->init_event_state)
   {
     if (part->initial_anim_sync_frame > 0)
-    {
-      if (part->init_delay_counter > 0)
-       part->initial_anim_sync_frame -= part->init_delay_counter;
-      else
-       part->initial_anim_sync_frame = anim_sync_frame;
-    }
+      part->initial_anim_sync_frame = anim_sync_frame;
 
     part->init_delay_counter = 1;
     part->init_event_state = FALSE;
@@ -1733,12 +1730,17 @@ static int HandleGlobalAnim_Part(struct GlobalAnimPartControlInfo *part,
   if (c->position == POS_CE)
   {
     // calculate playfield position (with scrolling) for related CE tile
+    // (do not use FX/FY, which are incorrect during envelope requests)
+    int FX0 = 2 * TILEX_VAR;   // same as FX during DRAW_TO_FIELDBUFFER
+    int FY0 = 2 * TILEY_VAR;   // same as FY during DRAW_TO_FIELDBUFFER
     int fx = getFieldbufferOffsetX_RND(ScreenMovDir, ScreenGfxPos);
     int fy = getFieldbufferOffsetY_RND(ScreenMovDir, ScreenGfxPos);
-    int sx = FX + SCREENX(part->tile_x) * TILEX_VAR;
-    int sy = FY + SCREENY(part->tile_y) * TILEY_VAR;
-    int x = sx - fx;
-    int y = sy - fy;
+    int sx = FX0 + SCREENX(part->tile_x) * TILEX_VAR;
+    int sy = FY0 + SCREENY(part->tile_y) * TILEY_VAR;
+    int cx = SX - REAL_SX;
+    int cy = SY - REAL_SY;
+    int x = sx - fx + cx;
+    int y = sy - fy + cy;
 
     part->tile_xoffset += part->step_xoffset;
     part->tile_yoffset += part->step_yoffset;
@@ -2160,11 +2162,16 @@ void RestartGlobalAnimsByStatus(int status)
   global.anim_status = status;
 
   // force restarting global animations by changed global animation status
-  SDLRedrawWindow();
+  DrawGlobalAnimationsExt(DRAW_TO_SCREEN, DRAW_GLOBAL_ANIM_STAGE_RESTART);
 
   global.anim_status = anim_status_last;
 }
 
+void SetAnimStatusBeforeFading(int status)
+{
+  anim_status_last_before_fading = status;
+}
+
 boolean HandleGlobalAnimClicks(int mx, int my, int button, boolean force_click)
 {
   static boolean click_consumed = FALSE;