small hto load improvements

This commit is contained in:
Krzosa Karol
2025-01-26 19:55:31 +01:00
parent 5d127b7f2c
commit 8ae6e15bf8
18 changed files with 197 additions and 216 deletions

View File

@@ -38,17 +38,28 @@ int main(int argc, char **argv) {
b32 run_server = false; b32 run_server = false;
b32 core_test_target = true; b32 core_test_target = true;
b32 win32_target = true; b32 win32_target = true;
b32 standalone_w32_target = false;
b32 wasm_target = false; b32 wasm_target = false;
if (run_server) { if (run_server) {
os_systemf("start /D ..\\package ..\\package\\run_server.bat"); os_systemf("start /D ..\\package ..\\package\\run_server.bat");
} }
if (standalone_w32_target && cache_code_modified(s8_lit("../src/wasm_app/main.c"), s8_lit("standalone_app.exe"))) {
ok = os_systemf(
"cl ../src/wasm_app/main.c -Fe:standalone_app.exe -Fd:standalone_app.pdb"
" -I ../src"
" /Zi /FC /nologo /Oi"
" /WX /W3 /wd4200 /diagnostics:column"
" /link /incremental:no /DEBUG:FULL"
);
if (ok != 0) return ok;
}
if (win32_target && cache_code_modified(s8_lit("../src/wasm_app/main.c"), s8_lit("app.dll"))) { if (win32_target && cache_code_modified(s8_lit("../src/wasm_app/main.c"), s8_lit("app.dll"))) {
os_delete_file(s8_lit("app_win32.pdb"));
ok = os_systemf( ok = os_systemf(
"cl ../src/wasm_app/main.c -Fe:app.dll -Fd:app.pdb" "cl ../src/wasm_app/main.c -Fe:app.dll -Fd:app.pdb"
" -I ../src" " -I ../src /DAPP_IS_DLL"
" /Zi /FC /nologo /Oi" " /Zi /FC /nologo /Oi"
" /WX /W3 /wd4200 /diagnostics:column" " /WX /W3 /wd4200 /diagnostics:column"
" /link /incremental:no /DEBUG:FULL /DLL" " /link /incremental:no /DEBUG:FULL /DLL"
@@ -57,7 +68,6 @@ int main(int argc, char **argv) {
} }
if (win32_target && cache_code_modified(s8_lit("../src/app/app_win32_exe.c"), s8_lit("app_win32.exe"))) { if (win32_target && cache_code_modified(s8_lit("../src/app/app_win32_exe.c"), s8_lit("app_win32.exe"))) {
// os_delete_file(s8_lit("app_win32.pdb"));
ok = os_systemf( ok = os_systemf(
"cl ../src/app/app_win32_exe.c -Fe:app_win32.exe -Fd:app_win32.pdb" "cl ../src/app/app_win32_exe.c -Fe:app_win32.exe -Fd:app_win32.pdb"
" -I ../src" " -I ../src"

View File

@@ -99,46 +99,8 @@ class memory_t {
const canvas = document.getElementById("canvas"); const canvas = document.getElementById("canvas");
const ctx2d = canvas.getContext('2d'); const ctx2d = canvas.getContext('2d');
const mem = new memory_t(new WebAssembly['Memory']({ initial: 2000, maximum: 65536 }));
(async function main() { const wasm_app_imports = {
if (!ctx2d) {
alert('Outdated browser, cant draw :(');
return;
}
const mem = new memory_t(new WebAssembly['Memory']({ initial: 2000, maximum: 65536 }));
const request = await fetch('main.wasm');
const binary = await request.arrayBuffer();
const wasm_os_imports = {
wasm_local_time_now: (ptr, len) => {
const date = new Date();
const stream = mem.stream_write(ptr, len);
stream.write_u16(date.getMilliseconds());
stream.write_u16(date.getSeconds());
stream.write_u16(date.getMinutes());
stream.write_u16(date.getHours());
stream.write_u16(date.getDate());
stream.write_u16(date.getMonth());
stream.write_u16(date.getFullYear());
},
wasm_universal_time_now: (ptr, len) => {
const date = new Date();
const stream = mem.stream_write(ptr, len);
stream.write_u16(date.getUTCMilliseconds());
stream.write_u16(date.getUTCSeconds());
stream.write_u16(date.getUTCMinutes());
stream.write_u16(date.getUTCHours());
stream.write_u16(date.getUTCDate());
stream.write_u16(date.getUTCMonth());
stream.write_u16(date.getUTCFullYear());
},
wasm_milliseconds_now: () => { return performance.now(); },
};
let wasm_app_imports = {
// core // core
memory: mem.mem, memory: mem.mem,
wasm_parse_float: (str, len) => { return parseFloat(mem.read_cstr(str, len)); }, wasm_parse_float: (str, len) => { return parseFloat(mem.read_cstr(str, len)); },
@@ -159,12 +121,6 @@ const ctx2d = canvas.getContext('2d');
const metrics = ctx2d.measureText(mem.read_cstr(str, len)); const metrics = ctx2d.measureText(mem.read_cstr(str, len));
return metrics.width; return metrics.width;
}, },
// wasm_get_font_height: (font_str, font_len, font_size) => {
// ctx2d.font = `${font_size}px ${mem.read_cstr(font_str, font_len)}`;
// ctx2d.textBaseline = "top";
// const v = ctx2d.measureText('NothinBelowTheBaseline');
// return v.fontBoundingBoxDescent;
// },
wasm_draw_rect: (x, y, w, h, r, g, b, a) => { wasm_draw_rect: (x, y, w, h, r, g, b, a) => {
ctx2d.beginPath(); ctx2d.beginPath();
ctx2d.rect(x, y, w, h); ctx2d.rect(x, y, w, h);
@@ -181,16 +137,21 @@ const ctx2d = canvas.getContext('2d');
ctx2d.rect(x, y, w, h); ctx2d.rect(x, y, w, h);
ctx2d.clip(); ctx2d.clip();
}, },
};
}; (async function main() {
if (!ctx2d) {
Object.assign(wasm_app_imports, wasm_os_imports); alert('Outdated browser, cant draw :(');
return;
}
const request = await fetch('main.wasm');
const binary = await request.arrayBuffer();
const program = await WebAssembly['instantiate'](binary, { "env": wasm_app_imports }); const program = await WebAssembly['instantiate'](binary, { "env": wasm_app_imports });
const instance = program['instance']; const instance = program['instance'];
const wasm_exports = instance['exports']; const wasm_exports = instance['exports'];
mem.exports = wasm_exports; mem.exports = wasm_exports;
wasm_exports['wasm_init'](window.devicePixelRatio); wasm_exports['wasm_init']();
let awake = true; let awake = true;

View File

@@ -1,7 +1,9 @@
#include "app.gen.c" #include "app.gen.c"
#if PLATFORM_WINDOWS #if PLATFORM_WINDOWS
#ifndef APP_IS_DLL
#include "app_win32.c" #include "app_win32.c"
#endif
#elif PLATFORM_WASM #elif PLATFORM_WASM
#include "app_wasm.c" #include "app_wasm.c"
#endif #endif

View File

@@ -276,16 +276,14 @@ type_t type__app_event_t = { type_kind_struct, s8_const_lit("app_event_t"), size
}; };
type_t type__app_frame_t = { type_kind_struct, s8_const_lit("app_frame_t"), sizeof(app_frame_t), type_t type__app_frame_t = { type_kind_struct, s8_const_lit("app_frame_t"), sizeof(app_frame_t),
.members = (type_member_t[]){ .members = (type_member_t[]){
{.name = s8_const_lit("next"), .type = &(type_t){type_kind_pointer, s8_const_lit("app_frame_t*"), sizeof(void *), .base = &type__app_frame_t}, .offset = offsetof(app_frame_t, next), .dont_serialize = 0},
{.name = s8_const_lit("delta"), .type = &type__f64, .offset = offsetof(app_frame_t, delta), .dont_serialize = 0},
{.name = s8_const_lit("dpr"), .type = &type__f32, .offset = offsetof(app_frame_t, dpr), .dont_serialize = 0},
{.name = s8_const_lit("frame"), .type = &type__u64, .offset = offsetof(app_frame_t, frame), .dont_serialize = 0},
{.name = s8_const_lit("window_size"), .type = &type__v2f32_t, .offset = offsetof(app_frame_t, window_size), .dont_serialize = 0}, {.name = s8_const_lit("window_size"), .type = &type__v2f32_t, .offset = offsetof(app_frame_t, window_size), .dont_serialize = 0},
{.name = s8_const_lit("mouse_pos"), .type = &type__v2f32_t, .offset = offsetof(app_frame_t, mouse_pos), .dont_serialize = 0}, {.name = s8_const_lit("mouse_pos"), .type = &type__v2f32_t, .offset = offsetof(app_frame_t, mouse_pos), .dont_serialize = 0},
{.name = s8_const_lit("dpr"), .type = &type__f32, .offset = offsetof(app_frame_t, dpr), .dont_serialize = 0},
{.name = s8_const_lit("delta"), .type = &type__f64, .offset = offsetof(app_frame_t, delta), .dont_serialize = 0},
{.name = s8_const_lit("frame"), .type = &type__u64, .offset = offsetof(app_frame_t, frame), .dont_serialize = 0},
{.name = s8_const_lit("event_count"), .type = &type__i32, .offset = offsetof(app_frame_t, event_count), .dont_serialize = 0}, {.name = s8_const_lit("event_count"), .type = &type__i32, .offset = offsetof(app_frame_t, event_count), .dont_serialize = 0},
{.name = s8_const_lit("first_event"), .type = &(type_t){type_kind_pointer, s8_const_lit("app_event_t*"), sizeof(void *), .base = &type__app_event_t}, .offset = offsetof(app_frame_t, first_event), .dont_serialize = 0}, {.name = s8_const_lit("first_event"), .type = &(type_t){type_kind_pointer, s8_const_lit("app_event_t*"), sizeof(void *), .base = &type__app_event_t}, .offset = offsetof(app_frame_t, first_event), .dont_serialize = 0},
{.name = s8_const_lit("last_event"), .type = &(type_t){type_kind_pointer, s8_const_lit("app_event_t*"), sizeof(void *), .base = &type__app_event_t}, .offset = offsetof(app_frame_t, last_event), .dont_serialize = 0}, {.name = s8_const_lit("last_event"), .type = &(type_t){type_kind_pointer, s8_const_lit("app_event_t*"), sizeof(void *), .base = &type__app_event_t}, .offset = offsetof(app_frame_t, last_event), .dont_serialize = 0},
{.name = s8_const_lit("update"), .type = &type__f64, .offset = offsetof(app_frame_t, update), .dont_serialize = 0},
}, },
.count = 10, .count = 8,
}; };

View File

@@ -113,14 +113,12 @@ struct app_event_t {
typedef struct app_frame_t app_frame_t; typedef struct app_frame_t app_frame_t;
struct app_frame_t { struct app_frame_t {
app_frame_t* next;
f64 delta;
f32 dpr;
u64 frame;
v2f32_t window_size; v2f32_t window_size;
v2f32_t mouse_pos; v2f32_t mouse_pos;
f32 dpr;
f64 delta;
u64 frame;
i32 event_count; i32 event_count;
app_event_t* first_event; app_event_t* first_event;
app_event_t* last_event; app_event_t* last_event;
f64 update;
}; };

View File

@@ -1,4 +1,8 @@
#include "app.gen.h" #include "app.gen.h"
typedef b32 app_update_t(thread_ctx_t *tcx, app_frame_t *frame); typedef b32 app_update_t(thread_ctx_t *tcx, app_frame_t *frame);
#if PLATFORM_WINDOWS
#define fn_export __declspec(dllexport) #define fn_export __declspec(dllexport)
#else
#define fn_export
#endif

View File

@@ -145,7 +145,7 @@ void mt_app(ma_arena_t *arena) {
typedef enum { typedef enum {
app_event_kind_null, app_event_kind_null,
app_event_kind_update, app_event_kind_update, // update is send when there are no events in a frame
app_event_kind_init, app_event_kind_init,
app_event_kind_reload, app_event_kind_reload,
app_event_kind_unload, app_event_kind_unload,
@@ -181,18 +181,16 @@ void mt_app(ma_arena_t *arena) {
typedef struct app_frame_t app_frame_t; typedef struct app_frame_t app_frame_t;
struct app_frame_t { struct app_frame_t {
app_frame_t *next;
f64 delta;
f32 dpr;
u64 frame;
v2f32_t window_size; v2f32_t window_size;
v2f32_t mouse_pos; v2f32_t mouse_pos;
f32 dpr;
f64 delta;
u64 frame;
i32 event_count; i32 event_count;
app_event_t *first_event; app_event_t *first_event;
app_event_t *last_event; app_event_t *last_event;
f64 update;
}; };
)); ));

View File

@@ -18,8 +18,12 @@ struct wasm_cached_t {
b8 ctrl, alt, shift; b8 ctrl, alt, shift;
} wasm_cached; } wasm_cached;
fn b32 app_update(app_frame_t *frame); fn b32 app_update(thread_ctx_t *ctx, app_frame_t *frame);
fn void app_init(f32 dpr);
fn void wasm_add_event_ex(app_frame_t *frame, app_event_t *ev) {
SLLQ_APPEND(wasm_frame.first_event, wasm_frame.last_event, ev);
wasm_frame.event_count += 1;
}
fn void wasm_add_event(app_event_t event) { fn void wasm_add_event(app_event_t event) {
app_event_t *ev = ma_push_type(tcx->temp, app_event_t); app_event_t *ev = ma_push_type(tcx->temp, app_event_t);
@@ -30,8 +34,7 @@ fn void wasm_add_event(app_event_t event) {
ev->shift = wasm_cached.shift; ev->shift = wasm_cached.shift;
ev->mouse_pos = wasm_cached.mouse_pos; ev->mouse_pos = wasm_cached.mouse_pos;
ev->mouse_delta = wasm_cached.mouse_delta; ev->mouse_delta = wasm_cached.mouse_delta;
SLLQ_APPEND(wasm_frame.first_event, wasm_frame.last_event, ev); wasm_add_event_ex(&wasm_frame, ev);
wasm_frame.event_count += 1;
} }
fn void wasm_set_cached_mouse(v2f32_t p) { fn void wasm_set_cached_mouse(v2f32_t p) {
@@ -126,13 +129,22 @@ fn_wasm_export b32 wasm_update(f64 time, f32 width, f32 height, f32 dpr) {
wasm_delta_time = wasm_time - wasm_last_time; wasm_delta_time = wasm_time - wasm_last_time;
wasm_dpr = dpr; wasm_dpr = dpr;
if (wasm_frame.first_event == NULL) wasm_add_event((app_event_t){.kind = app_event_kind_update});
wasm_frame.window_size = (v2f32_t){width, height}; wasm_frame.window_size = (v2f32_t){width, height};
wasm_frame.dpr = wasm_dpr; wasm_frame.dpr = wasm_dpr;
wasm_frame.mouse_pos = wasm_frame.last_event->mouse_pos; wasm_frame.mouse_pos = wasm_frame.last_event->mouse_pos;
wasm_frame.delta = wasm_delta_time / 1000.0; wasm_frame.delta = wasm_delta_time / 1000.0;
wasm_frame.frame = wasm_frame_counter; wasm_frame.frame = wasm_frame_counter;
b32 animating = app_update(&wasm_frame); if (wasm_frame.frame == 0) {
app_frame_t frame = wasm_frame;
frame.first_event = frame.last_event = NULL;
frame.event_count = 0;
wasm_add_event_ex(&frame, &(app_event_t){.kind = app_event_kind_init});
app_update(tcx, &frame);
}
if (wasm_frame.first_event == NULL) {
wasm_add_event((app_event_t){.kind = app_event_kind_update});
}
b32 animating = app_update(tcx, &wasm_frame);
ma_set0(tcx->temp); ma_set0(tcx->temp);
zero_struct(&wasm_frame); zero_struct(&wasm_frame);
@@ -142,7 +154,6 @@ fn_wasm_export b32 wasm_update(f64 time, f32 width, f32 height, f32 dpr) {
return animating; return animating;
} }
fn_wasm_export void wasm_init(f32 dpr) { fn_wasm_export void wasm_init(void) {
core_init(); core_init();
app_init(dpr);
} }

View File

@@ -99,46 +99,8 @@ class memory_t {
const canvas = document.getElementById("canvas"); const canvas = document.getElementById("canvas");
const ctx2d = canvas.getContext('2d'); const ctx2d = canvas.getContext('2d');
const mem = new memory_t(new WebAssembly['Memory']({ initial: 2000, maximum: 65536 }));
(async function main() { const wasm_app_imports = {
if (!ctx2d) {
alert('Outdated browser, cant draw :(');
return;
}
const mem = new memory_t(new WebAssembly['Memory']({ initial: 2000, maximum: 65536 }));
const request = await fetch('main.wasm');
const binary = await request.arrayBuffer();
const wasm_os_imports = {
wasm_local_time_now: (ptr, len) => {
const date = new Date();
const stream = mem.stream_write(ptr, len);
stream.write_u16(date.getMilliseconds());
stream.write_u16(date.getSeconds());
stream.write_u16(date.getMinutes());
stream.write_u16(date.getHours());
stream.write_u16(date.getDate());
stream.write_u16(date.getMonth());
stream.write_u16(date.getFullYear());
},
wasm_universal_time_now: (ptr, len) => {
const date = new Date();
const stream = mem.stream_write(ptr, len);
stream.write_u16(date.getUTCMilliseconds());
stream.write_u16(date.getUTCSeconds());
stream.write_u16(date.getUTCMinutes());
stream.write_u16(date.getUTCHours());
stream.write_u16(date.getUTCDate());
stream.write_u16(date.getUTCMonth());
stream.write_u16(date.getUTCFullYear());
},
wasm_milliseconds_now: () => { return performance.now(); },
};
let wasm_app_imports = {
// core // core
memory: mem.mem, memory: mem.mem,
wasm_parse_float: (str, len) => { return parseFloat(mem.read_cstr(str, len)); }, wasm_parse_float: (str, len) => { return parseFloat(mem.read_cstr(str, len)); },
@@ -159,12 +121,6 @@ const ctx2d = canvas.getContext('2d');
const metrics = ctx2d.measureText(mem.read_cstr(str, len)); const metrics = ctx2d.measureText(mem.read_cstr(str, len));
return metrics.width; return metrics.width;
}, },
// wasm_get_font_height: (font_str, font_len, font_size) => {
// ctx2d.font = `${font_size}px ${mem.read_cstr(font_str, font_len)}`;
// ctx2d.textBaseline = "top";
// const v = ctx2d.measureText('NothinBelowTheBaseline');
// return v.fontBoundingBoxDescent;
// },
wasm_draw_rect: (x, y, w, h, r, g, b, a) => { wasm_draw_rect: (x, y, w, h, r, g, b, a) => {
ctx2d.beginPath(); ctx2d.beginPath();
ctx2d.rect(x, y, w, h); ctx2d.rect(x, y, w, h);
@@ -181,16 +137,21 @@ const ctx2d = canvas.getContext('2d');
ctx2d.rect(x, y, w, h); ctx2d.rect(x, y, w, h);
ctx2d.clip(); ctx2d.clip();
}, },
};
}; (async function main() {
if (!ctx2d) {
Object.assign(wasm_app_imports, wasm_os_imports); alert('Outdated browser, cant draw :(');
return;
}
const request = await fetch('main.wasm');
const binary = await request.arrayBuffer();
const program = await WebAssembly['instantiate'](binary, { "env": wasm_app_imports }); const program = await WebAssembly['instantiate'](binary, { "env": wasm_app_imports });
const instance = program['instance']; const instance = program['instance'];
const wasm_exports = instance['exports']; const wasm_exports = instance['exports'];
mem.exports = wasm_exports; mem.exports = wasm_exports;
wasm_exports['wasm_init'](window.devicePixelRatio); wasm_exports['wasm_init']();
let awake = true; let awake = true;

View File

@@ -11,7 +11,7 @@ gb HWND w32_window_handle;
gb HDC w32_dc; gb HDC w32_dc;
gb b32 w32_quit_app; gb b32 w32_quit_app;
fn b32 app_update(thread_ctx_t *tcx, app_frame_t *frame); fn_export b32 app_update(thread_ctx_t *thread_ctx, app_frame_t *frame);
fn v2f32_t w32_get_window_size(HWND window) { fn v2f32_t w32_get_window_size(HWND window) {
RECT window_rect; RECT window_rect;
@@ -420,17 +420,40 @@ int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int n
w32_wc = wc; w32_wc = wc;
} }
f64 primary_monitor_size_x = (f64)GetSystemMetrics(SM_CXSCREEN); #define APP_MODE_T 1
f64 primary_monitor_size_y = (f64)GetSystemMetrics(SM_CYSCREEN); #define APP_MODE_HALF 2
#define APP_WINDOW_MODE APP_MODE_HALF
RECT window_rect = {0}; RECT window_rect = {0};
{ {
window_rect.left = 0 + 0; f64 x = (f64)GetSystemMetrics(SM_CXSCREEN);
window_rect.right = 0 + (int)(primary_monitor_size_x * 0.8); f64 y = (f64)GetSystemMetrics(SM_CYSCREEN);
window_rect.bottom = 30 + (int)(primary_monitor_size_y * 0.8); #if APP_WINDOW_MODE == APP_MODE_T
window_rect.left = (int)(x*0.8);
window_rect.right = (int)(x*1.0);
window_rect.bottom = 30 + (int)(y * 0.4);
window_rect.top = 30 + 0; window_rect.top = 30 + 0;
#elif APP_WINDOW_MODE == APP_MODE_HALF
window_rect.left = (int)(x * 0.0) + 0;
window_rect.right = (int)(x * 0.0) + (int)(x * 0.5);
window_rect.top = 30 + 0;
window_rect.bottom = (int)(y * 0.96);
#else
window_rect.left = (int)(x * 0.1) + 0;
window_rect.right = (int)(x * 0.1) + (int)(x * 0.8);
window_rect.bottom = (int)(y * 0.1) + (int)(y * 0.8);
window_rect.top = (int)(y * 0.1) + 0;
#endif
AdjustWindowRectEx(&window_rect, WS_OVERLAPPEDWINDOW, false, 0); AdjustWindowRectEx(&window_rect, WS_OVERLAPPEDWINDOW, false, 0);
} }
w32_window_handle = CreateWindowW(w32_wc.lpszClassName, L"Zzz... Window, hello!", WS_OVERLAPPEDWINDOW, window_rect.left, window_rect.top, window_rect.right - window_rect.left, window_rect.bottom - window_rect.top, NULL, NULL, hInstance, NULL); DWORD ext_style = 0;
#if APP_WINDOW_MODE == APP_MODE_T
ext_style |= WS_EX_LAYERED | WS_EX_TOPMOST;
#endif
w32_window_handle = CreateWindowExW(ext_style, w32_wc.lpszClassName, L"Zzz... Window, hello!", WS_OVERLAPPEDWINDOW, window_rect.left, window_rect.top, window_rect.right - window_rect.left, window_rect.bottom - window_rect.top, NULL, NULL, hInstance, NULL);
#if APP_WINDOW_MODE == APP_MODE_T
SetLayeredWindowAttributes(w32_window_handle, 0, 200, LWA_ALPHA);
#endif
assert(w32_window_handle); assert(w32_window_handle);
w32_dc = GetDC(w32_window_handle); w32_dc = GetDC(w32_window_handle);
@@ -490,7 +513,6 @@ int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int n
frame.dpr = w32_get_dpr(w32_window_handle); frame.dpr = w32_get_dpr(w32_window_handle);
frame.mouse_pos = frame.last_event->mouse_pos; frame.mouse_pos = frame.last_event->mouse_pos;
frame.delta = time_delta; frame.delta = time_delta;
frame.update = time_update;
frame.frame = frame_counter; frame.frame = frame_counter;
b32 animating = true; b32 animating = true;

View File

@@ -9,7 +9,5 @@ gb_thread thread_ctx_t global_thread_context = {
fn void core_init(void) { fn void core_init(void) {
tcx = &global_thread_context; tcx = &global_thread_context;
tcx->temp = ma_create(ma_default_reserve_size);
ma_init(&tcx->perm, ma_default_reserve_size);
os_core_init(); os_core_init();
} }

View File

@@ -23,7 +23,7 @@ fn void default_log_proc(log_level_t level, s8_t file_and_line, s8_t string) {
} break; } break;
case log_level_fatal: { case log_level_fatal: {
os_error_box(s8_printf(scratch.arena, "%S: fatal error: %S\n", file_and_line, string).str); os_error_box(s8_printf(scratch.arena, "%S: fatal error: %S\n", file_and_line, string).str);
debug_break(); if (tcx->log.break_on_fatal) debug_break();
} break; } break;
default_is_invalid; default_is_invalid;
} }

View File

@@ -34,4 +34,6 @@ fn f64 os_parse_float(char *str) {
} }
fn void os_core_init(void) { fn void os_core_init(void) {
tcx->temp = ma_create(ma_default_reserve_size);
ma_init(&tcx->perm, ma_default_reserve_size);
} }

View File

@@ -41,13 +41,13 @@ fn void os_core_init(void) {
isize page_count = __builtin_wasm_memory_size(0); isize page_count = __builtin_wasm_memory_size(0);
u8 *memory = (u8 *)&__heap_base; u8 *memory = (u8 *)&__heap_base;
usize memory_size = page_count * (page_size) - (isize)memory; usize memory_size = page_count * (page_size) - (isize)memory;
tcx._perm.data = memory; tcx->perm.data = memory;
tcx._perm.commit = tcx._perm.reserve = memory_size; tcx->perm.commit = tcx->perm.reserve = memory_size;
ma_arena_t *perm = &tcx._perm; ma_arena_t *perm = &tcx->perm;
ma_push_arena_ex(&tcx._perm, &tcx.scratch[0], mib(1)); 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[1], kib(256));
ma_push_arena_ex(&tcx._perm, &tcx.scratch[2], kib(64)); ma_push_arena_ex(&tcx->perm, &tcx->scratch[2], kib(64));
tcx.temp = ma_push_arena(perm, mib(2)); tcx->temp = ma_push_arena(perm, mib(2));
} }

View File

@@ -34,4 +34,6 @@ fn f64 os_parse_float(char *str) {
} }
fn void os_core_init(void) { fn void os_core_init(void) {
tcx->temp = ma_create(ma_default_reserve_size);
ma_init(&tcx->perm, ma_default_reserve_size);
} }

View File

@@ -16,13 +16,16 @@ struct rn_state_t {
rn_font_t *main_font; rn_font_t *main_font;
app_frame_t *frame; app_frame_t *frame;
}; };
rn_state_t rn_state; rn_state_t *rn;
fn void rn_reload_font(f32 font_size, f32 dpr) { fn void rn_reload_font(f32 font_size, f32 dpr) {
rn->main_font->size = font_size * dpr; rn->main_font->size = font_size * dpr;
} }
fn void rn_init(ma_arena_t *perm, f32 font_size, f32 dpr) { fn void rn_init(ma_arena_t *perm, f32 font_size, f32 dpr) {
tcx->data[tcx_slot_rn] = ma_push_type(perm, rn_state_t);
rn = tcx->data[tcx_slot_rn];
rn->main_font = ma_push_type(perm, rn_font_t); rn->main_font = ma_push_type(perm, rn_font_t);
rn_reload_font(font_size, dpr); rn_reload_font(font_size, dpr);
} }
@@ -54,7 +57,7 @@ fn v2f32_t rn_draw_string(rn_font_t *font, v2f32_t pos, v4f32_t color, s8_t stri
} }
fn v2f32_t rn_draw_stringf(rn_font_t *font, v2f32_t pos, v4f32_t color, char *str, ...) { fn v2f32_t rn_draw_stringf(rn_font_t *font, v2f32_t pos, v4f32_t color, char *str, ...) {
S8_FMT(tcx.temp, str, string); S8_FMT(tcx->temp, str, string);
return rn_draw_string(font, pos, color, string); return rn_draw_string(font, pos, color, string);
} }
@@ -62,12 +65,19 @@ fn void rn_set_clip(r2f32_t rect) {
wasm_set_clip(rect.min.x, rect.min.y, (rect.max.x - rect.min.x), (rect.max.y - rect.min.y)); wasm_set_clip(rect.min.x, rect.min.y, (rect.max.x - rect.min.x), (rect.max.y - rect.min.y));
} }
fn void rn_begin(app_frame_t *frame, v4f32_t clear_color) { fn void rn_begin_frame(app_frame_t *frame) {
rn = tcx->data[tcx_slot_rn];
rn->frame = frame; rn->frame = frame;
}
fn void rn_begin(v4f32_t clear_color) {
r2f32_t window_rect = r2f32(0, 0, rn->frame->window_size.x, rn->frame->window_size.y); r2f32_t window_rect = r2f32(0, 0, rn->frame->window_size.x, rn->frame->window_size.y);
wasm_clear(); wasm_clear();
rn_draw_rect(window_rect, clear_color); rn_draw_rect(window_rect, clear_color);
} }
fn void rn_end() { fn void rn_end(void) {
}
fn void rn_reload(void) {
} }

View File

@@ -894,7 +894,6 @@ fn void ui_serial_subtype(void *p, type_t *type, s8_t name) {
fn void ui_serial_type(void *p, type_t *type) { fn void ui_serial_type(void *p, type_t *type) {
ui_serial_subtype(p, type, type->name); ui_serial_subtype(p, type, type->name);
} }
//
fn void ui_reload(void) { fn void ui_reload(void) {
ui_init_colors(); ui_init_colors();
@@ -907,6 +906,7 @@ fn void ui_init(ma_arena_t *arena) {
ui_reload(); ui_reload();
} }
gb app_event_t ui_test_event;
gb i32 ui_g_panel = 1; gb i32 ui_g_panel = 1;
fn void ui_demo_update(app_frame_t *frame, mt_tweak_t *tweak_table, i32 tweak_count) { fn void ui_demo_update(app_frame_t *frame, mt_tweak_t *tweak_table, i32 tweak_count) {
ui_begin_frame(frame); ui_begin_frame(frame);
@@ -921,12 +921,11 @@ fn void ui_demo_update(app_frame_t *frame, mt_tweak_t *tweak_table, i32 tweak_co
ui_set_lop(ui_lop_cut_left) ui_set_lop(ui_lop_cut_left)
ui_set_top(top_box) { ui_set_top(top_box) {
ui_radio_button(&ui_g_panel, 1, "1"); ui_radio_button(&ui_g_panel, 1, "1");
ui_radio_button(&ui_g_panel, 2, "4"); ui_radio_button(&ui_g_panel, 2, "2");
} }
ui->top->rect = r2f32_shrinks(ui->top->rect, ui_em(1)); ui->top->rect = r2f32_shrinks(ui->top->rect, ui_em(1));
if (ui_g_panel == 1) { if (ui_g_panel == 1) {
ui_box_t *scroller_box = ui_boxf((ui_box_flags_t){.draw_rect = true, .clip_rect = true}, "scrollbar"); ui_box_t *scroller_box = ui_boxf((ui_box_flags_t){.draw_rect = true, .clip_rect = true}, "scrollbar");
ui_set_rect(scroller_box, r2f32_cut_right(&ui->top->rect, 10 * frame->dpr), ui_lop_cut_right); ui_set_rect(scroller_box, r2f32_cut_right(&ui->top->rect, 10 * frame->dpr), ui_lop_cut_right);
@@ -969,7 +968,11 @@ fn void ui_demo_update(app_frame_t *frame, mt_tweak_t *tweak_table, i32 tweak_co
} else_is_invalid; } else_is_invalid;
} }
ui_label("allocated boxes: %d", ui->allocated_boxes); ui_label("allocated boxes: %d", ui->allocated_boxes);
// ui_serial_type(&ui_test_event, type(app_event_t)); ui_serial_type(&ui_test_event, type(app_event_t));
ui_set_id(ui_idf("a")) {
ui_serial_type(&ui_test_event, type(app_event_t));
}
} }
locl f32 scroller_value; locl f32 scroller_value;
@@ -992,7 +995,7 @@ fn void ui_demo_update(app_frame_t *frame, mt_tweak_t *tweak_table, i32 tweak_co
ui_set_rect(box, r2f32_cut_top(&ui->top->rect, scroller_size * scroller_box_size), ui_lop_cut_top); ui_set_rect(box, r2f32_cut_top(&ui->top->rect, scroller_size * scroller_box_size), ui_lop_cut_top);
ui_signal_t signal = ui_signal_from_box(box); ui_signal_t signal = ui_signal_from_box(box);
if (signal.dragging) { if (signal.dragging) {
scroller_value += (signal.drag.y / item_box_size * 2) * (all_items_size); scroller_value += signal.drag.y;
scroller_value = CLAMP(scroller_value, 0, all_items_size); scroller_value = CLAMP(scroller_value, 0, all_items_size);
} }
if (ev->kind == app_event_kind_mouse_wheel) { if (ev->kind == app_event_kind_mouse_wheel) {

View File

@@ -3,6 +3,7 @@
#include "ui/ui_inc.h" #include "ui/ui_inc.h"
#include "core/core_inc.c" #include "core/core_inc.c"
#include "app/app.c"
#include "render/render_inc.c" #include "render/render_inc.c"
#include "ui/ui_inc.c" #include "ui/ui_inc.c"