summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Lutz <michi@icosahedron.de>2020-05-17 23:32:08 +0200
committerMichael Lutz <michi@icosahedron.de>2020-05-21 20:02:34 +0200
commit37bc2f806462b3c2a84891b3aad6db00e935da86 (patch)
tree9f832e8646ec0c4a4038f6c0642c853fbe02038a
parenta49fdb7ebbb8d8ce96bcd7bd779b18bcd86d0643 (diff)
downloadopenttd-37bc2f806462b3c2a84891b3aad6db00e935da86.tar.xz
Codechange: Use std::string in the driver and blitter selection code.
-rw-r--r--src/blitter/factory.hpp29
-rw-r--r--src/driver.cpp80
-rw-r--r--src/driver.h15
-rw-r--r--src/music/allegro_m.cpp2
-rw-r--r--src/music/allegro_m.h2
-rw-r--r--src/music/bemidi.cpp2
-rw-r--r--src/music/bemidi.h2
-rw-r--r--src/music/cocoa_m.cpp2
-rw-r--r--src/music/cocoa_m.h2
-rw-r--r--src/music/dmusic.cpp2
-rw-r--r--src/music/dmusic.h2
-rw-r--r--src/music/extmidi.cpp2
-rw-r--r--src/music/extmidi.h2
-rw-r--r--src/music/fluidsynth.cpp2
-rw-r--r--src/music/fluidsynth.h2
-rw-r--r--src/music/music_driver.hpp2
-rw-r--r--src/music/null_m.h2
-rw-r--r--src/music/os2_m.cpp2
-rw-r--r--src/music/os2_m.h2
-rw-r--r--src/music/win32_m.cpp2
-rw-r--r--src/music/win32_m.h2
-rw-r--r--src/openttd.cpp60
-rw-r--r--src/sound/allegro_s.cpp2
-rw-r--r--src/sound/allegro_s.h2
-rw-r--r--src/sound/cocoa_s.cpp2
-rw-r--r--src/sound/cocoa_s.h2
-rw-r--r--src/sound/null_s.h2
-rw-r--r--src/sound/sdl2_s.cpp2
-rw-r--r--src/sound/sdl_s.cpp2
-rw-r--r--src/sound/sdl_s.h2
-rw-r--r--src/sound/sound_driver.hpp2
-rw-r--r--src/sound/win32_s.cpp2
-rw-r--r--src/sound/win32_s.h2
-rw-r--r--src/sound/xaudio2_s.cpp2
-rw-r--r--src/sound/xaudio2_s.h2
-rw-r--r--src/table/misc_settings.ini8
-rw-r--r--src/video/allegro_v.cpp2
-rw-r--r--src/video/allegro_v.h2
-rw-r--r--src/video/cocoa/cocoa_v.h2
-rw-r--r--src/video/cocoa/cocoa_v.mm4
-rw-r--r--src/video/dedicated_v.cpp2
-rw-r--r--src/video/dedicated_v.h2
-rw-r--r--src/video/null_v.cpp2
-rw-r--r--src/video/null_v.h2
-rw-r--r--src/video/sdl2_v.cpp4
-rw-r--r--src/video/sdl2_v.h2
-rw-r--r--src/video/sdl_v.cpp4
-rw-r--r--src/video/sdl_v.h2
-rw-r--r--src/video/video_driver.hpp2
-rw-r--r--src/video/win32_v.cpp4
-rw-r--r--src/video/win32_v.h2
51 files changed, 126 insertions, 166 deletions
diff --git a/src/blitter/factory.hpp b/src/blitter/factory.hpp
index 30a70570b..c7776f4a4 100644
--- a/src/blitter/factory.hpp
+++ b/src/blitter/factory.hpp
@@ -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 */
diff --git a/src/driver.cpp b/src/driver.cpp
index a642a2f86..c4efd3569 100644
--- a/src/driver.cpp
+++ b/src/driver.cpp
@@ -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();
}
diff --git a/src/driver.h b/src/driver.h
index 3ac4f7f8a..68d9fac92 100644
--- a/src/driver.h
+++ b/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);
/**
diff --git a/src/music/allegro_m.cpp b/src/music/allegro_m.cpp
index 4f90bce06..6d06ce87e 100644
--- a/src/music/allegro_m.cpp
+++ b/src/music/allegro_m.cpp
@@ -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 &param)
{
if (_allegro_instance_count == 0 && install_allegro(SYSTEM_AUTODETECT, &errno, nullptr)) {
DEBUG(driver, 0, "allegro: install_allegro failed '%s'", allegro_error);
diff --git a/src/music/allegro_m.h b/src/music/allegro_m.h
index 1965626ca..b07a7073b 100644
--- a/src/music/allegro_m.h
+++ b/src/music/allegro_m.h
@@ -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 &param) override;
void Stop() override;
diff --git a/src/music/bemidi.cpp b/src/music/bemidi.cpp
index c3ea152da..4175f526b 100644
--- a/src/music/bemidi.cpp
+++ b/src/music/bemidi.cpp
@@ -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;
}
diff --git a/src/music/bemidi.h b/src/music/bemidi.h
index a524069db..8e96acc8d 100644
--- a/src/music/bemidi.h
+++ b/src/music/bemidi.h
@@ -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 &param) override;
void Stop() override;
diff --git a/src/music/cocoa_m.cpp b/src/music/cocoa_m.cpp
index 9fec5ba15..a989cfe76 100644
--- a/src/music/cocoa_m.cpp
+++ b/src/music/cocoa_m.cpp
@@ -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";
diff --git a/src/music/cocoa_m.h b/src/music/cocoa_m.h
index aa477edda..046a60c38 100644
--- a/src/music/cocoa_m.h
+++ b/src/music/cocoa_m.h
@@ -14,7 +14,7 @@
class MusicDriver_Cocoa : public MusicDriver {
public:
- const char *Start(const char * const *param) override;
+ const char *Start(const StringList &param) override;
void Stop() override;
diff --git a/src/music/dmusic.cpp b/src/music/dmusic.cpp
index 4a7461ee8..780666142 100644
--- a/src/music/dmusic.cpp
+++ b/src/music/dmusic.cpp
@@ -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";
diff --git a/src/music/dmusic.h b/src/music/dmusic.h
index bfbb07f16..616bf0120 100644
--- a/src/music/dmusic.h
+++ b/src/music/dmusic.h
@@ -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 &param) override;
void Stop() override;
diff --git a/src/music/extmidi.cpp b/src/music/extmidi.cpp
index b7e7e63b9..f88245250 100644
--- a/src/music/extmidi.cpp
+++ b/src/music/extmidi.cpp
@@ -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) {
diff --git a/src/music/extmidi.h b/src/music/extmidi.h
index 495e9a72c..f43bbad17 100644
--- a/src/music/extmidi.h
+++ b/src/music/extmidi.h
@@ -22,7 +22,7 @@ private:
void DoStop();
public:
- const char *Start(const char * const *param) override;
+ const char *Start(const StringList &param) override;
void Stop() override;
diff --git a/src/music/fluidsynth.cpp b/src/music/fluidsynth.cpp
index 64abe0e53..61686a441 100644
--- a/src/music/fluidsynth.cpp
+++ b/src/music/fluidsynth.cpp
@@ -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 &param)
{
std::lock_guard<std::mutex> lock{ _midi.synth_mutex };
diff --git a/src/music/fluidsynth.h b/src/music/fluidsynth.h
index 71d43fec4..91543662d 100644
--- a/src/music/fluidsynth.h
+++ b/src/music/fluidsynth.h
@@ -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 &param) override;
void Stop() override;
diff --git a/src/music/music_driver.hpp b/src/music/music_driver.hpp
index 601cc6d47..3953685bf 100644
--- a/src/music/music_driver.hpp
+++ b/src/music/music_driver.hpp
@@ -48,6 +48,6 @@ public:
}
};
-extern char *_ini_musicdriver;
+extern std::string _ini_musicdriver;
#endif /* MUSIC_MUSIC_DRIVER_HPP */
diff --git a/src/music/null_m.h b/src/music/null_m.h
index 09f84e35c..3a034110d 100644
--- a/src/music/null_m.h
+++ b/src/music/null_m.h
@@ -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 &param) override { return nullptr; }
void Stop() override { }
diff --git a/src/music/os2_m.cpp b/src/music/os2_m.cpp
index f66c2bd9e..473606567 100644
--- a/src/music/os2_m.cpp
+++ b/src/music/os2_m.cpp
@@ -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;
}
diff --git a/src/music/os2_m.h b/src/music/os2_m.h
index d0a4809b2..a60f5bbfc 100644
--- a/src/music/os2_m.h
+++ b/src/music/os2_m.h
@@ -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 &param) override;
void Stop() override;
diff --git a/src/music/win32_m.cpp b/src/music/win32_m.cpp
index b4f656b14..249fc5b6d 100644
--- a/src/music/win32_m.cpp
+++ b/src/music/win32_m.cpp
@@ -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");
diff --git a/src/music/win32_m.h b/src/music/win32_m.h
index 394c3d990..5101d2932 100644
--- a/src/music/win32_m.h
+++ b/src/music/win32_m.h
@@ -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 &param) override;
void Stop() override;
diff --git a/src/openttd.cpp b/src/openttd.cpp
index e5a6d1b05..980eb2f13 100644
--- a/src/openttd.cpp
+++ b/src/openttd.cpp
@@ -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;
diff --git a/src/sound/allegro_s.cpp b/src/sound/allegro_s.cpp
index f7fa5df08..09198100b 100644
--- a/src/sound/allegro_s.cpp
+++ b/src/sound/allegro_s.cpp
@@ -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);
diff --git a/src/sound/allegro_s.h b/src/sound/allegro_s.h
index 307d10fca..6d40c5876 100644
--- a/src/sound/allegro_s.h
+++ b/src/sound/allegro_s.h
@@ -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 &param);
void Stop();
diff --git a/src/sound/cocoa_s.cpp b/src/sound/cocoa_s.cpp
index cb1bc59e8..f5003a23c 100644
--- a/src/sound/cocoa_s.cpp
+++ b/src/sound/cocoa_s.cpp
@@ -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;
diff --git a/src/sound/cocoa_s.h b/src/sound/cocoa_s.h
index 43646504d..dca542191 100644
--- a/src/sound/cocoa_s.h
+++ b/src/sound/cocoa_s.h
@@ -14,7 +14,7 @@
class SoundDriver_Cocoa : public SoundDriver {
public:
- const char *Start(const char * const *param) override;
+ const char *Start(const StringList &param) override;
void Stop() override;
const char *GetName() const override { return "cocoa"; }
diff --git a/src/sound/null_s.h b/src/sound/null_s.h
index 5b883dde1..c01eae32a 100644
--- a/src/sound/null_s.h
+++ b/src/sound/null_s.h
@@ -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 &param) override { return nullptr; }
void Stop() override { }
const char *GetName() const override { return "null"; }
diff --git a/src/sound/sdl2_s.cpp b/src/sound/sdl2_s.cpp
index 0b4e6c086..9d1e47fab 100644
--- a/src/sound/sdl2_s.cpp
+++ b/src/sound/sdl2_s.cpp
@@ -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;
diff --git a/src/sound/sdl_s.cpp b/src/sound/sdl_s.cpp
index aac786dab..737192a7e 100644
--- a/src/sound/sdl_s.cpp
+++ b/src/sound/sdl_s.cpp
@@ -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;
diff --git a/src/sound/sdl_s.h b/src/sound/sdl_s.h
index 4f746107c..2b3be4d14 100644
--- a/src/sound/sdl_s.h
+++ b/src/sound/sdl_s.h
@@ -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 &param) override;
void Stop() override;
const char *GetName() const override { return "sdl"; }
diff --git a/src/sound/sound_driver.hpp b/src/sound/sound_driver.hpp
index f1a0519f8..6de66d74e 100644
--- a/src/sound/sound_driver.hpp
+++ b/src/sound/sound_driver.hpp
@@ -26,6 +26,6 @@ public:
}
};
-extern char *_ini_sounddriver;
+extern std::string _ini_sounddriver;
#endif /* SOUND_SOUND_DRIVER_HPP */
diff --git a/src/sound/win32_s.cpp b/src/sound/win32_s.cpp
index f45a619b5..4551778bd 100644
--- a/src/sound/win32_s.cpp
+++ b/src/sound/win32_s.cpp
@@ -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;
diff --git a/src/sound/win32_s.h b/src/sound/win32_s.h
index be48a055c..6f8f9791d 100644
--- a/src/sound/win32_s.h
+++ b/src/sound/win32_s.h
@@ -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 &param) override;
void Stop() override;
const char *GetName() const override { return "win32"; }
diff --git a/src/sound/xaudio2_s.cpp b/src/sound/xaudio2_s.cpp
index 8b9afbd1b..5aa058040 100644
--- a/src/sound/xaudio2_s.cpp
+++ b/src/sound/xaudio2_s.cpp
@@ -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);
diff --git a/src/sound/xaudio2_s.h b/src/sound/xaudio2_s.h
index 70b4d80cc..9fcd26fd0 100644
--- a/src/sound/xaudio2_s.h
+++ b/src/sound/xaudio2_s.h
@@ -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 &param) override;
void Stop() override;
const char *GetName() const override { return "xaudio2"; }
diff --git a/src/table/misc_settings.ini b/src/table/misc_settings.ini
index c97663605..60799a436 100644
--- a/src/table/misc_settings.ini
+++ b/src/table/misc_settings.ini
@@ -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
diff --git a/src/video/allegro_v.cpp b/src/video/allegro_v.cpp
index 88e5c528f..9b0bef1ac 100644
--- a/src/video/allegro_v.cpp
+++ b/src/video/allegro_v.cpp
@@ -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);
diff --git a/src/video/allegro_v.h b/src/video/allegro_v.h
index fb7b84ee2..641e3d6c2 100644
--- a/src/video/allegro_v.h
+++ b/src/video/allegro_v.h
@@ -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 &param) override;
void Stop() override;
diff --git a/src/video/cocoa/cocoa_v.h b/src/video/cocoa/cocoa_v.h
index 7286c685b..3da6848d0 100644
--- a/src/video/cocoa/cocoa_v.h
+++ b/src/video/cocoa/cocoa_v.h
@@ -14,7 +14,7 @@
class VideoDriver_Cocoa : public VideoDriver {
public:
- const char *Start(const char * const *param) override;
+ const char *Start(const StringList &param) override;
/** Stop the video driver */
void Stop() override;
diff --git a/src/video/cocoa/cocoa_v.mm b/src/video/cocoa/cocoa_v.mm
index 13a9cc9c4..10f30027b 100644
--- a/src/video/cocoa/cocoa_v.mm
+++ b/src/video/cocoa/cocoa_v.mm
@@ -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;
}
diff --git a/src/video/dedicated_v.cpp b/src/video/dedicated_v.cpp
index ac7d38bb7..0089d163d 100644
--- a/src/video/dedicated_v.cpp
+++ b/src/video/dedicated_v.cpp
@@ -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));
diff --git a/src/video/dedicated_v.h b/src/video/dedicated_v.h
index 27401aae9..54e2dd402 100644
--- a/src/video/dedicated_v.h
+++ b/src/video/dedicated_v.h
@@ -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 &param) override;
void Stop() override;
diff --git a/src/video/null_v.cpp b/src/video/null_v.cpp
index 3e98ea925..2fa45e1bc 100644
--- a/src/video/null_v.cpp
+++ b/src/video/null_v.cpp
@@ -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. */
diff --git a/src/video/null_v.h b/src/video/null_v.h
index ed563bffb..ee83de7e6 100644
--- a/src/video/null_v.h
+++ b/src/video/null_v.h
@@ -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 &param) override;
void Stop() override;
diff --git a/src/video/sdl2_v.cpp b/src/video/sdl2_v.cpp
index 0b3b9b8e3..0442a0e87 100644
--- a/src/video/sdl2_v.cpp
+++ b/src/video/sdl2_v.cpp
@@ -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;
diff --git a/src/video/sdl2_v.h b/src/video/sdl2_v.h
index ae456a39d..80d4018a7 100644
--- a/src/video/sdl2_v.h
+++ b/src/video/sdl2_v.h
@@ -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 &param) override;
void Stop() override;
diff --git a/src/video/sdl_v.cpp b/src/video/sdl_v.cpp
index aacd3f2cb..fba6166c9 100644
--- a/src/video/sdl_v.cpp
+++ b/src/video/sdl_v.cpp
@@ -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;
}
diff --git a/src/video/sdl_v.h b/src/video/sdl_v.h
index 39c77e5d3..ffebd041e 100644
--- a/src/video/sdl_v.h
+++ b/src/video/sdl_v.h
@@ -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 &param) override;
void Stop() override;
diff --git a/src/video/video_driver.hpp b/src/video/video_driver.hpp
index 2cca66d3b..15dd5d0d4 100644
--- a/src/video/video_driver.hpp
+++ b/src/video/video_driver.hpp
@@ -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;
diff --git a/src/video/win32_v.cpp b/src/video/win32_v.cpp
index 3deb0beb0..341187320 100644
--- a/src/video/win32_v.cpp
+++ b/src/video/win32_v.cpp
@@ -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;
}
diff --git a/src/video/win32_v.h b/src/video/win32_v.h
index a0b5c7e16..5c1b20322 100644
--- a/src/video/win32_v.h
+++ b/src/video/win32_v.h
@@ -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 &param) override;
void Stop() override;