summaryrefslogtreecommitdiff
path: root/src/client
diff options
context:
space:
mode:
authorsfan5 <sfan5@live.de>2021-04-05 13:38:31 +0200
committerGitHub <noreply@github.com>2021-04-05 13:38:31 +0200
commitf0bad0e2badbb7d4777aac7de1b50239bca4010a (patch)
tree4c3115a42ac86e9a64d9e5f088fe187022885779 /src/client
parent3e1904fa8c4aae3448d58b7e60545a4fdd8234f3 (diff)
downloadminetest-f0bad0e2badbb7d4777aac7de1b50239bca4010a.tar.gz
minetest-f0bad0e2badbb7d4777aac7de1b50239bca4010a.tar.bz2
minetest-f0bad0e2badbb7d4777aac7de1b50239bca4010a.zip
Reserve vectors before pushing and other code quality changes (#11161)
Diffstat (limited to 'src/client')
-rw-r--r--src/client/clientmap.cpp9
-rw-r--r--src/client/clouds.cpp2
-rw-r--r--src/client/hud.cpp16
-rw-r--r--src/client/sky.cpp26
-rw-r--r--src/client/sky.h22
5 files changed, 38 insertions, 37 deletions
diff --git a/src/client/clientmap.cpp b/src/client/clientmap.cpp
index be8343009..c5b47532c 100644
--- a/src/client/clientmap.cpp
+++ b/src/client/clientmap.cpp
@@ -499,12 +499,12 @@ int ClientMap::getBackgroundBrightness(float max_d, u32 daylight_factor,
static v3f z_directions[50] = {
v3f(-100, 0, 0)
};
- static f32 z_offsets[sizeof(z_directions)/sizeof(*z_directions)] = {
+ static f32 z_offsets[50] = {
-1000,
};
- if(z_directions[0].X < -99){
- for(u32 i=0; i<sizeof(z_directions)/sizeof(*z_directions); i++){
+ if (z_directions[0].X < -99) {
+ for (u32 i = 0; i < ARRLEN(z_directions); i++) {
// Assumes FOV of 72 and 16/9 aspect ratio
z_directions[i] = v3f(
0.02 * myrand_range(-100, 100),
@@ -520,7 +520,8 @@ int ClientMap::getBackgroundBrightness(float max_d, u32 daylight_factor,
if(sunlight_min_d > 35*BS)
sunlight_min_d = 35*BS;
std::vector<int> values;
- for(u32 i=0; i<sizeof(z_directions)/sizeof(*z_directions); i++){
+ values.reserve(ARRLEN(z_directions));
+ for (u32 i = 0; i < ARRLEN(z_directions); i++) {
v3f z_dir = z_directions[i];
core::CMatrix4<f32> a;
a.buildRotateFromTo(v3f(0,1,0), z_dir);
diff --git a/src/client/clouds.cpp b/src/client/clouds.cpp
index 253dee8b9..5a075aaf0 100644
--- a/src/client/clouds.cpp
+++ b/src/client/clouds.cpp
@@ -170,7 +170,7 @@ void Clouds::render()
// Read noise
- std::vector<char> grid(m_cloud_radius_i * 2 * m_cloud_radius_i * 2); // vector<bool> is broken
+ std::vector<bool> grid(m_cloud_radius_i * 2 * m_cloud_radius_i * 2);
std::vector<video::S3DVertex> vertices;
vertices.reserve(16 * m_cloud_radius_i * m_cloud_radius_i);
diff --git a/src/client/hud.cpp b/src/client/hud.cpp
index e5c7a4cfd..6d332490c 100644
--- a/src/client/hud.cpp
+++ b/src/client/hud.cpp
@@ -336,22 +336,22 @@ void Hud::drawLuaElements(const v3s16 &camera_offset)
irr::gui::IGUIFont* font = g_fontengine->getFont();
// Reorder elements by z_index
- std::vector<size_t> ids;
+ std::vector<HudElement*> elems;
+ elems.reserve(player->maxHudId());
for (size_t i = 0; i != player->maxHudId(); i++) {
HudElement *e = player->getHud(i);
if (!e)
continue;
- auto it = ids.begin();
- while (it != ids.end() && player->getHud(*it)->z_index <= e->z_index)
+ auto it = elems.begin();
+ while (it != elems.end() && (*it)->z_index <= e->z_index)
++it;
- ids.insert(it, i);
+ elems.insert(it, e);
}
- for (size_t i : ids) {
- HudElement *e = player->getHud(i);
+ for (HudElement *e : elems) {
v2s32 pos(floor(e->pos.X * (float) m_screensize.X + 0.5),
floor(e->pos.Y * (float) m_screensize.Y + 0.5));
@@ -522,8 +522,8 @@ void Hud::drawLuaElements(const v3s16 &camera_offset)
client->getMinimap()->drawMinimap(rect);
break; }
default:
- infostream << "Hud::drawLuaElements: ignoring drawform " << e->type <<
- " of hud element ID " << i << " due to unrecognized type" << std::endl;
+ infostream << "Hud::drawLuaElements: ignoring drawform " << e->type
+ << " due to unrecognized type" << std::endl;
}
}
}
diff --git a/src/client/sky.cpp b/src/client/sky.cpp
index caf695e7a..44c8f1574 100644
--- a/src/client/sky.cpp
+++ b/src/client/sky.cpp
@@ -82,13 +82,13 @@ Sky::Sky(s32 id, ITextureSource *tsrc, IShaderSource *ssrc) :
// Ensures that sun and moon textures and tonemaps are correct.
setSkyDefaults();
m_sun_texture = tsrc->isKnownSourceImage(m_sun_params.texture) ?
- tsrc->getTextureForMesh(m_sun_params.texture) : NULL;
+ tsrc->getTextureForMesh(m_sun_params.texture) : nullptr;
m_moon_texture = tsrc->isKnownSourceImage(m_moon_params.texture) ?
- tsrc->getTextureForMesh(m_moon_params.texture) : NULL;
+ tsrc->getTextureForMesh(m_moon_params.texture) : nullptr;
m_sun_tonemap = tsrc->isKnownSourceImage(m_sun_params.tonemap) ?
- tsrc->getTexture(m_sun_params.tonemap) : NULL;
+ tsrc->getTexture(m_sun_params.tonemap) : nullptr;
m_moon_tonemap = tsrc->isKnownSourceImage(m_moon_params.tonemap) ?
- tsrc->getTexture(m_moon_params.tonemap) : NULL;
+ tsrc->getTexture(m_moon_params.tonemap) : nullptr;
if (m_sun_texture) {
m_materials[3] = baseMaterial();
@@ -744,14 +744,14 @@ void Sky::place_sky_body(
}
}
-void Sky::setSunTexture(std::string sun_texture,
- std::string sun_tonemap, ITextureSource *tsrc)
+void Sky::setSunTexture(const std::string &sun_texture,
+ const std::string &sun_tonemap, ITextureSource *tsrc)
{
// Ignore matching textures (with modifiers) entirely,
// but lets at least update the tonemap before hand.
m_sun_params.tonemap = sun_tonemap;
m_sun_tonemap = tsrc->isKnownSourceImage(m_sun_params.tonemap) ?
- tsrc->getTexture(m_sun_params.tonemap) : NULL;
+ tsrc->getTexture(m_sun_params.tonemap) : nullptr;
m_materials[3].Lighting = !!m_sun_tonemap;
if (m_sun_params.texture == sun_texture)
@@ -780,7 +780,7 @@ void Sky::setSunTexture(std::string sun_texture,
}
}
-void Sky::setSunriseTexture(std::string sunglow_texture,
+void Sky::setSunriseTexture(const std::string &sunglow_texture,
ITextureSource* tsrc)
{
// Ignore matching textures (with modifiers) entirely.
@@ -792,14 +792,14 @@ void Sky::setSunriseTexture(std::string sunglow_texture,
);
}
-void Sky::setMoonTexture(std::string moon_texture,
- std::string moon_tonemap, ITextureSource *tsrc)
+void Sky::setMoonTexture(const std::string &moon_texture,
+ const std::string &moon_tonemap, ITextureSource *tsrc)
{
// Ignore matching textures (with modifiers) entirely,
// but lets at least update the tonemap before hand.
m_moon_params.tonemap = moon_tonemap;
m_moon_tonemap = tsrc->isKnownSourceImage(m_moon_params.tonemap) ?
- tsrc->getTexture(m_moon_params.tonemap) : NULL;
+ tsrc->getTexture(m_moon_params.tonemap) : nullptr;
m_materials[4].Lighting = !!m_moon_tonemap;
if (m_moon_params.texture == moon_texture)
@@ -893,7 +893,7 @@ void Sky::setSkyColors(const SkyColor &sky_color)
}
void Sky::setHorizonTint(video::SColor sun_tint, video::SColor moon_tint,
- std::string use_sun_tint)
+ const std::string &use_sun_tint)
{
// Change sun and moon tinting:
m_sky_params.fog_sun_tint = sun_tint;
@@ -907,7 +907,7 @@ void Sky::setHorizonTint(video::SColor sun_tint, video::SColor moon_tint,
m_default_tint = true;
}
-void Sky::addTextureToSkybox(std::string texture, int material_id,
+void Sky::addTextureToSkybox(const std::string &texture, int material_id,
ITextureSource *tsrc)
{
// Sanity check for more than six textures.
diff --git a/src/client/sky.h b/src/client/sky.h
index 342a97596..dc7da5021 100644
--- a/src/client/sky.h
+++ b/src/client/sky.h
@@ -65,15 +65,15 @@ public:
}
void setSunVisible(bool sun_visible) { m_sun_params.visible = sun_visible; }
- void setSunTexture(std::string sun_texture,
- std::string sun_tonemap, ITextureSource *tsrc);
+ void setSunTexture(const std::string &sun_texture,
+ const std::string &sun_tonemap, ITextureSource *tsrc);
void setSunScale(f32 sun_scale) { m_sun_params.scale = sun_scale; }
void setSunriseVisible(bool glow_visible) { m_sun_params.sunrise_visible = glow_visible; }
- void setSunriseTexture(std::string sunglow_texture, ITextureSource* tsrc);
+ void setSunriseTexture(const std::string &sunglow_texture, ITextureSource* tsrc);
void setMoonVisible(bool moon_visible) { m_moon_params.visible = moon_visible; }
- void setMoonTexture(std::string moon_texture,
- std::string moon_tonemap, ITextureSource *tsrc);
+ void setMoonTexture(const std::string &moon_texture,
+ const std::string &moon_tonemap, ITextureSource *tsrc);
void setMoonScale(f32 moon_scale) { m_moon_params.scale = moon_scale; }
void setStarsVisible(bool stars_visible) { m_star_params.visible = stars_visible; }
@@ -87,21 +87,21 @@ public:
void setVisible(bool visible) { m_visible = visible; }
// Set only from set_sky API
void setCloudsEnabled(bool clouds_enabled) { m_clouds_enabled = clouds_enabled; }
- void setFallbackBgColor(const video::SColor &fallback_bg_color)
+ void setFallbackBgColor(video::SColor fallback_bg_color)
{
m_fallback_bg_color = fallback_bg_color;
}
- void overrideColors(const video::SColor &bgcolor, const video::SColor &skycolor)
+ void overrideColors(video::SColor bgcolor, video::SColor skycolor)
{
m_bgcolor = bgcolor;
m_skycolor = skycolor;
}
void setSkyColors(const SkyColor &sky_color);
void setHorizonTint(video::SColor sun_tint, video::SColor moon_tint,
- std::string use_sun_tint);
+ const std::string &use_sun_tint);
void setInClouds(bool clouds) { m_in_clouds = clouds; }
void clearSkyboxTextures() { m_sky_params.textures.clear(); }
- void addTextureToSkybox(std::string texture, int material_id,
+ void addTextureToSkybox(const std::string &texture, int material_id,
ITextureSource *tsrc);
const video::SColorf &getCurrentStarColor() const { return m_star_color; }
@@ -126,7 +126,7 @@ private:
}
// Mix two colors by a given amount
- video::SColor m_mix_scolor(video::SColor col1, video::SColor col2, f32 factor)
+ static video::SColor m_mix_scolor(video::SColor col1, video::SColor col2, f32 factor)
{
video::SColor result = video::SColor(
col1.getAlpha() * (1 - factor) + col2.getAlpha() * factor,
@@ -135,7 +135,7 @@ private:
col1.getBlue() * (1 - factor) + col2.getBlue() * factor);
return result;
}
- video::SColorf m_mix_scolorf(video::SColorf col1, video::SColorf col2, f32 factor)
+ static video::SColorf m_mix_scolorf(video::SColorf col1, video::SColorf col2, f32 factor)
{
video::SColorf result =
video::SColorf(col1.r * (1 - factor) + col2.r * factor,