diff options
Diffstat (limited to 'src/pathfinder/yapf')
-rw-r--r-- | src/pathfinder/yapf/nodelist.hpp | 20 | ||||
-rw-r--r-- | src/pathfinder/yapf/yapf_base.hpp | 28 | ||||
-rw-r--r-- | src/pathfinder/yapf/yapf_common.hpp | 6 | ||||
-rw-r--r-- | src/pathfinder/yapf/yapf_costcache.hpp | 2 | ||||
-rw-r--r-- | src/pathfinder/yapf/yapf_costrail.hpp | 8 | ||||
-rw-r--r-- | src/pathfinder/yapf/yapf_node.hpp | 2 | ||||
-rw-r--r-- | src/pathfinder/yapf/yapf_node_rail.hpp | 12 | ||||
-rw-r--r-- | src/pathfinder/yapf/yapf_rail.cpp | 36 | ||||
-rw-r--r-- | src/pathfinder/yapf/yapf_road.cpp | 10 | ||||
-rw-r--r-- | src/pathfinder/yapf/yapf_ship.cpp | 12 |
10 files changed, 68 insertions, 68 deletions
diff --git a/src/pathfinder/yapf/nodelist.hpp b/src/pathfinder/yapf/nodelist.hpp index 87e65fd26..45a72efd5 100644 --- a/src/pathfinder/yapf/nodelist.hpp +++ b/src/pathfinder/yapf/nodelist.hpp @@ -42,7 +42,7 @@ public: /** default constructor */ CNodeList_HashTableT() : m_open_queue(2048) { - m_new_node = NULL; + m_new_node = nullptr; } /** destructor */ @@ -65,7 +65,7 @@ public: /** allocate new data item from m_arr */ inline Titem_ *CreateNewNode() { - if (m_new_node == NULL) m_new_node = m_arr.AppendC(); + if (m_new_node == nullptr) m_new_node = m_arr.AppendC(); return m_new_node; } @@ -74,7 +74,7 @@ public: { /* for now it is enough to invalidate m_new_node if it is our given node */ if (&item == m_new_node) { - m_new_node = NULL; + m_new_node = nullptr; } /* TODO: do we need to store best nodes found in some extra list/array? Probably not now. */ } @@ -82,11 +82,11 @@ public: /** insert given item as open node (into m_open and m_open_queue) */ inline void InsertOpenNode(Titem_ &item) { - assert(m_closed.Find(item.GetKey()) == NULL); + assert(m_closed.Find(item.GetKey()) == nullptr); m_open.Push(item); m_open_queue.Include(&item); if (&item == m_new_node) { - m_new_node = NULL; + m_new_node = nullptr; } } @@ -96,7 +96,7 @@ public: if (!m_open_queue.IsEmpty()) { return m_open_queue.Begin(); } - return NULL; + return nullptr; } /** remove and return the best open node */ @@ -107,10 +107,10 @@ public: m_open.Pop(*item); return item; } - return NULL; + return nullptr; } - /** return the open node specified by a key or NULL if not found */ + /** return the open node specified by a key or nullptr if not found */ inline Titem_ *FindOpenNode(const Key &key) { Titem_ *item = m_open.Find(key); @@ -129,11 +129,11 @@ public: /** close node */ inline void InsertClosedNode(Titem_ &item) { - assert(m_open.Find(item.GetKey()) == NULL); + assert(m_open.Find(item.GetKey()) == nullptr); m_closed.Push(item); } - /** return the closed node specified by a key or NULL if not found */ + /** return the closed node specified by a key or nullptr if not found */ inline Titem_ *FindClosedNode(const Key &key) { Titem_ *item = m_closed.Find(key); diff --git a/src/pathfinder/yapf/yapf_base.hpp b/src/pathfinder/yapf/yapf_base.hpp index 6360567bb..5483b9874 100644 --- a/src/pathfinder/yapf/yapf_base.hpp +++ b/src/pathfinder/yapf/yapf_base.hpp @@ -81,11 +81,11 @@ public: public: /** default constructor */ inline CYapfBaseT() - : m_pBestDestNode(NULL) - , m_pBestIntermediateNode(NULL) + : m_pBestDestNode(nullptr) + , m_pBestIntermediateNode(nullptr) , m_settings(&_settings_game.pf.yapf) , m_max_search_nodes(PfGetSettings().max_search_nodes) - , m_veh(NULL) + , m_veh(nullptr) , m_stats_cost_calcs(0) , m_stats_cache_hits(0) , m_num_steps(0) @@ -131,12 +131,12 @@ public: for (;;) { m_num_steps++; Node *n = m_nodes.GetBestOpenNode(); - if (n == NULL) { + if (n == nullptr) { break; } /* if the best open node was worse than the best path found, we can finish */ - if (m_pBestDestNode != NULL && m_pBestDestNode->GetCost() < n->GetCostEstimate()) { + if (m_pBestDestNode != nullptr && m_pBestDestNode->GetCost() < n->GetCostEstimate()) { break; } @@ -150,7 +150,7 @@ public: } } - bDestFound &= (m_pBestDestNode != NULL); + bDestFound &= (m_pBestDestNode != nullptr); perf.Stop(); if (_debug_yapf_level >= 2) { @@ -158,7 +158,7 @@ public: _total_pf_time_us += t; if (_debug_yapf_level >= 3) { - UnitID veh_idx = (m_veh != NULL) ? m_veh->unitnumber : 0; + UnitID veh_idx = (m_veh != nullptr) ? m_veh->unitnumber : 0; char ttc = Yapf().TransportTypeChar(); float cache_hit_ratio = (m_stats_cache_hits == 0) ? 0.0f : ((float)m_stats_cache_hits / (float)(m_stats_cache_hits + m_stats_cost_calcs) * 100.0f); int cost = bDestFound ? m_pBestDestNode->m_cost : -1; @@ -180,7 +180,7 @@ public: */ inline Node *GetBestNode() { - return (m_pBestDestNode != NULL) ? m_pBestDestNode : m_pBestIntermediateNode; + return (m_pBestDestNode != nullptr) ? m_pBestDestNode : m_pBestIntermediateNode; } /** @@ -198,7 +198,7 @@ public: { Yapf().PfNodeCacheFetch(n); /* insert the new node only if it is not there */ - if (m_nodes.FindOpenNode(n.m_key) == NULL) { + if (m_nodes.FindOpenNode(n.m_key) == nullptr) { m_nodes.InsertOpenNode(n); } else { /* if we are here, it means that node is already there - how it is possible? @@ -229,7 +229,7 @@ public: */ void PruneIntermediateNodeBranch() { - while (Yapf().m_pBestIntermediateNode != NULL && (Yapf().m_pBestIntermediateNode->m_segment->m_end_segment_reason & ESRB_CHOICE_FOLLOWS) == 0) { + while (Yapf().m_pBestIntermediateNode != nullptr && (Yapf().m_pBestIntermediateNode->m_segment->m_end_segment_reason & ESRB_CHOICE_FOLLOWS) == 0) { Yapf().m_pBestIntermediateNode = Yapf().m_pBestIntermediateNode->m_parent; } } @@ -262,20 +262,20 @@ public: /* detect the destination */ bool bDestination = Yapf().PfDetectDestination(n); if (bDestination) { - if (m_pBestDestNode == NULL || n < *m_pBestDestNode) { + if (m_pBestDestNode == nullptr || n < *m_pBestDestNode) { m_pBestDestNode = &n; } m_nodes.FoundBestNode(n); return; } - if (m_max_search_nodes > 0 && (m_pBestIntermediateNode == NULL || (m_pBestIntermediateNode->GetCostEstimate() - m_pBestIntermediateNode->GetCost()) > (n.GetCostEstimate() - n.GetCost()))) { + if (m_max_search_nodes > 0 && (m_pBestIntermediateNode == nullptr || (m_pBestIntermediateNode->GetCostEstimate() - m_pBestIntermediateNode->GetCost()) > (n.GetCostEstimate() - n.GetCost()))) { m_pBestIntermediateNode = &n; } /* check new node against open list */ Node *openNode = m_nodes.FindOpenNode(n.GetKey()); - if (openNode != NULL) { + if (openNode != nullptr) { /* another node exists with the same key in the open list * is it better than new one? */ if (n.GetCostEstimate() < openNode->GetCostEstimate()) { @@ -290,7 +290,7 @@ public: /* check new node against closed list */ Node *closedNode = m_nodes.FindClosedNode(n.GetKey()); - if (closedNode != NULL) { + if (closedNode != nullptr) { /* another node exists with the same key in the closed list * is it better than new one? */ int node_est = n.GetCostEstimate(); diff --git a/src/pathfinder/yapf/yapf_common.hpp b/src/pathfinder/yapf/yapf_common.hpp index 8ff69b3f6..95adf37d7 100644 --- a/src/pathfinder/yapf/yapf_common.hpp +++ b/src/pathfinder/yapf/yapf_common.hpp @@ -46,7 +46,7 @@ public: for (TrackdirBits tdb = m_orgTrackdirs; tdb != TRACKDIR_BIT_NONE; tdb = KillFirstBit(tdb)) { Trackdir td = (Trackdir)FindFirstBit2x64(tdb); Node &n1 = Yapf().CreateNewNode(); - n1.Set(NULL, m_orgTile, td, is_choice); + n1.Set(nullptr, m_orgTile, td, is_choice); Yapf().AddStartupNode(n1); } } @@ -92,12 +92,12 @@ public: { if (m_orgTile != INVALID_TILE && m_orgTd != INVALID_TRACKDIR) { Node &n1 = Yapf().CreateNewNode(); - n1.Set(NULL, m_orgTile, m_orgTd, false); + n1.Set(nullptr, m_orgTile, m_orgTd, false); Yapf().AddStartupNode(n1); } if (m_revTile != INVALID_TILE && m_revTd != INVALID_TRACKDIR) { Node &n2 = Yapf().CreateNewNode(); - n2.Set(NULL, m_revTile, m_revTd, false); + n2.Set(nullptr, m_revTile, m_revTd, false); n2.m_cost = m_reverse_penalty; Yapf().AddStartupNode(n2); } diff --git a/src/pathfinder/yapf/yapf_costcache.hpp b/src/pathfinder/yapf/yapf_costcache.hpp index f16d4054c..2cdbf06c0 100644 --- a/src/pathfinder/yapf/yapf_costcache.hpp +++ b/src/pathfinder/yapf/yapf_costcache.hpp @@ -143,7 +143,7 @@ struct CSegmentCostCacheT : public CSegmentCostCacheBase { inline Tsegment& Get(Key &key, bool *found) { Tsegment *item = m_map.Find(key); - if (item == NULL) { + if (item == nullptr) { *found = false; item = new (m_heap.Append()) Tsegment(key); m_map.Push(*item); diff --git a/src/pathfinder/yapf/yapf_costrail.hpp b/src/pathfinder/yapf/yapf_costrail.hpp index 022b9a167..6c1c3ca7a 100644 --- a/src/pathfinder/yapf/yapf_costrail.hpp +++ b/src/pathfinder/yapf/yapf_costrail.hpp @@ -251,7 +251,7 @@ public: { int cost = 0; const Train *v = Yapf().GetVehicle(); - assert(v != NULL); + assert(v != nullptr); assert(v->type == VEH_TRAIN); assert(v->gcache.cached_total_length != 0); int missing_platform_length = CeilDiv(v->gcache.cached_total_length, TILE_SIZE) - platform_length; @@ -285,7 +285,7 @@ public: CPerfStart perf_cost(Yapf().m_perf_cost); /* Does the node have some parent node? */ - bool has_parent = (n.m_parent != NULL); + bool has_parent = (n.m_parent != nullptr); /* Do we already have a cached segment? */ CachedData &segment = *n.m_segment; @@ -606,7 +606,7 @@ no_entry_cost: // jump here at the beginning if the node has no parent (it is th /* Station platform-length penalty. */ if ((end_segment_reason & ESRB_STATION) != ESRB_NONE) { const BaseStation *st = BaseStation::GetByTile(n.GetLastTile()); - assert(st != NULL); + assert(st != nullptr); uint platform_length = st->GetPlatformLength(n.GetLastTile(), ReverseDiagDir(TrackdirToExitdir(n.GetLastTrackdir()))); /* Reduce the extra cost caused by passing-station penalty (each station receives it in the segment cost). */ extra_cost -= Yapf().PfGetSettings().rail_station_penalty * platform_length; @@ -624,7 +624,7 @@ no_entry_cost: // jump here at the beginning if the node has no parent (it is th inline bool CanUseGlobalCache(Node &n) const { return !m_disable_cache - && (n.m_parent != NULL) + && (n.m_parent != nullptr) && (n.m_parent->m_num_signals_passed >= m_sig_look_ahead_costs.Size()); } diff --git a/src/pathfinder/yapf/yapf_node.hpp b/src/pathfinder/yapf/yapf_node.hpp index e510b2a6c..136ce53bd 100644 --- a/src/pathfinder/yapf/yapf_node.hpp +++ b/src/pathfinder/yapf/yapf_node.hpp @@ -72,7 +72,7 @@ struct CYapfNodeT { inline void Set(Node *parent, TileIndex tile, Trackdir td, bool is_choice) { m_key.Set(tile, td); - m_hash_next = NULL; + m_hash_next = nullptr; m_parent = parent; m_cost = 0; m_estimate = 0; diff --git a/src/pathfinder/yapf/yapf_node_rail.hpp b/src/pathfinder/yapf/yapf_node_rail.hpp index 180c89439..2dfd6ae7d 100644 --- a/src/pathfinder/yapf/yapf_node_rail.hpp +++ b/src/pathfinder/yapf/yapf_node_rail.hpp @@ -83,7 +83,7 @@ struct CYapfRailSegment , m_last_signal_tile(INVALID_TILE) , m_last_signal_td(INVALID_TRACKDIR) , m_end_segment_reason(ESRB_NONE) - , m_hash_next(NULL) + , m_hash_next(nullptr) {} inline const Key& GetKey() const @@ -142,8 +142,8 @@ struct CYapfRailNodeT inline void Set(CYapfRailNodeT *parent, TileIndex tile, Trackdir td, bool is_choice) { base::Set(parent, tile, td, is_choice); - m_segment = NULL; - if (parent == NULL) { + m_segment = nullptr; + if (parent == nullptr) { m_num_signals_passed = 0; flags_u.m_inherited_flags = 0; m_last_red_signal_type = SIGTYPE_NORMAL; @@ -169,19 +169,19 @@ struct CYapfRailNodeT inline TileIndex GetLastTile() const { - assert(m_segment != NULL); + assert(m_segment != nullptr); return m_segment->m_last_tile; } inline Trackdir GetLastTrackdir() const { - assert(m_segment != NULL); + assert(m_segment != nullptr); return m_segment->m_last_td; } inline void SetLastTileTrackdir(TileIndex tile, Trackdir td) { - assert(m_segment != NULL); + assert(m_segment != nullptr); m_segment->m_last_tile = tile; m_segment->m_last_td = td; } diff --git a/src/pathfinder/yapf/yapf_rail.cpp b/src/pathfinder/yapf/yapf_rail.cpp index d3f8e8aee..8d69b8aad 100644 --- a/src/pathfinder/yapf/yapf_rail.cpp +++ b/src/pathfinder/yapf/yapf_rail.cpp @@ -28,8 +28,8 @@ template <typename Tpf> void DumpState(Tpf &pf1, Tpf &pf2) pf2.DumpBase(dmp2); FILE *f1 = fopen("yapf1.txt", "wt"); FILE *f2 = fopen("yapf2.txt", "wt"); - assert(f1 != NULL); - assert(f2 != NULL); + assert(f1 != nullptr); + assert(f2 != nullptr); fwrite(dmp1.m_out.Data(), 1, dmp1.m_out.Size(), f1); fwrite(dmp2.m_out.Data(), 1, dmp2.m_out.Size(), f2); fclose(f1); @@ -84,7 +84,7 @@ private: tile = TILE_ADD(tile, diff); } while (IsCompatibleTrainStationTile(tile, start) && tile != m_origin_tile); - TriggerStationRandomisation(NULL, start, SRT_PATH_RESERVATION); + TriggerStationRandomisation(nullptr, start, SRT_PATH_RESERVATION); return true; } @@ -138,7 +138,7 @@ public: /** Check the node for a possible reservation target. */ inline void FindSafePositionOnNode(Node *node) { - assert(node->m_parent != NULL); + assert(node->m_parent != nullptr); /* We will never pass more than two signals, no need to check for a safe tile. */ if (node->m_parent->m_num_signals_passed >= 2) return; @@ -154,7 +154,7 @@ public: m_res_fail_tile = INVALID_TILE; m_origin_tile = origin; - if (target != NULL) { + if (target != nullptr) { target->tile = m_res_dest; target->trackdir = m_res_dest_td; target->okay = false; @@ -163,7 +163,7 @@ public: /* Don't bother if the target is reserved. */ if (!IsWaitingPositionFree(Yapf().GetVehicle(), m_res_dest, m_res_dest_td)) return false; - for (Node *node = m_res_node; node->m_parent != NULL; node = node->m_parent) { + for (Node *node = m_res_node; node->m_parent != nullptr; node = node->m_parent) { node->IterateTiles(Yapf().GetVehicle(), Yapf(), *this, &CYapfReserveTrack<Types>::ReserveSingleTrack); if (m_res_fail_tile != INVALID_TILE) { /* Reservation failed, undo. */ @@ -173,13 +173,13 @@ public: /* If this is the node that failed, stop at the failed tile. */ m_res_fail_tile = fail_node == node ? stop_tile : INVALID_TILE; fail_node->IterateTiles(Yapf().GetVehicle(), Yapf(), *this, &CYapfReserveTrack<Types>::UnreserveSingleTrack); - } while (fail_node != node && (fail_node = fail_node->m_parent) != NULL); + } while (fail_node != node && (fail_node = fail_node->m_parent) != nullptr); return false; } } - if (target != NULL) target->okay = true; + if (target != nullptr) target->okay = true; if (Yapf().CanUseGlobalCache(*m_res_node)) { YapfNotifyTrackLayoutChange(INVALID_TILE, INVALID_TRACK); @@ -270,7 +270,7 @@ public: /* walk through the path back to the origin */ Node *pNode = n; - while (pNode->m_parent != NULL) { + while (pNode->m_parent != nullptr) { pNode = pNode->m_parent; } @@ -351,15 +351,15 @@ public: this->SetReservationTarget(pNode, pNode->GetLastTile(), pNode->GetLastTrackdir()); /* Walk through the path back to the origin. */ - Node *pPrev = NULL; - while (pNode->m_parent != NULL) { + Node *pPrev = nullptr; + while (pNode->m_parent != nullptr) { pPrev = pNode; pNode = pNode->m_parent; this->FindSafePositionOnNode(pPrev); } - return dont_reserve || this->TryReservePath(NULL, pNode->GetLastTile()); + return dont_reserve || this->TryReservePath(nullptr, pNode->GetLastTile()); } }; @@ -408,7 +408,7 @@ public: if (_debug_desync_level < 2) { result1 = pf1.ChooseRailTrack(v, tile, enterdir, tracks, path_found, reserve_track, target); } else { - result1 = pf1.ChooseRailTrack(v, tile, enterdir, tracks, path_found, false, NULL); + result1 = pf1.ChooseRailTrack(v, tile, enterdir, tracks, path_found, false, nullptr); Tpf pf2; pf2.DisableCache(true); Trackdir result2 = pf2.ChooseRailTrack(v, tile, enterdir, tracks, path_found, reserve_track, target); @@ -423,7 +423,7 @@ public: inline Trackdir ChooseRailTrack(const Train *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks, bool &path_found, bool reserve_track, PBSTileInfo *target) { - if (target != NULL) target->tile = INVALID_TILE; + if (target != nullptr) target->tile = INVALID_TILE; /* set origin and destination nodes */ PBSTileInfo origin = FollowTrainReservation(v); @@ -436,14 +436,14 @@ public: /* if path not found - return INVALID_TRACKDIR */ Trackdir next_trackdir = INVALID_TRACKDIR; Node *pNode = Yapf().GetBestNode(); - if (pNode != NULL) { + if (pNode != nullptr) { /* reserve till end of path */ this->SetReservationTarget(pNode, pNode->GetLastTile(), pNode->GetLastTrackdir()); /* path was found or at least suggested * walk through the path back to the origin */ - Node *pPrev = NULL; - while (pNode->m_parent != NULL) { + Node *pPrev = nullptr; + while (pNode->m_parent != nullptr) { pPrev = pNode; pNode = pNode->m_parent; @@ -494,7 +494,7 @@ public: /* path was found * walk through the path back to the origin */ Node *pNode = Yapf().GetBestNode(); - while (pNode->m_parent != NULL) { + while (pNode->m_parent != nullptr) { pNode = pNode->m_parent; } diff --git a/src/pathfinder/yapf/yapf_road.cpp b/src/pathfinder/yapf/yapf_road.cpp index 908915763..3122dd111 100644 --- a/src/pathfinder/yapf/yapf_road.cpp +++ b/src/pathfinder/yapf/yapf_road.cpp @@ -118,7 +118,7 @@ public: /* start at n.m_key.m_tile / n.m_key.m_td and walk to the end of segment */ TileIndex tile = n.m_key.m_tile; Trackdir trackdir = n.m_key.m_td; - int parent_cost = (n.m_parent != NULL) ? n.m_parent->m_cost : 0; + int parent_cost = (n.m_parent != nullptr) ? n.m_parent->m_cost : 0; for (;;) { /* base tile cost depending on distance between edges */ @@ -381,13 +381,13 @@ public: /* if path not found - return INVALID_TRACKDIR */ Trackdir next_trackdir = INVALID_TRACKDIR; Node *pNode = Yapf().GetBestNode(); - if (pNode != NULL) { + if (pNode != nullptr) { uint steps = 0; - for (Node *n = pNode; n->m_parent != NULL; n = n->m_parent) steps++; + for (Node *n = pNode; n->m_parent != nullptr; n = n->m_parent) steps++; /* path was found or at least suggested * walk through the path back to its origin */ - while (pNode->m_parent != NULL) { + while (pNode->m_parent != nullptr) { steps--; if (pNode->GetIsChoice() && steps < YAPF_ROADVEH_PATH_CACHE_SEGMENTS) { TrackdirByte td; @@ -436,7 +436,7 @@ public: if (!Yapf().FindPath(v)) return dist; Node *pNode = Yapf().GetBestNode(); - if (pNode != NULL) { + if (pNode != nullptr) { /* path was found * get the path cost estimate */ dist = pNode->GetCostEstimate(); diff --git a/src/pathfinder/yapf/yapf_ship.cpp b/src/pathfinder/yapf/yapf_ship.cpp index b880128f5..e7391d686 100644 --- a/src/pathfinder/yapf/yapf_ship.cpp +++ b/src/pathfinder/yapf/yapf_ship.cpp @@ -89,13 +89,13 @@ public: Trackdir next_trackdir = INVALID_TRACKDIR; // this would mean "path not found" Node *pNode = pf.GetBestNode(); - if (pNode != NULL) { + if (pNode != nullptr) { uint steps = 0; - for (Node *n = pNode; n->m_parent != NULL; n = n->m_parent) steps++; + for (Node *n = pNode; n->m_parent != nullptr; n = n->m_parent) steps++; /* walk through the path back to the origin */ - Node *pPrevNode = NULL; - while (pNode->m_parent != NULL) { + Node *pPrevNode = nullptr; + while (pNode->m_parent != nullptr) { steps--; if (steps > 0 && steps < YAPF_SHIP_PATH_CACHE_LENGTH) { TrackdirByte td; @@ -138,11 +138,11 @@ public: if (!pf.FindPath(v)) return false; Node *pNode = pf.GetBestNode(); - if (pNode == NULL) return false; + if (pNode == nullptr) return false; /* path was found * walk through the path back to the origin */ - while (pNode->m_parent != NULL) { + while (pNode->m_parent != nullptr) { pNode = pNode->m_parent; } |