2020-09-18 16:40:22 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
2020-06-23 18:07:00 +00:00
|
|
|
//
|
2020-09-18 16:40:22 +00:00
|
|
|
// EmulationStation Desktop Edition
|
2020-11-10 21:33:57 +00:00
|
|
|
// SystemScreensaver.cpp
|
2020-06-23 18:07:00 +00:00
|
|
|
//
|
2020-11-10 21:18:20 +00:00
|
|
|
// Screensaver, supporting the following types:
|
2020-07-27 14:53:54 +00:00
|
|
|
// Dim, black, slideshow, video.
|
2020-06-23 18:07:00 +00:00
|
|
|
//
|
|
|
|
|
2020-11-10 21:33:57 +00:00
|
|
|
#include "SystemScreensaver.h"
|
2017-11-01 22:21:10 +00:00
|
|
|
|
2020-08-23 15:04:30 +00:00
|
|
|
#if defined(_RPI_)
|
2016-12-14 08:30:54 +00:00
|
|
|
#include "components/VideoPlayerComponent.h"
|
|
|
|
#endif
|
|
|
|
#include "components/VideoVlcComponent.h"
|
2018-01-09 22:55:09 +00:00
|
|
|
#include "utils/FileSystemUtil.h"
|
2017-11-01 22:21:10 +00:00
|
|
|
#include "views/gamelist/IGameListView.h"
|
|
|
|
#include "views/ViewController.h"
|
|
|
|
#include "FileData.h"
|
|
|
|
#include "Log.h"
|
2017-08-02 19:56:33 +00:00
|
|
|
#include "PowerSaver.h"
|
2016-12-14 08:30:54 +00:00
|
|
|
#include "SystemData.h"
|
2020-07-03 18:23:51 +00:00
|
|
|
|
2020-11-10 21:18:20 +00:00
|
|
|
#include <random>
|
2018-01-29 22:50:10 +00:00
|
|
|
#include <time.h>
|
2020-09-21 17:17:34 +00:00
|
|
|
#include <unordered_map>
|
2020-07-03 18:23:51 +00:00
|
|
|
|
2020-08-23 15:04:30 +00:00
|
|
|
#if defined(_WIN64)
|
2020-07-03 18:23:51 +00:00
|
|
|
#include <cstring>
|
|
|
|
#endif
|
|
|
|
|
2020-06-23 18:07:00 +00:00
|
|
|
#define FADE_TIME 300
|
|
|
|
|
2020-11-10 21:18:20 +00:00
|
|
|
SystemScreensaver::SystemScreensaver(
|
|
|
|
Window* window)
|
|
|
|
: mImageScreensaver(nullptr),
|
|
|
|
mVideoScreensaver(nullptr),
|
|
|
|
mWindow(window),
|
|
|
|
mState(STATE_INACTIVE),
|
|
|
|
mOpacity(0.0f),
|
|
|
|
mTimer(0),
|
|
|
|
mSystemName(""),
|
|
|
|
mGameName(""),
|
|
|
|
mCurrentGame(nullptr),
|
|
|
|
mHasMediaFiles(false)
|
2016-12-14 08:30:54 +00:00
|
|
|
{
|
2020-11-10 21:18:20 +00:00
|
|
|
mWindow->setScreensaver(this);
|
2020-06-23 18:07:00 +00:00
|
|
|
mVideoChangeTime = 30000;
|
2016-12-14 08:30:54 +00:00
|
|
|
}
|
|
|
|
|
2020-11-10 21:18:20 +00:00
|
|
|
SystemScreensaver::~SystemScreensaver()
|
2016-12-14 08:30:54 +00:00
|
|
|
{
|
2020-06-23 18:07:00 +00:00
|
|
|
mCurrentGame = nullptr;
|
|
|
|
delete mVideoScreensaver;
|
|
|
|
delete mImageScreensaver;
|
2016-12-14 08:30:54 +00:00
|
|
|
}
|
|
|
|
|
2020-11-10 21:18:20 +00:00
|
|
|
bool SystemScreensaver::allowSleep()
|
2016-12-14 08:30:54 +00:00
|
|
|
{
|
2020-06-23 18:07:00 +00:00
|
|
|
return ((mVideoScreensaver == nullptr) && (mImageScreensaver == nullptr));
|
2017-06-01 20:08:44 +00:00
|
|
|
}
|
|
|
|
|
2020-11-10 21:18:20 +00:00
|
|
|
bool SystemScreensaver::isScreensaverActive()
|
2017-06-01 20:08:44 +00:00
|
|
|
{
|
2020-06-23 18:07:00 +00:00
|
|
|
return (mState != STATE_INACTIVE);
|
2016-12-14 08:30:54 +00:00
|
|
|
}
|
|
|
|
|
2020-11-10 21:18:20 +00:00
|
|
|
void SystemScreensaver::startScreensaver(bool generateMediaList)
|
2016-12-14 08:30:54 +00:00
|
|
|
{
|
2020-11-10 21:18:20 +00:00
|
|
|
std::string path = "";
|
|
|
|
std::string screensaverType = Settings::getInstance()->getString("ScreensaverType");
|
|
|
|
mHasMediaFiles = false;
|
2020-07-28 09:10:14 +00:00
|
|
|
|
|
|
|
// Set mPreviousGame which will be used to avoid showing the same game again during
|
|
|
|
// the random selection.
|
2020-11-10 21:18:20 +00:00
|
|
|
if ((screensaverType == "video" || screensaverType == "slideshow") &&
|
2020-07-28 09:10:14 +00:00
|
|
|
mCurrentGame != nullptr)
|
|
|
|
mPreviousGame = mCurrentGame;
|
|
|
|
|
2020-11-10 21:18:20 +00:00
|
|
|
if (screensaverType == "slideshow") {
|
|
|
|
if (generateMediaList) {
|
|
|
|
mImageFiles.clear();
|
|
|
|
mImageCustomFiles.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
// This creates a fade transition between the images.
|
|
|
|
mState = STATE_FADE_OUT_WINDOW;
|
|
|
|
|
|
|
|
mVideoChangeTime = Settings::getInstance()->getInt("ScreensaverSwapImageTimeout");
|
|
|
|
mOpacity = 0.0f;
|
|
|
|
|
|
|
|
// Load a random image.
|
|
|
|
if (Settings::getInstance()->getBool("ScreensaverSlideshowCustomImages")) {
|
|
|
|
if (generateMediaList)
|
|
|
|
generateCustomImageList();
|
|
|
|
pickRandomCustomImage(path);
|
|
|
|
|
|
|
|
if (mImageCustomFiles.size() > 0)
|
|
|
|
mHasMediaFiles = true;
|
|
|
|
// Custom images are not tied to the game list.
|
|
|
|
mCurrentGame = nullptr;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (generateMediaList)
|
|
|
|
generateImageList();
|
|
|
|
pickRandomImage(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mImageFiles.size() > 0)
|
|
|
|
mHasMediaFiles = true;
|
|
|
|
|
|
|
|
// Don't attempt to render the screensaver if there are no images available, but
|
|
|
|
// do flag it as running. This way Window::render() will fade to a black screen, i.e.
|
|
|
|
// it will activate the 'Black' screensaver type.
|
|
|
|
if (mImageFiles.size() > 0 || mImageCustomFiles.size() > 0) {
|
|
|
|
if (!mImageScreensaver)
|
|
|
|
mImageScreensaver = new ImageComponent(mWindow, false, false);
|
|
|
|
|
|
|
|
mTimer = 0;
|
|
|
|
|
|
|
|
mImageScreensaver->setImage(path);
|
|
|
|
mImageScreensaver->setOrigin(0.5f, 0.5f);
|
|
|
|
mImageScreensaver->setPosition(Renderer::getScreenWidth() / 2.0f,
|
|
|
|
Renderer::getScreenHeight() / 2.0f);
|
|
|
|
|
|
|
|
if (Settings::getInstance()->getBool("ScreensaverStretchImages"))
|
|
|
|
mImageScreensaver->setResize(static_cast<float>(Renderer::getScreenWidth()),
|
|
|
|
static_cast<float>(Renderer::getScreenHeight()));
|
|
|
|
else
|
|
|
|
mImageScreensaver->setMaxSize(static_cast<float>(Renderer::getScreenWidth()),
|
|
|
|
static_cast<float>(Renderer::getScreenHeight()));
|
|
|
|
}
|
|
|
|
PowerSaver::runningScreensaver(true);
|
|
|
|
mTimer = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if (!mVideoScreensaver && (screensaverType == "video")) {
|
|
|
|
if (generateMediaList)
|
|
|
|
mVideoFiles.clear();
|
|
|
|
|
|
|
|
// This creates a fade transition between the videos.
|
|
|
|
mState = STATE_FADE_OUT_WINDOW;
|
|
|
|
|
2020-11-05 17:18:11 +00:00
|
|
|
mVideoChangeTime = Settings::getInstance()->getInt("ScreensaverSwapVideoTimeout");
|
2020-06-23 18:07:00 +00:00
|
|
|
mOpacity = 0.0f;
|
|
|
|
|
|
|
|
// Load a random video.
|
2020-11-10 21:18:20 +00:00
|
|
|
if (generateMediaList)
|
|
|
|
generateVideoList();
|
2020-06-23 18:07:00 +00:00
|
|
|
pickRandomVideo(path);
|
|
|
|
|
2020-11-10 21:18:20 +00:00
|
|
|
if (mVideoFiles.size() > 0)
|
|
|
|
mHasMediaFiles = true;
|
2020-06-23 18:07:00 +00:00
|
|
|
|
|
|
|
if (!path.empty() && Utils::FileSystem::exists(path)) {
|
2020-08-23 15:04:30 +00:00
|
|
|
#if defined(_RPI_)
|
2020-06-23 18:07:00 +00:00
|
|
|
// Create the correct type of video component
|
2020-11-05 17:18:11 +00:00
|
|
|
if (Settings::getInstance()->getBool("ScreensaverOmxPlayer"))
|
2020-10-17 14:06:01 +00:00
|
|
|
mVideoScreensaver = new VideoPlayerComponent(mWindow);
|
2020-06-23 18:07:00 +00:00
|
|
|
else
|
2020-10-17 14:06:01 +00:00
|
|
|
mVideoScreensaver = new VideoVlcComponent(mWindow);
|
2020-06-23 18:07:00 +00:00
|
|
|
#else
|
2020-10-17 14:06:01 +00:00
|
|
|
mVideoScreensaver = new VideoVlcComponent(mWindow);
|
2020-06-23 18:07:00 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
mVideoScreensaver->topWindow(true);
|
|
|
|
mVideoScreensaver->setOrigin(0.5f, 0.5f);
|
|
|
|
mVideoScreensaver->setPosition(Renderer::getScreenWidth() / 2.0f,
|
|
|
|
Renderer::getScreenHeight() / 2.0f);
|
|
|
|
|
2020-11-05 17:18:11 +00:00
|
|
|
if (Settings::getInstance()->getBool("ScreensaverStretchVideos"))
|
2020-09-18 16:40:22 +00:00
|
|
|
mVideoScreensaver->setResize(static_cast<float>(Renderer::getScreenWidth()),
|
|
|
|
static_cast<float>(Renderer::getScreenHeight()));
|
2020-06-23 18:07:00 +00:00
|
|
|
else
|
2020-09-18 16:40:22 +00:00
|
|
|
mVideoScreensaver->setMaxSize(static_cast<float>(Renderer::getScreenWidth()),
|
|
|
|
static_cast<float>(Renderer::getScreenHeight()));
|
2020-06-23 18:07:00 +00:00
|
|
|
|
|
|
|
mVideoScreensaver->setVideo(path);
|
|
|
|
mVideoScreensaver->setScreensaverMode(true);
|
|
|
|
mVideoScreensaver->onShow();
|
2020-11-10 21:18:20 +00:00
|
|
|
PowerSaver::runningScreensaver(true);
|
2020-06-23 18:07:00 +00:00
|
|
|
mTimer = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2020-11-10 21:18:20 +00:00
|
|
|
// No videos or images, just use a standard screensaver.
|
2020-06-23 18:07:00 +00:00
|
|
|
mState = STATE_SCREENSAVER_ACTIVE;
|
|
|
|
mCurrentGame = nullptr;
|
2016-12-14 08:30:54 +00:00
|
|
|
}
|
|
|
|
|
2020-11-10 21:18:20 +00:00
|
|
|
void SystemScreensaver::stopScreensaver()
|
2016-12-14 08:30:54 +00:00
|
|
|
{
|
2020-06-23 18:07:00 +00:00
|
|
|
delete mVideoScreensaver;
|
|
|
|
mVideoScreensaver = nullptr;
|
|
|
|
delete mImageScreensaver;
|
|
|
|
mImageScreensaver = nullptr;
|
|
|
|
|
|
|
|
mState = STATE_INACTIVE;
|
2020-11-10 21:18:20 +00:00
|
|
|
PowerSaver::runningScreensaver(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SystemScreensaver::nextGame() {
|
|
|
|
stopScreensaver();
|
|
|
|
startScreensaver(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SystemScreensaver::launchGame()
|
|
|
|
{
|
|
|
|
if (mCurrentGame != nullptr) {
|
|
|
|
// Launching game
|
|
|
|
ViewController::get()->goToGameList(mCurrentGame->getSystem());
|
|
|
|
IGameListView* view = ViewController::get()->
|
|
|
|
getGameListView(mCurrentGame->getSystem()).get();
|
|
|
|
view->setCursor(mCurrentGame);
|
|
|
|
ViewController::get()->resetMovingCamera();
|
|
|
|
ViewController::get()->launch(mCurrentGame);
|
|
|
|
}
|
2016-12-14 08:30:54 +00:00
|
|
|
}
|
|
|
|
|
2020-11-10 21:18:20 +00:00
|
|
|
void SystemScreensaver::renderScreensaver()
|
2016-12-14 08:30:54 +00:00
|
|
|
{
|
2020-11-10 21:18:20 +00:00
|
|
|
std::string screensaverType = Settings::getInstance()->getString("ScreensaverType");
|
|
|
|
if (mVideoScreensaver && screensaverType == "video") {
|
2020-06-23 18:07:00 +00:00
|
|
|
// Render black background.
|
|
|
|
Renderer::setMatrix(Transform4x4f::Identity());
|
|
|
|
Renderer::drawRect(0.0f, 0.0f, Renderer::getScreenWidth(),
|
|
|
|
Renderer::getScreenHeight(), 0x000000FF, 0x000000FF);
|
|
|
|
|
|
|
|
// Only render the video if the state requires it.
|
2020-09-18 16:40:22 +00:00
|
|
|
if (static_cast<int>(mState) >= STATE_FADE_IN_VIDEO) {
|
2020-06-23 18:07:00 +00:00
|
|
|
Transform4x4f transform = Transform4x4f::Identity();
|
|
|
|
mVideoScreensaver->render(transform);
|
|
|
|
}
|
|
|
|
}
|
2020-11-10 21:18:20 +00:00
|
|
|
else if (mImageScreensaver && screensaverType == "slideshow") {
|
|
|
|
// Render a black background.
|
2020-06-23 18:07:00 +00:00
|
|
|
Renderer::setMatrix(Transform4x4f::Identity());
|
|
|
|
Renderer::drawRect(0.0f, 0.0f, Renderer::getScreenWidth(),
|
|
|
|
Renderer::getScreenHeight(), 0x000000FF, 0x000000FF);
|
|
|
|
|
|
|
|
// Only render the video if the state requires it.
|
2020-11-10 21:18:20 +00:00
|
|
|
if (static_cast<int>(mState) >= STATE_FADE_IN_VIDEO) {
|
2020-06-23 18:07:00 +00:00
|
|
|
if (mImageScreensaver->hasImage()) {
|
2020-09-18 16:40:22 +00:00
|
|
|
mImageScreensaver->setOpacity(255 - static_cast<unsigned char>(mOpacity * 255));
|
2020-06-23 18:07:00 +00:00
|
|
|
|
|
|
|
Transform4x4f transform = Transform4x4f::Identity();
|
|
|
|
mImageScreensaver->render(transform);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-11-10 21:18:20 +00:00
|
|
|
#if !defined(USE_OPENGL_21)
|
2020-06-23 18:07:00 +00:00
|
|
|
else if (mState != STATE_INACTIVE) {
|
|
|
|
Renderer::setMatrix(Transform4x4f::Identity());
|
2020-11-10 21:18:20 +00:00
|
|
|
unsigned char color = screensaverType == "dim" ? 0x000000A0 : 0x000000FF;
|
2020-06-23 18:07:00 +00:00
|
|
|
Renderer::drawRect(0.0f, 0.0f, Renderer::getScreenWidth(),
|
|
|
|
Renderer::getScreenHeight(), color, color);
|
|
|
|
}
|
2020-11-10 21:18:20 +00:00
|
|
|
#endif
|
2016-12-14 08:30:54 +00:00
|
|
|
}
|
|
|
|
|
2020-11-10 21:18:20 +00:00
|
|
|
void SystemScreensaver::update(int deltaTime)
|
2016-12-14 08:30:54 +00:00
|
|
|
{
|
2020-11-10 21:18:20 +00:00
|
|
|
// Use this to update the fade value for the current fade stage.
|
|
|
|
if (mState == STATE_FADE_OUT_WINDOW) {
|
|
|
|
mOpacity += static_cast<float>(deltaTime) / FADE_TIME;
|
|
|
|
if (mOpacity >= 1.0f) {
|
|
|
|
mOpacity = 1.0f;
|
2020-06-23 18:07:00 +00:00
|
|
|
|
2020-11-10 21:18:20 +00:00
|
|
|
// Update to the next state.
|
|
|
|
mState = STATE_FADE_IN_VIDEO;
|
2020-06-23 18:07:00 +00:00
|
|
|
}
|
|
|
|
}
|
2020-11-10 21:18:20 +00:00
|
|
|
else if (mState == STATE_FADE_IN_VIDEO) {
|
|
|
|
mOpacity -= static_cast<float>(deltaTime) / FADE_TIME;
|
|
|
|
if (mOpacity <= 0.0f) {
|
|
|
|
mOpacity = 0.0f;
|
|
|
|
// Update to the next state.
|
|
|
|
mState = STATE_SCREENSAVER_ACTIVE;
|
|
|
|
}
|
2020-06-23 18:07:00 +00:00
|
|
|
}
|
2020-11-10 21:18:20 +00:00
|
|
|
else if (mState == STATE_SCREENSAVER_ACTIVE) {
|
|
|
|
// Update the timer that swaps the videos.
|
|
|
|
mTimer += deltaTime;
|
|
|
|
if (mTimer > mVideoChangeTime)
|
|
|
|
nextGame();
|
2020-06-23 18:07:00 +00:00
|
|
|
}
|
2020-11-10 21:18:20 +00:00
|
|
|
|
|
|
|
// If we have a loaded video then update it.
|
|
|
|
if (mVideoScreensaver)
|
|
|
|
mVideoScreensaver->update(deltaTime);
|
|
|
|
if (mImageScreensaver)
|
|
|
|
mImageScreensaver->update(deltaTime);
|
2017-09-09 03:45:50 +00:00
|
|
|
}
|
|
|
|
|
2020-11-10 21:18:20 +00:00
|
|
|
void SystemScreensaver::generateImageList()
|
2017-09-09 03:45:50 +00:00
|
|
|
{
|
2020-11-10 21:18:20 +00:00
|
|
|
for (auto it = SystemData::sSystemVector.cbegin();
|
2020-06-23 18:07:00 +00:00
|
|
|
it != SystemData::sSystemVector.cend(); ++it) {
|
|
|
|
// We only want nodes from game systems that are not collections.
|
|
|
|
if (!(*it)->isGameSystem() || (*it)->isCollection())
|
|
|
|
continue;
|
|
|
|
|
2020-11-10 21:18:20 +00:00
|
|
|
std::vector<FileData*> allFiles = (*it)->getRootFolder()->getFilesRecursive(GAME, true);
|
|
|
|
for (auto it = allFiles.begin(); it != allFiles.end(); it++) {
|
|
|
|
std::string imagePath = (*it)->getImagePath();
|
|
|
|
if (imagePath != "")
|
|
|
|
mImageFiles.push_back((*it));
|
2020-07-28 09:10:14 +00:00
|
|
|
}
|
2020-06-23 18:07:00 +00:00
|
|
|
}
|
2017-09-09 03:45:50 +00:00
|
|
|
}
|
|
|
|
|
2020-11-10 21:18:20 +00:00
|
|
|
void SystemScreensaver::generateVideoList()
|
2017-09-09 03:45:50 +00:00
|
|
|
{
|
2020-11-10 21:18:20 +00:00
|
|
|
for (auto it = SystemData::sSystemVector.cbegin();
|
|
|
|
it != SystemData::sSystemVector.cend(); ++it) {
|
|
|
|
// We only want nodes from game systems that are not collections.
|
|
|
|
if (!(*it)->isGameSystem() || (*it)->isCollection())
|
|
|
|
continue;
|
2020-07-28 09:10:14 +00:00
|
|
|
|
2020-11-10 21:18:20 +00:00
|
|
|
std::vector<FileData*> allFiles = (*it)->getRootFolder()->getFilesRecursive(GAME, true);
|
|
|
|
for (auto it = allFiles.begin(); it != allFiles.end(); it++) {
|
|
|
|
std::string videoPath = (*it)->getVideoPath();
|
|
|
|
if (videoPath != "")
|
|
|
|
mVideoFiles.push_back((*it));
|
2020-07-28 09:10:14 +00:00
|
|
|
}
|
2020-06-23 18:07:00 +00:00
|
|
|
}
|
2017-09-09 03:45:50 +00:00
|
|
|
}
|
|
|
|
|
2020-11-10 21:18:20 +00:00
|
|
|
void SystemScreensaver::generateCustomImageList()
|
2017-09-09 03:45:50 +00:00
|
|
|
{
|
2020-11-10 21:18:20 +00:00
|
|
|
std::string imageDir = Utils::FileSystem::expandHomePath(
|
|
|
|
Settings::getInstance()->getString("ScreensaverSlideshowImageDir"));
|
2020-06-23 18:07:00 +00:00
|
|
|
|
2020-11-10 21:18:20 +00:00
|
|
|
if (imageDir != "" && Utils::FileSystem::isDirectory(imageDir)) {
|
2020-11-05 17:18:11 +00:00
|
|
|
std::string imageFilter = ".jpg, .JPG, .png, .PNG";
|
2020-06-23 18:07:00 +00:00
|
|
|
Utils::FileSystem::stringList dirContent = Utils::FileSystem::getDirContent(
|
2020-11-05 17:18:11 +00:00
|
|
|
imageDir, Settings::getInstance()->getBool("ScreensaverSlideshowRecurse"));
|
2020-06-23 18:07:00 +00:00
|
|
|
|
2020-11-10 21:18:20 +00:00
|
|
|
for (auto it = dirContent.begin(); it != dirContent.end(); it++) {
|
2020-06-23 18:07:00 +00:00
|
|
|
if (Utils::FileSystem::isRegularFile(*it)) {
|
2020-11-10 21:18:20 +00:00
|
|
|
if (imageFilter.find(Utils::FileSystem::getExtension(*it)) != std::string::npos)
|
|
|
|
mImageCustomFiles.push_back(*it);
|
2020-06-23 18:07:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2020-11-10 21:18:20 +00:00
|
|
|
LOG(LogWarning) << "Custom screensaver image directory '" <<
|
|
|
|
imageDir << "' does not exist.";
|
2020-06-23 18:07:00 +00:00
|
|
|
}
|
2017-09-09 03:45:50 +00:00
|
|
|
}
|
|
|
|
|
2020-11-10 21:18:20 +00:00
|
|
|
void SystemScreensaver::pickRandomImage(std::string& path)
|
2016-12-14 08:30:54 +00:00
|
|
|
{
|
2020-11-10 21:18:20 +00:00
|
|
|
mCurrentGame = nullptr;
|
2020-06-23 18:07:00 +00:00
|
|
|
|
2020-11-10 21:18:20 +00:00
|
|
|
if (mImageFiles.size() == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (mImageFiles.size() == 1) {
|
|
|
|
mPreviousGame = nullptr;
|
|
|
|
mCurrentGame = mImageFiles.front();
|
|
|
|
path = mImageFiles.front()->getImagePath();
|
|
|
|
return;
|
2020-06-23 18:07:00 +00:00
|
|
|
}
|
|
|
|
|
2020-11-10 21:18:20 +00:00
|
|
|
unsigned int index;
|
|
|
|
do {
|
|
|
|
// Get a random number in range.
|
|
|
|
std::random_device randDev;
|
|
|
|
// Mersenne Twister pseudorandom number generator.
|
|
|
|
std::mt19937 engine{randDev()};
|
|
|
|
std::uniform_int_distribution<int> uniform_dist(0, mImageFiles.size() - 1);
|
|
|
|
index = uniform_dist(engine);
|
|
|
|
}
|
|
|
|
while (mPreviousGame && mImageFiles.at(index) == mPreviousGame);
|
2017-06-01 20:08:44 +00:00
|
|
|
|
2020-11-10 21:18:20 +00:00
|
|
|
path = mImageFiles.at(index)->getImagePath();
|
|
|
|
mGameName = mImageFiles.at(index)->getName();
|
|
|
|
mSystemName = mImageFiles.at(index)->getSystem()->getFullName();
|
|
|
|
mCurrentGame = mImageFiles.at(index);
|
2017-06-01 20:08:44 +00:00
|
|
|
}
|
|
|
|
|
2020-11-10 21:18:20 +00:00
|
|
|
void SystemScreensaver::pickRandomVideo(std::string& path)
|
2017-06-01 20:08:44 +00:00
|
|
|
{
|
2020-11-10 21:18:20 +00:00
|
|
|
mCurrentGame = nullptr;
|
|
|
|
|
|
|
|
if (mVideoFiles.size() == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (mVideoFiles.size() == 1) {
|
|
|
|
mPreviousGame = nullptr;
|
|
|
|
mCurrentGame = mVideoFiles.front();
|
|
|
|
path = mVideoFiles.front()->getVideoPath();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int index;
|
|
|
|
do {
|
|
|
|
// Get a random number in range.
|
|
|
|
std::random_device randDev;
|
|
|
|
// Mersenne Twister pseudorandom number generator.
|
|
|
|
std::mt19937 engine{randDev()};
|
|
|
|
std::uniform_int_distribution<int> uniform_dist(0, mVideoFiles.size() - 1);
|
|
|
|
index = uniform_dist(engine);
|
|
|
|
}
|
|
|
|
while (mPreviousGame && mVideoFiles.at(index) == mPreviousGame);
|
|
|
|
|
|
|
|
path = mVideoFiles.at(index)->getVideoPath();
|
|
|
|
mGameName = mVideoFiles.at(index)->getName();
|
|
|
|
mSystemName = mVideoFiles.at(index)->getSystem()->getFullName();
|
|
|
|
mCurrentGame = mVideoFiles.at(index);
|
2017-06-01 20:08:44 +00:00
|
|
|
}
|
|
|
|
|
2020-11-10 21:18:20 +00:00
|
|
|
void SystemScreensaver::pickRandomCustomImage(std::string& path)
|
2017-06-01 20:08:44 +00:00
|
|
|
{
|
2020-11-10 21:18:20 +00:00
|
|
|
if (mImageCustomFiles.size() == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (mVideoFiles.size() == 1) {
|
|
|
|
mPreviousCustomImage = mImageCustomFiles.front();
|
|
|
|
path = mImageCustomFiles.front();
|
|
|
|
return;
|
2020-06-23 18:07:00 +00:00
|
|
|
}
|
2020-11-10 21:18:20 +00:00
|
|
|
|
|
|
|
unsigned int index;
|
|
|
|
do {
|
|
|
|
// Get a random number in range.
|
|
|
|
std::random_device randDev;
|
|
|
|
// Mersenne Twister pseudorandom number generator.
|
|
|
|
std::mt19937 engine{randDev()};
|
|
|
|
std::uniform_int_distribution<int> uniform_dist(0, mImageCustomFiles.size() - 1);
|
|
|
|
index = uniform_dist(engine);
|
|
|
|
}
|
|
|
|
while (mPreviousCustomImage != "" && mImageCustomFiles.at(index) == mPreviousCustomImage);
|
|
|
|
|
|
|
|
path = mImageCustomFiles.at(index);
|
|
|
|
mPreviousCustomImage = path;
|
|
|
|
mGameName = "";
|
|
|
|
mSystemName = "";
|
2017-08-02 19:56:33 +00:00
|
|
|
}
|