MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / DrawSmallMapColumn

Method DrawSmallMapColumn

src/smallmap_gui.cpp:910–943  ·  view source on GitHub ↗

* Draws one column of tiles of the small map in a certain mode onto the screen buffer, skipping the shifted rows in between. * * @param dst Pointer to a part of the screen buffer to write to. * @param xc The X coordinate of the first tile in the column. * @param yc The Y coordinate of the first tile in the column * @param pitch Number of pixels to advance in the screen buffer each time a

Source from the content-addressed store, hash-verified

908 * @note If pixel position is below \c 0, skip drawing.
909 */
910 void DrawSmallMapColumn(void *dst, uint xc, uint yc, int pitch, int reps, int start_pos, int end_pos, Blitter *blitter) const
911 {
912 void *dst_ptr_abs_end = blitter->MoveTo(_screen.dst_ptr, 0, _screen.height);
913 uint min_xy = _settings_game.construction.freeform_edges ? 1 : 0;
914
915 do {
916 /* Check if the tile (xc,yc) is within the map range */
917 if (xc >= Map::MaxX() || yc >= Map::MaxY()) continue;
918
919 /* Check if the dst pointer points to a pixel inside the screen buffer */
920 if (dst < _screen.dst_ptr) continue;
921 if (dst >= dst_ptr_abs_end) continue;
922
923 /* Construct tilearea covered by (xc, yc, xc + this->zoom, yc + this->zoom) such that it is within min_xy limits. */
924 TileArea ta;
925 if (min_xy == 1 && (xc == 0 || yc == 0)) {
926 if (this->zoom == 1) continue; // The tile area is empty, don't draw anything.
927
928 ta = TileArea(TileXY(std::max(min_xy, xc), std::max(min_xy, yc)), this->zoom - (xc == 0), this->zoom - (yc == 0));
929 } else {
930 ta = TileArea(TileXY(xc, yc), this->zoom, this->zoom);
931 }
932 ta.ClampToMap(); // Clamp to map boundaries (may contain MP_VOID tiles!).
933
934 uint32_t val = this->GetTileColours(ta);
935 uint8_t *val8 = (uint8_t *)&val;
936 int idx = std::max(0, -start_pos);
937 for (int pos = std::max(0, start_pos); pos < end_pos; pos++) {
938 blitter->SetPixel(dst, idx, 0, PixelColour{val8[idx]});
939 idx++;
940 }
941 /* Switch to next tile in the column */
942 } while (xc += this->zoom, yc += this->zoom, dst = blitter->MoveTo(dst, pitch, 0), --reps != 0);
943 }
944
945 /**
946 * Adds vehicles to the smallmap.

Callers 1

DrawSmallMapMethod · 0.95

Calls 5

GetTileColoursMethod · 0.95
TileXYFunction · 0.85
ClampToMapMethod · 0.80
MoveToMethod · 0.45
SetPixelMethod · 0.45

Tested by

no test coverage detected