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
This commit is contained in:
Jordan Snelling 2020-03-08 15:13:36 +00:00 committed by GitHub
parent 23c907befe
commit b9a0626d88
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 32 deletions

@ -6044,7 +6044,7 @@ object you are working with still exists.
* `star_color`: ColorSpec, sets the colors of the stars, * `star_color`: ColorSpec, sets the colors of the stars,
alpha channel is used to set overall star brightness. alpha channel is used to set overall star brightness.
(default: `#ebebff69`) (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 * `get_stars()`: returns a table with the current stars parameters as in
`set_stars`. `set_stars`.
* `set_clouds(parameters)`: set cloud parameters * `set_clouds(parameters)`: set cloud parameters

@ -724,10 +724,10 @@ void Sky::draw_stars(video::IVideoDriver * driver, float wicked_time_of_day)
if (m_star_params.starcolor.getAlpha() < 1) if (m_star_params.starcolor.getAlpha() < 1)
return; return;
#if ENABLE_GLES #if ENABLE_GLES
u16 *indices = new u16[m_star_count * 3]; u16 *indices = new u16[m_star_params.count * 3];
video::S3DVertex *vertices = video::S3DVertex *vertices =
new video::S3DVertex[m_star_count * 3]; new video::S3DVertex[m_star_params.count * 3];
for (u32 i = 0; i < m_star_count; i++) { for (u32 i = 0; i < m_star_params.count; i++) {
indices[i * 3 + 0] = i * 3 + 0; indices[i * 3 + 0] = i * 3 + 0;
indices[i * 3 + 1] = i * 3 + 1; indices[i * 3 + 1] = i * 3 + 1;
indices[i * 3 + 2] = i * 3 + 2; 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].Pos = p2;
vertices[i * 3 + 2].Color = starcolor; vertices[i * 3 + 2].Color = starcolor;
} }
driver->drawIndexedTriangleList(vertices.data(), m_star_count * 3, driver->drawIndexedTriangleList(vertices, m_star_params.count * 3,
indices.data(), m_star_count); indices, m_star_params.count);
delete[] indices; delete[] indices;
delete[] vertices; delete[] vertices;
#else #else
@ -914,25 +914,8 @@ void Sky::setMoonTexture(std::string moon_texture,
void Sky::setStarCount(u16 star_count, bool force_update) void Sky::setStarCount(u16 star_count, bool force_update)
{ {
// Force updating star count at game init. // Allow force updating star count at game init.
if (force_update) { if (m_star_params.count != star_count || 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 {
m_star_params.count = star_count; m_star_params.count = star_count;
m_stars.clear(); m_stars.clear();
// Rebuild the stars surrounding the camera // Rebuild the stars surrounding the camera

@ -2059,7 +2059,7 @@ int ObjectRef::l_set_stars(lua_State *L)
lua_pop(L, 1); lua_pop(L, 1);
star_params.scale = getfloatfield_default(L, 2, star_params.scale = getfloatfield_default(L, 2,
"size", star_params.scale); "scale", star_params.scale);
getServer(L)->setStars(player, star_params); getServer(L)->setStars(player, star_params);
lua_pushboolean(L, true); lua_pushboolean(L, true);

@ -19,7 +19,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#pragma once #pragma once
struct skycolor struct SkyColor
{ {
video::SColor day_sky; video::SColor day_sky;
video::SColor day_horizon; video::SColor day_horizon;
@ -36,7 +36,7 @@ struct SkyboxParams
std::string type; std::string type;
std::vector<std::string> textures; std::vector<std::string> textures;
bool clouds; bool clouds;
skycolor sky_color; SkyColor sky_color;
video::SColor sun_tint; video::SColor sun_tint;
video::SColor moon_tint; video::SColor moon_tint;
std::string tint_type; std::string tint_type;
@ -72,9 +72,9 @@ struct StarParams
class SkyboxDefaults class SkyboxDefaults
{ {
public: public:
const skycolor getSkyColorDefaults() const SkyColor getSkyColorDefaults()
{ {
skycolor sky; SkyColor sky;
// Horizon colors // Horizon colors
sky.day_horizon = video::SColor(255, 155, 193, 240); sky.day_horizon = video::SColor(255, 155, 193, 240);
sky.indoors = video::SColor(255, 100, 100, 100); sky.indoors = video::SColor(255, 100, 100, 100);
@ -112,6 +112,7 @@ public:
const StarParams getStarDefaults() const StarParams getStarDefaults()
{ {
StarParams stars; StarParams stars;
stars.visible = true;
stars.count = 1000; stars.count = 1000;
stars.starcolor = video::SColor(105, 235, 235, 255); stars.starcolor = video::SColor(105, 235, 235, 255);
stars.scale = 1; stars.scale = 1;