Set sky API: Add bool for clouds in front of custom skybox
authorparamat <mat.gregory@virginmedia.com>
Fri, 28 Apr 2017 02:06:49 +0000 (03:06 +0100)
committerAuke Kok <sofar+github@foo-projects.org>
Wed, 3 May 2017 03:42:35 +0000 (20:42 -0700)
Default true.
Add 'm_clouds_enabled' bool to sky.h, set from new bool in 'set sky' API.
Make 'getCloudsVisible()' depend on 'm_clouds_enabled' instead of
'm_visible' (whether normal sky is visible).

12 files changed:
doc/lua_api.txt
src/client.h
src/game.cpp
src/network/clientpackethandler.cpp
src/network/networkprotocol.h
src/remoteplayer.h
src/script/lua_api/l_object.cpp
src/script/lua_api/l_object.h
src/server.cpp
src/server.h
src/sky.cpp
src/sky.h

index 77ffb88e298b31f911189e4e9bc8edab36d4cc20..599e02fcb190ae1e511989ac0614fc59dce1ec90 100644 (file)
@@ -3077,13 +3077,15 @@ This is basically a reference to a C++ `ServerActiveObject`
 * `hud_set_hotbar_selected_image(texturename)`
     * sets image for selected item of hotbar
 * `hud_get_hotbar_selected_image`: returns texturename
-* `set_sky(bgcolor, type, {texture names})`
+* `set_sky(bgcolor, type, {texture names}, clouds)`
     * `bgcolor`: ColorSpec, defaults to white
-    * Available types:
+    * `type`: Available types:
         * `"regular"`: Uses 0 textures, `bgcolor` ignored
         * `"skybox"`: Uses 6 textures, `bgcolor` used
         * `"plain"`: Uses 0 textures, `bgcolor` used
-* `get_sky()`: returns bgcolor, type and a table with the textures
+    * `clouds`: Boolean for whether clouds appear in front of `"skybox"` or
+      `"plain"` custom skyboxes (default: `true`)
+* `get_sky()`: returns bgcolor, type, table of textures, clouds
 * `set_clouds(parameters)`: set cloud parameters
        * `parameters` is a table with the following optional fields:
                * `density`: from `0` (no clouds) to `1` (full clouds) (default `0.4`)
index e8db7de44e73ce963bcc0bd72ef5d735f1735e35..0dd519308308d1e7b8d538da8a74a18844d94e45 100644 (file)
@@ -174,6 +174,7 @@ struct ClientEvent
                        video::SColor *bgcolor;
                        std::string *type;
                        std::vector<std::string> *params;
+                       bool clouds;
                } set_sky;
                struct{
                        bool do_override;
index ba6530d8037eb214112c705ed4125ca2ea18f19d..7dd9c942d5e4a3785259a2c6841ce461cc5bd344 100644 (file)
@@ -3255,6 +3255,8 @@ void Game::processClientEvents(CameraOrientation *cam)
 
                case CE_SET_SKY:
                        sky->setVisible(false);
+                       // Whether clouds are visible in front of a custom skybox
+                       sky->setCloudsEnabled(event.set_sky.clouds);
 
                        if (skybox) {
                                skybox->remove();
@@ -3264,6 +3266,7 @@ void Game::processClientEvents(CameraOrientation *cam)
                        // Handle according to type
                        if (*event.set_sky.type == "regular") {
                                sky->setVisible(true);
+                               sky->setCloudsEnabled(true);
                        } else if (*event.set_sky.type == "skybox" &&
                                        event.set_sky.params->size() == 6) {
                                sky->setFallbackBgColor(*event.set_sky.bgcolor);
index 4316a77d4ca1c8ccf2b26d2327216ddd4a60b7dc..c3626158e18a85f6ecec63889179f327d55ba1c4 100644 (file)
@@ -1192,11 +1192,17 @@ void Client::handleCommand_HudSetSky(NetworkPacket* pkt)
        for (size_t i = 0; i < count; i++)
                params->push_back(deSerializeString(is));
 
+       bool clouds = true;
+       try {
+               clouds = readU8(is);
+       } catch (...) {}
+
        ClientEvent event;
        event.type            = CE_SET_SKY;
        event.set_sky.bgcolor = bgcolor;
        event.set_sky.type    = type;
        event.set_sky.params  = params;
+       event.set_sky.clouds  = clouds;
        m_client_event_queue.push(event);
 }
 
index 70cad85d8dfbd14f0a2ca9c45e97a4c81b858502..7126c237be2b30f6f3b77d0ee11f0b8ace401fcf 100644 (file)
@@ -584,6 +584,7 @@ enum ToClientCommand
                foreach count:
                        u8 len
                        u8[len] param
+               u8 clouds (boolean)
        */
 
        TOCLIENT_OVERRIDE_DAY_NIGHT_RATIO = 0x50,
index b9d9c74f540b0ac168ec5517e22d3863a2007e21..7d46205c5b5812fc605558a013abc33cc4960c7a 100644 (file)
@@ -85,19 +85,21 @@ public:
        }
 
        void setSky(const video::SColor &bgcolor, const std::string &type,
-                       const std::vector<std::string> &params)
+                       const std::vector<std::string> &params, bool &clouds)
        {
                m_sky_bgcolor = bgcolor;
                m_sky_type = type;
                m_sky_params = params;
+               m_sky_clouds = clouds;
        }
 
        void getSky(video::SColor *bgcolor, std::string *type,
-                       std::vector<std::string> *params)
+                       std::vector<std::string> *params, bool *clouds)
        {
                *bgcolor = m_sky_bgcolor;
                *type = m_sky_type;
                *params = m_sky_params;
+               *clouds = m_sky_clouds;
        }
 
        void setCloudParams(const CloudParams &cloud_params)
