Web save mechanism

This commit is contained in:
elasota
2021-05-07 23:09:35 -04:00
parent 1ac8032411
commit fb7b9b02d9
7 changed files with 977 additions and 924 deletions

4
.gitmodules vendored Normal file
View File

@@ -0,0 +1,4 @@
[submodule "AerofoilWeb/FileSaverDotJS"]
path = AerofoilWeb/FileSaverDotJS
url = https://github.com/eligrey/FileSaver.js.git
branch = master

File diff suppressed because it is too large Load Diff

View File

@@ -30,6 +30,7 @@ public:
void SetDelayCallback(DelayCallback_t delayCallback) override; void SetDelayCallback(DelayCallback_t delayCallback) override;
static void MarkFSStateDirty(); static void MarkFSStateDirty();
static void SyncDownloadFile(const std::string &filePath, const std::string &prettyName);
static void FlushFS(); static void FlushFS();
static GpFileSystem_Web *GetInstance(); static GpFileSystem_Web *GetInstance();
@@ -54,7 +55,7 @@ private:
static IGpDirectoryCursor *ScanCatalog(const GpFileSystem_Web_Resources::FileCatalog &catalog); static IGpDirectoryCursor *ScanCatalog(const GpFileSystem_Web_Resources::FileCatalog &catalog);
bool ResolvePath(PortabilityLayer::VirtualDirectory_t virtualDirectory, char const* const* paths, size_t numPaths, bool trailingSlash, std::string &resolution); bool ResolvePath(PortabilityLayer::VirtualDirectory_t virtualDirectory, char const* const* paths, size_t numPaths, bool trailingSlash, std::string &resolution, bool &outIsIDB);
DelayCallback_t m_delayCallback; DelayCallback_t m_delayCallback;

View File

