Experimental MP lobby: scroll to selected game less often

The lobby calls tlistbox::set_row_shown() every single time there is *any*
change in the gamelist. Most of the time, the visibility of rows hasn't
even changed.

Tlistbox::set_row_shown() calls content_resize_request() to determine if
twindow::invalidate_layout() needs to be called. Content_resize_request()
unconditionally calls show_content_rect() that checks if the selected item
is visible and scrolls to it if it isn't.

With this commit, set_row_shown() returns early if visibility of rows
hasn't changed. This reduces the frequency of scrolling.

This commit isn't a complete fix, since the selected game will still come
into view when, for example, a new game is created. However, at least this
improves the situation.
This commit is contained in:
Jyrki Vesterinen 2016-10-01 12:03:48 +03:00
parent 722600a313
commit 667064a8af
2 changed files with 19 additions and 0 deletions

View file

@ -18,6 +18,8 @@
#include "widget.hpp"
#include "tstring.hpp"
#include <boost/dynamic_bitset.hpp>
#include <array>
typedef std::map<std::string, t_string> string_map;
@ -117,6 +119,17 @@ public:
/** Returns whether the item is shown. */
virtual bool get_item_shown(const unsigned index) const = 0;
/** Returns the visibility of all the items as a bit set. */
boost::dynamic_bitset<> get_items_shown()
{
boost::dynamic_bitset<> items_shown(get_item_count());
for (unsigned int i = 0u; i < get_item_count(); ++i)
{
items_shown[i] = get_item_shown(i);
}
return items_shown;
}
/** Returns the number of items. */
virtual unsigned get_item_count() const = 0;

View file

@ -185,6 +185,12 @@ void tlistbox::set_row_shown(const boost::dynamic_bitset<>& shown)
assert(generator_);
assert(shown.size() == get_item_count());
if (generator_->get_items_shown() == shown)
{
LOG_GUI_G << LOG_HEADER << " returning early" << std::endl;
return;
}
twindow* window = get_window();
assert(window);