Updated image.cpp to

1. Use t_token in place of std:string to save on string construction

2. Use boost::unordered_map in place of std::map as per todo by silene
This commit is contained in:
Thonsew 2011-09-08 19:17:41 +00:00
parent 3a41db7acd
commit 7e99017fa4
17 changed files with 181 additions and 187 deletions

View file

@ -153,7 +153,8 @@ terrain_builder::terrain_builder(const config& level,
tile_map_(map().w(), map().h()),
terrain_by_type_()
{
image::precache_file_existence("terrain/");
static const config::t_token z_cterrain("terrain/", false);
image::precache_file_existence(z_cterrain);
if(building_rules_.empty() && rules_cfg_){
//off_map first to prevent some default rule seems to block it
@ -288,7 +289,7 @@ static bool image_exists(const std::string& name)
{
bool precached = name.find("..") == std::string::npos;
if(precached && image::precached_file_exists(name)) {
if(precached && image::precached_file_exists(n_token::t_token(name))) { //todo remove extra init
return true;
} else if(image::exists(name)) {
return true;

View file

@ -161,7 +161,7 @@ std::string rgb2highlight(Uint32 rgb)
int color_range::index() const
{
for(int i = 1; i <= gamemap::MAX_PLAYERS; ++i) {
if(*this==(game_config::color_info(lexical_cast<std::string>(i)))) {
if(*this==(game_config::color_info(n_token::t_token(lexical_cast<std::string>(i))))) {
return i;
}
}

View file

@ -735,7 +735,7 @@ std::vector<surface> display::get_terrain_images(const map_location &loc,
surface surf;
if(!use_local_light) {
const bool off_map = (image.get_filename() == off_map_name);
const bool off_map = (image.get_filename() == n_token::t_token(off_map_name));
surf = image::get_image(image, off_map ? image::SCALED_TO_HEX : image_type);
} else if(color_mod.empty()) {
surf = image::get_image(image, image::SCALED_TO_HEX);

View file

@ -64,7 +64,7 @@ namespace game_config
default_defeat_music;
namespace images {
std::string game_title,
n_token::t_token game_title,
// orbs and hp/xp bar
moved_orb,
unmoved_orb,
@ -89,9 +89,9 @@ namespace game_config
tod_bright,
tod_dark,
///@todo de-hardcode this
checked_menu = "buttons/checkbox-pressed.png",
unchecked_menu = "buttons/checkbox.png",
wml_menu = "buttons/WML-custom.png",
checked_menu = n_token::t_token( "buttons/checkbox-pressed.png"),
unchecked_menu = n_token::t_token( "buttons/checkbox.png"),
wml_menu = n_token::t_token( "buttons/WML-custom.png"),
level,
ellipsis,
missing;
@ -113,7 +113,7 @@ namespace game_config
std::string foot_teleport_enter;
std::string foot_teleport_exit;
std::map<std::string, color_range > team_rgb_range;
t_team_rgb_range team_rgb_range;
std::map<std::string, t_string > team_rgb_name;
std::map<std::string, std::vector<Uint32> > team_rgb_colors;
@ -179,33 +179,33 @@ namespace game_config
if(const config &i = v.child("images")){
using namespace game_config::images;
game_title = i["game_title"].str();
game_title = i["game_title"].token();
moved_orb = i["moved_orb"].str();
unmoved_orb = i["unmoved_orb"].str();
partmoved_orb = i["partmoved_orb"].str();
enemy_orb = i["enemy_orb"].str();
ally_orb = i["ally_orb"].str();
energy = i["energy"].str();
moved_orb = i["moved_orb"].token();
unmoved_orb = i["unmoved_orb"].token();
partmoved_orb = i["partmoved_orb"].token();
enemy_orb = i["enemy_orb"].token();
ally_orb = i["ally_orb"].token();
energy = i["energy"].token();
flag = i["flag"].str();
flag_icon = i["flag_icon"].str();
flag = i["flag"].token();
flag_icon = i["flag_icon"].token();
terrain_mask = i["terrain_mask"].str();
grid_top = i["grid_top"].str();
grid_bottom = i["grid_bottom"].str();
mouseover = i["mouseover"].str();
selected = i["selected"].str();
editor_brush = i["editor_brush"].str();
unreachable = i["unreachable"].str();
linger = i["linger"].str();
terrain_mask = i["terrain_mask"].token();
grid_top = i["grid_top"].token();
grid_bottom = i["grid_bottom"].token();
mouseover = i["mouseover"].token();
selected = i["selected"].token();
editor_brush = i["editor_brush"].token();
unreachable = i["unreachable"].token();
linger = i["linger"].token();
observer = i["observer"].str();
tod_bright = i["tod_bright"].str();
tod_dark = i["tod_dark"].str();
level = i["level"].str();
ellipsis = i["ellipsis"].str();
missing = i["missing"].str();
observer = i["observer"].token();
tod_bright = i["tod_bright"].token();
tod_dark = i["tod_dark"].token();
level = i["level"].token();
ellipsis = i["ellipsis"].token();
missing = i["missing"].token();
} // images
hp_bar_scaling = v["hp_bar_scaling"].to_double(0.666);
@ -246,17 +246,17 @@ namespace game_config
void add_color_info(const config &v)
{
foreach (const config &teamC, v.child_range("color_range"))
{
foreach (const config &teamC, v.child_range("color_range")) {
const config::attribute_value *a1 = teamC.get("id"),
*a2 = teamC.get("rgb");
if (!a1 || !a2) continue;
std::string id = *a1;
std::string const & id = *a1;
config::t_token const & idt = *a1;
std::vector<Uint32> temp = string2rgb(*a2);
team_rgb_range.insert(std::make_pair(id,color_range(temp)));
team_rgb_name[id] = teamC["name"];
//generate palette of same name;
std::vector<Uint32> tp = palette(team_rgb_range[id]);
std::vector<Uint32> tp = palette(team_rgb_range[idt]);
if (tp.empty()) continue;
team_rgb_colors.insert(std::make_pair(id,tp));
//if this is being used, output log of palette for artists use.
@ -289,9 +289,9 @@ namespace game_config
}
}
const color_range& color_info(const std::string& name)
const color_range& color_info(const n_token::t_token& name)
{
std::map<std::string, color_range>::const_iterator i = team_rgb_range.find(name);
t_team_rgb_range::const_iterator i = team_rgb_range.find(name);
if(i == team_rgb_range.end()) {
try {
team_rgb_range.insert(std::make_pair(name,color_range(string2rgb(name))));

View file

@ -70,7 +70,7 @@ namespace game_config
default_defeat_music;
namespace images {
extern std::string game_title,
extern n_token::t_token game_title,
// orbs and hp/xp bar
moved_orb,
unmoved_orb,
@ -116,7 +116,8 @@ namespace game_config
extern std::vector<std::string> foot_speed_prefix;
extern std::string foot_teleport_enter, foot_teleport_exit;
extern std::map<std::string, color_range> team_rgb_range;
typedef boost::unordered_map<n_token::t_token, color_range> t_team_rgb_range;
extern t_team_rgb_range team_rgb_range;
extern std::map<std::string, t_string> team_rgb_name;
extern std::map<std::string, std::vector<Uint32> > team_rgb_colors;
@ -142,7 +143,7 @@ namespace game_config
void add_color_info(const config& v);
const std::vector<Uint32>& tc_info(const std::string& name);
const color_range& color_info(const std::string& name);
const color_range& color_info(const n_token::t_token& name);
/**
* Return a color corresponding to the value val

View file

@ -90,11 +90,11 @@ game_display::game_display(unit_map& units, CVideo& video, const gamemap& map,
// Inits the flag list and the team colors used by ~TC
flags_.reserve(teams_.size());
std::vector<std::string> side_colors;
std::vector<config::t_token> side_colors;
side_colors.reserve(teams_.size());
for(size_t i = 0; i != teams_.size(); ++i) {
std::string side_color = team::get_side_color_index(i+1);
config::t_token side_color = team::get_side_color_index(i+1);
side_colors.push_back(side_color);
std::string flag = teams_[i].flag();
std::string old_rgb = game_config::flag_rgb;

View file

@ -118,17 +118,17 @@ image::bool_cache in_hex_info_;
// const int cache_version_ = 0;
std::map<std::string,bool> image_existence_map;
boost::unordered_map<n_token::t_token,bool> image_existence_map;
// directories where we already cached file existence
std::set<std::string> precached_dirs;
boost::unordered_set<n_token::t_token> precached_dirs;
std::map<surface, surface> reversed_images_;
boost::unordered_map<surface, surface> reversed_images_;
int red_adjust = 0, green_adjust = 0, blue_adjust = 0;
/** List of colors used by the TC image modification */
std::vector<std::string> team_colors;
std::vector<n_token::t_token> team_colors;
int zoom = image::tile_size;
int cached_zoom = 0;
@ -172,8 +172,8 @@ void flush_cache()
void locator::init_index()
{
std::map<value, int>& finder = locator_finder[hash_value(val_)];
std::map<value, int>::iterator i = finder.find(val_);
boost::unordered_map<value, int>& finder = locator_finder[hash_value(val_)];
boost::unordered_map<value, int>::iterator i = finder.find(val_);
if(i == finder.end()) {
index_ = last_index_++;
@ -185,7 +185,7 @@ void locator::init_index()
void locator::parse_arguments()
{
std::string& fn = val_.filename_;
std::string const & fn = static_cast<std::string const &>(val_.filename_);
if(fn.empty()) {
return;
}
@ -193,30 +193,24 @@ void locator::parse_arguments()
if(markup_field != std::string::npos) {
val_.type_ = SUB_FILE;
val_.modifications_ = fn.substr(markup_field, fn.size() - markup_field);
fn = fn.substr(0,markup_field);
val_.modifications_ = n_token::t_token(fn.substr(markup_field, fn.size() - markup_field));
val_.filename_ = n_token::t_token( fn.substr(0,markup_field) );
}
}
locator::locator() :
index_(-1),
val_()
{
}
locator::locator() : index_(-1), val_() {}
locator::locator(const locator &a, const std::string& mods):
index_(-1),
val_(a.val_)
{
locator::locator(const locator &a, const n_token::t_token& mods):
index_(-1), val_(a.val_) {
if(!mods.empty()){
val_.modifications_ += mods;
val_.type_=SUB_FILE;
init_index();
val_.modifications_ = config::t_token( val_.modifications_ + mods );
val_.type_=SUB_FILE;
init_index();
}
else index_=a.index_;
else index_ = a.index_;
}
locator::locator(const char *filename) :
locator::locator(const n_token::t_token &filename) :
index_(-1),
val_(filename)
{
@ -224,39 +218,50 @@ locator::locator(const char *filename) :
init_index();
}
locator::locator(const std::string &filename) :
index_(-1),
val_(filename)
{
locator::locator(const n_token::t_token &filename, const n_token::t_token& modifications) :
index_(-1), val_(filename, modifications) {
init_index();
}
locator::locator(const n_token::t_token &filename, const map_location &loc,
int center_x, int center_y, const n_token::t_token& modifications) :
index_(-1), val_(filename, modifications, loc, center_x, center_y) {
init_index();
}
locator::locator(const char *filename) :
index_(-1), val_(n_token::t_token( filename )) {
parse_arguments();
init_index();
}
locator::locator(const std::string & filename) :
index_(-1), val_(n_token::t_token( filename )) {
parse_arguments();
init_index();
}
locator::locator(const std::string &filename, const std::string& modifications) :
index_(-1),
val_(filename, modifications)
{
index_(-1), val_(n_token::t_token( filename), n_token::t_token( modifications)) {
init_index();
}
locator::locator(const std::string &filename, const map_location &loc,
int center_x, int center_y, const std::string& modifications) :
index_(-1),
val_(filename, loc, center_x, center_y, modifications)
{
int center_x, int center_y, const std::string& modifications) :
index_(-1), val_(n_token::t_token( filename), n_token::t_token( modifications), loc, center_x, center_y) {
init_index();
}
locator::locator(const config::t_token &filename, const config::t_token& modifications, const map_location &loc,
int center_x, int center_y) :
index_(-1),
val_(filename, loc, center_x, center_y, modifications)
{
init_index();
}
// locator::locator(const config::t_token &filename, const config::t_token& modifications, const map_location &loc,
// int center_x, int center_y) :
// index_(-1), val_(filename, modifications, loc, center_x, center_y) {
// init_index();
// }
locator& locator::operator=(const locator &a)
{
locator& locator::operator=(const locator &a) {
index_ = a.index_;
val_ = a.val_;
@ -264,48 +269,29 @@ locator& locator::operator=(const locator &a)
}
locator::value::value(const locator::value& a) :
type_(a.type_), filename_(a.filename_), loc_(a.loc_),
modifications_(a.modifications_),
center_x_(a.center_x_), center_y_(a.center_y_)
{
}
type_(a.type_), filename_(a.filename_), loc_(a.loc_), modifications_(a.modifications_)
, center_x_(a.center_x_), center_y_(a.center_y_) { }
locator::value::value() :
type_(NONE), filename_(), loc_(), modifications_(),
center_x_(0), center_y_(0)
type_(NONE), filename_(), loc_(), modifications_(), center_x_(0), center_y_(0) { }
{}
locator::value::value(const n_token::t_token& filename) :
type_(FILE), filename_(filename), loc_(), modifications_(), center_x_(0), center_y_(0) { }
locator::value::value(const char *filename) :
type_(FILE), filename_(filename), loc_(), modifications_(),
center_x_(0), center_y_(0)
// locator::value::value(const n_token::t_token& filename, const n_token::t_token& modifications) :
// type_(SUB_FILE), filename_(filename), loc_(), modifications_(modifications),
// center_x_(0), center_y_(0)
{
}
// {
// }
locator::value::value(const std::string& filename) :
type_(FILE), filename_(filename), loc_(), modifications_(),
center_x_(0), center_y_(0)
{
}
locator::value::value(const std::string& filename, const std::string& modifications) :
type_(SUB_FILE), filename_(filename), loc_(), modifications_(modifications),
center_x_(0), center_y_(0)
{
}
locator::value::value(const std::string& filename, const map_location& loc, int center_x, int center_y, const std::string& modifications) :
type_(SUB_FILE), filename_(filename), loc_(loc), modifications_(modifications), center_x_(center_x), center_y_(center_y)
{
}
// locator::value::value(const n_token::t_token& filename, const map_location& loc, int center_x, int center_y, const n_token::t_token& modifications) :
// type_(SUB_FILE), filename_(filename), loc_(loc), modifications_(modifications), center_x_(center_x), center_y_(center_y)
// {
// }
locator::value::value(const config::t_token& filename, const config::t_token& modifications, const map_location& loc, int center_x, int center_y) :
type_(SUB_FILE), filename_(static_cast<std::string const &>(filename)), loc_(loc), modifications_(static_cast<std::string const &>(modifications)), center_x_(center_x), center_y_(center_y)
{
}
type_(SUB_FILE), filename_(filename), loc_(loc), modifications_(modifications), center_x_(center_x), center_y_(center_y) { }
bool locator::value::operator==(const value& a) const
{
@ -473,7 +459,7 @@ surface locator::load_image_file() const
if (res.null() && !val_.filename_.empty()) {
ERR_DP << "could not open image '" << val_.filename_ << "'\n";
if (game_config::debug && val_.filename_ != game_config::images::missing)
return get_image(game_config::images::missing, UNSCALED);
return get_image(locator(game_config::images::missing), UNSCALED);
}
return res;
@ -481,7 +467,7 @@ surface locator::load_image_file() const
surface locator::load_image_sub_file() const
{
surface surf = get_image(val_.filename_, UNSCALED);
surface surf = get_image(locator( val_.filename_ ) , UNSCALED);
if(surf == NULL)
return NULL;
@ -586,7 +572,7 @@ void color_adjustment_resetter::reset()
set_color_adjustment(r_, g_, b_);
}
void set_team_colors(const std::vector<std::string>* colors)
void set_team_colors(const std::vector<n_token::t_token>* colors)
{
if (colors == NULL)
team_colors.clear();
@ -595,7 +581,7 @@ void set_team_colors(const std::vector<std::string>* colors)
}
}
const std::vector<std::string>& get_team_colors()
const std::vector<n_token::t_token>& get_team_colors()
{
return team_colors;
}
@ -835,7 +821,7 @@ surface reverse_image(const surface& surf)
return surface(NULL);
}
const std::map<surface,surface>::iterator itor = reversed_images_.find(surf);
const boost::unordered_map<surface,surface>::iterator itor = reversed_images_.find(surf);
if(itor != reversed_images_.end()) {
// sdl_add_ref(itor->second);
return itor->second;
@ -859,7 +845,7 @@ bool exists(const image::locator& i_locator)
return false;
// The insertion will fail if there is already an element in the cache
std::pair< std::map< std::string, bool >::iterator, bool >
std::pair< boost::unordered_map< n_token::t_token, bool >::iterator, bool >
it = image_existence_map.insert(std::make_pair(i_locator.get_filename(), false));
bool &cache = it.first->second;
if (it.second)
@ -867,9 +853,9 @@ bool exists(const image::locator& i_locator)
return cache;
}
static void precache_file_existence_internal(const std::string& dir, const std::string& subdir)
static void precache_file_existence_internal(const n_token::t_token& dir, const n_token::t_token& subdir)
{
const std::string checked_dir = dir + "/" + subdir;
const n_token::t_token checked_dir = n_token::t_token(static_cast<std::string const &>(dir) + "/" + static_cast<std::string const &>(subdir));
if (precached_dirs.find(checked_dir) != precached_dirs.end())
return;
precached_dirs.insert(checked_dir);
@ -881,16 +867,16 @@ static void precache_file_existence_internal(const std::string& dir, const std::
for(std::vector<std::string>::const_iterator f = files_found.begin();
f != files_found.end(); ++f) {
image_existence_map[subdir + *f] = true;
image_existence_map[n_token::t_token(subdir + *f)] = true;
}
for(std::vector<std::string>::const_iterator d = dirs_found.begin();
d != dirs_found.end(); ++d) {
precache_file_existence_internal(dir, subdir + *d + "/");
precache_file_existence_internal(dir, n_token::t_token( subdir + *d + "/" ));
}
}
void precache_file_existence(const std::string& subdir)
void precache_file_existence(const n_token::t_token& subdir)
{
const std::vector<std::string>& paths = get_binary_paths("images");
@ -898,13 +884,13 @@ void precache_file_existence(const std::string& subdir)
p != paths.end(); ++p) {
const std::string dir = *p + "/" + subdir;
precache_file_existence_internal(*p, subdir);
precache_file_existence_internal(n_token::t_token( *p ), subdir);
}
}
bool precached_file_exists(const std::string& file)
bool precached_file_exists(const n_token::t_token& file)
{
std::map<std::string, bool>::const_iterator b = image_existence_map.find(file);
boost::unordered_map<n_token::t_token, bool>::const_iterator b = image_existence_map.find(file);
if (b != image_existence_map.end())
return b->second;
else

View file

@ -49,19 +49,19 @@ namespace image {
struct value {
value();
value(const value &a);
value(const char *filename);
value(const std::string& filename);
value(const std::string& filename, const std::string& modifications);
value(const std::string& filename, const map_location& loc, int center_x, int center_y, const std::string& modifications);
value(const n_token::t_token& filename, const n_token::t_token& modifications, const map_location& loc, int center_x, int center_y);
explicit value(const n_token::t_token& filename);
// value(const n_token::t_token& filename, const n_token::t_token& modifications);
// value(const n_token::t_token& filename, const map_location& loc, int center_x, int center_y, const n_token::t_token& modifications);
value(const n_token::t_token& filename, const n_token::t_token& modifications
, const map_location& loc = map_location::null_location, int center_x=0, int center_y=0);
bool operator==(const value& a) const;
bool operator<(const value& a) const;
type type_;
std::string filename_;
n_token::t_token filename_;
map_location loc_;
std::string modifications_;
n_token::t_token modifications_;
int center_x_;
int center_y_;
};
@ -70,37 +70,37 @@ namespace image {
public:
/**
* @todo replace this with std::unordered_map<value, int> or boost::unordered_map<value, int>
* boost::unordered_map can almost just be dropped in as boost::hash<T>(T val) will return hash_value(val), but it
* requires boost 1.35 (preferably 1.36 or later)
*
**/
typedef std::map<size_t, std::map<value, int> > locator_finder_t;
typedef boost::unordered_map<size_t, boost::unordered_map<value, int> > locator_finder_t;
// Constructing locators is somewhat slow, accessing image
// through locators is fast. The idea is that calling functions
// should store locators, and not strings to construct locators
// (the second will work, of course, but will be slower)
locator();
locator(const locator &a, const std::string &mods ="");
locator();
locator(const locator &a, const n_token::t_token &mods = z_empty);
// locator(const locator &a, const std::string &mods ="");
locator(const n_token::t_token& filename);
locator(const n_token::t_token& filename, const n_token::t_token& modifications);
locator(const n_token::t_token& filename, const map_location& loc, int center_x, int center_y
, const n_token::t_token& modifications=z_empty);
locator(const char *filename);
locator(const std::string& filename);
locator(const std::string& filename, const std::string& modifications);
locator(const std::string& filename, const map_location& loc, int center_x, int center_y, const std::string& modifications="");
locator(const n_token::t_token& filename, const n_token::t_token& modifications = z_empty
, const map_location& loc = map_location::null_location, int center_x = 0 , int center_y =0 );
locator& operator=(const locator &a);
bool operator==(const locator &a) const { return index_ == a.index_; }
bool operator!=(const locator &a) const { return index_ != a.index_; }
bool operator<(const locator &a) const { return index_ < a.index_; }
const std::string &get_filename() const { return val_.filename_; }
const n_token::t_token &get_filename() const { return val_.filename_; }
const map_location& get_loc() const { return val_.loc_ ; }
int get_center_x() const { return val_.center_x_; }
int get_center_y() const { return val_.center_y_; }
const std::string& get_modifications() const {return val_.modifications_;}
const n_token::t_token& get_modifications() const {return val_.modifications_;}
type get_type() const { return val_.type_; };
// const int get_index() const { return index_; };
@ -144,7 +144,7 @@ namespace image {
typedef cache_type<surface> image_cache;
typedef cache_type<bool> bool_cache;
typedef std::map<t_translation::t_terrain, surface> mini_terrain_cache_map;
typedef boost::unordered_map<t_translation::t_terrain, surface> mini_terrain_cache_map;
extern mini_terrain_cache_map mini_terrain_cache;
extern mini_terrain_cache_map mini_fogged_terrain_cache;
@ -176,9 +176,9 @@ namespace image {
///set the team colors used by the TC image modification
///use a vector with one string for each team
///using NULL will reset to default TC
void set_team_colors(const std::vector<std::string>* colors = NULL);
void set_team_colors(const std::vector<n_token::t_token>* colors = NULL);
const std::vector<std::string>& get_team_colors();
const std::vector<n_token::t_token>& get_team_colors();
///sets the pixel format used by the images. Is called every time the
///video mode changes. Invalidates all images.
@ -218,8 +218,8 @@ namespace image {
bool exists(const locator& i_locator);
/// precache the existence of files in the subdir (ex: "terrain/")
void precache_file_existence(const std::string& subdir = "");
bool precached_file_exists(const std::string& file);
void precache_file_existence(const n_token::t_token& subdir = z_empty);
bool precached_file_exists(const n_token::t_token& file);
}
#endif

View file

@ -401,7 +401,7 @@ REGISTER_MOD_PARSER(TC, args)
std::map<Uint32, Uint32> rc_map;
try {
color_range const& new_color =
game_config::color_info(team_color);
game_config::color_info(n_token::t_token(team_color));
std::vector<Uint32> const& old_color =
game_config::tc_info(params[1]);
@ -422,7 +422,7 @@ REGISTER_MOD_PARSER(TC, args)
// Team-color-based color range selection and recoloring
REGISTER_MOD_PARSER(RC, args)
{
const std::vector<std::string> recolor_params = utils::split(args,'>');
const std::vector<config::t_token> recolor_params = utils::split_token(n_token::t_token(args), '>');
if(recolor_params.size()>1){
//

View file

@ -270,7 +270,7 @@ void wait::join_game(bool observe)
}
int color = side_num;
const std::string color_str = (*side_choice)["color"];
const config::t_token color_str = (*side_choice)["color"];
if (!color_str.empty())
color = game_config::color_info(color_str).index() - 1;
@ -485,7 +485,7 @@ void wait::generate_menu()
if (RCcolor.empty())
RCcolor = sd["side"].str();
leader_image = utg.image() + std::string("~RC(") + std::string(utg.flag_rgb() + ">" + RCcolor + ")");
leader_image = static_cast<std::string const &>(utg.image()) + "~RC(" + static_cast<std::string const &>(utg.flag_rgb()) + ">" + RCcolor + ")";
#endif
} else {
leader_image = leader_list_manager::random_enemy_picture;

View file

@ -117,9 +117,9 @@ void team::team_info::read(const config &cfg)
side = cfg["side"].to_int(1);
if(cfg.has_attribute("color")) {
color = cfg["color"].str();
color = cfg["color"].token();
} else {
color = cfg["side"].str();
color = cfg["side"].token();
}
// If arel starting new scenario overide settings from [ai] tags
@ -158,7 +158,7 @@ void team::team_info::read(const config &cfg)
}
const std::string temp_rgb_str = cfg["team_rgb"];
std::map<std::string, color_range>::iterator global_rgb = game_config::team_rgb_range.find(cfg["side"]);
game_config::t_team_rgb_range::const_iterator global_rgb = game_config::team_rgb_range.find(cfg["side"]);
if(!temp_rgb_str.empty()){
std::vector<Uint32> temp_rgb = string2rgb(temp_rgb_str);
@ -765,8 +765,8 @@ bool team::shroud_map::copy_from(const std::vector<const shroud_map*>& maps)
std::map<int, color_range> team::team_color_range_;
const color_range team::get_side_color_range(int side){
std::string index = get_side_color_index(side);
std::map<std::string, color_range>::iterator gp=game_config::team_rgb_range.find(index);
config::t_token index = get_side_color_index(side);
game_config::t_team_rgb_range::const_iterator gp=game_config::team_rgb_range.find(index);
if(gp != game_config::team_rgb_range.end()){
return(gp->second);
@ -787,17 +787,17 @@ SDL_Color team::get_minimap_color(int side)
return int_to_color(get_side_color_range(side).rep());
}
std::string team::get_side_color_index(int side)
config::t_token team::get_side_color_index(int side)
{
size_t index = size_t(side-1);
if(teams != NULL && index < teams->size()) {
const std::string side_map = (*teams)[index].map_color_to();
const config::t_token &side_map = (*teams)[index].map_color_to();
if(!side_map.empty()) {
return side_map;
}
}
return str_cast(side);
return config::t_token(str_cast(side));
}
std::string team::get_side_highlight(int side)

View file

@ -105,7 +105,7 @@ public:
std::string music;
std::string color;
config::t_token color;
int side;
bool persistent;
@ -251,7 +251,7 @@ public:
bool auto_shroud_updates() const { return auto_shroud_updates_; }
void set_auto_shroud_updates(bool value) { auto_shroud_updates_ = value; }
bool get_disallow_observers() const {return info_.disallow_observers; };
std::string map_color_to() const { return info_.color; };
config::t_token map_color_to() const { return info_.color; };
bool no_leader() const { return info_.no_leader; }
void have_leader(bool value=true) { info_.no_leader = !value; }
bool hidden() const { return info_.hidden; }
@ -267,7 +267,7 @@ public:
static Uint32 get_side_rgb_min(int side) { return(get_side_color_range(side).min()); }
static SDL_Color get_side_color(int side);
static SDL_Color get_minimap_color(int side);
static std::string get_side_color_index(int side);
static config::t_token get_side_color_index(int side);
static std::string get_side_highlight(int side);
void log_recruitable();

View file

@ -175,7 +175,7 @@ terrain_type::terrain_type(const terrain_type& base, const terrain_type& overlay
minimap_image_(base.minimap_image_),
minimap_image_overlay_(overlay.minimap_image_),
editor_image_(overlay.editor_image_),
id_(base.id_+"^"+overlay.id_),
id_(static_cast<std::string const &>(base.id_)+"^"+static_cast<std::string const &>(overlay.id_) ),
name_(overlay.name_),
editor_name_(overlay.editor_name_),
description_(overlay.description_),

View file

@ -71,10 +71,10 @@ private:
*/
void set_up_team_colors()
{
std::vector<std::string> tc;
std::vector<config::t_token> tc;
tc.push_back("red");
tc.push_back("blue");
tc.push_back(config::t_token("red"));
tc.push_back(config::t_token("blue"));
image::set_team_colors(&tc);
}
@ -179,7 +179,7 @@ BOOST_AUTO_TEST_CASE(test_tc_modification_decoding)
const std::vector<Uint32>& old_color = game_config::tc_info("blue");
// The first team color is red
const color_range& new_color = game_config::color_info("red");
const color_range& new_color = game_config::color_info(config::t_token("red"));
std::map<Uint32, Uint32> expected = recolor_range(new_color, old_color);
BOOST_CHECK(expected == mod->map());
@ -212,7 +212,7 @@ BOOST_AUTO_TEST_CASE(test_rc_modification_decoding)
BOOST_REQUIRE(mod != NULL);
const std::vector<Uint32>& old_color = game_config::tc_info("red");
const color_range& new_color = game_config::color_info("blue");
const color_range& new_color = game_config::color_info(config::t_token("blue"));
std::map<Uint32, Uint32> expected = recolor_range(new_color, old_color);
BOOST_CHECK(expected == mod->map());

View file

@ -74,6 +74,12 @@ public:
return out << static_cast<std::string const &>(a); }
};
inline std::string operator+(const n_token::t_token &a, const std::string &b) { return static_cast<std::string const &>(a) + b; }
inline std::string operator+(const std::string &a, const n_token::t_token &b) { return a + static_cast<std::string const &>(b); }
inline std::string operator+(const n_token::t_token &a, const n_token::t_token &b) {
return static_cast<std::string const &>(a) + static_cast<std::string const &>(b); }
}//end namepace
#endif

View file

@ -2018,7 +2018,7 @@ void unit::redraw_unit()
params.image= static_cast<std::string const &>(absolute_image());
if(get_state(STATE_PETRIFIED)) params.image_mod +="~GS()";
if(get_state(STATE_PETRIFIED)) params.image_mod = config::t_token(params.image_mod + "~GS()" );
params.primary_frame = t_true;
const frame_parameters adjusted_params = anim_->get_current_params(params);
@ -2106,7 +2106,7 @@ void unit::redraw_unit()
static const image::locator unmoved_orb(game_config::images::unmoved_orb);
static const image::locator partmoved_orb(game_config::images::partmoved_orb);
const std::string* energy_file = &game_config::images::energy;
const config::t_token* energy_file = &game_config::images::energy;
if(size_t(side()) != disp.viewing_team()+1) {
if(disp.team_valid() &&
@ -3094,7 +3094,7 @@ temporary_unit_mover::~temporary_unit_mover()
std::string unit::TC_image_mods() const{
std::stringstream modifier;
if(static_cast< std::string const &>(flag_rgb_).size()){
if(!flag_rgb_.empty()){
modifier << "~RC("<< flag_rgb_ << ">" << team::get_side_color_index(side()) << ")";
}
return modifier.str();

View file

@ -531,10 +531,10 @@ void unit_frame::redraw(const int frame_time,bool first_time,const map_location
}
image::locator image_loc;
if(direction != map_location::NORTH && direction != map_location::SOUTH) {
image_loc = image::locator(current_data.image_diagonal,current_data.image_mod);
image_loc = image::locator(current_data.image_diagonal, n_token::t_token(current_data.image_mod)); //todo remove
}
if(image_loc.is_void() || image_loc.get_filename() == "") { // invalid diag image, or not diagonal
image_loc = image::locator(current_data.image,current_data.image_mod);
image_loc = image::locator(current_data.image,n_token::t_token(current_data.image_mod)); //rmove extra contructor
}
surface image;
@ -634,10 +634,10 @@ std::set<map_location> unit_frame::get_overlaped_hex(const int frame_time,const
image::locator image_loc;
if(direction != map_location::NORTH && direction != map_location::SOUTH) {
image_loc = image::locator(current_data.image_diagonal,current_data.image_mod);
image_loc = image::locator(current_data.image_diagonal, n_token::t_token(current_data.image_mod));
}
if(image_loc.is_void() || image_loc.get_filename() == "") { // invalid diag image, or not diagonal
image_loc = image::locator(current_data.image,current_data.image_mod);
image_loc = image::locator(current_data.image, n_token::t_token(current_data.image_mod));
}
// we always invalidate our own hex because we need to be called at redraw time even