From 02b76e5abab8d0bb7425adf69d0bdf9ae6337d5c Mon Sep 17 00:00:00 2001 From: krzys-h Date: Fri, 14 Aug 2015 00:07:45 +0200 Subject: [PATCH] Workaround for too fast calling of m_app->Render --- src/app/app.cpp | 19 +++++++++++++++++++ src/app/app.h | 6 ++++++ src/level/robotmain.cpp | 7 +++++++ src/ui/screen/screen_loading.cpp | 2 +- 4 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/app/app.cpp b/src/app/app.cpp index baef7bf6..ed169904 100644 --- a/src/app/app.cpp +++ b/src/app/app.cpp @@ -136,6 +136,9 @@ CApplication::CApplication(CSystemUtils* systemUtils) m_curTimeStamp = m_systemUtils->CreateTimeStamp(); m_lastTimeStamp = m_systemUtils->CreateTimeStamp(); + m_manualFrameLast = m_systemUtils->CreateTimeStamp(); + m_manualFrameTime = m_systemUtils->CreateTimeStamp(); + for (int i = 0; i < PCNT_MAX; ++i) { m_performanceCounters[i][0] = m_systemUtils->CreateTimeStamp(); @@ -166,6 +169,9 @@ CApplication::~CApplication() m_systemUtils->DestroyTimeStamp(m_curTimeStamp); m_systemUtils->DestroyTimeStamp(m_lastTimeStamp); + m_systemUtils->DestroyTimeStamp(m_manualFrameLast); + m_systemUtils->DestroyTimeStamp(m_manualFrameTime); + for (int i = 0; i < PCNT_MAX; ++i) { m_systemUtils->DestroyTimeStamp(m_performanceCounters[i][0]); @@ -1316,6 +1322,19 @@ void CApplication::Render() StopPerformanceCounter(PCNT_SWAP_BUFFERS); } +void CApplication::RenderIfNeeded(int updateRate) +{ + m_systemUtils->GetCurrentTimeStamp(m_manualFrameTime); + long long diff = m_systemUtils->TimeStampExactDiff(m_manualFrameLast, m_manualFrameTime); + if (diff < 1e9f / updateRate) + { + return; + } + m_systemUtils->CopyTimeStamp(m_manualFrameLast, m_manualFrameTime); + + Render(); +} + void CApplication::SuspendSimulation() { m_simulationSuspended = true; diff --git a/src/app/app.h b/src/app/app.h index c730d659..bea0fdae 100644 --- a/src/app/app.h +++ b/src/app/app.h @@ -329,6 +329,9 @@ public: //! Renders the image in window void Render(); + //! Renders the image in window if needed + void RenderIfNeeded(int updateRate); + protected: //! Creates the window's SDL_Surface bool CreateVideoSurface(); @@ -421,6 +424,9 @@ protected: bool m_simulationSuspended; //@} + SystemTimeStamp* m_manualFrameLast; + SystemTimeStamp* m_manualFrameTime; + //! Graphics device to use std::string m_graphics; diff --git a/src/level/robotmain.cpp b/src/level/robotmain.cpp index 2f701171..b2885668 100644 --- a/src/level/robotmain.cpp +++ b/src/level/robotmain.cpp @@ -3778,6 +3778,13 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) CompileScript(soluce); // compiles all scripts m_ui->GetLoadingScreen()->SetProgress(1.0f, RT_LOADING_FINISHED); + if (m_ui->GetLoadingScreen()->IsVisible()) + { + // Force render of the "Loading finished" screen + // TODO: For some reason, rendering of the first frame after the simulation starts is very slow + // We're doing this because it looks weird when the progress bar is finished but it still says "Loading programs" + m_app->Render(); + } if (!resetObject) { diff --git a/src/ui/screen/screen_loading.cpp b/src/ui/screen/screen_loading.cpp index f1a303d5..400e5f25 100644 --- a/src/ui/screen/screen_loading.cpp +++ b/src/ui/screen/screen_loading.cpp @@ -154,7 +154,7 @@ void CScreenLoading::SetProgress(float progress, const std::string& text, const { SetBackground("textures/interface/interface.png"); m_engine->SetBackForce(true); - m_app->Render(); + m_app->RenderIfNeeded(60); } m_lastProgress = progress;