Skip to content

Commit 5809d74

Browse files
committed
init emscripten dbfs before app start
1 parent fa7d825 commit 5809d74

File tree

3 files changed

+48
-14
lines changed

3 files changed

+48
-14
lines changed

cmake/sokol.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ if(BUILD_SOKOL)
1616
target_compile_definitions(sokol PUBLIC SOKOL_D3D11 UNICODE)
1717
elseif(EMSCRIPTEN)
1818

19+
target_compile_definitions(sokol PUBLIC SOKOL_NO_ENTRY)
20+
1921
if(BUILD_SOKOL_WEBGPU)
2022
target_compile_definitions(sokol PUBLIC SOKOL_WGPU)
2123
target_compile_options(sokol PRIVATE --use-port=emdawnwebgpu)

src/system/sokol/main.c

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,7 +1011,7 @@ static const sapp_icon_desc iconDesc(App *app)
10111011
};
10121012
}
10131013

1014-
sapp_desc sokol_main(s32 argc, char* argv[])
1014+
sapp_desc sokol_start(s32 argc, char* argv[])
10151015
{
10161016
App *app = NEW(App);
10171017
memset(app, 0, sizeof *app);
@@ -1029,19 +1029,6 @@ sapp_desc sokol_main(s32 argc, char* argv[])
10291029

10301030
const char* path = ssys_app_folder(TIC_PACKAGE, TIC_NAME);
10311031

1032-
#if defined(__TIC_EMSCRIPTEN__)
1033-
EM_ASM_
1034-
(
1035-
{
1036-
var dir = UTF8ToString($0);
1037-
FS.mkdirTree(dir);
1038-
FS.mount(IDBFS, {}, dir);
1039-
FS.syncfs(true, function(err) {});
1040-
1041-
}, path
1042-
);
1043-
#endif
1044-
10451032
app->studio = studio_create(argc, argv, cli ? TIC80_SAMPLERATE : saudio_sample_rate(),
10461033
TIC80_PIXEL_COLOR_RGBA8888, path, INT32_MAX, app);
10471034

src/system/sokol/sokol.c

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,48 @@
2323
#define SOKOL_IMPL
2424

2525
#include "sokol.h"
26+
27+
extern sapp_desc sokol_start(int argc, char* argv[]);
28+
29+
static void start(int argc, char* argv[])
30+
{
31+
sapp_desc desc = sokol_start(argc, argv);
32+
sapp_run(&desc);
33+
}
34+
35+
#if defined(SOKOL_NO_ENTRY)
36+
37+
int main(int argc, char* argv[])
38+
{
39+
#if defined(__EMSCRIPTEN__)
40+
41+
EM_ASM_
42+
(
43+
{
44+
var dir = 'com.nesbox.tic/TIC-80/';
45+
FS.mkdirTree(dir);
46+
FS.mount(IDBFS, {}, dir);
47+
FS.syncfs(true, function(err) {
48+
dynCall('vip', $0, [$1, $2]);
49+
});
50+
51+
}, start, argc, argv
52+
);
53+
54+
#else
55+
56+
start(argc, argv)
57+
58+
#endif
59+
60+
return 0;
61+
}
62+
63+
#else
64+
65+
sapp_desc sokol_main(s32 argc, char* argv[])
66+
{
67+
return sokol_start(argc, argv);
68+
}
69+
70+
#endif

0 commit comments

Comments
 (0)