Reenable fog toggle unless server restricts fog distance (#14634)

see comments in #14539
This commit is contained in:
sfan5 2024-05-14 18:31:51 +02:00 committed by GitHub
parent 5a4d7fb0d6
commit c38e0d05bf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 23 additions and 22 deletions

@ -381,8 +381,7 @@ crosshair_alpha (Crosshair alpha) int 255 0 255
[**Fog] [**Fog]
# Whether to fog out the end of the visible area. This option only works # Whether to fog out the end of the visible area.
# with the 'debug' privilege.
enable_fog (Fog) bool true enable_fog (Fog) bool true
# Make fog and sky colors depend on daytime (dawn/sunset) and view direction. # Make fog and sky colors depend on daytime (dawn/sunset) and view direction.
@ -2511,7 +2510,7 @@ keymap_toggle_chat (Chat toggle key) key KEY_F2
# Key for toggling the display of the large chat console. # Key for toggling the display of the large chat console.
keymap_console (Large chat console key) key KEY_F10 keymap_console (Large chat console key) key KEY_F10
# Key for toggling the display of fog. Only usable with 'debug' privilege. # Key for toggling the display of fog.
keymap_toggle_fog (Fog toggle key) key KEY_F3 keymap_toggle_fog (Fog toggle key) key KEY_F3
# Key for toggling the camera update. Only usable with 'debug' privilege. # Key for toggling the camera update. Only usable with 'debug' privilege.

@ -8257,14 +8257,13 @@ child will follow movement and rotation of that bone.
`"default"` uses the classic Minetest sun and moon tinting. `"default"` uses the classic Minetest sun and moon tinting.
Will use tonemaps, if set to `"default"`. (default: `"default"`) Will use tonemaps, if set to `"default"`. (default: `"default"`)
* `fog`: A table with following optional fields: * `fog`: A table with following optional fields:
* `fog_distance`: integer, set an upper bound the client's viewing_range (inluding range_all). * `fog_distance`: integer, set an upper bound for the client's viewing_range.
By default, fog_distance is controlled by the client's viewing_range, and this field is not set. Any value >= 0 sets the desired upper bound for viewing_range,
Any value >= 0 sets the desired upper bound for the client's viewing_range and disables range_all. disables range_all and prevents disabling fog (F3 key by default).
Any value < 0, resets the behavior to being client-controlled. Any value < 0 resets the behavior to being client-controlled.
(default: -1) (default: -1)
* `fog_start`: float, override the client's fog_start. * `fog_start`: float, override the client's fog_start.
Fraction of the visible distance at which fog starts to be rendered. Fraction of the visible distance at which fog starts to be rendered.
By default, fog_start is controlled by the client's `fog_start` setting, and this field is not set.
Any value between [0.0, 0.99] set the fog_start as a fraction of the viewing_range. Any value between [0.0, 0.99] set the fog_start as a fraction of the viewing_range.
Any value < 0, resets the behavior to being client-controlled. Any value < 0, resets the behavior to being client-controlled.
(default: -1) (default: -1)

@ -792,6 +792,14 @@ protected:
void showOverlayMessage(const char *msg, float dtime, int percent, void showOverlayMessage(const char *msg, float dtime, int percent,
bool draw_clouds = true); bool draw_clouds = true);
inline bool fogEnabled()
{
// Client setting only takes effect if fog distance unlimited or debug priv
if (sky->getFogDistance() < 0 || client->checkPrivilege("debug"))
return m_cache_enable_fog;
return true;
}
static void settingChangedCallback(const std::string &setting_name, void *data); static void settingChangedCallback(const std::string &setting_name, void *data);
void readSettings(); void readSettings();
@ -2467,15 +2475,12 @@ void Game::toggleMinimap(bool shift_pressed)
void Game::toggleFog() void Game::toggleFog()
{ {
bool flag; bool flag = !g_settings->getBool("enable_fog");
// do not modify setting if no privilege g_settings->setBool("enable_fog", flag);
if (!client->checkPrivilege("debug")) { bool allowed = sky->getFogDistance() < 0 || client->checkPrivilege("debug");
flag = true; if (!allowed)
} else { m_game_ui->showTranslatedStatusText("Fog enabled by game or mod");
flag = !g_settings->getBool("enable_fog"); else if (flag)
g_settings->setBool("enable_fog", flag);
}
if (flag)
m_game_ui->showTranslatedStatusText("Fog enabled"); m_game_ui->showTranslatedStatusText("Fog enabled");
else else
m_game_ui->showTranslatedStatusText("Fog disabled"); m_game_ui->showTranslatedStatusText("Fog disabled");
@ -4230,8 +4235,7 @@ void Game::updateClouds(float dtime)
camera_node_position.Y = camera_node_position.Y + camera_offset.Y * BS; camera_node_position.Y = camera_node_position.Y + camera_offset.Y * BS;
camera_node_position.Z = camera_node_position.Z + camera_offset.Z * BS; camera_node_position.Z = camera_node_position.Z + camera_offset.Z * BS;
this->clouds->update(camera_node_position, this->sky->getCloudColor()); this->clouds->update(camera_node_position, this->sky->getCloudColor());
bool enable_fog = this->m_cache_enable_fog || !client->checkPrivilege("debug"); if (this->clouds->isCameraInsideCloud() && this->fogEnabled()) {
if (this->clouds->isCameraInsideCloud() && enable_fog) {
// If camera is inside cloud and fog is enabled, use cloud's colors as sky colors. // If camera is inside cloud and fog is enabled, use cloud's colors as sky colors.
video::SColor clouds_dark = this->clouds->getColor().getInterpolated( video::SColor clouds_dark = this->clouds->getColor().getInterpolated(
video::SColor(255, 0, 0, 0), 0.9); video::SColor(255, 0, 0, 0), 0.9);
@ -4291,7 +4295,7 @@ void Game::drawScene(ProfilerGraph *graph, RunStats *stats)
/* /*
Fog Fog
*/ */
if (this->m_cache_enable_fog || !client->checkPrivilege("debug")) { if (this->fogEnabled()) {
this->driver->setFog( this->driver->setFog(
fog_color, fog_color,
video::EFT_FOG_LINEAR, video::EFT_FOG_LINEAR,

@ -172,11 +172,10 @@ void set_default_settings()
settings->setDefault("keymap_toggle_block_bounds", ""); settings->setDefault("keymap_toggle_block_bounds", "");
settings->setDefault("keymap_toggle_hud", "KEY_F1"); settings->setDefault("keymap_toggle_hud", "KEY_F1");
settings->setDefault("keymap_toggle_chat", "KEY_F2"); settings->setDefault("keymap_toggle_chat", "KEY_F2");
#ifndef NDEBUG
settings->setDefault("keymap_toggle_fog", "KEY_F3"); settings->setDefault("keymap_toggle_fog", "KEY_F3");
#ifndef NDEBUG
settings->setDefault("keymap_toggle_update_camera", "KEY_F4"); settings->setDefault("keymap_toggle_update_camera", "KEY_F4");
#else #else
settings->setDefault("keymap_toggle_fog", "");
settings->setDefault("keymap_toggle_update_camera", ""); settings->setDefault("keymap_toggle_update_camera", "");
#endif #endif
settings->setDefault("keymap_toggle_debug", "KEY_F5"); settings->setDefault("keymap_toggle_debug", "KEY_F5");