Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract updateClouds method from updateFrame #13939

Merged
merged 4 commits into from
Nov 8, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
59 changes: 32 additions & 27 deletions src/client/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -819,6 +819,7 @@ class Game {
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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -4217,6 +4193,35 @@ 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);
// camera->getPosition is not enough for 3rd person views
JosiahWI marked this conversation as resolved.
Show resolved Hide resolved
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());
JosiahWI marked this conversation as resolved.
Show resolved Hide resolved
if (this->clouds->isCameraInsideCloud() && this->m_cache_enable_fog) {
// if inside clouds, and fog enabled, use that as sky
// color(s)
grorp marked this conversation as resolved.
Show resolved Hide resolved
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);
// do not draw clouds after all
this->clouds->setVisible(false);
}
} else {
this->clouds->setVisible(false);
}
}

/* Log times and stuff for visualization */
inline void Game::updateProfilerGraphs(ProfilerGraph *graph)
{
Expand Down