From 8ae15d9797194c3b30ab562ae6688d73a5a95159 Mon Sep 17 00:00:00 2001 From: translators Date: Tue, 16 Apr 2019 19:45:42 +0200 Subject: [PATCH 01/17] Update: Translations from eints indonesian: 6 changes by fanioz --- src/lang/indonesian.txt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/lang/indonesian.txt b/src/lang/indonesian.txt index 2e063a29c5..6056121da6 100644 --- a/src/lang/indonesian.txt +++ b/src/lang/indonesian.txt @@ -464,6 +464,7 @@ STR_TOOLBAR_SOUND_MUSIC :Suara/musik ############ range for message menu starts STR_NEWS_MENU_LAST_MESSAGE_NEWS_REPORT :Pesan/Berita terakhir STR_NEWS_MENU_MESSAGE_HISTORY_MENU :Berita Lampau +STR_NEWS_MENU_DELETE_ALL_MESSAGES :Hapus semua pesan ############ range ends here ############ range for about menu starts @@ -1567,6 +1568,7 @@ STR_CONFIG_SETTING_TOWN_FOUNDING_HELPTEXT :Mengaktifkan se STR_CONFIG_SETTING_TOWN_FOUNDING_FORBIDDEN :Dilarang STR_CONFIG_SETTING_TOWN_FOUNDING_ALLOWED :Diijinkan STR_CONFIG_SETTING_TOWN_FOUNDING_ALLOWED_CUSTOM_LAYOUT :Diijinkan, layout kota sendiri +STR_CONFIG_SETTING_TOWN_CARGOGENMODE_BITCOUNT :Linier STR_CONFIG_SETTING_EXTRA_TREE_PLACEMENT :Penempatan pohon dalam permainan: {STRING} STR_CONFIG_SETTING_EXTRA_TREE_PLACEMENT_HELPTEXT :Mengendalikan kemunculan pohon dalam permainan. Ini akan berefek pada industri yang memerlukan pohon, contohnya pengolahan kayu gelondongan @@ -2693,6 +2695,7 @@ STR_ABOUT_COPYRIGHT_OPENTTD :{BLACK}OpenTTD # Framerate display window STR_FRAMERATE_CAPTION_SMALL :{STRING}{WHITE} ({DECIMAL}x) STR_FRAMERATE_RATE_GAMELOOP :{WHITE}Rata simulasi: {STRING} +STR_FRAMERATE_RATE_GAMELOOP_TOOLTIP :{BLACK}Jumlah detak permainan tersimulasi per detik. STR_FRAMERATE_SPEED_FACTOR_TOOLTIP :{BLACK}Beberapa cepat permainan lagi berjalan, dibanding dengan kecepatan diharapkan memakai rata simulasi biasa. STR_FRAMERATE_CURRENT :{WHITE}Sekarang STR_FRAMERATE_DATA_POINTS :{WHITE}Data tergantung oleh ukuran {COMMA} @@ -2908,6 +2911,7 @@ STR_SPRITE_ALIGNER_PREVIOUS_BUTTON :{BLACK}Sprite s STR_SPRITE_ALIGNER_PREVIOUS_TOOLTIP :{BLACK}Lanjutkan ke sprite normal sebelumnya, lewati sembarang sprite bayangan/warna ulang/huruf dan pembungkus saat mulai STR_SPRITE_ALIGNER_SPRITE_TOOLTIP :{BLACK}Mewakili sprite yang sedang dipilih. Penjajaran diabaikan ketika sprite ini digambar STR_SPRITE_ALIGNER_MOVE_TOOLTIP :{BLACK}Pindahkan sprite, mengubah offset X dan Y +STR_SPRITE_ALIGNER_RESET_BUTTON :{BLACK}Reset relatif STR_SPRITE_ALIGNER_PICKER_BUTTON :{BLACK}Pilih sprite STR_SPRITE_ALIGNER_PICKER_TOOLTIP :{BLACK}Pilih sebuah sprite di manapun pada layar @@ -3435,6 +3439,8 @@ STR_BUY_VEHICLE_ROAD_VEHICLE_BUY_VEHICLE_TOOLTIP :{BLACK}Beli ken STR_BUY_VEHICLE_SHIP_BUY_VEHICLE_TOOLTIP :{BLACK}Beli kapal yang dipilih. Shift untuk menampilkan perkiraan biaya STR_BUY_VEHICLE_AIRCRAFT_BUY_VEHICLE_TOOLTIP :{BLACK}Beli pesawat yang dipilih. Shift untuk menampilkan perkiraan biaya +STR_BUY_VEHICLE_ROAD_VEHICLE_BUY_REFIT_VEHICLE_TOOLTIP :{BLACK}Beli lalu karoseri kendaraan yang dipilih. Shift+Klik untuk menampilkan perkiraan biaya tanpa membelinya +STR_BUY_VEHICLE_SHIP_BUY_REFIT_VEHICLE_TOOLTIP :{BLACK}Beli lalu karoseri kapal yang dipilih. Shift+Klik untuk menampilkan perkiraan biaya tanpa membelinya STR_BUY_VEHICLE_TRAIN_RENAME_BUTTON :{BLACK}Ubah Nama STR_BUY_VEHICLE_ROAD_VEHICLE_RENAME_BUTTON :{BLACK}Ganti Nama From 671a310d219cb0e12270578d0e63cd66701eae02 Mon Sep 17 00:00:00 2001 From: PeterN Date: Tue, 16 Apr 2019 20:30:07 +0100 Subject: [PATCH 02/17] Fix #7235: Ensure catchment area of neutral station covers entire industry. (#7518) --- src/bitmap_type.h | 11 ++++++++++- src/station.cpp | 4 +++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/bitmap_type.h b/src/bitmap_type.h index 3c9c4afbdf..655c8f3baa 100644 --- a/src/bitmap_type.h +++ b/src/bitmap_type.h @@ -57,7 +57,7 @@ public: * Initialize the BitmapTileArea with the specified Rect. * @param rect Rect to use. */ - void Initialize(Rect r) + void Initialize(const Rect &r) { this->tile = TileXY(r.left, r.top); this->w = r.right - r.left + 1; @@ -66,6 +66,15 @@ public: this->data.resize(Index(w, h)); } + void Initialize(const TileArea &ta) + { + this->tile = ta.tile; + this->w = ta.w; + this->h = ta.h; + this->data.clear(); + this->data.resize(Index(w, h)); + } + /** * Add a tile as part of the tile area. * @param tile Tile to add. diff --git a/src/station.cpp b/src/station.cpp index 85603a38c8..e8ae1bc208 100644 --- a/src/station.cpp +++ b/src/station.cpp @@ -421,10 +421,10 @@ void Station::RecomputeCatchment() this->catchment_tiles.Reset(); return; } - this->catchment_tiles.Initialize(GetCatchmentRect()); if (!_settings_game.station.serve_neutral_industries && this->industry != nullptr) { /* Station is associated with an industry, so we only need to deliver to that industry. */ + this->catchment_tiles.Initialize(this->industry->location); TILE_AREA_LOOP(tile, this->industry->location) { if (IsTileType(tile, MP_INDUSTRY) && GetIndustryIndex(tile) == this->industry->index) { this->catchment_tiles.SetTile(tile); @@ -440,6 +440,8 @@ void Station::RecomputeCatchment() return; } + this->catchment_tiles.Initialize(GetCatchmentRect()); + /* Loop finding all station tiles */ TileArea ta(TileXY(this->rect.left, this->rect.top), TileXY(this->rect.right, this->rect.bottom)); TILE_AREA_LOOP(tile, ta) { From f0b3267615b79dd9301226979812eeed39158e2d Mon Sep 17 00:00:00 2001 From: translators Date: Wed, 17 Apr 2019 19:45:47 +0200 Subject: [PATCH 03/17] Update: Translations from eints indonesian: 9 changes by fanioz --- src/lang/indonesian.txt | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/lang/indonesian.txt b/src/lang/indonesian.txt index 6056121da6..ca6c968166 100644 --- a/src/lang/indonesian.txt +++ b/src/lang/indonesian.txt @@ -990,7 +990,10 @@ STR_GAME_OPTIONS_GUI_ZOOM_DROPDOWN_NORMAL :Normal STR_GAME_OPTIONS_GUI_ZOOM_DROPDOWN_2X_ZOOM :Kali dua STR_GAME_OPTIONS_GUI_ZOOM_DROPDOWN_4X_ZOOM :Kali empat +STR_GAME_OPTIONS_FONT_ZOOM :{BLACK}Ukuran font +STR_GAME_OPTIONS_FONT_ZOOM_DROPDOWN_NORMAL :Normal +STR_GAME_OPTIONS_FONT_ZOOM_DROPDOWN_4X_ZOOM :4 kali STR_GAME_OPTIONS_BASE_GRF :{BLACK}Set Grafik Dasar STR_GAME_OPTIONS_BASE_GRF_TOOLTIP :{BLACK}Pilih grafik dasar yang digunakan @@ -1222,7 +1225,7 @@ STR_CONFIG_SETTING_NONSTOP_BY_DEFAULT :Tujuan baru sta STR_CONFIG_SETTING_NONSTOP_BY_DEFAULT_HELPTEXT :Biasanya, kendaraan akan berhenti di setiap stasiun yang di lewati. Dengan mengaktifkan pengaturan ini, maka kendaraan akan melewati semua stasiun dalam perjalanan ke tujuan akhir. Perhatikan, bahwa pengaturan ini hanya mendefinisikan nilai default. Perintah individu dapat diatur STR_CONFIG_SETTING_STOP_LOCATION :Order kereta yang baru aslinya berhenti {STRING} dari stasiun STR_CONFIG_SETTING_STOP_LOCATION_HELPTEXT :Tempat kereta akan berhenti di peron stasiun. 'Dekat akhir' berarti dekat dengan titik masuk, 'tengah' berarti di tengah-tengah peron, dan 'jauh dari akhir' berarti jauh dari titik masuk -STR_CONFIG_SETTING_STOP_LOCATION_NEAR_END :hampir selesai +STR_CONFIG_SETTING_STOP_LOCATION_NEAR_END :tepi terdekat STR_CONFIG_SETTING_STOP_LOCATION_MIDDLE :tengah STR_CONFIG_SETTING_STOP_LOCATION_FAR_END :jauh di belakang STR_CONFIG_SETTING_AUTOSCROLL :Geser tampilan saat mouse ada di tepi: {STRING} @@ -1259,6 +1262,7 @@ STR_CONFIG_SETTING_DYNAMIC_ENGINES_EXISTING_VEHICLES :{WHITE}Tidak di STR_CONFIG_SETTING_INFRASTRUCTURE_MAINTENANCE :Pemeliharaan Infrastruktur: {STRING} STR_CONFIG_SETTING_INFRASTRUCTURE_MAINTENANCE_HELPTEXT :Jika dinyalakan, infrastruktur membutuhkan biaya pemeliharaan. Biaya berkembang secara proporsional sesuai dengan ukuran jaringan, lebih berdampak pada perusahaan besar dari pada perusahaan kecil +STR_CONFIG_SETTING_COMPANY_STARTING_COLOUR_HELPTEXT :Pilih warna awal perusahaan STR_CONFIG_SETTING_NEVER_EXPIRE_AIRPORTS :Bandara tidak kedaluarsa: {STRING} STR_CONFIG_SETTING_NEVER_EXPIRE_AIRPORTS_HELPTEXT :Menyalakan setelan ini membuat semua jenis bandara tetap ada selamanya sejak pendesainanya @@ -1809,6 +1813,7 @@ STR_CHEAT_CHANGE_DATE_QUERY_CAPT :{WHITE}Ubah tah STR_CHEAT_SETUP_PROD :{LTBLUE}Aktifkan modifikasi nilai produksi: {ORANGE}{STRING} # Livery window +STR_LIVERY_CAPTION :{WHITE}{COMPANY} - Skema Warna STR_LIVERY_GENERAL_TOOLTIP :{BLACK}Tampilkan skema warna umum STR_LIVERY_TRAIN_TOOLTIP :{BLACK}Tampilkan skema warna kereta @@ -2712,6 +2717,7 @@ STR_FRAMERATE_GL_SHIPS :{WHITE} Titik k STR_FRAMERATE_GL_AIRCRAFT :{WHITE} Titik pesawat: STR_FRAMERATE_GL_LANDSCAPE :{WHITE} Titik dunia: STR_FRAMERATE_DRAWING_VIEWPORTS :{WHITE} Viewport dunia: +STR_FRAMERATE_VIDEO :{BLACK}Keluaran Video: STR_FRAMERATE_SOUND :{WHITE}Mixing suara: ############ End of leave-in-this-order ############ Leave those lines in this order!! @@ -2722,6 +2728,7 @@ STR_FRAMETIME_CAPTION_GL_SHIPS :Titik kapal STR_FRAMETIME_CAPTION_GL_AIRCRAFT :Titik pesawat STR_FRAMETIME_CAPTION_GL_LANDSCAPE :Titik dunia STR_FRAMETIME_CAPTION_SOUND :Mixing suara +STR_FRAMETIME_CAPTION_AI :AI {NUM} {STRING} ############ End of leave-in-this-order @@ -3414,6 +3421,7 @@ STR_PURCHASE_INFO_RELIABILITY :{BLACK}Kehandal STR_PURCHASE_INFO_COST :{BLACK}Biaya: {GOLD}{CURRENCY_LONG} STR_PURCHASE_INFO_WEIGHT_CWEIGHT :{BLACK}Berat: {GOLD}{WEIGHT_SHORT} ({WEIGHT_SHORT}) STR_PURCHASE_INFO_COST_SPEED :{BLACK}Biaya: {GOLD}{CURRENCY_LONG}{BLACK} Kecepatan: {GOLD}{VELOCITY} +STR_PURCHASE_INFO_COST_REFIT_SPEED :{BLACK}Biaya: {GOLD}{CURRENCY_LONG}{BLACK} (Biaya Karoseri: {GOLD}{CURRENCY_LONG}{BLACK}) Kecepatan: {GOLD}{VELOCITY} STR_PURCHASE_INFO_AIRCRAFT_CAPACITY :{BLACK}Daya Muat: {GOLD}{CARGO_LONG}, {CARGO_LONG} STR_PURCHASE_INFO_PWAGPOWER_PWAGWEIGHT :{BLACK}Daya Gerbong: {GOLD}+{POWER}{BLACK} Berat: {GOLD}+{WEIGHT_SHORT} STR_PURCHASE_INFO_REFITTABLE_TO :{BLACK}Kargo dapat di ganti untuk: {GOLD}{STRING} From 0797de06be265da4f3bb06114cae4d8e5c830e71 Mon Sep 17 00:00:00 2001 From: glx Date: Fri, 12 Apr 2019 17:47:13 +0200 Subject: [PATCH 04/17] Codechange: use std::vector for _sorted_cargo_specs --- src/cargotype.cpp | 32 +++++++++++++++----------------- src/cargotype.h | 6 +++--- src/smallmap_gui.cpp | 2 +- 3 files changed, 19 insertions(+), 21 deletions(-) diff --git a/src/cargotype.cpp b/src/cargotype.cpp index 6cc02f63a3..4a2dd6a32d 100644 --- a/src/cargotype.cpp +++ b/src/cargotype.cpp @@ -14,7 +14,7 @@ #include "newgrf_cargo.h" #include "string_func.h" #include "strings_func.h" -#include "core/sort_func.hpp" +#include #include "table/sprites.h" #include "table/strings.h" @@ -132,56 +132,54 @@ SpriteID CargoSpec::GetCargoIcon() const return sprite; } -const CargoSpec *_sorted_cargo_specs[NUM_CARGO]; ///< Cargo specifications sorted alphabetically by name. -uint8 _sorted_cargo_specs_size; ///< Number of cargo specifications stored at the _sorted_cargo_specs array (including special cargoes). -uint8 _sorted_standard_cargo_specs_size; ///< Number of standard cargo specifications stored at the _sorted_cargo_specs array. +std::vector _sorted_cargo_specs; ///< Cargo specifications sorted alphabetically by name. +uint8 _sorted_standard_cargo_specs_size; ///< Number of standard cargo specifications stored in the _sorted_cargo_specs array. /** Sort cargo specifications by their name. */ -static int CDECL CargoSpecNameSorter(const CargoSpec * const *a, const CargoSpec * const *b) +static bool CargoSpecNameSorter(const CargoSpec * const &a, const CargoSpec * const &b) { static char a_name[64]; static char b_name[64]; - GetString(a_name, (*a)->name, lastof(a_name)); - GetString(b_name, (*b)->name, lastof(b_name)); + GetString(a_name, a->name, lastof(a_name)); + GetString(b_name, b->name, lastof(b_name)); int res = strnatcmp(a_name, b_name); // Sort by name (natural sorting). /* If the names are equal, sort by cargo bitnum. */ - return (res != 0) ? res : ((*a)->bitnum - (*b)->bitnum); + return (res != 0) ? res < 0 : (a->bitnum < b->bitnum); } /** Sort cargo specifications by their cargo class. */ -static int CDECL CargoSpecClassSorter(const CargoSpec * const *a, const CargoSpec * const *b) +static bool CargoSpecClassSorter(const CargoSpec * const &a, const CargoSpec * const &b) { - int res = ((*b)->classes & CC_PASSENGERS) - ((*a)->classes & CC_PASSENGERS); + int res = (b->classes & CC_PASSENGERS) - (a->classes & CC_PASSENGERS); if (res == 0) { - res = ((*b)->classes & CC_MAIL) - ((*a)->classes & CC_MAIL); + res = (b->classes & CC_MAIL) - (a->classes & CC_MAIL); if (res == 0) { - res = ((*a)->classes & CC_SPECIAL) - ((*b)->classes & CC_SPECIAL); + res = (a->classes & CC_SPECIAL) - (b->classes & CC_SPECIAL); if (res == 0) { return CargoSpecNameSorter(a, b); } } } - return res; + return res < 0; } /** Initialize the list of sorted cargo specifications. */ void InitializeSortedCargoSpecs() { - _sorted_cargo_specs_size = 0; + _sorted_cargo_specs.clear(); const CargoSpec *cargo; /* Add each cargo spec to the list. */ FOR_ALL_CARGOSPECS(cargo) { - _sorted_cargo_specs[_sorted_cargo_specs_size] = cargo; - _sorted_cargo_specs_size++; + _sorted_cargo_specs.push_back(cargo); } /* Sort cargo specifications by cargo class and name. */ - QSortT(_sorted_cargo_specs, _sorted_cargo_specs_size, &CargoSpecClassSorter); + std::sort(_sorted_cargo_specs.begin(), _sorted_cargo_specs.end(), &CargoSpecClassSorter); _standard_cargo_mask = 0; diff --git a/src/cargotype.h b/src/cargotype.h index b35eef9659..aa67561d88 100644 --- a/src/cargotype.h +++ b/src/cargotype.h @@ -17,6 +17,7 @@ #include "gfx_type.h" #include "strings_type.h" #include "landscape_type.h" +#include /** Globally unique label of a cargo type. */ typedef uint32 CargoLabel; @@ -137,8 +138,7 @@ CargoID GetCargoIDByLabel(CargoLabel cl); CargoID GetCargoIDByBitnum(uint8 bitnum); void InitializeSortedCargoSpecs(); -extern const CargoSpec *_sorted_cargo_specs[NUM_CARGO]; -extern uint8 _sorted_cargo_specs_size; +extern std::vector _sorted_cargo_specs; extern uint8 _sorted_standard_cargo_specs_size; /** @@ -163,7 +163,7 @@ static inline bool IsCargoInClass(CargoID c, CargoClass cc) * @param var Reference getting the cargospec. * @see CargoSpec */ -#define FOR_ALL_SORTED_CARGOSPECS(var) for (uint8 index = 0; index < _sorted_cargo_specs_size && (var = _sorted_cargo_specs[index], true) ; index++) +#define FOR_ALL_SORTED_CARGOSPECS(var) for (uint8 index = 0; index < _sorted_cargo_specs.size() && (var = _sorted_cargo_specs[index], true) ; index++) /** * Loop header for iterating over 'real' cargoes, sorted by name. Phony cargoes like regearing cargoes are skipped. diff --git a/src/smallmap_gui.cpp b/src/smallmap_gui.cpp index 1249851735..69ce56d345 100644 --- a/src/smallmap_gui.cpp +++ b/src/smallmap_gui.cpp @@ -210,7 +210,7 @@ void BuildLinkStatsLegend() memset(_legend_linkstats, 0, sizeof(_legend_linkstats)); uint i = 0; - for (; i < _sorted_cargo_specs_size; ++i) { + for (; i < _sorted_cargo_specs.size(); ++i) { const CargoSpec *cs = _sorted_cargo_specs[i]; _legend_linkstats[i].legend = cs->name; From 25e534f3cf42a723f97d6fc08d582329e60a0186 Mon Sep 17 00:00:00 2001 From: glx Date: Fri, 12 Apr 2019 17:55:35 +0200 Subject: [PATCH 05/17] Codechange: use std::vector for _sorted_railtypes --- src/rail.h | 5 ++--- src/rail_cmd.cpp | 13 ++++++------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/rail.h b/src/rail.h index 8bfc3f025b..8619bac6d9 100644 --- a/src/rail.h +++ b/src/rail.h @@ -464,14 +464,13 @@ void ResetRailTypes(); void InitRailTypes(); RailType AllocateRailType(RailTypeLabel label); -extern RailType _sorted_railtypes[RAILTYPE_END]; -extern uint8 _sorted_railtypes_size; +extern std::vector _sorted_railtypes; extern RailTypes _railtypes_hidden_mask; /** * Loop header for iterating over railtypes, sorted by sortorder. * @param var Railtype. */ -#define FOR_ALL_SORTED_RAILTYPES(var) for (uint8 index = 0; index < _sorted_railtypes_size && (var = _sorted_railtypes[index], true) ; index++) +#define FOR_ALL_SORTED_RAILTYPES(var) for (uint8 index = 0; index < _sorted_railtypes.size() && (var = _sorted_railtypes[index], true) ; index++) #endif /* RAIL_H */ diff --git a/src/rail_cmd.cpp b/src/rail_cmd.cpp index d8327c4449..6964a5aaf0 100644 --- a/src/rail_cmd.cpp +++ b/src/rail_cmd.cpp @@ -44,8 +44,7 @@ typedef std::vector TrainList; RailtypeInfo _railtypes[RAILTYPE_END]; -RailType _sorted_railtypes[RAILTYPE_END]; -uint8 _sorted_railtypes_size; +std::vector _sorted_railtypes; RailTypes _railtypes_hidden_mask; /** Enum holding the signal offset in the sprite sheet according to the side it is representing. */ @@ -130,9 +129,9 @@ void ResolveRailTypeGUISprites(RailtypeInfo *rti) * @param second The railtype to compare. * @return True iff the first should be sorted before the second. */ -static int CDECL CompareRailTypes(const RailType *first, const RailType *second) +static bool CompareRailTypes(const RailType &first, const RailType &second) { - return GetRailTypeInfo(*first)->sorting_order - GetRailTypeInfo(*second)->sorting_order; + return GetRailTypeInfo(first)->sorting_order < GetRailTypeInfo(second)->sorting_order; } /** @@ -146,13 +145,13 @@ void InitRailTypes() if (HasBit(rti->flags, RTF_HIDDEN)) SetBit(_railtypes_hidden_mask, rt); } - _sorted_railtypes_size = 0; + _sorted_railtypes.clear(); for (RailType rt = RAILTYPE_BEGIN; rt != RAILTYPE_END; rt++) { if (_railtypes[rt].label != 0 && !HasBit(_railtypes_hidden_mask, rt)) { - _sorted_railtypes[_sorted_railtypes_size++] = rt; + _sorted_railtypes.push_back(rt); } } - QSortT(_sorted_railtypes, _sorted_railtypes_size, CompareRailTypes); + std::sort(_sorted_railtypes.begin(), _sorted_railtypes.end(), CompareRailTypes); } /** From 9195f2337a7c4f9154058877093bbb74db33cf32 Mon Sep 17 00:00:00 2001 From: glx Date: Fri, 12 Apr 2019 18:46:49 +0200 Subject: [PATCH 06/17] Codechange: use std::vector for _resolutions --- src/core/geometry_type.hpp | 14 ++++++++++++++ src/driver.cpp | 17 ++++++++--------- src/gfx.cpp | 13 +++---------- src/gfx_func.h | 5 ++--- src/settings_gui.cpp | 21 +++++++++------------ src/video/allegro_v.cpp | 38 ++++++++++++++------------------------ src/video/cocoa/cocoa_v.mm | 20 +++++++++----------- src/video/sdl_v.cpp | 38 +++++++++++++------------------------- src/video/video_driver.hpp | 4 ++-- src/video/win32_v.cpp | 33 +++++++++------------------------ 10 files changed, 83 insertions(+), 120 deletions(-) diff --git a/src/core/geometry_type.hpp b/src/core/geometry_type.hpp index d1f363127b..2927cd9804 100644 --- a/src/core/geometry_type.hpp +++ b/src/core/geometry_type.hpp @@ -29,6 +29,20 @@ struct Point { struct Dimension { uint width; uint height; + + Dimension(uint w = 0, uint h = 0) : width(w), height(h) {}; + + bool operator< (const Dimension &other) const + { + int x = (*this).width - other.width; + if (x != 0) return x < 0; + return (*this).height < other.height; + } + + bool operator== (const Dimension &other) const + { + return (*this).width == other.width && (*this).height == other.height; + } }; /** Specification of a rectangle with absolute coordinates of all edges */ diff --git a/src/driver.cpp b/src/driver.cpp index 390fb381e0..f1b4d67ded 100644 --- a/src/driver.cpp +++ b/src/driver.cpp @@ -18,18 +18,17 @@ #include "safeguards.h" -char *_ini_videodriver; ///< The video driver a stored in the configuration file. -int _num_resolutions; ///< The number of resolutions. -Dimension _resolutions[32]; ///< List of resolutions. -Dimension _cur_resolution; ///< The current resolution. -bool _rightclick_emulate; ///< Whether right clicking is emulated. +char *_ini_videodriver; ///< The video driver a stored in the configuration file. +std::vector _resolutions; ///< List of resolutions. +Dimension _cur_resolution; ///< The current resolution. +bool _rightclick_emulate; ///< Whether right clicking is emulated. -char *_ini_sounddriver; ///< The sound driver a stored in the configuration file. +char *_ini_sounddriver; ///< The sound driver a stored in the configuration file. -char *_ini_musicdriver; ///< The music driver a stored in the configuration file. +char *_ini_musicdriver; ///< The music driver a stored in the configuration file. -char *_ini_blitter; ///< The blitter as stored in the configuration file. -bool _blitter_autodetected; ///< Was the blitter autodetected or specified by the user? +char *_ini_blitter; ///< The blitter as stored in the configuration file. +bool _blitter_autodetected; ///< Was the blitter autodetected or specified by the user? /** * Get a string parameter the list of parameters. diff --git a/src/gfx.cpp b/src/gfx.cpp index 279dd35a82..97ae0f510e 100644 --- a/src/gfx.cpp +++ b/src/gfx.cpp @@ -1691,20 +1691,13 @@ bool ChangeResInGame(int width, int height) bool ToggleFullScreen(bool fs) { bool result = VideoDriver::GetInstance()->ToggleFullscreen(fs); - if (_fullscreen != fs && _num_resolutions == 0) { + if (_fullscreen != fs && _resolutions.empty()) { DEBUG(driver, 0, "Could not find a suitable fullscreen resolution"); } return result; } -static int CDECL compare_res(const Dimension *pa, const Dimension *pb) +void SortResolutions() { - int x = pa->width - pb->width; - if (x != 0) return x; - return pa->height - pb->height; -} - -void SortResolutions(int count) -{ - QSortT(_resolutions, count, &compare_res); + std::sort(_resolutions.begin(), _resolutions.end()); } diff --git a/src/gfx_func.h b/src/gfx_func.h index bbace39132..1724a931f5 100644 --- a/src/gfx_func.h +++ b/src/gfx_func.h @@ -66,8 +66,7 @@ extern bool _right_button_clicked; extern DrawPixelInfo _screen; extern bool _screen_disable_anim; ///< Disable palette animation (important for 32bpp-anim blitter during giant screenshot) -extern int _num_resolutions; -extern Dimension _resolutions[32]; +extern std::vector _resolutions; extern Dimension _cur_resolution; extern Palette _cur_palette; ///< Current palette @@ -162,7 +161,7 @@ void SetAnimatedMouseCursor(const AnimCursor *table); void CursorTick(); void UpdateCursorSize(); bool ChangeResInGame(int w, int h); -void SortResolutions(int count); +void SortResolutions(); bool ToggleFullScreen(bool fs); /* gfx.cpp */ diff --git a/src/settings_gui.cpp b/src/settings_gui.cpp index 51b5340e39..f4c7e466c4 100644 --- a/src/settings_gui.cpp +++ b/src/settings_gui.cpp @@ -104,17 +104,14 @@ static inline StringID TownName(int town_name) /** * Get index of the current screen resolution. - * @return Index of the current screen resolution if it is a known resolution, #_num_resolutions otherwise. + * @return Index of the current screen resolution if it is a known resolution, _resolutions.size() otherwise. */ -static int GetCurRes() +static uint GetCurRes() { - int i; + uint i; - for (i = 0; i != _num_resolutions; i++) { - if ((int)_resolutions[i].width == _screen.width && - (int)_resolutions[i].height == _screen.height) { - break; - } + for (i = 0; i != _resolutions.size(); i++) { + if (_resolutions[i] == Dimension(_screen.width, _screen.height)) break; } return i; } @@ -286,10 +283,10 @@ struct GameOptionsWindow : Window { } case WID_GO_RESOLUTION_DROPDOWN: // Setup resolution dropdown - if (_num_resolutions == 0) break; + if (_resolutions.empty()) break; *selected_index = GetCurRes(); - for (int i = 0; i < _num_resolutions; i++) { + for (uint i = 0; i < _resolutions.size(); i++) { list.emplace_back(new DropDownListStringItem(SPECSTR_RESOLUTION_START + i, i, false)); } break; @@ -336,7 +333,7 @@ struct GameOptionsWindow : Window { case WID_GO_TOWNNAME_DROPDOWN: SetDParam(0, TownName(this->opt->game_creation.town_name)); break; case WID_GO_AUTOSAVE_DROPDOWN: SetDParam(0, _autosave_dropdown[_settings_client.gui.autosave]); break; case WID_GO_LANG_DROPDOWN: SetDParamStr(0, _current_language->own_name); break; - case WID_GO_RESOLUTION_DROPDOWN: SetDParam(0, GetCurRes() == _num_resolutions ? STR_GAME_OPTIONS_RESOLUTION_OTHER : SPECSTR_RESOLUTION_START + GetCurRes()); break; + case WID_GO_RESOLUTION_DROPDOWN: SetDParam(0, GetCurRes() == _resolutions.size() ? STR_GAME_OPTIONS_RESOLUTION_OTHER : SPECSTR_RESOLUTION_START + GetCurRes()); break; case WID_GO_GUI_ZOOM_DROPDOWN: SetDParam(0, _gui_zoom_dropdown[ZOOM_LVL_OUT_4X - _gui_zoom]); break; case WID_GO_FONT_ZOOM_DROPDOWN: SetDParam(0, _font_zoom_dropdown[ZOOM_LVL_OUT_4X - _font_zoom]); break; case WID_GO_BASE_GRF_DROPDOWN: SetDParamStr(0, BaseGraphics::GetUsedSet()->name); break; @@ -535,7 +532,7 @@ struct GameOptionsWindow : Window { break; case WID_GO_RESOLUTION_DROPDOWN: // Change resolution - if (index < _num_resolutions && ChangeResInGame(_resolutions[index].width, _resolutions[index].height)) { + if ((uint)index < _resolutions.size() && ChangeResInGame(_resolutions[index].width, _resolutions[index].height)) { this->SetDirty(); } break; diff --git a/src/video/allegro_v.cpp b/src/video/allegro_v.cpp index 47dd92e1e2..3d4aea8f11 100644 --- a/src/video/allegro_v.cpp +++ b/src/video/allegro_v.cpp @@ -28,6 +28,7 @@ #include "../thread.h" #include "allegro_v.h" #include +#include #include "../safeguards.h" @@ -139,34 +140,25 @@ static void GetVideoModes() * cards ourselves... and we need a card to get the modes. */ set_gfx_mode(_fullscreen ? GFX_AUTODETECT_FULLSCREEN : GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0); + _resolutions.clear(); + GFX_MODE_LIST *mode_list = get_gfx_mode_list(gfx_driver->id); if (mode_list == nullptr) { - memcpy(_resolutions, default_resolutions, sizeof(default_resolutions)); - _num_resolutions = lengthof(default_resolutions); + _resolutions.assign(std::begin(default_resolutions), std::end(default_resolutions)); return; } GFX_MODE *modes = mode_list->mode; - int n = 0; for (int i = 0; modes[i].bpp != 0; i++) { uint w = modes[i].width; uint h = modes[i].height; - if (w >= 640 && h >= 480) { - int j; - for (j = 0; j < n; j++) { - if (_resolutions[j].width == w && _resolutions[j].height == h) break; - } - - if (j == n) { - _resolutions[j].width = w; - _resolutions[j].height = h; - if (++n == lengthof(_resolutions)) break; - } - } + if (w < 640 || h < 480) continue; + if (std::find(_resolutions.begin(), _resolutions.end(), Dimension(w, h)) != _resolutions.end()) continue; + _resolutions.emplace_back(w, h); } - _num_resolutions = n; - SortResolutions(_num_resolutions); + + SortResolutions(); destroy_gfx_mode_list(mode_list); } @@ -174,17 +166,15 @@ static void GetVideoModes() static void GetAvailableVideoMode(uint *w, uint *h) { /* No video modes, so just try it and see where it ends */ - if (_num_resolutions == 0) return; + if (_resolutions.empty()) return; /* is the wanted mode among the available modes? */ - for (int i = 0; i != _num_resolutions; i++) { - if (*w == _resolutions[i].width && *h == _resolutions[i].height) return; - } + if (std::find(_resolutions.begin(), _resolutions.end(), Dimension(*w, *h)) != _resolutions.end()) return; /* use the closest possible resolution */ - int best = 0; + uint best = 0; uint delta = Delta(_resolutions[0].width, *w) * Delta(_resolutions[0].height, *h); - for (int i = 1; i != _num_resolutions; ++i) { + for (uint i = 1; i != _resolutions.size(); ++i) { uint newdelta = Delta(_resolutions[i].width, *w) * Delta(_resolutions[i].height, *h); if (newdelta < delta) { best = i; @@ -545,7 +535,7 @@ bool VideoDriver_Allegro::ToggleFullscreen(bool fullscreen) { _fullscreen = fullscreen; GetVideoModes(); // get the list of available video modes - if (_num_resolutions == 0 || !this->ChangeResolution(_cur_resolution.width, _cur_resolution.height)) { + if (_resolutions.empty() || !this->ChangeResolution(_cur_resolution.width, _cur_resolution.height)) { /* switching resolution failed, put back full_screen to original status */ _fullscreen ^= true; return false; diff --git a/src/video/cocoa/cocoa_v.mm b/src/video/cocoa/cocoa_v.mm index d165610245..17bca028ba 100644 --- a/src/video/cocoa/cocoa_v.mm +++ b/src/video/cocoa/cocoa_v.mm @@ -234,13 +234,13 @@ static void setupApplication() } -static int CDECL ModeSorter(const OTTD_Point *p1, const OTTD_Point *p2) +static bool ModeSorter(const OTTD_Point &p1, const OTTD_Point &p2) { - if (p1->x < p2->x) return -1; - if (p1->x > p2->x) return +1; - if (p1->y < p2->y) return -1; - if (p1->y > p2->y) return +1; - return 0; + if (p1.x < p2.x) return true; + if (p1.x > p2.x) return false; + if (p1.y < p2.y) return true; + if (p1.y > p2.y) return false; + return false; } static void QZ_GetDisplayModeInfo(CFArrayRef modes, CFIndex i, int &bpp, uint16 &width, uint16 &height) @@ -326,7 +326,7 @@ uint QZ_ListModes(OTTD_Point *modes, uint max_modes, CGDirectDisplayID display_i } /* Sort list smallest to largest */ - QSortT(modes, count, &ModeSorter); + std::sort(modes, modes + count, ModeSorter); #if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6) if (MacOSVersionIsAtLeast(10, 6, 0)) CFRelease(mode_list); @@ -363,12 +363,10 @@ static void QZ_UpdateVideoModes() OTTD_Point modes[32]; uint count = _cocoa_subdriver->ListModes(modes, lengthof(modes)); + _resolutions.clear(); for (uint i = 0; i < count; i++) { - _resolutions[i].width = modes[i].x; - _resolutions[i].height = modes[i].y; + _resolutions.emplace_back(modes[i].x, modes[i].y); } - - _num_resolutions = count; } /** diff --git a/src/video/sdl_v.cpp b/src/video/sdl_v.cpp index 2f6184e852..87880dea7c 100644 --- a/src/video/sdl_v.cpp +++ b/src/video/sdl_v.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include "../safeguards.h" @@ -207,53 +208,40 @@ static void GetVideoModes() SDL_Rect **modes = SDL_ListModes(nullptr, SDL_SWSURFACE | SDL_FULLSCREEN); if (modes == nullptr) usererror("sdl: no modes available"); + _resolutions.clear(); + _all_modes = (SDL_ListModes(nullptr, SDL_SWSURFACE | (_fullscreen ? SDL_FULLSCREEN : 0)) == (void*)-1); if (modes == (void*)-1) { - int n = 0; for (uint i = 0; i < lengthof(_default_resolutions); i++) { if (SDL_VideoModeOK(_default_resolutions[i].width, _default_resolutions[i].height, 8, SDL_FULLSCREEN) != 0) { - _resolutions[n] = _default_resolutions[i]; - if (++n == lengthof(_resolutions)) break; + _resolutions.push_back(_default_resolutions[i]); } } - _num_resolutions = n; } else { - int n = 0; for (int i = 0; modes[i]; i++) { uint w = modes[i]->w; uint h = modes[i]->h; if (w < 640 || h < 480) continue; // reject too small resolutions - int j; - for (j = 0; j < n; j++) { - if (_resolutions[j].width == w && _resolutions[j].height == h) break; - } - - if (j == n) { - _resolutions[j].width = w; - _resolutions[j].height = h; - if (++n == lengthof(_resolutions)) break; - } + if (std::find(_resolutions.begin(), _resolutions.end(), Dimension(w, h)) != _resolutions.end()) continue; + _resolutions.emplace_back(w, h); } - if (n == 0) usererror("No usable screen resolutions found!\n"); - _num_resolutions = n; - SortResolutions(_num_resolutions); + if (_resolutions.empty()) usererror("No usable screen resolutions found!\n"); + SortResolutions(); } } static void GetAvailableVideoMode(uint *w, uint *h) { /* All modes available? */ - if (_all_modes || _num_resolutions == 0) return; + if (_all_modes || _resolutions.empty()) return; /* Is the wanted mode among the available modes? */ - for (int i = 0; i != _num_resolutions; i++) { - if (*w == _resolutions[i].width && *h == _resolutions[i].height) return; - } + if (std::find(_resolutions.begin(), _resolutions.end(), Dimension(*w, *h)) != _resolutions.end()) return; /* Use the closest possible resolution */ - int best = 0; + uint best = 0; uint delta = Delta(_resolutions[0].width, *w) * Delta(_resolutions[0].height, *h); - for (int i = 1; i != _num_resolutions; ++i) { + for (uint i = 1; i != _resolutions.size(); ++i) { uint newdelta = Delta(_resolutions[i].width, *w) * Delta(_resolutions[i].height, *h); if (newdelta < delta) { best = i; @@ -817,7 +805,7 @@ bool VideoDriver_SDL::ToggleFullscreen(bool fullscreen) _fullscreen = fullscreen; GetVideoModes(); // get the list of available video modes - bool ret = _num_resolutions != 0 && CreateMainSurface(_cur_resolution.width, _cur_resolution.height); + bool ret = !_resolutions.empty() && CreateMainSurface(_cur_resolution.width, _cur_resolution.height); if (!ret) { /* switching resolution failed, put back full_screen to original status */ diff --git a/src/video/video_driver.hpp b/src/video/video_driver.hpp index 5cb3c6cc3f..b774c7ba6e 100644 --- a/src/video/video_driver.hpp +++ b/src/video/video_driver.hpp @@ -14,6 +14,7 @@ #include "../driver.h" #include "../core/geometry_type.hpp" +#include /** The base of all video drivers. */ class VideoDriver : public Driver { @@ -101,8 +102,7 @@ public: }; extern char *_ini_videodriver; -extern int _num_resolutions; -extern Dimension _resolutions[32]; +extern std::vector _resolutions; extern Dimension _cur_resolution; extern bool _rightclick_emulate; diff --git a/src/video/win32_v.cpp b/src/video/win32_v.cpp index 7eea4782ac..cd2b298aea 100644 --- a/src/video/win32_v.cpp +++ b/src/video/win32_v.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include "../safeguards.h" @@ -1085,45 +1086,29 @@ static const Dimension default_resolutions[] = { static void FindResolutions() { - uint n = 0; uint i; DEVMODEA dm; /* Check modes for the relevant fullscreen bpp */ uint bpp = _support8bpp != S8BPP_HARDWARE ? 32 : BlitterFactory::GetCurrentBlitter()->GetScreenDepth(); + _resolutions.clear(); + /* XXX - EnumDisplaySettingsW crashes with unicows.dll on Windows95 * Doesn't really matter since we don't pass a string anyways, but still * a letdown */ for (i = 0; EnumDisplaySettingsA(nullptr, i, &dm) != 0; i++) { - if (dm.dmBitsPerPel == bpp && - dm.dmPelsWidth >= 640 && dm.dmPelsHeight >= 480) { - uint j; - - for (j = 0; j < n; j++) { - if (_resolutions[j].width == dm.dmPelsWidth && _resolutions[j].height == dm.dmPelsHeight) break; - } - - /* In the previous loop we have checked already existing/added resolutions if - * they are the same as the new ones. If this is not the case (j == n); we have - * looped all and found none, add the new one to the list. If we have reached the - * maximum amount of resolutions, then quit querying the display */ - if (j == n) { - _resolutions[j].width = dm.dmPelsWidth; - _resolutions[j].height = dm.dmPelsHeight; - if (++n == lengthof(_resolutions)) break; - } - } + if (dm.dmBitsPerPel != bpp || dm.dmPelsWidth < 640 || dm.dmPelsHeight < 480) continue; + if (std::find(_resolutions.begin(), _resolutions.end(), Dimension(dm.dmPelsWidth, dm.dmPelsHeight)) != _resolutions.end()) continue; + _resolutions.emplace_back(dm.dmPelsWidth, dm.dmPelsHeight); } /* We have found no resolutions, show the default list */ - if (n == 0) { - memcpy(_resolutions, default_resolutions, sizeof(default_resolutions)); - n = lengthof(default_resolutions); + if (_resolutions.empty()) { + _resolutions.assign(std::begin(default_resolutions), std::end(default_resolutions)); } - _num_resolutions = n; - SortResolutions(_num_resolutions); + SortResolutions(); } static FVideoDriver_Win32 iFVideoDriver_Win32; From 889927261452da616c5289f016e84b6f201141e8 Mon Sep 17 00:00:00 2001 From: glx Date: Sat, 13 Apr 2019 22:53:18 +0200 Subject: [PATCH 07/17] Codechange: use std::vector for _language_dropdown --- src/network/network_gui.cpp | 14 +++++++------- src/strings.cpp | 8 ++++---- src/strings_func.h | 2 +- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/network/network_gui.cpp b/src/network/network_gui.cpp index 50678e8a6b..29bc88959a 100644 --- a/src/network/network_gui.cpp +++ b/src/network/network_gui.cpp @@ -63,18 +63,18 @@ static const StringID _lan_internet_types_dropdown[] = { INVALID_STRING_ID }; -static StringID _language_dropdown[NETLANG_COUNT + 1] = {STR_NULL}; +static std::vector _language_dropdown; void SortNetworkLanguages() { /* Init the strings */ - if (_language_dropdown[0] == STR_NULL) { - for (int i = 0; i < NETLANG_COUNT; i++) _language_dropdown[i] = STR_NETWORK_LANG_ANY + i; - _language_dropdown[NETLANG_COUNT] = INVALID_STRING_ID; + if (_language_dropdown.empty()) { + for (int i = 0; i < NETLANG_COUNT; i++) _language_dropdown.emplace_back(STR_NETWORK_LANG_ANY + i); + _language_dropdown.emplace_back(INVALID_STRING_ID); } /* Sort the strings (we don't move 'any' and the 'invalid' one) */ - QSortT(_language_dropdown + 1, NETLANG_COUNT - 1, &StringIDSorter); + std::sort(_language_dropdown.begin() + 1, _language_dropdown.end() - 1, StringIDSorter); } /** @@ -1172,13 +1172,13 @@ struct NetworkStartServerWindow : public Window { case WID_NSS_LANGUAGE_BTN: { // Language uint sel = 0; - for (uint i = 0; i < lengthof(_language_dropdown) - 1; i++) { + for (uint i = 0; i < _language_dropdown.size() - 1; i++) { if (_language_dropdown[i] == STR_NETWORK_LANG_ANY + _settings_client.network.server_lang) { sel = i; break; } } - ShowDropDownMenu(this, _language_dropdown, sel, WID_NSS_LANGUAGE_BTN, 0, 0); + ShowDropDownMenu(this, _language_dropdown.data(), sel, WID_NSS_LANGUAGE_BTN, 0, 0); break; } diff --git a/src/strings.cpp b/src/strings.cpp index ed8d439b4f..1ed679e27a 100644 --- a/src/strings.cpp +++ b/src/strings.cpp @@ -1864,14 +1864,14 @@ const char *GetCurrentLocale(const char *param) const char *GetCurrentLocale(const char *param); #endif /* !(defined(_WIN32) || defined(__APPLE__)) */ -int CDECL StringIDSorter(const StringID *a, const StringID *b) +bool StringIDSorter(const StringID &a, const StringID &b) { char stra[512]; char strb[512]; - GetString(stra, *a, lastof(stra)); - GetString(strb, *b, lastof(strb)); + GetString(stra, a, lastof(stra)); + GetString(strb, b, lastof(strb)); - return strnatcmp(stra, strb); + return strnatcmp(stra, strb) < 0; } /** diff --git a/src/strings_func.h b/src/strings_func.h index a5e2e1ca22..d0fbde4956 100644 --- a/src/strings_func.h +++ b/src/strings_func.h @@ -238,7 +238,7 @@ extern TextDirection _current_text_dir; ///< Text direction of the currently sel void InitializeLanguagePacks(); const char *GetCurrentLanguageIsoCode(); -int CDECL StringIDSorter(const StringID *a, const StringID *b); +bool StringIDSorter(const StringID &a, const StringID &b); /** * A searcher for missing glyphs. From 9388fa2aa12db72b80d10def4752d5c37bb806cb Mon Sep 17 00:00:00 2001 From: glx Date: Sat, 13 Apr 2019 23:11:56 +0200 Subject: [PATCH 08/17] Codechange: use std::vector to sort _all_grfs linked list --- src/newgrf_config.cpp | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/src/newgrf_config.cpp b/src/newgrf_config.cpp index 2eef5d1833..676f677bcf 100644 --- a/src/newgrf_config.cpp +++ b/src/newgrf_config.cpp @@ -709,16 +709,13 @@ bool GRFFileScanner::AddFile(const char *filename, size_t basepath_length, const /** * Simple sorter for GRFS - * @param p1 the first GRFConfig * - * @param p2 the second GRFConfig * - * @return the same strcmp would return for the name of the NewGRF. + * @param c1 the first GRFConfig * + * @param c2 the second GRFConfig * + * @return true if the name of first NewGRF is before the name of the second. */ -static int CDECL GRFSorter(GRFConfig * const *p1, GRFConfig * const *p2) +static bool GRFSorter(GRFConfig * const &c1, GRFConfig * const &c2) { - const GRFConfig *c1 = *p1; - const GRFConfig *c2 = *p2; - - return strnatcmp(c1->GetName(), c2->GetName()); + return strnatcmp(c1->GetName(), c2->GetName()) < 0; } /** @@ -740,16 +737,16 @@ void DoScanNewGRFFiles(NewGRFScanCallback *callback) /* Sort the linked list using quicksort. * For that we first have to make an array, then sort and * then remake the linked list. */ - GRFConfig **to_sort = MallocT(num); + std::vector to_sort; uint i = 0; for (GRFConfig *p = _all_grfs; p != nullptr; p = p->next, i++) { - to_sort[i] = p; + to_sort.push_back(p); } /* Number of files is not necessarily right */ num = i; - QSortT(to_sort, num, &GRFSorter); + std::sort(to_sort.begin(), to_sort.end(), GRFSorter); for (i = 1; i < num; i++) { to_sort[i - 1]->next = to_sort[i]; @@ -757,8 +754,6 @@ void DoScanNewGRFFiles(NewGRFScanCallback *callback) to_sort[num - 1]->next = nullptr; _all_grfs = to_sort[0]; - free(to_sort); - NetworkAfterNewGRFScan(); } From 60da17418a190eb262eda5eadb03954a8b98a0e6 Mon Sep 17 00:00:00 2001 From: glx Date: Sat, 13 Apr 2019 23:19:58 +0200 Subject: [PATCH 09/17] Codechange: use std::sort in SaveHighScoreValueNetwork() --- src/highscore.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/highscore.cpp b/src/highscore.cpp index a69bdc46af..71b31c384a 100644 --- a/src/highscore.cpp +++ b/src/highscore.cpp @@ -79,9 +79,9 @@ int8 SaveHighScoreValue(const Company *c) } /** Sort all companies given their performance */ -static int CDECL HighScoreSorter(const Company * const *a, const Company * const *b) +static bool HighScoreSorter(const Company * const &a, const Company * const &b) { - return (*b)->old_economy[0].performance_history - (*a)->old_economy[0].performance_history; + return b->old_economy[0].performance_history < a->old_economy[0].performance_history; } /** @@ -98,7 +98,7 @@ int8 SaveHighScoreValueNetwork() /* Sort all active companies with the highest score first */ FOR_ALL_COMPANIES(c) cl[count++] = c; - QSortT(cl, count, &HighScoreSorter); + std::sort(std::begin(cl), std::begin(cl) + count, HighScoreSorter); { uint i; From 48f99fd980f0577ab4336d7807a1781000253c3b Mon Sep 17 00:00:00 2001 From: glx Date: Sat, 13 Apr 2019 23:46:11 +0200 Subject: [PATCH 10/17] Codechange: use std::array for _sorted_industry_types --- src/industry_gui.cpp | 24 +++++++++++------------- src/industrytype.h | 3 ++- src/smallmap_gui.cpp | 3 +-- 3 files changed, 14 insertions(+), 16 deletions(-) diff --git a/src/industry_gui.cpp b/src/industry_gui.cpp index 98fb098591..f698ace570 100644 --- a/src/industry_gui.cpp +++ b/src/industry_gui.cpp @@ -183,23 +183,23 @@ static inline void GetAllCargoSuffixes(CargoSuffixInOut use_input, CargoSuffixTy } } -IndustryType _sorted_industry_types[NUM_INDUSTRYTYPES]; ///< Industry types sorted by name. +std::array _sorted_industry_types; ///< Industry types sorted by name. /** Sort industry types by their name. */ -static int CDECL IndustryTypeNameSorter(const IndustryType *a, const IndustryType *b) +static bool IndustryTypeNameSorter(const IndustryType &a, const IndustryType &b) { static char industry_name[2][64]; - const IndustrySpec *indsp1 = GetIndustrySpec(*a); + const IndustrySpec *indsp1 = GetIndustrySpec(a); GetString(industry_name[0], indsp1->name, lastof(industry_name[0])); - const IndustrySpec *indsp2 = GetIndustrySpec(*b); + const IndustrySpec *indsp2 = GetIndustrySpec(b); GetString(industry_name[1], indsp2->name, lastof(industry_name[1])); int r = strnatcmp(industry_name[0], industry_name[1]); // Sort by name (natural sorting). /* If the names are equal, sort by industry type. */ - return (r != 0) ? r : (*a - *b); + return (r != 0) ? r < 0 : (a < b); } /** @@ -213,7 +213,7 @@ void SortIndustryTypes() } /* Sort industry types by name. */ - QSortT(_sorted_industry_types, NUM_INDUSTRYTYPES, &IndustryTypeNameSorter); + std::sort(_sorted_industry_types.begin(), _sorted_industry_types.end(), IndustryTypeNameSorter); } /** @@ -302,8 +302,7 @@ class BuildIndustryWindow : public Window { * The tests performed after the enabled allow to load the industries * In the same way they are inserted by grf (if any) */ - for (uint i = 0; i < NUM_INDUSTRYTYPES; i++) { - IndustryType ind = _sorted_industry_types[i]; + for (IndustryType ind : _sorted_industry_types) { const IndustrySpec *indsp = GetIndustrySpec(ind); if (indsp->enabled) { /* Rule is that editor mode loads all industries. @@ -2723,8 +2722,7 @@ struct IndustryCargoesWindow : public Window { case WID_IC_IND_DROPDOWN: { DropDownList lst; - for (uint i = 0; i < NUM_INDUSTRYTYPES; i++) { - IndustryType ind = _sorted_industry_types[i]; + for (IndustryType ind : _sorted_industry_types) { const IndustrySpec *indsp = GetIndustrySpec(ind); if (!indsp->enabled) continue; lst.emplace_back(new DropDownListStringItem(indsp->name, ind, false)); @@ -2811,10 +2809,10 @@ const int IndustryCargoesWindow::VERT_TEXT_PADDING = 5; ///< Vertical padding ar static void ShowIndustryCargoesWindow(IndustryType id) { if (id >= NUM_INDUSTRYTYPES) { - for (uint i = 0; i < NUM_INDUSTRYTYPES; i++) { - const IndustrySpec *indsp = GetIndustrySpec(_sorted_industry_types[i]); + for (IndustryType ind : _sorted_industry_types) { + const IndustrySpec *indsp = GetIndustrySpec(ind); if (indsp->enabled) { - id = _sorted_industry_types[i]; + id = ind; break; } } diff --git a/src/industrytype.h b/src/industrytype.h index cd451fa777..8f1357b671 100644 --- a/src/industrytype.h +++ b/src/industrytype.h @@ -12,6 +12,7 @@ #ifndef INDUSTRYTYPE_H #define INDUSTRYTYPE_H +#include #include "map_type.h" #include "slope_type.h" #include "industry_type.h" @@ -179,7 +180,7 @@ extern IndustryTileSpec _industry_tile_specs[NUM_INDUSTRYTILES]; /* industry_gui.cpp */ void SortIndustryTypes(); /* Industry types sorted alphabetically by name. */ -extern IndustryType _sorted_industry_types[NUM_INDUSTRYTYPES]; +extern std::array _sorted_industry_types; /** * Do industry gfx ID translation for NewGRFs. diff --git a/src/smallmap_gui.cpp b/src/smallmap_gui.cpp index 69ce56d345..58e89c57fc 100644 --- a/src/smallmap_gui.cpp +++ b/src/smallmap_gui.cpp @@ -178,8 +178,7 @@ void BuildIndustriesLegend() uint j = 0; /* Add each name */ - for (uint i = 0; i < NUM_INDUSTRYTYPES; i++) { - IndustryType ind = _sorted_industry_types[i]; + for (IndustryType ind : _sorted_industry_types) { const IndustrySpec *indsp = GetIndustrySpec(ind); if (indsp->enabled) { _legend_from_industries[j].legend = indsp->name; From ebd4f32d15c34d7191546002cd06f99ad6b43d0c Mon Sep 17 00:00:00 2001 From: glx Date: Sun, 14 Apr 2019 00:42:45 +0200 Subject: [PATCH 11/17] Cleanup: remove core/sort_func.hpp as it's not used anymore --- projects/openttd_vs140.vcxproj | 1 - projects/openttd_vs140.vcxproj.filters | 3 - projects/openttd_vs141.vcxproj | 1 - projects/openttd_vs141.vcxproj.filters | 3 - projects/openttd_vs142.vcxproj | 1 - projects/openttd_vs142.vcxproj.filters | 3 - source.list | 1 - src/core/smallmap_type.hpp | 1 - src/core/sort_func.hpp | 89 -------------------------- src/highscore.cpp | 1 - src/sortlist_type.h | 1 - src/timetable_cmd.cpp | 1 - 12 files changed, 106 deletions(-) delete mode 100644 src/core/sort_func.hpp diff --git a/projects/openttd_vs140.vcxproj b/projects/openttd_vs140.vcxproj index f437e2c891..8bcb36764a 100644 --- a/projects/openttd_vs140.vcxproj +++ b/projects/openttd_vs140.vcxproj @@ -742,7 +742,6 @@ - diff --git a/projects/openttd_vs140.vcxproj.filters b/projects/openttd_vs140.vcxproj.filters index 399894b73e..140e632e3e 100644 --- a/projects/openttd_vs140.vcxproj.filters +++ b/projects/openttd_vs140.vcxproj.filters @@ -1314,9 +1314,6 @@ Core Source Code - - Core Source Code - Core Source Code diff --git a/projects/openttd_vs141.vcxproj b/projects/openttd_vs141.vcxproj index 89b9d0217f..3f0eff4730 100644 --- a/projects/openttd_vs141.vcxproj +++ b/projects/openttd_vs141.vcxproj @@ -742,7 +742,6 @@ - diff --git a/projects/openttd_vs141.vcxproj.filters b/projects/openttd_vs141.vcxproj.filters index 399894b73e..140e632e3e 100644 --- a/projects/openttd_vs141.vcxproj.filters +++ b/projects/openttd_vs141.vcxproj.filters @@ -1314,9 +1314,6 @@ Core Source Code - - Core Source Code - Core Source Code diff --git a/projects/openttd_vs142.vcxproj b/projects/openttd_vs142.vcxproj index a3ac8fd368..de1838a23c 100644 --- a/projects/openttd_vs142.vcxproj +++ b/projects/openttd_vs142.vcxproj @@ -742,7 +742,6 @@ - diff --git a/projects/openttd_vs142.vcxproj.filters b/projects/openttd_vs142.vcxproj.filters index 399894b73e..140e632e3e 100644 --- a/projects/openttd_vs142.vcxproj.filters +++ b/projects/openttd_vs142.vcxproj.filters @@ -1314,9 +1314,6 @@ Core Source Code - - Core Source Code - Core Source Code diff --git a/source.list b/source.list index 5496edc55a..f5089d03de 100644 --- a/source.list +++ b/source.list @@ -447,7 +447,6 @@ core/smallmap_type.hpp core/smallmatrix_type.hpp core/smallstack_type.hpp core/smallvec_type.hpp -core/sort_func.hpp core/string_compare_type.hpp # GUI Source Code diff --git a/src/core/smallmap_type.hpp b/src/core/smallmap_type.hpp index 21cc0e76fd..d050522821 100644 --- a/src/core/smallmap_type.hpp +++ b/src/core/smallmap_type.hpp @@ -13,7 +13,6 @@ #define SMALLMAP_TYPE_HPP #include "smallvec_type.hpp" -#include "sort_func.hpp" /** * Simple pair of data. Both types have to be POD ("Plain Old Data")! diff --git a/src/core/sort_func.hpp b/src/core/sort_func.hpp deleted file mode 100644 index d557d24bd7..0000000000 --- a/src/core/sort_func.hpp +++ /dev/null @@ -1,89 +0,0 @@ -/* $Id$ */ - -/* - * This file is part of OpenTTD. - * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2. - * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see . - */ - -/** @file sort_func.hpp Functions related to sorting operations. */ - -#ifndef SORT_FUNC_HPP -#define SORT_FUNC_HPP - -#include "mem_func.hpp" - -/** - * Type safe qsort() - * - * @note Use this sort for irregular sorted data. - * - * @param base Pointer to the first element of the array to be sorted. - * @param num Number of elements in the array pointed by base. - * @param comparator Function that compares two elements. - * @param desc Sort descending. - */ -template -static inline void QSortT(T *base, size_t num, int (CDECL *comparator)(const T*, const T*), bool desc = false) -{ - if (num < 2) return; - - qsort(base, num, sizeof(T), (int (CDECL *)(const void *, const void *))comparator); - - if (desc) MemReverseT(base, num); -} - -/** - * Type safe Gnome Sort. - * - * This is a slightly modified Gnome search. The basic - * Gnome search tries to sort already sorted list parts. - * The modification skips these. - * - * @note Use this sort for presorted / regular sorted data. - * - * @param base Pointer to the first element of the array to be sorted. - * @param num Number of elements in the array pointed by base. - * @param comparator Function that compares two elements. - * @param desc Sort descending. - */ -template -static inline void GSortT(T *base, size_t num, int (CDECL *comparator)(const T*, const T*), bool desc = false) -{ - if (num < 2) return; - - assert(base != nullptr); - assert(comparator != nullptr); - - T *a = base; - T *b = base + 1; - uint offset = 0; - - while (num > 1) { - const int diff = comparator(a, b); - if ((!desc && diff <= 0) || (desc && diff >= 0)) { - if (offset != 0) { - /* Jump back to the last direction switch point */ - a += offset; - b += offset; - offset = 0; - continue; - } - - a++; - b++; - num--; - } else { - Swap(*a, *b); - - if (a == base) continue; - - a--; - b--; - offset++; - } - } -} - -#endif /* SORT_FUNC_HPP */ diff --git a/src/highscore.cpp b/src/highscore.cpp index 71b31c384a..687417229b 100644 --- a/src/highscore.cpp +++ b/src/highscore.cpp @@ -17,7 +17,6 @@ #include "string_func.h" #include "strings_func.h" #include "table/strings.h" -#include "core/sort_func.hpp" #include "debug.h" #include "safeguards.h" diff --git a/src/sortlist_type.h b/src/sortlist_type.h index 8174995cab..47f6638634 100644 --- a/src/sortlist_type.h +++ b/src/sortlist_type.h @@ -14,7 +14,6 @@ #include "core/enum_type.hpp" #include "core/bitmath_func.hpp" -#include "core/sort_func.hpp" #include "core/smallvec_type.hpp" #include "date_type.h" diff --git a/src/timetable_cmd.cpp b/src/timetable_cmd.cpp index 2b2de28a91..979534bb37 100644 --- a/src/timetable_cmd.cpp +++ b/src/timetable_cmd.cpp @@ -16,7 +16,6 @@ #include "window_func.h" #include "vehicle_base.h" #include "cmd_helper.h" -#include "core/sort_func.hpp" #include "table/strings.h" From 66a8db9dc5d2eaa586f19aef47b06d7bc08a732f Mon Sep 17 00:00:00 2001 From: glx22 Date: Fri, 19 Apr 2019 18:48:01 +0200 Subject: [PATCH 12/17] Fix #7526, 5b77102b6: FiosItem::operator< must return false for equality (#7528) --- src/fios.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/fios.cpp b/src/fios.cpp index 76a2e7430f..30a505ef7e 100644 --- a/src/fios.cpp +++ b/src/fios.cpp @@ -52,16 +52,15 @@ extern void GetOldSaveGameName(const char *file, char *title, const char *last); */ bool FiosItem::operator< (const FiosItem &other) const { - bool r = false; + int r = false; if ((_savegame_sort_order & SORT_BY_NAME) == 0 && (*this).mtime != other.mtime) { - r = (*this).mtime < other.mtime; + r = (*this).mtime - other.mtime; } else { - r = strcasecmp((*this).title, other.title) < 0; + r = strcasecmp((*this).title, other.title); } - - if (_savegame_sort_order & SORT_DESCENDING) r = !r; - return r; + if (r == 0) return false; + return (_savegame_sort_order & SORT_DESCENDING) ? r > 0 : r < 0; } FileList::~FileList() From d2b6176cdf9f37bea676972239471d950df4d531 Mon Sep 17 00:00:00 2001 From: PeterN Date: Sat, 20 Apr 2019 02:21:25 +0100 Subject: [PATCH 13/17] Add: NewGRF string codes to access PUSH/POP_COLOUR. (#7527) --- src/newgrf_text.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/newgrf_text.cpp b/src/newgrf_text.cpp index 4cba3c368a..5387d67679 100644 --- a/src/newgrf_text.cpp +++ b/src/newgrf_text.cpp @@ -528,6 +528,9 @@ char *TranslateTTDPatchCodes(uint32 grfid, uint8 language_id, bool allow_newline d += Utf8Encode(d, SCC_NEWGRF_PRINT_DWORD_DATE_LONG + code - 0x16); break; + case 0x1F: d += Utf8Encode(d, SCC_PUSH_COLOUR); break; + case 0x20: d += Utf8Encode(d, SCC_POP_COLOUR); break; + default: grfmsg(1, "missing handler for extended format code"); break; From be073b46daa9b70102e6299588f43454a35e46cf Mon Sep 17 00:00:00 2001 From: PeterN Date: Sat, 20 Apr 2019 02:34:25 +0100 Subject: [PATCH 14/17] Fix: Bounds check access to railtype_map. (#7529) --- src/newgrf.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/newgrf.cpp b/src/newgrf.cpp index 7e4ba801d7..20408394ee 100644 --- a/src/newgrf.cpp +++ b/src/newgrf.cpp @@ -5478,7 +5478,8 @@ static void RailTypeMapSpriteGroup(ByteReader *buf, uint8 idcount) { uint8 *railtypes = AllocaM(uint8, idcount); for (uint i = 0; i < idcount; i++) { - railtypes[i] = _cur.grffile->railtype_map[buf->ReadByte()]; + uint8 id = buf->ReadByte(); + railtypes[i] = id < RAILTYPE_END ? _cur.grffile->railtype_map[id] : INVALID_RAILTYPE; } uint8 cidcount = buf->ReadByte(); From c17736b493bccad5aeb51fd3b490d79ec7b60a7a Mon Sep 17 00:00:00 2001 From: PeterN Date: Sat, 20 Apr 2019 17:49:54 +0100 Subject: [PATCH 15/17] Fix e8d397e: Invisible station/waypoint signs could still be clicked on. (#7531) --- src/viewport.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/viewport.cpp b/src/viewport.cpp index 804aa1cc6f..b3865f7639 100644 --- a/src/viewport.cpp +++ b/src/viewport.cpp @@ -1999,15 +1999,17 @@ static bool CheckClickOnViewportSign(const ViewPort *vp, int x, int y, const Vie */ static bool CheckClickOnViewportSign(const ViewPort *vp, int x, int y) { + if (_game_mode == GM_MENU) return false; + x = ScaleByZoom(x - vp->left, vp->zoom) + vp->virtual_left; y = ScaleByZoom(y - vp->top, vp->zoom) + vp->virtual_top; Rect search_rect{ x - 1, y - 1, x + 1, y + 1 }; search_rect = ExpandRectWithViewportSignMargins(search_rect, vp->zoom); - bool show_stations = HasBit(_display_opt, DO_SHOW_STATION_NAMES) && _game_mode != GM_MENU; - bool show_waypoints = HasBit(_display_opt, DO_SHOW_WAYPOINT_NAMES) && _game_mode != GM_MENU; - bool show_towns = HasBit(_display_opt, DO_SHOW_TOWN_NAMES) && _game_mode != GM_MENU; + bool show_stations = HasBit(_display_opt, DO_SHOW_STATION_NAMES) && !IsInvisibilitySet(TO_SIGNS); + bool show_waypoints = HasBit(_display_opt, DO_SHOW_WAYPOINT_NAMES) && !IsInvisibilitySet(TO_SIGNS); + bool show_towns = HasBit(_display_opt, DO_SHOW_TOWN_NAMES); bool show_signs = HasBit(_display_opt, DO_SHOW_SIGNS) && !IsInvisibilitySet(TO_SIGNS); bool show_competitors = HasBit(_display_opt, DO_SHOW_COMPETITOR_SIGNS); From ac1e1a272fbba07195c1bf7613a886b692fb159d Mon Sep 17 00:00:00 2001 From: peter1138 Date: Sun, 21 Apr 2019 21:01:42 +0100 Subject: [PATCH 16/17] Fix: Replace int with std::underlying_type in DECLARE_ENUM_AS_BIT_SET. This fixes 64 bit uses of this macro. --- src/core/enum_type.hpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/core/enum_type.hpp b/src/core/enum_type.hpp index 35a0cb2926..920cb514a8 100644 --- a/src/core/enum_type.hpp +++ b/src/core/enum_type.hpp @@ -31,13 +31,13 @@ /** Operators to allow to work with enum as with type safe bit set in C++ */ # define DECLARE_ENUM_AS_BIT_SET(mask_t) \ - inline mask_t operator | (mask_t m1, mask_t m2) {return (mask_t)((int)m1 | m2);} \ - inline mask_t operator & (mask_t m1, mask_t m2) {return (mask_t)((int)m1 & m2);} \ - inline mask_t operator ^ (mask_t m1, mask_t m2) {return (mask_t)((int)m1 ^ m2);} \ + inline mask_t operator | (mask_t m1, mask_t m2) {return (mask_t)((std::underlying_type::type)m1 | m2);} \ + inline mask_t operator & (mask_t m1, mask_t m2) {return (mask_t)((std::underlying_type::type)m1 & m2);} \ + inline mask_t operator ^ (mask_t m1, mask_t m2) {return (mask_t)((std::underlying_type::type)m1 ^ m2);} \ inline mask_t& operator |= (mask_t& m1, mask_t m2) {m1 = m1 | m2; return m1;} \ inline mask_t& operator &= (mask_t& m1, mask_t m2) {m1 = m1 & m2; return m1;} \ inline mask_t& operator ^= (mask_t& m1, mask_t m2) {m1 = m1 ^ m2; return m1;} \ - inline mask_t operator ~(mask_t m) {return (mask_t)(~(int)m);} + inline mask_t operator ~(mask_t m) {return (mask_t)(~(std::underlying_type::type)m);} /** From 66cd32a252ee0edab11448b560371878b2189223 Mon Sep 17 00:00:00 2001 From: peter1138 Date: Sun, 21 Apr 2019 21:48:08 +0100 Subject: [PATCH 17/17] Codechange: Use std::underlying_type for DECLARE_POSTFIX_INCREMENT. --- src/core/enum_type.hpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/core/enum_type.hpp b/src/core/enum_type.hpp index 920cb514a8..d5bcf6dbe1 100644 --- a/src/core/enum_type.hpp +++ b/src/core/enum_type.hpp @@ -13,17 +13,17 @@ #define ENUM_TYPE_HPP /** Some enums need to have allowed incrementing (i.e. StationClassID) */ -#define DECLARE_POSTFIX_INCREMENT(type) \ - inline type operator ++(type& e, int) \ +#define DECLARE_POSTFIX_INCREMENT(enum_type) \ + inline enum_type operator ++(enum_type& e, int) \ { \ - type e_org = e; \ - e = (type)((int)e + 1); \ + enum_type e_org = e; \ + e = (enum_type)((std::underlying_type::type)e + 1); \ return e_org; \ } \ - inline type operator --(type& e, int) \ + inline enum_type operator --(enum_type& e, int) \ { \ - type e_org = e; \ - e = (type)((int)e - 1); \ + enum_type e_org = e; \ + e = (enum_type)((std::underlying_type::type)e - 1); \ return e_org; \ }