Merge branch 'JGRennison:jgrpp' into jgrpp

This commit is contained in:
RoqueDeicide
2023-07-04 07:59:38 +04:00
committed by GitHub
82 changed files with 303 additions and 253 deletions

View File

@@ -1666,8 +1666,7 @@ constexpr auto encode_types() -> unsigned long long {
template <typename Context, typename T> template <typename Context, typename T>
FMT_CONSTEXPR FMT_INLINE auto make_value(T&& val) -> value<Context> { FMT_CONSTEXPR FMT_INLINE auto make_value(T&& val) -> value<Context> {
auto&& arg = arg_mapper<Context>().map(FMT_FORWARD(val)); using arg_type = remove_cvref_t<decltype(arg_mapper<Context>().map(val))>;
using arg_type = remove_cvref_t<decltype(arg)>;
constexpr bool formattable_char = constexpr bool formattable_char =
!std::is_same<arg_type, unformattable_char>::value; !std::is_same<arg_type, unformattable_char>::value;
@@ -1686,7 +1685,7 @@ FMT_CONSTEXPR FMT_INLINE auto make_value(T&& val) -> value<Context> {
formattable, formattable,
"Cannot format an argument. To make type T formattable provide a " "Cannot format an argument. To make type T formattable provide a "
"formatter<T> specialization: https://fmt.dev/latest/api.html#udt"); "formatter<T> specialization: https://fmt.dev/latest/api.html#udt");
return {arg}; return {arg_mapper<Context>().map(val)};
} }
template <typename Context, typename T> template <typename Context, typename T>

View File

