changeset 18011:9243bb1fc073 draft

(svn r22820) -Codechange: perform a full (re)draw cycle in the first draw during progress instead of waiting 200ms
author rubidium <rubidium@openttd.org>
date Wed, 24 Aug 2011 12:18:53 +0000
parents 944ec3d730d9
children ab5d1e04c521
files src/gfx.cpp src/lang/english.txt src/newgrf_config.cpp src/newgrf_gui.cpp src/progress.cpp src/progress.h
diffstat 6 files changed, 32 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/src/gfx.cpp
+++ b/src/gfx.cpp
@@ -1561,7 +1561,7 @@
 		_modal_progress_work_mutex->EndCritical();
 
 		/* Wait a while and update _realtime_tick so we are given the rights */
-		CSleep(MODAL_PROGRESS_REDRAW_TIMEOUT);
+		if (!IsFirstModalProgressLoop()) CSleep(MODAL_PROGRESS_REDRAW_TIMEOUT);
 		_realtime_tick += MODAL_PROGRESS_REDRAW_TIMEOUT;
 		_modal_progress_paint_mutex->BeginCritical();
 		_modal_progress_work_mutex->BeginCritical();
--- a/src/lang/english.txt
+++ b/src/lang/english.txt
@@ -2527,6 +2527,7 @@
 STR_NEWGRF_SCAN_CAPTION                                         :{WHITE}Scanning NewGRFs
 STR_NEWGRF_SCAN_MESSAGE                                         :{BLACK}Scanning NewGRFs. Depending on the amount this can take a while...
 STR_NEWGRF_SCAN_STATUS                                          :{BLACK}{NUM} NewGRF{P "" s} scanned out of an estimated {NUM} NewGRF{P "" s}
+STR_NEWGRF_SCAN_ARCHIVES                                        :Scanning for archives
 
 # Sign list window
 STR_SIGN_LIST_CAPTION                                           :{WHITE}Sign List - {COMMA} Sign{P "" s}
--- a/src/newgrf_config.cpp
+++ b/src/newgrf_config.cpp
@@ -629,14 +629,7 @@
  */
 void DoScanNewGRFFiles(void *callback)
 {
-	/* First set the modal progress. This ensures that it will eventually let go of the paint mutex. */
-	SetModalProgress(true);
-	_modal_progress_paint_mutex->BeginCritical();
-
-	/* Only then can we really start, especially by marking the whole screen dirty. Get those other windows hidden!. */
-	MarkWholeScreenDirty();
 	_modal_progress_work_mutex->BeginCritical();
-	_modal_progress_paint_mutex->EndCritical();
 
 	ClearGRFConfigList(&_all_grfs);
 
@@ -694,12 +687,19 @@
  */
 void ScanNewGRFFiles(NewGRFScanCallback *callback)
 {
+	/* First set the modal progress. This ensures that it will eventually let go of the paint mutex. */
+	SetModalProgress(true);
+	/* Only then can we really start, especially by marking the whole screen dirty. Get those other windows hidden!. */
+	MarkWholeScreenDirty();
+
 	if (!_video_driver->HasGUI() || !ThreadObject::New(&DoScanNewGRFFiles, callback, NULL)) {
 		_modal_progress_work_mutex->EndCritical();
 		_modal_progress_paint_mutex->EndCritical();
 		DoScanNewGRFFiles(callback);
 		_modal_progress_paint_mutex->BeginCritical();
 		_modal_progress_work_mutex->BeginCritical();
+	} else {
+		UpdateNewGRFScanStatus(0, NULL);
 	}
 }
 
--- a/src/newgrf_gui.cpp
+++ b/src/newgrf_gui.cpp
@@ -1787,7 +1787,13 @@
 	void UpdateNewGRFScanStatus(uint num, const char *name)
 	{
 		free(this->last_name);
-		this->last_name = strdup(name);
+		if (name == NULL) {
+			char buf[256];
+			GetString(buf, STR_NEWGRF_SCAN_ARCHIVES, lastof(buf));
+			this->last_name = strdup(buf);
+		} else {
+			this->last_name = strdup(name);
+		}
 		this->scanned = num;
 		if (num > _settings_client.gui.last_newgrf_count) _settings_client.gui.last_newgrf_count = num;
 
--- a/src/progress.cpp
+++ b/src/progress.cpp
@@ -15,6 +15,7 @@
 
 /** Are we in a modal progress or not? */
 bool _in_modal_progress = false;
+bool _first_in_modal_loop = false;
 /** Rights for the performing work. */
 ThreadMutex *_modal_progress_work_mutex = ThreadMutex::New();
 /** Rights for the painting. */
@@ -22,9 +23,23 @@
 
 /**
  * Set the modal progress state.
+ * @note Makes IsFirstModalProgressLoop return true for the next call.
  * @param state The new state; are we modal or not?
  */
 void SetModalProgress(bool state)
 {
 	_in_modal_progress = state;
+	_first_in_modal_loop = true;
 }
+
+/**
+ * Check whether this is the first modal progress loop.
+ * @note Set by SetModalProgress, unset by calling this method.
+ * @return True if this is the first loop.
+ */
+bool IsFirstModalProgressLoop()
+{
+	bool ret = _first_in_modal_loop;
+	_first_in_modal_loop = false;
+	return ret;
+}
--- a/src/progress.h
+++ b/src/progress.h
@@ -26,10 +26,7 @@
 	return _in_modal_progress;
 }
 
-/**
- * Set the modal progress state.
- * @param state The new state; are we modal or not?
- */
+bool IsFirstModalProgressLoop();
 void SetModalProgress(bool state);
 
 extern class ThreadMutex *_modal_progress_work_mutex;