CYapfBaseT< Types > Class Template Reference

CYapfBaseT - A-star type path finder base class. More...

#include <yapf_base.hpp>

Inheritance diagram for CYapfBaseT< Types >:

CYapfT< CYapfRail_TypesT< CYapfAnyDepotRail1, CFollowTrackT, CNodeList_HashTableT, CYapfDestinationAnyDepotRailT< Types >, CYapfFollowAnyDepotRailT< Types > > > CYapfT< CYapfRail_TypesT< CYapfAnyDepotRail2, CFollowTrackT, CNodeList_HashTableT, CYapfDestinationAnyDepotRailT< Types >, CYapfFollowAnyDepotRailT< Types > > > CYapfT< CYapfRail_TypesT< CYapfAnySafeTileRail1, CFollowTrackT, CNodeList_HashTableT, CYapfDestinationAnySafeTileRailT< Types >, CYapfFollowAnySafeTileRailT< Types > > > CYapfT< CYapfRail_TypesT< CYapfAnySafeTileRail2, CFollowTrackT, CNodeList_HashTableT, CYapfDestinationAnySafeTileRailT< Types >, CYapfFollowAnySafeTileRailT< Types > > > CYapfT< CYapfRail_TypesT< CYapfRail1, CFollowTrackT, CNodeList_HashTableT, CYapfDestinationTileOrStationRailT< Types >, CYapfFollowRailT< Types > > > CYapfT< CYapfRail_TypesT< CYapfRail2, CFollowTrackT, CNodeList_HashTableT, CYapfDestinationTileOrStationRailT< Types >, CYapfFollowRailT< Types > > > CYapfT< CYapfRoad_TypesT< CYapfRoad1, CNodeList_HashTableT, CYapfDestinationTileRoadT< Types > > > CYapfT< CYapfRoad_TypesT< CYapfRoad2, CNodeList_HashTableT, CYapfDestinationTileRoadT< Types > > > CYapfT< CYapfRoad_TypesT< CYapfRoadAnyDepot1, CNodeList_HashTableT, CYapfDestinationAnyDepotRoadT< Types > > > CYapfT< CYapfRoad_TypesT< CYapfRoadAnyDepot2, CNodeList_HashTableT, CYapfDestinationAnyDepotRoadT< Types > > > CYapfT< CYapfShip_TypesT< CYapfShip1, CFollowTrackT, CNodeList_HashTableT > > CYapfT< CYapfShip_TypesT< CYapfShip2, CFollowTrackT, CNodeList_HashTableT > > CYapfT< CYapfShip_TypesT< CYapfShip3, CFollowTrackT, CNodeList_HashTableT > >

Public Types

typedef Types::Tpf Tpf
 the pathfinder class (derived from THIS class)
typedef Types::TrackFollower TrackFollower
typedef Types::NodeList NodeList
 our node list
typedef NodeList::Titem Node
 this will be our node type
typedef Node::Key Key
 key to hash tables

Public Member Functions

FORCEINLINE CYapfBaseT ()
 default constructor
 ~CYapfBaseT ()
 default destructor
FORCEINLINE const YAPFSettingsPfGetSettings () const
 return current settings (can be custom - company based - but later)
bool FindPath (const Vehicle *v)
 Main pathfinder routine:
  • set startup node(s)
  • main loop that stops if:
    • the destination was found
    • or the open list is empty (no route to destination).

FORCEINLINE NodeGetBestNode ()
 If path was found return the best node that has reached the destination.
FORCEINLINE NodeCreateNewNode ()
 Calls NodeList::CreateNewNode() - allocates new node that can be filled and used as argument for AddStartupNode() or AddNewNode().
FORCEINLINE void AddStartupNode (Node &n)
 Add new node (created by CreateNewNode and filled with data) into open list.
FORCEINLINE void AddMultipleNodes (Node *parent, const TrackFollower &tf)
 add multiple nodes - direct children of the given node
