2017-02-24 20:26:38 +01:00
|
|
|
#include <cstdio>
|
2020-09-29 13:46:43 +02:00
|
|
|
#include <cstdint>
|
2020-10-05 20:58:33 +02:00
|
|
|
#include <ctime>
|
|
|
|
|
|
|
|
#include "ppsspp_config.h"
|
2017-02-24 20:26:38 +01:00
|
|
|
|
2020-08-15 20:53:08 +02:00
|
|
|
#include "Common/TimeUtil.h"
|
2012-03-24 23:39:19 +01:00
|
|
|
|
2020-10-05 20:58:33 +02:00
|
|
|
#ifdef HAVE_LIBNX
|
|
|
|
#include <switch.h>
|
|
|
|
#endif // HAVE_LIBNX
|
|
|
|
|
2012-03-24 23:39:19 +01:00
|
|
|
#ifdef _WIN32
|
2020-10-05 20:58:33 +02:00
|
|
|
#include "CommonWindows.h"
|
|
|
|
#include <mmsystem.h>
|
|
|
|
#include <sys/timeb.h>
|
2012-03-24 23:39:19 +01:00
|
|
|
#else
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static double curtime = 0;
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
|
2020-09-25 09:33:42 +02:00
|
|
|
static LARGE_INTEGER frequency;
|
|
|
|
static double frequencyMult;
|
|
|
|
static LARGE_INTEGER startTime;
|
2012-03-24 23:39:19 +01:00
|
|
|
|
2020-09-24 23:52:03 +02:00
|
|
|
double time_now_d() {
|
2014-12-29 10:06:19 -08:00
|
|
|
if (frequency.QuadPart == 0) {
|
|
|
|
QueryPerformanceFrequency(&frequency);
|
|
|
|
QueryPerformanceCounter(&startTime);
|
|
|
|
curtime = 0.0;
|
|
|
|
frequencyMult = 1.0 / static_cast<double>(frequency.QuadPart);
|
2012-10-30 13:20:55 +01:00
|
|
|
}
|
2014-12-29 10:06:19 -08:00
|
|
|
LARGE_INTEGER time;
|
|
|
|
QueryPerformanceCounter(&time);
|
|
|
|
double elapsed = static_cast<double>(time.QuadPart - startTime.QuadPart);
|
|
|
|
return elapsed * frequencyMult;
|
2012-03-24 23:39:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
2020-09-25 09:33:42 +02:00
|
|
|
static uint64_t _frequency = 0;
|
|
|
|
static uint64_t _starttime = 0;
|
2013-07-27 00:34:36 +02:00
|
|
|
|
2020-09-24 23:52:03 +02:00
|
|
|
double time_now_d() {
|
2015-04-04 11:27:22 +02:00
|
|
|
static time_t start;
|
|
|
|
struct timeval tv;
|
|
|
|
gettimeofday(&tv, NULL);
|
|
|
|
if (start == 0) {
|
|
|
|
start = tv.tv_sec;
|
|
|
|
}
|
|
|
|
tv.tv_sec -= start;
|
|
|
|
return (double)tv.tv_sec + (double)tv.tv_usec / 1000000.0;
|
2012-03-24 23:39:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void sleep_ms(int ms) {
|
|
|
|
#ifdef _WIN32
|
2012-10-30 13:20:55 +01:00
|
|
|
Sleep(ms);
|
2020-03-15 07:56:38 -07:00
|
|
|
#elif defined(HAVE_LIBNX)
|
|
|
|
svcSleepThread(ms * 1000000);
|
2012-03-24 23:39:19 +01:00
|
|
|
#else
|
2012-10-30 13:20:55 +01:00
|
|
|
usleep(ms * 1000);
|
2012-03-24 23:39:19 +01:00
|
|
|
#endif
|
|
|
|
}
|
2020-10-05 20:58:33 +02:00
|
|
|
|
|
|
|
// Return the current time formatted as Minutes:Seconds:Milliseconds
|
|
|
|
// in the form 00:00:000.
|
|
|
|
void GetTimeFormatted(char formattedTime[13]) {
|
|
|
|
time_t sysTime;
|
|
|
|
struct tm * gmTime;
|
|
|
|
char tmp[13];
|
|
|
|
|
|
|
|
time(&sysTime);
|
|
|
|
gmTime = localtime(&sysTime);
|
|
|
|
|
|
|
|
strftime(tmp, 6, "%M:%S", gmTime);
|
|
|
|
|
|
|
|
// Now tack on the milliseconds
|
|
|
|
#ifdef _WIN32
|
|
|
|
struct timeb tp;
|
|
|
|
(void)::ftime(&tp);
|
|
|
|
snprintf(formattedTime, 13, "%s:%03i", tmp, tp.millitm);
|
|
|
|
#else
|
|
|
|
struct timeval t;
|
|
|
|
(void)gettimeofday(&t, NULL);
|
|
|
|
snprintf(formattedTime, 13, "%s:%03d", tmp, (int)(t.tv_usec / 1000));
|
|
|
|
#endif
|
|
|
|
}
|