sketch out os api, binary stream writer in js, app sleep when no animation, local and universal time

This commit is contained in:
krzosa
2025-01-04 11:03:36 +01:00
parent 6f795b7ea6
commit dcd1266477
13 changed files with 316 additions and 87 deletions

View File

@@ -0,0 +1,7 @@
#if PLATFORM_WASM
#include "os_wasm.c"
#elif PLATFORM_WINDOWS
#include "os_win32.c"
#else
#include "os_unix.c"
#endif

View File

@@ -9,4 +9,42 @@ struct os_date_t {
u16 year;
};
fn os_date_t os_date_now(void);
fn os_date_t os_local_time_now(void);
fn os_date_t os_universal_time_now(void);
fn f64 os_milliseconds_now(void);
#if 0
fn u64 os_microseconds_now();
fn f64 os_seconds_now();
fn u32 os_unix_time_now();
fn os_date_t os_local_time_to_universal_time();
fn os_date_t os_universal_time_to_local_time();
fn void os_sleep_milliseconds();
fn s8_t os_list_files(arena, path, recursive);
fn os_file_iter_t os_iterate_files();
fn void os_advance()
fn b32 os_is_valid();
fn s8_t os_read_file(ma_arena_t *arena, s8_t path);
fn void os_write_file(s8_t path, s8_t content);
fn void os_make_dir(s8_t path);
fn os_result_t os_copy_file(s8_t from, s8_t to, b32 overwrite);
fn os_result_t os_delete_file(s8_t path);
fn i64 os_get_file_mod_time(s8_t path);
fn b32 os_path_exists(s8_t path);
fn b32 os_path_is_dir(s8_t path);
fn b32 os_path_is_file(s8_t path);
fn b32 os_path_is_abs(s8_t path);
fn b32 os_path_is_rel(s8_t path);
fn s8_t os_path_to_abs(ma_arena_t *arena, s8_t path);
fn s8_t os_path_exe(ma_arena_t *arena);
fn s8_t os_path_exe_dir(ma_arena_t *arena);
fn s8_t os_path_cwd(ma_arena_t *arena);
fn void os_path_set_cwd(s8_t path);
#endif

View File

@@ -1,4 +1,4 @@
fn os_date_t os_date_now(void) {
fn os_date_t os_local_time_now(void) {
os_date_t result = {0};
time_t time = time(NULL);
struct tm *lt = localtime(&time);

View File

@@ -1,4 +1,20 @@
fn os_date_t os_date_now(void) {
os_date_t result = {0}; // don't need timed logs in browser
fn_wasm_import void wasm_local_time_now(void *buff, i32 size);
fn_wasm_import void wasm_universal_time_now(void *buff, i32 size);
fn_wasm_import f64 wasm_milliseconds_now(void);
fn os_date_t os_local_time_now(void) {
os_date_t result = {0};
wasm_local_time_now(&result, sizeof(result));
return result;
}
fn os_date_t os_universal_time_now(void) {
os_date_t result = {0};
wasm_universal_time_now(&result, sizeof(result));
return result;
}
fn f64 os_milliseconds_now(void) {
return wasm_milliseconds_now();
}

View File

@@ -1,4 +1,4 @@
fn os_date_t os_date_now(void) {
fn os_date_t os_local_time_now(void) {
os_date_t result = {0};
SYSTEMTIME lt;
GetLocalTime(&lt);