mirror of https://github.com/OpenTTD/OpenTTD.git
Codechange: Use std::string in the driver and blitter selection code.
This commit is contained in:
parent
a49fdb7ebb
commit
37bc2f8064
|
@ -22,10 +22,10 @@
|
|||
*/
|
||||
class BlitterFactory {
|
||||
private:
|
||||
const char *name; ///< The name of the blitter factory.
|
||||
const char *description; ///< The description of the blitter.
|
||||
const std::string name; ///< The name of the blitter factory.
|
||||
const std::string description; ///< The description of the blitter.
|
||||
|
||||
typedef std::map<const char *, BlitterFactory *, StringCompare> Blitters; ///< Map of blitter factories.
|
||||
typedef std::map<std::string, BlitterFactory *> Blitters; ///< Map of blitter factories.
|
||||
|
||||
/**
|
||||
* Get the map with currently known blitters.
|
||||
|
@ -58,7 +58,7 @@ protected:
|
|||
* @pre There is no blitter registered with this name.
|
||||
*/
|
||||
BlitterFactory(const char *name, const char *description, bool usable = true) :
|
||||
name(stredup(name)), description(stredup(description))
|
||||
name(name), description(description)
|
||||
{
|
||||
if (usable) {
|
||||
/*
|
||||
|
@ -78,9 +78,6 @@ public:
|
|||
{
|
||||
GetBlitters().erase(this->name);
|
||||
if (GetBlitters().empty()) delete &GetBlitters();
|
||||
|
||||
free(this->name);
|
||||
free(this->description);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -88,7 +85,7 @@ public:
|
|||
* @param name the blitter to select.
|
||||
* @post Sets the blitter so GetCurrentBlitter() returns it too.
|
||||
*/
|
||||
static Blitter *SelectBlitter(const char *name)
|
||||
static Blitter *SelectBlitter(const std::string &name)
|
||||
{
|
||||
BlitterFactory *b = GetBlitterFactory(name);
|
||||
if (b == nullptr) return nullptr;
|
||||
|
@ -97,7 +94,7 @@ public:
|
|||
delete *GetActiveBlitter();
|
||||
*GetActiveBlitter() = newb;
|
||||
|
||||
DEBUG(driver, 1, "Successfully %s blitter '%s'", StrEmpty(name) ? "probed" : "loaded", newb->GetName());
|
||||
DEBUG(driver, 1, "Successfully %s blitter '%s'", name.empty() ? "probed" : "loaded", newb->GetName());
|
||||
return newb;
|
||||
}
|
||||
|
||||
|
@ -106,7 +103,7 @@ public:
|
|||
* @param name the blitter factory to select.
|
||||
* @return The blitter factory, or nullptr when there isn't one with the wanted name.
|
||||
*/
|
||||
static BlitterFactory *GetBlitterFactory(const char *name)
|
||||
static BlitterFactory *GetBlitterFactory(const std::string &name)
|
||||
{
|
||||
#if defined(DEDICATED)
|
||||
const char *default_blitter = "null";
|
||||
|
@ -116,12 +113,12 @@ public:
|
|||
const char *default_blitter = "8bpp-optimized";
|
||||
#endif
|
||||
if (GetBlitters().size() == 0) return nullptr;
|
||||
const char *bname = (StrEmpty(name)) ? default_blitter : name;
|
||||
const char *bname = name.empty() ? default_blitter : name.c_str();
|
||||
|
||||
Blitters::iterator it = GetBlitters().begin();
|
||||
for (; it != GetBlitters().end(); it++) {
|
||||
BlitterFactory *b = (*it).second;
|
||||
if (strcasecmp(bname, b->name) == 0) {
|
||||
if (strcasecmp(bname, b->name.c_str()) == 0) {
|
||||
return b;
|
||||
}
|
||||
}
|
||||
|
@ -148,7 +145,7 @@ public:
|
|||
Blitters::iterator it = GetBlitters().begin();
|
||||
for (; it != GetBlitters().end(); it++) {
|
||||
BlitterFactory *b = (*it).second;
|
||||
p += seprintf(p, last, "%18s: %s\n", b->name, b->GetDescription());
|
||||
p += seprintf(p, last, "%18s: %s\n", b->name.c_str(), b->GetDescription().c_str());
|
||||
}
|
||||
p += seprintf(p, last, "\n");
|
||||
|
||||
|
@ -158,7 +155,7 @@ public:
|
|||
/**
|
||||
* Get the long, human readable, name for the Blitter-class.
|
||||
*/
|
||||
const char *GetName() const
|
||||
const std::string &GetName() const
|
||||
{
|
||||
return this->name;
|
||||
}
|
||||
|
@ -166,7 +163,7 @@ public:
|
|||
/**
|
||||
* Get a nice description of the blitter-class.
|
||||
*/
|
||||
const char *GetDescription() const
|
||||
const std::string &GetDescription() const
|
||||
{
|
||||
return this->description;
|
||||
}
|
||||
|
@ -177,7 +174,7 @@ public:
|
|||
virtual Blitter *CreateInstance() = 0;
|
||||
};
|
||||
|
||||
extern char *_ini_blitter;
|
||||
extern std::string _ini_blitter;
|
||||
extern bool _blitter_autodetected;
|
||||
|
||||
#endif /* BLITTER_FACTORY_HPP */
|
||||
|
|
|
@ -13,19 +13,21 @@
|
|||
#include "music/music_driver.hpp"
|
||||
#include "video/video_driver.hpp"
|
||||
#include "string_func.h"
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
|
||||
#include "safeguards.h"
|
||||
|
||||
char *_ini_videodriver; ///< The video driver a stored in the configuration file.
|
||||
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.
|
||||
|
||||
char *_ini_sounddriver; ///< The sound driver a stored in the configuration file.
|
||||
std::string _ini_sounddriver; ///< The sound driver a stored in the configuration file.
|
||||
|
||||
char *_ini_musicdriver; ///< The music driver a stored in the configuration file.
|
||||
std::string _ini_musicdriver; ///< The music driver a stored in the configuration file.
|
||||
|
||||
char *_ini_blitter; ///< The blitter as 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?
|
||||
|
||||
/**
|
||||
|
@ -34,19 +36,15 @@ bool _blitter_autodetected; ///< Was the blitter autodetected or specif
|
|||
* @param name The parameter name we're looking for.
|
||||
* @return The parameter value.
|
||||
*/
|
||||
const char *GetDriverParam(const char * const *parm, const char *name)
|
||||
const char *GetDriverParam(const StringList &parm, const char *name)
|
||||
{
|
||||
size_t len;
|
||||
if (parm.empty()) return nullptr;
|
||||
|
||||
if (parm == nullptr) return nullptr;
|
||||
|
||||
len = strlen(name);
|
||||
for (; *parm != nullptr; parm++) {
|
||||
const char *p = *parm;
|
||||
|
||||
if (strncmp(p, name, len) == 0) {
|
||||
if (p[len] == '=') return p + len + 1;
|
||||
if (p[len] == '\0') return p + len;
|
||||
size_t len = strlen(name);
|
||||
for (auto &p : parm) {
|
||||
if (p.compare(0, len, name) == 0) {
|
||||
if (p.length() == len) return "";
|
||||
if (p[len] == '=') return p.c_str() + len + 1;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
|
@ -58,7 +56,7 @@ const char *GetDriverParam(const char * const *parm, const char *name)
|
|||
* @param name The parameter name we're looking for.
|
||||
* @return The parameter value.
|
||||
*/
|
||||
bool GetDriverParamBool(const char * const *parm, const char *name)
|
||||
bool GetDriverParamBool(const StringList &parm, const char *name)
|
||||
{
|
||||
return GetDriverParam(parm, name) != nullptr;
|
||||
}
|
||||
|
@ -70,7 +68,7 @@ bool GetDriverParamBool(const char * const *parm, const char *name)
|
|||
* @param def The default value if the parameter doesn't exist.
|
||||
* @return The parameter value.
|
||||
*/
|
||||
int GetDriverParamInt(const char * const *parm, const char *name, int def)
|
||||
int GetDriverParamInt(const StringList &parm, const char *name, int def)
|
||||
{
|
||||
const char *p = GetDriverParam(parm, name);
|
||||
return p != nullptr ? atoi(p) : def;
|
||||
|
@ -82,12 +80,12 @@ 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.
|
||||
*/
|
||||
void DriverFactoryBase::SelectDriver(const char *name, Driver::Type type)
|
||||
void DriverFactoryBase::SelectDriver(const std::string &name, Driver::Type type)
|
||||
{
|
||||
if (!DriverFactoryBase::SelectDriverImpl(name, type)) {
|
||||
StrEmpty(name) ?
|
||||
name.empty() ?
|
||||
usererror("Failed to autoprobe %s driver", GetDriverTypeName(type)) :
|
||||
usererror("Failed to select requested %s driver '%s'", GetDriverTypeName(type), name);
|
||||
usererror("Failed to select requested %s driver '%s'", GetDriverTypeName(type), name.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -98,11 +96,11 @@ void DriverFactoryBase::SelectDriver(const char *name, Driver::Type type)
|
|||
* @post Sets the driver so GetCurrentDriver() returns it too.
|
||||
* @return True upon success, otherwise false.
|
||||
*/
|
||||
bool DriverFactoryBase::SelectDriverImpl(const char *name, Driver::Type type)
|
||||
bool DriverFactoryBase::SelectDriverImpl(const std::string &name, Driver::Type type)
|
||||
{
|
||||
if (GetDrivers().size() == 0) return false;
|
||||
|
||||
if (StrEmpty(name)) {
|
||||
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();
|
||||
|
@ -117,7 +115,7 @@ bool DriverFactoryBase::SelectDriverImpl(const char *name, Driver::Type type)
|
|||
Driver *newd = d->CreateInstance();
|
||||
*GetActiveDriver(type) = newd;
|
||||
|
||||
const char *err = newd->Start(nullptr);
|
||||
const char *err = newd->Start({});
|
||||
if (err == nullptr) {
|
||||
DEBUG(driver, 1, "Successfully probed %s driver '%s'", GetDriverTypeName(type), d->name);
|
||||
delete oldd;
|
||||
|
@ -131,23 +129,15 @@ bool DriverFactoryBase::SelectDriverImpl(const char *name, Driver::Type type)
|
|||
}
|
||||
usererror("Couldn't find any suitable %s driver", GetDriverTypeName(type));
|
||||
} else {
|
||||
char *parm;
|
||||
char buffer[256];
|
||||
const char *parms[32];
|
||||
|
||||
/* Extract the driver name and put parameter list in parm */
|
||||
strecpy(buffer, name, lastof(buffer));
|
||||
parm = strchr(buffer, ':');
|
||||
parms[0] = nullptr;
|
||||
if (parm != nullptr) {
|
||||
uint np = 0;
|
||||
/* Tokenize the parm. */
|
||||
do {
|
||||
*parm++ = '\0';
|
||||
if (np < lengthof(parms) - 1) parms[np++] = parm;
|
||||
while (*parm != '\0' && *parm != ',') parm++;
|
||||
} while (*parm == ',');
|
||||
parms[np] = nullptr;
|
||||
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 */
|
||||
|
@ -159,7 +149,7 @@ bool DriverFactoryBase::SelectDriverImpl(const char *name, Driver::Type type)
|
|||
if (d->type != type) continue;
|
||||
|
||||
/* Check driver name */
|
||||
if (strcasecmp(buffer, d->name) != 0) continue;
|
||||
if (strcasecmp(dname.c_str(), d->name) != 0) continue;
|
||||
|
||||
/* Found our driver, let's try it */
|
||||
Driver *newd = d->CreateInstance();
|
||||
|
@ -175,7 +165,7 @@ bool DriverFactoryBase::SelectDriverImpl(const char *name, Driver::Type type)
|
|||
*GetActiveDriver(type) = newd;
|
||||
return true;
|
||||
}
|
||||
usererror("No such %s driver: %s\n", GetDriverTypeName(type), buffer);
|
||||
usererror("No such %s driver: %s\n", GetDriverTypeName(type), dname.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -221,9 +211,7 @@ DriverFactoryBase::DriverFactoryBase(Driver::Type type, int priority, const char
|
|||
strecpy(buf, GetDriverTypeName(type), lastof(buf));
|
||||
strecpy(buf + 5, name, lastof(buf));
|
||||
|
||||
const char *longname = stredup(buf);
|
||||
|
||||
std::pair<Drivers::iterator, bool> P = GetDrivers().insert(Drivers::value_type(longname, this));
|
||||
std::pair<Drivers::iterator, bool> P = GetDrivers().insert(Drivers::value_type(buf, this));
|
||||
assert(P.second);
|
||||
}
|
||||
|
||||
|
@ -240,10 +228,6 @@ DriverFactoryBase::~DriverFactoryBase()
|
|||
Drivers::iterator it = GetDrivers().find(buf);
|
||||
assert(it != GetDrivers().end());
|
||||
|
||||
const char *longname = (*it).first;
|
||||
|
||||
GetDrivers().erase(it);
|
||||
free(longname);
|
||||
|
||||
if (GetDrivers().empty()) delete &GetDrivers();
|
||||
}
|
||||
|
|
15
src/driver.h
15
src/driver.h
|
@ -12,11 +12,12 @@
|
|||
|
||||
#include "core/enum_type.hpp"
|
||||
#include "core/string_compare_type.hpp"
|
||||
#include "string_type.h"
|
||||
#include <map>
|
||||
|
||||
const char *GetDriverParam(const char * const *parm, const char *name);
|
||||
bool GetDriverParamBool(const char * const *parm, const char *name);
|
||||
int GetDriverParamInt(const char * const *parm, const char *name, int def);
|
||||
const char *GetDriverParam(const StringList &parm, const char *name);
|
||||
bool GetDriverParamBool(const StringList &parm, const char *name);
|
||||
int GetDriverParamInt(const StringList &parm, const char *name, int def);
|
||||
|
||||
/** A driver for communicating with the user. */
|
||||
class Driver {
|
||||
|
@ -26,7 +27,7 @@ public:
|
|||
* @param parm Parameters passed to the driver.
|
||||
* @return nullptr if everything went okay, otherwise an error message.
|
||||
*/
|
||||
virtual const char *Start(const char * const *parm) = 0;
|
||||
virtual const char *Start(const StringList &parm) = 0;
|
||||
|
||||
/**
|
||||
* Stop this driver.
|
||||
|
@ -66,7 +67,7 @@ private:
|
|||
const char *name; ///< The name of the drivers of this factory.
|
||||
const char *description; ///< The description of this driver.
|
||||
|
||||
typedef std::map<const char *, DriverFactoryBase *, StringCompare> Drivers; ///< Type for a map of drivers.
|
||||
typedef std::map<std::string, DriverFactoryBase *> Drivers; ///< Type for a map of drivers.
|
||||
|
||||
/**
|
||||
* Get the map with drivers.
|
||||
|
@ -99,7 +100,7 @@ private:
|
|||
return driver_type_name[type];
|
||||
}
|
||||
|
||||
static bool SelectDriverImpl(const char *name, Driver::Type type);
|
||||
static bool SelectDriverImpl(const std::string &name, Driver::Type type);
|
||||
|
||||
protected:
|
||||
DriverFactoryBase(Driver::Type type, int priority, const char *name, const char *description);
|
||||
|
@ -118,7 +119,7 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
static void SelectDriver(const char *name, Driver::Type type);
|
||||
static void SelectDriver(const std::string &name, Driver::Type type);
|
||||
static char *GetDriversInfo(char *p, const char *last);
|
||||
|
||||
/**
|
||||
|
|
|
@ -26,7 +26,7 @@ static MIDI *_midi = nullptr;
|
|||
*/
|
||||
extern int _allegro_instance_count;
|
||||
|
||||
const char *MusicDriver_Allegro::Start(const char * const *param)
|
||||
const char *MusicDriver_Allegro::Start(const StringList ¶m)
|
||||
{
|
||||
if (_allegro_instance_count == 0 && install_allegro(SYSTEM_AUTODETECT, &errno, nullptr)) {
|
||||
DEBUG(driver, 0, "allegro: install_allegro failed '%s'", allegro_error);
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
/** Allegro's music player. */
|
||||
class MusicDriver_Allegro : public MusicDriver {
|
||||
public:
|
||||
const char *Start(const char * const *param) override;
|
||||
const char *Start(const StringList ¶m) override;
|
||||
|
||||
void Stop() override;
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ static BMidiSynthFile midiSynthFile;
|
|||
/** Factory for BeOS' midi player. */
|
||||
static FMusicDriver_BeMidi iFMusicDriver_BeMidi;
|
||||
|
||||
const char *MusicDriver_BeMidi::Start(const char * const *parm)
|
||||
const char *MusicDriver_BeMidi::Start(const StringList &parm)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
/** The midi player for BeOS. */
|
||||
class MusicDriver_BeMidi : public MusicDriver {
|
||||
public:
|
||||
const char *Start(const char * const *param) override;
|
||||
const char *Start(const StringList ¶m) override;
|
||||
|
||||
void Stop() override;
|
||||
|
||||
|
|
|
@ -79,7 +79,7 @@ static void DoSetVolume()
|
|||
/**
|
||||
* Initialized the MIDI player, including QuickTime initialization.
|
||||
*/
|
||||
const char *MusicDriver_Cocoa::Start(const char * const *parm)
|
||||
const char *MusicDriver_Cocoa::Start(const StringList &parm)
|
||||
{
|
||||
if (NewMusicPlayer(&_player) != noErr) return "failed to create music player";
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
class MusicDriver_Cocoa : public MusicDriver {
|
||||
public:
|
||||
const char *Start(const char * const *param) override;
|
||||
const char *Start(const StringList ¶m) override;
|
||||
|
||||
void Stop() override;
|
||||
|
||||
|
|
|
@ -1071,7 +1071,7 @@ static const char *LoadDefaultDLSFile(const char *user_dls)
|
|||
}
|
||||
|
||||
|
||||
const char *MusicDriver_DMusic::Start(const char * const *parm)
|
||||
const char *MusicDriver_DMusic::Start(const StringList &parm)
|
||||
{
|
||||
/* Initialize COM */
|
||||
if (FAILED(CoInitializeEx(nullptr, COINITBASE_MULTITHREADED))) return "COM initialization failed";
|
||||
|
|
|
@ -17,7 +17,7 @@ class MusicDriver_DMusic : public MusicDriver {
|
|||
public:
|
||||
virtual ~MusicDriver_DMusic();
|
||||
|
||||
const char *Start(const char * const *param) override;
|
||||
const char *Start(const StringList ¶m) override;
|
||||
|
||||
void Stop() override;
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@
|
|||
/** Factory for the midi player that uses external players. */
|
||||
static FMusicDriver_ExtMidi iFMusicDriver_ExtMidi;
|
||||
|
||||
const char *MusicDriver_ExtMidi::Start(const char * const * parm)
|
||||
const char *MusicDriver_ExtMidi::Start(const StringList &parm)
|
||||
{
|
||||
if (strcmp(VideoDriver::GetInstance()->GetName(), "allegro") == 0 ||
|
||||
strcmp(SoundDriver::GetInstance()->GetName(), "allegro") == 0) {
|
||||
|
|
|
@ -22,7 +22,7 @@ private:
|
|||
void DoStop();
|
||||
|
||||
public:
|
||||
const char *Start(const char * const *param) override;
|
||||
const char *Start(const StringList ¶m) override;
|
||||
|
||||
void Stop() override;
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@ static void RenderMusicStream(int16 *buffer, size_t samples)
|
|||
fluid_synth_write_s16(_midi.synth, samples, buffer, 0, 2, buffer, 1, 2);
|
||||
}
|
||||
|
||||
const char *MusicDriver_FluidSynth::Start(const char * const *param)
|
||||
const char *MusicDriver_FluidSynth::Start(const StringList ¶m)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock{ _midi.synth_mutex };
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
/** Music driver making use of FluidSynth. */
|
||||
class MusicDriver_FluidSynth : public MusicDriver {
|
||||
public:
|
||||
const char *Start(const char * const *param) override;
|
||||
const char *Start(const StringList ¶m) override;
|
||||
|
||||
void Stop() override;
|
||||
|
||||
|
|
|
@ -48,6 +48,6 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
extern char *_ini_musicdriver;
|
||||
extern std::string _ini_musicdriver;
|
||||
|
||||
#endif /* MUSIC_MUSIC_DRIVER_HPP */
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
/** The music player that does nothing. */
|
||||
class MusicDriver_Null : public MusicDriver {
|
||||
public:
|
||||
const char *Start(const char * const *param) override { return nullptr; }
|
||||
const char *Start(const StringList ¶m) override { return nullptr; }
|
||||
|
||||
void Stop() override { }
|
||||
|
||||
|
|
|
@ -80,7 +80,7 @@ bool MusicDriver_OS2::IsSongPlaying()
|
|||
return strcmp(buf, "playing") == 0 || strcmp(buf, "seeking") == 0;
|
||||
}
|
||||
|
||||
const char *MusicDriver_OS2::Start(const char * const *parm)
|
||||
const char *MusicDriver_OS2::Start(const StringList &parm)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
/** OS/2's music player. */
|
||||
class MusicDriver_OS2 : public MusicDriver {
|
||||
public:
|
||||
const char *Start(const char * const *param) override;
|
||||
const char *Start(const StringList ¶m) override;
|
||||
|
||||
void Stop() override;
|
||||
|
||||
|
|
|
@ -362,7 +362,7 @@ void MusicDriver_Win32::SetVolume(byte vol)
|
|||
_midi.new_volume = vol;
|
||||
}
|
||||
|
||||
const char *MusicDriver_Win32::Start(const char * const *parm)
|
||||
const char *MusicDriver_Win32::Start(const StringList &parm)
|
||||
{
|
||||
DEBUG(driver, 2, "Win32-MIDI: Start: initializing");
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
/** The Windows music player. */
|
||||
class MusicDriver_Win32 : public MusicDriver {
|
||||
public:
|
||||
const char *Start(const char * const *param) override;
|
||||
const char *Start(const StringList ¶m) override;
|
||||
|
||||
void Stop() override;
|
||||
|
||||
|
|
|
@ -533,10 +533,10 @@ static const OptionData _options[] = {
|
|||
*/
|
||||
int openttd_main(int argc, char *argv[])
|
||||
{
|
||||
char *musicdriver = nullptr;
|
||||
char *sounddriver = nullptr;
|
||||
char *videodriver = nullptr;
|
||||
char *blitter = nullptr;
|
||||
std::string musicdriver;
|
||||
std::string sounddriver;
|
||||
std::string videodriver;
|
||||
std::string blitter;
|
||||
std::string graphics_set;
|
||||
std::string sounds_set;
|
||||
std::string music_set;
|
||||
|
@ -566,19 +566,15 @@ int openttd_main(int argc, char *argv[])
|
|||
case 'I': graphics_set = mgo.opt; break;
|
||||
case 'S': sounds_set = mgo.opt; break;
|
||||
case 'M': music_set = mgo.opt; break;
|
||||
case 'm': free(musicdriver); musicdriver = stredup(mgo.opt); break;
|
||||
case 's': free(sounddriver); sounddriver = stredup(mgo.opt); break;
|
||||
case 'v': free(videodriver); videodriver = stredup(mgo.opt); break;
|
||||
case 'b': free(blitter); blitter = stredup(mgo.opt); break;
|
||||
case 'm': musicdriver = mgo.opt; break;
|
||||
case 's': sounddriver = mgo.opt; break;
|
||||
case 'v': videodriver = mgo.opt; break;
|
||||
case 'b': blitter = mgo.opt; break;
|
||||
case 'D':
|
||||
free(musicdriver);
|
||||
free(sounddriver);
|
||||
free(videodriver);
|
||||
free(blitter);
|
||||
musicdriver = stredup("null");
|
||||
sounddriver = stredup("null");
|
||||
videodriver = stredup("dedicated");
|
||||
blitter = stredup("null");
|
||||
musicdriver = "null";
|
||||
sounddriver = "null";
|
||||
videodriver = "dedicated";
|
||||
blitter = "null";
|
||||
dedicated = true;
|
||||
SetDebugString("net=6");
|
||||
if (mgo.opt != nullptr) {
|
||||
|
@ -746,8 +742,8 @@ int openttd_main(int argc, char *argv[])
|
|||
GfxInitPalettes();
|
||||
|
||||
DEBUG(misc, 1, "Loading blitter...");
|
||||
if (blitter == nullptr && _ini_blitter != nullptr) blitter = stredup(_ini_blitter);
|
||||
_blitter_autodetected = StrEmpty(blitter);
|
||||
if (blitter.empty() && !_ini_blitter.empty()) blitter = _ini_blitter;
|
||||
_blitter_autodetected = blitter.empty();
|
||||
/* Activate the initial blitter.
|
||||
* This is only some initial guess, after NewGRFs have been loaded SwitchNewGRFBlitter may switch to a different one.
|
||||
* - Never guess anything, if the user specified a blitter. (_blitter_autodetected)
|
||||
|
@ -758,16 +754,14 @@ int openttd_main(int argc, char *argv[])
|
|||
(_support8bpp != S8BPP_NONE && (BaseGraphics::GetUsedSet() == nullptr || BaseGraphics::GetUsedSet()->blitter == BLT_8BPP)) ||
|
||||
BlitterFactory::SelectBlitter("32bpp-anim") == nullptr) {
|
||||
if (BlitterFactory::SelectBlitter(blitter) == nullptr) {
|
||||
StrEmpty(blitter) ?
|
||||
blitter.empty() ?
|
||||
usererror("Failed to autoprobe blitter") :
|
||||
usererror("Failed to select requested blitter '%s'; does it exist?", blitter);
|
||||
usererror("Failed to select requested blitter '%s'; does it exist?", blitter.c_str());
|
||||
}
|
||||
}
|
||||
free(blitter);
|
||||
|
||||
if (videodriver == nullptr && _ini_videodriver != nullptr) videodriver = stredup(_ini_videodriver);
|
||||
if (videodriver.empty() && !_ini_videodriver.empty()) videodriver = _ini_videodriver;
|
||||
DriverFactoryBase::SelectDriver(videodriver, Driver::DT_VIDEO);
|
||||
free(videodriver);
|
||||
|
||||
InitializeSpriteSorter();
|
||||
|
||||
|
@ -824,13 +818,11 @@ int openttd_main(int argc, char *argv[])
|
|||
}
|
||||
}
|
||||
|
||||
if (sounddriver == nullptr && _ini_sounddriver != nullptr) sounddriver = stredup(_ini_sounddriver);
|
||||
if (sounddriver.empty() && !_ini_sounddriver.empty()) sounddriver = _ini_sounddriver;
|
||||
DriverFactoryBase::SelectDriver(sounddriver, Driver::DT_SOUND);
|
||||
free(sounddriver);
|
||||
|
||||
if (musicdriver == nullptr && _ini_musicdriver != nullptr) musicdriver = stredup(_ini_musicdriver);
|
||||
if (musicdriver.empty() && !_ini_musicdriver.empty()) musicdriver = _ini_musicdriver;
|
||||
DriverFactoryBase::SelectDriver(musicdriver, Driver::DT_MUSIC);
|
||||
free(musicdriver);
|
||||
|
||||
/* Take our initial lock on whatever we might want to do! */
|
||||
try {
|
||||
|
@ -868,23 +860,9 @@ int openttd_main(int argc, char *argv[])
|
|||
|
||||
/* Reset windowing system, stop drivers, free used memory, ... */
|
||||
ShutdownGame();
|
||||
goto exit_normal;
|
||||
|
||||
exit_noshutdown:
|
||||
/* These three are normally freed before bootstrap. */
|
||||
free(videodriver);
|
||||
free(blitter);
|
||||
|
||||
exit_bootstrap:
|
||||
/* These are normally freed before exit, but after bootstrap. */
|
||||
free(musicdriver);
|
||||
free(sounddriver);
|
||||
|
||||
exit_normal:
|
||||
free(_ini_musicdriver);
|
||||
free(_ini_sounddriver);
|
||||
free(_ini_videodriver);
|
||||
free(_ini_blitter);
|
||||
|
||||
delete scanner;
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@ void SoundDriver_Allegro::MainLoop()
|
|||
*/
|
||||
extern int _allegro_instance_count;
|
||||
|
||||
const char *SoundDriver_Allegro::Start(const char * const *parm)
|
||||
const char *SoundDriver_Allegro::Start(const StringList &parm)
|
||||
{
|
||||
if (_allegro_instance_count == 0 && install_allegro(SYSTEM_AUTODETECT, &errno, nullptr)) {
|
||||
DEBUG(driver, 0, "allegro: install_allegro failed '%s'", allegro_error);
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
/** Implementation of the allegro sound driver. */
|
||||
class SoundDriver_Allegro : public SoundDriver {
|
||||
public:
|
||||
const char *Start(const char * const *param);
|
||||
const char *Start(const StringList ¶m);
|
||||
|
||||
void Stop();
|
||||
|
||||
|
|
|
@ -44,7 +44,7 @@ static OSStatus audioCallback(void *inRefCon, AudioUnitRenderActionFlags *inActi
|
|||
}
|
||||
|
||||
|
||||
const char *SoundDriver_Cocoa::Start(const char * const *parm)
|
||||
const char *SoundDriver_Cocoa::Start(const StringList &parm)
|
||||
{
|
||||
struct AURenderCallbackStruct callback;
|
||||
AudioStreamBasicDescription requestedDesc;
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
class SoundDriver_Cocoa : public SoundDriver {
|
||||
public:
|
||||
const char *Start(const char * const *param) override;
|
||||
const char *Start(const StringList ¶m) override;
|
||||
|
||||
void Stop() override;
|
||||
const char *GetName() const override { return "cocoa"; }
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
/** Implementation of the null sound driver. */
|
||||
class SoundDriver_Null : public SoundDriver {
|
||||
public:
|
||||
const char *Start(const char * const *param) override { return nullptr; }
|
||||
const char *Start(const StringList ¶m) override { return nullptr; }
|
||||
|
||||
void Stop() override { }
|
||||
const char *GetName() const override { return "null"; }
|
||||
|
|
|
@ -31,7 +31,7 @@ static void CDECL fill_sound_buffer(void *userdata, Uint8 *stream, int len)
|
|||
MxMixSamples(stream, len / 4);
|
||||
}
|
||||
|
||||
const char *SoundDriver_SDL::Start(const char * const *parm)
|
||||
const char *SoundDriver_SDL::Start(const StringList &parm)
|
||||
{
|
||||
SDL_AudioSpec spec;
|
||||
SDL_AudioSpec spec_actual;
|
||||
|
|
|
@ -31,7 +31,7 @@ static void CDECL fill_sound_buffer(void *userdata, Uint8 *stream, int len)
|
|||
MxMixSamples(stream, len / 4);
|
||||
}
|
||||
|
||||
const char *SoundDriver_SDL::Start(const char * const *parm)
|
||||
const char *SoundDriver_SDL::Start(const StringList &parm)
|
||||
{
|
||||
SDL_AudioSpec spec;
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
/** Implementation of the SDL sound driver. */
|
||||
class SoundDriver_SDL : public SoundDriver {
|
||||
public:
|
||||
const char *Start(const char * const *param) override;
|
||||
const char *Start(const StringList ¶m) override;
|
||||
|
||||
void Stop() override;
|
||||
const char *GetName() const override { return "sdl"; }
|
||||
|
|
|
@ -26,6 +26,6 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
extern char *_ini_sounddriver;
|
||||
extern std::string _ini_sounddriver;
|
||||
|
||||
#endif /* SOUND_SOUND_DRIVER_HPP */
|
||||
|
|
|
@ -58,7 +58,7 @@ static DWORD WINAPI SoundThread(LPVOID arg)
|
|||
return 0;
|
||||
}
|
||||
|
||||
const char *SoundDriver_Win32::Start(const char * const *parm)
|
||||
const char *SoundDriver_Win32::Start(const StringList &parm)
|
||||
{
|
||||
WAVEFORMATEX wfex;
|
||||
wfex.wFormatTag = WAVE_FORMAT_PCM;
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
/** Implementation of the sound driver for Windows. */
|
||||
class SoundDriver_Win32 : public SoundDriver {
|
||||
public:
|
||||
const char *Start(const char * const *param) override;
|
||||
const char *Start(const StringList ¶m) override;
|
||||
|
||||
void Stop() override;
|
||||
const char *GetName() const override { return "win32"; }
|
||||
|
|
|
@ -126,7 +126,7 @@ static StreamingVoiceContext* _voice_context = nullptr;
|
|||
* @return An error message if unsuccessful, or nullptr otherwise.
|
||||
*
|
||||
*/
|
||||
const char *SoundDriver_XAudio2::Start(const char * const *parm)
|
||||
const char *SoundDriver_XAudio2::Start(const StringList &parm)
|
||||
{
|
||||
HRESULT hr = CoInitializeEx(nullptr, COINIT_MULTITHREADED);
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
/** Implementation of the XAudio2 sound driver. */
|
||||
class SoundDriver_XAudio2 : public SoundDriver {
|
||||
public:
|
||||
const char *Start(const char * const *param) override;
|
||||
const char *Start(const StringList ¶m) override;
|
||||
|
||||
void Stop() override;
|
||||
const char *GetName() const override { return "xaudio2"; }
|
||||
|
|
|
@ -80,28 +80,28 @@ var = BaseMusic::ini_set
|
|||
def = nullptr
|
||||
cat = SC_BASIC
|
||||
|
||||
[SDTG_STR]
|
||||
[SDTG_SSTR]
|
||||
name = ""videodriver""
|
||||
type = SLE_STRQ
|
||||
var = _ini_videodriver
|
||||
def = nullptr
|
||||
cat = SC_EXPERT
|
||||
|
||||
[SDTG_STR]
|
||||
[SDTG_SSTR]
|
||||
name = ""musicdriver""
|
||||
type = SLE_STRQ
|
||||
var = _ini_musicdriver
|
||||
def = nullptr
|
||||
cat = SC_EXPERT
|
||||
|
||||
[SDTG_STR]
|
||||
[SDTG_SSTR]
|
||||
name = ""sounddriver""
|
||||
type = SLE_STRQ
|
||||
var = _ini_sounddriver
|
||||
def = nullptr
|
||||
cat = SC_EXPERT
|
||||
|
||||
[SDTG_STR]
|
||||
[SDTG_SSTR]
|
||||
name = ""blitter""
|
||||
type = SLE_STRQ
|
||||
var = _ini_blitter
|
||||
|
|
|
@ -410,7 +410,7 @@ static void PollEvent()
|
|||
*/
|
||||
int _allegro_instance_count = 0;
|
||||
|
||||
const char *VideoDriver_Allegro::Start(const char * const *parm)
|
||||
const char *VideoDriver_Allegro::Start(const StringList &parm)
|
||||
{
|
||||
if (_allegro_instance_count == 0 && install_allegro(SYSTEM_AUTODETECT, &errno, nullptr)) {
|
||||
DEBUG(driver, 0, "allegro: install_allegro failed '%s'", allegro_error);
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
/** The allegro video driver. */
|
||||
class VideoDriver_Allegro : public VideoDriver {
|
||||
public:
|
||||
const char *Start(const char * const *param) override;
|
||||
const char *Start(const StringList ¶m) override;
|
||||
|
||||
void Stop() override;
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
class VideoDriver_Cocoa : public VideoDriver {
|
||||
public:
|
||||
const char *Start(const char * const *param) override;
|
||||
const char *Start(const StringList ¶m) override;
|
||||
|
||||
/** Stop the video driver */
|
||||
void Stop() override;
|
||||
|
|
|
@ -396,7 +396,7 @@ void VideoDriver_Cocoa::Stop()
|
|||
/**
|
||||
* Initialize a cocoa video subdriver.
|
||||
*/
|
||||
const char *VideoDriver_Cocoa::Start(const char * const *parm)
|
||||
const char *VideoDriver_Cocoa::Start(const StringList &parm)
|
||||
{
|
||||
if (!MacOSVersionIsAtLeast(10, 6, 0)) return "The Cocoa video driver requires Mac OS X 10.6 or later.";
|
||||
|
||||
|
@ -520,7 +520,7 @@ void CocoaDialog(const char *title, const char *message, const char *buttonLabel
|
|||
bool wasstarted = _cocoa_video_started;
|
||||
if (VideoDriver::GetInstance() == NULL) {
|
||||
setupApplication(); // Setup application before showing dialog
|
||||
} else if (!_cocoa_video_started && VideoDriver::GetInstance()->Start(NULL) != NULL) {
|
||||
} else if (!_cocoa_video_started && VideoDriver::GetInstance()->Start(StringList()) != NULL) {
|
||||
fprintf(stderr, "%s: %s\n", title, message);
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -133,7 +133,7 @@ extern bool SafeLoad(const char *filename, SaveLoadOperation fop, DetailedFileTy
|
|||
static FVideoDriver_Dedicated iFVideoDriver_Dedicated;
|
||||
|
||||
|
||||
const char *VideoDriver_Dedicated::Start(const char * const *parm)
|
||||
const char *VideoDriver_Dedicated::Start(const StringList &parm)
|
||||
{
|
||||
int bpp = BlitterFactory::GetCurrentBlitter()->GetScreenDepth();
|
||||
_dedicated_video_mem = (bpp == 0) ? nullptr : MallocT<byte>(_cur_resolution.width * _cur_resolution.height * (bpp / 8));
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
/** The dedicated server video driver. */
|
||||
class VideoDriver_Dedicated : public VideoDriver {
|
||||
public:
|
||||
const char *Start(const char * const *param) override;
|
||||
const char *Start(const StringList ¶m) override;
|
||||
|
||||
void Stop() override;
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
/** Factory for the null video driver. */
|
||||
static FVideoDriver_Null iFVideoDriver_Null;
|
||||
|
||||
const char *VideoDriver_Null::Start(const char * const *parm)
|
||||
const char *VideoDriver_Null::Start(const StringList &parm)
|
||||
{
|
||||
#ifdef _MSC_VER
|
||||
/* Disable the MSVC assertion message box. */
|
||||
|
|
|
@ -18,7 +18,7 @@ private:
|
|||
uint ticks; ///< Amount of ticks to run.
|
||||
|
||||
public:
|
||||
const char *Start(const char * const *param) override;
|
||||
const char *Start(const StringList ¶m) override;
|
||||
|
||||
void Stop() override;
|
||||
|
||||
|
|
|
@ -626,7 +626,7 @@ int VideoDriver_SDL::PollEvent()
|
|||
return -1;
|
||||
}
|
||||
|
||||
const char *VideoDriver_SDL::Start(const char * const *parm)
|
||||
const char *VideoDriver_SDL::Start(const StringList &parm)
|
||||
{
|
||||
/* Explicitly disable hardware acceleration. Enabling this causes
|
||||
* UpdateWindowSurface() to update the window's texture instead of
|
||||
|
@ -652,7 +652,7 @@ const char *VideoDriver_SDL::Start(const char * const *parm)
|
|||
|
||||
MarkWholeScreenDirty();
|
||||
|
||||
_draw_threaded = GetDriverParam(parm, "no_threads") == nullptr && GetDriverParam(parm, "no_thread") == nullptr;
|
||||
_draw_threaded = !GetDriverParamBool(parm, "no_threads") && !GetDriverParamBool(parm, "no_thread");
|
||||
|
||||
SDL_StopTextInput();
|
||||
this->edit_box_focused = false;
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
/** The SDL video driver. */
|
||||
class VideoDriver_SDL : public VideoDriver {
|
||||
public:
|
||||
const char *Start(const char * const *param) override;
|
||||
const char *Start(const StringList ¶m) override;
|
||||
|
||||
void Stop() override;
|
||||
|
||||
|
|
|
@ -596,7 +596,7 @@ int VideoDriver_SDL::PollEvent()
|
|||
return -1;
|
||||
}
|
||||
|
||||
const char *VideoDriver_SDL::Start(const char * const *parm)
|
||||
const char *VideoDriver_SDL::Start(const StringList &parm)
|
||||
{
|
||||
char buf[30];
|
||||
_use_hwpalette = GetDriverParamInt(parm, "hw_palette", 2);
|
||||
|
@ -623,7 +623,7 @@ const char *VideoDriver_SDL::Start(const char * const *parm)
|
|||
MarkWholeScreenDirty();
|
||||
SetupKeyboard();
|
||||
|
||||
_draw_threaded = GetDriverParam(parm, "no_threads") == nullptr && GetDriverParam(parm, "no_thread") == nullptr;
|
||||
_draw_threaded = !GetDriverParamBool(parm, "no_threads") && !GetDriverParamBool(parm, "no_thread");
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
/** The SDL video driver. */
|
||||
class VideoDriver_SDL : public VideoDriver {
|
||||
public:
|
||||
const char *Start(const char * const *param) override;
|
||||
const char *Start(const StringList ¶m) override;
|
||||
|
||||
void Stop() override;
|
||||
|
||||
|
|
|
@ -104,7 +104,7 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
extern char *_ini_videodriver;
|
||||
extern std::string _ini_videodriver;
|
||||
extern std::vector<Dimension> _resolutions;
|
||||
extern Dimension _cur_resolution;
|
||||
extern bool _rightclick_emulate;
|
||||
|
|
|
@ -1111,7 +1111,7 @@ static void FindResolutions()
|
|||
|
||||
static FVideoDriver_Win32 iFVideoDriver_Win32;
|
||||
|
||||
const char *VideoDriver_Win32::Start(const char * const *parm)
|
||||
const char *VideoDriver_Win32::Start(const StringList &parm)
|
||||
{
|
||||
memset(&_wnd, 0, sizeof(_wnd));
|
||||
|
||||
|
@ -1132,7 +1132,7 @@ const char *VideoDriver_Win32::Start(const char * const *parm)
|
|||
|
||||
MarkWholeScreenDirty();
|
||||
|
||||
_draw_threaded = GetDriverParam(parm, "no_threads") == nullptr && GetDriverParam(parm, "no_thread") == nullptr && std::thread::hardware_concurrency() > 1;
|
||||
_draw_threaded = !GetDriverParamBool(parm, "no_threads") && !GetDriverParamBool(parm, "no_thread") && std::thread::hardware_concurrency() > 1;
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
/** The video driver for windows. */
|
||||
class VideoDriver_Win32 : public VideoDriver {
|
||||
public:
|
||||
const char *Start(const char * const *param) override;
|
||||
const char *Start(const StringList ¶m) override;
|
||||
|
||||
void Stop() override;
|
||||
|
||||
|
|
Loading…
Reference in New Issue