Skip to content

Commit 946c03c

Browse files
Jordachsfan5
authored andcommittedMar 5, 2020
set_sky improvements, set_sun, set_moon and set_stars
1 parent 580e7e8 commit 946c03c

19 files changed

+1519
-394
lines changed
 

‎doc/lua_api.txt

+76-9
Original file line numberDiff line numberDiff line change
@@ -5964,15 +5964,82 @@ object you are working with still exists.
59645964
* `hud_set_hotbar_selected_image(texturename)`
59655965
* sets image for selected item of hotbar
59665966
* `hud_get_hotbar_selected_image`: returns texturename
5967-
* `set_sky(bgcolor, type, {texture names}, clouds)`
5968-
* `bgcolor`: ColorSpec, defaults to white
5969-
* `type`: Available types:
5970-
* `"regular"`: Uses 0 textures, `bgcolor` ignored
5971-
* `"skybox"`: Uses 6 textures, `bgcolor` used
5972-
* `"plain"`: Uses 0 textures, `bgcolor` used
5973-
* `clouds`: Boolean for whether clouds appear in front of `"skybox"` or
5974-
`"plain"` custom skyboxes (default: `true`)
5975-
* `get_sky()`: returns bgcolor, type, table of textures, clouds
5967+
* `set_sky(parameters)`
5968+
* `parameters` is a table with the following optional fields:
5969+
* `base_color`: ColorSpec, changes fog in "skybox" and "plain".
5970+
* `type`: Available types:
5971+
* `"regular"`: Uses 0 textures, `base_color` ignored
5972+
* `"skybox"`: Uses 6 textures, `base_color` used as fog.
5973+
* `"plain"`: Uses 0 textures, `base_color` used as both fog and sky.
5974+
* `textures`: A table containing up to six textures in the following
5975+
order: Y+ (top), Y- (bottom), X- (west), X+ (east), Z+ (north), Z- (south).
5976+
* `clouds`: Boolean for whether clouds appear. (default: `true`)
5977+
* `sky_color`: A table containing the following values, alpha is ignored:
5978+
* `day_sky`: ColorSpec, for the top half of the `"regular"`
5979+
skybox during the day. (default: `#8cbafa`)
5980+
* `day_horizon`: ColorSpec, for the bottom half of the
5981+
`"regular"` skybox during the day. (default: `#9bc1f0`)
5982+
* `dawn_sky`: ColorSpec, for the top half of the `"regular"`
5983+
skybox during dawn/sunset. (default: `#b4bafa`)
5984+
* `dawn_horizon`: ColorSpec, for the bottom half of the `"regular"`
5985+
skybox during dawn/sunset. (default: `#bac1f0`)
5986+
* `night_sky`: ColorSpec, for the top half of the `"regular"`
5987+
skybox during the night. (default: `#006aff`)
5988+
* `night_horizon`: ColorSpec, for the bottom half of the `"regular"`
5989+
skybox during the night. (default: `#4090ff`)
5990+
* `indoors`: ColorSpec, for when you're either indoors or
5991+
underground. Only applies to the `"regular"` skybox.
5992+
(default: `#646464`)
5993+
* `fog_sun_tint`: ColorSpec, changes the fog tinting for the sun
5994+
at sunrise and sunset.
5995+
* `fog_moon_tint`: ColorSpec, changes the fog tinting for the moon
5996+
at sunrise and sunset.
5997+
* `fog_tint_type`: string, changes which mode the directional fog
5998+
abides by, `"custom"` uses `sun_tint` and `moon_tint`, while
5999+
`"default"` uses the classic Minetest sun and moon tinting.
6000+
Will use tonemaps, if set to `"default"`. (default: `"default"`)
6001+
* `get_sky()`: returns base_color, type, table of textures, clouds.
6002+
* `get_sky_color()`: returns a table with the `sky_color` parameters as in
6003+
`set_sky`.
6004+
* `set_sun(parameters)`:
6005+
* `parameters` is a table with the following optional fields:
6006+
* `visible`: Boolean for whether the sun is visible.
6007+
(default: `true`)
6008+
* `texture`: A regular texture for the sun. Setting to `""`
6009+
will re-enable the mesh sun. (default: `"sun.png"`)
6010+
* `tonemap`: A 512x1 texture containing the tonemap for the sun
6011+
(default: `"sun_tonemap.png"`)
6012+
* `sunrise`: A regular texture for the sunrise texture.
6013+
(default: `"sunrisebg.png"`)
6014+
* `sunrise_visible`: Boolean for whether the sunrise texture is visible.
6015+
(default: `true`)
6016+
* `scale`: Float controlling the overall size of the sun. (default: `1`)
6017+
* `get_sun()`: returns a table with the current sun parameters as in
6018+
`set_sun`.
6019+
* `set_moon(parameters)`:
6020+
* `parameters` is a table with the following optional fields:
6021+
* `visible`: Boolean for whether the moon is visible.
6022+
(default: `true`)
6023+
* `texture`: A regular texture for the moon. Setting to `""`
6024+
will re-enable the mesh moon. (default: `"moon.png"`)
6025+
* `tonemap`: A 512x1 texture containing the tonemap for the moon
6026+
(default: `"moon_tonemap.png"`)
6027+
* `scale`: Float controlling the overall size of the moon (default: `1`)
6028+
* `get_moon()`: returns a table with the current moon parameters as in
6029+
`set_moon`.
6030+
* `set_stars(parameters)`:
6031+
* `parameters` is a table with the following optional fields:
6032+
* `visible`: Boolean for whether the stars are visible.
6033+
(default: `true`)
6034+
* `count`: Integer number to set the number of stars in
6035+
the skybox. Only applies to `"skybox"` and `"regular"` skyboxes.
6036+
(default: `1000`)
6037+
* `star_color`: ColorSpec, sets the colors of the stars,
6038+
alpha channel is used to set overall star brightness.
6039+
(default: `#ebebff69`)
6040+
* `size`: Float controlling the overall size of the stars (default: `1`)
6041+
* `get_stars()`: returns a table with the current stars parameters as in
6042+
`set_stars`.
59766043
* `set_clouds(parameters)`: set cloud parameters
59776044
* `parameters` is a table with the following optional fields:
59786045
* `density`: from `0` (no clouds) to `1` (full clouds) (default `0.4`)

