diff options
author | rubidium <rubidium@openttd.org> | 2012-03-25 19:06:59 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2012-03-25 19:06:59 +0000 |
commit | 927734e6ce825f6b34380f73a2e73c74591dd16e (patch) | |
tree | c63e9e557e47cb68aff12e8ee01e8e41574ea900 /src | |
parent | c8ce0faca49f85bbe72a3257bc327d14208f3d6c (diff) | |
download | openttd-927734e6ce825f6b34380f73a2e73c74591dd16e.tar.xz |
(svn r24065) -Feature-ish [FS#5101]: debug option for showing the redrawn dirty blocks/rectangles
Diffstat (limited to 'src')
-rw-r--r-- | src/gfx.cpp | 2 | ||||
-rw-r--r-- | src/lang/english.txt | 1 | ||||
-rw-r--r-- | src/main_gui.cpp | 6 | ||||
-rw-r--r-- | src/toolbar_gui.cpp | 20 | ||||
-rw-r--r-- | src/toolbar_gui.h | 1 | ||||
-rw-r--r-- | src/viewport.cpp | 26 |
6 files changed, 55 insertions, 1 deletions
diff --git a/src/gfx.cpp b/src/gfx.cpp index 63baa999d..93335de8a 100644 --- a/src/gfx.cpp +++ b/src/gfx.cpp @@ -110,6 +110,7 @@ static const uint DIRTY_BLOCK_WIDTH = 64; 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 index 7397c1d4a..0b06eeaf3 100644 --- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -453,6 +453,7 @@ STR_ABOUT_MENU_GIANT_SCREENSHOT :Whole map scree 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 index 04dbd3533..3e8a7d778 100644 --- 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> MainWindow::global_hotkeys[] = { Hotkey<MainWindow>(_ghk_abandon_keys, "abandon", GHK_ABANDON), Hotkey<MainWindow>(WKC_BACKQUOTE, "console", GHK_CONSOLE), Hotkey<MainWindow>('B' | WKC_CTRL, "bounding_boxes", GHK_BOUNDING_BOXES), + Hotkey<MainWindow>('I' | WKC_CTRL, "dirty_blocks", GHK_DIRTY_BLOCKS), Hotkey<MainWindow>('C', "center", GHK_CENTER), Hotkey<MainWindow>('Z', "center_zoom", GHK_CENTER_ZOOM), Hotkey<MainWindow>(WKC_ESC, "reset_object_to_place", GHK_RESET_OBJECT_TO_PLACE), diff --git a/src/toolbar_gui.cpp b/src/toolbar_gui.cpp index 423dba436..31613f2e9 100644 --- a/src/toolbar_gui.cpp +++ b/src/toolbar_gui.cpp @@ -949,7 +949,7 @@ static CallBackFunction PlaceLandBlockInfo() 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(int index) 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 index 59c7c6efb..1d5390048 100644 --- 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 index 2f134056f..3cce19c3b 100644 --- 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(const ParentSpriteToSortVector *psd) } } +/** + * 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, int left, int top, int right, int bottom 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); |