1
0
Fork 0

Compare commits

...

5 Commits

Author SHA1 Message Date
Peter Nelson 1071acb483
Codechange: Redundant use of char * and c_str(). (#11454) 2023-11-10 00:17:36 +00:00
Peter Nelson 938c8339d2 Codechange: Ensure space between `for`/`if` and `(`. 2023-11-09 20:15:38 +00:00
Peter Nelson d4008850e3 Codechange: Ensure function opening `{` is on new line. 2023-11-09 20:15:38 +00:00
Jonathan G Rennison 1de1af08b9
Codechange: Replace AllocatedStringParameters with ArrayStringParameters (#11452)
All uses of AllocatedStringParameters are with a compile-time fixed
constant.
Use of a dynamically allocated buffer on the heap is unnecessary and
increases overhead, particularly due to frequent use as a temporary.
2023-11-09 19:43:47 +00:00
translators 92816ac96b Update: Translations from eints
german: 3 changes by SecretIdetity
romanian: 6 changes by bnegrut
2023-11-09 18:37:36 +00:00
35 changed files with 118 additions and 59 deletions

View File

@ -106,19 +106,19 @@ struct BaseSet {
* @param isocode the isocode to search for * @param isocode the isocode to search for
* @return the description * @return the description
*/ */
const char *GetDescription(const std::string &isocode) const const std::string &GetDescription(const std::string &isocode) const
{ {
if (!isocode.empty()) { if (!isocode.empty()) {
/* First the full ISO code */ /* First the full ISO code */
auto desc = this->description.find(isocode); auto desc = this->description.find(isocode);
if (desc != this->description.end()) return desc->second.c_str(); if (desc != this->description.end()) return desc->second;
/* Then the first two characters */ /* Then the first two characters */
desc = this->description.find(isocode.substr(0, 2)); desc = this->description.find(isocode.substr(0, 2));
if (desc != this->description.end()) return desc->second.c_str(); if (desc != this->description.end()) return desc->second;
} }
/* Then fall back */ /* Then fall back */
return this->description.at(std::string{}).c_str(); return this->description.at(std::string{});
} }
/** /**

View File

@ -125,11 +125,11 @@ struct BaseStation : StationPool::PoolItem<&_station_pool> {
*/ */
virtual void UpdateVirtCoord() = 0; virtual void UpdateVirtCoord() = 0;
inline const char *GetCachedName() const inline const std::string &GetCachedName() const
{ {
if (!this->name.empty()) return this->name.c_str(); if (!this->name.empty()) return this->name;
if (this->cached_name.empty()) this->FillCachedName(); if (this->cached_name.empty()) this->FillCachedName();
return this->cached_name.c_str(); return this->cached_name;
} }
virtual void MoveSign(TileIndex new_xy) virtual void MoveSign(TileIndex new_xy)

View File

@ -18,11 +18,13 @@ struct fmt::formatter<E, Char, std::enable_if_t<std::is_enum<E>::value>> : fmt::
using underlying_type = typename std::underlying_type<E>::type; using underlying_type = typename std::underlying_type<E>::type;
using parent = typename fmt::formatter<underlying_type>; using parent = typename fmt::formatter<underlying_type>;
constexpr fmt::format_parse_context::iterator parse(fmt::format_parse_context &ctx) { constexpr fmt::format_parse_context::iterator parse(fmt::format_parse_context &ctx)
{
return parent::parse(ctx); return parent::parse(ctx);
} }
fmt::format_context::iterator format(const E &e, format_context &ctx) const { fmt::format_context::iterator format(const E &e, format_context &ctx) const
{
return parent::format(underlying_type(e), ctx); return parent::format(underlying_type(e), ctx);
} }
}; };
@ -32,11 +34,13 @@ struct fmt::formatter<T, Char, std::enable_if_t<std::is_base_of<StrongTypedefBas
using underlying_type = typename T::BaseType; using underlying_type = typename T::BaseType;
using parent = typename fmt::formatter<underlying_type>; using parent = typename fmt::formatter<underlying_type>;
constexpr fmt::format_parse_context::iterator parse(fmt::format_parse_context &ctx) { constexpr fmt::format_parse_context::iterator parse(fmt::format_parse_context &ctx)
{
return parent::parse(ctx); return parent::parse(ctx);
} }
fmt::format_context::iterator format(const T &t, format_context &ctx) const { fmt::format_context::iterator format(const T &t, format_context &ctx) const
{
return parent::format(t.base(), ctx); return parent::format(t.base(), ctx);
} }
}; };

View File

