Changeset - r27634:055c9bd809d0
[Not reviewed]
master
0 3 0
Rubidium - 12 months ago 2023-06-22 18:10:02
rubidium@openttd.org
Codechange: reduce passing around parameters, but formatting strings earlier
3 files changed with 23 insertions and 22 deletions:
0 comments (0 inline, 0 general)
src/texteff.cpp
Show inline comments
 
@@ -126,7 +126,9 @@ void DrawTextEffects(DrawPixelInfo *dpi)
 
	for (TextEffect &te : _text_effects) {
 
		if (te.string_id == INVALID_STRING_ID) continue;
 
		if (te.mode == TE_RISING || (_settings_client.gui.loading_indicators && !IsTransparencySet(TO_LOADING))) {
 
			ViewportAddString(dpi, ZOOM_LVL_OUT_8X, &te, te.string_id, te.string_id - 1, STR_NULL, te.params_1, te.params_2);
 
			SetDParam(0, te.params_1);
 
			SetDParam(1, te.params_2);
 
			ViewportAddString(dpi, ZOOM_LVL_OUT_8X, &te, te.string_id, te.string_id - 1, STR_NULL);
 
		}
 
	}
 
}
src/viewport.cpp
Show inline comments
 
@@ -112,11 +112,11 @@ static const int MAX_TILE_EXTENT_TOP    
 
static const int MAX_TILE_EXTENT_BOTTOM = ZOOM_LVL_BASE * (TILE_PIXELS + 2 * TILE_HEIGHT); ///< Maximum bottom extent of tile relative to north corner (worst case: #SLOPE_STEEP_N).
 

	
 
struct StringSpriteToDraw {
 
	StringID string;
 
	std::string string;
 
	StringID string_id;
 
	Colours colour;
 
	int32 x;
 
	int32 y;
 
	uint64 params[2];
 
	uint16 width;
 
};
 

	
 
@@ -849,15 +849,14 @@ void AddChildSpriteScreen(SpriteID image
 
	_vd.last_child = &cs.next;
 
}
 

	
 
static void AddStringToDraw(int x, int y, StringID string, uint64 params_1, uint64 params_2, Colours colour, uint16 width)
 
static void AddStringToDraw(int x, int y, StringID string, Colours colour, uint16 width)
 
{
 
	assert(width != 0);
 
	StringSpriteToDraw &ss = _vd.string_sprites_to_draw.emplace_back();
 
	ss.string = string;
 
	ss.string = GetString(string);
 
	ss.string_id = string;
 
	ss.x = x;
 
	ss.y = y;
 
	ss.params[0] = params_1;
 
	ss.params[1] = params_2;
 
	ss.width = width;
 
	ss.colour = colour;
 
}
 
@@ -1297,7 +1296,7 @@ static void ViewportAddLandscape()
 
 * @param string_small_shadow Shadow string for 4x and 8x zoom level; or #STR_NULL if no shadow
 
 * @param colour colour of the sign background; or INVALID_COLOUR if transparent
 
 */
 
void ViewportAddString(const DrawPixelInfo *dpi, ZoomLevel small_from, const ViewportSign *sign, StringID string_normal, StringID string_small, StringID string_small_shadow, uint64 params_1, uint64 params_2, Colours colour)
 
void ViewportAddString(const DrawPixelInfo *dpi, ZoomLevel small_from, const ViewportSign *sign, StringID string_normal, StringID string_small, StringID string_small_shadow, Colours colour)
 
{
 
	bool small = dpi->zoom >= small_from;
 

	
 
@@ -1317,15 +1316,14 @@ void ViewportAddString(const DrawPixelIn
 
	}
 

	
 
	if (!small) {
 
		AddStringToDraw(sign->center - sign_half_width, sign->top, string_normal, params_1, params_2, colour, sign->width_normal);
 
		AddStringToDraw(sign->center - sign_half_width, sign->top, string_normal, colour, sign->width_normal);
 
	} else {
 
		int shadow_offset = 0;
 
		if (string_small_shadow != STR_NULL) {
 
			shadow_offset = 4;
 
			AddStringToDraw(sign->center - sign_half_width + shadow_offset, sign->top, string_small_shadow, params_1, params_2, INVALID_COLOUR, sign->width_small | 0x8000);
 
			AddStringToDraw(sign->center - sign_half_width + shadow_offset, sign->top, string_small_shadow, INVALID_COLOUR, sign->width_small | 0x8000);
 
		}
 
		AddStringToDraw(sign->center - sign_half_width, sign->top - shadow_offset, string_small, params_1, params_2,
 
				colour, sign->width_small | 0x8000);
 
		AddStringToDraw(sign->center - sign_half_width, sign->top - shadow_offset, string_small, colour, sign->width_small | 0x8000);
 
	}
 
}
 

	
 
