Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Governor fixes #2301

Merged
merged 4 commits into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions client/attribute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,9 @@ void attribute_set(int key, int id, int x, int y, size_t data_length,
} else {
attribute_hash->remove(akey);
}

// Sync with the server
attribute_flush();
}

/**
Expand Down
14 changes: 1 addition & 13 deletions client/governor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@

static struct preset_list *preset_list = nullptr;

static void city_changed(int city_id);
static void city_remove(int city_id)
{
attr_city_set(ATTR_CITY_CMA_PARAMETER, city_id, 0, nullptr);
Expand Down Expand Up @@ -160,7 +159,7 @@ void governor::run()
continue;
}
if (pcity) {
city_changed(pcity->id);
gimb->handle_city(pcity);
}
}
scity_changed.clear();
Expand Down Expand Up @@ -630,15 +629,6 @@ void cma_yoloswag::handle_city(struct city *pcity)
log_handle_city2("END handle city=(%d)", city_id);
}

static void city_changed(int city_id)
{
struct city *pcity = game_city_by_number(city_id);

if (pcity) {
gimb->handle_city(pcity);
}
}

/**
Put city under governor control
*/
Expand Down Expand Up @@ -701,10 +691,8 @@ void cmafec_get_fe_parameter(struct city *pcity, struct cm_parameter *dest)
{
struct cm_parameter parameter;

// our fe_parameter could be stale. our agents parameter is uptodate
if (cma_is_city_under_agent(pcity, &parameter)) {
cm_copy_parameter(dest, &parameter);
cmafec_set_fe_parameter(pcity, dest);
} else {
// Create a dummy parameter to return.
cm_init_parameter(dest);
Expand Down
18 changes: 16 additions & 2 deletions client/widgets/city/governor_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

// Qt
#include <QSlider>
#include <QTimer>

namespace freeciv {

Expand Down Expand Up @@ -49,7 +50,7 @@ governor_widget::governor_widget(QWidget *parent) : QWidget(parent)
};
for (auto slider : sliders) {
connect(slider, &QSlider::valueChanged, this,
&governor_widget::emit_params_changed);
&governor_widget::queue_params_changed);
}

const auto checkboxes = {
Expand All @@ -60,7 +61,7 @@ governor_widget::governor_widget(QWidget *parent) : QWidget(parent)
};
for (auto box : checkboxes) {
connect(box, &QCheckBox::toggled, this,
&governor_widget::emit_params_changed);
&governor_widget::queue_params_changed);
}
}

Expand Down Expand Up @@ -130,6 +131,19 @@ void governor_widget::set_parameters(const cm_parameter &params)
void governor_widget::emit_params_changed()
{
emit parameters_changed(parameters());
m_dirty = false;
}

/**
* Queues an update of the parameters. This prevents emitting
* parameters_changed, and thus recalculating the results, too often.
*/
void governor_widget::queue_params_changed()
{
if (!m_dirty) {
QTimer::singleShot(100, this, &governor_widget::emit_params_changed);
m_dirty = true;
}
}

} // namespace freeciv
3 changes: 3 additions & 0 deletions client/widgets/city/governor_widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ class governor_widget : public QWidget {

private:
void emit_params_changed();
void queue_params_changed();

bool m_dirty = false; ///< Whether we need to propagate a params update.
};

} // namespace freeciv
Loading