reduce the impact of lobby lag by applying gamelist diffs at a set interval

default refresh interval set to 6 seconds, but this may need some fine-tuning
This commit is contained in:
Patrick Parker 2007-02-04 06:43:03 +00:00
parent 195ea6f7ca
commit e965dce832
5 changed files with 23 additions and 6 deletions

View file

@ -76,6 +76,7 @@
tip_width=495
tip_padding=20
tinygui_tip_padding=4
lobby_refresh=6000
map_image="maps/wesnoth.png"
sidebar_image="misc/rightside.png"

View file

@ -33,6 +33,7 @@ namespace game_config
int recall_cost = 20;
int kill_experience = 8;
int leadership_bonus = 25;
int lobby_refresh = 6000;
const std::string version = VERSION;
bool debug = false, editor = false, ignore_replay_errors = false, mp_debug = false, exit_at_end = false, no_delay = false, disable_autosave = false;
@ -110,6 +111,7 @@ namespace game_config
rest_heal_amount = atoi(v["rest_heal_amount"].c_str());
recall_cost = atoi(v["recall_cost"].c_str());
kill_experience = atoi(v["kill_experience"].c_str());
lobby_refresh = atoi(v["lobby_refresh"].c_str());
game_icon = v["icon"];
game_title = v["title"];

View file

@ -31,6 +31,7 @@ namespace game_config
extern int recall_cost;
extern int kill_experience;
extern int leadership_bonus;
extern int lobby_refresh;
extern const std::string version;
extern bool debug, editor, ignore_replay_errors, mp_debug, exit_at_end, no_delay, disable_autosave;

View file

@ -206,7 +206,9 @@ ui::ui(display& disp, const std::string& title, const config& cfg, chat& c, conf
chat_textbox_(disp.video(), 100, "", false),
users_menu_(disp.video(), std::vector<std::string>(), false, -1, -1, NULL, &umenu_style),
result_(CONTINUE)
result_(CONTINUE),
gamelist_refresh_(false),
lobby_clock_(0)
{
const SDL_Rect area = { 0, 0, disp.video().getx(), disp.video().gety() };
users_menu_.set_numeric_keypress_selection(false);
@ -216,7 +218,6 @@ ui::ui(display& disp, const std::string& title, const config& cfg, chat& c, conf
void ui::process_network()
{
config data;
try {
const network::connection sock = network::receive_data(data);
@ -227,6 +228,14 @@ void ui::process_network()
process_network_error(e);
}
//apply diffs at a set interval
if(gamelist_refresh_ && SDL_GetTicks() - lobby_clock_ > game_config::lobby_refresh)
{
gamelist_updated(false);
gamelist_refresh_ = false;
lobby_clock_ = SDL_GetTicks();
}
if (accept_connections()) {
network::connection sock = network::accept_connection();
if(sock) {
@ -382,7 +391,7 @@ void ui::handle_key_event(const SDL_KeyboardEvent& event)
if(matches.empty()) {
best_match = *i;
} else {
int j= 0;;
int j= 0;
while(toupper(best_match[j]) == toupper((*i)[j])) j++;
best_match.erase(best_match.begin()+j,best_match.end());
}
@ -462,16 +471,17 @@ void ui::process_network_data(const config& data, const network::connection /*so
chat_.update_textbox(chat_textbox_);
}
}
if(data.child("gamelist")) {
if(!gamelist_initialized_)
gamelist_initialized_ = true;
gamelist_ = data;
gamelist_updated(false);
gamelist_refresh_ = false;
lobby_clock_ = SDL_GetTicks();
} else if(data.child("gamelist_diff")) {
if(gamelist_initialized_) {
gamelist_.apply_diff(*data.child("gamelist_diff"));
gamelist_updated(false);
gamelist_refresh_ = true;
}
}
}

View file

@ -62,7 +62,6 @@ private:
std::string format_message(const msg& message);
msg_hist message_history_;
msg_hist::size_type last_update_;
};
@ -188,6 +187,10 @@ private:
std::vector<std::string> user_list_;
result result_;
bool gamelist_refresh_;
Uint32 lobby_clock_;
};
}