Skip to content

Commit ad9fcf8

Browse files
paramatsofar
authored andcommittedMay 3, 2017
Set sky API: Add bool for clouds in front of custom skybox
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).
1 parent f9fdb48 commit ad9fcf8

12 files changed

+53
-20
lines changed
 

Diff for: ‎doc/lua_api.txt

+5-3
Original file line numberDiff line numberDiff line change
@@ -3077,13 +3077,15 @@ This is basically a reference to a C++ `ServerActiveObject`
30773077
* `hud_set_hotbar_selected_image(texturename)`
30783078
* sets image for selected item of hotbar
30793079
* `hud_get_hotbar_selected_image`: returns texturename
3080-
* `set_sky(bgcolor, type, {texture names})`
3080+
* `set_sky(bgcolor, type, {texture names}, clouds)`
30813081
* `bgcolor`: ColorSpec, defaults to white
3082-
* Available types:
3082+
* `type`: Available types:
30833083
* `"regular"`: Uses 0 textures, `bgcolor` ignored
30843084
* `"skybox"`: Uses 6 textures, `bgcolor` used
30853085
* `"plain"`: Uses 0 textures, `bgcolor` used
3086-
* `get_sky()`: returns bgcolor, type and a table with the textures
3086+
* `clouds`: Boolean for whether clouds appear in front of `"skybox"` or
3087+
`"plain"` custom skyboxes (default: `true`)
3088+
* `get_sky()`: returns bgcolor, type, table of textures, clouds
30873089
* `set_clouds(parameters)`: set cloud parameters
30883090
* `parameters` is a table with the following optional fields:
30893091
* `density`: from `0` (no clouds) to `1` (full clouds) (default `0.4`)

Diff for: ‎src/client.h

+1
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ struct ClientEvent
174174
video::SColor *bgcolor;
175175
std::string *type;
176176
std::vector<std::string> *params;
177+
bool clouds;
177178
} set_sky;
178179
struct{
179180
bool do_override;

Diff for: ‎src/game.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -3255,6 +3255,8 @@ void Game::processClientEvents(CameraOrientation *cam)
32553255

32563256
case CE_SET_SKY:
32573257
sky->setVisible(false);
3258+
// Whether clouds are visible in front of a custom skybox
3259+
sky->setCloudsEnabled(event.set_sky.clouds);
32583260

32593261
if (skybox) {
32603262
skybox->remove();
@@ -3264,6 +3266,7 @@ void Game::processClientEvents(CameraOrientation *cam)
32643266
// Handle according to type
32653267
if (*event.set_sky.type == "regular") {
32663268
sky->setVisible(true);
3269+
sky->setCloudsEnabled(true);
32673270
} else if (*event.set_sky.type == "skybox" &&
32683271
event.set_sky.params->size() == 6) {
32693272
sky->setFallbackBgColor(*event.set_sky.bgcolor);

Diff for: ‎src/network/clientpackethandler.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -1192,11 +1192,17 @@ void Client::handleCommand_HudSetSky(NetworkPacket* pkt)
11921192
for (size_t i = 0; i < count; i++)
11931193
params->push_back(deSerializeString(is));
11941194

1195+
bool clouds = true;
1196+
try {
1197+
clouds = readU8(is);
1198+
} catch (...) {}
1199+
11951200
ClientEvent event;
11961201
event.type = CE_SET_SKY;
11971202
event.set_sky.bgcolor = bgcolor;
11981203
event.set_sky.type = type;
11991204
event.set_sky.params = params;
1205+
event.set_sky.clouds = clouds;
12001206
m_client_event_queue.push(event);
12011207
}
12021208

Diff for: ‎src/network/networkprotocol.h

+1
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,7 @@ enum ToClientCommand
584584
foreach count:
585585
u8 len
586586
u8[len] param
587+
u8 clouds (boolean)
587588
*/
588589

589590
TOCLIENT_OVERRIDE_DAY_NIGHT_RATIO = 0x50,

Diff for: ‎src/remoteplayer.h

+6-2
Original file line numberDiff line numberDiff line change
@@ -85,19 +85,21 @@ class RemotePlayer : public Player
8585
}
8686

8787
void setSky(const video::SColor &bgcolor, const std::string &type,
88-
const std::vector<std::string> &params)
88+
const std::vector<std::string> &params, bool &clouds)
8989
{
9090
m_sky_bgcolor = bgcolor;
9191
m_sky_type = type;
9292
m_sky_params = params;
93+
m_sky_clouds = clouds;
9394
}
9495

9596
void getSky(video::SColor *bgcolor, std::string *type,
96-
std::vector<std::string> *params)
97+
std::vector<std::string> *params, bool *clouds)
9798
{
9899
*bgcolor = m_sky_bgcolor;
99100
*type = m_sky_type;
100101
*params = m_sky_params;
102+
*clouds = m_sky_clouds;
101103
}
102104

103105
void setCloudParams(const CloudParams &cloud_params)
@@ -165,6 +167,8 @@ class RemotePlayer : public Player
165167
std::string m_sky_type;
166168
video::SColor m_sky_bgcolor;
167169
std::vector<std::string> m_sky_params;
170+
bool m_sky_clouds;
171+
168172
CloudParams m_cloud_params;
169173
};
170174

Diff for: ‎src/script/lua_api/l_object.cpp

+10-5
Original file line numberDiff line numberDiff line change
@@ -1662,7 +1662,7 @@ int ObjectRef::l_hud_get_hotbar_selected_image(lua_State *L)
16621662
return 1;
16631663
}
16641664

1665-
// set_sky(self, bgcolor, type, list)
1665+
// set_sky(self, bgcolor, type, list, clouds = true)
16661666
int ObjectRef::l_set_sky(lua_State *L)
16671667
{
16681668
NO_MAP_LOCK_REQUIRED;
@@ -1678,9 +1678,8 @@ int ObjectRef::l_set_sky(lua_State *L)
16781678

16791679
std::vector<std::string> params;
16801680
if (lua_istable(L, 4)) {
1681-
int table = lua_gettop(L);
16821681
lua_pushnil(L);
1683-
while (lua_next(L, table) != 0) {
1682+
while (lua_next(L, 4) != 0) {
16841683
// key at index -2 and value at index -1
16851684
if (lua_isstring(L, -1))
16861685
params.push_back(lua_tostring(L, -1));
@@ -1694,7 +1693,11 @@ int ObjectRef::l_set_sky(lua_State *L)
16941693
if (type == "skybox" && params.size() != 6)
16951694
throw LuaError("skybox expects 6 textures");
16961695

1697-
if (!getServer(L)->setSky(player, bgcolor, type, params))
1696+
bool clouds = true;
1697+
if (lua_isboolean(L, 5))
1698+
clouds = lua_toboolean(L, 5);
1699+
1700+
if (!getServer(L)->setSky(player, bgcolor, type, params, clouds))
16981701
return 0;
16991702

17001703
lua_pushboolean(L, true);
@@ -1712,8 +1715,9 @@ int ObjectRef::l_get_sky(lua_State *L)
17121715
video::SColor bgcolor(255, 255, 255, 255);
17131716
std::string type;
17141717
std::vector<std::string> params;
1718+
bool clouds;
17151719

1716-
player->getSky(&bgcolor, &type, &params);
1720+
player->getSky(&bgcolor, &type, &params, &clouds);
17171721
type = type == "" ? "regular" : type;
17181722

17191723
push_ARGB8(L, bgcolor);
@@ -1726,6 +1730,7 @@ int ObjectRef::l_get_sky(lua_State *L)
17261730
lua_rawseti(L, -2, i);
17271731
i++;
17281732
}
1733+
lua_pushboolean(L, clouds);
17291734
return 3;
17301735
}
17311736

Diff for: ‎src/script/lua_api/l_object.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -283,10 +283,10 @@ class ObjectRef : public ModApiBase {
283283
// hud_get_hotbar_selected_image(self)
284284
static int l_hud_get_hotbar_selected_image(lua_State *L);
285285

286-
// set_sky(self, type, list)
286+
// set_sky(self, bgcolor, type, list, clouds = true)
287287
static int l_set_sky(lua_State *L);
288288

289-
// get_sky(self, type, list)
289+
// get_sky(self)
290290
static int l_get_sky(lua_State *L);
291291

292292
// set_clouds(self, {density=, color=, ambient=, height=, thickness=, speed=})

Diff for: ‎src/server.cpp

+8-4
Original file line numberDiff line numberDiff line change
@@ -1871,14 +1871,17 @@ void Server::SendHUDSetParam(u16 peer_id, u16 param, const std::string &value)
18711871
}
18721872

18731873
void Server::SendSetSky(u16 peer_id, const video::SColor &bgcolor,
1874-
const std::string &type, const std::vector<std::string> &params)
1874+
const std::string &type, const std::vector<std::string> &params,
1875+
bool &clouds)
18751876
{
18761877
NetworkPacket pkt(TOCLIENT_SET_SKY, 0, peer_id);
18771878
pkt << bgcolor << type << (u16) params.size();
18781879

18791880
for(size_t i=0; i<params.size(); i++)
18801881
pkt << params[i];
18811882

1883+
pkt << clouds;
1884+
18821885
Send(&pkt);
18831886
}
18841887

@@ -3254,13 +3257,14 @@ bool Server::setPlayerEyeOffset(RemotePlayer *player, v3f first, v3f third)
32543257
}
32553258

32563259
bool Server::setSky(RemotePlayer *player, const video::SColor &bgcolor,
3257-
const std::string &type, const std::vector<std::string> &params)
3260+
const std::string &type, const std::vector<std::string> &params,
3261+
bool &clouds)
32583262
{
32593263
if (!player)
32603264
return false;
32613265

3262-
player->setSky(bgcolor, type, params);
3263-
SendSetSky(player->peer_id, bgcolor, type, params);
3266+
player->setSky(bgcolor, type, params, clouds);
3267+
SendSetSky(player->peer_id, bgcolor, type, params, clouds);
32643268
return true;
32653269
}
32663270

Diff for: ‎src/server.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,8 @@ class Server : public con::PeerHandler, public MapEventReceiver,
335335
bool setPlayerEyeOffset(RemotePlayer *player, v3f first, v3f third);
336336

337337
bool setSky(RemotePlayer *player, const video::SColor &bgcolor,
338-
const std::string &type, const std::vector<std::string> &params);
338+
const std::string &type, const std::vector<std::string> &params,
339+
bool &clouds);
339340
bool setClouds(RemotePlayer *player, float density,
340341
const video::SColor &color_bright,
341342
const video::SColor &color_ambient,
@@ -410,7 +411,8 @@ class Server : public con::PeerHandler, public MapEventReceiver,
410411
void SendHUDSetFlags(u16 peer_id, u32 flags, u32 mask);
411412
void SendHUDSetParam(u16 peer_id, u16 param, const std::string &value);
412413
void SendSetSky(u16 peer_id, const video::SColor &bgcolor,
413-
const std::string &type, const std::vector<std::string> &params);
414+
const std::string &type, const std::vector<std::string> &params,
415+
bool &clouds);
414416
void SendCloudParams(u16 peer_id, float density,
415417
const video::SColor &color_bright,
416418
const video::SColor &color_ambient,

Diff for: ‎src/sky.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ Sky::Sky(scene::ISceneNode* parent, scene::ISceneManager* mgr, s32 id,
8585
}
8686

8787
m_directional_colored_fog = g_settings->getBool("directional_colored_fog");
88+
89+
m_clouds_enabled = true;
8890
}
8991

9092

Diff for: ‎src/sky.h

+5-2
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,12 @@ class Sky : public scene::ISceneNode
6565
return m_visible ? m_skycolor : m_fallback_bg_color;
6666
}
6767

68-
bool getCloudsVisible() { return m_clouds_visible && m_visible; }
68+
bool getCloudsVisible() { return m_clouds_visible && m_clouds_enabled; }
6969
const video::SColorf &getCloudColor() { return m_cloudcolor_f; }
7070

7171
void setVisible(bool visible) { m_visible = visible; }
72+
// Set only from set_sky API
73+
void setCloudsEnabled(bool clouds_enabled) { m_clouds_enabled = clouds_enabled; }
7274
void setFallbackBgColor(const video::SColor &fallback_bg_color)
7375
{
7476
m_fallback_bg_color = fallback_bg_color;
@@ -123,7 +125,8 @@ class Sky : public scene::ISceneNode
123125
bool m_sunlight_seen;
124126
float m_brightness;
125127
float m_cloud_brightness;
126-
bool m_clouds_visible;
128+
bool m_clouds_visible; // Whether clouds are disabled due to player underground
129+
bool m_clouds_enabled; // Initialised to true, reset only by set_sky API
127130
bool m_directional_colored_fog;
128131
video::SColorf m_bgcolor_bright_f;
129132
video::SColorf m_skycolor_bright_f;

0 commit comments

Comments
 (0)
Please sign in to comment.