changeset 19191:631c14db8f5a draft

(svn r24065) -Feature-ish [FS#5101]: debug option for showing the redrawn dirty blocks/rectangles
author rubidium <rubidium@openttd.org>
date Sun, 25 Mar 2012 19:06:59 +0000
parents 102959356aa1
children 25d3ab54cf2f
files src/gfx.cpp src/lang/english.txt src/main_gui.cpp src/toolbar_gui.cpp src/toolbar_gui.h src/viewport.cpp
diffstat 6 files changed, 55 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/gfx.cpp
+++ b/src/gfx.cpp
@@ -110,6 +110,7 @@
 
 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 @@
 		} 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;
--- a/src/lang/english.txt
+++ b/src/lang/english.txt
@@ -453,6 +453,7 @@
 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)
--- a/src/main_gui.cpp
+++ b/src/main_gui.cpp
@@ -217,6 +217,7 @@
 	GHK_ABANDON,
 	GHK_CONSOLE,
 	GHK_BOUNDING_BOXES,
+	GHK_DIRTY_BLOCKS,
 	GHK_CENTER,
 	GHK_CENTER_ZOOM,
 	GHK_RESET_OBJECT_TO_PLACE,
@@ -301,6 +302,10 @@
 			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>(_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),
--- a/src/toolbar_gui.cpp
+++ b/src/toolbar_gui.cpp
@@ -949,7 +949,7 @@
 
 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 @@
 }
 
 /**
+ * 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 @@
 		case  8: ShowAboutWindow();                break;
 		case  9: ShowSpriteAlignerWindow();        break;
 		case 10: ToggleBoundingBoxes();            break;
+		case 11: ToggleDirtyBlocks();              break;
 	}
 	return CBF_NONE;
 }
--- 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;
 
--- 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 @@
 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 @@
 	}
 }
 
+/**
+ * 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 @@
 	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);