better handling of history in wesnothd (merged 2008-03-30T15:01:12Z!davewx7@gmail.com from trunk)

This commit is contained in:
Gunter Labes 2008-04-08 22:49:53 +00:00
parent c50a38c44f
commit 90bce95505
2 changed files with 20 additions and 5 deletions

View file

@ -1145,11 +1145,26 @@ void game::send_observerquit(const player_map::const_iterator observer) const {
void game::send_history(const network::connection sock) const
{
for(std::vector<simple_wml::document*>::const_iterator i = history_.begin();
i != history_.end(); ++i) {
const simple_wml::string_span& data = (*i)->output_compressed();
network::send_raw_data(data.begin(), data.size(), sock);
if(history_.empty()) {
return;
}
//we make a new document based on converting to plain text and
//concatenating the buffers.
//TODO: Work out how to concentate buffers without decompressing.
std::string buf;
for(std::vector<simple_wml::document*>::iterator i = history_.begin();
i != history_.end(); ++i) {
buf += (*i)->output();
delete *i;
}
simple_wml::document* doc = new simple_wml::document(buf.c_str(), simple_wml::INIT_STATIC);
const simple_wml::string_span& data = doc->output_compressed();
doc->compress();
network::send_raw_data(data.begin(), data.size(), sock);
history_.clear();
history_.push_back(doc);
}
void game::record_data(simple_wml::document* data) {

View file

@ -202,7 +202,7 @@ private:
//! The current scenario data.
simple_wml::document level_;
//! Replay data.
std::vector<simple_wml::document*> history_;
mutable std::vector<simple_wml::document*> history_;
//! Pointer to the game's description in the games_and_users_list_.
simple_wml::node* description_;