Skip to content

Commit

Permalink
PowerSaver updates:
Browse files Browse the repository at this point in the history
- Video Screensaver to skip fade in/out if Instant
- Video Previews to skip fade in/out if Instant
- Added Pause/Resume methods to PS for better description
- Added basic documentation to PS header file
- Added trailing after waking up from SS
- Added proper timing offsets after PS is triggered
- PS set to Disabled by default
- some whitespace edits
  • Loading branch information
hex007 committed Aug 11, 2017
1 parent 244bf47 commit 90cd10b
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 37 deletions.
16 changes: 9 additions & 7 deletions es-app/src/SystemScreenSaver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,10 @@ void SystemScreenSaver::startScreenSaver()
{
if (!mVideoScreensaver && (Settings::getInstance()->getString("ScreenSaverBehavior") == "random video"))
{
// Configure to fade out the windows
mState = STATE_FADE_OUT_WINDOW;
// Configure to fade out the windows, Skip Fading if Instant mode
mState = PowerSaver::getMode() == PowerSaver::INSTANT
? STATE_SCREENSAVER_ACTIVE
: STATE_FADE_OUT_WINDOW;
mOpacity = 0.0f;

// Load a random video
Expand Down Expand Up @@ -316,9 +318,9 @@ void SystemScreenSaver::launchGame()
// launching Game
ViewController::get()->goToGameList(mCurrentGame->getSystem());
IGameListView* view = ViewController::get()->getGameListView(mCurrentGame->getSystem()).get();
view->setCursor(mCurrentGame);
if (Settings::getInstance()->getBool("ScreenSaverControls"))
{
view->launch(mCurrentGame);
}
view->setCursor(mCurrentGame);
if (Settings::getInstance()->getBool("ScreenSaverControls"))
{
view->launch(mCurrentGame);
}
}
20 changes: 10 additions & 10 deletions es-app/src/guis/GuiGameScraper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,25 @@
#include "PowerSaver.h"
#include "Settings.h"

GuiGameScraper::GuiGameScraper(Window* window, ScraperSearchParams params, std::function<void(const ScraperSearchResult&)> doneFunc) : GuiComponent(window),
mGrid(window, Eigen::Vector2i(1, 7)),
GuiGameScraper::GuiGameScraper(Window* window, ScraperSearchParams params, std::function<void(const ScraperSearchResult&)> doneFunc) : GuiComponent(window),
mGrid(window, Eigen::Vector2i(1, 7)),
mBox(window, ":/frame.png"),
mSearchParams(params),
mClose(false)
{
PowerSaver::setState(false);
PowerSaver::pause();
addChild(&mBox);
addChild(&mGrid);

// row 0 is a spacer

mGameName = std::make_shared<TextComponent>(mWindow, strToUpper(mSearchParams.game->getPath().filename().generic_string()),
mGameName = std::make_shared<TextComponent>(mWindow, strToUpper(mSearchParams.game->getPath().filename().generic_string()),
Font::get(FONT_SIZE_MEDIUM), 0x777777FF, ALIGN_CENTER);
mGrid.setEntry(mGameName, Eigen::Vector2i(0, 1), false, true);

// row 2 is a spacer

mSystemName = std::make_shared<TextComponent>(mWindow, strToUpper(mSearchParams.system->getFullName()), Font::get(FONT_SIZE_SMALL),
mSystemName = std::make_shared<TextComponent>(mWindow, strToUpper(mSearchParams.system->getFullName()), Font::get(FONT_SIZE_SMALL),
0x888888FF, ALIGN_CENTER);
mGrid.setEntry(mSystemName, Eigen::Vector2i(0, 3), false, true);

Expand All @@ -40,9 +40,9 @@ GuiGameScraper::GuiGameScraper(Window* window, ScraperSearchParams params, std::
// buttons
std::vector< std::shared_ptr<ButtonComponent> > buttons;

buttons.push_back(std::make_shared<ButtonComponent>(mWindow, "INPUT", "search", [&] {
mSearch->openInputScreen(mSearchParams);
mGrid.resetCursor();
buttons.push_back(std::make_shared<ButtonComponent>(mWindow, "INPUT", "search", [&] {
mSearch->openInputScreen(mSearchParams);
mGrid.resetCursor();
}));
buttons.push_back(std::make_shared<ButtonComponent>(mWindow, "CANCEL", "cancel", [&] { delete this; }));
mButtonGrid = makeButtonGrid(mWindow, buttons);
Expand Down Expand Up @@ -98,7 +98,7 @@ bool GuiGameScraper::input(InputConfig* config, Input input)
{
if(config->isMappedTo("b", input) && input.value)
{
PowerSaver::setState(true);
PowerSaver::resume();
delete this;
return true;
}
Expand All @@ -122,4 +122,4 @@ std::vector<HelpPrompt> GuiGameScraper::getHelpPrompts()
void GuiGameScraper::close()
{
mClose = true;
}
}
18 changes: 9 additions & 9 deletions es-app/src/guis/GuiScraperMulti.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@

using namespace Eigen;

GuiScraperMulti::GuiScraperMulti(Window* window, const std::queue<ScraperSearchParams>& searches, bool approveResults) :
GuiComponent(window), mBackground(window, ":/frame.png"), mGrid(window, Vector2i(1, 5)),
GuiScraperMulti::GuiScraperMulti(Window* window, const std::queue<ScraperSearchParams>& searches, bool approveResults) :
GuiComponent(window), mBackground(window, ":/frame.png"), mGrid(window, Vector2i(1, 5)),
mSearchQueue(searches)
{
assert(mSearchQueue.size());

PowerSaver::setState(false);
addChild(&mBackground);
addChild(&mGrid);

PowerSaver::pause();
mIsProcessing = true;

mTotalGames = mSearchQueue.size();
Expand All @@ -40,7 +40,7 @@ GuiScraperMulti::GuiScraperMulti(Window* window, const std::queue<ScraperSearchP
mSubtitle = std::make_shared<TextComponent>(mWindow, "subtitle text", Font::get(FONT_SIZE_SMALL), 0x888888FF, ALIGN_CENTER);
mGrid.setEntry(mSubtitle, Vector2i(0, 2), false, true);

mSearchComp = std::make_shared<ScraperSearchComponent>(mWindow,
mSearchComp = std::make_shared<ScraperSearchComponent>(mWindow,
approveResults ? ScraperSearchComponent::ALWAYS_ACCEPT_MATCHING_CRC : ScraperSearchComponent::ALWAYS_ACCEPT_FIRST_RESULT);
mSearchComp->setAcceptCallback(std::bind(&GuiScraperMulti::acceptResult, this, std::placeholders::_1));
mSearchComp->setSkipCallback(std::bind(&GuiScraperMulti::skip, this));
Expand All @@ -51,9 +51,9 @@ GuiScraperMulti::GuiScraperMulti(Window* window, const std::queue<ScraperSearchP

if(approveResults)
{
buttons.push_back(std::make_shared<ButtonComponent>(mWindow, "INPUT", "search", [&] {
mSearchComp->openInputScreen(mSearchQueue.front());
mGrid.resetCursor();
buttons.push_back(std::make_shared<ButtonComponent>(mWindow, "INPUT", "search", [&] {
mSearchComp->openInputScreen(mSearchQueue.front());
mGrid.resetCursor();
}));

buttons.push_back(std::make_shared<ButtonComponent>(mWindow, "SKIP", "skip", [&] {
Expand Down Expand Up @@ -95,7 +95,6 @@ void GuiScraperMulti::doNextSearch()
{
if(mSearchQueue.empty())
{
PowerSaver::setState(true);
finish();
return;
}
Expand Down Expand Up @@ -146,10 +145,11 @@ void GuiScraperMulti::finish()
ss << "\n" << mTotalSkipped << " GAME" << ((mTotalSkipped > 1) ? "S" : "") << " SKIPPED.";
}

mWindow->pushGui(new GuiMsgBox(mWindow, ss.str(),
mWindow->pushGui(new GuiMsgBox(mWindow, ss.str(),
"OK", [&] { delete this; }));

mIsProcessing = false;
PowerSaver::resume();
}

std::vector<HelpPrompt> GuiScraperMulti::getHelpPrompts()
Expand Down
12 changes: 9 additions & 3 deletions es-app/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,14 +335,20 @@ int main(int argc, char* argv[])
}
} while(SDL_PollEvent(&event));

// triggered if exiting from SDL_WaitEvent
// triggered if exiting from SDL_WaitEvent due to event
if (ps_standby)
// show as if continuing from last event
lastTime = SDL_GetTicks();

// reset counter
ps_time = SDL_GetTicks();
}
else if (ps_standby)
{
// If exitting SDL_WaitEventTimeout due to timeout. Trail considering
// timeout as an event
ps_time = SDL_GetTicks();
}

if(window.isSleeping())
{
Expand All @@ -355,8 +361,8 @@ int main(int argc, char* argv[])
int deltaTime = curTime - lastTime;
lastTime = curTime;

// cap deltaTime
if((deltaTime > PowerSaver::getTimeout() && PowerSaver::getTimeout() > 0) || deltaTime < 0)
// cap deltaTime if it ever goes negative
if(deltaTime < 0)
deltaTime = 1000;

window.update(deltaTime);
Expand Down
12 changes: 9 additions & 3 deletions es-core/src/PowerSaver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@ PowerSaver::mode PowerSaver::mMode = PowerSaver::DISABLED;
void PowerSaver::init()
{
setState(true);
updateTimeouts();
updateMode();
}

int PowerSaver::getTimeout()
{
// Used only for SDL_WaitEventTimeout. Use `getMode()` for modes.
return mRunningScreenSaver ? mPlayNextTimeout : mScreenSaverTimeout;
}

void PowerSaver::updateTimeouts()
{
mScreenSaverTimeout = (unsigned int) Settings::getInstance()->getInt("ScreenSaverTime");
mScreenSaverTimeout = mScreenSaverTimeout > 0 ? mScreenSaverTimeout - 100 : -1;
mPlayNextTimeout = 30000;
mScreenSaverTimeout = mScreenSaverTimeout > 0 ? mScreenSaverTimeout - getMode() : -1;
mPlayNextTimeout = 30000 - getMode();
}

PowerSaver::mode PowerSaver::getMode()
Expand All @@ -46,6 +46,7 @@ void PowerSaver::updateMode()
} else {
mMode = DEFAULT;
}
updateTimeouts();
}

bool PowerSaver::getState()
Expand All @@ -63,3 +64,8 @@ void PowerSaver::runningScreenSaver(bool state)
{
mRunningScreenSaver = state;
}

bool PowerSaver::isScreenSaverActive()
{
return mRunningScreenSaver;
}
14 changes: 14 additions & 0 deletions es-core/src/PowerSaver.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,32 @@ class PowerSaver
public:
enum mode : int { DISABLED = -1, INSTANT = 200, ENHANCED = 3000, DEFAULT = 10000 };

// Call when you want PS to reload all state and settings
static void init();

// Get timeout to wake up from for the next event
static int getTimeout();
// Update currently set timeouts after User changes Timeout settings
static void updateTimeouts();

// Use this to check which mode you are in or get the mode timeout
static mode getMode();
// Called when user changes mode from Settings
static void updateMode();

// Get current state of PS. Not to be confused with Mode
static bool getState();
// State is used to temporarily pause and resume PS
static void setState(bool state);

// Paired calls when you want to pause PS briefly till you finish animating
// or processing over cycles
static void pause() { setState(false); }
static void resume() { setState(true); }

// This is used by ScreenSaver to let PS know when to switch to SS timeouts
static void runningScreenSaver(bool state);
static bool isScreenSaverActive();

private:
static bool mState;
Expand Down
2 changes: 1 addition & 1 deletion es-core/src/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ void Settings::setDefaults()
mBoolMap["ScreenSaverControls"] = true;
mStringMap["ScreenSaverGameInfo"] = "never";
mBoolMap["StretchVideoOnScreenSaver"] = false;
mStringMap["PowerSaverMode"] = "default";
mStringMap["PowerSaverMode"] = "disabled";

// This setting only applies to raspberry pi but set it for all platforms so
// we don't get a warning if we encounter it on a different platform
Expand Down
3 changes: 2 additions & 1 deletion es-core/src/components/VideoComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "ThemeData.h"
#include "Util.h"
#include "Window.h"
#include "PowerSaver.h"
#ifdef WIN32
#include <codecvt>
#endif
Expand Down Expand Up @@ -264,7 +265,7 @@ void VideoComponent::startVideoWithDelay()
// Set the video that we are going to be playing so we don't attempt to restart it
mPlayingVideoPath = mVideoPath;

if (mConfig.startDelay == 0)
if (mConfig.startDelay == 0 || PowerSaver::getMode() == PowerSaver::INSTANT)
{
// No delay. Just start the video
mStartDelayed = false;
Expand Down
5 changes: 2 additions & 3 deletions es-core/src/components/VideoVlcComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ void VideoVlcComponent::startVideo()
}
}
#endif
PowerSaver::setState(false);
PowerSaver::pause();
setupContext();

// Setup the media player
Expand Down Expand Up @@ -361,12 +361,11 @@ void VideoVlcComponent::stopVideo()
// Release the media player so it stops calling back to us
if (mMediaPlayer)
{
PowerSaver::setState(true);
libvlc_media_player_stop(mMediaPlayer);
libvlc_media_player_release(mMediaPlayer);
libvlc_media_release(mMedia);
mMediaPlayer = NULL;
freeContext();
PowerSaver::resume();
}
}

0 comments on commit 90cd10b

Please sign in to comment.