@@ -165,6 +167,8 @@ private:
        std::string m_sky_type;
        video::SColor m_sky_bgcolor;
        std::vector<std::string> m_sky_params;
+       bool m_sky_clouds;
+
        CloudParams m_cloud_params;
 };
 
index 6cd852299c2cbe470f906f180e653204b4a76cf1..6f61ab55cc50e3b8c9159c4d3c7a6be6a9fe78c5 100644 (file)
@@ -1662,7 +1662,7 @@ int ObjectRef::l_hud_get_hotbar_selected_image(lua_State *L)
        return 1;
 }
 
-// set_sky(self, bgcolor, type, list)
+// set_sky(self, bgcolor, type, list, clouds = true)
 int ObjectRef::l_set_sky(lua_State *L)
 {
        NO_MAP_LOCK_REQUIRED;
@@ -1678,9 +1678,8 @@ int ObjectRef::l_set_sky(lua_State *L)
 
        std::vector<std::string> params;
        if (lua_istable(L, 4)) {
-               int table = lua_gettop(L);
                lua_pushnil(L);
-               while (lua_next(L, table) != 0) {
+               while (lua_next(L, 4) != 0) {
                        // key at index -2 and value at index -1
                        if (lua_isstring(L, -1))
                                params.push_back(lua_tostring(L, -1));
@@ -1694,7 +1693,11 @@ int ObjectRef::l_set_sky(lua_State *L)
        if (type == "skybox" && params.size() != 6)
                throw LuaError("skybox expects 6 textures");
 
-       if (!getServer(L)->setSky(player, bgcolor, type, params))
+       bool clouds = true;
+       if (lua_isboolean(L, 5))
+               clouds = lua_toboolean(L, 5);
+
+       if (!getServer(L)->setSky(player, bgcolor, type, params, clouds))
                return 0;
 
        lua_pushboolean(L, true);
@@ -1712,8 +1715,9 @@ int ObjectRef::l_get_sky(lua_State *L)
        video::SColor bgcolor(255, 255, 255, 255);
        std::string type;
        std::vector<std::string> params;
+       bool clouds;
 
-       player->getSky(&bgcolor, &type, &params);
+       player->getSky(&bgcolor, &type, &params, &clouds);
        type = type == "" ? "regular" : type;
 
        push_ARGB8(L, bgcolor);
@@ -1726,6 +1730,7 @@ int ObjectRef::l_get_sky(lua_State *L)
                lua_rawseti(L, -2, i);
                i++;
        }
+       lua_pushboolean(L, clouds);
        return 3;
 }
 
index 0912a1c49d0b67feed8887292b1eb55a16ccc9a4..9801ce02b3b5c2c7b7a839d741bba5f57d840dd6 100644 (file)
@@ -283,10 +283,10 @@ private:
        // hud_get_hotbar_selected_image(self)
        static int l_hud_get_hotbar_selected_image(lua_State *L);
 
-       // set_sky(self, type, list)
+       // set_sky(self, bgcolor, type, list, clouds = true)
        static int l_set_sky(lua_State *L);
 
-       // get_sky(self, type, list)
+       // get_sky(self)
        static int l_get_sky(lua_State *L);
 
        // set_clouds(self, {density=, color=, ambient=, height=, thickness=, speed=})
index 190a1baf2dbc569d622bbb04a7ed4c3a7d5c45b5..bf01fb7eb0577f8ce503f88b9aa2f73358f9dc84 100644 (file)
@@ -1871,7 +1871,8 @@ void Server::SendHUDSetParam(u16 peer_id, u16 param, const std::string &value)
 }
 
 void Server::SendSetSky(u16 peer_id, const video::SColor &bgcolor,
-               const std::string &type, const std::vector<std::string> &params)
+               const std::string &type, const std::vector<std::string> &params,
+               bool &clouds)
 {
        NetworkPacket pkt(TOCLIENT_SET_SKY, 0, peer_id);
        pkt << bgcolor << type << (u16) params.size();
@@ -1879,6 +1880,8 @@ void Server::SendSetSky(u16 peer_id, const video::SColor &bgcolor,
        for(size_t i=0; i<params.size(); i++)
                pkt << params[i];
 
+       pkt << clouds;
+
        Send(&pkt);
 }
 
@@ -3254,13 +3257,14 @@ bool Server::setPlayerEyeOffset(RemotePlayer *player, v3f first, v3f third)
 }
 
 bool Server::setSky(RemotePlayer *player, const video::SColor &bgcolor,
-       const std::string &type, const std::vector<std::string> &params)
+       const std::string &type, const std::vector<std::string> &params,
+       bool &clouds)
 {
        if (!player)
                return false;
 
-       player->setSky(bgcolor, type, params);
-       SendSetSky(player->peer_id, bgcolor, type, params);
+       player->setSky(bgcolor, type, params, clouds);
+       SendSetSky(player->peer_id, bgcolor, type, params, clouds);
        return true;
 }
 
