OpenTTD Source: Dirty

OpenTTD Source 14.0-beta1

Functions | Variables
Dirty

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

## Functions
void | RedrawScreenRect (int left, int top, int right, int bottom)
| Repaints a specific rectangle of the screen. More...
void | DrawDirtyBlocks ()
| Repaints the rectangle blocks which are marked as 'dirty'. More...
void | AddDirtyBlock (int left, int top, int right, int bottom)
| Extend the internal _invalid_rect rectangle to contain the rectangle defined by the given parameters. More...
void | MarkWholeScreenDirty ()
| This function mark the whole screen as dirty. More...
static void | TerraformAddDirtyTile (TerraformerState *ts, TileIndex tile)
| Adds a tile to the "tile_table" in a TerraformerState. More...
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. More...
virtual void | Vehicle::MarkDirty ()
| Marks the vehicles to be redrawn and updates cached variables. More...
static bool | 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. More...
bool | MarkAllViewportsDirty (int left, int top, int right, int bottom)
| Mark all viewports that display an area as dirty (in need of repaint). More...
void | MarkTileDirtyByTile (TileIndex tile, int bridge_level_offset, int tile_height_override)
| Mark a tile given by its index dirty for repaint. More...
static void | SetSelectionTilesDirty ()
| Marks the selected tiles as dirty. More...
void | MarkTileDirtyByTile (TileIndex tile, int bridge_level_offset=0)
| Mark a tile given by its index dirty for repaint. More...
static void | MarkCanalsAndRiversAroundDirty (TileIndex tile)
| Marks the tiles around a tile as dirty, if they are canals or rivers. More...
void | Station::MarkTilesDirty (bool cargo_change) const
| Marks the tiles of the station as dirty.
void | ViewportSign::MarkDirty (ZoomLevel maxzoom=ZOOM_LVL_MAX) const
| Mark the sign dirty in all viewports. More...
void | Window::SetDirty () const
| Mark entire window as dirty (in need of re-paint)

## Variables
static Rect | _invalid_rect
| The rect for repaint. More...

## 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 normally uninteresting 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 uninteresting, too) the video driver repaints all these saved rectangle instead of the whole screen and drop the rectangle information. Then a new round begins by marking objects "dirty".

See also
  VideoDriver::MakeDirty
  _invalid_rect
  _screen

## Function Documentation

## ◆ AddDirtyBlock()

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

Extend the internal _invalid_rect rectangle to contain 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 bottom edge of the rectangle

See also
  DrawDirtyBlocks

Definition at line 1509 of file gfx.cpp.

Referenced by MarkViewportDirty(), MarkWholeScreenDirty(), NWidgetBase::SetDirty(), Window::SetDirty(), and NewsWindow::SetWindowTop().

## ◆ DrawDirtyBlocks()

void DrawDirtyBlocks | ( |  | ) |

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

See also
  AddDirtyBlock

Definition at line 1420 of file gfx.cpp.

Referenced by UpdateWindows().

## ◆ MarkAllViewportsDirty()

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

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

Parameters

  left | Left edge of area to repaint. (viewport coordinates, that is wrt. ZOOM_LVL_NORMAL)
  top | Top edge of area to repaint. (viewport coordinates, that is wrt. ZOOM_LVL_NORMAL)
  right | Right edge of area to repaint. (viewport coordinates, that is wrt. ZOOM_LVL_NORMAL)
  bottom | Bottom edge of area to repaint. (viewport coordinates, that is wrt. ZOOM_LVL_NORMAL)

Returns
  true if at least one viewport has a dirty block

Definition at line 2016 of file viewport.cpp.

References MarkViewportDirty(), and Viewport::width.

Referenced by Vehicle::MarkAllViewportsDirty(), and MarkTileDirtyByTile().

## ◆ MarkCanalsAndRiversAroundDirty()

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 86 of file water_cmd.cpp.

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

## ◆ MarkDirty() [1/2]

virtual void Vehicle::MarkDirty | ( |  | ) |
| inlinevirtual

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.

Reimplemented in RoadVehicle, Train, Aircraft, and Ship.

Definition at line 402 of file vehicle_base.h.

## ◆ MarkDirty() [2/2]

void ViewportSign::MarkDirty | ( | ZoomLevel | maxzoom = `ZOOM_LVL_MAX` | ) | const

Mark the sign dirty in all viewports.

Parameters

  maxzoom | Maximum ZoomLevel at which the text is visible.

Definition at line 1489 of file viewport.cpp.

