Fixed FPS stable computation

This commit is contained in:
brunoherbelin
2021-02-23 23:44:04 +01:00
parent 0ee5eebf91
commit afc0c7af0e
2 changed files with 5 additions and 7 deletions

View File

@@ -109,8 +109,7 @@ static void saveSession(const std::string& filename, Session *session)
session->unlock();
}
Mixer::Mixer() : session_(nullptr), back_session_(nullptr), current_view_(nullptr),
/*update_time_(GST_CLOCK_TIME_NONE),*/ dt_(0.f), fps_(59.f)
Mixer::Mixer() : session_(nullptr), back_session_(nullptr), current_view_(nullptr), dt_(0.f), dt__(0.f)
{
// unsused initial empty session
session_ = new Session;
@@ -203,9 +202,8 @@ void Mixer::update()
dt_ = g_timer_elapsed (timer, NULL) * 1000.0;
g_timer_start(timer);
// compute fps
if (dt_ > 1.f)
fps_ = 1.f / (dt_+1.f) + 0.999f * fps_;
// compute stabilized dt__
dt__ = 0.05f * dt_ + 0.95f * dt__;
// update session and associated sources
session_->update(dt_);

View File

@@ -33,7 +33,7 @@ public:
// update session and all views
void update();
inline float dt() const { return dt_;}
inline float fps() const { return fps_;}
inline int fps() const { return int(roundf(1000.f/dt__));}
// draw session and current view
void draw();
@@ -129,7 +129,7 @@ protected:
TransitionView transition_;
float dt_;
float fps_;
float dt__;
};
#endif // MIXER_H