ORTS

SimpleTerrain::ST_Terrain::PFEngine Class Reference

#include <ST_PFEngine.H>

List of all members.

Classes

class  Map
 Extend the SimpleMap with set/access methods to allow multiple levels-of-detail. More...

Public Types

typedef uint4 LevelOfDetail
 index into the LOD array passed to the ctor

Public Member Functions

 PFEngine (sint4 tiles_x_, sint4 tiles_y_, sint4 tile_points_, const Vector< sint4 > &lods_needed)
Changes to the world.
void insert_object (const Object *obj)
 Insert a given object to the internal world representation.
void remove_object (const Object *obj)
void update_object (const Object *obj)
void insert_boundary (const Segment &line)
void ir_path (const Object *obj, const Path &path, bool insert)
Perform path finding
bool find_path (const Object *obj, const Loc &goal, Path &output, LevelOfDetail lod=0, ConsiderObjects consider=CONSIDER_ALL, uint4 stop_time=0)
 Perform pathfinding to a location, return true iff path found, and the path itself in 'output'.
bool find_path (const Object *obj, const Object *goal, Path &output, LevelOfDetail lod=0, ConsiderObjects consider=CONSIDER_ALL, uint4 stop_time=0)
 Perform pathfinding to a target object, return true iff path found, and the path itself in 'output' If found then output is guaranteed to include at least one waypoint for the goal.
bool find_path (const Loc loc, const Loc &goal, sint4 radius, Path &output, LevelOfDetail lod=0, ConsiderObjects consider=CONSIDER_ALL, uint4 stop_time=0)
 MINE!!! Perform pathfinding on a small submap, loc to loc, return true iff path found, and the path itself in 'output'.
bool sub_path (const Object *obj, const Loc &topLeft, const Loc &bottomRight, const Object *goal_obj, Path &output, LevelOfDetail lod=0, ConsiderObjects consider=CONSIDER_ALL, uint4 stop_time=0)
 Perform pathfinding to a target object, return true iff path found, and the path itself in 'output' If found then output is guaranteed to include at least one waypoint for the goal.
bool sub_path (const Object *obj, const Loc &topLeft, const Loc &bottomRight, const Loc &goal_loc, Path &output, LevelOfDetail lod=0, ConsiderObjects consider=CONSIDER_ALL, uint4 stop_time=0)
 Perform pathfinding on a small submap, to a location, return true iff path found, and the path itself in 'output'.
bool sub_path (const Loc loc, const Loc &topLeft, const Loc &bottomRight, const Loc &goal_loc, sint4 radius, Path &output, LevelOfDetail lod=0, ConsiderObjects consider=CONSIDER_ALL, uint4 stop_time=0)
 Perform pathfinding on a small submap, to a location, return true iff path found, and the path itself in 'output'.

Private Types

typedef
ArbitraryResolutionSimpleMap
< AStarCell
AStarMap
typedef Vector
< boost::shared_ptr< Map > > 
MapsVector

Private Member Functions

boost::shared_ptr< const Mapget_ground_map () const
 cost of passing though a square within the direction of another units x-second distance x-second distance: if a unit continues to move in a straight line it will be there in x-seconds
boost::shared_ptr< const Mapget_air_map () const
Actual computation of paths
template<class GoalTester >
bool find_path (const Object *obj, const Loc &start_position, const Loc &goal, GoalTester goal_tester, const Loc &topleft, const Loc &bottomright, LevelOfDetail lod, ConsiderObjects consider, Path &output, uint4 stop_time)
 This implementation can handle multiple target locations and can handle a target object.
Actual computation of paths. Loc to Loc
template<class GoalTester >
bool find_path (const sint4 radius, const Loc &start_position, const Loc &goal, GoalTester goal_tester, const Loc &topleft, const Loc &bottomright, LevelOfDetail lod, ConsiderObjects consider, Path &output, uint4 stop_time)
 This implementation can handle multiple target locations and can handle a target location.
template<class GoalTester >
bool simple_astar (const Map &world_view, AStarMap &astar_data, Bucket to_move, sint4 x2, sint4 y2, GoalTester goal_tester, const Loc &topleft, const Loc &bottomright, uint4 &end_of_path, uint4 stop_time)
 The actual A* implementation.
