diff --git a/es-app/src/ApiSystem.cpp b/es-app/src/ApiSystem.cpp index 6c9c8dd743..f48559c641 100644 --- a/es-app/src/ApiSystem.cpp +++ b/es-app/src/ApiSystem.cpp @@ -1802,8 +1802,6 @@ std::vector ApiSystem::extractPdfImages(const std::string& fileName int hardWareCoreCount = std::thread::hardware_concurrency(); if (hardWareCoreCount > 1) { - int lastTime = SDL_GetTicks(); - int numberOfPagesToProcess = 1; if (hardWareCoreCount < 8) numberOfPagesToProcess = 2; @@ -1818,9 +1816,6 @@ std::vector ApiSystem::extractPdfImages(const std::string& fileName pool.wait(); - int time = SDL_GetTicks() - lastTime; - std::string timeText = std::to_string(time) + "ms"; - for (auto file : Utils::FileSystem::getDirContent(pdfFolder, false)) { auto ext = Utils::String::toLower(Utils::FileSystem::getExtension(file)); @@ -1837,8 +1832,6 @@ std::vector ApiSystem::extractPdfImages(const std::string& fileName } } - int lastTime = SDL_GetTicks(); - std::string page; std::string squality = Renderer::isSmallScreen() ? "96" : "125"; @@ -1865,9 +1858,6 @@ std::vector ApiSystem::extractPdfImages(const std::string& fileName executeEnumerationScript("pdftoppm -jpeg -r "+ squality +" -cropbox" + page + " \"" + fileName + "\" \"" + pdfFolder + "/" + prefix + "\""); #endif - int time = SDL_GetTicks() - lastTime; - std::string text = std::to_string(time); - for (auto file : Utils::FileSystem::getDirContent(pdfFolder, false)) { auto ext = Utils::String::toLower(Utils::FileSystem::getExtension(file)); @@ -1884,7 +1874,6 @@ std::vector ApiSystem::extractPdfImages(const std::string& fileName return ret; } - std::vector ApiSystem::getBatoceraStorePackages() { std::vector packages; diff --git a/es-app/src/main.cpp b/es-app/src/main.cpp index 98418f8b9e..4ad43fbc63 100644 --- a/es-app/src/main.cpp +++ b/es-app/src/main.cpp @@ -382,7 +382,7 @@ void playVideo() vid.onShow(); vid.topWindow(true); - int lastTime = SDL_GetTicks(); + auto lastTime = std::chrono::steady_clock::now(); int totalTime = 0; while (!exitLoop) @@ -399,19 +399,16 @@ void playVideo() while (SDL_PollEvent(&event)); } - int curTime = SDL_GetTicks(); - int deltaTime = curTime - lastTime; + auto deltaTime = std::chrono::duration_cast(std::chrono::steady_clock::now() - lastTime); if (vid.isPlaying()) { - totalTime += deltaTime; - - if (gPlayVideoDuration > 0 && totalTime > gPlayVideoDuration * 100) + if (gPlayVideoDuration > 0 && deltaTime.count() > gPlayVideoDuration * 100) break; } Transform4x4f transform = Transform4x4f::Identity(); - vid.update(deltaTime); + vid.update(deltaTime.count()); vid.render(transform); Renderer::swapBuffers(); @@ -649,20 +646,23 @@ int main(int argc, char* argv[]) timeLimit = 0; #endif - int lastTime = SDL_GetTicks(); - int ps_time = SDL_GetTicks(); + auto lastTime = std::chrono::steady_clock::now(); + auto ps_time = lastTime; bool running = true; while(running) { #ifdef WIN32 - int processStart = SDL_GetTicks(); + auto processStart = std::chrono::steady_clock::now(); #endif SDL_Event event; - bool ps_standby = PowerSaver::getState() && (int) SDL_GetTicks() - ps_time > PowerSaver::getMode(); + auto now = std::chrono::steady_clock::now(); + auto delta = std::chrono::duration_cast(now - ps_time); + + bool ps_standby = PowerSaver::getState() && (int) delta.count() > PowerSaver::getMode(); if(ps_standby ? SDL_WaitEventTimeout(&event, PowerSaver::getTimeout()) : SDL_PollEvent(&event)) { // PowerSaver can push events to exit SDL_WaitEventTimeout immediatly @@ -684,10 +684,10 @@ int main(int argc, char* argv[]) // triggered if exiting from SDL_WaitEvent due to event if (ps_standby) // show as if continuing from last event - lastTime = SDL_GetTicks(); + lastTime = std::chrono::steady_clock::now(); // reset counter - ps_time = SDL_GetTicks(); + ps_time = std::chrono::steady_clock::now(); } else if (ps_standby == false) { @@ -696,18 +696,19 @@ int main(int argc, char* argv[]) // If exitting SDL_WaitEventTimeout due to timeout. Trail considering // timeout as an event - // ps_time = SDL_GetTicks(); + // ps_time = std::chrono::steady_clock::now(); } if (window.isSleeping()) { - lastTime = SDL_GetTicks(); + lastTime = std::chrono::steady_clock::now(); SDL_Delay(1); // this doesn't need to be accurate, we're just giving up our CPU time until something wakes us up continue; } - int curTime = SDL_GetTicks(); - int deltaTime = curTime - lastTime; + auto curTime = std::chrono::steady_clock::now(); + int deltaTime = std::chrono::duration_cast(curTime - lastTime).count(); + lastTime = curTime; // cap deltaTime if it ever goes negative diff --git a/es-app/src/scrapers/Scraper.cpp b/es-app/src/scrapers/Scraper.cpp index 755fcbc32b..44c61e8c8c 100644 --- a/es-app/src/scrapers/Scraper.cpp +++ b/es-app/src/scrapers/Scraper.cpp @@ -264,7 +264,7 @@ ScraperHttpRequest::ScraperHttpRequest(std::vector& results mRequest = new HttpReq(url, &mOptions); mRetryCount = 0; - mOverQuotaPendingTime = 0; + mOverQuotaPending = false; mOverQuotaRetryDelay = OVERQUOTA_RETRY_DELAY; mOverQuotaRetryCount = OVERQUOTA_RETRY_COUNT; } @@ -276,12 +276,12 @@ ScraperHttpRequest::~ScraperHttpRequest() void ScraperHttpRequest::update() { - if (mOverQuotaPendingTime > 0) + if (mOverQuotaPending) { - int lastTime = SDL_GetTicks(); - if (lastTime - mOverQuotaPendingTime > mOverQuotaRetryDelay) + auto lastTime = std::chrono::steady_clock::now(); + if (std::chrono::duration_cast(lastTime - mOverQuotaPendingTime).count() > mOverQuotaRetryDelay) { - mOverQuotaPendingTime = 0; + mOverQuotaPending = false; LOG(LogDebug) << "REQ_429_TOOMANYREQUESTS : Retrying"; @@ -331,7 +331,8 @@ void ScraperHttpRequest::update() setStatus(ASYNC_IN_PROGRESS); - mOverQuotaPendingTime = SDL_GetTicks(); + mOverQuotaPendingTime = std::chrono::steady_clock::now(); + mOverQuotaPending = true; LOG(LogDebug) << "REQ_429_TOOMANYREQUESTS : Retrying in " << mOverQuotaRetryDelay << " seconds"; return; } @@ -500,7 +501,7 @@ ImageDownloadHandle::ImageDownloadHandle(const std::string& url, const std::stri mSavePath(path), mMaxWidth(maxWidth), mMaxHeight(maxHeight) { mRetryCount = 0; - mOverQuotaPendingTime = 0; + mOverQuotaPending = false; mOverQuotaRetryDelay = OVERQUOTA_RETRY_DELAY; mOverQuotaRetryCount = OVERQUOTA_RETRY_COUNT; @@ -550,12 +551,13 @@ int ImageDownloadHandle::getPercent() void ImageDownloadHandle::update() { - if (mOverQuotaPendingTime > 0) + if (mOverQuotaPending) { - int lastTime = SDL_GetTicks(); - if (lastTime - mOverQuotaPendingTime > mOverQuotaRetryDelay) + auto lastTime = std::chrono::steady_clock::now(); + + if (std::chrono::duration_cast(lastTime - mOverQuotaPendingTime).count() > mOverQuotaRetryDelay) { - mOverQuotaPendingTime = 0; + mOverQuotaPending = false; LOG(LogDebug) << "REQ_429_TOOMANYREQUESTS : Retrying"; @@ -590,7 +592,8 @@ void ImageDownloadHandle::update() mOverQuotaRetryDelay = Utils::String::toInteger(retryDelay) * 1000; } - mOverQuotaPendingTime = SDL_GetTicks(); + mOverQuotaPendingTime = std::chrono::steady_clock::now(); + mOverQuotaPending = true; LOG(LogDebug) << "REQ_429_TOOMANYREQUESTS : Retrying in " << mOverQuotaRetryDelay << " seconds"; return; } diff --git a/es-app/src/scrapers/Scraper.h b/es-app/src/scrapers/Scraper.h index 14694b5764..a249654077 100644 --- a/es-app/src/scrapers/Scraper.h +++ b/es-app/src/scrapers/Scraper.h @@ -10,6 +10,7 @@ #include #include #include +#include #include #include "FileData.h" @@ -101,7 +102,8 @@ class ScraperHttpRequest : public ScraperRequest HttpReqOptions mOptions; int mRetryCount; - int mOverQuotaPendingTime; + std::chrono::steady_clock::time_point mOverQuotaPendingTime; + bool mOverQuotaPending = false; int mOverQuotaRetryDelay; int mOverQuotaRetryCount; }; @@ -141,13 +143,14 @@ class ImageDownloadHandle : public AsyncHandle HttpReq* mRequest; int mRetryCount; - int mOverQuotaPendingTime; + std::chrono::steady_clock::time_point mOverQuotaPendingTime; int mOverQuotaRetryDelay; int mOverQuotaRetryCount; std::string mSavePath; int mMaxWidth; int mMaxHeight; + bool mOverQuotaPending=false; }; diff --git a/es-app/src/views/ViewController.cpp b/es-app/src/views/ViewController.cpp index 0a14af5617..8157a8b162 100644 --- a/es-app/src/views/ViewController.cpp +++ b/es-app/src/views/ViewController.cpp @@ -1195,7 +1195,7 @@ void ViewController::reloadAll(Window* window, bool reloadTheme) if (gameListCount > 0) { - int lastTime = SDL_GetTicks() - 50; + auto lastTime = std::chrono::system_clock::now() - std::chrono::milliseconds(50); if (window) window->renderSplashScreen(_("Loading gamelists"), 0.0f); @@ -1217,10 +1217,11 @@ void ViewController::reloadAll(Window* window, bool reloadTheme) idx++; - int time = SDL_GetTicks(); - if (window && time - lastTime >= 20) + auto now = std::chrono::system_clock::now(); + + if (window && std::chrono::duration_cast(now - lastTime).count() >= 20) { - lastTime = time; + lastTime = now; window->renderSplashScreen(_("Loading gamelists"), (float)idx / (float)gameListCount); } } diff --git a/es-core/src/SystemConf.cpp b/es-core/src/SystemConf.cpp index 54b8249c7a..9057007543 100644 --- a/es-core/src/SystemConf.cpp +++ b/es-core/src/SystemConf.cpp @@ -1,6 +1,7 @@ #include "SystemConf.h" #include #include +#include #include "Log.h" #include "utils/StringUtil.h" #include "utils/FileSystemUtil.h" @@ -132,7 +133,7 @@ bool SystemConf::saveSystemConf() static std::string removeID = "$^�(p$^mpv$�rpver$^vper$vper$^vper$vper$vper$^vperv^pervncvizn"; - int lastTime = SDL_GetTicks(); + auto lastTime = std::chrono::steady_clock::now(); /* Save new value if exists */ for (auto& it : changedConf) @@ -181,9 +182,7 @@ bool SystemConf::saveSystemConf() } } - lastTime = SDL_GetTicks() - lastTime; - - LOG(LogDebug) << "saveSystemConf : " << lastTime; + LOG(LogDebug) << "saveSystemConf : " << std::chrono::duration_cast(std::chrono::steady_clock::now() - lastTime).count(); std::ofstream fileout(mSystemConfFileTmp); //Temporary file if (!fileout) diff --git a/es-core/src/components/VideoComponent.cpp b/es-core/src/components/VideoComponent.cpp index c67b492c54..7e65046575 100644 --- a/es-core/src/components/VideoComponent.cpp +++ b/es-core/src/components/VideoComponent.cpp @@ -358,7 +358,7 @@ void VideoComponent::handleStartDelay() return; // Timeout not yet completed - if (mStartTime > SDL_GetTicks()) + if (mStartTime > std::chrono::steady_clock::now()) return; // Completed @@ -421,7 +421,7 @@ void VideoComponent::startVideoWithDelay() // Configure the start delay mStartDelayed = true; mFadeIn = 0.0f; - mStartTime = SDL_GetTicks() + mConfig.startDelay; + mStartTime = std::chrono::steady_clock::now() + std::chrono::milliseconds(mConfig.startDelay); } } @@ -436,10 +436,10 @@ void VideoComponent::update(int deltaTime) if (mStartDelayed) { - Uint32 ticks = SDL_GetTicks(); - if (mStartTime > ticks) + auto now = std::chrono::steady_clock::now(); + if (mStartTime > now) { - Uint32 diff = mStartTime - ticks; + Uint32 diff = std::chrono::duration_cast(mStartTime - now).count(); if (diff < FADE_TIME_MS) { mFadeIn = (float)diff / (float)FADE_TIME_MS; diff --git a/es-core/src/components/VideoComponent.h b/es-core/src/components/VideoComponent.h index 1b5d8f545c..64fe303c5c 100644 --- a/es-core/src/components/VideoComponent.h +++ b/es-core/src/components/VideoComponent.h @@ -1,7 +1,7 @@ #pragma once #ifndef ES_CORE_COMPONENTS_VIDEO_COMPONENT_H #define ES_CORE_COMPONENTS_VIDEO_COMPONENT_H - +#include #include "components/ImageComponent.h" #include "components/ImageGridComponent.h" #include "GuiComponent.h" @@ -193,36 +193,36 @@ class VideoComponent : public GuiComponent void manageState(); protected: - unsigned mVideoWidth; - unsigned mVideoHeight; - Vector2f mTargetSize; - std::shared_ptr mTexture; - float mFadeIn; - std::string mStaticImagePath; - ImageComponent mStaticImage; - bool mPlayAudio; + unsigned mVideoWidth; + unsigned mVideoHeight; + Vector2f mTargetSize; + std::shared_ptr mTexture; + float mFadeIn; + std::string mStaticImagePath; + ImageComponent mStaticImage; + bool mPlayAudio; - std::string mVideoPath; - std::string mPlayingVideoPath; + std::string mVideoPath; + std::string mPlayingVideoPath; - std::string mThemedPath; + std::string mThemedPath; - bool mStartDelayed; - unsigned mStartTime; - bool mIsPlaying; - bool mScreensaverActive; - bool mScreensaverMode; - bool mTargetIsMax; - bool mTargetIsMin; + bool mStartDelayed; + std::chrono::steady_clock::time_point mStartTime; + bool mIsPlaying; + bool mScreensaverActive; + bool mScreensaverMode; + bool mTargetIsMax; + bool mTargetIsMin; - bool mIsWaitingForVideoToStart; + bool mIsWaitingForVideoToStart; - bool mIsTopWindow; - bool mEnabled; + bool mIsTopWindow; + bool mEnabled; - float mRoundCorners; + float mRoundCorners; - Configuration mConfig; + Configuration mConfig; }; #endif // ES_CORE_COMPONENTS_VIDEO_COMPONENT_H diff --git a/es-core/src/guis/GuiInfoPopup.cpp b/es-core/src/guis/GuiInfoPopup.cpp index 6f0ba2db75..131f8b976e 100644 --- a/es-core/src/guis/GuiInfoPopup.cpp +++ b/es-core/src/guis/GuiInfoPopup.cpp @@ -58,7 +58,7 @@ GuiInfoPopup::GuiInfoPopup(Window* window, std::string message, int duration) : addChild(mFrame); // we only init the actual time when we first start to render - mStartTime = 0; + mStarted = false; mGrid = new ComponentGrid(window, Vector2i(1, 3)); mGrid->setSize(mSize); @@ -82,12 +82,15 @@ void GuiInfoPopup::update(int deltaTime) { GuiComponent::update(deltaTime); - int curTime = SDL_GetTicks(); + auto curTime = std::chrono::steady_clock::now(); // we only init the actual time when we first start to render - if (mStartTime == 0) + if (!mStarted) + { mStartTime = curTime; - else if (curTime - mStartTime > mDuration || curTime < mStartTime) + mStarted = true; + } + else if (std::chrono::duration_cast(curTime - mStartTime).count() > mDuration || curTime < mStartTime) { // If we're past the popup duration, no need to render or if SDL reset : Stop mRunning = false; @@ -100,11 +103,11 @@ void GuiInfoPopup::update(int deltaTime) // compute fade in effect int alpha = 255; - if (curTime - mStartTime <= FADE_DURATION) - alpha = ((curTime - mStartTime) * 255 / FADE_DURATION); - else if (curTime - mStartTime >= mDuration - FADE_DURATION) + if (std::chrono::duration_cast(curTime - mStartTime).count() <= FADE_DURATION) + alpha = ((std::chrono::duration_cast(curTime - mStartTime).count()) * 255 / FADE_DURATION); + else if (std::chrono::duration_cast(curTime - mStartTime).count() >= mDuration - FADE_DURATION) { - alpha = ((-(curTime - mStartTime - mDuration) * 255) / FADE_DURATION); + alpha = ((-(std::chrono::duration_cast(curTime - mStartTime).count() - mDuration) * 255) / FADE_DURATION); mFadeOut = (float) (255 - alpha) / 255.0; } diff --git a/es-core/src/guis/GuiInfoPopup.h b/es-core/src/guis/GuiInfoPopup.h index 0cf00217aa..f4490d0eef 100644 --- a/es-core/src/guis/GuiInfoPopup.h +++ b/es-core/src/guis/GuiInfoPopup.h @@ -1,7 +1,7 @@ #pragma once #ifndef ES_APP_GUIS_GUI_INFO_POPUP_H #define ES_APP_GUIS_GUI_INFO_POPUP_H - +#include #include "GuiComponent.h" #include "Window.h" @@ -22,16 +22,17 @@ class GuiInfoPopup : public GuiComponent std::string getMessage() { return mMessage; } private: - std::string mMessage; + std::string mMessage; - int mStartTime; - int mDuration; - bool mRunning; + bool mStarted=false; + std::chrono::steady_clock::time_point mStartTime; + int mDuration; + bool mRunning; - float mFadeOut; + float mFadeOut; - ComponentGrid* mGrid; - NinePatchComponent* mFrame; + ComponentGrid* mGrid; + NinePatchComponent* mFrame; }; #endif // ES_APP_GUIS_GUI_INFO_POPUP_H