# Dirty

Handles the repaint of some part of the screen. More...

## Functions
void | MarkTileDirty (int x, int y)
| Mark a tile given by its coordinate dirty for repaint.
void | MarkTileDirtyByTile (TileIndex tile)
| Mark a tile given by its index dirty for repaint.
void | MarkAllViewportsDirty (int left, int top, int right, int bottom)
| Mark all viewports dirty for repaint.
void | DrawDirtyBlocks ()
| Let the dirty blocks repainting by the video driver.
void | SetDirtyBlocks (int left, int top, int right, int bottom)
| Set a new dirty block.
void | MarkWholeScreenDirty ()
| Marks the whole screen as dirty.
void | MarkSignDirty (Sign *si)
| Marks the region of a sign as dirty.
void | Station::MarkDirty () const
| Mark the sign of a station dirty for repaint.
void | Station::MarkTilesDirty (bool cargo_change) const
| Marks the tiles of the station as dirty.
static void | UpdateStationVirtCoordDirty (Station *st)
| Update the station virt coords while making the modified parts dirty.
static void | TerraformAddDirtyTile (TerraformerState *ts, TileIndex tile)
| Adds a tile to the "tile_table" in a TerraformerState.
static void | TerraformAddDirtyTileAround (TerraformerState *ts, TileIndex tile)
| Adds all tiles that incident with the north corner of a specific tile to the "tile_table" in a TerraformerState.
static void | MarkTextEffectAreaDirty (TextEffect *te)
| Mark the area of the text effect as dirty.
static void | MarkTownSignDirty (Town *t)
| Marks the town sign as needing a repaint.
virtual void | Vehicle::MarkDirty ()
| Marks the vehicles to be redrawn and updates cached variables.
static void | MarkViewportDirty (const ViewPort *vp, int left, int top, int right, int bottom)
| Marks a viewport as dirty for repaint if it displays (a part of) the area the needs to be repainted.
static void | SetSelectionTilesDirty ()
| Marks the selected tiles as dirty.
static void | MarkCanalsAndRiversAroundDirty (TileIndex tile)
| Marks the tiles around a tile as dirty, if they are canals or rivers.
void | SetWindowDirty (const Window *w)
| Mark entire window as dirty (in need of re-paint).
void | Window::SetDirty () const
| Mark entire window as dirty (in need of re-paint).
## Variables
static Rect | _invalid_rect
| The rect for repaint.
TileIndex | TerraformerState::tile_table [TERRAFORMER_TILE_TABLE_SIZE]
| Dirty tiles, i.e. at least one corner changed.

## Detailed Description

Handles the repaint of some part of the screen.

Some places in the code are called functions which makes something "dirty". This has nothing to do with making a Tile or Window darker or less visible. This term comes from memory caching and is used to define an object must be repaint. If some data of an object (like a Tile, Window, Vehicle, whatever) are changed which are so extensive the object must be repaint its marked as "dirty". The video driver repaint this object instead of the whole screen (this is btw. also possible if needed). This is used to avoid a flickering of the screen by the video driver constantly repainting it.

This whole mechanism is controlled by an rectangle defined in _invalid_rect. This rectangle defines the area on the screen which must be repaint. If a new object needs to be repainted this rectangle is extended to 'catch' the object on the screen. At some point (which is normaly uninteressted for patch writers) this rectangle is send to the video drivers method VideoDriver::MakeDirty and it is truncated back to an empty rectangle. At some later point (which is uninteressted, too) the video driver repaints all these saved rectangle instead of the whole screen and drop the rectangle informations. Then a new round begins by marking objects "dirty".

See also:
  VideoDriver::MakeDirty

  _invalid_rect

  _screen

## Function Documentation

void DrawDirtyBlocks | ( |  | ) |

Let the dirty blocks repainting by the video driver.

Repaints the rectangle blocks which are marked as 'dirty'.

See also:
  SetDirtyBlocks

Definition at line 1388 of file gfx.cpp.

References _genworld_mapgen_mutex, _genworld_paint_mutex, Align(), ThreadMutex::BeginCritical(), Rect::bottom, ThreadMutex::EndCritical(), GENWORLD_REDRAW_TIMEOUT, IsGeneratingWorld(), Rect::left, Rect::right, and Rect::top.

