23#include "table/strings.h"
49 if (parm.empty())
return std::nullopt;
51 for (
auto &p : parm) {
53 if (consumer.ReadIf(name)) {
54 if (!consumer.AnyBytesLeft())
return "";
55 if (consumer.ReadIf(
"="))
return consumer.
GetLeftData();
82 if (!p.has_value())
return def;
83 auto value = ParseInteger<int>(*p);
84 if (value.has_value())
return *value;
85 UserError(
"Invalid value for driver parameter {}: {}", name, *p);
131 if (!filename.empty()) {
169 std::istringstream buffer(
name);
171 std::getline(buffer, dname,
':');
174 std::vector<std::string> parms;
175 while (std::getline(buffer, param,
',')) {
176 parms.push_back(param);
191 auto err = newd->Start(parms);
193 UserError(
"Unable to load driver '{}'. The error was: {}", d->
name, *err);
213 if (!filename.empty())
FioRemove(filename);
234 fmt::format_to(output_iterator,
"\n");
246 type(type), priority(priority), name(name), description(description)
252 assert(drivers.find(typed_name) == drivers.end());
253 drivers.insert(Drivers::value_type(typed_name,
this));
264 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.
static Drivers & GetDrivers()
Get the map with drivers.
virtual bool UsesHardwareAcceleration() const
Does the driver use hardware acceleration (video-drivers only).
static std::unique_ptr< Driver > & GetActiveDriver(Driver::Type type)
Get the active driver for the given type.
DriverFactoryBase(Driver::Type type, int priority, std::string_view name, std::string_view description)
Construct a new DriverFactory.
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.
virtual std::unique_ptr< Driver > CreateInstance() const =0
Create an instance of this driver-class.
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.
virtual ~DriverFactoryBase()
Frees memory used for this->name.
int priority
The priority of this factory.
@ DT_END
Helper for iteration.
@ DT_VIDEO
A video driver.
@ DT_BEGIN
Helper for iteration.
The data of the error message.
Parse data from a string / buffer.
std::string_view GetLeftData() const noexcept
Get data left to read.
Functions related to debugging.
#define Debug(category, level, format_string,...)
Output a line of debugging information.
int GetDriverParamInt(const StringList &parm, std::string_view name, int def)
Get an integer parameter the list of parameters.
std::optional< std::string_view > GetDriverParam(const StringList &parm, std::string_view name)
Get a string parameter the list of parameters.
bool _blitter_autodetected
Was the blitter autodetected or specified by the user?
bool GetDriverParamBool(const StringList &parm, std::string_view name)
Get a boolean parameter the list of parameters.
std::string _ini_videodriver
The video driver a stored in the configuration file.
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.
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.
bool FioRemove(const std::string &filename)
Remove a file.
std::optional< FileHandle > FioFOpenFile(std::string_view filename, std::string_view mode, Subdirectory subdir, size_t *filesize)
Opens a OpenTTD file somewhere in a personal or global directory.
std::string FioFindFullPath(Subdirectory subdir, std::string_view filename)
Find a path to the filename in one of the search directories.
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(std::string_view str1, 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.
EncodedString GetEncodedString(StringID str)
Encode a string with no parameters into an encoded string.
Functions related to OTTD's 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.