OpenTTD Source 20241224-master-gf74b0cf984
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.
 
void DrawDirtyBlocks ()
 Repaints the rectangle blocks which are marked as 'dirty'.
 
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.
 
void MarkWholeScreenDirty ()
 This function mark the whole screen as 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.
 
virtual void Vehicle::MarkDirty ()
 Marks the vehicles to be redrawn and updates cached variables.
 
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.
 
bool MarkAllViewportsDirty (int left, int top, int right, int bottom)
 Mark all viewports that display an area as dirty (in need of repaint).
 
void MarkTileDirtyByTile (TileIndex tile, int bridge_level_offset, int tile_height_override)
 Mark a tile given by its index dirty for repaint.
 
static void SetSelectionTilesDirty ()
 Marks the selected tiles as dirty.
 
void MarkTileDirtyByTile (TileIndex tile, int bridge_level_offset=0)
 Mark a tile given by its index dirty for repaint.
 
static void MarkCanalsAndRiversAroundDirty (TileIndex tile)
 Marks the tiles around a tile as dirty, if they are canals or rivers.
 
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.
 
void Window::SetDirty () const
 Mark entire window as dirty (in need of re-paint)
 

Variables

static Rect _invalid_rect
 The rect for repaint.
 

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
leftThe left edge of the rectangle
topThe top edge of the rectangle
rightThe right edge of the rectangle
bottomThe bottom edge of the rectangle
See also
DrawDirtyBlocks

Definition at line 1486 of file gfx.cpp.

References _invalid_rect.

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

◆ DrawDirtyBlocks()

void DrawDirtyBlocks ( )

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

See also
AddDirtyBlock

Definition at line 1397 of file gfx.cpp.

References _invalid_rect, Align(), and RedrawScreenRect().

Referenced by RealMakeScreenshot(), and 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
leftLeft edge of area to repaint. (viewport coordinates, that is wrt. ZOOM_LVL_MIN)
topTop edge of area to repaint. (viewport coordinates, that is wrt. ZOOM_LVL_MIN)
rightRight edge of area to repaint. (viewport coordinates, that is wrt. ZOOM_LVL_MIN)
bottomBottom edge of area to repaint. (viewport coordinates, that is wrt. ZOOM_LVL_MIN)
Returns
true if at least one viewport has a dirty block

Definition at line 2022 of file viewport.cpp.

References MarkViewportDirty(), and Viewport::width.

Referenced by MarkTileDirtyByTile(), and SetSelectionTilesDirty().

◆ MarkCanalsAndRiversAroundDirty()

static void MarkCanalsAndRiversAroundDirty ( TileIndex  tile)
static

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

Parameters
tileThe 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().

Referenced by CmdBuildCanal(), DoBuildLock(), DoFloodTile(), and RemoveLock().

◆ 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 Aircraft, RoadVehicle, Ship, and Train.

Definition at line 407 of file vehicle_base.h.

Referenced by Vehicle::BeginLoading(), CmdRefitVehicle(), CmdStartStopVehicle(), Vehicle::HandleBreakdown(), Vehicle::LeaveStation(), LoadUnloadVehicle(), RunEconomyVehicleDayProc(), and VehicleEnterDepot().

◆ MarkDirty() [2/2]

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

◆ 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
tileThe tile to mark dirty.
bridge_level_offsetHeight of bridge on tile to also mark dirty. (Height level relative to north corner.)
tile_height_overrideHeight of the tile (TileHeight).

Definition at line 2057 of file viewport.cpp.

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

Referenced by AddAnimatedTile(), AdvanceSingleHouseConstruction(), AnimationBase< Tbase, Tspec, Tobj, Textra, GetCallback, Tframehelper >::AnimateTile(), AnimateTile_Town(), BuildObject(), CheckTrainStayInDepot(), ClearMakeHouseTile(), ClearPathReservation(), CmdBuildBuoy(), CmdBuildCanal(), CmdBuildRailWaypoint(), CmdBuildRoad(), CmdBuildRoadDepot(), CmdBuildRoadStop(), CmdBuildRoadWaypoint(), CmdBuildShipDepot(), CmdBuildSingleRail(), CmdBuildSingleSignal(), CmdBuildTrainDepot(), CmdConvertRail(), CmdConvertRoad(), CmdPlantTree(), CmdRemoveSingleRail(), CmdRemoveSingleSignal(), CmdTerraformLand(), DoBuildLock(), DoClearBridge(), DoDryUp(), DoFloodTile(), DoTriggerIndustryTile(), ExtendTrainReservation(), FloodHalftile(), FreeTrainTrackReservation(), GenerateDesertArea(), GenerateRockyArea(), IncreaseAnimationStage(), MakeRiverAndModifyDesertZoneAround(), MarkBridgeDirty(), MarkDirtyAdjacentLevelCrossingTiles(), MarkTileDirtyByTile(), MarkTileDirtyIfCanalOrRiver(), Station::MarkTilesDirty(), BuildRailToolbarWindow::OnHotkey(), BuildRoadToolbarWindow::OnHotkey(), PlaceTree(), PlaceTreeGroupAroundTile(), RemoveDock(), RemoveRoad(), CYapfReserveTrack< Types >::ReserveRailStationPlatform(), CYapfReserveTrack< Types >::ReserveSingleTrack(), SetRailStationPlatformReservation(), SetRedErrorSquare(), SetSelectionTilesDirty(), SetWaterClassDependingOnSurroundings(), TileLoopClearAlps(), TownActionBuildStatue(), TrainController(), TriggerRoadStopRandomisation(), TriggerStationRandomisation(), TryPathReserve(), TryReserveRailTrack(), UnreserveRailTrack(), UpdateAdjacentLevelCrossingTilesOnLevelCrossingRemoval(), UpdateLevelCrossingTile(), UpdateSignalsAroundSegment(), 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
tileThe tile to mark dirty.
bridge_level_offsetHeight 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().

