mirror of
https://github.com/luanti-org/luanti.git
synced 2025-10-05 19:31:04 +00:00
Add setting callbacks for Camera and TouchControls (#15700)
This commit is contained in:
parent
b5e084c9a5
commit
41dfac96c1
6 changed files with 71 additions and 25 deletions
|
@ -33,6 +33,11 @@ static constexpr f32 CAMERA_OFFSET_STEP = 200;
|
|||
#define WIELDMESH_AMPLITUDE_X 7.0f
|
||||
#define WIELDMESH_AMPLITUDE_Y 10.0f
|
||||
|
||||
static const char *setting_names[] = {
|
||||
"fall_bobbing_amount", "view_bobbing_amount", "fov", "arm_inertia",
|
||||
"show_nametag_backgrounds",
|
||||
};
|
||||
|
||||
Camera::Camera(MapDrawControl &draw_control, Client *client, RenderingEngine *rendering_engine):
|
||||
m_draw_control(draw_control),
|
||||
m_client(client),
|
||||
|
@ -54,11 +59,21 @@ Camera::Camera(MapDrawControl &draw_control, Client *client, RenderingEngine *re
|
|||
m_wieldnode->setItem(ItemStack(), m_client);
|
||||
m_wieldnode->drop(); // m_wieldmgr grabbed it
|
||||
|
||||
/* TODO: Add a callback function so these can be updated when a setting
|
||||
* changes. At this point in time it doesn't matter (e.g. /set
|
||||
* is documented to change server settings only)
|
||||
*
|
||||
* TODO: Local caching of settings is not optimal and should at some stage
|
||||
m_nametags.clear();
|
||||
|
||||
readSettings();
|
||||
for (auto name : setting_names)
|
||||
g_settings->registerChangedCallback(name, settingChangedCallback, this);
|
||||
}
|
||||
|
||||
void Camera::settingChangedCallback(const std::string &name, void *data)
|
||||
{
|
||||
static_cast<Camera *>(data)->readSettings();
|
||||
}
|
||||
|
||||
void Camera::readSettings()
|
||||
{
|
||||
/* TODO: Local caching of settings is not optimal and should at some stage
|
||||
* be updated to use a global settings object for getting thse values
|
||||
* (as opposed to the this local caching). This can be addressed in
|
||||
* a later release.
|
||||
|
@ -69,12 +84,12 @@ Camera::Camera(MapDrawControl &draw_control, Client *client, RenderingEngine *re
|
|||
// as a zoom FOV and load world beyond the set server limits.
|
||||
m_cache_fov = g_settings->getFloat("fov", 45.0f, 160.0f);
|
||||
m_arm_inertia = g_settings->getBool("arm_inertia");
|
||||
m_nametags.clear();
|
||||
m_show_nametag_backgrounds = g_settings->getBool("show_nametag_backgrounds");
|
||||
}
|
||||
|
||||
Camera::~Camera()
|
||||
{
|
||||
g_settings->deregisterAllChangedCallbacks(this);
|
||||
m_wieldmgr->drop();
|
||||
}
|
||||
|
||||
|
|
|
@ -70,6 +70,9 @@ public:
|
|||
Camera(MapDrawControl &draw_control, Client *client, RenderingEngine *rendering_engine);
|
||||
~Camera();
|
||||
|
||||
static void settingChangedCallback(const std::string &name, void *data);
|
||||
void readSettings();
|
||||
|
||||
// Get camera scene node.
|
||||
// It has the eye transformation, pitch and view bobbing applied.
|
||||
inline scene::ICameraSceneNode* getCameraNode() const
|
||||
|
|
|
@ -820,6 +820,8 @@ Game::Game() :
|
|||
&settingChangedCallback, this);
|
||||
g_settings->registerChangedCallback("pause_on_lost_focus",
|
||||
&settingChangedCallback, this);
|
||||
g_settings->registerChangedCallback("touch_use_crosshair",
|
||||
&settingChangedCallback, this);
|
||||
|
||||
readSettings();
|
||||
}
|
||||
|
@ -896,8 +898,6 @@ bool Game::startup(bool *kill,
|
|||
|
||||
m_first_loop_after_window_activation = true;
|
||||
|
||||
m_touch_use_crosshair = g_settings->getBool("touch_use_crosshair");
|
||||
|
||||
g_client_translations->clear();
|
||||
|
||||
// address can change if simple_singleplayer_mode
|
||||
|
@ -4111,6 +4111,10 @@ void Game::readSettings()
|
|||
m_invert_hotbar_mouse_wheel = g_settings->getBool("invert_hotbar_mouse_wheel");
|
||||
|
||||
m_does_lost_focus_pause_game = g_settings->getBool("pause_on_lost_focus");
|
||||
|
||||
m_touch_use_crosshair = g_settings->getBool("touch_use_crosshair");
|
||||
if (g_touchcontrols)
|
||||
g_touchcontrols->setUseCrosshair(!isTouchCrosshairDisabled());
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue