diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/client/clouds.h | 2 | ||||
-rw-r--r-- | src/cloudparams.h | 30 | ||||
-rw-r--r-- | src/remoteplayer.cpp | 17 | ||||
-rw-r--r-- | src/remoteplayer.h | 1 | ||||
-rw-r--r-- | src/script/lua_api/l_object.cpp | 140 | ||||
-rw-r--r-- | src/skyparams.h | 43 |
6 files changed, 115 insertions, 118 deletions
diff --git a/src/client/clouds.h b/src/client/clouds.h index c009a05b7..6db88d93c 100644 --- a/src/client/clouds.h +++ b/src/client/clouds.h @@ -22,7 +22,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "irrlichttypes_extrabloated.h" #include <iostream> #include "constants.h" -#include "cloudparams.h" +#include "skyparams.h" // Menu clouds class Clouds; diff --git a/src/cloudparams.h b/src/cloudparams.h deleted file mode 100644 index 88b5760ee..000000000 --- a/src/cloudparams.h +++ /dev/null @@ -1,30 +0,0 @@ -/* -Minetest -Copyright (C) 2017 bendeutsch, Ben Deutsch <ben@bendeutsch.de> - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Lesser General Public License for more details. - -You should have received a copy of the GNU Lesser General Public License along -with this program; if not, write to the Free Software Foundation, Inc., -51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#pragma once - -struct CloudParams -{ - float density; - video::SColor color_bright; - video::SColor color_ambient; - float thickness; - float height; - v2f speed; -}; diff --git a/src/remoteplayer.cpp b/src/remoteplayer.cpp index d537965a2..3f0eae0f0 100644 --- a/src/remoteplayer.cpp +++ b/src/remoteplayer.cpp @@ -68,19 +68,10 @@ RemotePlayer::RemotePlayer(const char *name, IItemDefManager *idef): m_cloud_params.speed = v2f(0.0f, -2.0f); // Skybox defaults: - - SkyboxDefaults sky_defaults; - - m_skybox_params.sky_color = sky_defaults.getSkyColorDefaults(); - m_skybox_params.type = "regular"; - m_skybox_params.clouds = true; - m_skybox_params.fog_sun_tint = video::SColor(255, 244, 125, 29); - m_skybox_params.fog_moon_tint = video::SColorf(0.5, 0.6, 0.8, 1).toSColor(); - m_skybox_params.fog_tint_type = "default"; - - m_sun_params = sky_defaults.getSunDefaults(); - m_moon_params = sky_defaults.getMoonDefaults(); - m_star_params = sky_defaults.getStarDefaults(); + m_skybox_params = SkyboxDefaults::getSkyDefaults(); + m_sun_params = SkyboxDefaults::getSunDefaults(); + m_moon_params = SkyboxDefaults::getMoonDefaults(); + m_star_params = SkyboxDefaults::getStarDefaults(); } diff --git a/src/remoteplayer.h b/src/remoteplayer.h index bd39b68ba..c8991480b 100644 --- a/src/remoteplayer.h +++ b/src/remoteplayer.h @@ -21,7 +21,6 @@ with this program; if not, write to the Free Software Foundation, Inc., #pragma once #include "player.h" -#include "cloudparams.h" #include "skyparams.h" class PlayerSAO; diff --git a/src/script/lua_api/l_object.cpp b/src/script/lua_api/l_object.cpp index 7d937b306..b177a9f7e 100644 --- a/src/script/lua_api/l_object.cpp +++ b/src/script/lua_api/l_object.cpp @@ -1732,9 +1732,11 @@ int ObjectRef::l_set_sky(lua_State *L) return 0; SkyboxParams sky_params = player->getSkyParams(); - bool is_colorspec = is_color_table(L, 2); - if (lua_istable(L, 2) && !is_colorspec) { + // reset if empty + if (lua_isnoneornil(L, 2) && lua_isnone(L, 3)) { + sky_params = SkyboxDefaults::getSkyDefaults(); + } else if (lua_istable(L, 2) && !is_color_table(L, 2)) { lua_getfield(L, 2, "base_color"); if (!lua_isnil(L, -1)) read_color(L, -1, &sky_params.bgcolor); @@ -1758,17 +1760,11 @@ int ObjectRef::l_set_sky(lua_State *L) } lua_pop(L, 1); - /* - We want to avoid crashes, so we're checking even if we're not using them. - However, we want to ensure that the skybox can be set to nil when - using "regular" or "plain" skybox modes as textures aren't needed. - */ - - if (sky_params.textures.size() != 6 && sky_params.textures.size() > 0) + // Validate that we either have six or zero textures + if (sky_params.textures.size() != 6 && !sky_params.textures.empty()) throw LuaError("Skybox expects 6 textures!"); - sky_params.clouds = getboolfield_default(L, 2, - "clouds", sky_params.clouds); + sky_params.clouds = getboolfield_default(L, 2, "clouds", sky_params.clouds); lua_getfield(L, 2, "sky_color"); if (lua_istable(L, -1)) { @@ -1816,7 +1812,7 @@ int ObjectRef::l_set_sky(lua_State *L) sky_params.fog_tint_type = luaL_checkstring(L, -1); lua_pop(L, 1); - // Because we need to leave the "sky_color" table. + // pop "sky_color" table lua_pop(L, 1); } } else { @@ -1852,11 +1848,8 @@ int ObjectRef::l_set_sky(lua_State *L) if (lua_istable(L, 4)) { lua_pushnil(L); while (lua_next(L, 4) != 0) { - // Key at index -2, and value at index -1 - if (lua_isstring(L, -1)) - sky_params.textures.emplace_back(readParam<std::string>(L, -1)); - else - sky_params.textures.emplace_back(""); + // Key at index -2, and value at index -1 + sky_params.textures.emplace_back(readParam<std::string>(L, -1)); // Remove the value, keep the key for the next iteration lua_pop(L, 1); } @@ -1872,6 +1865,7 @@ int ObjectRef::l_set_sky(lua_State *L) getServer(L)->setMoon(player, moon_params); getServer(L)->setStars(player, star_params); } + getServer(L)->setSky(player, sky_params); lua_pushboolean(L, true); return 1; @@ -1947,21 +1941,20 @@ int ObjectRef::l_set_sun(lua_State *L) if (player == nullptr) return 0; - luaL_checktype(L, 2, LUA_TTABLE); SunParams sun_params = player->getSunParams(); - sun_params.visible = getboolfield_default(L, 2, - "visible", sun_params.visible); - sun_params.texture = getstringfield_default(L, 2, - "texture", sun_params.texture); - sun_params.tonemap = getstringfield_default(L, 2, - "tonemap", sun_params.tonemap); - sun_params.sunrise = getstringfield_default(L, 2, - "sunrise", sun_params.sunrise); - sun_params.sunrise_visible = getboolfield_default(L, 2, - "sunrise_visible", sun_params.sunrise_visible); - sun_params.scale = getfloatfield_default(L, 2, - "scale", sun_params.scale); + // reset if empty + if (lua_isnoneornil(L, 2)) { + sun_params = SkyboxDefaults::getSunDefaults(); + } else { + luaL_checktype(L, 2, LUA_TTABLE); + sun_params.visible = getboolfield_default(L, 2, "visible", sun_params.visible); + sun_params.texture = getstringfield_default(L, 2, "texture", sun_params.texture); + sun_params.tonemap = getstringfield_default(L, 2, "tonemap", sun_params.tonemap); + sun_params.sunrise = getstringfield_default(L, 2, "sunrise", sun_params.sunrise); + sun_params.sunrise_visible = getboolfield_default(L, 2, "sunrise_visible", sun_params.sunrise_visible); + sun_params.scale = getfloatfield_default(L, 2, "scale", sun_params.scale); + } getServer(L)->setSun(player, sun_params); lua_pushboolean(L, true); @@ -2004,17 +1997,18 @@ int ObjectRef::l_set_moon(lua_State *L) if (player == nullptr) return 0; - luaL_checktype(L, 2, LUA_TTABLE); MoonParams moon_params = player->getMoonParams(); - moon_params.visible = getboolfield_default(L, 2, - "visible", moon_params.visible); - moon_params.texture = getstringfield_default(L, 2, - "texture", moon_params.texture); - moon_params.tonemap = getstringfield_default(L, 2, - "tonemap", moon_params.tonemap); - moon_params.scale = getfloatfield_default(L, 2, - "scale", moon_params.scale); + // reset if empty + if (lua_isnoneornil(L, 2)) { + moon_params = SkyboxDefaults::getMoonDefaults(); + } else { + luaL_checktype(L, 2, LUA_TTABLE); + moon_params.visible = getboolfield_default(L, 2, "visible", moon_params.visible); + moon_params.texture = getstringfield_default(L, 2, "texture", moon_params.texture); + moon_params.tonemap = getstringfield_default(L, 2, "tonemap", moon_params.tonemap); + moon_params.scale = getfloatfield_default(L, 2, "scale", moon_params.scale); + } getServer(L)->setMoon(player, moon_params); lua_pushboolean(L, true); @@ -2053,21 +2047,24 @@ int ObjectRef::l_set_stars(lua_State *L) if (player == nullptr) return 0; - luaL_checktype(L, 2, LUA_TTABLE); StarParams star_params = player->getStarParams(); - star_params.visible = getboolfield_default(L, 2, - "visible", star_params.visible); - star_params.count = getintfield_default(L, 2, - "count", star_params.count); + // reset if empty + if (lua_isnoneornil(L, 2)) { + star_params = SkyboxDefaults::getStarDefaults(); + } else { + luaL_checktype(L, 2, LUA_TTABLE); + star_params.visible = getboolfield_default(L, 2, "visible", star_params.visible); + star_params.count = getintfield_default(L, 2, "count", star_params.count); - lua_getfield(L, 2, "star_color"); - if (!lua_isnil(L, -1)) - read_color(L, -1, &star_params.starcolor); - lua_pop(L, 1); + lua_getfield(L, 2, "star_color"); + if (!lua_isnil(L, -1)) + read_color(L, -1, &star_params.starcolor); + lua_pop(L, 1); - star_params.scale = getfloatfield_default(L, 2, - "scale", star_params.scale); + star_params.scale = getfloatfield_default(L, 2, + "scale", star_params.scale); + } getServer(L)->setStars(player, star_params); lua_pushboolean(L, true); @@ -2106,31 +2103,36 @@ int ObjectRef::l_set_clouds(lua_State *L) if (player == nullptr) return 0; - luaL_checktype(L, 2, LUA_TTABLE); CloudParams cloud_params = player->getCloudParams(); - cloud_params.density = getfloatfield_default(L, 2, "density", cloud_params.density); + // reset if empty + if (lua_isnoneornil(L, 2)) { + cloud_params = SkyboxDefaults::getCloudDefaults(); + } else { + luaL_checktype(L, 2, LUA_TTABLE); + cloud_params.density = getfloatfield_default(L, 2, "density", cloud_params.density); - lua_getfield(L, 2, "color"); - if (!lua_isnil(L, -1)) - read_color(L, -1, &cloud_params.color_bright); - lua_pop(L, 1); - lua_getfield(L, 2, "ambient"); - if (!lua_isnil(L, -1)) - read_color(L, -1, &cloud_params.color_ambient); - lua_pop(L, 1); + lua_getfield(L, 2, "color"); + if (!lua_isnil(L, -1)) + read_color(L, -1, &cloud_params.color_bright); + lua_pop(L, 1); + lua_getfield(L, 2, "ambient"); + if (!lua_isnil(L, -1)) + read_color(L, -1, &cloud_params.color_ambient); + lua_pop(L, 1); - cloud_params.height = getfloatfield_default(L, 2, "height", cloud_params.height ); - cloud_params.thickness = getfloatfield_default(L, 2, "thickness", cloud_params.thickness); + cloud_params.height = getfloatfield_default(L, 2, "height", cloud_params.height); + cloud_params.thickness = getfloatfield_default(L, 2, "thickness", cloud_params.thickness); - lua_getfield(L, 2, "speed"); - if (lua_istable(L, -1)) { - v2f new_speed; - new_speed.X = getfloatfield_default(L, -1, "x", 0); - new_speed.Y = getfloatfield_default(L, -1, "z", 0); - cloud_params.speed = new_speed; + lua_getfield(L, 2, "speed"); + if (lua_istable(L, -1)) { + v2f new_speed; + new_speed.X = getfloatfield_default(L, -1, "x", 0); + new_speed.Y = getfloatfield_default(L, -1, "z", 0); + cloud_params.speed = new_speed; + } + lua_pop(L, 1); } - lua_pop(L, 1); getServer(L)->setClouds(player, cloud_params); lua_pushboolean(L, true); diff --git a/src/skyparams.h b/src/skyparams.h index 1de494d69..cabbf531c 100644 --- a/src/skyparams.h +++ b/src/skyparams.h @@ -68,11 +68,34 @@ struct StarParams f32 scale; }; +struct CloudParams +{ + float density; + video::SColor color_bright; + video::SColor color_ambient; + float thickness; + float height; + v2f speed; +}; + // Utility class for setting default sky, sun, moon, stars values: class SkyboxDefaults { public: - const SkyColor getSkyColorDefaults() + static const SkyboxParams getSkyDefaults() + { + SkyboxParams sky; + sky.bgcolor = video::SColor(255, 255, 255, 255); + sky.type = "regular"; + sky.clouds = true; + sky.sky_color = getSkyColorDefaults(); + sky.fog_sun_tint = video::SColor(255, 244, 125, 29); + sky.fog_moon_tint = video::SColorf(0.5, 0.6, 0.8, 1).toSColor(); + sky.fog_tint_type = "default"; + return sky; + } + + static const SkyColor getSkyColorDefaults() { SkyColor sky; // Horizon colors @@ -87,7 +110,7 @@ public: return sky; } - const SunParams getSunDefaults() + static const SunParams getSunDefaults() { SunParams sun; sun.visible = true; @@ -99,7 +122,7 @@ public: return sun; } - const MoonParams getMoonDefaults() + static const MoonParams getMoonDefaults() { MoonParams moon; moon.visible = true; @@ -109,7 +132,7 @@ public: return moon; } - const StarParams getStarDefaults() + static const StarParams getStarDefaults() { StarParams stars; stars.visible = true; @@ -118,4 +141,16 @@ public: stars.scale = 1; return stars; } + + static const CloudParams getCloudDefaults() + { + CloudParams clouds; + clouds.density = 0.4f; + clouds.color_bright = video::SColor(229, 240, 240, 255); + clouds.color_ambient = video::SColor(255, 0, 0, 0); + clouds.thickness = 16.0f; + clouds.height = 120; + clouds.speed = v2f(0.0f, -2.0f); + return clouds; + } }; |