diff --git a/src/3rdparty/fmt/core.h b/src/3rdparty/fmt/core.h index d6333bbeb1..26517a4958 100644 --- a/src/3rdparty/fmt/core.h +++ b/src/3rdparty/fmt/core.h @@ -1666,8 +1666,7 @@ constexpr auto encode_types() -> unsigned long long { template FMT_CONSTEXPR FMT_INLINE auto make_value(T&& val) -> value { - auto&& arg = arg_mapper().map(FMT_FORWARD(val)); - using arg_type = remove_cvref_t; + using arg_type = remove_cvref_t().map(val))>; constexpr bool formattable_char = !std::is_same::value; @@ -1686,7 +1685,7 @@ FMT_CONSTEXPR FMT_INLINE auto make_value(T&& val) -> value { formattable, "Cannot format an argument. To make type T formattable provide a " "formatter specialization: https://fmt.dev/latest/api.html#udt"); - return {arg}; + return {arg_mapper().map(val)}; } template diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 720664aa68..891b9b7568 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -238,6 +238,7 @@ add_files( league_gui.cpp league_type.h livery.h + load_check.h main_gui.cpp map.cpp map_func.h diff --git a/src/base_station_base.h b/src/base_station_base.h index 3541589d47..6f2e73b8fb 100644 --- a/src/base_station_base.h +++ b/src/base_station_base.h @@ -17,6 +17,7 @@ #include "core/geometry_type.hpp" #include "core/tinystring_type.hpp" #include +#include typedef Pool StationPool; extern StationPool _station_pool; diff --git a/src/cargo_type.h b/src/cargo_type.h index 808ac13339..48af1a7ed9 100644 --- a/src/cargo_type.h +++ b/src/cargo_type.h @@ -12,6 +12,9 @@ #include "core/enum_type.hpp" +#include +#include + /** * Cargo slots to indicate a cargo type within a game. * Numbers are re-used between different climates. diff --git a/src/command_aux.h b/src/command_aux.h index f9af2884da..72ee23a1ab 100644 --- a/src/command_aux.h +++ b/src/command_aux.h @@ -15,6 +15,7 @@ #include "string_type.h" #include "core/serialisation.hpp" #include +#include struct CommandDeserialisationBuffer : public BufferDeserialisationHelper { const uint8 *buffer; diff --git a/src/console_cmds.cpp b/src/console_cmds.cpp index 5fa8f2d5b8..c56b927181 100644 --- a/src/console_cmds.cpp +++ b/src/console_cmds.cpp @@ -2284,7 +2284,7 @@ DEF_CONSOLE_CMD(ConFont) InitFontCache(fs == FS_MONO); fc = FontCache::Get(fs); } - IConsolePrintF(CC_DEFAULT, "%s: \"%s\" %d %s [\"%s\" %d %s]", FontSizeToName(fs), fc->GetFontName(), fc->GetFontSize(), GetFontAAState(fs) ? "aa" : "noaa", setting->font.c_str(), setting->size, setting->aa ? "aa" : "noaa"); + IConsolePrintF(CC_DEFAULT, "%s: \"%s\" %d %s [\"%s\" %d %s]", FontSizeToName(fs), fc->GetFontName().c_str(), fc->GetFontSize(), GetFontAAState(fs) ? "aa" : "noaa", setting->font.c_str(), setting->size, setting->aa ? "aa" : "noaa"); } return true; diff --git a/src/core/pool_type.hpp b/src/core/pool_type.hpp index b1ae61b350..80e5ececed 100644 --- a/src/core/pool_type.hpp +++ b/src/core/pool_type.hpp @@ -11,6 +11,7 @@ #define POOL_TYPE_HPP #include "enum_type.hpp" +#include /** Various types of a pool. */ enum PoolType { diff --git a/src/core/smallstack_type.hpp b/src/core/smallstack_type.hpp index 662ed1aa23..c5a8291d55 100644 --- a/src/core/smallstack_type.hpp +++ b/src/core/smallstack_type.hpp @@ -9,6 +9,7 @@ #ifndef SMALLSTACK_TYPE_HPP #define SMALLSTACK_TYPE_HPP +#include /** * A simplified pool which stores values instead of pointers and doesn't diff --git a/src/crashlog.cpp b/src/crashlog.cpp index 401e0c6c29..827afb8dce 100644 --- a/src/crashlog.cpp +++ b/src/crashlog.cpp @@ -273,7 +273,7 @@ char *CrashLog::LogConfiguration(char *buffer, const char *last) const auto log_font = [&](FontSize fs) -> const char * { FontCache *fc = FontCache::Get(fs); if (fc != nullptr) { - return fc->GetFontName(); + return fc->GetFontName().c_str(); } else { return "[NULL]"; } diff --git a/src/departures_type.h b/src/departures_type.h index 91ccfadb66..82e7d33941 100644 --- a/src/departures_type.h +++ b/src/departures_type.h @@ -15,6 +15,7 @@ #include "station_base.h" #include "order_base.h" #include "vehicle_base.h" +#include /** Whether or not a vehicle has arrived for a departure. */ typedef enum { diff --git a/src/engine_base.h b/src/engine_base.h index 299fd58fbf..c199aacbce 100644 --- a/src/engine_base.h +++ b/src/engine_base.h @@ -17,6 +17,7 @@ #include "newgrf_commons.h" #include "3rdparty/cpp-btree/btree_map.h" +#include struct WagonOverride { std::vector engines; diff --git a/src/fios.h b/src/fios.h index 2742549b71..efb61888bf 100644 --- a/src/fios.h +++ b/src/fios.h @@ -14,6 +14,7 @@ #include "company_base.h" #include "newgrf_config.h" #include "network/core/tcp_content_type.h" +#include /** Special values for save-load window for the data parameter of #InvalidateWindowData. */ @@ -23,73 +24,6 @@ enum SaveLoadInvalidateWindowData { SLIWD_FILTER_CHANGES, ///< The filename filter has changed (via the editbox) }; -using CompanyPropertiesMap = std::map>; - -/** - * Container for loading in mode SL_LOAD_CHECK. - */ -struct LoadCheckData { - bool checkable; ///< True if the savegame could be checked by SL_LOAD_CHECK. (Old savegames are not checkable.) - StringID error; ///< Error message from loading. INVALID_STRING_ID if no error. - std::string error_msg; ///< Data to pass to SetDParamStr when displaying #error. - - uint32 map_size_x, map_size_y; - Date current_date; - - GameSettings settings; - - CompanyPropertiesMap companies; ///< Company information. - - GRFConfig *grfconfig; ///< NewGrf configuration from save. - bool want_grf_compatibility = true; - GRFListCompatibility grf_compatibility; ///< Summary state of NewGrfs, whether missing files or only compatible found. - - struct LoggedAction *gamelog_action; ///< Gamelog actions - uint gamelog_actions; ///< Number of gamelog actions - - bool want_debug_data = false; - std::string debug_log_data; - std::string debug_config_data; - - bool sl_is_ext_version = false; - - LoadCheckData() : grfconfig(nullptr), - grf_compatibility(GLC_NOT_FOUND), gamelog_action(nullptr), gamelog_actions(0) - { - this->Clear(); - } - - /** - * Don't leak memory at program exit - */ - ~LoadCheckData() - { - this->Clear(); - } - - /** - * Check whether loading the game resulted in errors. - * @return true if errors were encountered. - */ - bool HasErrors() - { - return this->checkable && this->error != INVALID_STRING_ID; - } - - /** - * Check whether the game uses any NewGrfs. - * @return true if NewGrfs are used. - */ - bool HasNewGrfs() - { - return this->checkable && this->error == INVALID_STRING_ID && this->grfconfig != nullptr; - } - - void Clear(); -}; - -extern LoadCheckData _load_check_data; - /** Deals with finding savegames */ struct FiosItem { FiosType type; diff --git a/src/fios_gui.cpp b/src/fios_gui.cpp index b87197993d..5504bba5c5 100644 --- a/src/fios_gui.cpp +++ b/src/fios_gui.cpp @@ -8,6 +8,7 @@ /** @file fios_gui.cpp GUIs for loading/saving games, scenarios, heightmaps, ... */ #include "stdafx.h" +#include "load_check.h" #include "sl/saveload.h" #include "error.h" #include "gui.h" @@ -57,9 +58,7 @@ void LoadCheckData::Clear() companies.clear(); - GamelogFree(this->gamelog_action, this->gamelog_actions); - this->gamelog_action = nullptr; - this->gamelog_actions = 0; + GamelogFree(this->gamelog_actions); ClearGRFConfigList(&this->grfconfig); @@ -790,7 +789,7 @@ public: ShowQuery(STR_SAVELOAD_OVERWRITE_TITLE_DIFFERENT_ID, STR_SAVELOAD_OVERWRITE_WARNING_DIFFERENT_ID, this, SaveLoadWindow::SaveGameConfirmationCallback); } else if (_settings_client.gui.savegame_overwrite_confirm >= (known_id ? 3 : 2) && file_exists) { if (this->selected != nullptr && !_load_check_data.sl_is_ext_version) { - const char *version = GamelogGetLastRevision(_load_check_data.gamelog_action, _load_check_data.gamelog_actions); + const char *version = GamelogGetLastRevision(_load_check_data.gamelog_actions); SetDParam(0, STR_SAVELOAD_OVERWRITE_TITLE); std::string caption = GetString(STR_SAVELOAD_OVERWRITE_TITLE_DIFFERENT_VERSION_SUFFIX); diff --git a/src/fontcache.h b/src/fontcache.h index a84eec5012..2204c1aea0 100644 --- a/src/fontcache.h +++ b/src/fontcache.h @@ -138,7 +138,7 @@ public: * Get the name of this font. * @return The name of the font. */ - virtual const char *GetFontName() = 0; + virtual std::string GetFontName() = 0; /** * Get the font cache of a given font size. diff --git a/src/fontcache/freetypefontcache.cpp b/src/fontcache/freetypefontcache.cpp index 9f3c7f4e68..d568949bd5 100644 --- a/src/fontcache/freetypefontcache.cpp +++ b/src/fontcache/freetypefontcache.cpp @@ -15,6 +15,7 @@ #include "../core/math_func.hpp" #include "../zoom_func.h" #include "../fileio_func.h" +#include "../string_func.h" #include "truetypefontcache.h" #include "../table/control_codes.h" @@ -41,7 +42,7 @@ public: ~FreeTypeFontCache(); void ClearFontCache() override; GlyphID MapCharToGlyph(WChar key) override; - const char *GetFontName() override { return face->family_name; } + std::string GetFontName() override { return stdstr_fmt("%s, %s", face->family_name, face->style_name); } bool IsBuiltInFont() override { return false; } const void *GetOSHandle() override { return &face; } }; diff --git a/src/fontcache/spritefontcache.h b/src/fontcache/spritefontcache.h index a47b4ac18f..ce74972b3e 100644 --- a/src/fontcache/spritefontcache.h +++ b/src/fontcache/spritefontcache.h @@ -31,7 +31,7 @@ public: virtual bool GetDrawGlyphShadow(); virtual GlyphID MapCharToGlyph(WChar key) { assert(IsPrintable(key)); return SPRITE_GLYPH | key; } virtual const void *GetFontTable(uint32 tag, size_t &length) { length = 0; return nullptr; } - virtual const char *GetFontName() { return "sprite"; } + virtual std::string GetFontName() { return "sprite"; } virtual bool IsBuiltInFont() { return true; } }; diff --git a/src/gamelog.cpp b/src/gamelog.cpp index 59cf1466be..e22c4cf329 100644 --- a/src/gamelog.cpp +++ b/src/gamelog.cpp @@ -33,8 +33,7 @@ extern byte _sl_minor_version; ///< the minor savegame version, DO NOT USE! static GamelogActionType _gamelog_action_type = GLAT_NONE; ///< action to record if anything changes -LoggedAction *_gamelog_action = nullptr; ///< first logged action -uint _gamelog_actions = 0; ///< number of actions +std::vector _gamelog_actions; ///< logged actions static LoggedAction *_current_action = nullptr; ///< current action we are logging, nullptr when there is no action active @@ -72,19 +71,17 @@ void GamelogStopAnyAction() /** * Frees the memory allocated by a gamelog */ -void GamelogFree(LoggedAction *gamelog_action, uint gamelog_actions) +void GamelogFree(std::vector &gamelog_actions) { - for (uint i = 0; i < gamelog_actions; i++) { - const LoggedAction *la = &gamelog_action[i]; - for (uint j = 0; j < la->changes; j++) { - const LoggedChange *lc = &la->change[j]; - if (lc->ct == GLCT_SETTING) free(lc->setting.name); - if (lc->ct == GLCT_REVISION) free(lc->revision.text); + for (LoggedAction &la : gamelog_actions) { + for (LoggedChange &lc : la.changes) { + if (lc.ct == GLCT_SETTING) free(lc.setting.name); + if (lc.ct == GLCT_REVISION) free(lc.revision.text); + lc.ct = GLCT_NONE; } - free(la->change); } - free(gamelog_action); + gamelog_actions.clear(); } /** @@ -93,10 +90,7 @@ void GamelogFree(LoggedAction *gamelog_action, uint gamelog_actions) void GamelogReset() { assert(_gamelog_action_type == GLAT_NONE); - GamelogFree(_gamelog_action, _gamelog_actions); - - _gamelog_action = nullptr; - _gamelog_actions = 0; + GamelogFree(_gamelog_actions); _current_action = nullptr; } @@ -174,17 +168,14 @@ void GamelogPrint(GamelogPrintProc *proc) proc("---- gamelog start ----"); - const LoggedAction *laend = &_gamelog_action[_gamelog_actions]; + for (const LoggedAction &la : _gamelog_actions) { + assert((uint)la.at < GLAT_END); - for (const LoggedAction *la = _gamelog_action; la != laend; la++) { - assert((uint)la->at < GLAT_END); - - seprintf(buffer, lastof(buffer), "Tick %u: %s", (uint)la->tick, la_text[(uint)la->at]); + seprintf(buffer, lastof(buffer), "Tick %u: %s", (uint)la.tick, la_text[(uint)la.at]); proc(buffer); - const LoggedChange *lcend = &la->change[la->changes]; - - for (const LoggedChange *lc = la->change; lc != lcend; lc++) { + for (const LoggedChange &lchange : la.changes) { + const LoggedChange *lc = &lchange; char *buf = buffer; switch (lc->ct) { @@ -259,12 +250,12 @@ void GamelogPrint(GamelogPrintProc *proc) case GLCT_GRFREM: { /* A NewGRF got removed from the game, either manually or by it missing when loading the game. */ auto gm = grf_names.find(lc->grfrem.grfid); - buf += seprintf(buf, lastof(buffer), la->at == GLAT_LOAD ? "Missing NewGRF: " : "Removed NewGRF: "); + buf += seprintf(buf, lastof(buffer), la.at == GLAT_LOAD ? "Missing NewGRF: " : "Removed NewGRF: "); buf = PrintGrfInfo(buf, lastof(buffer), lc->grfrem.grfid, nullptr, gm != grf_names.end() ? gm->second.gc : nullptr); if (gm == grf_names.end()) { buf += seprintf(buf, lastof(buffer), ". Gamelog inconsistency: GrfID was never added!"); } else { - if (la->at == GLAT_LOAD) { + if (la.at == GLAT_LOAD) { /* Missing grfs on load are not removed from the configuration */ gm->second.was_missing = true; } else { @@ -371,18 +362,14 @@ static LoggedChange *GamelogChange(GamelogChangeType ct) if (_current_action == nullptr) { if (_gamelog_action_type == GLAT_NONE) return nullptr; - _gamelog_action = ReallocT(_gamelog_action, _gamelog_actions + 1); - _current_action = &_gamelog_action[_gamelog_actions++]; + _current_action = &_gamelog_actions.emplace_back(); _current_action->at = _gamelog_action_type; _current_action->tick = _tick_counter; - _current_action->change = nullptr; - _current_action->changes = 0; } - _current_action->change = ReallocT(_current_action->change, _current_action->changes + 1); - - LoggedChange *lc = &_current_action->change[_current_action->changes++]; + _current_action->changes.push_back({}); + LoggedChange *lc = &_current_action->changes.back(); lc->ct = ct; return lc; @@ -406,17 +393,13 @@ void GamelogEmergency() */ bool GamelogTestEmergency() { - const LoggedChange *emergency = nullptr; - - const LoggedAction *laend = &_gamelog_action[_gamelog_actions]; - for (const LoggedAction *la = _gamelog_action; la != laend; la++) { - const LoggedChange *lcend = &la->change[la->changes]; - for (const LoggedChange *lc = la->change; lc != lcend; lc++) { - if (lc->ct == GLCT_EMERGENCY) emergency = lc; + for (LoggedAction &la : _gamelog_actions) { + for (LoggedChange &lc : la.changes) { + if (lc.ct == GLCT_EMERGENCY) return true; } } - return (emergency != nullptr); + return false; } /** @@ -490,11 +473,9 @@ void GamelogTestRevision() { const LoggedChange *rev = nullptr; - const LoggedAction *laend = &_gamelog_action[_gamelog_actions]; - for (const LoggedAction *la = _gamelog_action; la != laend; la++) { - const LoggedChange *lcend = &la->change[la->changes]; - for (const LoggedChange *lc = la->change; lc != lcend; lc++) { - if (lc->ct == GLCT_REVISION) rev = lc; + for (LoggedAction &la : _gamelog_actions) { + for (LoggedChange &lc : la.changes) { + if (lc.ct == GLCT_REVISION) rev = &lc; } } @@ -513,11 +494,9 @@ void GamelogTestMode() { const LoggedChange *mode = nullptr; - const LoggedAction *laend = &_gamelog_action[_gamelog_actions]; - for (const LoggedAction *la = _gamelog_action; la != laend; la++) { - const LoggedChange *lcend = &la->change[la->changes]; - for (const LoggedChange *lc = la->change; lc != lcend; lc++) { - if (lc->ct == GLCT_MODE) mode = lc; + for (LoggedAction &la : _gamelog_actions) { + for (LoggedChange &lc : la.changes) { + if (lc.ct == GLCT_MODE) mode = &lc; } } @@ -554,12 +533,10 @@ static void GamelogGRFBug(uint32 grfid, byte bug, uint64 data) */ bool GamelogGRFBugReverse(uint32 grfid, uint16 internal_id) { - const LoggedAction *laend = &_gamelog_action[_gamelog_actions]; - for (const LoggedAction *la = _gamelog_action; la != laend; la++) { - const LoggedChange *lcend = &la->change[la->changes]; - for (const LoggedChange *lc = la->change; lc != lcend; lc++) { - if (lc->ct == GLCT_GRFBUG && lc->grfbug.grfid == grfid && - lc->grfbug.bug == GBUG_VEH_LENGTH && lc->grfbug.data == internal_id) { + for (LoggedAction &la : _gamelog_actions) { + for (LoggedChange &lc : la.changes) { + if (lc.ct == GLCT_GRFBUG && lc.grfbug.grfid == grfid && + lc.grfbug.bug == GBUG_VEH_LENGTH && lc.grfbug.data == internal_id) { return false; } } @@ -789,18 +766,16 @@ void GamelogGRFUpdate(const GRFConfig *oldc, const GRFConfig *newc) * @param[out] ever_modified Max value of 'modified' from all binaries that ever saved this savegame. * @param[out] removed_newgrfs Set to true if any NewGRFs have been removed. */ -void GamelogInfo(LoggedAction *gamelog_action, uint gamelog_actions, uint32 *last_ottd_rev, byte *ever_modified, bool *removed_newgrfs) +void GamelogInfo(const std::vector &gamelog_actions, uint32 *last_ottd_rev, byte *ever_modified, bool *removed_newgrfs) { - const LoggedAction *laend = &gamelog_action[gamelog_actions]; - for (const LoggedAction *la = gamelog_action; la != laend; la++) { - const LoggedChange *lcend = &la->change[la->changes]; - for (const LoggedChange *lc = la->change; lc != lcend; lc++) { - switch (lc->ct) { + for (const LoggedAction &la : gamelog_actions) { + for (const LoggedChange &lc : la.changes) { + switch (lc.ct) { default: break; case GLCT_REVISION: - *last_ottd_rev = lc->revision.newgrf; - *ever_modified = std::max(*ever_modified, lc->revision.modified); + *last_ottd_rev = lc.revision.newgrf; + *ever_modified = std::max(*ever_modified, lc.revision.modified); break; case GLCT_GRFREM: @@ -811,15 +786,14 @@ void GamelogInfo(LoggedAction *gamelog_action, uint gamelog_actions, uint32 *las } } -const char *GamelogGetLastRevision(const LoggedAction *gamelog_action, uint gamelog_actions) +const char *GamelogGetLastRevision(const std::vector &gamelog_actions) { - for (uint i = gamelog_actions; i > 0; i--) { - const LoggedAction &la = gamelog_action[i - 1]; - const LoggedChange *lcend = &(la.change[la.changes]); - for (const LoggedChange *lc = la.change; lc != lcend; lc++) { - switch (lc->ct) { + for (size_t i = gamelog_actions.size(); i > 0; i--) { + const LoggedAction &la = gamelog_actions[i - 1]; + for (const LoggedChange &lc : la.changes) { + switch (lc.ct) { case GLCT_REVISION: - return lc->revision.text; + return lc.revision.text; break; default: diff --git a/src/gamelog.h b/src/gamelog.h index f9ab0a47e0..40277483f2 100644 --- a/src/gamelog.h +++ b/src/gamelog.h @@ -11,6 +11,9 @@ #define GAMELOG_H #include "newgrf_config.h" +#include + +struct LoggedAction; /** The actions we log. */ enum GamelogActionType : uint8 { @@ -29,7 +32,7 @@ void GamelogStartAction(GamelogActionType at); void GamelogStopAction(); void GamelogStopAnyAction(); -void GamelogFree(struct LoggedAction *gamelog_action, uint gamelog_actions); +void GamelogFree(std::vector &gamelog_actions); void GamelogReset(); /** @@ -61,7 +64,7 @@ void GamelogTestMode(); bool GamelogGRFBugReverse(uint32 grfid, uint16 internal_id); -void GamelogInfo(struct LoggedAction *gamelog_action, uint gamelog_actions, uint32 *last_ottd_rev, byte *ever_modified, bool *removed_newgrfs); -const char *GamelogGetLastRevision(const struct LoggedAction *gamelog_action, uint gamelog_actions); +void GamelogInfo(const std::vector &gamelog_actions, uint32 *last_ottd_rev, byte *ever_modified, bool *removed_newgrfs); +const char *GamelogGetLastRevision(const std::vector &gamelog_actions); #endif /* GAMELOG_H */ diff --git a/src/gamelog_internal.h b/src/gamelog_internal.h index a6f8780f0e..b49b42a6df 100644 --- a/src/gamelog_internal.h +++ b/src/gamelog_internal.h @@ -12,6 +12,8 @@ #include "gamelog.h" +#include + /** Type of logged change */ enum GamelogChangeType { GLCT_MODE, ///< Scenario editor x Game, different landscape @@ -78,13 +80,11 @@ struct LoggedChange { /** Contains information about one logged action that caused at least one logged change */ struct LoggedAction { - LoggedChange *change; ///< First logged change in this action - uint32 changes; ///< Number of changes in this action + std::vector changes; ///< Changes in this action GamelogActionType at; ///< Type of action uint64 tick; ///< Tick when it happened }; -extern LoggedAction *_gamelog_action; -extern uint _gamelog_actions; +extern std::vector _gamelog_actions; #endif /* GAMELOG_INTERNAL_H */ diff --git a/src/gfx_func.h b/src/gfx_func.h index 1a26712b20..7ef1acb86b 100644 --- a/src/gfx_func.h +++ b/src/gfx_func.h @@ -42,6 +42,7 @@ #include "gfx_type.h" #include "strings_type.h" #include "string_type.h" +#include void GameLoop(); diff --git a/src/gfx_layout.cpp b/src/gfx_layout.cpp index 9de917a80e..a17ef42f1c 100644 --- a/src/gfx_layout.cpp +++ b/src/gfx_layout.cpp @@ -64,8 +64,8 @@ static inline void GetLayouter(Layouter::LineCacheItem &line, std::string_view s { if (line.buffer != nullptr) free(line.buffer); - typename T::CharType *buff_begin = MallocT(DRAW_STRING_BUFFER); - const typename T::CharType *buffer_last = buff_begin + DRAW_STRING_BUFFER; + typename T::CharType *buff_begin = MallocT(str.size() + 1); + const typename T::CharType *buffer_last = buff_begin + str.size() + 1; typename T::CharType *buff = buff_begin; FontMap &fontMapping = line.runs; Font *f = Layouter::GetFont(state.fontsize, state.cur_colour); @@ -206,6 +206,19 @@ Dimension Layouter::GetBounds() return d; } +/** + * Test whether a character is a non-printable formatting code + */ +static bool IsConsumedFormattingCode(WChar ch) +{ + if (ch >= SCC_BLUE && ch <= SCC_BLACK) return true; + if (ch == SCC_PUSH_COLOUR) return true; + if (ch == SCC_POP_COLOUR) return true; + if (ch >= SCC_FIRST_FONT && ch <= SCC_LAST_FONT) return true; + // All other characters defined in Unicode standard are assumed to be non-consumed. + return false; +} + /** * Get the position of a character in the layout. * @param ch Character to get the position of. Must be an iterator of the string passed to the constructor. @@ -228,7 +241,7 @@ Point Layouter::GetCharPosition(std::string_view::const_iterator ch) const auto str = this->string.begin(); while (str < ch) { WChar c = Utf8Consume(str); - index += line->GetInternalCharLength(c); + if (!IsConsumedFormattingCode(c)) index += line->GetInternalCharLength(c); } /* We couldn't find the code point index. */ @@ -255,9 +268,9 @@ Point Layouter::GetCharPosition(std::string_view::const_iterator ch) const } /** - * Get the character that is at a position. + * Get the character that is at a pixel position in the first line of the layouted text. * @param x Position in the string. - * @return Index of the position or -1 if no character is at the position. + * @return String offset of the position (bytes) or -1 if no character is at the position. */ ptrdiff_t Layouter::GetCharAtPosition(int x) const { @@ -278,12 +291,11 @@ ptrdiff_t Layouter::GetCharAtPosition(int x) const size_t index = run.GetGlyphToCharMap()[i]; size_t cur_idx = 0; - int char_index = 0; - for (auto str = this->string.begin(); str != this->string.end(); char_index++) { - if (cur_idx == index) return char_index; + for (auto str = this->string.begin(); str != this->string.end();) { + if (cur_idx == index) return str - this->string.begin(); WChar c = Utf8Consume(str); - cur_idx += line->GetInternalCharLength(c); + if (!IsConsumedFormattingCode(c)) cur_idx += line->GetInternalCharLength(c); } } } diff --git a/src/landscape.h b/src/landscape.h index 5c0d8327c7..4b029e80c1 100644 --- a/src/landscape.h +++ b/src/landscape.h @@ -12,6 +12,7 @@ #include "core/geometry_type.hpp" #include "tile_cmd.h" +#include static const uint SNOW_LINE_MONTHS = 12; ///< Number of months in the snow line table. static const uint SNOW_LINE_DAYS = 32; ///< Number of days in each month in the snow line table. diff --git a/src/language.h b/src/language.h index 0966ccb197..7e1ed3bc47 100644 --- a/src/language.h +++ b/src/language.h @@ -14,6 +14,7 @@ #include #endif /* WITH_ICU_I18N */ #include "strings_type.h" +#include static const uint8 CASE_GENDER_LEN = 16; ///< The (maximum) length of a case/gender string. static const uint8 MAX_NUM_GENDERS = 8; ///< Maximum number of supported genders. diff --git a/src/linkgraph/demands.h b/src/linkgraph/demands.h index b759c64941..c21e9cdc99 100644 --- a/src/linkgraph/demands.h +++ b/src/linkgraph/demands.h @@ -4,6 +4,7 @@ #define DEMANDS_H #include "linkgraphjob_base.h" +#include /** * Calculate the demands. This class has a state, but is recreated for each diff --git a/src/linkgraph/linkgraph.h b/src/linkgraph/linkgraph.h index a50604de75..0fc571346c 100644 --- a/src/linkgraph/linkgraph.h +++ b/src/linkgraph/linkgraph.h @@ -19,6 +19,7 @@ #include "linkgraph_type.h" #include "../3rdparty/cpp-btree/btree_map.h" #include +#include class LinkGraph; diff --git a/src/linkgraph/linkgraphschedule.h b/src/linkgraph/linkgraphschedule.h index af54751afc..ee7602a221 100644 --- a/src/linkgraph/linkgraphschedule.h +++ b/src/linkgraph/linkgraphschedule.h @@ -13,6 +13,7 @@ #include "../thread.h" #include "linkgraph.h" #include +#include class LinkGraphJob; diff --git a/src/load_check.h b/src/load_check.h new file mode 100644 index 0000000000..fbdae78853 --- /dev/null +++ b/src/load_check.h @@ -0,0 +1,89 @@ +/* + * This file is part of OpenTTD. + * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2. + * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see . + */ + +/** @file load_check.h Load check data. */ + +#ifndef LOAD_CHECK_H +#define LOAD_CHECK_H + +#include "company_base.h" +#include "date_type.h" +#include "gamelog_internal.h" +#include "newgrf_config.h" +#include "strings_type.h" +#include "3rdparty/cpp-btree/btree_map.h" +#include +#include +#include + +using CompanyPropertiesMap = btree::btree_map>; + +/** + * Container for loading in mode SL_LOAD_CHECK. + */ +struct LoadCheckData { + bool checkable; ///< True if the savegame could be checked by SL_LOAD_CHECK. (Old savegames are not checkable.) + StringID error; ///< Error message from loading. INVALID_STRING_ID if no error. + std::string error_msg; ///< Data to pass to SetDParamStr when displaying #error. + + uint32 map_size_x, map_size_y; + Date current_date; + + GameSettings settings; + + CompanyPropertiesMap companies; ///< Company information. + + GRFConfig *grfconfig; ///< NewGrf configuration from save. + bool want_grf_compatibility = true; + GRFListCompatibility grf_compatibility; ///< Summary state of NewGrfs, whether missing files or only compatible found. + + std::vector gamelog_actions; ///< Gamelog actions + + bool want_debug_data = false; + std::string debug_log_data; + std::string debug_config_data; + + bool sl_is_ext_version = false; + + LoadCheckData() : grfconfig(nullptr), + grf_compatibility(GLC_NOT_FOUND) + { + this->Clear(); + } + + /** + * Don't leak memory at program exit + */ + ~LoadCheckData() + { + this->Clear(); + } + + /** + * Check whether loading the game resulted in errors. + * @return true if errors were encountered. + */ + bool HasErrors() + { + return this->checkable && this->error != INVALID_STRING_ID; + } + + /** + * Check whether the game uses any NewGrfs. + * @return true if NewGrfs are used. + */ + bool HasNewGrfs() + { + return this->checkable && this->error == INVALID_STRING_ID && this->grfconfig != nullptr; + } + + void Clear(); +}; + +extern LoadCheckData _load_check_data; + +#endif /* LOAD_CHECK_H */ diff --git a/src/network/core/address.h b/src/network/core/address.h index 65adb9f3fc..8bad0618ff 100644 --- a/src/network/core/address.h +++ b/src/network/core/address.h @@ -17,6 +17,7 @@ #include #include +#include class NetworkAddress; typedef std::vector NetworkAddressList; ///< Type for a list of addresses. diff --git a/src/network/core/packet.h b/src/network/core/packet.h index 37780c92d4..52544d754e 100644 --- a/src/network/core/packet.h +++ b/src/network/core/packet.h @@ -20,6 +20,7 @@ #include #include #include +#include typedef uint16 PacketSize; ///< Size of the whole packet. typedef uint8 PacketType; ///< Identifier for the packet diff --git a/src/network/core/tcp.h b/src/network/core/tcp.h index 80b73ac3f1..d5551ce89e 100644 --- a/src/network/core/tcp.h +++ b/src/network/core/tcp.h @@ -20,6 +20,7 @@ #include #include #include +#include #include #if defined(__MINGW32__) #include "3rdparty/mingw-std-threads/mingw.thread.h" diff --git a/src/network/core/tcp_content_type.h b/src/network/core/tcp_content_type.h index f63cdbd492..5049c13f3c 100644 --- a/src/network/core/tcp_content_type.h +++ b/src/network/core/tcp_content_type.h @@ -13,6 +13,7 @@ #define NETWORK_CORE_TCP_CONTENT_TYPE_H #include "../../3rdparty/md5/md5.h" +#include /** The values in the enum are important; they are used as database 'keys' */ enum ContentType { diff --git a/src/network/network_content.h b/src/network/network_content.h index 53e4e1bb66..9c5287fb4c 100644 --- a/src/network/network_content.h +++ b/src/network/network_content.h @@ -14,6 +14,7 @@ #include "core/http.h" #include "../core/container_func.hpp" #include "../3rdparty/cpp-btree/btree_map.h" +#include /** Vector with content info */ typedef std::vector ContentVector; diff --git a/src/network/network_query.h b/src/network/network_query.h index e4e09fa1bb..2ef5b3ed63 100644 --- a/src/network/network_query.h +++ b/src/network/network_query.h @@ -11,6 +11,7 @@ #define NETWORK_QUERY_H #include "network_internal.h" +#include /** Class for handling the client side of quering a game server. */ class QueryNetworkGameSocketHandler : public ZeroedMemoryAllocator, public NetworkGameSocketHandler { diff --git a/src/network/network_survey.h b/src/network/network_survey.h index c957108ecf..48206e51cd 100644 --- a/src/network/network_survey.h +++ b/src/network/network_survey.h @@ -12,6 +12,10 @@ #include #include +#if defined(__MINGW32__) +#include "../3rdparty/mingw-std-threads/mingw.condition_variable.h" +#include "../3rdparty/mingw-std-threads/mingw.mutex.h" +#endif #include "core/http.h" /** diff --git a/src/newgrf.h b/src/newgrf.h index 7566bb95d1..69c8185030 100644 --- a/src/newgrf.h +++ b/src/newgrf.h @@ -20,6 +20,7 @@ #include "core/mem_func.hpp" #include "3rdparty/cpp-btree/btree_map.h" #include +#include /** * List of different canal 'features'. diff --git a/src/newgrf_commons.h b/src/newgrf_commons.h index fd462508e4..0034212c89 100644 --- a/src/newgrf_commons.h +++ b/src/newgrf_commons.h @@ -18,6 +18,7 @@ #include "command_type.h" #include "direction_type.h" #include "company_type.h" +#include /** Context for tile accesses */ enum TileContext : uint8 { diff --git a/src/newgrf_config.h b/src/newgrf_config.h index ef0c1e6a4c..69ddfccf83 100644 --- a/src/newgrf_config.h +++ b/src/newgrf_config.h @@ -18,6 +18,8 @@ #include "newgrf_text.h" #include "3rdparty/md5/md5.h" #include +#include +#include static const uint MAX_NON_STATIC_GRF_COUNT = 256; diff --git a/src/newgrf_debug.h b/src/newgrf_debug.h index 56a9c60117..2b134654cd 100644 --- a/src/newgrf_debug.h +++ b/src/newgrf_debug.h @@ -13,6 +13,7 @@ #include "newgrf.h" #include "tile_type.h" #include "vehicle_type.h" +#include /** Current state of spritepicker */ enum NewGrfDebugSpritePickerMode { diff --git a/src/newgrf_internal.h b/src/newgrf_internal.h index c04f49499c..1ff083cd2d 100644 --- a/src/newgrf_internal.h +++ b/src/newgrf_internal.h @@ -19,6 +19,7 @@ #include "3rdparty/cpp-btree/btree_map.h" #include +#include /** Base GRF ID for OpenTTD's base graphics GRFs. */ static const uint32 OPENTTD_GRAPHICS_BASE_GRF_ID = BSWAP32(0xFF4F5400); diff --git a/src/newgrf_newlandscape.h b/src/newgrf_newlandscape.h index 105e6ce1a8..504121f907 100644 --- a/src/newgrf_newlandscape.h +++ b/src/newgrf_newlandscape.h @@ -12,6 +12,7 @@ #include "newgrf_commons.h" #include "newgrf_spritegroup.h" +#include extern std::vector _new_landscape_rocks_grfs; diff --git a/src/newgrf_object.h b/src/newgrf_object.h index ef6b3763ea..30b14c4614 100644 --- a/src/newgrf_object.h +++ b/src/newgrf_object.h @@ -19,6 +19,7 @@ #include "newgrf_animation_type.h" #include "newgrf_class.h" #include "newgrf_commons.h" +#include /** Various object behaviours. */ enum ObjectFlags : uint16 { diff --git a/src/newgrf_spritegroup.h b/src/newgrf_spritegroup.h index e5b3b5204b..410e715f2b 100644 --- a/src/newgrf_spritegroup.h +++ b/src/newgrf_spritegroup.h @@ -23,6 +23,7 @@ #include "3rdparty/cpp-btree/btree_set.h" #include +#include /** * Gets the value of a so-called newgrf "register". diff --git a/src/newgrf_station.h b/src/newgrf_station.h index 1514e4d296..9f02b486a5 100644 --- a/src/newgrf_station.h +++ b/src/newgrf_station.h @@ -19,6 +19,7 @@ #include "rail_type.h" #include "newgrf_spritegroup.h" #include "newgrf_town.h" +#include /** Scope resolver for stations. */ struct StationScopeResolver : public ScopeResolver { diff --git a/src/object_base.h b/src/object_base.h index b60f7cb626..a0e791e8c0 100644 --- a/src/object_base.h +++ b/src/object_base.h @@ -15,6 +15,7 @@ #include "tilearea_type.h" #include "town_type.h" #include "date_type.h" +#include typedef Pool ObjectPool; extern ObjectPool _object_pool; diff --git a/src/openttd.cpp b/src/openttd.cpp index 81919036aa..0ac04903f7 100644 --- a/src/openttd.cpp +++ b/src/openttd.cpp @@ -25,6 +25,7 @@ #include "command_func.h" #include "news_func.h" #include "fios.h" +#include "load_check.h" #include "aircraft.h" #include "roadveh.h" #include "train.h" @@ -328,7 +329,7 @@ static void WriteSavegameInfo(const char *name) byte ever_modified = 0; bool removed_newgrfs = false; - GamelogInfo(_load_check_data.gamelog_action, _load_check_data.gamelog_actions, &last_ottd_rev, &ever_modified, &removed_newgrfs); + GamelogInfo(_load_check_data.gamelog_actions, &last_ottd_rev, &ever_modified, &removed_newgrfs); char buf[65536]; char *p = buf; diff --git a/src/order_backup.h b/src/order_backup.h index 33d7f1be62..4953a5b183 100644 --- a/src/order_backup.h +++ b/src/order_backup.h @@ -17,6 +17,7 @@ #include "base_consist.h" #include "order_base.h" #include "sl/saveload_common.h" +#include /** Unique identifier for an order backup. */ typedef uint8 OrderBackupID; diff --git a/src/os/macosx/font_osx.h b/src/os/macosx/font_osx.h index 7b58bc772c..72518c5676 100644 --- a/src/os/macosx/font_osx.h +++ b/src/os/macosx/font_osx.h @@ -30,7 +30,7 @@ public: void ClearFontCache() override; GlyphID MapCharToGlyph(WChar key) override; - const char *GetFontName() override { return font_name.c_str(); } + std::string GetFontName() override { return font_name; } bool IsBuiltInFont() override { return false; } const void *GetOSHandle() override { return font.get(); } }; diff --git a/src/os/macosx/string_osx.cpp b/src/os/macosx/string_osx.cpp index 68a683b876..25e8fb71c7 100644 --- a/src/os/macosx/string_osx.cpp +++ b/src/os/macosx/string_osx.cpp @@ -180,7 +180,7 @@ static CTRunDelegateCallbacks _sprite_font_callback = { if (font == nullptr) { if (!_font_cache[i.second->fc->GetSize()]) { /* Cache font information. */ - CFAutoRelease font_name(CFStringCreateWithCString(kCFAllocatorDefault, i.second->fc->GetFontName(), kCFStringEncodingUTF8)); + CFAutoRelease font_name(CFStringCreateWithCString(kCFAllocatorDefault, i.second->fc->GetFontName().c_str(), kCFStringEncodingUTF8)); _font_cache[i.second->fc->GetSize()].reset(CTFontCreateWithName(font_name.get(), i.second->fc->GetFontSize(), nullptr)); } font = _font_cache[i.second->fc->GetSize()].get(); diff --git a/src/os/windows/font_win32.h b/src/os/windows/font_win32.h index b83b2c5f35..7f5f62a7f2 100644 --- a/src/os/windows/font_win32.h +++ b/src/os/windows/font_win32.h @@ -34,7 +34,7 @@ public: ~Win32FontCache(); void ClearFontCache() override; GlyphID MapCharToGlyph(WChar key) override; - const char *GetFontName() override { return this->fontname.c_str(); } + std::string GetFontName() override { return this->fontname; } const void *GetOSHandle() override { return &this->logfont; } }; diff --git a/src/programmable_signals.h b/src/programmable_signals.h index 2a348bf800..1365471690 100644 --- a/src/programmable_signals.h +++ b/src/programmable_signals.h @@ -13,6 +13,7 @@ #include "tracerestrict.h" #include "core/container_func.hpp" #include +#include /** @defgroup progsigs Programmable Pre-Signals */ ///@{ diff --git a/src/rail.h b/src/rail.h index 4efd4c3489..e916e3c505 100644 --- a/src/rail.h +++ b/src/rail.h @@ -21,6 +21,7 @@ #include "signal_type.h" #include "rail_map.h" #include "settings_type.h" +#include /** Railtype flags. */ enum RailTypeFlags { diff --git a/src/saveload/afterload.cpp b/src/saveload/afterload.cpp index ec60fb4c5e..d2d1a0605f 100644 --- a/src/saveload/afterload.cpp +++ b/src/saveload/afterload.cpp @@ -389,12 +389,11 @@ static void ResetSignalHandlers() */ static const GRFIdentifier *GetOverriddenIdentifier(const GRFConfig *c) { - const LoggedAction *la = &_gamelog_action[_gamelog_actions - 1]; - if (la->at != GLAT_LOAD) return &c->ident; + const LoggedAction &la = _gamelog_actions.back(); + if (la.at != GLAT_LOAD) return &c->ident; - const LoggedChange *lcend = &la->change[la->changes]; - for (const LoggedChange *lc = la->change; lc != lcend; lc++) { - if (lc->ct == GLCT_GRFCOMPAT && lc->grfcompat.grfid == c->ident.grfid) return &lc->grfcompat; + for (const LoggedChange &lc : la.changes) { + if (lc.ct == GLCT_GRFCOMPAT && lc.grfcompat.grfid == c->ident.grfid) return &lc.grfcompat; } return &c->ident; diff --git a/src/saveload/company_sl.cpp b/src/saveload/company_sl.cpp index fb4f8aa823..213e2d08a4 100644 --- a/src/saveload/company_sl.cpp +++ b/src/saveload/company_sl.cpp @@ -15,6 +15,7 @@ #include "../company_func.h" #include "../company_manager_face.h" #include "../fios.h" +#include "../load_check.h" #include "../tunnelbridge_map.h" #include "../tunnelbridge.h" #include "../station_base.h" diff --git a/src/saveload/gamelog_sl.cpp b/src/saveload/gamelog_sl.cpp index c0ebd3991b..3b0d28dc92 100644 --- a/src/saveload/gamelog_sl.cpp +++ b/src/saveload/gamelog_sl.cpp @@ -14,6 +14,7 @@ #include "../gamelog_internal.h" #include "../fios.h" +#include "../load_check.h" #include "../string_func.h" #include "../safeguards.h" @@ -309,27 +310,26 @@ public: void Save(LoggedAction *la) const override { - SlSetStructListLength(la->changes); + SlSetStructListLength(la->changes.size()); - const LoggedChange *lcend = &la->change[la->changes]; - for (LoggedChange *lc = la->change; lc != lcend; lc++) { - assert((uint)lc->ct < GLCT_END); - SlObject(lc, this->GetDescription()); + for (LoggedChange &lc : la->changes) { + assert((uint)lc.ct < GLCT_END); + SlObject(&lc, this->GetDescription()); } } void Load(LoggedAction *la) const override { + la->changes.clear(); + if (IsSavegameVersionBefore(SLV_RIFF_TO_ARRAY)) { byte type; while ((type = SlReadByte()) != GLCT_NONE) { if (type >= GLCT_END) SlErrorCorrupt("Invalid gamelog change type"); GamelogChangeType ct = (GamelogChangeType)type; - la->change = ReallocT(la->change, la->changes + 1); - - LoggedChange *lc = &la->change[la->changes++]; - *lc = LoggedChange{}; + la->changes.push_back({}); + LoggedChange *lc = &la->changes.back(); lc->ct = ct; SlObject(lc, this->GetLoadDescription()); @@ -338,12 +338,11 @@ public: } size_t length = SlGetStructListLength(UINT32_MAX); - la->change = ReallocT(la->change, length); - la->changes = (uint32)length; + la->changes.reserve(length); for (size_t i = 0; i < length; i++) { - LoggedChange *lc = &la->change[i]; - *lc = LoggedChange{}; + la->changes.push_back({}); + LoggedChange *lc = &la->changes.back(); lc->ct = (GamelogChangeType)SlReadByte(); SlObject(lc, this->GetLoadDescription()); @@ -363,10 +362,9 @@ static const SaveLoad _gamelog_desc[] = { struct GLOGChunkHandler : ChunkHandler { GLOGChunkHandler() : ChunkHandler('GLOG', CH_TABLE) {} - void LoadCommon(LoggedAction *&gamelog_action, uint &gamelog_actions) const + void LoadCommon(std::vector &gamelog_actions) const { - assert(gamelog_action == nullptr); - assert(gamelog_actions == 0); + assert(gamelog_actions.empty()); const std::vector slt = SlCompatTableHeader(_gamelog_desc, _gamelog_sl_compat); @@ -375,22 +373,18 @@ struct GLOGChunkHandler : ChunkHandler { while ((type = SlReadByte()) != GLAT_NONE) { if (type >= GLAT_END) SlErrorCorrupt("Invalid gamelog action type"); - gamelog_action = ReallocT(gamelog_action, gamelog_actions + 1); - LoggedAction *la = &gamelog_action[gamelog_actions++]; - *la = LoggedAction{}; + LoggedAction &la = gamelog_actions.emplace_back(); - la->at = (GamelogActionType)type; - SlObject(la, slt); + la.at = (GamelogActionType)type; + SlObject(&la, slt); } return; } while (SlIterateArray() != -1) { - gamelog_action = ReallocT(gamelog_action, gamelog_actions + 1); - LoggedAction *la = &gamelog_action[gamelog_actions++]; - *la = LoggedAction{}; + LoggedAction &la = gamelog_actions.emplace_back(); - SlObject(la, slt); + SlObject(&la, slt); } } @@ -398,23 +392,22 @@ struct GLOGChunkHandler : ChunkHandler { { SlTableHeader(_gamelog_desc); - const LoggedAction *laend = &_gamelog_action[_gamelog_actions]; - uint i = 0; - for (LoggedAction *la = _gamelog_action; la != laend; la++, i++) { + for (LoggedAction &la : _gamelog_actions) { SlSetArrayIndex(i); - SlObject(la, _gamelog_desc); + SlObject(&la, _gamelog_desc); + i++; } } void Load() const override { - this->LoadCommon(_gamelog_action, _gamelog_actions); + this->LoadCommon(_gamelog_actions); } void LoadCheck(size_t) const override { - this->LoadCommon(_load_check_data.gamelog_action, _load_check_data.gamelog_actions); + this->LoadCommon(_load_check_data.gamelog_actions); } }; diff --git a/src/saveload/map_sl.cpp b/src/saveload/map_sl.cpp index d974da8322..afea07a59d 100644 --- a/src/saveload/map_sl.cpp +++ b/src/saveload/map_sl.cpp @@ -15,6 +15,7 @@ #include "../map_func.h" #include "../core/bitmath_func.hpp" #include "../fios.h" +#include "../load_check.h" #include #include "../safeguards.h" diff --git a/src/saveload/misc_sl.cpp b/src/saveload/misc_sl.cpp index e597c4a4d4..857a499a85 100644 --- a/src/saveload/misc_sl.cpp +++ b/src/saveload/misc_sl.cpp @@ -20,6 +20,7 @@ #include "../gfx_func.h" #include "../core/random_func.hpp" #include "../fios.h" +#include "../load_check.h" #include "../timer/timer.h" #include "../timer/timer_game_tick.h" diff --git a/src/saveload/newgrf_sl.cpp b/src/saveload/newgrf_sl.cpp index ae36fe7756..99c73d979d 100644 --- a/src/saveload/newgrf_sl.cpp +++ b/src/saveload/newgrf_sl.cpp @@ -14,6 +14,7 @@ #include "newgrf_sl.h" #include "../fios.h" +#include "../load_check.h" #include "../safeguards.h" diff --git a/src/saveload/settings_sl.cpp b/src/saveload/settings_sl.cpp index 5224e01d0f..3a807f2e0b 100644 --- a/src/saveload/settings_sl.cpp +++ b/src/saveload/settings_sl.cpp @@ -17,6 +17,7 @@ #include "../settings_internal.h" #include "../network/network.h" #include "../fios.h" +#include "../load_check.h" #include "../safeguards.h" diff --git a/src/settings.cpp b/src/settings.cpp index b6cb548870..344a3d7f83 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -66,6 +66,7 @@ #include "smallmap_gui.h" #include "roadveh.h" #include "fios.h" +#include "load_check.h" #include "strings_func.h" #include "string_func.h" #include "debug.h" diff --git a/src/settings_internal.h b/src/settings_internal.h index 90eb39ce89..465556803b 100644 --- a/src/settings_internal.h +++ b/src/settings_internal.h @@ -13,6 +13,7 @@ #include "sl/saveload_types.h" #include +#include enum SettingFlag : uint32 { SF_NONE = 0, diff --git a/src/sl/company_sl.cpp b/src/sl/company_sl.cpp index 4bf791441c..5a6bb6d970 100644 --- a/src/sl/company_sl.cpp +++ b/src/sl/company_sl.cpp @@ -11,6 +11,7 @@ #include "../company_func.h" #include "../company_manager_face.h" #include "../fios.h" +#include "../load_check.h" #include "../tunnelbridge_map.h" #include "../tunnelbridge.h" #include "../station_base.h" diff --git a/src/sl/debug_sl.cpp b/src/sl/debug_sl.cpp index 7c904d73bf..6bfb1fe77b 100644 --- a/src/sl/debug_sl.cpp +++ b/src/sl/debug_sl.cpp @@ -13,6 +13,7 @@ #include "saveload.h" #include "saveload_buffer.h" #include "../fios.h" +#include "../load_check.h" #include "../safeguards.h" diff --git a/src/sl/gamelog_sl.cpp b/src/sl/gamelog_sl.cpp index 8270190c53..8d4f313409 100644 --- a/src/sl/gamelog_sl.cpp +++ b/src/sl/gamelog_sl.cpp @@ -10,6 +10,7 @@ #include "../stdafx.h" #include "../gamelog_internal.h" #include "../fios.h" +#include "../load_check.h" #include "../string_func.h" #include "saveload.h" @@ -96,37 +97,31 @@ static const SaveLoadTable _glog_desc[] = { static_assert(lengthof(_glog_desc) == GLCT_END); -static void Load_GLOG_common(LoggedAction *&gamelog_action, uint &gamelog_actions) +static void Load_GLOG_common(std::vector &gamelog_actions) { - assert(gamelog_action == nullptr); - assert(gamelog_actions == 0); + assert(gamelog_actions.empty()); byte type; while ((type = SlReadByte()) != GLAT_NONE) { if (type >= GLAT_END) SlErrorCorrupt("Invalid gamelog action type"); GamelogActionType at = (GamelogActionType)type; - gamelog_action = ReallocT(gamelog_action, gamelog_actions + 1); - LoggedAction *la = &gamelog_action[gamelog_actions++]; + LoggedAction &la = gamelog_actions.emplace_back(); - la->at = at; + la.at = at; - SlObject(la, _glog_action_desc); // has to be saved after 'DATE'! - la->change = nullptr; - la->changes = 0; + SlObject(&la, _glog_action_desc); // has to be saved after 'DATE'! while ((type = SlReadByte()) != GLCT_NONE) { if (type >= GLCT_END) SlErrorCorrupt("Invalid gamelog change type"); GamelogChangeType ct = (GamelogChangeType)type; - la->change = ReallocT(la->change, la->changes + 1); + la.changes.push_back({}); + LoggedChange *lc = &la.changes.back(); - LoggedChange *lc = &la->change[la->changes++]; - /* for SLE_STR, pointer has to be valid! so make it nullptr */ - memset(lc, 0, sizeof(*lc)); lc->ct = ct; - SlObject(lc, _glog_desc[ct]); + if (ct == GLCT_REVISION && SlXvIsFeatureMissing(XSLFI_EXTENDED_GAMELOG)) { lc->revision.text = stredup(old_revision_text, lastof(old_revision_text)); } @@ -136,44 +131,30 @@ static void Load_GLOG_common(LoggedAction *&gamelog_action, uint &gamelog_action static void Save_GLOG() { - const LoggedAction *laend = &_gamelog_action[_gamelog_actions]; - size_t length = 0; + SlAutolength([](void *) { + for (LoggedAction &la : _gamelog_actions) { + SlWriteByte(la.at); + SlObject(&la, _glog_action_desc); - for (const LoggedAction *la = _gamelog_action; la != laend; la++) { - const LoggedChange *lcend = &la->change[la->changes]; - for (LoggedChange *lc = la->change; lc != lcend; lc++) { - assert((uint)lc->ct < lengthof(_glog_desc)); - length += SlCalcObjLength(lc, _glog_desc[lc->ct]) + 1; + for (LoggedChange &lc : la.changes) { + SlWriteByte(lc.ct); + assert((uint)lc.ct < GLCT_END); + SlObject(&lc, _glog_desc[lc.ct]); + } + SlWriteByte(GLCT_NONE); } - length += 10; - } - length++; - - SlSetLength(length); - - for (LoggedAction *la = _gamelog_action; la != laend; la++) { - SlWriteByte(la->at); - SlObject(la, _glog_action_desc); - - const LoggedChange *lcend = &la->change[la->changes]; - for (LoggedChange *lc = la->change; lc != lcend; lc++) { - SlWriteByte(lc->ct); - assert((uint)lc->ct < GLCT_END); - SlObject(lc, _glog_desc[lc->ct]); - } - SlWriteByte(GLCT_NONE); - } - SlWriteByte(GLAT_NONE); + SlWriteByte(GLAT_NONE); + }, nullptr); } static void Load_GLOG() { - Load_GLOG_common(_gamelog_action, _gamelog_actions); + Load_GLOG_common(_gamelog_actions); } static void Check_GLOG() { - Load_GLOG_common(_load_check_data.gamelog_action, _load_check_data.gamelog_actions); + Load_GLOG_common(_load_check_data.gamelog_actions); } static const ChunkHandler gamelog_chunk_handlers[] = { diff --git a/src/sl/map_sl.cpp b/src/sl/map_sl.cpp index 5017b7557e..80d8771fd9 100644 --- a/src/sl/map_sl.cpp +++ b/src/sl/map_sl.cpp @@ -13,6 +13,7 @@ #include "../core/endian_func.hpp" #include "../core/endian_type.hpp" #include "../fios.h" +#include "../load_check.h" #include #include "saveload.h" diff --git a/src/sl/misc_sl.cpp b/src/sl/misc_sl.cpp index ddc64b7ca4..9a4d2551f3 100644 --- a/src/sl/misc_sl.cpp +++ b/src/sl/misc_sl.cpp @@ -16,6 +16,7 @@ #include "../gfx_func.h" #include "../core/random_func.hpp" #include "../fios.h" +#include "../load_check.h" #include "../road_type.h" #include "../core/checksum_func.hpp" #include "../event_logs.h" diff --git a/src/sl/newgrf_sl.cpp b/src/sl/newgrf_sl.cpp index dd5932a750..288ae701e6 100644 --- a/src/sl/newgrf_sl.cpp +++ b/src/sl/newgrf_sl.cpp @@ -9,6 +9,7 @@ #include "../stdafx.h" #include "../fios.h" +#include "../load_check.h" #include "../string_func.h" #include "saveload.h" diff --git a/src/sl/saveload.cpp b/src/sl/saveload.cpp index fc4bf9f1fd..300f015d88 100644 --- a/src/sl/saveload.cpp +++ b/src/sl/saveload.cpp @@ -42,6 +42,7 @@ #include "../string_func.h" #include "../string_func_extra.h" #include "../fios.h" +#include "../load_check.h" #include "../error.h" #include "../scope.h" #include diff --git a/src/sl/saveload.h b/src/sl/saveload.h index d849bb0e4d..dc17a68964 100644 --- a/src/sl/saveload.h +++ b/src/sl/saveload.h @@ -19,7 +19,6 @@ #include #include #include -#include /** Save or load result codes. */ enum SaveOrLoadResult { diff --git a/src/smallmap_gui.h b/src/smallmap_gui.h index 939f8382b8..2d8f75a70a 100644 --- a/src/smallmap_gui.h +++ b/src/smallmap_gui.h @@ -18,6 +18,7 @@ #include "linkgraph/linkgraph_gui.h" #include "widgets/smallmap_widget.h" #include "guitimer_func.h" +#include static const int NUM_NO_COMPANY_ENTRIES = 4; ///< Number of entries in the owner legend that are not companies. diff --git a/src/sortlist_type.h b/src/sortlist_type.h index 3d4a2c3ea9..554478fd89 100644 --- a/src/sortlist_type.h +++ b/src/sortlist_type.h @@ -14,6 +14,7 @@ #include "core/bitmath_func.hpp" #include "core/mem_func.hpp" #include "date_type.h" +#include /** Flags of the sort list. */ enum SortListFlags { diff --git a/src/stringfilter_type.h b/src/stringfilter_type.h index 5b24587cb5..ef2b4d7efc 100644 --- a/src/stringfilter_type.h +++ b/src/stringfilter_type.h @@ -11,6 +11,7 @@ #define STRINGFILTER_TYPE_H #include "strings_type.h" +#include /** * String filter and state. diff --git a/src/textfile_gui.h b/src/textfile_gui.h index f71f8e5686..b2e71084cd 100644 --- a/src/textfile_gui.h +++ b/src/textfile_gui.h @@ -15,6 +15,7 @@ #include "textfile_type.h" #include "window_gui.h" #include +#include const char *GetTextfile(TextfileType type, Subdirectory dir, const char *filename); diff --git a/src/town_type.h b/src/town_type.h index d0cf7aaf9b..b7e327ce15 100644 --- a/src/town_type.h +++ b/src/town_type.h @@ -11,6 +11,7 @@ #define TOWN_TYPE_H #include "core/enum_type.hpp" +#include typedef uint16 TownID; struct Town; diff --git a/src/vehicle_base.h b/src/vehicle_base.h index 27028ca221..c192abeb0d 100644 --- a/src/vehicle_base.h +++ b/src/vehicle_base.h @@ -28,6 +28,7 @@ #include "sl/saveload_common.h" #include #include +#include CommandCost CmdRefitVehicle(TileIndex, DoCommandFlag, uint32, uint32, const char*); diff --git a/src/vehicle_func.h b/src/vehicle_func.h index 87e67433c5..3815de6b88 100644 --- a/src/vehicle_func.h +++ b/src/vehicle_func.h @@ -20,6 +20,7 @@ #include "track_type.h" #include "livery.h" #include "cargo_type.h" +#include #define is_custom_sprite(x) (x >= 0xFD) #define IS_CUSTOM_FIRSTHEAD_SPRITE(x) (x == 0xFD) diff --git a/src/vehicle_gui.h b/src/vehicle_gui.h index 1099fe0d0e..256b9a4dce 100644 --- a/src/vehicle_gui.h +++ b/src/vehicle_gui.h @@ -17,6 +17,7 @@ #include "engine_type.h" #include "company_type.h" #include "widgets/dropdown_func.h" +#include void ShowVehicleRefitWindow(const Vehicle *v, VehicleOrderID order, Window *parent, bool auto_refit = false, bool is_virtual_train = false); diff --git a/src/vehiclelist.h b/src/vehiclelist.h index 4aadc7b786..866f4eb632 100644 --- a/src/vehiclelist.h +++ b/src/vehiclelist.h @@ -14,6 +14,7 @@ #include "company_type.h" #include "tile_type.h" #include "cargo_type.h" +#include /** Vehicle List type flags */ enum VehicleListType { diff --git a/src/video/sdl2_v.h b/src/video/sdl2_v.h index ce7d79f249..3def038f44 100644 --- a/src/video/sdl2_v.h +++ b/src/video/sdl2_v.h @@ -16,6 +16,7 @@ #endif #include "video_driver.hpp" +#include /** The SDL video driver. */ class VideoDriver_SDL_Base : public VideoDriver { diff --git a/src/video/win32_v.h b/src/video/win32_v.h index 31f83c827b..968eb6b195 100644 --- a/src/video/win32_v.h +++ b/src/video/win32_v.h @@ -17,6 +17,7 @@ #include "../3rdparty/mingw-std-threads/mingw.mutex.h" #include "../3rdparty/mingw-std-threads/mingw.condition_variable.h" #endif +#include /** Base class for Windows video drivers. */ class VideoDriver_Win32Base : public VideoDriver { diff --git a/src/viewport_sprite_sorter.h b/src/viewport_sprite_sorter.h index b3e7ea5945..a631543d07 100644 --- a/src/viewport_sprite_sorter.h +++ b/src/viewport_sprite_sorter.h @@ -7,13 +7,13 @@ /** @file viewport_sprite_sorter.h Types related to sprite sorting. */ -#include "stdafx.h" -#include "core/bitmath_func.hpp" -#include "gfx_type.h" - #ifndef VIEWPORT_SPRITE_SORTER_H #define VIEWPORT_SPRITE_SORTER_H +#include "core/bitmath_func.hpp" +#include "gfx_type.h" +#include + /** Parent sprite that should be drawn */ #ifdef _MSC_VER struct __declspec(align(16)) ParentSpriteToDraw { diff --git a/src/widgets/dropdown_type.h b/src/widgets/dropdown_type.h index 6b668efc27..87f3517048 100644 --- a/src/widgets/dropdown_type.h +++ b/src/widgets/dropdown_type.h @@ -13,6 +13,7 @@ #include "../window_type.h" #include "../gfx_func.h" #include "table/strings.h" +#include enum DropDownSyncFocus { DDSF_NONE = 0, diff --git a/src/window_gui.h b/src/window_gui.h index bb4eb11856..eadd59e17f 100644 --- a/src/window_gui.h +++ b/src/window_gui.h @@ -20,6 +20,7 @@ #include #include +#include /** * Flags to describe the look of the frame