mirror of
https://github.com/QB64-Phoenix-Edition/QB64pe.git
synced 2024-05-12 12:00:13 +00:00
Make Linux GetTicks() start from zero
Since the GetTicks() is visible in the logging, it's useful to have it start from zero rather than an arbitrary number.
This commit is contained in:
parent
11e40594ef
commit
07c0705ab8
|
@ -29914,6 +29914,8 @@ int32 func__scaledheight() { return environment_2d__screen_scaled_height; }
|
|||
extern void set_dynamic_info();
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
clock_init();
|
||||
|
||||
|
||||
#if defined(QB64_LINUX) && defined(X11)
|
||||
XInitThreads();
|
||||
|
|
|
@ -4,6 +4,14 @@
|
|||
#include <stdint.h>
|
||||
#include "qbs.h"
|
||||
|
||||
#ifdef QB64_LINUX
|
||||
// Initializes the clock returned by 'GetTicks()' so that it starts from zero
|
||||
// Should be called at the very beginning of the program
|
||||
void clock_init();
|
||||
#else
|
||||
static inline void clock_init() { }
|
||||
#endif
|
||||
|
||||
int64_t GetTicks();
|
||||
|
||||
double func_timer(double accuracy, int32_t passed);
|
||||
|
|
|
@ -37,10 +37,18 @@ static int64_t orwl_gettime(void) {
|
|||
#endif
|
||||
|
||||
#ifdef QB64_LINUX
|
||||
static int64_t initial_tick = 0;
|
||||
|
||||
void clock_init() {
|
||||
// When GetTicks() is called here initial_tick is zero, so as a result
|
||||
// GetTicks() returns the original value of the clock.
|
||||
initial_tick = GetTicks();
|
||||
}
|
||||
|
||||
int64_t GetTicks() {
|
||||
struct timespec tp;
|
||||
clock_gettime(CLOCK_MONOTONIC, &tp);
|
||||
return tp.tv_sec * 1000 + tp.tv_nsec / 1000000;
|
||||
return (tp.tv_sec * 1000 + tp.tv_nsec / 1000000) - initial_tick;
|
||||
}
|
||||
#elif defined QB64_MACOSX
|
||||
int64_t GetTicks() { return orwl_gettime(); }
|
||||
|
|
Loading…
Reference in a new issue