1
0
mirror of https://github.com/minetest/minetest.git synced 2025-07-06 01:40:21 +02: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)

View File

@ -24,7 +24,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "constants.h"
#include "settings.h"
#include "lighting.h"
#include <list>
class Client;
class Environment;
@ -39,14 +38,33 @@ enum class LocalPlayerAnimation
NO_ANIM,
WALK_ANIM,
DIG_ANIM,
WD_ANIM
}; // no local animation, walking, digging, both
WD_ANIM // walking + digging
};
struct PlayerSettings
{
bool free_move = false;
bool pitch_move = false;
bool fast_move = false;
bool continuous_forward = false;
bool always_fly_fast = false;
bool aux1_descends = false;
bool noclip = false;
bool autojump = false;
void readGlobalSettings();
void registerSettingsCallback();
void deregisterSettingsCallback();
private:
static void settingsChangedCallback(const std::string &name, void *data);
};
class LocalPlayer : public Player
{
public:
LocalPlayer(Client *client, const char *name);
virtual ~LocalPlayer() = default;
virtual ~LocalPlayer();
// Initialize hp to 0, so that no hearts will be shown if server
// doesn't support health points
@ -161,6 +179,8 @@ public:
inline Lighting& getLighting() { return m_lighting; }
inline PlayerSettings &getPlayerSettings() { return m_player_settings; }
private:
void accelerate(const v3f &target_speed, const f32 max_increase_H,
const f32 max_increase_V, const bool use_pitch);
@ -211,5 +231,7 @@ private:
GenericCAO *m_cao = nullptr;
Client *m_client;
PlayerSettings m_player_settings;
Lighting m_lighting;
};