@@ -1545,6 +1545,9 @@ class Game {
1545
1545
void showOverlayMessage (const wchar_t *msg, float dtime, int percent,
1546
1546
bool draw_clouds = true );
1547
1547
1548
+ static void settingChangedCallback (const std::string &setting_name, void *data);
1549
+ void readSettings ();
1550
+
1548
1551
private:
1549
1552
InputHandler *input;
1550
1553
@@ -1616,10 +1619,7 @@ class Game {
1616
1619
1617
1620
IntervalLimiter profiler_interval;
1618
1621
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
+ /*
1623
1623
* TODO: Local caching of settings is not optimal and should at some stage
1624
1624
* be updated to use a global settings object for getting thse values
1625
1625
* (as opposed to the this local caching). This can be addressed in
@@ -1662,15 +1662,22 @@ Game::Game() :
1662
1662
hud(NULL ),
1663
1663
mapper(NULL )
1664
1664
{
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 ();
1674
1681
1675
1682
#ifdef __ANDROID__
1676
1683
m_cache_hold_aux1 = false ; // This is initialised properly later
@@ -1705,6 +1712,21 @@ Game::~Game()
1705
1712
delete draw_control;
1706
1713
1707
1714
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 );
1708
1730
}
1709
1731
1710
1732
bool Game::startup (bool *kill,
@@ -4287,6 +4309,23 @@ void Game::showOverlayMessage(const wchar_t *msg, float dtime,
4287
4309
delete[] msg;
4288
4310
}
4289
4311
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
+ }
4290
4329
4291
4330
/* ***************************************************************************/
4292
4331
/* ***************************************************************************
0 commit comments