@@ -1,110 +1,109 @@
#include <SDL.h> #include <SDL.h>
#include "SDL_main.h" #include "SDL_main.h"
#include "GpMain.h" #include "GpMain.h"
#include "GpAllocator_C.h" #include "GpAllocator_C.h"
#include "GpAudioDriverFactory.h" #include "GpAudioDriverFactory.h"
#include "GpDisplayDriverFactory.h" #include "GpDisplayDriverFactory.h"
#include "GpGlobalConfig.h" #include "GpGlobalConfig.h"
#include "GpFileSystem_Web.h" #include "GpFileSystem_Web.h"
#include "GpLogDriver_Web.h" #include "GpLogDriver_Web.h"
#include "GpFontHandlerFactory.h" #include "GpFontHandlerFactory.h"
#include "GpInputDriverFactory.h" #include "GpInputDriverFactory.h"
#include "GpAppInterface.h" #include "GpAppInterface.h"
#include "GpSystemServices_Web.h" #include "GpSystemServices_Web.h"
#include "GpVOSEvent.h" #include "GpVOSEvent.h"
#include "GpX.h" #include "GpX.h"
#include "IGpFileSystem.h" #include "IGpFileSystem.h"
#include "IGpThreadEvent.h" #include "IGpThreadEvent.h"
#include "IGpVOSEventQueue.h" #include "IGpVOSEventQueue.h"
#include <string> #include <string>
#include <emscripten.h> #include <emscripten.h>
GpXGlobals g_gpXGlobals; GpXGlobals g_gpXGlobals;
IGpDisplayDriver *GpDriver_CreateDisplayDriver_SDL_GL2(const GpDisplayDriverProperties &properties); IGpDisplayDriver *GpDriver_CreateDisplayDriver_SDL_GL2(const GpDisplayDriverProperties &properties);
IGpAudioDriver *GpDriver_CreateAudioDriver_SDL(const GpAudioDriverProperties &properties); IGpAudioDriver *GpDriver_CreateAudioDriver_SDL(const GpAudioDriverProperties &properties);
IGpInputDriver *GpDriver_CreateInputDriver_SDL2_Gamepad(const GpInputDriverProperties &properties); IGpInputDriver *GpDriver_CreateInputDriver_SDL2_Gamepad(const GpInputDriverProperties &properties);
EM_JS(void, InitFileSystem, (), { EM_JS(void, InitFileSystem, (), {
Asyncify.handleSleep(wakeUp => { Asyncify.handleSleep(wakeUp => {
FS.mkdir('/aerofoil'); FS.mkdir('/aerofoil');
//FS.mkdir('/aerofoil_memfs'); FS.mkdir('/aerofoil_memfs');
FS.mount(IDBFS, {}, '/aerofoil'); FS.mount(IDBFS, {}, '/aerofoil');
//FS.mount(MEMFS, {}, '/aerofoil_memfs'); FS.mount(MEMFS, {}, '/aerofoil_memfs');
//FS.mkdir('/aerofoil_memfs/Export'); FS.syncfs(true, function (err) {
FS.syncfs(true, function (err) { assert(!err);
assert(!err); wakeUp();
wakeUp(); });
}); });
}); });
});
int main(int argc, char* argv[])
int main(int argc, char* argv[]) {
{ IGpAllocator *alloc = GpAllocator_C::GetInstance();
IGpAllocator *alloc = GpAllocator_C::GetInstance();
InitFileSystem();
InitFileSystem();
GpLogDriver_Web::Init();
GpLogDriver_Web::Init(); IGpLogDriver *logger = GpLogDriver_Web::GetInstance();
IGpLogDriver *logger = GpLogDriver_Web::GetInstance();
#if GP_ASYNCIFY_PARANOID
#if GP_ASYNCIFY_PARANOID SDL_SetHint(SDL_HINT_EMSCRIPTEN_ASYNCIFY, "0");
SDL_SetHint(SDL_HINT_EMSCRIPTEN_ASYNCIFY, "0"); #endif
#endif
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMECONTROLLER) < 0)
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMECONTROLLER) < 0) return -1;
return -1;
if (logger)
if (logger) logger->Printf(IGpLogDriver::Category_Information, "Starting filesystem...");
logger->Printf(IGpLogDriver::Category_Information, "Starting filesystem...");
GpFileSystem_Web::GetInstance()->Init();
GpFileSystem_Web::GetInstance()->Init();
GpDriverCollection *drivers = GpAppInterface_Get()->PL_GetDriverCollection();
GpDriverCollection *drivers = GpAppInterface_Get()->PL_GetDriverCollection();
if (logger)
if (logger) logger->Printf(IGpLogDriver::Category_Information, "Setting up drivers...");
logger->Printf(IGpLogDriver::Category_Information, "Setting up drivers...");
drivers->SetDriver<GpDriverIDs::kFileSystem>(GpFileSystem_Web::GetInstance());
drivers->SetDriver<GpDriverIDs::kFileSystem>(GpFileSystem_Web::GetInstance()); drivers->SetDriver<GpDriverIDs::kSystemServices>(GpSystemServices_Web::GetInstance());
drivers->SetDriver<GpDriverIDs::kSystemServices>(GpSystemServices_Web::GetInstance()); drivers->SetDriver<GpDriverIDs::kLog>(GpLogDriver_Web::GetInstance());
drivers->SetDriver<GpDriverIDs::kLog>(GpLogDriver_Web::GetInstance()); drivers->SetDriver<GpDriverIDs::kAlloc>(alloc);
drivers->SetDriver<GpDriverIDs::kAlloc>(alloc);
g_gpGlobalConfig.m_displayDriverType = EGpDisplayDriverType_SDL_GL2;
g_gpGlobalConfig.m_displayDriverType = EGpDisplayDriverType_SDL_GL2;
g_gpGlobalConfig.m_audioDriverType = EGpAudioDriverType_SDL2;
g_gpGlobalConfig.m_audioDriverType = EGpAudioDriverType_SDL2;
g_gpGlobalConfig.m_fontHandlerType = EGpFontHandlerType_None;
g_gpGlobalConfig.m_fontHandlerType = EGpFontHandlerType_None;
EGpInputDriverType inputDrivers[] =
EGpInputDriverType inputDrivers[] = {
{ EGpInputDriverType_SDL2_Gamepad
EGpInputDriverType_SDL2_Gamepad };
};
g_gpGlobalConfig.m_inputDriverTypes = inputDrivers;
g_gpGlobalConfig.m_inputDriverTypes = inputDrivers; g_gpGlobalConfig.m_numInputDrivers = sizeof(inputDrivers) / sizeof(inputDrivers[0]);
g_gpGlobalConfig.m_numInputDrivers = sizeof(inputDrivers) / sizeof(inputDrivers[0]);
g_gpGlobalConfig.m_osGlobals = &g_gpXGlobals;
g_gpGlobalConfig.m_osGlobals = &g_gpXGlobals; g_gpGlobalConfig.m_logger = logger;
g_gpGlobalConfig.m_logger = logger; g_gpGlobalConfig.m_systemServices = GpSystemServices_Web::GetInstance();
g_gpGlobalConfig.m_systemServices = GpSystemServices_Web::GetInstance(); g_gpGlobalConfig.m_allocator = alloc;
g_gpGlobalConfig.m_allocator = alloc;
GpDisplayDriverFactory::RegisterDisplayDriverFactory(EGpDisplayDriverType_SDL_GL2, GpDriver_CreateDisplayDriver_SDL_GL2);
GpDisplayDriverFactory::RegisterDisplayDriverFactory(EGpDisplayDriverType_SDL_GL2, GpDriver_CreateDisplayDriver_SDL_GL2); GpAudioDriverFactory::RegisterAudioDriverFactory(EGpAudioDriverType_SDL2, GpDriver_CreateAudioDriver_SDL);
GpAudioDriverFactory::RegisterAudioDriverFactory(EGpAudioDriverType_SDL2, GpDriver_CreateAudioDriver_SDL); GpInputDriverFactory::RegisterInputDriverFactory(EGpInputDriverType_SDL2_Gamepad, GpDriver_CreateInputDriver_SDL2_Gamepad);
GpInputDriverFactory::RegisterInputDriverFactory(EGpInputDriverType_SDL2_Gamepad, GpDriver_CreateInputDriver_SDL2_Gamepad);
if (logger)
if (logger) logger->Printf(IGpLogDriver::Category_Information, "SDL environment configured, starting up");
logger->Printf(IGpLogDriver::Category_Information, "SDL environment configured, starting up");
int returnCode = GpMain::Run();
int returnCode = GpMain::Run();
if (logger)
if (logger) logger->Printf(IGpLogDriver::Category_Information, "SDL environment exited with code %i, cleaning up", returnCode);
logger->Printf(IGpLogDriver::Category_Information, "SDL environment exited with code %i, cleaning up", returnCode);
SDL_Quit();
SDL_Quit();
return returnCode;
return returnCode; }
}

View File

@@ -4,5 +4,7 @@ set OUTPUT_DIR=bin
rem set DEBUG_LEVEL_FLAGS=-g4 -O0 rem set DEBUG_LEVEL_FLAGS=-g4 -O0
set DEBUG_LEVEL_FLAGS=-O3 set DEBUG_LEVEL_FLAGS=-O3
copy /Y FileSaverDotJS\dist\FileSaver.js bin\FileSaver.js
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 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% 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%

View File

@@ -3,7 +3,7 @@
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Aerofoil Web Pre-Release</title> <title>Aerofoil</title>
<style> <style>
.emscripten { padding-right: 0; padding-top: 0; margin-left: auto; margin-right: auto; margin-top: 0; display: block; } .emscripten { padding-right: 0; padding-top: 0; margin-left: auto; margin-right: auto; margin-top: 0; display: block; }
textarea.emscripten { font-family: monospace; width: 80%; } textarea.emscripten { font-family: monospace; width: 80%; }
@@ -135,6 +135,7 @@
}; };
}; };
</script> </script>
<script type="text/javascript" src="FileSaver.js"></script>
{{{ SCRIPT }}} {{{ SCRIPT }}}
</body> </body>
</html> </html>