Renamed STime to SFWTime.

This commit is contained in:
Relintai 2024-01-13 19:08:12 +01:00
parent 7df1e7a0f3
commit 71192064e6
22 changed files with 107 additions and 107 deletions

View File

@ -41,7 +41,7 @@ ccache g++ -Wall -D_REENTRANT -g -Isfw -c sfw/core/dir_access.cpp -o sfw/core/di
ccache g++ -Wall -D_REENTRANT -g -Isfw -c sfw/core/pool_vector.cpp -o sfw/core/pool_vector.o ccache g++ -Wall -D_REENTRANT -g -Isfw -c sfw/core/pool_vector.cpp -o sfw/core/pool_vector.o
ccache g++ -Wall -D_REENTRANT -g -Isfw -c sfw/core/pool_allocator.cpp -o sfw/core/pool_allocator.o ccache g++ -Wall -D_REENTRANT -g -Isfw -c sfw/core/pool_allocator.cpp -o sfw/core/pool_allocator.o
ccache g++ -Wall -D_REENTRANT -g -Isfw -c sfw/core/mutex.cpp -o sfw/core/mutex.o ccache g++ -Wall -D_REENTRANT -g -Isfw -c sfw/core/mutex.cpp -o sfw/core/mutex.o
ccache g++ -Wall -D_REENTRANT -g -Isfw -c sfw/core/stime.cpp -o sfw/core/stime.o ccache g++ -Wall -D_REENTRANT -g -Isfw -c sfw/core/sfw_time.cpp -o sfw/core/SFWTime.o
ccache g++ -Wall -D_REENTRANT -g -Isfw -c sfw/core/sfw_core.cpp -o sfw/core/sfw_core.o ccache g++ -Wall -D_REENTRANT -g -Isfw -c sfw/core/sfw_core.cpp -o sfw/core/sfw_core.o
@ -106,7 +106,7 @@ ccache g++ -Wall -lm -ldl -lpthread -lX11 -D_REENTRANT -g sfw/core/aabb.o sfw/c
sfw/core/ustring.o sfw/core/string_name.o \ sfw/core/ustring.o sfw/core/string_name.o \
sfw/core/vector2.o sfw/core/vector2i.o sfw/core/vector3.o \ sfw/core/vector2.o sfw/core/vector2i.o sfw/core/vector3.o \
sfw/core/vector3i.o sfw/core/vector4.o sfw/core/vector4i.o \ sfw/core/vector3i.o sfw/core/vector4.o sfw/core/vector4i.o \
sfw/core/pool_vector.o sfw/core/pool_allocator.o sfw/core/mutex.o sfw/core/stime.o \ sfw/core/pool_vector.o sfw/core/pool_allocator.o sfw/core/mutex.o sfw/core/SFWTime.o \
sfw/core/dir_access.o sfw/core/file_access.o \ sfw/core/dir_access.o sfw/core/file_access.o \
sfw/core/sfw_core.o \ sfw/core/sfw_core.o \
sfw/object/object.o sfw/object/reference.o sfw/object/core_string_names.o \ sfw/object/object.o sfw/object/reference.o sfw/object/core_string_names.o \

View File

@ -41,7 +41,7 @@ ccache g++ -Wall -D_REENTRANT -g -Isfw -c sfw/core/dir_access.cpp -o sfw/core/di
ccache g++ -Wall -D_REENTRANT -g -Isfw -c sfw/core/pool_vector.cpp -o sfw/core/pool_vector.o ccache g++ -Wall -D_REENTRANT -g -Isfw -c sfw/core/pool_vector.cpp -o sfw/core/pool_vector.o
ccache g++ -Wall -D_REENTRANT -g -Isfw -c sfw/core/pool_allocator.cpp -o sfw/core/pool_allocator.o ccache g++ -Wall -D_REENTRANT -g -Isfw -c sfw/core/pool_allocator.cpp -o sfw/core/pool_allocator.o
ccache g++ -Wall -D_REENTRANT -g -Isfw -c sfw/core/mutex.cpp -o sfw/core/mutex.o ccache g++ -Wall -D_REENTRANT -g -Isfw -c sfw/core/mutex.cpp -o sfw/core/mutex.o
ccache g++ -Wall -D_REENTRANT -g -Isfw -c sfw/core/stime.cpp -o sfw/core/stime.o ccache g++ -Wall -D_REENTRANT -g -Isfw -c sfw/core/sfw_time.cpp -o sfw/core/SFWTime.o
ccache g++ -Wall -D_REENTRANT -g -Isfw -c sfw/core/sfw_core.cpp -o sfw/core/sfw_core.o ccache g++ -Wall -D_REENTRANT -g -Isfw -c sfw/core/sfw_core.cpp -o sfw/core/sfw_core.o
@ -106,7 +106,7 @@ ccache g++ -Wall -lm -ldl -lpthread -lX11 -D_REENTRANT -g sfw/core/aabb.o sfw/c
sfw/core/ustring.o sfw/core/string_name.o \ sfw/core/ustring.o sfw/core/string_name.o \
sfw/core/vector2.o sfw/core/vector2i.o sfw/core/vector3.o \ sfw/core/vector2.o sfw/core/vector2i.o sfw/core/vector3.o \
sfw/core/vector3i.o sfw/core/vector4.o sfw/core/vector4i.o \ sfw/core/vector3i.o sfw/core/vector4.o sfw/core/vector4i.o \
sfw/core/pool_vector.o sfw/core/pool_allocator.o sfw/core/mutex.o sfw/core/stime.o \ sfw/core/pool_vector.o sfw/core/pool_allocator.o sfw/core/mutex.o sfw/core/SFWTime.o \
sfw/core/dir_access.o sfw/core/file_access.o \ sfw/core/dir_access.o sfw/core/file_access.o \
sfw/core/sfw_core.o \ sfw/core/sfw_core.o \
sfw/object/object.o sfw/object/reference.o sfw/object/core_string_names.o \ sfw/object/object.o sfw/object/reference.o sfw/object/core_string_names.o \