void AddNewNode (Node &n, const TrackFollower &tf)
 AddNewNode() - called by Tderived::PfFollowNode() for each child node.
const Vehicle * GetVehicle () const
void DumpBase (DumpTarget &dmp) const

Data Fields

NodeList m_nodes
 node list multi-container
CPerformanceTimer m_perf_cost
 stats - total CPU time of this run
CPerformanceTimer m_perf_slope_cost
 stats - slope calculation CPU time
CPerformanceTimer m_perf_ts_cost
 stats - GetTrackStatus() CPU time
CPerformanceTimer m_perf_other_cost
 stats - other CPU time
int m_num_steps
 this is there for debugging purposes (hope it doesn't hurt)

Protected Member Functions

FORCEINLINE TpfYapf ()
 to access inherited path finder

Protected Attributes

Nodem_pBestDestNode
 pointer to the destination node found at last round
Nodem_pBestIntermediateNode
 here should be node closest to the destination if path not found
const YAPFSettingsm_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
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

Detailed Description

template<class Types>
class CYapfBaseT< Types >

CYapfBaseT - A-star type path finder base class.

Derive your own pathfinder from it. You must provide the following template argument: Types - used as collection of local types used in pathfinder

Requirements for the Types struct: ---------------------------------- The following types must be defined in the 'Types' argument:

For node list you can use template class CNodeList_HashTableT, for which you need to declare only your node type. Look at test_yapf.h for an example.

Requrements to your pathfinder class derived from CYapfBaseT: ------------------------------------------------------------- Your pathfinder derived class needs to implement following methods: FORCEINLINE void PfSetStartupNodes() FORCEINLINE void PfFollowNode(Node& org) FORCEINLINE bool PfCalcCost(Node& n) FORCEINLINE bool PfCalcEstimate(Node& n) FORCEINLINE bool PfDetectDestination(Node& n)

For more details about those methods, look at the end of CYapfBaseT declaration. There are some examples. For another example look at test_yapf.h (part or unittest project).

Definition at line 43 of file yapf_base.hpp.


Member Function Documentation

template<class Types>
bool CYapfBaseT< Types >::FindPath ( const Vehicle *  v  )  [inline]

Main pathfinder routine:

  • set startup node(s)
  • main loop that stops if:
    • the destination was found
    • or the open list is empty (no route to destination).

  • or the maximum amount of loops reached - m_max_search_nodes (default = 10000)
    Returns:
    true if the path was found

Definition at line 110 of file yapf_base.hpp.

References CYapfBaseT< Types >::m_max_search_nodes, CYapfBaseT< Types >::m_nodes, CYapfBaseT< Types >::m_num_steps, CYapfBaseT< Types >::m_pBestDestNode, CYapfBaseT< Types >::m_pBestIntermediateNode, CYapfBaseT< Types >::m_perf_cost, CYapfBaseT< Types >::m_perf_other_cost, CYapfBaseT< Types >::m_perf_slope_cost, CYapfBaseT< Types >::m_perf_ts_cost, CYapfBaseT< Types >::m_stats_cache_hits, CYapfBaseT< Types >::m_stats_cost_calcs, CYapfBaseT< Types >::m_veh, and CYapfBaseT< Types >::Yapf().

template<class Types>
FORCEINLINE Node* CYapfBaseT< Types >::GetBestNode (  )  [inline]

If path was found return the best node that has reached the destination.

Otherwise return the best visited node (which was nearest to the destination).

Definition at line 172 of file yapf_base.hpp.

References CYapfBaseT< Types >::m_pBestDestNode, and CYapfBaseT< Types >::m_pBestIntermediateNode.

template<class Types>
void CYapfBaseT< Types >::AddNewNode ( Node n,
const TrackFollower &  tf 
) [inline]


The documentation for this class was generated from the following file:

Generated on Mon May 11 15:48:26 2009 for OpenTTD by  doxygen 1.5.6