bleck, reverting

master
MitchellHansen 9 years ago
parent 56c4f158fc
commit 68aa5ac3e2

@ -22,7 +22,7 @@ private:
sf::Uint8* _pixelArray; sf::Uint8* _pixelArray;
sf::Sprite pixel_array_sprite; sf::Sprite pixel_array_sprite;
sf::Texture pixel_array_texture; sf::Texture pixel_array_texture;
Explorer* explorer; Explorer* explorer;
// Art assets // Art assets

@ -1,10 +1,11 @@
#include "Explorer.h" #include "Explorer.h"
#include <iostream> #include <iostream>
Explorer::Explorer(Map* map_) { Explorer::Explorer(Map* map_){
color = sf::Color::Blue; color = sf::Color::Blue;
position = sf::Vector2i(10, 10); position = sf::Vector2i(10, 10);
map = map_; map = map_;
pather = new Pather(map_);
} }
@ -24,7 +25,7 @@ bool Explorer::move() {
// While there are moves for us to take // While there are moves for us to take
if (!movement_stack.empty()) { if (!movement_stack.empty()) {
bool valid = false; // If the next move is valid, collision bool valid = false; // If the next move is valid, collision
int x = movement_stack.top(); int x = movement_stack.front();
switch (x) { switch (x) {
@ -59,13 +60,13 @@ bool Explorer::move() {
std::cout << "Path blocked" << std::endl; std::cout << "Path blocked" << std::endl;
// Flush the moves list // Flush the moves list
while(!movement_stack.empty()) { while(!movement_stack.empty()) {
movement_stack.pop(); movement_stack.pop_front();
} }
return false; return false;
} }
// If everything went well, pop and return true // If everything went well, pop and return true
movement_stack.pop(); movement_stack.pop_front();
return true; return true;
} }
else else
@ -74,6 +75,6 @@ bool Explorer::move() {
// A* // A*
bool Explorer::plan(sf::Vector2i destination_) { bool Explorer::plan(sf::Vector2i destination_) {
movement_stack = pather->pathTo(position, destination_);
return true; return true;
} }

@ -2,6 +2,7 @@
#include <SFML/Graphics.hpp> #include <SFML/Graphics.hpp>
#include <stack> #include <stack>
#include "Map.h" #include "Map.h"
#include "Pather.h"
class Explorer { class Explorer {
public: public:
@ -13,8 +14,9 @@ private:
sf::Color color; sf::Color color;
sf::Vector2i position; sf::Vector2i position;
Map* map; Map* map;
Pather* pather;
std::stack<int> movement_stack; std::deque<int> movement_stack;
bool move(); bool move();
bool plan(sf::Vector2i destination_); bool plan(sf::Vector2i destination_);
}; };

@ -100,6 +100,10 @@ Pather::Pather(Map* map_) {
map = map_; map = map_;
} }
Pather::Pather() {
}
Pather::~Pather() { Pather::~Pather() {
} }
@ -107,7 +111,7 @@ sf::Vector2i Pather::getEndNodePosition() {
return end_node->xy; return end_node->xy;
} }
std::vector<int> Pather::pathTo(sf::Vector2i start, sf::Vector2i end) { std::deque<int> Pather::pathTo(sf::Vector2i start, sf::Vector2i end) {
// Clear the visited map for erroneous data // Clear the visited map for erroneous data
for (int i = 0; i < Map::CELLS_WIDTH; i++) { for (int i = 0; i < Map::CELLS_WIDTH; i++) {
@ -129,13 +133,13 @@ std::vector<int> Pather::pathTo(sf::Vector2i start, sf::Vector2i end) {
openList.emplace(start_node, 0); openList.emplace(start_node, 0);
early_exit = false; early_exit = false;
//path_list = Loop(); path_list = loop();
return path_list; return path_list;
} }
std::vector<int> Pather::loop() { std::deque<int> Pather::loop() {
while (!openList.empty() && !early_exit) { while (!openList.empty() && !early_exit) {
// Early exit jankyness, need to change this // Early exit jankyness, need to change this
if (closedList.size() > 3000) { if (closedList.size() > 3000) {
@ -172,17 +176,17 @@ std::vector<int> Pather::loop() {
} }
} }
std::vector<int> return_path = returnPath(); std::deque<int> return_path = returnPath();
if (no_path || return_path.empty()) { if (no_path || return_path.empty()) {
return std::vector<int>(0, 0);
std::cout << " no return path " << std::endl; std::cout << " no return path " << std::endl;
return return_path;
} }
return return_path; return return_path;
} }
std::vector<int> Pather::returnPath() { std::deque<int> Pather::returnPath() {
std::vector<int> path; std::deque<int> path;
while (active_node != nullptr) { while (active_node != nullptr) {
path.push_back(active_node->cameFrom); path.push_back(active_node->cameFrom);

@ -29,6 +29,7 @@ private:
class Pather { class Pather {
public: public:
Pather(Map* map_); Pather(Map* map_);
Pather();
~Pather(); ~Pather();
Map* map; Map* map;
@ -37,9 +38,9 @@ public:
std::unordered_map<node*, int> closedList; std::unordered_map<node*, int> closedList;
int visitedMap[App::WINDOW_HEIGHT][App::WINDOW_WIDTH]; int visitedMap[App::WINDOW_HEIGHT][App::WINDOW_WIDTH];
std::vector<int> pathTo(sf::Vector2i start, sf::Vector2i end); std::deque<int> pathTo(sf::Vector2i start, sf::Vector2i end);
std::vector<int> loop(); std::deque<int> loop();
std::vector<int> returnPath(); std::deque<int> returnPath();
sf::Vector2i getEndNodePosition(); sf::Vector2i getEndNodePosition();
@ -51,7 +52,7 @@ public:
private: private:
std::vector<int> path_list; std::deque<int> path_list;
node* end_node; node* end_node;
}; };

@ -1,6 +1,7 @@
#include <SFML/Window.hpp> #include <SFML/Window.hpp>
#include <SFML/Graphics.hpp> #include <SFML/Graphics.hpp>
#include "App.h" #include "App.h"
#include "Pather.h"
int main() int main()
{ {

Loading…
Cancel
Save