mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-12 10:30:28 +00:00
(svn r24065) -Feature-ish [FS#5101]: debug option for showing the redrawn dirty blocks/rectangles
This commit is contained in:
parent
c8ce0faca4
commit
927734e6ce
@ -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;
|
||||
|
@ -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)
|
||||
|
@ -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),
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
@ -990,6 +990,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.
|
||||
@ -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;
|
||||
}
|
||||
|
@ -14,6 +14,7 @@
|
||||
|
||||
void AllocateToolbar();
|
||||
void ToggleBoundingBoxes();
|
||||
void ToggleDirtyBlocks();
|
||||
|
||||
extern int16 *_preferred_toolbar_size;
|
||||
|
||||
|
@ -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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user