Cache viewport station/waypoint sign infomation
This commit is contained in:
@@ -67,6 +67,7 @@ void InitializeGame(uint size_x, uint size_y, bool reset_date, bool reset_settin
|
|||||||
AllocateMap(size_x, size_y);
|
AllocateMap(size_x, size_y);
|
||||||
|
|
||||||
ViewportMapClearTunnelCache();
|
ViewportMapClearTunnelCache();
|
||||||
|
ViewportClearStationSignCache();
|
||||||
ClearCommandLog();
|
ClearCommandLog();
|
||||||
|
|
||||||
_pause_mode = PM_UNPAUSED;
|
_pause_mode = PM_UNPAUSED;
|
||||||
|
@@ -373,6 +373,7 @@ static void ShutdownGame()
|
|||||||
UninitFreeType();
|
UninitFreeType();
|
||||||
|
|
||||||
ViewportMapClearTunnelCache();
|
ViewportMapClearTunnelCache();
|
||||||
|
ViewportClearStationSignCache();
|
||||||
ClearCommandLog();
|
ClearCommandLog();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -51,6 +51,7 @@ BaseStation::~BaseStation()
|
|||||||
DeleteWindowById(WC_DEPARTURES_BOARD, this->index);
|
DeleteWindowById(WC_DEPARTURES_BOARD, this->index);
|
||||||
|
|
||||||
this->sign.MarkDirty();
|
this->sign.MarkDirty();
|
||||||
|
ViewportClearStationSignCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
Station::Station(TileIndex tile) :
|
Station::Station(TileIndex tile) :
|
||||||
|
@@ -425,6 +425,7 @@ void Station::UpdateVirtCoord()
|
|||||||
this->sign.UpdatePosition(pt.x, pt.y, STR_VIEWPORT_STATION);
|
this->sign.UpdatePosition(pt.x, pt.y, STR_VIEWPORT_STATION);
|
||||||
|
|
||||||
SetWindowDirty(WC_STATION_VIEW, this->index);
|
SetWindowDirty(WC_STATION_VIEW, this->index);
|
||||||
|
ViewportClearStationSignCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Update the virtual coords needed to draw the station sign for all stations. */
|
/** Update the virtual coords needed to draw the station sign for all stations. */
|
||||||
|
@@ -264,6 +264,18 @@ std::vector<DrawnPathRouteTileLine> _vp_route_paths_last_mark_dirty;
|
|||||||
|
|
||||||
static void MarkRoutePathsDirty(const std::vector<DrawnPathRouteTileLine> &lines);
|
static void MarkRoutePathsDirty(const std::vector<DrawnPathRouteTileLine> &lines);
|
||||||
|
|
||||||
|
struct ViewportStationSignCacheEntry {
|
||||||
|
int32 top; ///< The top of the sign
|
||||||
|
int32 left; ///< The left bound of the sign
|
||||||
|
int32 right; ///< The right bound of the sign
|
||||||
|
StationID id; ///< Station ID
|
||||||
|
};
|
||||||
|
|
||||||
|
static byte _viewport_station_sign_cache_display_mode = 0;
|
||||||
|
static const byte VIEWPORT_STATION_SIGN_CACHE_DISPLAY_MODE_MASK = ((1 << DO_SHOW_STATION_NAMES) | (1 << DO_SHOW_WAYPOINT_NAMES) | (1 << DO_SHOW_COMPETITOR_SIGNS));
|
||||||
|
static OwnerByte _viewport_station_sign_cache_local_company { INVALID_OWNER };
|
||||||
|
static std::vector<ViewportStationSignCacheEntry> _viewport_station_sign_cache;
|
||||||
|
|
||||||
TileHighlightData _thd;
|
TileHighlightData _thd;
|
||||||
static TileInfo *_cur_ti;
|
static TileInfo *_cur_ti;
|
||||||
bool _draw_bounding_boxes = false;
|
bool _draw_bounding_boxes = false;
|
||||||
@@ -1391,6 +1403,26 @@ struct ViewportAddStringApproxBoundsChecker {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct ViewportStationSignCacheApproxBoundsChecker {
|
||||||
|
int top;
|
||||||
|
int bottom;
|
||||||
|
int left;
|
||||||
|
int right;
|
||||||
|
|
||||||
|
ViewportStationSignCacheApproxBoundsChecker(const DrawPixelInfo *dpi)
|
||||||
|
{
|
||||||
|
this->top = dpi->top - ScaleByZoom(VPSM_TOP + FONT_HEIGHT_NORMAL + VPSM_BOTTOM, dpi->zoom);
|
||||||
|
this->bottom = dpi->top + dpi->height;
|
||||||
|
this->left = dpi->left;
|
||||||
|
this->right = dpi->left + dpi->width;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool IsStationSignCacheEntryMaybeOnScreen(const ViewportStationSignCacheEntry *sign) const
|
||||||
|
{
|
||||||
|
return !(this->bottom < sign->top || this->top > sign->top || this->right < sign->left || this->left > sign->right);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
static void ViewportAddTownNames(DrawPixelInfo *dpi)
|
static void ViewportAddTownNames(DrawPixelInfo *dpi)
|
||||||
{
|
{
|
||||||
if (!HasBit(_display_opt, DO_SHOW_TOWN_NAMES) || _game_mode == GM_MENU) return;
|
if (!HasBit(_display_opt, DO_SHOW_TOWN_NAMES) || _game_mode == GM_MENU) return;
|
||||||
@@ -1406,12 +1438,18 @@ static void ViewportAddTownNames(DrawPixelInfo *dpi)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ViewportClearStationSignCache()
|
||||||
static void ViewportAddStationNames(DrawPixelInfo *dpi)
|
|
||||||
{
|
{
|
||||||
if (!(HasBit(_display_opt, DO_SHOW_STATION_NAMES) || HasBit(_display_opt, DO_SHOW_WAYPOINT_NAMES)) || _game_mode == GM_MENU) return;
|
_viewport_station_sign_cache.clear();
|
||||||
|
_viewport_station_sign_cache_display_mode = 0;
|
||||||
|
_viewport_station_sign_cache_local_company = INVALID_OWNER;
|
||||||
|
}
|
||||||
|
|
||||||
ViewportAddStringApproxBoundsChecker checker(dpi);
|
void ViewportFillStationSignCache()
|
||||||
|
{
|
||||||
|
_viewport_station_sign_cache.clear();
|
||||||
|
_viewport_station_sign_cache_display_mode = _display_opt & VIEWPORT_STATION_SIGN_CACHE_DISPLAY_MODE_MASK;
|
||||||
|
_viewport_station_sign_cache_local_company = _local_company;
|
||||||
|
|
||||||
const BaseStation *st;
|
const BaseStation *st;
|
||||||
FOR_ALL_BASE_STATIONS(st) {
|
FOR_ALL_BASE_STATIONS(st) {
|
||||||
@@ -1424,7 +1462,27 @@ static void ViewportAddStationNames(DrawPixelInfo *dpi)
|
|||||||
/* Don't draw if station is owned by another company and competitor station names are hidden. Stations owned by none are never ignored. */
|
/* Don't draw if station is owned by another company and competitor station names are hidden. Stations owned by none are never ignored. */
|
||||||
if (!HasBit(_display_opt, DO_SHOW_COMPETITOR_SIGNS) && _local_company != st->owner && st->owner != OWNER_NONE) continue;
|
if (!HasBit(_display_opt, DO_SHOW_COMPETITOR_SIGNS) && _local_company != st->owner && st->owner != OWNER_NONE) continue;
|
||||||
|
|
||||||
if (!checker.IsSignMaybeOnScreen(&st->sign)) continue;
|
int sign_half_width = max(ScaleByZoom(st->sign.width_normal, ZOOM_LVL_OUT_8X), ScaleByZoom(st->sign.width_small, ZOOM_LVL_DRAW_SPR)) / 2;
|
||||||
|
_viewport_station_sign_cache.push_back({ st->sign.top, st->sign.center - sign_half_width, st->sign.center + sign_half_width, st->index });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ViewportAddStationNames(DrawPixelInfo *dpi)
|
||||||
|
{
|
||||||
|
if (!(HasBit(_display_opt, DO_SHOW_STATION_NAMES) || HasBit(_display_opt, DO_SHOW_WAYPOINT_NAMES)) || _game_mode == GM_MENU) return;
|
||||||
|
|
||||||
|
if (_viewport_station_sign_cache_display_mode != (_display_opt & VIEWPORT_STATION_SIGN_CACHE_DISPLAY_MODE_MASK) || _viewport_station_sign_cache_local_company != _local_company) {
|
||||||
|
ViewportFillStationSignCache();
|
||||||
|
}
|
||||||
|
|
||||||
|
ViewportStationSignCacheApproxBoundsChecker checker(dpi);
|
||||||
|
|
||||||
|
for (const ViewportStationSignCacheEntry &entry : _viewport_station_sign_cache) {
|
||||||
|
|
||||||
|
if (!checker.IsStationSignCacheEntryMaybeOnScreen(&entry)) continue;
|
||||||
|
|
||||||
|
const BaseStation *st = BaseStation::Get(entry.id);
|
||||||
|
bool is_station = Station::IsExpected(st);
|
||||||
|
|
||||||
ViewportAddString(dpi, ZOOM_LVL_OUT_16X, &st->sign,
|
ViewportAddString(dpi, ZOOM_LVL_OUT_16X, &st->sign,
|
||||||
is_station ? STR_VIEWPORT_STATION : STR_VIEWPORT_WAYPOINT,
|
is_station ? STR_VIEWPORT_STATION : STR_VIEWPORT_WAYPOINT,
|
||||||
|
@@ -101,6 +101,7 @@ Point GetViewportStationMiddle(const ViewPort *vp, const Station *st);
|
|||||||
void ShowTooltipForTile(Window *w, const TileIndex tile);
|
void ShowTooltipForTile(Window *w, const TileIndex tile);
|
||||||
|
|
||||||
void ViewportMapClearTunnelCache();
|
void ViewportMapClearTunnelCache();
|
||||||
|
void ViewportClearStationSignCache();
|
||||||
void ViewportMapInvalidateTunnelCacheByTile(const TileIndex tile);
|
void ViewportMapInvalidateTunnelCacheByTile(const TileIndex tile);
|
||||||
|
|
||||||
void DrawTileSelectionRect(const TileInfo *ti, PaletteID pal);
|
void DrawTileSelectionRect(const TileInfo *ti, PaletteID pal);
|
||||||
|
@@ -44,6 +44,7 @@ void Waypoint::UpdateVirtCoord()
|
|||||||
this->sign.UpdatePosition(pt.x, pt.y - 32 * ZOOM_LVL_BASE, STR_VIEWPORT_WAYPOINT);
|
this->sign.UpdatePosition(pt.x, pt.y - 32 * ZOOM_LVL_BASE, STR_VIEWPORT_WAYPOINT);
|
||||||
/* Recenter viewport */
|
/* Recenter viewport */
|
||||||
InvalidateWindowData(WC_WAYPOINT_VIEW, this->index);
|
InvalidateWindowData(WC_WAYPOINT_VIEW, this->index);
|
||||||
|
ViewportClearStationSignCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user