From f5f7c5d8ffe7d6b99bdf555f207ee91b1e16c915 Mon Sep 17 00:00:00 2001 From: martinfouilleul Date: Fri, 16 Jun 2023 20:07:26 +0200 Subject: [PATCH] [wip, win32] wip implementing missing win32 platform functions --- milepost | 2 +- src/io_impl.c | 2 +- src/main.c | 4 +- src/orca_app.h | 207 ++++++++++++++++++++++++++++++------------------- 4 files changed, 133 insertions(+), 82 deletions(-) diff --git a/milepost b/milepost index 6499bcd..e93bf76 160000 --- a/milepost +++ b/milepost @@ -1 +1 @@ -Subproject commit 6499bcd2a213028577f9543f50e84563a6695141 +Subproject commit e93bf76adcf8e26b4d039da1066847bdf7b80d1f diff --git a/src/io_impl.c b/src/io_impl.c index f9b58e9..bce2a4e 100644 --- a/src/io_impl.c +++ b/src/io_impl.c @@ -35,7 +35,7 @@ io_cmp orca_io_wait_single_req(io_req* wasmReq) { //NOTE: change root to app local folder req.handle = orca->rootDir; - req.openFlags |= FILE_OPEN_RESTRICT; + req.open.flags |= FILE_OPEN_RESTRICT; } } cmp = io_wait_single_req_with_table(&req, &orca->fileTable); diff --git a/src/main.c b/src/main.c index 32b6cd9..eaf67a0 100644 --- a/src/main.c +++ b/src/main.c @@ -357,7 +357,7 @@ void* orca_runloop(void* user) M3Result res = m3_CompileModule(app->runtime.m3Module); if(res) { - M3ErrorInfo errInfo = {}; + M3ErrorInfo errInfo = {0}; m3_GetErrorInfo(app->runtime.m3Runtime, &errInfo); log_error("wasm error: %s\n", errInfo.message); @@ -424,7 +424,7 @@ void* orca_runloop(void* user) str8 localRootPath = path_executable_relative(mem_scratch(), STR8("../app/data")); io_req req = {.op = IO_OP_OPEN_AT, - .openFlags = FILE_OPEN_READ, + .open.rights = FILE_ACCESS_READ, .size = localRootPath.len, .buffer = localRootPath.ptr}; io_cmp cmp = io_wait_single_req_with_table(&req, &app->fileTable); diff --git a/src/orca_app.h b/src/orca_app.h index 518d2ac..6646a52 100644 --- a/src/orca_app.h +++ b/src/orca_app.h @@ -1,78 +1,129 @@ -/************************************************************//** -* -* @file: orca_runtime.h -* @author: Martin Fouilleul -* @date: 17/04/2023 -* -*****************************************************************/ -#ifndef __ORCA_RUNTIME_H_ -#define __ORCA_RUNTIME_H_ - -#include"wasm3.h" -#include"m3_env.h" -#include"m3_compile.h" - -#define G_EVENTS(X) \ - X(G_EVENT_START, "OnInit", "", "") \ - X(G_EVENT_MOUSE_DOWN, "OnMouseDown", "", "i") \ - X(G_EVENT_MOUSE_UP, "OnMouseUp", "", "i") \ - X(G_EVENT_MOUSE_ENTER, "OnMouseEnter", "", "") \ - X(G_EVENT_MOUSE_LEAVE, "OnMouseLeave", "", "") \ - X(G_EVENT_MOUSE_MOVE, "OnMouseMove", "", "ffff") \ - X(G_EVENT_MOUSE_WHEEL, "OnMouseWheel", "", "ff") \ - X(G_EVENT_KEY_DOWN, "OnKeyDown", "", "i") \ - X(G_EVENT_KEY_UP, "OnKeyUp", "", "i") \ - X(G_EVENT_FRAME_REFRESH, "OnFrameRefresh", "", "") \ - X(G_EVENT_FRAME_RESIZE, "OnFrameResize", "", "ii") - -typedef enum { - #define G_EVENT_KIND(kind, ...) kind, - G_EVENTS(G_EVENT_KIND) - G_EVENT_COUNT -} guest_event_kind; - - -typedef struct g_event_handler_desc -{ - str8 name; - str8 retTags; - str8 argTags; -} g_event_handler_desc; - -const g_event_handler_desc G_EVENT_HANDLER_DESC[] = { - - #define STR8LIT(s) {sizeof(s), s} //NOTE: msvc doesn't accept STR8(s) as compile-time constant... - #define G_EVENT_HANDLER_DESC_ENTRY(kind, name, rets, args) {STR8LIT(name), STR8LIT(rets), STR8LIT(args)}, - - G_EVENTS(G_EVENT_HANDLER_DESC_ENTRY) - - #undef G_EVENT_HANDLER_DESC_ENTRY - #undef STR8LIT -}; - -typedef struct wasm_memory -{ - char* ptr; - u64 reserved; - u64 committed; - -} wasm_memory; - -typedef struct orca_runtime -{ - str8 wasmBytecode; - wasm_memory wasmMemory; - - // wasm3 data - IM3Environment m3Env; - IM3Runtime m3Runtime; - IM3Module m3Module; - IM3Function eventHandlers[G_EVENT_COUNT]; - -} orca_runtime; - - -orca_runtime* orca_runtime_get(); - - -#endif //__ORCA_RUNTIME_H_ +/************************************************************//** +* +* @file: orca_runtime.h +* @author: Martin Fouilleul +* @date: 17/04/2023 +* +*****************************************************************/ +#ifndef __ORCA_RUNTIME_H_ +#define __ORCA_RUNTIME_H_ + +#include"platform/platform_io_internal.h" + +#include"wasm3.h" +#include"m3_env.h" +#include"m3_compile.h" + +#define G_EVENTS(X) \ + X(G_EVENT_START, "OnInit", "", "") \ + X(G_EVENT_MOUSE_DOWN, "OnMouseDown", "", "i") \ + X(G_EVENT_MOUSE_UP, "OnMouseUp", "", "i") \ + X(G_EVENT_MOUSE_ENTER, "OnMouseEnter", "", "") \ + X(G_EVENT_MOUSE_LEAVE, "OnMouseLeave", "", "") \ + X(G_EVENT_MOUSE_MOVE, "OnMouseMove", "", "ffff") \ + X(G_EVENT_MOUSE_WHEEL, "OnMouseWheel", "", "ff") \ + X(G_EVENT_KEY_DOWN, "OnKeyDown", "", "i") \ + X(G_EVENT_KEY_UP, "OnKeyUp", "", "i") \ + X(G_EVENT_FRAME_REFRESH, "OnFrameRefresh", "", "") \ + X(G_EVENT_FRAME_RESIZE, "OnFrameResize", "", "ii") + +typedef enum { + #define G_EVENT_KIND(kind, ...) kind, + G_EVENTS(G_EVENT_KIND) + G_EVENT_COUNT +} guest_event_kind; + + +typedef struct g_event_handler_desc +{ + str8 name; + str8 retTags; + str8 argTags; +} g_event_handler_desc; + +const g_event_handler_desc G_EVENT_HANDLER_DESC[] = { + #define STR8LIT(s) {sizeof(s), s} //NOTE: msvc doesn't accept STR8(s) as compile-time constant... + #define G_EVENT_HANDLER_DESC_ENTRY(kind, name, rets, args) {STR8LIT(name), STR8LIT(rets), STR8LIT(args)}, + + G_EVENTS(G_EVENT_HANDLER_DESC_ENTRY) + + #undef G_EVENT_HANDLER_DESC_ENTRY + #undef STR8LIT +}; + +typedef struct wasm_memory +{ + char* ptr; + u64 reserved; + u64 committed; + +} wasm_memory; + +typedef struct orca_runtime +{ + str8 wasmBytecode; + wasm_memory wasmMemory; + + // wasm3 data + IM3Environment m3Env; + IM3Runtime m3Runtime; + IM3Module m3Module; + IM3Function eventHandlers[G_EVENT_COUNT]; + +} orca_runtime; + +typedef struct log_entry +{ + list_elt listElt; + u64 cap; + + log_level level; + str8 file; + str8 function; + int line; + str8 msg; + + u64 recordIndex; + +} log_entry; + +typedef struct orca_debug_overlay +{ + bool show; + mg_surface surface; + mg_canvas canvas; + mg_font fontReg; + mg_font fontBold; + ui_context ui; + + + mem_arena logArena; + list_info logEntries; + list_info logFreeList; + u32 entryCount; + u32 maxEntries; + u64 logEntryTotalCount; + bool logScrollToLast; + +} orca_debug_overlay; + +typedef struct orca_app +{ + mp_window window; + mg_surface surface; + mg_canvas canvas; + + file_table fileTable; + file_handle rootDir; + + orca_runtime runtime; + + orca_debug_overlay debugOverlay; + +} orca_app; + +orca_app* orca_app_get(); +orca_runtime* orca_runtime_get(); + + +#endif //__ORCA_RUNTIME_H_