index 5e6211637b921d42dbf1c70acfb349effebb4183..2e735e77c62abeded92d77f5f6f30a4fe3618a0c 100644 (file)
@@ -335,7 +335,8 @@ public:
        bool setPlayerEyeOffset(RemotePlayer *player, v3f first, v3f third);
 
        bool setSky(RemotePlayer *player, const video::SColor &bgcolor,
-                       const std::string &type, const std::vector<std::string> &params);
+                       const std::string &type, const std::vector<std::string> &params,
+                       bool &clouds);
        bool setClouds(RemotePlayer *player, float density,
                        const video::SColor &color_bright,
                        const video::SColor &color_ambient,
@@ -410,7 +411,8 @@ private:
        void SendHUDSetFlags(u16 peer_id, u32 flags, u32 mask);
        void SendHUDSetParam(u16 peer_id, u16 param, const std::string &value);
        void SendSetSky(u16 peer_id, const video::SColor &bgcolor,
-                       const std::string &type, const std::vector<std::string> &params);
+                       const std::string &type, const std::vector<std::string> &params,
+                       bool &clouds);
        void SendCloudParams(u16 peer_id, float density,
                        const video::SColor &color_bright,
                        const video::SColor &color_ambient,
index 7f999feb0ec371ea25748c3656fa3a4be2756bfa..5414f74bd5056d0f9578cce1f663052882036f6e 100644 (file)
@@ -85,6 +85,8 @@ Sky::Sky(scene::ISceneNode* parent, scene::ISceneManager* mgr, s32 id,
        }
 
        m_directional_colored_fog = g_settings->getBool("directional_colored_fog");
+
+       m_clouds_enabled = true;
 }
 
 
index 72cb2d581735bc8327404fbe51dd31952d5592c5..c9678a80b3d6cb75ab62755c3bdbdade2c0f1d6b 100644 (file)
--- a/src/sky.h
+++ b/src/sky.h
@@ -65,10 +65,12 @@ public:
                return m_visible ? m_skycolor : m_fallback_bg_color;
        }
 
-       bool getCloudsVisible() { return m_clouds_visible && m_visible; }
+       bool getCloudsVisible() { return m_clouds_visible && m_clouds_enabled; }
        const video::SColorf &getCloudColor() { return m_cloudcolor_f; }
 
        void setVisible(bool visible) { m_visible = visible; }
+       // Set only from set_sky API
+       void setCloudsEnabled(bool clouds_enabled) { m_clouds_enabled = clouds_enabled; }
        void setFallbackBgColor(const video::SColor &fallback_bg_color)
        {
                m_fallback_bg_color = fallback_bg_color;
@@ -123,7 +125,8 @@ private:
        bool m_sunlight_seen;
        float m_brightness;
        float m_cloud_brightness;
-       bool m_clouds_visible;
+       bool m_clouds_visible;  // Whether clouds are disabled due to player underground
+       bool m_clouds_enabled;  // Initialised to true, reset only by set_sky API
        bool m_directional_colored_fog;
        video::SColorf m_bgcolor_bright_f;
        video::SColorf m_skycolor_bright_f;