Feedback
This commit is contained in:
parent
a683c163cb
commit
bffcaa4abf
6
build.sh
6
build.sh
|
@ -67,6 +67,12 @@ elif [ $target = orca ] ; then
|
|||
--guest-include graphics.h \
|
||||
--wasm3-bindings ./src/canvas_api_bind_gen.c
|
||||
|
||||
python3 ./scripts/bindgen2.py clock \
|
||||
src/clock_api.json \
|
||||
--guest-stubs sdk/orca_clock.c \
|
||||
--guest-include platform_clock.h \
|
||||
--wasm3-bindings ./src/clock_api_bind_gen.c
|
||||
|
||||
python3 ./scripts/bindgen2.py io \
|
||||
src/io_api.json \
|
||||
--guest-stubs sdk/io_stubs.c \
|
||||
|
|
|
@ -10,7 +10,7 @@ set wasmFlags=--target=wasm32^
|
|||
-O2 ^
|
||||
-mbulk-memory ^
|
||||
-D__ORCA__ ^
|
||||
-isystem ..\..\cstdlib\include -I ..\..\sdk -I..\..\milepost\ext -I ..\..\milepost -I ..\..\milepost\src -I ..\..\milepost\src\util -I ..\..\milepost\src\platform
|
||||
-isystem ..\..\cstdlib\include -I ..\..\sdk -I..\..\milepost\ext -I ..\..\milepost -I ..\..\milepost\src
|
||||
|
||||
clang %wasmFlags% -o .\module.wasm ..\..\sdk\orca.c ..\..\cstdlib\src\*.c src\main.c
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ wasmFlags="--target=wasm32 \
|
|||
-D__ORCA__ \
|
||||
-I $STDLIB_DIR/include \
|
||||
-I $ORCA_SDK_DIR \
|
||||
-I $MILEPOST_DIR/ext -I $MILEPOST_DIR -I $MILEPOST_DIR/src -I $MILEPOST_DIR/src/util -I $MILEPOST_DIR/src/platform"
|
||||
-I $MILEPOST_DIR/ext -I $MILEPOST_DIR -I $MILEPOST_DIR/src"
|
||||
|
||||
$CLANG $wasmFlags -o ./module.wasm ../../sdk/orca.c ../../cstdlib/src/*.c src/main.c
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ set wasmFlags=--target=wasm32^
|
|||
-O2 ^
|
||||
-mbulk-memory ^
|
||||
-D__ORCA__ ^
|
||||
-isystem ..\..\cstdlib\include -I ..\..\sdk -I..\..\milepost\ext -I ..\..\milepost -I ..\..\milepost\src -I ..\..\milepost\src\util -I ..\..\milepost\src\platform
|
||||
-isystem ..\..\cstdlib\include -I ..\..\sdk -I..\..\milepost\ext -I ..\..\milepost -I ..\..\milepost\src
|
||||
|
||||
clang %wasmFlags% -o .\module.wasm ..\..\sdk\orca.c ..\..\cstdlib\src\*.c src\main.c
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ wasmFlags="--target=wasm32 \
|
|||
-O2 \
|
||||
-mbulk-memory \
|
||||
-D__ORCA__ \
|
||||
-isystem ../../cstdlib/include -I ../../sdk -I../../milepost/ext -I ../../milepost -I ../../milepost/src -I ../../milepost/src/util -I ../../milepost/src/platform -I../.."
|
||||
-isystem ../../cstdlib/include -I ../../sdk -I../../milepost/ext -I ../../milepost -I ../../milepost/src"
|
||||
|
||||
$CLANG $wasmFlags -o ./module.wasm ../../sdk/orca.c ../../cstdlib/src/*.c src/main.c
|
||||
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
|
||||
vec2 frameSize = {100, 100};
|
||||
|
||||
mg_canvas canvas;
|
||||
mg_surface surface;
|
||||
mg_canvas canvas;
|
||||
mg_font font;
|
||||
ui_context ui;
|
||||
mem_arena textArena = {0};
|
||||
|
|
|
@ -1,12 +1,5 @@
|
|||
#include"orca.h"
|
||||
|
||||
ORCA_EXPORT mp_event* _OrcaGetRawEventPtr()
|
||||
{
|
||||
static mp_event event;
|
||||
return &event;
|
||||
}
|
||||
mp_event _OrcaRawEvent;
|
||||
|
||||
ORCA_EXPORT void _OrcaClockInit()
|
||||
{
|
||||
mp_clock_init();
|
||||
}
|
||||
ORCA_EXPORT mp_event *_OrcaRawEventPtr;
|
||||
|
|
|
@ -1,10 +1,4 @@
|
|||
[
|
||||
{
|
||||
"name": "mp_clock_init",
|
||||
"cname": "mp_clock_init",
|
||||
"ret": {"name": "void", "tag": "v"},
|
||||
"args": []
|
||||
},
|
||||
{
|
||||
"name": "mp_get_time",
|
||||
"cname": "mp_get_time",
|
||||
|
|
81
src/main.c
81
src/main.c
|
@ -381,26 +381,26 @@ void* orca_runloop(void* user)
|
|||
return((void*)-1);
|
||||
}
|
||||
|
||||
//NOTE: Find and type check exports.
|
||||
for(int i=0; i<G_EXPORT_COUNT; i++)
|
||||
//NOTE: Find and type check event handlers.
|
||||
for(int i=0; i<G_EVENT_COUNT; i++)
|
||||
{
|
||||
const g_export_desc* desc = &G_EXPORT_DESC[i];
|
||||
IM3Function export = 0;
|
||||
m3_FindFunction(&export, app->runtime.m3Runtime, desc->name.ptr);
|
||||
const g_event_handler_desc* desc = &G_EVENT_HANDLER_DESC[i];
|
||||
IM3Function handler = 0;
|
||||
m3_FindFunction(&handler, app->runtime.m3Runtime, desc->name.ptr);
|
||||
|
||||
if(export)
|
||||
if(handler)
|
||||
{
|
||||
bool checked = false;
|
||||
|
||||
//NOTE: check function signature
|
||||
int retCount = m3_GetRetCount(export);
|
||||
int argCount = m3_GetArgCount(export);
|
||||
int retCount = m3_GetRetCount(handler);
|
||||
int argCount = m3_GetArgCount(handler);
|
||||
if(retCount == desc->retTags.len && argCount == desc->argTags.len)
|
||||
{
|
||||
checked = true;
|
||||
for(int retIndex = 0; retIndex < retCount; retIndex++)
|
||||
{
|
||||
M3ValueType m3Type = m3_GetRetType(export, retIndex);
|
||||
M3ValueType m3Type = m3_GetRetType(handler, retIndex);
|
||||
char tag = m3_type_to_tag(m3Type);
|
||||
|
||||
if(tag != desc->retTags.ptr[retIndex])
|
||||
|
@ -413,7 +413,7 @@ void* orca_runloop(void* user)
|
|||
{
|
||||
for(int argIndex = 0; argIndex < argCount; argIndex++)
|
||||
{
|
||||
M3ValueType m3Type = m3_GetArgType(export, argIndex);
|
||||
M3ValueType m3Type = m3_GetArgType(handler, argIndex);
|
||||
char tag = m3_type_to_tag(m3Type);
|
||||
|
||||
if(tag != desc->argTags.ptr[argIndex])
|
||||
|
@ -427,29 +427,18 @@ void* orca_runloop(void* user)
|
|||
|
||||
if(checked)
|
||||
{
|
||||
app->runtime.exports[i] = export;
|
||||
app->runtime.eventHandlers[i] = handler;
|
||||
}
|
||||
else
|
||||
{
|
||||
log_error("type mismatch for export %.*s\n", (int)desc->name.len, desc->name.ptr);
|
||||
log_error("type mismatch for event handler %.*s\n", (int)desc->name.len, desc->name.ptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
IM3Function* exports = app->runtime.exports;
|
||||
|
||||
//NOTE: get location of the raw event slot
|
||||
if (exports[G_EXPORT_GET_RAW_EVENT_PTR])
|
||||
{
|
||||
m3_CallV(exports[G_EXPORT_GET_RAW_EVENT_PTR]);
|
||||
const void* getRawEventPtrResults[1] = {&app->runtime.rawEventOffset};
|
||||
m3_GetResults(exports[G_EXPORT_GET_RAW_EVENT_PTR], 1, getRawEventPtrResults);
|
||||
}
|
||||
|
||||
//NOTE: init clock
|
||||
if (exports[G_EXPORT_CLOCK_INIT])
|
||||
{
|
||||
m3_CallV(exports[G_EXPORT_CLOCK_INIT]);
|
||||
}
|
||||
IM3Global rawEventGlobal = m3_FindGlobal(app->runtime.m3Module, "_OrcaRawEventPtr");
|
||||
app->runtime.rawEventOffset = (u32)rawEventGlobal->intValue;
|
||||
|
||||
//NOTE: preopen the app local root dir
|
||||
{
|
||||
|
@ -466,10 +455,12 @@ void* orca_runloop(void* user)
|
|||
//NOTE: prepare GL surface
|
||||
mg_surface_prepare(app->surface);
|
||||
|
||||
IM3Function* eventHandlers = app->runtime.eventHandlers;
|
||||
|
||||
//NOTE: call init handler
|
||||
if(exports[G_EXPORT_ON_INIT])
|
||||
if(eventHandlers[G_EVENT_START])
|
||||
{
|
||||
M3Result err = m3_Call(exports[G_EXPORT_ON_INIT], 0, 0);
|
||||
M3Result err = m3_Call(eventHandlers[G_EVENT_START], 0, 0);
|
||||
if(err != NULL)
|
||||
{
|
||||
log_error("runtime error: %s\n", err);
|
||||
|
@ -486,13 +477,13 @@ void* orca_runloop(void* user)
|
|||
}
|
||||
}
|
||||
|
||||
if(exports[G_EXPORT_ON_FRAME_RESIZE])
|
||||
if(eventHandlers[G_EVENT_FRAME_RESIZE])
|
||||
{
|
||||
mp_rect frame = mg_surface_get_frame(app->surface);
|
||||
u32 width = (u32)frame.w;
|
||||
u32 height = (u32)frame.h;
|
||||
const void* args[2] = {&width, &height};
|
||||
m3_Call(exports[G_EXPORT_ON_FRAME_RESIZE], 2, args);
|
||||
m3_Call(eventHandlers[G_EVENT_FRAME_RESIZE], 2, args);
|
||||
}
|
||||
|
||||
ui_set_context(&app->debugOverlay.ui);
|
||||
|
@ -508,7 +499,7 @@ void* orca_runloop(void* user)
|
|||
ui_process_event(event);
|
||||
}
|
||||
|
||||
if(exports[G_EXPORT_ON_RAW_EVENT])
|
||||
if(eventHandlers[G_EVENT_RAW_EVENT])
|
||||
{
|
||||
if (app->runtime.rawEventOffset == 0)
|
||||
{
|
||||
|
@ -520,7 +511,7 @@ void* orca_runloop(void* user)
|
|||
memcpy(eventPtr, event, sizeof(*event));
|
||||
|
||||
const void* args[1] = {&app->runtime.rawEventOffset};
|
||||
m3_Call(exports[G_EXPORT_ON_RAW_EVENT], 1, args);
|
||||
m3_Call(eventHandlers[G_EVENT_RAW_EVENT], 1, args);
|
||||
#else
|
||||
log_error("OnRawEvent() is not supported on big endian platforms");
|
||||
#endif
|
||||
|
@ -540,12 +531,12 @@ void* orca_runloop(void* user)
|
|||
|
||||
// mg_surface_set_frame(app->debugOverlay.surface, frame);
|
||||
|
||||
if(exports[G_EXPORT_ON_FRAME_RESIZE])
|
||||
if(eventHandlers[G_EVENT_FRAME_RESIZE])
|
||||
{
|
||||
u32 width = (u32)event->frame.rect.w;
|
||||
u32 height = (u32)event->frame.rect.h;
|
||||
const void* args[2] = {&width, &height};
|
||||
m3_Call(exports[G_EXPORT_ON_FRAME_RESIZE], 2, args);
|
||||
m3_Call(eventHandlers[G_EVENT_FRAME_RESIZE], 2, args);
|
||||
}
|
||||
} break;
|
||||
|
||||
|
@ -553,30 +544,30 @@ void* orca_runloop(void* user)
|
|||
{
|
||||
if(event->key.action == MP_KEY_PRESS)
|
||||
{
|
||||
if(exports[G_EXPORT_ON_MOUSE_DOWN])
|
||||
if(eventHandlers[G_EVENT_MOUSE_DOWN])
|
||||
{
|
||||
int key = event->key.code;
|
||||
const void* args[1] = {&key};
|
||||
m3_Call(exports[G_EXPORT_ON_MOUSE_DOWN], 1, args);
|
||||
m3_Call(eventHandlers[G_EVENT_MOUSE_DOWN], 1, args);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(exports[G_EXPORT_ON_MOUSE_UP])
|
||||
if(eventHandlers[G_EVENT_MOUSE_UP])
|
||||
{
|
||||
int key = event->key.code;
|
||||
const void* args[1] = {&key};
|
||||
m3_Call(exports[G_EXPORT_ON_MOUSE_UP], 1, args);
|
||||
m3_Call(eventHandlers[G_EVENT_MOUSE_UP], 1, args);
|
||||
}
|
||||
}
|
||||
} break;
|
||||
|
||||
case MP_EVENT_MOUSE_MOVE:
|
||||
{
|
||||
if(exports[G_EXPORT_ON_MOUSE_MOVE])
|
||||
if(eventHandlers[G_EVENT_MOUSE_MOVE])
|
||||
{
|
||||
const void* args[4] = {&event->move.x, &event->move.y, &event->move.deltaX, &event->move.deltaY};
|
||||
m3_Call(exports[G_EXPORT_ON_MOUSE_MOVE], 4, args);
|
||||
m3_Call(eventHandlers[G_EVENT_MOUSE_MOVE], 4, args);
|
||||
}
|
||||
} break;
|
||||
|
||||
|
@ -591,18 +582,18 @@ void* orca_runloop(void* user)
|
|||
#endif
|
||||
}
|
||||
|
||||
if(exports[G_EXPORT_ON_KEY_DOWN])
|
||||
if(eventHandlers[G_EVENT_KEY_DOWN])
|
||||
{
|
||||
const void* args[1] = {&event->key.code};
|
||||
m3_Call(exports[G_EXPORT_ON_KEY_DOWN], 1, args);
|
||||
m3_Call(eventHandlers[G_EVENT_KEY_DOWN], 1, args);
|
||||
}
|
||||
}
|
||||
else if(event->key.action == MP_KEY_RELEASE)
|
||||
{
|
||||
if(exports[G_EXPORT_ON_KEY_UP])
|
||||
if(eventHandlers[G_EVENT_KEY_UP])
|
||||
{
|
||||
const void* args[1] = {&event->key.code};
|
||||
m3_Call(exports[G_EXPORT_ON_KEY_UP], 1, args);
|
||||
m3_Call(eventHandlers[G_EVENT_KEY_UP], 1, args);
|
||||
}
|
||||
}
|
||||
} break;
|
||||
|
@ -749,10 +740,10 @@ void* orca_runloop(void* user)
|
|||
mg_render(app->debugOverlay.surface, app->debugOverlay.canvas);
|
||||
}
|
||||
|
||||
if(exports[G_EXPORT_ON_FRAME_REFRESH])
|
||||
if(eventHandlers[G_EVENT_FRAME_REFRESH])
|
||||
{
|
||||
mg_surface_prepare(app->surface);
|
||||
m3_Call(exports[G_EXPORT_ON_FRAME_REFRESH], 0, 0);
|
||||
m3_Call(eventHandlers[G_EVENT_FRAME_REFRESH], 0, 0);
|
||||
}
|
||||
|
||||
if(app->debugOverlay.show)
|
||||
|
|
|
@ -14,43 +14,41 @@
|
|||
#include"m3_env.h"
|
||||
#include"m3_compile.h"
|
||||
|
||||
#define G_EXPORTS(X) \
|
||||
X(G_EXPORT_ON_INIT, "OnInit", "", "") \
|
||||
X(G_EXPORT_ON_MOUSE_DOWN, "OnMouseDown", "", "i") \
|
||||
X(G_EXPORT_ON_MOUSE_UP, "OnMouseUp", "", "i") \
|
||||
X(G_EXPORT_ON_MOUSE_ENTER, "OnMouseEnter", "", "") \
|
||||
X(G_EXPORT_ON_MOUSE_LEAVE, "OnMouseLeave", "", "") \
|
||||
X(G_EXPORT_ON_MOUSE_MOVE, "OnMouseMove", "", "ffff") \
|
||||
X(G_EXPORT_ON_MOUSE_WHEEL, "OnMouseWheel", "", "ff") \
|
||||
X(G_EXPORT_ON_KEY_DOWN, "OnKeyDown", "", "i") \
|
||||
X(G_EXPORT_ON_KEY_UP, "OnKeyUp", "", "i") \
|
||||
X(G_EXPORT_ON_FRAME_REFRESH, "OnFrameRefresh", "", "") \
|
||||
X(G_EXPORT_ON_FRAME_RESIZE, "OnFrameResize", "", "ii") \
|
||||
X(G_EXPORT_ON_RAW_EVENT, "OnRawEvent", "", "i") \
|
||||
X(G_EXPORT_GET_RAW_EVENT_PTR, "_OrcaGetRawEventPtr", "i", "") \
|
||||
X(G_EXPORT_CLOCK_INIT, "_OrcaClockInit", "", "")
|
||||
#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") \
|
||||
X(G_EVENT_RAW_EVENT, "OnRawEvent", "", "i") \
|
||||
|
||||
typedef enum {
|
||||
#define G_EXPORT_KIND(kind, ...) kind,
|
||||
G_EXPORTS(G_EXPORT_KIND)
|
||||
G_EXPORT_COUNT
|
||||
} guest_export_kind;
|
||||
#define G_EVENT_KIND(kind, ...) kind,
|
||||
G_EVENTS(G_EVENT_KIND)
|
||||
G_EVENT_COUNT
|
||||
} guest_event_kind;
|
||||
|
||||
|
||||
typedef struct g_export_desc
|
||||
typedef struct g_event_handler_desc
|
||||
{
|
||||
str8 name;
|
||||
str8 retTags;
|
||||
str8 argTags;
|
||||
} g_export_desc;
|
||||
} g_event_handler_desc;
|
||||
|
||||
const g_export_desc G_EXPORT_DESC[] = {
|
||||
const g_event_handler_desc G_EVENT_HANDLER_DESC[] = {
|
||||
#define STR8LIT(s) {sizeof(s)-1, s} //NOTE: msvc doesn't accept STR8(s) as compile-time constant...
|
||||
#define G_EXPORT_DESC_ENTRY(kind, name, rets, args) {STR8LIT(name), STR8LIT(rets), STR8LIT(args)},
|
||||
#define G_EVENT_HANDLER_DESC_ENTRY(kind, name, rets, args) {STR8LIT(name), STR8LIT(rets), STR8LIT(args)},
|
||||
|
||||
G_EXPORTS(G_EXPORT_DESC_ENTRY)
|
||||
G_EVENTS(G_EVENT_HANDLER_DESC_ENTRY)
|
||||
|
||||
#undef G_EXPORT_DESC_ENTRY
|
||||
#undef G_EVENT_HANDLER_DESC_ENTRY
|
||||
#undef STR8LIT
|
||||
};
|
||||
|
||||
|
@ -71,7 +69,7 @@ typedef struct orca_runtime
|
|||
IM3Environment m3Env;
|
||||
IM3Runtime m3Runtime;
|
||||
IM3Module m3Module;
|
||||
IM3Function exports[G_EXPORT_COUNT];
|
||||
IM3Function eventHandlers[G_EVENT_COUNT];
|
||||
u32 rawEventOffset;
|
||||
|
||||
} orca_runtime;
|
||||
|
|
Loading…
Reference in New Issue