From 3ad143c43a7dce89060168a335557233471d7718 Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Mon, 15 Apr 2024 23:07:36 +0100 Subject: [PATCH] Codechange: Use `x = y` instead of `x{y}` for value-type member initialisation. (#12501) This is easier to read and less likely to look like an array definition. --- src/bootstrap_gui.cpp | 8 ++++---- src/cargopacket.h | 18 +++++++++--------- src/cargotype.h | 8 ++++---- src/newgrf_storage.h | 2 +- src/station_base.h | 18 +++++++++--------- src/textfile_gui.h | 16 ++++++++-------- 6 files changed, 35 insertions(+), 35 deletions(-) diff --git a/src/bootstrap_gui.cpp b/src/bootstrap_gui.cpp index e2e0e37004..3f19c7fae0 100644 --- a/src/bootstrap_gui.cpp +++ b/src/bootstrap_gui.cpp @@ -291,10 +291,10 @@ public: # include "video/video_driver.hpp" class BootstrapEmscripten : public ContentCallback { - bool downloading{false}; - uint total_files{0}; - uint total_bytes{0}; - uint downloaded_bytes{0}; + bool downloading = false; + uint total_files = 0; + uint total_bytes = 0; + uint downloaded_bytes = 0; public: BootstrapEmscripten() diff --git a/src/cargopacket.h b/src/cargopacket.h index 6498760822..07ae8911d9 100644 --- a/src/cargopacket.h +++ b/src/cargopacket.h @@ -45,23 +45,23 @@ private: int16_t y; }; - uint16_t count{0}; ///< The amount of cargo in this packet. - uint16_t periods_in_transit{0}; ///< Amount of cargo aging periods this packet has been in transit. + uint16_t count = 0; ///< The amount of cargo in this packet. + uint16_t periods_in_transit = 0; ///< Amount of cargo aging periods this packet has been in transit. - Money feeder_share{0}; ///< Value of feeder pickup to be paid for on delivery of cargo. + Money feeder_share = 0; ///< Value of feeder pickup to be paid for on delivery of cargo. - TileIndex source_xy{INVALID_TILE}; ///< The origin of the cargo. + TileIndex source_xy = INVALID_TILE; ///< The origin of the cargo. Vector travelled{0, 0}; ///< If cargo is in station: the vector from the unload tile to the source tile. If in vehicle: an intermediate value. - SourceID source_id{INVALID_SOURCE}; ///< Index of industry/town/HQ, INVALID_SOURCE if unknown/invalid. - SourceType source_type{SourceType::Industry}; ///< Type of \c source_id. + SourceID source_id = INVALID_SOURCE; ///< Index of industry/town/HQ, INVALID_SOURCE if unknown/invalid. + SourceType source_type = SourceType::Industry; ///< Type of \c source_id. #ifdef WITH_ASSERT - bool in_vehicle{false}; ///< NOSAVE: Whether this cargo is in a vehicle or not. + bool in_vehicle = false; ///< NOSAVE: Whether this cargo is in a vehicle or not. #endif /* WITH_ASSERT */ - StationID first_station{INVALID_STATION}; ///< The station where the cargo came from first. - StationID next_hop{INVALID_STATION}; ///< Station where the cargo wants to go next. + StationID first_station = INVALID_STATION; ///< The station where the cargo came from first. + StationID next_hop = INVALID_STATION; ///< Station where the cargo wants to go next. /** The CargoList caches, thus needs to know about it. */ template friend class CargoList; diff --git a/src/cargotype.h b/src/cargotype.h index 9314d34482..10aae014d2 100644 --- a/src/cargotype.h +++ b/src/cargotype.h @@ -67,19 +67,19 @@ static const uint TOWN_PRODUCTION_DIVISOR = 256; /** Specification of a cargo type. */ struct CargoSpec { CargoLabel label; ///< Unique label of the cargo type. - uint8_t bitnum{INVALID_CARGO_BITNUM}; ///< Cargo bit number, is #INVALID_CARGO_BITNUM for a non-used spec. + uint8_t bitnum = INVALID_CARGO_BITNUM; ///< Cargo bit number, is #INVALID_CARGO_BITNUM for a non-used spec. uint8_t legend_colour; uint8_t rating_colour; uint8_t weight; ///< Weight of a single unit of this cargo type in 1/16 ton (62.5 kg). - uint16_t multiplier{0x100}; ///< Capacity multiplier for vehicles. (8 fractional bits) + uint16_t multiplier = 0x100; ///< Capacity multiplier for vehicles. (8 fractional bits) uint16_t classes; ///< Classes of this cargo type. @see CargoClass int32_t initial_payment; ///< Initial payment rate before inflation is applied. uint8_t transit_periods[2]; bool is_freight; ///< Cargo type is considered to be freight (affects train freight multiplier). TownAcceptanceEffect town_acceptance_effect; ///< The effect that delivering this cargo type has on towns. Also affects destination of subsidies. - TownProductionEffect town_production_effect{INVALID_TPE}; ///< The effect on town cargo production. - uint16_t town_production_multiplier{TOWN_PRODUCTION_DIVISOR}; ///< Town production multipler, if commanded by TownProductionEffect. + TownProductionEffect town_production_effect = INVALID_TPE; ///< The effect on town cargo production. + uint16_t town_production_multiplier = TOWN_PRODUCTION_DIVISOR; ///< Town production multipler, if commanded by TownProductionEffect. uint8_t callback_mask; ///< Bitmask of cargo callbacks that have to be called StringID name; ///< Name of this type of cargo. diff --git a/src/newgrf_storage.h b/src/newgrf_storage.h index fe71caea1f..cad016d691 100644 --- a/src/newgrf_storage.h +++ b/src/newgrf_storage.h @@ -136,7 +136,7 @@ struct TemporaryStorageArray { StorageType storage{}; ///< Memory for the storage array StorageInitType init{}; ///< Storage has been assigned, if this equals 'init_key'. - uint16_t init_key{1}; ///< Magic key to 'init'. + uint16_t init_key = 1; ///< Magic key to 'init'. /** * Stores some value at a given position. diff --git a/src/station_base.h b/src/station_base.h index 17e2147e21..12ed87355a 100644 --- a/src/station_base.h +++ b/src/station_base.h @@ -210,20 +210,20 @@ struct GoodsEntry { StationCargoList cargo{}; ///< The cargo packets of cargo waiting in this station FlowStatMap flows{}; ///< Planned flows through this station. - uint max_waiting_cargo{0}; ///< Max cargo from this station waiting at any station. - NodeID node{INVALID_NODE}; ///< ID of node in link graph referring to this goods entry. - LinkGraphID link_graph{INVALID_LINK_GRAPH}; ///< Link graph this station belongs to. + uint max_waiting_cargo = 0; ///< Max cargo from this station waiting at any station. + NodeID node = INVALID_NODE; ///< ID of node in link graph referring to this goods entry. + LinkGraphID link_graph = INVALID_LINK_GRAPH; ///< Link graph this station belongs to. - uint8_t status{0}; ///< Status of this cargo, see #GoodsEntryStatus. + uint8_t status = 0; ///< Status of this cargo, see #GoodsEntryStatus. /** * Number of rating-intervals (up to 255) since the last vehicle tried to load this cargo. * The unit used is STATION_RATING_TICKS. * This does not imply there was any cargo to load. */ - uint8_t time_since_pickup{255}; + uint8_t time_since_pickup = 255; - uint8_t rating{INITIAL_STATION_RATING}; ///< %Station rating for this cargo. + uint8_t rating = INITIAL_STATION_RATING; ///< %Station rating for this cargo. /** * Maximum speed (up to 255) of the last vehicle that tried to load this cargo. @@ -234,15 +234,15 @@ struct GoodsEntry { * - Ships: 0.5 * km-ish/h * - Aircraft: 8 * mph */ - uint8_t last_speed{0}; + uint8_t last_speed = 0; /** * Age in years (up to 255) of the last vehicle that tried to load this cargo. * This does not imply there was any cargo to load. */ - uint8_t last_age{255}; + uint8_t last_age = 255; - uint8_t amount_fract{0}; ///< Fractional part of the amount in the cargo list + uint8_t amount_fract = 0; ///< Fractional part of the amount in the cargo list /** * Reports whether a vehicle has ever tried to load the cargo at this station. diff --git a/src/textfile_gui.h b/src/textfile_gui.h index 09d55a355d..ab365d42d5 100644 --- a/src/textfile_gui.h +++ b/src/textfile_gui.h @@ -44,10 +44,10 @@ protected: void ConstructWindow(); struct Line { - int top{0}; ///< Top scroll position in visual lines. - int bottom{0}; ///< Bottom scroll position in visual lines. - std::string text{}; ///< Contents of the line. - TextColour colour{TC_WHITE}; ///< Colour to render text line in. + int top = 0; ///< Top scroll position in visual lines. + int bottom = 0; ///< Bottom scroll position in visual lines. + std::string text{}; ///< Contents of the line. + TextColour colour = TC_WHITE; ///< Colour to render text line in. Line(int top, std::string_view text) : top(top), bottom(top + 1), text(text) {} Line() {} @@ -73,8 +73,8 @@ protected: std::vector links; ///< Clickable links in lines. std::vector link_anchors; ///< Anchor names of headings that can be linked to. std::vector history; ///< Browsing history in this window. - size_t history_pos{0}; ///< Position in browsing history (for forward movement). - bool trusted{false}; ///< Whether the content is trusted (read: not from content like NewGRFs, etc). + size_t history_pos = 0; ///< Position in browsing history (for forward movement). + bool trusted = false; ///< Whether the content is trusted (read: not from content like NewGRFs, etc). void LoadText(std::string_view buf); void FindHyperlinksInMarkdown(Line &line, size_t line_index); @@ -97,8 +97,8 @@ protected: void NavigateHistory(int delta); private: - uint search_iterator{0}; ///< Iterator for the font check search. - uint max_length{0}; ///< Maximum length of unwrapped text line. + uint search_iterator = 0; ///< Iterator for the font check search. + uint max_length = 0; ///< Maximum length of unwrapped text line. uint ReflowContent(); uint GetContentHeight();