Fix viewport signs and text effects marking viewports dirty unnecessarily
* When at high zoom levels where the signs are not shown * Where the sign type is disabled in the display options
This commit is contained in:
@@ -51,7 +51,8 @@ void Sign::UpdateVirtCoord()
|
||||
if (_viewport_sign_kdtree_valid && this->sign.kdtree_valid) _viewport_sign_kdtree.Remove(ViewportSignKdtreeItem::MakeSign(this->index));
|
||||
|
||||
SetDParam(0, this->index);
|
||||
this->sign.UpdatePosition(pt.x, pt.y - 6 * ZOOM_LVL_BASE, STR_WHITE_SIGN);
|
||||
bool shown = HasBit(_display_opt, DO_SHOW_SIGNS) && !(this->IsCompetitorOwned() && !HasBit(_display_opt, DO_SHOW_COMPETITOR_SIGNS));
|
||||
this->sign.UpdatePosition(shown ? ZOOM_LVL_DRAW_SPR : ZOOM_LVL_END, pt.x, pt.y - 6 * ZOOM_LVL_BASE, STR_WHITE_SIGN);
|
||||
|
||||
if (_viewport_sign_kdtree_valid) _viewport_sign_kdtree.Insert(ViewportSignKdtreeItem::MakeSign(this->index));
|
||||
}
|
||||
|
@@ -14,6 +14,7 @@
|
||||
#include "viewport_type.h"
|
||||
#include "core/pool_type.hpp"
|
||||
#include "company_type.h"
|
||||
#include "company_func.h"
|
||||
|
||||
typedef Pool<Sign, SignID, 16, 64000> SignPool;
|
||||
extern SignPool _sign_pool;
|
||||
@@ -29,6 +30,11 @@ struct Sign : SignPool::PoolItem<&_sign_pool> {
|
||||
Sign(Owner owner = INVALID_OWNER);
|
||||
~Sign();
|
||||
|
||||
bool IsCompetitorOwned() const
|
||||
{
|
||||
return _local_company != this->owner && this->owner != OWNER_DEITY;
|
||||
}
|
||||
|
||||
void UpdateVirtCoord();
|
||||
};
|
||||
|
||||
|
@@ -97,7 +97,9 @@ CommandCost CmdRenameSign(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
|
||||
}
|
||||
} else { // Delete sign
|
||||
if (flags & DC_EXEC) {
|
||||
si->sign.MarkDirty();
|
||||
if (HasBit(_display_opt, DO_SHOW_SIGNS) && !(si->IsCompetitorOwned() && !HasBit(_display_opt, DO_SHOW_COMPETITOR_SIGNS))) {
|
||||
si->sign.MarkDirty(ZOOM_LVL_DRAW_SPR);
|
||||
}
|
||||
if (_viewport_sign_kdtree_valid && si->sign.kdtree_valid) _viewport_sign_kdtree.Remove(ViewportSignKdtreeItem::MakeSign(si->index));
|
||||
delete si;
|
||||
|
||||
|
@@ -64,7 +64,10 @@ BaseStation::~BaseStation()
|
||||
DeleteWindowById(WC_AIRCRAFT_LIST, VehicleListIdentifier(VL_STATION_LIST, VEH_AIRCRAFT, this->owner, this->index).Pack());
|
||||
DeleteWindowById(WC_DEPARTURES_BOARD, this->index);
|
||||
|
||||
this->sign.MarkDirty();
|
||||
if (HasBit(_display_opt, Station::IsExpected(this) ? DO_SHOW_STATION_NAMES : DO_SHOW_WAYPOINT_NAMES) &&
|
||||
!(_local_company != this->owner && this->owner != OWNER_NONE && !HasBit(_display_opt, DO_SHOW_COMPETITOR_SIGNS))) {
|
||||
this->sign.MarkDirty(ZOOM_LVL_DRAW_SPR);
|
||||
}
|
||||
}
|
||||
|
||||
Station::Station(TileIndex tile) :
|
||||
|
@@ -417,7 +417,8 @@ void Station::UpdateVirtCoord()
|
||||
|
||||
SetDParam(0, this->index);
|
||||
SetDParam(1, this->facilities);
|
||||
this->sign.UpdatePosition(pt.x, pt.y, STR_VIEWPORT_STATION);
|
||||
bool shown = HasBit(_display_opt, DO_SHOW_STATION_NAMES) && !(_local_company != this->owner && this->owner != OWNER_NONE && !HasBit(_display_opt, DO_SHOW_COMPETITOR_SIGNS));
|
||||
this->sign.UpdatePosition(shown ? ZOOM_LVL_DRAW_SPR : ZOOM_LVL_END, pt.x, pt.y, STR_VIEWPORT_STATION);
|
||||
|
||||
if (_viewport_sign_kdtree_valid) _viewport_sign_kdtree.Insert(ViewportSignKdtreeItem::MakeStation(this->index));
|
||||
|
||||
|
@@ -32,7 +32,7 @@ struct TextEffect : public ViewportSign {
|
||||
/** Reset the text effect */
|
||||
void Reset()
|
||||
{
|
||||
this->MarkDirty();
|
||||
this->MarkDirty(ZOOM_LVL_OUT_8X);
|
||||
this->width_normal = 0;
|
||||
this->string_id = INVALID_STRING_ID;
|
||||
this->params_1 = _free_text_effect;
|
||||
@@ -64,7 +64,7 @@ TextEffectID AddTextEffect(StringID msg, int center, int y, uint8 duration, Text
|
||||
|
||||
/* Make sure we only dirty the new area */
|
||||
te.width_normal = 0;
|
||||
te.UpdatePosition(center, y, msg);
|
||||
te.UpdatePosition(ZOOM_LVL_OUT_8X, center, y, msg);
|
||||
|
||||
return i;
|
||||
}
|
||||
@@ -78,7 +78,7 @@ void UpdateTextEffect(TextEffectID te_id, StringID msg)
|
||||
te->params_1 = GetDParam(0);
|
||||
te->params_2 = GetDParam(1);
|
||||
|
||||
te->UpdatePosition(te->center, te->top, msg);
|
||||
te->UpdatePosition(ZOOM_LVL_OUT_8X, te->center, te->top, msg);
|
||||
}
|
||||
|
||||
void RemoveTextEffect(TextEffectID te_id)
|
||||
|
@@ -513,7 +513,7 @@ void Town::UpdateVirtCoord()
|
||||
|
||||
SetDParam(0, this->index);
|
||||
SetDParam(1, this->cache.population);
|
||||
this->cache.sign.UpdatePosition(pt.x, pt.y - 24 * ZOOM_LVL_BASE, this->Label(), STR_VIEWPORT_TOWN);
|
||||
this->cache.sign.UpdatePosition(HasBit(_display_opt, DO_SHOW_TOWN_NAMES) ? ZOOM_LVL_OUT_128X : ZOOM_LVL_END, pt.x, pt.y - 24 * ZOOM_LVL_BASE, this->Label(), STR_VIEWPORT_TOWN);
|
||||
|
||||
if (_viewport_sign_kdtree_valid) _viewport_sign_kdtree.Insert(ViewportSignKdtreeItem::MakeTown(this->index));
|
||||
|
||||
|
@@ -1677,7 +1677,7 @@ static void ViewportAddKdtreeSigns(DrawPixelInfo *dpi, bool towns_only)
|
||||
/* Don't draw if sign is owned by another company and competitor signs should be hidden.
|
||||
* Note: It is intentional that also signs owned by OWNER_NONE are hidden. Bankrupt
|
||||
* companies can leave OWNER_NONE signs after them. */
|
||||
if (!show_competitors && _local_company != si->owner && si->owner != OWNER_DEITY) break;
|
||||
if (!show_competitors && si->IsCompetitorOwned()) break;
|
||||
|
||||
signs.push_back(si);
|
||||
break;
|
||||
@@ -1725,9 +1725,9 @@ static void ViewportAddKdtreeSigns(DrawPixelInfo *dpi, bool towns_only)
|
||||
* @param str the string to show in the sign
|
||||
* @param str_small the string to show when zoomed out. STR_NULL means same as \a str
|
||||
*/
|
||||
void ViewportSign::UpdatePosition(int center, int top, StringID str, StringID str_small)
|
||||
void ViewportSign::UpdatePosition(ZoomLevel maxzoom, int center, int top, StringID str, StringID str_small)
|
||||
{
|
||||
if (this->width_normal != 0) this->MarkDirty();
|
||||
if (this->width_normal != 0) this->MarkDirty(maxzoom);
|
||||
|
||||
this->top = top;
|
||||
|
||||
@@ -1743,7 +1743,7 @@ void ViewportSign::UpdatePosition(int center, int top, StringID str, StringID st
|
||||
}
|
||||
this->width_small = VPSM_LEFT + Align(GetStringBoundingBox(buffer, FS_SMALL).width, 2) + VPSM_RIGHT;
|
||||
|
||||
this->MarkDirty();
|
||||
this->MarkDirty(maxzoom);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1754,6 +1754,8 @@ void ViewportSign::UpdatePosition(int center, int top, StringID str, StringID st
|
||||
*/
|
||||
void ViewportSign::MarkDirty(ZoomLevel maxzoom) const
|
||||
{
|
||||
if (maxzoom == ZOOM_LVL_END) return;
|
||||
|
||||
Rect zoomlevels[ZOOM_LVL_COUNT];
|
||||
|
||||
for (ZoomLevel zoom = ZOOM_LVL_BEGIN; zoom != ZOOM_LVL_END; zoom++) {
|
||||
|
@@ -62,8 +62,8 @@ struct ViewportSign {
|
||||
uint16 width_normal; ///< The width when not zoomed out (normal font)
|
||||
uint16 width_small; ///< The width when zoomed out (small font)
|
||||
|
||||
void UpdatePosition(int center, int top, StringID str, StringID str_small = STR_NULL);
|
||||
void MarkDirty(ZoomLevel maxzoom = ZOOM_LVL_MAX) const;
|
||||
void UpdatePosition(ZoomLevel maxzoom, int center, int top, StringID str, StringID str_small = STR_NULL);
|
||||
void MarkDirty(ZoomLevel maxzoom) const;
|
||||
};
|
||||
|
||||
/** Specialised ViewportSign that tracks whether it is valid for entering into a Kdtree */
|
||||
@@ -74,10 +74,10 @@ struct TrackedViewportSign : ViewportSign {
|
||||
* Update the position of the viewport sign.
|
||||
* Note that this function hides the base class function.
|
||||
*/
|
||||
void UpdatePosition(int center, int top, StringID str, StringID str_small = STR_NULL)
|
||||
void UpdatePosition(ZoomLevel maxzoom, int center, int top, StringID str, StringID str_small = STR_NULL)
|
||||
{
|
||||
this->kdtree_valid = true;
|
||||
this->ViewportSign::UpdatePosition(center, top, str, str_small);
|
||||
this->ViewportSign::UpdatePosition(maxzoom, center, top, str, str_small);
|
||||
}
|
||||
|
||||
|
||||
|
@@ -42,7 +42,8 @@ void Waypoint::UpdateVirtCoord()
|
||||
if (_viewport_sign_kdtree_valid && this->sign.kdtree_valid) _viewport_sign_kdtree.Remove(ViewportSignKdtreeItem::MakeWaypoint(this->index));
|
||||
|
||||
SetDParam(0, this->index);
|
||||
this->sign.UpdatePosition(pt.x, pt.y - 32 * ZOOM_LVL_BASE, STR_VIEWPORT_WAYPOINT);
|
||||
bool shown = HasBit(_display_opt, DO_SHOW_WAYPOINT_NAMES) && !(_local_company != this->owner && this->owner != OWNER_NONE && !HasBit(_display_opt, DO_SHOW_COMPETITOR_SIGNS));
|
||||
this->sign.UpdatePosition(shown ? ZOOM_LVL_DRAW_SPR : ZOOM_LVL_END, pt.x, pt.y - 32 * ZOOM_LVL_BASE, STR_VIEWPORT_WAYPOINT);
|
||||
|
||||
if (_viewport_sign_kdtree_valid) _viewport_sign_kdtree.Insert(ViewportSignKdtreeItem::MakeWaypoint(this->index));
|
||||
|
||||
|
Reference in New Issue
Block a user