Prettied it up, comments, refactors
This commit is contained in:
@@ -2,58 +2,54 @@
|
||||
#include <map>
|
||||
#include "App.h"
|
||||
#include <unordered_map>
|
||||
|
||||
class Pather;
|
||||
|
||||
class node {
|
||||
public:
|
||||
|
||||
node(sf::Vector2i XY, double h, int cF, int cL, node* p, Pather* pather_);
|
||||
node();
|
||||
~node();
|
||||
|
||||
sf::Vector2i xy;
|
||||
|
||||
// Ugh, pointers, ugh c++
|
||||
node* parent;
|
||||
double hueristic;
|
||||
int cameFrom;
|
||||
int closedList;
|
||||
Pather* pather;
|
||||
|
||||
void neighbors();
|
||||
private:
|
||||
|
||||
};
|
||||
#include "node.h"
|
||||
|
||||
class Pather {
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
Pather(Map* map_);
|
||||
~Pather();
|
||||
|
||||
// Reference to the map data
|
||||
Map* map;
|
||||
|
||||
std::unordered_map<node*, double> openList;
|
||||
std::unordered_map<node*, double> closedList;
|
||||
// Containers for the loop, probably inefficient as hell
|
||||
std::unordered_map<node*, double> open_list;
|
||||
std::unordered_map<node*, double> closed_list;
|
||||
|
||||
MultiArray<int, Map::CELLS_WIDTH , Map::CELLS_HEIGHT> visitedMap;
|
||||
//int visitedMap[App::WINDOW_HEIGHT][App::WINDOW_WIDTH];
|
||||
// A stack allocated 2d array from a template I stole from stackOverflow
|
||||
MultiArray<int, Map::CELLS_WIDTH , Map::CELLS_HEIGHT> visited_map;
|
||||
|
||||
std::deque<int> pathTo(sf::Vector2i start, sf::Vector2i end);
|
||||
std::deque<int> loop();
|
||||
std::deque<int> returnPath();
|
||||
// Return a deque with the movement info to path to the end position from the start position
|
||||
std::deque<int> getPathTo(sf::Vector2i start, sf::Vector2i end);
|
||||
|
||||
// Returns the end node of the current path
|
||||
sf::Vector2i getEndNodePosition();
|
||||
|
||||
node* start_node;
|
||||
node* active_node;
|
||||
|
||||
bool no_path = false;
|
||||
bool early_exit;
|
||||
// Returns the current active node
|
||||
node* getActiveNode();
|
||||
|
||||
private:
|
||||
// Whether we couldn't find a path
|
||||
bool no_path = false;
|
||||
// If we found the path and can exit early
|
||||
bool early_exit;
|
||||
|
||||
// Calculate the return path from back tracing the active nodes
|
||||
std::deque<int> returnPath();
|
||||
|
||||
// The main iterative loop for a*
|
||||
std::deque<int> loop();
|
||||
|
||||
// Movement list for the Explorer
|
||||
std::deque<int> path_list;
|
||||
|
||||
// Start positions node
|
||||
node* start_node;
|
||||
// Current positions node
|
||||
node* active_node;
|
||||
// End positions node
|
||||
node* end_node;
|
||||
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user