1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

PlayerSettings struct for player movement code (#7243)

Instead of calling g_settings->getBool("flag") multiple times
during each movement step, the current settings are cached
in a new player object member. Updated via registered callbacks.
This commit is contained in:
Ben Deutsch 2018-04-18 20:56:01 +02:00 committed by SmallJoker
parent b1e58c9c35
commit 3eac249464
3 changed files with 63 additions and 15 deletions

View file

@ -74,6 +74,20 @@ Player::Player(const char *name, IItemDefManager *idef):
HUD_FLAG_MINIMAP_RADAR_VISIBLE;
hud_hotbar_itemcount = HUD_HOTBAR_ITEMCOUNT_DEFAULT;
m_player_settings.readGlobalSettings();
g_settings->registerChangedCallback("free_move", &Player::settingsChangedCallback,
&m_player_settings);
g_settings->registerChangedCallback("fast_move", &Player::settingsChangedCallback,
&m_player_settings);
g_settings->registerChangedCallback("continuous_forward",
&Player::settingsChangedCallback, &m_player_settings);
g_settings->registerChangedCallback("always_fly_fast",
&Player::settingsChangedCallback, &m_player_settings);
g_settings->registerChangedCallback("aux1_descends",
&Player::settingsChangedCallback, &m_player_settings);
g_settings->registerChangedCallback(
"noclip", &Player::settingsChangedCallback, &m_player_settings);
}
Player::~Player()
@ -126,3 +140,18 @@ void Player::clearHud()
hud.pop_back();
}
}
void PlayerSettings::readGlobalSettings()
{
free_move = g_settings->getBool("free_move");
fast_move = g_settings->getBool("fast_move");
continuous_forward = g_settings->getBool("continuous_forward");
always_fly_fast = g_settings->getBool("always_fly_fast");
aux1_descends = g_settings->getBool("aux1_descends");
noclip = g_settings->getBool("noclip");
}
void Player::settingsChangedCallback(const std::string &name, void *data)
{
((PlayerSettings *)data)->readGlobalSettings();
}