References ViewportSign::center, FS_NORMAL, GetCharacterHeight(), MarkViewportDirty(), ScaleByZoom(), WidgetDimensions::scaled, Window::viewport, Viewport::width, ViewportSign::width_normal, Viewport::zoom, ZOOM_LVL_BEGIN, and ZOOM_LVL_END.

Referenced by TextEffect::Reset(), and ViewportSign::UpdatePosition().

## ◆ MarkTileDirtyByTile() [1/2]

void MarkTileDirtyByTile | ( | TileIndex | tile,
|  | int | bridge_level_offset,
|  | int | tile_height_override
| ) |  |

Mark a tile given by its index dirty for repaint.

Parameters

  tile | The tile to mark dirty.
  bridge_level_offset | Height of bridge on tile to also mark dirty. (Height level relative to north corner.)
  tile_height_override | Height of the tile (TileHeight).

Definition at line 2051 of file viewport.cpp.

References MarkAllViewportsDirty(), MAX_TILE_EXTENT_LEFT, MAX_TILE_EXTENT_TOP, RemapCoords(), TILE_HEIGHT, TILE_SIZE, TileX(), and TileY().

Referenced by AddAnimatedTile(), ClearPathReservation(), CmdConvertRail(), DeleteAnimatedTile(), IncreaseAnimationStage(), MarkBridgeDirty(), MarkDirtyAdjacentLevelCrossingTiles(), MarkTileDirtyByTile(), MarkTileDirtyIfCanalOrRiver(), Station::MarkTilesDirty(), BuildRoadToolbarWindow::OnHotkey(), BuildRailToolbarWindow::OnHotkey(), PlaceTree(), CYapfReserveTrack< Types >::ReserveRailStationPlatform(), SetRailStationPlatformReservation(), SetWaterClassDependingOnSurroundings(), TileLoopClearAlps(), TryPathReserve(), TryReserveRailTrack(), UnreserveRailTrack(), UpdateAdjacentLevelCrossingTilesOnLevelCrossingRemoval(), and VehicleEnterDepot().

## ◆ MarkTileDirtyByTile() [2/2]

void MarkTileDirtyByTile | ( | TileIndex | tile,
|  | int | bridge_level_offset = `0`
| ) |  |
| inline

Mark a tile given by its index dirty for repaint.

Parameters

  tile | The tile to mark dirty.
  bridge_level_offset | Height of bridge on tile to also mark dirty. (Height level relative to north corner.)

Definition at line 91 of file viewport_func.h.

References MarkTileDirtyByTile(), and TileHeight().

## ◆ MarkViewportDirty()

static bool 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

Returns
  true if the viewport contains a dirty block

Definition at line 1977 of file viewport.cpp.

References AddDirtyBlock(), Viewport::left, Viewport::top, UnScaleByZoom(), UnScaleByZoomLower(), Viewport::virtual_height, Viewport::virtual_left, Viewport::virtual_top, Viewport::virtual_width, and Viewport::zoom.

Referenced by MarkAllViewportsDirty(), and ViewportSign::MarkDirty().

## ◆ MarkWholeScreenDirty()

void MarkWholeScreenDirty | ( |  | ) |

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 1552 of file gfx.cpp.

References AddDirtyBlock().

Referenced by CleanupGeneration(), CmdCompanyCtrl(), CmdRenameCompany(), CmdRenameEngine(), CmdRenamePresident(), CmdRenameVehicle(), CmdSetCompanyManagerFace(), FlatEmptyWorld(), NetworkClientListWindow::OnClickCompanyJoin(), ScanNewGRFFiles(), SetLocalCompany(), UpdateLinkgraphColours(), and Town::~Town().

## ◆ RedrawScreenRect()

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

Repaints a specific rectangle of the screen.

Parameters

  left,top,right,bottom | The area of the screen that needs repainting

Precondition
  The rectangle should have been previously marked dirty with `AddDirtyBlock`.

See also
  AddDirtyBlock
  DrawDirtyBlocks

Definition at line 1394 of file gfx.cpp.

## ◆ SetSelectionTilesDirty()

static void SetSelectionTilesDirty | ( |  | ) |
| static

Marks the selected tiles as dirty.

This function marks the selected tiles as dirty for repaint

Definition at line 2068 of file viewport.cpp.

## ◆ TerraformAddDirtyTile()

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 70 of file terraform_cmd.cpp.

References TerraformerState::dirty_tiles.

Referenced by TerraformAddDirtyTileAround().

## ◆ 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 82 of file terraform_cmd.cpp.

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

## Variable Documentation

## ◆ _invalid_rect

Rect _invalid_rect
| static

The rect for repaint.

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

Definition at line 72 of file gfx.cpp.