Optimized MP chat log building (helps bug #10430)

This commit is contained in:
Pauli Nieminen 2008-02-05 14:34:38 +00:00
parent abcd882956
commit 90e7897691
3 changed files with 54 additions and 17 deletions

View file

@ -36,6 +36,7 @@ Version 1.3.15+svn:
* Remember cleared hotkey
* Added some toys&whisles to unit tests
* Added networking unit tests
* Optimized MP chat log building
* Hide race sections having only units with "hide_help=true"
* Fixed ai handling of unit without attacking weapons (bug #10886)
* Optimize roads placing of random map

View file

@ -428,36 +428,60 @@ void replay::add_advancement(const gamemap::location& loc)
cmd->add_child("advance_unit",val);
}
void replay::add_chat_message_location()
{
message_locations.push_back(pos_-1);
}
void replay::speak(const config& cfg)
{
config* const cmd = add_command(false);
if(cmd != NULL) {
cmd->add_child("speak",cfg);
(*cmd)["undo"] = "no";
add_chat_message_location();
}
}
std::string replay::build_chat_log(const std::string& team) const
void replay::add_chat_log_entry(const config* speak, std::stringstream& str, const std::string& team) const
{
const config& cfg = *speak;
const std::string& team_name = cfg["team_name"];
if(team_name == "" || team_name == team) {
if(team_name == "") {
str << "<" << cfg["description"] << "> ";
} else {
str << "*" << cfg["description"] << "* ";
}
str << cfg["message"] << "\n";
}
}
std::string replay::build_chat_log(const std::string& team)
{
std::stringstream str;
const config::child_list& cmd = commands();
for(config::child_list::const_iterator i = cmd.begin(); i != cmd.end(); ++i) {
const config* speak = (**i).child("speak");
if(speak != NULL) {
const config& cfg = *speak;
const std::string& team_name = cfg["team_name"];
if(team_name == "" || team_name == team) {
if(team_name == "") {
str << "<" << cfg["description"] << "> ";
} else {
str << "*" << cfg["description"] << "* ";
}
std::vector<int>::iterator loc_it;
int last_location = 0;
for (loc_it = message_locations.begin(); loc_it != message_locations.end(); ++loc_it)
{
last_location = *loc_it;
const config* speak = cmd[last_location]->child("speak");
add_chat_log_entry(speak,str,team);
str << cfg["message"] << "\n";
}
}
}
#if 0
for(config::child_list::const_iterator i = cmd.begin() + (last_location + 1); i != cmd.end(); ++i) {
++last_location;
const config* speak = (**i).child("speak");
if(speak != NULL) {
message_locations.push_back(last_location);
add_chat_log_entry(speak,str,team);
}
}
#endif
return str.str();
}
@ -625,6 +649,7 @@ void replay::set_to_end()
void replay::clear()
{
message_locations.clear();
cfg_ = config();
pos_ = 0;
current_ = NULL;
@ -641,6 +666,11 @@ void replay::add_config(const config& cfg, MARK_SENT mark)
{
for(config::const_child_itors i = cfg.child_range("command"); i.first != i.second; ++i.first) {
config& cfg = cfg_.add_child("command",**i.first);
if (cfg.child("speak"))
{
pos_ = ncommands();
add_chat_message_location();
}
if(mark == MARK_AS_SENT) {
cfg["sent"] = "yes";
}
@ -812,6 +842,7 @@ bool do_replay_handle(game_display& disp, const gamemap& map, const game_data& g
const std::string& message = (*child)["message"];
//if (!preferences::show_lobby_join(speaker_name, message)) return;
bool is_whisper = (speaker_name.find("whisper: ") == 0);
get_replay_source().add_chat_message_location();
if (!get_replay_source().is_skipping() || is_whisper) {
const int side = lexical_cast_default<int>((*child)["side"],0);
disp.add_chat_message(time(NULL), speaker_name, side, message,

View file

@ -73,9 +73,10 @@ public:
* determines which advancement option has been choosen
*/
void add_advancement(const gamemap::location& loc);
void add_chat_message_location();
void speak(const config& cfg);
std::string build_chat_log(const std::string& team) const;
std::string build_chat_log(const std::string& team);
//get data range will get a range of moves from the replay system.
//if data_type is 'ALL_DATA' then it will return all data in this range
@ -121,6 +122,8 @@ private:
void add_value(const std::string& type, int value);
void add_chat_log_entry(const config*, std::stringstream&, const std::string&) const;
const config::child_list& commands() const;
/** Adds a new empty command to the command list.
*
@ -142,6 +145,8 @@ private:
game_state saveInfo_;
bool skip_;
std::vector<int> message_locations;
};
replay& get_replay_source();