18 #include "table/strings.h"
46 if (parm.empty())
return nullptr;
48 size_t len = strlen(name);
49 for (
auto &p : parm) {
50 if (p.compare(0, len, name) == 0) {
51 if (p.length() == len)
return "";
52 if (p[len] ==
'=')
return p.c_str() + len + 1;
79 return p !=
nullptr ? atoi(p) : def;
125 if (!filename.empty()) {
131 ErrorMessageData msg(STR_VIDEO_DRIVER_ERROR, STR_VIDEO_DRIVER_ERROR_HARDWARE_ACCELERATION_CRASH,
true);
144 auto err = newd->
Start({});
157 ErrorMessageData msg(STR_VIDEO_DRIVER_ERROR, STR_VIDEO_DRIVER_ERROR_NO_HARDWARE_ACCELERATION,
true);
165 std::istringstream buffer(
name);
167 std::getline(buffer, dname,
':');
170 std::vector<std::string> parms;
171 while (std::getline(buffer, param,
',')) {
172 parms.push_back(param);
188 auto err = newd->
Start(parms);
191 UserError(
"Unable to load driver '{}'. The error was: {}", d->
name, *err);
212 if (!filename.empty())
FioRemove(filename);
233 fmt::format_to(output_iterator,
"\n");
245 type(type), priority(priority), name(name), description(description)
251 assert(drivers.find(typed_name) == drivers.end());
252 drivers.insert(Drivers::value_type(typed_name,
this));
263 Drivers::iterator it =
GetDrivers().find(typed_name);
Base for all driver factories.
static void MarkVideoDriverOperational()
Mark the current video driver as operational.
std::string_view name
The name of the drivers of this factory.
std::string_view GetDescription() const
Get a nice description of the driver-class.
std::map< std::string, DriverFactoryBase * > Drivers
Type for a map of drivers.
virtual bool UsesHardwareAcceleration() const
Does the driver use hardware acceleration (video-drivers only).
virtual Driver * CreateInstance() const =0
Create an instance of this driver-class.
static void SelectDriver(const std::string &name, Driver::Type type)
Find the requested driver and return its class.
static std::string_view 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 Drivers & GetDrivers()
Get the map with drivers.
DriverFactoryBase(Driver::Type type, int priority, const char *name, const char *description)
Construct a new DriverFactory.
static void GetDriversInfo(std::back_insert_iterator< std::string > &output_iterator)
Build a human readable list of available drivers, grouped by type.
Driver::Type type
The type of driver.
static Driver ** GetActiveDriver(Driver::Type type)
Get the active driver for the given type.
virtual ~DriverFactoryBase()
Frees memory used for this->name.
int priority
The priority of this factory.
A driver for communicating with the user.
virtual std::optional< std::string_view > Start(const StringList &parm)=0
Start this driver.
@ DT_END
Helper for iteration.
@ DT_VIDEO
A video driver.
@ DT_BEGIN
Helper for iteration.
The data of the error message.
Functions related to debugging.
#define Debug(category, level, format_string,...)
Ouptut a line of debugging information.
const char * GetDriverParam(const StringList &parm, const char *name)
Get a string parameter the list of parameters.
bool _blitter_autodetected
Was the blitter autodetected or specified by the user?
std::string _ini_videodriver
The video driver a stored in the configuration file.
int GetDriverParamInt(const StringList &parm, const char *name, int def)
Get an integer parameter the list of parameters.
std::string _ini_musicdriver
The music 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_blitter
The blitter as stored in the configuration file.
bool GetDriverParamBool(const StringList &parm, const char *name)
Get a boolean parameter the list of parameters.
std::string _ini_sounddriver
The sound driver a stored in the configuration file.
static const std::string HWACCELERATION_TEST_FILE
Filename to test if we crashed last time we tried to use hardware acceleration.
Functions related to errors.
void ScheduleErrorMessage(ErrorList &datas)
Schedule a list of errors.
Error reporting related functions.
std::string FioFindFullPath(Subdirectory subdir, const std::string &filename)
Find a path to the filename in one of the search directories.
bool FioRemove(const std::string &filename)
Remove a file.
std::optional< FileHandle > FioFOpenFile(const std::string &filename, const char *mode, Subdirectory subdir, size_t *filesize)
Opens a OpenTTD file somewhere in a personal or global directory.
Functions for Standard In/Out file operations.
@ BASE_DIR
Base directory for all subdirectories.
Base for all music playback.
A number of safeguards to prevent using unsafe methods.
Base for all sound drivers.
Definition of base types and functions in a cross-platform compatible way.
bool StrEqualsIgnoreCase(const std::string_view str1, const std::string_view str2)
Compares two string( view)s for equality, while ignoring the case of the characters.
Functions related to low-level strings.
std::vector< std::string > StringList
Type for a list of strings.
Dimensions (a width and height) of a rectangle in 2D.
bool _video_hw_accel
Whether to consider hardware accelerated video drivers on startup.
Base of all video drivers.