Go to the documentation of this file.
17 #include "table/strings.h"
52 if (parm.empty())
return nullptr;
54 size_t len = strlen(name);
55 for (
auto &p : parm) {
56 if (p.compare(0, len, name) == 0) {
57 if (p.length() == len)
return "";
58 if (p[len] ==
'=')
return p.c_str() + len + 1;
85 return p !=
nullptr ? atoi(p) : def;
132 if (!filename.empty()) {
133 unlink(filename.c_str());
138 ErrorMessageData msg(STR_VIDEO_DRIVER_ERROR, STR_VIDEO_DRIVER_ERROR_HARDWARE_ACCELERATION_CRASH,
true);
152 const char *err = newd->
Start({});
153 if (err ==
nullptr) {
165 ErrorMessageData msg(STR_VIDEO_DRIVER_ERROR, STR_VIDEO_DRIVER_ERROR_NO_HARDWARE_ACCELERATION,
true);
173 std::istringstream buffer(
name);
175 std::getline(buffer, dname,
':');
178 std::vector<std::string> parms;
179 while (std::getline(buffer, param,
',')) {
180 parms.push_back(param);
192 if (strcasecmp(dname.c_str(), d->
name) != 0)
continue;
197 const char *err = newd->
Start(parms);
198 if (err !=
nullptr) {
200 usererror(
"Unable to load driver '%s'. The error was: %s", d->
name, err);
221 if (!filename.empty()) unlink(filename.c_str());
259 type(type), priority(priority), name(name), description(description)
267 assert(drivers.find(buf) == drivers.end());
268 drivers.insert(Drivers::value_type(buf,
this));
281 Drivers::iterator it =
GetDrivers().find(buf);
static const char * GetDriverTypeName(Driver::Type type)
Get the driver type name.
static bool SelectDriverImpl(const std::string &name, Driver::Type type)
Find the requested driver and return its class.
static Driver ** GetActiveDriver(Driver::Type type)
Get the active driver for the given type.
void CDECL usererror(const char *s,...)
Error handling for fatal user errors.
Dimensions (a width and height) of a rectangle in 2D.
const char * name
The name of the drivers of this factory.
std::string _ini_blitter
The blitter as stored in the configuration file.
DriverFactoryBase(Driver::Type type, int priority, const char *name, const char *description)
Construct a new DriverFactory.
virtual Driver * CreateInstance() const =0
Create an instance of this driver-class.
virtual ~DriverFactoryBase()
Frees memory used for this->name.
const char * GetDriverParam(const StringList &parm, const char *name)
Get a string parameter the list of parameters.
static Drivers & GetDrivers()
Get the map with drivers.
std::string _ini_musicdriver
The music driver a stored in the configuration file.
@ BASE_DIR
Base directory for all subdirectories.
int priority
The priority of this factory.
std::map< std::string, DriverFactoryBase * > Drivers
Type for a map of drivers.
static char * GetDriversInfo(char *p, const char *last)
Build a human readable list of available drivers, grouped by type.
FILE * FioFOpenFile(const std::string &filename, const char *mode, Subdirectory subdir, size_t *filesize)
Opens a OpenTTD file somewhere in a personal or global directory.
virtual const char * Start(const StringList &parm)=0
Start this driver.
Driver::Type type
The type of driver.
std::vector< std::string > StringList
Type for a list of strings.
std::vector< Dimension > _resolutions
List of resolutions.
The data of the error message.
@ DT_END
Helper for iteration.
int GetDriverParamInt(const StringList &parm, const char *name, int def)
Get an integer parameter the list of parameters.
bool _rightclick_emulate
Whether right clicking is emulated.
@ DT_BEGIN
Helper for iteration.
@ DT_VIDEO
A video driver.
bool _blitter_autodetected
Was the blitter autodetected or specified by the user?
std::string _ini_sounddriver
The sound driver a stored in the configuration file.
bool _video_hw_accel
Whether to consider hardware accelerated video drivers.
void ScheduleErrorMessage(const ErrorMessageData &data)
Schedule an error.
virtual bool UsesHardwareAcceleration() const
Does the driver use hardware acceleration (video-drivers only).
const char * GetDescription() const
Get a nice description of the driver-class.
int CDECL seprintf(char *str, const char *last, const char *format,...)
Safer implementation of snprintf; same as snprintf except:
static void SelectDriver(const std::string &name, Driver::Type type)
Find the requested driver and return its class.
#define Debug(name, level, format_string,...)
Ouptut a line of debugging information.
A driver for communicating with the user.
std::string FioFindFullPath(Subdirectory subdir, const char *filename)
Find a path to the filename in one of the search directories.
char * strecpy(char *dst, const char *src, const char *last)
Copies characters from one buffer to another.
#define lastof(x)
Get the last element of an fixed size array.
bool GetDriverParamBool(const StringList &parm, const char *name)
Get a boolean parameter the list of parameters.
Dimension _cur_resolution
The current resolution.
Base for all driver factories.
std::string _ini_videodriver
The video driver a stored in the configuration file.
static void MarkVideoDriverOperational()
Mark the current video driver as operational.
void FioFCloseFile(FILE *f)
Close a file in a safe way.
static const std::string HWACCELERATION_TEST_FILE
Filename to test if we crashed last time we tried to use hardware acceleration.