Changeset - r24053:47b8c8b643e3
[Not reviewed]
master
0 3 0
Jonathan G Rennison - 5 years ago 2020-01-06 20:31:57
j.g.rennison@gmail.com
Change: Only resort industry directory window on production change if necessary
3 files changed with 25 insertions and 9 deletions:
0 comments (0 inline, 0 general)
src/industry.h
Show inline comments
 
@@ -194,7 +194,15 @@ struct IndustryBuildData {
 

	
 
	void MonthlyLoop();
 
};
 

	
 
extern IndustryBuildData _industry_builder;
 

	
 

	
 
/** Special values for the industry list window for the data parameter of #InvalidateWindowData. */
 
enum IndustryDirectoryInvalidateWindowData {
 
	IDIWD_FORCE_REBUILD,
 
	IDIWD_PRODUCTION_CHANGE,
 
	IDIWD_FORCE_RESORT,
 
};
 

	
 
#endif /* INDUSTRY_H */
src/industry_cmd.cpp
Show inline comments
 
@@ -201,13 +201,13 @@ Industry::~Industry()
 
/**
 
 * Invalidating some stuff after removing item from the pool.
 
 * @param index index of deleted item
 
 */
 
void Industry::PostDestructor(size_t index)
 
{
 
	InvalidateWindowData(WC_INDUSTRY_DIRECTORY, 0, 0);
 
	InvalidateWindowData(WC_INDUSTRY_DIRECTORY, 0, IDIWD_FORCE_REBUILD);
 
}
 

	
 

	
 
/**
 
 * Return a random valid industry.
 
 * @return random industry, nullptr if there are no industries
 
@@ -1897,13 +1897,13 @@ static void DoCreateNewIndustry(Industry
 
		}
 
	}
 

	
 
	if (GetIndustrySpec(i->type)->behaviour & INDUSTRYBEH_PLANT_ON_BUILT) {
 
		for (uint j = 0; j != 50; j++) PlantRandomFarmField(i);
 
	}
 
	InvalidateWindowData(WC_INDUSTRY_DIRECTORY, 0, 0);
 
	InvalidateWindowData(WC_INDUSTRY_DIRECTORY, 0, IDIWD_FORCE_REBUILD);
 

	
 
	if (!_generating_world) PopulateStationsNearby(i);
 
}
 

	
 
/**
 
 * Helper function for Build/Fund an industry
 
@@ -2826,13 +2826,13 @@ void IndustryDailyLoop()
 
		}
 
	}
 

	
 
	cur_company.Restore();
 

	
 
	/* production-change */
 
	InvalidateWindowData(WC_INDUSTRY_DIRECTORY, 0, 1);
 
	InvalidateWindowData(WC_INDUSTRY_DIRECTORY, 0, IDIWD_PRODUCTION_CHANGE);
 
}
 

	
 
void IndustryMonthlyLoop()
 
{
 
	Backup<CompanyID> cur_company(_current_company, OWNER_NONE, FILE_LINE);
 

	
 
@@ -2848,13 +2848,13 @@ void IndustryMonthlyLoop()
 
		}
 
	}
 

	
 
	cur_company.Restore();
 

	
 
	/* production-change */
 
	InvalidateWindowData(WC_INDUSTRY_DIRECTORY, 0, 1);
 
	InvalidateWindowData(WC_INDUSTRY_DIRECTORY, 0, IDIWD_PRODUCTION_CHANGE);
 
}
 

	
 

	
 
void InitializeIndustries()
 
{
 
	Industry::ResetIndustryCounts();
src/industry_gui.cpp
Show inline comments
 
@@ -1705,17 +1705,25 @@ public:
 
	 * Some data on this window has become invalid.
 
	 * @param data Information about the changed data.
 
	 * @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
 
	 */
 
	void OnInvalidateData(int data = 0, bool gui_scope = true) override
 
	{
 
		if (data == 0) {
 
			/* This needs to be done in command-scope to enforce rebuilding before resorting invalid data */
 
			this->industries.ForceRebuild();
 
		} else {
 
			this->industries.ForceResort();
 
		switch (data) {
 
			case IDIWD_FORCE_REBUILD:
 
				/* This needs to be done in command-scope to enforce rebuilding before resorting invalid data */
 
				this->industries.ForceRebuild();
 
				break;
 

	
 
			case IDIWD_PRODUCTION_CHANGE:
 
				if (this->industries.SortType() == 2) this->industries.ForceResort();
 
				break;
 

	
 
			default:
 
				this->industries.ForceResort();
 
				break;
 
		}
 
	}
 
};
 

	
 
Listing IndustryDirectoryWindow::last_sorting = {false, 0};
 
const Industry *IndustryDirectoryWindow::last_industry = nullptr;
0 comments (0 inline, 0 general)