NAME

Game::TileMap::Pathfinding::Result - Pathfinding result object

SYNOPSIS

while (my ($x, $y) = $result->next_step) {
	...
}

DESCRIPTION

This is a lightweight blessed object which represents a result of successful pathfinding. The underlying reference is an array of 2n elements, where n is the number of steps.

Each step consists of two elements in this array. This array can be accessed manually, this module only functions as a syntactic sugar. For example, it may be more convenient (and surely more performant) to avoid using this interface and use for_list in modern perl instead:

use v5.42;

foreach my ($x, $y) ($result->@*) {
	...
}

Interface

new

$pf_result = $class->new($array_ref)

Returns a new instance of this class. This is done automatically in "find_path" in Game::TileMap::Pathfinding.

next_step

($x, $y) = $pf_result->next_step()

This removes the first coordinate pair from the underlying array and returns x and y integers. Can be called in loop until it starts to return undefs.

steps

@all_steps = $pf_result->steps()

This method returns all steps as an array of two-element array references. This is less efficient because of the extra arrays created, and does not mix with "next_step". However, can come in handy in certain scenarios.

step_count

$count = $pf_result->step_count()

This returns the number of steps needed to reach the destination. This will be reduced by 1 after each call to "next_step", and when it reaches 0, the destination has been reached.

SEE ALSO

Game::TileMap::Pathfinding