remove time stuff from core

This commit is contained in:
krzosa
2025-01-03 14:01:32 +01:00
parent da3fceb19f
commit 1a16255c24
11 changed files with 25 additions and 44 deletions

View File

@@ -45,8 +45,8 @@ glb_wasm_export i32 wasm_temp_buff2_len = 127;
global f64 wasm_dpr;
global f64 wasm_delta_time;
global f64 wasm_time;
global f64 wasm_last_time_milliseconds;
global f64 wasm_app_init_time_milliseconds;
global f64 wasm_last_time;
global f64 wasm_app_init_time;
global app_event_list_t wasm_event_list;
typedef struct wasm_cached_t wasm_cached_t;
@@ -178,9 +178,13 @@ fn_wasm_export void wasm_key_up(char *key, b32 ctrl, b32 shift, b32 alt, b32 met
}
}
fn f64 wasm_seconds_now(void) {
return wasm_get_milliseconds() / 1000.0;
}
fn_wasm_export void wasm_update(f64 width, f64 height, f64 dpr) {
wasm_time = os_milliseconds_now();
wasm_delta_time = wasm_time - wasm_last_time_milliseconds;
wasm_time = wasm_seconds_now();
wasm_delta_time = wasm_time - wasm_last_time;
v2f64_t window_size = (v2f64_t){width / dpr, height / dpr};
wasm_dpr = dpr;
@@ -205,13 +209,13 @@ fn_wasm_export void wasm_update(f64 width, f64 height, f64 dpr) {
ma_set0(tcx.temp);
zero_struct(&wasm_event_list);
wasm_last_time_milliseconds = wasm_time;
wasm_last_time = wasm_time;
}
fn_wasm_export void wasm_init(void) {
core_init();
app_init();
wasm_app_init_time_milliseconds = os_milliseconds_now();
wasm_app_init_time = wasm_seconds_now();
}
fn f64 app_get_anim_time(void) {

View File

@@ -236,6 +236,20 @@ void w32_try_resizing_canvas(w32_canvas_t *canvas, HWND window_handle) {
}
}
fn f64 os_seconds_now(void) {
static int64_t counts_per_second;
if (counts_per_second == 0) {
LARGE_INTEGER freq;
QueryPerformanceFrequency(&freq);
counts_per_second = freq.QuadPart;
}
LARGE_INTEGER time;
QueryPerformanceCounter(&time);
f64 result = (f64)time.QuadPart / (f64)counts_per_second;
return result;
}
int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) {
tcx.temp = ma_create(ma_default_reserve_size);

View File

@@ -32,19 +32,6 @@ fn date_t os_date_now(void) {
return result;
}
fn u64 os_get_microseconds(void) {
struct timespec t;
clock_gettime(CLOCK_MONOTONIC, &t);
u64 result = t.tv_sec*million(1) + (t.tv_nsec/thousand(1));
return result;
}
fn f64 os_milliseconds_now(void) {
u64 micros = os_get_microseconds();
f64 result = (f64)micros / 1000.0;
return result;
}
fn void os_error_box(char *str) {
fprintf(stderr, "%s", str);
}

View File

@@ -38,10 +38,6 @@ fn f64 os_parse_float(char *str) {
return wasm_parse_float((isize)str, str_len((char *)str));
}
fn f64 os_milliseconds_now(void) {
return wasm_get_milliseconds();
}
fn void core_init(void) {
isize page_size = kib(64);
isize page_count = __builtin_wasm_memory_size(0);

View File

@@ -32,26 +32,6 @@ fn date_t os_date_now(void) {
return result;
}
fn f64 os_seconds_now(void) {
static int64_t counts_per_second;
if (counts_per_second == 0) {
LARGE_INTEGER freq;
QueryPerformanceFrequency(&freq);
counts_per_second = freq.QuadPart;
}
LARGE_INTEGER time;
QueryPerformanceCounter(&time);
f64 result = (f64)time.QuadPart / (f64)counts_per_second;
return result;
}
fn f64 os_milliseconds_now(void) {
f64 secs = os_seconds_now();
f64 result = secs * 1000;
return result;
}
fn void os_error_box(char *str) {
MessageBoxA(NULL, str, "fatal error", MB_OK);
fprintf(stderr, "%s", str);

0
src/os/os.c Normal file
View File

0
src/os/os.h Normal file
View File

0
src/os/os_unix.c Normal file
View File

0
src/os/os_wasm.c Normal file
View File

0
src/os/os_win32.c Normal file
View File