Skip to content

Commit a670ecf

Browse files
committedAug 13, 2015
game.cpp: Update cached settings
1 parent def274a commit a670ecf

File tree

1 file changed

+52
-13
lines changed

1 file changed

+52
-13
lines changed
 

Diff for: ‎src/game.cpp

+52-13
Original file line numberDiff line numberDiff line change
@@ -1545,6 +1545,9 @@ class Game {
15451545
void showOverlayMessage(const wchar_t *msg, float dtime, int percent,
15461546
bool draw_clouds = true);
15471547

1548+
static void settingChangedCallback(const std::string &setting_name, void *data);
1549+
void readSettings();
1550+
15481551
private:
15491552
InputHandler *input;
15501553

@@ -1616,10 +1619,7 @@ class Game {
16161619

16171620
IntervalLimiter profiler_interval;
16181621

1619-
/* TODO: Add a callback function so these can be updated when a setting
1620-
* changes. At this point in time it doesn't matter (e.g. /set
1621-
* is documented to change server settings only)
1622-
*
1622+
/*
16231623
* TODO: Local caching of settings is not optimal and should at some stage
16241624
* be updated to use a global settings object for getting thse values
16251625
* (as opposed to the this local caching). This can be addressed in
@@ -1662,15 +1662,22 @@ Game::Game() :
16621662
hud(NULL),
16631663
mapper(NULL)
16641664
{
1665-
m_cache_doubletap_jump = g_settings->getBool("doubletap_jump");
1666-
m_cache_enable_node_highlighting = g_settings->getBool("enable_node_highlighting");
1667-
m_cache_enable_clouds = g_settings->getBool("enable_clouds");
1668-
m_cache_enable_particles = g_settings->getBool("enable_particles");
1669-
m_cache_enable_fog = g_settings->getBool("enable_fog");
1670-
m_cache_mouse_sensitivity = g_settings->getFloat("mouse_sensitivity");
1671-
m_repeat_right_click_time = g_settings->getFloat("repeat_rightclick_time");
1672-
1673-
m_cache_mouse_sensitivity = rangelim(m_cache_mouse_sensitivity, 0.001, 100.0);
1665+
g_settings->registerChangedCallback("doubletap_jump",
1666+
&settingChangedCallback, this);
1667+
g_settings->registerChangedCallback("enable_node_highlighting",
1668+
&settingChangedCallback, this);
1669+
g_settings->registerChangedCallback("enable_clouds",
1670+
&settingChangedCallback, this);
1671+
g_settings->registerChangedCallback("enable_particles",
1672+
&settingChangedCallback, this);
1673+
g_settings->registerChangedCallback("enable_fog",
1674+
&settingChangedCallback, this);
1675+
g_settings->registerChangedCallback("mouse_sensitivity",
1676+
&settingChangedCallback, this);
1677+
g_settings->registerChangedCallback("repeat_rightclick_time",
1678+
&settingChangedCallback, this);
1679+
1680+
readSettings();
16741681

16751682
#ifdef __ANDROID__
16761683
m_cache_hold_aux1 = false; // This is initialised properly later
@@ -1705,6 +1712,21 @@ Game::~Game()
17051712
delete draw_control;
17061713

17071714
extendedResourceCleanup();
1715+
1716+
g_settings->deregisterChangedCallback("doubletap_jump",
1717+
&settingChangedCallback, this);
1718+
g_settings->deregisterChangedCallback("enable_node_highlighting",
1719+
&settingChangedCallback, this);
1720+
g_settings->deregisterChangedCallback("enable_clouds",
1721+
&settingChangedCallback, this);
1722+
g_settings->deregisterChangedCallback("enable_particles",
1723+
&settingChangedCallback, this);
1724+
g_settings->deregisterChangedCallback("enable_fog",
1725+
&settingChangedCallback, this);
1726+
g_settings->deregisterChangedCallback("mouse_sensitivity",
1727+
&settingChangedCallback, this);
1728+
g_settings->deregisterChangedCallback("repeat_rightclick_time",
1729+
&settingChangedCallback, this);
17081730
}
17091731

17101732
bool Game::startup(bool *kill,
@@ -4287,6 +4309,23 @@ void Game::showOverlayMessage(const wchar_t *msg, float dtime,
42874309
delete[] msg;
42884310
}
42894311

4312+
void Game::settingChangedCallback(const std::string &setting_name, void *data)
4313+
{
4314+
((Game *)data)->readSettings();
4315+
}
4316+
4317+
void Game::readSettings()
4318+
{
4319+
m_cache_doubletap_jump = g_settings->getBool("doubletap_jump");
4320+
m_cache_enable_node_highlighting = g_settings->getBool("enable_node_highlighting");
4321+
m_cache_enable_clouds = g_settings->getBool("enable_clouds");
4322+
m_cache_enable_particles = g_settings->getBool("enable_particles");
4323+
m_cache_enable_fog = g_settings->getBool("enable_fog");
4324+
m_cache_mouse_sensitivity = g_settings->getFloat("mouse_sensitivity");
4325+
m_repeat_right_click_time = g_settings->getFloat("repeat_rightclick_time");
4326+
4327+
m_cache_mouse_sensitivity = rangelim(m_cache_mouse_sensitivity, 0.001, 100.0);
4328+
}
42904329

42914330
/****************************************************************************/
42924331
/****************************************************************************

0 commit comments

Comments
 (0)
Please sign in to comment.