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

Move PlayerSettings class to client code

This commit is contained in:
sfan5 2024-02-29 15:13:52 +01:00
parent c524c52baa
commit badd42789a
4 changed files with 83 additions and 59 deletions

View file

@ -28,6 +28,49 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "client.h"
#include "content_cao.h"
/*
PlayerSettings
*/
const static std::string PlayerSettings_names[] = {
"free_move", "pitch_move", "fast_move", "continuous_forward", "always_fly_fast",
"aux1_descends", "noclip", "autojump"
};
void PlayerSettings::readGlobalSettings()
{
free_move = g_settings->getBool("free_move");
pitch_move = g_settings->getBool("pitch_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");
autojump = g_settings->getBool("autojump");
}
void PlayerSettings::registerSettingsCallback()
{
for (auto &name : PlayerSettings_names) {
g_settings->registerChangedCallback(name,
&PlayerSettings::settingsChangedCallback, this);
}
}
void PlayerSettings::deregisterSettingsCallback()
{
for (auto &name : PlayerSettings_names) {
g_settings->deregisterChangedCallback(name,
&PlayerSettings::settingsChangedCallback, this);
}
}
void PlayerSettings::settingsChangedCallback(const std::string &name, void *data)
{
((PlayerSettings *)data)->readGlobalSettings();
}
/*
LocalPlayer
*/
@ -36,6 +79,13 @@ LocalPlayer::LocalPlayer(Client *client, const char *name):
Player(name, client->idef()),
m_client(client)
{
m_player_settings.readGlobalSettings();
m_player_settings.registerSettingsCallback();
}
LocalPlayer::~LocalPlayer()
{
m_player_settings.deregisterSettingsCallback();
}
static aabb3f getNodeBoundingBox(const std::vector<aabb3f> &nodeboxes)