| 665 | } |
| 666 | |
| 667 | Maybe<pair<Vec2F, bool>> ActorMovementController::pathMove(Vec2F const& position, bool, Maybe<PlatformerAStar::Parameters> const& parameters) { |
| 668 | if (!m_pathController) |
| 669 | m_pathController = make_shared<PathController>(world()); |
| 670 | |
| 671 | // set new parameters if they have changed |
| 672 | if (m_pathController->targetPosition().isNothing() || (parameters && m_pathController->parameters() != *parameters)) { |
| 673 | if (parameters) |
| 674 | m_pathController->setParameters(*parameters); |
| 675 | m_pathMoveResult = m_pathController->findPath(*this, position).apply([position](bool result) { return pair<Vec2F, bool>(position, result); }); |
| 676 | } |
| 677 | |
| 678 | // update target position if it has changed |
| 679 | if (m_pathController) { |
| 680 | m_pathController->findPath(*this, position); |
| 681 | } |
| 682 | |
| 683 | if (m_pathMoveResult.isValid()) { |
| 684 | // path controller failed or succeeded, return the result and reset the controller |
| 685 | m_pathController->reset(); |
| 686 | } |
| 687 | |
| 688 | return take(m_pathMoveResult); |
| 689 | } |
| 690 | |
| 691 | Maybe<pair<Vec2F, bool>> ActorMovementController::controlPathMove(Vec2F const& position, bool run, Maybe<PlatformerAStar::Parameters> const& parameters) { |
| 692 | auto result = pathMove(position, run, parameters); |
no test coverage detected