# HG changeset patch # User rubidium # Date 2012-03-25 19:06:59 # Node ID 5af5e99269303caee55d37ec960fae19a55be14b # Parent dfdbe5936610d16b10ae448c77c369e5d8f358ce (svn r24065) -Feature-ish [FS#5101]: debug option for showing the redrawn dirty blocks/rectangles diff --git a/src/gfx.cpp b/src/gfx.cpp --- a/src/gfx.cpp +++ b/src/gfx.cpp @@ -110,6 +110,7 @@ static const uint DIRTY_BLOCK_WIDTH = static uint _dirty_bytes_per_line = 0; static byte *_dirty_blocks = NULL; +extern uint _dirty_block_colour; void GfxScroll(int left, int top, int width, int height, int xo, int yo) { @@ -1807,6 +1808,7 @@ void DrawDirtyBlocks() } while (b++, (x += DIRTY_BLOCK_WIDTH) != w); } while (b += -(int)(w / DIRTY_BLOCK_WIDTH) + _dirty_bytes_per_line, (y += DIRTY_BLOCK_HEIGHT) != h); + ++_dirty_block_colour; _invalid_rect.left = w; _invalid_rect.top = h; _invalid_rect.right = 0; diff --git a/src/lang/english.txt b/src/lang/english.txt --- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -453,6 +453,7 @@ STR_ABOUT_MENU_GIANT_SCREENSHOT STR_ABOUT_MENU_ABOUT_OPENTTD :About 'OpenTTD' STR_ABOUT_MENU_SPRITE_ALIGNER :Sprite aligner STR_ABOUT_MENU_TOGGLE_BOUNDING_BOXES :Toggle bounding boxes +STR_ABOUT_MENU_TOGGLE_DIRTY_BLOCKS :Toggle colouring of dirty blocks ############ range ends here ############ range for days starts (also used for the place in the highscore window) diff --git a/src/main_gui.cpp b/src/main_gui.cpp --- a/src/main_gui.cpp +++ b/src/main_gui.cpp @@ -217,6 +217,7 @@ enum { GHK_ABANDON, GHK_CONSOLE, GHK_BOUNDING_BOXES, + GHK_DIRTY_BLOCKS, GHK_CENTER, GHK_CENTER_ZOOM, GHK_RESET_OBJECT_TO_PLACE, @@ -301,6 +302,10 @@ struct MainWindow : Window case GHK_BOUNDING_BOXES: ToggleBoundingBoxes(); return ES_HANDLED; + + case GHK_DIRTY_BLOCKS: + ToggleDirtyBlocks(); + return ES_HANDLED; } if (_game_mode == GM_MENU) return ES_NOT_HANDLED; @@ -455,6 +460,7 @@ Hotkey MainWindow::global_ho Hotkey(_ghk_abandon_keys, "abandon", GHK_ABANDON), Hotkey(WKC_BACKQUOTE, "console", GHK_CONSOLE), Hotkey('B' | WKC_CTRL, "bounding_boxes", GHK_BOUNDING_BOXES), + Hotkey('I' | WKC_CTRL, "dirty_blocks", GHK_DIRTY_BLOCKS), Hotkey('C', "center", GHK_CENTER), Hotkey('Z', "center_zoom", GHK_CENTER_ZOOM), Hotkey(WKC_ESC, "reset_object_to_place", GHK_RESET_OBJECT_TO_PLACE), diff --git a/src/toolbar_gui.cpp b/src/toolbar_gui.cpp --- a/src/toolbar_gui.cpp +++ b/src/toolbar_gui.cpp @@ -949,7 +949,7 @@ static CallBackFunction PlaceLandBlockIn static CallBackFunction ToolbarHelpClick(Window *w) { - PopupMainToolbMenu(w, WID_TN_HELP, STR_ABOUT_MENU_LAND_BLOCK_INFO, _settings_client.gui.newgrf_developer_tools ? 11 : 9); + PopupMainToolbMenu(w, WID_TN_HELP, STR_ABOUT_MENU_LAND_BLOCK_INFO, _settings_client.gui.newgrf_developer_tools ? 12 : 9); return CBF_NONE; } @@ -991,6 +991,23 @@ void ToggleBoundingBoxes() } /** + * Toggle drawing of the dirty blocks. + * @note has only an effect when newgrf_developer_tools are active. + * + * Function is found here and not in viewport.cpp in order to avoid + * importing the settings structs to there. + */ +void ToggleDirtyBlocks() +{ + extern bool _draw_dirty_blocks; + /* Always allow to toggle them off */ + if (_settings_client.gui.newgrf_developer_tools || _draw_dirty_blocks) { + _draw_dirty_blocks = !_draw_dirty_blocks; + MarkWholeScreenDirty(); + } +} + +/** * Choose the proper callback function for the main toolbar's help menu. * @param index The menu index which was selected. * @return CBF_NONE @@ -1008,6 +1025,7 @@ static CallBackFunction MenuClickHelp(in case 8: ShowAboutWindow(); break; case 9: ShowSpriteAlignerWindow(); break; case 10: ToggleBoundingBoxes(); break; + case 11: ToggleDirtyBlocks(); break; } return CBF_NONE; } diff --git a/src/toolbar_gui.h b/src/toolbar_gui.h --- a/src/toolbar_gui.h +++ b/src/toolbar_gui.h @@ -14,6 +14,7 @@ void AllocateToolbar(); void ToggleBoundingBoxes(); +void ToggleDirtyBlocks(); extern int16 *_preferred_toolbar_size; diff --git a/src/viewport.cpp b/src/viewport.cpp --- a/src/viewport.cpp +++ b/src/viewport.cpp @@ -47,6 +47,7 @@ #include "window_gui.h" #include "table/strings.h" +#include "table/palettes.h" Point _tile_fract_coords; @@ -148,6 +149,8 @@ static ViewportDrawer _vd; TileHighlightData _thd; static TileInfo *_cur_ti; bool _draw_bounding_boxes = false; +bool _draw_dirty_blocks = false; +uint _dirty_block_colour = 0; static Point MapXYZToViewport(const ViewPort *vp, int x, int y, int z) { @@ -1361,6 +1364,28 @@ static void ViewportDrawBoundingBoxes(co } } +/** + * Draw/colour the blocks that have been redrawn. + */ +static void ViewportDrawDirtyBlocks() +{ + Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter(); + const DrawPixelInfo *dpi = _cur_dpi; + void *dst; + int right = UnScaleByZoom(dpi->width, dpi->zoom); + int bottom = UnScaleByZoom(dpi->height, dpi->zoom); + + int colour = _string_colourmap[_dirty_block_colour & 0xF]; + + dst = dpi->dst_ptr; + + byte bo = UnScaleByZoom(dpi->left + dpi->top, dpi->zoom) & 1; + do { + for (int i = (bo ^= 1); i < right; i += 2) blitter->SetPixel(dst, i, 0, (uint8)colour); + dst = blitter->MoveTo(dst, 0, 1); + } while (--bottom > 0); +} + static void ViewportDrawStrings(DrawPixelInfo *dpi, const StringSpriteToDrawVector *sstdv) { DrawPixelInfo dp; @@ -1457,6 +1482,7 @@ void ViewportDoDraw(const ViewPort *vp, ViewportDrawParentSprites(&_vd.parent_sprites_to_sort, &_vd.child_screen_sprites_to_draw); if (_draw_bounding_boxes) ViewportDrawBoundingBoxes(&_vd.parent_sprites_to_sort); + if (_draw_dirty_blocks) ViewportDrawDirtyBlocks(); if (_vd.string_sprites_to_draw.Length() != 0) ViewportDrawStrings(&_vd.dpi, &_vd.string_sprites_to_draw);