diff options
Diffstat (limited to 'src/openttd.cpp')
-rw-r--r-- | src/openttd.cpp | 46 |
1 files changed, 18 insertions, 28 deletions
diff --git a/src/openttd.cpp b/src/openttd.cpp index 7d9bd09a6..e5a6d1b05 100644 --- a/src/openttd.cpp +++ b/src/openttd.cpp @@ -537,9 +537,9 @@ int openttd_main(int argc, char *argv[]) char *sounddriver = nullptr; char *videodriver = nullptr; char *blitter = nullptr; - char *graphics_set = nullptr; - char *sounds_set = nullptr; - char *music_set = nullptr; + std::string graphics_set; + std::string sounds_set; + std::string music_set; Dimension resolution = {0, 0}; /* AfterNewGRFScan sets save_config to true after scanning completed. */ bool save_config = false; @@ -563,9 +563,9 @@ int openttd_main(int argc, char *argv[]) int i; while ((i = mgo.GetOpt()) != -1) { switch (i) { - case 'I': free(graphics_set); graphics_set = stredup(mgo.opt); break; - case 'S': free(sounds_set); sounds_set = stredup(mgo.opt); break; - case 'M': free(music_set); music_set = stredup(mgo.opt); break; + 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; @@ -731,17 +731,16 @@ int openttd_main(int argc, char *argv[]) InitWindowSystem(); BaseGraphics::FindSets(); - if (graphics_set == nullptr && BaseGraphics::ini_set != nullptr) graphics_set = stredup(BaseGraphics::ini_set); + if (graphics_set.empty() && !BaseGraphics::ini_set.empty()) graphics_set = BaseGraphics::ini_set; if (!BaseGraphics::SetSet(graphics_set)) { - if (!StrEmpty(graphics_set)) { - BaseGraphics::SetSet(nullptr); + if (!graphics_set.empty()) { + BaseGraphics::SetSet({}); ErrorMessageData msg(STR_CONFIG_ERROR, STR_CONFIG_ERROR_INVALID_BASE_GRAPHICS_NOT_FOUND); - msg.SetDParamStr(0, graphics_set); + msg.SetDParamStr(0, graphics_set.c_str()); ScheduleErrorMessage(msg); } } - free(graphics_set); /* Initialize game palette */ GfxInitPalettes(); @@ -802,30 +801,28 @@ int openttd_main(int argc, char *argv[]) InitializeScreenshotFormats(); BaseSounds::FindSets(); - if (sounds_set == nullptr && BaseSounds::ini_set != nullptr) sounds_set = stredup(BaseSounds::ini_set); + if (sounds_set.empty() && !BaseSounds::ini_set.empty()) sounds_set = BaseSounds::ini_set; if (!BaseSounds::SetSet(sounds_set)) { - if (StrEmpty(sounds_set) || !BaseSounds::SetSet(nullptr)) { + if (sounds_set.empty() || !BaseSounds::SetSet({})) { usererror("Failed to find a sounds set. Please acquire a sounds set for OpenTTD. See section 1.4 of README.md."); } else { ErrorMessageData msg(STR_CONFIG_ERROR, STR_CONFIG_ERROR_INVALID_BASE_SOUNDS_NOT_FOUND); - msg.SetDParamStr(0, sounds_set); + msg.SetDParamStr(0, sounds_set.c_str()); ScheduleErrorMessage(msg); } } - free(sounds_set); BaseMusic::FindSets(); - if (music_set == nullptr && BaseMusic::ini_set != nullptr) music_set = stredup(BaseMusic::ini_set); + if (music_set.empty() && !BaseMusic::ini_set.empty()) music_set = BaseMusic::ini_set; if (!BaseMusic::SetSet(music_set)) { - if (StrEmpty(music_set) || !BaseMusic::SetSet(nullptr)) { + if (music_set.empty() || !BaseMusic::SetSet({})) { usererror("Failed to find a music set. Please acquire a music set for OpenTTD. See section 1.4 of README.md."); } else { ErrorMessageData msg(STR_CONFIG_ERROR, STR_CONFIG_ERROR_INVALID_BASE_MUSIC_NOT_FOUND); - msg.SetDParamStr(0, music_set); + msg.SetDParamStr(0, music_set.c_str()); ScheduleErrorMessage(msg); } } - free(music_set); if (sounddriver == nullptr && _ini_sounddriver != nullptr) sounddriver = stredup(_ini_sounddriver); DriverFactoryBase::SelectDriver(sounddriver, Driver::DT_SOUND); @@ -875,22 +872,15 @@ int openttd_main(int argc, char *argv[]) exit_noshutdown: /* These three are normally freed before bootstrap. */ - free(graphics_set); free(videodriver); free(blitter); exit_bootstrap: /* These are normally freed before exit, but after bootstrap. */ - free(sounds_set); - free(music_set); free(musicdriver); free(sounddriver); exit_normal: - free(BaseGraphics::ini_set); - free(BaseSounds::ini_set); - free(BaseMusic::ini_set); - free(_ini_musicdriver); free(_ini_sounddriver); free(_ini_videodriver); @@ -1142,9 +1132,9 @@ void SwitchToMode(SwitchMode new_mode) case SM_MENU: // Switch to game intro menu LoadIntroGame(); - if (BaseSounds::ini_set == nullptr && BaseSounds::GetUsedSet()->fallback) { + if (BaseSounds::ini_set.empty() && BaseSounds::GetUsedSet()->fallback) { ShowErrorMessage(STR_WARNING_FALLBACK_SOUNDSET, INVALID_STRING_ID, WL_CRITICAL); - BaseSounds::ini_set = stredup(BaseSounds::GetUsedSet()->name); + BaseSounds::ini_set = BaseSounds::GetUsedSet()->name; } break; |