Changeset - r19177:5af5e9926930
[Not reviewed]
master
0 6 0
rubidium - 12 years ago 2012-03-25 19:06:59
rubidium@openttd.org
(svn r24065) -Feature-ish [FS#5101]: debug option for showing the redrawn dirty blocks/rectangles
6 files changed with 55 insertions and 1 deletions:
0 comments (0 inline, 0 general)
src/gfx.cpp
Show inline comments
 
@@ -107,12 +107,13 @@ static byte _string_colourremap[3]; ///<
 

	
 
static const uint DIRTY_BLOCK_HEIGHT   = 8;
 
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)
 
{
 
	Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter();
 

	
 
	if (xo == 0 && yo == 0) return;
 
@@ -1804,12 +1805,13 @@ 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;
 
	_invalid_rect.bottom = 0;
 
}
 

	
src/lang/english.txt
Show inline comments
 
@@ -450,12 +450,13 @@ STR_ABOUT_MENU_SCREENSHOT               
 
STR_ABOUT_MENU_ZOOMIN_SCREENSHOT                                :Fully zoomed in screenshot
 
STR_ABOUT_MENU_DEFAULTZOOM_SCREENSHOT                           :Default zoom screenshot
 
STR_ABOUT_MENU_GIANT_SCREENSHOT                                 :Whole map 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)
 
STR_ORDINAL_NUMBER_1ST                                          :1st
 
STR_ORDINAL_NUMBER_2ND                                          :2nd
 
STR_ORDINAL_NUMBER_3RD                                          :3rd
src/main_gui.cpp
Show inline comments
 
@@ -214,12 +214,13 @@ static const WindowDesc _main_window_des
 

	
 
enum {
 
	GHK_QUIT,
 
	GHK_ABANDON,
 
	GHK_CONSOLE,
 
	GHK_BOUNDING_BOXES,
 
	GHK_DIRTY_BLOCKS,
 
	GHK_CENTER,
 
	GHK_CENTER_ZOOM,
 
	GHK_RESET_OBJECT_TO_PLACE,
 
	GHK_DELETE_WINDOWS,
 
	GHK_DELETE_NONVITAL_WINDOWS,
 
	GHK_REFRESH_SCREEN,
 
@@ -298,12 +299,16 @@ struct MainWindow : Window
 
				IConsoleSwitch();
 
				return ES_HANDLED;
 

	
 
			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;
 

	
 
		switch (num) {
 
			case GHK_CENTER:
 
@@ -452,12 +457,13 @@ const uint16 _ghk_chat_server_keys[] = {
 

	
 
Hotkey<MainWindow> MainWindow::global_hotkeys[] = {
 
	Hotkey<MainWindow>(_ghk_quit_keys, "quit", GHK_QUIT),
 
	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),
 
	Hotkey<MainWindow>(WKC_DELETE, "delete_windows", GHK_DELETE_WINDOWS),
 
	Hotkey<MainWindow>(WKC_DELETE | WKC_SHIFT, "delete_all_windows", GHK_DELETE_NONVITAL_WINDOWS),
 
	Hotkey<MainWindow>('R' | WKC_CTRL, "refresh_screen", GHK_REFRESH_SCREEN),
src/toolbar_gui.cpp
Show inline comments
 
@@ -946,13 +946,13 @@ static CallBackFunction PlaceLandBlockIn
 
		return CBF_PLACE_LANDINFO;
 
	}
 
}
 

	
 
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;
 
}
 

	
 
static void MenuClickSmallScreenshot()
 
{
 
	MakeScreenshot(SC_VIEWPORT, NULL);
 
@@ -988,12 +988,29 @@ void ToggleBoundingBoxes()
 
		_draw_bounding_boxes = !_draw_bounding_boxes;
 
		MarkWholeScreenDirty();
 
	}
 
}
 

	
 
/**
 
 * 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
 
 */
 
static CallBackFunction MenuClickHelp(int index)
 
{
 
@@ -1005,12 +1022,13 @@ static CallBackFunction MenuClickHelp(in
 
		case  5: MenuClickZoomedInScreenshot();    break;
 
		case  6: MenuClickDefaultZoomScreenshot(); break;
 
		case  7: MenuClickWorldScreenshot();       break;
 
		case  8: ShowAboutWindow();                break;
 
		case  9: ShowSpriteAlignerWindow();        break;
 
		case 10: ToggleBoundingBoxes();            break;
 
		case 11: ToggleDirtyBlocks();              break;
 
	}
 
	return CBF_NONE;
 
}
 

	
 
/* --- Switch toolbar button --- */
 

	
src/toolbar_gui.h
Show inline comments
 
@@ -11,10 +11,11 @@
 

	
 
#ifndef TOOLBAR_GUI_H
 
#define TOOLBAR_GUI_H
 

	
 
void AllocateToolbar();
 
void ToggleBoundingBoxes();
 
void ToggleDirtyBlocks();
 

	
 
extern int16 *_preferred_toolbar_size;
 

	
 
#endif /* TOOLBAR_GUI_H */
src/viewport.cpp
Show inline comments
 
@@ -44,12 +44,13 @@
 
#include "waypoint_func.h"
 
#include "window_func.h"
 
#include "tilehighlight_func.h"
 
#include "window_gui.h"
 

	
 
#include "table/strings.h"
 
#include "table/palettes.h"
 

	
 
Point _tile_fract_coords;
 

	
 
struct StringSpriteToDraw {
 
	StringID string;
 
	Colours colour;
 
@@ -145,12 +146,14 @@ struct ViewportDrawer {
 

	
 
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)
 
{
 
	Point p = RemapCoords(x, y, z);
 
	p.x -= vp->virtual_width / 2;
 
	p.y -= vp->virtual_height / 2;
 
@@ -1358,12 +1361,34 @@ static void ViewportDrawBoundingBoxes(co
 
		        pt2.x - pt1.x, pt2.y - pt1.y,
 
		        pt3.x - pt1.x, pt3.y - pt1.y,
 
		        pt4.x - pt1.x, pt4.y - pt1.y);
 
	}
 
}
 

	
 
/**
 
 * 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;
 
	ZoomLevel zoom;
 

	
 
	_cur_dpi = &dp;
 
@@ -1454,12 +1479,13 @@ void ViewportDoDraw(const ViewPort *vp, 
 
	}
 

	
 
	ViewportSortParentSprites(&_vd.parent_sprites_to_sort);
 
	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);
 

	
 
	_cur_dpi = old_dpi;
 

	
 
	_vd.string_sprites_to_draw.Clear();
0 comments (0 inline, 0 general)