From a012c6d3e765f528e1b6eec20a944599a94fadc3 Mon Sep 17 00:00:00 2001 From: elasota Date: Fri, 7 May 2021 20:12:41 -0400 Subject: [PATCH] Fix web build and add export path --- AerofoilWeb/BuildAerofoilPortable.bat | 11 +++++++++++ AerofoilWeb/BuildAerofoilWeb.bat | 6 +++++- AerofoilWeb/GpFileSystem_Web.cpp | 26 ++++++++++++++++++-------- AerofoilWeb/GpFileSystem_Web.h | 1 + AerofoilWeb/GpMain_SDL_Web.cpp | 12 ++++++++++-- AerofoilWeb/Link.bat | 8 ++++++-- 6 files changed, 51 insertions(+), 13 deletions(-) create mode 100644 AerofoilWeb/BuildAerofoilPortable.bat diff --git a/AerofoilWeb/BuildAerofoilPortable.bat b/AerofoilWeb/BuildAerofoilPortable.bat new file mode 100644 index 0000000..6badad6 --- /dev/null +++ b/AerofoilWeb/BuildAerofoilPortable.bat @@ -0,0 +1,11 @@ +set INPUT_DIR=../AerofoilPortable +set OUTPUT_DIR=obj + +rem set DEBUG_LEVEL_FLAGS=-g4 -O0 +set DEBUG_LEVEL_FLAGS=-O3 + +set FLAGS=-s USE_SDL=2 -flto -I../GpCommon/ -I../Common/ -s ASYNCIFY %DEBUG_LEVEL_FLAGS% -DGP_DEBUG_CONFIG=0 + +emcc -c %INPUT_DIR%/GpAllocator_C.cpp -o %OUTPUT_DIR%/AerofoilPortable_Combined.o %FLAGS% + +pause diff --git a/AerofoilWeb/BuildAerofoilWeb.bat b/AerofoilWeb/BuildAerofoilWeb.bat index 56e6b65..f072b72 100644 --- a/AerofoilWeb/BuildAerofoilWeb.bat +++ b/AerofoilWeb/BuildAerofoilWeb.bat @@ -1,6 +1,10 @@ set INPUT_DIR=. set OUTPUT_DIR=obj -set FLAGS=-s USE_SDL=2 -flto -I../GpCommon/ -I../PortabilityLayer/ -I../Common/ -I../GpShell/ -s ASYNCIFY -O3 -DGP_DEBUG_CONFIG=0 + +rem set DEBUG_LEVEL_FLAGS=-g4 -O0 +set DEBUG_LEVEL_FLAGS=-O3 + +set FLAGS=-s USE_SDL=2 -flto -I../GpCommon/ -I../PortabilityLayer/ -I../Common/ -I../AerofoilPortable/ -I../GpShell/ -s ASYNCIFY %DEBUG_LEVEL_FLAGS% -DGP_DEBUG_CONFIG=0 emcc -c %INPUT_DIR%/AerofoilWeb_Combined.cpp -o %OUTPUT_DIR%/AerofoilWeb_Combined.o %FLAGS% diff --git a/AerofoilWeb/GpFileSystem_Web.cpp b/AerofoilWeb/GpFileSystem_Web.cpp index a5da4b6..b823a12 100644 --- a/AerofoilWeb/GpFileSystem_Web.cpp +++ b/AerofoilWeb/GpFileSystem_Web.cpp @@ -386,7 +386,8 @@ bool GpFileSystem_Web::ms_fsStateDirty; bool GpFileSystem_Web::ResolvePath(PortabilityLayer::VirtualDirectory_t virtualDirectory, char const* const* paths, size_t numPaths, bool trailingSlash, std::string &resolution) { - const char *prefsAppend = nullptr; + const char *pathAppend = nullptr; + const std::string *rootPath = nullptr; std::string unsanitized; switch (virtualDirectory) @@ -401,24 +402,32 @@ bool GpFileSystem_Web::ResolvePath(PortabilityLayer::VirtualDirectory_t virtualD unsanitized = std::string("Resources"); break; case PortabilityLayer::VirtualDirectories::kHighScores: - prefsAppend = "HighScores"; + pathAppend = "HighScores"; + rootPath = &m_basePath; break; case PortabilityLayer::VirtualDirectories::kUserData: - prefsAppend = "Houses"; + pathAppend = "Houses"; + rootPath = &m_basePath; break; case PortabilityLayer::VirtualDirectories::kUserSaves: - prefsAppend = "SavedGames"; + pathAppend = "SavedGames"; + rootPath = &m_basePath; break; case PortabilityLayer::VirtualDirectories::kPrefs: - prefsAppend = "Prefs"; + pathAppend = "Prefs"; + rootPath = &m_basePath; + break; + case PortabilityLayer::VirtualDirectories::kSourceExport: + pathAppend = "Export"; + rootPath = &m_exportPath; break; default: return false; }; - if (prefsAppend) + if (pathAppend) { - unsanitized = prefsAppend; + unsanitized = pathAppend; for (size_t i = 0; i < numPaths; i++) { @@ -448,7 +457,7 @@ bool GpFileSystem_Web::ResolvePath(PortabilityLayer::VirtualDirectory_t virtualD } } - resolution = m_prefsPath + "/" + sanitized; + resolution = (*rootPath) + "/" + sanitized; } else { @@ -478,6 +487,7 @@ GpFileSystem_Web::~GpFileSystem_Web() void GpFileSystem_Web::Init() { m_prefsPath = "/aerofoil"; + m_exportPath = "/aerofoil_memfs"; char *baseDir = SDL_GetBasePath(); m_basePath = baseDir; diff --git a/AerofoilWeb/GpFileSystem_Web.h b/AerofoilWeb/GpFileSystem_Web.h index 3eb7b81..f0ae197 100644 --- a/AerofoilWeb/GpFileSystem_Web.h +++ b/AerofoilWeb/GpFileSystem_Web.h @@ -60,6 +60,7 @@ private: std::string m_prefsPath; std::string m_basePath; + std::string m_exportPath; static bool ms_fsStateDirty; static GpFileSystem_Web ms_instance; diff --git a/AerofoilWeb/GpMain_SDL_Web.cpp b/AerofoilWeb/GpMain_SDL_Web.cpp index 6ca001c..9ef6412 100644 --- a/AerofoilWeb/GpMain_SDL_Web.cpp +++ b/AerofoilWeb/GpMain_SDL_Web.cpp @@ -2,6 +2,7 @@ #include "SDL_main.h" #include "GpMain.h" +#include "GpAllocator_C.h" #include "GpAudioDriverFactory.h" #include "GpDisplayDriverFactory.h" #include "GpGlobalConfig.h" @@ -28,9 +29,12 @@ IGpAudioDriver *GpDriver_CreateAudioDriver_SDL(const GpAudioDriverProperties &pr IGpInputDriver *GpDriver_CreateInputDriver_SDL2_Gamepad(const GpInputDriverProperties &properties); EM_JS(void, InitFileSystem, (), { - Asyncify.handleSleep(wakeUp => { - FS.mkdir('/aerofoil'); + Asyncify.handleSleep(wakeUp => { + FS.mkdir('/aerofoil'); + //FS.mkdir('/aerofoil_memfs'); FS.mount(IDBFS, {}, '/aerofoil'); + //FS.mount(MEMFS, {}, '/aerofoil_memfs'); + //FS.mkdir('/aerofoil_memfs/Export'); FS.syncfs(true, function (err) { assert(!err); wakeUp(); @@ -40,6 +44,8 @@ EM_JS(void, InitFileSystem, (), { int main(int argc, char* argv[]) { + IGpAllocator *alloc = GpAllocator_C::GetInstance(); + InitFileSystem(); GpLogDriver_Web::Init(); @@ -65,6 +71,7 @@ int main(int argc, char* argv[]) drivers->SetDriver(GpFileSystem_Web::GetInstance()); drivers->SetDriver(GpSystemServices_Web::GetInstance()); drivers->SetDriver(GpLogDriver_Web::GetInstance()); + drivers->SetDriver(alloc); g_gpGlobalConfig.m_displayDriverType = EGpDisplayDriverType_SDL_GL2; @@ -83,6 +90,7 @@ int main(int argc, char* argv[]) g_gpGlobalConfig.m_osGlobals = &g_gpXGlobals; g_gpGlobalConfig.m_logger = logger; g_gpGlobalConfig.m_systemServices = GpSystemServices_Web::GetInstance(); + g_gpGlobalConfig.m_allocator = alloc; GpDisplayDriverFactory::RegisterDisplayDriverFactory(EGpDisplayDriverType_SDL_GL2, GpDriver_CreateDisplayDriver_SDL_GL2); GpAudioDriverFactory::RegisterAudioDriverFactory(EGpAudioDriverType_SDL2, GpDriver_CreateAudioDriver_SDL); diff --git a/AerofoilWeb/Link.bat b/AerofoilWeb/Link.bat index 5ea6d17..39524b1 100644 --- a/AerofoilWeb/Link.bat +++ b/AerofoilWeb/Link.bat @@ -1,4 +1,8 @@ set INPUT_DIR=. set OUTPUT_DIR=bin -set FLAGS=-flto -O3 -s USE_SDL=2 -s USE_ZLIB=1 -s ASYNCIFY -s ASYNCIFY_IGNORE_INDIRECT -s INITIAL_MEMORY=33554432 -s ASYNCIFY_ADVISE -lidbfs.js -s ASYNCIFY_IMPORTS=['InitFileSystem','FlushFileSystem'] --shell-file shell_minimal.html -emcc obj/AerofoilWeb_Combined.o obj/AerofoilWeb_Resources.o obj/GpShell_Combined.o obj/AerofoilSDL_Combined.o obj/GpApp_Combined.o obj/PortabilityLayer_Combined.o obj/MacRomanConversion.o -o %OUTPUT_DIR%/aerofoil.html %FLAGS% + +rem set DEBUG_LEVEL_FLAGS=-g4 -O0 +set DEBUG_LEVEL_FLAGS=-O3 + +set FLAGS=-flto %DEBUG_LEVEL_FLAGS% -s USE_SDL=2 -s USE_ZLIB=1 -s ASYNCIFY -s ASYNCIFY_IGNORE_INDIRECT -s INITIAL_MEMORY=33554432 -s ASYNCIFY_ADVISE -lidbfs.js -s ASYNCIFY_IMPORTS=['InitFileSystem','FlushFileSystem'] --shell-file shell_minimal.html +emcc obj/AerofoilWeb_Combined.o obj/AerofoilWeb_Resources.o obj/GpShell_Combined.o obj/AerofoilSDL_Combined.o obj/AerofoilPortable_Combined.o obj/GpApp_Combined.o obj/PortabilityLayer_Combined.o obj/MacRomanConversion.o -o %OUTPUT_DIR%/aerofoil.html %FLAGS%