orca/src/runtime.h

137 lines
3.4 KiB
C
Raw Normal View History

2023-09-07 12:51:48 +00:00
/*************************************************************************
*
2023-09-07 12:51:48 +00:00
* Orca
* Copyright 2023 Martin Fouilleul and the Orca project contributors
* See LICENSE.txt for licensing information
*
2023-09-07 12:51:48 +00:00
**************************************************************************/
This commit restructures the codebase to melt the milepost platform layer into the main orca codebase. Here's a list of commits squashed in this update: - move angle files to ext/ and pull includes/libs from there when needed - remove milepost/ext/angle_headers - Collapsed milepost/ext into ext - Collapse milepost/scripts into scripts/ - collapse milepost/resources into resources/. WARN: this temporarily breaks milepost's native examples - collapse milepost/test into test/ - renamed test/ to tests/ - build milepost directly into build/bin - remove unused GLES and KHR folders from sdk/ - reorganizing milepost directory tree into app, graphics, platfrom, ui, util - collapse milepost/src to src/ - Move all native examples to sketches/ and remove milepost repo - Moving sketches resources into their own shared folder separate from the runtime's resource folder - Moving all binding code to src/wasmbind - Moving all binding code to src/wasmbind - pong: fix typo in error log - fixing log parameter order - add error logs to mg_image_create_* - Fix build scripts on windows - fixed include mistake after rebase - collapsing milepost.{h|c|m} to orca.{h|c|m} and moving from sdk/ to src/ - rename orca_app.h/main.c to runtime.h/c - collapsed sdk/ to src/ - put old sdk files into their respective dirs - renamed canvas_api.json to surface_api.json - moved all stb headers in ext/stb/ - remove unused OpenSansLatinSubset.ttf font - moving cstdlib to src/wasmlibc and removing some duplicates with src/platform - move libc stdarg and string functions from platform/ to wasmlibc/ - rename wasmlibc to libc-shim to reflect non-completeness - Expose abort/assert variadic functions and macros to orca apps, and forward libc-shim abort/assert to these - move Orca API runtime implementations to runtime_xxx - fix missing math constants when including math.h with msvc in graphics_common.c - Change name of runtime to orca_runtime. When bundling on Windows, change name of runtime executable to the name of the app.
2023-08-09 11:06:32 +00:00
#ifndef __RUNTIME_H_
#define __RUNTIME_H_
2023-08-19 12:49:23 +00:00
#include "platform/platform_io_internal.h"
2023-09-11 08:59:23 +00:00
#include "runtime_memory.h"
#include "runtime_clipboard.h"
2023-08-19 12:49:23 +00:00
#include "m3_compile.h"
#include "m3_env.h"
#include "wasm3.h"
#define OC_EXPORTS(X) \
X(OC_EXPORT_ON_INIT, "oc_on_init", "", "") \
X(OC_EXPORT_MOUSE_DOWN, "oc_on_mouse_down", "", "i") \
X(OC_EXPORT_MOUSE_UP, "oc_on_mouse_up", "", "i") \
X(OC_EXPORT_MOUSE_ENTER, "oc_on_mouse_enter", "", "") \
X(OC_EXPORT_MOUSE_LEAVE, "oc_on_mouse_leave", "", "") \
X(OC_EXPORT_MOUSE_MOVE, "oc_on_mouse_move", "", "ffff") \
X(OC_EXPORT_MOUSE_WHEEL, "oc_on_mouse_wheel", "", "ff") \
X(OC_EXPORT_KEY_DOWN, "oc_on_key_down", "", "ii") \
X(OC_EXPORT_KEY_UP, "oc_on_key_up", "", "ii") \
2023-08-19 12:49:23 +00:00
X(OC_EXPORT_FRAME_REFRESH, "oc_on_frame_refresh", "", "") \
X(OC_EXPORT_FRAME_RESIZE, "oc_on_resize", "", "ii") \
X(OC_EXPORT_RAW_EVENT, "oc_on_raw_event", "", "i") \
X(OC_EXPORT_TERMINATE, "oc_on_terminate", "", "") \
X(OC_EXPORT_ARENA_PUSH, "oc_arena_push_stub", "i", "iI")
2023-08-19 12:49:23 +00:00
typedef enum
{
2023-08-19 12:49:23 +00:00
#define OC_EXPORT_KIND(kind, ...) kind,
OC_EXPORTS(OC_EXPORT_KIND)
OC_EXPORT_COUNT
} guest_export_kind;
typedef struct oc_export_desc
{
2023-08-19 12:49:23 +00:00
oc_str8 name;
oc_str8 retTags;
oc_str8 argTags;
} oc_export_desc;
const oc_export_desc OC_EXPORT_DESC[] = {
2023-08-19 12:49:23 +00:00
#define OC_EXPORT_DESC_ENTRY(kind, name, rets, args) { OC_STR8_LIT(name), OC_STR8_LIT(rets), OC_STR8_LIT(args) },
2023-08-19 12:49:23 +00:00
OC_EXPORTS(OC_EXPORT_DESC_ENTRY)
2023-08-19 12:49:23 +00:00
#undef OC_EXPORT_DESC_ENTRY
#undef OC_STR8_LIT
};
typedef struct oc_wasm_memory
{
2023-08-19 12:49:23 +00:00
char* ptr;
u64 reserved;
u64 committed;
} oc_wasm_memory;
typedef struct oc_wasm_env
{
2023-08-19 12:49:23 +00:00
oc_str8 wasmBytecode;
oc_wasm_memory wasmMemory;
2023-08-19 12:49:23 +00:00
// wasm3 data
IM3Environment m3Env;
IM3Runtime m3Runtime;
IM3Module m3Module;
IM3Function exports[OC_EXPORT_COUNT];
u32 rawEventOffset;
} oc_wasm_env;
typedef struct log_entry
{
2023-08-19 12:49:23 +00:00
oc_list_elt listElt;
u64 cap;
2023-08-19 12:49:23 +00:00
oc_log_level level;
oc_str8 file;
oc_str8 function;
int line;
oc_str8 msg;
2023-08-19 12:49:23 +00:00
u64 recordIndex;
} log_entry;
typedef struct oc_debug_overlay
{
2023-08-19 12:49:23 +00:00
bool show;
oc_surface surface;
oc_canvas canvas;
oc_font fontReg;
oc_font fontBold;
oc_ui_context ui;
oc_arena logArena;
oc_list logEntries;
oc_list logFreeList;
u32 entryCount;
u32 maxEntries;
u64 logEntryTotalCount;
bool logScrollToLast;
} oc_debug_overlay;
typedef struct oc_runtime
{
bool quit;
2023-08-19 12:49:23 +00:00
oc_window window;
oc_debug_overlay debugOverlay;
2023-08-19 12:49:23 +00:00
oc_file_table fileTable;
oc_file rootDir;
oc_wasm_env env;
2023-09-11 08:59:23 +00:00
oc_runtime_clipboard clipboard;
} oc_runtime;
oc_runtime* oc_runtime_get(void);
oc_wasm_env* oc_runtime_get_env(void);
oc_str8 oc_runtime_get_wasm_memory(void);
void orca_wasm3_abort(IM3Runtime runtime, M3Result res, const char* file, const char* function, int line, const char* msg);
#define ORCA_WASM3_ABORT(runtime, err, msg) orca_wasm3_abort(runtime, err, __FILE__, __FUNCTION__, __LINE__, msg)
This commit restructures the codebase to melt the milepost platform layer into the main orca codebase. Here's a list of commits squashed in this update: - move angle files to ext/ and pull includes/libs from there when needed - remove milepost/ext/angle_headers - Collapsed milepost/ext into ext - Collapse milepost/scripts into scripts/ - collapse milepost/resources into resources/. WARN: this temporarily breaks milepost's native examples - collapse milepost/test into test/ - renamed test/ to tests/ - build milepost directly into build/bin - remove unused GLES and KHR folders from sdk/ - reorganizing milepost directory tree into app, graphics, platfrom, ui, util - collapse milepost/src to src/ - Move all native examples to sketches/ and remove milepost repo - Moving sketches resources into their own shared folder separate from the runtime's resource folder - Moving all binding code to src/wasmbind - Moving all binding code to src/wasmbind - pong: fix typo in error log - fixing log parameter order - add error logs to mg_image_create_* - Fix build scripts on windows - fixed include mistake after rebase - collapsing milepost.{h|c|m} to orca.{h|c|m} and moving from sdk/ to src/ - rename orca_app.h/main.c to runtime.h/c - collapsed sdk/ to src/ - put old sdk files into their respective dirs - renamed canvas_api.json to surface_api.json - moved all stb headers in ext/stb/ - remove unused OpenSansLatinSubset.ttf font - moving cstdlib to src/wasmlibc and removing some duplicates with src/platform - move libc stdarg and string functions from platform/ to wasmlibc/ - rename wasmlibc to libc-shim to reflect non-completeness - Expose abort/assert variadic functions and macros to orca apps, and forward libc-shim abort/assert to these - move Orca API runtime implementations to runtime_xxx - fix missing math constants when including math.h with msvc in graphics_common.c - Change name of runtime to orca_runtime. When bundling on Windows, change name of runtime executable to the name of the app.
2023-08-09 11:06:32 +00:00
#endif //__RUNTIME_H_