Update to 1.11.0-RC1
This commit is contained in:
@@ -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;
|
||||
@@ -602,6 +603,9 @@ public:
|
||||
|
||||
bool GRFFileScanner::AddFile(const std::string &filename, size_t basepath_length, const std::string &tar_filename)
|
||||
{
|
||||
/* Abort if the user stopped the game during a scan. */
|
||||
if (_exit_game) return false;
|
||||
|
||||
GRFConfig *c = new GRFConfig(filename.c_str() + basepath_length);
|
||||
|
||||
bool added = true;
|
||||
@@ -634,20 +638,12 @@ bool GRFFileScanner::AddFile(const std::string &filename, size_t basepath_length
|
||||
}
|
||||
|
||||
this->num_scanned++;
|
||||
if (this->next_update <= _realtime_tick) {
|
||||
_modal_progress_work_mutex.unlock();
|
||||
_modal_progress_paint_mutex.lock();
|
||||
|
||||
const char *name = nullptr;
|
||||
if (c->name != nullptr) name = GetGRFStringFromGRFText(c->name);
|
||||
if (name == nullptr) name = c->filename;
|
||||
UpdateNewGRFScanStatus(this->num_scanned, name);
|
||||
|
||||
_modal_progress_work_mutex.lock();
|
||||
_modal_progress_paint_mutex.unlock();
|
||||
|
||||
this->next_update = _realtime_tick + MODAL_PROGRESS_REDRAW_TIMEOUT;
|
||||
}
|
||||
const char *name = nullptr;
|
||||
if (c->name != nullptr) name = GetGRFStringFromGRFText(c->name);
|
||||
if (name == nullptr) name = c->filename;
|
||||
UpdateNewGRFScanStatus(this->num_scanned, name);
|
||||
VideoDriver::GetInstance()->GameLoopPause();
|
||||
|
||||
if (!added) {
|
||||
/* File couldn't be opened, or is either not a NewGRF or is a
|
||||
@@ -675,8 +671,6 @@ static bool GRFSorter(GRFConfig * const &c1, GRFConfig * const &c2)
|
||||
*/
|
||||
void DoScanNewGRFFiles(NewGRFScanCallback *callback)
|
||||
{
|
||||
std::unique_lock<std::mutex> lock_work(_modal_progress_work_mutex);
|
||||
|
||||
ClearGRFConfigList(&_all_grfs);
|
||||
TarScanner::DoScan(TarScanner::NEWGRF);
|
||||
|
||||
@@ -708,13 +702,10 @@ void DoScanNewGRFFiles(NewGRFScanCallback *callback)
|
||||
NetworkAfterNewGRFScan();
|
||||
}
|
||||
|
||||
lock_work.unlock();
|
||||
std::lock_guard<std::mutex> lock_paint(_modal_progress_paint_mutex);
|
||||
|
||||
/* Yes... these are the NewGRF windows */
|
||||
InvalidateWindowClassesData(WC_SAVELOAD, 0, true);
|
||||
InvalidateWindowData(WC_GAME_OPTIONS, WN_GAME_OPTIONS_NEWGRF_STATE, GOID_NEWGRF_RESCANNED, true);
|
||||
if (callback != nullptr) callback->OnNewGRFsScanned();
|
||||
if (!_exit_game && callback != nullptr) callback->OnNewGRFsScanned();
|
||||
|
||||
DeleteWindowByClass(WC_MODAL_PROGRESS);
|
||||
SetModalProgress(false);
|
||||
@@ -732,15 +723,7 @@ void ScanNewGRFFiles(NewGRFScanCallback *callback)
|
||||
/* Only then can we really start, especially by marking the whole screen dirty. Get those other windows hidden!. */
|
||||
MarkWholeScreenDirty();
|
||||
|
||||
if (!UseThreadedModelProgress() || !VideoDriver::GetInstance()->HasGUI() || !StartNewThread(nullptr, "ottd:newgrf-scan", &DoScanNewGRFFiles, (NewGRFScanCallback *)callback)) { // Without the seemingly superfluous cast, strange compiler errors ensue.
|
||||
_modal_progress_work_mutex.unlock();
|
||||
_modal_progress_paint_mutex.unlock();
|
||||
DoScanNewGRFFiles(callback);
|
||||
_modal_progress_paint_mutex.lock();
|
||||
_modal_progress_work_mutex.lock();
|
||||
} else {
|
||||
UpdateNewGRFScanStatus(0, nullptr);
|
||||
}
|
||||
DoScanNewGRFFiles(callback);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user