Fixed multiple issues and glitches related to the screensaver.

This commit is contained in:
Leon Styhre 2020-09-18 18:40:22 +02:00
parent afa91aa093
commit 522fbebee8
5 changed files with 75 additions and 71 deletions

View file

@ -1,4 +1,6 @@
// SPDX-License-Identifier: MIT
//
// EmulationStation Desktop Edition
// SystemScreenSaver.cpp
//
// Screensaver, supporting the following modes:
@ -86,9 +88,8 @@ void SystemScreenSaver::startScreenSaver()
if (!mVideoScreensaver && (screensaver_behavior == "video")) {
// Configure to fade out the windows, skip fading if mode is set to Instant.
mState = PowerSaver::getMode() == PowerSaver::INSTANT
? STATE_SCREENSAVER_ACTIVE
: STATE_FADE_OUT_WINDOW;
mState = PowerSaver::getMode() ==
PowerSaver::INSTANT ? STATE_SCREENSAVER_ACTIVE : STATE_FADE_OUT_WINDOW;
mVideoChangeTime = Settings::getInstance()->getInt("ScreenSaverSwapVideoTimeout");
mOpacity = 0.0f;
@ -120,11 +121,11 @@ void SystemScreenSaver::startScreenSaver()
Renderer::getScreenHeight() / 2.0f);
if (Settings::getInstance()->getBool("ScreenSaverStretchVideos"))
mVideoScreensaver->setResize((float)Renderer::getScreenWidth(),
(float)Renderer::getScreenHeight());
mVideoScreensaver->setResize(static_cast<float>(Renderer::getScreenWidth()),
static_cast<float>(Renderer::getScreenHeight()));
else
mVideoScreensaver->setMaxSize((float)Renderer::getScreenWidth(),
(float)Renderer::getScreenHeight());
mVideoScreensaver->setMaxSize(static_cast<float>(Renderer::getScreenWidth()),
static_cast<float>(Renderer::getScreenHeight()));
mVideoScreensaver->setVideo(path);
mVideoScreensaver->setScreensaverMode(true);
@ -136,9 +137,8 @@ void SystemScreenSaver::startScreenSaver()
}
else if (screensaver_behavior == "slideshow") {
// Configure to fade out the windows, skip fading if mode is set to Instant.
mState = PowerSaver::getMode() == PowerSaver::INSTANT
? STATE_SCREENSAVER_ACTIVE
: STATE_FADE_OUT_WINDOW;
mState = PowerSaver::getMode() ==
PowerSaver::INSTANT ? STATE_SCREENSAVER_ACTIVE : STATE_FADE_OUT_WINDOW;
mVideoChangeTime = Settings::getInstance()->getInt("ScreenSaverSwapImageTimeout");
mOpacity = 0.0f;
@ -164,11 +164,11 @@ void SystemScreenSaver::startScreenSaver()
Renderer::getScreenHeight() / 2.0f);
if (Settings::getInstance()->getBool("ScreenSaverStretchImages"))
mImageScreensaver->setResize((float)Renderer::getScreenWidth(),
(float)Renderer::getScreenHeight());
mImageScreensaver->setResize(static_cast<float>(Renderer::getScreenWidth()),
static_cast<float>(Renderer::getScreenHeight()));
else
mImageScreensaver->setMaxSize((float)Renderer::getScreenWidth(),
(float)Renderer::getScreenHeight());
mImageScreensaver->setMaxSize(static_cast<float>(Renderer::getScreenWidth()),
static_cast<float>(Renderer::getScreenHeight()));
std::string bg_audio_file = Settings::getInstance()->
getString("SlideshowScreenSaverBackgroundAudioFile");
@ -222,7 +222,7 @@ void SystemScreenSaver::renderScreenSaver()
Renderer::getScreenHeight(), 0x000000FF, 0x000000FF);
// Only render the video if the state requires it.
if ((int)mState >= STATE_FADE_IN_VIDEO) {
if (static_cast<int>(mState) >= STATE_FADE_IN_VIDEO) {
Transform4x4f transform = Transform4x4f::Identity();
mVideoScreensaver->render(transform);
}
@ -236,7 +236,7 @@ void SystemScreenSaver::renderScreenSaver()
// Only render the video if the state requires it.
if ((int)mState >= STATE_FADE_IN_VIDEO) {
if (mImageScreensaver->hasImage()) {
mImageScreensaver->setOpacity(255- (unsigned char) (mOpacity * 255));
mImageScreensaver->setOpacity(255 - static_cast<unsigned char>(mOpacity * 255));
Transform4x4f transform = Transform4x4f::Identity();
mImageScreensaver->render(transform);
@ -357,7 +357,8 @@ void SystemScreenSaver::pickRandomVideo(std::string& path)
// not shown again.
if (mVideoCount > 0) {
do {
int video = (int)(((float)rand() / float(RAND_MAX)) * (float)mVideoCount);
int video = static_cast<int>((static_cast<float>(rand()) /
static_cast<float>(RAND_MAX)) * static_cast<float>(mVideoCount));
pickGameListNode(video, "video", path);
}
while (mPreviousGame && mCurrentGame == mPreviousGame);
@ -376,7 +377,8 @@ void SystemScreenSaver::pickRandomGameListImage(std::string& path)
// not shown again.
if (mImageCount > 0) {
do {
int image = (int)(((float)rand() / float(RAND_MAX)) * (float)mImageCount);
int image = static_cast<int>((static_cast<float>(rand()) /
static_cast<float>(RAND_MAX)) * static_cast<float>(mImageCount));
pickGameListNode(image, "image", path);
}
while (mPreviousGame && mCurrentGame == mPreviousGame);
@ -405,7 +407,7 @@ void SystemScreenSaver::pickRandomCustomImage(std::string& path)
}
}
int fileCount = (int)matchingFiles.size();
int fileCount = static_cast<int>(matchingFiles.size());
if (fileCount > 0) {
// Get a random index in the range 0 to fileCount (exclusive).
int randomIndex = rand() % fileCount;
@ -425,7 +427,7 @@ void SystemScreenSaver::update(int deltaTime)
{
// Use this to update the fade value for the current fade stage.
if (mState == STATE_FADE_OUT_WINDOW) {
mOpacity += (float)deltaTime / FADE_TIME;
mOpacity += static_cast<float>(deltaTime) / FADE_TIME;
if (mOpacity >= 1.0f) {
mOpacity = 1.0f;
@ -434,7 +436,7 @@ void SystemScreenSaver::update(int deltaTime)
}
}
else if (mState == STATE_FADE_IN_VIDEO) {
mOpacity -= (float)deltaTime / FADE_TIME;
mOpacity -= static_cast<float>(deltaTime) / FADE_TIME;
if (mOpacity <= 0.0f) {
mOpacity = 0.0f;
// Update to the next state.
@ -475,7 +477,7 @@ void SystemScreenSaver::launchGame()
IGameListView* view = ViewController::get()->
getGameListView(mCurrentGame->getSystem()).get();
view->setCursor(mCurrentGame);
if (Settings::getInstance()->getBool("ScreenSaverControls"))
view->launch(mCurrentGame);
ViewController::get()->resetMovingCamera();
ViewController::get()->launch(mCurrentGame);
}
}

View file

@ -1,11 +1,12 @@
// SPDX-License-Identifier: MIT
//
// EmulationStation Desktop Edition
// SystemScreenSaver.h
//
// Screensaver, supporting the following modes:
// Dim, black, slideshow, video.
//
#pragma once
#ifndef ES_APP_SYSTEM_SCREEN_SAVER_H
#define ES_APP_SYSTEM_SCREEN_SAVER_H

View file

@ -37,7 +37,8 @@ SystemView::SystemView(
mExtrasCamOffset = 0;
mExtrasFadeOpacity = 0.0f;
setSize((float)Renderer::getScreenWidth(), (float)Renderer::getScreenHeight());
setSize(static_cast<float>(Renderer::getScreenWidth()),
static_cast<float>(Renderer::getScreenHeight()));
populate();
}
@ -218,13 +219,7 @@ bool SystemView::input(InputConfig* config, Input input)
setCursor(SystemData::getRandomSystem(getSelected()));
return true;
}
}
else {
if (config->isMappedLike("left", input) ||
config->isMappedLike("right", input) ||
config->isMappedLike("up", input) ||
config->isMappedLike("down", input))
listInput(0);
if (!UIModeController::getInstance()->isUIModeKid() &&
config->isMappedTo("select", input) &&
Settings::getInstance()->getBool("ScreenSaverControls")) {
@ -232,12 +227,16 @@ bool SystemView::input(InputConfig* config, Input input)
mWindow->startScreenSaver();
mWindow->renderScreenSaver();
}
else {
mWindow->cancelScreenSaver();
}
return true;
}
}
else {
if (config->isMappedLike("left", input) ||
config->isMappedLike("right", input) ||
config->isMappedLike("up", input) ||
config->isMappedLike("down", input))
listInput(0);
}
return GuiComponent::input(config, input);
}
@ -255,8 +254,8 @@ void SystemView::onCursorChanged(const CursorState& /*state*/)
float startPos = mCamOffset;
float posMax = (float)mEntries.size();
float target = (float)mCursor;
float posMax = static_cast<float>(mEntries.size());
float target = static_cast<float>(mCursor);
// What's the shortest way to get to our target?
// It's one of these...
@ -280,8 +279,9 @@ void SystemView::onCursorChanged(const CursorState& /*state*/)
Animation* infoFadeOut = new LambdaAnimation(
[infoStartOpacity, this] (float t) {
mSystemInfo.setOpacity((unsigned char)(Math::lerp(infoStartOpacity, 0.f, t) * 255));
}, (int)(infoStartOpacity * (goFast ? 10 : 150)));
mSystemInfo.setOpacity(static_cast<unsigned char>(
Math::lerp(infoStartOpacity, 0.f, t) * 255));
}, static_cast<int>(infoStartOpacity * (goFast ? 10 : 150)));
unsigned int gameCount = getSelected()->getDisplayedGameCount();
@ -299,7 +299,7 @@ void SystemView::onCursorChanged(const CursorState& /*state*/)
Animation* infoFadeIn = new LambdaAnimation(
[this](float t) {
mSystemInfo.setOpacity((unsigned char)(Math::lerp(0.f, 1.f, t) * 255));
mSystemInfo.setOpacity(static_cast<unsigned char>(Math::lerp(0.f, 1.f, t) * 255));
}, goFast ? 10 : 300);
// Wait 150ms to fade in.
@ -467,8 +467,8 @@ void SystemView::renderCarousel(const Transform4x4f& trans)
mCarousel.origin.y() * mCarousel.size.y() * -1, 0.0f));
Vector2f clipPos(carouselTrans.translation().x(), carouselTrans.translation().y());
Renderer::pushClipRect(Vector2i((int)clipPos.x(), (int)clipPos.y()),
Vector2i((int)mCarousel.size.x(), (int)mCarousel.size.y()));
Renderer::pushClipRect(Vector2i(static_cast<int>(clipPos.x()), static_cast<int>(clipPos.y())),
Vector2i(static_cast<int>(mCarousel.size.x()), static_cast<int>(mCarousel.size.y())));
Renderer::setMatrix(carouselTrans);
Renderer::drawRect(0.0f, 0.0f, mCarousel.size.x(), mCarousel.size.y(),
@ -530,8 +530,8 @@ void SystemView::renderCarousel(const Transform4x4f& trans)
break;
}
int center = (int)(mCamOffset);
int logoCount = Math::min(mCarousel.maxLogoCount, (int)mEntries.size());
int center = static_cast<int>(mCamOffset);
int logoCount = Math::min(mCarousel.maxLogoCount, static_cast<int>(mEntries.size()));
// Adding texture loading buffers depending on scrolling speed and status.
int bufferIndex = getScrollingVelocity() + 1;
@ -546,9 +546,9 @@ void SystemView::renderCarousel(const Transform4x4f& trans)
i <= center + logoCount / 2 + bufferRight; i++) {
int index = i;
while (index < 0)
index += (int)mEntries.size();
while (index >= (int)mEntries.size())
index -= (int)mEntries.size();
index += static_cast<int>(mEntries.size());
while (index >= static_cast<int>(mEntries.size()))
index -= static_cast<int>(mEntries.size());
Transform4x4f logoTrans = carouselTrans;
logoTrans.translate(Vector3f(i * logoSpacing[0] + xOff, i * logoSpacing[1] + yOff, 0));
@ -559,8 +559,9 @@ void SystemView::renderCarousel(const Transform4x4f& trans)
scale = Math::min(mCarousel.logoScale, Math::max(1.0f, scale));
scale /= mCarousel.logoScale;
int opacity = (int)Math::round(0x80 + ((0xFF - 0x80) * (1.0f - fabs(distance))));
opacity = Math::max((int) 0x80, opacity);
int opacity = static_cast<int>(Math::round(0x80 + ((0xFF - 0x80) *
(1.0f - fabs(distance)))));
opacity = Math::max(static_cast<int>(0x80), opacity);
const std::shared_ptr<GuiComponent> &comp = mEntries.at(index).data.logo;
if (mCarousel.type == VERTICAL_WHEEL || mCarousel.type == HORIZONTAL_WHEEL) {
@ -568,7 +569,7 @@ void SystemView::renderCarousel(const Transform4x4f& trans)
comp->setRotationOrigin(mCarousel.logoRotationOrigin);
}
comp->setScale(scale);
comp->setOpacity((unsigned char)opacity);
comp->setOpacity(static_cast<unsigned char>(opacity));
comp->render(logoTrans);
}
Renderer::popClipRect();
@ -583,20 +584,21 @@ void SystemView::renderInfoBar(const Transform4x4f& trans)
// Draw background extras.
void SystemView::renderExtras(const Transform4x4f& trans, float lower, float upper)
{
int extrasCenter = (int)mExtrasCamOffset;
int extrasCenter = static_cast<int>(mExtrasCamOffset);
// Adding texture loading buffers depending on scrolling speed and status.
int bufferIndex = getScrollingVelocity() + 1;
Renderer::pushClipRect(Vector2i::Zero(), Vector2i((int)mSize.x(), (int)mSize.y()));
Renderer::pushClipRect(Vector2i::Zero(), Vector2i(static_cast<int>(mSize.x()),
static_cast<int>(mSize.y())));
for (int i = extrasCenter + logoBuffersLeft[bufferIndex]; i <= extrasCenter +
logoBuffersRight[bufferIndex]; i++) {
int index = i;
while (index < 0)
index += (int)mEntries.size();
while (index >= (int)mEntries.size())
index -= (int)mEntries.size();
index += static_cast<int>(mEntries.size());
while (index >= static_cast<int>(mEntries.size()))
index -= static_cast<int>(mEntries.size());
// Only render selected system when not showing.
if (mShowing || index == mCursor)
@ -607,9 +609,9 @@ void SystemView::renderExtras(const Transform4x4f& trans, float lower, float upp
else
extrasTrans.translate(Vector3f(0, (i - mExtrasCamOffset) * mSize.y(), 0));
Renderer::pushClipRect(Vector2i((int)extrasTrans.translation()[0],
(int)extrasTrans.translation()[1]),
Vector2i((int)mSize.x(), (int)mSize.y()));
Renderer::pushClipRect(Vector2i(static_cast<int>(extrasTrans.translation()[0]),
static_cast<int>(extrasTrans.translation()[1])),
Vector2i(static_cast<int>(mSize.x()), static_cast<int>(mSize.y())));
SystemViewData data = mEntries.at(index).data;
for (unsigned int j = 0; j < data.backgroundExtras.size(); j++) {
GuiComponent *extra = data.backgroundExtras[j];
@ -627,7 +629,7 @@ void SystemView::renderFade(const Transform4x4f& trans)
{
// Fade extras if necessary.
if (mExtrasFadeOpacity) {
unsigned int fadeColor = 0x00000000 | (unsigned char)(mExtrasFadeOpacity * 255);
unsigned int fadeColor = 0x00000000 | static_cast<unsigned char>(mExtrasFadeOpacity * 255);
Renderer::setMatrix(trans);
Renderer::drawRect(0.0f, 0.0f, mSize.x(), mSize.y(), fadeColor, fadeColor);
}
@ -662,7 +664,7 @@ void SystemView::getDefaultElements(void)
mSystemInfo.setPosition(0, (mCarousel.pos.y() + mCarousel.size.y() - 0.2f));
mSystemInfo.setBackgroundColor(0xDDDDDDD8);
mSystemInfo.setRenderBackground(true);
mSystemInfo.setFont(Font::get((int)(0.035f * mSize.y()), Font::getDefaultPath()));
mSystemInfo.setFont(Font::get(static_cast<int>(0.035f * mSize.y()), Font::getDefaultPath()));
mSystemInfo.setColor(0x000000FF);
mSystemInfo.setZIndex(50);
mSystemInfo.setDefaultZIndex(50);
@ -699,7 +701,7 @@ void SystemView::getCarouselFromTheme(const ThemeData::ThemeElement* elem)
if (elem->has("logoSize"))
mCarousel.logoSize = elem->get<Vector2f>("logoSize") * mSize;
if (elem->has("maxLogoCount"))
mCarousel.maxLogoCount = (int)Math::round(elem->get<float>("maxLogoCount"));
mCarousel.maxLogoCount = static_cast<int>(Math::round(elem->get<float>("maxLogoCount")));
if (elem->has("zIndex"))
mCarousel.zIndex = elem->get<float>("zIndex");
if (elem->has("logoRotation"))

View file

@ -191,7 +191,7 @@ void ViewController::goToPrevGameList()
void ViewController::goToGameList(SystemData* system)
{
// Stop any scrolling, animations and camera movements.
if (mSystemListView) {
if (mState.viewing == SYSTEM_SELECT) {
mSystemListView->stopScrolling();
if (mSystemListView->isAnimationPlaying(0))
mSystemListView->finishAnimation(0);
@ -201,9 +201,8 @@ void ViewController::goToGameList(SystemData* system)
// Disable rendering of the system view.
if (getSystemListView()->getRenderView())
getSystemListView()->setRenderView(false);
// If switching between gamelists, disable rendering of the current view.
if (mCurrentView)
else if (mCurrentView)
mCurrentView->setRenderView(false);
if (mState.viewing == SYSTEM_SELECT) {
@ -329,8 +328,6 @@ void ViewController::launch(FileData* game, Vector3f center)
while (NavigationSounds::getInstance()->isPlayingThemeNavigationSound(LAUNCHSOUND));
game->launchGame(mWindow);
onFileChanged(game, FILE_METADATA_CHANGED);
if (mCurrentView)
mCurrentView->onShow();
// This is a workaround so that any key or button presses used for exiting the emulator
// are not captured upon returning to ES.
setAnimation(new LambdaAnimation([](float t){}, 1), 0, [this] {

View file

@ -136,6 +136,8 @@ void Window::textInput(const char* text)
void Window::input(InputConfig* config, Input input)
{
mTimeSinceLastInput = 0;
if (Settings::getInstance()->getBool("Debug"))
logInput(config, input);
@ -168,17 +170,17 @@ void Window::input(InputConfig* config, Input input)
if (mSleeping) {
// Wake up.
mTimeSinceLastInput = 0;
cancelScreenSaver();
mSleeping = false;
onWake();
return;
}
mTimeSinceLastInput = 0;
if (!config->isMappedTo("select", input))
if (cancelScreenSaver())
// Any keypress cancels the screensaver.
if (input.value != 0 && isScreenSaverActive()) {
cancelScreenSaver();
return;
}
if (config->getDeviceId() == DEVICE_KEYBOARD && input.value && input.id == SDLK_g &&
SDL_GetModState() & KMOD_LCTRL && Settings::getInstance()->getBool("Debug")) {