mirror of https://github.com/OpenTTD/OpenTTD
(svn r13357) -Codechange: add constness to YAPF.
parent
10b494d260
commit
3efece1284
|
@ -16,7 +16,7 @@
|
||||||
* @param tracks available tracks on the new tile (to choose from)
|
* @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
|
* @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.
|
/** Finds the best path for given road vehicle.
|
||||||
* @param v the RV that needs to find a path
|
* @param v the RV that needs to find a path
|
||||||
|
@ -24,7 +24,7 @@ Trackdir YapfChooseShipTrack(Vehicle *v, TileIndex tile, DiagDirection enterdir,
|
||||||
* @param enterdir diagonal direction which the RV will enter this new tile from
|
* @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
|
* @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.
|
/** Finds the best path for given train.
|
||||||
* @param v the train that needs to find a path
|
* @param v the train that needs to find a path
|
||||||
|
@ -34,7 +34,7 @@ Trackdir YapfChooseRoadTrack(Vehicle *v, TileIndex tile, DiagDirection enterdir)
|
||||||
* @param path_not_found [out] true is returned if no path can be found (returned Trackdir is only a 'guess')
|
* @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
|
* @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.
|
/** 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)
|
* @param v RV (its current tile will be the origin)
|
||||||
|
@ -58,10 +58,10 @@ Depot* YapfFindNearestRoadDepot(const Vehicle *v);
|
||||||
* @param reversed receives true if train needs to reversed first
|
* @param reversed receives true if train needs to reversed first
|
||||||
* @return the true if depot was found.
|
* @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 */
|
/** 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 */
|
/** Use this function to notify YAPF that track layout (or signal configuration) has change */
|
||||||
void YapfNotifyTrackLayoutChange(TileIndex tile, Track track);
|
void YapfNotifyTrackLayoutChange(TileIndex tile, Track track);
|
||||||
|
|
|
@ -11,7 +11,7 @@ protected:
|
||||||
RailTypes m_compatible_railtypes;
|
RailTypes m_compatible_railtypes;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void SetDestination(Vehicle* v)
|
void SetDestination(const Vehicle* v)
|
||||||
{
|
{
|
||||||
m_compatible_railtypes = v->u.rail.compatible_railtypes;
|
m_compatible_railtypes = v->u.rail.compatible_railtypes;
|
||||||
}
|
}
|
||||||
|
@ -84,7 +84,7 @@ protected:
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void SetDestination(Vehicle* v)
|
void SetDestination(const Vehicle* v)
|
||||||
{
|
{
|
||||||
switch (v->current_order.GetType()) {
|
switch (v->current_order.GetType()) {
|
||||||
case OT_GOTO_STATION:
|
case OT_GOTO_STATION:
|
||||||
|
|
|
@ -45,7 +45,7 @@ public:
|
||||||
/// return debug report character to identify the transportation type
|
/// return debug report character to identify the transportation type
|
||||||
FORCEINLINE char TransportTypeChar() const {return 't';}
|
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;
|
Tpf pf1;
|
||||||
bool result1 = pf1.FindNearestDepotTwoWay(v, t1, td1, t2, td2, max_distance, reverse_penalty, depot_tile, reversed);
|
bool result1 = pf1.FindNearestDepotTwoWay(v, t1, td1, t2, td2, max_distance, reverse_penalty, depot_tile, reversed);
|
||||||
|
@ -64,7 +64,7 @@ public:
|
||||||
return result1;
|
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
|
// set origin and destination nodes
|
||||||
Yapf().SetOrigin(t1, td1, t2, td2, reverse_penalty, true);
|
Yapf().SetOrigin(t1, td1, t2, td2, reverse_penalty, true);
|
||||||
|
@ -121,7 +121,7 @@ public:
|
||||||
/// return debug report character to identify the transportation type
|
/// return debug report character to identify the transportation type
|
||||||
FORCEINLINE char TransportTypeChar() const {return 't';}
|
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
|
// create pathfinder instance
|
||||||
Tpf pf1;
|
Tpf pf1;
|
||||||
|
@ -148,7 +148,7 @@ public:
|
||||||
return result1;
|
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
|
// set origin and destination nodes
|
||||||
Yapf().SetOrigin(v->tile, GetVehicleTrackdir(v), INVALID_TILE, INVALID_TRACKDIR, 1, true);
|
Yapf().SetOrigin(v->tile, GetVehicleTrackdir(v), INVALID_TILE, INVALID_TRACKDIR, 1, true);
|
||||||
|
@ -181,7 +181,7 @@ public:
|
||||||
return next_trackdir;
|
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;
|
Tpf pf1;
|
||||||
bool result1 = pf1.CheckReverseTrain(v, t1, td1, t2, td2, reverse_penalty);
|
bool result1 = pf1.CheckReverseTrain(v, t1, td1, t2, td2, reverse_penalty);
|
||||||
|
@ -198,7 +198,7 @@ public:
|
||||||
return result1;
|
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
|
// create pathfinder instance
|
||||||
// set origin and destination nodes
|
// set origin and destination nodes
|
||||||
|
@ -247,10 +247,10 @@ struct CYapfAnyDepotRail1 : CYapfT<CYapfRail_TypesT<CYapfAnyDepotRail1, CFollowT
|
||||||
struct CYapfAnyDepotRail2 : CYapfT<CYapfRail_TypesT<CYapfAnyDepotRail2, CFollowTrackRailNo90, CRailNodeListTrackDir, CYapfDestinationAnyDepotRailT , CYapfFollowAnyDepotRailT> > {};
|
struct CYapfAnyDepotRail2 : CYapfT<CYapfRail_TypesT<CYapfAnyDepotRail2, CFollowTrackRailNo90, CRailNodeListTrackDir, CYapfDestinationAnyDepotRailT , CYapfFollowAnyDepotRailT> > {};
|
||||||
|
|
||||||
|
|
||||||
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
|
// 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;
|
PfnChooseRailTrack pfnChooseRailTrack = &CYapfRail1::stChooseRailTrack;
|
||||||
|
|
||||||
// check if non-default YAPF type needed
|
// check if non-default YAPF type needed
|
||||||
|
@ -263,10 +263,10 @@ Trackdir YapfChooseRailTrack(Vehicle *v, TileIndex tile, DiagDirection enterdir,
|
||||||
return td_ret;
|
return td_ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool YapfCheckReverseTrain(Vehicle* v)
|
bool YapfCheckReverseTrain(const Vehicle* v)
|
||||||
{
|
{
|
||||||
/* last wagon */
|
/* last wagon */
|
||||||
Vehicle* last_veh = GetLastVehicleInChain(v);
|
const Vehicle *last_veh = GetLastVehicleInChain(v);
|
||||||
|
|
||||||
// get trackdirs of both ends
|
// get trackdirs of both ends
|
||||||
Trackdir td = GetVehicleTrackdir(v);
|
Trackdir td = GetVehicleTrackdir(v);
|
||||||
|
@ -307,7 +307,7 @@ bool YapfCheckReverseTrain(Vehicle* v)
|
||||||
reverse_penalty += DistanceManhattan(cur_tile, tile_rev) * YAPF_TILE_LENGTH;
|
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;
|
PfnCheckReverseTrain pfnCheckReverseTrain = CYapfRail1::stCheckReverseTrain;
|
||||||
|
|
||||||
// check if non-default YAPF type needed
|
// check if non-default YAPF type needed
|
||||||
|
@ -323,12 +323,12 @@ bool YapfCheckReverseTrain(Vehicle* v)
|
||||||
return reverse;
|
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;
|
*depot_tile = INVALID_TILE;
|
||||||
*reversed = false;
|
*reversed = false;
|
||||||
|
|
||||||
Vehicle* last_veh = GetLastVehicleInChain(v);
|
const Vehicle *last_veh = GetLastVehicleInChain(v);
|
||||||
|
|
||||||
TileIndex tile = v->tile;
|
TileIndex tile = v->tile;
|
||||||
TileIndex last_tile = last_veh->tile;
|
TileIndex last_tile = last_veh->tile;
|
||||||
|
@ -337,7 +337,7 @@ bool YapfFindNearestRailDepotTwoWay(Vehicle *v, int max_distance, int reverse_pe
|
||||||
Trackdir td = GetVehicleTrackdir(v);
|
Trackdir td = GetVehicleTrackdir(v);
|
||||||
Trackdir td_rev = ReverseTrackdir(GetVehicleTrackdir(last_veh));
|
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;
|
PfnFindNearestDepotTwoWay pfnFindNearestDepotTwoWay = &CYapfAnyDepotRail1::stFindNearestDepotTwoWay;
|
||||||
|
|
||||||
// check if non-default YAPF type needed
|
// check if non-default YAPF type needed
|
||||||
|
|
|
@ -253,13 +253,13 @@ public:
|
||||||
/// return debug report character to identify the transportation type
|
/// return debug report character to identify the transportation type
|
||||||
FORCEINLINE char TransportTypeChar() const {return 'r';}
|
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;
|
Tpf pf;
|
||||||
return pf.ChooseRoadTrack(v, tile, enterdir);
|
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
|
// handle special case - when next tile is destination tile
|
||||||
if (tile == v->dest_tile) {
|
if (tile == v->dest_tile) {
|
||||||
|
@ -400,15 +400,16 @@ struct CYapfRoadAnyDepot1 : CYapfT<CYapfRoad_TypesT<CYapfRoadAnyDepot1, CRoadNod
|
||||||
struct CYapfRoadAnyDepot2 : CYapfT<CYapfRoad_TypesT<CYapfRoadAnyDepot2, CRoadNodeListExitDir , CYapfDestinationAnyDepotRoadT> > {};
|
struct CYapfRoadAnyDepot2 : CYapfT<CYapfRoad_TypesT<CYapfRoadAnyDepot2, CRoadNodeListExitDir , CYapfDestinationAnyDepotRoadT> > {};
|
||||||
|
|
||||||
|
|
||||||
Trackdir YapfChooseRoadTrack(Vehicle *v, TileIndex tile, DiagDirection enterdir)
|
Trackdir YapfChooseRoadTrack(const Vehicle *v, TileIndex tile, DiagDirection enterdir)
|
||||||
{
|
{
|
||||||
// default is YAPF type 2
|
// 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
|
PfnChooseRoadTrack pfnChooseRoadTrack = &CYapfRoad2::stChooseRoadTrack; // default: ExitDir, allow 90-deg
|
||||||
|
|
||||||
// check if non-default YAPF type should be used
|
// 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
|
pfnChooseRoadTrack = &CYapfRoad1::stChooseRoadTrack; // Trackdir, allow 90-deg
|
||||||
|
}
|
||||||
|
|
||||||
Trackdir td_ret = pfnChooseRoadTrack(v, tile, enterdir);
|
Trackdir td_ret = pfnChooseRoadTrack(v, tile, enterdir);
|
||||||
return td_ret;
|
return td_ret;
|
||||||
|
|
|
@ -34,7 +34,7 @@ public:
|
||||||
/// return debug report character to identify the transportation type
|
/// return debug report character to identify the transportation type
|
||||||
FORCEINLINE char TransportTypeChar() const {return 'w';}
|
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
|
// handle special case - when next tile is destination tile
|
||||||
if (tile == v->dest_tile) {
|
if (tile == v->dest_tile) {
|
||||||
|
@ -147,17 +147,18 @@ struct CYapfShip2 : CYapfT<CYapfShip_TypesT<CYapfShip2, CFollowTrackWater , C
|
||||||
struct CYapfShip3 : CYapfT<CYapfShip_TypesT<CYapfShip3, CFollowTrackWaterNo90, CShipNodeListTrackDir> > {};
|
struct CYapfShip3 : CYapfT<CYapfShip_TypesT<CYapfShip3, CFollowTrackWaterNo90, CShipNodeListTrackDir> > {};
|
||||||
|
|
||||||
/** Ship controller helper - path finder invoker */
|
/** 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
|
// 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
|
PfnChooseShipTrack pfnChooseShipTrack = CYapfShip2::ChooseShipTrack; // default: ExitDir, allow 90-deg
|
||||||
|
|
||||||
// check if non-default YAPF type needed
|
// 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
|
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
|
pfnChooseShipTrack = &CYapfShip1::ChooseShipTrack; // Trackdir, allow 90-deg
|
||||||
|
}
|
||||||
|
|
||||||
Trackdir td_ret = pfnChooseShipTrack(v, tile, enterdir, tracks);
|
Trackdir td_ret = pfnChooseShipTrack(v, tile, enterdir, tracks);
|
||||||
return td_ret;
|
return td_ret;
|
||||||
|
|
Loading…
Reference in New Issue