Referenced by UpdateWindows().

void MarkAllViewportsDirty | ( | int | left,
|  | int | top,
|  | int | right,
|  | int | bottom |
| ) |  |  |

Mark all viewports dirty for repaint.

Mark all viewports that display an area as dirty (in need of repaint).

Parameters:

  | left | Left edge of area to repaint
  | top | Top edge of area to repaint
  | right | Right edge of area to repaint
  | bottom | Bottom edge of area to repaint

Definition at line 1682 of file viewport.cpp.

References MarkViewportDirty(), Window::viewport, and ViewPort::width.

Referenced by Station::MarkDirty(), MarkSignDirty(), MarkSingleVehicleDirty(), MarkTextEffectAreaDirty(), MarkTileDirty(), MarkTileDirtyByTile(), MarkTownSignDirty(), RedrawWaypointSign(), and VehicleMove().

static void MarkCanalsAndRiversAroundDirty | ( | TileIndex | tile | ) | `[static]`

Marks the tiles around a tile as dirty, if they are canals or rivers.

Parameters:

  | tile | The center of the tile where all other tiles are marked as dirty

Definition at line 88 of file water_cmd.cpp.

References DIR_BEGIN, DIR_END, MarkTileDirtyIfCanalOrRiver(), and TileOffsByDir().

Referenced by CmdBuildCanal(), DoBuildShiplift(), and DoFloodTile().

virtual void Vehicle::MarkDirty | ( |  | ) | `[inline, virtual, inherited]`

Marks the vehicles to be redrawn and updates cached variables.

This method marks the area of the vehicle on the screen as dirty. It can be use to repaint the vehicle.

Definition at line 370 of file vehicle_base.h.

void MarkSignDirty | ( | Sign * | si | ) |

Marks the region of a sign as dirty.

This function marks the sign in all viewports as dirty for repaint.

Parameters:

  | si | Pointer to the Sign

Definition at line 64 of file signs.cpp.

References MarkAllViewportsDirty(), and ScaleByZoom().

Referenced by CmdPlaceSign(), and CmdRenameSign().

static void MarkTextEffectAreaDirty | ( | TextEffect * | te | ) | `[static]`

Mark the area of the text effect as dirty.

This function marks the area of a text effect as dirty for repaint.

Parameters:

  | te | The TextEffect to mark the area dirty

Definition at line 46 of file texteff.cpp.

References MarkAllViewportsDirty().

static void MarkTownSignDirty | ( | Town * | t | ) | `[static]`

Marks the town sign as needing a repaint.

This function marks the area of the sign of a town as dirty for repaint.

Parameters:

  | t | Town requesting town sign for repaint

Definition at line 308 of file town_cmd.cpp.

References MarkAllViewportsDirty().

Referenced by UpdateTownVirtCoord().

static void MarkViewportDirty | ( | const ViewPort * | vp,
|  | int | left,
|  | int | top,
|  | int | right,
|  | int | bottom |
| ) |  |  | `[static]`

Marks a viewport as dirty for repaint if it displays (a part of) the area the needs to be repainted.

Parameters:

  | vp | The viewport to mark as dirty
  | left | Left edge of area to repaint
  | top | Top edge of area to repaint
  | right | Right edge of area to repaint
  | bottom | Bottom edge of area to repaint

Definition at line 1650 of file viewport.cpp.

References ViewPort::left, max(), SetDirtyBlocks(), ViewPort::top, UnScaleByZoom(), UnScaleByZoomLower(), ViewPort::virtual_height, ViewPort::virtual_left, ViewPort::virtual_top, ViewPort::virtual_width, and ViewPort::zoom.

Referenced by MarkAllViewportsDirty().

void MarkWholeScreenDirty | ( |  | ) |

Marks the whole screen as dirty.

This function mark the whole screen as dirty. This results in repainting the whole screen. Use this with care as this function will break the idea about marking only parts of the screen as 'dirty'.

Definition at line 1534 of file gfx.cpp.

References SetDirtyBlocks().

