wesnoth-cvs-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Wesnoth-cvs-commits] wesnoth/src ai.cpp multiplayer_lobby.cpp networ...


From: David White
Subject: [Wesnoth-cvs-commits] wesnoth/src ai.cpp multiplayer_lobby.cpp networ...
Date: Mon, 11 Oct 2004 23:43:16 -0400

CVSROOT:        /cvsroot/wesnoth
Module name:    wesnoth
Branch:         
Changes by:     David White <address@hidden>    04/10/12 03:35:57

Modified files:
        src            : ai.cpp multiplayer_lobby.cpp network.cpp 
                         playlevel.cpp replay.cpp 
        src/widgets    : textbox.cpp textbox.hpp 

Log message:
        fixed lag when chatting in multiplayer lobby

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/ai.cpp.diff?tr1=1.121&tr2=1.122&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/multiplayer_lobby.cpp.diff?tr1=1.40&tr2=1.41&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/network.cpp.diff?tr1=1.44&tr2=1.45&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/playlevel.cpp.diff?tr1=1.156&tr2=1.157&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/replay.cpp.diff?tr1=1.82&tr2=1.83&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/widgets/textbox.cpp.diff?tr1=1.56&tr2=1.57&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/widgets/textbox.hpp.diff?tr1=1.30&tr2=1.31&r1=text&r2=text

