inline functions using expensive boost includes in map_location
From running scons with compiler flag -H it seems like these actually include quite a bit, and most of it does not have include guards.
This commit is contained in:
parent
267ebd3385
commit
54f4b77966
2 changed files with 27 additions and 17 deletions
|
@ -28,6 +28,9 @@
|
|||
#include "gettext.hpp"
|
||||
#include "util.hpp"
|
||||
|
||||
#include <boost/assign/list_of.hpp>
|
||||
#include <boost/functional/hash.hpp>
|
||||
|
||||
#define ERR_CF LOG_STREAM(err, config)
|
||||
#define LOG_G LOG_STREAM(info, general)
|
||||
#define DBG_G LOG_STREAM(debug, general)
|
||||
|
@ -44,6 +47,26 @@ std::ostream &operator<<(std::ostream &s, std::vector<map_location> const &v) {
|
|||
return s;
|
||||
}
|
||||
|
||||
/**
|
||||
* Default list of directions
|
||||
*
|
||||
* Moved out of inline, because boost assign list_of is somewhat expensive...
|
||||
*
|
||||
**/
|
||||
const std::vector<map_location::DIRECTION> & map_location::default_dirs() {
|
||||
static const std::vector<map_location::DIRECTION> dirs = boost::assign::list_of(map_location::NORTH)
|
||||
(map_location::NORTH_EAST)(map_location::SOUTH_EAST)(map_location::SOUTH)
|
||||
(map_location::SOUTH_WEST)(map_location::NORTH_WEST);
|
||||
return dirs;
|
||||
}
|
||||
|
||||
/** Moved out of inline because of the boost dependency **/
|
||||
std::size_t hash_value(map_location const & a){
|
||||
boost::hash<size_t> h;
|
||||
return h( (a.x << 16) ^ a.y );
|
||||
}
|
||||
|
||||
|
||||
map_location::DIRECTION map_location::parse_direction(const std::string& str)
|
||||
{
|
||||
if(!str.empty()) {
|
||||
|
|
|
@ -20,11 +20,10 @@
|
|||
class config;
|
||||
class variable_set;
|
||||
|
||||
#include <cmath>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <set>
|
||||
#include <boost/functional/hash.hpp>
|
||||
#include <boost/assign/list_of.hpp>
|
||||
|
||||
/**
|
||||
* Encapsulates the map of the game.
|
||||
|
@ -146,18 +145,6 @@ std::ostream &operator<<(std::ostream &s, map_location const &l);
|
|||
std::ostream &operator<<(std::ostream &s, std::vector<map_location> const &v);
|
||||
|
||||
/** Inlined bodies **/
|
||||
inline std::size_t hash_value(map_location const & a){
|
||||
boost::hash<size_t> h;
|
||||
return h( (a.x << 16) ^ a.y );
|
||||
}
|
||||
|
||||
/** Inline list of directions **/
|
||||
inline const std::vector<map_location::DIRECTION> & map_location::default_dirs() {
|
||||
static const std::vector<map_location::DIRECTION> dirs = boost::assign::list_of(map_location::NORTH)
|
||||
(map_location::NORTH_EAST)(map_location::SOUTH_EAST)(map_location::SOUTH)
|
||||
(map_location::SOUTH_WEST)(map_location::NORTH_WEST);
|
||||
return dirs;
|
||||
}
|
||||
|
||||
/** Inline direction manipulators **/
|
||||
inline map_location::DIRECTION map_location::rotate_right(map_location::DIRECTION d, unsigned int k) {
|
||||
|
@ -364,7 +351,7 @@ inline bool tiles_adjacent(const map_location& a, const map_location& b)
|
|||
|
||||
inline size_t distance_between(const map_location& a, const map_location& b)
|
||||
{
|
||||
const size_t hdistance = abs(a.x - b.x);
|
||||
const size_t hdistance = std::abs(a.x - b.x);
|
||||
|
||||
const size_t vpenalty = ( (((a.x & 1)==0) && ((b.x & 1)==1) && (a.y < b.y))
|
||||
|| (((b.x & 1)==0) && ((a.x & 1)==1) && (b.y < a.y)) ) ? 1 : 0;
|
||||
|
@ -379,7 +366,7 @@ inline size_t distance_between(const map_location& a, const map_location& b)
|
|||
// = maximum(hdistance, vdistance+hdistance-hdistance/2-hdistance%2)
|
||||
// = maximum(hdistance,abs(a.y-b.y)+vpenalty+hdistance/2)
|
||||
|
||||
return std::max<int>(hdistance, abs(a.y - b.y) + vpenalty + hdistance/2);
|
||||
return std::max<int>(hdistance, std::abs(a.y - b.y) + vpenalty + hdistance/2);
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue