fixed order of some drawing operations to be related to correct screen
[rocksndiamonds.git] / src / screens.c
index 7b5aaf9d86a0063d45e35a861950e5966a38faa6..5752a49d0e2308913a6bc3971af728be68904a6c 100644 (file)
@@ -235,6 +235,9 @@ static TreeInfo *drop_distance_current = NULL;
 static TreeInfo *level_number = NULL;
 static TreeInfo *level_number_current = NULL;
 
+static unsigned int sync_frame_delay = 0;
+static unsigned int sync_frame_delay_value = GAME_FRAME_DELAY;
+
 static struct
 {
   int value;
@@ -326,11 +329,12 @@ static struct
   char *text;
 } snapshot_modes_list[] =
 {
-  {    STR_SNAPSHOT_MODE_OFF,          "Off"           },
-  {    STR_SNAPSHOT_MODE_EVERY_STEP,   "Every Step"    },
-  {    STR_SNAPSHOT_MODE_EVERY_MOVE,   "Every Move"    },
+  {    STR_SNAPSHOT_MODE_OFF,                  "Off"           },
+  {    STR_SNAPSHOT_MODE_EVERY_STEP,           "Every Step"    },
+  {    STR_SNAPSHOT_MODE_EVERY_MOVE,           "Every Move"    },
+  {    STR_SNAPSHOT_MODE_EVERY_COLLECT,        "Every Collect" },
 
-  {    NULL,                           NULL            },
+  {    NULL,                                   NULL            },
 };
 
 static struct
@@ -1233,7 +1237,7 @@ static void drawChooseTreeCursor(int ypos, boolean active)
 
   drawCursorExt(0, ypos, active, -1);
 
-  game_status = last_game_status;      /* restore current game status */
+  SetGameStatus(last_game_status);     /* restore current game status */
 }
 
 void DrawHeadline()
@@ -1297,7 +1301,7 @@ void DrawTitleScreenMessage(int nr, boolean initial)
     return;
 
   /* force TITLE font on title message screen */
-  game_status = getTitleMessageGameMode(initial);
+  SetGameStatus(getTitleMessageGameMode(initial));
 
   /* if chars *and* width set to "-1", automatically determine width */
   if (tmi->chars == -1 && tmi->width == -1)
@@ -1336,7 +1340,7 @@ void DrawTitleScreenMessage(int nr, boolean initial)
               filename, tmi->font, tmi->chars, -1, tmi->lines, 0, -1,
               tmi->autowrap, tmi->centered, tmi->parse_comments);
 
-  game_status = last_game_status;      /* restore current game status */
+  SetGameStatus(last_game_status);     /* restore current game status */
 }
 
 void DrawTitleScreen()