@ -444,7 +444,8 @@ void ShowErrorMessage(StringID summary_msg, StringID detailed_msg, WarningLevel
* Close active error message window * Close active error message window
* @return true if a window was closed. * @return true if a window was closed.
*/ */
bool HideActiveErrorMessage() { bool HideActiveErrorMessage()
{
ErrmsgWindow *w = (ErrmsgWindow*)FindWindowById(WC_ERRMSG, 0); ErrmsgWindow *w = (ErrmsgWindow*)FindWindowById(WC_ERRMSG, 0);
if (w == nullptr) return false; if (w == nullptr) return false;
w->Close(); w->Close();

View File

@ -154,7 +154,8 @@ ICUParagraphLayout::ICUVisualRun::ICUVisualRun(const ICURun &run, int x) :
* @param buff The buffer of which a partial (depending on start/length of the run) will be shaped. * @param buff The buffer of which a partial (depending on start/length of the run) will be shaped.
* @param length The length of the buffer. * @param length The length of the buffer.
*/ */
void ICURun::Shape(UChar *buff, size_t buff_length) { void ICURun::Shape(UChar *buff, size_t buff_length)
{
auto hbfont = hb_ft_font_create_referenced(*(static_cast<const FT_Face *>(font->fc->GetOSHandle()))); auto hbfont = hb_ft_font_create_referenced(*(static_cast<const FT_Face *>(font->fc->GetOSHandle())));
hb_font_set_scale(hbfont, this->font->fc->GetFontSize() * FONT_SCALE, this->font->fc->GetFontSize() * FONT_SCALE); hb_font_set_scale(hbfont, this->font->fc->GetFontSize() * FONT_SCALE, this->font->fc->GetFontSize() * FONT_SCALE);

View File

@ -534,6 +534,7 @@ STR_ABOUT_MENU_ABOUT_OPENTTD :Über OpenTTD
STR_ABOUT_MENU_SPRITE_ALIGNER :Sprite-Ausrichtung STR_ABOUT_MENU_SPRITE_ALIGNER :Sprite-Ausrichtung
STR_ABOUT_MENU_TOGGLE_BOUNDING_BOXES :Hüllquader anzeigen/ausblenden STR_ABOUT_MENU_TOGGLE_BOUNDING_BOXES :Hüllquader anzeigen/ausblenden
STR_ABOUT_MENU_TOGGLE_DIRTY_BLOCKS :Neugezeichnete Felder farbig markieren STR_ABOUT_MENU_TOGGLE_DIRTY_BLOCKS :Neugezeichnete Felder farbig markieren
STR_ABOUT_MENU_TOGGLE_WIDGET_OUTLINES :Widget-Umrisse anzeigen/ausblenden
# Place in highscore window # Place in highscore window
###length 15 ###length 15
@ -3384,6 +3385,7 @@ STR_SAVE_PRESET_SAVE :{BLACK}Speicher
STR_SAVE_PRESET_SAVE_TOOLTIP :{BLACK}Voreinstellung unter dem ausgewählten Namen speichern STR_SAVE_PRESET_SAVE_TOOLTIP :{BLACK}Voreinstellung unter dem ausgewählten Namen speichern
# NewGRF parameters window # NewGRF parameters window
STR_BASEGRF_PARAMETERS_CAPTION :{WHITE}Parameter der Basisgrafiken ändern
STR_NEWGRF_PARAMETERS_CAPTION :{WHITE}NewGRF Parameter ändern STR_NEWGRF_PARAMETERS_CAPTION :{WHITE}NewGRF Parameter ändern
STR_NEWGRF_PARAMETERS_CLOSE :{BLACK}Schließen STR_NEWGRF_PARAMETERS_CLOSE :{BLACK}Schließen
STR_NEWGRF_PARAMETERS_RESET :{BLACK}Zurücksetzen STR_NEWGRF_PARAMETERS_RESET :{BLACK}Zurücksetzen
@ -5188,6 +5190,7 @@ STR_ERROR_CAN_T_TIMETABLE_VEHICLE :{WHITE}Fahrplan
STR_ERROR_TIMETABLE_ONLY_WAIT_AT_STATIONS :{WHITE}Fahrzeuge halten nur an Stationen STR_ERROR_TIMETABLE_ONLY_WAIT_AT_STATIONS :{WHITE}Fahrzeuge halten nur an Stationen
STR_ERROR_TIMETABLE_NOT_STOPPING_HERE :{WHITE}Das Fahrzeug hält nicht an dieser Station STR_ERROR_TIMETABLE_NOT_STOPPING_HERE :{WHITE}Das Fahrzeug hält nicht an dieser Station
STR_ERROR_TIMETABLE_INCOMPLETE :{WHITE}... Fahrplan ist unvollständig STR_ERROR_TIMETABLE_INCOMPLETE :{WHITE}... Fahrplan ist unvollständig
STR_ERROR_TIMETABLE_NOT_STARTED :{WHITE}... Fahrplan hat noch nicht begonnen
# Sign related errors # Sign related errors
STR_ERROR_TOO_MANY_SIGNS :{WHITE}... zu viele Schilder STR_ERROR_TOO_MANY_SIGNS :{WHITE}... zu viele Schilder

View File

@ -533,6 +533,7 @@ STR_ABOUT_MENU_ABOUT_OPENTTD :Despre 'OpenTTD
STR_ABOUT_MENU_SPRITE_ALIGNER :Aliniere imagini STR_ABOUT_MENU_SPRITE_ALIGNER :Aliniere imagini
STR_ABOUT_MENU_TOGGLE_BOUNDING_BOXES :Afişează/ascunde casetele de încadrare STR_ABOUT_MENU_TOGGLE_BOUNDING_BOXES :Afişează/ascunde casetele de încadrare
STR_ABOUT_MENU_TOGGLE_DIRTY_BLOCKS :Comutator pentru colorarea secțiunilor murdare STR_ABOUT_MENU_TOGGLE_DIRTY_BLOCKS :Comutator pentru colorarea secțiunilor murdare
STR_ABOUT_MENU_TOGGLE_WIDGET_OUTLINES :Comutați contururile widgetului
# Place in highscore window # Place in highscore window
###length 15 ###length 15
@ -924,6 +925,8 @@ STR_NEWS_NEW_VEHICLE_NOW_AVAILABLE_WITH_TYPE :{BLACK}Un nou t
STR_NEWS_SHOW_VEHICLE_GROUP_TOOLTIP :{BLACK}Deschide fereastra grupului fixată pe grupul vehiculului STR_NEWS_SHOW_VEHICLE_GROUP_TOOLTIP :{BLACK}Deschide fereastra grupului fixată pe grupul vehiculului
STR_NEWS_STATION_NO_LONGER_ACCEPTS_CARGO_LIST :{WHITE}{STATION} nu mai acceptă: {CARGO_LIST}
STR_NEWS_STATION_NOW_ACCEPTS_CARGO_LIST :{WHITE}{STATION} acceptă acum: {CARGO_LIST}
STR_NEWS_OFFER_OF_SUBSIDY_EXPIRED :{BIG_FONT}{BLACK}Ofertă expirată:{}{}Transportul de {STRING} de la {STRING} la {STRING} nu va mai fi subvenţionat STR_NEWS_OFFER_OF_SUBSIDY_EXPIRED :{BIG_FONT}{BLACK}Ofertă expirată:{}{}Transportul de {STRING} de la {STRING} la {STRING} nu va mai fi subvenţionat
STR_NEWS_SUBSIDY_WITHDRAWN_SERVICE :{BIG_FONT}{BLACK}Ofertă retrasă:{}{}Transportul de {STRING} de la {STRING} la {STRING} nu va mai fi subvenţionat STR_NEWS_SUBSIDY_WITHDRAWN_SERVICE :{BIG_FONT}{BLACK}Ofertă retrasă:{}{}Transportul de {STRING} de la {STRING} la {STRING} nu va mai fi subvenţionat
@ -2191,6 +2194,7 @@ STR_CHEAT_EDIT_MAX_HL_QUERY_CAPT :{WHITE}Schimbă
STR_CHEAT_CHANGE_DATE :{LTBLUE}Schimbă data: {ORANGE}{DATE_SHORT} STR_CHEAT_CHANGE_DATE :{LTBLUE}Schimbă data: {ORANGE}{DATE_SHORT}
STR_CHEAT_CHANGE_DATE_QUERY_CAPT :{WHITE}Schimbă anul curent STR_CHEAT_CHANGE_DATE_QUERY_CAPT :{WHITE}Schimbă anul curent
STR_CHEAT_SETUP_PROD :{LTBLUE}Activează accesul la valorile de producţie: {ORANGE}{STRING} STR_CHEAT_SETUP_PROD :{LTBLUE}Activează accesul la valorile de producţie: {ORANGE}{STRING}
STR_CHEAT_STATION_RATING :{LTBLUE}Remediați evaluările staţiei la 100%: {ORANGE}{STRING}
# Livery window # Livery window
STR_LIVERY_CAPTION :{WHITE}{COMPANY} - Schemă de culori STR_LIVERY_CAPTION :{WHITE}{COMPANY} - Schemă de culori
@ -3379,6 +3383,7 @@ STR_SAVE_PRESET_SAVE :{BLACK}Salveaz
STR_SAVE_PRESET_SAVE_TOOLTIP :{BLACK}Salvează setarea pe numele selectat STR_SAVE_PRESET_SAVE_TOOLTIP :{BLACK}Salvează setarea pe numele selectat
# NewGRF parameters window # NewGRF parameters window
STR_BASEGRF_PARAMETERS_CAPTION :{WHITE}Schimbați parametrii grafici de bază
STR_NEWGRF_PARAMETERS_CAPTION :{WHITE}Schimbă parametrii NewGRF STR_NEWGRF_PARAMETERS_CAPTION :{WHITE}Schimbă parametrii NewGRF
STR_NEWGRF_PARAMETERS_CLOSE :{BLACK}Închide STR_NEWGRF_PARAMETERS_CLOSE :{BLACK}Închide
STR_NEWGRF_PARAMETERS_RESET :{BLACK}Resetează STR_NEWGRF_PARAMETERS_RESET :{BLACK}Resetează
@ -5183,6 +5188,7 @@ STR_ERROR_CAN_T_TIMETABLE_VEHICLE :{WHITE}Nu pot p
STR_ERROR_TIMETABLE_ONLY_WAIT_AT_STATIONS :{WHITE}Vehiculele pot aştepta numai în staţii STR_ERROR_TIMETABLE_ONLY_WAIT_AT_STATIONS :{WHITE}Vehiculele pot aştepta numai în staţii
STR_ERROR_TIMETABLE_NOT_STOPPING_HERE :{WHITE}Acest vehicul nu are oprire în această staţie STR_ERROR_TIMETABLE_NOT_STOPPING_HERE :{WHITE}Acest vehicul nu are oprire în această staţie
STR_ERROR_TIMETABLE_INCOMPLETE :{WHITE}... orarul este incomplet STR_ERROR_TIMETABLE_INCOMPLETE :{WHITE}... orarul este incomplet
STR_ERROR_TIMETABLE_NOT_STARTED :{WHITE}... orarul nu a început încă
# Sign related errors # Sign related errors
STR_ERROR_TOO_MANY_SIGNS :{WHITE}... prea multe semne STR_ERROR_TOO_MANY_SIGNS :{WHITE}... prea multe semne

View File

@ -569,7 +569,8 @@ LinkGraphLegendWindow::LinkGraphLegendWindow(WindowDesc *desc, int window_number
* Set the overlay belonging to this menu and import its company/cargo settings. * Set the overlay belonging to this menu and import its company/cargo settings.
* @param overlay New overlay for this menu. * @param overlay New overlay for this menu.
*/ */
void LinkGraphLegendWindow::SetOverlay(std::shared_ptr<LinkGraphOverlay> overlay) { void LinkGraphLegendWindow::SetOverlay(std::shared_ptr<LinkGraphOverlay> overlay)
{
this->overlay = overlay; this->overlay = overlay;
CompanyMask companies = this->overlay->GetCompanyMask(); CompanyMask companies = this->overlay->GetCompanyMask();
for (uint c = 0; c < MAX_COMPANIES; c++) { for (uint c = 0; c < MAX_COMPANIES; c++) {

View File

@ -72,7 +72,8 @@ public:
private: private:
/** Helper function to write a tuple to the buffer. */ /** Helper function to write a tuple to the buffer. */
template<class Ttuple, size_t... Tindices> template<class Ttuple, size_t... Tindices>
void WriteTuple(const Ttuple &values, std::index_sequence<Tindices...>) { void WriteTuple(const Ttuple &values, std::index_sequence<Tindices...>)
{
((*this << std::get<Tindices>(values)), ...); ((*this << std::get<Tindices>(values)), ...);
} }
@ -165,7 +166,8 @@ public:
private: private:
/** Helper function to read a tuple from the buffer. */ /** Helper function to read a tuple from the buffer. */
template<class Ttuple, size_t... Tindices> template<class Ttuple, size_t... Tindices>
void ReadTuple(Ttuple &values, std::index_sequence<Tindices...>) { void ReadTuple(Ttuple &values, std::index_sequence<Tindices...>)
{
((*this >> std::get<Tindices>(values)), ...); ((*this >> std::get<Tindices>(values)), ...);
} }

View File

@ -71,7 +71,8 @@ struct DLSFile {
WSMPL wave_sample; WSMPL wave_sample;
std::vector<WLOOP> wave_loops; std::vector<WLOOP> wave_loops;
bool operator ==(long offset) const { bool operator ==(long offset) const
{
return this->file_offset == offset; return this->file_offset == offset;
} }
}; };

View File

@ -43,7 +43,8 @@ public:
/** /**
* Get the currently active instance of the music driver. * Get the currently active instance of the music driver.
*/ */
static MusicDriver *GetInstance() { static MusicDriver *GetInstance()
{
return static_cast<MusicDriver*>(*DriverFactoryBase::GetActiveDriver(Driver::DT_MUSIC)); return static_cast<MusicDriver*>(*DriverFactoryBase::GetActiveDriver(Driver::DT_MUSIC));
} }
}; };

View File

@ -1043,7 +1043,8 @@ static void ShowNewsMessage(const NewsItem *ni)
* Close active news message window * Close active news message window
* @return true if a window was closed. * @return true if a window was closed.
*/ */
bool HideActiveNewsMessage() { bool HideActiveNewsMessage()
{
NewsWindow *w = (NewsWindow*)FindWindowById(WC_NEWS_WINDOW, 0); NewsWindow *w = (NewsWindow*)FindWindowById(WC_NEWS_WINDOW, 0);
if (w == nullptr) return false; if (w == nullptr) return false;
w->Close(); w->Close();

View File

@ -326,7 +326,7 @@ void LoadCoreTextFont(FontSize fs)
path.reset(CFStringCreateWithCString(kCFAllocatorDefault, settings->font.c_str(), kCFStringEncodingUTF8)); path.reset(CFStringCreateWithCString(kCFAllocatorDefault, settings->font.c_str(), kCFStringEncodingUTF8));
} else { } else {
/* Scan the search-paths to see if it can be found. */ /* Scan the search-paths to see if it can be found. */
std::string full_font = FioFindFullPath(BASE_DIR, settings->font.c_str()); std::string full_font = FioFindFullPath(BASE_DIR, settings->font);
if (!full_font.empty()) { if (!full_font.empty()) {
path.reset(CFStringCreateWithCString(kCFAllocatorDefault, full_font.c_str(), kCFStringEncodingUTF8)); path.reset(CFStringCreateWithCString(kCFAllocatorDefault, full_font.c_str(), kCFStringEncodingUTF8));
} }

View File

@ -251,7 +251,8 @@ void OSOpenBrowser(const char *url)
} }
#endif /* __APPLE__ */ #endif /* __APPLE__ */
void SetCurrentThreadName([[maybe_unused]] const char *threadName) { void SetCurrentThreadName([[maybe_unused]] const char *threadName)
{
#if defined(__GLIBC__) #if defined(__GLIBC__)
if (threadName) pthread_setname_np(pthread_self(), threadName); if (threadName) pthread_setname_np(pthread_self(), threadName);
#endif /* defined(__GLIBC__) */ #endif /* defined(__GLIBC__) */

View File

@ -38,7 +38,8 @@ struct EFCParam {
MissingGlyphSearcher *callback; MissingGlyphSearcher *callback;
std::vector<std::wstring> fonts; std::vector<std::wstring> fonts;
bool Add(const std::wstring_view &font) { bool Add(const std::wstring_view &font)
{
for (const auto &entry : this->fonts) { for (const auto &entry : this->fonts) {
if (font.compare(entry) == 0) return false; if (font.compare(entry) == 0) return false;
} }

View File

@ -1395,7 +1395,8 @@ public:
/** /**
* Simply to have a easier way to get the StationType for bus, truck and trams from the WindowClass. * Simply to have a easier way to get the StationType for bus, truck and trams from the WindowClass.
*/ */
StationType GetRoadStationTypeByWindowClass(WindowClass window_class) const { StationType GetRoadStationTypeByWindowClass(WindowClass window_class) const
{
switch (window_class) { switch (window_class) {
case WC_BUS_STATION: return STATION_BUS; case WC_BUS_STATION: return STATION_BUS;
case WC_TRUCK_STATION: return STATION_TRUCK; case WC_TRUCK_STATION: return STATION_TRUCK;
@ -1475,13 +1476,15 @@ public:
} }
} }
void OnResize() override { void OnResize() override
{
if (this->vscrollList != nullptr) { if (this->vscrollList != nullptr) {
this->vscrollList->SetCapacityFromWidget(this, WID_BROS_NEWST_LIST); this->vscrollList->SetCapacityFromWidget(this, WID_BROS_NEWST_LIST);
} }
} }
void SetStringParameters(int widget) const override { void SetStringParameters(int widget) const override
{
if (widget == WID_BROS_SHOW_NEWST_TYPE) { if (widget == WID_BROS_SHOW_NEWST_TYPE) {
const RoadStopSpec *roadstopspec = RoadStopClass::Get(_roadstop_gui_settings.roadstop_class)->GetSpec(_roadstop_gui_settings.roadstop_type); const RoadStopSpec *roadstopspec = RoadStopClass::Get(_roadstop_gui_settings.roadstop_class)->GetSpec(_roadstop_gui_settings.roadstop_type);
SetDParam(0, (roadstopspec != nullptr && roadstopspec->name != 0) ? roadstopspec->name : STR_STATION_CLASS_DFLT_ROADSTOP); SetDParam(0, (roadstopspec != nullptr && roadstopspec->name != 0) ? roadstopspec->name : STR_STATION_CLASS_DFLT_ROADSTOP);

View File

@ -46,7 +46,7 @@ ScriptStorage::~ScriptStorage()
static void PrintFunc(bool error_msg, const std::string &message) static void PrintFunc(bool error_msg, const std::string &message)
{ {
/* Convert to OpenTTD internal capable string */ /* Convert to OpenTTD internal capable string */
ScriptController::Print(error_msg, message.c_str()); ScriptController::Print(error_msg, message);
} }
ScriptInstance::ScriptInstance(const char *APIName) : ScriptInstance::ScriptInstance(const char *APIName) :

View File

@ -45,7 +45,8 @@ namespace SQConvert {
template <> struct Return<HSQOBJECT> { static inline int Set(HSQUIRRELVM vm, HSQOBJECT res) { sq_pushobject(vm, res); return 1; } }; template <> struct Return<HSQOBJECT> { static inline int Set(HSQUIRRELVM vm, HSQOBJECT res) { sq_pushobject(vm, res); return 1; } };
template <> struct Return<std::optional<std::string>> { template <> struct Return<std::optional<std::string>> {
static inline int Set(HSQUIRRELVM vm, std::optional<std::string> res) { static inline int Set(HSQUIRRELVM vm, std::optional<std::string> res)
{
if (res.has_value()) { if (res.has_value()) {
sq_pushstring(vm, res.value(), -1); sq_pushstring(vm, res.value(), -1);
} else { } else {

View File

@ -1552,7 +1552,7 @@ void DeleteGRFPresetFromConfig(const char *config_name)
section += config_name; section += config_name;
ConfigIniFile ini(_config_file); ConfigIniFile ini(_config_file);
ini.RemoveGroup(section.c_str()); ini.RemoveGroup(section);
ini.SaveToDisk(_config_file); ini.SaveToDisk(_config_file);
} }

View File

@ -563,7 +563,8 @@ struct LinkGraphSettings {
uint8_t demand_distance; ///< influence of distance between stations on the demand function uint8_t demand_distance; ///< influence of distance between stations on the demand function
uint8_t short_path_saturation; ///< percentage up to which short paths are saturated before saturating most capacious paths uint8_t short_path_saturation; ///< percentage up to which short paths are saturated before saturating most capacious paths
inline DistributionType GetDistributionType(CargoID cargo) const { inline DistributionType GetDistributionType(CargoID cargo) const
{
if (IsCargoInClass(cargo, CC_PASSENGERS)) return this->distribution_pax; if (IsCargoInClass(cargo, CC_PASSENGERS)) return this->distribution_pax;
if (IsCargoInClass(cargo, CC_MAIL)) return this->distribution_mail; if (IsCargoInClass(cargo, CC_MAIL)) return this->distribution_mail;
if (IsCargoInClass(cargo, CC_ARMOURED)) return this->distribution_armoured; if (IsCargoInClass(cargo, CC_ARMOURED)) return this->distribution_armoured;

View File

@ -32,7 +32,8 @@ public:
/** /**
* Get the currently active instance of the sound driver. * Get the currently active instance of the sound driver.
*/ */
static SoundDriver *GetInstance() { static SoundDriver *GetInstance()
{
return static_cast<SoundDriver*>(*DriverFactoryBase::GetActiveDriver(Driver::DT_SOUND)); return static_cast<SoundDriver*>(*DriverFactoryBase::GetActiveDriver(Driver::DT_SOUND));
} }
}; };

View File

@ -64,7 +64,8 @@ SpriteCache *AllocateSpriteCache(uint index)
* @param filename The name of the file at the disk. * @param filename The name of the file at the disk.
* @return The SpriteFile or \c null. * @return The SpriteFile or \c null.
*/ */
static SpriteFile *GetCachedSpriteFileByName(const std::string &filename) { static SpriteFile *GetCachedSpriteFileByName(const std::string &filename)
{
for (auto &f : _sprite_files) { for (auto &f : _sprite_files) {
if (f->GetFilename() == filename) { if (f->GetFilename() == filename) {
return f.get(); return f.get();

View File

@ -413,7 +413,8 @@ void Station::AddIndustryToDeliver(Industry *ind, TileIndex tile)
* Remove nearby industry from station's industries_near list. * Remove nearby industry from station's industries_near list.
* @param ind Industry * @param ind Industry
*/ */
void Station::RemoveIndustryToDeliver(Industry *ind) { void Station::RemoveIndustryToDeliver(Industry *ind)
{
auto pos = std::find_if(this->industries_near.begin(), this->industries_near.end(), [&](const IndustryListEntry &e) { return e.industry->index == ind->index; }); auto pos = std::find_if(this->industries_near.begin(), this->industries_near.end(), [&](const IndustryListEntry &e) { return e.industry->index == ind->index; });
if (pos != this->industries_near.end()) { if (pos != this->industries_near.end()) {
this->industries_near.erase(pos); this->industries_near.erase(pos);

View File

@ -79,7 +79,7 @@ struct FileStringReader : StringReader {
* @param translation Are we reading a translation? * @param translation Are we reading a translation?
*/ */
FileStringReader(StringData &data, const std::filesystem::path &file, bool master, bool translation) : FileStringReader(StringData &data, const std::filesystem::path &file, bool master, bool translation) :
StringReader(data, file.generic_string().c_str(), master, translation) StringReader(data, file.generic_string(), master, translation)
{ {
this->input_stream.open(file, std::ifstream::binary); this->input_stream.open(file, std::ifstream::binary);
} }

View File

@ -58,7 +58,7 @@ TextDirection _current_text_dir; ///< Text direction of the currently selected l
std::unique_ptr<icu::Collator> _current_collator; ///< Collator for the language currently in use. std::unique_ptr<icu::Collator> _current_collator; ///< Collator for the language currently in use.
#endif /* WITH_ICU_I18N */ #endif /* WITH_ICU_I18N */
AllocatedStringParameters _global_string_params(20); ArrayStringParameters<20> _global_string_params;
/** /**
* Prepare the string parameters for the next formatting run. This means * Prepare the string parameters for the next formatting run. This means
@ -927,7 +927,7 @@ static void FormatString(StringBuilder &builder, const char *str_arg, StringPara
args.SetTypeOfNextParameter(b); args.SetTypeOfNextParameter(b);
switch (b) { switch (b) {
case SCC_ENCODED: { case SCC_ENCODED: {
AllocatedStringParameters sub_args(20); ArrayStringParameters<20> sub_args;
char *p; char *p;
uint32_t stringid = std::strtoul(str, &p, 16); uint32_t stringid = std::strtoul(str, &p, 16);
@ -1440,7 +1440,7 @@ static void FormatString(StringBuilder &builder, const char *str_arg, StringPara
assert(grffile != nullptr); assert(grffile != nullptr);
StartTextRefStackUsage(grffile, 6); StartTextRefStackUsage(grffile, 6);
AllocatedStringParameters tmp_params(6); ArrayStringParameters<6> tmp_params;
GetStringWithArgs(builder, GetGRFStringID(grffile->grfid, 0xD000 + callback), tmp_params); GetStringWithArgs(builder, GetGRFStringID(grffile->grfid, 0xD000 + callback), tmp_params);
StopTextRefStackUsage(); StopTextRefStackUsage();
@ -1448,7 +1448,7 @@ static void FormatString(StringBuilder &builder, const char *str_arg, StringPara
} }
} }
auto tmp_params = AllocatedStringParameters(); auto tmp_params = ArrayStringParameters<0>();
GetStringWithArgs(builder, e->info.string_id, tmp_params); GetStringWithArgs(builder, e->info.string_id, tmp_params);
break; break;
} }
@ -1478,7 +1478,7 @@ static void FormatString(StringBuilder &builder, const char *str_arg, StringPara
} else if (_scan_for_gender_data) { } else if (_scan_for_gender_data) {
/* Gender is defined by the industry type. /* Gender is defined by the industry type.
* STR_FORMAT_INDUSTRY_NAME may have the town first, so it would result in the gender of the town name */ * STR_FORMAT_INDUSTRY_NAME may have the town first, so it would result in the gender of the town name */
auto tmp_params = AllocatedStringParameters(); auto tmp_params = ArrayStringParameters<0>();
FormatString(builder, GetStringPtr(GetIndustrySpec(i->type)->name), tmp_params, next_substr_case_index); FormatString(builder, GetStringPtr(GetIndustrySpec(i->type)->name), tmp_params, next_substr_case_index);
} else { } else {
/* First print the town name and the industry type name. */ /* First print the town name and the industry type name. */
@ -1511,7 +1511,7 @@ static void FormatString(StringBuilder &builder, const char *str_arg, StringPara
/* The station doesn't exist anymore. The only place where we might /* The station doesn't exist anymore. The only place where we might
* be "drawing" an invalid station is in the case of cargo that is * be "drawing" an invalid station is in the case of cargo that is
* in transit. */ * in transit. */
auto tmp_params = AllocatedStringParameters(); auto tmp_params = ArrayStringParameters<0>();
GetStringWithArgs(builder, STR_UNKNOWN_STATION, tmp_params); GetStringWithArgs(builder, STR_UNKNOWN_STATION, tmp_params);
break; break;
} }
@ -1612,7 +1612,7 @@ static void FormatString(StringBuilder &builder, const char *str_arg, StringPara
auto tmp_params = MakeParameters(si->name); auto tmp_params = MakeParameters(si->name);
GetStringWithArgs(builder, STR_JUST_RAW_STRING, tmp_params); GetStringWithArgs(builder, STR_JUST_RAW_STRING, tmp_params);
} else { } else {
auto tmp_params = AllocatedStringParameters(); auto tmp_params = ArrayStringParameters<0>();
GetStringWithArgs(builder, STR_DEFAULT_SIGN_NAME, tmp_params); GetStringWithArgs(builder, STR_DEFAULT_SIGN_NAME, tmp_params);
} }
break; break;

View File

@ -198,17 +198,35 @@ public:
}; };
/** /**
* Extension of StringParameters with its own statically allocated buffer for * Extension of StringParameters with its own statically sized buffer for
* the parameters. * the parameters.
*/ */
class AllocatedStringParameters : public StringParameters { template <size_t N>
std::vector<StringParameter> params; ///< The actual parameters class ArrayStringParameters : public StringParameters {
std::array<StringParameter, N> params{}; ///< The actual parameters
public: public:
AllocatedStringParameters(size_t parameters = 0) : params(parameters) ArrayStringParameters()
{ {
this->parameters = span(params.data(), params.size()); this->parameters = span(params.data(), params.size());
} }
ArrayStringParameters(ArrayStringParameters&& other) noexcept
{
*this = std::move(other);
}
ArrayStringParameters& operator=(ArrayStringParameters &&other) noexcept
{
this->offset = other.offset;
this->next_type = other.next_type;
this->params = std::move(other.params);
this->parameters = span(params.data(), params.size());
return *this;
}
ArrayStringParameters(const ArrayStringParameters& other) = delete;
ArrayStringParameters& operator=(const ArrayStringParameters &other) = delete;
}; };
/** /**
@ -220,7 +238,7 @@ public:
template <typename... Args> template <typename... Args>
static auto MakeParameters(const Args&... args) static auto MakeParameters(const Args&... args)
{ {
AllocatedStringParameters parameters(sizeof...(args)); ArrayStringParameters<sizeof...(args)> parameters;
size_t index = 0; size_t index = 0;
(parameters.SetParam(index++, std::forward<const Args&>(args)), ...); (parameters.SetParam(index++, std::forward<const Args&>(args)), ...);
return parameters; return parameters;

View File

@ -38,7 +38,8 @@ public:
* *
* @param timer The timer to register. * @param timer The timer to register.
*/ */
static void RegisterTimer(BaseTimer<TTimerType> &timer) { static void RegisterTimer(BaseTimer<TTimerType> &timer)
{
#ifdef WITH_ASSERT #ifdef WITH_ASSERT
Validate(timer.period); Validate(timer.period);
#endif /* WITH_ASSERT */ #endif /* WITH_ASSERT */
@ -50,7 +51,8 @@ public:
* *
* @param timer The timer to unregister. * @param timer The timer to unregister.
*/ */
static void UnregisterTimer(BaseTimer<TTimerType> &timer) { static void UnregisterTimer(BaseTimer<TTimerType> &timer)
{
GetTimers().erase(&timer); GetTimers().erase(&timer);
} }
@ -87,14 +89,16 @@ private:
* same, it will sort based on the pointer value. * same, it will sort based on the pointer value.
*/ */
struct base_timer_sorter { struct base_timer_sorter {
bool operator() (BaseTimer<TTimerType> *a, BaseTimer<TTimerType> *b) const { bool operator() (BaseTimer<TTimerType> *a, BaseTimer<TTimerType> *b) const
{
if (a->period == b->period) return a < b; if (a->period == b->period) return a < b;
return a->period < b->period; return a->period < b->period;
} }
}; };
/** Singleton list, to store all the active timers. */ /** Singleton list, to store all the active timers. */
static std::set<BaseTimer<TTimerType> *, base_timer_sorter> &GetTimers() { static std::set<BaseTimer<TTimerType> *, base_timer_sorter> &GetTimers()
{
static std::set<BaseTimer<TTimerType> *, base_timer_sorter> timers; static std::set<BaseTimer<TTimerType> *, base_timer_sorter> timers;
return timers; return timers;
} }

View File

@ -690,7 +690,8 @@ static const int LTMN_PERFORMANCE_LEAGUE = -7; ///< Show default league t
static const int LTMN_PERFORMANCE_RATING = -8; ///< Show detailed performance rating static const int LTMN_PERFORMANCE_RATING = -8; ///< Show detailed performance rating
static const int LTMN_HIGHSCORE = -9; ///< Show highscrore table static const int LTMN_HIGHSCORE = -9; ///< Show highscrore table
static void AddDropDownLeagueTableOptions(DropDownList &list) { static void AddDropDownLeagueTableOptions(DropDownList &list)
{
if (LeagueTable::GetNumItems() > 0) { if (LeagueTable::GetNumItems() > 0) {
for (LeagueTable *lt : LeagueTable::Iterate()) { for (LeagueTable *lt : LeagueTable::Iterate()) {
list.push_back(std::make_unique<DropDownListStringItem>(lt->title, lt->index, false)); list.push_back(std::make_unique<DropDownListStringItem>(lt->title, lt->index, false));

View File

@ -304,7 +304,8 @@ void MakeDefaultName(T *obj)
* Converts original town ticks counters to plain game ticks. Note that * Converts original town ticks counters to plain game ticks. Note that
* tick 0 is a valid tick so actual amount is one more than the counter value. * tick 0 is a valid tick so actual amount is one more than the counter value.
*/ */
static inline uint16_t TownTicksToGameTicks(uint16_t ticks) { static inline uint16_t TownTicksToGameTicks(uint16_t ticks)
{
return (std::min(ticks, MAX_TOWN_GROWTH_TICKS) + 1) * Ticks::TOWN_GROWTH_TICKS - 1; return (std::min(ticks, MAX_TOWN_GROWTH_TICKS) + 1) * Ticks::TOWN_GROWTH_TICKS - 1;
} }

View File

@ -197,7 +197,8 @@ public:
/** /**
* Get the currently active instance of the video driver. * Get the currently active instance of the video driver.
*/ */
static VideoDriver *GetInstance() { static VideoDriver *GetInstance()
{
return static_cast<VideoDriver*>(*DriverFactoryBase::GetActiveDriver(Driver::DT_VIDEO)); return static_cast<VideoDriver*>(*DriverFactoryBase::GetActiveDriver(Driver::DT_VIDEO));
} }
@ -260,7 +261,8 @@ protected:
* Make sure the video buffer is ready for drawing. * Make sure the video buffer is ready for drawing.
* @returns True if the video buffer has to be unlocked. * @returns True if the video buffer has to be unlocked.
*/ */
virtual bool LockVideoBuffer() { virtual bool LockVideoBuffer()
{
return false; return false;
} }

View File

@ -434,7 +434,8 @@ bool RiverModifyDesertZone(TileIndex tile, void *)
* Make a river tile and remove desert directly around it. * Make a river tile and remove desert directly around it.
* @param tile The tile to change into river and create non-desert around * @param tile The tile to change into river and create non-desert around
*/ */
void MakeRiverAndModifyDesertZoneAround(TileIndex tile) { void MakeRiverAndModifyDesertZoneAround(TileIndex tile)
{
MakeRiver(tile, Random()); MakeRiver(tile, Random());
MarkTileDirtyByTile(tile); MarkTileDirtyByTile(tile);

View File

@ -483,7 +483,8 @@ public:
* @param widgets list of widgets * @param widgets list of widgets
*/ */
template<typename... Args> template<typename... Args>
void RaiseWidgetsWhenLowered(Args... widgets) { void RaiseWidgetsWhenLowered(Args... widgets)
{
(this->RaiseWidgetWhenLowered(widgets), ...); (this->RaiseWidgetWhenLowered(widgets), ...);
} }