diff --git a/libs/app/include/psemek/app/storage.hpp b/libs/app/include/psemek/app/storage.hpp new file mode 100644 index 00000000..67e48432 --- /dev/null +++ b/libs/app/include/psemek/app/storage.hpp @@ -0,0 +1,18 @@ +#pragma once + +#include + +#include +#include + +namespace psemek::app +{ + + std::filesystem::path storage_root(); + void set_storage_root(std::filesystem::path const & root); + + // Implemented by a backend library + std::unique_ptr read_storage(std::filesystem::path const & relative_path); + std::unique_ptr write_storage(std::filesystem::path const & relative_path); + +} diff --git a/libs/app/source/storage.cpp b/libs/app/source/storage.cpp new file mode 100644 index 00000000..c9a0fd17 --- /dev/null +++ b/libs/app/source/storage.cpp @@ -0,0 +1,24 @@ +#include +#include + +namespace psemek::app +{ + + namespace + { + + static std::filesystem::path global_storage_root = util::executable_path().parent_path(); + + } + + std::filesystem::path storage_root() + { + return global_storage_root; + } + + void set_storage_root(std::filesystem::path const & root) + { + global_storage_root = root; + } + +} diff --git a/libs/sdl2/source/main.cpp b/libs/sdl2/source/main.cpp index 3e5d6152..ce68b2ce 100644 --- a/libs/sdl2/source/main.cpp +++ b/libs/sdl2/source/main.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -56,6 +57,10 @@ int main(int argc, char ** argv) try // In web builds, resources are stored in // the Emscripten virtual filesystem app::set_resource_root("/resources"); + + backend_t opfs = wasmfs_create_opfs_backend(); + wasmfs_create_directory("/storage", 0777, opfs); + app::set_storage_root("/storage"); #endif auto const factory = app::make_application_factory(); diff --git a/libs/sdl2/source/storage.cpp b/libs/sdl2/source/storage.cpp new file mode 100644 index 00000000..d2fd0ba0 --- /dev/null +++ b/libs/sdl2/source/storage.cpp @@ -0,0 +1,20 @@ +#include +#include +#include + +namespace psemek::app +{ + + std::unique_ptr read_storage(std::filesystem::path const & relative_path) + { + log::info() << "Reading storage " << relative_path; + return std::make_unique(app::storage_root() / relative_path); + } + + std::unique_ptr write_storage(std::filesystem::path const & relative_path) + { + log::info() << "Writing storage " << relative_path; + return std::make_unique(app::storage_root() / relative_path); + } + +} diff --git a/package/CMakeLists.txt b/package/CMakeLists.txt index cbb1bd1a..71ea1900 100644 --- a/package/CMakeLists.txt +++ b/package/CMakeLists.txt @@ -8,7 +8,7 @@ if(PSEMEK_PACKAGE_MODE) set(PSEMEK_PACKAGE_LINK_FLAGS_RAW) if(PSEMEK_PLATFORM_WEB) - list(APPEND PSEMEK_PACKAGE_LINK_FLAGS_RAW "-sMIN_WEBGL_VERSION=2" "-sNO_DISABLE_EXCEPTION_CATCHING" "-sFULL_ES3") + list(APPEND PSEMEK_PACKAGE_LINK_FLAGS_RAW -sUSE_SDL=2 -sMIN_WEBGL_VERSION=2 -sNO_DISABLE_EXCEPTION_CATCHING -sFULL_ES3 -sWASMFS -sALLOW_MEMORY_GROWTH -sGROWABLE_ARRAYBUFFERS=0 -sASYNCIFY) list(APPEND PSEMEK_PACKAGE_LINK_FLAGS_RAW "-sDEFAULT_LIBRARY_FUNCS_TO_INCLUDE='$autoResumeAudioContext','$dynCall'") if(CMAKE_BUILD_TYPE STREQUAL Debug) list(APPEND PSEMEK_PACKAGE_LINK_FLAGS_RAW "-g")