‎src/client/client.h

+3
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,9 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef
218218
void handleCommand_HudSetFlags(NetworkPacket* pkt);
219219
void handleCommand_HudSetParam(NetworkPacket* pkt);
220220
void handleCommand_HudSetSky(NetworkPacket* pkt);
221+
void handleCommand_HudSetSun(NetworkPacket* pkt);
222+
void handleCommand_HudSetMoon(NetworkPacket* pkt);
223+
void handleCommand_HudSetStars(NetworkPacket* pkt);
221224
void handleCommand_CloudParams(NetworkPacket* pkt);
222225
void handleCommand_OverrideDayNightRatio(NetworkPacket* pkt);
223226
void handleCommand_LocalPlayerAnimations(NetworkPacket* pkt);

‎src/client/clientevent.h

+8-7
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
2222
#include <string>
2323
#include "irrlichttypes_bloated.h"
2424
#include "hud.h"
25+
#include "skyparams.h"
2526

2627
enum ClientEventType : u8
2728
{
@@ -38,6 +39,9 @@ enum ClientEventType : u8
3839
CE_HUDRM,
3940
CE_HUDCHANGE,
4041
CE_SET_SKY,
42+
CE_SET_SUN,
43+
CE_SET_MOON,
44+
CE_SET_STARS,
4145
CE_OVERRIDE_DAY_NIGHT_RATIO,
4246
CE_CLOUD_PARAMS,
4347
CLIENTEVENT_MAX,
@@ -147,13 +151,7 @@ struct ClientEvent
147151
v3f *v3fdata;
148152
v2s32 *v2s32data;
149153
} hudchange;
150-
struct
151-
{
152-
video::SColor *bgcolor;
153-
std::string *type;
154-
std::vector<std::string> *params;
155-
bool clouds;
156-
} set_sky;
154+
SkyboxParams *set_sky;
157155
struct
158156
{
159157
bool do_override;
@@ -169,5 +167,8 @@ struct ClientEvent
169167
f32 speed_x;
170168
f32 speed_y;
171169
} cloud_params;
170+
SunParams *sun_params;
171+
MoonParams *moon_params;
172+
StarParams *star_params;
172173
};
173174
};