@@ -1390,7 +1394,10 @@ void DrawMainMenu()
   /* needed if last screen was the playing screen, invoked from level editor */
   if (level_editor_test_game)
   {
-    game_status = GAME_MODE_EDITOR;
+    CloseDoor(DOOR_CLOSE_ALL);
+
+    SetGameStatus(GAME_MODE_EDITOR);
+
     DrawLevelEd();
 
     return;
@@ -1415,6 +1422,17 @@ void DrawMainMenu()
   /* needed if last screen (level choice) changed graphics, sounds or music */
   ReloadCustomArtwork(0);
 
+  if (CheckTitleScreen(levelset_has_changed))
+  {
+    game_status_last_screen = GAME_MODE_MAIN;
+
+    SetGameStatus(GAME_MODE_TITLE);
+
+    DrawTitleScreen();
+
+    return;
+  }
+
   /* needed if different viewport properties defined for menues */
   ChangeViewportPropertiesIfNeeded();
 
@@ -1431,16 +1449,6 @@ void DrawMainMenu()
 
   SetDrawtoField(DRAW_BACKBUFFER);
 
-  if (CheckTitleScreen(levelset_has_changed))
-  {
-    game_status_last_screen = GAME_MODE_MAIN;
-    game_status = GAME_MODE_TITLE;
-
-    DrawTitleScreen();
-
-    return;
-  }
-
   /* level_nr may have been set to value over handicap with level editor */
   if (setup.handicap && level_nr > leveldir_current->handicap_level)
     level_nr = leveldir_current->handicap_level;
@@ -1567,7 +1575,7 @@ void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
       if (num_title_screens == 0)
       {
        /* switch game mode from title screen mode back to info screen mode */
-       game_status = GAME_MODE_INFO;
+       SetGameStatus(GAME_MODE_INFO);
 
        DrawInfoScreen_NotAvailable("Title screen information:",
                                    "No title screen for this level set.");
@@ -1622,7 +1630,8 @@ void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
   {
     if (game_status_last_screen == GAME_MODE_INFO && num_title_screens == 0)
     {
-      game_status = GAME_MODE_INFO;
+      SetGameStatus(GAME_MODE_INFO);
+
       info_mode = INFO_MODE_MAIN;
 
       DrawInfoScreen();
@@ -1684,14 +1693,15 @@ void HandleTitleScreen(int mx, int my, int dx, int dy, int button)
 
     if (game_status_last_screen == GAME_MODE_INFO)
     {
-      game_status = GAME_MODE_INFO;
+      SetGameStatus(GAME_MODE_INFO);
+
       info_mode = INFO_MODE_MAIN;
 
       DrawInfoScreen();
     }
     else       /* default: return to main menu */
     {
-      game_status = GAME_MODE_MAIN;
+      SetGameStatus(GAME_MODE_MAIN);
 
       DrawMainMenu();
     }
@@ -1826,7 +1836,7 @@ void HandleMainMenu(int mx, int my, int dx, int dy, int button)
 
     CloseDoor(DOOR_CLOSE_2);
 
-    game_status = GAME_MODE_LEVELNR;
+    SetGameStatus(GAME_MODE_LEVELNR);
 
     ChangeViewportPropertiesIfNeeded();
 
@@ -1852,7 +1862,7 @@ void HandleMainMenu(int mx, int my, int dx, int dy, int button)
 
       if (pos == MAIN_CONTROL_NAME)
       {
-       game_status = GAME_MODE_PSEUDO_TYPENAME;
+       SetGameStatus(GAME_MODE_PSEUDO_TYPENAME);
 
        HandleTypeName(strlen(setup.player_name), 0);
       }
@@ -1864,7 +1874,7 @@ void HandleMainMenu(int mx, int my, int dx, int dy, int button)
 
          CloseDoor(DOOR_CLOSE_2);
 
-         game_status = GAME_MODE_LEVELS;
+         SetGameStatus(GAME_MODE_LEVELS);
 
          SaveLevelSetup_LastSeries();
          SaveLevelSetup_SeriesInfo();
@@ -1883,7 +1893,7 @@ void HandleMainMenu(int mx, int my, int dx, int dy, int button)
 
        CloseDoor(DOOR_CLOSE_2);
 
-       game_status = GAME_MODE_SCORES;
+       SetGameStatus(GAME_MODE_SCORES);
 
        DrawHallOfFame(-1);
       }
@@ -1897,7 +1907,7 @@ void HandleMainMenu(int mx, int my, int dx, int dy, int button)
 
        CloseDoor(DOOR_CLOSE_2);
 
-       game_status = GAME_MODE_EDITOR;
+       SetGameStatus(GAME_MODE_EDITOR);
 
        FadeSetEnterScreen();
 
@@ -1909,7 +1919,8 @@ void HandleMainMenu(int mx, int my, int dx, int dy, int button)
 
        CloseDoor(DOOR_CLOSE_2);
 
-       game_status = GAME_MODE_INFO;
+       SetGameStatus(GAME_MODE_INFO);
+
        info_mode = INFO_MODE_MAIN;
 
        ChangeViewportPropertiesIfNeeded();
@@ -1928,7 +1939,8 @@ void HandleMainMenu(int mx, int my, int dx, int dy, int button)
 
        CloseDoor(DOOR_CLOSE_2);
 
-       game_status = GAME_MODE_SETUP;
+       SetGameStatus(GAME_MODE_SETUP);
+
        setup_mode = SETUP_MODE_MAIN;
 
        ChangeViewportPropertiesIfNeeded();
@@ -1941,7 +1953,7 @@ void HandleMainMenu(int mx, int my, int dx, int dy, int button)
        SaveLevelSetup_SeriesInfo();
 
         if (Request("Do you really want to quit?", REQ_ASK | REQ_STAY_CLOSED))
-         game_status = GAME_MODE_QUIT;
+         SetGameStatus(GAME_MODE_QUIT);
       }
     }
   }
