Load rxdata async
This commit is contained in:
parent
ebe8d6f3bd
commit
ba2e08ec55
|
@ -261,6 +261,22 @@ runRMXPScripts(mrb_state *mrb, mrbc_context *ctx)
|
|||
return;
|
||||
}
|
||||
|
||||
/* Load Ruby Game Scripting System from rgss.rb */
|
||||
try
|
||||
{
|
||||
SDL_rw_file_helper fileHelper;
|
||||
fileHelper.filename = "rgss.rb";
|
||||
char * contents = fileHelper.read();
|
||||
int ai = mrb_gc_arena_save(mrb);
|
||||
mrb_load_nstring_cxt(mrb, contents, fileHelper.length, ctx);
|
||||
mrb_gc_arena_restore(mrb, ai);
|
||||
}
|
||||
catch (const Exception &e)
|
||||
{
|
||||
printf("Failed to read rgss.rb\n");
|
||||
return;
|
||||
}
|
||||
|
||||
/* We use a secondary util state to unmarshal the scripts */
|
||||
mrb_state *scriptMrb = mrb_open();
|
||||
|
||||
|
|
|
@ -2,7 +2,16 @@
|
|||
#include "file-helper.h"
|
||||
#include <SDL_rwops.h>
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
#include "emscripten.hpp"
|
||||
#endif
|
||||
|
||||
char* SDL_rw_file_helper::read() {
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
load_file_async_js(filename);
|
||||
#endif
|
||||
|
||||
SDL_RWops *rw = SDL_RWFromFile(filename, "rb");
|
||||
if (rw == NULL) return NULL;
|
||||
|
||||
|
|
|
@ -28,8 +28,10 @@ EM_JS(void, load_file_async_js, (const char* fullPathC), {
|
|||
// Get target URL
|
||||
const iurl = "gameasync/" + fullPath;
|
||||
|
||||
// Delete original file
|
||||
FS.unlink(path + "/" + filename);
|
||||
// Delete original file if existent
|
||||
try {
|
||||
FS.unlink(path + "/" + filename);
|
||||
} catch (err) {}
|
||||
|
||||
// Get the new file
|
||||
FS.createPreloadedFile(path, filename, iurl, true, true, function() {
|
||||
|
|
Loading…
Reference in New Issue