void ignore_objects (ConsiderObjects consider, boost::shared_ptr< Map > map, const Object *moved_obj)
 Remove objects we wish to ignore for PFing from the world map.
void reconsider_objects (ConsiderObjects consider, boost::shared_ptr< Map > map, const Object *moved_obj)
 Return the objects we ignored for the last PFing back to the world map.
void ignore_objects (ConsiderObjects consider, boost::shared_ptr< Map > map)
 Remove objects we wish to ignore for PFing from the world map.
void reconsider_objects (ConsiderObjects consider, boost::shared_ptr< Map > map)
 Return the objects we ignored for the last PFing back to the world map.
void smoothen_path (Vector< Loc > &path)
 Remove redundant waypoints (that fall on a straight line)
uint4 estimate (sint4 x1, sint4 y1, sint4 x2, sint4 y2)
 Compute the octile distance between two points.
bool on_line (const Loc &a, const Loc &b, const Loc &c)
 Check whether the given three points are on a straight line.

Static Private Member Functions

static void init_sizes (SimpleMap< SizeCell > &smap)
 Initialize a given map to be empty with a blocked border.

Private Attributes

Vector< sint4lods
 Levels Of Detail available.
LevelOfDetail max_details_LOD
 The most detailed level.
MapsVector ground_maps
MapsVector air_maps
Vector< boost::shared_ptr
< AStarMap > > 
astar_maps
std::set< const Object * > mobile_objects
 Set of all mobile objects, allows ignoring them during PFing.

Static Private Attributes

Cost constants
static const uint4 FACTOR = 128
 distance multiplier (real->int)
static const uint4 DIAG = sint4(FACTOR*1.4142)
static const sint4 UNIT_COST = 1000000
 cost of passing though a square occupied by another unit
static const sint4 BOUND_COST = 5000000
 cost of passing though a square occupied by and orts boundery

Friends

class Map
class SimpleTerrainWidget
class SimpleTerrainOverlay
Predicates for testing arrival to different types of goals
class IsTouchingTarget
class IsAtLocation
class IsAtClearLocation

Detailed Description

Definition at line 76 of file ST_PFEngine.H.


Member Typedef Documentation

index into the LOD array passed to the ctor

Definition at line 133 of file ST_PFEngine.H.

typedef Vector< boost::shared_ptr<Map> > SimpleTerrain::ST_Terrain::PFEngine::MapsVector [private]

Definition at line 221 of file ST_PFEngine.H.


Constructor & Destructor Documentation

SimpleTerrain::ST_Terrain::PFEngine::PFEngine ( sint4  tiles_x_,
sint4  tiles_y_,
sint4  tile_points_,
const Vector< sint4 > &  lods_needed 
)
Parameters:
tiles_x_Width of world in tiles.
tiles_y_Height of world in tiles.
tile_points_How many points per tile are in the full world representation.
lods_neededVector indicating levels of detail of inner world representation needed. 1 - full details, resolution as in the world rep; 2 - half resolution; 4 - quarter resultion; etc. (tiles_x_*tile_points_) and (tiles_y_*tile_points_) must be divisible by each LOD.

Definition at line 136 of file ST_PFEngine.C.

References air_maps, assert(), astar_maps, FORALL, ground_maps, init_sizes(), lods, Map, and max_details_LOD.


Member Function Documentation

uint4 SimpleTerrain::ST_Terrain::PFEngine::estimate ( sint4  x1,
sint4  y1,
sint4  x2,
sint4  y2 
) [private]

Compute the octile distance between two points.

Definition at line 1033 of file ST_PFEngine.C.

References min().

bool SimpleTerrain::ST_Terrain::PFEngine::find_path ( const Object obj,
const Loc goal,
Path output,
LevelOfDetail  lod = 0,
ConsiderObjects  consider = CONSIDER_ALL,
uint4  stop_time = 0 
)

Perform pathfinding to a location, return true iff path found, and the path itself in 'output'.

If found then output is guaranteed to include at least one waypoint for the goal. Waypoints are listed in reverse order, goal is in locs[0].

Definition at line 183 of file ST_PFEngine.C.

References SimpleTerrain::get_center_loc(), and TEST.