@@ -1411,33 +1409,37 @@ static void ViewportAddKdtreeSigns(DrawP
 
	/* Layering order (bottom to top): Town names, signs, stations */
 

	
 
	for (const auto *t : towns) {
 
		SetDParam(0, t->index);
 
		SetDParam(1, t->cache.population);
 
		ViewportAddString(dpi, ZOOM_LVL_OUT_16X, &t->cache.sign,
 
			_settings_client.gui.population_in_label ? STR_VIEWPORT_TOWN_POP : STR_VIEWPORT_TOWN,
 
			STR_VIEWPORT_TOWN_TINY_WHITE, STR_VIEWPORT_TOWN_TINY_BLACK,
 
			t->index, t->cache.population);
 
			STR_VIEWPORT_TOWN_TINY_WHITE, STR_VIEWPORT_TOWN_TINY_BLACK);
 
	}
 

	
 
	/* Do not draw signs nor station names if they are set invisible */
 
	if (IsInvisibilitySet(TO_SIGNS)) return;
 

	
 
	for (const auto *si : signs) {
 
		SetDParam(0, si->index);
 
		ViewportAddString(dpi, ZOOM_LVL_OUT_16X, &si->sign,
 
			STR_WHITE_SIGN,
 
			(IsTransparencySet(TO_SIGNS) || si->owner == OWNER_DEITY) ? STR_VIEWPORT_SIGN_SMALL_WHITE : STR_VIEWPORT_SIGN_SMALL_BLACK, STR_NULL,
 
			si->index, 0, (si->owner == OWNER_NONE) ? COLOUR_GREY : (si->owner == OWNER_DEITY ? INVALID_COLOUR : _company_colours[si->owner]));
 
			(si->owner == OWNER_NONE) ? COLOUR_GREY : (si->owner == OWNER_DEITY ? INVALID_COLOUR : _company_colours[si->owner]));
 
	}
 

	
 
	for (const auto *st : stations) {
 
		SetDParam(0, st->index);
 
		SetDParam(1, st->facilities);
 
		if (Station::IsExpected(st)) {
 
			/* Station */
 
			ViewportAddString(dpi, ZOOM_LVL_OUT_16X, &st->sign,
 
				STR_VIEWPORT_STATION, STR_VIEWPORT_STATION_TINY, STR_NULL,
 
				st->index, st->facilities, (st->owner == OWNER_NONE || !st->IsInUse()) ? COLOUR_GREY : _company_colours[st->owner]);
 
				(st->owner == OWNER_NONE || !st->IsInUse()) ? COLOUR_GREY : _company_colours[st->owner]);
 
		} else {
 
			/* Waypoint */
 
			ViewportAddString(dpi, ZOOM_LVL_OUT_16X, &st->sign,
 
				STR_VIEWPORT_WAYPOINT, STR_VIEWPORT_WAYPOINT_TINY, STR_NULL,
 
				st->index, st->facilities, (st->owner == OWNER_NONE || !st->IsInUse()) ? COLOUR_GREY : _company_colours[st->owner]);
 
				(st->owner == OWNER_NONE || !st->IsInUse()) ? COLOUR_GREY : _company_colours[st->owner]);
 
		}
 
	}
 
}
 
@@ -1700,11 +1702,8 @@ static void ViewportDrawStrings(ZoomLeve
 
		int y = UnScaleByZoom(ss.y, zoom);
 
		int h = WidgetDimensions::scaled.fullbevel.top + (small ? FONT_HEIGHT_SMALL : FONT_HEIGHT_NORMAL) + WidgetDimensions::scaled.fullbevel.bottom;
 

	
 
		SetDParam(0, ss.params[0]);
 
		SetDParam(1, ss.params[1]);
 

	
 
		if (ss.colour != INVALID_COLOUR) {
 
			if (IsTransparencySet(TO_SIGNS) && ss.string != STR_WHITE_SIGN) {
 
			if (IsTransparencySet(TO_SIGNS) && ss.string_id != STR_WHITE_SIGN) {
 
				/* Don't draw the rectangle.
 
				 * Real colours need the TC_IS_PALETTE_COLOUR flag.
 
				 * Otherwise colours from _string_colourmap are assumed. */
src/viewport_func.h
Show inline comments
 
@@ -53,7 +53,7 @@ void DrawGroundSprite(SpriteID image, Pa
 
void DrawGroundSpriteAt(SpriteID image, PaletteID pal, int32 x, int32 y, int z, const SubSprite *sub = nullptr, int extra_offs_x = 0, int extra_offs_y = 0);
 
void AddSortableSpriteToDraw(SpriteID image, PaletteID pal, int x, int y, int w, int h, int dz, int z, bool transparent = false, int bb_offset_x = 0, int bb_offset_y = 0, int bb_offset_z = 0, const SubSprite *sub = nullptr);
 
void AddChildSpriteScreen(SpriteID image, PaletteID pal, int x, int y, bool transparent = false, const SubSprite *sub = nullptr, bool scale = true, bool relative = true);
 
void ViewportAddString(const DrawPixelInfo *dpi, ZoomLevel small_from, const ViewportSign *sign, StringID string_normal, StringID string_small, StringID string_small_shadow, uint64 params_1, uint64 params_2 = 0, Colours colour = INVALID_COLOUR);
 
void ViewportAddString(const DrawPixelInfo *dpi, ZoomLevel small_from, const ViewportSign *sign, StringID string_normal, StringID string_small, StringID string_small_shadow, Colours colour = INVALID_COLOUR);
 

	
 

	
 
void StartSpriteCombine();
0 comments (0 inline, 0 general)