wasm app
This commit is contained in:
@@ -264,11 +264,9 @@ type_t type__app_event_t = { type_kind_struct, s8_const_lit("app_event_t"), size
|
||||
{.name = s8_const_lit("shift"), .type = &type__b8, .offset = offsetof(app_event_t, shift)},
|
||||
{.name = s8_const_lit("alt"), .type = &type__b8, .offset = offsetof(app_event_t, alt)},
|
||||
{.name = s8_const_lit("meta"), .type = &type__b8, .offset = offsetof(app_event_t, meta)},
|
||||
{.name = s8_const_lit("time"), .type = &type__f64, .offset = offsetof(app_event_t, time)},
|
||||
{.name = s8_const_lit("delta_time"), .type = &type__f64, .offset = offsetof(app_event_t, delta_time)},
|
||||
{.name = s8_const_lit("dpr"), .type = &type__f64, .offset = offsetof(app_event_t, dpr)},
|
||||
{.name = s8_const_lit("window_size"), .type = &type__v2f64_t, .offset = offsetof(app_event_t, window_size)},
|
||||
{.name = s8_const_lit("mouse_pos"), .type = &type__v2f64_t, .offset = offsetof(app_event_t, mouse_pos)},
|
||||
},
|
||||
.count = 14,
|
||||
.count = 12,
|
||||
};
|
||||
@@ -102,8 +102,6 @@ struct app_event_t {
|
||||
b8 shift;
|
||||
b8 alt;
|
||||
b8 meta;
|
||||
f64 time;
|
||||
f64 delta_time;
|
||||
f64 dpr;
|
||||
v2f64_t window_size;
|
||||
v2f64_t mouse_pos;
|
||||
|
||||
@@ -162,10 +162,10 @@ void meta_app(ma_arena_t *arena) {
|
||||
app_event_kind_t kind;
|
||||
|
||||
// data present only during events
|
||||
app_mouse_button_t mouse_button;
|
||||
app_key_t key;
|
||||
s8_t text;
|
||||
v3f64_t mouse_wheel_delta;
|
||||
app_mouse_button_t mouse_button; // @mouse_down @mouse_up
|
||||
app_key_t key; // @key_down @key_up
|
||||
s8_t text; // @text
|
||||
v3f64_t mouse_wheel_delta; // @mouse_wheel
|
||||
|
||||
// always present data
|
||||
b8 ctrl;
|
||||
@@ -173,9 +173,6 @@ void meta_app(ma_arena_t *arena) {
|
||||
b8 alt;
|
||||
b8 meta;
|
||||
|
||||
f64 time;
|
||||
f64 delta_time;
|
||||
|
||||
f64 dpr;
|
||||
v2f64_t window_size;
|
||||
v2f64_t mouse_pos;
|
||||
|
||||
@@ -1,13 +1,51 @@
|
||||
/*
|
||||
|
||||
.doesn't miss events (always processes all key strokes and buttons etc.)
|
||||
.replayable / deterministic (that is you can serialize all the events, replay them back and get the same results)
|
||||
..rendering and update decoupled
|
||||
.sleeps properly when nothing is happening
|
||||
.animations probably then should be in the rendering part
|
||||
|
||||
void app_update(app_event_t *events, i32 event_count) {
|
||||
loop (events) update(it);
|
||||
|
||||
{
|
||||
app_event_t *ev = events + event_count - 1;
|
||||
f64 delta_time = app_anim_get_delta_time();
|
||||
f64 time = app_anim_get_time();
|
||||
animate(ev, delta_time, time);
|
||||
render(ev);
|
||||
}
|
||||
}
|
||||
|
||||
while (true) {
|
||||
app_event_t *events = NULL;
|
||||
if (animating) {
|
||||
events = poll_events(); // non-blocking
|
||||
} else {
|
||||
events = wait_for_events(); // blocking
|
||||
}
|
||||
app_update(events, event_count);
|
||||
|
||||
SwapBuffers(); // vsync block
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
glb_wasm_export char wasm_temp_buff1[128] = {[127] = 0x13};
|
||||
glb_wasm_export i32 wasm_temp_buff1_len = 127;
|
||||
glb_wasm_export char wasm_temp_buff2[128] = {[127] = 0x13};
|
||||
glb_wasm_export i32 wasm_temp_buff2_len = 127;
|
||||
|
||||
glb f64 wasm_dpr;
|
||||
glb ma_arena_t *wasm_input_text_arena;
|
||||
glb STACK(app_event_t, 64) wasm_events;
|
||||
glb b32 wasm_event_failed_to_queue;
|
||||
glb f64 wasm_last_time = 0;
|
||||
global f64 wasm_dpr;
|
||||
global ma_arena_t *wasm_input_text_arena;
|
||||
global STACK(app_event_t, 64) wasm_events;
|
||||
global b32 wasm_event_failed_to_queue;
|
||||
|
||||
global f64 wasm_delta_time;
|
||||
global f64 wasm_time;
|
||||
global f64 wasm_last_time_milliseconds;
|
||||
global f64 wasm_app_init_time_milliseconds;
|
||||
|
||||
typedef struct wasm_cached_t wasm_cached_t;
|
||||
struct wasm_cached_t {
|
||||
@@ -141,10 +179,12 @@ fn_wasm_export void wasm_key_up(char *key, b32 ctrl, b32 shift, b32 alt, b32 met
|
||||
}
|
||||
}
|
||||
|
||||
fn_wasm_export void wasm_update(f64 time, f64 width, f64 height, f64 dpr) {
|
||||
f64 delta_time = (time - wasm_last_time);
|
||||
v2f64_t window_size = (v2f64_t){width / dpr, height / dpr};
|
||||
fn_wasm_export void wasm_update(f64 width, f64 height, f64 dpr) {
|
||||
wasm_time = os_get_milliseconds();
|
||||
wasm_delta_time = wasm_time - wasm_last_time_milliseconds;
|
||||
|
||||
v2f64_t window_size = (v2f64_t){width / dpr, height / dpr};
|
||||
wasm_dpr = dpr;
|
||||
|
||||
if (wasm_events.len == 0) {
|
||||
wasm_add_event((app_event_t){
|
||||
@@ -160,15 +200,12 @@ fn_wasm_export void wasm_update(f64 time, f64 width, f64 height, f64 dpr) {
|
||||
for (i32 i = 0; i < wasm_events.len; i += 1) {
|
||||
wasm_events.data[i].dpr = dpr;
|
||||
wasm_events.data[i].window_size = window_size;
|
||||
wasm_events.data[i].time = time;
|
||||
wasm_events.data[i].delta_time = delta_time;
|
||||
}
|
||||
wasm_dpr = dpr;
|
||||
|
||||
app_update(wasm_events.data, wasm_events.len);
|
||||
|
||||
wasm_events.len = 0;
|
||||
wasm_last_time = time;
|
||||
wasm_last_time_milliseconds = wasm_time;
|
||||
ma_set0(wasm_input_text_arena);
|
||||
}
|
||||
|
||||
@@ -176,4 +213,13 @@ fn_wasm_export void wasm_init(void) {
|
||||
core_init();
|
||||
wasm_input_text_arena = ma_push_arena(&tcx.perm, kib(1));
|
||||
app_init();
|
||||
wasm_app_init_time_milliseconds = os_get_milliseconds();
|
||||
}
|
||||
|
||||
fn f64 app_get_anim_time(void) {
|
||||
return wasm_time;
|
||||
}
|
||||
|
||||
fn f64 app_get_anim_delta_time(void) {
|
||||
return wasm_delta_time;
|
||||
}
|
||||
@@ -26,7 +26,7 @@ typedef double f64;
|
||||
#endif
|
||||
|
||||
#define fn
|
||||
#define glb
|
||||
#define global
|
||||
#define locl
|
||||
|
||||
#if PLATFORM_WASM
|
||||
@@ -53,10 +53,14 @@ typedef double f64;
|
||||
#define offsetof(st, m) ((usize)&(((st *)0)->m))
|
||||
#endif
|
||||
#define expect(x) if (!(x))
|
||||
#define unused(x) (void)(x)
|
||||
|
||||
#define kib(x) (1024ULL * (x##ULL))
|
||||
#define mib(x) (1024ULL * kib(x))
|
||||
#define gib(x) (1024ULL * mib(x))
|
||||
#define thousand(n) ((n)*1000)
|
||||
#define million(n) ((n)*1000000)
|
||||
#define billion(n) ((n)*1000000000)
|
||||
|
||||
#define DEFER_LOOP(begin, end) for (i32 PASTE(_i_, __LINE__) = (begin, 0); !PASTE(_i_, __LINE__); PASTE(_i_, __LINE__) += (end, 1))
|
||||
#define STACK(type, size) struct { type data[size]; i32 len; }
|
||||
|
||||
@@ -29,7 +29,7 @@ fn usize align_down(usize size, usize align) {
|
||||
fn void ma_init(ma_arena_t *arena, usize reserve) {
|
||||
reserve = align_up(reserve, ma_page_size);
|
||||
arena->align = ma_default_alignment;
|
||||
arena->data = (u8 *)vmem_reserve(reserve);
|
||||
arena->data = (u8 *)os_vmem_reserve(reserve);
|
||||
if (arena->data) {
|
||||
arena->reserve = reserve;
|
||||
}
|
||||
@@ -38,12 +38,12 @@ fn void ma_init(ma_arena_t *arena, usize reserve) {
|
||||
fn ma_arena_t *ma_create(usize reserve) {
|
||||
ma_arena_t *result = NULL;
|
||||
|
||||
void *data = vmem_reserve(reserve);
|
||||
void *data = os_vmem_reserve(reserve);
|
||||
if (!data) return result;
|
||||
|
||||
b32 success = vmem_commit(data, ma_page_size);
|
||||
b32 success = os_vmem_commit(data, ma_page_size);
|
||||
if (!success) {
|
||||
vmem_release(data);
|
||||
os_vmem_release(data);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ fn void *ma_push_size_ex(ma_arena_t *arena, usize size) {
|
||||
usize to_commit = new_len_aligned_to_page_size - arena->commit;
|
||||
usize to_commit_clamped = CLAMP_TOP(to_commit, arena->reserve);
|
||||
if (to_commit_clamped > 0) {
|
||||
b32 success = vmem_commit(arena->data + arena->commit, to_commit_clamped);
|
||||
b32 success = os_vmem_commit(arena->data + arena->commit, to_commit_clamped);
|
||||
if (success) {
|
||||
MA_ASAN_UNPOISON_MEMORY_REGION(arena->data + arena->commit, to_commit_clamped);
|
||||
arena->commit += to_commit_clamped;
|
||||
@@ -115,7 +115,7 @@ fn ma_arena_t *ma_push_arena(ma_arena_t *allocator, usize size) {
|
||||
fn void ma_destroy(ma_arena_t *arena) {
|
||||
if (arena == NULL || arena->data == NULL) return;
|
||||
b32 zero_memory = (u8 *)arena != arena->data;
|
||||
vmem_release(arena->data);
|
||||
os_vmem_release(arena->data);
|
||||
if (zero_memory) memory_zero(arena, sizeof(ma_arena_t));
|
||||
}
|
||||
|
||||
|
||||
@@ -257,7 +257,7 @@ fn lex_array_t lex_tokens(ma_arena_t *arena, char *file_name, s8_t stream) {
|
||||
return token_array;
|
||||
}
|
||||
|
||||
glb s8_t global_lex_kind_simple_strings[] = {
|
||||
global s8_t global_lex_kind_simple_strings[] = {
|
||||
#define X(KIND, STR, SIMPLE) s8_const_lit(SIMPLE),
|
||||
LEX_KIND_XLIST
|
||||
#undef X
|
||||
@@ -268,7 +268,7 @@ fn s8_t lex_kind_to_simple_s8(lex_kind_t kind) {
|
||||
return global_lex_kind_simple_strings[kind];
|
||||
}
|
||||
|
||||
glb s8_t global_lex_kind_strings[] = {
|
||||
global s8_t global_lex_kind_strings[] = {
|
||||
#define X(KIND, STR, SIMPLE) s8_const_lit(STR),
|
||||
LEX_KIND_XLIST
|
||||
#undef X
|
||||
|
||||
@@ -34,7 +34,7 @@ fn void default_log_proc(log_event_t ev) {
|
||||
b32 bdate = (tcx.log.flags & log_flag_date);
|
||||
b32 btime = (tcx.log.flags & log_flag_time);
|
||||
if (bdate || btime) {
|
||||
date = date_now();
|
||||
date = os_date_now();
|
||||
}
|
||||
if (bdate) {
|
||||
sb8_printf(sb, "%04u.%02u.%02u ", date.year, date.month, date.day);
|
||||
@@ -51,9 +51,9 @@ fn void default_log_proc(log_event_t ev) {
|
||||
s8_t result = sb8_serial_end(sb);
|
||||
|
||||
if (ev.level != log_level_fatal) {
|
||||
print_console_message(result.str);
|
||||
os_console_log(result.str);
|
||||
} else {
|
||||
print_error_message(result.str);
|
||||
os_error_box(result.str);
|
||||
#if PLATFORM_WASM
|
||||
debug_break();
|
||||
#else
|
||||
|
||||
@@ -63,7 +63,7 @@ fn void default_log_proc(log_event_t ev);
|
||||
|
||||
#define program_version "---"
|
||||
#if PLATFORM_DEBUG_ASSERT
|
||||
#define assert(x) (!(x) && (print_error_message(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, program version: " program_version "\n"), debug_break()))
|
||||
#else
|
||||
#define assert(x) (void)(x)
|
||||
#endif
|
||||
|
||||
@@ -205,9 +205,9 @@ union r3i64_t {
|
||||
|
||||
#define rgba_macro_const(r, g, b, a) { r / 255.0f, g / 255.0f, b / 255.0f, a / 255.0f }
|
||||
|
||||
glb v4f32_t primary_color_global = rgba_macro_const(245, 238, 230, 255);
|
||||
glb v4f32_t secondary_color_global = rgba_macro_const(255, 248, 227, 255);
|
||||
glb v4f32_t accent1_color_global = rgba_macro_const(243, 215, 202, 255);
|
||||
glb v4f32_t accent2_color_global = rgba_macro_const(230, 164, 180, 255);
|
||||
glb v4f32_t white_color_global = rgba_macro_const(255, 255, 255, 255);
|
||||
glb v4f32_t black_color_global = rgba_macro_const(0, 0, 0, 255);
|
||||
global v4f32_t primary_color_global = rgba_macro_const(245, 238, 230, 255);
|
||||
global v4f32_t secondary_color_global = rgba_macro_const(255, 248, 227, 255);
|
||||
global v4f32_t accent1_color_global = rgba_macro_const(243, 215, 202, 255);
|
||||
global v4f32_t accent2_color_global = rgba_macro_const(230, 164, 180, 255);
|
||||
global v4f32_t white_color_global = rgba_macro_const(255, 255, 255, 255);
|
||||
global v4f32_t black_color_global = rgba_macro_const(0, 0, 0, 255);
|
||||
|
||||
@@ -9,13 +9,13 @@ struct date_t {
|
||||
u16 year;
|
||||
};
|
||||
|
||||
fn void print_error_message(char *str);
|
||||
fn void print_console_message(char *str);
|
||||
fn date_t date_now(void);
|
||||
fn void os_error_box(char *str);
|
||||
fn void os_console_log(char *str);
|
||||
fn date_t os_date_now(void);
|
||||
|
||||
fn void *vmem_reserve(usize size);
|
||||
fn b32 vmem_commit(void *p, usize size);
|
||||
fn b32 vmem_release(void *p);
|
||||
fn b32 vmem_decommit(void *p, usize size);
|
||||
fn void *os_vmem_reserve(usize size);
|
||||
fn b32 os_vmem_commit(void *p, usize size);
|
||||
fn b32 os_vmem_release(void *p);
|
||||
fn b32 os_vmem_decommit(void *p, usize size);
|
||||
|
||||
fn void core_init(void); // required in wasm
|
||||
@@ -1,25 +1,25 @@
|
||||
fn void *vmem_reserve(usize size) {
|
||||
fn void *os_vmem_reserve(usize size) {
|
||||
void *result = mmap(0, size, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
|
||||
return result == MAP_FAILED ? NULL : result;
|
||||
}
|
||||
|
||||
fn b32 vmem_commit(void *p, usize size) {
|
||||
fn b32 os_vmem_commit(void *p, usize size) {
|
||||
mprotect(p, size, PROT_READ|PROT_WRITE);
|
||||
return true;
|
||||
}
|
||||
|
||||
fn b32 vmem_release(void *p) {
|
||||
fn b32 os_vmem_release(void *p) {
|
||||
void *result = munmap(ptr, size);
|
||||
return result == MAP_FAILED ? false : true;
|
||||
}
|
||||
|
||||
fn b32 vmem_decommit(void *p, usize size) {
|
||||
fn b32 os_vmem_decommit(void *p, usize size) {
|
||||
madvise(ptr, size, MADV_DONTNEED);
|
||||
mprotect(ptr, size, PROT_NONE);
|
||||
return true;
|
||||
}
|
||||
|
||||
fn date_t date_now(void) {
|
||||
fn date_t os_date_now(void) {
|
||||
date_t result = {0};
|
||||
time_t time = time(NULL);
|
||||
struct tm *lt = localtime(&time);
|
||||
@@ -32,11 +32,24 @@ fn date_t date_now(void) {
|
||||
return result;
|
||||
}
|
||||
|
||||
fn void print_error_message(char *str) {
|
||||
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;
|
||||
}
|
||||
|
||||
fn void os_error_box(char *str) {
|
||||
fprintf(stderr, "%s", str);
|
||||
}
|
||||
|
||||
fn void print_console_message(char *str) {
|
||||
fn void os_console_log(char *str) {
|
||||
puts(str);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,33 +1,36 @@
|
||||
fn_wasm_import void wasm_alert(isize ptr, i32 len);
|
||||
fn_wasm_import f64 wasm_parse_float(isize str, i32 len);
|
||||
fn_wasm_import void wasm_write_to_console(isize str, i32 len);
|
||||
fn_wasm_import f64 wasm_get_milliseconds(void);
|
||||
|
||||
fn void *vmem_reserve(usize size) {
|
||||
extern char __heap_base;
|
||||
|
||||
fn void *os_vmem_reserve(usize size) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
fn b32 vmem_commit(void *p, usize size) {
|
||||
fn b32 os_vmem_commit(void *p, usize size) {
|
||||
return false;
|
||||
}
|
||||
|
||||
fn b32 vmem_release(void *p) {
|
||||
fn b32 os_vmem_release(void *p) {
|
||||
return true;
|
||||
}
|
||||
|
||||
fn b32 vmem_decommit(void *p, usize size) {
|
||||
fn b32 os_vmem_decommit(void *p, usize size) {
|
||||
return true;
|
||||
}
|
||||
|
||||
fn date_t date_now(void) {
|
||||
fn date_t os_date_now(void) {
|
||||
date_t result = {0}; // don't need timed logs in browser
|
||||
return result;
|
||||
}
|
||||
|
||||
fn void print_error_message(char *str) {
|
||||
fn void os_error_box(char *str) {
|
||||
wasm_alert((isize)str, str_len(str));
|
||||
}
|
||||
|
||||
fn void print_console_message(char *str) {
|
||||
fn void os_console_log(char *str) {
|
||||
wasm_write_to_console((isize)str, str_len(str));
|
||||
}
|
||||
|
||||
@@ -36,7 +39,9 @@ fn double strtod(const char *str, char **end_unused) {
|
||||
return wasm_parse_float((isize)str, str_len((char *)str));
|
||||
}
|
||||
|
||||
extern char __heap_base;
|
||||
fn f64 os_get_milliseconds(void) {
|
||||
return wasm_get_milliseconds();
|
||||
}
|
||||
|
||||
fn void core_init(void) {
|
||||
isize page_size = kib(64);
|
||||
|
||||
@@ -1,24 +1,24 @@
|
||||
fn void *vmem_reserve(usize size) {
|
||||
fn void *os_vmem_reserve(usize size) {
|
||||
void *result = (uint8_t *)VirtualAlloc(0, size, MEM_RESERVE, PAGE_READWRITE);
|
||||
return result;
|
||||
}
|
||||
|
||||
fn b32 vmem_commit(void *p, usize size) {
|
||||
fn b32 os_vmem_commit(void *p, usize size) {
|
||||
void *result = VirtualAlloc(p, size, MEM_COMMIT, PAGE_READWRITE);
|
||||
return result ? true : false;
|
||||
}
|
||||
|
||||
fn b32 vmem_release(void *p) {
|
||||
fn b32 os_vmem_release(void *p) {
|
||||
BOOL result = VirtualFree(p, 0, MEM_RELEASE);
|
||||
return result ? true : false;
|
||||
}
|
||||
|
||||
fn b32 vmem_decommit(void *p, usize size) {
|
||||
fn b32 os_vmem_decommit(void *p, usize size) {
|
||||
BOOL result = VirtualFree(p, size, MEM_DECOMMIT);
|
||||
return result ? true : false;
|
||||
}
|
||||
|
||||
fn date_t date_now(void) {
|
||||
fn date_t os_date_now(void) {
|
||||
date_t result = {0};
|
||||
SYSTEMTIME lt;
|
||||
GetLocalTime(<);
|
||||
@@ -32,12 +32,37 @@ fn date_t date_now(void) {
|
||||
return result;
|
||||
}
|
||||
|
||||
fn void print_error_message(char *str) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
u64 result = 0;
|
||||
LARGE_INTEGER n;
|
||||
if (QueryPerformanceCounter(&n)) {
|
||||
result = (n.QuadPart*million(1))/win32_performance_frequency;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
fn f64 os_get_milliseconds(void) {
|
||||
u64 micros = os_get_microseconds();
|
||||
f64 result = (f64)micros / 1000.0;
|
||||
return result;
|
||||
}
|
||||
|
||||
fn void os_error_box(char *str) {
|
||||
MessageBoxA(NULL, str, "fatal error", MB_OK);
|
||||
fprintf(stderr, "%s", str);
|
||||
}
|
||||
|
||||
fn void print_console_message(char *str) {
|
||||
fn void os_console_log(char *str) {
|
||||
OutputDebugStringA(str);
|
||||
puts(str);
|
||||
}
|
||||
|
||||
@@ -69,47 +69,47 @@ fn type_member_t *ti_get_member(s8_t name, type_t *type);
|
||||
#define DEFINE_STRUCT(x) type_t type__##x = {type_kind_struct, s8_const_lit(#x), sizeof(x), .members = members__##x, .count = lengthof(members__##x)}
|
||||
#define POINTER(x) (type_t){type_kind_pointer, s8_const_lit(#x "*"), sizeof(void *), .base = &type__##x}
|
||||
|
||||
glb type_t type__i8 = {type_kind_i8, s8_const_lit("i8"), sizeof(i8)};
|
||||
glb type_t type__i16 = {type_kind_i16, s8_const_lit("i16"), sizeof(i16)};
|
||||
glb type_t type__i32 = {type_kind_i32, s8_const_lit("i32"), sizeof(i32)};
|
||||
glb type_t type__i64 = {type_kind_i64, s8_const_lit("i64"), sizeof(i64)};
|
||||
glb type_t type__u8 = {type_kind_u8, s8_const_lit("u8"), sizeof(u8)};
|
||||
glb type_t type__u16 = {type_kind_u16, s8_const_lit("u16"), sizeof(u16)};
|
||||
glb type_t type__u32 = {type_kind_u32, s8_const_lit("u32"), sizeof(u32)};
|
||||
glb type_t type__u64 = {type_kind_u64, s8_const_lit("u64"), sizeof(u64)};
|
||||
glb type_t type__b8 = {type_kind_b8, s8_const_lit("b8"), sizeof(b8)};
|
||||
glb type_t type__b16 = {type_kind_b16, s8_const_lit("b16"), sizeof(b16)};
|
||||
glb type_t type__b32 = {type_kind_b32, s8_const_lit("b32"), sizeof(b32)};
|
||||
glb type_t type__b64 = {type_kind_b64, s8_const_lit("b64"), sizeof(b64)};
|
||||
glb type_t type__f32 = {type_kind_f32, s8_const_lit("f32"), sizeof(f32)};
|
||||
glb type_t type__f64 = {type_kind_f64, s8_const_lit("f64"), sizeof(f64)};
|
||||
glb type_t type__isize = {type_kind_isize, s8_const_lit("isize"), sizeof(isize)};
|
||||
glb type_t type__usize = {type_kind_usize, s8_const_lit("usize"), sizeof(usize)};
|
||||
glb type_t type__int = {type_kind_int, s8_const_lit("int"), sizeof(int)};
|
||||
glb type_t type__char = {type_kind_char, s8_const_lit("char"), sizeof(char)};
|
||||
global type_t type__i8 = {type_kind_i8, s8_const_lit("i8"), sizeof(i8)};
|
||||
global type_t type__i16 = {type_kind_i16, s8_const_lit("i16"), sizeof(i16)};
|
||||
global type_t type__i32 = {type_kind_i32, s8_const_lit("i32"), sizeof(i32)};
|
||||
global type_t type__i64 = {type_kind_i64, s8_const_lit("i64"), sizeof(i64)};
|
||||
global type_t type__u8 = {type_kind_u8, s8_const_lit("u8"), sizeof(u8)};
|
||||
global type_t type__u16 = {type_kind_u16, s8_const_lit("u16"), sizeof(u16)};
|
||||
global type_t type__u32 = {type_kind_u32, s8_const_lit("u32"), sizeof(u32)};
|
||||
global type_t type__u64 = {type_kind_u64, s8_const_lit("u64"), sizeof(u64)};
|
||||
global type_t type__b8 = {type_kind_b8, s8_const_lit("b8"), sizeof(b8)};
|
||||
global type_t type__b16 = {type_kind_b16, s8_const_lit("b16"), sizeof(b16)};
|
||||
global type_t type__b32 = {type_kind_b32, s8_const_lit("b32"), sizeof(b32)};
|
||||
global type_t type__b64 = {type_kind_b64, s8_const_lit("b64"), sizeof(b64)};
|
||||
global type_t type__f32 = {type_kind_f32, s8_const_lit("f32"), sizeof(f32)};
|
||||
global type_t type__f64 = {type_kind_f64, s8_const_lit("f64"), sizeof(f64)};
|
||||
global type_t type__isize = {type_kind_isize, s8_const_lit("isize"), sizeof(isize)};
|
||||
global type_t type__usize = {type_kind_usize, s8_const_lit("usize"), sizeof(usize)};
|
||||
global type_t type__int = {type_kind_int, s8_const_lit("int"), sizeof(int)};
|
||||
global type_t type__char = {type_kind_char, s8_const_lit("char"), sizeof(char)};
|
||||
|
||||
glb type_t type__s8_t = { type_kind_struct, s8_const_lit("s8_t"), sizeof(s8_t), .count = 2,
|
||||
global type_t type__s8_t = { type_kind_struct, s8_const_lit("s8_t"), sizeof(s8_t), .count = 2,
|
||||
.members = (type_member_t[]){
|
||||
{s8_const_lit("str"), &POINTER(char), .offset = offsetof(s8_t, str)},
|
||||
{s8_const_lit("len"), &type__i64, .offset = offsetof(s8_t, len)},
|
||||
}
|
||||
};
|
||||
|
||||
glb type_t type__s16_t = { type_kind_struct, s8_const_lit("s16_t"), sizeof(s16_t), .count = 2,
|
||||
global type_t type__s16_t = { type_kind_struct, s8_const_lit("s16_t"), sizeof(s16_t), .count = 2,
|
||||
.members = (type_member_t[]){
|
||||
{s8_const_lit("str"), &POINTER(u16), .offset = offsetof(s16_t, str)},
|
||||
{s8_const_lit("len"), &type__i64, .offset = offsetof(s16_t, len)},
|
||||
}
|
||||
};
|
||||
|
||||
glb type_t type__s32_t = { type_kind_struct, s8_const_lit("s32_t"), sizeof(s32_t), .count = 2,
|
||||
global type_t type__s32_t = { type_kind_struct, s8_const_lit("s32_t"), sizeof(s32_t), .count = 2,
|
||||
.members = (type_member_t[]){
|
||||
{s8_const_lit("str"), &POINTER(u32), .offset = offsetof(s32_t, str)},
|
||||
{s8_const_lit("len"), &type__i64, .offset = offsetof(s32_t, len)},
|
||||
}
|
||||
};
|
||||
|
||||
glb type_t type__ma_arena_t = { type_kind_struct, s8_const_lit("ma_arena_t"), sizeof(ma_arena_t), .count = 6,
|
||||
global type_t type__ma_arena_t = { type_kind_struct, s8_const_lit("ma_arena_t"), sizeof(ma_arena_t), .count = 6,
|
||||
.members = (type_member_t[]){
|
||||
{s8_const_lit("data"), &POINTER(u8), .offset = offsetof(ma_arena_t, data)},
|
||||
{s8_const_lit("len"), &type__usize, .offset = offsetof(ma_arena_t, len)},
|
||||
@@ -120,21 +120,21 @@ glb type_t type__ma_arena_t = { type_kind_struct, s8_const_lit("ma_arena_t"), si
|
||||
}
|
||||
};
|
||||
|
||||
glb type_t type__ma_temp_t = { type_kind_struct, s8_const_lit("ma_temp_t"), sizeof(ma_temp_t), .count = 2,
|
||||
global type_t type__ma_temp_t = { type_kind_struct, s8_const_lit("ma_temp_t"), sizeof(ma_temp_t), .count = 2,
|
||||
.members = (type_member_t[]){
|
||||
{s8_const_lit("arena"), &POINTER(ma_arena_t), .offset = offsetof(ma_temp_t, arena)},
|
||||
{s8_const_lit("len"), &type__usize, .offset = offsetof(ma_temp_t, len)},
|
||||
}
|
||||
};
|
||||
|
||||
glb type_t type__v2f32_t = { type_kind_struct, s8_const_lit("v2f32_t"), sizeof(v2f32_t), .count = 2,
|
||||
global type_t type__v2f32_t = { type_kind_struct, s8_const_lit("v2f32_t"), sizeof(v2f32_t), .count = 2,
|
||||
.members = (type_member_t[]){
|
||||
{s8_const_lit("x"), &type__f32, .offset = offsetof(v2f32_t, x)},
|
||||
{s8_const_lit("y"), &type__f32, .offset = offsetof(v2f32_t, y)},
|
||||
}
|
||||
};
|
||||
|
||||
glb type_t type__v3f32_t = { type_kind_struct, s8_const_lit("v3f32_t"), sizeof(v3f32_t), .count = 3,
|
||||
global type_t type__v3f32_t = { type_kind_struct, s8_const_lit("v3f32_t"), sizeof(v3f32_t), .count = 3,
|
||||
.members = (type_member_t[]){
|
||||
{s8_const_lit("x"), &type__f32, .offset = offsetof(v3f32_t, x)},
|
||||
{s8_const_lit("y"), &type__f32, .offset = offsetof(v3f32_t, y)},
|
||||
@@ -142,7 +142,7 @@ glb type_t type__v3f32_t = { type_kind_struct, s8_const_lit("v3f32_t"), sizeof(v
|
||||
}
|
||||
};
|
||||
|
||||
glb type_t type__v4f32_t = { type_kind_struct, s8_const_lit("v4f32_t"), sizeof(v4f32_t), .count = 4,
|
||||
global type_t type__v4f32_t = { type_kind_struct, s8_const_lit("v4f32_t"), sizeof(v4f32_t), .count = 4,
|
||||
.members = (type_member_t[]){
|
||||
{s8_const_lit("x"), &type__f32, .offset = offsetof(v4f32_t, x)},
|
||||
{s8_const_lit("y"), &type__f32, .offset = offsetof(v4f32_t, y)},
|
||||
@@ -151,7 +151,7 @@ glb type_t type__v4f32_t = { type_kind_struct, s8_const_lit("v4f32_t"), sizeof(v
|
||||
}
|
||||
};
|
||||
|
||||
glb type_t type__r3f32_t = { type_kind_struct, s8_const_lit("r3f32_t"), sizeof(r3f32_t), .count = 6,
|
||||
global type_t type__r3f32_t = { type_kind_struct, s8_const_lit("r3f32_t"), sizeof(r3f32_t), .count = 6,
|
||||
.members = (type_member_t[]){
|
||||
{s8_const_lit("x0"), &type__f32, .offset = offsetof(r3f32_t, x0)},
|
||||
{s8_const_lit("y0"), &type__f32, .offset = offsetof(r3f32_t, y0)},
|
||||
@@ -162,28 +162,28 @@ glb type_t type__r3f32_t = { type_kind_struct, s8_const_lit("r3f32_t"), sizeof(r
|
||||
}
|
||||
};
|
||||
|
||||
glb type_member_t members__r2f32_t[] = {
|
||||
global type_member_t members__r2f32_t[] = {
|
||||
{s8_const_lit("x0"), &type__f32, .offset = offsetof(r2f32_t, x0)},
|
||||
{s8_const_lit("y0"), &type__f32, .offset = offsetof(r2f32_t, y0)},
|
||||
{s8_const_lit("x1"), &type__f32, .offset = offsetof(r2f32_t, x1)},
|
||||
{s8_const_lit("y1"), &type__f32, .offset = offsetof(r2f32_t, y1)},
|
||||
};
|
||||
glb DEFINE_STRUCT(r2f32_t);
|
||||
global DEFINE_STRUCT(r2f32_t);
|
||||
|
||||
glb type_member_t members__r1f32_t[] = {
|
||||
global type_member_t members__r1f32_t[] = {
|
||||
{s8_const_lit("x0"), &type__f32, .offset = offsetof(r1f32_t, x0)},
|
||||
{s8_const_lit("x1"), &type__f32, .offset = offsetof(r1f32_t, x1)},
|
||||
};
|
||||
glb DEFINE_STRUCT(r1f32_t);
|
||||
global DEFINE_STRUCT(r1f32_t);
|
||||
|
||||
glb type_t type__v2f64_t = { type_kind_struct, s8_const_lit("v2f64_t"), sizeof(v2f64_t), .count = 2,
|
||||
global type_t type__v2f64_t = { type_kind_struct, s8_const_lit("v2f64_t"), sizeof(v2f64_t), .count = 2,
|
||||
.members = (type_member_t[]){
|
||||
{s8_const_lit("x"), &type__f64, .offset = offsetof(v2f64_t, x)},
|
||||
{s8_const_lit("y"), &type__f64, .offset = offsetof(v2f64_t, y)},
|
||||
}
|
||||
};
|
||||
|
||||
glb type_t type__v3f64_t = { type_kind_struct, s8_const_lit("v3f64_t"), sizeof(v3f64_t), .count = 3,
|
||||
global type_t type__v3f64_t = { type_kind_struct, s8_const_lit("v3f64_t"), sizeof(v3f64_t), .count = 3,
|
||||
.members = (type_member_t[]){
|
||||
{s8_const_lit("x"), &type__f64, .offset = offsetof(v3f64_t, x)},
|
||||
{s8_const_lit("y"), &type__f64, .offset = offsetof(v3f64_t, y)},
|
||||
@@ -191,7 +191,7 @@ glb type_t type__v3f64_t = { type_kind_struct, s8_const_lit("v3f64_t"), sizeof(v
|
||||
}
|
||||
};
|
||||
|
||||
glb type_t type__v4f64_t = { type_kind_struct, s8_const_lit("v4f64_t"), sizeof(v4f64_t), .count = 4,
|
||||
global type_t type__v4f64_t = { type_kind_struct, s8_const_lit("v4f64_t"), sizeof(v4f64_t), .count = 4,
|
||||
.members = (type_member_t[]){
|
||||
{s8_const_lit("x"), &type__f64, .offset = offsetof(v4f64_t, x)},
|
||||
{s8_const_lit("y"), &type__f64, .offset = offsetof(v4f64_t, y)},
|
||||
@@ -200,7 +200,7 @@ glb type_t type__v4f64_t = { type_kind_struct, s8_const_lit("v4f64_t"), sizeof(v
|
||||
}
|
||||
};
|
||||
|
||||
glb type_t type__r3f64_t = { type_kind_struct, s8_const_lit("r3f64_t"), sizeof(r3f64_t), .count = 6,
|
||||
global type_t type__r3f64_t = { type_kind_struct, s8_const_lit("r3f64_t"), sizeof(r3f64_t), .count = 6,
|
||||
.members = (type_member_t[]){
|
||||
{s8_const_lit("x0"), &type__f64, .offset = offsetof(r3f64_t, x0)},
|
||||
{s8_const_lit("y0"), &type__f64, .offset = offsetof(r3f64_t, y0)},
|
||||
@@ -211,28 +211,28 @@ glb type_t type__r3f64_t = { type_kind_struct, s8_const_lit("r3f64_t"), sizeof(r
|
||||
}
|
||||
};
|
||||
|
||||
glb type_member_t members__r2f64_t[] = {
|
||||
global type_member_t members__r2f64_t[] = {
|
||||
{s8_const_lit("x0"), &type__f64, .offset = offsetof(r2f64_t, x0)},
|
||||
{s8_const_lit("y0"), &type__f64, .offset = offsetof(r2f64_t, y0)},
|
||||
{s8_const_lit("x1"), &type__f64, .offset = offsetof(r2f64_t, x1)},
|
||||
{s8_const_lit("y1"), &type__f64, .offset = offsetof(r2f64_t, y1)},
|
||||
};
|
||||
glb DEFINE_STRUCT(r2f64_t);
|
||||
global DEFINE_STRUCT(r2f64_t);
|
||||
|
||||
glb type_member_t members__r1f64_t[] = {
|
||||
global type_member_t members__r1f64_t[] = {
|
||||
{s8_const_lit("x0"), &type__f64, .offset = offsetof(r1f64_t, x0)},
|
||||
{s8_const_lit("x1"), &type__f64, .offset = offsetof(r1f64_t, x1)},
|
||||
};
|
||||
glb DEFINE_STRUCT(r1f64_t);
|
||||
global DEFINE_STRUCT(r1f64_t);
|
||||
|
||||
glb type_t type__v2i32_t = { type_kind_struct, s8_const_lit("v2i32_t"), sizeof(v2i32_t), .count = 2,
|
||||
global type_t type__v2i32_t = { type_kind_struct, s8_const_lit("v2i32_t"), sizeof(v2i32_t), .count = 2,
|
||||
.members = (type_member_t[]){
|
||||
{s8_const_lit("x"), &type__i32, .offset = offsetof(v2i32_t, x)},
|
||||
{s8_const_lit("y"), &type__i32, .offset = offsetof(v2i32_t, y)},
|
||||
}
|
||||
};
|
||||
|
||||
glb type_t type__v3i32_t = { type_kind_struct, s8_const_lit("v3i32_t"), sizeof(v3i32_t), .count = 3,
|
||||
global type_t type__v3i32_t = { type_kind_struct, s8_const_lit("v3i32_t"), sizeof(v3i32_t), .count = 3,
|
||||
.members = (type_member_t[]){
|
||||
{s8_const_lit("x"), &type__i32, .offset = offsetof(v3i32_t, x)},
|
||||
{s8_const_lit("y"), &type__i32, .offset = offsetof(v3i32_t, y)},
|
||||
@@ -240,7 +240,7 @@ glb type_t type__v3i32_t = { type_kind_struct, s8_const_lit("v3i32_t"), sizeof(v
|
||||
}
|
||||
};
|
||||
|
||||
glb type_t type__v4i32_t = { type_kind_struct, s8_const_lit("v4i32_t"), sizeof(v4i32_t), .count = 4,
|
||||
global type_t type__v4i32_t = { type_kind_struct, s8_const_lit("v4i32_t"), sizeof(v4i32_t), .count = 4,
|
||||
.members = (type_member_t[]){
|
||||
{s8_const_lit("x"), &type__i32, .offset = offsetof(v4i32_t, x)},
|
||||
{s8_const_lit("y"), &type__i32, .offset = offsetof(v4i32_t, y)},
|
||||
@@ -249,7 +249,7 @@ glb type_t type__v4i32_t = { type_kind_struct, s8_const_lit("v4i32_t"), sizeof(v
|
||||
}
|
||||
};
|
||||
|
||||
glb type_t type__r3i32_t = { type_kind_struct, s8_const_lit("r3i32_t"), sizeof(r3i32_t), .count = 6,
|
||||
global type_t type__r3i32_t = { type_kind_struct, s8_const_lit("r3i32_t"), sizeof(r3i32_t), .count = 6,
|
||||
.members = (type_member_t[]){
|
||||
{s8_const_lit("x0"), &type__i32, .offset = offsetof(r3i32_t, x0)},
|
||||
{s8_const_lit("y0"), &type__i32, .offset = offsetof(r3i32_t, y0)},
|
||||
@@ -260,29 +260,29 @@ glb type_t type__r3i32_t = { type_kind_struct, s8_const_lit("r3i32_t"), sizeof(r
|
||||
}
|
||||
};
|
||||
|
||||
glb type_member_t members__r2i32_t[] = {
|
||||
global type_member_t members__r2i32_t[] = {
|
||||
{s8_const_lit("x0"), &type__i32, .offset = offsetof(r2i32_t, x0)},
|
||||
{s8_const_lit("y0"), &type__i32, .offset = offsetof(r2i32_t, y0)},
|
||||
{s8_const_lit("x1"), &type__i32, .offset = offsetof(r2i32_t, x1)},
|
||||
{s8_const_lit("y1"), &type__i32, .offset = offsetof(r2i32_t, y1)},
|
||||
};
|
||||
glb DEFINE_STRUCT(r2i32_t);
|
||||
global DEFINE_STRUCT(r2i32_t);
|
||||
|
||||
glb type_member_t members__r1i32_t[] = {
|
||||
global type_member_t members__r1i32_t[] = {
|
||||
{s8_const_lit("x0"), &type__i32, .offset = offsetof(r1i32_t, x0)},
|
||||
{s8_const_lit("x1"), &type__i32, .offset = offsetof(r1i32_t, x1)},
|
||||
};
|
||||
glb DEFINE_STRUCT(r1i32_t);
|
||||
global DEFINE_STRUCT(r1i32_t);
|
||||
|
||||
|
||||
glb type_t type__v2i64_t = { type_kind_struct, s8_const_lit("v2i64_t"), sizeof(v2i64_t), .count = 2,
|
||||
global type_t type__v2i64_t = { type_kind_struct, s8_const_lit("v2i64_t"), sizeof(v2i64_t), .count = 2,
|
||||
.members = (type_member_t[]){
|
||||
{s8_const_lit("x"), &type__i64, .offset = offsetof(v2i64_t, x)},
|
||||
{s8_const_lit("y"), &type__i64, .offset = offsetof(v2i64_t, y)},
|
||||
}
|
||||
};
|
||||
|
||||
glb type_t type__v3i64_t = { type_kind_struct, s8_const_lit("v3i64_t"), sizeof(v3i64_t), .count = 3,
|
||||
global type_t type__v3i64_t = { type_kind_struct, s8_const_lit("v3i64_t"), sizeof(v3i64_t), .count = 3,
|
||||
.members = (type_member_t[]){
|
||||
{s8_const_lit("x"), &type__i64, .offset = offsetof(v3i64_t, x)},
|
||||
{s8_const_lit("y"), &type__i64, .offset = offsetof(v3i64_t, y)},
|
||||
@@ -290,7 +290,7 @@ glb type_t type__v3i64_t = { type_kind_struct, s8_const_lit("v3i64_t"), sizeof(v
|
||||
}
|
||||
};
|
||||
|
||||
glb type_t type__v4i64_t = { type_kind_struct, s8_const_lit("v4i64_t"), sizeof(v4i64_t), .count = 4,
|
||||
global type_t type__v4i64_t = { type_kind_struct, s8_const_lit("v4i64_t"), sizeof(v4i64_t), .count = 4,
|
||||
.members = (type_member_t[]){
|
||||
{s8_const_lit("x"), &type__i64, .offset = offsetof(v4i64_t, x)},
|
||||
{s8_const_lit("y"), &type__i64, .offset = offsetof(v4i64_t, y)},
|
||||
@@ -299,7 +299,7 @@ glb type_t type__v4i64_t = { type_kind_struct, s8_const_lit("v4i64_t"), sizeof(v
|
||||
}
|
||||
};
|
||||
|
||||
glb type_t type__r3i64_t = { type_kind_struct, s8_const_lit("r3i64_t"), sizeof(r3i64_t), .count = 6,
|
||||
global type_t type__r3i64_t = { type_kind_struct, s8_const_lit("r3i64_t"), sizeof(r3i64_t), .count = 6,
|
||||
.members = (type_member_t[]){
|
||||
{s8_const_lit("x0"), &type__i64, .offset = offsetof(r3i64_t, x0)},
|
||||
{s8_const_lit("y0"), &type__i64, .offset = offsetof(r3i64_t, y0)},
|
||||
@@ -310,35 +310,35 @@ glb type_t type__r3i64_t = { type_kind_struct, s8_const_lit("r3i64_t"), sizeof(r
|
||||
}
|
||||
};
|
||||
|
||||
glb type_member_t members__r2i64_t[] = {
|
||||
global type_member_t members__r2i64_t[] = {
|
||||
{s8_const_lit("x0"), &type__i64, .offset = offsetof(r2i64_t, x0)},
|
||||
{s8_const_lit("y0"), &type__i64, .offset = offsetof(r2i64_t, y0)},
|
||||
{s8_const_lit("x1"), &type__i64, .offset = offsetof(r2i64_t, x1)},
|
||||
{s8_const_lit("y1"), &type__i64, .offset = offsetof(r2i64_t, y1)},
|
||||
};
|
||||
glb DEFINE_STRUCT(r2i64_t);
|
||||
global DEFINE_STRUCT(r2i64_t);
|
||||
|
||||
glb type_member_t members__r1i64_t[] = {
|
||||
global type_member_t members__r1i64_t[] = {
|
||||
{s8_const_lit("x0"), &type__i64, .offset = offsetof(r1i64_t, x0)},
|
||||
{s8_const_lit("x1"), &type__i64, .offset = offsetof(r1i64_t, x1)},
|
||||
};
|
||||
glb DEFINE_STRUCT(r1i64_t);
|
||||
global DEFINE_STRUCT(r1i64_t);
|
||||
|
||||
glb type_member_t members__lex_kind_t[] = {
|
||||
global type_member_t members__lex_kind_t[] = {
|
||||
#define X(KIND, STR, SIMPLE) {.name = s8_const_lit("lex_kind_" #KIND), .value = lex_kind_##KIND},
|
||||
LEX_KIND_XLIST
|
||||
#undef X
|
||||
};
|
||||
DEFINE_ENUM(lex_kind_t);
|
||||
|
||||
glb type_member_t members__lex_suffix_t[] = {
|
||||
global type_member_t members__lex_suffix_t[] = {
|
||||
#define X(KIND) {.name = s8_const_lit("lex_suffix_" #KIND), .value = lex_suffix_##KIND},
|
||||
LEX_SUFFIX_XLIST
|
||||
#undef X
|
||||
};
|
||||
DEFINE_ENUM(lex_suffix_t);
|
||||
|
||||
glb type_member_t members__log_level_t[] = {
|
||||
global type_member_t members__log_level_t[] = {
|
||||
{.name = s8_const_lit("log_level_debug"), .value = log_level_debug},
|
||||
{.name = s8_const_lit("log_level_info"), .value = log_level_info},
|
||||
{.name = s8_const_lit("log_level_warning"), .value = log_level_warning},
|
||||
|
||||
@@ -5,7 +5,7 @@ fn_wasm_import f64 wasm_measure_text(isize str, i32 len, isize font_str, i32 fo
|
||||
fn_wasm_import f64 wasm_get_font_height(isize font_str, i32 font_len, i32 font_size);
|
||||
fn_wasm_import void wasm_set_clip(f64 x, f64 y, f64 w, f64 h);
|
||||
|
||||
glb s8_t font_face = s8_const_lit("open_sans_regular");
|
||||
global s8_t font_face = s8_const_lit("open_sans_regular");
|
||||
|
||||
|
||||
fn void set_clip(r2f64_t rect) {
|
||||
@@ -52,17 +52,17 @@ typedef enum {
|
||||
|
||||
typedef struct gfx2d_cmd_t gfx2d_cmd_t;
|
||||
struct gfx2d_cmd_t {
|
||||
gfx2d_cmd_t *next;
|
||||
gfx2d_kind_t kind;
|
||||
r2f64_t rect;
|
||||
v4f32_t color;
|
||||
s8_t text;
|
||||
r2f64_t rect;
|
||||
v4f32_t color;
|
||||
s8_t text;
|
||||
};
|
||||
|
||||
typedef struct gfx2d_t gfx2d_t;
|
||||
struct gfx2d_t {
|
||||
ma_arena_t *ma;
|
||||
gfx2d_cmd_t *cmds;
|
||||
i32 cmds_len;
|
||||
gfx2d_cmd_t *first;
|
||||
gfx2d_cmd_t *last;
|
||||
app_event_t *ev;
|
||||
};
|
||||
|
||||
@@ -73,9 +73,7 @@ void gfx2d_begin(gfx2d_t *gfx, app_event_t *ev) {
|
||||
void gfx2d_end(gfx2d_t *gfx) {
|
||||
app_event_t *ev = gfx->ev;
|
||||
r2f64_t window = (r2f64_t){0, 0, ev->window_size.x, ev->window_size.y};
|
||||
for (i32 i = 0; i < gfx->cmds_len; i += 1) {
|
||||
gfx2d_cmd_t *cmd = gfx->cmds + i;
|
||||
|
||||
for (gfx2d_cmd_t *cmd = gfx->first; cmd; cmd = cmd->next) {
|
||||
if (cmd->kind == gfx2d_kind_clear) {
|
||||
wasm_clear();
|
||||
draw_rect(window, cmd->color);
|
||||
@@ -90,15 +88,13 @@ void gfx2d_end(gfx2d_t *gfx) {
|
||||
}
|
||||
}
|
||||
|
||||
gfx->cmds_len = 0;
|
||||
ma_set0(gfx->ma);
|
||||
gfx->first = gfx->last = NULL;
|
||||
}
|
||||
|
||||
void gfx2d_add_cmd(gfx2d_t *gfx, gfx2d_cmd_t cmd) {
|
||||
gfx2d_cmd_t *c = ma_push_type(gfx->ma, gfx2d_cmd_t);
|
||||
gfx2d_cmd_t *c = ma_push_type(tcx.temp, gfx2d_cmd_t);
|
||||
*c = cmd;
|
||||
if (gfx->cmds_len == 0) gfx->cmds = c;
|
||||
gfx->cmds_len += 1;
|
||||
SLLQ_APPEND(gfx->first, gfx->last, c);
|
||||
}
|
||||
|
||||
void gfx2d_clear(gfx2d_t *gfx, v4f32_t color) {
|
||||
|
||||
@@ -3,51 +3,34 @@
|
||||
#include "app/app.h"
|
||||
#include "app/app.c"
|
||||
#include "gfx2d/gfx2d.c"
|
||||
#include "ui.c"
|
||||
// #include "ui.c"
|
||||
|
||||
gfx2d_t *gfx2d = NULL;
|
||||
|
||||
void app_init(void) {
|
||||
tcx.temp = ma_push_arena(&tcx.perm, mib(1));
|
||||
gfx2d = ma_push_type(&tcx.perm, gfx2d_t);
|
||||
gfx2d->ma = ma_push_arena(&tcx.perm, mib(2));
|
||||
}
|
||||
|
||||
void app_update(app_event_t *events, i32 event_count) {
|
||||
|
||||
// @todo: record render commands and replay
|
||||
// @todo: ignore render commands
|
||||
for (i32 i = 0; i < event_count - 1; i += 1) {
|
||||
ui_demo(gfx2d, events + i);
|
||||
gfx2d->cmds_len = 0;
|
||||
ma_set0(gfx2d->ma);
|
||||
}
|
||||
|
||||
{
|
||||
app_event_t *ev = &events[event_count - 1];
|
||||
|
||||
gfx2d_begin(gfx2d, ev);
|
||||
gfx2d_clear(gfx2d, white_color_global);
|
||||
ui_demo(gfx2d, ev);
|
||||
// gfx2d_textf(gfx2d, v2f64(0,0), black_color_global, "delta time: %f", ev->delta_time);
|
||||
gfx2d_end(gfx2d);
|
||||
}
|
||||
void app_update(app_event_t *events, i32 events_len) {
|
||||
ma_set0(tcx.temp);
|
||||
|
||||
|
||||
#if 0
|
||||
ma_scratch_scope(temp) {
|
||||
f64 offset = get_font_height() + 8;
|
||||
f64 pos = offset;
|
||||
for (i32 i = 0; i < event_count; i += 1) {
|
||||
s8_t string = ti_serial_data(temp.arena, events + i, app_event_t);
|
||||
sb8_t split = s8_split(temp.arena, string, s8_lit("\n"), s8_split_none);
|
||||
|
||||
for (sb8_node_t *it = split.first; it; it = it->next) {
|
||||
draw_text((v2f64_t){0, pos}, black_color_global, it->string);
|
||||
|
||||
pos += offset;
|
||||
}
|
||||
}
|
||||
for (app_event_t *ev = events; ev < (events + events_len); ev += 1) {
|
||||
// update(ev)
|
||||
}
|
||||
#endif
|
||||
|
||||
// These steps should be totally optional!!
|
||||
{
|
||||
app_event_t *ev = events + events_len - 1;
|
||||
f64 delta = app_get_anim_delta_time();
|
||||
f64 time = app_get_anim_time();
|
||||
|
||||
// animate
|
||||
// render
|
||||
gfx2d_begin(gfx2d, ev);
|
||||
gfx2d_clear(gfx2d, white_color_global);
|
||||
gfx2d_textf(gfx2d, (v2f64_t){0,0}, black_color_global, "delta: %f, time: %f", delta, time);
|
||||
gfx2d_end(gfx2d);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user