Skip to content

Commit

Permalink
Stop rendering when the window is minimized
Browse files Browse the repository at this point in the history
  • Loading branch information
scrawl committed Sep 4, 2015
1 parent 7a96a04 commit d11952c
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 8 deletions.
22 changes: 15 additions & 7 deletions apps/openmw/engine.cpp
Expand Up @@ -92,10 +92,11 @@ void OMW::Engine::frame(float frametime)
// update input
mEnvironment.getInputManager()->update(frametime, false);

// When the window is minimized, pause everything. Currently this *has* to be here to work around a MyGUI bug.
// If we are not currently rendering, then RenderItems will not be reused resulting in a memory leak upon changing widget textures.
//if (!mOgre->getWindow()->isActive() || !mOgre->getWindow()->isVisible())
// return true;
// When the window is minimized, pause the game. Currently this *has* to be here to work around a MyGUI bug.
// If we are not currently rendering, then RenderItems will not be reused resulting in a memory leak upon changing widget textures (fixed in MyGUI 3.3.2),
// and destroyed widgets will not be deleted (not fixed yet, https://github.com/MyGUI/mygui/issues/21)
if (!mEnvironment.getInputManager()->isWindowVisible())
return;

// sound
if (mUseSound)
Expand Down Expand Up @@ -689,9 +690,16 @@ void OMW::Engine::go()

frame(dt);

mViewer->eventTraversal();
mViewer->updateTraversal();
mViewer->renderingTraversals();
if (!mEnvironment.getInputManager()->isWindowVisible())
{
OpenThreads::Thread::microSleep(5000);
}
else
{
mViewer->eventTraversal();
mViewer->updateTraversal();
mViewer->renderingTraversals();
}
}

// Save user settings
Expand Down
2 changes: 2 additions & 0 deletions apps/openmw/mwbase/inputmanager.hpp
Expand Up @@ -25,6 +25,8 @@ namespace MWBase

virtual ~InputManager() {}

virtual bool isWindowVisible() = 0;

virtual void update(float dt, bool disableControls, bool disableEvents=false) = 0;

virtual void changeInputMode(bool guiMode) = 0;
Expand Down
8 changes: 7 additions & 1 deletion apps/openmw/mwinput/inputmanagerimp.cpp
Expand Up @@ -41,6 +41,7 @@ namespace MWInput
const std::string& userFile, bool userFileExists,
const std::string& controllerBindingsFile, bool grab)
: mWindow(window)
, mWindowVisible(true)
, mViewer(viewer)
, mJoystickLastUsed(false)
, mPlayer(NULL)
Expand Down Expand Up @@ -156,6 +157,11 @@ namespace MWInput
delete mVideoWrapper;
}

bool InputManager::isWindowVisible()
{
return mWindowVisible;
}

void InputManager::setPlayerControlsEnabled(bool enabled)
{
int nPlayerChannels = 17;
Expand Down Expand Up @@ -850,7 +856,7 @@ namespace MWInput

void InputManager::windowVisibilityChange(bool visible)
{
//TODO: Pause game?
mWindowVisible = visible;
}

void InputManager::windowResized(int x, int y)
Expand Down
3 changes: 3 additions & 0 deletions apps/openmw/mwinput/inputmanagerimp.hpp
Expand Up @@ -83,6 +83,8 @@ namespace MWInput

virtual ~InputManager();

virtual bool isWindowVisible();

/// Clear all savegame-specific data
virtual void clear();

Expand Down Expand Up @@ -153,6 +155,7 @@ namespace MWInput

private:
SDL_Window* mWindow;
bool mWindowVisible;
osg::ref_ptr<osgViewer::Viewer> mViewer;

bool mJoystickLastUsed;
Expand Down

0 comments on commit d11952c

Please sign in to comment.