Skip to content

Commit

Permalink
Merge pull request #1731 from jere8184/default_entry_sector_value
Browse files Browse the repository at this point in the history
change default entry sector value from null
  • Loading branch information
heinezen authored Dec 15, 2024
2 parents 2b902a9 + 775b3f6 commit 846c1fa
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
11 changes: 6 additions & 5 deletions libopenage/pathfinding/pathfinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,11 +269,12 @@ const Pathfinder::portal_star_t Pathfinder::portal_a_star(const PathRequest &req
}

// get the exits of the current node
const auto &exits = current_node->get_exits(current_node->entry_sector);
ENSURE(current_node->entry_sector != std::nullopt, "Entry sector not set for portal node.");
const auto &exits = current_node->get_exits(current_node->entry_sector.value());

// evaluate all neighbors of the current candidate for further progress
for (auto &[exit, distance_cost] : exits) {
exit->entry_sector = current_node->portal->get_exit_sector(current_node->entry_sector);
exit->entry_sector = current_node->portal->get_exit_sector(current_node->entry_sector.value());
bool not_visited = !visited_portals.contains(exit->portal->get_id());

if (not_visited) {
Expand All @@ -289,9 +290,9 @@ const Pathfinder::portal_star_t Pathfinder::portal_a_star(const PathRequest &req
if (not_visited or tentative_cost < exit->current_cost) {
if (not_visited) {
// Get heuristic cost (from exit node to target cell)
auto exit_sector = grid->get_sector(exit->portal->get_exit_sector(exit->entry_sector));
auto exit_sector = grid->get_sector(exit->portal->get_exit_sector(exit->entry_sector.value()));
auto exit_sector_pos = exit_sector->get_position().to_tile(sector_size);
auto exit_portal_pos = exit->portal->get_exit_center(exit->entry_sector);
auto exit_portal_pos = exit->portal->get_exit_center(exit->entry_sector.value());
exit->heuristic_cost = Pathfinder::heuristic_cost(
exit_sector_pos + exit_portal_pos,
request.target);
Expand Down Expand Up @@ -469,7 +470,7 @@ int Pathfinder::distance_cost(const coord::tile_delta &portal1_pos,

PortalNode::PortalNode(const std::shared_ptr<Portal> &portal) :
portal{portal},
entry_sector{NULL},
entry_sector{std::nullopt},
future_cost{std::numeric_limits<int>::max()},
current_cost{std::numeric_limits<int>::max()},
heuristic_cost{std::numeric_limits<int>::max()},
Expand Down
3 changes: 2 additions & 1 deletion libopenage/pathfinding/pathfinder.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <map>
#include <memory>
#include <optional>
#include <unordered_map>

#include "coord/tile.h"
Expand Down Expand Up @@ -209,7 +210,7 @@ class PortalNode : public std::enable_shared_from_this<PortalNode> {
/**
* Sector where the portal is entered.
*/
sector_id_t entry_sector;
std::optional<sector_id_t> entry_sector;

/**
* Future cost estimation value for this node.
Expand Down

0 comments on commit 846c1fa

Please sign in to comment.