diff options
-rw-r--r-- | doc/lua_api.txt | 3 | ||||
-rw-r--r-- | src/client/game.cpp | 1 | ||||
-rw-r--r-- | src/client/sky.cpp | 7 | ||||
-rw-r--r-- | src/client/sky.h | 1 | ||||
-rw-r--r-- | src/network/clientpackethandler.cpp | 5 | ||||
-rw-r--r-- | src/network/networkprotocol.h | 1 | ||||
-rw-r--r-- | src/script/lua_api/l_object.cpp | 5 | ||||
-rw-r--r-- | src/server.cpp | 3 | ||||
-rw-r--r-- | src/skyparams.h | 2 |
9 files changed, 24 insertions, 4 deletions
diff --git a/doc/lua_api.txt b/doc/lua_api.txt index b5f58d7f2..994a30981 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -7200,6 +7200,9 @@ object you are working with still exists. * `star_parameters` is a table with the following optional fields: * `visible`: Boolean for whether the stars are visible. (default: `true`) + * `day_opacity`: Float for maximum opacity of stars at day. + No effect if `visible` is false. + (default: 0.0; maximum: 1.0; minimum: 0.0) * `count`: Integer number to set the number of stars in the skybox. Only applies to `"skybox"` and `"regular"` sky types. (default: `1000`) diff --git a/src/client/game.cpp b/src/client/game.cpp index 81a996c08..e6308c3b6 100644 --- a/src/client/game.cpp +++ b/src/client/game.cpp @@ -2876,6 +2876,7 @@ void Game::handleClientEvent_SetStars(ClientEvent *event, CameraOrientation *cam sky->setStarCount(event->star_params->count); sky->setStarColor(event->star_params->starcolor); sky->setStarScale(event->star_params->scale); + sky->setStarDayOpacity(event->star_params->day_opacity); delete event->star_params; } diff --git a/src/client/sky.cpp b/src/client/sky.cpp index 0ab710eee..ca56889b4 100644 --- a/src/client/sky.cpp +++ b/src/client/sky.cpp @@ -660,9 +660,12 @@ void Sky::draw_stars(video::IVideoDriver * driver, float wicked_time_of_day) // to time 4000. float tod = wicked_time_of_day < 0.5f ? wicked_time_of_day : (1.0f - wicked_time_of_day); - float starbrightness = (0.25f - fabsf(tod)) * 20.0f; + float day_opacity = clamp(m_star_params.day_opacity, 0.0f, 1.0f); + float starbrightness = (0.25f - fabs(tod)) * 20.0f; + float alpha = clamp(starbrightness, day_opacity, 1.0f); + m_star_color = m_star_params.starcolor; - m_star_color.a *= clamp(starbrightness, 0.0f, 1.0f); + m_star_color.a *= alpha; if (m_star_color.a <= 0.0f) // Stars are only drawn when not fully transparent return; m_materials[0].DiffuseColor = m_materials[0].EmissiveColor = m_star_color.toSColor(); diff --git a/src/client/sky.h b/src/client/sky.h index e03683f12..cbb1186aa 100644 --- a/src/client/sky.h +++ b/src/client/sky.h @@ -82,6 +82,7 @@ public: void setStarCount(u16 star_count); void setStarColor(video::SColor star_color) { m_star_params.starcolor = star_color; } void setStarScale(f32 star_scale) { m_star_params.scale = star_scale; updateStars(); } + void setStarDayOpacity(f32 day_opacity) { m_star_params.day_opacity = day_opacity; } bool getCloudsVisible() const { return m_clouds_visible && m_clouds_enabled; } const video::SColorf &getCloudColor() const { return m_cloudcolor_f; } diff --git a/src/network/clientpackethandler.cpp b/src/network/clientpackethandler.cpp index 764f6569f..fba0fe72d 100644 --- a/src/network/clientpackethandler.cpp +++ b/src/network/clientpackethandler.cpp @@ -1340,10 +1340,13 @@ void Client::handleCommand_HudSetMoon(NetworkPacket *pkt) void Client::handleCommand_HudSetStars(NetworkPacket *pkt) { - StarParams stars; + StarParams stars = SkyboxDefaults::getStarDefaults(); *pkt >> stars.visible >> stars.count >> stars.starcolor >> stars.scale; + try { + *pkt >> stars.day_opacity; + } catch (PacketError &e) {}; ClientEvent *event = new ClientEvent(); event->type = CE_SET_STARS; diff --git a/src/network/networkprotocol.h b/src/network/networkprotocol.h index 3923cb858..7c5b2e3fe 100644 --- a/src/network/networkprotocol.h +++ b/src/network/networkprotocol.h @@ -735,6 +735,7 @@ enum ToClientCommand u32 count u8[4] starcolor (ARGB) f32 scale + f32 day_opacity */ TOCLIENT_SRP_BYTES_S_B = 0x60, diff --git a/src/script/lua_api/l_object.cpp b/src/script/lua_api/l_object.cpp index 37ba1521a..6bd07a4c1 100644 --- a/src/script/lua_api/l_object.cpp +++ b/src/script/lua_api/l_object.cpp @@ -2084,6 +2084,9 @@ int ObjectRef::l_set_stars(lua_State *L) "scale", star_params.scale); } + star_params.day_opacity = getfloatfield_default(L, 2, + "day_opacity", star_params.day_opacity); + getServer(L)->setStars(player, star_params); return 0; } @@ -2108,6 +2111,8 @@ int ObjectRef::l_get_stars(lua_State *L) lua_setfield(L, -2, "star_color"); lua_pushnumber(L, star_params.scale); lua_setfield(L, -2, "scale"); + lua_pushnumber(L, star_params.day_opacity); + lua_setfield(L, -2, "day_opacity"); return 1; } diff --git a/src/server.cpp b/src/server.cpp index a47062a4d..d94271143 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -1775,7 +1775,8 @@ void Server::SendSetStars(session_t peer_id, const StarParams ¶ms) NetworkPacket pkt(TOCLIENT_SET_STARS, 0, peer_id); pkt << params.visible << params.count - << params.starcolor << params.scale; + << params.starcolor << params.scale + << params.day_opacity; Send(&pkt); } diff --git a/src/skyparams.h b/src/skyparams.h index f7f694427..07068634b 100644 --- a/src/skyparams.h +++ b/src/skyparams.h @@ -66,6 +66,7 @@ struct StarParams u32 count; video::SColor starcolor; f32 scale; + f32 day_opacity; }; struct CloudParams @@ -141,6 +142,7 @@ public: stars.count = 1000; stars.starcolor = video::SColor(105, 235, 235, 255); stars.scale = 1; + stars.day_opacity = 0; return stars; } |