|
|
/*
|
|
|
* This file is part of OpenTTD.
|
|
|
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
|
|
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
|
|
*/
|
|
|
|
|
|
/** @file driver.cpp Base for all driver handling. */
|
|
|
|
|
|
#include "stdafx.h"
|
|
|
#include "debug.h"
|
|
|
#include "error.h"
|
|
|
#include "sound/sound_driver.hpp"
|
|
|
#include "music/music_driver.hpp"
|
|
|
#include "video/video_driver.hpp"
|
|
|
#include "string_func.h"
|
|
|
#include "table/strings.h"
|
|
|
#include <string>
|
|
|
#include <sstream>
|
|
|
|
|
|
#include "safeguards.h"
|
|
|
|
|
|
std::string _ini_videodriver; ///< The video driver a stored in the configuration file.
|
|
|
std::vector<Dimension> _resolutions; ///< List of resolutions.
|
|
|
Dimension _cur_resolution; ///< The current resolution.
|
|
|
bool _rightclick_emulate; ///< Whether right clicking is emulated.
|
|
|
|
|
|
std::string _ini_sounddriver; ///< The sound driver a stored in the configuration file.
|
|
|
|
|
|
std::string _ini_musicdriver; ///< The music driver a stored in the configuration file.
|
|
|
|
|
|
std::string _ini_blitter; ///< The blitter as stored in the configuration file.
|
|
|
bool _blitter_autodetected; ///< Was the blitter autodetected or specified by the user?
|
|
|
|
|
|
/**
|
|
|
* Get a string parameter the list of parameters.
|
|
|
* @param parm The parameters.
|
|
|
* @param name The parameter name we're looking for.
|
|
|
* @return The parameter value.
|
|
|
*/
|
|
|
const char *GetDriverParam(const StringList &parm, const char *name)
|
|
@@ -90,62 +92,70 @@ void DriverFactoryBase::SelectDriver(con
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 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 std::string &name, Driver::Type type)
|
|
|
{
|
|
|
if (GetDrivers().size() == 0) return false;
|
|
|
|
|
|
if (name.empty()) {
|
|
|
/* Probe for this driver, but do not fall back to dedicated/null! */
|
|
|
for (int priority = 10; priority > 0; priority--) {
|
|
|
Drivers::iterator it = GetDrivers().begin();
|
|
|
for (; it != GetDrivers().end(); ++it) {
|
|
|
DriverFactoryBase *d = (*it).second;
|
|
|
|
|
|
/* Check driver type */
|
|
|
if (d->type != type) continue;
|
|
|
if (d->priority != priority) continue;
|
|
|
|
|
|
if (type == Driver::DT_VIDEO && !_video_hw_accel && d->UsesHardwareAcceleration()) continue;
|
|
|
|
|
|
Driver *oldd = *GetActiveDriver(type);
|
|
|
Driver *newd = d->CreateInstance();
|
|
|
*GetActiveDriver(type) = newd;
|
|
|
|
|
|
const char *err = newd->Start({});
|
|
|
if (err == nullptr) {
|
|
|
DEBUG(driver, 1, "Successfully probed %s driver '%s'", GetDriverTypeName(type), d->name);
|
|
|
delete oldd;
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
*GetActiveDriver(type) = oldd;
|
|
|
DEBUG(driver, 1, "Probing %s driver '%s' failed with error: %s", GetDriverTypeName(type), d->name, err);
|
|
|
delete newd;
|
|
|
|
|
|
if (type == Driver::DT_VIDEO && _video_hw_accel && d->UsesHardwareAcceleration()) {
|
|
|
_video_hw_accel = false;
|
|
|
ErrorMessageData msg(STR_VIDEO_DRIVER_ERROR, STR_VIDEO_DRIVER_ERROR_NO_HARDWARE_ACCELERATION);
|
|
|
ScheduleErrorMessage(msg);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
usererror("Couldn't find any suitable %s driver", GetDriverTypeName(type));
|
|
|
} else {
|
|
|
/* Extract the driver name and put parameter list in parm */
|
|
|
std::istringstream buffer(name);
|
|
|
std::string dname;
|
|
|
std::getline(buffer, dname, ':');
|
|
|
|
|
|
std::string param;
|
|
|
std::vector<std::string> parms;
|
|
|
while (std::getline(buffer, param, ',')) {
|
|
|
parms.push_back(param);
|
|
|
}
|
|
|
|
|
|
/* Find this driver */
|
|
|
Drivers::iterator it = GetDrivers().begin();
|
|
|
for (; it != GetDrivers().end(); ++it) {
|
|
|
DriverFactoryBase *d = (*it).second;
|
|
|
|
|
|
/* Check driver type */
|
|
|
if (d->type != type) continue;
|
|
|
|
|
|
/* Check driver name */
|