View File

@ -6,7 +6,7 @@
//--STRIP //--STRIP
#include "core/random_pcg.h" #include "core/random_pcg.h"
#include "core/stime.h" #include "core/sfw_time.h"
#include "core/error_macros.h" #include "core/error_macros.h"
//--STRIP //--STRIP
@ -17,7 +17,7 @@ RandomPCG::RandomPCG(uint64_t p_seed, uint64_t p_inc) :
} }
void RandomPCG::randomize() { void RandomPCG::randomize() {
seed((STime::date() + STime::time_us()) * pcg.state + PCG_DEFAULT_INC_64); seed((SFWTime::date() + SFWTime::time_us()) * pcg.state + PCG_DEFAULT_INC_64);
} }
double RandomPCG::random(double p_from, double p_to) { double RandomPCG::random(double p_from, double p_to) {

View File

@ -2,7 +2,7 @@
// time // time
//--STRIP //--STRIP
#include "core/stime.h" #include "core/sfw_time.h"
#include <sys/time.h> #include <sys/time.h>
#include <time.h> #include <time.h>
@ -11,42 +11,42 @@
//--STRIP //--STRIP
#if 0 #if 0
uint64_t STime::time_gpu() { uint64_t SFWTime::time_gpu() {
GLint64 t = 123456789; GLint64 t = 123456789;
glGetInteger64v(GL_TIMESTAMP, &t); glGetInteger64v(GL_TIMESTAMP, &t);
return (uint64_t)t; return (uint64_t)t;
} }
#endif #endif
uint64_t STime::date() { uint64_t SFWTime::date() {
//time_t epoch = time(0); //time_t epoch = time(0);
//struct tm *ti = localtime(&epoch); //struct tm *ti = localtime(&epoch);
//return atoi64(va("%04d%02d%02d%02d%02d%02d", ti->tm_year + 1900, ti->tm_mon + 1, ti->tm_mday, ti->tm_hour, ti->tm_min, ti->tm_sec)); //return atoi64(va("%04d%02d%02d%02d%02d%02d", ti->tm_year + 1900, ti->tm_mon + 1, ti->tm_mday, ti->tm_hour, ti->tm_min, ti->tm_sec));
return 0; return 0;
} }
char *STime::date_string() { char *SFWTime::date_string() {
//time_t epoch = time(0); //time_t epoch = time(0);
//struct tm *ti = localtime(&epoch); //struct tm *ti = localtime(&epoch);
//return va("%04d-%02d-%02d %02d:%02d:%02d", ti->tm_year + 1900, ti->tm_mon + 1, ti->tm_mday, ti->tm_hour, ti->tm_min, ti->tm_sec); //return va("%04d-%02d-%02d %02d:%02d:%02d", ti->tm_year + 1900, ti->tm_mon + 1, ti->tm_mday, ti->tm_hour, ti->tm_min, ti->tm_sec);
return 0; return 0;
} }
uint64_t STime::date_epoch() { uint64_t SFWTime::date_epoch() {
time_t epoch = time(0); time_t epoch = time(0);
return epoch; return epoch;
} }
#if 0 #if 0
double STime::time_ss() { double SFWTime::time_ss() {
return glfwGetTime(); return glfwGetTime();
} }
double STime::time_ms() { double SFWTime::time_ms() {
return glfwGetTime() * 1000.0; return glfwGetTime() * 1000.0;
} }
uint64_t STime::time_us() { uint64_t SFWTime::time_us() {
return (uint64_t)(glfwGetTime() * 1000000.0); // @fixme: use a high resolution timer instead, or time_gpu below return (uint64_t)(glfwGetTime() * 1000000.0); // @fixme: use a high resolution timer instead, or time_gpu below
} }
uint64_t STime::sleep_us(uint64_t us) { // @fixme: use a high resolution sleeper instead uint64_t SFWTime::sleep_us(uint64_t us) { // @fixme: use a high resolution sleeper instead
return sleep_ms( us / 1000.0 ); return sleep_ms( us / 1000.0 );
} }
double STime::sleep_ms(double ms) { double SFWTime::sleep_ms(double ms) {
double now = time_ms(); double now = time_ms();
if( ms <= 0 ) { if( ms <= 0 ) {
#if defined(_WIN64) || defined(_WIN32) #if defined(_WIN64) || defined(_WIN32)
@ -113,7 +113,7 @@ static uint64_t nanotimer(uint64_t *out_freq) {
#endif #endif
} }
uint64_t STime::time_ns() { uint64_t SFWTime::time_ns() {
static __thread uint64_t epoch = 0; static __thread uint64_t epoch = 0;
static __thread uint64_t freq = 0; static __thread uint64_t freq = 0;
if (!freq) { if (!freq) {
@ -130,23 +130,23 @@ uint64_t STime::time_ns() {
uint64_t r = a % c; uint64_t r = a % c;
return q * b + r * b / c; return q * b + r * b / c;
} }
uint64_t STime::time_us() { uint64_t SFWTime::time_us() {
return time_ns() / TIMER_E3; return time_ns() / TIMER_E3;
} }
uint64_t STime::time_ms() { uint64_t SFWTime::time_ms() {
return time_ns() / TIMER_E6; return time_ns() / TIMER_E6;
} }
double STime::time_ss() { double SFWTime::time_ss() {
return time_ns() / 1e9; // TIMER_E9; return time_ns() / 1e9; // TIMER_E9;
} }
double STime::time_mm() { double SFWTime::time_mm() {
return time_ss() / 60; return time_ss() / 60;
} }
double STime::time_hh() { double SFWTime::time_hh() {
return time_mm() / 60; return time_mm() / 60;
} }
void STime::sleep_ns(double ns) { void SFWTime::sleep_ns(double ns) {
#if defined(_WIN64) || defined(_WIN32) #if defined(_WIN64) || defined(_WIN32)
if (ns >= 100) { if (ns >= 100) {
LARGE_INTEGER li; // Windows sleep in 100ns units LARGE_INTEGER li; // Windows sleep in 100ns units
@ -170,12 +170,12 @@ void STime::sleep_ns(double ns) {
#endif #endif
} }
} }
void STime::sleep_us(double us) { void SFWTime::sleep_us(double us) {
sleep_ns(us * 1e3); sleep_ns(us * 1e3);
} }
void STime::sleep_ms(double ms) { void SFWTime::sleep_ms(double ms) {
sleep_ns(ms * 1e6); sleep_ns(ms * 1e6);
} }
void STime::sleep_ss(double ss) { void SFWTime::sleep_ss(double ss) {
sleep_ns(ss * 1e9); sleep_ns(ss * 1e9);
} }

View File

@ -1,6 +1,6 @@
//--STRIP //--STRIP
#ifndef STIME_H #ifndef SFW_TIME_H
#define STIME_H #define SFW_TIME_H
//--STRIP //--STRIP
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
@ -11,7 +11,7 @@
#include "core/int_types.h" #include "core/int_types.h"
//--STRIP //--STRIP
class STime { class SFWTime {
public: public:
static uint64_t date(); // YYYYMMDDhhmmss static uint64_t date(); // YYYYMMDDhhmmss
static uint64_t date_epoch(); // linux epoch static uint64_t date_epoch(); // linux epoch

View File

@ -2673,7 +2673,7 @@ typedef void (*GLADpostcallback)(void *ret, const char *name, GLADapiproc apipro
* khronos_time_ns_t unsigned 64 bit time in nanoseconds * khronos_time_ns_t unsigned 64 bit time in nanoseconds
* khronos_utime_nanoseconds_t unsigned time interval or absolute time in * khronos_utime_nanoseconds_t unsigned time interval or absolute time in
* nanoseconds * nanoseconds
* khronos_stime_nanoseconds_t signed time interval in nanoseconds * khronos_SFWTime_nanoseconds_t signed time interval in nanoseconds
* khronos_boolean_enum_t enumerated boolean type. This should * khronos_boolean_enum_t enumerated boolean type. This should
* only be used as a base type when a client API's boolean type is * only be used as a base type when a client API's boolean type is
* an enum. Client APIs which use an integer or other type for * an enum. Client APIs which use an integer or other type for
@ -2873,7 +2873,7 @@ typedef float khronos_float_t;
* may be either signed or unsigned. * may be either signed or unsigned.
*/ */
typedef khronos_uint64_t khronos_utime_nanoseconds_t; typedef khronos_uint64_t khronos_utime_nanoseconds_t;
typedef khronos_int64_t khronos_stime_nanoseconds_t; typedef khronos_int64_t khronos_SFWTime_nanoseconds_t;
#endif #endif
/* /*

View File

@ -3961,7 +3961,7 @@ GLFWAPI GLFWwindowcontentscalefun glfwSetWindowContentScaleCallback(GLFWwindow*
* *
* @sa @ref events * @sa @ref events
* @sa @ref glfwWaitEvents * @sa @ref glfwWaitEvents
* @sa @ref glfwWaitEventsTimeout * @sa @ref glfwWaitEventSFWTimeout
* *
* @since Added in version 1.0. * @since Added in version 1.0.
* *
@ -4006,7 +4006,7 @@ GLFWAPI void glfwPollEvents(void);
* *
* @sa @ref events * @sa @ref events
* @sa @ref glfwPollEvents * @sa @ref glfwPollEvents
* @sa @ref glfwWaitEventsTimeout * @sa @ref glfwWaitEventSFWTimeout
* *
* @since Added in version 2.5. * @since Added in version 2.5.
* *
@ -4061,12 +4061,12 @@ GLFWAPI void glfwWaitEvents(void);
* *
* @ingroup window * @ingroup window
*/ */
GLFWAPI void glfwWaitEventsTimeout(double timeout); GLFWAPI void glfwWaitEventSFWTimeout(double timeout);
/*! @brief Posts an empty event to the event queue. /*! @brief Posts an empty event to the event queue.
* *
* This function posts an empty event from the current thread to the event * This function posts an empty event from the current thread to the event
* queue, causing @ref glfwWaitEvents or @ref glfwWaitEventsTimeout to return. * queue, causing @ref glfwWaitEvents or @ref glfwWaitEventSFWTimeout to return.
* *
* @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref
* GLFW_PLATFORM_ERROR. * GLFW_PLATFORM_ERROR.
@ -4075,7 +4075,7 @@ GLFWAPI void glfwWaitEventsTimeout(double timeout);
* *
* @sa @ref events * @sa @ref events
* @sa @ref glfwWaitEvents * @sa @ref glfwWaitEvents
* @sa @ref glfwWaitEventsTimeout * @sa @ref glfwWaitEventSFWTimeout
* *
* @since Added in version 3.1. * @since Added in version 3.1.
* *
@ -9438,7 +9438,7 @@ typedef struct _GLFWwindowX11
// The time of the last KeyPress event per keycode, for discarding // The time of the last KeyPress event per keycode, for discarding
// duplicate key events generated for some keys by ibus // duplicate key events generated for some keys by ibus
Time keyPressTimes[256]; Time keyPresSFWTimes[256];
} _GLFWwindowX11; } _GLFWwindowX11;
// X11-specific global data // X11-specific global data
@ -11434,7 +11434,7 @@ void _glfwPlatformSetWindowOpacity(_GLFWwindow* window, float opacity);
void _glfwPlatformPollEvents(void); void _glfwPlatformPollEvents(void);
void _glfwPlatformWaitEvents(void); void _glfwPlatformWaitEvents(void);
void _glfwPlatformWaitEventsTimeout(double timeout); void _glfwPlatformWaitEventSFWTimeout(double timeout);
void _glfwPlatformPostEmptyEvent(void); void _glfwPlatformPostEmptyEvent(void);
void _glfwPlatformGetRequiredInstanceExtensions(const char** extensions); void _glfwPlatformGetRequiredInstanceExtensions(const char** extensions);
@ -18236,7 +18236,7 @@ GLFWAPI void glfwWaitEvents(void)
_glfwPlatformWaitEvents(); _glfwPlatformWaitEvents();
} }
GLFWAPI void glfwWaitEventsTimeout(double timeout) GLFWAPI void glfwWaitEventSFWTimeout(double timeout)
{ {
_GLFW_REQUIRE_INIT(); _GLFW_REQUIRE_INIT();
assert(timeout == timeout); assert(timeout == timeout);
@ -18249,7 +18249,7 @@ GLFWAPI void glfwWaitEventsTimeout(double timeout)
return; return;
} }
_glfwPlatformWaitEventsTimeout(timeout); _glfwPlatformWaitEventSFWTimeout(timeout);
} }
GLFWAPI void glfwPostEmptyEvent(void) GLFWAPI void glfwPostEmptyEvent(void)
@ -22497,7 +22497,7 @@ void _glfwPlatformWaitEvents(void)
_glfwPlatformPollEvents(); _glfwPlatformPollEvents();
} }
void _glfwPlatformWaitEventsTimeout(double timeout) void _glfwPlatformWaitEventSFWTimeout(double timeout)
{ {
MsgWaitForMultipleObjects(0, NULL, FALSE, (DWORD) (timeout * 1e3), QS_ALLEVENTS); MsgWaitForMultipleObjects(0, NULL, FALSE, (DWORD) (timeout * 1e3), QS_ALLEVENTS);
@ -23984,7 +23984,7 @@ void _glfwPlatformWaitEvents(void)
{ {
} }
void _glfwPlatformWaitEventsTimeout(double timeout) void _glfwPlatformWaitEventSFWTimeout(double timeout)
{ {
} }
@ -27352,13 +27352,13 @@ static void processEvent(XEvent *event)
// NOTE: Always allow the first event for each key through // NOTE: Always allow the first event for each key through
// (the server never sends a timestamp of zero) // (the server never sends a timestamp of zero)
// NOTE: Timestamp difference is compared to handle wrap-around // NOTE: Timestamp difference is compared to handle wrap-around
Time diff = event->xkey.time - window->x11.keyPressTimes[keycode]; Time diff = event->xkey.time - window->x11.keyPresSFWTimes[keycode];
if (diff == event->xkey.time || (diff > 0 && diff < ((Time)1 << 31))) if (diff == event->xkey.time || (diff > 0 && diff < ((Time)1 << 31)))
{ {
if (keycode) if (keycode)
_glfwInputKey(window, key, keycode, GLFW_PRESS, mods); _glfwInputKey(window, key, keycode, GLFW_PRESS, mods);
window->x11.keyPressTimes[keycode] = event->xkey.time; window->x11.keyPresSFWTimes[keycode] = event->xkey.time;
} }
if (!filtered) if (!filtered)
@ -28887,7 +28887,7 @@ void _glfwPlatformWaitEvents(void)
_glfwPlatformPollEvents(); _glfwPlatformPollEvents();
} }
void _glfwPlatformWaitEventsTimeout(double timeout) void _glfwPlatformWaitEventSFWTimeout(double timeout)
{ {
waitForAnyEvent(&timeout); waitForAnyEvent(&timeout);
_glfwPlatformPollEvents(); _glfwPlatformPollEvents();
@ -32923,7 +32923,7 @@ void _glfwPlatformWaitEvents(void)
handleEvents(NULL); handleEvents(NULL);
} }
void _glfwPlatformWaitEventsTimeout(double timeout) void _glfwPlatformWaitEventSFWTimeout(double timeout)
{ {
handleEvents(&timeout); handleEvents(&timeout);
} }
@ -37115,7 +37115,7 @@ void _glfwPlatformWaitEvents(void)
} // autoreleasepool } // autoreleasepool
} }
void _glfwPlatformWaitEventsTimeout(double timeout) void _glfwPlatformWaitEventSFWTimeout(double timeout)
{ {
@autoreleasepool { @autoreleasepool {

View File

@ -25,7 +25,7 @@
#undef Time #undef Time
#include "core/error_macros.h" #include "core/error_macros.h"
#include "core/stime.h" #include "core/sfw_time.h"
#include "core/ustring.h" #include "core/ustring.h"
#include "core/vector4.h" #include "core/vector4.h"
#include "render_core/application.h" #include "render_core/application.h"
@ -40,11 +40,11 @@ static int fps__timing_thread(void *arg) {
while (fps_active) { while (fps_active) {
if (framerate <= 0) { if (framerate <= 0) {
loop_counter = timer_counter = 0; loop_counter = timer_counter = 0;
STime::sleep_ms(250); SFWTime::sleep_ms(250);
} else { } else {
timer_counter++; timer_counter++;
int64_t tt = (int64_t)(1e9 / (float)framerate) - ns_excess; int64_t tt = (int64_t)(1e9 / (float)framerate) - ns_excess;
uint64_t took = -STime::time_ns(); uint64_t took = -SFWTime::time_ns();
#if is(win32) #if is(win32)
timeBeginPeriod(1); timeBeginPeriod(1);
Sleep(tt > 0 ? tt / 1e6 : 0); Sleep(tt > 0 ? tt / 1e6 : 0);
@ -84,7 +84,7 @@ static int fps_wait() {
// if we throttled too much, cpu idle wait // if we throttled too much, cpu idle wait
while (fps_active && (loop_counter > timer_counter)) { while (fps_active && (loop_counter > timer_counter)) {
//thread_yield(); //thread_yield();
STime::sleep_ns(100); SFWTime::sleep_ns(100);
} }
// max auto frameskip is 10: ie, even if speed is low paint at least one frame every 10 // max auto frameskip is 10: ie, even if speed is low paint at least one frame every 10
@ -434,7 +434,7 @@ bool AppWindow::create(bool full_Screen, float canvas_scale, unsigned int flags,
char *AppWindow::get_stats() { char *AppWindow::get_stats() {
static double num_frames = 0, begin = FLT_MAX, prev_frame = 0; static double num_frames = 0, begin = FLT_MAX, prev_frame = 0;
double now = STime::time_ss(); double now = SFWTime::time_ss();
if (boot_time < 0) { if (boot_time < 0) {
boot_time = now; boot_time = now;
} }

View File

@ -8,7 +8,7 @@
#include "core/math_defs.h" #include "core/math_defs.h"
#include "core/stime.h" #include "core/sfw_time.h"
#include "render_core/input.h" #include "render_core/input.h"
#include "render_core/input_map.h" #include "render_core/input_map.h"
#include "render_core/app_window.h" #include "render_core/app_window.h"
@ -46,7 +46,7 @@ void Application::start_main_loop() {
} }
void Application::main_loop() { void Application::main_loop() {
uint64_t start = STime::time_us(); uint64_t start = SFWTime::time_us();
AppWindow *w = AppWindow::get_singleton(); AppWindow *w = AppWindow::get_singleton();
@ -64,7 +64,7 @@ void Application::main_loop() {
//render //render
render(); render();
uint64_t end = STime::time_us(); uint64_t end = SFWTime::time_us();
uint64_t elapsed_us = end - start; uint64_t elapsed_us = end - start;
@ -78,7 +78,7 @@ void Application::main_loop() {
if (remaining > 0) { if (remaining > 0) {
frame_delta = tfps; frame_delta = tfps;
STime::sleep_us((double)SEC_TO_USEC(remaining)); SFWTime::sleep_us((double)SEC_TO_USEC(remaining));
} else { } else {
frame_delta = elapsed_seconds; frame_delta = elapsed_seconds;
} }

View File

@ -7,7 +7,7 @@
#include "input.h" #include "input.h"
#include "core/logger.h" #include "core/logger.h"
#include "core/stime.h" #include "core/sfw_time.h"
#include "render_core/application.h" #include "render_core/application.h"
#include "render_core/input_map.h" #include "render_core/input_map.h"
#include "render_core/keyboard.h" #include "render_core/keyboard.h"
@ -578,7 +578,7 @@ void Input::GLFWmousebuttonfunCallback(GLFWwindow *window, int button, int actio
mb->set_pressed(pressed); mb->set_pressed(pressed);
if (pressed) { if (pressed) {
uint64_t diff = STime::time_us() / 1000 - self->last_click_ms; uint64_t diff = SFWTime::time_us() / 1000 - self->last_click_ms;
if (mb->get_button_index() == self->last_click_button_index) { if (mb->get_button_index() == self->last_click_button_index) {
if (diff < 400 && Point2(self->last_click_pos).distance_to(last_mouse_pos) < 5) { if (diff < 400 && Point2(self->last_click_pos).distance_to(last_mouse_pos) < 5) {
@ -798,7 +798,7 @@ String Input::_hex_str(uint8_t p_byte) {
Input *Input::singleton = nullptr; Input *Input::singleton = nullptr;
void Input::SpeedTrack::update(const Vector2 &p_delta_p) { void Input::SpeedTrack::update(const Vector2 &p_delta_p) {
uint64_t tick = STime::time_us(); uint64_t tick = SFWTime::time_us();
uint32_t tdiff = tick - last_tick; uint32_t tdiff = tick - last_tick;
float delta_t = tdiff / 1000000.0; float delta_t = tdiff / 1000000.0;
last_tick = tick; last_tick = tick;
@ -825,7 +825,7 @@ void Input::SpeedTrack::update(const Vector2 &p_delta_p) {
} }
void Input::SpeedTrack::reset() { void Input::SpeedTrack::reset() {
last_tick = STime::time_us(); last_tick = SFWTime::time_us();
speed = Vector2(); speed = Vector2();
accum = Vector2(); accum = Vector2();
accum_t = 0; accum_t = 0;

View File

@ -6,7 +6,7 @@
//--STRIP //--STRIP
#include "core/random_pcg.h" #include "core/random_pcg.h"
#include "core/stime.h" #include "core/sfw_time.h"
#include "core/error_macros.h" #include "core/error_macros.h"
//--STRIP //--STRIP
@ -17,7 +17,7 @@ RandomPCG::RandomPCG(uint64_t p_seed, uint64_t p_inc) :
} }
void RandomPCG::randomize() { void RandomPCG::randomize() {
seed((STime::date() + STime::time_us()) * pcg.state + PCG_DEFAULT_INC_64); seed((SFWTime::date() + SFWTime::time_us()) * pcg.state + PCG_DEFAULT_INC_64);
} }
double RandomPCG::random(double p_from, double p_to) { double RandomPCG::random(double p_from, double p_to) {

View File

@ -2,7 +2,7 @@
// time // time
//--STRIP //--STRIP
#include "core/stime.h" #include "core/sfw_time.h"
#include <sys/time.h> #include <sys/time.h>
#include <time.h> #include <time.h>
@ -11,42 +11,42 @@
//--STRIP //--STRIP
#if 0 #if 0
uint64_t STime::time_gpu() { uint64_t SFWTime::time_gpu() {
GLint64 t = 123456789; GLint64 t = 123456789;
glGetInteger64v(GL_TIMESTAMP, &t); glGetInteger64v(GL_TIMESTAMP, &t);
return (uint64_t)t; return (uint64_t)t;
} }
#endif #endif
uint64_t STime::date() { uint64_t SFWTime::date() {
//time_t epoch = time(0); //time_t epoch = time(0);
//struct tm *ti = localtime(&epoch); //struct tm *ti = localtime(&epoch);
//return atoi64(va("%04d%02d%02d%02d%02d%02d", ti->tm_year + 1900, ti->tm_mon + 1, ti->tm_mday, ti->tm_hour, ti->tm_min, ti->tm_sec)); //return atoi64(va("%04d%02d%02d%02d%02d%02d", ti->tm_year + 1900, ti->tm_mon + 1, ti->tm_mday, ti->tm_hour, ti->tm_min, ti->tm_sec));
return 0; return 0;
} }
char *STime::date_string() { char *SFWTime::date_string() {
//time_t epoch = time(0); //time_t epoch = time(0);
//struct tm *ti = localtime(&epoch); //struct tm *ti = localtime(&epoch);
//return va("%04d-%02d-%02d %02d:%02d:%02d", ti->tm_year + 1900, ti->tm_mon + 1, ti->tm_mday, ti->tm_hour, ti->tm_min, ti->tm_sec); //return va("%04d-%02d-%02d %02d:%02d:%02d", ti->tm_year + 1900, ti->tm_mon + 1, ti->tm_mday, ti->tm_hour, ti->tm_min, ti->tm_sec);
return 0; return 0;
} }
uint64_t STime::date_epoch() { uint64_t SFWTime::date_epoch() {
time_t epoch = time(0); time_t epoch = time(0);
return epoch; return epoch;
} }
#if 0 #if 0
double STime::time_ss() { double SFWTime::time_ss() {
return glfwGetTime(); return glfwGetTime();
} }
double STime::time_ms() { double SFWTime::time_ms() {
return glfwGetTime() * 1000.0; return glfwGetTime() * 1000.0;
} }
uint64_t STime::time_us() { uint64_t SFWTime::time_us() {
return (uint64_t)(glfwGetTime() * 1000000.0); // @fixme: use a high resolution timer instead, or time_gpu below return (uint64_t)(glfwGetTime() * 1000000.0); // @fixme: use a high resolution timer instead, or time_gpu below
} }
uint64_t STime::sleep_us(uint64_t us) { // @fixme: use a high resolution sleeper instead uint64_t SFWTime::sleep_us(uint64_t us) { // @fixme: use a high resolution sleeper instead
return sleep_ms( us / 1000.0 ); return sleep_ms( us / 1000.0 );
} }
double STime::sleep_ms(double ms) { double SFWTime::sleep_ms(double ms) {
double now = time_ms(); double now = time_ms();
if( ms <= 0 ) { if( ms <= 0 ) {
#if defined(_WIN64) || defined(_WIN32) #if defined(_WIN64) || defined(_WIN32)
@ -113,7 +113,7 @@ static uint64_t nanotimer(uint64_t *out_freq) {
#endif #endif
} }
uint64_t STime::time_ns() { uint64_t SFWTime::time_ns() {
static __thread uint64_t epoch = 0; static __thread uint64_t epoch = 0;
static __thread uint64_t freq = 0; static __thread uint64_t freq = 0;
if (!freq) { if (!freq) {
@ -130,23 +130,23 @@ uint64_t STime::time_ns() {
uint64_t r = a % c; uint64_t r = a % c;
return q * b + r * b / c; return q * b + r * b / c;
} }
uint64_t STime::time_us() { uint64_t SFWTime::time_us() {
return time_ns() / TIMER_E3; return time_ns() / TIMER_E3;
} }
uint64_t STime::time_ms() { uint64_t SFWTime::time_ms() {
return time_ns() / TIMER_E6; return time_ns() / TIMER_E6;
} }
double STime::time_ss() { double SFWTime::time_ss() {
return time_ns() / 1e9; // TIMER_E9; return time_ns() / 1e9; // TIMER_E9;
} }
double STime::time_mm() { double SFWTime::time_mm() {
return time_ss() / 60; return time_ss() / 60;
} }
double STime::time_hh() { double SFWTime::time_hh() {
return time_mm() / 60; return time_mm() / 60;
} }
void STime::sleep_ns(double ns) { void SFWTime::sleep_ns(double ns) {
#if defined(_WIN64) || defined(_WIN32) #if defined(_WIN64) || defined(_WIN32)
if (ns >= 100) { if (ns >= 100) {
LARGE_INTEGER li; // Windows sleep in 100ns units LARGE_INTEGER li; // Windows sleep in 100ns units
@ -170,12 +170,12 @@ void STime::sleep_ns(double ns) {
#endif #endif
} }
} }
void STime::sleep_us(double us) { void SFWTime::sleep_us(double us) {
sleep_ns(us * 1e3); sleep_ns(us * 1e3);
} }
void STime::sleep_ms(double ms) { void SFWTime::sleep_ms(double ms) {
sleep_ns(ms * 1e6); sleep_ns(ms * 1e6);
} }
void STime::sleep_ss(double ss) { void SFWTime::sleep_ss(double ss) {
sleep_ns(ss * 1e9); sleep_ns(ss * 1e9);
} }

View File

@ -1,5 +1,5 @@
#ifndef STIME_H #ifndef SFWTime_H
#define STIME_H #define SFWTime_H
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// time framework utils // time framework utils
@ -9,7 +9,7 @@
#include "core/int_types.h" #include "core/int_types.h"
//--STRIP //--STRIP
class STime { class SFWTime {
public: public:
static uint64_t date(); // YYYYMMDDhhmmss static uint64_t date(); // YYYYMMDDhhmmss
static uint64_t date_epoch(); // linux epoch static uint64_t date_epoch(); // linux epoch

View File

@ -663,10 +663,10 @@ Files
Time Time
------------------------------------------------------------------ ------------------------------------------------------------------
<a name="CLASS_STime"></a> <a name="CLASS_SFWTime"></a>
<details><summary>STime</summary> <details><summary>SFWTime</summary>
|||CLASS_STime||| |||CLASS_SFWTime|||
</details> </details>

View File

@ -35,9 +35,9 @@
{{FILE:sfw/core/safe_refcount.cpp}} {{FILE:sfw/core/safe_refcount.cpp}}
//--STRIP //--STRIP
//#include "core/stime.h" //#include "core/sfw_time.h"
//--STRIP //--STRIP
{{FILE:sfw/core/stime.cpp}} {{FILE:sfw/core/sfw_time.cpp}}
//--STRIP //--STRIP
//#include "core/memory.h" //#include "core/memory.h"
@ -62,7 +62,7 @@
//--STRIP //--STRIP
//#include "core/random_pcg.h" //#include "core/random_pcg.h"
//#include "core/stime.h" //#include "core/sfw_time.h"
//#include "core/error_macros.h" //#include "core/error_macros.h"
//--STRIP //--STRIP
{{FILE:sfw/core/random_pcg.cpp}} {{FILE:sfw/core/random_pcg.cpp}}

View File

@ -47,7 +47,7 @@
//--STRIP //--STRIP
//#include "core/int_types.h" //#include "core/int_types.h"
//--STRIP //--STRIP
{{FILE:sfw/core/stime.h}} {{FILE:sfw/core/sfw_time.h}}
//--STRIP //--STRIP
//#include "core/typedefs.h" //#include "core/typedefs.h"
//--STRIP //--STRIP

View File

@ -207,9 +207,9 @@
{{FILE:sfw/core/safe_refcount.cpp}} {{FILE:sfw/core/safe_refcount.cpp}}
//--STRIP //--STRIP
//#include "core/stime.h" //#include "core/sfw_time.h"
//--STRIP //--STRIP
{{FILE:sfw/core/stime.cpp}} {{FILE:sfw/core/sfw_time.cpp}}
//--STRIP //--STRIP
//#include "core/memory.h" //#include "core/memory.h"
@ -234,7 +234,7 @@
//--STRIP //--STRIP
//#include "core/random_pcg.h" //#include "core/random_pcg.h"
//#include "core/stime.h" //#include "core/sfw_time.h"
//#include "core/error_macros.h" //#include "core/error_macros.h"
//--STRIP //--STRIP
{{FILE:sfw/core/random_pcg.cpp}} {{FILE:sfw/core/random_pcg.cpp}}
@ -475,7 +475,7 @@
//--STRIP //--STRIP
//#include "render_core/application.h" //#include "render_core/application.h"
//#include "core/math_defs.h" //#include "core/math_defs.h"
//#include "core/stime.h" //#include "core/sfw_time.h"
//#include "render_core/input.h" //#include "render_core/input.h"
//#include "render_core/input_map.h" //#include "render_core/input_map.h"
//#include "render_core/app_window.h" //#include "render_core/app_window.h"
@ -578,7 +578,7 @@
//#include "render_core/3rd_glad.h" //#include "render_core/3rd_glad.h"
//#include "3rd_glfw3.h" //#include "3rd_glfw3.h"
//#include "core/error_macros.h" //#include "core/error_macros.h"
//#include "core/stime.h" //#include "core/sfw_time.h"
//#include "core/ustring.h" //#include "core/ustring.h"
//#include "core/vector4.h" //#include "core/vector4.h"
//#include "render_core/application.h" //#include "render_core/application.h"
@ -603,7 +603,7 @@
//--STRIP //--STRIP
//#include "input.h" //#include "input.h"
//#include "core/logger.h" //#include "core/logger.h"
//#include "core/stime.h" //#include "core/sfw_time.h"
//#include "render_core/application.h" //#include "render_core/application.h"
//#include "render_core/input_map.h" //#include "render_core/input_map.h"
//#include "render_core/keyboard.h" //#include "render_core/keyboard.h"

View File

@ -47,7 +47,7 @@
//--STRIP //--STRIP
//#include "core/int_types.h" //#include "core/int_types.h"
//--STRIP //--STRIP
{{FILE:sfw/core/stime.h}} {{FILE:sfw/core/sfw_time.h}}
//--STRIP //--STRIP
//#include "core/typedefs.h" //#include "core/typedefs.h"
//--STRIP //--STRIP

View File

@ -35,9 +35,9 @@
{{FILE:sfwl/core/safe_refcount.cpp}} {{FILE:sfwl/core/safe_refcount.cpp}}
//--STRIP //--STRIP
//#include "core/stime.h" //#include "core/sfw_time.h"
//--STRIP //--STRIP
{{FILE:sfwl/core/stime.cpp}} {{FILE:sfwl/core/sfw_time.cpp}}
//--STRIP //--STRIP
//#include "core/memory.h" //#include "core/memory.h"
@ -62,7 +62,7 @@
//--STRIP //--STRIP
//#include "core/random_pcg.h" //#include "core/random_pcg.h"
//#include "core/stime.h" //#include "core/sfw_time.h"
//#include "core/error_macros.h" //#include "core/error_macros.h"
//--STRIP //--STRIP
{{FILE:sfwl/core/random_pcg.cpp}} {{FILE:sfwl/core/random_pcg.cpp}}

View File

@ -40,7 +40,7 @@
//--STRIP //--STRIP
//#include "core/int_types.h" //#include "core/int_types.h"
//--STRIP //--STRIP
{{FILE:sfwl/core/stime.h}} {{FILE:sfwl/core/sfw_time.h}}
//--STRIP //--STRIP
//#include "core/typedefs.h" //#include "core/typedefs.h"
//--STRIP //--STRIP

View File

@ -35,9 +35,9 @@
{{FILE:sfwl/core/safe_refcount.cpp}} {{FILE:sfwl/core/safe_refcount.cpp}}
//--STRIP //--STRIP
//#include "core/stime.h" //#include "core/sfw_time.h"
//--STRIP //--STRIP
{{FILE:sfwl/core/stime.cpp}} {{FILE:sfwl/core/sfw_time.cpp}}
//--STRIP //--STRIP
//#include "core/memory.h" //#include "core/memory.h"
@ -62,7 +62,7 @@
//--STRIP //--STRIP
//#include "core/random_pcg.h" //#include "core/random_pcg.h"
//#include "core/stime.h" //#include "core/sfw_time.h"
//#include "core/error_macros.h" //#include "core/error_macros.h"
//--STRIP //--STRIP
{{FILE:sfwl/core/random_pcg.cpp}} {{FILE:sfwl/core/random_pcg.cpp}}

View File

@ -40,7 +40,7 @@
//--STRIP //--STRIP
//#include "core/int_types.h" //#include "core/int_types.h"
//--STRIP //--STRIP
{{FILE:sfwl/core/stime.h}} {{FILE:sfwl/core/sfw_time.h}}
//--STRIP //--STRIP
//#include "core/typedefs.h" //#include "core/typedefs.h"
//--STRIP //--STRIP