Skip to content

Commit 826b95b

Browse files
authored
fix(settings): remove useless calls to updateState (#1296)
On every setting update (commited or not), updateState would be called in ModsLayer, ModPopup (if it's active), and all ModItems that are enabled. This obviously led to bad performance. This commit just checks if the value change is commited before calling updateState on ModsLayer, ModItem and ModPopup
1 parent dd7ee00 commit 826b95b

File tree

4 files changed

+19
-3
lines changed

4 files changed

+19
-3
lines changed

loader/src/loader/SettingNodeV3.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,11 @@ class NumberSettingNodeV3 : public SettingValueNodeV3<S> {
222222
this->setValue(value, static_cast<CCNode*>(sender));
223223
}
224224
void onSlider(CCObject*) {
225-
this->setValue(this->valueFromSlider(m_slider->m_touchLogic->m_thumb->getValue()), m_slider);
225+
auto value = this->valueFromSlider(m_slider->m_touchLogic->m_thumb->getValue());
226+
227+
if (value != this->getValue()) {
228+
this->setValue(value, m_slider);
229+
}
226230
}
227231

228232
public:

loader/src/ui/mods/ModsLayer.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <Geode/ui/BasedButtonSprite.hpp>
55
#include <Geode/utils/file.hpp>
66
#include <Geode/cocos/cocoa/CCObject.h>
7+
#include <Geode/loader/Event.hpp>
78
#include "SwelvyBG.hpp"
89
#include <Geode/ui/TextInput.hpp>
910
#include <Geode/utils/ColorProvider.hpp>
@@ -91,6 +92,9 @@ bool ModsStatusNode::init() {
9192
m_downloadListener.bind([this](auto) { this->updateState(); });
9293

9394
m_settingNodeListener.bind([this](SettingNodeValueChangeEvent* ev) {
95+
if (!ev->isCommit()) {
96+
return ListenerResult::Propagate;
97+
}
9498
this->updateState();
9599
return ListenerResult::Propagate;
96100
});

loader/src/ui/mods/list/ModItem.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <Geode/ui/GeodeUI.hpp>
88
#include <Geode/utils/ColorProvider.hpp>
99
#include <Geode/binding/ButtonSprite.hpp>
10+
#include <Geode/loader/Event.hpp>
1011
#include <Geode/loader/Loader.hpp>
1112
#include "server/DownloadManager.hpp"
1213
#include "ui/mods/GeodeStyle.hpp"
@@ -350,7 +351,10 @@ bool ModItem::init(ModSource&& source) {
350351
m_downloadListener.bind([this](auto) { this->updateState(); });
351352
m_downloadListener.setFilter(server::ModDownloadFilter(m_source.getID()));
352353

353-
m_settingNodeListener.bind([this](SettingNodeValueChangeEvent*) {
354+
m_settingNodeListener.bind([this](SettingNodeValueChangeEvent* ev) {
355+
if (!ev->isCommit()) {
356+
return ListenerResult::Propagate;
357+
}
354358
this->updateState();
355359
return ListenerResult::Propagate;
356360
});

loader/src/ui/mods/popups/ModPopup.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <Geode/ui/MDTextArea.hpp>
77
#include <Geode/ui/TextInput.hpp>
88
#include <Geode/utils/web.hpp>
9+
#include <Geode/loader/Event.hpp>
910
#include <Geode/loader/Loader.hpp>
1011
#include <Geode/loader/ModSettingsManager.hpp>
1112
#include <Geode/ui/GeodeUI.hpp>
@@ -646,7 +647,10 @@ bool ModPopup::setup(ModSource&& src) {
646647
m_downloadListener.bind([this](auto) { this->updateState(); });
647648
m_downloadListener.setFilter(m_source.getID());
648649

649-
m_settingNodeListener.bind([this](SettingNodeValueChangeEvent*) {
650+
m_settingNodeListener.bind([this](SettingNodeValueChangeEvent* ev) {
651+
if (!ev->isCommit()) {
652+
return ListenerResult::Propagate;
653+
}
650654
this->updateState();
651655
return ListenerResult::Propagate;
652656
});

0 commit comments

Comments
 (0)