From 7c8e7c6b6e16d4a26259a676db32d8776b99817e Mon Sep 17 00:00:00 2001 From: Henry Wilson Date: Wed, 10 Apr 2019 22:07:06 +0100 Subject: Codechange: Use null pointer literal instead of the NULL macro --- src/pathfinder/follow_track.hpp | 18 +++++----- src/pathfinder/npf/aystar.cpp | 18 +++++----- src/pathfinder/npf/npf.cpp | 32 ++++++++--------- src/pathfinder/npf/queue.cpp | 62 ++++++++++++++++----------------- src/pathfinder/pf_performance_timer.hpp | 6 ++-- src/pathfinder/yapf/nodelist.hpp | 20 +++++------ src/pathfinder/yapf/yapf_base.hpp | 28 +++++++-------- src/pathfinder/yapf/yapf_common.hpp | 6 ++-- src/pathfinder/yapf/yapf_costcache.hpp | 2 +- src/pathfinder/yapf/yapf_costrail.hpp | 8 ++--- src/pathfinder/yapf/yapf_node.hpp | 2 +- src/pathfinder/yapf/yapf_node_rail.hpp | 12 +++---- src/pathfinder/yapf/yapf_rail.cpp | 36 +++++++++---------- src/pathfinder/yapf/yapf_road.cpp | 10 +++--- src/pathfinder/yapf/yapf_ship.cpp | 12 +++---- 15 files changed, 136 insertions(+), 136 deletions(-) (limited to 'src/pathfinder') diff --git a/src/pathfinder/follow_track.hpp b/src/pathfinder/follow_track.hpp index 2bbad8d70..999f7f94d 100644 --- a/src/pathfinder/follow_track.hpp +++ b/src/pathfinder/follow_track.hpp @@ -53,27 +53,27 @@ struct CFollowTrackT CPerformanceTimer *m_pPerf; RailTypes m_railtypes; - inline CFollowTrackT(const VehicleType *v = NULL, RailTypes railtype_override = INVALID_RAILTYPES, CPerformanceTimer *pPerf = NULL) + inline CFollowTrackT(const VehicleType *v = nullptr, RailTypes railtype_override = INVALID_RAILTYPES, CPerformanceTimer *pPerf = nullptr) { Init(v, railtype_override, pPerf); } - inline CFollowTrackT(Owner o, RailTypes railtype_override = INVALID_RAILTYPES, CPerformanceTimer *pPerf = NULL) + inline CFollowTrackT(Owner o, RailTypes railtype_override = INVALID_RAILTYPES, CPerformanceTimer *pPerf = nullptr) { - m_veh = NULL; + m_veh = nullptr; Init(o, railtype_override, pPerf); } inline void Init(const VehicleType *v, RailTypes railtype_override, CPerformanceTimer *pPerf) { - assert(!IsRailTT() || (v != NULL && v->type == VEH_TRAIN)); + assert(!IsRailTT() || (v != nullptr && v->type == VEH_TRAIN)); m_veh = v; - Init(v != NULL ? v->owner : INVALID_OWNER, IsRailTT() && railtype_override == INVALID_RAILTYPES ? Train::From(v)->compatible_railtypes : railtype_override, pPerf); + Init(v != nullptr ? v->owner : INVALID_OWNER, IsRailTT() && railtype_override == INVALID_RAILTYPES ? Train::From(v)->compatible_railtypes : railtype_override, pPerf); } inline void Init(Owner o, RailTypes railtype_override, CPerformanceTimer *pPerf) { - assert(!IsRoadTT() || m_veh != NULL); + assert(!IsRoadTT() || m_veh != nullptr); assert(!IsRailTT() || railtype_override != INVALID_RAILTYPES); m_veh_owner = o; m_pPerf = pPerf; @@ -126,7 +126,7 @@ struct CFollowTrackT m_err = EC_NONE; assert( ((TrackStatusToTrackdirBits( - GetTileTrackStatus(m_old_tile, TT(), (IsRoadTT() && m_veh != NULL) ? RoadVehicle::From(m_veh)->compatible_roadtypes : 0) + GetTileTrackStatus(m_old_tile, TT(), (IsRoadTT() && m_veh != nullptr) ? RoadVehicle::From(m_veh)->compatible_roadtypes : 0) ) & TrackdirToTrackdirBits(m_old_td)) != 0) || (IsTram() && GetSingleTramBit(m_old_tile) != INVALID_DIAGDIR) // Disable the assertion for single tram bits ); @@ -447,7 +447,7 @@ protected: public: /** Helper for pathfinders - get min/max speed on the m_old_tile/m_old_td */ - int GetSpeedLimit(int *pmin_speed = NULL) const + int GetSpeedLimit(int *pmin_speed = nullptr) const { int min_speed = 0; int max_speed = INT_MAX; // no limit @@ -465,7 +465,7 @@ public: } /* if min speed was requested, return it */ - if (pmin_speed != NULL) *pmin_speed = min_speed; + if (pmin_speed != nullptr) *pmin_speed = min_speed; return max_speed; } }; diff --git a/src/pathfinder/npf/aystar.cpp b/src/pathfinder/npf/aystar.cpp index beac06291..addfc4930 100644 --- a/src/pathfinder/npf/aystar.cpp +++ b/src/pathfinder/npf/aystar.cpp @@ -32,7 +32,7 @@ /** * This looks in the hash whether a node exists in the closed list. * @param node Node to search. - * @return The #PathNode if it is available, else \c NULL + * @return The #PathNode if it is available, else \c nullptr */ PathNode *AyStar::ClosedListIsInList(const AyStarNode *node) { @@ -55,7 +55,7 @@ void AyStar::ClosedListAdd(const PathNode *node) /** * Check whether a node is in the open list. * @param node Node to search. - * @return If the node is available, it is returned, else \c NULL is returned. + * @return If the node is available, it is returned, else \c nullptr is returned. */ OpenListNode *AyStar::OpenListIsInList(const AyStarNode *node) { @@ -65,13 +65,13 @@ OpenListNode *AyStar::OpenListIsInList(const AyStarNode *node) /** * Gets the best node from the open list. * It deletes the returned node from the open list. - * @returns the best node available, or \c NULL of none is found. + * @returns the best node available, or \c nullptr of none is found. */ OpenListNode *AyStar::OpenListPop() { /* Return the item the Queue returns.. the best next OpenList item. */ OpenListNode *res = (OpenListNode*)this->openlist_queue.Pop(); - if (res != NULL) { + if (res != nullptr) { this->openlist_hash.DeleteValue(res->path.node.tile, res->path.node.direction); } @@ -105,7 +105,7 @@ void AyStar::CheckTile(AyStarNode *current, OpenListNode *parent) OpenListNode *check; /* Check the new node against the ClosedList */ - if (this->ClosedListIsInList(current) != NULL) return; + if (this->ClosedListIsInList(current) != nullptr) return; /* Calculate the G-value for this node */ new_g = this->CalculateG(this, current, parent); @@ -131,7 +131,7 @@ void AyStar::CheckTile(AyStarNode *current, OpenListNode *parent) /* Check if this item is already in the OpenList */ check = this->OpenListIsInList(current); - if (check != NULL) { + if (check != nullptr) { uint i; /* Yes, check if this g value is lower.. */ if (new_g > check->g) return; @@ -167,11 +167,11 @@ int AyStar::Loop() /* Get the best node from OpenList */ OpenListNode *current = this->OpenListPop(); /* If empty, drop an error */ - if (current == NULL) return AYSTAR_EMPTY_OPENLIST; + if (current == nullptr) return AYSTAR_EMPTY_OPENLIST; /* Check for end node and if found, return that code */ if (this->EndNodeCheck(this, current) == AYSTAR_FOUND_END_NODE && !CheckIgnoreFirstTile(¤t->path)) { - if (this->FoundEndNode != NULL) { + if (this->FoundEndNode != nullptr) { this->FoundEndNode(this, current); } free(current); @@ -285,7 +285,7 @@ void AyStar::AddStartNode(AyStarNode *start_node, uint g) printf("[AyStar] Starting A* Algorithm from node (%d, %d, %d)\n", TileX(start_node->tile), TileY(start_node->tile), start_node->direction); #endif - this->OpenListAdd(NULL, start_node, 0, g); + this->OpenListAdd(nullptr, start_node, 0, g); } /** diff --git a/src/pathfinder/npf/npf.cpp b/src/pathfinder/npf/npf.cpp index 32c6e982d..2863e7881 100644 --- a/src/pathfinder/npf/npf.cpp +++ b/src/pathfinder/npf/npf.cpp @@ -103,7 +103,7 @@ static inline void NPFSetFlag(AyStarNode *node, NPFNodeFlag flag, bool value) bool CheckIgnoreFirstTile(const PathNode *node) { - return (node->parent == NULL && HasBit(node->node.user_data[NPF_NODE_FLAGS], NPF_FLAG_IGNORE_START_TILE)); + return (node->parent == nullptr && HasBit(node->node.user_data[NPF_NODE_FLAGS], NPF_FLAG_IGNORE_START_TILE)); } /** @@ -192,7 +192,7 @@ static int32 NPFCalcStationOrTileHeuristic(AyStar *as, AyStarNode *current, Open * choice */ static void NPFFillTrackdirChoice(AyStarNode *current, OpenListNode *parent) { - if (parent->path.parent == NULL) { + if (parent->path.parent == nullptr) { Trackdir trackdir = current->direction; /* This is a first order decision, so we'd better save the * direction we chose */ @@ -584,7 +584,7 @@ static const PathNode *FindSafePosition(PathNode *path, const Train *v) /* If there is no signal, reserve the whole path. */ PathNode *sig = path; - for (; path->parent != NULL; path = path->parent) { + for (; path->parent != nullptr; path = path->parent) { if (IsSafeWaitingPosition(v, path->node.tile, path->node.direction, true, _settings_game.pf.forbid_90_deg)) { sig = path; } @@ -625,7 +625,7 @@ static void NPFSaveTargetData(AyStar *as, OpenListNode *current) ftd->node = current->path.node; ftd->res_okay = false; - if (as->user_target != NULL && ((NPFFindStationOrTileData*)as->user_target)->reserve_path && user->type == TRANSPORT_RAIL) { + if (as->user_target != nullptr && ((NPFFindStationOrTileData*)as->user_target)->reserve_path && user->type == TRANSPORT_RAIL) { /* Path reservation is requested. */ const Train *v = Train::From(((NPFFindStationOrTileData *)as->user_target)->v); @@ -647,7 +647,7 @@ static void NPFSaveTargetData(AyStar *as, OpenListNode *current) if (!IsWaitingPositionFree(v, target->node.tile, target->node.direction, _settings_game.pf.forbid_90_deg)) return; } - for (const PathNode *cur = target; cur->parent != NULL; cur = cur->parent) { + for (const PathNode *cur = target; cur->parent != nullptr; cur = cur->parent) { if (!TryReserveRailTrack(cur->node.tile, TrackdirToTrack(cur->node.direction))) { /* Reservation failed, undo. */ ClearPathReservation(target, cur); @@ -957,7 +957,7 @@ static void NPFFollowTrack(AyStar *aystar, OpenListNode *current) /* * Plan a route to the specified target (which is checked by target_proc), - * from start1 and if not NULL, from start2 as well. The type of transport we + * from start1 and if not nullptr, from start2 as well. The type of transport we * are checking is in type. reverse_penalty is applied to all routes that * originate from the second start node. * When we are looking for one specific target (optionally multiple tiles), we @@ -989,7 +989,7 @@ static NPFFoundTargetData NPFRouteInternal(AyStarNode *start1, bool ignore_start NPFSetFlag(start1, NPF_FLAG_IGNORE_START_TILE, ignore_start_tile1); NPFSetFlag(start1, NPF_FLAG_IGNORE_RESERVED, ignore_reserved); _npf_aystar.AddStartNode(start1, 0); - if (start2 != NULL) { + if (start2 != nullptr) { start2->user_data[NPF_TRACKDIR_CHOICE] = INVALID_TRACKDIR; start2->user_data[NPF_NODE_FLAGS] = 0; NPFSetFlag(start2, NPF_FLAG_IGNORE_START_TILE, ignore_start_tile2); @@ -1017,10 +1017,10 @@ static NPFFoundTargetData NPFRouteInternal(AyStarNode *start1, bool ignore_start assert(r != AYSTAR_STILL_BUSY); if (result.best_bird_dist != 0) { - if (target != NULL) { + if (target != nullptr) { DEBUG(npf, 1, "Could not find route to tile 0x%X from 0x%X.", target->dest_coords, start1->tile); } else { - /* Assumption: target == NULL, so we are looking for a depot */ + /* Assumption: target == nullptr, so we are looking for a depot */ DEBUG(npf, 1, "Could not find route to a depot from tile 0x%X.", start1->tile); } @@ -1041,7 +1041,7 @@ static NPFFoundTargetData NPFRouteToStationOrTileTwoWay(TileIndex tile1, Trackdi start1.direction = trackdir1; start2.direction = trackdir2; - return NPFRouteInternal(&start1, ignore_start_tile1, (IsValidTile(tile2) ? &start2 : NULL), ignore_start_tile2, target, NPFFindStationOrTile, NPFCalcStationOrTileHeuristic, user, 0); + return NPFRouteInternal(&start1, ignore_start_tile1, (IsValidTile(tile2) ? &start2 : nullptr), ignore_start_tile2, target, NPFFindStationOrTile, NPFCalcStationOrTileHeuristic, user, 0); } /* Will search from the given tile and direction, for a route to the given @@ -1069,9 +1069,9 @@ static NPFFoundTargetData NPFRouteToDepotBreadthFirstTwoWay(TileIndex tile1, Tra start1.direction = trackdir1; start2.direction = trackdir2; - /* perform a breadth first search. Target is NULL, + /* perform a breadth first search. Target is nullptr, * since we are just looking for any depot...*/ - return NPFRouteInternal(&start1, ignore_start_tile1, (IsValidTile(tile2) ? &start2 : NULL), ignore_start_tile2, target, NPFFindDepot, NPFCalcZero, user, reverse_penalty, false, max_penalty); + return NPFRouteInternal(&start1, ignore_start_tile1, (IsValidTile(tile2) ? &start2 : nullptr), ignore_start_tile2, target, NPFFindDepot, NPFCalcZero, user, reverse_penalty, false, max_penalty); } void InitializeNPF() @@ -1121,7 +1121,7 @@ FindDepotData NPFRoadVehicleFindNearestDepot(const RoadVehicle *v, int max_penal Trackdir trackdir = v->GetVehicleTrackdir(); AyStarUserData user = { v->owner, TRANSPORT_ROAD, INVALID_RAILTYPES, v->compatible_roadtypes }; - NPFFoundTargetData ftd = NPFRouteToDepotBreadthFirstTwoWay(v->tile, trackdir, false, INVALID_TILE, INVALID_TRACKDIR, false, NULL, &user, 0, max_penalty); + NPFFoundTargetData ftd = NPFRouteToDepotBreadthFirstTwoWay(v->tile, trackdir, false, INVALID_TILE, INVALID_TRACKDIR, false, nullptr, &user, 0, max_penalty); if (ftd.best_bird_dist != 0) return FindDepotData(); @@ -1233,10 +1233,10 @@ bool NPFTrainFindNearestSafeTile(const Train *v, TileIndex tile, Trackdir trackd RailTypes railtypes = v->compatible_railtypes; if (override_railtype) railtypes |= GetRailTypeInfo(v->railtype)->compatible_railtypes; - /* perform a breadth first search. Target is NULL, + /* perform a breadth first search. Target is nullptr, * since we are just looking for any safe tile...*/ AyStarUserData user = { v->owner, TRANSPORT_RAIL, railtypes, ROADTYPES_NONE }; - return NPFRouteInternal(&start1, true, NULL, false, &fstd, NPFFindSafeTile, NPFCalcZero, &user, 0, true).res_okay; + return NPFRouteInternal(&start1, true, nullptr, false, &fstd, NPFFindSafeTile, NPFCalcZero, &user, 0, true).res_okay; } bool NPFTrainCheckReverse(const Train *v) @@ -1269,7 +1269,7 @@ Track NPFTrainChooseTrack(const Train *v, bool &path_found, bool reserve_track, AyStarUserData user = { v->owner, TRANSPORT_RAIL, v->compatible_railtypes, ROADTYPES_NONE }; NPFFoundTargetData ftd = NPFRouteToStationOrTile(origin.tile, origin.trackdir, true, &fstd, &user); - if (target != NULL) { + if (target != nullptr) { target->tile = ftd.node.tile; target->trackdir = (Trackdir)ftd.node.direction; target->okay = ftd.res_okay; diff --git a/src/pathfinder/npf/queue.cpp b/src/pathfinder/npf/queue.cpp index 2afb41391..02a195c5d 100644 --- a/src/pathfinder/npf/queue.cpp +++ b/src/pathfinder/npf/queue.cpp @@ -37,7 +37,7 @@ void BinaryHeap::Clear(bool free_values) uint j; for (i = 0; i < this->blocks; i++) { - if (this->elements[i] == NULL) { + if (this->elements[i] == nullptr) { /* No more allocated blocks */ break; } @@ -55,7 +55,7 @@ void BinaryHeap::Clear(bool free_values) if (i != 0) { /* Leave the first block of memory alone */ free(this->elements[i]); - this->elements[i] = NULL; + this->elements[i] = nullptr; } } this->size = 0; @@ -73,7 +73,7 @@ void BinaryHeap::Free(bool free_values) this->Clear(free_values); for (i = 0; i < this->blocks; i++) { - if (this->elements[i] == NULL) break; + if (this->elements[i] == nullptr) break; free(this->elements[i]); } free(this->elements); @@ -88,7 +88,7 @@ bool BinaryHeap::Push(void *item, int priority) if (this->size == this->max_size) return false; assert(this->size < this->max_size); - if (this->elements[this->size >> BINARY_HEAP_BLOCKSIZE_BITS] == NULL) { + if (this->elements[this->size >> BINARY_HEAP_BLOCKSIZE_BITS] == nullptr) { /* The currently allocated blocks are full, allocate a new one */ assert((this->size & BINARY_HEAP_BLOCKSIZE_MASK) == 0); this->elements[this->size >> BINARY_HEAP_BLOCKSIZE_BITS] = MallocT(BINARY_HEAP_BLOCKSIZE); @@ -195,7 +195,7 @@ void *BinaryHeap::Pop() { void *result; - if (this->size == 0) return NULL; + if (this->size == 0) return nullptr; /* The best item is always on top, so give that as result */ result = this->GetElement(1).item; @@ -264,7 +264,7 @@ void Hash::Delete(bool free_values) /* Free the first value */ if (free_values) free(this->buckets[i].value); node = this->buckets[i].next; - while (node != NULL) { + while (node != nullptr) { HashNode *prev = node; node = node->next; @@ -296,7 +296,7 @@ void Hash::PrintStatistics() const const HashNode *node; used_buckets++; - for (node = &this->buckets[i]; node != NULL; node = node->next) collision++; + for (node = &this->buckets[i]; node != nullptr; node = node->next) collision++; if (collision > max_collision) max_collision = collision; } if (collision >= lengthof(usage)) collision = lengthof(usage) - 1; @@ -351,7 +351,7 @@ void Hash::Clear(bool free_values) /* Free the first value */ if (free_values) free(this->buckets[i].value); node = this->buckets[i].next; - while (node != NULL) { + while (node != nullptr) { HashNode *prev = node; node = node->next; @@ -365,32 +365,32 @@ void Hash::Clear(bool free_values) /** * Finds the node that that saves this key pair. If it is not - * found, returns NULL. If it is found, *prev is set to the + * found, returns nullptr. If it is found, *prev is set to the * node before the one found, or if the node found was the first in the bucket - * to NULL. If it is not found, *prev is set to the last HashNode in the - * bucket, or NULL if it is empty. prev can also be NULL, in which case it is + * to nullptr. If it is not found, *prev is set to the last HashNode in the + * bucket, or nullptr if it is empty. prev can also be nullptr, in which case it is * not used for output. */ HashNode *Hash::FindNode(uint key1, uint key2, HashNode** prev_out) const { uint hash = this->hash(key1, key2); - HashNode *result = NULL; + HashNode *result = nullptr; /* Check if the bucket is empty */ if (!this->buckets_in_use[hash]) { - if (prev_out != NULL) *prev_out = NULL; - result = NULL; + if (prev_out != nullptr) *prev_out = nullptr; + result = nullptr; /* Check the first node specially */ } else if (this->buckets[hash].key1 == key1 && this->buckets[hash].key2 == key2) { /* Save the value */ result = this->buckets + hash; - if (prev_out != NULL) *prev_out = NULL; + if (prev_out != nullptr) *prev_out = nullptr; /* Check all other nodes */ } else { HashNode *prev = this->buckets + hash; HashNode *node; - for (node = prev->next; node != NULL; node = node->next) { + for (node = prev->next; node != nullptr; node = node->next) { if (node->key1 == key1 && node->key2 == key2) { /* Found it */ result = node; @@ -398,14 +398,14 @@ HashNode *Hash::FindNode(uint key1, uint key2, HashNode** prev_out) const } prev = node; } - if (prev_out != NULL) *prev_out = prev; + if (prev_out != nullptr) *prev_out = prev; } return result; } /** * Deletes the value with the specified key pair from the hash and returns - * that value. Returns NULL when the value was not present. The value returned + * that value. Returns nullptr when the value was not present. The value returned * is _not_ free()'d! */ void *Hash::DeleteValue(uint key1, uint key2) @@ -414,15 +414,15 @@ void *Hash::DeleteValue(uint key1, uint key2) HashNode *prev; // Used as output var for below function call HashNode *node = this->FindNode(key1, key2, &prev); - if (node == NULL) { + if (node == nullptr) { /* not found */ - result = NULL; - } else if (prev == NULL) { + result = nullptr; + } else if (prev == nullptr) { /* It is in the first node, we can't free that one, so we free * the next one instead (if there is any)*/ /* Save the value */ result = node->value; - if (node->next != NULL) { + if (node->next != nullptr) { HashNode *next = node->next; /* Copy the second to the first */ *node = *next; @@ -443,20 +443,20 @@ void *Hash::DeleteValue(uint key1, uint key2) /* Free the node */ free(node); } - if (result != NULL) this->size--; + if (result != nullptr) this->size--; return result; } /** * Sets the value associated with the given key pair to the given value. - * Returns the old value if the value was replaced, NULL when it was not yet present. + * Returns the old value if the value was replaced, nullptr when it was not yet present. */ void *Hash::Set(uint key1, uint key2, void *value) { HashNode *prev; HashNode *node = this->FindNode(key1, key2, &prev); - if (node != NULL) { + if (node != nullptr) { /* Found it */ void *result = node->value; @@ -464,7 +464,7 @@ void *Hash::Set(uint key1, uint key2, void *value) return result; } /* It is not yet present, let's add it */ - if (prev == NULL) { + if (prev == nullptr) { /* The bucket is still empty */ uint hash = this->hash(key1, key2); this->buckets_in_use[hash] = true; @@ -474,21 +474,21 @@ void *Hash::Set(uint key1, uint key2, void *value) node = MallocT(1); prev->next = node; } - node->next = NULL; + node->next = nullptr; node->key1 = key1; node->key2 = key2; node->value = value; this->size++; - return NULL; + return nullptr; } /** - * Gets the value associated with the given key pair, or NULL when it is not + * Gets the value associated with the given key pair, or nullptr when it is not * present. */ void *Hash::Get(uint key1, uint key2) const { - HashNode *node = this->FindNode(key1, key2, NULL); + HashNode *node = this->FindNode(key1, key2, nullptr); - return (node != NULL) ? node->value : NULL; + return (node != nullptr) ? node->value : nullptr; } diff --git a/src/pathfinder/pf_performance_timer.hpp b/src/pathfinder/pf_performance_timer.hpp index 808542d25..c06ef815e 100644 --- a/src/pathfinder/pf_performance_timer.hpp +++ b/src/pathfinder/pf_performance_timer.hpp @@ -53,7 +53,7 @@ struct CPerfStartReal inline CPerfStartReal(CPerformanceTimer& perf) : m_pperf(&perf) { - if (m_pperf != NULL) m_pperf->Start(); + if (m_pperf != nullptr) m_pperf->Start(); } inline ~CPerfStartReal() @@ -63,9 +63,9 @@ struct CPerfStartReal inline void Stop() { - if (m_pperf != NULL) { + if (m_pperf != nullptr) { m_pperf->Stop(); - m_pperf = NULL; + m_pperf = nullptr; } } }; 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 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::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::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; } -- cgit v1.2.3-70-g09d2