diff --git a/src/client/game.cpp b/src/client/game.cpp index 65128b9e6..cc8891547 100644 --- a/src/client/game.cpp +++ b/src/client/game.cpp @@ -819,6 +819,7 @@ protected: const ItemStack &selected_item, const ItemStack &hand_item, f32 dtime); void updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime, const CameraOrientation &cam); + void updateClouds(float dtime); void updateShadows(); // Misc @@ -4012,33 +4013,8 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime, /* Update clouds */ - if (clouds) { - if (sky->getCloudsVisible()) { - clouds->setVisible(true); - clouds->step(dtime); - // camera->getPosition is not enough for 3rd person views - v3f camera_node_position = camera->getCameraNode()->getPosition(); - v3s16 camera_offset = camera->getOffset(); - camera_node_position.X = camera_node_position.X + camera_offset.X * BS; - camera_node_position.Y = camera_node_position.Y + camera_offset.Y * BS; - camera_node_position.Z = camera_node_position.Z + camera_offset.Z * BS; - clouds->update(camera_node_position, - sky->getCloudColor()); - if (clouds->isCameraInsideCloud() && m_cache_enable_fog) { - // if inside clouds, and fog enabled, use that as sky - // color(s) - video::SColor clouds_dark = clouds->getColor() - .getInterpolated(video::SColor(255, 0, 0, 0), 0.9); - sky->overrideColors(clouds_dark, clouds->getColor()); - sky->setInClouds(true); - runData.fog_range = std::fmin(runData.fog_range * 0.5f, 32.0f * BS); - // do not draw clouds after all - clouds->setVisible(false); - } - } else { - clouds->setVisible(false); - } - } + if (clouds) + updateClouds(dtime); /* Update particles @@ -4217,6 +4193,33 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime, g_profiler->avg("Game::updateFrame(): update frame [ms]", tt_update.stop(true)); } +void Game::updateClouds(float dtime) +{ + if (this->sky->getCloudsVisible()) { + this->clouds->setVisible(true); + this->clouds->step(dtime); + // this->camera->getPosition is not enough for third-person camera. + v3f camera_node_position = this->camera->getCameraNode()->getPosition(); + v3s16 camera_offset = this->camera->getOffset(); + camera_node_position.X = camera_node_position.X + camera_offset.X * BS; + camera_node_position.Y = camera_node_position.Y + camera_offset.Y * BS; + camera_node_position.Z = camera_node_position.Z + camera_offset.Z * BS; + this->clouds->update(camera_node_position, this->sky->getCloudColor()); + if (this->clouds->isCameraInsideCloud() && this->m_cache_enable_fog) { + // If camera is inside cloud and fog is enabled, use cloud's colors as sky colors. + video::SColor clouds_dark = this->clouds->getColor().getInterpolated( + video::SColor(255, 0, 0, 0), 0.9); + this->sky->overrideColors(clouds_dark, this->clouds->getColor()); + this->sky->setInClouds(true); + this->runData.fog_range = std::fmin(this->runData.fog_range * 0.5f, 32.0f * BS); + // Clouds are not drawn in this case. + this->clouds->setVisible(false); + } + } else { + this->clouds->setVisible(false); + } +} + /* Log times and stuff for visualization */ inline void Game::updateProfilerGraphs(ProfilerGraph *graph) {