Skip to content

Commit 2c4a5e1

Browse files
committed
Revert "Make the GameGlobalShaderConstantSetter use the settings callback (8% perf improvement in game loop)"
This reverts commit a555e2d.
1 parent 800d192 commit 2c4a5e1

File tree

4 files changed

+11
-27
lines changed

4 files changed

+11
-27
lines changed

src/fontengine.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
3636
FontEngine* g_fontengine = NULL;
3737

3838
/** callback to be used on change of font size setting */
39-
static void font_setting_changed(const std::string, void *userdata) {
39+
static void font_setting_changed(const std::string) {
4040
g_fontengine->readSettings();
4141
}
4242

src/game.cpp

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -809,31 +809,15 @@ class GameGlobalShaderConstantSetter : public IShaderConstantSetter
809809
bool *m_force_fog_off;
810810
f32 *m_fog_range;
811811
Client *m_client;
812-
bool m_fogEnabled;
813812

814813
public:
815-
816-
void onSettingsChange(const std::string &name)
817-
{
818-
if (name == "enable_fog")
819-
m_fogEnabled = g_settings->getBool("enable_fog");
820-
}
821-
822-
static void SettingsCallback(const std::string name, void *userdata)
823-
{
824-
reinterpret_cast<GameGlobalShaderConstantSetter*>(userdata)->onSettingsChange(name);
825-
}
826-
827814
GameGlobalShaderConstantSetter(Sky *sky, bool *force_fog_off,
828815
f32 *fog_range, Client *client) :
829816
m_sky(sky),
830817
m_force_fog_off(force_fog_off),
831818
m_fog_range(fog_range),
832819
m_client(client)
833-
{
834-
g_settings->registerChangedCallback("enable_fog", SettingsCallback, this);
835-
}
836-
820+
{}
837821
~GameGlobalShaderConstantSetter() {}
838822

839823
virtual void onSetConstants(video::IMaterialRendererServices *services,
@@ -856,7 +840,7 @@ class GameGlobalShaderConstantSetter : public IShaderConstantSetter
856840
// Fog distance
857841
float fog_distance = 10000 * BS;
858842

859-
if (m_fogEnabled && !*m_force_fog_off)
843+
if (g_settings->getBool("enable_fog") && !*m_force_fog_off)
860844
fog_distance = *m_fog_range;
861845

862846
services->setPixelShaderConstant("fogDistance", &fog_distance, 1);

src/settings.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -965,15 +965,15 @@ void Settings::clearNoLock()
965965

966966

967967
void Settings::registerChangedCallback(std::string name,
968-
setting_changed_callback cbf, void *userdata)
968+
setting_changed_callback cbf)
969969
{
970-
m_callbacks[name].push_back(std::make_pair(cbf,userdata));
970+
m_callbacks[name].push_back(cbf);
971971
}
972972

973973

974974
void Settings::doCallbacks(const std::string name)
975975
{
976-
std::vector<std::pair<setting_changed_callback,void*> > tempvector;
976+
std::vector<setting_changed_callback> tempvector;
977977
{
978978
JMutexAutoLock lock(m_mutex);
979979
if (m_callbacks.find(name) != m_callbacks.end())
@@ -982,9 +982,9 @@ void Settings::doCallbacks(const std::string name)
982982
}
983983
}
984984

985-
std::vector<std::pair<setting_changed_callback, void*> >::iterator iter;
985+
std::vector<setting_changed_callback>::iterator iter;
986986
for (iter = tempvector.begin(); iter != tempvector.end(); iter++)
987987
{
988-
(iter->first)(name,iter->second);
988+
(*iter)(name);
989989
}
990990
}

src/settings.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class Settings;
3232
struct NoiseParams;
3333

3434
/** function type to register a changed callback */
35-
typedef void (*setting_changed_callback)(const std::string, void *userdata);
35+
typedef void (*setting_changed_callback)(const std::string);
3636

3737
enum ValueType {
3838
VALUETYPE_STRING,
@@ -204,7 +204,7 @@ class Settings {
204204
void clear();
205205
void updateValue(const Settings &other, const std::string &name);
206206
void update(const Settings &other);
207-
void registerChangedCallback(std::string name, setting_changed_callback cbf, void *userdata = NULL);
207+
void registerChangedCallback(std::string name, setting_changed_callback cbf);
208208

209209
private:
210210

@@ -215,7 +215,7 @@ class Settings {
215215

216216
std::map<std::string, SettingsEntry> m_settings;
217217
std::map<std::string, SettingsEntry> m_defaults;
218-
std::map<std::string, std::vector<std::pair<setting_changed_callback,void*> > > m_callbacks;
218+
std::map<std::string, std::vector<setting_changed_callback> > m_callbacks;
219219
// All methods that access m_settings/m_defaults directly should lock this.
220220
mutable JMutex m_mutex;
221221
};

0 commit comments

Comments
 (0)