commit
84c7b2e2ad
14 changed files with 60 additions and 27 deletions
|
@ -184,7 +184,7 @@ bool ai_default_recruitment_stage::recruit_usage(const std::string& usage)
|
|||
LOG_AI << "recruiting '" << usage << "'\n";
|
||||
|
||||
//make sure id, usage and cost are known for the coming evaluation of unit types
|
||||
unit_types.build_all(unit_type::HELP_INDEX);
|
||||
unit_types.build_all(unit_type::HELP_INDEXED);
|
||||
|
||||
std::vector<std::string> options;
|
||||
bool found = false;
|
||||
|
|
|
@ -318,7 +318,7 @@ bool recruitment_phase::recruit_usage(const std::string& usage)
|
|||
LOG_AI_TESTING_AI_DEFAULT << "recruiting '" << usage << "'\n";
|
||||
|
||||
//make sure id, usage and cost are known for the coming evaluation of unit types
|
||||
unit_types.build_all(unit_type::HELP_INDEX);
|
||||
unit_types.build_all(unit_type::HELP_INDEXED);
|
||||
|
||||
std::vector<std::string> options;
|
||||
bool found = false;
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
|
||||
#include <boost/foreach.hpp>
|
||||
#include <boost/algorithm/string/replace.hpp>
|
||||
#include <boost/iostreams/filter/gzip.hpp>
|
||||
|
||||
static lg::log_domain log_cache("cache");
|
||||
#define ERR_CACHE LOG_STREAM(err, log_cache)
|
||||
|
@ -217,6 +218,9 @@ namespace game_config {
|
|||
ERR_CACHE << "cache " << fname << extension << " is corrupt. Loading from files: "<< e.message<<"\n";
|
||||
} catch(io_exception&) {
|
||||
ERR_CACHE << "error reading cache " << fname << extension << ". Loading from files\n";
|
||||
} catch (boost::iostreams::gzip_error& e) {
|
||||
//read_file -> ... -> read_gz can throw this exeption.
|
||||
ERR_CACHE << "cache " << fname << extension << " is corrupt. Error code: " << e.error() << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -360,7 +360,7 @@ void manager::init() const
|
|||
get_files_in_dir(path, &files, NULL, ENTIRE_FILE_PATH);
|
||||
BOOST_FOREACH(const std::string& file, files)
|
||||
if(file.substr(file.length() - 4) == ".ttf" || file.substr(file.length() - 4) == ".ttc")
|
||||
AddFontResource(file.c_str());
|
||||
AddFontResourceA(file.c_str());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
@ -377,7 +377,7 @@ void manager::deinit() const
|
|||
get_files_in_dir(path, &files, NULL, ENTIRE_FILE_PATH);
|
||||
BOOST_FOREACH(const std::string& file, files)
|
||||
if(file.substr(file.length() - 4) == ".ttf" || file.substr(file.length() - 4) == ".ttc")
|
||||
RemoveFontResource(file.c_str());
|
||||
RemoveFontResourceA(file.c_str());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -1033,7 +1033,7 @@ formula::formula(const std::string& str, function_symbol_table* symbols) :
|
|||
|
||||
tokens.push_back( get_token(i1,i2) );
|
||||
|
||||
TOKEN_TYPE current_type = tokens.back().type;
|
||||
formula_tokenizer::TOKEN_TYPE current_type = tokens.back().type;
|
||||
|
||||
if(current_type == TOKEN_WHITESPACE) {
|
||||
tokens.pop_back();
|
||||
|
|
|
@ -20,6 +20,7 @@ namespace formula_tokenizer
|
|||
|
||||
typedef std::string::const_iterator iterator;
|
||||
|
||||
/// TOKEN_TYPE is already defined in a Winnt.h (a windows header wich is included under some conditions.)
|
||||
enum TOKEN_TYPE { TOKEN_OPERATOR, TOKEN_STRING_LITERAL,
|
||||
TOKEN_IDENTIFIER, TOKEN_INTEGER, TOKEN_DECIMAL,
|
||||
TOKEN_LPARENS, TOKEN_RPARENS,
|
||||
|
|
|
@ -301,7 +301,10 @@ wml_menu_item & wmi_container::get_item(const std::string& id)
|
|||
{
|
||||
// Try to insert a dummy value. This combines looking for an existing
|
||||
// entry with insertion.
|
||||
map_t::iterator add_it = wml_menu_items_.insert(map_t::value_type(id, NULL)).first;
|
||||
|
||||
// the static cast fixes http://connect.microsoft.com/VisualStudio/feedback/details/520043/
|
||||
// c++11's nullptr would be a better solution as soon as we support it.
|
||||
map_t::iterator add_it = wml_menu_items_.insert(map_t::value_type(id, static_cast<wml_menu_item *>(NULL))).first;
|
||||
|
||||
// If we ended up with a dummy value, create an entry for it.
|
||||
if ( add_it->second == NULL )
|
||||
|
|
|
@ -110,7 +110,7 @@ void tunit_create::pre_show(CVideo& /*video*/, twindow& window)
|
|||
FOREACH(const AUTO& i, unit_types.types())
|
||||
{
|
||||
// Make sure this unit type is built with the data we need.
|
||||
unit_types.build_unit_type(i.second, unit_type::HELP_INDEX);
|
||||
unit_types.build_unit_type(i.second, unit_type::HELP_INDEXED);
|
||||
|
||||
// And so we map an unit_type id to a list subscript. Ugh.
|
||||
type_ids_.push_back(i.first);
|
||||
|
|
10
src/help.cpp
10
src/help.cpp
|
@ -1358,7 +1358,7 @@ public:
|
|||
|
||||
BOOST_FOREACH(const std::string &adv, adv_units)
|
||||
{
|
||||
const unit_type *type = unit_types.find(adv, unit_type::HELP_INDEX);
|
||||
const unit_type *type = unit_types.find(adv, unit_type::HELP_INDEXED);
|
||||
if (!type || type->hide_help()) continue;
|
||||
|
||||
if (first) {
|
||||
|
@ -1387,7 +1387,7 @@ public:
|
|||
}
|
||||
|
||||
const unit_type* parent = variation_.empty() ? &type_ :
|
||||
unit_types.find(type_.id(), unit_type::HELP_INDEX);
|
||||
unit_types.find(type_.id(), unit_type::HELP_INDEXED);
|
||||
if (!variation_.empty()) {
|
||||
ss << _("Base unit: ") << "<ref>dst='" << ".." << unit_prefix + type_.id()
|
||||
<< "' text='" << escape(parent->type_name()) << "'</ref>\n";
|
||||
|
@ -1398,7 +1398,7 @@ public:
|
|||
ss << _("Base units: ");
|
||||
first = false;
|
||||
}
|
||||
const unit_type* base_type = unit_types.find(base_id, unit_type::HELP_INDEX);
|
||||
const unit_type* base_type = unit_types.find(base_id, unit_type::HELP_INDEXED);
|
||||
const std::string section_prefix = base_type->variations().empty() ? "" : "..";
|
||||
ss << "<ref>dst='" << section_prefix << unit_prefix + base_id
|
||||
<< "' text='" << escape(base_type->type_name()) << "'</ref>\n";
|
||||
|
@ -1744,7 +1744,7 @@ std::string make_unit_link(const std::string& type_id)
|
|||
{
|
||||
std::string link;
|
||||
|
||||
const unit_type *type = unit_types.find(type_id, unit_type::HELP_INDEX);
|
||||
const unit_type *type = unit_types.find(type_id, unit_type::HELP_INDEXED);
|
||||
if (!type) {
|
||||
std::cerr << "Unknown unit type : " << type_id << "\n";
|
||||
// don't return an hyperlink (no page)
|
||||
|
@ -3297,7 +3297,7 @@ void show_help(display &disp, const section &toplevel_sec,
|
|||
|
||||
// Find all unit_types that have not been constructed yet and fill in the information
|
||||
// needed to create the help topics
|
||||
unit_types.build_all(unit_type::HELP_INDEX);
|
||||
unit_types.build_all(unit_type::HELP_INDEXED);
|
||||
|
||||
if (preferences::encountered_units().size() != size_t(last_num_encountered_units) ||
|
||||
preferences::encountered_terrains().size() != size_t(last_num_encountered_terrains) ||
|
||||
|
|
|
@ -148,7 +148,7 @@ static void wesnoth_setlocale(int category, std::string const &slocale,
|
|||
std::string win_locale(locale, 0, 2);
|
||||
#include "language_win32.ii"
|
||||
if(category == LC_MESSAGES) {
|
||||
SetEnvironmentVariable("LANG", win_locale.c_str());
|
||||
SetEnvironmentVariableA("LANG", win_locale.c_str());
|
||||
std::string env = "LANGUAGE=" + locale;
|
||||
_putenv(env.c_str());
|
||||
return;
|
||||
|
|
|
@ -926,14 +926,16 @@ namespace { // Helpers for create_unit()
|
|||
create_dlg.show(gui.video());
|
||||
|
||||
if(create_dlg.no_choice()) {
|
||||
return type_and_gender(NULL, unit_race::NUM_GENDERS);
|
||||
// the static cast fixes http://connect.microsoft.com/VisualStudio/feedback/details/520043/
|
||||
// c++11's nullptr would be a better solution as soon as we support it.
|
||||
return type_and_gender(static_cast<const unit_type *>(NULL), unit_race::NUM_GENDERS);
|
||||
}
|
||||
|
||||
const std::string& ut_id = create_dlg.choice();
|
||||
const unit_type *utp = unit_types.find(ut_id);
|
||||
if (!utp) {
|
||||
ERR_NG << "Create unit dialog returned nonexistent or unusable unit_type id '" << ut_id << "'.\n";
|
||||
return type_and_gender(NULL, unit_race::NUM_GENDERS);
|
||||
return type_and_gender(static_cast<const unit_type *>(NULL), unit_race::NUM_GENDERS);
|
||||
}
|
||||
const unit_type &ut = *utp;
|
||||
|
||||
|
@ -971,7 +973,7 @@ namespace { // Helpers for create_unit()
|
|||
std::stringstream row;
|
||||
|
||||
// Make sure the unit type was built for the data we need.
|
||||
unit_types.build_unit_type(i.second, unit_type::HELP_INDEX);
|
||||
unit_types.build_unit_type(i.second, unit_type::HELP_INDEXED);
|
||||
|
||||
row << i.second.race()->plural_name() << COLUMN_SEPARATOR;
|
||||
row << i.second.type_name() << COLUMN_SEPARATOR;
|
||||
|
@ -1025,7 +1027,7 @@ namespace { // Helpers for create_unit()
|
|||
unit_choices[choice]->genders().front());
|
||||
}
|
||||
else
|
||||
return type_and_gender(NULL, unit_race::NUM_GENDERS);
|
||||
return type_and_gender(static_cast<const unit_type *>(NULL), unit_race::NUM_GENDERS);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -392,23 +392,45 @@ void read_compressed(config &cfg, std::istream &file, abstract_validator * valid
|
|||
filter.push(decompressor());
|
||||
filter.push(file);
|
||||
|
||||
|
||||
#if (_MSC_VER >= 1500)
|
||||
// this seems to fix an msvc issue that causes crashes on a regular basis
|
||||
// this causes especialy gzip_error (or the coresponding bz2 error, maybe other erros too?) to be thrown here.
|
||||
// gzip_error will be thown in case of a invalid zip file
|
||||
// save_index_class::data expects that and config_cache::read_cache is also capable of catching.
|
||||
//
|
||||
// i(gfgtdf) still dont know how other compilers handle it.
|
||||
// especialy weather the catch for gzip_error in save_index_class::data is ever reached and when the exeption is thown.
|
||||
// and what happens when the code tries to read a corupt cache gz file.
|
||||
// note that parser(cfg, filter,validator)(); -> tokenizer::tokenizer can throw exeptions too (meaning this functions did already throw these exeptions before this patch).
|
||||
// also note that this doesn't fix the source of the currupted gz files wich is, that filtering_stream cannot create empty compressend gz files properly, see https://svn.boost.org/trac/boost/ticket/5237
|
||||
// filter.peek() might throw an exeption now.
|
||||
filter.exceptions(filter.exceptions() | std::ios_base::badbit);
|
||||
#endif
|
||||
/*
|
||||
* It sometimes seems the file is not empty but still no real data.
|
||||
* Filter that case here. It might be previous test is no longer required
|
||||
* but simply keep it.
|
||||
*/
|
||||
// at least on msvc filter.peek() != EOF does not imply filter.good() (without the line above)
|
||||
if(filter.peek() == EOF) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(!filter.good()) {
|
||||
LOG_CF << " filter.peek() != EOF but !filter.good(), this indicates a malformed gz stream.";
|
||||
}
|
||||
|
||||
parser(cfg, filter,validator)();
|
||||
}
|
||||
|
||||
/// might throw a std::ios_base::failure especially a gzip_error
|
||||
void read_gz(config &cfg, std::istream &file, abstract_validator * validator)
|
||||
{
|
||||
read_compressed<boost::iostreams::gzip_decompressor>(cfg, file, validator);
|
||||
}
|
||||
|
||||
/// might throw a std::ios_base::failure especially bzip2_error
|
||||
void read_bz2(config &cfg, std::istream &file, abstract_validator * validator)
|
||||
{
|
||||
read_compressed<boost::iostreams::bzip2_decompressor>(cfg, file, validator);
|
||||
|
|
|
@ -538,13 +538,13 @@ void unit_type::build_full(const movement_type_map &mv_types,
|
|||
}
|
||||
|
||||
/**
|
||||
* Partially load data into an empty unit_type (build to HELP_INDEX).
|
||||
* Partially load data into an empty unit_type (build to HELP_INDEXED).
|
||||
*/
|
||||
void unit_type::build_help_index(const movement_type_map &mv_types,
|
||||
const race_map &races, const config::const_child_itors &traits)
|
||||
{
|
||||
// Don't build twice.
|
||||
if ( HELP_INDEX <= build_status_ )
|
||||
if ( HELP_INDEXED <= build_status_ )
|
||||
return;
|
||||
// Make sure we are built to the preceding build level.
|
||||
build_created(mv_types, races, traits);
|
||||
|
@ -650,7 +650,7 @@ void unit_type::build_help_index(const movement_type_map &mv_types,
|
|||
|
||||
hide_help_= cfg_["hide_help"].to_bool();
|
||||
|
||||
build_status_ = HELP_INDEX;
|
||||
build_status_ = HELP_INDEXED;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -713,8 +713,8 @@ void unit_type::build(BUILD_STATUS status, const movement_type_map &movement_typ
|
|||
build_created(movement_types, races, traits);
|
||||
return;
|
||||
|
||||
case VARIATIONS: // Implemented as part of HELP_INDEX
|
||||
case HELP_INDEX:
|
||||
case VARIATIONS: // Implemented as part of HELP_INDEXED
|
||||
case HELP_INDEXED:
|
||||
// Build the data needed to feed the help index.
|
||||
build_help_index(movement_types, races, traits);
|
||||
return;
|
||||
|
@ -953,7 +953,7 @@ std::set<std::string> unit_type::advancement_tree() const
|
|||
const std::vector<std::string> unit_type::advances_from() const
|
||||
{
|
||||
// currently not needed (only help call us and already did it)
|
||||
unit_types.build_all(unit_type::HELP_INDEX);
|
||||
unit_types.build_all(unit_type::HELP_INDEXED);
|
||||
|
||||
std::vector<std::string> adv_from;
|
||||
BOOST_FOREACH(const unit_type_data::unit_type_map::value_type &ut, unit_types.types())
|
||||
|
|
|
@ -123,12 +123,13 @@ public:
|
|||
|
||||
/// Records the status of the lazy building of unit types.
|
||||
/// These are in order of increasing levels of being built.
|
||||
enum BUILD_STATUS {NOT_BUILT, CREATED, VARIATIONS, HELP_INDEX, WITHOUT_ANIMATIONS, FULL};
|
||||
/// HELP_INDEX is already defined in a windows header under some conditions.
|
||||
enum BUILD_STATUS {NOT_BUILT, CREATED, VARIATIONS, HELP_INDEXED , WITHOUT_ANIMATIONS, FULL};
|
||||
private: // These will be called by build().
|
||||
/// Load data into an empty unit_type (build to FULL).
|
||||
void build_full(const movement_type_map &movement_types,
|
||||
const race_map &races, const config::const_child_itors &traits);
|
||||
/// Partially load data into an empty unit_type (build to HELP_INDEX).
|
||||
/// Partially load data into an empty unit_type (build to HELP_INDEXED).
|
||||
void build_help_index(const movement_type_map &movement_types,
|
||||
const race_map &races, const config::const_child_itors &traits);
|
||||
/// Load the most needed data into an empty unit_type (build to CREATE).
|
||||
|
@ -244,7 +245,7 @@ public:
|
|||
bool has_random_traits() const;
|
||||
|
||||
/// The returned vector will not be empty, provided this has been built
|
||||
/// to the HELP_INDEX status.
|
||||
/// to the HELP_INDEXED status.
|
||||
const std::vector<unit_race::GENDER>& genders() const { return genders_; }
|
||||
std::vector<std::string> variations() const;
|
||||
|
||||
|
@ -257,7 +258,7 @@ public:
|
|||
/// Returns the ID of this type's race without the need to build the type.
|
||||
std::string race_id() const { return cfg_["race"]; } //race_->id(); }
|
||||
/// Never returns NULL, but may point to the null race.
|
||||
/// Requires building to the HELP_INDEX status to get the correct race.
|
||||
/// Requires building to the HELP_INDEXED status to get the correct race.
|
||||
const unit_race* race() const { return race_; }
|
||||
bool hide_help() const;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue