Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change default entry sector value from null #1731

Merged
merged 1 commit into from
Dec 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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());
heinezen marked this conversation as resolved.
Show resolved Hide resolved

// 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>
heinezen marked this conversation as resolved.
Show resolved Hide resolved
#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
Loading