Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/weekly-test-builds' into ppa-v0.5.1
Browse files Browse the repository at this point in the history
  • Loading branch information
o01eg committed Jan 7, 2025
2 parents e7cc878 + c19b869 commit 41d8c74
Show file tree
Hide file tree
Showing 22 changed files with 45 additions and 54 deletions.
29 changes: 5 additions & 24 deletions GG/src/Font.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2744,31 +2744,15 @@ Font::ExpensiveParseFromTextToTextElements(const std::string& text, const Flags<
// Fetch and use the regular expression from the TagHandler which parses all the known XML tags.
const sregex& regex = tag_handler.Regex(text, ignore_tags);
sregex_iterator it(text.begin(), text.end(), regex);

const sregex_iterator end_it;
while (it != end_it)
{
// Consolidate adjacent blocks of text.
// If adjacent found substrings are all text, merge them into a single Substring.
bool need_increment = true;
Substring combined_text;
sub_match<std::string::const_iterator> const* text_match;
while (it != end_it &&
(text_match = &(*it)[text_tag_idx]) &&
text_match->matched)
{
need_increment = false;
if (combined_text.empty())
combined_text = Substring(text, *text_match);
else
combined_text += *text_match;
++it;
}

for (; it != end_it; ++it) {
const auto& it_elem = *it;

if (!combined_text.empty()) {
text_elements.emplace_back(combined_text); // Basic text element.
if (it_elem[text_tag_idx].matched) {
auto matched_text = Substring(text, it_elem[text_tag_idx]);
if (!matched_text.empty())
text_elements.emplace_back(matched_text); // Basic text element.

} else if (it_elem[open_bracket_tag_idx].matched) {
// Open XML tag.
Expand Down Expand Up @@ -2808,9 +2792,6 @@ Font::ExpensiveParseFromTextToTextElements(const std::string& text, const Flags<
if (last_char == '\n' || last_char == '\f' || last_char == '\r')
text_elements.emplace_back(NEWLINE);
}

if (need_increment)
++it;
}

// fill in the widths of code points in each TextElement
Expand Down
1 change: 0 additions & 1 deletion UI/Sound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,6 @@ void Sound::Impl::Disable() {
m_temporary_disable_count = 0;

m_initialized = false;
DebugLogger() << "Audio " << (m_initialized ? "enabled." : "disabled.");
}

void Sound::Impl::InitOpenAL() {
Expand Down
2 changes: 1 addition & 1 deletion parse/BuildingsParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ namespace parse {
ScopedTimer timer("Buildings Parsing");

for (const auto& file : ListDir(path, IsFOCScript))
detail::parse_file<grammar, start_rule_payload>(lexer::tok, file, building_types);
detail::parse_file<grammar, start_rule_payload>(GetLexer(), file, building_types);

py_grammar p = py_grammar(parser, building_types);
for (const auto& file : ListDir(path, IsFOCPyScript))
Expand Down
8 changes: 5 additions & 3 deletions parse/DoubleValueRefParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,15 +188,17 @@ parse::double_parser_rules::double_parser_rules(

namespace parse {
bool double_free_variable(std::string& text) {
const auto& tok = GetLexer();

boost::spirit::qi::in_state_type in_state;
parse::detail::simple_double_parser_rules simple_double_rules(lexer::tok);
parse::detail::simple_double_parser_rules simple_double_rules(tok);

text_iterator first = text.begin();
text_iterator last = text.end();
token_iterator it = lexer::tok.begin(first, last);
token_iterator it = tok.begin(first, last);

bool success = boost::spirit::qi::phrase_parse(
it, lexer::tok.end(), simple_double_rules.free_variable_name, in_state("WS")[lexer::tok.self]);
it, tok.end(), simple_double_rules.free_variable_name, in_state("WS")[tok.self]);

return success;
}
Expand Down
2 changes: 1 addition & 1 deletion parse/EmpireStatsParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ namespace parse {

for (const auto& file : ListDir(path, IsFOCScript)) {
start_rule_payload stats_;
if (detail::parse_file<grammar, start_rule_payload>(lexer::tok, file, stats_)) {
if (detail::parse_file<grammar, start_rule_payload>(GetLexer(), file, stats_)) {
for (auto& stat : stats_) {
auto maybe_inserted = all_stats.emplace(stat.first, std::move(stat.second));
if (!maybe_inserted.second) {
Expand Down
2 changes: 1 addition & 1 deletion parse/EncyclopediaParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ namespace parse {
ScopedTimer timer("Encyclopedia Parsing");

for (const auto& file : ListDir(path, IsFOCScript))
detail::parse_file<grammar, ArticleMap>(lexer::tok, file, articles);
detail::parse_file<grammar, ArticleMap>(GetLexer(), file, articles);

return articles;
}
Expand Down
2 changes: 1 addition & 1 deletion parse/FieldsParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ namespace parse {
ScopedTimer timer("Fields Parsing");

for (const auto& file : ListDir(path, IsFOCScript))
detail::parse_file<grammar, start_rule_payload>(lexer::tok, file, field_types);
detail::parse_file<grammar, start_rule_payload>(GetLexer(), file, field_types);

return field_types;
}
Expand Down
2 changes: 1 addition & 1 deletion parse/FleetPlansParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ namespace parse {
start_rule_payload fleet_plans(const boost::filesystem::path& path) {
start_rule_payload fleet_plans_;
fleet_plans_.reserve(32); // guesstimate of enough space
detail::parse_file<grammar, start_rule_payload>(lexer::tok, path, fleet_plans_);
detail::parse_file<grammar, start_rule_payload>(GetLexer(), path, fleet_plans_);
return fleet_plans_;
}
}
8 changes: 5 additions & 3 deletions parse/IntValueRefParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,15 +200,17 @@ parse::int_arithmetic_rules::int_arithmetic_rules(

namespace parse {
bool int_free_variable(std::string& text) {
const auto& tok = GetLexer();

boost::spirit::qi::in_state_type in_state;
parse::detail::simple_int_parser_rules simple_int_rules(lexer::tok);
parse::detail::simple_int_parser_rules simple_int_rules(tok);

text_iterator first = text.begin();
text_iterator last = text.end();
token_iterator it = lexer::tok.begin(first, last);
token_iterator it = tok.begin(first, last);

bool success = boost::spirit::qi::phrase_parse(
it, lexer::tok.end(), simple_int_rules.free_variable_name, in_state("WS")[lexer::tok.self]);
it, tok.end(), simple_int_rules.free_variable_name, in_state("WS")[tok.self]);

return success;
}
Expand Down
4 changes: 2 additions & 2 deletions parse/ItemsParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,14 @@ namespace parse {
start_rule_payload items(const boost::filesystem::path& path) {
start_rule_payload items_;
items_.reserve(128); // should be more than enough as of this writing
detail::parse_file<grammar, start_rule_payload>(lexer::tok, path, items_);
detail::parse_file<grammar, start_rule_payload>(GetLexer(), path, items_);
return items_;
}

start_rule_payload starting_buildings(const boost::filesystem::path& path) {
start_rule_payload starting_buildings_;
starting_buildings_.reserve(32); // should be more than enough as of this writing...
detail::parse_file<grammar, start_rule_payload>(lexer::tok, path, starting_buildings_);
detail::parse_file<grammar, start_rule_payload>(GetLexer(), path, starting_buildings_);
return starting_buildings_;
}
}
2 changes: 0 additions & 2 deletions parse/Lexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,5 +119,3 @@ lexer::lexer() :
| end_of_line_comment
;
}

const lexer lexer::tok{};
6 changes: 5 additions & 1 deletion parse/Lexer.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,13 @@ struct lexer : boost::spirit::lex::lexer<spirit_lexer_base_type> {
static inline const std::string int_regex{"\\d+"};
static inline const std::string double_regex{"\\d+\\.\\d*|\\d*\\.\\d+"};
static inline const std::string string_regex{"\\\"[^\\\"]*\\\""};
static const lexer tok;
};

inline const lexer& GetLexer() {
static const lexer tok;
return tok;
}

/** The type of iterator passed to the script file parser by the script file
lexer. */
typedef lexer::iterator_type token_iterator;
Expand Down
2 changes: 1 addition & 1 deletion parse/MonsterFleetPlansParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ namespace {
namespace parse {
start_rule_payload monster_fleet_plans(const boost::filesystem::path& path) {
start_rule_payload monster_fleet_plans_;
detail::parse_file<grammar, start_rule_payload>(lexer::tok, path, monster_fleet_plans_);
detail::parse_file<grammar, start_rule_payload>(GetLexer(), path, monster_fleet_plans_);
return monster_fleet_plans_;
}
}
2 changes: 1 addition & 1 deletion parse/NamedValueRefParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ namespace parse {
ScopedTimer timer("Named ValueRef Parsing");

for (const auto& file : ListDir(path, IsFOCScript))
detail::parse_file<grammar, start_rule_payload>(lexer::tok, file, named_value_refs);
detail::parse_file<grammar, start_rule_payload>(GetLexer(), file, named_value_refs);

for (auto& k_v : named_value_refs)
ErrorLogger() << "Should have not returned anything: named_value_refs : " << k_v.first;
Expand Down
2 changes: 1 addition & 1 deletion parse/PoliciesParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ namespace parse {
ScopedTimer timer("Policies Parsing");

for (const auto& file : ListDir(path, IsFOCScript))
detail::parse_file<grammar, start_rule_payload>(lexer::tok, file, policies_);
detail::parse_file<grammar, start_rule_payload>(GetLexer(), file, policies_);

return policies_;
}
Expand Down
6 changes: 4 additions & 2 deletions parse/ShipDesignsParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,8 @@ namespace parse {

ScopedTimer timer("Ship Designs Parsing");

const auto& tok = GetLexer();

for (auto& file : ListDir(path, IsFOCScript)) {
TraceLogger() << "Parse ship design file " << file.filename();
if (file.filename() == "ShipDesignOrdering.focs.txt" ) {
Expand All @@ -237,7 +239,7 @@ namespace parse {
try {
boost::optional<std::unique_ptr<ParsedShipDesign>> maybe_design;
auto partial_result = detail::parse_file<grammar, boost::optional<std::unique_ptr<ParsedShipDesign>>>(
lexer::tok, file, maybe_design);
tok, file, maybe_design);

if (!partial_result || !maybe_design)
continue;
Expand All @@ -252,7 +254,7 @@ namespace parse {
if (!manifest_file.empty()) {
try {
detail::parse_file<manifest_grammar, std::vector<boost::uuids::uuid>>(
lexer::tok, manifest_file, ordering);
tok, manifest_file, ordering);

} catch (const std::runtime_error& e) {
ErrorLogger() << "Failed to parse ship design manifest in " << manifest_file << " from " << path
Expand Down
2 changes: 1 addition & 1 deletion parse/ShipHullsParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ namespace parse {
start_rule_payload hulls;

for (const auto& file : ListDir(path, IsFOCScript))
detail::parse_file<grammar, start_rule_payload>(lexer::tok, file, hulls);
detail::parse_file<grammar, start_rule_payload>(GetLexer(), file, hulls);

return hulls;
}
Expand Down
2 changes: 1 addition & 1 deletion parse/ShipPartsParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ namespace parse {
start_rule_payload parts;

for (const auto& file : ListDir(path, IsFOCScript))
detail::parse_file<grammar, start_rule_payload>(lexer::tok, file, parts);
detail::parse_file<grammar, start_rule_payload>(GetLexer(), file, parts);

return parts;
}
Expand Down
2 changes: 1 addition & 1 deletion parse/SpecialsParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ namespace parse {
start_rule_payload specials_;

for (const auto& file : ListDir(path, IsFOCScript))
detail::parse_file<grammar, start_rule_payload>(lexer::tok, file, specials_);
detail::parse_file<grammar, start_rule_payload>(GetLexer(), file, specials_);

return specials_;
}
Expand Down
6 changes: 4 additions & 2 deletions parse/StringValueRefParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,12 +203,14 @@ namespace parse {
bool string_free_variable(std::string& text) {
boost::spirit::qi::in_state_type in_state;

const auto& tok = GetLexer();

text_iterator first = text.begin();
text_iterator last = text.end();
token_iterator it = lexer::tok.begin(first, last);
token_iterator it = tok.begin(first, last);

bool success = boost::spirit::qi::phrase_parse(
it, lexer::tok.end(), lexer::tok.GalaxySeed_, in_state("WS")[lexer::tok.self]);
it, tok.end(), tok.GalaxySeed_, in_state("WS")[tok.self]);

return success;
}
Expand Down
3 changes: 2 additions & 1 deletion universe/Meter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,9 @@ int Meter::SetFromChars(std::string_view chars) noexcept(have_noexcept_to_chars)

static_assert(noexcept(result.ptr - chars.data()));
#else
const std::string null_terminated_chars{chars};
int chars_consumed = 0;
std::sscanf(chars.data(), "%d %d%n", &cur, &init, &chars_consumed);
std::sscanf(null_terminated_chars.data(), "%d %d%n", &cur, &init, &chars_consumed);
return chars_consumed;
#endif

Expand Down
4 changes: 2 additions & 2 deletions util/SerializeEmpire.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,6 @@ void Empire::serialize(Archive& ar, const unsigned int version)
} else {
ar & BOOST_SERIALIZATION_NVP(m_last_turn_received);
}

}

BOOST_CLASS_VERSION(Empire, 13)
Expand Down Expand Up @@ -363,8 +362,9 @@ void serialize(Archive& ar, EmpireManager& em, unsigned int const version)
for (const auto e1_id : em.m_empire_map | range_keys) {
const auto e1_id_lower = [e1_id](auto e2_id) { return e1_id < e2_id; };
for (const auto e2_id : em.m_empire_map | range_keys | range_filter(e1_id_lower)) {
auto dk = DiploKey(e1_id, e2_id);
const auto inserted_missing_status = em.m_empire_diplomatic_statuses.try_emplace(
DiploKey(e1_id, e2_id), DiplomaticStatus::DIPLO_WAR).second;
dk, DiplomaticStatus::DIPLO_WAR).second;
if (inserted_missing_status)
ErrorLogger() << "Added missing diplomatic status (default WAR) between empires "
<< e1_id << " and " << e2_id;
Expand Down

0 comments on commit 41d8c74

Please sign in to comment.