bool SimpleTerrain::ST_Terrain::PFEngine::find_path ( const Loc  loc,
const Loc goal,
sint4  radius,
Path output,
LevelOfDetail  lod = 0,
ConsiderObjects  consider = CONSIDER_ALL,
uint4  stop_time = 0 
)

MINE!!! Perform pathfinding on a small submap, loc to loc, return true iff path found, and the path itself in 'output'.

If found then output is guaranteed to include at least one waypoint for the goal. Waypoints are listed in reverse order, goal is in locs[0].

Definition at line 214 of file ST_PFEngine.C.

References TEST.

bool SimpleTerrain::ST_Terrain::PFEngine::find_path ( const Object obj,
const Object goal,
Path output,
LevelOfDetail  lod = 0,
ConsiderObjects  consider = CONSIDER_ALL,
uint4  stop_time = 0 
)

Perform pathfinding to a target object, return true iff path found, and the path itself in 'output' If found then output is guaranteed to include at least one waypoint for the goal.

Waypoints are listed in reverse order, goal is in locs[0].

Definition at line 202 of file ST_PFEngine.C.

References SimpleTerrain::get_center_loc(), and TEST.

template<class GoalTester >
bool SimpleTerrain::ST_Terrain::PFEngine::find_path ( const Object obj,
const Loc start_position,
const Loc goal,
GoalTester  goal_tester,
const Loc topleft,
const Loc bottomright,
LevelOfDetail  lod,
ConsiderObjects  consider,
Path output,
uint4  stop_time 
) [private]

This implementation can handle multiple target locations and can handle a target object.

To this end it accepts a predicate for testing whether a specific map location (inner coords + map pointer) is an allowable goal location. It currently doesn't support a pluggable distance huristic, but instead accepts 'the goal' location (probably the center of the target) and uses the usual octile distance huristic. This combination results in an inadmissible huristic, but should give reasonable results without resorting to the slower huristic h = min distance to all goal locations. stop and report failure when SDL_GetTicks() >= stop_time; 0 => no time limit

Parameters:
objthe object to move
start_positionMove it from where (not necessarily its current position)
goalthe goal location used for distance estimation
goal_testera predicate for an AStarCell which is true iff it is a goal location
toplefttopleft corner of the submap to explore for this path; use Loc(0,0) to specify the entire map
bottomrightbottomright corner of the submap to explore for this path; use Loc(-1,-1) or smaller to specify the entire map
lodthe LOD to use
considerwhat objects to consider/ignore as obstacles
outputoutput path is returned here

Definition at line 472 of file ST_PFEngine.C.

References assert(), SimpleTerrain::SimpleMap< T >::at(), SimpleTerrain::ST_Terrain::find_path(), found, SimpleTerrain::BucketFactory::get_bucket(), Object::get_radius(), Object::get_zcat(), TerrainBase::Path::locs, max(), min(), Object::ON_LAND, SimpleTerrain::Bucket::set_center(), TerrainBase::Loc::x, and TerrainBase::Loc::y.

template<class GoalTester >
bool SimpleTerrain::ST_Terrain::PFEngine::find_path ( const sint4  radius,
const Loc start_position,
const Loc goal,
GoalTester  goal_tester,
const Loc topleft,
const Loc bottomright,
LevelOfDetail  lod,
ConsiderObjects  consider,
Path output,
uint4  stop_time 
) [private]

This implementation can handle multiple target locations and can handle a target location.

To this end it accepts a predicate for testing whether a specific map location (inner coords + map pointer) is an allowable goal location. It currently doesn't support a pluggable distance huristic, but instead accepts 'the goal' location (probably the center of the target) and uses the usual octile distance huristic. This combination results in an inadmissible huristic, but should give reasonable results without resorting to the slower huristic h = min distance to all goal locations. stop and report failure when SDL_GetTicks() >= stop_time; 0 => no time limit

Parameters:
radiusthe radius to calculate
start_positionMove it from where (not necessarily its current position)
goalthe goal location used for distance estimation
goal_testera predicate for an AStarCell which is true iff it is a goal location
toplefttopleft corner of the submap to explore for this path; use Loc(0,0) to specify the entire map
bottomrightbottomright corner of the submap to explore for this path; use Loc(-1,-1) or smaller to specify the entire map
lodthe LOD to use
considerwhat objects to consider/ignore as obstacles
outputoutput path is returned here

Definition at line 356 of file ST_PFEngine.C.

References assert(), SimpleTerrain::SimpleMap< T >::at(), SimpleTerrain::ST_Terrain::find_path(), found, SimpleTerrain::BucketFactory::get_bucket(), TerrainBase::Path::locs, max(), min(), SimpleTerrain::Bucket::set_center(), TerrainBase::Loc::x, and TerrainBase::Loc::y.

boost::shared_ptr<const Map> SimpleTerrain::ST_Terrain::PFEngine::get_air_map ( ) const [inline, private]

Definition at line 360 of file ST_PFEngine.H.

boost::shared_ptr<const Map> SimpleTerrain::ST_Terrain::PFEngine::get_ground_map ( ) const [inline, private]

cost of passing though a square within the direction of another units x-second distance x-second distance: if a unit continues to move in a straight line it will be there in x-seconds

Serving the graphical widget that is used for developement.

Definition at line 359 of file ST_PFEngine.H.

References ground_maps.

void SimpleTerrain::ST_Terrain::PFEngine::ignore_objects ( ConsiderObjects  consider,
boost::shared_ptr< Map map,
const Object moved_obj 
) [private]

Remove objects we wish to ignore for PFing from the world map.

void SimpleTerrain::SimpleGlobalPF::ignore_objects ( ConsiderObjects  consider,
boost::shared_ptr< Map map 
) [private]
void SimpleTerrain::ST_Terrain::PFEngine::init_sizes ( SimpleMap< SizeCell > &  smap) [static, private]

Initialize a given map to be empty with a blocked border.

Definition at line 1115 of file ST_PFEngine.C.

References FORS, FORU, SimpleTerrain::SimpleMap< T >::get_h(), SimpleTerrain::SimpleMap< T >::get_n(), and SimpleTerrain::SimpleMap< T >::get_w().

Referenced by PFEngine().

void SimpleTerrain::ST_Terrain::PFEngine::insert_boundary ( const Segment line)

Definition at line 1099 of file ST_PFEngine.C.

void SimpleTerrain::ST_Terrain::PFEngine::insert_object ( const Object obj)

Insert a given object to the internal world representation.

Pointers must remain valid until a respective remove_object() call.

Definition at line 1067 of file ST_PFEngine.C.

References Object::get_max_speed(), Object::get_zcat(), and Object::ON_LAND.

void SimpleTerrain::ST_Terrain::PFEngine::ir_path ( const Object obj,
const Path path,
bool  insert 
)

Definition at line 1107 of file ST_PFEngine.C.

bool SimpleTerrain::ST_Terrain::PFEngine::on_line ( const Loc a,
const Loc b,
const Loc c 
) [private]

Check whether the given three points are on a straight line.

Definition at line 1057 of file ST_PFEngine.C.

References TerrainBase::Loc::x, and TerrainBase::Loc::y.

void SimpleTerrain::ST_Terrain::PFEngine::reconsider_objects ( ConsiderObjects  consider,
boost::shared_ptr< Map map,
const Object moved_obj 
) [private]

Return the objects we ignored for the last PFing back to the world map.

void SimpleTerrain::SimpleGlobalPF::reconsider_objects ( ConsiderObjects  consider,
boost::shared_ptr< Map map 
) [private]
void SimpleTerrain::ST_Terrain::PFEngine::remove_object ( const Object obj)

Definition at line 1079 of file ST_PFEngine.C.

References Object::get_max_speed(), Object::get_zcat(), and Object::ON_LAND.

template<class GoalTester >
bool SimpleTerrain::ST_Terrain::PFEngine::simple_astar ( const Map world_view,
AStarMap astar_data,
Bucket  to_move,
sint4  x2,
sint4  y2,
GoalTester  goal_tester,
const Loc topleft,
const Loc bottomright,
uint4 end_of_path,
uint4  stop_time 
) [private]
void SimpleTerrain::ST_Terrain::PFEngine::smoothen_path ( Vector< Loc > &  path) [private]

Remove redundant waypoints (that fall on a straight line)

