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
 
@@ -101,24 +101,25 @@ static ReusableBuffer<uint8> _cursor_bac
 
 *
 
 * @ingroup dirty
 
 */
 
static Rect _invalid_rect;
 
static const byte *_colour_remap_ptr;
 
static byte _string_colourremap[3]; ///< Recoloursprite for stringdrawing. The grf loader ensures that #ST_FONT sprites only use colours 0 to 2.
 

	
 
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;
 

	
 
	if (_cursor.visible) UndrawMouseCursor();
 

	
 
#ifdef ENABLE_NETWORK
 
	if (_networking) NetworkUndrawChatMessage();
 
#endif /* ENABLE_NETWORK */
 
@@ -1798,24 +1799,25 @@ void DrawDirtyBlocks()
 
				if (top    < _invalid_rect.top   ) top    = _invalid_rect.top;
 
				if (right  > _invalid_rect.right ) right  = _invalid_rect.right;
 
				if (bottom > _invalid_rect.bottom) bottom = _invalid_rect.bottom;
 

	
 
				if (left < right && top < bottom) {
 
					RedrawScreenRect(left, top, right, bottom);
 
				}
 

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

	
 
/**
 
 * This function extends the internal _invalid_rect rectangle as it
 
 * now contains the rectangle defined by the given parameters. Note
 
 * the point (0,0) is top left.
 
 *
 
 * @param left The left edge of the rectangle
src/lang/english.txt
Show inline comments
 
@@ -444,24 +444,25 @@ STR_NEWS_MENU_MESSAGE_HISTORY_MENU      
 
############ range for about menu starts
 
STR_ABOUT_MENU_LAND_BLOCK_INFO                                  :Land area information
 
STR_ABOUT_MENU_SEPARATOR                                        :
 
STR_ABOUT_MENU_TOGGLE_CONSOLE                                   :Toggle console
 
STR_ABOUT_MENU_AI_DEBUG                                         :AI/Game script debug
 
STR_ABOUT_MENU_SCREENSHOT                                       :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
 
STR_ORDINAL_NUMBER_4TH                                          :4th
 
STR_ORDINAL_NUMBER_5TH                                          :5th
 
STR_ORDINAL_NUMBER_6TH                                          :6th
 
STR_ORDINAL_NUMBER_7TH                                          :7th
 
STR_ORDINAL_NUMBER_8TH                                          :8th
 
STR_ORDINAL_NUMBER_9TH                                          :9th
src/main_gui.cpp
Show inline comments
 
@@ -208,24 +208,25 @@ static const struct NWidgetPart _nested_
 
static const WindowDesc _main_window_desc(
 
	WDP_MANUAL, 0, 0,
 
	WC_MAIN_WINDOW, WC_NONE,
 
	0,
 
	_nested_main_window_widgets, lengthof(_nested_main_window_widgets)
 
);
 

	
 
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,
 
	GHK_CRASH,
 
	GHK_MONEY,
 
	GHK_UPDATE_COORDS,
 
	GHK_TOGGLE_TRANSPARENCY,
 
	GHK_TOGGLE_INVISIBILITY = GHK_TOGGLE_TRANSPARENCY + 9,
 
	GHK_TRANSPARENCY_TOOLBAR = GHK_TOGGLE_INVISIBILITY + 8,
 
@@ -292,24 +293,28 @@ struct MainWindow : Window
 
				} else {
 
					AskExitToGameMenu();
 
				}
 
				return ES_HANDLED;
 

	
 
			case GHK_CONSOLE:
 
				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:
 
			case GHK_CENTER_ZOOM: {
 
				Point pt = GetTileBelowCursor();
 
				if (pt.x != -1) {
 
					bool instant = (num == GHK_CENTER_ZOOM && this->viewport->zoom != _settings_client.gui.zoom_min);
 
					if (num == GHK_CENTER_ZOOM) MaxZoomInOut(ZOOM_IN, this);
 
					ScrollMainWindowTo(pt.x, pt.y, -1, instant);
 
@@ -446,24 +451,25 @@ struct MainWindow : Window
 
const uint16 _ghk_quit_keys[] = {'Q' | WKC_CTRL, 'Q' | WKC_META, 0};
 
const uint16 _ghk_abandon_keys[] = {'W' | WKC_CTRL, 'W' | WKC_META, 0};
 
const uint16 _ghk_chat_keys[] = {WKC_RETURN, 'T', 0};
 
const uint16 _ghk_chat_all_keys[] = {WKC_SHIFT | WKC_RETURN, WKC_SHIFT | 'T', 0};
 
const uint16 _ghk_chat_company_keys[] = {WKC_CTRL | WKC_RETURN, WKC_CTRL | 'T', 0};
 
const uint16 _ghk_chat_server_keys[] = {WKC_CTRL | WKC_SHIFT | WKC_RETURN, WKC_CTRL | WKC_SHIFT | 'T', 0};
 

	
 
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),
 
#if defined(_DEBUG)
 
	Hotkey<MainWindow>('0' | WKC_ALT, "crash_game", GHK_CRASH),
 
	Hotkey<MainWindow>('1' | WKC_ALT, "money", GHK_MONEY),
 
	Hotkey<MainWindow>('2' | WKC_ALT, "update_coordinates", GHK_UPDATE_COORDS),
 
#endif
 
	Hotkey<MainWindow>('1' | WKC_CTRL, "transparency_signs", GHK_TOGGLE_TRANSPARENCY),
src/toolbar_gui.cpp
Show inline comments
 
@@ -940,25 +940,25 @@ static CallBackFunction PlaceLandBlockIn
 
{
 
	if (_cursor.sprite == SPR_CURSOR_QUERY) {
 
		ResetObjectToPlace();
 
		return CBF_NONE;
 
	} else {
 
		SetObjectToPlace(SPR_CURSOR_QUERY, PAL_NONE, HT_RECT, WC_MAIN_TOOLBAR, 0);
 
		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);
 
}
 

	
 
static void MenuClickZoomedInScreenshot()
 
{
 
	MakeScreenshot(SC_ZOOMEDIN, NULL);
 
}
 
@@ -982,41 +982,59 @@ static void MenuClickWorldScreenshot()
 
 */
 
