win32_app
This commit is contained in:
@@ -1,8 +1,15 @@
|
||||
typedef struct thread_ctx_t thread_ctx_t;
|
||||
struct thread_ctx_t {
|
||||
ma_arena_t scratch[3];
|
||||
ma_arena_t perm;
|
||||
ma_arena_t *temp; // application specific arena
|
||||
|
||||
// I probably want to discourage using it implicitly like: tcx.perm, instead just pass it around
|
||||
// to functions that allocate pernament memory. temp and scratch very nicely create reusable code
|
||||
// perm is basically global state so it would be nice to annotate which functions are reusable
|
||||
// and which functions have state
|
||||
ma_arena_t _perm;
|
||||
|
||||
|
||||
logger_t log;
|
||||
};
|
||||
|
||||
|
||||
@@ -63,7 +63,7 @@ fn void default_log_proc(log_event_t ev);
|
||||
|
||||
#define program_version "---"
|
||||
#if PLATFORM_DEBUG_ASSERT
|
||||
#define assert(x) (!(x) && (os_error_box(FILE_AND_LINE ": internal program error! assertion failed, program version: " program_version "\n"), debug_break()))
|
||||
#define assert(x) (!(x) && (os_error_box(FILE_AND_LINE ": internal program error! assertion failed: " #x ", program version: " program_version "\n"), debug_break()))
|
||||
#else
|
||||
#define assert(x) (void)(x)
|
||||
#endif
|
||||
|
||||
@@ -9,9 +9,27 @@ struct date_t {
|
||||
u16 year;
|
||||
};
|
||||
|
||||
#if 0
|
||||
typedef struct core_funcs_t core_funcs_t;
|
||||
struct core_funcs_t {
|
||||
void (*error_box)(char *str);
|
||||
void (*console_log)(char *str);
|
||||
|
||||
date_t (*date_now)(void);
|
||||
f64 (*milliseconds_now)(void);
|
||||
|
||||
void *(*reserve)(usize size);
|
||||
b32 (*commit)(void *p, usize size);
|
||||
b32 (*release)(void *p);
|
||||
b32 (*decommit)(void *p, usize size);
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
fn void os_error_box(char *str);
|
||||
fn void os_console_log(char *str);
|
||||
fn date_t os_date_now(void);
|
||||
fn f64 os_milliseconds_now(void);
|
||||
|
||||
fn void *os_vmem_reserve(usize size);
|
||||
fn b32 os_vmem_commit(void *p, usize size);
|
||||
|
||||
@@ -39,7 +39,7 @@ fn u64 os_get_microseconds(void) {
|
||||
return result;
|
||||
}
|
||||
|
||||
fn f64 os_get_milliseconds(void) {
|
||||
fn f64 os_milliseconds_now(void) {
|
||||
u64 micros = os_get_microseconds();
|
||||
f64 result = (f64)micros / 1000.0;
|
||||
return result;
|
||||
|
||||
@@ -39,7 +39,7 @@ fn double strtod(const char *str, char **end_unused) {
|
||||
return wasm_parse_float((isize)str, str_len((char *)str));
|
||||
}
|
||||
|
||||
fn f64 os_get_milliseconds(void) {
|
||||
fn f64 os_milliseconds_now(void) {
|
||||
return wasm_get_milliseconds();
|
||||
}
|
||||
|
||||
@@ -48,10 +48,10 @@ fn void core_init(void) {
|
||||
isize page_count = __builtin_wasm_memory_size(0);
|
||||
u8 *memory = (u8 *)&__heap_base;
|
||||
usize memory_size = page_count * (page_size) - (isize)memory;
|
||||
tcx.perm.data = memory;
|
||||
tcx.perm.commit = tcx.perm.reserve = memory_size;
|
||||
tcx._perm.data = memory;
|
||||
tcx._perm.commit = tcx._perm.reserve = memory_size;
|
||||
|
||||
ma_push_arena_ex(&tcx.perm, &tcx.scratch[0], mib(1));
|
||||
ma_push_arena_ex(&tcx.perm, &tcx.scratch[1], kib(256));
|
||||
ma_push_arena_ex(&tcx.perm, &tcx.scratch[2], kib(64));
|
||||
ma_push_arena_ex(&tcx._perm, &tcx.scratch[0], mib(1));
|
||||
ma_push_arena_ex(&tcx._perm, &tcx.scratch[1], kib(256));
|
||||
ma_push_arena_ex(&tcx._perm, &tcx.scratch[2], kib(64));
|
||||
}
|
||||
@@ -32,28 +32,23 @@ fn date_t os_date_now(void) {
|
||||
return result;
|
||||
}
|
||||
|
||||
global LARGE_INTEGER win32__performance_frequency;
|
||||
global u64 win32_performance_frequency = 1;
|
||||
|
||||
fn u64 os_get_microseconds(void) {
|
||||
if (win32__performance_frequency.QuadPart == 0) {
|
||||
win32__performance_frequency.QuadPart = 1; // don't query more then one time
|
||||
if(QueryPerformanceFrequency(&win32__performance_frequency)) {
|
||||
win32_performance_frequency = win32__performance_frequency.QuadPart;
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
u64 result = 0;
|
||||
LARGE_INTEGER n;
|
||||
if (QueryPerformanceCounter(&n)) {
|
||||
result = (n.QuadPart*million(1))/win32_performance_frequency;
|
||||
}
|
||||
LARGE_INTEGER time;
|
||||
QueryPerformanceCounter(&time);
|
||||
f64 result = (f64)time.QuadPart / (f64)counts_per_second;
|
||||
return result;
|
||||
}
|
||||
|
||||
fn f64 os_get_milliseconds(void) {
|
||||
u64 micros = os_get_microseconds();
|
||||
f64 result = (f64)micros / 1000.0;
|
||||
fn f64 os_milliseconds_now(void) {
|
||||
f64 secs = os_seconds_now();
|
||||
f64 result = secs * 1000;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user