@@ -2009,7 +2021,7 @@ static void execInfoLevelSet()
 
 static void execExitInfo()
 {
-  game_status = GAME_MODE_MAIN;
+  SetGameStatus(GAME_MODE_MAIN);
 
   DrawMainMenu();
 }
@@ -2145,8 +2157,6 @@ static void DrawInfoScreen_Main()
   FreeScreenGadgets();
   CreateScreenGadgets();
 
-  CloseDoor(DOOR_CLOSE_2);
-
   /* (needed after displaying title screens which disable auto repeat) */
   KeyboardAutoRepeatOn();
 
@@ -2156,10 +2166,10 @@ static void DrawInfoScreen_Main()
 
   ChangeViewportPropertiesIfNeeded();
 
-  OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
-
   ClearField();
 
+  OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
+
   DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Info Screen");
 
   info_info = info_info_main;
@@ -2181,11 +2191,6 @@ static void DrawInfoScreen_Main()
   PlayMenuSound();
   PlayMenuMusic();
 
-#if 1
-  // needed after returning from title screens with different window size
-  OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
-#endif
-
   DrawMaskedBorder(fade_mask);
 
   FadeIn(fade_mask);
@@ -2665,7 +2670,8 @@ void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos)
 void DrawInfoScreen_TitleScreen()
 {
   game_status_last_screen = GAME_MODE_INFO;
-  game_status = GAME_MODE_TITLE;
+
+  SetGameStatus(GAME_MODE_TITLE);
 
   DrawTitleScreen();
 }
@@ -3598,7 +3604,7 @@ void HandleTypeName(int newxpos, Key key)
 
     is_active = FALSE;
 
-    game_status = GAME_MODE_MAIN;
+    SetGameStatus(GAME_MODE_MAIN);
   }
   else if (key == KSYM_Escape)
   {
@@ -3606,7 +3612,7 @@ void HandleTypeName(int newxpos, Key key)
 
     is_active = FALSE;
 
-    game_status = GAME_MODE_MAIN;
+    SetGameStatus(GAME_MODE_MAIN);
   }
 
   if (is_active)
@@ -3644,7 +3650,7 @@ static void DrawChooseTree(TreeInfo **ti_ptr)
 
   if (strEqual((*ti_ptr)->subdir, STRING_TOP_DIRECTORY))
   {
-    game_status = GAME_MODE_MAIN;
+    SetGameStatus(GAME_MODE_MAIN);
 
     DrawMainMenu();
 
@@ -3656,14 +3662,12 @@ static void DrawChooseTree(TreeInfo **ti_ptr)
   FreeScreenGadgets();
   CreateScreenGadgets();
 
-  CloseDoor(DOOR_CLOSE_2);
-
   FadeOut(fade_mask);
 
-  OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
-
   ClearField();
 
+  OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
+
   HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr);
   MapScreenTreeGadgets(*ti_ptr);
 
@@ -3723,7 +3727,7 @@ static void drawChooseTreeList(int first_entry, int num_page_entries,
       initCursor(i, IMG_MENU_BUTTON);
   }
 
-  game_status = last_game_status;      /* restore current game status */
+  SetGameStatus(last_game_status);     /* restore current game status */
 
   redraw_mask |= REDRAW_FIELD;
 }
@@ -3780,7 +3784,7 @@ static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
   else
     num_page_entries = NUM_MENU_ENTRIES_ON_SCREEN;
 
-  game_status = last_game_status;      /* restore current game status */
+  SetGameStatus(last_game_status);     /* restore current game status */
 
   if (button == MB_MENU_INITIALIZE)
   {
@@ -3855,7 +3859,7 @@ static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
        HandleMainMenu_SelectLevel(0, 0, new_level_nr);
       }
 
-      game_status = GAME_MODE_MAIN;
+      SetGameStatus(GAME_MODE_MAIN);
 
       DrawMainMenu();
     }
@@ -3870,7 +3874,7 @@ static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
     x = (mx - mSX) / 32;
     y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS;
 
-    game_status = last_game_status;    /* restore current game status */
+    SetGameStatus(last_game_status);   /* restore current game status */
   }
   else if (dx || dy)   /* keyboard or scrollbar/scrollbutton input */
   {
@@ -4053,7 +4057,7 @@ static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
            HandleMainMenu_SelectLevel(0, 0, new_level_nr);
          }
 
