diff options
author | rubidium <rubidium@openttd.org> | 2014-04-28 21:06:51 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2014-04-28 21:06:51 +0000 |
commit | b476086c394c6bcf893f292ef67565ef2b5496a2 (patch) | |
tree | 7bbdfcc4597cae1378070d82c5da36c8668171e0 /src/driver.cpp | |
parent | 3b634b628c8b8ce30cdd11d38a38cf2f455a1c73 (diff) | |
download | openttd-b476086c394c6bcf893f292ef67565ef2b5496a2.tar.xz |
(svn r26538) -Codechange: remove double accounting of the drivers
Diffstat (limited to 'src/driver.cpp')
-rw-r--r-- | src/driver.cpp | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/src/driver.cpp b/src/driver.cpp index 2e90c2df1..70f695122 100644 --- a/src/driver.cpp +++ b/src/driver.cpp @@ -18,17 +18,14 @@ #include "safeguards.h" -VideoDriver *_video_driver; ///< The currently active video driver. char *_ini_videodriver; ///< The video driver a stored in the configuration file. int _num_resolutions; ///< The number of resolutions. Dimension _resolutions[32]; ///< List of resolutions. Dimension _cur_resolution; ///< The current resolution. bool _rightclick_emulate; ///< Whether right clicking is emulated. -SoundDriver *_sound_driver; ///< The currently active sound driver. char *_ini_sounddriver; ///< The sound driver a stored in the configuration file. -MusicDriver *_music_driver; ///< The currently active music driver. char *_ini_musicdriver; ///< The music driver a stored in the configuration file. char *_ini_blitter; ///< The blitter as stored in the configuration file. @@ -88,9 +85,25 @@ int GetDriverParamInt(const char * const *parm, const char *name, int def) * @param type the type of driver to select * @post Sets the driver so GetCurrentDriver() returns it too. */ -Driver *DriverFactoryBase::SelectDriver(const char *name, Driver::Type type) +void DriverFactoryBase::SelectDriver(const char *name, Driver::Type type) { - if (GetDrivers().size() == 0) return NULL; + if (!DriverFactoryBase::SelectDriverImpl(name, type)) { + StrEmpty(name) ? + usererror("Failed to autoprobe %s driver", GetDriverTypeName(type)) : + usererror("Failed to select requested %s driver '%s'", GetDriverTypeName(type), name); + } +} + +/** + * Find the requested driver and return its class. + * @param name the driver to select. + * @param type the type of driver to select + * @post Sets the driver so GetCurrentDriver() returns it too. + * @return True upon success, otherwise false. + */ +bool DriverFactoryBase::SelectDriverImpl(const char *name, Driver::Type type) +{ + if (GetDrivers().size() == 0) return false; if (StrEmpty(name)) { /* Probe for this driver, but do not fall back to dedicated/null! */ @@ -109,7 +122,7 @@ Driver *DriverFactoryBase::SelectDriver(const char *name, Driver::Type type) DEBUG(driver, 1, "Successfully probed %s driver '%s'", GetDriverTypeName(type), d->name); delete *GetActiveDriver(type); *GetActiveDriver(type) = newd; - return newd; + return true; } DEBUG(driver, 1, "Probing %s driver '%s' failed with error: %s", GetDriverTypeName(type), d->name, err); @@ -160,7 +173,7 @@ Driver *DriverFactoryBase::SelectDriver(const char *name, Driver::Type type) DEBUG(driver, 1, "Successfully loaded %s driver '%s'", GetDriverTypeName(type), d->name); delete *GetActiveDriver(type); *GetActiveDriver(type) = newd; - return newd; + return true; } usererror("No such %s driver: %s\n", GetDriverTypeName(type), buffer); } |