restructuring and updating CMakeLists

This commit is contained in:
2017-07-16 14:04:41 -07:00
parent 769c37f148
commit aa593870df
16 changed files with 96 additions and 26 deletions

78
include/App.h Normal file
View File

@@ -0,0 +1,78 @@
#pragma once
#include <SFML/Graphics.hpp>
#include "Map.h"
#include "Explorer.h"
// 2d heap allocated array structure stolen off of stackOverflow
template<typename T, int width, int height>
class MultiArray {
private:
typedef T cols[height];
cols * data;
public:
T& operator() (int x, int y) { return data[x][y]; }
MultiArray() { data = new cols[width]; }
~MultiArray() { delete[] data; }
};
class App {
public:
// Constants
static const int WINDOW_HEIGHT = 766;
static const int WINDOW_WIDTH = 1596;
const double PI = 3.141592653589793238462643383279;
App();
~App();
// Start the app
void Run();
private:
// Map and its data
Map map;
// The explorer that will traverse the map
Explorer* explorer;
// Art assets
sf::Texture* background_texture;
sf::Sprite backgroundSprite;
// Data required for hand drawing pixels
sf::Uint8* _pixelArray;
sf::Sprite pixel_array_sprite;
sf::Texture pixel_array_texture;
void Init();
void Input();
void Update(double step_size);
void Render();
// The main render window, probably should think about supporting multiple of these
sf::RenderWindow* window;
// The events for the event handler
sf::Event event;
// ============= Loop data ==================
float time();
// Size of the physics steps to take
float step_size = 0.005f;
double current_time = 0.0;
double frame_time = 0.0;
double instant_fps = 0.0;
double accumulator_time = 0.0;
int render_frame_count = 0;
double render_fps = 0;
int physics_frame_count = 0;
double physics_fps = 0;
double elapsed_time = 0;
double delta_time = 0;
};

37
include/Explorer.h Normal file
View File

@@ -0,0 +1,37 @@
#pragma once
#include <SFML/Graphics.hpp>
#include <stack>
#include "Map.h"
class Explorer {
public:
// Constructors
Explorer(Map* map_);
~Explorer();
// Getters
sf::Vector2i getPosition();
sf::Color getColor();
// Move to the specified destination
void setDestination(sf::Vector2i destination_);
// Follow the pathlist for one move
bool move();
private:
// Color that will be drawn
sf::Color color;
sf::Vector2i position;
// Reference to the map data
Map* map;
// Moves list that will be filled with plan(), and executed by move()
std::deque<int> movement_stack;
// Fills the movement stack with moves
bool plan(sf::Vector2i destination_);
};

30
include/Map.h Normal file
View File

@@ -0,0 +1,30 @@
#pragma once
#include "Tile.h"
#include <SFML/System/Vector2.hpp>
class Map {
public:
// Width and height of the map in individual cells
static const int CELLS_HEIGHT = 153;
static const int CELLS_WIDTH = 319;
// Constructors
Map();
~Map();
// Get the tile at the specified position, overloaded
Tile* getTile(sf::Vector2i position);
Tile* getTile(int x_, int y_);
bool isTileSolid(sf::Vector2i);
// completely replaces the data at the specified position
void overwriteTile(sf::Vector2i position, Tile* data);
private:
void Init();
// Data
Tile* tileArray[319][153];
};

58
include/Pather.h Normal file
View File

@@ -0,0 +1,58 @@
#pragma once
#include <map>
#include "App.h"
#include <unordered_map>
#include "node.h"
class Pather {
public:
// Constructor
Pather(Map* map_);
~Pather();
// Reference to the map data
Map* map;
// Containers for the loop, probably inefficient as hell
std::unordered_map<node*, double> open_list;
std::unordered_map<node*, double> closed_list;
// A stack allocated 2d array from a template I stole from stackOverflow
MultiArray<int, Map::CELLS_WIDTH , Map::CELLS_HEIGHT> visited_map;
// 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();
// 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;
};

22
include/Tile.h Normal file
View File

@@ -0,0 +1,22 @@
#pragma once
#include <SFML/Graphics.hpp>
class Tile {
public:
Tile(bool solid_, double movement_penalty_, sf::Color color_);
Tile();
~Tile();
bool isSolid();
double getPenalty();
sf::Color getColor();
void Rewrite(bool solid_, double movement_penalty_, sf::Color color_);
private:
bool solid = false;
double movement_penalty = 0.0;
sf::Color color;
};

44
include/node.h Normal file
View File

@@ -0,0 +1,44 @@
#pragma once
#include <map>
#include "App.h"
#include <unordered_map>
class Pather;
class node {
public:
// XY position, hueristic value, cameFrom direction, parent, ref to pather
node(sf::Vector2i position_, double hueristic_, int came_from_, node* parent_, Pather* pather_);
node();
~node();
// Populate the open_list with neighbors
void getNewNeighbors();
// HAS THE ABILITY TO DELETE THE PARENT!!
node* getParent();
sf::Vector2i getPosition();
double getHueristic();
int getCameFrom();
private:
// Position of the node
sf::Vector2i position;
// The parent of the node, previous one visited
node* parent;
// How close it is to the destination
double hueristic;
// What direction the parent was
int came_from;
// Ref to pather
Pather* pather;
};