Merge pull request #67 from verybadsoldier/no_sleep_when_processing

This should fix scraper getting stuck when screen dim kicks in...
This commit is contained in:
Jools Wills 2016-10-19 03:36:57 +01:00 committed by GitHub
commit 25478d045e
5 changed files with 42 additions and 8 deletions

View file

@ -21,6 +21,8 @@ GuiScraperMulti::GuiScraperMulti(Window* window, const std::queue<ScraperSearchP
addChild(&mBackground);
addChild(&mGrid);
mIsProcessing = true;
mTotalGames = mSearchQueue.size();
mCurrentGame = 0;
mTotalSuccessful = 0;
@ -143,6 +145,8 @@ void GuiScraperMulti::finish()
mWindow->pushGui(new GuiMsgBox(mWindow, ss.str(),
"OK", [&] { delete this; }));
mIsProcessing = false;
}
std::vector<HelpPrompt> GuiScraperMulti::getHelpPrompts()

View file

@ -6,7 +6,8 @@
#include "ThemeData.h"
GuiComponent::GuiComponent(Window* window) : mWindow(window), mParent(NULL), mOpacity(255),
mPosition(Eigen::Vector3f::Zero()), mSize(Eigen::Vector2f::Zero()), mTransform(Eigen::Affine3f::Identity())
mPosition(Eigen::Vector3f::Zero()), mSize(Eigen::Vector2f::Zero()), mTransform(Eigen::Affine3f::Identity()),
mIsProcessing(false)
{
for(unsigned char i = 0; i < MAX_ANIMATIONS; i++)
mAnimationMap[i] = NULL;
@ -339,3 +340,8 @@ HelpStyle GuiComponent::getHelpStyle()
{
return HelpStyle();
}
bool GuiComponent::isProcessing() const
{
return mIsProcessing;
}

View file

@ -90,6 +90,9 @@ public:
virtual HelpStyle getHelpStyle();
// Returns true if the component is busy doing background processing (e.g. HTTP downloads)
bool isProcessing() const;
protected:
void renderChildren(const Eigen::Affine3f& transform) const;
void updateSelf(int deltaTime); // updates animations
@ -104,6 +107,8 @@ protected:
Eigen::Vector3f mPosition;
Eigen::Vector2f mSize;
bool mIsProcessing;
public:
const static unsigned char MAX_ANIMATIONS = 4;

View file

@ -4,6 +4,7 @@
#include "AudioManager.h"
#include "Log.h"
#include "Settings.h"
#include <algorithm>
#include <iomanip>
#include "components/HelpComponent.h"
#include "components/ImageComponent.h"
@ -202,11 +203,16 @@ void Window::render()
}
unsigned int screensaverTime = (unsigned int)Settings::getInstance()->getInt("ScreenSaverTime");
if(mTimeSinceLastInput >= screensaverTime && screensaverTime != 0 && mAllowSleep)
if(mTimeSinceLastInput >= screensaverTime && screensaverTime != 0)
{
// go to sleep
mSleeping = true;
onSleep();
renderScreenSaver();
if (!isProcessing() && mAllowSleep)
{
// go to sleep
mSleeping = true;
onSleep();
}
}
}
@ -326,12 +332,21 @@ void Window::setHelpPrompts(const std::vector<HelpPrompt>& prompts, const HelpSt
void Window::onSleep()
{
Renderer::setMatrix(Eigen::Affine3f::Identity());
unsigned char opacity = Settings::getInstance()->getString("ScreenSaverBehavior") == "dim" ? 0xA0 : 0xFF;
Renderer::drawRect(0, 0, Renderer::getScreenWidth(), Renderer::getScreenHeight(), 0x00000000 | opacity);
}
void Window::onWake()
{
}
bool Window::isProcessing()
{
return count_if(mGuiStack.begin(), mGuiStack.end(), [](GuiComponent* c) { return c->isProcessing(); }) > 0;
}
void Window::renderScreenSaver()
{
Renderer::setMatrix(Eigen::Affine3f::Identity());
unsigned char opacity = Settings::getInstance()->getString("ScreenSaverBehavior") == "dim" ? 0xA0 : 0xFF;
Renderer::drawRect(0, 0, Renderer::getScreenWidth(), Renderer::getScreenHeight(), 0x00000000 | opacity);
}

View file

@ -41,6 +41,10 @@ private:
void onSleep();
void onWake();
// Returns true if at least one component on the stack is processing
bool isProcessing();
void renderScreenSaver();
HelpComponent* mHelp;
ImageComponent* mBackgroundOverlay;