widelands-dev team mailing list archive
-
widelands-dev team
-
Mailing list archive
-
Message #13517
[Merge] lp:~widelands-dev/widelands/bug-1769344-sp-thinks-too-much into lp:widelands
GunChleoc has proposed merging lp:~widelands-dev/widelands/bug-1769344-sp-thinks-too-much into lp:widelands.
Commit message:
UI Objects in single player setup screen do not think any more. Also, select player names and tribes for non-scenario maps.
Requested reviews:
Widelands Developers (widelands-dev)
Related bugs:
Bug #1769344 in widelands: "high processor load single player launch game screen"
https://bugs.launchpad.net/widelands/+bug/1769344
For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/bug-1769344-sp-thinks-too-much/+merge/346911
UI Objects in single player setup screen do not think any more. This should solve the problem of high processor load.
Also, select player names and tribes for non-scenario maps. In trunk, when selecting The Green Plateau and then selecting another map, the player names persist, which is a bug. I am also assuming that map editors set player names and tribes for a reason, so I don't think it does any harm for non-scenario maps.
--
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/bug-1769344-sp-thinks-too-much into lp:widelands.
=== modified file 'src/ui_fsmenu/launch_game.cc'
--- src/ui_fsmenu/launch_game.cc 2018-04-27 06:11:05 +0000
+++ src/ui_fsmenu/launch_game.cc 2018-05-26 16:29:55 +0000
@@ -78,13 +78,6 @@
delete lua_;
}
-void FullscreenMenuLaunchGame::think() {
- if (ctrl_)
- ctrl_->think();
-
- refresh();
-}
-
bool FullscreenMenuLaunchGame::init_win_condition_label() {
if (settings_->settings().scenario) {
win_condition_dropdown_.set_enabled(false);
=== modified file 'src/ui_fsmenu/launch_game.h'
--- src/ui_fsmenu/launch_game.h 2018-04-27 06:11:05 +0000
+++ src/ui_fsmenu/launch_game.h 2018-05-26 16:29:55 +0000
@@ -45,10 +45,6 @@
FullscreenMenuLaunchGame(GameSettingsProvider*, GameController*);
~FullscreenMenuLaunchGame() override;
- void think() override;
-
- virtual void refresh() = 0;
-
protected:
void clicked_ok() override;
void clicked_back() override;
=== modified file 'src/ui_fsmenu/launch_mpg.cc'
--- src/ui_fsmenu/launch_mpg.cc 2018-05-16 05:30:22 +0000
+++ src/ui_fsmenu/launch_mpg.cc 2018-05-26 16:29:55 +0000
@@ -359,6 +359,13 @@
}
}
+void FullscreenMenuLaunchMPG::think() {
+ if (ctrl_) {
+ ctrl_->think();
+ }
+ refresh();
+}
+
/**
* update the user interface and take care about the visibility of
* buttons and text.
=== modified file 'src/ui_fsmenu/launch_mpg.h'
--- src/ui_fsmenu/launch_mpg.h 2018-04-27 06:11:05 +0000
+++ src/ui_fsmenu/launch_mpg.h 2018-05-26 16:29:55 +0000
@@ -49,7 +49,8 @@
~FullscreenMenuLaunchMPG() override;
void set_chat_provider(ChatProvider&);
- void refresh() override;
+ void think() override;
+ void refresh();
protected:
void clicked_ok() override;
=== modified file 'src/ui_fsmenu/launch_spg.cc'
--- src/ui_fsmenu/launch_spg.cc 2018-04-27 06:11:05 +0000
+++ src/ui_fsmenu/launch_spg.cc 2018-05-26 16:29:55 +0000
@@ -84,6 +84,12 @@
// Variables and objects used in the menu
is_scenario_(false) {
+ subscriber_ =
+ Notifications::subscribe<NoteGameSettings>([this](const NoteGameSettings&) {
+ update();
+ });
+
+
ok_.set_pos(Vector2i(get_w() * 7 / 10, get_h() * 9 / 10));
back_.set_pos(Vector2i(get_w() * 7 / 10, get_h() * 17 / 20));
win_condition_dropdown_.set_pos(Vector2i(get_w() * 7 / 10, get_h() * 4 / 10 + buth_));
@@ -113,6 +119,8 @@
this, get_w() / 25, y, get_w() * 16 / 25, get_h() * 17 / 500 * 2, settings, i);
y += buth_ / 1.17;
}
+
+ set_thinks(false);
}
FullscreenMenuLaunchSPG::~FullscreenMenuLaunchSPG() {
@@ -145,7 +153,7 @@
select_map();
if (settings_->settings().mapname.empty())
return end_modal<FullscreenMenuBase::MenuTarget>(FullscreenMenuBase::MenuTarget::kBack);
- refresh();
+ update();
}
void FullscreenMenuLaunchSPG::win_condition_selected() {
@@ -181,10 +189,10 @@
}
/**
- * update the user interface and take care about the visibility of
+ * update the user interface and take care of the visibility of
* buttons and text.
*/
-void FullscreenMenuLaunchSPG::refresh() {
+void FullscreenMenuLaunchSPG::update() {
const GameSettings& settings = settings_->settings();
{
@@ -201,9 +209,7 @@
select_map_.set_visible(settings_->can_change_map());
select_map_.set_enabled(settings_->can_change_map());
- if (settings.scenario) {
- set_scenario_values();
- }
+ set_player_names_and_tribes();
// "Choose Position" Buttons in frond of PDG
for (uint8_t i = 0; i < nr_players_; ++i) {
@@ -216,8 +222,9 @@
pos_[i]->set_visible(false);
// update the player description groups
- for (uint32_t i = 0; i < kMaxPlayers; ++i)
- players_[i]->refresh();
+ for (uint32_t i = 0; i < kMaxPlayers; ++i) {
+ players_[i]->update();
+ }
}
/**
@@ -245,6 +252,7 @@
safe_place_for_host(nr_players_);
settings_->set_map(mapdata.name, mapdata.filename, nr_players_);
update_win_conditions();
+ update();
}
/**
@@ -252,7 +260,7 @@
* player names and player tribes and take care about visibility
* and usability of all the parts of the UI.
*/
-void FullscreenMenuLaunchSPG::set_scenario_values() {
+void FullscreenMenuLaunchSPG::set_player_names_and_tribes() {
if (settings_->settings().mapfilename.empty()) {
throw wexception("settings()->scenario was set to true, but no map is available");
}
@@ -273,6 +281,7 @@
*/
void FullscreenMenuLaunchSPG::switch_to_position(uint8_t const pos) {
settings_->set_player_number(pos);
+ update();
}
/**
=== modified file 'src/ui_fsmenu/launch_spg.h'
--- src/ui_fsmenu/launch_spg.h 2018-04-27 06:11:05 +0000
+++ src/ui_fsmenu/launch_spg.h 2018-05-26 16:29:55 +0000
@@ -24,6 +24,7 @@
#include <string>
#include "graphic/playercolor.h"
+#include "logic/game_settings.h"
#include "logic/map.h"
#include "ui_basic/button.h"
#include "ui_basic/textarea.h"
@@ -51,7 +52,6 @@
~FullscreenMenuLaunchSPG() override;
void start() override;
- void refresh() override;
protected:
void clicked_ok() override;
@@ -59,10 +59,11 @@
private:
void layout() override;
+ void update();
void select_map();
void win_condition_selected() override;
- void set_scenario_values();
+ void set_player_names_and_tribes();
void switch_to_position(uint8_t);
void safe_place_for_host(uint8_t);
@@ -76,6 +77,7 @@
std::string player_save_name_[kMaxPlayers];
std::string player_save_tribe_[kMaxPlayers];
bool is_scenario_;
+ std::unique_ptr<Notifications::Subscriber<NoteGameSettings>> subscriber_;
};
#endif // end of include guard: WL_UI_FSMENU_LAUNCH_SPG_H
=== modified file 'src/wui/playerdescrgroup.cc'
--- src/wui/playerdescrgroup.cc 2018-04-27 06:11:05 +0000
+++ src/wui/playerdescrgroup.cc 2018-05-26 16:29:55 +0000
@@ -86,7 +86,7 @@
d->btnPlayerInit->sigclicked.connect(
boost::bind(&PlayerDescriptionGroup::toggle_playerinit, boost::ref(*this)));
- refresh();
+ update();
}
PlayerDescriptionGroup::~PlayerDescriptionGroup() {
@@ -97,7 +97,7 @@
/**
* Update display and enabled buttons based on current settings.
*/
-void PlayerDescriptionGroup::refresh() {
+void PlayerDescriptionGroup::update() {
const GameSettings& settings = d->settings->settings();
if (d->plnum >= settings.players.size()) {
@@ -220,10 +220,12 @@
if (settings.players[d->plnum].state != PlayerSettings::State::kClosed)
d->settings->set_player_state(d->plnum, PlayerSettings::State::kClosed);
}
+ Notifications::publish(NoteGameSettings(NoteGameSettings::Action::kPlayer, d->plnum));
}
void PlayerDescriptionGroup::toggle_playertype() {
d->settings->next_player_state(d->plnum);
+ update();
}
/**
@@ -256,6 +258,7 @@
}
d->settings->set_player_tribe(d->plnum, nexttribe, random_tribe);
+ update();
}
/**
@@ -281,6 +284,7 @@
newteam = currentteam + 1;
d->settings->set_player_team(d->plnum, newteam);
+ update();
}
/// Cycle through available initializations for the player's tribe.
@@ -294,8 +298,10 @@
for (const Widelands::TribeBasicInfo& tribeinfo : settings.tribes) {
if (tribeinfo.name == player.tribe) {
- return d->settings->set_player_init(
- d->plnum, (player.initialization_index + 1) % tribeinfo.initializations.size());
+ d->settings->set_player_init(
+ d->plnum, (player.initialization_index + 1) % tribeinfo.initializations.size());
+ update();
+ return;
}
}
NEVER_HERE();
=== modified file 'src/wui/playerdescrgroup.h'
--- src/wui/playerdescrgroup.h 2018-04-07 16:59:00 +0000
+++ src/wui/playerdescrgroup.h 2018-05-26 16:29:55 +0000
@@ -43,7 +43,7 @@
uint32_t plnum);
~PlayerDescriptionGroup();
- void refresh();
+ void update();
private:
void enable_player(bool);
Follow ups