# HG changeset patch # User rubidium # Date 1212389046 0 # Node ID f3fc164fc5381adb715c007f8c14ceee79ffba71 # Parent 97512a15c41b0b7edd86ef3c9940edf835358406 (svn r13357) -Codechange: add constness to YAPF. diff -r 97512a15c41b -r f3fc164fc538 src/yapf/follow_track.hpp --- a/src/yapf/follow_track.hpp Mon Jun 02 06:42:27 2008 +0000 +++ b/src/yapf/follow_track.hpp Mon Jun 02 06:44:06 2008 +0000 @@ -22,7 +22,7 @@ EC_NO_WAY, }; - const Vehicle* m_veh; ///< moving vehicle + const Vehicle *m_veh; ///< moving vehicle TileIndex m_old_tile; ///< the origin (vehicle moved from) before move Trackdir m_old_td; ///< the trackdir (the vehicle was on) before move TileIndex m_new_tile; ///< the new tile (the vehicle has entered) @@ -33,14 +33,14 @@ bool m_is_station; ///< last turn passed station int m_tiles_skipped; ///< number of skipped tunnel or station tiles ErrorCode m_err; - CPerformanceTimer* m_pPerf; + CPerformanceTimer *m_pPerf; - FORCEINLINE CFollowTrackT(const Vehicle* v = NULL, CPerformanceTimer* pPerf = NULL) + FORCEINLINE CFollowTrackT(const Vehicle *v = NULL, CPerformanceTimer* pPerf = NULL) { Init(v, pPerf); } - FORCEINLINE void Init(const Vehicle* v, CPerformanceTimer* pPerf) + FORCEINLINE void Init(const Vehicle *v, CPerformanceTimer* pPerf) { assert(!IsRailTT() || (v != NULL && v->type == VEH_TRAIN)); m_veh = v; diff -r 97512a15c41b -r f3fc164fc538 src/yapf/yapf.h --- a/src/yapf/yapf.h Mon Jun 02 06:42:27 2008 +0000 +++ b/src/yapf/yapf.h Mon Jun 02 06:44:06 2008 +0000 @@ -16,7 +16,7 @@ * @param tracks available tracks on the new tile (to choose from) * @return the best trackdir for next turn or INVALID_TRACKDIR if the path could not be found */ -Trackdir YapfChooseShipTrack(Vehicle *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks); +Trackdir YapfChooseShipTrack(const Vehicle *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks); /** Finds the best path for given road vehicle. * @param v the RV that needs to find a path @@ -24,7 +24,7 @@ * @param enterdir diagonal direction which the RV will enter this new tile from * @return the best trackdir for next turn or INVALID_TRACKDIR if the path could not be found */ -Trackdir YapfChooseRoadTrack(Vehicle *v, TileIndex tile, DiagDirection enterdir); +Trackdir YapfChooseRoadTrack(const Vehicle *v, TileIndex tile, DiagDirection enterdir); /** Finds the best path for given train. * @param v the train that needs to find a path @@ -34,7 +34,7 @@ * @param path_not_found [out] true is returned if no path can be found (returned Trackdir is only a 'guess') * @return the best trackdir for next turn or INVALID_TRACKDIR if the path could not be found */ -Trackdir YapfChooseRailTrack(Vehicle *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks, bool *path_not_found); +Trackdir YapfChooseRailTrack(const Vehicle *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks, bool *path_not_found); /** Used by RV multistop feature to find the nearest road stop that has a free slot. * @param v RV (its current tile will be the origin) @@ -58,17 +58,17 @@ * @param reversed receives true if train needs to reversed first * @return the true if depot was found. */ -bool YapfFindNearestRailDepotTwoWay(Vehicle *v, int max_distance, int reverse_penalty, TileIndex* depot_tile, bool* reversed); +bool YapfFindNearestRailDepotTwoWay(const Vehicle *v, int max_distance, int reverse_penalty, TileIndex *depot_tile, bool *reversed); /** Returns true if it is better to reverse the train before leaving station */ -bool YapfCheckReverseTrain(Vehicle* v); +bool YapfCheckReverseTrain(const Vehicle* v); /** Use this function to notify YAPF that track layout (or signal configuration) has change */ void YapfNotifyTrackLayoutChange(TileIndex tile, Track track); /** performance measurement helpers */ void* NpfBeginInterval(); -int NpfEndInterval(void* perf); +int NpfEndInterval(void *perf); extern int _aystar_stats_open_size; diff -r 97512a15c41b -r f3fc164fc538 src/yapf/yapf_base.hpp --- a/src/yapf/yapf_base.hpp Mon Jun 02 06:42:27 2008 +0000 +++ b/src/yapf/yapf_base.hpp Mon Jun 02 06:44:06 2008 +0000 @@ -51,11 +51,11 @@ 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 + 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 Vehicle* m_veh; ///< vehicle that we are trying to drive + const Vehicle *m_veh; ///< vehicle that we are trying to drive 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 @@ -281,7 +281,7 @@ m_nodes.InsertOpenNode(n); } - const Vehicle* GetVehicle() const {return m_veh;} + const Vehicle * GetVehicle() const {return m_veh;} void DumpBase(DumpTarget &dmp) const { diff -r 97512a15c41b -r f3fc164fc538 src/yapf/yapf_costrail.hpp --- a/src/yapf/yapf_costrail.hpp Mon Jun 02 06:42:27 2008 +0000 +++ b/src/yapf/yapf_costrail.hpp Mon Jun 02 06:44:06 2008 +0000 @@ -191,7 +191,7 @@ FORCEINLINE int PlatformLengthPenalty(int platform_length) { int cost = 0; - const Vehicle* v = Yapf().GetVehicle(); + const Vehicle *v = Yapf().GetVehicle(); assert(v != NULL); assert(v->type == VEH_TRAIN); assert(v->u.rail.cached_total_length != 0); @@ -261,7 +261,7 @@ int segment_entry_cost = 0; int segment_cost = 0; - const Vehicle* v = Yapf().GetVehicle(); + const Vehicle *v = Yapf().GetVehicle(); // start at n.m_key.m_tile / n.m_key.m_td and walk to the end of segment TILE cur(n.m_key.m_tile, n.m_key.m_td); diff -r 97512a15c41b -r f3fc164fc538 src/yapf/yapf_destrail.hpp --- a/src/yapf/yapf_destrail.hpp Mon Jun 02 06:42:27 2008 +0000 +++ b/src/yapf/yapf_destrail.hpp Mon Jun 02 06:44:06 2008 +0000 @@ -11,7 +11,7 @@ RailTypes m_compatible_railtypes; public: - void SetDestination(Vehicle* v) + void SetDestination(const Vehicle* v) { m_compatible_railtypes = v->u.rail.compatible_railtypes; } @@ -84,7 +84,7 @@ } public: - void SetDestination(Vehicle* v) + void SetDestination(const Vehicle* v) { switch (v->current_order.GetType()) { case OT_GOTO_STATION: diff -r 97512a15c41b -r f3fc164fc538 src/yapf/yapf_rail.cpp --- a/src/yapf/yapf_rail.cpp Mon Jun 02 06:42:27 2008 +0000 +++ b/src/yapf/yapf_rail.cpp Mon Jun 02 06:44:06 2008 +0000 @@ -45,7 +45,7 @@ /// return debug report character to identify the transportation type FORCEINLINE char TransportTypeChar() const {return 't';} - static bool stFindNearestDepotTwoWay(Vehicle *v, TileIndex t1, Trackdir td1, TileIndex t2, Trackdir td2, int max_distance, int reverse_penalty, TileIndex* depot_tile, bool* reversed) + static bool stFindNearestDepotTwoWay(const Vehicle *v, TileIndex t1, Trackdir td1, TileIndex t2, Trackdir td2, int max_distance, int reverse_penalty, TileIndex* depot_tile, bool* reversed) { Tpf pf1; bool result1 = pf1.FindNearestDepotTwoWay(v, t1, td1, t2, td2, max_distance, reverse_penalty, depot_tile, reversed); @@ -64,7 +64,7 @@ return result1; } - FORCEINLINE bool FindNearestDepotTwoWay(Vehicle *v, TileIndex t1, Trackdir td1, TileIndex t2, Trackdir td2, int max_distance, int reverse_penalty, TileIndex* depot_tile, bool* reversed) + FORCEINLINE bool FindNearestDepotTwoWay(const Vehicle *v, TileIndex t1, Trackdir td1, TileIndex t2, Trackdir td2, int max_distance, int reverse_penalty, TileIndex* depot_tile, bool* reversed) { // set origin and destination nodes Yapf().SetOrigin(t1, td1, t2, td2, reverse_penalty, true); @@ -121,7 +121,7 @@ /// return debug report character to identify the transportation type FORCEINLINE char TransportTypeChar() const {return 't';} - static Trackdir stChooseRailTrack(Vehicle *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks, bool *path_not_found) + static Trackdir stChooseRailTrack(const Vehicle *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks, bool *path_not_found) { // create pathfinder instance Tpf pf1; @@ -148,7 +148,7 @@ return result1; } - FORCEINLINE Trackdir ChooseRailTrack(Vehicle *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks, bool *path_not_found) + FORCEINLINE Trackdir ChooseRailTrack(const Vehicle *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks, bool *path_not_found) { // set origin and destination nodes Yapf().SetOrigin(v->tile, GetVehicleTrackdir(v), INVALID_TILE, INVALID_TRACKDIR, 1, true); @@ -181,7 +181,7 @@ return next_trackdir; } - static bool stCheckReverseTrain(Vehicle* v, TileIndex t1, Trackdir td1, TileIndex t2, Trackdir td2, int reverse_penalty) + static bool stCheckReverseTrain(const Vehicle *v, TileIndex t1, Trackdir td1, TileIndex t2, Trackdir td2, int reverse_penalty) { Tpf pf1; bool result1 = pf1.CheckReverseTrain(v, t1, td1, t2, td2, reverse_penalty); @@ -198,7 +198,7 @@ return result1; } - FORCEINLINE bool CheckReverseTrain(Vehicle* v, TileIndex t1, Trackdir td1, TileIndex t2, Trackdir td2, int reverse_penalty) + FORCEINLINE bool CheckReverseTrain(const Vehicle *v, TileIndex t1, Trackdir td1, TileIndex t2, Trackdir td2, int reverse_penalty) { // create pathfinder instance // set origin and destination nodes @@ -247,10 +247,10 @@ struct CYapfAnyDepotRail2 : CYapfT > {}; -Trackdir YapfChooseRailTrack(Vehicle *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks, bool *path_not_found) +Trackdir YapfChooseRailTrack(const Vehicle *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks, bool *path_not_found) { // default is YAPF type 2 - typedef Trackdir (*PfnChooseRailTrack)(Vehicle*, TileIndex, DiagDirection, TrackBits, bool*); + typedef Trackdir (*PfnChooseRailTrack)(const Vehicle*, TileIndex, DiagDirection, TrackBits, bool*); PfnChooseRailTrack pfnChooseRailTrack = &CYapfRail1::stChooseRailTrack; // check if non-default YAPF type needed @@ -263,10 +263,10 @@ return td_ret; } -bool YapfCheckReverseTrain(Vehicle* v) +bool YapfCheckReverseTrain(const Vehicle* v) { /* last wagon */ - Vehicle* last_veh = GetLastVehicleInChain(v); + const Vehicle *last_veh = GetLastVehicleInChain(v); // get trackdirs of both ends Trackdir td = GetVehicleTrackdir(v); @@ -307,7 +307,7 @@ reverse_penalty += DistanceManhattan(cur_tile, tile_rev) * YAPF_TILE_LENGTH; } - typedef bool (*PfnCheckReverseTrain)(Vehicle*, TileIndex, Trackdir, TileIndex, Trackdir, int); + typedef bool (*PfnCheckReverseTrain)(const Vehicle*, TileIndex, Trackdir, TileIndex, Trackdir, int); PfnCheckReverseTrain pfnCheckReverseTrain = CYapfRail1::stCheckReverseTrain; // check if non-default YAPF type needed @@ -323,12 +323,12 @@ return reverse; } -bool YapfFindNearestRailDepotTwoWay(Vehicle *v, int max_distance, int reverse_penalty, TileIndex* depot_tile, bool* reversed) +bool YapfFindNearestRailDepotTwoWay(const Vehicle *v, int max_distance, int reverse_penalty, TileIndex *depot_tile, bool *reversed) { *depot_tile = INVALID_TILE; *reversed = false; - Vehicle* last_veh = GetLastVehicleInChain(v); + const Vehicle *last_veh = GetLastVehicleInChain(v); TileIndex tile = v->tile; TileIndex last_tile = last_veh->tile; @@ -337,7 +337,7 @@ Trackdir td = GetVehicleTrackdir(v); Trackdir td_rev = ReverseTrackdir(GetVehicleTrackdir(last_veh)); - typedef bool (*PfnFindNearestDepotTwoWay)(Vehicle*, TileIndex, Trackdir, TileIndex, Trackdir, int, int, TileIndex*, bool*); + typedef bool (*PfnFindNearestDepotTwoWay)(const Vehicle*, TileIndex, Trackdir, TileIndex, Trackdir, int, int, TileIndex*, bool*); PfnFindNearestDepotTwoWay pfnFindNearestDepotTwoWay = &CYapfAnyDepotRail1::stFindNearestDepotTwoWay; // check if non-default YAPF type needed diff -r 97512a15c41b -r f3fc164fc538 src/yapf/yapf_road.cpp --- a/src/yapf/yapf_road.cpp Mon Jun 02 06:42:27 2008 +0000 +++ b/src/yapf/yapf_road.cpp Mon Jun 02 06:44:06 2008 +0000 @@ -83,7 +83,7 @@ // base tile cost depending on distance between edges segment_cost += Yapf().OneTileCost(tile, trackdir); - const Vehicle* v = Yapf().GetVehicle(); + const Vehicle *v = Yapf().GetVehicle(); // we have reached the vehicle's destination - segment should end here to avoid target skipping if (v->current_order.IsType(OT_GOTO_STATION) && tile == v->dest_tile) break; @@ -253,13 +253,13 @@ /// return debug report character to identify the transportation type FORCEINLINE char TransportTypeChar() const {return 'r';} - static Trackdir stChooseRoadTrack(Vehicle *v, TileIndex tile, DiagDirection enterdir) + static Trackdir stChooseRoadTrack(const Vehicle *v, TileIndex tile, DiagDirection enterdir) { Tpf pf; return pf.ChooseRoadTrack(v, tile, enterdir); } - FORCEINLINE Trackdir ChooseRoadTrack(Vehicle *v, TileIndex tile, DiagDirection enterdir) + FORCEINLINE Trackdir ChooseRoadTrack(const Vehicle *v, TileIndex tile, DiagDirection enterdir) { // handle special case - when next tile is destination tile if (tile == v->dest_tile) { @@ -400,21 +400,22 @@ struct CYapfRoadAnyDepot2 : CYapfT > {}; -Trackdir YapfChooseRoadTrack(Vehicle *v, TileIndex tile, DiagDirection enterdir) +Trackdir YapfChooseRoadTrack(const Vehicle *v, TileIndex tile, DiagDirection enterdir) { // default is YAPF type 2 - typedef Trackdir (*PfnChooseRoadTrack)(Vehicle*, TileIndex, DiagDirection); + typedef Trackdir (*PfnChooseRoadTrack)(const Vehicle*, TileIndex, DiagDirection); PfnChooseRoadTrack pfnChooseRoadTrack = &CYapfRoad2::stChooseRoadTrack; // default: ExitDir, allow 90-deg // check if non-default YAPF type should be used - if (_settings_game.pf.yapf.disable_node_optimization) + if (_settings_game.pf.yapf.disable_node_optimization) { pfnChooseRoadTrack = &CYapfRoad1::stChooseRoadTrack; // Trackdir, allow 90-deg + } Trackdir td_ret = pfnChooseRoadTrack(v, tile, enterdir); return td_ret; } -uint YapfRoadVehDistanceToTile(const Vehicle* v, TileIndex tile) +uint YapfRoadVehDistanceToTile(const Vehicle *v, TileIndex tile) { // default is YAPF type 2 typedef uint (*PfnDistanceToTile)(const Vehicle*, TileIndex); diff -r 97512a15c41b -r f3fc164fc538 src/yapf/yapf_ship.cpp --- a/src/yapf/yapf_ship.cpp Mon Jun 02 06:42:27 2008 +0000 +++ b/src/yapf/yapf_ship.cpp Mon Jun 02 06:44:06 2008 +0000 @@ -34,7 +34,7 @@ /// return debug report character to identify the transportation type FORCEINLINE char TransportTypeChar() const {return 'w';} - static Trackdir ChooseShipTrack(Vehicle *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks) + static Trackdir ChooseShipTrack(const Vehicle *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks) { // handle special case - when next tile is destination tile if (tile == v->dest_tile) { @@ -147,24 +147,25 @@ struct CYapfShip3 : CYapfT > {}; /** Ship controller helper - path finder invoker */ -Trackdir YapfChooseShipTrack(Vehicle *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks) +Trackdir YapfChooseShipTrack(const Vehicle *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks) { // default is YAPF type 2 - typedef Trackdir (*PfnChooseShipTrack)(Vehicle*, TileIndex, DiagDirection, TrackBits); + typedef Trackdir (*PfnChooseShipTrack)(const Vehicle*, TileIndex, DiagDirection, TrackBits); PfnChooseShipTrack pfnChooseShipTrack = CYapfShip2::ChooseShipTrack; // default: ExitDir, allow 90-deg // check if non-default YAPF type needed - if (_settings_game.pf.forbid_90_deg) + if (_settings_game.pf.forbid_90_deg) { pfnChooseShipTrack = &CYapfShip3::ChooseShipTrack; // Trackdir, forbid 90-deg - else if (_settings_game.pf.yapf.disable_node_optimization) + } else if (_settings_game.pf.yapf.disable_node_optimization) { pfnChooseShipTrack = &CYapfShip1::ChooseShipTrack; // Trackdir, allow 90-deg + } Trackdir td_ret = pfnChooseShipTrack(v, tile, enterdir, tracks); return td_ret; } /** performance measurement helper */ -void* NpfBeginInterval() +void * NpfBeginInterval() { CPerformanceTimer& perf = *new CPerformanceTimer; perf.Start(); @@ -172,7 +173,7 @@ } /** performance measurement helper */ -int NpfEndInterval(void* vperf) +int NpfEndInterval(void *vperf) { CPerformanceTimer& perf = *(CPerformanceTimer*)vperf; perf.Stop();