From c537de51ef953f6307cd3ecbcb1addb35e70077f Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Wed, 7 Sep 2022 19:59:27 +0200 Subject: [PATCH] Some general code cleanup. --- es-app/src/scrapers/GamesDBJSONScraper.cpp | 26 ++++++------- .../scrapers/GamesDBJSONScraperResources.cpp | 11 +++--- es-core/src/GuiComponent.cpp | 8 ++-- es-core/src/HttpReq.cpp | 8 ++-- es-core/src/ThemeData.h | 38 +++++++++---------- es-core/src/components/FlexboxComponent.cpp | 2 +- .../src/components/LottieAnimComponent.cpp | 10 ++--- es-core/src/renderers/Renderer.h | 10 ++--- 8 files changed, 56 insertions(+), 57 deletions(-) diff --git a/es-app/src/scrapers/GamesDBJSONScraper.cpp b/es-app/src/scrapers/GamesDBJSONScraper.cpp index 1d043303a..6ae7c1b40 100644 --- a/es-app/src/scrapers/GamesDBJSONScraper.cpp +++ b/es-app/src/scrapers/GamesDBJSONScraper.cpp @@ -208,7 +208,7 @@ void thegamesdb_generate_json_scraper_requests( std::string platformQueryParam; auto& platforms = params.system->getPlatformIds(); if (!platforms.empty()) { - bool first = true; + bool first {true}; platformQueryParam += "&filter%5Bplatform%5D="; for (auto platformIt = platforms.cbegin(); // Line break. platformIt != platforms.cend(); ++platformIt) { @@ -243,7 +243,7 @@ void thegamesdb_generate_json_scraper_requests( { resources.prepare(); std::string path = "https://api.thegamesdb.net/v1"; - const std::string apiKey = std::string("apikey=") + resources.getApiKey(); + const std::string apiKey {std::string("apikey=") + resources.getApiKey()}; path += "/Games/Images/GamesImages?" + apiKey + "&games_id=" + gameIDs; @@ -285,7 +285,7 @@ namespace return ""; std::string out = ""; - bool first = true; + bool first {true}; for (int i = 0; i < static_cast(v.Size()); ++i) { auto mapIt = resources.gamesdb_new_developers_map.find(getIntOrThrow(v[i])); @@ -306,8 +306,8 @@ namespace if (!v.IsArray()) return ""; - std::string out = ""; - bool first = true; + std::string out; + bool first {true}; for (int i = 0; i < static_cast(v.Size()); ++i) { auto mapIt = resources.gamesdb_new_publishers_map.find(getIntOrThrow(v[i])); @@ -328,8 +328,8 @@ namespace if (!v.IsArray()) return ""; - std::string out = ""; - bool first = true; + std::string out; + bool first {true}; for (int i = 0; i < static_cast(v.Size()); ++i) { auto mapIt = resources.gamesdb_new_genres_map.find(getIntOrThrow(v[i])); @@ -416,7 +416,7 @@ void processMediaURLs(const Value& images, // Step through each game ID in the JSON server response. for (auto it = images.MemberBegin(); it != images.MemberEnd(); ++it) { result.gameID = it->name.GetString(); - const Value& gameMedia = images[it->name]; + const Value& gameMedia {images[it->name]}; result.coverUrl = ""; result.fanartUrl = ""; result.marqueeUrl = ""; @@ -469,8 +469,8 @@ void TheGamesDBJSONRequest::process(const std::unique_ptr& req, doc.Parse(req->getContent().c_str()); if (doc.HasParseError()) { - std::string err = std::string("TheGamesDBJSONRequest - Error parsing JSON \n\t") + - GetParseError_En(doc.GetParseError()); + std::string err {std::string("TheGamesDBJSONRequest - Error parsing JSON \n\t") + + GetParseError_En(doc.GetParseError())}; setError(err); LOG(LogError) << err; return; @@ -480,8 +480,8 @@ void TheGamesDBJSONRequest::process(const std::unique_ptr& req, if (doc.HasMember("data") && doc["data"].HasMember("images") && doc["data"]["images"].IsObject()) { - const Value& images = doc["data"]["images"]; - const Value& base_url = doc["data"]["base_url"]; + const Value& images {doc["data"]["images"]}; + const Value& base_url {doc["data"]["base_url"]}; std::string baseImageUrlLarge; if (base_url.HasMember("large") && base_url["large"].IsString()) { @@ -520,7 +520,7 @@ void TheGamesDBJSONRequest::process(const std::unique_ptr& req, return; } - const Value& games = doc["data"]["games"]; + const Value& games {doc["data"]["games"]}; resources.ensureResources(); for (int i = 0; i < static_cast(games.Size()); ++i) { diff --git a/es-app/src/scrapers/GamesDBJSONScraperResources.cpp b/es-app/src/scrapers/GamesDBJSONScraperResources.cpp index 342c407fa..731012573 100644 --- a/es-app/src/scrapers/GamesDBJSONScraperResources.cpp +++ b/es-app/src/scrapers/GamesDBJSONScraperResources.cpp @@ -55,7 +55,7 @@ namespace void ensureScrapersResourcesDir() { - std::string path = getScrapersResouceDir(); + std::string path {getScrapersResouceDir()}; if (!Utils::FileSystem::exists(path)) Utils::FileSystem::createDirectory(path); } @@ -146,7 +146,7 @@ bool TheGamesDBJSONRequestResources::saveResource(HttpReq* req, ensureScrapersResourcesDir(); - std::ofstream fout(file_name); + std::ofstream fout {file_name}; fout << req->getContent(); fout.close(); loadResource(resource, resource_name, file_name); @@ -155,9 +155,8 @@ bool TheGamesDBJSONRequestResources::saveResource(HttpReq* req, std::unique_ptr TheGamesDBJSONRequestResources::fetchResource(const std::string& endpoint) { - std::string path = "https://api.thegamesdb.net/v1"; - path += endpoint; - path += "?apikey=" + getApiKey(); + std::string path {"https://api.thegamesdb.net/v1"}; + path.append(endpoint).append("?apikey=").append(getApiKey()); return std::unique_ptr(new HttpReq(path)); } @@ -166,7 +165,7 @@ int TheGamesDBJSONRequestResources::loadResource(std::unordered_map::iterator it = - std::find(getParent()->mChildren.begin(), getParent()->mChildren.end(), this); + std::vector::iterator it { + std::find(getParent()->mChildren.begin(), getParent()->mChildren.end(), this)}; if (it != getParent()->mChildren.end()) return static_cast(std::distance(getParent()->mChildren.begin(), it)); @@ -250,7 +250,7 @@ void GuiComponent::setAnimation(Animation* anim, { assert(slot < MAX_ANIMATIONS); - AnimationController* oldAnim = mAnimationMap[slot]; + AnimationController* oldAnim {mAnimationMap[slot]}; mAnimationMap[slot] = new AnimationController(anim, delay, finishedCallback, reverse); if (oldAnim) @@ -340,7 +340,7 @@ void GuiComponent::applyTheme(const std::shared_ptr& theme, getParent()->getSize() : glm::vec2 {Renderer::getScreenWidth(), Renderer::getScreenHeight()}}; - const ThemeData::ThemeElement* elem = theme->getElement(view, element, ""); + const ThemeData::ThemeElement* elem {theme->getElement(view, element, "")}; if (!elem) return; diff --git a/es-core/src/HttpReq.cpp b/es-core/src/HttpReq.cpp index a991301f9..5b517f707 100644 --- a/es-core/src/HttpReq.cpp +++ b/es-core/src/HttpReq.cpp @@ -82,7 +82,7 @@ HttpReq::HttpReq(const std::string& url) } // Set the url. - CURLcode err = curl_easy_setopt(mHandle, CURLOPT_URL, url.c_str()); + CURLcode err {curl_easy_setopt(mHandle, CURLOPT_URL, url.c_str())}; if (err != CURLE_OK) { mStatus = REQ_IO_ERROR; onError(curl_easy_strerror(err)); @@ -176,7 +176,7 @@ HttpReq::~HttpReq() if (mHandle) { s_requests.erase(mHandle); - CURLMcode merr = curl_multi_remove_handle(s_multi_handle, mHandle); + CURLMcode merr {curl_multi_remove_handle(s_multi_handle, mHandle)}; if (merr != CURLM_OK) { LOG(LogError) << "Error removing curl_easy handle from curl_multi: " @@ -191,7 +191,7 @@ HttpReq::Status HttpReq::status() { if (mStatus == REQ_IN_PROGRESS) { int handle_count; - CURLMcode merr = curl_multi_perform(s_multi_handle, &handle_count); + CURLMcode merr {curl_multi_perform(s_multi_handle, &handle_count)}; if (merr != CURLM_OK && merr != CURLM_CALL_MULTI_PERFORM) { mStatus = REQ_IO_ERROR; onError(curl_multi_strerror(merr)); @@ -238,7 +238,7 @@ std::string HttpReq::getContent() const // Return value is number of elements successfully read. size_t HttpReq::write_content(void* buff, size_t size, size_t nmemb, void* req_ptr) { - std::stringstream& ss = (static_cast(req_ptr))->mContent; + std::stringstream& ss {static_cast(req_ptr)->mContent}; ss.write(static_cast(buff), size * nmemb); return nmemb; diff --git a/es-core/src/ThemeData.h b/es-core/src/ThemeData.h index b7ca5ab2e..70af8d3b6 100644 --- a/es-core/src/ThemeData.h +++ b/es-core/src/ThemeData.h @@ -41,26 +41,26 @@ namespace ThemeFlags // These are only the most common flags shared accross multiple components, in addition // to these there are many component-specific options. enum PropertyFlags : unsigned int { - PATH = 0x00000001, - POSITION = 0x00000002, - SIZE = 0x00000004, - ORIGIN = 0x00000008, - COLOR = 0x00000010, - FONT_PATH = 0x00000020, - FONT_SIZE = 0x00000040, - ALIGNMENT = 0x00000080, - TEXT = 0x00000100, - METADATA = 0x00000200, - LETTER_CASE = 0x00000400, + PATH = 0x00000001, + POSITION = 0x00000002, + SIZE = 0x00000004, + ORIGIN = 0x00000008, + COLOR = 0x00000010, + FONT_PATH = 0x00000020, + FONT_SIZE = 0x00000040, + ALIGNMENT = 0x00000080, + TEXT = 0x00000100, + METADATA = 0x00000200, + LETTER_CASE = 0x00000400, FORCE_UPPERCASE = 0x00000800, // For backward compatibility with legacy themes. - LINE_SPACING = 0x00001000, - DELAY = 0x00002000, - Z_INDEX = 0x00004000, - ROTATION = 0x00008000, - OPACITY = 0x00010000, - SATURATION = 0x00020000, - VISIBLE = 0x00040000, - ALL = 0xFFFFFFFF + LINE_SPACING = 0x00001000, + DELAY = 0x00002000, + Z_INDEX = 0x00004000, + ROTATION = 0x00008000, + OPACITY = 0x00010000, + SATURATION = 0x00020000, + VISIBLE = 0x00040000, + ALL = 0xFFFFFFFF }; // clang-format on } // namespace ThemeFlags diff --git a/es-core/src/components/FlexboxComponent.cpp b/es-core/src/components/FlexboxComponent.cpp index eba4a9f3f..c27657825 100644 --- a/es-core/src/components/FlexboxComponent.cpp +++ b/es-core/src/components/FlexboxComponent.cpp @@ -101,7 +101,7 @@ void FlexboxComponent::computeLayout() mItemsPerLine = static_cast(mItems.size()); } - glm::vec2 grid {}; + glm::vec2 grid {0.0f, 0.0f}; if (mDirection == "row") grid = {mItemsPerLine, mLines}; diff --git a/es-core/src/components/LottieAnimComponent.cpp b/es-core/src/components/LottieAnimComponent.cpp index 6ab191c71..76b396763 100644 --- a/es-core/src/components/LottieAnimComponent.cpp +++ b/es-core/src/components/LottieAnimComponent.cpp @@ -46,8 +46,8 @@ LottieAnimComponent::LottieAnimComponent() glm::clamp(Settings::getInstance()->getInt("LottieMaxFileCache"), 0, 1024) * 1024 * 1024); // Keep total cache size within 0 to 4096 MiB. - int maxTotalCache = - glm::clamp(Settings::getInstance()->getInt("LottieMaxTotalCache"), 0, 4096) * 1024 * 1024; + int maxTotalCache {glm::clamp(Settings::getInstance()->getInt("LottieMaxTotalCache"), 0, 4096) * + 1024 * 1024}; if (mMaxTotalFrameCache != static_cast(maxTotalCache)) mMaxTotalFrameCache = static_cast(maxTotalCache); @@ -161,7 +161,7 @@ void LottieAnimComponent::setAnimation(const std::string& path) } // Some statistics for the file. - double duration = mAnimation->duration(); + double duration {mAnimation->duration()}; mTotalFrames = mAnimation->totalFrame(); mFrameRate = mAnimation->frameRate(); mFrameSize = width * height * 4; @@ -229,7 +229,7 @@ void LottieAnimComponent::applyTheme(const std::shared_ptr& theme, const ThemeData::ThemeElement* elem {theme->getElement(view, element, "animation")}; if (elem->has("size")) { - glm::vec2 size = elem->get("size"); + glm::vec2 size {elem->get("size")}; if (size.x == 0.0f && size.y == 0.0f) { LOG(LogWarning) << "LottieAnimComponent: Invalid theme configuration, defined as \"" @@ -411,7 +411,7 @@ void LottieAnimComponent::render(const glm::mat4& parentTrans) // to the texture caching used for images. if (mCacheFrames && mLastRenderedFrame != -1 && mFrameCache.find(mLastRenderedFrame) == mFrameCache.end()) { - size_t newCacheSize = mCacheSize + mFrameSize; + size_t newCacheSize {mCacheSize + mFrameSize}; if (newCacheSize < mMaxCacheSize && mTotalFrameCache + mFrameSize < mMaxTotalFrameCache) { mFrameCache[mLastRenderedFrame] = mPictureRGBA; diff --git a/es-core/src/renderers/Renderer.h b/es-core/src/renderers/Renderer.h index 65fb533df..cc763a43c 100644 --- a/es-core/src/renderers/Renderer.h +++ b/es-core/src/renderers/Renderer.h @@ -42,15 +42,15 @@ public: // clang-format off enum Shader { - CORE = 0x00000001, + CORE = 0x00000001, BLUR_HORIZONTAL = 0x00000002, - BLUR_VERTICAL = 0x00000004, - SCANLINES = 0x00000008 + BLUR_VERTICAL = 0x00000004, + SCANLINES = 0x00000008 }; enum ShaderFlags { - BGRA_TO_RGBA = 0x00000001, - FONT_TEXTURE = 0x00000002, + BGRA_TO_RGBA = 0x00000001, + FONT_TEXTURE = 0x00000002, POST_PROCESSING = 0x00000004, CLIPPING = 0x00000008 };