Reduce the use of porting::getTimeMs() when rendering frames (#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 <sfan5@live.de>

Co-authored-by: sfan5 <sfan5@live.de>
This commit is contained in:
x2048 2022-08-13 22:33:26 +02:00 committed by GitHub
parent 0e439b2fa3
commit d1cbb4bd8a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 16 deletions

@ -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"
@ -513,3 +514,8 @@ void ClientEnvironment::getSelectedActiveObjects(
}
}
}
void ClientEnvironment::updateFrameTime()
{
m_frame_time = porting::getTimeMs();
}

@ -141,6 +141,10 @@ public:
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;
@ -153,4 +157,5 @@ private:
IntervalLimiter m_active_object_light_update_interval;
std::list<std::string> m_player_names;
v3s16 m_camera_offset;
u64 m_frame_time;
};

@ -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();
@ -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();

@ -502,7 +502,7 @@ public:
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);
@ -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);
@ -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
*/