Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugs/sdl gettick reset #7

Draft
wants to merge 11 commits into
base: knulli
Choose a base branch
from
11 changes: 0 additions & 11 deletions es-app/src/ApiSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1802,8 +1802,6 @@ std::vector<std::string> 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;
Expand All @@ -1818,9 +1816,6 @@ std::vector<std::string> 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));
Expand All @@ -1837,8 +1832,6 @@ std::vector<std::string> ApiSystem::extractPdfImages(const std::string& fileName
}
}

int lastTime = SDL_GetTicks();

std::string page;

std::string squality = Renderer::isSmallScreen() ? "96" : "125";
Expand All @@ -1865,9 +1858,6 @@ std::vector<std::string> 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));
Expand All @@ -1884,7 +1874,6 @@ std::vector<std::string> ApiSystem::extractPdfImages(const std::string& fileName
return ret;
}


std::vector<PacmanPackage> ApiSystem::getBatoceraStorePackages()
{
std::vector<PacmanPackage> packages;
Expand Down
35 changes: 18 additions & 17 deletions es-app/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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::milliseconds>(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();
Expand Down Expand Up @@ -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<std::chrono::milliseconds>(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
Expand All @@ -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)
{
Expand All @@ -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<std::chrono::milliseconds>(curTime - lastTime).count();

lastTime = curTime;

// cap deltaTime if it ever goes negative
Expand Down
27 changes: 15 additions & 12 deletions es-app/src/scrapers/Scraper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ ScraperHttpRequest::ScraperHttpRequest(std::vector<ScraperSearchResult>& results

mRequest = new HttpReq(url, &mOptions);
mRetryCount = 0;
mOverQuotaPendingTime = 0;
mOverQuotaPending = false;
mOverQuotaRetryDelay = OVERQUOTA_RETRY_DELAY;
mOverQuotaRetryCount = OVERQUOTA_RETRY_COUNT;
}
Expand All @@ -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<std::chrono::milliseconds>(lastTime - mOverQuotaPendingTime).count() > mOverQuotaRetryDelay)
{
mOverQuotaPendingTime = 0;
mOverQuotaPending = false;

LOG(LogDebug) << "REQ_429_TOOMANYREQUESTS : Retrying";

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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<std::chrono::milliseconds>(lastTime - mOverQuotaPendingTime).count() > mOverQuotaRetryDelay)
{
mOverQuotaPendingTime = 0;
mOverQuotaPending = false;

LOG(LogDebug) << "REQ_429_TOOMANYREQUESTS : Retrying";

Expand Down Expand Up @@ -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;
}
Expand Down
7 changes: 5 additions & 2 deletions es-app/src/scrapers/Scraper.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <queue>
#include <utility>
#include <set>
#include <chrono>
#include <assert.h>
#include "FileData.h"

Expand Down Expand Up @@ -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;
};
Expand Down Expand Up @@ -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;
};


Expand Down
9 changes: 5 additions & 4 deletions es-app/src/views/ViewController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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<std::chrono::milliseconds>(now - lastTime).count() >= 20)
{
lastTime = time;
lastTime = now;
window->renderSplashScreen(_("Loading gamelists"), (float)idx / (float)gameListCount);
}
}
Expand Down
7 changes: 3 additions & 4 deletions es-core/src/SystemConf.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "SystemConf.h"
#include <iostream>
#include <fstream>
#include <chrono>
#include "Log.h"
#include "utils/StringUtil.h"
#include "utils/FileSystemUtil.h"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -181,9 +182,7 @@ bool SystemConf::saveSystemConf()
}
}

lastTime = SDL_GetTicks() - lastTime;

LOG(LogDebug) << "saveSystemConf : " << lastTime;
LOG(LogDebug) << "saveSystemConf : " << std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now() - lastTime).count();

std::ofstream fileout(mSystemConfFileTmp); //Temporary file
if (!fileout)
Expand Down
10 changes: 5 additions & 5 deletions es-core/src/components/VideoComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
}

Expand All @@ -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<std::chrono::milliseconds>(mStartTime - now).count();
if (diff < FADE_TIME_MS)
{
mFadeIn = (float)diff / (float)FADE_TIME_MS;
Expand Down
Loading