/*
Minetest
Copyright (C) 2013 sapier, sapier at gmx dot net
Copyright (C) 2016 est31, <MTest31@outlook.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
/******************************************************************************/
/* Includes */
/******************************************************************************/
#include "pathfinder.h"
#include "serverenvironment.h"
#include "server.h"
#include "nodedef.h"
//#define PATHFINDER_DEBUG
//#define PATHFINDER_CALC_TIME
#ifdef PATHFINDER_DEBUG
#include <string>
#endif
#ifdef PATHFINDER_DEBUG
#include <iomanip>
#endif
#ifdef PATHFINDER_CALC_TIME
#include <sys/time.h>
#endif
/******************************************************************************/
/* Typedefs and macros */
/******************************************************************************/
#define LVL "(" << level << ")" <<
#ifdef PATHFINDER_DEBUG
#define DEBUG_OUT(a) std::cout << a
#define INFO_TARGET std::cout
#define VERBOSE_TARGET std::cout
#define ERROR_TARGET std::cout
#else
#define DEBUG_OUT(a) while(0)
#define INFO_TARGET infostream << "Pathfinder: "
#define VERBOSE_TARGET verbosestream << "Pathfinder: "
#define ERROR_TARGET warningstream << "Pathfinder: "
#endif
/******************************************************************************/
/* Class definitions */
/******************************************************************************/
/** representation of cost in specific direction */
class PathCost {
public:
/** default constructor */
PathCost();
/** copy constructor */
PathCost(const PathCost &b);
/** assignment operator */
PathCost &operator= (const PathCost &b);
bool valid; /**< movement is possible */
int value; /**< cost of movement */
int direction; /**< y-direction of movement */
bool updated; /**< this cost has ben calculated */
};
/** representation of a mapnode to be used for pathfinding */
class PathGridnode {
public:
/** default constructor */
PathGridnode();
/** copy constructor */
PathGridnode(const PathGridnode &b);
/**
* assignment operator
* @param b node to copy
*/
PathGridnode &operator= (const PathGridnode &b);
/**
* read cost in a specific direction
* @param dir direction of cost to fetch
*/
PathCost getCost(v3s16 dir);
/**
* set cost value for movement
* @param dir direction to set cost for
* @cost cost to set
*/
void setCost(v3s16 dir, const PathCost &cost);
bool valid; /**< node is on surface */
bool target; /**< node is target position */
bool source; /**< node is stating position */
int totalcost; /**< cost to move here from starting point */
v3s16 sourcedir; /**< origin of movement for current cost */
v3s16 pos; /**< real position of node */
PathCost directions[4]; /**< cost in different directions */
/* debug values */
bool is_element; /**< node is element of path detected */
char type; /**< type of node */
};
class Pathfinder;
/** Abstract class to manage the map data */
class GridNodeContainer {
public:
virtual PathGridnode &access(v3s16 p)=0;
virtual ~GridNodeContainer() {}
protected:
Pathfinder *m_pathf;
void initNode(v3s16 ipos, PathGridnode *p_node);
};
class ArrayGridNodeContainer : public GridNodeContainer {
public:
virtual ~ArrayGridNodeContainer() {}
ArrayGridNodeContainer(Pathfinder *pathf, v3s16 dimensions);
virtual PathGridnode &access(v3s16 p);
private:
v3s16 m_dimensions;
int m_x_stride;
int m_y_stride;
|