From de5328c851e0eca38ef82ad3ee6893d15f4ac08e Mon Sep 17 00:00:00 2001 From: MirceaKitsune Date: Wed, 23 Apr 2025 22:53:42 +0300 Subject: [PATCH] Convert transparency flag to skybox types --- doc/lua_api.md | 10 ++++------ src/client/game.cpp | 9 ++++----- src/client/sky.cpp | 4 ++-- src/client/sky.h | 4 ++-- src/network/clientpackethandler.cpp | 12 +++++++----- src/script/lua_api/l_object.cpp | 13 ++++--------- src/server.cpp | 8 +++++--- src/skyparams.h | 2 -- 8 files changed, 28 insertions(+), 34 deletions(-) diff --git a/doc/lua_api.md b/doc/lua_api.md index e77410eaa..f625f757c 100644 --- a/doc/lua_api.md +++ b/doc/lua_api.md @@ -8781,6 +8781,8 @@ child will follow movement and rotation of that bone. * `type`: Available types: * `"regular"`: Uses 0 textures, `base_color` ignored * `"skybox"`: Uses 6 textures, `base_color` used as fog. + * `"skybox_back"`: Uses 6 textures, `sky_color` used as fog, stars / sun / moon in foreground. + * `"skybox_front"`: Uses 6 textures, `sky_color` used as fog, stars / sun / moon in background. * `"plain"`: Uses 0 textures, `base_color` used as both fog and sky. (default: `"regular"`) * `textures`: A table containing up to six textures in the following @@ -8789,13 +8791,9 @@ child will follow movement and rotation of that bone. bottom texture and the bottom edge of the top texture touch the east face). Some top and bottom textures expect to be aligned with the north face and will need to be rotated by -90 and 90 degrees, respectively, to fit the eastward orientation. - * `transparency`: Used by the `"skybox"` type. The type of transparency to use. (default: `"solid"`) - * `"solid"`: For textures without an alpha channel, `sky_color` is not used. - * `"transparent_back"`: Show stars / sun / moon over the alpha channel, `sky_color` is used. - * `"transparent_front"`: Show stars / sun / moon behind the alpha channel, `sky_color` is used. * `clouds`: Boolean for whether clouds appear. (default: `true`) - * `sky_color`: A table used in `"regular"` and `"skybox"` types only. If used with the later, - the `textures` should have an alpha channel. Contains the following values (alpha is ignored): + * `sky_color`: A table used in `"regular"`, `"skybox_back"`, `"skybox_front"` types only. For a skybox + the `textures` should have an alpha channel. Contains the following values (alpha is ignored): * `day_sky`: ColorSpec, for the top half of the sky during the day. (default: `#61b5f5`) * `day_horizon`: ColorSpec, for the bottom half of the sky during the day. diff --git a/src/client/game.cpp b/src/client/game.cpp index 0cfdfab12..b16ba9db8 100644 --- a/src/client/game.cpp +++ b/src/client/game.cpp @@ -2848,9 +2848,9 @@ void Game::handleClientEvent_HudChange(ClientEvent *event, CameraOrientation *ca void Game::handleClientEvent_SetSky(ClientEvent *event, CameraOrientation *cam) { sky->setVisible(false); + sky->setType(event->set_sky->type); // Whether clouds are visible in front of a custom skybox. sky->setCloudsEnabled(event->set_sky->clouds); - sky->setTransparency(event->set_sky->transparency); // Clear the old textures out in case we switch rendering type. sky->clearSkyboxTextures(); @@ -2865,11 +2865,10 @@ void Game::handleClientEvent_SetSky(ClientEvent *event, CameraOrientation *cam) event->set_sky->fog_moon_tint, event->set_sky->fog_tint_type ); - } else if (event->set_sky->type == "skybox" && - event->set_sky->textures.size() == 6) { - const bool transparent = event->set_sky->transparency != "solid"; - + } else if ((event->set_sky->type == "skybox" || event->set_sky->type == "skybox_back" || + event->set_sky->type == "skybox_front") && event->set_sky->textures.size() == 6) { // Show the mesh and sky colors only if transparency is used. + const bool transparent = event->set_sky->type == "skybox_back" || event->set_sky->type == "skybox_front"; if(transparent) { sky->setVisible(true); sky->setSkyColors(event->set_sky->sky_color); diff --git a/src/client/sky.cpp b/src/client/sky.cpp index 7a7652661..b4c589749 100644 --- a/src/client/sky.cpp +++ b/src/client/sky.cpp @@ -211,7 +211,7 @@ void Sky::render() return; // Draw the six sided skybox, solid or transparent background. - if(has_tex && (m_transparency == "solid" || m_transparency == "transparent_back")) + if(has_tex && (m_type == "skybox" || m_type == "skybox_back")) renderTextures(driver); // Draw far cloudy fog thing blended with skycolor @@ -317,7 +317,7 @@ void Sky::render() } // Draw the six sided skybox, transparent foreground. - if(has_tex && m_transparency == "transparent_front") + if(has_tex && m_type == "skybox_front") renderTextures(driver); } } diff --git a/src/client/sky.h b/src/client/sky.h index 00eb29256..0589ff50b 100644 --- a/src/client/sky.h +++ b/src/client/sky.h @@ -83,9 +83,9 @@ public: const video::SColorf &getCloudColor() const { return m_cloudcolor_f; } void setVisible(bool visible) { m_visible = visible; } + void setType(std::string type) { m_type = type; } // Set only from set_sky API - void setTransparency(std::string transparency) { m_transparency = transparency; } void setCloudsEnabled(bool clouds_enabled) { m_clouds_enabled = clouds_enabled; } void setFallbackBgColor(video::SColor fallback_bg_color) { @@ -164,6 +164,7 @@ private: } bool m_visible = true; + std::string m_type = "regular"; // Used when m_visible=false video::SColor m_fallback_bg_color = video::SColor(255, 255, 255, 255); bool m_first_update = true; // Set before the sky is updated for the first time @@ -176,7 +177,6 @@ private: bool m_clouds_enabled = true; // Initialised to true, reset only by set_sky API bool m_directional_colored_fog; bool m_in_clouds = true; // Prevent duplicating bools to remember old values - std::string m_transparency = "solid"; // Type of transparency used video::SColorf m_bgcolor_bright_f = video::SColorf(1.0f, 1.0f, 1.0f, 1.0f); video::SColorf m_skycolor_bright_f = video::SColorf(1.0f, 1.0f, 1.0f, 1.0f); diff --git a/src/network/clientpackethandler.cpp b/src/network/clientpackethandler.cpp index e9207d4b5..3f5115ed9 100644 --- a/src/network/clientpackethandler.cpp +++ b/src/network/clientpackethandler.cpp @@ -1290,7 +1290,6 @@ void Client::handleCommand_HudSetSky(NetworkPacket* pkt) SkyboxParams skybox; skybox.bgcolor = video::SColor(readARGB8(is)); skybox.type = std::string(deSerializeString16(is)); - skybox.transparency = std::string("solid"); u16 count = readU16(is); for (size_t i = 0; i < count; i++) @@ -1304,7 +1303,8 @@ void Client::handleCommand_HudSetSky(NetworkPacket* pkt) StarParams stars = SkyboxDefaults::getStarDefaults(); // Fix for "regular" and "skybox" skies, as color isn't kept: - if (skybox.type == "regular" || skybox.type == "skybox") { + if (skybox.type == "regular" || skybox.type == "skybox" || + skybox.type == "skybox_back" || skybox.type == "skybox_front") { skybox.sky_color = SkyboxDefaults::getSkyColorDefaults(); skybox.fog_tint_type = "default"; skybox.fog_moon_tint = video::SColor(255, 255, 255, 255); @@ -1341,10 +1341,11 @@ void Client::handleCommand_HudSetSky(NetworkPacket* pkt) SkyboxParams skybox; - *pkt >> skybox.bgcolor >> skybox.type >> skybox.transparency >> skybox.clouds >> + *pkt >> skybox.bgcolor >> skybox.type >> skybox.clouds >> skybox.fog_sun_tint >> skybox.fog_moon_tint >> skybox.fog_tint_type; - if (skybox.type == "skybox") { + if (skybox.type == "skybox" || + skybox.type == "skybox_back" || skybox.type == "skybox_front") { u16 texture_count; std::string texture; *pkt >> texture_count; @@ -1353,7 +1354,8 @@ void Client::handleCommand_HudSetSky(NetworkPacket* pkt) skybox.textures.emplace_back(texture); } } - if (skybox.type == "regular" || skybox.type == "skybox") { + if (skybox.type == "regular" || skybox.type == "skybox" || + skybox.type == "skybox_back" || skybox.type == "skybox_front") { auto &c = skybox.sky_color; *pkt >> c.day_sky >> c.day_horizon >> c.dawn_sky >> c.dawn_horizon >> c.night_sky >> c.night_horizon >> c.indoors; diff --git a/src/script/lua_api/l_object.cpp b/src/script/lua_api/l_object.cpp index 8c35c4212..09b234a6a 100644 --- a/src/script/lua_api/l_object.cpp +++ b/src/script/lua_api/l_object.cpp @@ -2044,14 +2044,10 @@ int ObjectRef::l_set_sky(lua_State *L) sky_params.type = luaL_checkstring(L, -1); lua_pop(L, 1); - lua_getfield(L, 2, "transparency"); - if (!lua_isnil(L, -1)) - sky_params.transparency = luaL_checkstring(L, -1); - lua_pop(L, 1); - lua_getfield(L, 2, "textures"); sky_params.textures.clear(); - if (lua_istable(L, -1) && sky_params.type == "skybox") { + if (lua_istable(L, -1) && (sky_params.type == "skybox" || + sky_params.type == "skybox_back" || sky_params.type == "skybox_front")) { lua_pushnil(L); while (lua_next(L, -2) != 0) { // Key is at index -2 and value at index -1 @@ -2186,7 +2182,8 @@ int ObjectRef::l_set_sky(lua_State *L) static void push_sky_color(lua_State *L, const SkyboxParams ¶ms) { lua_newtable(L); - if (params.type == "regular" || params.type == "skybox") { + if (params.type == "regular" || params.type == "skybox" || + params.type == "skybox_back" || params.type == "skybox_front") { push_ARGB8(L, params.sky_color.day_sky); lua_setfield(L, -2, "day_sky"); push_ARGB8(L, params.sky_color.day_horizon); @@ -2243,8 +2240,6 @@ int ObjectRef::l_get_sky(lua_State *L) lua_setfield(L, -2, "base_color"); lua_pushlstring(L, skybox_params.type.c_str(), skybox_params.type.size()); lua_setfield(L, -2, "type"); - lua_pushlstring(L, skybox_params.transparency.c_str(), skybox_params.transparency.size()); - lua_setfield(L, -2, "transparency"); if (skybox_params.body_orbit_tilt != SkyboxParams::INVALID_SKYBOX_TILT) { lua_pushnumber(L, skybox_params.body_orbit_tilt); diff --git a/src/server.cpp b/src/server.cpp index 49bd41661..714173dcf 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -1859,16 +1859,18 @@ void Server::SendSetSky(session_t peer_id, const SkyboxParams ¶ms) pkt << params.clouds; } else { // Handle current clients and future clients - pkt << params.bgcolor << params.type << params.transparency + pkt << params.bgcolor << params.type << params.clouds << params.fog_sun_tint << params.fog_moon_tint << params.fog_tint_type; - if (params.type == "skybox") { + if (params.type == "skybox" || + params.type == "skybox_back" || params.type == "skybox_front") { pkt << (u16) params.textures.size(); for (const std::string &texture : params.textures) pkt << texture; } - if (params.type == "regular" || params.type == "skybox") { + if (params.type == "regular" || params.type == "skybox" || + params.type == "skybox_back" || params.type == "skybox_front") { auto &c = params.sky_color; pkt << c.day_sky << c.day_horizon << c.dawn_sky << c.dawn_horizon << c.night_sky << c.night_horizon << c.indoors; diff --git a/src/skyparams.h b/src/skyparams.h index 74e30a5be..c5cd574cd 100644 --- a/src/skyparams.h +++ b/src/skyparams.h @@ -28,7 +28,6 @@ struct SkyboxParams video::SColor bgcolor; std::string type; - std::string transparency; std::vector textures; bool clouds; SkyColor sky_color; @@ -90,7 +89,6 @@ public: SkyboxParams sky; sky.bgcolor = video::SColor(255, 255, 255, 255); sky.type = "regular"; - sky.transparency = "solid"; sky.clouds = true; sky.sky_color = getSkyColorDefaults(); sky.fog_sun_tint = video::SColor(255, 244, 125, 29);