@@ -238,6 +238,7 @@ add_files(
league_gui.cpp league_gui.cpp
league_type.h league_type.h
livery.h livery.h
load_check.h
main_gui.cpp main_gui.cpp
map.cpp map.cpp
map_func.h map_func.h

View File

@@ -17,6 +17,7 @@
#include "core/geometry_type.hpp" #include "core/geometry_type.hpp"
#include "core/tinystring_type.hpp" #include "core/tinystring_type.hpp"
#include <memory> #include <memory>
#include <vector>
typedef Pool<BaseStation, StationID, 32, 64000> StationPool; typedef Pool<BaseStation, StationID, 32, 64000> StationPool;
extern StationPool _station_pool; extern StationPool _station_pool;

View File

@@ -12,6 +12,9 @@
#include "core/enum_type.hpp" #include "core/enum_type.hpp"
#include <algorithm>
#include <array>
/** /**
* Cargo slots to indicate a cargo type within a game. * Cargo slots to indicate a cargo type within a game.
* Numbers are re-used between different climates. * Numbers are re-used between different climates.

View File

@@ -15,6 +15,7 @@
#include "string_type.h" #include "string_type.h"
#include "core/serialisation.hpp" #include "core/serialisation.hpp"
#include <optional> #include <optional>
#include <vector>
struct CommandDeserialisationBuffer : public BufferDeserialisationHelper<CommandDeserialisationBuffer> { struct CommandDeserialisationBuffer : public BufferDeserialisationHelper<CommandDeserialisationBuffer> {
const uint8 *buffer; const uint8 *buffer;

View File

@@ -2284,7 +2284,7 @@ DEF_CONSOLE_CMD(ConFont)
InitFontCache(fs == FS_MONO); InitFontCache(fs == FS_MONO);
fc = FontCache::Get(fs); 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; return true;

View File

@@ -11,6 +11,7 @@
#define POOL_TYPE_HPP #define POOL_TYPE_HPP
#include "enum_type.hpp" #include "enum_type.hpp"
#include <vector>
/** Various types of a pool. */ /** Various types of a pool. */
enum PoolType { enum PoolType {

View File

@@ -9,6 +9,7 @@
#ifndef SMALLSTACK_TYPE_HPP #ifndef SMALLSTACK_TYPE_HPP
#define SMALLSTACK_TYPE_HPP #define SMALLSTACK_TYPE_HPP
#include <vector>
/** /**
* A simplified pool which stores values instead of pointers and doesn't * A simplified pool which stores values instead of pointers and doesn't

View File

@@ -273,7 +273,7 @@ char *CrashLog::LogConfiguration(char *buffer, const char *last) const
auto log_font = [&](FontSize fs) -> const char * { auto log_font = [&](FontSize fs) -> const char * {
FontCache *fc = FontCache::Get(fs); FontCache *fc = FontCache::Get(fs);
if (fc != nullptr) { if (fc != nullptr) {
return fc->GetFontName(); return fc->GetFontName().c_str();
} else { } else {
return "[NULL]"; return "[NULL]";
} }

View File

@@ -15,6 +15,7 @@
#include "station_base.h" #include "station_base.h"
#include "order_base.h" #include "order_base.h"
#include "vehicle_base.h" #include "vehicle_base.h"
#include <vector>
/** Whether or not a vehicle has arrived for a departure. */ /** Whether or not a vehicle has arrived for a departure. */
typedef enum { typedef enum {

View File

@@ -17,6 +17,7 @@
#include "newgrf_commons.h" #include "newgrf_commons.h"
#include "3rdparty/cpp-btree/btree_map.h" #include "3rdparty/cpp-btree/btree_map.h"
#include <vector>
struct WagonOverride { struct WagonOverride {
std::vector<EngineID> engines; std::vector<EngineID> engines;

View File

@@ -14,6 +14,7 @@
#include "company_base.h" #include "company_base.h"
#include "newgrf_config.h" #include "newgrf_config.h"
#include "network/core/tcp_content_type.h" #include "network/core/tcp_content_type.h"
#include <vector>
/** Special values for save-load window for the data parameter of #InvalidateWindowData. */ /** 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) SLIWD_FILTER_CHANGES, ///< The filename filter has changed (via the editbox)
}; };
using CompanyPropertiesMap = std::map<uint, std::unique_ptr<CompanyProperties>>;
/**
* 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 */ /** Deals with finding savegames */
struct FiosItem { struct FiosItem {
FiosType type; FiosType type;

View File

@@ -8,6 +8,7 @@
/** @file fios_gui.cpp GUIs for loading/saving games, scenarios, heightmaps, ... */ /** @file fios_gui.cpp GUIs for loading/saving games, scenarios, heightmaps, ... */
#include "stdafx.h" #include "stdafx.h"
#include "load_check.h"
#include "sl/saveload.h" #include "sl/saveload.h"
#include "error.h" #include "error.h"
#include "gui.h" #include "gui.h"
@@ -57,9 +58,7 @@ void LoadCheckData::Clear()
companies.clear(); companies.clear();
GamelogFree(this->gamelog_action, this->gamelog_actions); GamelogFree(this->gamelog_actions);
this->gamelog_action = nullptr;
this->gamelog_actions = 0;
ClearGRFConfigList(&this->grfconfig); ClearGRFConfigList(&this->grfconfig);
@@ -790,7 +789,7 @@ public:
ShowQuery(STR_SAVELOAD_OVERWRITE_TITLE_DIFFERENT_ID, STR_SAVELOAD_OVERWRITE_WARNING_DIFFERENT_ID, this, SaveLoadWindow::SaveGameConfirmationCallback); 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) { } 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) { 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); SetDParam(0, STR_SAVELOAD_OVERWRITE_TITLE);
std::string caption = GetString(STR_SAVELOAD_OVERWRITE_TITLE_DIFFERENT_VERSION_SUFFIX); std::string caption = GetString(STR_SAVELOAD_OVERWRITE_TITLE_DIFFERENT_VERSION_SUFFIX);

View File

@@ -138,7 +138,7 @@ public:
* Get the name of this font. * Get the name of this font.
* @return The name of the 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. * Get the font cache of a given font size.

View File

@@ -15,6 +15,7 @@
#include "../core/math_func.hpp" #include "../core/math_func.hpp"
#include "../zoom_func.h" #include "../zoom_func.h"
#include "../fileio_func.h" #include "../fileio_func.h"
#include "../string_func.h"
#include "truetypefontcache.h" #include "truetypefontcache.h"
#include "../table/control_codes.h" #include "../table/control_codes.h"
@@ -41,7 +42,7 @@ public:
~FreeTypeFontCache(); ~FreeTypeFontCache();
void ClearFontCache() override; void ClearFontCache() override;
GlyphID MapCharToGlyph(WChar key) 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; } bool IsBuiltInFont() override { return false; }
const void *GetOSHandle() override { return &face; } const void *GetOSHandle() override { return &face; }
}; };

View File

@@ -31,7 +31,7 @@ public:
virtual bool GetDrawGlyphShadow(); virtual bool GetDrawGlyphShadow();
virtual GlyphID MapCharToGlyph(WChar key) { assert(IsPrintable(key)); return SPRITE_GLYPH | key; } 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 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; } virtual bool IsBuiltInFont() { return true; }
}; };

View File

@@ -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 static GamelogActionType _gamelog_action_type = GLAT_NONE; ///< action to record if anything changes
LoggedAction *_gamelog_action = nullptr; ///< first logged action std::vector<LoggedAction> _gamelog_actions; ///< logged actions
uint _gamelog_actions = 0; ///< number of actions
static LoggedAction *_current_action = nullptr; ///< current action we are logging, nullptr when there is no action active 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 * Frees the memory allocated by a gamelog
*/ */
void GamelogFree(LoggedAction *gamelog_action, uint gamelog_actions) void GamelogFree(std::vector<LoggedAction> &gamelog_actions)
{ {
for (uint i = 0; i < gamelog_actions; i++) { for (LoggedAction &la : gamelog_actions) {
const LoggedAction *la = &gamelog_action[i]; for (LoggedChange &lc : la.changes) {
for (uint j = 0; j < la->changes; j++) { if (lc.ct == GLCT_SETTING) free(lc.setting.name);
const LoggedChange *lc = &la->change[j]; if (lc.ct == GLCT_REVISION) free(lc.revision.text);
if (lc->ct == GLCT_SETTING) free(lc->setting.name); lc.ct = GLCT_NONE;
if (lc->ct == GLCT_REVISION) free(lc->revision.text);
} }
free(la->change);
} }
free(gamelog_action); gamelog_actions.clear();
} }
/** /**
@@ -93,10 +90,7 @@ void GamelogFree(LoggedAction *gamelog_action, uint gamelog_actions)
void GamelogReset() void GamelogReset()
{ {
assert(_gamelog_action_type == GLAT_NONE); assert(_gamelog_action_type == GLAT_NONE);
GamelogFree(_gamelog_action, _gamelog_actions); GamelogFree(_gamelog_actions);
_gamelog_action = nullptr;
_gamelog_actions = 0;
_current_action = nullptr; _current_action = nullptr;
} }
@@ -174,17 +168,14 @@ void GamelogPrint(GamelogPrintProc *proc)
proc("---- gamelog start ----"); 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++) { seprintf(buffer, lastof(buffer), "Tick %u: %s", (uint)la.tick, la_text[(uint)la.at]);
assert((uint)la->at < GLAT_END);
seprintf(buffer, lastof(buffer), "Tick %u: %s", (uint)la->tick, la_text[(uint)la->at]);
proc(buffer); proc(buffer);
const LoggedChange *lcend = &la->change[la->changes]; for (const LoggedChange &lchange : la.changes) {
const LoggedChange *lc = &lchange;
for (const LoggedChange *lc = la->change; lc != lcend; lc++) {
char *buf = buffer; char *buf = buffer;
switch (lc->ct) { switch (lc->ct) {
@@ -259,12 +250,12 @@ void GamelogPrint(GamelogPrintProc *proc)
case GLCT_GRFREM: { case GLCT_GRFREM: {
/* A NewGRF got removed from the game, either manually or by it missing when loading the game. */ /* 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); 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); buf = PrintGrfInfo(buf, lastof(buffer), lc->grfrem.grfid, nullptr, gm != grf_names.end() ? gm->second.gc : nullptr);
if (gm == grf_names.end()) { if (gm == grf_names.end()) {
buf += seprintf(buf, lastof(buffer), ". Gamelog inconsistency: GrfID was never added!"); buf += seprintf(buf, lastof(buffer), ". Gamelog inconsistency: GrfID was never added!");
} else { } else {
if (la->at == GLAT_LOAD) { if (la.at == GLAT_LOAD) {
/* Missing grfs on load are not removed from the configuration */ /* Missing grfs on load are not removed from the configuration */
gm->second.was_missing = true; gm->second.was_missing = true;
} else { } else {
@@ -371,18 +362,14 @@ static LoggedChange *GamelogChange(GamelogChangeType ct)
if (_current_action == nullptr) { if (_current_action == nullptr) {
if (_gamelog_action_type == GLAT_NONE) return nullptr; if (_gamelog_action_type == GLAT_NONE) return nullptr;
_gamelog_action = ReallocT(_gamelog_action, _gamelog_actions + 1); _current_action = &_gamelog_actions.emplace_back();
_current_action = &_gamelog_action[_gamelog_actions++];
_current_action->at = _gamelog_action_type; _current_action->at = _gamelog_action_type;
_current_action->tick = _tick_counter; _current_action->tick = _tick_counter;
_current_action->change = nullptr;
_current_action->changes = 0;
} }
_current_action->change = ReallocT(_current_action->change, _current_action->changes + 1); _current_action->changes.push_back({});
LoggedChange *lc = &_current_action->changes.back();
LoggedChange *lc = &_current_action->change[_current_action->changes++];
lc->ct = ct; lc->ct = ct;
return lc; return lc;
@@ -406,17 +393,13 @@ void GamelogEmergency()
*/ */
bool GamelogTestEmergency() bool GamelogTestEmergency()
{ {
const LoggedChange *emergency = nullptr; for (LoggedAction &la : _gamelog_actions) {
for (LoggedChange &lc : la.changes) {
const LoggedAction *laend = &_gamelog_action[_gamelog_actions]; if (lc.ct == GLCT_EMERGENCY) return true;
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;
} }
} }
return (emergency != nullptr); return false;
} }
/** /**
@@ -490,11 +473,9 @@ void GamelogTestRevision()
{ {
const LoggedChange *rev = nullptr; const LoggedChange *rev = nullptr;
const LoggedAction *laend = &_gamelog_action[_gamelog_actions]; for (LoggedAction &la : _gamelog_actions) {
for (const LoggedAction *la = _gamelog_action; la != laend; la++) { for (LoggedChange &lc : la.changes) {
const LoggedChange *lcend = &la->change[la->changes]; if (lc.ct == GLCT_REVISION) rev = &lc;
for (const LoggedChange *lc = la->change; lc != lcend; lc++) {
if (lc->ct == GLCT_REVISION) rev = lc;
} }
} }
@@ -513,11 +494,9 @@ void GamelogTestMode()
{ {
const LoggedChange *mode = nullptr; const LoggedChange *mode = nullptr;
const LoggedAction *laend = &_gamelog_action[_gamelog_actions]; for (LoggedAction &la : _gamelog_actions) {
for (const LoggedAction *la = _gamelog_action; la != laend; la++) { for (LoggedChange &lc : la.changes) {
const LoggedChange *lcend = &la->change[la->changes]; if (lc.ct == GLCT_MODE) mode = &lc;
for (const LoggedChange *lc = la->change; lc != lcend; lc++) {
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) bool GamelogGRFBugReverse(uint32 grfid, uint16 internal_id)
{ {
const LoggedAction *laend = &_gamelog_action[_gamelog_actions]; for (LoggedAction &la : _gamelog_actions) {
for (const LoggedAction *la = _gamelog_action; la != laend; la++) { for (LoggedChange &lc : la.changes) {
const LoggedChange *lcend = &la->change[la->changes]; if (lc.ct == GLCT_GRFBUG && lc.grfbug.grfid == grfid &&
for (const LoggedChange *lc = la->change; lc != lcend; lc++) { lc.grfbug.bug == GBUG_VEH_LENGTH && lc.grfbug.data == internal_id) {
if (lc->ct == GLCT_GRFBUG && lc->grfbug.grfid == grfid &&
lc->grfbug.bug == GBUG_VEH_LENGTH && lc->grfbug.data == internal_id) {
return false; 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] 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. * @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<LoggedAction> &gamelog_actions, uint32 *last_ottd_rev, byte *ever_modified, bool *removed_newgrfs)
{ {
const LoggedAction *laend = &gamelog_action[gamelog_actions]; for (const LoggedAction &la : gamelog_actions) {
for (const LoggedAction *la = gamelog_action; la != laend; la++) { for (const LoggedChange &lc : la.changes) {
const LoggedChange *lcend = &la->change[la->changes]; switch (lc.ct) {
for (const LoggedChange *lc = la->change; lc != lcend; lc++) {
switch (lc->ct) {
default: break; default: break;
case GLCT_REVISION: case GLCT_REVISION:
*last_ottd_rev = lc->revision.newgrf; *last_ottd_rev = lc.revision.newgrf;
*ever_modified = std::max(*ever_modified, lc->revision.modified); *ever_modified = std::max(*ever_modified, lc.revision.modified);
break; break;
case GLCT_GRFREM: 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<LoggedAction> &gamelog_actions)
{ {
for (uint i = gamelog_actions; i > 0; i--) { for (size_t i = gamelog_actions.size(); i > 0; i--) {
const LoggedAction &la = gamelog_action[i - 1]; const LoggedAction &la = gamelog_actions[i - 1];
const LoggedChange *lcend = &(la.change[la.changes]); for (const LoggedChange &lc : la.changes) {
for (const LoggedChange *lc = la.change; lc != lcend; lc++) { switch (lc.ct) {
switch (lc->ct) {
case GLCT_REVISION: case GLCT_REVISION:
return lc->revision.text; return lc.revision.text;
break; break;
default: default:

View File

@@ -11,6 +11,9 @@
#define GAMELOG_H #define GAMELOG_H
#include "newgrf_config.h" #include "newgrf_config.h"
#include <vector>
struct LoggedAction;
/** The actions we log. */ /** The actions we log. */
enum GamelogActionType : uint8 { enum GamelogActionType : uint8 {
@@ -29,7 +32,7 @@ void GamelogStartAction(GamelogActionType at);
void GamelogStopAction(); void GamelogStopAction();
void GamelogStopAnyAction(); void GamelogStopAnyAction();
void GamelogFree(struct LoggedAction *gamelog_action, uint gamelog_actions); void GamelogFree(std::vector<LoggedAction> &gamelog_actions);
void GamelogReset(); void GamelogReset();
/** /**
@@ -61,7 +64,7 @@ void GamelogTestMode();
bool GamelogGRFBugReverse(uint32 grfid, uint16 internal_id); 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); void GamelogInfo(const std::vector<LoggedAction> &gamelog_actions, uint32 *last_ottd_rev, byte *ever_modified, bool *removed_newgrfs);
const char *GamelogGetLastRevision(const struct LoggedAction *gamelog_action, uint gamelog_actions); const char *GamelogGetLastRevision(const std::vector<LoggedAction> &gamelog_actions);
#endif /* GAMELOG_H */ #endif /* GAMELOG_H */

View File

@@ -12,6 +12,8 @@
#include "gamelog.h" #include "gamelog.h"
#include <vector>
/** Type of logged change */ /** Type of logged change */
enum GamelogChangeType { enum GamelogChangeType {
GLCT_MODE, ///< Scenario editor x Game, different landscape 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 */ /** Contains information about one logged action that caused at least one logged change */
struct LoggedAction { struct LoggedAction {
LoggedChange *change; ///< First logged change in this action std::vector<LoggedChange> changes; ///< Changes in this action
uint32 changes; ///< Number of changes in this action
GamelogActionType at; ///< Type of action GamelogActionType at; ///< Type of action
uint64 tick; ///< Tick when it happened uint64 tick; ///< Tick when it happened
}; };
extern LoggedAction *_gamelog_action; extern std::vector<LoggedAction> _gamelog_actions;
extern uint _gamelog_actions;
#endif /* GAMELOG_INTERNAL_H */ #endif /* GAMELOG_INTERNAL_H */

View File

@@ -42,6 +42,7 @@
#include "gfx_type.h" #include "gfx_type.h"
#include "strings_type.h" #include "strings_type.h"
#include "string_type.h" #include "string_type.h"
#include <vector>
void GameLoop(); void GameLoop();

View File

@@ -64,8 +64,8 @@ static inline void GetLayouter(Layouter::LineCacheItem &line, std::string_view s
{ {
if (line.buffer != nullptr) free(line.buffer); if (line.buffer != nullptr) free(line.buffer);
typename T::CharType *buff_begin = MallocT<typename T::CharType>(DRAW_STRING_BUFFER); typename T::CharType *buff_begin = MallocT<typename T::CharType>(str.size() + 1);
const typename T::CharType *buffer_last = buff_begin + DRAW_STRING_BUFFER; const typename T::CharType *buffer_last = buff_begin + str.size() + 1;
typename T::CharType *buff = buff_begin; typename T::CharType *buff = buff_begin;
FontMap &fontMapping = line.runs; FontMap &fontMapping = line.runs;
Font *f = Layouter::GetFont(state.fontsize, state.cur_colour); Font *f = Layouter::GetFont(state.fontsize, state.cur_colour);
@@ -206,6 +206,19 @@ Dimension Layouter::GetBounds()
return d; 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. * 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. * @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(); auto str = this->string.begin();
while (str < ch) { while (str < ch) {
WChar c = Utf8Consume(str); WChar c = Utf8Consume(str);
index += line->GetInternalCharLength(c); if (!IsConsumedFormattingCode(c)) index += line->GetInternalCharLength(c);
} }
/* We couldn't find the code point index. */ /* 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. * @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 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 index = run.GetGlyphToCharMap()[i];
size_t cur_idx = 0; size_t cur_idx = 0;
int char_index = 0; for (auto str = this->string.begin(); str != this->string.end();) {
for (auto str = this->string.begin(); str != this->string.end(); char_index++) { if (cur_idx == index) return str - this->string.begin();
if (cur_idx == index) return char_index;
WChar c = Utf8Consume(str); WChar c = Utf8Consume(str);
cur_idx += line->GetInternalCharLength(c); if (!IsConsumedFormattingCode(c)) cur_idx += line->GetInternalCharLength(c);
} }
} }
} }

View File

@@ -12,6 +12,7 @@
#include "core/geometry_type.hpp" #include "core/geometry_type.hpp"
#include "tile_cmd.h" #include "tile_cmd.h"
#include <vector>
static const uint SNOW_LINE_MONTHS = 12; ///< Number of months in the snow line table. 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. static const uint SNOW_LINE_DAYS = 32; ///< Number of days in each month in the snow line table.

View File

@@ -14,6 +14,7 @@
#include <unicode/coll.h> #include <unicode/coll.h>
#endif /* WITH_ICU_I18N */ #endif /* WITH_ICU_I18N */
#include "strings_type.h" #include "strings_type.h"
#include <vector>
static const uint8 CASE_GENDER_LEN = 16; ///< The (maximum) length of a case/gender string. 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. static const uint8 MAX_NUM_GENDERS = 8; ///< Maximum number of supported genders.

View File

@@ -4,6 +4,7 @@
#define DEMANDS_H #define DEMANDS_H
#include "linkgraphjob_base.h" #include "linkgraphjob_base.h"
#include <vector>
/** /**
* Calculate the demands. This class has a state, but is recreated for each * Calculate the demands. This class has a state, but is recreated for each

View File

@@ -19,6 +19,7 @@
#include "linkgraph_type.h" #include "linkgraph_type.h"
#include "../3rdparty/cpp-btree/btree_map.h" #include "../3rdparty/cpp-btree/btree_map.h"
#include <utility> #include <utility>
#include <vector>
class LinkGraph; class LinkGraph;

View File

@@ -13,6 +13,7 @@
#include "../thread.h" #include "../thread.h"
#include "linkgraph.h" #include "linkgraph.h"
#include <memory> #include <memory>
#include <vector>
class LinkGraphJob; class LinkGraphJob;

89
src/load_check.h Normal file
View File

@@ -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 <http://www.gnu.org/licenses/>.
*/
/** @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 <memory>
#include <string>
#include <vector>
using CompanyPropertiesMap = btree::btree_map<uint, std::unique_ptr<CompanyProperties>>;
/**
* 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<LoggedAction> 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 */

View File

@@ -17,6 +17,7 @@
#include <map> #include <map>
#include <string> #include <string>
#include <vector>
class NetworkAddress; class NetworkAddress;
typedef std::vector<NetworkAddress> NetworkAddressList; ///< Type for a list of addresses. typedef std::vector<NetworkAddress> NetworkAddressList; ///< Type for a list of addresses.

View File

@@ -20,6 +20,7 @@
#include <string> #include <string>
#include <functional> #include <functional>
#include <limits> #include <limits>
#include <vector>
typedef uint16 PacketSize; ///< Size of the whole packet. typedef uint16 PacketSize; ///< Size of the whole packet.
typedef uint8 PacketType; ///< Identifier for the packet typedef uint8 PacketType; ///< Identifier for the packet

View File

@@ -20,6 +20,7 @@
#include <deque> #include <deque>
#include <map> #include <map>
#include <memory> #include <memory>
#include <vector>
#include <thread> #include <thread>
#if defined(__MINGW32__) #if defined(__MINGW32__)
#include "3rdparty/mingw-std-threads/mingw.thread.h" #include "3rdparty/mingw-std-threads/mingw.thread.h"

View File

@@ -13,6 +13,7 @@
#define NETWORK_CORE_TCP_CONTENT_TYPE_H #define NETWORK_CORE_TCP_CONTENT_TYPE_H
#include "../../3rdparty/md5/md5.h" #include "../../3rdparty/md5/md5.h"
#include <vector>
/** The values in the enum are important; they are used as database 'keys' */ /** The values in the enum are important; they are used as database 'keys' */
enum ContentType { enum ContentType {

View File

@@ -14,6 +14,7 @@
#include "core/http.h" #include "core/http.h"
#include "../core/container_func.hpp" #include "../core/container_func.hpp"
#include "../3rdparty/cpp-btree/btree_map.h" #include "../3rdparty/cpp-btree/btree_map.h"
#include <vector>
/** Vector with content info */ /** Vector with content info */
typedef std::vector<ContentInfo *> ContentVector; typedef std::vector<ContentInfo *> ContentVector;

View File

@@ -11,6 +11,7 @@
#define NETWORK_QUERY_H #define NETWORK_QUERY_H
#include "network_internal.h" #include "network_internal.h"
#include <vector>
/** Class for handling the client side of quering a game server. */ /** Class for handling the client side of quering a game server. */
class QueryNetworkGameSocketHandler : public ZeroedMemoryAllocator, public NetworkGameSocketHandler { class QueryNetworkGameSocketHandler : public ZeroedMemoryAllocator, public NetworkGameSocketHandler {

View File

@@ -12,6 +12,10 @@
#include <condition_variable> #include <condition_variable>
#include <mutex> #include <mutex>
#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" #include "core/http.h"
/** /**

View File

@@ -20,6 +20,7 @@
#include "core/mem_func.hpp" #include "core/mem_func.hpp"
#include "3rdparty/cpp-btree/btree_map.h" #include "3rdparty/cpp-btree/btree_map.h"
#include <bitset> #include <bitset>
#include <vector>
/** /**
* List of different canal 'features'. * List of different canal 'features'.

View File

@@ -18,6 +18,7 @@
#include "command_type.h" #include "command_type.h"
#include "direction_type.h" #include "direction_type.h"
#include "company_type.h" #include "company_type.h"
#include <vector>
/** Context for tile accesses */ /** Context for tile accesses */
enum TileContext : uint8 { enum TileContext : uint8 {

View File

@@ -18,6 +18,8 @@
#include "newgrf_text.h" #include "newgrf_text.h"
#include "3rdparty/md5/md5.h" #include "3rdparty/md5/md5.h"
#include <map> #include <map>
#include <vector>
#include <optional>
static const uint MAX_NON_STATIC_GRF_COUNT = 256; static const uint MAX_NON_STATIC_GRF_COUNT = 256;

View File

@@ -13,6 +13,7 @@
#include "newgrf.h" #include "newgrf.h"
#include "tile_type.h" #include "tile_type.h"
#include "vehicle_type.h" #include "vehicle_type.h"
#include <vector>
/** Current state of spritepicker */ /** Current state of spritepicker */
enum NewGrfDebugSpritePickerMode { enum NewGrfDebugSpritePickerMode {

View File

@@ -19,6 +19,7 @@
#include "3rdparty/cpp-btree/btree_map.h" #include "3rdparty/cpp-btree/btree_map.h"
#include <bitset> #include <bitset>
#include <vector>
/** Base GRF ID for OpenTTD's base graphics GRFs. */ /** Base GRF ID for OpenTTD's base graphics GRFs. */
static const uint32 OPENTTD_GRAPHICS_BASE_GRF_ID = BSWAP32(0xFF4F5400); static const uint32 OPENTTD_GRAPHICS_BASE_GRF_ID = BSWAP32(0xFF4F5400);

View File

@@ -12,6 +12,7 @@
#include "newgrf_commons.h" #include "newgrf_commons.h"
#include "newgrf_spritegroup.h" #include "newgrf_spritegroup.h"
#include <vector>
extern std::vector<const GRFFile *> _new_landscape_rocks_grfs; extern std::vector<const GRFFile *> _new_landscape_rocks_grfs;

View File

@@ -19,6 +19,7 @@
#include "newgrf_animation_type.h" #include "newgrf_animation_type.h"
#include "newgrf_class.h" #include "newgrf_class.h"
#include "newgrf_commons.h" #include "newgrf_commons.h"
#include <vector>
/** Various object behaviours. */ /** Various object behaviours. */
enum ObjectFlags : uint16 { enum ObjectFlags : uint16 {

View File

@@ -23,6 +23,7 @@
#include "3rdparty/cpp-btree/btree_set.h" #include "3rdparty/cpp-btree/btree_set.h"
#include <map> #include <map>
#include <vector>
/** /**
* Gets the value of a so-called newgrf "register". * Gets the value of a so-called newgrf "register".

View File

@@ -19,6 +19,7 @@
#include "rail_type.h" #include "rail_type.h"
#include "newgrf_spritegroup.h" #include "newgrf_spritegroup.h"
#include "newgrf_town.h" #include "newgrf_town.h"
#include <vector>
/** Scope resolver for stations. */ /** Scope resolver for stations. */
struct StationScopeResolver : public ScopeResolver { struct StationScopeResolver : public ScopeResolver {

View File

@@ -15,6 +15,7 @@
#include "tilearea_type.h" #include "tilearea_type.h"
#include "town_type.h" #include "town_type.h"
#include "date_type.h" #include "date_type.h"
#include <vector>
typedef Pool<Object, ObjectID, 64, 0xFF0000> ObjectPool; typedef Pool<Object, ObjectID, 64, 0xFF0000> ObjectPool;
extern ObjectPool _object_pool; extern ObjectPool _object_pool;

View File

@@ -25,6 +25,7 @@
#include "command_func.h" #include "command_func.h"
#include "news_func.h" #include "news_func.h"
#include "fios.h" #include "fios.h"
#include "load_check.h"
#include "aircraft.h" #include "aircraft.h"
#include "roadveh.h" #include "roadveh.h"
#include "train.h" #include "train.h"
@@ -328,7 +329,7 @@ static void WriteSavegameInfo(const char *name)
byte ever_modified = 0; byte ever_modified = 0;
bool removed_newgrfs = false; 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 buf[65536];
char *p = buf; char *p = buf;

View File

@@ -17,6 +17,7 @@
#include "base_consist.h" #include "base_consist.h"
#include "order_base.h" #include "order_base.h"
#include "sl/saveload_common.h" #include "sl/saveload_common.h"
#include <vector>
/** Unique identifier for an order backup. */ /** Unique identifier for an order backup. */
typedef uint8 OrderBackupID; typedef uint8 OrderBackupID;

View File

@@ -30,7 +30,7 @@ public:
void ClearFontCache() override; void ClearFontCache() override;
GlyphID MapCharToGlyph(WChar key) 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; } bool IsBuiltInFont() override { return false; }
const void *GetOSHandle() override { return font.get(); } const void *GetOSHandle() override { return font.get(); }
}; };

View File

@@ -180,7 +180,7 @@ static CTRunDelegateCallbacks _sprite_font_callback = {
if (font == nullptr) { if (font == nullptr) {
if (!_font_cache[i.second->fc->GetSize()]) { if (!_font_cache[i.second->fc->GetSize()]) {
/* Cache font information. */ /* Cache font information. */
CFAutoRelease<CFStringRef> font_name(CFStringCreateWithCString(kCFAllocatorDefault, i.second->fc->GetFontName(), kCFStringEncodingUTF8)); CFAutoRelease<CFStringRef> 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_cache[i.second->fc->GetSize()].reset(CTFontCreateWithName(font_name.get(), i.second->fc->GetFontSize(), nullptr));
} }
font = _font_cache[i.second->fc->GetSize()].get(); font = _font_cache[i.second->fc->GetSize()].get();

View File

@@ -34,7 +34,7 @@ public:
~Win32FontCache(); ~Win32FontCache();
void ClearFontCache() override; void ClearFontCache() override;
GlyphID MapCharToGlyph(WChar key) 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; } const void *GetOSHandle() override { return &this->logfont; }
}; };

View File

@@ -13,6 +13,7 @@
#include "tracerestrict.h" #include "tracerestrict.h"
#include "core/container_func.hpp" #include "core/container_func.hpp"
#include <map> #include <map>
#include <vector>
/** @defgroup progsigs Programmable Pre-Signals */ /** @defgroup progsigs Programmable Pre-Signals */
///@{ ///@{

View File

@@ -21,6 +21,7 @@
#include "signal_type.h" #include "signal_type.h"
#include "rail_map.h" #include "rail_map.h"
#include "settings_type.h" #include "settings_type.h"
#include <vector>
/** Railtype flags. */ /** Railtype flags. */
enum RailTypeFlags { enum RailTypeFlags {

View File

@@ -389,12 +389,11 @@ static void ResetSignalHandlers()
*/ */
static const GRFIdentifier *GetOverriddenIdentifier(const GRFConfig *c) static const GRFIdentifier *GetOverriddenIdentifier(const GRFConfig *c)
{ {
const LoggedAction *la = &_gamelog_action[_gamelog_actions - 1]; const LoggedAction &la = _gamelog_actions.back();
if (la->at != GLAT_LOAD) return &c->ident; if (la.at != GLAT_LOAD) return &c->ident;
const LoggedChange *lcend = &la->change[la->changes]; for (const LoggedChange &lc : 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;
if (lc->ct == GLCT_GRFCOMPAT && lc->grfcompat.grfid == c->ident.grfid) return &lc->grfcompat;
} }
return &c->ident; return &c->ident;

View File

@@ -15,6 +15,7 @@
#include "../company_func.h" #include "../company_func.h"
#include "../company_manager_face.h" #include "../company_manager_face.h"
#include "../fios.h" #include "../fios.h"
#include "../load_check.h"
#include "../tunnelbridge_map.h" #include "../tunnelbridge_map.h"
#include "../tunnelbridge.h" #include "../tunnelbridge.h"
#include "../station_base.h" #include "../station_base.h"

View File

@@ -14,6 +14,7 @@
#include "../gamelog_internal.h" #include "../gamelog_internal.h"
#include "../fios.h" #include "../fios.h"
#include "../load_check.h"
#include "../string_func.h" #include "../string_func.h"
#include "../safeguards.h" #include "../safeguards.h"
@@ -309,27 +310,26 @@ public:
void Save(LoggedAction *la) const override void Save(LoggedAction *la) const override
{ {
SlSetStructListLength(la->changes); SlSetStructListLength(la->changes.size());
const LoggedChange *lcend = &la->change[la->changes]; for (LoggedChange &lc : la->changes) {
for (LoggedChange *lc = la->change; lc != lcend; lc++) { assert((uint)lc.ct < GLCT_END);
assert((uint)lc->ct < GLCT_END); SlObject(&lc, this->GetDescription());
SlObject(lc, this->GetDescription());
} }
} }
void Load(LoggedAction *la) const override void Load(LoggedAction *la) const override
{ {
la->changes.clear();
if (IsSavegameVersionBefore(SLV_RIFF_TO_ARRAY)) { if (IsSavegameVersionBefore(SLV_RIFF_TO_ARRAY)) {
byte type; byte type;
while ((type = SlReadByte()) != GLCT_NONE) { while ((type = SlReadByte()) != GLCT_NONE) {
if (type >= GLCT_END) SlErrorCorrupt("Invalid gamelog change type"); if (type >= GLCT_END) SlErrorCorrupt("Invalid gamelog change type");
GamelogChangeType ct = (GamelogChangeType)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++];
*lc = LoggedChange{};
lc->ct = ct; lc->ct = ct;
SlObject(lc, this->GetLoadDescription()); SlObject(lc, this->GetLoadDescription());
@@ -338,12 +338,11 @@ public:
} }
size_t length = SlGetStructListLength(UINT32_MAX); size_t length = SlGetStructListLength(UINT32_MAX);
la->change = ReallocT(la->change, length); la->changes.reserve(length);
la->changes = (uint32)length;
for (size_t i = 0; i < length; i++) { for (size_t i = 0; i < length; i++) {
LoggedChange *lc = &la->change[i]; la->changes.push_back({});
*lc = LoggedChange{}; LoggedChange *lc = &la->changes.back();
lc->ct = (GamelogChangeType)SlReadByte(); lc->ct = (GamelogChangeType)SlReadByte();
SlObject(lc, this->GetLoadDescription()); SlObject(lc, this->GetLoadDescription());
@@ -363,10 +362,9 @@ static const SaveLoad _gamelog_desc[] = {
struct GLOGChunkHandler : ChunkHandler { struct GLOGChunkHandler : ChunkHandler {
GLOGChunkHandler() : ChunkHandler('GLOG', CH_TABLE) {} GLOGChunkHandler() : ChunkHandler('GLOG', CH_TABLE) {}
void LoadCommon(LoggedAction *&gamelog_action, uint &gamelog_actions) const void LoadCommon(std::vector<LoggedAction> &gamelog_actions) const
{ {
assert(gamelog_action == nullptr); assert(gamelog_actions.empty());
assert(gamelog_actions == 0);
const std::vector<SaveLoad> slt = SlCompatTableHeader(_gamelog_desc, _gamelog_sl_compat); const std::vector<SaveLoad> slt = SlCompatTableHeader(_gamelog_desc, _gamelog_sl_compat);
@@ -375,22 +373,18 @@ struct GLOGChunkHandler : ChunkHandler {
while ((type = SlReadByte()) != GLAT_NONE) { while ((type = SlReadByte()) != GLAT_NONE) {
if (type >= GLAT_END) SlErrorCorrupt("Invalid gamelog action type"); if (type >= GLAT_END) SlErrorCorrupt("Invalid gamelog action type");
gamelog_action = ReallocT(gamelog_action, gamelog_actions + 1); LoggedAction &la = gamelog_actions.emplace_back();
LoggedAction *la = &gamelog_action[gamelog_actions++];
*la = LoggedAction{};
la->at = (GamelogActionType)type; la.at = (GamelogActionType)type;
SlObject(la, slt); SlObject(&la, slt);
} }
return; return;
} }
while (SlIterateArray() != -1) { while (SlIterateArray() != -1) {
gamelog_action = ReallocT(gamelog_action, gamelog_actions + 1); LoggedAction &la = gamelog_actions.emplace_back();
LoggedAction *la = &gamelog_action[gamelog_actions++];
*la = LoggedAction{};
SlObject(la, slt); SlObject(&la, slt);
} }
} }
@@ -398,23 +392,22 @@ struct GLOGChunkHandler : ChunkHandler {
{ {
SlTableHeader(_gamelog_desc); SlTableHeader(_gamelog_desc);
const LoggedAction *laend = &_gamelog_action[_gamelog_actions];
uint i = 0; uint i = 0;
for (LoggedAction *la = _gamelog_action; la != laend; la++, i++) { for (LoggedAction &la : _gamelog_actions) {
SlSetArrayIndex(i); SlSetArrayIndex(i);
SlObject(la, _gamelog_desc); SlObject(&la, _gamelog_desc);
i++;
} }
} }
void Load() const override void Load() const override
{ {
this->LoadCommon(_gamelog_action, _gamelog_actions); this->LoadCommon(_gamelog_actions);
} }
void LoadCheck(size_t) const override 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);
} }
}; };

View File

@@ -15,6 +15,7 @@
#include "../map_func.h" #include "../map_func.h"
#include "../core/bitmath_func.hpp" #include "../core/bitmath_func.hpp"
#include "../fios.h" #include "../fios.h"
#include "../load_check.h"
#include <array> #include <array>
#include "../safeguards.h" #include "../safeguards.h"

View File

@@ -20,6 +20,7 @@
#include "../gfx_func.h" #include "../gfx_func.h"
#include "../core/random_func.hpp" #include "../core/random_func.hpp"
#include "../fios.h" #include "../fios.h"
#include "../load_check.h"
#include "../timer/timer.h" #include "../timer/timer.h"
#include "../timer/timer_game_tick.h" #include "../timer/timer_game_tick.h"

View File

@@ -14,6 +14,7 @@
#include "newgrf_sl.h" #include "newgrf_sl.h"
#include "../fios.h" #include "../fios.h"
#include "../load_check.h"
#include "../safeguards.h" #include "../safeguards.h"

View File

@@ -17,6 +17,7 @@
#include "../settings_internal.h" #include "../settings_internal.h"
#include "../network/network.h" #include "../network/network.h"
#include "../fios.h" #include "../fios.h"
#include "../load_check.h"
#include "../safeguards.h" #include "../safeguards.h"

View File

@@ -66,6 +66,7 @@
#include "smallmap_gui.h" #include "smallmap_gui.h"
#include "roadveh.h" #include "roadveh.h"
#include "fios.h" #include "fios.h"
#include "load_check.h"
#include "strings_func.h" #include "strings_func.h"
#include "string_func.h" #include "string_func.h"
#include "debug.h" #include "debug.h"

View File

@@ -13,6 +13,7 @@
#include "sl/saveload_types.h" #include "sl/saveload_types.h"
#include <functional> #include <functional>
#include <vector>
enum SettingFlag : uint32 { enum SettingFlag : uint32 {
SF_NONE = 0, SF_NONE = 0,

View File

@@ -11,6 +11,7 @@
#include "../company_func.h" #include "../company_func.h"
#include "../company_manager_face.h" #include "../company_manager_face.h"
#include "../fios.h" #include "../fios.h"
#include "../load_check.h"
#include "../tunnelbridge_map.h" #include "../tunnelbridge_map.h"
#include "../tunnelbridge.h" #include "../tunnelbridge.h"
#include "../station_base.h" #include "../station_base.h"

View File

@@ -13,6 +13,7 @@
#include "saveload.h" #include "saveload.h"
#include "saveload_buffer.h" #include "saveload_buffer.h"
#include "../fios.h" #include "../fios.h"
#include "../load_check.h"
#include "../safeguards.h" #include "../safeguards.h"

View File

@@ -10,6 +10,7 @@
#include "../stdafx.h" #include "../stdafx.h"
#include "../gamelog_internal.h" #include "../gamelog_internal.h"
#include "../fios.h" #include "../fios.h"
#include "../load_check.h"
#include "../string_func.h" #include "../string_func.h"
#include "saveload.h" #include "saveload.h"
@@ -96,37 +97,31 @@ static const SaveLoadTable _glog_desc[] = {
static_assert(lengthof(_glog_desc) == GLCT_END); 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<LoggedAction> &gamelog_actions)
{ {
assert(gamelog_action == nullptr); assert(gamelog_actions.empty());
assert(gamelog_actions == 0);
byte type; byte type;
while ((type = SlReadByte()) != GLAT_NONE) { while ((type = SlReadByte()) != GLAT_NONE) {
if (type >= GLAT_END) SlErrorCorrupt("Invalid gamelog action type"); if (type >= GLAT_END) SlErrorCorrupt("Invalid gamelog action type");
GamelogActionType at = (GamelogActionType)type; GamelogActionType at = (GamelogActionType)type;
gamelog_action = ReallocT(gamelog_action, gamelog_actions + 1); LoggedAction &la = gamelog_actions.emplace_back();
LoggedAction *la = &gamelog_action[gamelog_actions++];
la->at = at; la.at = at;
SlObject(la, _glog_action_desc); // has to be saved after 'DATE'! SlObject(&la, _glog_action_desc); // has to be saved after 'DATE'!
la->change = nullptr;
la->changes = 0;
while ((type = SlReadByte()) != GLCT_NONE) { while ((type = SlReadByte()) != GLCT_NONE) {
if (type >= GLCT_END) SlErrorCorrupt("Invalid gamelog change type"); if (type >= GLCT_END) SlErrorCorrupt("Invalid gamelog change type");
GamelogChangeType ct = (GamelogChangeType)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; lc->ct = ct;
SlObject(lc, _glog_desc[ct]); SlObject(lc, _glog_desc[ct]);
if (ct == GLCT_REVISION && SlXvIsFeatureMissing(XSLFI_EXTENDED_GAMELOG)) { if (ct == GLCT_REVISION && SlXvIsFeatureMissing(XSLFI_EXTENDED_GAMELOG)) {
lc->revision.text = stredup(old_revision_text, lastof(old_revision_text)); 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() static void Save_GLOG()
{ {
const LoggedAction *laend = &_gamelog_action[_gamelog_actions]; SlAutolength([](void *) {
size_t length = 0; for (LoggedAction &la : _gamelog_actions) {
SlWriteByte(la.at);
SlObject(&la, _glog_action_desc);
for (const LoggedAction *la = _gamelog_action; la != laend; la++) { for (LoggedChange &lc : la.changes) {
const LoggedChange *lcend = &la->change[la->changes]; SlWriteByte(lc.ct);
for (LoggedChange *lc = la->change; lc != lcend; lc++) { assert((uint)lc.ct < GLCT_END);
assert((uint)lc->ct < lengthof(_glog_desc)); SlObject(&lc, _glog_desc[lc.ct]);
length += SlCalcObjLength(lc, _glog_desc[lc->ct]) + 1; }
SlWriteByte(GLCT_NONE);
} }
length += 10; SlWriteByte(GLAT_NONE);
} }, nullptr);
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);
} }
static void Load_GLOG() static void Load_GLOG()
{ {
Load_GLOG_common(_gamelog_action, _gamelog_actions); Load_GLOG_common(_gamelog_actions);
} }
static void Check_GLOG() 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[] = { static const ChunkHandler gamelog_chunk_handlers[] = {

View File

@@ -13,6 +13,7 @@
#include "../core/endian_func.hpp" #include "../core/endian_func.hpp"
#include "../core/endian_type.hpp" #include "../core/endian_type.hpp"
#include "../fios.h" #include "../fios.h"
#include "../load_check.h"
#include <array> #include <array>
#include "saveload.h" #include "saveload.h"

View File

@@ -16,6 +16,7 @@
#include "../gfx_func.h" #include "../gfx_func.h"
#include "../core/random_func.hpp" #include "../core/random_func.hpp"
#include "../fios.h" #include "../fios.h"
#include "../load_check.h"
#include "../road_type.h" #include "../road_type.h"
#include "../core/checksum_func.hpp" #include "../core/checksum_func.hpp"
#include "../event_logs.h" #include "../event_logs.h"

View File

@@ -9,6 +9,7 @@
#include "../stdafx.h" #include "../stdafx.h"
#include "../fios.h" #include "../fios.h"
#include "../load_check.h"
#include "../string_func.h" #include "../string_func.h"
#include "saveload.h" #include "saveload.h"

View File

@@ -42,6 +42,7 @@
#include "../string_func.h" #include "../string_func.h"
#include "../string_func_extra.h" #include "../string_func_extra.h"
#include "../fios.h" #include "../fios.h"
#include "../load_check.h"
#include "../error.h" #include "../error.h"
#include "../scope.h" #include "../scope.h"
#include <atomic> #include <atomic>

View File

@@ -19,7 +19,6 @@
#include <stdarg.h> #include <stdarg.h>
#include <vector> #include <vector>
#include <string> #include <string>
#include <vector>
/** Save or load result codes. */ /** Save or load result codes. */
enum SaveOrLoadResult { enum SaveOrLoadResult {

View File

@@ -18,6 +18,7 @@
#include "linkgraph/linkgraph_gui.h" #include "linkgraph/linkgraph_gui.h"
#include "widgets/smallmap_widget.h" #include "widgets/smallmap_widget.h"
#include "guitimer_func.h" #include "guitimer_func.h"
#include <vector>
static const int NUM_NO_COMPANY_ENTRIES = 4; ///< Number of entries in the owner legend that are not companies. static const int NUM_NO_COMPANY_ENTRIES = 4; ///< Number of entries in the owner legend that are not companies.

View File

@@ -14,6 +14,7 @@
#include "core/bitmath_func.hpp" #include "core/bitmath_func.hpp"
#include "core/mem_func.hpp" #include "core/mem_func.hpp"
#include "date_type.h" #include "date_type.h"
#include <vector>
/** Flags of the sort list. */ /** Flags of the sort list. */
enum SortListFlags { enum SortListFlags {

View File

@@ -11,6 +11,7 @@
#define STRINGFILTER_TYPE_H #define STRINGFILTER_TYPE_H
#include "strings_type.h" #include "strings_type.h"
#include <vector>
/** /**
* String filter and state. * String filter and state.

View File

@@ -15,6 +15,7 @@
#include "textfile_type.h" #include "textfile_type.h"
#include "window_gui.h" #include "window_gui.h"
#include <optional> #include <optional>
#include <vector>
const char *GetTextfile(TextfileType type, Subdirectory dir, const char *filename); const char *GetTextfile(TextfileType type, Subdirectory dir, const char *filename);

View File

@@ -11,6 +11,7 @@
#define TOWN_TYPE_H #define TOWN_TYPE_H
#include "core/enum_type.hpp" #include "core/enum_type.hpp"
#include <vector>
typedef uint16 TownID; typedef uint16 TownID;
struct Town; struct Town;

View File

@@ -28,6 +28,7 @@
#include "sl/saveload_common.h" #include "sl/saveload_common.h"
#include <list> #include <list>
#include <map> #include <map>
#include <vector>
CommandCost CmdRefitVehicle(TileIndex, DoCommandFlag, uint32, uint32, const char*); CommandCost CmdRefitVehicle(TileIndex, DoCommandFlag, uint32, uint32, const char*);

View File

@@ -20,6 +20,7 @@
#include "track_type.h" #include "track_type.h"
#include "livery.h" #include "livery.h"
#include "cargo_type.h" #include "cargo_type.h"
#include <vector>
#define is_custom_sprite(x) (x >= 0xFD) #define is_custom_sprite(x) (x >= 0xFD)
#define IS_CUSTOM_FIRSTHEAD_SPRITE(x) (x == 0xFD) #define IS_CUSTOM_FIRSTHEAD_SPRITE(x) (x == 0xFD)

View File

@@ -17,6 +17,7 @@
#include "engine_type.h" #include "engine_type.h"
#include "company_type.h" #include "company_type.h"
#include "widgets/dropdown_func.h" #include "widgets/dropdown_func.h"
#include <vector>
void ShowVehicleRefitWindow(const Vehicle *v, VehicleOrderID order, Window *parent, bool auto_refit = false, bool is_virtual_train = false); void ShowVehicleRefitWindow(const Vehicle *v, VehicleOrderID order, Window *parent, bool auto_refit = false, bool is_virtual_train = false);

View File

@@ -14,6 +14,7 @@
#include "company_type.h" #include "company_type.h"
#include "tile_type.h" #include "tile_type.h"
#include "cargo_type.h" #include "cargo_type.h"
#include <vector>
/** Vehicle List type flags */ /** Vehicle List type flags */
enum VehicleListType { enum VehicleListType {

View File

@@ -16,6 +16,7 @@
#endif #endif
#include "video_driver.hpp" #include "video_driver.hpp"
#include <vector>
/** The SDL video driver. */ /** The SDL video driver. */
class VideoDriver_SDL_Base : public VideoDriver { class VideoDriver_SDL_Base : public VideoDriver {

View File

@@ -17,6 +17,7 @@
#include "../3rdparty/mingw-std-threads/mingw.mutex.h" #include "../3rdparty/mingw-std-threads/mingw.mutex.h"
#include "../3rdparty/mingw-std-threads/mingw.condition_variable.h" #include "../3rdparty/mingw-std-threads/mingw.condition_variable.h"
#endif #endif
#include <vector>
/** Base class for Windows video drivers. */ /** Base class for Windows video drivers. */
class VideoDriver_Win32Base : public VideoDriver { class VideoDriver_Win32Base : public VideoDriver {

View File

@@ -7,13 +7,13 @@
/** @file viewport_sprite_sorter.h Types related to sprite sorting. */ /** @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 #ifndef VIEWPORT_SPRITE_SORTER_H
#define VIEWPORT_SPRITE_SORTER_H #define VIEWPORT_SPRITE_SORTER_H
#include "core/bitmath_func.hpp"
#include "gfx_type.h"
#include <vector>
/** Parent sprite that should be drawn */ /** Parent sprite that should be drawn */
#ifdef _MSC_VER #ifdef _MSC_VER
struct __declspec(align(16)) ParentSpriteToDraw { struct __declspec(align(16)) ParentSpriteToDraw {

View File

@@ -13,6 +13,7 @@
#include "../window_type.h" #include "../window_type.h"
#include "../gfx_func.h" #include "../gfx_func.h"
#include "table/strings.h" #include "table/strings.h"
#include <vector>
enum DropDownSyncFocus { enum DropDownSyncFocus {
DDSF_NONE = 0, DDSF_NONE = 0,

View File

@@ -20,6 +20,7 @@
#include <algorithm> #include <algorithm>
#include <functional> #include <functional>
#include <vector>
/** /**
* Flags to describe the look of the frame * Flags to describe the look of the frame