fixed bug with statistics when loading with a replay
This commit is contained in:
parent
33d69d95e2
commit
1172ef776f
6 changed files with 29 additions and 8 deletions
|
@ -688,13 +688,13 @@ namespace {
|
|||
const std::string ConfigPostfix = "\n";
|
||||
}
|
||||
|
||||
size_t config::write_size() const
|
||||
size_t config::write_size(size_t tab) const
|
||||
{
|
||||
size_t res = 0;
|
||||
for(string_map::const_iterator i = values.begin(); i != values.end(); ++i) {
|
||||
if(i->second.empty() == false) {
|
||||
res += i->first.size() + AttributeEquals.size() +
|
||||
i->second.size() + AttributePostfix.size();
|
||||
i->second.size() + AttributePostfix.size() + tab;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -703,7 +703,7 @@ size_t config::write_size() const
|
|||
const std::string& name = *item.first;
|
||||
const config& cfg = *item.second;
|
||||
res += ElementPrefix.size() + name.size() + ElementPostfix.size() +
|
||||
cfg.write_size() + EndElementPrefix.size() + name.size() + EndElementPostfix.size();
|
||||
cfg.write_size(tab+1) + EndElementPrefix.size() + name.size() + EndElementPostfix.size() + tab*2;
|
||||
|
||||
}
|
||||
|
||||
|
@ -712,11 +712,14 @@ size_t config::write_size() const
|
|||
return res;
|
||||
}
|
||||
|
||||
std::string::iterator config::write_internal(std::string::iterator out) const
|
||||
std::string::iterator config::write_internal(std::string::iterator out, size_t tab) const
|
||||
{
|
||||
for(std::map<std::string,std::string>::const_iterator i = values.begin();
|
||||
i != values.end(); ++i) {
|
||||
if(i->second.empty() == false) {
|
||||
std::fill(out,out+tab,'\t');
|
||||
out += tab;
|
||||
|
||||
out = std::copy(i->first.begin(),i->first.end(),out);
|
||||
out = std::copy(AttributeEquals.begin(),AttributeEquals.end(),out);
|
||||
out = std::copy(i->second.begin(),i->second.end(),out);
|
||||
|
@ -729,10 +732,17 @@ std::string::iterator config::write_internal(std::string::iterator out) const
|
|||
const std::string& name = *item.first;
|
||||
const config& cfg = *item.second;
|
||||
|
||||
std::fill(out,out+tab,'\t');
|
||||
out += tab;
|
||||
|
||||
out = std::copy(ElementPrefix.begin(),ElementPrefix.end(),out);
|
||||
out = std::copy(name.begin(),name.end(),out);
|
||||
out = std::copy(ElementPostfix.begin(),ElementPostfix.end(),out);
|
||||
out = cfg.write_internal(out);
|
||||
out = cfg.write_internal(out,tab+1);
|
||||
|
||||
std::fill(out,out+tab,'\t');
|
||||
out += tab;
|
||||
|
||||
out = std::copy(EndElementPrefix.begin(),EndElementPrefix.end(),out);
|
||||
out = std::copy(name.begin(),name.end(),out);
|
||||
out = std::copy(EndElementPostfix.begin(),EndElementPostfix.end(),out);
|
||||
|
|
|
@ -218,8 +218,8 @@ struct config
|
|||
string_map values;
|
||||
|
||||
private:
|
||||
size_t write_size() const;
|
||||
std::string::iterator write_internal(std::string::iterator out) const;
|
||||
size_t write_size(size_t tab=0) const;
|
||||
std::string::iterator write_internal(std::string::iterator out, size_t tab=0) const;
|
||||
std::string::const_iterator read_compressed_internal(std::string::const_iterator i1, std::string::const_iterator i2, compression_schema& schema);
|
||||
void write_compressed_internal(compression_schema& schema, std::vector<char>& res) const;
|
||||
|
||||
|
|
|
@ -78,6 +78,8 @@ LEVEL_RESULT play_game(display& disp, game_state& state, config& game_config,
|
|||
} else {
|
||||
scenario = game_config.find_child(type,"id",state.scenario);
|
||||
}
|
||||
|
||||
statistics::clear_current_scenario();
|
||||
} else {
|
||||
std::cerr << "loading snapshot...\n";
|
||||
//load from a save-snapshot.
|
||||
|
|
|
@ -397,6 +397,14 @@ void fresh_stats()
|
|||
mid_scenario = false;
|
||||
}
|
||||
|
||||
void clear_current_scenario()
|
||||
{
|
||||
if(master_stats.empty() == false) {
|
||||
master_stats.pop_back();
|
||||
mid_scenario = false;
|
||||
}
|
||||
}
|
||||
|
||||
int sum_str_int_map(const stats::str_int_map& m)
|
||||
{
|
||||
int res = 0;
|
||||
|
|
|
@ -74,6 +74,7 @@ namespace statistics
|
|||
config write_stats();
|
||||
void read_stats(const config& cfg);
|
||||
void fresh_stats();
|
||||
void clear_current_scenario();
|
||||
|
||||
std::vector<std::string> get_categories();
|
||||
stats calculate_stats(int category, int side);
|
||||
|
|
|
@ -110,7 +110,7 @@ void scrollbar::redraw()
|
|||
|
||||
void scrollbar::draw()
|
||||
{
|
||||
if (!enabled() || !dirty())
|
||||
if(!enabled() || !dirty())
|
||||
return;
|
||||
|
||||
set_dirty(false);
|
||||
|
|
Loading…
Add table
Reference in a new issue