diff --git a/src/3rdparty/squirrel/squirrel/sqobject.cpp b/src/3rdparty/squirrel/squirrel/sqobject.cpp index 1af27a4660..d38fa96131 100644 --- a/src/3rdparty/squirrel/squirrel/sqobject.cpp +++ b/src/3rdparty/squirrel/squirrel/sqobject.cpp @@ -446,11 +446,11 @@ bool SQFunctionProto::Load(SQVM *v,SQUserPointer up,SQREADFUNC read,SQObjectPtr for(i = 0; i < noutervalues; i++){ SQUnsignedInteger type; - SQObjectPtr name; + SQObjectPtr value_name; _CHECK_IO(SafeRead(v,read,up, &type, sizeof(SQUnsignedInteger))); _CHECK_IO(ReadObject(v, up, read, o)); - _CHECK_IO(ReadObject(v, up, read, name)); - f->_outervalues[i] = SQOuterVar(name,o, (SQOuterType)type); + _CHECK_IO(ReadObject(v, up, read, value_name)); + f->_outervalues[i] = SQOuterVar(value_name,o, (SQOuterType)type); } _CHECK_IO(CheckTag(v,read,up,SQ_CLOSURESTREAM_PART)); diff --git a/src/3rdparty/squirrel/squirrel/sqstate.cpp b/src/3rdparty/squirrel/squirrel/sqstate.cpp index f491404d4f..54197aa084 100644 --- a/src/3rdparty/squirrel/squirrel/sqstate.cpp +++ b/src/3rdparty/squirrel/squirrel/sqstate.cpp @@ -246,9 +246,9 @@ void SQSharedState::DelayFinalFree(SQCollectable *collectable) if (!this->_collectable_free_processing) { this->_collectable_free_processing = true; while (!this->_collectable_free_queue.empty()) { - SQCollectable *collectable = this->_collectable_free_queue.back(); + SQCollectable *collectable_to_free = this->_collectable_free_queue.back(); this->_collectable_free_queue.pop_back(); - collectable->FinalFree(); + collectable_to_free->FinalFree(); } this->_collectable_free_processing = false; } diff --git a/src/3rdparty/squirrel/squirrel/sqvm.cpp b/src/3rdparty/squirrel/squirrel/sqvm.cpp index fd41212dfb..e643e25984 100644 --- a/src/3rdparty/squirrel/squirrel/sqvm.cpp +++ b/src/3rdparty/squirrel/squirrel/sqvm.cpp @@ -1064,11 +1064,11 @@ exception_trap: if(traps) { do { if(ci->_etraps > 0) { - SQExceptionTrap &et = _etraps.top(); - ci->_ip = et._ip; - _top = et._stacksize; - _stackbase = et._stackbase; - _stack._vals[_stackbase+et._extarget] = currerror; + SQExceptionTrap &trap = _etraps.top(); + ci->_ip = trap._ip; + _top = trap._stacksize; + _stackbase = trap._stackbase; + _stack._vals[_stackbase+trap._extarget] = currerror; _etraps.pop_back(); traps--; ci->_etraps--; CLEARSTACK(last_top); goto exception_restore; diff --git a/src/base_media_func.h b/src/base_media_func.h index f5a5995f17..a4fa6ed6fd 100644 --- a/src/base_media_func.h +++ b/src/base_media_func.h @@ -48,7 +48,7 @@ bool BaseSet::FillSetDetails(IniFile *ini, const this->description[std::string{}] = *item->value; /* Add the translations of the descriptions too. */ - for (const IniItem *item = metadata->item; item != nullptr; item = item->next) { + for (item = metadata->item; item != nullptr; item = item->next) { if (item->name.compare(0, 12, "description.") != 0) continue; this->description[item->name.substr(12)] = item->value.value_or(""); diff --git a/src/company_gui.cpp b/src/company_gui.cpp index 25128563da..1c10edabcb 100644 --- a/src/company_gui.cpp +++ b/src/company_gui.cpp @@ -685,7 +685,6 @@ private: void ShowColourDropDownMenu(uint32 widget) { uint32 used_colours = 0; - const Company *c; const Livery *livery, *default_livery = nullptr; bool primary = widget == WID_SCL_PRI_COL_DROPDOWN; byte default_col = 0; @@ -697,7 +696,7 @@ private: } } - c = Company::Get((CompanyID)this->window_number); + const Company *c = Company::Get((CompanyID)this->window_number); if (this->livery_class < LC_GROUP_RAIL) { /* Get the first selected livery to use as the default dropdown item */ diff --git a/src/core/backup_type.hpp b/src/core/backup_type.hpp index 8c9c73851b..23beedefb4 100644 --- a/src/core/backup_type.hpp +++ b/src/core/backup_type.hpp @@ -144,4 +144,46 @@ private: const int line; }; +/** + * Class to backup a specific variable and restore it upon destruction of this object to prevent + * stack values going out of scope before resetting the global to its original value. Contrary to + * #Backup this restores the variable automatically and there is no manual option to restore. + */ +template +struct AutoRestoreBackup { + /* + * There is explicitly no only original constructor version, as that would make it possible + * for the new value to go out of scope before this object goes out of scope, thus defeating + * the whole goal and reason for existing of this object. + */ + + /** + * Backup variable and switch to new value. + * @param original Variable to backup. + * @param new_value New value for variable. + */ + AutoRestoreBackup(T &original, T new_value) : original(original), original_value(original) + { + original = new_value; + } + + /** + * Restore the variable upon object destruction. + */ + ~AutoRestoreBackup() + { + this->original = this->original_value; + } + +private: + T &original; + T original_value; + + /* Prevent copy, assignment and allocation on stack. */ + AutoRestoreBackup(const AutoRestoreBackup&) = delete; + AutoRestoreBackup& operator=(AutoRestoreBackup&) = delete; + static void *operator new(std::size_t) = delete; + static void *operator new[](std::size_t) = delete; +}; + #endif /* BACKUP_TYPE_HPP */ diff --git a/src/core/bitmath_func.hpp b/src/core/bitmath_func.hpp index ffdfb2f616..b931205ccd 100644 --- a/src/core/bitmath_func.hpp +++ b/src/core/bitmath_func.hpp @@ -31,7 +31,7 @@ * @return The selected bits, aligned to a LSB. */ template -static inline uint GB(const T x, const uint8 s, const uint8 n) +debug_inline static uint GB(const T x, const uint8 s, const uint8 n) { return (x >> s) & (((T)1U << n) - 1); } @@ -103,7 +103,7 @@ static inline T AB(T &x, const uint8 s, const uint8 n, const U i) * @return True if the bit is set, false else. */ template -static inline bool HasBit(const T x, const uint8 y) +debug_inline static bool HasBit(const T x, const uint8 y) { return (x & ((T)1U << y)) != 0; } diff --git a/src/dock_gui.cpp b/src/dock_gui.cpp index ba4546f891..e64bfa256b 100644 --- a/src/dock_gui.cpp +++ b/src/dock_gui.cpp @@ -25,6 +25,7 @@ #include "hotkeys.h" #include "gui.h" #include "zoom_func.h" +#include "core/backup_type.hpp" #include "widgets/dock_widget.h" @@ -544,15 +545,13 @@ public: Axis axis = widget == WID_BDD_X ? AXIS_X : AXIS_Y; if (FillDrawPixelInfo(&tmp_dpi, r.left, r.top, r.Width(), r.Height())) { - DrawPixelInfo *old_dpi = _cur_dpi; - _cur_dpi = &tmp_dpi; + AutoRestoreBackup dpi_backup(_cur_dpi, &tmp_dpi); int x = (r.Width() - ScaleSpriteTrad(96)) / 2; int y = (r.Height() - ScaleSpriteTrad(64)) / 2; int x1 = ScaleSpriteTrad(63); int x2 = ScaleSpriteTrad(31); DrawShipDepotSprite(x + (axis == AXIS_X ? x1 : x2), y + ScaleSpriteTrad(17), axis, DEPOT_PART_NORTH); DrawShipDepotSprite(x + (axis == AXIS_X ? x2 : x1), y + ScaleSpriteTrad(33), axis, DEPOT_PART_SOUTH); - _cur_dpi = old_dpi; } break; } diff --git a/src/gfx.cpp b/src/gfx.cpp index e43cf32352..85b59c192b 100644 --- a/src/gfx.cpp +++ b/src/gfx.cpp @@ -1367,7 +1367,6 @@ void DoPaletteAnimations() const ExtraPaletteValues *ev = &_extra_palette_values; Colour old_val[PALETTE_ANIM_SIZE]; const uint old_tc = palette_animation_counter; - uint i; uint j; if (blitter != nullptr && blitter->UsePaletteAnimation() == Blitter::PALETTE_ANIMATION_NONE) { @@ -1382,7 +1381,7 @@ void DoPaletteAnimations() /* Fizzy Drink bubbles animation */ s = ev->fizzy_drink; j = EXTR2(512, EPV_CYCLES_FIZZY_DRINK); - for (i = 0; i != EPV_CYCLES_FIZZY_DRINK; i++) { + for (uint i = 0; i != EPV_CYCLES_FIZZY_DRINK; i++) { *palette_pos++ = s[j]; j++; if (j == EPV_CYCLES_FIZZY_DRINK) j = 0; @@ -1391,7 +1390,7 @@ void DoPaletteAnimations() /* Oil refinery fire animation */ s = ev->oil_refinery; j = EXTR2(512, EPV_CYCLES_OIL_REFINERY); - for (i = 0; i != EPV_CYCLES_OIL_REFINERY; i++) { + for (uint i = 0; i != EPV_CYCLES_OIL_REFINERY; i++) { *palette_pos++ = s[j]; j++; if (j == EPV_CYCLES_OIL_REFINERY) j = 0; @@ -1431,7 +1430,7 @@ void DoPaletteAnimations() /* Handle lighthouse and stadium animation */ s = ev->lighthouse; j = EXTR(256, EPV_CYCLES_LIGHTHOUSE); - for (i = 0; i != EPV_CYCLES_LIGHTHOUSE; i++) { + for (uint i = 0; i != EPV_CYCLES_LIGHTHOUSE; i++) { *palette_pos++ = s[j]; j++; if (j == EPV_CYCLES_LIGHTHOUSE) j = 0; @@ -1440,7 +1439,7 @@ void DoPaletteAnimations() /* Dark blue water */ s = (_settings_game.game_creation.landscape == LT_TOYLAND) ? ev->dark_water_toyland : ev->dark_water; j = EXTR(320, EPV_CYCLES_DARK_WATER); - for (i = 0; i != EPV_CYCLES_DARK_WATER; i++) { + for (uint i = 0; i != EPV_CYCLES_DARK_WATER; i++) { *palette_pos++ = s[j]; j++; if (j == EPV_CYCLES_DARK_WATER) j = 0; @@ -1449,7 +1448,7 @@ void DoPaletteAnimations() /* Glittery water */ s = (_settings_game.game_creation.landscape == LT_TOYLAND) ? ev->glitter_water_toyland : ev->glitter_water; j = EXTR(128, EPV_CYCLES_GLITTER_WATER); - for (i = 0; i != EPV_CYCLES_GLITTER_WATER / 3; i++) { + for (uint i = 0; i != EPV_CYCLES_GLITTER_WATER / 3; i++) { *palette_pos++ = s[j]; j += 3; if (j >= EPV_CYCLES_GLITTER_WATER) j -= EPV_CYCLES_GLITTER_WATER; diff --git a/src/industry_cmd.cpp b/src/industry_cmd.cpp index 932216628a..ebf9a3a34d 100644 --- a/src/industry_cmd.cpp +++ b/src/industry_cmd.cpp @@ -664,10 +664,8 @@ void AnimateTile_Industry(TileIndex tile) case GFX_PLASTIC_FOUNTAIN_ANIMATED_5: case GFX_PLASTIC_FOUNTAIN_ANIMATED_6: case GFX_PLASTIC_FOUNTAIN_ANIMATED_7: case GFX_PLASTIC_FOUNTAIN_ANIMATED_8: if ((_scaled_tick_counter & 3) == 0) { - IndustryGfx gfx = GetIndustryGfx(tile); - - gfx = (gfx < 155) ? gfx + 1 : 148; - SetIndustryGfx(tile, gfx); + IndustryGfx new_gfx = (gfx < 155) ? gfx + 1 : 148; + SetIndustryGfx(tile, new_gfx); MarkTileDirtyByTile(tile, VMDF_NOT_MAP_MODE); } break; @@ -677,8 +675,6 @@ void AnimateTile_Industry(TileIndex tile) case GFX_OILWELL_ANIMATED_3: if ((_scaled_tick_counter & 7) == 0) { bool b = Chance16(1, 7); - IndustryGfx gfx = GetIndustryGfx(tile); - byte m = GetAnimationFrame(tile) + 1; if (m == 4 && (m = 0, ++gfx) == GFX_OILWELL_ANIMATED_3 + 1 && (gfx = GFX_OILWELL_ANIMATED_1, b)) { SetIndustryGfx(tile, GFX_OILWELL_NOT_ANIMATED); diff --git a/src/industry_gui.cpp b/src/industry_gui.cpp index ff5ec19a8c..c6082de848 100644 --- a/src/industry_gui.cpp +++ b/src/industry_gui.cpp @@ -2790,12 +2790,12 @@ struct IndustryCargoesWindow : public Window { _displayed_industries_out.set(displayed_it); this->fields.clear(); - CargoesRow &row = this->fields.emplace_back(); - row.columns[0].MakeHeader(STR_INDUSTRY_CARGOES_PRODUCERS); - row.columns[1].MakeEmpty(CFT_SMALL_EMPTY); - row.columns[2].MakeEmpty(CFT_SMALL_EMPTY); - row.columns[3].MakeEmpty(CFT_SMALL_EMPTY); - row.columns[4].MakeHeader(STR_INDUSTRY_CARGOES_CUSTOMERS); + CargoesRow &first_row = this->fields.emplace_back(); + first_row.columns[0].MakeHeader(STR_INDUSTRY_CARGOES_PRODUCERS); + first_row.columns[1].MakeEmpty(CFT_SMALL_EMPTY); + first_row.columns[2].MakeEmpty(CFT_SMALL_EMPTY); + first_row.columns[3].MakeEmpty(CFT_SMALL_EMPTY); + first_row.columns[4].MakeHeader(STR_INDUSTRY_CARGOES_CUSTOMERS); const IndustrySpec *central_sp = GetIndustrySpec(displayed_it); bool houses_supply = HousesCanSupply(central_sp->accepts_cargo, lengthof(central_sp->accepts_cargo)); @@ -2871,12 +2871,12 @@ struct IndustryCargoesWindow : public Window { _displayed_industries_out.reset(); this->fields.clear(); - CargoesRow &row = this->fields.emplace_back(); - row.columns[0].MakeHeader(STR_INDUSTRY_CARGOES_PRODUCERS); - row.columns[1].MakeEmpty(CFT_SMALL_EMPTY); - row.columns[2].MakeHeader(STR_INDUSTRY_CARGOES_CUSTOMERS); - row.columns[3].MakeEmpty(CFT_SMALL_EMPTY); - row.columns[4].MakeEmpty(CFT_SMALL_EMPTY); + CargoesRow &first_row = this->fields.emplace_back(); + first_row.columns[0].MakeHeader(STR_INDUSTRY_CARGOES_PRODUCERS); + first_row.columns[1].MakeEmpty(CFT_SMALL_EMPTY); + first_row.columns[2].MakeHeader(STR_INDUSTRY_CARGOES_CUSTOMERS); + first_row.columns[3].MakeEmpty(CFT_SMALL_EMPTY); + first_row.columns[4].MakeEmpty(CFT_SMALL_EMPTY); bool houses_supply = HousesCanSupply(&cid, 1); bool houses_accept = HousesCanAccept(&cid, 1); @@ -2956,10 +2956,9 @@ struct IndustryCargoesWindow : public Window { if (widget != WID_IC_PANEL) return; Rect ir = r.Shrink(WidgetDimensions::scaled.framerect); - DrawPixelInfo tmp_dpi, *old_dpi; + DrawPixelInfo tmp_dpi; if (!FillDrawPixelInfo(&tmp_dpi, ir.left, ir.top, ir.Width(), ir.Height())) return; - old_dpi = _cur_dpi; - _cur_dpi = &tmp_dpi; + AutoRestoreBackup dpi_backup(_cur_dpi, &tmp_dpi); int left_pos = ir.left; if (this->ind_cargo >= NUM_INDUSTRYTYPES) left_pos += (CargoesField::industry_width + CargoesField::cargo_field_width) / 2; @@ -2988,8 +2987,6 @@ struct IndustryCargoesWindow : public Window { vpos += row_height; if (vpos >= height) break; } - - _cur_dpi = old_dpi; } /** diff --git a/src/lang/catalan.txt b/src/lang/catalan.txt index b8325504b2..b805caf356 100644 --- a/src/lang/catalan.txt +++ b/src/lang/catalan.txt @@ -2713,6 +2713,10 @@ STR_BUILD_SIGNAL_DRAG_SIGNALS_DENSITY_INCREASE_TOOLTIP :{BLACK}Augmenta STR_SELECT_RAIL_BRIDGE_CAPTION :{WHITE}Selecciona Pont de Tren STR_SELECT_ROAD_BRIDGE_CAPTION :{WHITE}Selecciona Pont de Carretera STR_SELECT_BRIDGE_SELECTION_TOOLTIP :{BLACK}Selecció de pont - clica sobre el pont triat per construir-lo +STR_SELECT_BRIDGE_INFO_NAME :{GOLD}{STRING} +STR_SELECT_BRIDGE_INFO_NAME_MAX_SPEED :{GOLD}{STRING},{} {VELOCITY} +STR_SELECT_BRIDGE_INFO_NAME_COST :{GOLD}{0:STRING},{} {WHITE}{2:CURRENCY_LONG} +STR_SELECT_BRIDGE_INFO_NAME_MAX_SPEED_COST :{GOLD}{STRING},{} {VELOCITY} {WHITE}{CURRENCY_LONG} STR_BRIDGE_NAME_SUSPENSION_STEEL :Pont penjant d'acer STR_BRIDGE_NAME_GIRDER_STEEL :Pont biga d'acer STR_BRIDGE_NAME_CANTILEVER_STEEL :Pont en mènsula d'acer diff --git a/src/lang/hebrew.txt b/src/lang/hebrew.txt index e7eb98753b..d196a8c149 100644 --- a/src/lang/hebrew.txt +++ b/src/lang/hebrew.txt @@ -971,6 +971,7 @@ STR_GAME_OPTIONS_AUTOSAVE_DROPDOWN_EVERY_12_MONTHS :כל 12 חוד STR_GAME_OPTIONS_LANGUAGE :{BLACK}שפה STR_GAME_OPTIONS_LANGUAGE_TOOLTIP :{BLACK}בחר את שפת הממשק +STR_GAME_OPTIONS_LANGUAGE_PERCENTAGE :{STRING} ({NUM}% הסתיים) STR_GAME_OPTIONS_FULLSCREEN :{BLACK}מסך מלא STR_GAME_OPTIONS_FULLSCREEN_TOOLTIP :{BLACK}סמן תיבה זו כדי לשחק OpenTTD על כל המסך @@ -1712,6 +1713,7 @@ STR_CONFIG_SETTING_COLOURED_NEWS_YEAR :{STRING} :הצ STR_CONFIG_SETTING_COLOURED_NEWS_YEAR_HELPTEXT :השנה בה הודעות העיתונות מודפסות בצבע. לפני שנה זו הן מודפסות בשחור-לבן. STR_CONFIG_SETTING_STARTING_YEAR :{STRING} :שנת התחלה +STR_CONFIG_SETTING_ENDING_YEAR :ניקוד סוף שנה: {STRING} ###setting-zero-is-special STR_CONFIG_SETTING_ENDING_YEAR_ZERO :לעולם לא @@ -1722,6 +1724,7 @@ STR_CONFIG_SETTING_ECONOMY_TYPE_ORIGINAL :מקורי STR_CONFIG_SETTING_ALLOW_SHARES :אפשר קניית מניות מחברות אחרות: {STRING} STR_CONFIG_SETTING_ALLOW_SHARES_HELPTEXT :כאשר מאופשר, מתיר קנייה ומכירה של מניות של חברות. מניות יהיו זמינות רק עבור חברות המגיעות לגיל מסוים +STR_CONFIG_SETTING_MIN_YEARS_FOR_SHARES :גיל מינימלי לחברה לסחור במניותיה: {STRING} STR_CONFIG_SETTING_FEEDER_PAYMENT_SHARE :אחוז הרווח מקטע נסיעה לתשלום במערכות הזנה: {STRING} STR_CONFIG_SETTING_FEEDER_PAYMENT_SHARE_HELPTEXT :אחוז הרווח הניתן לקטעי ביניים במערכות הזנה, דבר הנותן שליטה מוגברת על ההכנסות @@ -1774,6 +1777,7 @@ STR_CONFIG_SETTING_TOWN_CARGOGENMODE_BITCOUNT :לינארי STR_CONFIG_SETTING_EXTRA_TREE_PLACEMENT :מיקום עצים במהלך המשחק: {STRING} STR_CONFIG_SETTING_EXTRA_TREE_PLACEMENT_HELPTEXT :שלוט בהופעה אקראית של עצים במהלך המשחק. זה עלול להשפיע על תעשיות המסתמכות על צמיחת עצים, לדוגמא מנסרות ###length 4 +STR_CONFIG_SETTING_EXTRA_TREE_PLACEMENT_SPREAD_ALL :גדל ומתפשט בכל מקום STR_CONFIG_SETTING_EXTRA_TREE_PLACEMENT_NO_GROWTH_NO_SPREAD :אל תגדל, אל תתפשט {RED}(שובר מנסרות) STR_CONFIG_SETTING_TOOLBAR_POS :{STRING} :מיקום הסרגל העיקרי @@ -2154,6 +2158,7 @@ STR_NETWORK_SERVER_LIST_GAMESCRIPT :{SILVER}סקר STR_NETWORK_SERVER_LIST_PASSWORD :{SILVER}מוגן בסיסמה! STR_NETWORK_SERVER_LIST_SERVER_OFFLINE :{SILVER}שרת מנותק STR_NETWORK_SERVER_LIST_SERVER_FULL :{SILVER}שרת מלא +STR_NETWORK_SERVER_LIST_SERVER_TOO_OLD :{SILVER}השרת ישן מדי STR_NETWORK_SERVER_LIST_VERSION_MISMATCH :{SILVER}גרסה לא תואמת STR_NETWORK_SERVER_LIST_GRF_MISMATCH :{SILVER}אי התאמת קבצים גרפיים @@ -4336,6 +4341,7 @@ STR_AI_LIST_CANCEL :{BLACK}בטל STR_AI_LIST_CANCEL_TOOLTIP :{BLACK}אל תשנה את התסריט STR_SCREENSHOT_CAPTION :{WHITE}צלם מסך +STR_SCREENSHOT_SCREENSHOT :תמונת מסך רגילה STR_SCREENSHOT_DEFAULTZOOM_SCREENSHOT :{BLACK}זום ברירת מחדל לצילום מסך STR_SCREENSHOT_WORLD_SCREENSHOT :{BLACK}צילום מסך של כל המפה diff --git a/src/lang/turkish.txt b/src/lang/turkish.txt index 942aa17a2e..f2d7ee7c63 100644 --- a/src/lang/turkish.txt +++ b/src/lang/turkish.txt @@ -1937,13 +1937,13 @@ STR_CONFIG_SETTING_LINKGRAPH_TIME :Dağıtım graf STR_CONFIG_SETTING_LINKGRAPH_TIME_HELPTEXT :Bağlantı grafiğini oluşturan parçaların her tekrar hesaplaması için kullanılan zaman. Tekrar hesaplama başlatıldığında bu kadar gün sürecek bir işlem başlatılmış olur. Buraya daha kısa süreler girdikçe işlemin bitmesi gerekirken bitmemiş olma ihtimali artar. Ardından oyun ("lag") olana dek durur. Daha uzun süreler girdiğinizde güzergahlar değiştikçe dağıtımın güncellenmesi daha uzun sürer. STR_CONFIG_SETTING_DISTRIBUTION_PAX :Yolcular için dağıtım kipi: {STRING} -STR_CONFIG_SETTING_DISTRIBUTION_PAX_HELPTEXT :"simetrik" seçildiğinde A durağından B durağına taşınan ile B'den A'ya taşınan yolcu miktarı kabaca eşit olur. "asimetrik" seçildiğinde iki yönde de rastgele miktarda yolcu gönderilebilir. "el ile" seçildiğinde yolcular için otomatik dağıtım yapılmaz. +STR_CONFIG_SETTING_DISTRIBUTION_PAX_HELPTEXT :"Simetrik" seçildiğinde A durağından B durağına taşınan ile B'den A'ya taşınan yolcu miktarı kabaca eşit olur. "Asimetrik" seçildiğinde iki yönde de rastgele miktarda yolcu gönderilebilir. "el ile" seçildiğinde yolcular için otomatik dağıtım yapılmaz. STR_CONFIG_SETTING_DISTRIBUTION_MAIL :Posta için dağıtım kipi: {STRING} -STR_CONFIG_SETTING_DISTRIBUTION_MAIL_HELPTEXT :"simetrik" seçildiğinde A durağından B durağına gönderilen ile B'den A'ya gönderilen posta miktarı kabaca eşit olur. "asimetrik" seçildiğinde iki yönde de rastgele miktarda posta gönderilebilir. "el ile" seçildiğinde posta için otomatik dağıtım yapılmaz. +STR_CONFIG_SETTING_DISTRIBUTION_MAIL_HELPTEXT :"Simetrik" seçildiğinde A durağından B durağına gönderilen ile B'den A'ya gönderilen posta miktarı kabaca eşit olur. "Asimetrik" seçildiğinde iki yönde de rastgele miktarda posta gönderilebilir. "El ile" seçildiğinde posta için otomatik dağıtım yapılmaz. STR_CONFIG_SETTING_DISTRIBUTION_ARMOURED :ZIRHLI kargo sınıfı için dağıtım kipi: {STRING} STR_CONFIG_SETTING_DISTRIBUTION_ARMOURED_HELPTEXT :ZIRHLI kargo sınıfı ılıman iklimde değerli mallar, yarı-tropik iklimde elmaslar, veya yarı-soğuk iklimde altın içerir. NewGRF dosyaları bunu değiştirebilir. "Simetrik" olarak ayarlandığında A durağından B durağına gönderilen kargo miktarı, B'den A'ya gönderilene kabaca eşit olur. "Asimetrik" ise herhangi bir yönde rastgele miktarda kargo gönderilebileceğini gösterir. "El ile" seçildiğinde o kargo için otomatik dağıtım yapılmaz. Yarı-soğuk iklimde oynarken bu değeri "asimetrik" veya "el ile" olarak ayarlamanız tavsiye edilir, çünkü bankalar altınları altın madenine geri göndermez. Ilıman ve yarı-tropik iklim için aynı zamanda "simetrik" seçebilirsiniz, zira bankalar değerli malların bir kısmını malların geldiği kaynak bankaya geri gönderir. STR_CONFIG_SETTING_DISTRIBUTION_DEFAULT :Diğer kargo sınıfları için dağılım kipi: {STRING} -STR_CONFIG_SETTING_DISTRIBUTION_DEFAULT_HELPTEXT :"asimetrik", kargonun iki yönde de rastgele miktarda gönderileceğini gösterir. "el ile" seçildiği takdirde o kargolar için otomatik dağılım yapılmaz. +STR_CONFIG_SETTING_DISTRIBUTION_DEFAULT_HELPTEXT :"Asimetrik", kargonun iki yönde de rastgele miktarda gönderileceğini gösterir. "El ile" seçildiği takdirde o kargolar için otomatik dağılım yapılmaz. ###length 3 STR_CONFIG_SETTING_DISTRIBUTION_MANUAL :el ile (manual) STR_CONFIG_SETTING_DISTRIBUTION_ASYMMETRIC :asimetrik @@ -2712,6 +2712,10 @@ STR_BUILD_SIGNAL_DRAG_SIGNALS_DENSITY_INCREASE_TOOLTIP :{BLACK}Sinyal s STR_SELECT_RAIL_BRIDGE_CAPTION :{WHITE}Tren Köprüsü Seç STR_SELECT_ROAD_BRIDGE_CAPTION :{WHITE}Köprü Seç STR_SELECT_BRIDGE_SELECTION_TOOLTIP :{BLACK}Köprü seçimi - tercih ettiğiniz köprüyü yapmak için tıklayın +STR_SELECT_BRIDGE_INFO_NAME :{GOLD}{STRING} +STR_SELECT_BRIDGE_INFO_NAME_MAX_SPEED :{GOLD}{STRING},{} {VELOCITY} +STR_SELECT_BRIDGE_INFO_NAME_COST :{GOLD}{0:STRING},{} {WHITE}{2:CURRENCY_LONG} +STR_SELECT_BRIDGE_INFO_NAME_MAX_SPEED_COST :{GOLD}{STRING},{} {VELOCITY} {WHITE}{CURRENCY_LONG} STR_BRIDGE_NAME_SUSPENSION_STEEL :Çelik, Asma STR_BRIDGE_NAME_GIRDER_STEEL :Çelik, Kirişli STR_BRIDGE_NAME_CANTILEVER_STEEL :Çelik, Ağ diff --git a/src/map_func.h b/src/map_func.h index a2ce2e1e28..0436293c7a 100644 --- a/src/map_func.h +++ b/src/map_func.h @@ -161,7 +161,7 @@ typedef int32 TileIndexDiff; * @param y The y coordinate of the tile * @return The TileIndex calculated by the coordinate */ -static inline TileIndex TileXY(uint x, uint y) +debug_inline static TileIndex TileXY(uint x, uint y) { return (y << MapLogX()) + x; } @@ -192,7 +192,7 @@ static inline TileIndexDiff TileDiffXY(int x, int y) * @param y The virtual y coordinate of the tile. * @return The TileIndex calculated by the coordinate. */ -static inline TileIndex TileVirtXY(uint x, uint y) +debug_inline static TileIndex TileVirtXY(uint x, uint y) { return (y >> 4 << MapLogX()) + (x >> 4); } @@ -216,7 +216,7 @@ static inline TileIndex TileVirtXYClampedToMap(int x, int y) * @param tile the tile to get the X component of * @return the X component */ -static inline uint TileX(TileIndex tile) +debug_inline static uint TileX(TileIndex tile) { return tile & MapMaxX(); } @@ -226,7 +226,7 @@ static inline uint TileX(TileIndex tile) * @param tile the tile to get the Y component of * @return the Y component */ -static inline uint TileY(TileIndex tile) +debug_inline static uint TileY(TileIndex tile) { return tile >> MapLogX(); } diff --git a/src/misc_gui.cpp b/src/misc_gui.cpp index 58666280bc..3aade766d6 100644 --- a/src/misc_gui.cpp +++ b/src/misc_gui.cpp @@ -29,6 +29,7 @@ #include "guitimer_func.h" #include "viewport_func.h" #include "rev.h" +#include "core/backup_type.hpp" #include "widgets/misc_widget.h" @@ -893,8 +894,7 @@ void QueryString::DrawEditBox(const Window *w, int wid) const DrawPixelInfo dpi; if (!FillDrawPixelInfo(&dpi, fr.left, fr.top, fr.Width(), fr.Height())) return; - DrawPixelInfo *old_dpi = _cur_dpi; - _cur_dpi = &dpi; + AutoRestoreBackup dpi_backup(_cur_dpi, &dpi); /* We will take the current widget length as maximum width, with a small * space reserved at the end for the caret to show */ @@ -912,8 +912,6 @@ void QueryString::DrawEditBox(const Window *w, int wid) const int caret_width = GetStringBoundingBox("_").width; DrawString(tb->caretxoffs + delta, tb->caretxoffs + delta + caret_width, 0, "_", TC_WHITE); } - - _cur_dpi = old_dpi; } /** diff --git a/src/network/network_content.cpp b/src/network/network_content.cpp index 8091939ff3..c28d0cc376 100644 --- a/src/network/network_content.cpp +++ b/src/network/network_content.cpp @@ -1060,11 +1060,11 @@ void ClientNetworkContentSocketHandler::CheckDependencyState(ContentInfo *ci) * After that's done run over them once again to test their children * to unselect. Don't do it immediately because it'll do exactly what * we're doing now. */ - for (const ContentInfo *c : parents) { - if (c->state == ContentInfo::AUTOSELECTED) this->Unselect(c->id); + for (const ContentInfo *parent : parents) { + if (parent->state == ContentInfo::AUTOSELECTED) this->Unselect(parent->id); } - for (const ContentInfo *c : parents) { - this->CheckDependencyState(this->GetContent(c->id)); + for (const ContentInfo *parent : parents) { + this->CheckDependencyState(this->GetContent(parent->id)); } } } diff --git a/src/newgrf.cpp b/src/newgrf.cpp index 63ef07175f..360916feb8 100644 --- a/src/newgrf.cpp +++ b/src/newgrf.cpp @@ -4510,13 +4510,13 @@ static ChangeInfoResult RailTypeChangeInfo(uint id, int numinfo, int prop, const int n = buf->ReadByte(); for (int j = 0; j != n; j++) { RailTypeLabel label = buf->ReadDWord(); - RailType rt = GetRailTypeByLabel(BSWAP32(label), false); - if (rt != INVALID_RAILTYPE) { + RailType resolved_rt = GetRailTypeByLabel(BSWAP32(label), false); + if (resolved_rt != INVALID_RAILTYPE) { switch (prop) { - case 0x0F: SetBit(rti->powered_railtypes, rt); FALLTHROUGH; // Powered implies compatible. - case 0x0E: SetBit(rti->compatible_railtypes, rt); break; - case 0x18: SetBit(rti->introduction_required_railtypes, rt); break; - case 0x19: SetBit(rti->introduces_railtypes, rt); break; + case 0x0F: SetBit(rti->powered_railtypes, resolved_rt); FALLTHROUGH; // Powered implies compatible. + case 0x0E: SetBit(rti->compatible_railtypes, resolved_rt); break; + case 0x18: SetBit(rti->introduction_required_railtypes, resolved_rt); break; + case 0x19: SetBit(rti->introduces_railtypes, resolved_rt); break; } } } @@ -4763,12 +4763,12 @@ static ChangeInfoResult RoadTypeChangeInfo(uint id, int numinfo, int prop, const int n = buf->ReadByte(); for (int j = 0; j != n; j++) { RoadTypeLabel label = buf->ReadDWord(); - RoadType rt = GetRoadTypeByLabel(BSWAP32(label), false); - if (rt != INVALID_ROADTYPE) { + RoadType resolved_rt = GetRoadTypeByLabel(BSWAP32(label), false); + if (resolved_rt != INVALID_ROADTYPE) { switch (prop) { - case 0x0F: SetBit(rti->powered_roadtypes, rt); break; - case 0x18: SetBit(rti->introduction_required_roadtypes, rt); break; - case 0x19: SetBit(rti->introduces_roadtypes, rt); break; + case 0x0F: SetBit(rti->powered_roadtypes, resolved_rt); break; + case 0x18: SetBit(rti->introduction_required_roadtypes, resolved_rt); break; + case 0x19: SetBit(rti->introduces_roadtypes, resolved_rt); break; } } } diff --git a/src/newgrf_debug_gui.cpp b/src/newgrf_debug_gui.cpp index 38cd120685..bdf874504c 100644 --- a/src/newgrf_debug_gui.cpp +++ b/src/newgrf_debug_gui.cpp @@ -10,6 +10,7 @@ #include "stdafx.h" #include #include +#include "core/backup_type.hpp" #include "window_gui.h" #include "window_func.h" #include "random_access_file_type.h" @@ -1324,17 +1325,13 @@ struct SpriteAlignerWindow : Window { DrawPixelInfo new_dpi; if (!FillDrawPixelInfo(&new_dpi, ir.left, ir.top, ir.Width(), ir.Height())) break; - DrawPixelInfo *old_dpi = _cur_dpi; - _cur_dpi = &new_dpi; + AutoRestoreBackup dpi_backup(_cur_dpi, &new_dpi); DrawSprite(this->current_sprite, PAL_NONE, x, y, nullptr, ZOOM_LVL_GUI); if (this->crosshair) { GfxDrawLine(x, 0, x, ir.Height() - 1, PC_WHITE, 1, 1); GfxDrawLine(0, y, ir.Width() - 1, y, PC_WHITE, 1, 1); } - - _cur_dpi = old_dpi; - break; } diff --git a/src/newgrf_gui.cpp b/src/newgrf_gui.cpp index 9d854076ee..1e1b066408 100644 --- a/src/newgrf_gui.cpp +++ b/src/newgrf_gui.cpp @@ -1289,16 +1289,16 @@ struct NewGRFWindow : public Window, NewGRFScanCallback { WIDGET_LIST_END ); - const GRFConfig *c = (this->avail_sel == nullptr) ? this->active_sel : this->avail_sel; + const GRFConfig *selected_config = (this->avail_sel == nullptr) ? this->active_sel : this->avail_sel; for (TextfileType tft = TFT_BEGIN; tft < TFT_END; tft++) { - this->SetWidgetDisabledState(WID_NS_NEWGRF_TEXTFILE + tft, c == nullptr || c->GetTextfile(tft) == nullptr); + this->SetWidgetDisabledState(WID_NS_NEWGRF_TEXTFILE + tft, selected_config == nullptr || selected_config->GetTextfile(tft) == nullptr); } - this->SetWidgetDisabledState(WID_NS_OPEN_URL, c == nullptr || StrEmpty(c->GetURL())); + this->SetWidgetDisabledState(WID_NS_OPEN_URL, selected_config == nullptr || StrEmpty(selected_config->GetURL())); this->SetWidgetDisabledState(WID_NS_SET_PARAMETERS, !this->show_params || this->active_sel == nullptr || this->active_sel->num_valid_params == 0); this->SetWidgetDisabledState(WID_NS_VIEW_PARAMETERS, !this->show_params || this->active_sel == nullptr || this->active_sel->num_valid_params == 0); this->SetWidgetDisabledState(WID_NS_TOGGLE_PALETTE, disable_all || - (!(_settings_client.gui.newgrf_developer_tools || _settings_client.gui.scenario_developer) && ((c->palette & GRFP_GRF_MASK) != GRFP_GRF_UNSET))); + (!(_settings_client.gui.newgrf_developer_tools || _settings_client.gui.scenario_developer) && ((selected_config->palette & GRFP_GRF_MASK) != GRFP_GRF_UNSET))); if (!disable_all) { /* All widgets are now enabled, so disable widgets we can't use */ diff --git a/src/object_gui.cpp b/src/object_gui.cpp index 78ead21f9a..09ca2ce95c 100644 --- a/src/object_gui.cpp +++ b/src/object_gui.cpp @@ -24,6 +24,7 @@ #include "window_gui.h" #include "window_func.h" #include "zoom_func.h" +#include "core/backup_type.hpp" #include "widgets/object_widget.h" @@ -360,8 +361,7 @@ public: DrawPixelInfo tmp_dpi; /* Set up a clipping area for the preview. */ if (FillDrawPixelInfo(&tmp_dpi, r.left, r.top, r.Width(), r.Height())) { - DrawPixelInfo *old_dpi = _cur_dpi; - _cur_dpi = &tmp_dpi; + AutoRestoreBackup dpi_backup(_cur_dpi, &tmp_dpi); if (spec->grf_prop.grffile == nullptr) { extern const DrawTileSprites _objects[]; const DrawTileSprites *dts = &_objects[spec->grf_prop.local_id]; @@ -369,7 +369,6 @@ public: } else { DrawNewObjectTileInGUI(r.Width() / 2 - 1, (r.Height() + matrix_height / 2) / 2 - this->object_margin - ScaleSpriteTrad(TILE_PIXELS), spec, GB(widget, 16, 16)); } - _cur_dpi = old_dpi; } break; } @@ -387,8 +386,7 @@ public: DrawPixelInfo tmp_dpi; /* Set up a clipping area for the preview. */ if (FillDrawPixelInfo(&tmp_dpi, r.left, r.top, r.Width(), r.Height())) { - DrawPixelInfo *old_dpi = _cur_dpi; - _cur_dpi = &tmp_dpi; + AutoRestoreBackup dpi_backup(_cur_dpi, &tmp_dpi); if (spec->grf_prop.grffile == nullptr) { extern const DrawTileSprites _objects[]; const DrawTileSprites *dts = &_objects[spec->grf_prop.local_id]; @@ -397,7 +395,6 @@ public: DrawNewObjectTileInGUI(r.Width() / 2 - 1, r.Height() - this->object_margin - ScaleSpriteTrad(TILE_PIXELS), spec, std::min(_selected_object_view, spec->views - 1)); } - _cur_dpi = old_dpi; } break; } diff --git a/src/openttd.cpp b/src/openttd.cpp index 34bf6836ee..f822147998 100644 --- a/src/openttd.cpp +++ b/src/openttd.cpp @@ -1980,7 +1980,7 @@ void StateGameLoop() #ifndef DEBUG_DUMP_COMMANDS { - PerformanceMeasurer framerate(PFE_ALLSCRIPTS); + PerformanceMeasurer script_framerate(PFE_ALLSCRIPTS); AI::GameLoop(); Game::GameLoop(); } diff --git a/src/order_cmd.cpp b/src/order_cmd.cpp index 016f937e9b..8347603f2e 100644 --- a/src/order_cmd.cpp +++ b/src/order_cmd.cpp @@ -2402,7 +2402,7 @@ CommandCost CmdCloneOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 /* Sanity checks */ if (src == nullptr || !src->IsPrimaryVehicle() || dst->type != src->type || dst == src) return CMD_ERROR; - CommandCost ret = CheckOwnership(src->owner); + ret = CheckOwnership(src->owner); if (ret.Failed()) return ret; /* Trucks can't share orders with busses (and visa versa) */ @@ -2495,7 +2495,7 @@ CommandCost CmdCloneOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 /* Sanity checks */ if (src == nullptr || !src->IsPrimaryVehicle() || dst->type != src->type || dst == src) return CMD_ERROR; - CommandCost ret = CheckOwnership(src->owner); + ret = CheckOwnership(src->owner); if (ret.Failed()) return ret; /* Trucks can't copy all the orders from busses (and visa versa), @@ -2754,7 +2754,7 @@ void RemoveOrderFromAllVehicles(OrderType type, DestinationID destination, bool for (Vehicle *v : Vehicle::Iterate()) { Order *order = &v->current_order; if ((v->type == VEH_AIRCRAFT && order->IsType(OT_GOTO_DEPOT) && !hangar ? OT_GOTO_STATION : order->GetType()) == type && - (!hangar || v->type == VEH_AIRCRAFT) && v->current_order.GetDestination() == destination) { + (!hangar || v->type == VEH_AIRCRAFT) && order->GetDestination() == destination) { order->MakeDummy(); SetWindowDirty(WC_VEHICLE_VIEW, v->index); } diff --git a/src/pathfinder/follow_track.hpp b/src/pathfinder/follow_track.hpp index 652bae8f12..06f28c32d7 100644 --- a/src/pathfinder/follow_track.hpp +++ b/src/pathfinder/follow_track.hpp @@ -87,11 +87,11 @@ struct CFollowTrackT m_railtypes = railtype_override; } - inline static TransportType TT() { return Ttr_type_; } - inline static bool IsWaterTT() { return TT() == TRANSPORT_WATER; } - inline static bool IsRailTT() { return TT() == TRANSPORT_RAIL; } + debug_inline static TransportType TT() { return Ttr_type_; } + debug_inline static bool IsWaterTT() { return TT() == TRANSPORT_WATER; } + debug_inline static bool IsRailTT() { return TT() == TRANSPORT_RAIL; } inline bool IsTram() const { return IsRoadTT() && RoadTypeIsTram(RoadVehicle::From(m_veh)->roadtype); } - inline static bool IsRoadTT() { return TT() == TRANSPORT_ROAD; } + debug_inline static bool IsRoadTT() { return TT() == TRANSPORT_ROAD; } inline static bool Allow90degTurns() { return T90deg_turns_allowed_; } inline static bool DoTrackMasking() { return Tmask_reserved_tracks; } diff --git a/src/rail_cmd.cpp b/src/rail_cmd.cpp index c73b1b0bb7..7710f95b14 100644 --- a/src/rail_cmd.cpp +++ b/src/rail_cmd.cpp @@ -831,7 +831,7 @@ CommandCost CmdBuildSingleRail(TileIndex tile, DoCommandFlag flags, uint32 p1, u /* Disallow breaking end-of-line of someone else * so trams can still reverse on this tile. */ if (Company::IsValidID(tram_owner) && HasExactlyOneBit(tram)) { - CommandCost ret = CheckOwnership(tram_owner); + ret = CheckOwnership(tram_owner); if (ret.Failed()) return ret; } diff --git a/src/rail_gui.cpp b/src/rail_gui.cpp index 96a65d36c9..899782de06 100644 --- a/src/rail_gui.cpp +++ b/src/rail_gui.cpp @@ -39,6 +39,7 @@ #include "tracerestrict.h" #include "programmable_signals.h" #include "newgrf_newsignals.h" +#include "core/backup_type.hpp" #include "station_map.h" #include "tunnelbridge_map.h" @@ -1399,28 +1400,24 @@ public: case WID_BRAS_PLATFORM_DIR_X: /* Set up a clipping area for the '/' station preview */ if (FillDrawPixelInfo(&tmp_dpi, r.left, r.top, r.Width(), r.Height())) { - DrawPixelInfo *old_dpi = _cur_dpi; - _cur_dpi = &tmp_dpi; + AutoRestoreBackup dpi_backup(_cur_dpi, &tmp_dpi); int x = (r.Width() - ScaleSpriteTrad(64)) / 2 + ScaleSpriteTrad(31); int y = (r.Height() + ScaleSpriteTrad(58)) / 2 - ScaleSpriteTrad(31); if (!DrawStationTile(x, y, _cur_railtype, AXIS_X, _railstation.station_class, _railstation.station_type)) { StationPickerDrawSprite(x, y, STATION_RAIL, _cur_railtype, INVALID_ROADTYPE, 2); } - _cur_dpi = old_dpi; } break; case WID_BRAS_PLATFORM_DIR_Y: /* Set up a clipping area for the '\' station preview */ if (FillDrawPixelInfo(&tmp_dpi, r.left, r.top, r.Width(), r.Height())) { - DrawPixelInfo *old_dpi = _cur_dpi; - _cur_dpi = &tmp_dpi; + AutoRestoreBackup dpi_backup(_cur_dpi, &tmp_dpi); int x = (r.Width() - ScaleSpriteTrad(64)) / 2 + ScaleSpriteTrad(31); int y = (r.Height() + ScaleSpriteTrad(58)) / 2 - ScaleSpriteTrad(31); if (!DrawStationTile(x, y, _cur_railtype, AXIS_Y, _railstation.station_class, _railstation.station_type)) { StationPickerDrawSprite(x, y, STATION_RAIL, _cur_railtype, INVALID_ROADTYPE, 3); } - _cur_dpi = old_dpi; } break; @@ -1450,14 +1447,12 @@ public: /* Set up a clipping area for the station preview. */ if (FillDrawPixelInfo(&tmp_dpi, r.left, r.top, r.Width(), r.Height())) { - DrawPixelInfo *old_dpi = _cur_dpi; - _cur_dpi = &tmp_dpi; + AutoRestoreBackup dpi_backup(_cur_dpi, &tmp_dpi); int x = (r.Width() - ScaleSpriteTrad(64)) / 2 + ScaleSpriteTrad(31); int y = (r.Height() + ScaleSpriteTrad(58)) / 2 - ScaleSpriteTrad(31); if (!DrawStationTile(x, y, _cur_railtype, _railstation.orientation, _railstation.station_class, type)) { StationPickerDrawSprite(x, y, STATION_RAIL, _cur_railtype, INVALID_ROADTYPE, 2 + _railstation.orientation); } - _cur_dpi = old_dpi; } break; } @@ -2302,12 +2297,10 @@ struct BuildRailDepotWindow : public PickerWindowBase { DrawPixelInfo tmp_dpi; if (FillDrawPixelInfo(&tmp_dpi, r.left, r.top, r.Width(), r.Height())) { - DrawPixelInfo *old_dpi = _cur_dpi; - _cur_dpi = &tmp_dpi; + AutoRestoreBackup dpi_backup(_cur_dpi, &tmp_dpi); int x = (r.Width() - ScaleSpriteTrad(64)) / 2 + ScaleSpriteTrad(31); int y = (r.Height() + ScaleSpriteTrad(48)) / 2 - ScaleSpriteTrad(31); DrawTrainDepotSprite(x, y, widget - WID_BRAD_DEPOT_NE + DIAGDIR_NE, _cur_railtype); - _cur_dpi = old_dpi; } } @@ -2414,12 +2407,10 @@ struct BuildRailWaypointWindow : PickerWindowBase { DrawPixelInfo tmp_dpi; if (FillDrawPixelInfo(&tmp_dpi, r.left, r.top, r.Width(), r.Height())) { - DrawPixelInfo *old_dpi = _cur_dpi; - _cur_dpi = &tmp_dpi; + AutoRestoreBackup dpi_backup(_cur_dpi, &tmp_dpi); int x = (r.Width() - ScaleSpriteTrad(64)) / 2 + ScaleSpriteTrad(31); int y = (r.Height() + ScaleSpriteTrad(58)) / 2 - ScaleSpriteTrad(31); DrawWaypointSprite(x, y, type, _cur_railtype); - _cur_dpi = old_dpi; } if (!IsStationAvailable(statspec)) { diff --git a/src/rail_map.h b/src/rail_map.h index 42439fbbd9..ebe89c729c 100644 --- a/src/rail_map.h +++ b/src/rail_map.h @@ -34,7 +34,7 @@ enum RailTileType { * @pre IsTileType(t, MP_RAILWAY) * @return the RailTileType */ -static inline RailTileType GetRailTileType(TileIndex t) +debug_inline static RailTileType GetRailTileType(TileIndex t) { dbg_assert_tile(IsTileType(t, MP_RAILWAY), t); return (RailTileType)GB(_m[t].m5, 6, 2); @@ -47,7 +47,7 @@ static inline RailTileType GetRailTileType(TileIndex t) * @pre IsTileType(t, MP_RAILWAY) * @return true if and only if the tile is normal rail (with or without signals) */ -static inline bool IsPlainRail(TileIndex t) +debug_inline static bool IsPlainRail(TileIndex t) { RailTileType rtt = GetRailTileType(t); return rtt == RAIL_TILE_NORMAL || rtt == RAIL_TILE_SIGNALS; @@ -58,7 +58,7 @@ static inline bool IsPlainRail(TileIndex t) * @param t the tile to get the information from * @return true if and only if the tile is normal rail (with or without signals) */ -static inline bool IsPlainRailTile(TileIndex t) +debug_inline static bool IsPlainRailTile(TileIndex t) { return IsTileType(t, MP_RAILWAY) && IsPlainRail(t); } @@ -93,7 +93,7 @@ static inline void SetHasSignals(TileIndex tile, bool signals) * @pre IsTileType(t, MP_RAILWAY) * @return true if and only if the tile is a rail depot */ -static inline bool IsRailDepot(TileIndex t) +debug_inline static bool IsRailDepot(TileIndex t) { return GetRailTileType(t) == RAIL_TILE_DEPOT; } @@ -103,7 +103,7 @@ static inline bool IsRailDepot(TileIndex t) * @param t the tile to get the information from * @return true if and only if the tile is a rail depot */ -static inline bool IsRailDepotTile(TileIndex t) +debug_inline static bool IsRailDepotTile(TileIndex t) { return IsTileType(t, MP_RAILWAY) && IsRailDepot(t); } diff --git a/src/road_cmd.cpp b/src/road_cmd.cpp index 7010d6f223..7a606d17ab 100644 --- a/src/road_cmd.cpp +++ b/src/road_cmd.cpp @@ -2282,7 +2282,7 @@ static void DrawTile_Road(TileInfo *ti, DrawTileProcParams params) /* Draw rail/PBS overlay */ bool draw_pbs = _game_mode != GM_MENU && _settings_client.gui.show_track_reservation && HasCrossingReservation(ti->tile); if (rti->UsesOverlay()) { - PaletteID pal = draw_pbs ? PALETTE_CRASH : PAL_NONE; + pal = draw_pbs ? PALETTE_CRASH : PAL_NONE; SpriteID rail = GetCustomRailSprite(rti, ti->tile, RTSG_CROSSING) + axis; DrawGroundSprite(rail, pal); @@ -2329,7 +2329,7 @@ static void DrawTile_Road(TileInfo *ti, DrawTileProcParams params) } } else if (draw_pbs || tram_rti != nullptr || road_rti->UsesOverlay()) { /* Add another rail overlay, unless there is only the base road sprite. */ - PaletteID pal = draw_pbs ? PALETTE_CRASH : PAL_NONE; + pal = draw_pbs ? PALETTE_CRASH : PAL_NONE; SpriteID rail = GetCrossingRoadAxis(ti->tile) == AXIS_Y ? GetRailTypeInfo(GetRailType(ti->tile))->base_sprites.single_x : GetRailTypeInfo(GetRailType(ti->tile))->base_sprites.single_y; DrawGroundSprite(rail, pal); } diff --git a/src/road_gui.cpp b/src/road_gui.cpp index c85dafcc6e..95b7572a92 100644 --- a/src/road_gui.cpp +++ b/src/road_gui.cpp @@ -40,6 +40,7 @@ #include "sortlist_type.h" #include "stringfilter_type.h" #include "string_func.h" +#include "core/backup_type.hpp" #include "widgets/road_widget.h" #include "table/strings.h" @@ -1139,12 +1140,10 @@ struct BuildRoadDepotWindow : public PickerWindowBase { DrawPixelInfo tmp_dpi; if (FillDrawPixelInfo(&tmp_dpi, r.left, r.top, r.Width(), r.Height())) { - DrawPixelInfo *old_dpi = _cur_dpi; - _cur_dpi = &tmp_dpi; + AutoRestoreBackup dpi_backup(_cur_dpi, &tmp_dpi); int x = (r.Width() - ScaleSpriteTrad(64)) / 2 + ScaleSpriteTrad(31); int y = (r.Height() + ScaleSpriteTrad(48)) / 2 - ScaleSpriteTrad(31); DrawRoadDepotSprite(x, y, (DiagDirection)(widget - WID_BROD_DEPOT_NE + DIAGDIR_NE), _cur_roadtype); - _cur_dpi = old_dpi; } } @@ -1564,8 +1563,7 @@ public: bool disabled = (spec != nullptr && widget < WID_BROS_STATION_X && HasBit(spec->flags, RSF_DRIVE_THROUGH_ONLY)); DrawPixelInfo tmp_dpi; if (FillDrawPixelInfo(&tmp_dpi, r.left, r.top, r.Width(), r.Height())) { - DrawPixelInfo *old_dpi = _cur_dpi; - _cur_dpi = &tmp_dpi; + AutoRestoreBackup dpi_backup(_cur_dpi, &tmp_dpi); int x = (r.Width() - ScaleSpriteTrad(64)) / 2 + ScaleSpriteTrad(31); int y = (r.Height() + ScaleSpriteTrad(48)) / 2 - ScaleSpriteTrad(31); if (spec != nullptr && spec->height > 2) y += (spec->height - 2) * ScaleSpriteTrad(4); @@ -1575,7 +1573,6 @@ public: } else { DrawRoadStopTile(x, y, _cur_roadtype, spec, st, widget - WID_BROS_STATION_NE); } - _cur_dpi = old_dpi; } break; } @@ -1607,8 +1604,7 @@ public: } if (FillDrawPixelInfo(&tmp_dpi, r.left, r.top, r.right - r.left + 1, r.bottom - r.top + 1)) { - DrawPixelInfo *old_dpi = _cur_dpi; - _cur_dpi = &tmp_dpi; + AutoRestoreBackup dpi_backup(_cur_dpi, &tmp_dpi); int x = (r.Width() - ScaleSpriteTrad(64)) / 2 + ScaleSpriteTrad(31); int y = (r.Height() + ScaleSpriteTrad(48)) / 2 - ScaleSpriteTrad(31); if (spec == nullptr) { @@ -1618,7 +1614,6 @@ public: if (orientation < DIAGDIR_END && HasBit(spec->flags, RSF_DRIVE_THROUGH_ONLY)) orientation = DIAGDIR_END; DrawRoadStopTile(x, y, _cur_roadtype, spec, st, (uint8)orientation); } - _cur_dpi = old_dpi; } break; } diff --git a/src/road_map.h b/src/road_map.h index bc0710061c..a9dce6800b 100644 --- a/src/road_map.h +++ b/src/road_map.h @@ -52,7 +52,7 @@ static inline bool MayHaveRoad(TileIndex t) * @pre IsTileType(t, MP_ROAD) * @return The road tile type. */ -static inline RoadTileType GetRoadTileType(TileIndex t) +debug_inline static RoadTileType GetRoadTileType(TileIndex t) { dbg_assert_tile(IsTileType(t, MP_ROAD), t); return (RoadTileType)GB(_m[t].m5, 6, 2); @@ -64,7 +64,7 @@ static inline RoadTileType GetRoadTileType(TileIndex t) * @pre IsTileType(t, MP_ROAD) * @return True if normal road. */ -static inline bool IsNormalRoad(TileIndex t) +debug_inline static bool IsNormalRoad(TileIndex t) { return GetRoadTileType(t) == ROAD_TILE_NORMAL; } @@ -74,7 +74,7 @@ static inline bool IsNormalRoad(TileIndex t) * @param t Tile to query. * @return True if normal road tile. */ -static inline bool IsNormalRoadTile(TileIndex t) +debug_inline static bool IsNormalRoadTile(TileIndex t) { return IsTileType(t, MP_ROAD) && IsNormalRoad(t); } @@ -106,7 +106,7 @@ static inline bool IsLevelCrossingTile(TileIndex t) * @pre IsTileType(t, MP_ROAD) * @return True if road depot. */ -static inline bool IsRoadDepot(TileIndex t) +debug_inline static bool IsRoadDepot(TileIndex t) { return GetRoadTileType(t) == ROAD_TILE_DEPOT; } @@ -116,7 +116,7 @@ static inline bool IsRoadDepot(TileIndex t) * @param t Tile to query. * @return True if road depot tile. */ -static inline bool IsRoadDepotTile(TileIndex t) +debug_inline static bool IsRoadDepotTile(TileIndex t) { return IsTileType(t, MP_ROAD) && IsRoadDepot(t); } diff --git a/src/roadveh_gui.cpp b/src/roadveh_gui.cpp index 0f076228cc..ef38835a67 100644 --- a/src/roadveh_gui.cpp +++ b/src/roadveh_gui.cpp @@ -8,6 +8,7 @@ /** @file roadveh_gui.cpp GUI for road vehicles. */ #include "stdafx.h" +#include "core/backup_type.hpp" #include "roadveh.h" #include "window_gui.h" #include "strings_func.h" @@ -136,13 +137,12 @@ void DrawRoadVehImage(const Vehicle *v, const Rect &r, VehicleID selection, Engi Direction dir = rtl ? DIR_E : DIR_W; const RoadVehicle *u = RoadVehicle::From(v); - DrawPixelInfo tmp_dpi, *old_dpi; + DrawPixelInfo tmp_dpi; int max_width = r.Width(); if (!FillDrawPixelInfo(&tmp_dpi, r.left, r.top, r.Width(), r.Height())) return; - old_dpi = _cur_dpi; - _cur_dpi = &tmp_dpi; + AutoRestoreBackup dpi_backup(_cur_dpi, &tmp_dpi); int px = rtl ? max_width + skip : -skip; int y = r.Height() / 2; @@ -161,8 +161,6 @@ void DrawRoadVehImage(const Vehicle *v, const Rect &r, VehicleID selection, Engi px += rtl ? -width : width; } - _cur_dpi = old_dpi; - if (v->index == selection) { int height = ScaleSpriteTrad(12); Rect hr = {(rtl ? px : 0), 0, (rtl ? max_width : px) - 1, height - 1}; diff --git a/src/saveload/oldloader_sl.cpp b/src/saveload/oldloader_sl.cpp index ad9edd210e..7599110d7c 100644 --- a/src/saveload/oldloader_sl.cpp +++ b/src/saveload/oldloader_sl.cpp @@ -385,11 +385,13 @@ static bool FixTTOEngines() } /* Load the default engine set. Many of them will be overridden later */ - uint j = 0; - for (uint i = 0; i < lengthof(_orig_rail_vehicle_info); i++, j++) new (GetTempDataEngine(j)) Engine(VEH_TRAIN, i); - for (uint i = 0; i < lengthof(_orig_road_vehicle_info); i++, j++) new (GetTempDataEngine(j)) Engine(VEH_ROAD, i); - for (uint i = 0; i < lengthof(_orig_ship_vehicle_info); i++, j++) new (GetTempDataEngine(j)) Engine(VEH_SHIP, i); - for (uint i = 0; i < lengthof(_orig_aircraft_vehicle_info); i++, j++) new (GetTempDataEngine(j)) Engine(VEH_AIRCRAFT, i); + { + uint j = 0; + for (uint i = 0; i < lengthof(_orig_rail_vehicle_info); i++, j++) new (GetTempDataEngine(j)) Engine(VEH_TRAIN, i); + for (uint i = 0; i < lengthof(_orig_road_vehicle_info); i++, j++) new (GetTempDataEngine(j)) Engine(VEH_ROAD, i); + for (uint i = 0; i < lengthof(_orig_ship_vehicle_info); i++, j++) new (GetTempDataEngine(j)) Engine(VEH_SHIP, i); + for (uint i = 0; i < lengthof(_orig_aircraft_vehicle_info); i++, j++) new (GetTempDataEngine(j)) Engine(VEH_AIRCRAFT, i); + } Date aging_date = std::min(_date + DAYS_TILL_ORIGINAL_BASE_YEAR, ConvertYMDToDate(2050, 0, 1)); diff --git a/src/saveload/upstream/saveload.cpp b/src/saveload/upstream/saveload.cpp index 0f8e4fc7d1..b682f00e1c 100644 --- a/src/saveload/upstream/saveload.cpp +++ b/src/saveload/upstream/saveload.cpp @@ -1697,26 +1697,26 @@ std::vector SlTableHeader(const SaveLoadTable &slt) DEBUG(sl, _sl.action == SLA_LOAD ? 2 : 6, "Field '%s' of type 0x%02X not found, skipping", key.c_str(), type); std::shared_ptr handler = nullptr; - SaveLoadType slt; + SaveLoadType saveload_type; switch (type & SLE_FILE_TYPE_MASK) { case SLE_FILE_STRING: /* Strings are always marked with SLE_FILE_HAS_LENGTH_FIELD, as they are a list of chars. */ - slt = SL_STR; + saveload_type = SL_STR; break; case SLE_FILE_STRUCT: /* Structs are always marked with SLE_FILE_HAS_LENGTH_FIELD as SL_STRUCT is seen as a list of 0/1 in length. */ - slt = SL_STRUCTLIST; + saveload_type = SL_STRUCTLIST; handler = std::make_shared(); break; default: - slt = (type & SLE_FILE_HAS_LENGTH_FIELD) ? SL_ARR : SL_VAR; + saveload_type = (type & SLE_FILE_HAS_LENGTH_FIELD) ? SL_ARR : SL_VAR; break; } /* We don't know this field, so read to nothing. */ - saveloads.push_back({key, slt, ((VarType)type & SLE_FILE_TYPE_MASK) | SLE_VAR_NULL, 1, SL_MIN_VERSION, SL_MAX_VERSION, 0, nullptr, 0, handler}); + saveloads.push_back({key, saveload_type, ((VarType)type & SLE_FILE_TYPE_MASK) | SLE_VAR_NULL, 1, SL_MIN_VERSION, SL_MAX_VERSION, 0, nullptr, 0, handler}); continue; } diff --git a/src/screenshot.cpp b/src/screenshot.cpp index c3c29cdd53..83449fff89 100644 --- a/src/screenshot.cpp +++ b/src/screenshot.cpp @@ -8,6 +8,7 @@ /** @file screenshot.cpp The creation of screenshots! */ #include "stdafx.h" +#include "core/backup_type.hpp" #include "fileio_func.h" #include "viewport_func.h" #include "gfx_func.h" @@ -635,7 +636,7 @@ static void CurrentScreenCallback(void *userdata, void *buf, uint y, uint pitch, static void LargeWorldCallback(void *userdata, void *buf, uint y, uint pitch, uint n) { Viewport *vp = (Viewport *)userdata; - DrawPixelInfo dpi, *old_dpi; + DrawPixelInfo dpi; int wx, left; /* We are no longer rendering to the screen */ @@ -648,8 +649,7 @@ static void LargeWorldCallback(void *userdata, void *buf, uint y, uint pitch, ui _screen.pitch = pitch; _screen_disable_anim = true; - old_dpi = _cur_dpi; - _cur_dpi = &dpi; + Backup dpi_backup(_cur_dpi, &dpi, FILE_LINE); dpi.dst_ptr = buf; dpi.height = n; @@ -674,7 +674,7 @@ static void LargeWorldCallback(void *userdata, void *buf, uint y, uint pitch, ui ); } - _cur_dpi = old_dpi; + dpi_backup.Restore(); ViewportDoDrawProcessAllPending(); diff --git a/src/smallmap_gui.cpp b/src/smallmap_gui.cpp index a5810f3361..38fca6a8d7 100644 --- a/src/smallmap_gui.cpp +++ b/src/smallmap_gui.cpp @@ -8,6 +8,7 @@ /** @file smallmap_gui.cpp GUI that shows a small map of the world with metadata like owner or height. */ #include "stdafx.h" +#include "core/backup_type.hpp" #include "clear_map.h" #include "industry.h" #include "station_map.h" @@ -955,10 +956,7 @@ void SmallMapWindow::DrawMapIndicators() const void SmallMapWindow::DrawSmallMap(DrawPixelInfo *dpi, bool draw_indicators) const { Blitter *blitter = BlitterFactory::GetCurrentBlitter(); - DrawPixelInfo *old_dpi; - - old_dpi = _cur_dpi; - _cur_dpi = dpi; + AutoRestoreBackup dpi_backup(_cur_dpi, dpi); /* Clear it */ GfxFillRect(dpi->left, dpi->top, dpi->left + dpi->width - 1, dpi->top + dpi->height - 1, PC_BLACK); @@ -1017,8 +1015,6 @@ void SmallMapWindow::DrawSmallMap(DrawPixelInfo *dpi, bool draw_indicators) cons /* Draw map indicators */ if (draw_indicators) this->DrawMapIndicators(); - - _cur_dpi = old_dpi; } /** diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp index 137b19cd2c..bc7822d387 100644 --- a/src/station_cmd.cpp +++ b/src/station_cmd.cpp @@ -1176,7 +1176,7 @@ CommandCost CheckFlatLandRoadStop(TileArea tile_area, const RoadStopSpec *spec, if (road_owner == OWNER_TOWN) { if (!_settings_game.construction.road_stop_on_town_road) return_cmd_error(STR_ERROR_DRIVE_THROUGH_ON_TOWN_ROAD); } else if (!_settings_game.construction.road_stop_on_competitor_road && road_owner != OWNER_NONE) { - CommandCost ret = CheckOwnership(road_owner); + ret = CheckOwnership(road_owner); if (ret.Failed()) return ret; } uint num_pieces = CountBits(GetRoadBits(cur_tile, RTT_ROAD)); @@ -1197,7 +1197,7 @@ CommandCost CheckFlatLandRoadStop(TileArea tile_area, const RoadStopSpec *spec, /* Disallow breaking end-of-line of someone else * so trams can still reverse on this tile. */ HasExactlyOneBit(GetRoadBits(cur_tile, RTT_TRAM)))) { - CommandCost ret = CheckOwnership(tram_owner); + ret = CheckOwnership(tram_owner); if (ret.Failed()) return ret; } uint num_pieces = CountBits(GetRoadBits(cur_tile, RTT_TRAM)); @@ -1550,7 +1550,7 @@ CommandCost CmdBuildRailStation(TileIndex tile_org, DoCommandFlag flags, uint32 if (ret.Failed()) return ret; if (st != nullptr && st->train_station.tile != INVALID_TILE) { - CommandCost ret = CanExpandRailStation(st, new_location, axis); + ret = CanExpandRailStation(st, new_location, axis); if (ret.Failed()) return ret; } @@ -1821,7 +1821,7 @@ CommandCost RemoveFromRailBaseStation(TileArea ta, std::vector &affected_st if (st == nullptr) continue; if (_current_company != OWNER_WATER) { - CommandCost ret = CheckOwnership(st->owner); + ret = CheckOwnership(st->owner); error.AddCost(ret); if (ret.Failed()) continue; } @@ -3522,7 +3522,6 @@ draw_default_foundation: /* PBS debugging, draw reserved tracks darker */ if (_game_mode != GM_MENU && _settings_client.gui.show_track_reservation && HasStationRail(ti->tile) && HasStationReservation(ti->tile)) { - const RailtypeInfo *rti = GetRailTypeInfo(GetRailType(ti->tile)); DrawGroundSprite(GetRailStationAxis(ti->tile) == AXIS_X ? rti->base_sprites.single_x : rti->base_sprites.single_y, PALETTE_CRASH); } } @@ -3605,17 +3604,17 @@ void StationPickerDrawSprite(int x, int y, StationType st, RailType railtype, Ro int32 total_offset = 0; PaletteID pal = COMPANY_SPRITE_COLOUR(_local_company); const DrawTileSprites *t = GetStationTileLayout(st, image); - const RailtypeInfo *rti = nullptr; + const RailtypeInfo *railtype_info = nullptr; if (railtype != INVALID_RAILTYPE) { - rti = GetRailTypeInfo(railtype); - total_offset = rti->GetRailtypeSpriteOffset(); + railtype_info = GetRailTypeInfo(railtype); + total_offset = railtype_info->GetRailtypeSpriteOffset(); } SpriteID img = t->ground.sprite; RailTrackOffset overlay_offset; - if (rti != nullptr && rti->UsesOverlay() && SplitGroundSpriteForOverlay(nullptr, &img, &overlay_offset)) { - SpriteID ground = GetCustomRailSprite(rti, INVALID_TILE, RTSG_GROUND); + if (railtype_info != nullptr && railtype_info->UsesOverlay() && SplitGroundSpriteForOverlay(nullptr, &img, &overlay_offset)) { + SpriteID ground = GetCustomRailSprite(railtype_info, INVALID_TILE, RTSG_GROUND); DrawSprite(img, PAL_NONE, x, y); DrawSprite(ground + overlay_offset, PAL_NONE, x, y); } else { @@ -3623,25 +3622,25 @@ void StationPickerDrawSprite(int x, int y, StationType st, RailType railtype, Ro } if (roadtype != INVALID_ROADTYPE) { - const RoadTypeInfo* rti = GetRoadTypeInfo(roadtype); + const RoadTypeInfo *roadtype_info = GetRoadTypeInfo(roadtype); if (image >= 4) { /* Drive-through stop */ uint sprite_offset = 5 - image; /* Road underlay takes precedence over tram */ - if (rti->UsesOverlay()) { - SpriteID ground = GetCustomRoadSprite(rti, INVALID_TILE, ROTSG_GROUND); + if (roadtype_info->UsesOverlay()) { + SpriteID ground = GetCustomRoadSprite(roadtype_info, INVALID_TILE, ROTSG_GROUND); DrawSprite(ground + sprite_offset, PAL_NONE, x, y); - SpriteID overlay = GetCustomRoadSprite(rti, INVALID_TILE, ROTSG_OVERLAY); + SpriteID overlay = GetCustomRoadSprite(roadtype_info, INVALID_TILE, ROTSG_OVERLAY); if (overlay) DrawSprite(overlay + sprite_offset, PAL_NONE, x, y); } else if (RoadTypeIsTram(roadtype)) { DrawSprite(SPR_TRAMWAY_TRAM + sprite_offset, PAL_NONE, x, y); } } else { /* Drive-in stop */ - if (RoadTypeIsRoad(roadtype) && rti->UsesOverlay()) { - SpriteID ground = GetCustomRoadSprite(rti, INVALID_TILE, ROTSG_ROADSTOP); + if (RoadTypeIsRoad(roadtype) && roadtype_info->UsesOverlay()) { + SpriteID ground = GetCustomRoadSprite(roadtype_info, INVALID_TILE, ROTSG_ROADSTOP); DrawSprite(ground + image, PAL_NONE, x, y); } } diff --git a/src/statusbar_gui.cpp b/src/statusbar_gui.cpp index c65099be79..45782cfd02 100644 --- a/src/statusbar_gui.cpp +++ b/src/statusbar_gui.cpp @@ -8,6 +8,7 @@ /** @file statusbar_gui.cpp The GUI for the bottom status bar. */ #include "stdafx.h" +#include "core/backup_type.hpp" #include "date_func.h" #include "gfx_func.h" #include "news_func.h" @@ -68,10 +69,8 @@ static bool DrawScrollingStatusText(const NewsItem *ni, int scroll_pos, int left int width = GetStringBoundingBox(buffer).width; int pos = (_current_text_dir == TD_RTL) ? (scroll_pos - width) : (right - scroll_pos - left); - DrawPixelInfo *old_dpi = _cur_dpi; - _cur_dpi = &tmp_dpi; + AutoRestoreBackup dpi_backup(_cur_dpi, &tmp_dpi); DrawString(pos, INT16_MAX, 0, buffer, TC_LIGHT_BLUE, SA_LEFT | SA_FORCE); - _cur_dpi = old_dpi; return (_current_text_dir == TD_RTL) ? (pos < right - left) : (pos + width > 0); } diff --git a/src/stdafx.h b/src/stdafx.h index 6b55f9d17c..8adade8a54 100644 --- a/src/stdafx.h +++ b/src/stdafx.h @@ -334,6 +334,51 @@ #define OTTD_PRINTFHEX64 "%" OTTD_PRINTFHEX64_SUFFIX #define OTTD_PRINTFHEX64PAD "%016" OTTD_PRINTFHEX64_SUFFIX +/* + * When making a (pure) debug build, the compiler will by default disable + * inlining of functions. This has a detremental effect on the performance of + * debug builds, especially when more and more trivial (wrapper) functions get + * added to the code base. + * Take for example the savegame called "Wentbourne", when running this game + * for 100 ticks with the null video driver a number of fairly trivial + * functions show up on top. The most common one is the implicit conversion + * operator of TileIndex to unsigned int, which takes up over 5% of the total + * run time and functionally does absolutely nothing. The remaining functions + * for the top 5 are GB, GetTileType, Map::Size and IsTileType to a total of + * about 12.5% of the game's total run time. + * It is possible to still force inlining in the most commonly used compilers, + * but that is at the cost of some problems with debugging due to the forced + * inlining. However, the performance benefit can be enormous; when forcing + * inlining for the previously mentioned top 5, the debug build ran about 15% + * quicker. + * The following debug_inline annotation may be added to functions comply + * with the following preconditions: + * 1: the function takes more than 0.5% of a profiled debug runtime + * 2: the function does not modify the game state + * 3: the function does not contain selection or iteration statements, + * i.e. no if, switch, for, do, while, etcetera. + * 4: the function is one line of code, excluding assertions. + * 5: the function is defined in a header file. + * The debug_inline annotation must be placed in front of the function, i.e. + * before the optional static or constexpr modifier. + */ +#if !defined(_DEBUG) || defined(NO_DEBUG_INLINE) +/* + * Do not force inlining when not in debug. This way we do not work against + * any carefully designed compiler optimizations. + */ +#define debug_inline inline +#elif defined(__clang__) || defined(__GNUC__) +#define debug_inline [[gnu::always_inline]] inline +#else +/* + * MSVC explicitly disables inlining, even forced inlining, in debug builds + * so __forceinline makes no difference compared to inline. Other unknown + * compilers can also just fallback to a normal inline. + */ +#define debug_inline inline +#endif + typedef unsigned char byte; /* This is already defined in unix, but not in QNX Neutrino (6.x) or Cygwin. */ diff --git a/src/story_gui.cpp b/src/story_gui.cpp index 7d213182d4..6b0e2eafe1 100644 --- a/src/story_gui.cpp +++ b/src/story_gui.cpp @@ -25,6 +25,7 @@ #include "company_base.h" #include "tilehighlight_func.h" #include "vehicle_base.h" +#include "core/backup_type.hpp" #include "widgets/story_widget.h" @@ -697,8 +698,7 @@ public: DrawPixelInfo tmp_dpi; if (!FillDrawPixelInfo(&tmp_dpi, fr.left, fr.top, fr.Width(), fr.Height())) return; - DrawPixelInfo *old_dpi = _cur_dpi; - _cur_dpi = &tmp_dpi; + AutoRestoreBackup dpi_backup(_cur_dpi, &tmp_dpi); /* Draw content (now coordinates given to Draw** are local to the new clipping region). */ fr = fr.Translate(-fr.left, -fr.top); @@ -757,9 +757,6 @@ public: default: NOT_REACHED(); } } - - /* Restore clipping region. */ - _cur_dpi = old_dpi; } void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override diff --git a/src/strgen/strgen.cpp b/src/strgen/strgen.cpp index 8db994cae2..c99e09ebb0 100644 --- a/src/strgen/strgen.cpp +++ b/src/strgen/strgen.cpp @@ -473,9 +473,9 @@ int CDECL main(int argc, char *argv[]) case 'P': printf("name\tflags\tdefault\tdescription\n"); - for (size_t i = 0; i < lengthof(_pragmas); i++) { + for (size_t j = 0; j < lengthof(_pragmas); j++) { printf("\"%s\"\t%s\t\"%s\"\t\"%s\"\n", - _pragmas[i][0], _pragmas[i][1], _pragmas[i][2], _pragmas[i][3]); + _pragmas[j][0], _pragmas[j][1], _pragmas[j][2], _pragmas[j][3]); } return 0; diff --git a/src/strgen/strgen_base.cpp b/src/strgen/strgen_base.cpp index 4fdc22f06d..44f4fff132 100644 --- a/src/strgen/strgen_base.cpp +++ b/src/strgen/strgen_base.cpp @@ -878,7 +878,7 @@ static int TranslateArgumentIdx(int argidx, int offset) } for (int i = sum = 0; i < argidx; i++) { - const CmdStruct *cs = _cur_pcs.cmd[i]; + cs = _cur_pcs.cmd[i]; sum += (cs != nullptr) ? cs->consumes : 1; } diff --git a/src/strings.cpp b/src/strings.cpp index aa5c774e70..968273525f 100644 --- a/src/strings.cpp +++ b/src/strings.cpp @@ -1296,19 +1296,19 @@ static char *FormatString(char *buff, const char *str_arg, StringParameters *arg case SCC_RAW_STRING_POINTER: { // {RAW_STRING} if (game_script) break; - const char *str = (const char *)(size_t)args->GetInt64(SCC_RAW_STRING_POINTER); - buff = FormatString(buff, str, args, last); + const char *raw_string = (const char *)(size_t)args->GetInt64(SCC_RAW_STRING_POINTER); + buff = FormatString(buff, raw_string, args, last); break; } case SCC_STRING: {// {STRING} - StringID str = args->GetInt32(SCC_STRING); - if (game_script && GetStringTab(str) != TEXT_TAB_GAMESCRIPT_START) break; + StringID string_id = args->GetInt32(SCC_STRING); + if (game_script && GetStringTab(string_id) != TEXT_TAB_GAMESCRIPT_START) break; /* WARNING. It's prohibited for the included string to consume any arguments. * For included strings that consume argument, you should use STRING1, STRING2 etc. * To debug stuff you can set argv to nullptr and it will tell you */ StringParameters tmp_params(args->GetDataPointer(), args->GetDataLeft(), nullptr); - buff = GetStringWithArgs(buff, str, &tmp_params, last, next_substr_case_index, game_script); + buff = GetStringWithArgs(buff, string_id, &tmp_params, last, next_substr_case_index, game_script); next_substr_case_index = 0; break; } @@ -1322,14 +1322,14 @@ static char *FormatString(char *buff, const char *str_arg, StringParameters *arg case SCC_STRING7: case SCC_STRING8: { // {STRING1..8} /* Strings that consume arguments */ - StringID str = args->GetInt32(b); - if (game_script && GetStringTab(str) != TEXT_TAB_GAMESCRIPT_START) break; + StringID string_id = args->GetInt32(b); + if (game_script && GetStringTab(string_id) != TEXT_TAB_GAMESCRIPT_START) break; uint size = b - SCC_STRING1 + 1; if (game_script && size > args->GetDataLeft()) { buff = strecat(buff, "(too many parameters)", last); } else { StringParameters sub_args(*args, size); - buff = GetStringWithArgs(buff, str, &sub_args, last, next_substr_case_index, game_script); + buff = GetStringWithArgs(buff, string_id, &sub_args, last, next_substr_case_index, game_script); } next_substr_case_index = 0; break; @@ -1835,7 +1835,7 @@ static char *FormatString(char *buff, const char *str_arg, StringParameters *arg StringParameters tmp_params(args_array); buff = GetStringWithArgs(buff, STR_JUST_RAW_STRING, &tmp_params, last); } else { - StringID str = st->string_id; + StringID string_id = st->string_id; if (st->indtype != IT_INVALID) { /* Special case where the industry provides the name for the station */ const IndustrySpec *indsp = GetIndustrySpec(st->indtype); @@ -1844,17 +1844,17 @@ static char *FormatString(char *buff, const char *str_arg, StringParameters *arg * thus cause very strange things. Here we check for that before we * actually set the station name. */ if (indsp->station_name != STR_NULL && indsp->station_name != STR_UNDEFINED) { - str = indsp->station_name; + string_id = indsp->station_name; } } if (st->extra_name_index != UINT16_MAX && st->extra_name_index < _extra_station_names_used) { - str = _extra_station_names[st->extra_name_index].str; + string_id = _extra_station_names[st->extra_name_index].str; } uint64 args_array[] = {STR_TOWN_NAME, st->town->index, st->index}; WChar types_array[] = {0, SCC_TOWN_NAME, SCC_NUM}; StringParameters tmp_params(args_array, 3, types_array); - buff = GetStringWithArgs(buff, str, &tmp_params, last); + buff = GetStringWithArgs(buff, string_id, &tmp_params, last); } break; } @@ -1884,9 +1884,9 @@ static char *FormatString(char *buff, const char *str_arg, StringParameters *arg } else { int64 args_array[] = {wp->town->index, wp->town_cn + 1}; StringParameters tmp_params(args_array); - StringID str = ((wp->string_id == STR_SV_STNAME_BUOY) ? STR_FORMAT_BUOY_NAME : STR_FORMAT_WAYPOINT_NAME); - if (wp->town_cn != 0) str++; - buff = GetStringWithArgs(buff, str, &tmp_params, last); + StringID string_id = ((wp->string_id == STR_SV_STNAME_BUOY) ? STR_FORMAT_BUOY_NAME : STR_FORMAT_WAYPOINT_NAME); + if (wp->town_cn != 0) string_id++; + buff = GetStringWithArgs(buff, string_id, &tmp_params, last); } break; } @@ -1916,14 +1916,14 @@ static char *FormatString(char *buff, const char *str_arg, StringParameters *arg int64 args_array[] = {v->unitnumber}; StringParameters tmp_params(args_array); - StringID str; + StringID string_id; if (v->type < VEH_COMPANY_END) { - str = ((_settings_client.gui.vehicle_names == 1) ? STR_SV_TRAIN_NAME : STR_TRADITIONAL_TRAIN_NAME) + v->type; + string_id = ((_settings_client.gui.vehicle_names == 1) ? STR_SV_TRAIN_NAME : STR_TRADITIONAL_TRAIN_NAME) + v->type; } else { - str = STR_INVALID_VEHICLE; + string_id = STR_INVALID_VEHICLE; } - buff = GetStringWithArgs(buff, str, &tmp_params, last); + buff = GetStringWithArgs(buff, string_id, &tmp_params, last); } break; } diff --git a/src/textfile_gui.cpp b/src/textfile_gui.cpp index e490491f50..021d7326d5 100644 --- a/src/textfile_gui.cpp +++ b/src/textfile_gui.cpp @@ -8,6 +8,7 @@ /** @file textfile_gui.cpp Implementation of textfile window. */ #include "stdafx.h" +#include "core/backup_type.hpp" #include "fileio_func.h" #include "fontcache.h" #include "gfx_type.h" @@ -152,8 +153,7 @@ void TextfileWindow::SetupScrollbars(bool force_reflow) DrawPixelInfo new_dpi; if (!FillDrawPixelInfo(&new_dpi, fr.left, fr.top, fr.Width(), fr.Height())) return; - DrawPixelInfo *old_dpi = _cur_dpi; - _cur_dpi = &new_dpi; + AutoRestoreBackup dpi_backup(_cur_dpi, &new_dpi); /* Draw content (now coordinates given to DrawString* are local to the new clipping region). */ fr = fr.Translate(-fr.left, -fr.top); @@ -172,8 +172,6 @@ void TextfileWindow::SetupScrollbars(bool force_reflow) DrawString(-this->hscroll->GetPosition(), fr.right, y_offset, line.text, TC_BLACK, SA_TOP | SA_LEFT, false, FS_MONO); } } - - _cur_dpi = old_dpi; } /* virtual */ void TextfileWindow::OnResize() diff --git a/src/tile_map.h b/src/tile_map.h index 444d415d18..2032b88450 100644 --- a/src/tile_map.h +++ b/src/tile_map.h @@ -26,7 +26,7 @@ * @return the height of the tile * @pre tile < MapSize() */ -static inline uint TileHeight(TileIndex tile) +debug_inline static uint TileHeight(TileIndex tile) { /* this method is inlined in many places and is performance-critical, drop assertion in non-debug builds */ #ifdef _DEBUG @@ -96,7 +96,7 @@ static inline uint TilePixelHeightOutsideMap(int x, int y) * @return The tiletype of the tile * @pre tile < MapSize() */ -static inline TileType GetTileType(TileIndex tile) +debug_inline static TileType GetTileType(TileIndex tile) { /* this method is inlined in many places and is performance-critical, drop assertion in non-debug builds */ #ifdef _DEBUG @@ -153,7 +153,7 @@ static inline void SetTileType(TileIndex tile, TileType type) * @param type The type to check against * @return true If the type matches against the type of the tile */ -static inline bool IsTileType(TileIndex tile, TileType type) +debug_inline static bool IsTileType(TileIndex tile, TileType type) { return GetTileType(tile) == type; } diff --git a/src/timetable_gui.cpp b/src/timetable_gui.cpp index 2e011ed701..ae50fcfea2 100644 --- a/src/timetable_gui.cpp +++ b/src/timetable_gui.cpp @@ -124,16 +124,16 @@ static void FillTimetableArrivalDepartureTable(const Vehicle *v, VehicleOrderID assert(v->GetNumOrders() >= 2); assert(start < v->GetNumOrders()); - Ticks sum = offset; - VehicleOrderID i = start; - const Order *order = v->GetOrder(i); - /* Pre-initialize with unknown time */ for (int i = 0; i < v->GetNumOrders(); ++i) { table[i].arrival = table[i].departure = INVALID_TICKS; table[i].flags = 0; } + Ticks sum = offset; + VehicleOrderID i = start; + const Order *order = v->GetOrder(i); + bool predicted = false; bool no_offset = false; bool skip_travel = false; diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp index 6797d7f8f2..e3ea6458dc 100644 --- a/src/town_cmd.cpp +++ b/src/town_cmd.cpp @@ -99,7 +99,7 @@ static bool TestTownOwnsBridge(TileIndex tile, const Town *t) if (!town_owned) { /* Or other adjacent road */ - TileIndex adjacent = tile + TileOffsByDiagDir(ReverseDiagDir(GetTunnelBridgeDirection(GetOtherTunnelBridgeEnd(tile)))); + adjacent = tile + TileOffsByDiagDir(ReverseDiagDir(GetTunnelBridgeDirection(GetOtherTunnelBridgeEnd(tile)))); town_owned = IsTileType(adjacent, MP_ROAD) && IsTileOwner(adjacent, OWNER_TOWN) && GetTownIndex(adjacent) == t->index; } diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp index 3c2f38e90c..ca97a321b4 100644 --- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -2157,7 +2157,7 @@ CommandCost CmdMoveRailVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, u /* If the autoreplace flag is set we do not need to test for the validity * because we are going to revert the train to its original state. As we * assume the original state was correct autoreplace can skip this. */ - CommandCost ret = ValidateTrains(original_dst_head, dst_head, original_src_head, src_head, true); + ret = ValidateTrains(original_dst_head, dst_head, original_src_head, src_head, true); if (ret.Failed()) { /* Restore the train we had. */ RestoreTrainBackup(original_src); diff --git a/src/train_gui.cpp b/src/train_gui.cpp index d8b3d4cfcc..5be4b4acae 100644 --- a/src/train_gui.cpp +++ b/src/train_gui.cpp @@ -14,6 +14,7 @@ #include "strings_func.h" #include "vehicle_func.h" #include "zoom_func.h" +#include "core/backup_type.hpp" #include "table/strings.h" @@ -100,7 +101,7 @@ void DrawTrainImage(const Train *v, const Rect &r, VehicleID selection, EngineIm bool rtl = _current_text_dir == TD_RTL; Direction dir = rtl ? DIR_E : DIR_W; - DrawPixelInfo tmp_dpi, *old_dpi; + DrawPixelInfo tmp_dpi; /* Position of highlight box */ int highlight_l = 0; int highlight_r = 0; @@ -108,56 +109,55 @@ void DrawTrainImage(const Train *v, const Rect &r, VehicleID selection, EngineIm if (!FillDrawPixelInfo(&tmp_dpi, r.left, r.top, r.Width(), r.Height())) return; - old_dpi = _cur_dpi; - _cur_dpi = &tmp_dpi; + { + AutoRestoreBackup dpi_backup(_cur_dpi, &tmp_dpi); - int px = rtl ? max_width + skip : -skip; - int y = r.Height() / 2; - bool sel_articulated = false; - bool dragging = (drag_dest != INVALID_VEHICLE); - bool drag_at_end_of_train = (drag_dest == v->index); // Head index is used to mark dragging at end of train. - for (; v != nullptr && (rtl ? px > 0 : px < max_width); v = v->Next()) { - if (dragging && !drag_at_end_of_train && drag_dest == v->index) { - /* Highlight the drag-and-drop destination inside the train. */ - int drag_hlight_width = HighlightDragPosition(px, max_width, y, selection, _cursor.vehchain); - px += rtl ? -drag_hlight_width : drag_hlight_width; - } - - Point offset; - int width = Train::From(v)->GetDisplayImageWidth(&offset); - - if (rtl ? px + width > 0 : px - width < max_width) { - PaletteID pal = (v->vehstatus & VS_CRASHED) ? PALETTE_CRASH : GetVehiclePalette(v); - VehicleSpriteSeq seq; - v->GetImage(dir, image_type, &seq); - seq.Draw(px + (rtl ? -offset.x : offset.x), y + offset.y, pal, (v->vehstatus & VS_CRASHED) != 0); - } - - if (!v->IsArticulatedPart()) sel_articulated = false; - - if (v->index == selection) { - /* Set the highlight position */ - highlight_l = rtl ? px - width : px; - highlight_r = rtl ? px - 1 : px + width - 1; - sel_articulated = true; - } else if ((_cursor.vehchain && highlight_r != 0) || sel_articulated) { - if (rtl) { - highlight_l -= width; - } else { - highlight_r += width; + int px = rtl ? max_width + skip : -skip; + int y = r.Height() / 2; + bool sel_articulated = false; + bool dragging = (drag_dest != INVALID_VEHICLE); + bool drag_at_end_of_train = (drag_dest == v->index); // Head index is used to mark dragging at end of train. + for (; v != nullptr && (rtl ? px > 0 : px < max_width); v = v->Next()) { + if (dragging && !drag_at_end_of_train && drag_dest == v->index) { + /* Highlight the drag-and-drop destination inside the train. */ + int drag_hlight_width = HighlightDragPosition(px, max_width, y, selection, _cursor.vehchain); + px += rtl ? -drag_hlight_width : drag_hlight_width; } + + Point offset; + int width = Train::From(v)->GetDisplayImageWidth(&offset); + + if (rtl ? px + width > 0 : px - width < max_width) { + PaletteID pal = (v->vehstatus & VS_CRASHED) ? PALETTE_CRASH : GetVehiclePalette(v); + VehicleSpriteSeq seq; + v->GetImage(dir, image_type, &seq); + seq.Draw(px + (rtl ? -offset.x : offset.x), y + offset.y, pal, (v->vehstatus & VS_CRASHED) != 0); + } + + if (!v->IsArticulatedPart()) sel_articulated = false; + + if (v->index == selection) { + /* Set the highlight position */ + highlight_l = rtl ? px - width : px; + highlight_r = rtl ? px - 1 : px + width - 1; + sel_articulated = true; + } else if ((_cursor.vehchain && highlight_r != 0) || sel_articulated) { + if (rtl) { + highlight_l -= width; + } else { + highlight_r += width; + } + } + + px += rtl ? -width : width; } - px += rtl ? -width : width; + if (dragging && drag_at_end_of_train) { + /* Highlight the drag-and-drop destination at the end of the train. */ + HighlightDragPosition(px, max_width, y, selection, _cursor.vehchain); + } } - if (dragging && drag_at_end_of_train) { - /* Highlight the drag-and-drop destination at the end of the train. */ - HighlightDragPosition(px, max_width, y, selection, _cursor.vehchain); - } - - _cur_dpi = old_dpi; - if (highlight_l != highlight_r) { /* Draw the highlight. Now done after drawing all the engines, as * the next engine after the highlight could overlap it. */ diff --git a/src/tunnelbridge_cmd.cpp b/src/tunnelbridge_cmd.cpp index 6133571259..c7d65720ff 100644 --- a/src/tunnelbridge_cmd.cpp +++ b/src/tunnelbridge_cmd.cpp @@ -1222,7 +1222,7 @@ static CommandCost DoClearTunnel(TileIndex tile, DoCommandFlag flags) /* Check if you are allowed to remove the tunnel owned by a town * Removal depends on difficulty settings */ - CommandCost ret = CheckforTownRating(flags, t, TUNNELBRIDGE_REMOVE); + ret = CheckforTownRating(flags, t, TUNNELBRIDGE_REMOVE); if (ret.Failed()) return ret; } @@ -1345,7 +1345,7 @@ static CommandCost DoClearBridge(TileIndex tile, DoCommandFlag flags) /* Check if you are allowed to remove the bridge owned by a town * Removal depends on difficulty settings */ - CommandCost ret = CheckforTownRating(flags, t, TUNNELBRIDGE_REMOVE); + ret = CheckforTownRating(flags, t, TUNNELBRIDGE_REMOVE); if (ret.Failed()) return ret; } diff --git a/src/vehicle_base.h b/src/vehicle_base.h index f48fa90b4f..55fa5b54a3 100644 --- a/src/vehicle_base.h +++ b/src/vehicle_base.h @@ -573,7 +573,7 @@ public: * Check if the vehicle is a ground vehicle. * @return True iff the vehicle is a train or a road vehicle. */ - inline bool IsGroundVehicle() const + debug_inline bool IsGroundVehicle() const { return this->type == VEH_TRAIN || this->type == VEH_ROAD; } @@ -1059,7 +1059,7 @@ public: * Check if the vehicle is a front engine. * @return Returns true if the vehicle is a front engine. */ - inline bool IsFrontEngine() const + debug_inline bool IsFrontEngine() const { return this->IsGroundVehicle() && HasBit(this->subtype, GVSF_FRONT); } diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp index 28dd228b60..31c45d272d 100644 --- a/src/vehicle_gui.cpp +++ b/src/vehicle_gui.cpp @@ -4064,8 +4064,8 @@ public: } /* The same system applies to widget WID_VV_REFIT_VEH and VVW_WIDGET_TURN_AROUND.*/ if (v->IsGroundVehicle()) { - PlaneSelections plane = veh_stopped ? SEL_RT_REFIT : SEL_RT_TURN_AROUND; - NWidgetStacked *nwi = this->GetWidget(WID_VV_SELECT_REFIT_TURN); + plane = veh_stopped ? SEL_RT_REFIT : SEL_RT_TURN_AROUND; + nwi = this->GetWidget(WID_VV_SELECT_REFIT_TURN); if (nwi->shown_plane + SEL_RT_BASEPLANE != plane) { this->SelectPlane(plane); this->SetWidgetDirty(WID_VV_SELECT_REFIT_TURN); diff --git a/src/video/opengl.cpp b/src/video/opengl.cpp index 34b15388fb..2ab8b20f7d 100644 --- a/src/video/opengl.cpp +++ b/src/video/opengl.cpp @@ -1120,8 +1120,8 @@ void OpenGLBackend::PopulateCursorCache() if (!this->cursor_cache.Contains(sprite)) { Sprite *old = this->cursor_cache.Insert(sprite, (Sprite *)GetRawSprite(sprite, ST_NORMAL, &SimpleSpriteAlloc, this)); if (old != nullptr) { - OpenGLSprite *sprite = (OpenGLSprite *)old->data; - sprite->~OpenGLSprite(); + OpenGLSprite *gl_sprite = (OpenGLSprite *)old->data; + gl_sprite->~OpenGLSprite(); free(old); } } diff --git a/src/viewport.cpp b/src/viewport.cpp index dda4cf4a94..f0e055aa08 100644 --- a/src/viewport.cpp +++ b/src/viewport.cpp @@ -1826,9 +1826,6 @@ static void ViewportAddKdtreeSigns(ViewportDrawerDynamic *vdd, DrawPixelInfo *dp bool show_competitors = HasBit(_display_opt, DO_SHOW_COMPETITOR_SIGNS) && !towns_only; bool hide_hidden_waypoints = _settings_client.gui.allow_hiding_waypoint_labels && !HasBit(_extra_display_opt, XDO_SHOW_HIDDEN_SIGNS); - const BaseStation *st; - const Sign *si; - /* Collect all the items first and draw afterwards, to ensure layering */ std::vector stations; std::vector towns; @@ -1836,19 +1833,20 @@ static void ViewportAddKdtreeSigns(ViewportDrawerDynamic *vdd, DrawPixelInfo *dp _viewport_sign_kdtree.FindContained(search_rect.left, search_rect.top, search_rect.right, search_rect.bottom, [&](const ViewportSignKdtreeItem & item) { switch (item.type) { - case ViewportSignKdtreeItem::VKI_STATION: + case ViewportSignKdtreeItem::VKI_STATION: { if (!show_stations) break; - st = BaseStation::Get(item.id.station); + const BaseStation *st = BaseStation::Get(item.id.station); /* Don't draw if station is owned by another company and competitor station names are hidden. Stations owned by none are never ignored. */ if (!show_competitors && _local_company != st->owner && st->owner != OWNER_NONE) break; stations.push_back(st); break; + } - case ViewportSignKdtreeItem::VKI_WAYPOINT: + case ViewportSignKdtreeItem::VKI_WAYPOINT: { if (!show_waypoints) break; - st = BaseStation::Get(item.id.station); + const BaseStation *st = BaseStation::Get(item.id.station); /* Don't draw if station is owned by another company and competitor station names are hidden. Stations owned by none are never ignored. */ if (!show_competitors && _local_company != st->owner && st->owner != OWNER_NONE) break; @@ -1856,15 +1854,16 @@ static void ViewportAddKdtreeSigns(ViewportDrawerDynamic *vdd, DrawPixelInfo *dp stations.push_back(st); break; + } case ViewportSignKdtreeItem::VKI_TOWN: if (!show_towns) break; towns.push_back(Town::Get(item.id.town)); break; - case ViewportSignKdtreeItem::VKI_SIGN: + case ViewportSignKdtreeItem::VKI_SIGN: { if (!show_signs) break; - si = Sign::Get(item.id.sign); + const Sign *si = Sign::Get(item.id.sign); /* Don't draw if sign is owned by another company and competitor signs should be hidden. * Note: It is intentional that also signs owned by OWNER_NONE are hidden. Bankrupt @@ -1873,6 +1872,7 @@ static void ViewportAddKdtreeSigns(ViewportDrawerDynamic *vdd, DrawPixelInfo *dp signs.push_back(si); break; + } default: NOT_REACHED(); diff --git a/src/widget.cpp b/src/widget.cpp index e39536c3fa..3ecda66931 100644 --- a/src/widget.cpp +++ b/src/widget.cpp @@ -8,6 +8,7 @@ /** @file widget.cpp Handling of the default/simple widgets. */ #include "stdafx.h" +#include "core/backup_type.hpp" #include "company_func.h" #include "window_gui.h" #include "viewport_func.h" @@ -2058,8 +2059,7 @@ void NWidgetMatrix::FillDirtyWidgets(std::vector &dirty_widgets) bool rtl = _current_text_dir == TD_RTL; DrawPixelInfo tmp_dpi; if (!FillDrawPixelInfo(&tmp_dpi, this->pos_x + (rtl ? this->pip_post : this->pip_pre), this->pos_y + this->pip_pre, this->current_x - this->pip_pre - this->pip_post, this->current_y - this->pip_pre - this->pip_post)) return; - DrawPixelInfo *old_dpi = _cur_dpi; - _cur_dpi = &tmp_dpi; + AutoRestoreBackup dpi_backup(_cur_dpi, &tmp_dpi); /* Get the appropriate offsets so we can draw the right widgets. */ NWidgetCore *child = dynamic_cast(this->head); @@ -2092,9 +2092,6 @@ void NWidgetMatrix::FillDirtyWidgets(std::vector &dirty_widgets) child->Draw(w); } } - - /* Restore the clipping area. */ - _cur_dpi = old_dpi; } /** @@ -2911,8 +2908,7 @@ void NWidgetLeaf::Draw(const Window *w) new_dpi.left += this->pos_x; new_dpi.top += this->pos_y; - DrawPixelInfo *old_dpi = _cur_dpi; - _cur_dpi = &new_dpi; + AutoRestoreBackup dpi_backup(_cur_dpi, &new_dpi); Rect r = this->GetCurrentRect(); @@ -3026,8 +3022,6 @@ void NWidgetLeaf::Draw(const Window *w) if (this->IsDisabled()) { GfxFillRect(r.Shrink(WidgetDimensions::scaled.bevel), _colour_gradient[this->colour & 0xF][2], FILLRECT_CHECKER); } - - _cur_dpi = old_dpi; } /** diff --git a/src/window.cpp b/src/window.cpp index a5b9408927..bf3e426abe 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -38,6 +38,7 @@ #include "network/network_func.h" #include "guitimer_func.h" #include "news_func.h" +#include "core/backup_type.hpp" #include "safeguards.h" @@ -255,9 +256,9 @@ void Window::SetWidgetHighlight(byte widget_index, TextColour highlighted_colour /* If we disable a highlight, check all widgets if anyone still has a highlight */ bool valid = false; for (uint i = 0; i < this->nested_array_size; i++) { - NWidgetBase *nwid = this->GetWidget(i); - if (nwid == nullptr) continue; - if (!nwid->IsHighlighted()) continue; + NWidgetBase *child_nwid = this->GetWidget(i); + if (child_nwid == nullptr) continue; + if (!child_nwid->IsHighlighted()) continue; valid = true; } @@ -979,9 +980,8 @@ void DrawOverlappedWindow(Window *w, int left, int top, int right, int bottom, D */ void DrawOverlappedWindowForAll(int left, int top, int right, int bottom) { - DrawPixelInfo *old_dpi = _cur_dpi; DrawPixelInfo bk; - _cur_dpi = &bk; + AutoRestoreBackup dpi_backup(_cur_dpi, &bk); for (Window *w : Window::IterateFromBack()) { if (MayBeShown(w) && @@ -993,7 +993,6 @@ void DrawOverlappedWindowForAll(int left, int top, int right, int bottom) DrawOverlappedWindow(w, std::max(left, w->left), std::max(top, w->top), std::min(right, w->left + w->width), std::min(bottom, w->top + w->height), DOWF_NONE); } } - _cur_dpi = old_dpi; } static void SetWindowDirtyPending(Window *w)