bool SimpleTerrain::ST_Terrain::PFEngine::sub_path ( const Loc  loc,
const Loc topLeft,
const Loc bottomRight,
const Loc goal_loc,
sint4  radius,
Path output,
LevelOfDetail  lod = 0,
ConsiderObjects  consider = CONSIDER_ALL,
uint4  stop_time = 0 
)

Perform pathfinding on a small submap, to a location, return true iff path found, and the path itself in 'output'.

If found then output is guaranteed to include at least one waypoint for the goal. Waypoints are listed in reverse order, goal is in locs[0].

bool SimpleTerrain::ST_Terrain::PFEngine::sub_path ( const Object obj,
const Loc topLeft,
const Loc bottomRight,
const Loc goal_loc,
Path output,
LevelOfDetail  lod = 0,
ConsiderObjects  consider = CONSIDER_ALL,
uint4  stop_time = 0 
)

Perform pathfinding on a small submap, to a location, return true iff path found, and the path itself in 'output'.

If found then output is guaranteed to include at least one waypoint for the goal. Waypoints are listed in reverse order, goal is in locs[0].

The next refinement doesn't work very well: If the target location is very near to an obstacle, such that the size of the moving object forbids it from being there, the PF will search the entire map (which is slow) before realizing this.

Definition at line 228 of file ST_PFEngine.C.

References SimpleTerrain::ST_Terrain::find_path(), found, SimpleTerrain::get_center_loc(), and TerrainBase::Path::locs.

bool SimpleTerrain::ST_Terrain::PFEngine::sub_path ( const Object obj,
const Loc topLeft,
const Loc bottomRight,
const Object goal_obj,
Path output,
LevelOfDetail  lod = 0,
ConsiderObjects  consider = CONSIDER_ALL,
uint4  stop_time = 0 
)

Perform pathfinding to a target object, return true iff path found, and the path itself in 'output' If found then output is guaranteed to include at least one waypoint for the goal.

Waypoints are listed in reverse order, goal is in locs[0].

void SimpleTerrain::ST_Terrain::PFEngine::update_object ( const Object obj)

Definition at line 1091 of file ST_PFEngine.C.

References Object::get_zcat(), and Object::ON_LAND.


Friends And Related Function Documentation

friend class IsAtClearLocation [friend]

Definition at line 335 of file ST_PFEngine.H.

friend class IsAtLocation [friend]

Definition at line 331 of file ST_PFEngine.H.

friend class IsTouchingTarget [friend]

Definition at line 327 of file ST_PFEngine.H.

friend class Map [friend]

Definition at line 127 of file ST_PFEngine.H.

Referenced by PFEngine().

friend class SimpleTerrainOverlay [friend]

Definition at line 362 of file ST_PFEngine.H.

friend class SimpleTerrainWidget [friend]

Definition at line 360 of file ST_PFEngine.H.


Member Data Documentation

Definition at line 226 of file ST_PFEngine.H.

Referenced by PFEngine().

Definition at line 227 of file ST_PFEngine.H.

Referenced by PFEngine().

const sint4 SimpleTerrain::ST_Terrain::PFEngine::BOUND_COST = 5000000 [static, private]

cost of passing though a square occupied by and orts boundery

Definition at line 349 of file ST_PFEngine.H.

const uint4 SimpleTerrain::ST_Terrain::PFEngine::DIAG = sint4(FACTOR*1.4142) [static, private]

Definition at line 345 of file ST_PFEngine.H.

const uint4 SimpleTerrain::ST_Terrain::PFEngine::FACTOR = 128 [static, private]

distance multiplier (real->int)

Definition at line 344 of file ST_PFEngine.H.

Levels Of Detail available.

Definition at line 223 of file ST_PFEngine.H.

Referenced by PFEngine().

The most detailed level.

Definition at line 224 of file ST_PFEngine.H.

Referenced by PFEngine().

Set of all mobile objects, allows ignoring them during PFing.

Definition at line 228 of file ST_PFEngine.H.

const sint4 SimpleTerrain::ST_Terrain::PFEngine::UNIT_COST = 1000000 [static, private]

cost of passing though a square occupied by another unit

Definition at line 347 of file ST_PFEngine.H.


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


Generated on Fri May 18 2012 03:03:14 for ORTS by Doxygen1.7.3