From 340765892f8f35c9cb2c8cb32c1a81f2df8b9c34 Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Sun, 19 Feb 2023 19:06:11 +0100 Subject: [PATCH] Changed some optimizations to much better ones in SystemView and GamelistView. --- es-app/src/views/GamelistView.cpp | 174 +++++++++++------------------- es-app/src/views/SystemView.cpp | 86 ++++++--------- 2 files changed, 97 insertions(+), 163 deletions(-) diff --git a/es-app/src/views/GamelistView.cpp b/es-app/src/views/GamelistView.cpp index 571d14ff3..760ac4963 100644 --- a/es-app/src/views/GamelistView.cpp +++ b/es-app/src/views/GamelistView.cpp @@ -203,7 +203,8 @@ void GamelistView::onThemeChanged(const std::shared_ptr& theme) mPrimary->applyTheme(theme, "gamelist", element.first, ALL); addChild(mPrimary); } - if (element.second.type == "image") { + if (element.second.type == "image" && + (!(element.second.has("visible") && !element.second.get("visible")))) { // If this is the startup system, then forceload the images to avoid texture pop-in. if (isStartupSystem) mImageComponents.push_back(std::make_unique(true)); @@ -211,77 +212,54 @@ void GamelistView::onThemeChanged(const std::shared_ptr& theme) mImageComponents.push_back(std::make_unique()); mImageComponents.back()->setDefaultZIndex(30.0f); mImageComponents.back()->applyTheme(theme, "gamelist", element.first, ALL); - if (mImageComponents.back()->getThemeOpacity() != 0.0f) { - if (mImageComponents.back()->getThemeImageTypes().size() != 0) - mImageComponents.back()->setScrollHide(true); - else if (mImageComponents.back()->getMetadataElement()) - mImageComponents.back()->setScrollHide(true); - addChild(mImageComponents.back().get()); - } - else { - mImageComponents.pop_back(); - } + if (mImageComponents.back()->getThemeImageTypes().size() != 0) + mImageComponents.back()->setScrollHide(true); + else if (mImageComponents.back()->getMetadataElement()) + mImageComponents.back()->setScrollHide(true); + addChild(mImageComponents.back().get()); } - else if (element.second.type == "video") { + else if (element.second.type == "video" && + (!(element.second.has("visible") && !element.second.get("visible")))) { if (element.second.has("path")) { mStaticVideoComponents.push_back(std::make_unique()); mStaticVideoComponents.back()->setDefaultZIndex(30.0f); mStaticVideoComponents.back()->applyTheme(theme, "gamelist", element.first, ALL); - if (mStaticVideoComponents.back()->getThemeOpacity() != 0.0f) { - if (mStaticVideoComponents.back()->getMetadataElement()) - mStaticVideoComponents.back()->setScrollHide(true); - mStaticVideoComponents.back()->setGeneralFade(true); - if (element.second.has("audio")) - mStaticVideoAudio = element.second.get("audio"); - addChild(mStaticVideoComponents.back().get()); - } - else { - mStaticVideoComponents.pop_back(); - } + if (mStaticVideoComponents.back()->getMetadataElement()) + mStaticVideoComponents.back()->setScrollHide(true); + mStaticVideoComponents.back()->setGeneralFade(true); + if (element.second.has("audio")) + mStaticVideoAudio = element.second.get("audio"); + addChild(mStaticVideoComponents.back().get()); } else { mVideoComponents.push_back(std::make_unique()); mVideoComponents.back()->setDefaultZIndex(30.0f); mVideoComponents.back()->applyTheme(theme, "gamelist", element.first, ALL); - if (mVideoComponents.back()->getThemeOpacity() != 0.0f) { - if (mVideoComponents.back()->getThemeImageTypes().size() != 0) - mVideoComponents.back()->setScrollHide(true); - addChild(mVideoComponents.back().get()); - } - else { - mVideoComponents.pop_back(); - } + if (mVideoComponents.back()->getThemeImageTypes().size() != 0) + mVideoComponents.back()->setScrollHide(true); + addChild(mVideoComponents.back().get()); } } - else if (element.second.type == "animation" && element.second.has("path")) { + else if (element.second.type == "animation" && element.second.has("path") && + (!(element.second.has("visible") && !element.second.get("visible")))) { const std::string extension { Utils::FileSystem::getExtension(element.second.get("path"))}; if (extension == ".json") { mLottieAnimComponents.push_back(std::make_unique()); mLottieAnimComponents.back()->setDefaultZIndex(35.0f); mLottieAnimComponents.back()->applyTheme(theme, "gamelist", element.first, ALL); - if (mLottieAnimComponents.back()->getThemeOpacity() != 0.0f) { - if (mLottieAnimComponents.back()->getMetadataElement()) - mLottieAnimComponents.back()->setScrollHide(true); - addChild(mLottieAnimComponents.back().get()); - } - else { - mLottieAnimComponents.pop_back(); - } + if (mLottieAnimComponents.back()->getMetadataElement()) + mLottieAnimComponents.back()->setScrollHide(true); + addChild(mLottieAnimComponents.back().get()); } else if (extension == ".gif") { mGIFAnimComponents.push_back(std::make_unique()); mGIFAnimComponents.back()->setDefaultZIndex(35.0f); mGIFAnimComponents.back()->applyTheme(theme, "gamelist", element.first, ALL); - if (mGIFAnimComponents.back()->getThemeOpacity() != 0.0f) { - if (mGIFAnimComponents.back()->getMetadataElement()) - mGIFAnimComponents.back()->setScrollHide(true); - addChild(mGIFAnimComponents.back().get()); - } - else { - mGIFAnimComponents.pop_back(); - } + if (mGIFAnimComponents.back()->getMetadataElement()) + mGIFAnimComponents.back()->setScrollHide(true); + addChild(mGIFAnimComponents.back().get()); } else if (extension == ".") { LOG(LogWarning) @@ -295,19 +273,16 @@ void GamelistView::onThemeChanged(const std::shared_ptr& theme) << extension << "\""; } } - else if (element.second.type == "badges") { + else if (element.second.type == "badges" && + (!(element.second.has("visible") && !element.second.get("visible")))) { mBadgeComponents.push_back(std::make_unique()); mBadgeComponents.back()->setDefaultZIndex(35.0f); mBadgeComponents.back()->applyTheme(theme, "gamelist", element.first, ALL); - if (mBadgeComponents.back()->getThemeOpacity() != 0.0f) { - mBadgeComponents.back()->setScrollHide(true); - addChild(mBadgeComponents.back().get()); - } - else { - mBadgeComponents.pop_back(); - } + mBadgeComponents.back()->setScrollHide(true); + addChild(mBadgeComponents.back().get()); } - else if (element.second.type == "text") { + else if (element.second.type == "text" && + (!(element.second.has("visible") && !element.second.get("visible")))) { // Set as container by default if metadata type is "description". bool container {false}; if (element.second.has("container")) { @@ -326,77 +301,56 @@ void GamelistView::onThemeChanged(const std::shared_ptr& theme) mContainerComponents.back()->applyTheme(theme, "gamelist", element.first, POSITION | ThemeFlags::SIZE | Z_INDEX | VISIBLE); - if (mContainerComponents.back()->getThemeOpacity() != 0.0f) { - mContainerComponents.back()->setAutoScroll(true); - mContainerTextComponents.back()->setSize( - mContainerComponents.back()->getSize().x, 0.0f); - mContainerTextComponents.back()->applyTheme( - theme, "gamelist", element.first, - ALL ^ POSITION ^ ORIGIN ^ Z_INDEX ^ ThemeFlags::SIZE ^ VISIBLE ^ - ROTATION); - if (mContainerTextComponents.back()->getThemeMetadata() != "") - mContainerComponents.back()->setScrollHide(true); - else if (mContainerTextComponents.back()->getMetadataElement()) - mContainerComponents.back()->setScrollHide(true); - addChild(mContainerComponents.back().get()); - } - else { - mContainerComponents.pop_back(); - } + mContainerComponents.back()->setAutoScroll(true); + mContainerTextComponents.back()->setSize( + mContainerComponents.back()->getSize().x, 0.0f); + mContainerTextComponents.back()->applyTheme( + theme, "gamelist", element.first, + ALL ^ POSITION ^ ORIGIN ^ Z_INDEX ^ ThemeFlags::SIZE ^ VISIBLE ^ ROTATION); + if (mContainerTextComponents.back()->getThemeMetadata() != "") + mContainerComponents.back()->setScrollHide(true); + else if (mContainerTextComponents.back()->getMetadataElement()) + mContainerComponents.back()->setScrollHide(true); + addChild(mContainerComponents.back().get()); } else { mTextComponents.push_back(std::make_unique()); mTextComponents.back()->setDefaultZIndex(40.0f); mTextComponents.back()->applyTheme(theme, "gamelist", element.first, ALL); - if (mTextComponents.back()->getThemeOpacity() != 0.0f) { - const std::string& metadata {mTextComponents.back()->getThemeMetadata()}; - if (metadata != "" && metadata != "systemName" && - metadata != "systemFullname" && metadata != "sourceSystemName" && - metadata != "sourceSystemFullname") - mTextComponents.back()->setScrollHide(true); - else if (mTextComponents.back()->getMetadataElement()) - mTextComponents.back()->setScrollHide(true); - addChild(mTextComponents.back().get()); - } - else { - mTextComponents.pop_back(); - } + const std::string& metadata {mTextComponents.back()->getThemeMetadata()}; + if (metadata != "" && metadata != "systemName" && + metadata != "systemFullname" && metadata != "sourceSystemName" && + metadata != "sourceSystemFullname") + mTextComponents.back()->setScrollHide(true); + else if (mTextComponents.back()->getMetadataElement()) + mTextComponents.back()->setScrollHide(true); + addChild(mTextComponents.back().get()); } } - else if (element.second.type == "datetime") { + else if (element.second.type == "datetime" && + (!(element.second.has("visible") && !element.second.get("visible")))) { mDateTimeComponents.push_back(std::make_unique()); mDateTimeComponents.back()->setDefaultZIndex(40.0f); mDateTimeComponents.back()->applyTheme(theme, "gamelist", element.first, ALL); - if (mDateTimeComponents.back()->getThemeOpacity() != 0.0f) { - if (mDateTimeComponents.back()->getThemeMetadata() != "") - mDateTimeComponents.back()->setScrollHide(true); - addChild(mDateTimeComponents.back().get()); - } - else { - mDateTimeComponents.pop_back(); - } + if (mDateTimeComponents.back()->getThemeMetadata() != "") + mDateTimeComponents.back()->setScrollHide(true); + addChild(mDateTimeComponents.back().get()); } - else if (element.second.type == "gamelistinfo") { + else if (element.second.type == "gamelistinfo" && + (!(element.second.has("visible") && !element.second.get("visible")))) { mGamelistInfoComponents.push_back(std::make_unique()); mGamelistInfoComponents.back()->setDefaultZIndex(45.0f); mGamelistInfoComponents.back()->applyTheme(theme, "gamelist", element.first, ALL); - if (mGamelistInfoComponents.back()->getThemeOpacity() != 0.0f) - addChild(mGamelistInfoComponents.back().get()); - else - mGamelistInfoComponents.pop_back(); + addChild(mGamelistInfoComponents.back().get()); } - else if (element.second.type == "rating") { + else if (element.second.type == "rating" && + (!(element.second.has("visible") && !element.second.get("visible")))) { mRatingComponents.push_back(std::make_unique()); mRatingComponents.back()->setDefaultZIndex(45.0f); mRatingComponents.back()->applyTheme(theme, "gamelist", element.first, ALL); - if (mRatingComponents.back()->getThemeOpacity() != 0.0f) { - mRatingComponents.back()->setScrollHide(true); - mRatingComponents.back()->setOpacity(mRatingComponents.back()->getOpacity()); - addChild(mRatingComponents.back().get()); - } - else { - mRatingComponents.pop_back(); - } + mRatingComponents.back()->setScrollHide(true); + mRatingComponents.back()->setOpacity(mRatingComponents.back()->getOpacity()); + addChild(mRatingComponents.back().get()); } } diff --git a/es-app/src/views/SystemView.cpp b/es-app/src/views/SystemView.cpp index 056075ce6..c68577ef8 100644 --- a/es-app/src/views/SystemView.cpp +++ b/es-app/src/views/SystemView.cpp @@ -583,9 +583,10 @@ void SystemView::populate() itemText = element.second.get("text"); } } - else if (element.second.type == "image") { - // If this is the first system, then forceload the images to avoid texture - // pop-in. + else if (element.second.type == "image" && + (!(element.second.has("visible") && + !element.second.get("visible")))) { + // If this is the first system then forceload to avoid texture pop-in. if (it == SystemData::sSystemVector.front()) elements.imageComponents.emplace_back( std::make_unique(true)); @@ -596,24 +597,22 @@ void SystemView::populate() elements.imageComponents.back()->setDefaultZIndex(30.0f); elements.imageComponents.back()->applyTheme(theme, "system", element.first, ThemeFlags::ALL); - if (elements.imageComponents.back()->getThemeOpacity() != 0.0f) - elements.children.emplace_back(elements.imageComponents.back().get()); - else - elements.imageComponents.pop_back(); + elements.children.emplace_back(elements.imageComponents.back().get()); } - else if (element.second.type == "video") { + else if (element.second.type == "video" && + (!(element.second.has("visible") && + !element.second.get("visible")))) { elements.videoComponents.emplace_back( std::make_unique()); elements.videoComponents.back()->setDefaultZIndex(30.0f); elements.videoComponents.back()->setStaticVideo(); elements.videoComponents.back()->applyTheme(theme, "system", element.first, ThemeFlags::ALL); - if (elements.videoComponents.back()->getThemeOpacity() != 0.0f) - elements.children.emplace_back(elements.videoComponents.back().get()); - else - elements.videoComponents.pop_back(); + elements.children.emplace_back(elements.videoComponents.back().get()); } - else if (element.second.type == "animation" && element.second.has("path")) { + else if (element.second.type == "animation" && element.second.has("path") && + (!(element.second.has("visible") && + !element.second.get("visible")))) { const std::string extension {Utils::FileSystem::getExtension( element.second.get("path"))}; if (extension == ".json") { @@ -622,11 +621,8 @@ void SystemView::populate() elements.lottieAnimComponents.back()->setDefaultZIndex(35.0f); elements.lottieAnimComponents.back()->applyTheme( theme, "system", element.first, ThemeFlags::ALL); - if (elements.lottieAnimComponents.back()->getThemeOpacity() != 0.0f) - elements.children.emplace_back( - elements.lottieAnimComponents.back().get()); - else - elements.lottieAnimComponents.pop_back(); + elements.children.emplace_back( + elements.lottieAnimComponents.back().get()); } else if (extension == ".gif") { elements.GIFAnimComponents.emplace_back( @@ -634,11 +630,7 @@ void SystemView::populate() elements.GIFAnimComponents.back()->setDefaultZIndex(35.0f); elements.GIFAnimComponents.back()->applyTheme( theme, "system", element.first, ThemeFlags::ALL); - if (elements.GIFAnimComponents.back()->getThemeOpacity() != 0.0f) - elements.children.emplace_back( - elements.GIFAnimComponents.back().get()); - else - elements.GIFAnimComponents.pop_back(); + elements.children.emplace_back(elements.GIFAnimComponents.back().get()); } else if (extension == ".") { LOG(LogWarning) @@ -652,7 +644,9 @@ void SystemView::populate() << extension << "\""; } } - else if (element.second.type == "text") { + else if (element.second.type == "text" && + (!(element.second.has("visible") && + !element.second.get("visible")))) { if (element.second.has("systemdata") && element.second.get("systemdata").substr(0, 9) == "gamecount") { @@ -662,11 +656,8 @@ void SystemView::populate() elements.gameCountComponents.back()->setDefaultZIndex(40.0f); elements.gameCountComponents.back()->applyTheme( theme, "system", element.first, ThemeFlags::ALL); - if (elements.gameCountComponents.back()->getThemeOpacity() != 0.0f) - elements.children.emplace_back( - elements.gameCountComponents.back().get()); - else - elements.gameCountComponents.pop_back(); + elements.children.emplace_back( + elements.gameCountComponents.back().get()); } } else { @@ -674,42 +665,31 @@ void SystemView::populate() elements.textComponents.back()->setDefaultZIndex(40.0f); elements.textComponents.back()->applyTheme( theme, "system", element.first, ThemeFlags::ALL); - if (elements.textComponents.back()->getThemeOpacity() != 0.0f) - elements.children.emplace_back( - elements.textComponents.back().get()); - else - elements.textComponents.pop_back(); + elements.children.emplace_back(elements.textComponents.back().get()); } } - else if (element.second.type == "datetime") { + else if (element.second.type == "datetime" && + (!(element.second.has("visible") && + !element.second.get("visible")))) { elements.dateTimeComponents.emplace_back( std::make_unique()); elements.dateTimeComponents.back()->setDefaultZIndex(40.0f); elements.dateTimeComponents.back()->applyTheme( theme, "system", element.first, ThemeFlags::ALL); - if (elements.dateTimeComponents.back()->getThemeOpacity() != 0.0f) { - elements.dateTimeComponents.back()->setVisible(false); - elements.children.emplace_back( - elements.dateTimeComponents.back().get()); - } - else { - elements.dateTimeComponents.pop_back(); - } + elements.dateTimeComponents.back()->setVisible(false); + elements.children.emplace_back(elements.dateTimeComponents.back().get()); } - else if (element.second.type == "rating") { + else if (element.second.type == "rating" && + (!(element.second.has("visible") && + !element.second.get("visible")))) { elements.ratingComponents.emplace_back(std::make_unique()); elements.ratingComponents.back()->setDefaultZIndex(45.0f); elements.ratingComponents.back()->applyTheme(theme, "system", element.first, ThemeFlags::ALL); - if (elements.ratingComponents.back()->getThemeOpacity() != 0.0f) { - elements.ratingComponents.back()->setVisible(false); - elements.ratingComponents.back()->setOpacity( - elements.ratingComponents.back()->getOpacity()); - elements.children.emplace_back(elements.ratingComponents.back().get()); - } - else { - elements.ratingComponents.pop_back(); - } + elements.ratingComponents.back()->setVisible(false); + elements.ratingComponents.back()->setOpacity( + elements.ratingComponents.back()->getOpacity()); + elements.children.emplace_back(elements.ratingComponents.back().get()); } } }