From ff42b7d35282309c03297e7b37ae8e964fba31f8 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Thu, 28 Mar 2024 19:03:30 +1100 Subject: [PATCH] Use stopwatch time for measuring ping and launcher caret, change UTC time measurement to seconds instead of milliseconds --- src/EntityRenderers.c | 6 +++--- src/Http_Web.c | 2 +- src/LBackend.c | 6 +++--- src/LScreens.c | 4 ++-- src/Platform.h | 8 ++++---- src/Platform_3DS.c | 5 ++--- src/Platform_Dreamcast.c | 4 ++-- src/Platform_GCWii.c | 7 +++---- src/Platform_N64.c | 5 ++--- src/Platform_NDS.c | 5 ++--- src/Platform_PS1.c | 3 +-- src/Platform_PS2.c | 5 ++--- src/Platform_PS3.c | 7 +++---- src/Platform_PSP.c | 5 ++--- src/Platform_PSVita.c | 5 ++--- src/Platform_Posix.c | 5 ++--- src/Platform_Switch.c | 5 ++--- src/Platform_Web.c | 5 ++--- src/Platform_WiiU.c | 13 +++++-------- src/Platform_Windows.c | 12 ++++++------ src/Platform_Xbox.c | 12 ++++++------ src/Platform_Xbox360.c | 5 ++--- src/SSL.c | 2 +- src/Server.c | 16 +++++++++------- src/Utils.h | 2 +- src/_HttpBase.h | 6 +++--- 26 files changed, 73 insertions(+), 87 deletions(-) diff --git a/src/EntityRenderers.c b/src/EntityRenderers.c index 4a35f8eb2..863ca2c46 100644 --- a/src/EntityRenderers.c +++ b/src/EntityRenderers.c @@ -232,9 +232,9 @@ static void EntityShadows_MakeTexture(void) { BitmapCol* row = Bitmap_GetRow(&bmp, y); for (x = 0; x < sh_size; x++) { - double dist = - (sh_half - (x + 0.5)) * (sh_half - (x + 0.5)) + - (sh_half - (y + 0.5)) * (sh_half - (y + 0.5)); + float dist = + (sh_half - (x + 0.5f)) * (sh_half - (x + 0.5f)) + + (sh_half - (y + 0.5f)) * (sh_half - (y + 0.5f)); row[x] = dist < sh_half * sh_half ? color : 0; } } diff --git a/src/Http_Web.c b/src/Http_Web.c index dad8300fb..7dbc35e9e 100644 --- a/src/Http_Web.c +++ b/src/Http_Web.c @@ -139,7 +139,7 @@ static void Http_Init(void) { Http_InitCommon(); /* If this webpage is https://, browsers deny any http:// downloading */ httpsOnly = interop_IsHttpsOnly(); - startTime = DateTime_CurrentUTC_MS(); + startTime = DateTime_CurrentUTC(); RequestList_Init(&queuedReqs); RequestList_Init(&workingReqs); diff --git a/src/LBackend.c b/src/LBackend.c index 28f7610b2..dc55743e5 100644 --- a/src/LBackend.c +++ b/src/LBackend.c @@ -534,7 +534,7 @@ void LBackend_CheckboxDraw(struct LCheckbox* w) { /*########################################################################################################################* *------------------------------------------------------InputWidget--------------------------------------------------------* *#########################################################################################################################*/ -static TimeMS caretStart; +static cc_uint64 caretStart; static Rect2D caretRect, lastCaretRect; #define Rect2D_Equals(a, b) a.x == b.x && a.y == b.y && a.Width == b.Width && a.Height == b.Height @@ -620,7 +620,7 @@ void LBackend_InputTick(struct LInput* w) { Rect2D r; if (!caretStart) return; - elapsed = (int)(DateTime_CurrentUTC_MS() - caretStart); + elapsed = Stopwatch_ElapsedMS(caretStart, Stopwatch_Measure()); caretShow = (elapsed % 1000) < 500; if (caretShow == w->caretShow) return; @@ -641,7 +641,7 @@ void LBackend_InputTick(struct LInput* w) { void LBackend_InputSelect(struct LInput* w, int idx, cc_bool wasSelected) { struct OpenKeyboardArgs args; - caretStart = DateTime_CurrentUTC_MS(); + caretStart = Stopwatch_Measure(); w->caretShow = true; LInput_MoveCaretToCursor(w, idx); LBackend_MarkDirty(w); diff --git a/src/LScreens.c b/src/LScreens.c index ea611bf06..539df3b5f 100644 --- a/src/LScreens.c +++ b/src/LScreens.c @@ -1600,9 +1600,9 @@ static void UpdatesScreen_Format(struct LLabel* lbl, const char* prefix, cc_uint if (!timestamp) { String_AppendConst(&str, "&cCheck failed"); } else { - now = DateTime_CurrentUTC_MS() - UNIX_EPOCH; + now = DateTime_CurrentUTC() - UNIX_EPOCH_SECONDS; /* must divide as cc_uint64, int delta overflows after 26 days */ - delta = (int)((now / 1000) - timestamp); + delta = (int)(now - timestamp); UpdatesScreen_FormatTime(&str, delta); } LLabel_SetText(lbl, &str); diff --git a/src/Platform.h b/src/Platform.h index 3b1635847..f5415ec14 100644 --- a/src/Platform.h +++ b/src/Platform.h @@ -24,8 +24,8 @@ typedef int cc_file; /* Origin points for when seeking in a file. */ /* NOTE: These have same values as SEEK_SET/SEEK_CUR/SEEK_END, do not change them */ enum File_SeekFrom { FILE_SEEKFROM_BEGIN, FILE_SEEKFROM_CURRENT, FILE_SEEKFROM_END }; -/* Number of milliseconds since 01/01/0001 to start of unix time. */ -#define UNIX_EPOCH 62135596800000ULL +/* Number of seconds since 01/01/0001 to start of unix time. */ +#define UNIX_EPOCH_SECONDS 62135596800ULL extern const cc_result ReturnCode_FileShareViolation; extern const cc_result ReturnCode_FileNotFound; @@ -163,8 +163,8 @@ void Platform_Log2(const char* format, const void* a1, const void* a2); void Platform_Log3(const char* format, const void* a1, const void* a2, const void* a3); void Platform_Log4(const char* format, const void* a1, const void* a2, const void* a3, const void* a4); -/* Returns the current UTC time, as number of milliseconds since 1/1/0001 */ -CC_API TimeMS DateTime_CurrentUTC_MS(void); +/* Returns the current UTC time, as number of seconds since 1/1/0001 */ +CC_API TimeMS DateTime_CurrentUTC(void); /* Returns the current local Time. */ CC_API void DateTime_CurrentLocal(struct DateTime* t); /* Takes a platform-specific stopwatch measurement. */ diff --git a/src/Platform_3DS.c b/src/Platform_3DS.c index 89fd1291d..0c40cd584 100644 --- a/src/Platform_3DS.c +++ b/src/Platform_3DS.c @@ -62,11 +62,10 @@ void Platform_Log(const char* msg, int len) { svcOutputDebugString("\n", 1); } -#define UnixTime_TotalMS(time) ((cc_uint64)time.tv_sec * 1000 + UNIX_EPOCH + (time.tv_usec / 1000)) -TimeMS DateTime_CurrentUTC_MS(void) { +TimeMS DateTime_CurrentUTC(void) { struct timeval cur; gettimeofday(&cur, NULL); - return UnixTime_TotalMS(cur); + return (cc_uint64)cur.tv_sec + UNIX_EPOCH_SECONDS; } void DateTime_CurrentLocal(struct DateTime* t) { diff --git a/src/Platform_Dreamcast.c b/src/Platform_Dreamcast.c index f2ecccad7..095d06bdd 100644 --- a/src/Platform_Dreamcast.c +++ b/src/Platform_Dreamcast.c @@ -75,7 +75,7 @@ void Platform_Log(const char* msg, int len) { LogOnscreen(msg, len); } -TimeMS DateTime_CurrentUTC_MS(void) { +TimeMS DateTime_CurrentUTC(void) { uint32 secs, ms; timer_ms_gettime(&secs, &ms); @@ -86,7 +86,7 @@ TimeMS DateTime_CurrentUTC_MS(void) { if (boot_time < boot_time_2000) boot_time = boot_time_2024; cc_uint64 curSecs = boot_time + secs; - return (curSecs * 1000 + ms) + UNIX_EPOCH; + return curSecs + UNIX_EPOCH_SECONDS; } void DateTime_CurrentLocal(struct DateTime* t) { diff --git a/src/Platform_GCWii.c b/src/Platform_GCWii.c index 97acf81df..15023fe82 100644 --- a/src/Platform_GCWii.c +++ b/src/Platform_GCWii.c @@ -61,11 +61,10 @@ void Platform_Log(const char* msg, int len) { // TODO: Just use printf("%s", somehow ??? } -#define UnixTime_TotalMS(time) ((cc_uint64)time.tv_sec * 1000 + UNIX_EPOCH + (time.tv_usec / 1000)) -TimeMS DateTime_CurrentUTC_MS(void) { +TimeMS DateTime_CurrentUTC(void) { struct timeval cur; gettimeofday(&cur, NULL); - return UnixTime_TotalMS(cur); + return (cc_uint64)cur.tv_sec + UNIX_EPOCH_SECONDS; } void DateTime_CurrentLocal(struct DateTime* t) { @@ -594,4 +593,4 @@ static cc_result GetMachineID(cc_uint32* key) { } #endif -#endif \ No newline at end of file +#endif diff --git a/src/Platform_N64.c b/src/Platform_N64.c index 7b7428caa..1b2aeeee1 100644 --- a/src/Platform_N64.c +++ b/src/Platform_N64.c @@ -48,11 +48,10 @@ void Platform_Log(const char* msg, int len) { write(STDERR_FILENO, "\n", 1); } -#define UnixTime_TotalMS(time) ((cc_uint64)time.tv_sec * 1000 + UNIX_EPOCH + (time.tv_usec / 1000)) -TimeMS DateTime_CurrentUTC_MS(void) { +TimeMS DateTime_CurrentUTC(void) { struct timeval cur; gettimeofday(&cur, NULL); - return UnixTime_TotalMS(cur); + return (cc_uint64)cur.tv_sec + UNIX_EPOCH_SECONDS; } void DateTime_CurrentLocal(struct DateTime* t) { diff --git a/src/Platform_NDS.c b/src/Platform_NDS.c index 14f0d2b90..e1dc5e382 100644 --- a/src/Platform_NDS.c +++ b/src/Platform_NDS.c @@ -84,11 +84,10 @@ void Platform_Log(const char* msg, int len) { LogNocash(msg, len); } -#define UnixTime_TotalMS(time) ((cc_uint64)time.tv_sec * 1000 + UNIX_EPOCH) -TimeMS DateTime_CurrentUTC_MS(void) { +TimeMS DateTime_CurrentUTC(void) { struct timeval cur; gettimeofday(&cur, NULL); - return UnixTime_TotalMS(cur); // no usec on the DS + return (cc_uint64)cur.tv_sec + UNIX_EPOCH_SECONDS; } void DateTime_CurrentLocal(struct DateTime* t) { diff --git a/src/Platform_PS1.c b/src/Platform_PS1.c index e654127c9..0df90e033 100644 --- a/src/Platform_PS1.c +++ b/src/Platform_PS1.c @@ -39,8 +39,7 @@ void Platform_Log(const char* msg, int len) { printf("%s\n", tmp); } -#define UnixTime_TotalMS(time) ((cc_uint64)time.tv_sec * 1000 + UNIX_EPOCH + (time.tv_usec / 1000)) -TimeMS DateTime_CurrentUTC_MS(void) { +TimeMS DateTime_CurrentUTC(void) { return 0; } diff --git a/src/Platform_PS2.c b/src/Platform_PS2.c index ada09b7c4..5be4c5480 100644 --- a/src/Platform_PS2.c +++ b/src/Platform_PS2.c @@ -56,11 +56,10 @@ void Platform_Log(const char* msg, int len) { _print("%s", tmp); } -#define UnixTime_TotalMS(time) ((cc_uint64)time.tv_sec * 1000 + UNIX_EPOCH + (time.tv_usec / 1000)) -TimeMS DateTime_CurrentUTC_MS(void) { +TimeMS DateTime_CurrentUTC(void) { struct timeval cur; gettimeofday(&cur, NULL); - return UnixTime_TotalMS(cur); + return (cc_uint64)cur.tv_sec + UNIX_EPOCH_SECONDS; } void DateTime_CurrentLocal(struct DateTime* t) { diff --git a/src/Platform_PS3.c b/src/Platform_PS3.c index a70279d0c..b24744bd0 100644 --- a/src/Platform_PS3.c +++ b/src/Platform_PS3.c @@ -52,11 +52,10 @@ void Platform_Log(const char* msg, int len) { sysTtyWrite(STDOUT_FILENO, "\n", 1, &done); } -#define UnixTime_TotalMS(time) ((cc_uint64)time.tv_sec * 1000 + UNIX_EPOCH + (time.tv_usec / 1000)) -TimeMS DateTime_CurrentUTC_MS(void) { +TimeMS DateTime_CurrentUTC(void) { struct timeval cur; gettimeofday(&cur, NULL); - return UnixTime_TotalMS(cur); + return (cc_uint64)cur.tv_sec + UNIX_EPOCH_SECONDS; } void DateTime_CurrentLocal(struct DateTime* t) { @@ -483,4 +482,4 @@ cc_bool Platform_DescribeError(cc_result res, cc_string* dst) { static cc_result GetMachineID(cc_uint32* key) { return ERR_NOT_SUPPORTED; } -#endif \ No newline at end of file +#endif diff --git a/src/Platform_PSP.c b/src/Platform_PSP.c index 3667b5dee..014edd575 100644 --- a/src/Platform_PSP.c +++ b/src/Platform_PSP.c @@ -54,11 +54,10 @@ void Platform_Log(const char* msg, int len) { //File_Close(file); } -#define UnixTime_TotalMS(time) ((cc_uint64)time.tv_sec * 1000 + UNIX_EPOCH + (time.tv_usec / 1000)) -TimeMS DateTime_CurrentUTC_MS(void) { +TimeMS DateTime_CurrentUTC(void) { struct SceKernelTimeval cur; sceKernelLibcGettimeofday(&cur, NULL); - return UnixTime_TotalMS(cur); + return (cc_uint64)cur.tv_sec + UNIX_EPOCH_SECONDS; } void DateTime_CurrentLocal(struct DateTime* t) { diff --git a/src/Platform_PSVita.c b/src/Platform_PSVita.c index e5e47c232..e002e5945 100644 --- a/src/Platform_PSVita.c +++ b/src/Platform_PSVita.c @@ -37,11 +37,10 @@ void Platform_Log(const char* msg, int len) { sceIoWrite(stdout_fd, msg, len); } -#define UnixTime_TotalMS(time) ((cc_uint64)time.sec * 1000 + UNIX_EPOCH + (time.usec / 1000)) -TimeMS DateTime_CurrentUTC_MS(void) { +TimeMS DateTime_CurrentUTC(void) { struct SceKernelTimeval cur; sceKernelLibcGettimeofday(&cur, NULL); - return UnixTime_TotalMS(cur); + return (cc_uint64)cur.sec + UNIX_EPOCH_SECONDS; } void DateTime_CurrentLocal(struct DateTime* t) { diff --git a/src/Platform_Posix.c b/src/Platform_Posix.c index 1bb56e988..04d2f26c0 100644 --- a/src/Platform_Posix.c +++ b/src/Platform_Posix.c @@ -103,11 +103,10 @@ void Platform_Log(const char* msg, int len) { } #endif -#define UnixTime_TotalMS(time) ((cc_uint64)time.tv_sec * 1000 + UNIX_EPOCH + (time.tv_usec / 1000)) -TimeMS DateTime_CurrentUTC_MS(void) { +TimeMS DateTime_CurrentUTC(void) { struct timeval cur; gettimeofday(&cur, NULL); - return UnixTime_TotalMS(cur); + return (cc_uint64)cur.tv_sec + UNIX_EPOCH_SECONDS; } void DateTime_CurrentLocal(struct DateTime* t) { diff --git a/src/Platform_Switch.c b/src/Platform_Switch.c index 846b61b27..a5111a720 100644 --- a/src/Platform_Switch.c +++ b/src/Platform_Switch.c @@ -87,11 +87,10 @@ void Platform_Log(const char* msg, int len) { svcOutputDebugString(msg, len); } -#define UnixTime_TotalMS(time) ((cc_uint64)time.tv_sec * 1000 + UNIX_EPOCH + (time.tv_usec / 1000)) -TimeMS DateTime_CurrentUTC_MS(void) { +TimeMS DateTime_CurrentUTC(void) { struct timeval cur; gettimeofday(&cur, NULL); - return UnixTime_TotalMS(cur); + return (cc_uint64)cur.tv_sec + UNIX_EPOCH_SECONDS; } void DateTime_CurrentLocal(struct DateTime* t) { diff --git a/src/Platform_Web.c b/src/Platform_Web.c index f1b43bec2..2fd862701 100644 --- a/src/Platform_Web.c +++ b/src/Platform_Web.c @@ -84,11 +84,10 @@ void Platform_Log(const char* msg, int len) { interop_Log(msg, len); } -#define UnixTime_TotalMS(time) ((cc_uint64)time.tv_sec * 1000 + UNIX_EPOCH + (time.tv_usec / 1000)) -TimeMS DateTime_CurrentUTC_MS(void) { +TimeMS DateTime_CurrentUTC(void) { struct timeval cur; gettimeofday(&cur, NULL); - return UnixTime_TotalMS(cur); + return (cc_uint64)cur.tv_sec + UNIX_EPOCH_SECONDS; } extern void interop_GetLocalTime(struct DateTime* t); diff --git a/src/Platform_WiiU.c b/src/Platform_WiiU.c index ba3069e48..384956904 100644 --- a/src/Platform_WiiU.c +++ b/src/Platform_WiiU.c @@ -58,15 +58,12 @@ void Platform_Log(const char* msg, int len) { OSReport("%s\n", tmp); } -#define WIIU_EPOCH_ADJUST 946684800000ULL // Wii U time epoch is year 2000, not 1970 +#define WIIU_EPOCH_ADJUST 946684800ULL // Wii U time epoch is year 2000, not 1970 -TimeMS DateTime_CurrentUTC_MS(void) { - OSTime time = OSGetTime(); - // avoid overflow in time calculation +TimeMS DateTime_CurrentUTC(void) { + OSTime time = OSGetTime(); cc_int64 secs = (time_t)OSTicksToSeconds(time); - time -= OSSecondsToTicks(secs); - cc_uint64 msecs = OSTicksToMilliseconds(time); - return (secs * 1000 + msecs) + UNIX_EPOCH + WIIU_EPOCH_ADJUST; + return secs + UNIX_EPOCH_SECONDS + WIIU_EPOCH_ADJUST; } void DateTime_CurrentLocal(struct DateTime* t) { @@ -455,4 +452,4 @@ void Platform_Init(void) { *-------------------------------------------------------Encryption--------------------------------------------------------* *#########################################################################################################################*/ static cc_result GetMachineID(cc_uint32* key) { return ERR_NOT_SUPPORTED; } -#endif \ No newline at end of file +#endif diff --git a/src/Platform_Windows.c b/src/Platform_Windows.c index 52d128dab..00aa6e3b6 100644 --- a/src/Platform_Windows.c +++ b/src/Platform_Windows.c @@ -96,18 +96,18 @@ void Platform_Log(const char* msg, int len) { OutputDebugStringA("\n"); } -#define FILETIME_EPOCH 50491123200000ULL -#define FILETIME_UNIX_EPOCH 11644473600LL -#define FileTime_TotalMS(time) ((time / 10000) + FILETIME_EPOCH) -#define FileTime_UnixTime(time) ((time / 10000000) - FILETIME_UNIX_EPOCH) -TimeMS DateTime_CurrentUTC_MS(void) { +#define FILETIME_EPOCH 50491123200ULL +#define FILETIME_UNIX_EPOCH 11644473600ULL +#define FileTime_TotalSecs(time) ((time / 10000000) + FILETIME_EPOCH) +#define FileTime_UnixTime(time) ((time / 10000000) - FILETIME_UNIX_EPOCH) +TimeMS DateTime_CurrentUTC(void) { FILETIME ft; cc_uint64 raw; GetSystemTimeAsFileTime(&ft); /* in 100 nanosecond units, since Jan 1 1601 */ raw = ft.dwLowDateTime | ((cc_uint64)ft.dwHighDateTime << 32); - return FileTime_TotalMS(raw); + return FileTime_TotalSecs(raw); } void DateTime_CurrentLocal(struct DateTime* t) { diff --git a/src/Platform_Xbox.c b/src/Platform_Xbox.c index f53fe1dd0..80f3f1422 100644 --- a/src/Platform_Xbox.c +++ b/src/Platform_Xbox.c @@ -39,16 +39,16 @@ void Platform_Log(const char* msg, int len) { OutputDebugStringA(tmp); } -#define FILETIME_EPOCH 50491123200000ULL -#define FILETIME_UNIX_EPOCH 11644473600LL -#define FileTime_TotalMS(time) ((time / 10000) + FILETIME_EPOCH) -#define FileTime_UnixTime(time) ((time / 10000000) - FILETIME_UNIX_EPOCH) -TimeMS DateTime_CurrentUTC_MS(void) { +#define FILETIME_EPOCH 50491123200ULL +#define FILETIME_UNIX_EPOCH 11644473600ULL +#define FileTime_TotalSecs(time) ((time / 10000000) + FILETIME_EPOCH) +#define FileTime_UnixTime(time) ((time / 10000000) - FILETIME_UNIX_EPOCH) +TimeMS DateTime_CurrentUTC(void) { LARGE_INTEGER ft; KeQuerySystemTime(&ft); /* in 100 nanosecond units, since Jan 1 1601 */ - return FileTime_TotalMS(ft.QuadPart); + return FileTime_TotalSecs(ft.QuadPart); } void DateTime_CurrentLocal(struct DateTime* t) { diff --git a/src/Platform_Xbox360.c b/src/Platform_Xbox360.c index c230bc370..d18920e81 100644 --- a/src/Platform_Xbox360.c +++ b/src/Platform_Xbox360.c @@ -41,11 +41,10 @@ void Platform_Log(const char* msg, int len) { puts(tmp); } -#define UnixTime_TotalMS(time) ((cc_uint64)time.tv_sec * 1000 + UNIX_EPOCH + (time.tv_usec / 1000)) -TimeMS DateTime_CurrentUTC_MS(void) { +TimeMS DateTime_CurrentUTC(void) { struct timeval cur; gettimeofday(&cur, NULL); - return UnixTime_TotalMS(cur); + return (cc_uint64)cur.tv_sec + UNIX_EPOCH_SECONDS; } void DateTime_CurrentLocal(struct DateTime* t) { diff --git a/src/SSL.c b/src/SSL.c index 1bf323e69..389117e96 100644 --- a/src/SSL.c +++ b/src/SSL.c @@ -476,7 +476,7 @@ static void InjectEntropy(SSLContext* ctx) { #endif static void SetCurrentTime(SSLContext* ctx) { - cc_uint64 cur = DateTime_CurrentUTC_MS() / 1000; + cc_uint64 cur = DateTime_CurrentUTC(); uint32_t days = (uint32_t)(cur / 86400) + 366; uint32_t secs = (uint32_t)(cur % 86400); diff --git a/src/Server.c b/src/Server.c index 3d1b8dad3..3a60f5b52 100644 --- a/src/Server.c +++ b/src/Server.c @@ -67,7 +67,7 @@ int Ping_NextPingId(void) { head = (head + 1) % Array_Elems(ping_entries); ping_entries[head].id = next; - ping_entries[head].sent = DateTime_CurrentUTC_MS(); + ping_entries[head].sent = Stopwatch_Measure(); ping_entries[head].recv = 0; ping_head = head; @@ -79,25 +79,27 @@ void Ping_Update(int id) { for (i = 0; i < Array_Elems(ping_entries); i++) { if (ping_entries[i].id != id) continue; - ping_entries[i].recv = DateTime_CurrentUTC_MS(); + ping_entries[i].recv = Stopwatch_Measure(); return; } } int Ping_AveragePingMS(void) { - int i, measures = 0, totalMs = 0; + int i, measures = 0, totalMs; + cc_int64 total = 0; for (i = 0; i < Array_Elems(ping_entries); i++) { struct PingEntry entry = ping_entries[i]; if (!entry.sent || !entry.recv) continue; - totalMs += (int)(entry.recv - entry.sent); + total += entry.recv - entry.sent; measures++; } - if (!measures) return 0; - /* (recv - send) is time for packet to be sent to server and then sent back. */ - /* However for ping, only want time to send data to server, so half the total. */ + + totalMs = Stopwatch_ElapsedMS(0, total); + /* (recv - send) is average time for packet to be sent to server and then sent back. */ + /* However for ping, only want average time to send data to server, so half the total. */ totalMs /= 2; return totalMs / measures; } diff --git a/src/Utils.h b/src/Utils.h index 8cfa7f090..7d8f245ad 100644 --- a/src/Utils.h +++ b/src/Utils.h @@ -9,7 +9,7 @@ Copyright 2014-2023 ClassiCube | Licensed under BSD-3 struct Bitmap; struct StringsBuffer; /* Represents a particular instance in time in some timezone. Not necessarily UTC time. */ -/* NOTE: TimeMS and DateTime_CurrentUTC_MS() should almost always be used instead. */ +/* NOTE: TimeMS and DateTime_CurrentUTC() should almost always be used instead. */ /* This struct should only be used when actually needed. (e.g. log message time) */ struct DateTime { int year; /* Year, ranges from 0 to 65535 */ diff --git a/src/_HttpBase.h b/src/_HttpBase.h index 55a11a15e..d0b0c4bc5 100644 --- a/src/_HttpBase.h +++ b/src/_HttpBase.h @@ -192,7 +192,7 @@ static void Http_FinishRequest(struct HttpRequest* req) { Mutex_Lock(processedMutex); { - req->timeDownloaded = DateTime_CurrentUTC_MS(); + req->timeDownloaded = DateTime_CurrentUTC(); RequestList_Append(&processedReqs, req, false); } Mutex_Unlock(processedMutex); @@ -205,10 +205,10 @@ static void Http_CleanCacheTask(struct ScheduledTask* task) { Mutex_Lock(processedMutex); { - TimeMS now = DateTime_CurrentUTC_MS(); + TimeMS now = DateTime_CurrentUTC(); for (i = processedReqs.count - 1; i >= 0; i--) { item = &processedReqs.entries[i]; - if (item->timeDownloaded + (10 * 1000) >= now) continue; + if (now > item->timeDownloaded + 10) continue; HttpRequest_Free(item); RequestList_RemoveAt(&processedReqs, i);