+ Bitmap *fade_bitmap;
+ Bitmap *src_bitmap;
+ int src_x, src_y;
+ int dst_x, dst_y;
+ int graphic = IMG_GLOBAL_TILE_CURSOR;
+ int frame = 0;
+ int tilesize = TILESIZE_VAR;
+ int width = tilesize;
+ int height = tilesize;
+
+ if (game_status != GAME_MODE_PLAYING)
+ return;
+
+ if (!tile_cursor.enabled ||
+ !tile_cursor.active)
+ return;
+
+ if (tile_cursor.moving)
+ {
+ int step = TILESIZE_VAR / 4;
+ int dx = tile_cursor.target_x - tile_cursor.x;
+ int dy = tile_cursor.target_y - tile_cursor.y;
+
+ if (ABS(dx) < step)
+ tile_cursor.x = tile_cursor.target_x;
+ else
+ tile_cursor.x += SIGN(dx) * step;
+
+ if (ABS(dy) < step)
+ tile_cursor.y = tile_cursor.target_y;
+ else
+ tile_cursor.y += SIGN(dy) * step;
+
+ if (tile_cursor.x == tile_cursor.target_x &&
+ tile_cursor.y == tile_cursor.target_y)
+ tile_cursor.moving = FALSE;
+ }
+
+ dst_x = tile_cursor.x;
+ dst_y = tile_cursor.y;
+
+ frame = getGraphicAnimationFrame(graphic, -1);
+
+ getSizedGraphicSource(graphic, frame, tilesize, &src_bitmap, &src_x, &src_y);
+
+ fade_bitmap =
+ (draw_target == DRAW_TO_FADE_SOURCE ? gfx.fade_bitmap_source :
+ draw_target == DRAW_TO_FADE_TARGET ? gfx.fade_bitmap_target : NULL);
+
+ if (draw_target == DRAW_TO_SCREEN)
+ BlitToScreenMasked(src_bitmap, src_x, src_y, width, height, dst_x, dst_y);
+ else
+ BlitBitmapMasked(src_bitmap, fade_bitmap, src_x, src_y, width, height,
+ dst_x, dst_y);
+}
+
+void BlitScreenToBitmapExt_RND(Bitmap *target_bitmap, int fx, int fy)
+{
+ BlitBitmap(drawto_field, target_bitmap, fx, fy, SXSIZE, SYSIZE, SX, SY);
+}
+
+void BlitScreenToBitmap_RND(Bitmap *target_bitmap)
+{
+ int fx = getFieldbufferOffsetX_RND(ScreenMovDir, ScreenGfxPos);
+ int fy = getFieldbufferOffsetY_RND(ScreenMovDir, ScreenGfxPos);
+
+ BlitScreenToBitmapExt_RND(target_bitmap, fx, fy);
+}
+
+void BlitScreenToBitmap(Bitmap *target_bitmap)
+{
+ if (level.game_engine_type == GAME_ENGINE_TYPE_EM)
+ BlitScreenToBitmap_EM(target_bitmap);
+ else if (level.game_engine_type == GAME_ENGINE_TYPE_SP)
+ BlitScreenToBitmap_SP(target_bitmap);
+ else if (level.game_engine_type == GAME_ENGINE_TYPE_MM)
+ BlitScreenToBitmap_MM(target_bitmap);
+ else if (level.game_engine_type == GAME_ENGINE_TYPE_RND)
+ BlitScreenToBitmap_RND(target_bitmap);
+
+ redraw_mask |= REDRAW_FIELD;
+}
+
+static void DrawFramesPerSecond(void)
+{
+ char text[100];
+ int font_nr = FONT_TEXT_2;
+ int font_width = getFontWidth(font_nr);
+ int draw_deactivation_mask = GetDrawDeactivationMask();
+ boolean draw_masked = (draw_deactivation_mask == REDRAW_NONE);
+
+ // draw FPS with leading space (needed if field buffer deactivated)
+ sprintf(text, " %04.1f fps", global.frames_per_second);
+
+ // override draw deactivation mask (required for invisible warp mode)
+ SetDrawDeactivationMask(REDRAW_NONE);
+
+ // draw opaque FPS if field buffer deactivated, else draw masked FPS
+ DrawTextExt(backbuffer, SX + SXSIZE - font_width * strlen(text), SY, text,
+ font_nr, (draw_masked ? BLIT_MASKED : BLIT_OPAQUE));
+
+ // set draw deactivation mask to previous value
+ SetDrawDeactivationMask(draw_deactivation_mask);
+
+ // force full-screen redraw in this frame
+ redraw_mask = REDRAW_ALL;
+}
+
+#if DEBUG_FRAME_TIME
+static void PrintFrameTimeDebugging(void)
+{
+ static unsigned int last_counter = 0;
+ unsigned int counter = Counter();
+ int diff_1 = counter - last_counter;
+ int diff_2 = diff_1 - GAME_FRAME_DELAY;
+ int diff_2_max = 20;
+ int diff_2_cut = MIN(ABS(diff_2), diff_2_max);
+ char diff_bar[2 * diff_2_max + 5];
+ int pos = 0;
+ int i;
+
+ diff_bar[pos++] = (diff_2 < -diff_2_max ? '<' : ' ');
+
+ for (i = 0; i < diff_2_max; i++)
+ diff_bar[pos++] = (diff_2 >= 0 ? ' ' :
+ i >= diff_2_max - diff_2_cut ? '-' : ' ');
+
+ diff_bar[pos++] = '|';
+
+ for (i = 0; i < diff_2_max; i++)
+ diff_bar[pos++] = (diff_2 <= 0 ? ' ' : i < diff_2_cut ? '+' : ' ');
+
+ diff_bar[pos++] = (diff_2 > diff_2_max ? '>' : ' ');
+
+ diff_bar[pos++] = '\0';
+
+ Debug("time:frame", "%06d [%02d] [%c%02d] %s",
+ counter,
+ diff_1,
+ (diff_2 < 0 ? '-' : diff_2 > 0 ? '+' : ' '), ABS(diff_2),
+ diff_bar);
+
+ last_counter = counter;
+}
+#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(void)
+{
+ static int last_redraw_mask = REDRAW_NONE;
+
+ // force screen redraw in every frame to continue drawing global animations
+ // (but always use the last redraw mask to prevent unwanted side effects)
+ if (redraw_mask == REDRAW_NONE)
+ redraw_mask = last_redraw_mask;
+
+ last_redraw_mask = redraw_mask;
+
+#if 1
+ // masked border now drawn immediately when blitting backbuffer to window
+#else
+ // draw masked border to all viewports, if defined
+ DrawMaskedBorder(redraw_mask);
+#endif
+
+ // draw frames per second (only if debug mode is enabled)
+ 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;
+
+ /* although redrawing the whole window would be fine for normal gameplay,
+ being able to only redraw the playfield is required for deactivating
+ certain drawing areas (mainly playfield) to work, which is needed for
+ warp-forward to be fast enough (by skipping redraw of most frames) */
+
+ if (redraw_mask & REDRAW_ALL)
+ {
+ BlitBitmap(backbuffer, window, 0, 0, WIN_XSIZE, WIN_YSIZE, 0, 0);
+ }
+ else if (redraw_mask & REDRAW_FIELD)
+ {
+ BlitBitmap(backbuffer, window,
+ REAL_SX, REAL_SY, FULL_SXSIZE, FULL_SYSIZE, REAL_SX, REAL_SY);
+ }
+ else if (redraw_mask & REDRAW_DOORS)
+ {
+ // merge door areas to prevent calling screen redraw more than once
+ int x1 = WIN_XSIZE;
+ int y1 = WIN_YSIZE;
+ int x2 = 0;
+ int y2 = 0;
+
+ if (redraw_mask & REDRAW_DOOR_1)
+ {
+ x1 = MIN(x1, DX);
+ y1 = MIN(y1, DY);
+ x2 = MAX(x2, DX + DXSIZE);
+ y2 = MAX(y2, DY + DYSIZE);
+ }
+
+ if (redraw_mask & REDRAW_DOOR_2)
+ {
+ x1 = MIN(x1, VX);
+ y1 = MIN(y1, VY);
+ x2 = MAX(x2, VX + VXSIZE);
+ y2 = MAX(y2, VY + VYSIZE);
+ }
+
+ if (redraw_mask & REDRAW_DOOR_3)
+ {
+ x1 = MIN(x1, EX);
+ y1 = MIN(y1, EY);
+ x2 = MAX(x2, EX + EXSIZE);
+ y2 = MAX(y2, EY + EYSIZE);
+ }
+
+ // make sure that at least one pixel is blitted, and inside the screen
+ // (else nothing is blitted, causing the animations not to be updated)
+ x1 = MIN(MAX(0, x1), WIN_XSIZE - 1);
+ y1 = MIN(MAX(0, y1), WIN_YSIZE - 1);
+ x2 = MIN(MAX(1, x2), WIN_XSIZE);
+ y2 = MIN(MAX(1, y2), WIN_YSIZE);
+
+ BlitBitmap(backbuffer, window, x1, y1, x2 - x1, y2 - y1, x1, y1);
+ }
+
+ redraw_mask = REDRAW_NONE;
+
+#if DEBUG_FRAME_TIME
+ PrintFrameTimeDebugging();
+#endif
+}
+
+void BackToFront_WithFrameDelay(unsigned int frame_delay_value)
+{
+ unsigned int frame_delay_value_old = GetVideoFrameDelay();
+
+ SetVideoFrameDelay(frame_delay_value);
+
+ BackToFront();
+
+ SetVideoFrameDelay(frame_delay_value_old);
+}
+
+static int fade_type_skip = FADE_TYPE_NONE;
+
+static void FadeExt(int fade_mask, int fade_mode, int fade_type)
+{
+ void (*draw_border_function)(void) = NULL;
+ int x, y, width, height;
+ int fade_delay, post_delay;
+
+ if (fade_type == FADE_TYPE_FADE_OUT)
+ {
+ if (fade_type_skip != FADE_TYPE_NONE)
+ {
+ // skip all fade operations until specified fade operation
+ if (fade_type & fade_type_skip)
+ fade_type_skip = FADE_TYPE_NONE;
+
+ return;
+ }
+
+ if (fading.fade_mode & FADE_TYPE_TRANSFORM)
+ return;
+ }
+
+ redraw_mask |= fade_mask;
+
+ if (fade_type == FADE_TYPE_SKIP)
+ {
+ fade_type_skip = fade_mode;
+
+ return;
+ }
+
+ fade_delay = fading.fade_delay;
+ post_delay = (fade_mode == FADE_MODE_FADE_OUT ? fading.post_delay : 0);
+
+ if (fade_type_skip != FADE_TYPE_NONE)
+ {
+ // skip all fade operations until specified fade operation
+ if (fade_type & fade_type_skip)
+ fade_type_skip = FADE_TYPE_NONE;
+
+ fade_delay = 0;
+ }
+
+ if (global.autoplay_leveldir)
+ {
+ return;
+ }
+
+ if (fade_mask == REDRAW_FIELD)
+ {
+ x = FADE_SX;
+ y = FADE_SY;
+ width = FADE_SXSIZE;
+ height = FADE_SYSIZE;
+
+ if (border.draw_masked_when_fading)
+ draw_border_function = DrawMaskedBorder_FIELD; // update when fading
+ else
+ DrawMaskedBorder_FIELD(); // draw once
+ }
+ else // REDRAW_ALL
+ {
+ x = 0;
+ y = 0;
+ width = WIN_XSIZE;
+ height = WIN_YSIZE;
+ }
+
+ // when switching screens without fading, set fade delay to zero
+ if (!setup.fade_screens || fading.fade_mode == FADE_MODE_NONE)
+ fade_delay = 0;
+
+ // do not display black frame when fading out without fade delay
+ if (fade_mode == FADE_MODE_FADE_OUT && fade_delay == 0)
+ return;
+
+ FadeRectangle(x, y, width, height, fade_mode, fade_delay, post_delay,
+ draw_border_function);
+
+ redraw_mask &= ~fade_mask;
+
+ ClearAutoRepeatKeyEvents();
+}
+
+static void SetScreenStates_BeforeFadingIn(void)
+{
+ // temporarily set screen mode for animations to screen after fading in
+ global.anim_status = global.anim_status_next;
+
+ // store backbuffer with all animations that will be started after fading in
+ PrepareFadeBitmap(DRAW_TO_FADE_TARGET);
+
+ // set screen mode for animations back to fading
+ global.anim_status = GAME_MODE_PSEUDO_FADING;
+}
+
+static void SetScreenStates_AfterFadingIn(void)
+{
+ // store new source screen (to use correct masked border for fading)
+ gfx.fade_border_source_status = global.border_status;
+
+ global.anim_status = global.anim_status_next;
+}
+
+static void SetScreenStates_BeforeFadingOut(void)
+{
+ // store new target screen (to use correct masked border for fading)
+ gfx.fade_border_target_status = game_status;
+
+ // set screen mode for animations to fading
+ global.anim_status = GAME_MODE_PSEUDO_FADING;
+
+ // store backbuffer with all animations that will be stopped for fading out
+ PrepareFadeBitmap(DRAW_TO_FADE_SOURCE);
+}
+
+static void SetScreenStates_AfterFadingOut(void)
+{
+ global.border_status = game_status;
+}
+
+void FadeIn(int fade_mask)
+{
+ SetScreenStates_BeforeFadingIn();
+
+#if 1
+ DrawMaskedBorder(REDRAW_ALL);
+#endif
+
+ if (fading.fade_mode & FADE_TYPE_TRANSFORM)
+ FadeExt(fade_mask, fading.fade_mode, FADE_TYPE_FADE_IN);
+ else
+ FadeExt(fade_mask, FADE_MODE_FADE_IN, FADE_TYPE_FADE_IN);
+
+ FADE_SX = REAL_SX;
+ FADE_SY = REAL_SY;
+ FADE_SXSIZE = FULL_SXSIZE;
+ FADE_SYSIZE = FULL_SYSIZE;
+
+ // activate virtual buttons depending on upcoming game status
+ if (strEqual(setup.touch.control_type, TOUCH_CONTROL_VIRTUAL_BUTTONS) &&
+ game_status == GAME_MODE_PLAYING && !tape.playing)
+ SetOverlayActive(TRUE);
+
+ 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) &&
+ fade_type_skip != FADE_MODE_SKIP_FADE_OUT)
+ BackToFront();
+
+ SetScreenStates_BeforeFadingOut();
+
+ SetTileCursorActive(FALSE);
+ SetOverlayActive(FALSE);
+
+#if 0
+ DrawMaskedBorder(REDRAW_ALL);
+#endif
+
+ if (fading.fade_mode & FADE_TYPE_TRANSFORM)
+ FadeExt(fade_mask, fading.fade_mode, FADE_TYPE_FADE_OUT);
+ else
+ FadeExt(fade_mask, FADE_MODE_FADE_OUT, FADE_TYPE_FADE_OUT);
+
+ SetScreenStates_AfterFadingOut();
+}
+
+static void FadeSetLeaveNext(struct TitleFadingInfo fading_leave, boolean set)
+{
+ static struct TitleFadingInfo fading_leave_stored;
+
+ if (set)
+ fading_leave_stored = fading_leave;
+ else
+ fading = fading_leave_stored;
+}
+
+void FadeSetEnterMenu(void)
+{
+ fading = menu.enter_menu;
+
+ FadeSetLeaveNext(fading, TRUE); // (keep same fade mode)
+}
+
+void FadeSetLeaveMenu(void)
+{
+ fading = menu.leave_menu;
+
+ FadeSetLeaveNext(fading, TRUE); // (keep same fade mode)
+}
+
+void FadeSetEnterScreen(void)
+{
+ fading = menu.enter_screen[game_status];
+
+ FadeSetLeaveNext(menu.leave_screen[game_status], TRUE); // store
+}
+
+void FadeSetNextScreen(void)
+{
+ fading = menu.next_screen[game_status];
+
+ // (do not overwrite fade mode set by FadeSetEnterScreen)
+ // FadeSetLeaveNext(fading, TRUE); // (keep same fade mode)
+}
+
+void FadeSetLeaveScreen(void)
+{
+ FadeSetLeaveNext(menu.leave_screen[game_status], FALSE); // recall
+}
+
+void FadeSetFromType(int type)
+{
+ if (type & TYPE_ENTER_SCREEN)
+ FadeSetEnterScreen();
+ else if (type & TYPE_ENTER)
+ FadeSetEnterMenu();
+ else if (type & TYPE_LEAVE)
+ FadeSetLeaveMenu();
+}
+
+void FadeSetDisabled(void)
+{
+ static struct TitleFadingInfo fading_none = { FADE_MODE_NONE, -1, -1, -1 };
+
+ fading = fading_none;
+}
+
+void FadeSkipNextFadeIn(void)
+{
+ FadeExt(0, FADE_MODE_SKIP_FADE_IN, FADE_TYPE_SKIP);
+}
+
+void FadeSkipNextFadeOut(void)
+{
+ FadeExt(0, FADE_MODE_SKIP_FADE_OUT, FADE_TYPE_SKIP);
+}
+
+static Bitmap *getBitmapFromGraphicOrDefault(int graphic, int default_graphic)
+{
+ if (graphic == IMG_UNDEFINED)
+ return NULL;
+
+ boolean redefined = getImageListEntryFromImageID(graphic)->redefined;
+
+ return (graphic_info[graphic].bitmap != NULL || redefined ?
+ graphic_info[graphic].bitmap :
+ graphic_info[default_graphic].bitmap);
+}
+
+static Bitmap *getBackgroundBitmap(int graphic)
+{
+ return getBitmapFromGraphicOrDefault(graphic, IMG_BACKGROUND);
+}
+
+static Bitmap *getGlobalBorderBitmap(int graphic)
+{
+ return getBitmapFromGraphicOrDefault(graphic, IMG_GLOBAL_BORDER);
+}
+
+Bitmap *getGlobalBorderBitmapFromStatus(int status)
+{
+ int graphic =
+ (status == GAME_MODE_MAIN ||
+ status == GAME_MODE_PSEUDO_TYPENAME ? IMG_GLOBAL_BORDER_MAIN :
+ status == GAME_MODE_SCORES ? IMG_GLOBAL_BORDER_SCORES :
+ status == GAME_MODE_EDITOR ? IMG_GLOBAL_BORDER_EDITOR :
+ status == GAME_MODE_PLAYING ? IMG_GLOBAL_BORDER_PLAYING :
+ IMG_GLOBAL_BORDER);
+
+ return getGlobalBorderBitmap(graphic);
+}
+
+void SetWindowBackgroundImageIfDefined(int graphic)
+{
+ if (graphic_info[graphic].bitmap)
+ SetWindowBackgroundBitmap(graphic_info[graphic].bitmap);
+}
+
+void SetMainBackgroundImageIfDefined(int graphic)
+{
+ if (graphic_info[graphic].bitmap)
+ SetMainBackgroundBitmap(graphic_info[graphic].bitmap);
+}
+
+void SetDoorBackgroundImageIfDefined(int graphic)
+{
+ if (graphic_info[graphic].bitmap)
+ SetDoorBackgroundBitmap(graphic_info[graphic].bitmap);
+}
+
+void SetWindowBackgroundImage(int graphic)
+{
+ SetWindowBackgroundBitmap(getBackgroundBitmap(graphic));
+}
+
+void SetMainBackgroundImage(int graphic)
+{
+ SetMainBackgroundBitmap(getBackgroundBitmap(graphic));
+}
+
+void SetDoorBackgroundImage(int graphic)
+{
+ SetDoorBackgroundBitmap(getBackgroundBitmap(graphic));
+}
+
+void SetPanelBackground(void)
+{
+ struct GraphicInfo *gfx = &graphic_info[IMG_BACKGROUND_PANEL];
+
+ BlitBitmapTiled(gfx->bitmap, bitmap_db_panel, gfx->src_x, gfx->src_y,
+ gfx->width, gfx->height, 0, 0, DXSIZE, DYSIZE);
+
+ SetDoorBackgroundBitmap(bitmap_db_panel);
+}
+
+void DrawBackground(int x, int y, int width, int height)
+{
+ // "drawto" might still point to playfield buffer here (hall of fame)
+ ClearRectangleOnBackground(backbuffer, x, y, width, height);
+
+ if (IN_GFX_FIELD_FULL(x, y))
+ redraw_mask |= REDRAW_FIELD;
+ else if (IN_GFX_DOOR_1(x, y))
+ redraw_mask |= REDRAW_DOOR_1;
+ else if (IN_GFX_DOOR_2(x, y))
+ redraw_mask |= REDRAW_DOOR_2;
+ else if (IN_GFX_DOOR_3(x, y))
+ redraw_mask |= REDRAW_DOOR_3;
+}
+
+void DrawBackgroundForFont(int x, int y, int width, int height, int font_nr)
+{
+ struct FontBitmapInfo *font = getFontBitmapInfo(font_nr);
+
+ if (font->bitmap == NULL)
+ return;
+
+ DrawBackground(x, y, width, height);
+}
+
+void DrawBackgroundForGraphic(int x, int y, int width, int height, int graphic)
+{
+ struct GraphicInfo *g = &graphic_info[graphic];
+
+ if (g->bitmap == NULL)
+ return;
+
+ DrawBackground(x, y, width, height);
+}
+
+static int game_status_last = -1;
+static Bitmap *global_border_bitmap_last = NULL;
+static Bitmap *global_border_bitmap = NULL;
+static int real_sx_last = -1, real_sy_last = -1;
+static int full_sxsize_last = -1, full_sysize_last = -1;
+static int dx_last = -1, dy_last = -1;
+static int dxsize_last = -1, dysize_last = -1;
+static int vx_last = -1, vy_last = -1;
+static int vxsize_last = -1, vysize_last = -1;
+static int ex_last = -1, ey_last = -1;
+static int exsize_last = -1, eysize_last = -1;
+
+boolean CheckIfGlobalBorderHasChanged(void)
+{
+ // if game status has not changed, global border has not changed either
+ if (game_status == game_status_last)
+ return FALSE;
+
+ // determine and store new global border bitmap for current game status
+ global_border_bitmap = getGlobalBorderBitmapFromStatus(game_status);
+
+ return (global_border_bitmap_last != global_border_bitmap);
+}
+
+#define ONLY_REDRAW_GLOBAL_BORDER_IF_NEEDED 0
+
+#if ONLY_REDRAW_GLOBAL_BORDER_IF_NEEDED
+static boolean CheckIfGlobalBorderRedrawIsNeeded(void)
+{
+ // if game status has not changed, nothing has to be redrawn
+ if (game_status == game_status_last)
+ return FALSE;
+
+ // redraw if last screen was title screen
+ if (game_status_last == GAME_MODE_TITLE)
+ return TRUE;
+
+ // redraw if global screen border has changed
+ if (CheckIfGlobalBorderHasChanged())
+ return TRUE;
+
+ // redraw if position or size of playfield area has changed
+ if (real_sx_last != REAL_SX || real_sy_last != REAL_SY ||
+ full_sxsize_last != FULL_SXSIZE || full_sysize_last != FULL_SYSIZE)
+ return TRUE;
+
+ // redraw if position or size of door area has changed
+ if (dx_last != DX || dy_last != DY ||
+ dxsize_last != DXSIZE || dysize_last != DYSIZE)
+ return TRUE;
+
+ // redraw if position or size of tape area has changed
+ if (vx_last != VX || vy_last != VY ||
+ vxsize_last != VXSIZE || vysize_last != VYSIZE)
+ return TRUE;
+
+ // redraw if position or size of editor area has changed
+ if (ex_last != EX || ey_last != EY ||
+ exsize_last != EXSIZE || eysize_last != EYSIZE)
+ return TRUE;
+
+ return FALSE;
+}
+#endif
+
+static void RedrawGlobalBorderFromBitmap(Bitmap *bitmap)
+{
+ if (bitmap)
+ BlitBitmap(bitmap, backbuffer, 0, 0, WIN_XSIZE, WIN_YSIZE, 0, 0);
+ else
+ ClearRectangle(backbuffer, 0, 0, WIN_XSIZE, WIN_YSIZE);
+}
+
+void RedrawGlobalBorder(void)
+{
+ Bitmap *bitmap = getGlobalBorderBitmapFromStatus(game_status);
+
+ RedrawGlobalBorderFromBitmap(bitmap);
+
+ redraw_mask = REDRAW_ALL;
+}
+
+static void RedrawGlobalBorderIfNeeded(void)
+{
+#if ONLY_REDRAW_GLOBAL_BORDER_IF_NEEDED
+ if (game_status == game_status_last)
+ return;
+#endif
+
+ // copy current draw buffer to later copy back areas that have not changed
+ if (game_status_last != GAME_MODE_TITLE)
+ BlitBitmap(backbuffer, bitmap_db_store_1, 0, 0, WIN_XSIZE, WIN_YSIZE, 0, 0);
+
+#if ONLY_REDRAW_GLOBAL_BORDER_IF_NEEDED
+ if (CheckIfGlobalBorderRedrawIsNeeded())
+#else
+ // determine and store new global border bitmap for current game status
+ global_border_bitmap = getGlobalBorderBitmapFromStatus(game_status);
+#endif
+ {
+ // redraw global screen border (or clear, if defined to be empty)
+ RedrawGlobalBorderFromBitmap(global_border_bitmap);
+
+ if (game_status == GAME_MODE_EDITOR)
+ DrawSpecialEditorDoor();
+
+ // copy previous playfield and door areas, if they are defined on both
+ // previous and current screen and if they still have the same size
+
+ if (real_sx_last != -1 && real_sy_last != -1 &&
+ REAL_SX != -1 && REAL_SY != -1 &&
+ full_sxsize_last == FULL_SXSIZE && full_sysize_last == FULL_SYSIZE)
+ BlitBitmap(bitmap_db_store_1, backbuffer,
+ real_sx_last, real_sy_last, FULL_SXSIZE, FULL_SYSIZE,
+ REAL_SX, REAL_SY);
+
+ if (dx_last != -1 && dy_last != -1 &&
+ DX != -1 && DY != -1 &&
+ dxsize_last == DXSIZE && dysize_last == DYSIZE)
+ BlitBitmap(bitmap_db_store_1, backbuffer,
+ dx_last, dy_last, DXSIZE, DYSIZE, DX, DY);
+
+ if (game_status != GAME_MODE_EDITOR)
+ {
+ if (vx_last != -1 && vy_last != -1 &&
+ VX != -1 && VY != -1 &&
+ vxsize_last == VXSIZE && vysize_last == VYSIZE)
+ BlitBitmap(bitmap_db_store_1, backbuffer,
+ vx_last, vy_last, VXSIZE, VYSIZE, VX, VY);
+ }
+ else
+ {
+ if (ex_last != -1 && ey_last != -1 &&
+ EX != -1 && EY != -1 &&
+ exsize_last == EXSIZE && eysize_last == EYSIZE)
+ BlitBitmap(bitmap_db_store_1, backbuffer,
+ ex_last, ey_last, EXSIZE, EYSIZE, EX, EY);
+ }
+
+ redraw_mask = REDRAW_ALL;
+ }
+
+ game_status_last = game_status;
+
+ global_border_bitmap_last = global_border_bitmap;
+
+ real_sx_last = REAL_SX;
+ real_sy_last = REAL_SY;
+ full_sxsize_last = FULL_SXSIZE;
+ full_sysize_last = FULL_SYSIZE;
+ dx_last = DX;
+ dy_last = DY;
+ dxsize_last = DXSIZE;
+ dysize_last = DYSIZE;
+ vx_last = VX;
+ vy_last = VY;
+ vxsize_last = VXSIZE;
+ vysize_last = VYSIZE;
+ ex_last = EX;
+ ey_last = EY;
+ exsize_last = EXSIZE;
+ eysize_last = EYSIZE;
+}
+
+void ClearField(void)
+{
+ RedrawGlobalBorderIfNeeded();
+
+ // !!! "drawto" might still point to playfield buffer here (see above) !!!
+ // (when entering hall of fame after playing)
+ DrawBackground(REAL_SX, REAL_SY, FULL_SXSIZE, FULL_SYSIZE);
+
+ // !!! maybe this should be done before clearing the background !!!
+ if (game_status == GAME_MODE_PLAYING)
+ {
+ ClearRectangle(fieldbuffer, 0, 0, FXSIZE, FYSIZE);
+ SetDrawtoField(DRAW_TO_FIELDBUFFER);
+ }
+ else
+ {
+ SetDrawtoField(DRAW_TO_BACKBUFFER);
+ }
+}
+
+void MarkTileDirty(int x, int y)
+{
+ redraw_mask |= REDRAW_FIELD;
+}
+
+void SetBorderElement(void)
+{
+ int x, y;
+
+ BorderElement = EL_EMPTY;
+
+ // only the R'n'D game engine may use an additional steelwall border
+ if (level.game_engine_type != GAME_ENGINE_TYPE_RND)
+ return;
+