Skip to content

Commit

Permalink
Reduce the use of porting::getTimeMs() when rendering frames (minetes…
Browse files Browse the repository at this point in the history
…t#12679)

* Avoid calling TimeTaker too frequently in renderMapXXX
* Calculate animation timer once per frame
* Remove code that breaks rendering frame at 2000ms

Co-authored-by: sfan5 <[email protected]>

Co-authored-by: sfan5 <[email protected]>
  • Loading branch information
x2048 and sfan5 committed Aug 13, 2022
1 parent 0e439b2 commit d1cbb4b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 16 deletions.
6 changes: 6 additions & 0 deletions src/client/clientenvironment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "settings.h"
#include "shader.h"
#include "content_cao.h"
#include "porting.h"
#include <algorithm>
#include "client/renderingengine.h"

Expand Down Expand Up @@ -513,3 +514,8 @@ void ClientEnvironment::getSelectedActiveObjects(
}
}
}

void ClientEnvironment::updateFrameTime()
{
m_frame_time = porting::getTimeMs();
}
5 changes: 5 additions & 0 deletions src/client/clientenvironment.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ class ClientEnvironment : public Environment
void updateCameraOffset(const v3s16 &camera_offset)
{ m_camera_offset = camera_offset; }
v3s16 getCameraOffset() const { return m_camera_offset; }

void updateFrameTime();
u64 getFrameTime() const { return m_frame_time; }

private:
ClientMap *m_map;
LocalPlayer *m_local_player = nullptr;
Expand All @@ -153,4 +157,5 @@ class ClientEnvironment : public Environment
IntervalLimiter m_active_object_light_update_interval;
std::list<std::string> m_player_names;
v3s16 m_camera_offset;
u64 m_frame_time;
};
14 changes: 0 additions & 14 deletions src/client/clientmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -449,13 +449,6 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass)
for (auto &descriptor : draw_order) {
scene::IMeshBuffer *buf = descriptor.getBuffer();

// Check and abort if the machine is swapping a lot
if (draw.getTimerTime() > 2000) {
infostream << "ClientMap::renderMap(): Rendering took >2s, " <<
"returning." << std::endl;
return;
}

if (!descriptor.m_reuse_material) {
auto &material = buf->getMaterial();

Expand Down Expand Up @@ -803,13 +796,6 @@ void ClientMap::renderMapShadows(video::IVideoDriver *driver,
for (auto &descriptor : draw_order) {
scene::IMeshBuffer *buf = descriptor.getBuffer();

// Check and abort if the machine is swapping a lot
if (draw.getTimerTime() > 1000) {
infostream << "ClientMap::renderMapShadows(): Rendering "
"took >1s, returning." << std::endl;
break;
}

if (!descriptor.m_reuse_material) {
// override some material properties
video::SMaterial local_material = buf->getMaterial();
Expand Down
10 changes: 8 additions & 2 deletions src/client/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ class GameGlobalShaderConstantSetter : public IShaderConstantSetter
float clr[4] = {star_color.r, star_color.g, star_color.b, star_color.a};
m_star_color.set(clr, services);

u32 animation_timer = porting::getTimeMs() % 1000000;
u32 animation_timer = m_client->getEnv().getFrameTime() % 1000000;
float animation_timer_f = (float)animation_timer / 100000.f;
m_animation_timer_vertex.set(&animation_timer_f, services);
m_animation_timer_pixel.set(&animation_timer_f, services);
Expand Down Expand Up @@ -3275,7 +3275,7 @@ PointedThing Game::updatePointedThing(
final_color_blend(&c, light_level, daynight_ratio);

// Modify final color a bit with time
u32 timer = porting::getTimeMs() % 5000;
u32 timer = client->getEnv().getFrameTime() % 5000;
float timerf = (float) (irr::core::PI * ((timer / 2500.0) - 0.5));
float sin_r = 0.08f * std::sin(timerf);
float sin_g = 0.08f * std::sin(timerf + irr::core::PI * 0.5f);
Expand Down Expand Up @@ -3747,6 +3747,12 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime,
TimeTaker tt_update("Game::updateFrame()");
LocalPlayer *player = client->getEnv().getLocalPlayer();

/*
Frame time
*/

client->getEnv().updateFrameTime();

/*
Fog range
*/
Expand Down

0 comments on commit d1cbb4b

Please sign in to comment.