Changed the screensaver to never show the same game again until all games have been cycled through

This commit is contained in:
Leon Styhre 2023-08-20 15:28:30 +02:00
parent b669280412
commit 912c8bb75a
3 changed files with 120 additions and 81 deletions

View file

@ -82,7 +82,9 @@ void Screensaver::startScreensaver(bool generateMediaList)
if (mScreensaverType == "slideshow") {
if (generateMediaList) {
mImageFiles.clear();
mFilesInventory.clear();
mImageCustomFiles.clear();
mCustomFilesInventory.clear();
}
mMediaSwapTime = Settings::getInstance()->getInt("ScreensaverSwapImageTimeout");
@ -93,6 +95,11 @@ void Screensaver::startScreensaver(bool generateMediaList)
generateCustomImageList();
pickRandomCustomImage(path);
// We've cycled through all games, so start from the beginning again.
if (mImageCustomFiles.size() == 0 && mCustomFilesInventory.size() > 0)
mImageCustomFiles.insert(mImageCustomFiles.begin(), mCustomFilesInventory.begin(),
mCustomFilesInventory.end());
if (mImageCustomFiles.size() > 0)
mHasMediaFiles = true;
// Custom images are not tied to the game list.
@ -104,6 +111,10 @@ void Screensaver::startScreensaver(bool generateMediaList)
pickRandomImage(path);
}
// We've cycled through all games, so start from the beginning again.
if (mImageFiles.size() == 0 && mFilesInventory.size() > 0)
mImageFiles.insert(mImageFiles.begin(), mFilesInventory.begin(), mFilesInventory.end());
if (mImageFiles.size() > 0)
mHasMediaFiles = true;
@ -135,8 +146,10 @@ void Screensaver::startScreensaver(bool generateMediaList)
return;
}
else if (!mVideoScreensaver && (mScreensaverType == "video")) {
if (generateMediaList)
if (generateMediaList) {
mVideoFiles.clear();
mFilesInventory.clear();
}
mMediaSwapTime = Settings::getInstance()->getInt("ScreensaverSwapVideoTimeout");
@ -145,6 +158,10 @@ void Screensaver::startScreensaver(bool generateMediaList)
generateVideoList();
pickRandomVideo(path);
// We've cycled through all games, so start from the beginning again.
if (mVideoFiles.size() == 0 && mFilesInventory.size() > 0)
mVideoFiles.insert(mVideoFiles.begin(), mFilesInventory.begin(), mFilesInventory.end());
if (mVideoFiles.size() > 0)
mHasMediaFiles = true;
@ -276,12 +293,12 @@ void Screensaver::renderScreensaver()
}
}
if (isScreensaverActive()) {
if (mScreensaverType == "slideshow") {
if (mHasMediaFiles) {
if (Settings::getInstance()->getBool("ScreensaverSlideshowScanlines"))
mRenderer->shaderPostprocessing(Renderer::Shader::SCANLINES);
if (Settings::getInstance()->getBool("ScreensaverSlideshowGameInfo") &&
!Settings::getInstance()->getBool("ScreensaverSlideshowCustomImages") &&
mGameOverlay) {
mRenderer->setMatrix(mRenderer->getIdentity());
if (mGameOverlayRectangleCoords.size() == 4) {
@ -290,8 +307,7 @@ void Screensaver::renderScreensaver()
mGameOverlayRectangleCoords[2], mGameOverlayRectangleCoords[3],
0x00000000 | mRectangleFadeIn, 0x00000000 | mRectangleFadeIn);
}
mRectangleFadeIn =
glm::clamp(mRectangleFadeIn + 6 + mRectangleFadeIn / 20, 0, 170);
mRectangleFadeIn = glm::clamp(mRectangleFadeIn + 6 + mRectangleFadeIn / 20, 0, 170);
mGameOverlay.get()->setColor(0xFFFFFF00 | mTextFadeIn);
if (mTextFadeIn > 50)
@ -311,8 +327,7 @@ void Screensaver::renderScreensaver()
if (Settings::getInstance()->getBool("ScreensaverVideoScanlines"))
shaders = Renderer::Shader::SCANLINES;
if (Settings::getInstance()->getBool("ScreensaverVideoBlur")) {
if (mRenderer->getScreenRotation() == 90 ||
mRenderer->getScreenRotation() == 270)
if (mRenderer->getScreenRotation() == 90 || mRenderer->getScreenRotation() == 270)
shaders |= Renderer::Shader::BLUR_VERTICAL;
else
shaders |= Renderer::Shader::BLUR_HORIZONTAL;
@ -333,8 +348,7 @@ void Screensaver::renderScreensaver()
mGameOverlayRectangleCoords[2], mGameOverlayRectangleCoords[3],
0x00000000 | mRectangleFadeIn, 0x00000000 | mRectangleFadeIn);
}
mRectangleFadeIn =
glm::clamp(mRectangleFadeIn + 6 + mRectangleFadeIn / 20, 0, 170);
mRectangleFadeIn = glm::clamp(mRectangleFadeIn + 6 + mRectangleFadeIn / 20, 0, 170);
mGameOverlay.get()->setColor(0xFFFFFF00 | mTextFadeIn);
if (mTextFadeIn > 50)
@ -347,6 +361,7 @@ void Screensaver::renderScreensaver()
mFallbackScreensaver = true;
}
}
if (mFallbackScreensaver || mScreensaverType == "dim") {
Renderer::postProcessingParams dimParameters;
dimParameters.dimming = mDimValue;
@ -365,7 +380,6 @@ void Screensaver::renderScreensaver()
mDimValue = glm::clamp(mDimValue - 0.045f, 0.0f, 1.0f);
}
}
}
void Screensaver::update(int deltaTime)
{
@ -417,6 +431,8 @@ void Screensaver::generateImageList()
mImageFiles.push_back((*it2));
}
}
mFilesInventory.insert(mFilesInventory.begin(), mImageFiles.begin(), mImageFiles.end());
}
void Screensaver::generateVideoList()
@ -442,6 +458,8 @@ void Screensaver::generateVideoList()
mVideoFiles.push_back((*it2));
}
}
mFilesInventory.insert(mFilesInventory.begin(), mVideoFiles.begin(), mVideoFiles.end());
}
void Screensaver::generateCustomImageList()
@ -469,6 +487,9 @@ void Screensaver::generateCustomImageList()
else {
LOG(LogWarning) << "Custom screensaver image directory '" << imageDir << "' does not exist";
}
mCustomFilesInventory.insert(mCustomFilesInventory.begin(), mImageCustomFiles.begin(),
mImageCustomFiles.end());
}
void Screensaver::pickRandomImage(std::string& path)
@ -485,6 +506,7 @@ void Screensaver::pickRandomImage(std::string& path)
mGameName = mImageFiles.front()->getName();
mSystemName = mImageFiles.front()->getSystem()->getFullName();
mCurrentGame = mImageFiles.front();
mImageFiles.clear();
return;
}
@ -503,6 +525,10 @@ void Screensaver::pickRandomImage(std::string& path)
mGameName = mImageFiles.at(index)->getName();
mSystemName = mImageFiles.at(index)->getSystem()->getFullName();
mCurrentGame = mImageFiles.at(index);
// Don't display the same image again until we've cycled through all entries.
auto it = mImageFiles.begin() + index;
mImageFiles.erase(it);
}
void Screensaver::pickRandomVideo(std::string& path)
@ -519,6 +545,7 @@ void Screensaver::pickRandomVideo(std::string& path)
mGameName = mVideoFiles.front()->getName();
mSystemName = mVideoFiles.front()->getSystem()->getFullName();
mCurrentGame = mVideoFiles.front();
mVideoFiles.clear();
return;
}
@ -537,6 +564,10 @@ void Screensaver::pickRandomVideo(std::string& path)
mGameName = mVideoFiles.at(index)->getName();
mSystemName = mVideoFiles.at(index)->getSystem()->getFullName();
mCurrentGame = mVideoFiles.at(index);
// Don't play the same video again until we've cycled through all entries.
auto it = mVideoFiles.begin() + index;
mVideoFiles.erase(it);
}
void Screensaver::pickRandomCustomImage(std::string& path)
@ -547,6 +578,7 @@ void Screensaver::pickRandomCustomImage(std::string& path)
if (mImageCustomFiles.size() == 1) {
mPreviousCustomImage = mImageCustomFiles.front();
path = mImageCustomFiles.front();
mImageCustomFiles.clear();
return;
}
@ -565,6 +597,10 @@ void Screensaver::pickRandomCustomImage(std::string& path)
mPreviousCustomImage = path;
mGameName = "";
mSystemName = "";
// Don't display the same image again until we've cycled through all entries.
auto it = mImageCustomFiles.begin() + index;
mImageCustomFiles.erase(it);
}
void Screensaver::generateOverlayInfo()

View file

@ -49,7 +49,9 @@ private:
std::vector<FileData*> mImageFiles;
std::vector<FileData*> mVideoFiles;
std::vector<FileData*> mFilesInventory;
std::vector<std::string> mImageCustomFiles;
std::vector<std::string> mCustomFilesInventory;
std::unique_ptr<ImageComponent> mImageScreensaver;
std::unique_ptr<VideoComponent> mVideoScreensaver;

View file

@ -810,6 +810,7 @@ void Window::startScreensaver(bool onTimer)
setAllowTextScrolling(false);
setAllowFileAnimation(false);
mScreensaver->startScreensaver(true);
mScreensaver->renderScreensaver();
mRenderScreensaver = true;
}
}