Skip to content

Commit fa7d825

Browse files
committed
fixed syncfs
1 parent c102ae2 commit fa7d825

File tree

5 files changed

+38
-3
lines changed

5 files changed

+38
-3
lines changed

.clinerules/build-directory.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
## Brief overview
2+
Guidelines for organizing builds in TIC-80, specifying the standard location for build artifacts to maintain consistency across different build types.
3+
4+
## Build Location
5+
- Always build projects in the 'build' folder to keep build artifacts organized and avoid cluttering the source directory.
6+
7+
## Project-Specific Notes
8+
- Applies to all TIC-80 build configurations, including SDL, Sokol, and Emscripten builds.

.clinerules/emscripten-build.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
## Brief overview
2+
Guidelines for building TIC-80 with Emscripten support, ensuring proper configuration for web deployment with IDBFS.
3+
4+
## Emscripten Configuration
5+
- Use `emcmake cmake -G Ninja .. --fresh` to configure the build for Emscripten, ensuring a clean and proper setup for cross-compilation.
6+
7+
## Project-Specific Notes
8+
- This rule applies to TIC-80 projects requiring Emscripten builds for web platforms.

cmake/sokol.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ if(BUILD_SOKOL)
9696
elseif(EMSCRIPTEN)
9797
add_executable(tic80 ${TIC80_SRC})
9898

99-
set(LINK_FLAGS "-s EXPORT_ES6=1 -s ALLOW_MEMORY_GROWTH=1 -s FETCH=1 -s DEFAULT_LIBRARY_FUNCS_TO_INCLUDE=['$dynCall','$writeArrayToMemory'] -s EXPORTED_RUNTIME_METHODS=['FS'] -s EXPORTED_FUNCTIONS=['_main','_free','_force_exit']")
99+
set(LINK_FLAGS "-s EXPORT_ES6=1 -s ALLOW_MEMORY_GROWTH=1 -s FETCH=1 -lidbfs.js -s DEFAULT_LIBRARY_FUNCS_TO_INCLUDE=['$dynCall','$writeArrayToMemory'] -s EXPORTED_RUNTIME_METHODS=['FS'] -s EXPORTED_FUNCTIONS=['_main','_free','_force_exit']")
100100

101101
if(BUILD_SOKOL_WEBGPU)
102102
set_target_properties(tic80 PROPERTIES LINK_FLAGS "${LINK_FLAGS} --use-port=emdawnwebgpu")

src/studio/fs.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,12 @@ struct tic_fs
7474
void syncfs()
7575
{
7676
#if defined(__TIC_EMSCRIPTEN__)
77-
EM_ASM({Module.syncFSRequests++;});
77+
EM_ASM({
78+
if (Module.syncTimerId) { clearTimeout(Module.syncTimerId); }
79+
Module.syncTimerId = setTimeout(function() {
80+
FS.syncfs(function(err){});
81+
}, 100);
82+
});
7883
#endif
7984
}
8085

src/system/sokol/main.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1028,7 +1028,21 @@ sapp_desc sokol_main(s32 argc, char* argv[])
10281028
}
10291029

10301030
const char* path = ssys_app_folder(TIC_PACKAGE, TIC_NAME);
1031-
app->studio = studio_create(argc, argv, cli ? TIC80_SAMPLERATE : saudio_sample_rate(),
1031+
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+
1045+
app->studio = studio_create(argc, argv, cli ? TIC80_SAMPLERATE : saudio_sample_rate(),
10321046
TIC80_PIXEL_COLOR_RGBA8888, path, INT32_MAX, app);
10331047

10341048
if(cli)

0 commit comments

Comments
 (0)