(svn r11092) -Add: allow 'blitter=<value>' in openttd.cfg to set the blitter (so you don't have to keep on doing 'openttd -b 32bpp-optimized'..)
authortruelight
Thu, 13 Sep 2007 12:28:53 +0000
changeset 8063 0e907a0b5add
parent 8062 9eb6efa04d44
child 8064 d850cf8f90de
(svn r11092) -Add: allow 'blitter=<value>' in openttd.cfg to set the blitter (so you don't have to keep on doing 'openttd -b 32bpp-optimized'..)
src/blitter/factory.hpp
src/openttd.cpp
src/settings.cpp
src/variables.h
--- a/src/blitter/factory.hpp	Wed Sep 12 23:56:21 2007 +0000
+++ b/src/blitter/factory.hpp	Thu Sep 13 12:28:53 2007 +0000
@@ -4,6 +4,7 @@
 #define BLITTER_FACTORY_HPP
 
 #include "base.hpp"
+#include "../string.h"
 #include <string>
 #include <map>
 
@@ -61,12 +62,15 @@
 	 */
 	static Blitter *SelectBlitter(const char *name)
 	{
+		const char *default_blitter = "8bpp-optimized";
+
 		if (GetBlitters().size() == 0) return NULL;
+		const char *bname = (StrEmpty(name)) ? default_blitter : name;
 
 		Blitters::iterator it = GetBlitters().begin();
 		for (; it != GetBlitters().end(); it++) {
 			BlitterFactoryBase *b = (*it).second;
-			if (strcasecmp(name, b->name) == 0) {
+			if (strcasecmp(bname, b->name) == 0) {
 				Blitter *newb = b->CreateInstance();
 				delete *GetActiveBlitter();
 				*GetActiveBlitter() = newb;
--- a/src/openttd.cpp	Wed Sep 12 23:56:21 2007 +0000
+++ b/src/openttd.cpp	Thu Sep 13 12:28:53 2007 +0000
@@ -89,8 +89,6 @@
 extern void ShowOSErrorBox(const char *buf);
 extern void SetDefaultRailGui();
 
-const char *_default_blitter = "8bpp-optimized";
-
 /* TODO: usrerror() for errors which are not of an internal nature but
  * caused by the user, i.e. missing files or fatal configuration errors.
  * Post-0.4.0 since Celestar doesn't want this in SVN before. --pasky */
@@ -474,7 +472,7 @@
 	if (!StrEmpty(musicdriver)) ttd_strlcpy(_ini_musicdriver, musicdriver, sizeof(_ini_musicdriver));
 	if (!StrEmpty(sounddriver)) ttd_strlcpy(_ini_sounddriver, sounddriver, sizeof(_ini_sounddriver));
 	if (!StrEmpty(videodriver)) ttd_strlcpy(_ini_videodriver, videodriver, sizeof(_ini_videodriver));
-	if (StrEmpty(blitter)) ttd_strlcpy(blitter, _default_blitter, sizeof(blitter));
+	if (!StrEmpty(blitter))     ttd_strlcpy(_ini_blitter, blitter, sizeof(_ini_blitter));
 	if (resolution[0] != 0) { _cur_resolution[0] = resolution[0]; _cur_resolution[1] = resolution[1]; }
 	if (startyear != INVALID_YEAR) _patches_newgame.starting_year = startyear;
 	if (generation_seed != GENERATE_NEW_SEED) _patches_newgame.generation_seed = generation_seed;
@@ -519,9 +517,11 @@
 	/* Initialize game palette */
 	GfxInitPalettes();
 
-	DEBUG(misc, 1, "Loading blitter '%s'...", blitter);
-	if (BlitterFactoryBase::SelectBlitter(blitter) == NULL)
-		error("Failed to select requested blitter '%s'; does it exist?", blitter);
+	DEBUG(misc, 1, "Loading blitter...");
+	if (BlitterFactoryBase::SelectBlitter(_ini_blitter) == NULL)
+		StrEmpty(_ini_blitter) ?
+			error("Failed to autoprobe blitter") :
+			error("Failed to select requested blitter '%s'; does it exist?", _ini_blitter);
 
 	DEBUG(driver, 1, "Loading drivers...");
 
--- a/src/settings.cpp	Wed Sep 12 23:56:21 2007 +0000
+++ b/src/settings.cpp	Thu Sep 13 12:28:53 2007 +0000
@@ -1245,6 +1245,7 @@
 	  SDTG_STR("videodriver",      SLE_STRB,C|S,0, _ini_videodriver,       NULL,    STR_NULL, NULL),
 	  SDTG_STR("musicdriver",      SLE_STRB,C|S,0, _ini_musicdriver,       NULL,    STR_NULL, NULL),
 	  SDTG_STR("sounddriver",      SLE_STRB,C|S,0, _ini_sounddriver,       NULL,    STR_NULL, NULL),
+	  SDTG_STR("blitter",          SLE_STRB,C|S,0, _ini_blitter,           NULL,    STR_NULL, NULL),
 	  SDTG_STR("language",         SLE_STRB, S, 0, _dynlang.curr_file,     NULL,    STR_NULL, NULL),
 	 SDTG_LIST("resolution",     SLE_UINT16, S, 0, _cur_resolution,   "640,480",    STR_NULL, NULL),
 	  SDTG_STR("screenshot_format",SLE_STRB, S, 0, _screenshot_format_name,NULL,    STR_NULL, NULL),
--- a/src/variables.h	Wed Sep 12 23:56:21 2007 +0000
+++ b/src/variables.h	Thu Sep 13 12:28:53 2007 +0000
@@ -315,7 +315,7 @@
 
 VARDEF Vehicle *_place_clicked_vehicle;
 
-VARDEF char _ini_videodriver[32], _ini_musicdriver[32], _ini_sounddriver[32];
+VARDEF char _ini_videodriver[32], _ini_musicdriver[32], _ini_sounddriver[32], _ini_blitter[32];
 
 VARDEF int _num_resolutions;
 VARDEF uint16 _resolutions[32][2];