Plans: Cache whether any plans are currently visible

pull/642/head
Jonathan G Rennison 3 months ago
parent 1159224d6f
commit 3d87cfeca5

@ -42,6 +42,7 @@
#include "timer/timer.h"
#include "timer/timer_game_tick.h"
#include "tilehighlight_func.h"
#include "plans_func.h"
#include "table/strings.h"
@ -147,6 +148,7 @@ void SetLocalCompany(CompanyID new_company)
InvalidateWindowClassesData(WC_SIGN_LIST, -1);
InvalidateWindowClassesData(WC_GOALS_LIST);
ClearZoningCaches();
InvalidatePlanCaches();
}
/**

@ -58,6 +58,7 @@
#include "pathfinder/yapf/yapf_cache.h"
#include "debug_desync.h"
#include "event_logs.h"
#include "plans_func.h"
#include "table/strings.h"
#include "table/pricebase.h"
@ -669,6 +670,8 @@ void ChangeOwnershipOfCompanyItems(Owner old_owner, Owner new_owner)
extern void MarkAllViewportMapLandscapesDirty();
MarkAllViewportMapLandscapesDirty();
InvalidatePlanCaches();
}
/**

@ -41,6 +41,7 @@
#include "tbtr_template_vehicle_func.h"
#include "event_logs.h"
#include "string_func.h"
#include "plans_func.h"
#include "3rdparty/monocypher/monocypher.h"
#include "safeguards.h"
@ -176,6 +177,7 @@ void InitializeGame(uint size_x, uint size_y, bool reset_date, bool reset_settin
ClearAllSignalSpeedRestrictions();
ClearZoningCaches();
InvalidatePlanCaches();
IntialiseOrderDestinationRefcountMap();
ResetPersistentNewGRFData();

@ -93,6 +93,7 @@
#include "timer/timer_game_realtime.h"
#include "timer/timer_game_tick.h"
#include "network/network_sync.h"
#include "plans_func.h"
#include "linkgraph/linkgraphschedule.h"
#include "tracerestrict.h"
@ -507,6 +508,7 @@ static void ShutdownGame()
ClearAllSignalSpeedRestrictions();
ClearZoningCaches();
InvalidatePlanCaches();
ClearOrderDestinationRefcountMap();
/* No NewGRFs were loaded when it was still bootstrapping. */

@ -17,6 +17,9 @@ INSTANTIATE_POOL_METHODS(Plan)
Plan *_current_plan = nullptr;
Plan *_new_plan = nullptr;
uint64_t _plan_update_counter = 0;
uint64_t _last_plan_visibility_check = 0;
bool _last_plan_visibility_check_result = false;
void PlanLine::UpdateVisualExtents()
{
@ -63,3 +66,25 @@ bool Plan::ValidateNewLine()
}
return ret;
}
void UpdateAreAnyPlansVisible()
{
_last_plan_visibility_check = _plan_update_counter;
if (_current_plan && _current_plan->temp_line->tiles.size() > 1) {
_last_plan_visibility_check_result = true;
return;
}
for (const Plan *p : Plan::Iterate()) {
if (!p->IsVisible()) continue;
for (const PlanLine *pl : p->lines) {
if (pl->visible) {
_last_plan_visibility_check_result = true;
return;
}
}
}
_last_plan_visibility_check_result = false;
}

@ -36,6 +36,7 @@ struct PlanLine {
{
this->visible = true;
this->focused = false;
_plan_update_counter++;
}
~PlanLine()
@ -46,6 +47,7 @@ struct PlanLine {
void Clear()
{
this->tiles.clear();
_plan_update_counter++;
}
bool AppendTile(TileIndex tile)
@ -81,12 +83,16 @@ struct PlanLine {
if (this->tiles.size() * sizeof(TileIndex) >= MAX_CMD_TEXT_LENGTH) return false;
this->tiles.push_back(tile);
_plan_update_counter++;
return true;
}
void SetFocus(bool focused)
{
if (this->focused != focused) this->MarkDirty();
if (this->focused != focused) {
this->MarkDirty();
_plan_update_counter++;
}
this->focused = focused;
}
@ -98,7 +104,10 @@ struct PlanLine {
void SetVisibility(bool visible)
{
if (this->visible != visible) this->MarkDirty();
if (this->visible != visible) {
this->MarkDirty();
_plan_update_counter++;
}
this->visible = visible;
}
@ -176,6 +185,7 @@ struct Plan : PlanPool::PoolItem<&_plan_pool> {
void SetVisibility(bool visible, bool do_lines = true)
{
this->visible = visible;
_plan_update_counter++;
if (!do_lines) return;
for (PlanLineVector::iterator it = lines.begin(); it != lines.end(); it++) {

@ -160,6 +160,7 @@ CommandCost CmdChangePlanColour(TileIndex tile, DoCommandFlag flags, uint32_t p1
if (ret.Failed()) return ret;
if (flags & DC_EXEC) {
p->colour = (Colours)p2;
_plan_update_counter++;
Window *w = FindWindowById(WC_PLANS, 0);
if (w) w->InvalidateData(INVALID_PLAN, false);
for (const PlanLine *line : p->lines) {

@ -12,9 +12,24 @@
#include "plans_type.h"
void ShowPlansWindow();
extern Plan *_new_plan;
extern Plan *_current_plan;
extern uint64_t _plan_update_counter;
extern uint64_t _last_plan_visibility_check;
extern bool _last_plan_visibility_check_result;
void ShowPlansWindow();
void UpdateAreAnyPlansVisible();
inline bool AreAnyPlansVisible()
{
if (_plan_update_counter != _last_plan_visibility_check) UpdateAreAnyPlansVisible();
return _last_plan_visibility_check_result;
}
inline void InvalidatePlanCaches()
{
_plan_update_counter++;
}
#endif /* PLANS_FUNC_H */

@ -2726,7 +2726,7 @@ static void ViewportDrawVehicleRouteSteps(const Viewport * const vp)
void ViewportDrawPlans(const Viewport *vp)
{
if (Plan::GetNumItems() == 0 && !(_current_plan && _current_plan->temp_line->tiles.size() > 1)) return;
if (!AreAnyPlansVisible()) return;
DrawPixelInfo dpi_for_text = _vdd->MakeDPIForText();
_cur_dpi = &dpi_for_text;

Loading…
Cancel
Save