void ToggleBoundingBoxes()
 
{
 
	extern bool _draw_bounding_boxes;
 
	/* Always allow to toggle them off */
 
	if (_settings_client.gui.newgrf_developer_tools || _draw_bounding_boxes) {
 
		_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)
 
{
 
	switch (index) {
 
		case  0: return PlaceLandBlockInfo();
 
		case  2: IConsoleSwitch();                 break;
 
		case  3: ShowAIDebugWindow();              break;
 
		case  4: MenuClickSmallScreenshot();       break;
 
		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 --- */
 

	
 
static CallBackFunction ToolbarSwitchClick(Window *w)
 
{
 
	if (_toolbar_mode != TB_LOWER) {
 
		_toolbar_mode = TB_LOWER;
 
	} else {
 
		_toolbar_mode = TB_UPPER;
src/toolbar_gui.h
Show inline comments
 
@@ -5,16 +5,17 @@
 
 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
 
 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
 
 */
 

	
 
/** @file toolbar_gui.h Stuff related to the (main) toolbar. */
 

	
 
#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
 
@@ -38,24 +38,25 @@
 
#include "vehicle_gui.h"
 
#include "blitter/factory.hpp"
 
#include "strings_func.h"
 
#include "zoom_func.h"
 
#include "vehicle_func.h"
 
#include "company_func.h"
 
#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;
 
	int32 x;
 
	int32 y;
 
	uint64 params[2];
 
	uint16 width;
 
};
 

	
 
@@ -139,24 +140,26 @@ struct ViewportDrawer {
 

	
 
	int foundation[FOUNDATION_PART_END];             ///< Foundation sprites (index into parent_sprites_to_draw).
 
	FoundationPart foundation_part;                  ///< Currently active foundation for ground sprite drawing.
 
	int *last_foundation_child[FOUNDATION_PART_END]; ///< Tail of ChildSprite list of the foundations. (index into child_screen_sprites_to_draw)
 
	Point foundation_offset[FOUNDATION_PART_END];    ///< Pixel offset for ground sprites on the foundations.
 
};
 

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

	
 
void DeleteWindowViewport(Window *w)
 
{
 
	free(w->viewport);
 
@@ -1352,24 +1355,46 @@ static void ViewportDrawBoundingBoxes(co
 
		Point pt1 = RemapCoords(ps->xmax + 1, ps->ymax + 1, ps->zmax + 1); // top front corner
 
		Point pt2 = RemapCoords(ps->xmin    , ps->ymax + 1, ps->zmax + 1); // top left corner
 
		Point pt3 = RemapCoords(ps->xmax + 1, ps->ymin    , ps->zmax + 1); // top right corner
 
		Point pt4 = RemapCoords(ps->xmax + 1, ps->ymax + 1, ps->zmin    ); // bottom front corner
 

	
 
		DrawBox(        pt1.x,         pt1.y,
 
		        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;
 
	dp = *dpi;
 

	
 
	zoom = dp.zoom;
 
	dp.zoom = ZOOM_LVL_NORMAL;
 

	
 
	dp.left   = UnScaleByZoom(dp.left,   zoom);
 
@@ -1448,24 +1473,25 @@ void ViewportDoDraw(const ViewPort *vp, 
 

	
 
	if (_vd.tile_sprites_to_draw.Length() != 0) ViewportDrawTileSprites(&_vd.tile_sprites_to_draw);
 

	
 
	ParentSpriteToDraw *psd_end = _vd.parent_sprites_to_draw.End();
 
	for (ParentSpriteToDraw *it = _vd.parent_sprites_to_draw.Begin(); it != psd_end; it++) {
 
		*_vd.parent_sprites_to_sort.Append() = it;
 
	}
 

	
 
	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();
 
	_vd.tile_sprites_to_draw.Clear();
 
	_vd.parent_sprites_to_draw.Clear();
 
	_vd.parent_sprites_to_sort.Clear();
 
	_vd.child_screen_sprites_to_draw.Clear();
 
}
 

	
0 comments (0 inline, 0 general)