◆ MarkTilesDirty()

void Station::MarkTilesDirty ( bool  cargo_change) const

◆ 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
vpThe viewport to mark as dirty
leftLeft edge of area to repaint
topTop edge of area to repaint
rightRight edge of area to repaint
bottomBottom edge of area to repaint
Returns
true if the viewport contains a dirty block

Definition at line 1983 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 ( )

◆ RedrawScreenRect()

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

Repaints a specific rectangle of the screen.

Parameters
left,top,right,bottomThe 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 1371 of file gfx.cpp.

References _networking, CursorVars::draw_size, DrawOverlappedWindowForAll(), VideoDriver::GetInstance(), VideoDriver::MakeDirty(), NetworkUndrawChatMessage(), and CursorVars::visible.

Referenced by DrawDirtyBlocks().

◆ SetDirty()

void Window::SetDirty ( ) const

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

Definition at line 940 of file window.cpp.

References AddDirtyBlock(), Window::height, Window::left, Window::top, and Window::width.

Referenced by BringWindowToFront(), BringWindowToFrontById(), IndustryDirectoryWindow::BuildSortIndustriesList(), ChangeVehicleViewports(), NetworkChatWindow::ChatTabCompletion(), CheckRedrawStationCoverage(), Window::Close(), CloseConstructionWindows(), IndustryCargoesWindow::ComputeCargoDisplay(), IndustryCargoesWindow::ComputeIndustryDisplay(), DepotWindow::DepotClick(), DispatchMouseWheelEvent(), Window::FindWindowPlacementAndResize(), QueryWindow::FindWindowPlacementAndResize(), NetworkAskRelayWindow::FindWindowPlacementAndResize(), NetworkAskSurveyWindow::FindWindowPlacementAndResize(), HandlePlacePushButton(), HandleScrollbarScrolling(), HandleWindowDragging(), IConsoleWindow::InsertTextString(), Window::InvalidateData(), MaybeBringWindowToFront(), TextfileWindow::NavigateHistory(), BuildAirportWindow::OnClick(), ReplaceVehicleWindow::OnClick(), BuildBridgeWindow::OnClick(), BuildVehicleWindow::OnClick(), CheatWindow::OnClick(), SelectCompanyLiveryWindow::OnClick(), SelectCompanyManagerFaceWindow::OnClick(), BuildDocksStationWindow::OnClick(), BuildDocksDepotWindow::OnClick(), DropdownWindow::OnClick(), SaveLoadWindow::OnClick(), GSConfigWindow::OnClick(), CreateScenarioWindow::OnClick(), GraphLegendWindow::OnClick(), BaseGraphWindow::OnClick(), PaymentRatesGraphWindow::OnClick(), PerformanceRatingDetailWindow::OnClick(), IndustryProductionGraphWindow::OnClick(), VehicleGroupWindow::OnClick(), BuildIndustryWindow::OnClick(), IndustryViewWindow::OnClick(), IndustryDirectoryWindow::OnClick(), LinkGraphLegendWindow::OnClick(), NetworkGameWindow::OnClick(), NetworkStartServerWindow::OnClick(), SpriteAlignerWindow::OnClick(), NewGRFParametersWindow::OnClick(), NewGRFWindow::OnClick(), OskWindow::OnClick(), BuildRailStationWindow::OnClick(), BuildRailDepotWindow::OnClick(), BuildRoadToolbarWindow::OnClick(), BuildRoadDepotWindow::OnClick(), BuildRoadStationWindow::OnClick(), ScriptListWindow::OnClick(), ScriptSettingsWindow::OnClick(), GameOptionsWindow::OnClick(), GameSettingsWindow::OnClick(), CustomCurrencyWindow::OnClick(), CompanyStationsWindow::OnClick(), ScenarioEditorLandscapeGenerationWindow::OnClick(), TimetableWindow::OnClick(), TownAuthorityWindow::OnClick(), TownDirectoryWindow::OnClick(), FoundTownWindow::OnClick(), TransparenciesWindow::OnClick(), VehicleListWindow::OnClick(), VehicleDetailsWindow::OnClick(), BaseNetworkContentDownloadStatusWindow::OnDownloadProgress(), DepotWindow::OnDragDrop(), GameSettingsWindow::OnDropdownClose(), GSConfigWindow::OnDropdownClose(), NewGRFParametersWindow::OnDropdownClose(), ScriptSettingsWindow::OnDropdownClose(), CompanyStationsWindow::OnDropdownSelect(), ReplaceVehicleWindow::OnDropdownSelect(), BuildVehicleWindow::OnDropdownSelect(), SetDateWindow::OnDropdownSelect(), CreateScenarioWindow::OnDropdownSelect(), VehicleGroupWindow::OnDropdownSelect(), NetworkStartServerWindow::OnDropdownSelect(), NetworkClientListWindow::OnDropdownSelect(), NewGRFParametersWindow::OnDropdownSelect(), GameOptionsWindow::OnDropdownSelect(), GameSettingsWindow::OnDropdownSelect(), VehicleListWindow::OnDropdownSelect(), NetworkGameWindow::OnEditboxChanged(), PerformanceRatingDetailWindow::OnGameTick(), VehicleGroupWindow::OnGameTick(), PerformanceLeagueWindow::OnGameTick(), CompanyStationsWindow::OnGameTick(), VehicleListWindow::OnGameTick(), SignListWindow::OnInit(), SelectCompanyLiveryWindow::OnInvalidateData(), VehicleGroupWindow::OnInvalidateData(), BuildIndustryWindow::OnInvalidateData(), MusicTrackSelectionWindow::OnInvalidateData(), MusicWindow::OnInvalidateData(), NetworkGameWindow::OnInvalidateData(), SelectStationWindow< T >::OnInvalidateData(), TownViewWindow::OnInvalidateData(), IConsoleWindow::OnKeyPress(), NetworkGameWindow::OnKeyPress(), IConsoleWindow::OnMouseLoop(), DepotWindow::OnMouseLoop(), DropdownWindow::OnMouseLoop(), VehicleGroupWindow::OnMouseLoop(), GameOptionsWindow::OnMouseLoop(), VehicleListWindow::OnMouseLoop(), TownAuthorityWindow::OnPaint(), ScenarioEditorLandscapeGenerationWindow::OnPlaceObjectAbort(), CheatWindow::OnQueryTextFinished(), SelectCompanyManagerFaceWindow::OnQueryTextFinished(), CreateScenarioWindow::OnQueryTextFinished(), IndustryViewWindow::OnQueryTextFinished(), NetworkStartServerWindow::OnQueryTextFinished(), NewGRFInspectWindow::OnQueryTextFinished(), SpriteAlignerWindow::OnQueryTextFinished(), NewGRFParametersWindow::OnQueryTextFinished(), GameSettingsWindow::OnQueryTextFinished(), ScenarioEditorToolbarWindow::OnQueryTextFinished(), ReplaceVehicleWindow::OnRailRoadTypeChange(), FramerateWindow::OnRealtimeTick(), FrametimeGraphWindow::OnRealtimeTick(), SelectStationWindow< T >::OnRealtimeTick(), CheatWindow::OnTimeout(), IndustryViewWindow::OnTimeout(), GameSettingsWindow::OnTimeout(), CustomCurrencyWindow::OnTimeout(), Window::ReInit(), ResetSignalVariant(), ResizeWindow(), IConsoleWindow::Scroll(), ScrollbarClickPositioning(), VehicleGroupWindow::SelectGroup(), StationViewWindow::SelectGroupBy(), StationViewWindow::SelectSortBy(), StationViewWindow::SelectSortOrder(), NewGRFInspectWindow::SetCallerGRFID(), GameSettingsWindow::SetDisplayedHelpText(), SetScreenshotWindowVisibility(), SetWindowClassesDirty(), SetWindowDirty(), ShowTerraformToolbar(), BuildObjectWindow::UpdateButtons(), BuildTreesWindow::UpdateMode(), ScanProgressWindow::UpdateNewGRFScanStatus(), UpdateOSKOriginalText(), and IndustryProductionGraphWindow::UpdateStatistics().

◆ SetSelectionTilesDirty()

static void SetSelectionTilesDirty ( )
static

◆ TerraformAddDirtyTile()

static void TerraformAddDirtyTile ( TerraformerState ts,
TileIndex  tile 
)
static

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

Parameters
tsTerraformerState.
tileTile.

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
tsTerraformerState.
tileTile.

Definition at line 82 of file terraform_cmd.cpp.

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

Referenced by TerraformTileHeight().

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

Referenced by AddDirtyBlock(), and DrawDirtyBlocks().