‎src/client/game.cpp

+76-26
Original file line numberDiff line numberDiff line change
@@ -811,6 +811,9 @@ class Game {
811811
void handleClientEvent_HudRemove(ClientEvent *event, CameraOrientation *cam);
812812
void handleClientEvent_HudChange(ClientEvent *event, CameraOrientation *cam);
813813
void handleClientEvent_SetSky(ClientEvent *event, CameraOrientation *cam);
814+
void handleClientEvent_SetSun(ClientEvent *event, CameraOrientation *cam);
815+
void handleClientEvent_SetMoon(ClientEvent *event, CameraOrientation *cam);
816+
void handleClientEvent_SetStars(ClientEvent *event, CameraOrientation *cam);
814817
void handleClientEvent_OverrideDayNigthRatio(ClientEvent *event,
815818
CameraOrientation *cam);
816819
void handleClientEvent_CloudParams(ClientEvent *event, CameraOrientation *cam);
@@ -2523,6 +2526,9 @@ const ClientEventHandler Game::clientEventHandler[CLIENTEVENT_MAX] = {
25232526
{&Game::handleClientEvent_HudRemove},
25242527
{&Game::handleClientEvent_HudChange},
25252528
{&Game::handleClientEvent_SetSky},
2529+
{&Game::handleClientEvent_SetSun},
2530+
{&Game::handleClientEvent_SetMoon},
2531+
{&Game::handleClientEvent_SetStars},
25262532
{&Game::handleClientEvent_OverrideDayNigthRatio},
25272533
{&Game::handleClientEvent_CloudParams},
25282534
};
@@ -2744,41 +2750,85 @@ void Game::handleClientEvent_HudChange(ClientEvent *event, CameraOrientation *ca
27442750
void Game::handleClientEvent_SetSky(ClientEvent *event, CameraOrientation *cam)
27452751
{
27462752
sky->setVisible(false);
2747-
// Whether clouds are visible in front of a custom skybox
2748-
sky->setCloudsEnabled(event->set_sky.clouds);
2753+
// Whether clouds are visible in front of a custom skybox.
2754+
sky->setCloudsEnabled(event->set_sky->clouds);
27492755

27502756
if (skybox) {
27512757
skybox->remove();
27522758
skybox = NULL;
27532759
}
2754-
2760+
// Clear the old textures out in case we switch rendering type.
2761+
sky->clearSkyboxTextures();
27552762
// Handle according to type
2756-
if (*event->set_sky.type == "regular") {
2763+
if (event->set_sky->type == "regular") {
2764+
// Shows the mesh skybox
27572765
sky->setVisible(true);
2758-
sky->setCloudsEnabled(true);
2759-
} else if (*event->set_sky.type == "skybox" &&
2760-
event->set_sky.params->size() == 6) {
2761-
sky->setFallbackBgColor(*event->set_sky.bgcolor);
2762-
skybox = RenderingEngine::get_scene_manager()->addSkyBoxSceneNode(
2763-
texture_src->getTextureForMesh((*event->set_sky.params)[0]),
2764-
texture_src->getTextureForMesh((*event->set_sky.params)[1]),
2765-
texture_src->getTextureForMesh((*event->set_sky.params)[2]),
2766-
texture_src->getTextureForMesh((*event->set_sky.params)[3]),
2767-
texture_src->getTextureForMesh((*event->set_sky.params)[4]),
2768-
texture_src->getTextureForMesh((*event->set_sky.params)[5]));
2769-
}
2770-
// Handle everything else as plain color
2771-
else {
2772-
if (*event->set_sky.type != "plain")
2766+
// Update mesh based skybox colours if applicable.
2767+
sky->setSkyColors(*event->set_sky);
2768+
sky->setHorizonTint(
2769+
event->set_sky->sun_tint,
2770+
event->set_sky->moon_tint,
2771+
event->set_sky->tint_type
2772+
);
2773+
} else if (event->set_sky->type == "skybox" &&
2774+
event->set_sky->textures.size() == 6) {
2775+
// Disable the dyanmic mesh skybox:
2776+
sky->setVisible(false);
2777+
// Set fog colors:
2778+
sky->setFallbackBgColor(event->set_sky->bgcolor);
2779+
// Set sunrise and sunset fog tinting:
2780+
sky->setHorizonTint(
2781+
event->set_sky->sun_tint,
2782+
event->set_sky->moon_tint,
2783+
event->set_sky->tint_type
2784+
);
2785+
// Add textures to skybox.
2786+
for (int i = 0; i < 6; i++)
2787+
sky->addTextureToSkybox(event->set_sky->textures[i], i, texture_src);
2788+
} else {
2789+
// Handle everything else as plain color.
2790+
if (event->set_sky->type != "plain")
27732791
infostream << "Unknown sky type: "
2774-
<< (*event->set_sky.type) << std::endl;
2775-
2776-
sky->setFallbackBgColor(*event->set_sky.bgcolor);
2792+
<< (event->set_sky->type) << std::endl;
2793+
sky->setVisible(false);
2794+
sky->setFallbackBgColor(event->set_sky->bgcolor);
2795+
// Disable directional sun/moon tinting on plain or invalid skyboxes.
2796+
sky->setHorizonTint(
2797+
event->set_sky->bgcolor,
2798+
event->set_sky->bgcolor,
2799+
"custom"
2800+
);
27772801
}
2802+
delete event->set_sky;
2803+
}
27782804

2779-
delete event->set_sky.bgcolor;
2780-
delete event->set_sky.type;
2781-
delete event->set_sky.params;
2805+
void Game::handleClientEvent_SetSun(ClientEvent *event, CameraOrientation *cam)
2806+
{
2807+
sky->setSunVisible(event->sun_params->visible);
2808+
sky->setSunTexture(event->sun_params->texture,
2809+
event->sun_params->tonemap, texture_src);
2810+
sky->setSunScale(event->sun_params->scale);
2811+
sky->setSunriseVisible(event->sun_params->sunrise_visible);
2812+
sky->setSunriseTexture(event->sun_params->sunrise, texture_src);
2813+
delete event->sun_params;
2814+
}
2815+
2816+
void Game::handleClientEvent_SetMoon(ClientEvent *event, CameraOrientation *cam)
2817+
{
2818+
sky->setMoonVisible(event->moon_params->visible);
2819+
sky->setMoonTexture(event->moon_params->texture,
2820+
event->moon_params->tonemap, texture_src);
2821+
sky->setMoonScale(event->moon_params->scale);
2822+
delete event->moon_params;
2823+
}
2824+
2825+
void Game::handleClientEvent_SetStars(ClientEvent *event, CameraOrientation *cam)
2826+
{
2827+
sky->setStarsVisible(event->star_params->visible);
2828+
sky->setStarCount(event->star_params->count, false);
2829+
sky->setStarColor(event->star_params->starcolor);
2830+
sky->setStarScale(event->star_params->scale);
2831+
delete event->star_params;
27822832
}
27832833

27842834
void Game::handleClientEvent_OverrideDayNigthRatio(ClientEvent *event,
@@ -3706,7 +3756,7 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime,
37063756
video::SColor clouds_dark = clouds->getColor()
37073757
.getInterpolated(video::SColor(255, 0, 0, 0), 0.9);
37083758
sky->overrideColors(clouds_dark, clouds->getColor());
3709-
sky->setBodiesVisible(false);
3759+
sky->setInClouds(true);
37103760
runData.fog_range = std::fmin(runData.fog_range * 0.5f, 32.0f * BS);
37113761
// do not draw clouds after all
37123762
clouds->setVisible(false);

0 commit comments

Comments
 (0)
Please sign in to comment.