Changeset - r24842:f3b877164faa
[Not reviewed]
master
0 2 0
Patric Stout - 3 years ago 2021-02-19 18:31:45
truebrain@openttd.org
Fix d437445c: also use std::chrono for the GRFFileScanner modal window

For some reason I only converted one of the two modal windows we
have, and completely forgot the other.

While at it, synchronize the way those two modal windows work
in terms of "next_update".
2 files changed with 12 insertions and 12 deletions:
0 comments (0 inline, 0 general)
src/genworld_gui.cpp
Show inline comments
 
@@ -1188,7 +1188,7 @@ struct GenWorldStatus {
 
	StringID cls;
 
	uint current;
 
	uint total;
 
	std::chrono::steady_clock::time_point timer;
 
	std::chrono::steady_clock::time_point next_update;
 
};
 

	
 
static GenWorldStatus _gws;
 
@@ -1290,11 +1290,11 @@ struct GenerateProgressWindow : public W
 
 */
 
void PrepareGenerateWorldProgress()
 
{
 
	_gws.cls     = STR_GENERATION_WORLD_GENERATION;
 
	_gws.cls = STR_GENERATION_WORLD_GENERATION;
 
	_gws.current = 0;
 
	_gws.total   = 0;
 
	_gws.total = 0;
 
	_gws.percent = 0;
 
	_gws.timer   = std::chrono::steady_clock::now() - std::chrono::milliseconds(MODAL_PROGRESS_REDRAW_TIMEOUT * 2); // Ensure we draw on first update
 
	_gws.next_update = std::chrono::steady_clock::now();
 
}
 

	
 
/**
 
@@ -1329,7 +1329,8 @@ static void _SetGeneratingWorldProgress(
 
	}
 

	
 
	/* Don't update the screen too often. So update it once in every once in a while... */
 
	if (!_network_dedicated && std::chrono::steady_clock::now() - _gws.timer < std::chrono::milliseconds(MODAL_PROGRESS_REDRAW_TIMEOUT)) return;
 
	if (!_network_dedicated && std::chrono::steady_clock::now() < _gws.next_update) return;
 
	_gws.next_update = std::chrono::steady_clock::now() + std::chrono::milliseconds(MODAL_PROGRESS_REDRAW_TIMEOUT);
 

	
 
	/* Percentage is about the number of completed tasks, so 'current - 1' */
 
	_gws.percent = percent_table[cls] + (percent_table[cls + 1] - percent_table[cls]) * (_gws.current == 0 ? 0 : _gws.current - 1) / _gws.total;
 
@@ -1364,8 +1365,6 @@ static void _SetGeneratingWorldProgress(
 
	_modal_progress_paint_mutex.lock();
 
	_modal_progress_work_mutex.lock();
 
	_modal_progress_paint_mutex.unlock();
 

	
 
	_gws.timer = std::chrono::steady_clock::now();
 
}
 

	
 
/**
src/newgrf_config.cpp
Show inline comments
 
@@ -578,12 +578,13 @@ compatible_grf:
 

	
 
/** Helper for scanning for files with GRF as extension */
 
class GRFFileScanner : FileScanner {
 
	uint next_update; ///< The next (realtime tick) we do update the screen.
 
	std::chrono::steady_clock::time_point next_update; ///< The next moment we do update the screen.
 
	uint num_scanned; ///< The number of GRFs we have scanned.
 

	
 
public:
 
	GRFFileScanner() : next_update(_realtime_tick), num_scanned(0)
 
	GRFFileScanner() : num_scanned(0)
 
	{
 
		this->next_update = std::chrono::steady_clock::now();
 
	}
 

	
 
	bool AddFile(const std::string &filename, size_t basepath_length, const std::string &tar_filename) override;
 
@@ -634,7 +635,9 @@ bool GRFFileScanner::AddFile(const std::
 
	}
 

	
 
	this->num_scanned++;
 
	if (this->next_update <= _realtime_tick) {
 
	if (std::chrono::steady_clock::now() >= this->next_update) {
 
		this->next_update = std::chrono::steady_clock::now() + std::chrono::milliseconds(MODAL_PROGRESS_REDRAW_TIMEOUT);
 

	
 
		_modal_progress_work_mutex.unlock();
 
		_modal_progress_paint_mutex.lock();
 

	
 
@@ -645,8 +648,6 @@ bool GRFFileScanner::AddFile(const std::
 

	
 
		_modal_progress_work_mutex.lock();
 
		_modal_progress_paint_mutex.unlock();
 

	
 
		this->next_update = _realtime_tick + MODAL_PROGRESS_REDRAW_TIMEOUT;
 
	}
 

	
 
	if (!added) {
0 comments (0 inline, 0 general)