Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Various uninitialised variable fixes
sky.cpp: m_bgcolor.getAlpha() was being used before initialised

mesh related: m_highlight_mesh_color was being used uninitialised
  • Loading branch information
Zeno- authored and kahrl committed Oct 19, 2014
1 parent fe8ef1b commit 076c5ee
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 27 deletions.
1 change: 1 addition & 0 deletions src/client.cpp
Expand Up @@ -250,6 +250,7 @@ Client::Client(
m_inventory_updated(false),
m_inventory_from_server(NULL),
m_inventory_from_server_age(0.0),
m_show_hud(true),
m_animation_time(0),
m_crack_level(-1),
m_crack_pos(0,0,0),
Expand Down
10 changes: 5 additions & 5 deletions src/content_mapblock.cpp
Expand Up @@ -188,10 +188,10 @@ void mapblock_mesh_generate_special(MeshMakeData *data,

// Create selection mesh
v3s16 p = data->m_highlighted_pos_relative;
if (data->m_show_hud &
(p.X >= 0) & (p.X < MAP_BLOCKSIZE) &
(p.Y >= 0) & (p.Y < MAP_BLOCKSIZE) &
(p.Z >= 0) & (p.Z < MAP_BLOCKSIZE)) {
if (data->m_show_hud &&
(p.X >= 0) && (p.X < MAP_BLOCKSIZE) &&
(p.Y >= 0) && (p.Y < MAP_BLOCKSIZE) &&
(p.Z >= 0) && (p.Z < MAP_BLOCKSIZE)) {

MapNode n = data->m_vmanip.getNodeNoEx(blockpos_nodes + p);
if(n.getContent() != CONTENT_AIR) {
Expand All @@ -215,7 +215,7 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
l = l1;
}
video::SColor c = MapBlock_LightColor(255, l, 0);
data->m_highlight_mesh_color = c;
data->m_highlight_mesh_color = c;
std::vector<aabb3f> boxes = n.getSelectionBoxes(nodedef);
TileSpec h_tile;
h_tile.material_flags |= MATERIAL_FLAG_HIGHLIGHTED;
Expand Down
8 changes: 5 additions & 3 deletions src/mapblock_mesh.cpp
Expand Up @@ -48,6 +48,8 @@ MeshMakeData::MeshMakeData(IGameDef *gamedef):
m_crack_pos_relative(-1337, -1337, -1337),
m_highlighted_pos_relative(-1337, -1337, -1337),
m_smooth_lighting(false),
m_show_hud(false),
m_highlight_mesh_color(255, 255, 255, 255),
m_gamedef(gamedef)
{}

Expand Down Expand Up @@ -330,15 +332,15 @@ static void finalColorBlend(video::SColor& result,

// Emphase blue a bit in darker places
// Each entry of this array represents a range of 8 blue levels
static u8 emphase_blue_when_dark[32] = {
static const u8 emphase_blue_when_dark[32] = {
1, 4, 6, 6, 6, 5, 4, 3, 2, 1, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
};
b += emphase_blue_when_dark[b / 8];
b = irr::core::clamp (b, 0, 255);

// Artificial light is yellow-ish
static u8 emphase_yellow_when_artificial[16] = {
static const u8 emphase_yellow_when_artificial[16] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 10, 15, 15, 15
};
rg += emphase_yellow_when_artificial[night/16];
Expand Down Expand Up @@ -1086,7 +1088,7 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data, v3s16 camera_offset):

mapblock_mesh_generate_special(data, collector);

m_highlight_mesh_color = data->m_highlight_mesh_color;
m_highlight_mesh_color = data->m_highlight_mesh_color;

/*
Convert MeshCollector to SMesh
Expand Down
32 changes: 14 additions & 18 deletions src/sky.cpp
Expand Up @@ -573,6 +573,20 @@ void Sky::update(float time_of_day, float time_brightness,
m_clouds_visible = false;
}

video::SColor bgcolor_bright = m_bgcolor_bright_f.toSColor();
m_bgcolor = video::SColor(
255,
bgcolor_bright.getRed() * m_brightness,
bgcolor_bright.getGreen() * m_brightness,
bgcolor_bright.getBlue() * m_brightness);

video::SColor skycolor_bright = m_skycolor_bright_f.toSColor();
m_skycolor = video::SColor(
255,
skycolor_bright.getRed() * m_brightness,
skycolor_bright.getGreen() * m_brightness,
skycolor_bright.getBlue() * m_brightness);

// Horizon coloring based on sun and moon direction during sunset and sunrise
video::SColor pointcolor = video::SColor(255, 255, 255, m_bgcolor.getAlpha());
if (m_directional_colored_fog) {
Expand Down Expand Up @@ -606,25 +620,7 @@ void Sky::update(float time_of_day, float time_brightness,
// calculate the blend color
pointcolor = m_mix_scolor(pointcolor_moon, pointcolor_sun, pointcolor_blend);
}
}

video::SColor bgcolor_bright = m_bgcolor_bright_f.toSColor();
m_bgcolor = video::SColor(
255,
bgcolor_bright.getRed() * m_brightness,
bgcolor_bright.getGreen() * m_brightness,
bgcolor_bright.getBlue() * m_brightness);
if (m_directional_colored_fog) {
m_bgcolor = m_mix_scolor(m_bgcolor, pointcolor, m_horizon_blend() * 0.5);
}

video::SColor skycolor_bright = m_skycolor_bright_f.toSColor();
m_skycolor = video::SColor(
255,
skycolor_bright.getRed() * m_brightness,
skycolor_bright.getGreen() * m_brightness,
skycolor_bright.getBlue() * m_brightness);
if (m_directional_colored_fog) {
m_skycolor = m_mix_scolor(m_skycolor, pointcolor, m_horizon_blend() * 0.25);
}

Expand Down
3 changes: 2 additions & 1 deletion src/sky.h
Expand Up @@ -79,7 +79,8 @@ class Sky : public scene::ISceneNode
{
if (!m_sunlight_seen)
return 0;
float x; m_time_of_day >= 0.5 ? x = (1 - m_time_of_day) * 2 : x = m_time_of_day * 2;
float x = m_time_of_day >= 0.5 ? (1 - m_time_of_day) * 2 : m_time_of_day * 2;

if (x <= 0.3)
return 0;
if (x <= 0.4) // when the sun and moon are aligned
Expand Down

0 comments on commit 076c5ee

Please sign in to comment.