Patches:
Index: wesnoth/src/ai.cpp
diff -u wesnoth/src/ai.cpp:1.121 wesnoth/src/ai.cpp:1.122
--- wesnoth/src/ai.cpp:1.121    Mon Oct 11 23:46:39 2004
+++ wesnoth/src/ai.cpp  Tue Oct 12 03:35:56 2004
@@ -1,4 +1,4 @@
-/* $Id: ai.cpp,v 1.121 2004/10/11 23:46:39 Sirp Exp $ */
+/* $Id: ai.cpp,v 1.122 2004/10/12 03:35:56 Sirp Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -241,11 +241,6 @@
 bool ai_interface::recruit(const std::string& unit_name, location loc)
 {
        const std::set<std::string>& recruits = current_team().recruits();
-       std::cerr << "recruits: ";
-       for(std::set<std::string>::const_iterator mi = recruits.begin(); mi != 
recruits.end(); ++mi) {
-               std::cerr << "'" << *mi << "', ";
-       }
-       std::cerr << "\n";
 
        const std::set<std::string>::const_iterator i = 
recruits.find(unit_name);
        if(i == recruits.end()) {
@@ -253,7 +248,6 @@
        }
 
        const int num = std::distance(recruits.begin(),i);
-       std::cerr << "recruit '" << unit_name << "' number " << num << "\n";
 
        recorder.add_recruit(num,loc);
        replay_undo replay_guard(recorder);
Index: wesnoth/src/multiplayer_lobby.cpp
diff -u wesnoth/src/multiplayer_lobby.cpp:1.40 
wesnoth/src/multiplayer_lobby.cpp:1.41
--- wesnoth/src/multiplayer_lobby.cpp:1.40      Thu Oct  7 19:30:19 2004
+++ wesnoth/src/multiplayer_lobby.cpp   Tue Oct 12 03:35:57 2004
@@ -238,26 +238,28 @@
 
                update_whole_screen();
 
-               bool old_enter = true, chat_invalidated = true;
+               bool old_enter = true;
+
+               size_t last_message = messages.size() < 50 ? 0 : 
messages.size() - 50;
 
                for(;;) {
 
-                       if(chat_invalidated) {
+                       if(last_message < messages.size()) {
                                // Display Chats
                                std::stringstream text;
-                               for(size_t n = messages.size() > 50 ? 
messages.size()-50 : 0;
-                                       n != messages.size(); ++n) {
-                                       text << messages[n] << "\n";
+                               for(; last_message != messages.size(); 
++last_message) {
+                                       text << messages[last_message];
+                                       if(last_message+1 != messages.size()) {
+                                               text << "\n";
+                                       }
                                }
 
-                               chat_textbox.set_text(text.str());
+                               chat_textbox.append_text(text.str());
 
                                chat_textbox.set_location(chat_area);
                                chat_textbox.set_wrap(true);
                                chat_textbox.scroll_to_bottom();
                                chat_textbox.set_dirty();
-
-                               chat_invalidated = false;
                        }
 
                        int mousex, mousey;
@@ -318,7 +320,6 @@
                                std::stringstream message;
                                message << "<" << child["sender"] << ">  " << 
child["message"];
                                messages.push_back(message.str());
-                               chat_invalidated = true;
                        }
 
                        if(last_escape == false && key[SDLK_ESCAPE] || dlg == 
NULL && quit_game.process(mousex,mousey,left_button)){
@@ -371,7 +372,6 @@
                                        std::stringstream message;
                                        message << "<" << msg["sender"] << ">  
" << msg["message"];
                                        messages.push_back(message.str());
-                                       chat_invalidated = true;
                                }
                        }
 
Index: wesnoth/src/network.cpp
diff -u wesnoth/src/network.cpp:1.44 wesnoth/src/network.cpp:1.45
--- wesnoth/src/network.cpp:1.44        Mon Oct 11 23:46:39 2004
+++ wesnoth/src/network.cpp     Tue Oct 12 03:35:57 2004
@@ -609,6 +609,7 @@
 
 void process_send_queue(connection connection_num, size_t max_size)
 {
+       check_error();
 }
 
 void send_data_all_except(const config& cfg, connection connection_num, size_t 
max_size)
Index: wesnoth/src/playlevel.cpp
diff -u wesnoth/src/playlevel.cpp:1.156 wesnoth/src/playlevel.cpp:1.157
--- wesnoth/src/playlevel.cpp:1.156     Mon Oct 11 23:46:40 2004
+++ wesnoth/src/playlevel.cpp   Tue Oct 12 03:35:57 2004
@@ -1,4 +1,4 @@
-/* $Id: playlevel.cpp,v 1.156 2004/10/11 23:46:40 Sirp Exp $ */
+/* $Id: playlevel.cpp,v 1.157 2004/10/12 03:35:57 Sirp Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -236,14 +236,6 @@
 
                teams.push_back(team(**ui,ngold));
 
-               std::cerr << "team " << teams.size() << " can recruit: ";
-               const std::set<std::string>& recruits = teams.back().recruits();
-               for(std::set<std::string>::const_iterator r = recruits.begin(); 
r != recruits.end(); ++r) {
-                       std::cerr << "'" << *r << "', ";
-               }
-
-               std::cerr << "\n";
-
                //if this side tag describes the leader of the side
                if((**ui)["no_leader"] != "yes" && (**ui)["controller"] != 
"null") {
                        unit new_unit(gameinfo, **ui);
Index: wesnoth/src/replay.cpp
diff -u wesnoth/src/replay.cpp:1.82 wesnoth/src/replay.cpp:1.83
--- wesnoth/src/replay.cpp:1.82 Mon Oct 11 23:46:40 2004
+++ wesnoth/src/replay.cpp      Tue Oct 12 03:35:57 2004
@@ -1,4 +1,4 @@
-/* $Id: replay.cpp,v 1.82 2004/10/11 23:46:40 Sirp Exp $ */
+/* $Id: replay.cpp,v 1.83 2004/10/12 03:35:57 Sirp Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -707,15 +707,6 @@
                                throw replay::error();
                        }
 
-                       std::cerr << "recruiting unit from options: ";
-                       for(std::set<std::string>::const_iterator r = 
recruits.begin(); r != recruits.end(); ++r) {
-                               std::cerr << "'" << *r << "', ";
-                       }
-
-                       std::cerr << "\n";
-
-                       std::cerr << "recruiting unit " << val << " '" << *itor 
<< "'\n";
-
                        unit new_unit(&(u_type->second),team_num,true);
                        const std::string& res = 
recruit_unit(map,team_num,units,new_unit,loc);
                        if(!res.empty()) {
Index: wesnoth/src/widgets/textbox.cpp
diff -u wesnoth/src/widgets/textbox.cpp:1.56 
wesnoth/src/widgets/textbox.cpp:1.57
--- wesnoth/src/widgets/textbox.cpp:1.56        Mon Sep 27 00:24:42 2004
+++ wesnoth/src/widgets/textbox.cpp     Tue Oct 12 03:35:57 2004
@@ -1,4 +1,4 @@
-/* $Id: textbox.cpp,v 1.56 2004/09/27 00:24:42 ydirson Exp $ */
+/* $Id: textbox.cpp,v 1.57 2004/10/12 03:35:57 Sirp Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -52,7 +52,7 @@
 }
 
 // set_text does not respect max_size_
-void textbox::set_text(std::string text)
+void textbox::set_text(const std::string& text)
 {
        text_ = string_to_wstring(text);
        cursor_ = text_.size();
@@ -62,6 +62,34 @@
        update_text_cache(true);
 }
 
+void textbox::append_text(const std::string& text)
+{
+       if(text_image_.get() == NULL) {
+               set_text(text);
+               return;
+       }
+
+       const wide_string& wtext = string_to_wstring(text);
+
+       const surface new_text = add_text_line(wtext);
+       const surface new_surface = 
create_compatible_surface(text_image_,maximum<size_t>(text_image_->w,new_text->w),text_image_->h+new_text->h);
+
+       SDL_SetAlpha(new_text.get(),0,0);
+       SDL_SetAlpha(text_image_.get(),0,0);
+
+       SDL_BlitSurface(text_image_,NULL,new_surface,NULL);
+
+       SDL_Rect target = {0,text_image_->h,new_text->w,new_text->h};
+       SDL_BlitSurface(new_text,NULL,new_surface,&target);
+       text_image_.assign(new_surface);
+
+       text_.resize(text_.size() + wtext.size());
+       std::copy(wtext.begin(),wtext.end(),text_.end()-wtext.size());
+
+       set_dirty(true);
+       update_text_cache(false);
+}
+
 void textbox::clear()
 {
        text_.clear();
@@ -259,75 +287,78 @@
        set_dirty(true);
 }
 
-void textbox::update_text_cache(bool changed)
+surface textbox::add_text_line(const wide_string& text)
 {
-       if(changed) {
-               char_x_.clear();
-               char_y_.clear();
-               char_x_.push_back(0);
+       line_height_ = font::get_max_height(font_size);
+
+       if(char_y_.empty()) {
                char_y_.push_back(0);
+       } else {
+               char_y_.push_back(char_y_.back() + line_height_);
+       }
 
-               // Re-calculate the position of each glyph. We approximate this 
by asking the
-               // width of each substring, but this is a flawed assumption 
which won't work with
-               // some more complex scripts (that is, RTL languages). This 
part of the work should
-               // actually be done by the font-rendering system.
-               std::string visible_string;
-               wide_string wrapped_text;
-                
-               wide_string::const_iterator backup_itor;
-               
-               wide_string::const_iterator itor = text_.begin();
-               while(itor != text_.end()) {
-                       //If this is a space, save copies of the current state 
so we can roll back
-                       if(char(*itor) == ' ') {
-                               backup_itor = itor;
+       char_x_.push_back(0);
+       
+       // Re-calculate the position of each glyph. We approximate this by 
asking the
+       // width of each substring, but this is a flawed assumption which won't 
work with
+       // some more complex scripts (that is, RTL languages). This part of the 
work should
+       // actually be done by the font-rendering system.
+       std::string visible_string;
+       wide_string wrapped_text;
+        
+       wide_string::const_iterator backup_itor = text.end();
+       
+       wide_string::const_iterator itor = text.begin();
+       while(itor != text.end()) {
+               //If this is a space, save copies of the current state so we 
can roll back
+               if(char(*itor) == ' ') {
+                       backup_itor = itor;
+               }
+               visible_string.append(wchar_to_string(*itor));
+
+               if(char(*itor) == '\n') {
+                       backup_itor = text.end();
+                       visible_string = "";
+               }
+
+               int w = font::line_width(visible_string, font_size);
+
+               if(wrap_ && w >= location().w - scrollbar_.get_max_width()) {
+                       if(backup_itor != text.end()) {
+                               int backup = itor - backup_itor;
+                               itor = backup_itor + 1;
+                               if(backup > 0) {
+                                       char_x_.erase(char_x_.end()-backup, 
char_x_.end());
+                                       char_y_.erase(char_y_.end()-backup, 
char_y_.end());
+                                       
wrapped_text.erase(wrapped_text.end()-backup, wrapped_text.end());
+                               }
                        }
-                       visible_string.append(wchar_to_string(*itor));
+                       backup_itor = text.end();
+                       wrapped_text.push_back(wchar_t('\n'));
+                       char_x_.push_back(0);
+                       char_y_.push_back(char_y_.back() + line_height_);
+                       visible_string = "";
+               } else {
+                       wrapped_text.push_back(*itor);
+                       char_x_.push_back(w);
+                       char_y_.push_back(char_y_.back() + (char(*itor) == '\n' 
? line_height_ : 0));
+                       ++itor;
+               }
+       }
 
-                       if(char(*itor) == '\n') {
-                               backup_itor = text_.end();
-                               visible_string = "";
-                       }
+       const std::string s = wstring_to_string(wrapped_text);
+       const surface res(font::get_rendered_text(s, font_size, 
font::NORMAL_COLOUR));          
 
-                       int w = font::line_width(visible_string, font_size);
+       return res;
+}
 
-                       if(wrap_ && w >= location().w - 
scrollbar_.get_max_width()) {
-                               if(backup_itor != text_.end()) {
-                                       int backup = itor - backup_itor;
-                                       itor = backup_itor + 1;
-                                       if(backup > 0) {
-                                               
char_x_.erase(char_x_.end()-backup, char_x_.end());
-                                               
char_y_.erase(char_y_.end()-backup, char_y_.end());
-                                               
wrapped_text.erase(wrapped_text.end()-backup, wrapped_text.end());
-                                       }
-                               }
-                               backup_itor = text_.end();
-                               wrapped_text.push_back(wchar_t('\n'));
-                               char_x_.push_back(0);
-                               char_y_.push_back(char_y_.back()+1);
-                               visible_string = "";
-                       } else {
-                               wrapped_text.push_back(*itor);
-                               char_x_.push_back(w);
-                               char_y_.push_back(char_y_.back() + (char(*itor) 
== '\n' ? 1 : 0));
-                               ++itor;
-                       }
-               }
+void textbox::update_text_cache(bool changed)
+{
+       if(changed) {
+               char_x_.clear();
+               char_y_.clear();
 
-               text_size_.x = 0;
-               text_size_.y = 0;
-               const std::string s = wstring_to_string(wrapped_text);
-               text_size_.w = font::line_width(s, font_size);
-               text_size_.h = location().h;
-
-               text_image_.assign(font::get_rendered_text(s, font_size, 
font::NORMAL_COLOUR));         
-
-               //so far we've set char_y_ in terms of the line it's on, now 
set it in terms of proper y
-               //co-ordinates, by calculating the height of a line, and 
multiplying each member of char_y_ by that height
-               line_height_ = font::get_max_height(font_size);
-               for(std::vector<int>::iterator i = char_y_.begin(); i != 
char_y_.end(); ++i) {
-                       *i = *i * line_height_;
-               }
+               text_image_.assign(add_text_line(text_));
        }
 
        int cursor_x = char_x_[cursor_];
Index: wesnoth/src/widgets/textbox.hpp
diff -u wesnoth/src/widgets/textbox.hpp:1.30 
wesnoth/src/widgets/textbox.hpp:1.31
--- wesnoth/src/widgets/textbox.hpp:1.30        Sun Jul 18 19:02:25 2004
+++ wesnoth/src/widgets/textbox.hpp     Tue Oct 12 03:35:57 2004
@@ -1,4 +1,4 @@
-/* $Id: textbox.hpp,v 1.30 2004/07/18 19:02:25 gruikya Exp $ */
+/* $Id: textbox.hpp,v 1.31 2004/10/12 03:35:57 Sirp Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -33,7 +33,8 @@
        textbox(display& d, int width, const std::string& text="", bool 
editable=true, size_t max_size = 256);
 
        const std::string text() const;
-       void set_text(std::string text);
+       void set_text(const std::string& text);
+       void append_text(const std::string& text);
        void clear();
        void process();
 
@@ -72,7 +73,6 @@
        //this will be reset when keyboard input events occur
        int show_cursor_at_;
        surface text_image_;
-       SDL_Rect text_size_;
 
        //variables used for multi-line textboxes which support scrolling
        scrollbar scrollbar_;
@@ -88,6 +88,7 @@
 
        void draw_cursor(int pos, display &disp) const;
        void update_text_cache(bool reset = false);
+       surface add_text_line(const wide_string& text);
        bool is_selection();
        void erase_selection();
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]