mirror of
https://github.com/minetest/minetest.git
synced 2025-07-04 08:50:22 +02:00
Reserve vectors before pushing and other code quality changes (#11161)
This commit is contained in:
@ -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);
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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.
|
||||
|
@ -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,
|
||||
|
Reference in New Issue
Block a user