readd seconds stuff
This commit is contained in:
@@ -227,7 +227,7 @@ app_key_t w32_map_wparam_to_app_key(WPARAM wparam) {
|
||||
default: {return app_key_null;} break;
|
||||
}
|
||||
}
|
||||
#endif/*D:\dev\wasm\src/app/app.meta.c*/
|
||||
#endif/*C:\dev\wasm\src/app/app.meta.c*/
|
||||
type_t type__app_mouse_button_t = { type_kind_enum, s8_const_lit("app_mouse_button_t"), sizeof(app_mouse_button_t),
|
||||
.members = (type_member_t[]){
|
||||
{.name = s8_const_lit("app_mouse_button_null"), .value = app_mouse_button_null},
|
||||
|
||||
@@ -70,7 +70,7 @@ app_key_page_up,
|
||||
app_key_page_down,
|
||||
app_key_count,
|
||||
} app_key_t;
|
||||
/*D:\dev\wasm\src/app/app.meta.c*/
|
||||
/*C:\dev\wasm\src/app/app.meta.c*/
|
||||
typedef enum {
|
||||
app_mouse_button_null,
|
||||
app_mouse_button_left,
|
||||
|
||||
@@ -40,6 +40,20 @@ fn f64 w32_get_dpr(HWND window_handle) {
|
||||
return result;
|
||||
}
|
||||
|
||||
fn f64 w32_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;
|
||||
}
|
||||
|
||||
///////////////////////////////
|
||||
// event processing
|
||||
|
||||
@@ -240,20 +254,6 @@ 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);
|
||||
|
||||
@@ -339,7 +339,7 @@ int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int n
|
||||
refresh_rate = (f64)devmodew.dmDisplayFrequency;
|
||||
}
|
||||
|
||||
f64 time_frame_start = os_seconds_now();
|
||||
f64 time_frame_start = w32_seconds_now();
|
||||
f64 time_delta = 1.0 / refresh_rate;
|
||||
f64 time_total = 0.0;
|
||||
f64 time_update = 0.0;
|
||||
@@ -373,7 +373,7 @@ int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int n
|
||||
///////////////////////////////
|
||||
// end of frame timings
|
||||
|
||||
f64 time_update_partial = os_seconds_now() - time_frame_start;
|
||||
f64 time_update_partial = w32_seconds_now() - time_frame_start;
|
||||
time_update = time_update_partial;
|
||||
if (time_update < time_delta) {
|
||||
consecutive_missed_frames = 0;
|
||||
@@ -393,9 +393,9 @@ int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int n
|
||||
|
||||
// busy loop if we dont have good scheduling
|
||||
// or we woke up early
|
||||
time_update = os_seconds_now() - time_frame_start;
|
||||
time_update = w32_seconds_now() - time_frame_start;
|
||||
while (time_update < time_delta) {
|
||||
time_update = os_seconds_now() - time_frame_start;
|
||||
time_update = w32_seconds_now() - time_frame_start;
|
||||
}
|
||||
} else {
|
||||
missed_frames += 1;
|
||||
@@ -409,7 +409,7 @@ int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int n
|
||||
// probably want the locked frame rate and total should reflect that, so choosing
|
||||
// time_delta seems the correct choice but not really sure what is correct.
|
||||
time_total += time_delta;
|
||||
time_frame_start = os_seconds_now();
|
||||
time_frame_start = w32_seconds_now();
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -10,3 +10,16 @@ fn os_date_t os_local_time_now(void) {
|
||||
result.year = lt->tm_year;
|
||||
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_get_milliseconds(void) {
|
||||
u64 micros = os_get_microseconds();
|
||||
f64 result = (f64)micros / 1000.0;
|
||||
return result;
|
||||
}
|
||||
@@ -11,3 +11,23 @@ fn os_date_t os_local_time_now(void) {
|
||||
result.year = lt.wYear;
|
||||
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_get_milliseconds(void) {
|
||||
f64 secs = os_seconds_now();
|
||||
f64 result = secs * 1000;
|
||||
return result;
|
||||
}
|
||||
Reference in New Issue
Block a user