fixed bug with extremely slow envelopes when using "request.step_delay: 0"
[rocksndiamonds.git] / src / tools.c
index 324bd45bf150f22d8964a81506922b8724d88410..21f062b41cdc21fb2bfc3c257f08ffbefc87d9f7 100644 (file)
@@ -1444,13 +1444,6 @@ void getSizedGraphicSourceExt(int graphic, int frame, int tilesize,
   *y = *y * tilesize / g->tile_size;
 }
 
-void getFixedGraphicSourceExt(int graphic, int frame, Bitmap **bitmap,
-                             int *x, int *y, boolean get_backside)
-{
-  getSizedGraphicSourceExt(graphic, frame, TILESIZE, bitmap, x, y,
-                          get_backside);
-}
-
 void getSizedGraphicSource(int graphic, int frame, int tilesize,
                           Bitmap **bitmap, int *x, int *y)
 {
@@ -2518,7 +2511,7 @@ void AnimateEnvelope(int envelope_nr, int anim_mode, int action)
   boolean no_delay = (tape.warp_forward);
   unsigned int anim_delay = 0;
   int frame_delay_value = (ffwd_delay ? FfwdFrameDelay : GameFrameDelay);
-  int anim_delay_value = (no_delay ? 0 : frame_delay_value) / 2;
+  int anim_delay_value = MAX(1, (no_delay ? 0 : frame_delay_value) / 2);
   int font_nr = FONT_ENVELOPE_1 + envelope_nr;
   int font_width = getFontWidth(font_nr);
   int font_height = getFontHeight(font_nr);
@@ -2775,7 +2768,7 @@ void AnimateEnvelopeRequest(int anim_mode, int action)
   boolean ffwd_delay = (tape.playing && tape.fast_forward);
   boolean no_delay = (tape.warp_forward);
   int delay_value = (ffwd_delay ? delay_value_fast : delay_value_normal);
-  int anim_delay_value = (no_delay ? 0 : delay_value + 500 * 0) / 2;
+  int anim_delay_value = MAX(1, (no_delay ? 0 : delay_value + 500 * 0) / 2);
   unsigned int anim_delay = 0;
 
   int tile_size = MAX(request.step_offset, 1);
@@ -2981,7 +2974,7 @@ void DrawMiniLevel(int size_x, int size_y, int scroll_x, int scroll_y)
   redraw_mask |= REDRAW_FIELD;
 }
 
-static void DrawPreviewLevelPlayfieldExt(int from_x, int from_y)
+static void DrawPreviewLevelPlayfield(int from_x, int from_y)
 {
   boolean show_level_border = (BorderElement != EL_EMPTY);
   int level_xsize = lev_fieldx + (show_level_border ? 2 : 0);
@@ -3046,9 +3039,8 @@ static int getMaxTextLength(struct TextPosInfo *pos, int font_nr)
   return max_text_width / font_width;
 }
 
-static void DrawPreviewLevelLabelExt(int mode)
+static void DrawPreviewLevelLabelExt(int mode, struct TextPosInfo *pos)
 {
-  struct TextPosInfo *pos = &menu.main.text.level_info_2;
   char label_text[MAX_OUTPUT_LINESIZE + 1];
   int max_len_label_text;
   int font_nr = pos->font;
@@ -3091,6 +3083,19 @@ static void DrawPreviewLevelLabelExt(int mode)
   redraw_mask |= REDRAW_FIELD;
 }
 
+static void DrawPreviewLevelLabel(int mode)
+{
+  DrawPreviewLevelLabelExt(mode, &menu.main.text.level_info_2);
+}
+
+static void DrawPreviewLevelInfo(int mode)
+{
+  if (mode == MICROLABEL_LEVEL_NAME)
+    DrawPreviewLevelLabelExt(mode, &menu.main.text.level_name);
+  else if (mode == MICROLABEL_LEVEL_AUTHOR)
+    DrawPreviewLevelLabelExt(mode, &menu.main.text.level_author);
+}
+
 static void DrawPreviewLevelExt(boolean restart)
 {
   static unsigned int scroll_delay = 0;
@@ -3122,8 +3127,11 @@ static void DrawPreviewLevelExt(boolean restart)
     label_state = 1;
     label_counter = 0;
 
-    DrawPreviewLevelPlayfieldExt(from_x, from_y);
-    DrawPreviewLevelLabelExt(label_state);
+    DrawPreviewLevelPlayfield(from_x, from_y);
+    DrawPreviewLevelLabel(label_state);
+
+    DrawPreviewLevelInfo(MICROLABEL_LEVEL_NAME);
+    DrawPreviewLevelInfo(MICROLABEL_LEVEL_AUTHOR);
 
     /* initialize delay counters */
     DelayReached(&scroll_delay, 0);
@@ -3202,7 +3210,7 @@ static void DrawPreviewLevelExt(boolean restart)
        break;
     }
 
-    DrawPreviewLevelPlayfieldExt(from_x, from_y);
+    DrawPreviewLevelPlayfield(from_x, from_y);
   }
 
   /* !!! THIS ALL SUCKS -- SHOULD BE CLEANLY REWRITTEN !!! */
@@ -3243,7 +3251,7 @@ static void DrawPreviewLevelExt(boolean restart)
       label_state = (label_state == MICROLABEL_IMPORTED_FROM_HEAD ?
                     MICROLABEL_IMPORTED_BY_HEAD : MICROLABEL_IMPORTED_BY);
 
-    DrawPreviewLevelLabelExt(label_state);
+    DrawPreviewLevelLabel(label_state);
   }
 }
 
@@ -3762,12 +3770,10 @@ void WaitForEventToContinue()
 
   while (still_wait)
   {
-    if (PendingEvent())
-    {
-      Event event;
-
-      NextEvent(&event);
+    Event event;
 
+    if (NextValidEvent(&event))
+    {
       switch (event.type)
       {
        case EVENT_BUTTONPRESS:
@@ -4866,6 +4872,9 @@ unsigned int MoveDoor(unsigned int door_state)
        SkipUntilDelayReached(&door_delay, door_delay_value, &k, last_frame);
 
        current_move_delay += max_step_delay;
+
+       /* prevent OS (Windows) from complaining about program not responding */
+       CheckQuitEvent();
       }
 
       if (door_part_done_all)
@@ -8482,7 +8491,7 @@ void PlayMenuMusicExt(int music)
 void PlayMenuMusic()
 {
   char *curr_music = getCurrentlyPlayingMusicFilename();
-  char *next_music = getMusicListEntry(menu.music[game_status])->filename;
+  char *next_music = getMusicInfoEntryFilename(menu.music[game_status]);
 
   if (!strEqual(curr_music, next_music))
     PlayMenuMusicExt(menu.music[game_status]);
@@ -8502,7 +8511,7 @@ static void FadeMenuSounds()
 static void FadeMenuMusic()
 {
   char *curr_music = getCurrentlyPlayingMusicFilename();
-  char *next_music = getMusicListEntry(menu.music[game_status])->filename;
+  char *next_music = getMusicInfoEntryFilename(menu.music[game_status]);
 
   if (!strEqual(curr_music, next_music))
     FadeMusic();