Load rxdata async

This commit is contained in:
Varun Patil 2020-05-05 16:00:11 +05:30
parent ebe8d6f3bd
commit ba2e08ec55
3 changed files with 29 additions and 2 deletions

View file

@ -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();

View file

@ -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;