From 69f234d97b04f2263455a65c221c981f3482cb53 Mon Sep 17 00:00:00 2001 From: scrawl Date: Fri, 23 Oct 2015 16:50:08 +0200 Subject: [PATCH] Small delay before the loading screen shows Kinda irritating to have the loading bar pop up for a fraction of a second. --- apps/openmw/mwgui/loadingscreen.cpp | 74 +++++++++++++++++++---------- apps/openmw/mwgui/loadingscreen.hpp | 1 + 2 files changed, 50 insertions(+), 25 deletions(-) diff --git a/apps/openmw/mwgui/loadingscreen.cpp b/apps/openmw/mwgui/loadingscreen.cpp index 9b99ad7bf..9afce6873 100644 --- a/apps/openmw/mwgui/loadingscreen.cpp +++ b/apps/openmw/mwgui/loadingscreen.cpp @@ -235,40 +235,64 @@ namespace MWGui draw(); } - void LoadingScreen::draw() + bool LoadingScreen::needToDrawLoadingScreen() { - if (mTimer.time_m() > mLastRenderTime + (1.0/mTargetFrameRate) * 1000.0) + if ( mTimer.time_m() <= mLastRenderTime + (1.0/mTargetFrameRate) * 1000.0) + return false; + + // the minimal delay before a loading screen shows + const float initialDelay = 0.05; + + bool alreadyShown = (mLastRenderTime > mLoadingOnTime); + float diff = (mTimer.time_m() - mLoadingOnTime); + + if (!alreadyShown) { - bool showWallpaper = (MWBase::Environment::get().getStateManager()->getState() - == MWBase::StateManager::State_NoGame); + // bump the delay by the current progress - i.e. if during the initial delay the loading + // has almost finished, no point showing the loading screen now + diff -= mProgress / static_cast(mProgressBar->getScrollRange()) * 100.f; + } - if (showWallpaper && mTimer.time_m() > mLastWallpaperChangeTime + 5000*1) - { - mLastWallpaperChangeTime = mTimer.time_m(); - changeWallpaper(); - } + bool showWallpaper = (MWBase::Environment::get().getStateManager()->getState() + == MWBase::StateManager::State_NoGame); + if (!showWallpaper && diff < initialDelay*1000) + return false; + return true; + } - // Turn off rendering except the GUI - int oldUpdateMask = mViewer->getUpdateVisitor()->getTraversalMask(); - int oldCullMask = mViewer->getCamera()->getCullMask(); - mViewer->getUpdateVisitor()->setTraversalMask(MWRender::Mask_GUI); - mViewer->getCamera()->setCullMask(MWRender::Mask_GUI); + void LoadingScreen::draw() + { + if (!needToDrawLoadingScreen()) + return; + + bool showWallpaper = (MWBase::Environment::get().getStateManager()->getState() + == MWBase::StateManager::State_NoGame); + if (showWallpaper && mTimer.time_m() > mLastWallpaperChangeTime + 5000*1) + { + mLastWallpaperChangeTime = mTimer.time_m(); + changeWallpaper(); + } - MWBase::Environment::get().getInputManager()->update(0, true, true); + // Turn off rendering except the GUI + int oldUpdateMask = mViewer->getUpdateVisitor()->getTraversalMask(); + int oldCullMask = mViewer->getCamera()->getCullMask(); + mViewer->getUpdateVisitor()->setTraversalMask(MWRender::Mask_GUI); + mViewer->getCamera()->setCullMask(MWRender::Mask_GUI); - //osg::Timer timer; - mViewer->frame(mViewer->getFrameStamp()->getSimulationTime()); - //std::cout << "frame took " << timer.time_m() << std::endl; + MWBase::Environment::get().getInputManager()->update(0, true, true); - //if (mViewer->getIncrementalCompileOperation()) - //std::cout << "num to compile " << mViewer->getIncrementalCompileOperation()->getToCompile().size() << std::endl; + //osg::Timer timer; + mViewer->frame(mViewer->getFrameStamp()->getSimulationTime()); + //std::cout << "frame took " << timer.time_m() << std::endl; - // resume 3d rendering - mViewer->getUpdateVisitor()->setTraversalMask(oldUpdateMask); - mViewer->getCamera()->setCullMask(oldCullMask); + //if (mViewer->getIncrementalCompileOperation()) + //std::cout << "num to compile " << mViewer->getIncrementalCompileOperation()->getToCompile().size() << std::endl; - mLastRenderTime = mTimer.time_m(); - } + // resume 3d rendering + mViewer->getUpdateVisitor()->setTraversalMask(oldUpdateMask); + mViewer->getCamera()->setCullMask(oldCullMask); + + mLastRenderTime = mTimer.time_m(); } } diff --git a/apps/openmw/mwgui/loadingscreen.hpp b/apps/openmw/mwgui/loadingscreen.hpp index 194535eee..f0f354223 100644 --- a/apps/openmw/mwgui/loadingscreen.hpp +++ b/apps/openmw/mwgui/loadingscreen.hpp @@ -52,6 +52,7 @@ namespace MWGui private: void findSplashScreens(); + bool needToDrawLoadingScreen(); const VFS::Manager* mVFS; osg::ref_ptr mViewer;