From 6ccb5835ff55d85156be91473c598eca9d6cb9a6 Mon Sep 17 00:00:00 2001 From: Elias Fleckenstein Date: Wed, 4 Nov 2020 16:57:41 +0100 Subject: Revert "Make Lint Happy" This reverts commit ad148587dcf5244c2d2011dba339786c765c54c4. --- src/client/sky.cpp | 551 +++++++++++++++++++++++------------------------------ 1 file changed, 239 insertions(+), 312 deletions(-) (limited to 'src/client/sky.cpp') diff --git a/src/client/sky.cpp b/src/client/sky.cpp index fa36f623e..2e0cbca86 100644 --- a/src/client/sky.cpp +++ b/src/client/sky.cpp @@ -35,9 +35,8 @@ with this program; if not, write to the Free Software Foundation, Inc., using namespace irr::core; Sky::Sky(s32 id, ITextureSource *tsrc) : - scene::ISceneNode( - RenderingEngine::get_scene_manager()->getRootSceneNode(), - RenderingEngine::get_scene_manager(), id) + scene::ISceneNode(RenderingEngine::get_scene_manager()->getRootSceneNode(), + RenderingEngine::get_scene_manager(), id) { setAutomaticCulling(scene::EAC_OFF); m_box.MaxEdge.set(0, 0, 0); @@ -61,40 +60,33 @@ Sky::Sky(s32 id, ITextureSource *tsrc) : m_materials[0] = mat; m_materials[1] = mat; - // m_materials[1].MaterialType = video::EMT_TRANSPARENT_VERTEX_ALPHA; + //m_materials[1].MaterialType = video::EMT_TRANSPARENT_VERTEX_ALPHA; m_materials[1].MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL; m_materials[2] = mat; m_materials[2].setTexture(0, tsrc->getTextureForMesh("sunrisebg.png")); m_materials[2].MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL; - // m_materials[2].MaterialType = video::EMT_TRANSPARENT_ADD_COLOR; + //m_materials[2].MaterialType = video::EMT_TRANSPARENT_ADD_COLOR; // 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; - m_moon_texture = tsrc->isKnownSourceImage(m_moon_params.texture) - ? tsrc->getTextureForMesh(m_moon_params.texture) - : NULL; - m_sun_tonemap = tsrc->isKnownSourceImage(m_sun_params.tonemap) - ? tsrc->getTexture(m_sun_params.tonemap) - : NULL; - m_moon_tonemap = tsrc->isKnownSourceImage(m_moon_params.tonemap) - ? tsrc->getTexture(m_moon_params.tonemap) - : NULL; + m_sun_texture = tsrc->isKnownSourceImage(m_sun_params.texture) ? + tsrc->getTextureForMesh(m_sun_params.texture) : NULL; + m_moon_texture = tsrc->isKnownSourceImage(m_moon_params.texture) ? + tsrc->getTextureForMesh(m_moon_params.texture) : NULL; + m_sun_tonemap = tsrc->isKnownSourceImage(m_sun_params.tonemap) ? + tsrc->getTexture(m_sun_params.tonemap) : NULL; + m_moon_tonemap = tsrc->isKnownSourceImage(m_moon_params.tonemap) ? + tsrc->getTexture(m_moon_params.tonemap) : NULL; if (m_sun_texture) { m_materials[3] = mat; m_materials[3].setTexture(0, m_sun_texture); m_materials[3].MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL; // Disables texture filtering - m_materials[3].setFlag( - video::E_MATERIAL_FLAG::EMF_BILINEAR_FILTER, false); - m_materials[3].setFlag( - video::E_MATERIAL_FLAG::EMF_TRILINEAR_FILTER, false); - m_materials[3].setFlag( - video::E_MATERIAL_FLAG::EMF_ANISOTROPIC_FILTER, false); + m_materials[3].setFlag(video::E_MATERIAL_FLAG::EMF_BILINEAR_FILTER, false); + m_materials[3].setFlag(video::E_MATERIAL_FLAG::EMF_TRILINEAR_FILTER, false); + m_materials[3].setFlag(video::E_MATERIAL_FLAG::EMF_ANISOTROPIC_FILTER, false); // Use tonemaps if available if (m_sun_tonemap) m_materials[3].Lighting = true; @@ -104,12 +96,9 @@ Sky::Sky(s32 id, ITextureSource *tsrc) : m_materials[4].setTexture(0, m_moon_texture); m_materials[4].MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL; // Disables texture filtering - m_materials[4].setFlag( - video::E_MATERIAL_FLAG::EMF_BILINEAR_FILTER, false); - m_materials[4].setFlag( - video::E_MATERIAL_FLAG::EMF_TRILINEAR_FILTER, false); - m_materials[4].setFlag( - video::E_MATERIAL_FLAG::EMF_ANISOTROPIC_FILTER, false); + m_materials[4].setFlag(video::E_MATERIAL_FLAG::EMF_BILINEAR_FILTER, false); + m_materials[4].setFlag(video::E_MATERIAL_FLAG::EMF_TRILINEAR_FILTER, false); + m_materials[4].setFlag(video::E_MATERIAL_FLAG::EMF_ANISOTROPIC_FILTER, false); // Use tonemaps if available if (m_moon_tonemap) m_materials[4].Lighting = true; @@ -157,9 +146,9 @@ void Sky::render() if (m_sunlight_seen) { float sunsize = 0.07; video::SColorf suncolor_f(1, 1, 0, 1); - // suncolor_f.r = 1; - // suncolor_f.g = MYMAX(0.3, MYMIN(1.0, 0.7 + m_time_brightness * 0.5)); - // suncolor_f.b = MYMAX(0.0, m_brightness * 0.95); + //suncolor_f.r = 1; + //suncolor_f.g = MYMAX(0.3, MYMIN(1.0, 0.7 + m_time_brightness * 0.5)); + //suncolor_f.b = MYMAX(0.0, m_brightness * 0.95); video::SColorf suncolor2_f(1, 1, 1, 1); // The values below were probably meant to be suncolor2_f instead of a // reassignment of suncolor_f. However, the resulting colour was chosen @@ -177,8 +166,7 @@ void Sky::render() float wn = nightlength / 2; float wicked_time_of_day = 0; if (m_time_of_day > wn && m_time_of_day < 1.0 - wn) - wicked_time_of_day = (m_time_of_day - wn) / (1.0 - wn * 2) * 0.5 + - 0.25; + wicked_time_of_day = (m_time_of_day - wn) / (1.0 - wn * 2) * 0.5 + 0.25; else if (m_time_of_day < 0.5) wicked_time_of_day = m_time_of_day / wn * 0.25; else @@ -192,25 +180,22 @@ void Sky::render() video::SColor mooncolor2 = mooncolor2_f.toSColor(); // Calculate offset normalized to the X dimension of a 512x1 px tonemap - float offset = (1.0 - fabs(sin((m_time_of_day - 0.5) * irr::core::PI))) * - 511; + float offset = (1.0 - fabs(sin((m_time_of_day - 0.5) * irr::core::PI))) * 511; if (m_sun_tonemap) { - u8 *texels = (u8 *)m_sun_tonemap->lock(); - video::SColor *texel = - (video::SColor *)(texels + (u32)offset * 4); - video::SColor texel_color(255, texel->getRed(), texel->getGreen(), - texel->getBlue()); + u8 * texels = (u8 *)m_sun_tonemap->lock(); + video::SColor* texel = (video::SColor *)(texels + (u32)offset * 4); + video::SColor texel_color (255, texel->getRed(), + texel->getGreen(), texel->getBlue()); m_sun_tonemap->unlock(); m_materials[3].EmissiveColor = texel_color; } if (m_moon_tonemap) { - u8 *texels = (u8 *)m_moon_tonemap->lock(); - video::SColor *texel = - (video::SColor *)(texels + (u32)offset * 4); - video::SColor texel_color(255, texel->getRed(), texel->getGreen(), - texel->getBlue()); + u8 * texels = (u8 *)m_moon_tonemap->lock(); + video::SColor* texel = (video::SColor *)(texels + (u32)offset * 4); + video::SColor texel_color (255, texel->getRed(), + texel->getGreen(), texel->getBlue()); m_moon_tonemap->unlock(); m_materials[4].EmissiveColor = texel_color; } @@ -236,14 +221,10 @@ void Sky::render() driver->setMaterial(m_materials[j]); // Use 1.05 rather than 1.0 to avoid colliding with the // sun, moon and stars, as this is a background skybox. - vertices[0] = video::S3DVertex( - -1.05, -1.05, -1.05, 0, 0, 1, c, t, t); - vertices[1] = video::S3DVertex( - 1.05, -1.05, -1.05, 0, 0, 1, c, o, t); - vertices[2] = video::S3DVertex( - 1.05, 1.05, -1.05, 0, 0, 1, c, o, o); - vertices[3] = video::S3DVertex( - -1.05, 1.05, -1.05, 0, 0, 1, c, t, o); + vertices[0] = video::S3DVertex(-1.05, -1.05, -1.05, 0, 0, 1, c, t, t); + vertices[1] = video::S3DVertex( 1.05, -1.05, -1.05, 0, 0, 1, c, o, t); + vertices[2] = video::S3DVertex( 1.05, 1.05, -1.05, 0, 0, 1, c, o, o); + vertices[3] = video::S3DVertex(-1.05, 1.05, -1.05, 0, 0, 1, c, t, o); for (video::S3DVertex &vertex : vertices) { if (j == 5) { // Top texture vertex.Pos.rotateYZBy(90); @@ -256,16 +237,14 @@ void Sky::render() } else if (j == 8) { // Right texture vertex.Pos.rotateXZBy(-90); } else if (j == 9) { // Front texture, do nothing - // Irrlicht doesn't like it when vertexes - // are left alone and not rotated for some - // reason. + // Irrlicht doesn't like it when vertexes are left + // alone and not rotated for some reason. vertex.Pos.rotateXZBy(0); - } else { // Back texture + } else {// Back texture vertex.Pos.rotateXZBy(180); } } - driver->drawIndexedTriangleFan( - &vertices[0], 4, indices, 2); + driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2); } } @@ -273,19 +252,15 @@ void Sky::render() if (m_visible) { driver->setMaterial(m_materials[1]); for (u32 j = 0; j < 4; j++) { - vertices[0] = video::S3DVertex( - -1, -0.02, -1, 0, 0, 1, m_bgcolor, t, t); - vertices[1] = video::S3DVertex( - 1, -0.02, -1, 0, 0, 1, m_bgcolor, o, t); - vertices[2] = video::S3DVertex( - 1, 0.45, -1, 0, 0, 1, m_skycolor, o, o); - vertices[3] = video::S3DVertex( - -1, 0.45, -1, 0, 0, 1, m_skycolor, t, o); + vertices[0] = video::S3DVertex(-1, -0.02, -1, 0, 0, 1, m_bgcolor, t, t); + vertices[1] = video::S3DVertex( 1, -0.02, -1, 0, 0, 1, m_bgcolor, o, t); + vertices[2] = video::S3DVertex( 1, 0.45, -1, 0, 0, 1, m_skycolor, o, o); + vertices[3] = video::S3DVertex(-1, 0.45, -1, 0, 0, 1, m_skycolor, t, o); for (video::S3DVertex &vertex : vertices) { if (j == 0) - // Don't switch - { - } else if (j == 1) + // Don't switch + {} + else if (j == 1) // Switch from -Z (south) to +X (east) vertex.Pos.rotateXZBy(90); else if (j == 2) @@ -295,8 +270,7 @@ void Sky::render() // Switch from -Z (south) to +Z (north) vertex.Pos.rotateXZBy(-180); } - driver->drawIndexedTriangleFan( - &vertices[0], 4, indices, 2); + driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2); } } @@ -312,15 +286,13 @@ void Sky::render() float mid = wicked_time_of_day < 0.5 ? mid1 : (1.0 - mid1); float a_ = 1.0f - std::fabs(wicked_time_of_day - mid) * 35.0f; float a = easeCurve(MYMAX(0, MYMIN(1, a_))); - // std::cerr<<"a_="<getTextureForMesh( + sunglow_texture.empty() ? "sunrisebg.png" : sunglow_texture) + ); } -void Sky::setMoonTexture( - std::string moon_texture, std::string moon_tonemap, ITextureSource *tsrc) +void Sky::setMoonTexture(std::string moon_texture, + 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; + m_moon_tonemap = tsrc->isKnownSourceImage(m_moon_params.tonemap) ? + tsrc->getTexture(m_moon_params.tonemap) : NULL; m_materials[4].Lighting = !!m_moon_tonemap; if (m_moon_params.texture == moon_texture) @@ -945,18 +872,15 @@ void Sky::setMoonTexture( if (m_moon_texture) { m_materials[4] = m_materials[0]; m_materials[4].setTexture(0, m_moon_texture); - m_materials[4].MaterialType = - video::EMT_TRANSPARENT_ALPHA_CHANNEL; + m_materials[4].MaterialType = video:: + EMT_TRANSPARENT_ALPHA_CHANNEL; // Disables texture filtering m_materials[4].setFlag( - video::E_MATERIAL_FLAG::EMF_BILINEAR_FILTER, - false); + video::E_MATERIAL_FLAG::EMF_BILINEAR_FILTER, false); m_materials[4].setFlag( - video::E_MATERIAL_FLAG::EMF_TRILINEAR_FILTER, - false); + video::E_MATERIAL_FLAG::EMF_TRILINEAR_FILTER, false); m_materials[4].setFlag( - video::E_MATERIAL_FLAG::EMF_ANISOTROPIC_FILTER, - false); + video::E_MATERIAL_FLAG::EMF_ANISOTROPIC_FILTER, false); } } else { m_moon_texture = nullptr; @@ -971,9 +895,11 @@ void Sky::setStarCount(u16 star_count, bool force_update) 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)); + v3f star = v3f( + myrand_range(-10000, 10000), + myrand_range(-10000, 10000), + myrand_range(-10000, 10000) + ); star.normalize(); m_stars.emplace_back(star); @@ -986,8 +912,8 @@ void Sky::setSkyColors(const SkyColor &sky_color) m_sky_params.sky_color = sky_color; } -void Sky::setHorizonTint( - video::SColor sun_tint, video::SColor moon_tint, std::string use_sun_tint) +void Sky::setHorizonTint(video::SColor sun_tint, video::SColor moon_tint, + std::string use_sun_tint) { // Change sun and moon tinting: m_sky_params.fog_sun_tint = sun_tint; @@ -1001,7 +927,8 @@ void Sky::setHorizonTint( m_default_tint = true; } -void Sky::addTextureToSkybox(std::string texture, int material_id, ITextureSource *tsrc) +void Sky::addTextureToSkybox(std::string texture, int material_id, + ITextureSource *tsrc) { // Sanity check for more than six textures. if (material_id + 5 >= SKY_MATERIAL_COUNT) @@ -1009,9 +936,9 @@ void Sky::addTextureToSkybox(std::string texture, int material_id, ITextureSourc // Keep a list of texture names handy. m_sky_params.textures.emplace_back(texture); video::ITexture *result = tsrc->getTextureForMesh(texture); - m_materials[material_id + 5] = m_materials[0]; - m_materials[material_id + 5].setTexture(0, result); - m_materials[material_id + 5].MaterialType = video::EMT_SOLID; + m_materials[material_id+5] = m_materials[0]; + m_materials[material_id+5].setTexture(0, result); + m_materials[material_id+5].MaterialType = video::EMT_SOLID; } // To be called once at game init to setup default values. -- cgit v1.2.3