changeset 18009:9cb580113ce5 draft

(svn r22818) -Fix [FS#4742] (r22796, rlongago): don't spawn threads for world generation and NewGRF scanning when using the dedicated or null video driver regardless of the used blitter
author rubidium <rubidium@openttd.org>
date Wed, 24 Aug 2011 12:11:10 +0000
parents cf2c1b7a2231
children 944ec3d730d9
files src/genworld.cpp src/newgrf_config.cpp src/openttd.cpp src/video/dedicated_v.h src/video/null_v.h src/video/video_driver.hpp
diffstat 6 files changed, 20 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/src/genworld.cpp
+++ b/src/genworld.cpp
@@ -24,7 +24,7 @@
 #include "engine_func.h"
 #include "newgrf_storage.h"
 #include "water.h"
-#include "blitter/factory.hpp"
+#include "video/video_driver.hpp"
 #include "tilehighlight_func.h"
 #include "saveload/saveload.h"
 #include "void_map.h"
@@ -310,8 +310,7 @@
 		_gw.thread = NULL;
 	}
 
-	if (BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth() == 0 ||
-			!ThreadObject::New(&_GenerateWorld, NULL, &_gw.thread)) {
+	if (!_video_driver->HasGUI() || !ThreadObject::New(&_GenerateWorld, NULL, &_gw.thread)) {
 		DEBUG(misc, 1, "Cannot create genworld thread, reverting to single-threaded mode");
 		_gw.threaded = false;
 		_modal_progress_work_mutex->EndCritical();
--- a/src/newgrf_config.cpp
+++ b/src/newgrf_config.cpp
@@ -19,8 +19,7 @@
 #include "window_func.h"
 #include "progress.h"
 #include "thread/thread.h"
-#include "blitter/factory.hpp"
-#include "network/network.h"
+#include "video/video_driver.hpp"
 
 #include "fileio_func.h"
 #include "fios.h"
@@ -696,7 +695,7 @@
  */
 void ScanNewGRFFiles(NewGRFScanCallback *callback)
 {
-	if (BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth() == 0 || _network_dedicated || !ThreadObject::New(&DoScanNewGRFFiles, callback, NULL)) {
+	if (!_video_driver->HasGUI() || !ThreadObject::New(&DoScanNewGRFFiles, callback, NULL)) {
 		_modal_progress_work_mutex->EndCritical();
 		_modal_progress_paint_mutex->EndCritical();
 		DoScanNewGRFFiles(callback);
--- a/src/openttd.cpp
+++ b/src/openttd.cpp
@@ -766,7 +766,7 @@
 	SettingsDisableElrail(_settings_game.vehicle.disable_elrails);
 
 	/* In a dedicated server, the server does not play */
-	if (_network_dedicated || BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth() == 0) {
+	if (!_video_driver->HasGUI()) {
 		SetLocalCompany(COMPANY_SPECTATOR);
 		IConsoleCmdExec("exec scripts/game_start.scr 0");
 		return;
--- a/src/video/dedicated_v.h
+++ b/src/video/dedicated_v.h
@@ -29,6 +29,7 @@
 
 	/* virtual */ bool ToggleFullscreen(bool fullscreen);
 	/* virtual */ const char *GetName() const { return "dedicated"; }
+	/* virtual */ bool HasGUI() const { return false; }
 };
 
 /** Factory for the dedicated server video driver. */
--- a/src/video/null_v.h
+++ b/src/video/null_v.h
@@ -32,6 +32,7 @@
 
 	/* virtual */ bool ToggleFullscreen(bool fullscreen);
 	/* virtual */ const char *GetName() const { return "null"; }
+	/* virtual */ bool HasGUI() const { return false; }
 };
 
 /** Factory the null video driver. */
--- a/src/video/video_driver.hpp
+++ b/src/video/video_driver.hpp
@@ -46,6 +46,19 @@
 	 * @return True if the change succeeded.
 	 */
 	virtual bool ToggleFullscreen(bool fullscreen) = 0;
+
+	/**
+	 * Whether the driver has a graphical user interface with the end user.
+	 * Or in other words, whether we should spawn a thread for world generation
+	 * and NewGRF scanning so the graphical updates can keep coming. Otherwise
+	 * progress has to be shown on the console, which uses by definition another
+	 * thread/process for display purposes.
+	 * @return True for all drivers except null and dedicated.
+	 */
+	virtual bool HasGUI() const
+	{
+		return true;
+	}
 };
 
 /** Base of the factory for the video drivers. */