From a496e9397c6897d2a6f74d077d2cd7ef9309a010 Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Mon, 14 Oct 2024 20:42:20 +0100 Subject: [PATCH] Codechange: Prefer member-initialization. --- src/pathfinder/yapf/yapf_base.hpp | 33 ++++++++++---------------- src/pathfinder/yapf/yapf_node_rail.hpp | 27 +++++++-------------- 2 files changed, 21 insertions(+), 39 deletions(-) diff --git a/src/pathfinder/yapf/yapf_base.hpp b/src/pathfinder/yapf/yapf_base.hpp index 51d795d1d4..3b87051915 100644 --- a/src/pathfinder/yapf/yapf_base.hpp +++ b/src/pathfinder/yapf/yapf_base.hpp @@ -56,33 +56,24 @@ public: typedef typename Node::Key Key; ///< key to hash tables - NodeList m_nodes; ///< node list multi-container -protected: - Node *m_pBestDestNode; ///< pointer to the destination node found at last round - Node *m_pBestIntermediateNode; ///< here should be node closest to the destination if path not found - const YAPFSettings *m_settings; ///< current settings (_settings_game.yapf) - int m_max_search_nodes; ///< maximum number of nodes we are allowed to visit before we give up - const VehicleType *m_veh; ///< vehicle that we are trying to drive + NodeList m_nodes; ///< node list multi-container - int m_stats_cost_calcs; ///< stats - how many node's costs were calculated - int m_stats_cache_hits; ///< stats - how many node's costs were reused from cache +protected: + Node *m_pBestDestNode = nullptr; ///< pointer to the destination node found at last round + Node *m_pBestIntermediateNode = nullptr; ///< here should be node closest to the destination if path not found + const YAPFSettings *m_settings; ///< current settings (_settings_game.yapf) + int m_max_search_nodes; ///< maximum number of nodes we are allowed to visit before we give up + const VehicleType *m_veh = nullptr; ///< vehicle that we are trying to drive + + int m_stats_cost_calcs = 0; ///< stats - how many node's costs were calculated + int m_stats_cache_hits = 0; ///< stats - how many node's costs were reused from cache public: - int m_num_steps; ///< this is there for debugging purposes (hope it doesn't hurt) + int m_num_steps = 0; ///< this is there for debugging purposes (hope it doesn't hurt) public: /** default constructor */ - inline CYapfBaseT() - : m_pBestDestNode(nullptr) - , m_pBestIntermediateNode(nullptr) - , m_settings(&_settings_game.pf.yapf) - , m_max_search_nodes(PfGetSettings().max_search_nodes) - , m_veh(nullptr) - , m_stats_cost_calcs(0) - , m_stats_cache_hits(0) - , m_num_steps(0) - { - } + inline CYapfBaseT() : m_settings(&_settings_game.pf.yapf), m_max_search_nodes(PfGetSettings().max_search_nodes) {} /** default destructor */ ~CYapfBaseT() {} diff --git a/src/pathfinder/yapf/yapf_node_rail.hpp b/src/pathfinder/yapf/yapf_node_rail.hpp index 19724dbc01..9cafc632de 100644 --- a/src/pathfinder/yapf/yapf_node_rail.hpp +++ b/src/pathfinder/yapf/yapf_node_rail.hpp @@ -68,25 +68,16 @@ struct CYapfRailSegment { typedef CYapfRailSegmentKey Key; - CYapfRailSegmentKey m_key; - TileIndex m_last_tile; - Trackdir m_last_td; - int m_cost; - TileIndex m_last_signal_tile; - Trackdir m_last_signal_td; - EndSegmentReasonBits m_end_segment_reason; - CYapfRailSegment *m_hash_next; + CYapfRailSegmentKey m_key; + TileIndex m_last_tile = INVALID_TILE; + Trackdir m_last_td = INVALID_TRACKDIR; + int m_cost = -1; + TileIndex m_last_signal_tile = INVALID_TILE; + Trackdir m_last_signal_td = INVALID_TRACKDIR; + EndSegmentReasonBits m_end_segment_reason = ESRB_NONE; + CYapfRailSegment *m_hash_next = nullptr; - inline CYapfRailSegment(const CYapfRailSegmentKey &key) - : m_key(key) - , m_last_tile(INVALID_TILE) - , m_last_td(INVALID_TRACKDIR) - , m_cost(-1) - , m_last_signal_tile(INVALID_TILE) - , m_last_signal_td(INVALID_TRACKDIR) - , m_end_segment_reason(ESRB_NONE) - , m_hash_next(nullptr) - {} + inline CYapfRailSegment(const CYapfRailSegmentKey &key) : m_key(key) {} inline const Key &GetKey() const {