Referenced by CleanupGeneration(), CmdCompanyCtrl(), CmdRenameCompany(), CmdRenameEngine(), CmdRenamePresident(), CmdRenameStation(), CmdRenameTown(), CmdRenameVehicle(), CmdRenameWaypoint(), CmdSetCompanyColour(), CmdSetCompanyManagerFace(), FlatEmptyWorld(), GameSizeChanged(), LoadHeightmap(), CompanyWindow::OnClick(), ReinitGuiAfterToggleElrail(), ReloadNewGRFData(), ResetLandscapeConfirmationCallback(), ResetRestoreAllTransparency(), SetLocalCompany(), and StartScenario().

void SetDirtyBlocks | ( | int | left,
|  | int | top,
|  | int | right,
|  | int | bottom |
| ) |  |  |

Set a new dirty block.

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.

Parameters:

  | left | The left edge of the rectangle
  | top | The top edge of the rectangle
  | right | The right edge of the rectangle
  | bottom | The bottm edge of the rectangle

See also:
  DrawDirtyBlocks

Todo:
  The name of the function should be called like `AddDirtyBlock` as it neither set a dirty rect nor add several dirty rects although the function name is in plural. (Progman)

Definition at line 1492 of file gfx.cpp.

References Rect::bottom, Rect::left, Rect::right, and Rect::top.

Referenced by Window::InvalidateWidget(), MarkViewportDirty(), MarkWholeScreenDirty(), PositionMainToolbar(), and Window::SetDirty().

static void SetSelectionTilesDirty | ( |  | ) | `[static]`

Marks the selected tiles as dirty.

This function marks the selected tiles as dirty for repaint

Note:
  Documentation may be wrong (Progman)

Definition at line 1731 of file viewport.cpp.

References MarkTileDirty(), and TILE_SIZE.

Referenced by UpdateTileSelection().

void SetWindowDirty | ( | const Window * | w | ) |

Mark entire window as dirty (in need of re-paint).

Parameters:

  | w | Window to redraw

Definition at line 505 of file window.cpp.

References Window::SetDirty().

Referenced by ClickChangeDateCheat(), and IConsoleGUIPrint().

static void TerraformAddDirtyTile | ( | TerraformerState * | ts,
|  | TileIndex | tile |
| ) |  |  | `[static]`

Adds a tile to the "tile_table" in a TerraformerState.

Parameters:

  | ts | TerraformerState.
  | tile | Tile.

Definition at line 110 of file terraform_cmd.cpp.

Referenced by TerraformAddDirtyTileAround().

static void TerraformAddDirtyTileAround | ( | TerraformerState * | ts,
|  | TileIndex | tile |
| ) |  |  | `[static]`

Adds all tiles that incident with the north corner of a specific tile to the "tile_table" in a TerraformerState.

Parameters:

  | ts | TerraformerState.
  | tile | Tile.

Definition at line 130 of file terraform_cmd.cpp.

References TerraformAddDirtyTile(), TileDiffXY(), TileX(), and TileY().

Referenced by TerraformTileHeight().

static void UpdateStationVirtCoordDirty | ( | Station * | st | ) | `[static]`

Update the station virt coords while making the modified parts dirty.

This function updates the virt coords and mark the modified parts as dirty

Parameters:

  | st | The station to update the virt coords

Definition at line 416 of file station_cmd.cpp.

References Station::MarkDirty(), and UpdateStationVirtCoord().

Referenced by CmdBuildAirport(), CmdBuildBuoy(), CmdBuildDock(), CmdBuildRailroadStation(), CmdBuildRoadStop(), CmdRemoveFromRailroadStation(), and RemoveRoadStop().

## Variable Documentation

Rect _invalid_rect`[static]`

The rect for repaint.

This rectangle defines the area which should be repaint by the video driver.

Definition at line 65 of file gfx.cpp.

TileIndex TerraformerState::tile_table[TERRAFORMER_TILE_TABLE_SIZE]`[inherited]`

Dirty tiles, i.e. at least one corner changed.

This array contains the tiles which are or will be marked as dirty.

Definition at line 47 of file terraform_cmd.cpp.