-         game_status = GAME_MODE_MAIN;
+         SetGameStatus(GAME_MODE_MAIN);
 
          DrawMainMenu();
        }
@@ -4142,9 +4146,6 @@ void DrawHallOfFame(int highlight_position)
 {
   int fade_mask = REDRAW_FIELD;
 
-  /* required before door position may be changed in next step */
-  CloseDoor(DOOR_CLOSE_ALL);
-
   /* needed if different viewport properties defined for scores */
   ChangeViewportPropertiesIfNeeded();
 
@@ -4269,7 +4270,7 @@ void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
 
     FadeSound(SND_BACKGROUND_SCORES);
 
-    game_status = GAME_MODE_MAIN;
+    SetGameStatus(GAME_MODE_MAIN);
 
     DrawMainMenu();
   }
@@ -4279,7 +4280,7 @@ void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
 
     FadeSound(SND_BACKGROUND_SCORES);
 
-    game_status = GAME_MODE_MAIN;
+    SetGameStatus(GAME_MODE_MAIN);
 
     DrawMainMenu();
   }
@@ -5269,7 +5270,7 @@ static void execSetupShortcuts5()
 
 static void execExitSetup()
 {
-  game_status = GAME_MODE_MAIN;
+  SetGameStatus(GAME_MODE_MAIN);
 
   DrawMainMenu();
 }
@@ -5379,7 +5380,7 @@ static struct TokenInfo setup_info_graphics[] =
   { TYPE_SWITCH,       &setup.quick_switch,    "Quick Player Focus Switch:" },
   { TYPE_SWITCH,       &setup.quick_doors,     "Quick Menu Doors:"     },
   { TYPE_SWITCH,       &setup.show_titlescreen,"Show Title Screens:"   },
-  { TYPE_SWITCH,       &setup.toons,           "Show Toons:"           },
+  { TYPE_SWITCH,       &setup.toons,           "Show Menu Animations:" },
   { TYPE_ECS_AGA,      &setup.prefer_aga_graphics,"EMC graphics preference:" },
   { TYPE_SWITCH, &setup.sp_show_border_elements,"Supaplex Border Elements:" },
   { TYPE_SWITCH,       &setup.small_game_graphics, "Small Game Graphics:" },
@@ -5598,8 +5599,7 @@ static Key getSetupKey()
     DoAnimation();
     BackToFront();
 
-    /* don't eat all CPU time */
-    Delay(10);
+    WaitUntilDelayReached(&sync_frame_delay, sync_frame_delay_value);
   }
 
   return key;
@@ -5770,17 +5770,15 @@ static void DrawSetupScreen_Generic()
   FreeScreenGadgets();
   CreateScreenGadgets();
 
-  CloseDoor(DOOR_CLOSE_2);
-
   if (redraw_mask & REDRAW_ALL)
     redraw_all = TRUE;
 
   FadeOut(fade_mask);
 
-  OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
-
   ClearField();
 
+  OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
+
   if (setup_mode == SETUP_MODE_MAIN)
   {
     setup_info = setup_info_main;
@@ -6286,8 +6284,7 @@ void CustomizeKeyboard(int player_nr)
     DoAnimation();
     BackToFront();
 
-    /* don't eat all CPU time */
-    Delay(10);
+    WaitUntilDelayReached(&sync_frame_delay, sync_frame_delay_value);
   }
 
   /* write new key bindings back to player setup */
@@ -6442,8 +6439,7 @@ static boolean CalibrateJoystickMain(int player_nr)
     DoAnimation();
     BackToFront();
 
-    /* don't eat all CPU time */
-    Delay(10);
+    WaitUntilDelayReached(&sync_frame_delay, sync_frame_delay_value);
   }
 
   /* calibrated center position (joystick should now be centered) */
@@ -6465,7 +6461,7 @@ static boolean CalibrateJoystickMain(int player_nr)
       NextEvent(&event);
       HandleOtherEvents(&event);
 
-      Delay(10);
+      WaitUntilDelayReached(&sync_frame_delay, sync_frame_delay_value);
     }
   }
 
@@ -6923,7 +6919,7 @@ void CreateScreenGadgets()
   CreateScreenScrollbuttons();
   CreateScreenScrollbars();
 
-  game_status = last_game_status;      /* restore current game status */
+  SetGameStatus(last_game_status);     /* restore current game status */
 }
 
 void FreeScreenGadgets()