From b9a0626d8893324aa6be41607efbc131d23eee2d Mon Sep 17 00:00:00 2001 From: Jordan Snelling Date: Sun, 8 Mar 2020 15:13:36 +0000 Subject: [PATCH] Fix star visilibity and documentation (since 946c03c6) Fix memory leak (unused allocation) Fix star rendering Rename sky color struct Fix stars on android Remove extraneous .data() from android star draw --- doc/lua_api.txt | 2 +- src/client/sky.cpp | 35 +++++++++------------------------ src/script/lua_api/l_object.cpp | 2 +- src/skyparams.h | 9 +++++---- 4 files changed, 16 insertions(+), 32 deletions(-) diff --git a/doc/lua_api.txt b/doc/lua_api.txt index a603a5a37..5a3e37292 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -6044,7 +6044,7 @@ object you are working with still exists. * `star_color`: ColorSpec, sets the colors of the stars, alpha channel is used to set overall star brightness. (default: `#ebebff69`) - * `size`: Float controlling the overall size of the stars (default: `1`) + * `scale`: Float controlling the overall size of the stars (default: `1`) * `get_stars()`: returns a table with the current stars parameters as in `set_stars`. * `set_clouds(parameters)`: set cloud parameters diff --git a/src/client/sky.cpp b/src/client/sky.cpp index f2cab2f0f..7a7b188ce 100644 --- a/src/client/sky.cpp +++ b/src/client/sky.cpp @@ -724,10 +724,10 @@ void Sky::draw_stars(video::IVideoDriver * driver, float wicked_time_of_day) if (m_star_params.starcolor.getAlpha() < 1) return; #if ENABLE_GLES - u16 *indices = new u16[m_star_count * 3]; + u16 *indices = new u16[m_star_params.count * 3]; video::S3DVertex *vertices = - new video::S3DVertex[m_star_count * 3]; - for (u32 i = 0; i < m_star_count; i++) { + new video::S3DVertex[m_star_params.count * 3]; + for (u32 i = 0; i < m_star_params.count; i++) { indices[i * 3 + 0] = i * 3 + 0; indices[i * 3 + 1] = i * 3 + 1; indices[i * 3 + 2] = i * 3 + 2; @@ -750,8 +750,8 @@ void Sky::draw_stars(video::IVideoDriver * driver, float wicked_time_of_day) vertices[i * 3 + 2].Pos = p2; vertices[i * 3 + 2].Color = starcolor; } - driver->drawIndexedTriangleList(vertices.data(), m_star_count * 3, - indices.data(), m_star_count); + driver->drawIndexedTriangleList(vertices, m_star_params.count * 3, + indices, m_star_params.count); delete[] indices; delete[] vertices; #else @@ -864,7 +864,7 @@ void Sky::setSunTexture(std::string sun_texture, } } -void Sky::setSunriseTexture(std::string sunglow_texture, +void Sky::setSunriseTexture(std::string sunglow_texture, ITextureSource* tsrc) { // Ignore matching textures (with modifiers) entirely. @@ -876,7 +876,7 @@ void Sky::setSunriseTexture(std::string sunglow_texture, ); } -void Sky::setMoonTexture(std::string moon_texture, +void Sky::setMoonTexture(std::string moon_texture, std::string moon_tonemap, ITextureSource *tsrc) { // Ignore matching textures (with modifiers) entirely, @@ -914,25 +914,8 @@ void Sky::setMoonTexture(std::string moon_texture, void Sky::setStarCount(u16 star_count, bool force_update) { - // Force updating star count at game init. - if (force_update) { - m_star_params.count = star_count; - m_stars.clear(); - // Rebuild the stars surrounding the camera - for (u16 i = 0; i < star_count; i++) { - v3f star = v3f( - myrand_range(-10000, 10000), - myrand_range(-10000, 10000), - myrand_range(-10000, 10000) - ); - - star.normalize(); - m_stars.emplace_back(star); - } - // Ignore changing star count if the new value is identical - } else if (m_star_params.count == star_count) - return; - else { + // Allow force updating star count at game init. + if (m_star_params.count != star_count || force_update) { m_star_params.count = star_count; m_stars.clear(); // Rebuild the stars surrounding the camera diff --git a/src/script/lua_api/l_object.cpp b/src/script/lua_api/l_object.cpp index 70e21f088..23ed1ffe0 100644 --- a/src/script/lua_api/l_object.cpp +++ b/src/script/lua_api/l_object.cpp @@ -2059,7 +2059,7 @@ int ObjectRef::l_set_stars(lua_State *L) lua_pop(L, 1); star_params.scale = getfloatfield_default(L, 2, - "size", star_params.scale); + "scale", star_params.scale); getServer(L)->setStars(player, star_params); lua_pushboolean(L, true); diff --git a/src/skyparams.h b/src/skyparams.h index 877907e31..9fdfd89da 100644 --- a/src/skyparams.h +++ b/src/skyparams.h @@ -19,7 +19,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #pragma once -struct skycolor +struct SkyColor { video::SColor day_sky; video::SColor day_horizon; @@ -36,7 +36,7 @@ struct SkyboxParams std::string type; std::vector textures; bool clouds; - skycolor sky_color; + SkyColor sky_color; video::SColor sun_tint; video::SColor moon_tint; std::string tint_type; @@ -72,9 +72,9 @@ struct StarParams class SkyboxDefaults { public: - const skycolor getSkyColorDefaults() + const SkyColor getSkyColorDefaults() { - skycolor sky; + SkyColor sky; // Horizon colors sky.day_horizon = video::SColor(255, 155, 193, 240); sky.indoors = video::SColor(255, 100, 100, 100); @@ -112,6 +112,7 @@ public: const StarParams getStarDefaults() { StarParams stars; + stars.visible = true; stars.count = 1000; stars.starcolor = video::SColor(105, 235, 235, 255); stars.scale = 1;