Add async image load

This commit is contained in:
Varun Patil 2019-05-08 17:11:57 +05:30
parent 0dbe2008af
commit 5388573dbc
16 changed files with 310 additions and 171 deletions

View File

@ -52,6 +52,8 @@
#ifdef __EMSCRIPTEN__ #ifdef __EMSCRIPTEN__
#include <emscripten.h> #include <emscripten.h>
#include <emscripten/fetch.h>
#include <fstream>
#endif #endif
static void mrbBindingExecute(); static void mrbBindingExecute();
@ -87,9 +89,9 @@ void audioBindingInit(mrb_state *);
void graphicsBindingInit(mrb_state *); void graphicsBindingInit(mrb_state *);
/* From module_rpg.c */ /* From module_rpg.c */
extern const uint8_t mrbModuleRPG[]; extern const uint8_t rpg_mrb[];
static void mrbBindingInit(mrb_state *mrb) static void __attribute__ ((optnone)) mrbBindingInit(mrb_state *mrb)
{ {
int arena = mrb_gc_arena_save(mrb); int arena = mrb_gc_arena_save(mrb);
@ -115,7 +117,7 @@ static void mrbBindingInit(mrb_state *mrb)
graphicsBindingInit(mrb); graphicsBindingInit(mrb);
/* Load RPG module */ /* Load RPG module */
mrb_load_irep(mrb, mrbModuleRPG); mrb_load_irep(mrb, rpg_mrb);
/* Load global constants */ /* Load global constants */
mrb_define_global_const(mrb, "MKXP", mrb_true_value()); mrb_define_global_const(mrb, "MKXP", mrb_true_value());
@ -257,26 +259,32 @@ runMrbFile(mrb_state *mrb, const char *filename)
fclose(f); fclose(f);
} }
static mrb_state * static_mrb; static MrbData * mrbData;
static mrb_state * static_scriptmrb; static mrb_state * static_scriptmrb;
void __attribute__ ((optnone)) main_update_loop() { static void __attribute__ ((optnone)) main_update_loop() {
mrb_load_nstring_cxt(static_mrb, "main_update_loop", 16, NULL); mrb_state * mrb = (mrb_state *) static_cast<mrb_state*>(shState->bindingData());
mrb_load_nstring_cxt(mrb, "main_update_loop", 16, NULL);
#ifdef __EMSCRIPTEN__ #ifdef __EMSCRIPTEN__
if (static_mrb->exc) { if (mrb->exc) {
printf("Execution Errored\n"); printf("Execution Errored\n");
mrb_value s = mrb_funcall(static_mrb, mrb_obj_value(static_mrb->exc), "inspect", 0); mrb_value s = mrb_funcall(mrb, mrb_obj_value(mrb->exc), "inspect", 0);
if (mrb_string_p(s)) { if (mrb_string_p(s)) {
printf("%s", mrb_str_to_cstr(static_mrb, s)); printf("%s", mrb_str_to_cstr(mrb, s));
printf("\n"); printf("\n");
} }
mrb_close(static_scriptmrb); emscripten_cancel_main_loop();
shState->texPool().disable(); //mrb_close(static_scriptmrb);
mrb_close(static_mrb); //shState->texPool().disable();
//mrb_close(static_mrb);
} }
#endif #endif
} }
static bool initialized = false;
static emscripten_fetch_t *fetchScripts;
static std::atomic<int> assetQ;
static void static void
runRMXPScripts(mrb_state *mrb, mrbc_context *ctx) runRMXPScripts(mrb_state *mrb, mrbc_context *ctx)
{ {
@ -302,16 +310,16 @@ runRMXPScripts(mrb_state *mrb, mrbc_context *ctx)
try try
{ {
SDL_rw_file_helper fileHelper; const char * contents = fetchScripts->data;
fileHelper.filename = scriptPack.c_str(); mrb_value rawdata = mrb_str_new_static(mrb, contents, fetchScripts->numBytes);
char * contents = fileHelper.read();
mrb_value rawdata = mrb_str_new_static(mrb, contents, fileHelper.length);
scriptArray = mrb_marshal_load(mrb, rawdata); scriptArray = mrb_marshal_load(mrb, rawdata);
} }
catch (const Exception &e) catch (const Exception &e)
{ {
readError = std::string(": ") + e.msg; readError = std::string(": ") + e.msg;
} }
emscripten_fetch_close(fetchScripts);
fetchScripts = NULL;
if (!mrb_array_p(scriptArray)) if (!mrb_array_p(scriptArray))
{ {
@ -383,51 +391,45 @@ runRMXPScripts(mrb_state *mrb, mrbc_context *ctx)
break; break;
} }
static_mrb = mrb;
static_scriptmrb = scriptMrb; static_scriptmrb = scriptMrb;
#ifdef __EMSCRIPTEN__ #ifdef __EMSCRIPTEN__
/* Use loop for emscripten */
mrb_load_nstring_cxt(static_mrb, "main_update_loop", 16, NULL);
emscripten_set_main_loop(main_update_loop, 0, 1);
return; return;
#else #else
while (true) { while (true) {
main_update_loop(); main_update_loop();
SDL_Delay(3); SDL_Delay(3);
if (static_mrb->exc) if (mrb->exc)
break; break;
} }
mrb_close(scriptMrb); mrb_close(scriptMrb);
#endif #endif
} }
static void mrbBindingExecute() static void __attribute__ ((optnone)) mrbBindingMain()
{ {
mrb_state *mrb = mrb_open(); mrb_state *mrb = mrb_open();
shState->setBindingData(mrb); shState->setBindingData(mrb);
MrbData mrbData(mrb); mrbData = new MrbData(mrb);
mrb->ud = &mrbData; mrb->ud = mrbData;
mrb_define_module_function(mrb, mrb->kernel_module, "time_op", mrb_define_module_function(mrb, mrb->kernel_module, "time_op",
mkxpTimeOp, MRB_ARGS_OPT(2) | MRB_ARGS_BLOCK()); mkxpTimeOp, MRB_ARGS_OPT(2) | MRB_ARGS_BLOCK());
mrbBindingInit(mrb); mrbBindingInit(mrb);
const Config &conf = shState->rtData().config;
const std::string &customScript = conf.customScript;
(void) runMrbFile; // FIXME mrbFile support on ice for now
mrbc_context *ctx = mrbc_context_new(mrb); mrbc_context *ctx = mrbc_context_new(mrb);
ctx->capture_errors = 1; ctx->capture_errors = 1;
const Config &conf = shState->rtData().config; if (!customScript.empty()) {
const std::string &customScript = conf.customScript;
// const std::string &mrbFile = conf.mrbFile;
(void) runMrbFile; // FIXME mrbFile support on ice for now
if (!customScript.empty())
runCustomScript(mrb, ctx, customScript.c_str()); runCustomScript(mrb, ctx, customScript.c_str());
// else if (!mrbFile.empty()) }
// runMrbFile(mrb, mrbFile.c_str());
else else
runRMXPScripts(mrb, ctx); runRMXPScripts(mrb, ctx);
@ -442,6 +444,48 @@ static void mrbBindingExecute()
#endif #endif
} }
void downloadSucceeded(emscripten_fetch_t *fetch) {
printf("Finished downloading %llu bytes from URL %s.\n", fetch->numBytes, fetch->url);
fetchScripts = fetch;
assetQ--;
}
void downloadFailed(emscripten_fetch_t *fetch) {
printf("Downloading %s failed, HTTP failure status code: %d.\n", fetch->url, fetch->status);
fetchScripts = fetch;
assetQ--;
emscripten_fetch_close(fetch);
}
void __attribute__ ((optnone)) supermainloop() {
if (assetQ > 0) return;
if (initialized) {
main_update_loop();
} else {
mrbBindingMain();
initialized = true;
}
}
static void __attribute__ ((optnone)) mrbBindingExecute()
{
assetQ = 1;
emscripten_fetch_attr_t attr;
emscripten_fetch_attr_init(&attr);
strcpy(attr.requestMethod, "GET");
attr.attributes = EMSCRIPTEN_FETCH_LOAD_TO_MEMORY;
attr.onsuccess = downloadSucceeded;
attr.onerror = downloadFailed;
emscripten_fetch(&attr, "async/Data/Scripts.rxdata");
emscripten_set_main_loop(supermainloop, 0, 0);
}
void addAssetDownloadMap(char * path) {
}
static void mrbBindingTerminate() static void mrbBindingTerminate()
{ {
mrb_state *mrb = static_cast<mrb_state*>(shState->bindingData()); mrb_state *mrb = static_cast<mrb_state*>(shState->bindingData());

View File

@ -29,7 +29,7 @@
DEF_TYPE(Bitmap); DEF_TYPE(Bitmap);
MRB_METHOD(bitmapInitialize) __attribute__ ((optnone)) MRB_METHOD(bitmapInitialize)
{ {
Bitmap *b = 0; Bitmap *b = 0;
@ -65,7 +65,7 @@ MRB_METHOD(bitmapInitialize)
return self; return self;
} }
MRB_METHOD(bitmapWidth) __attribute__ ((optnone)) MRB_METHOD(bitmapWidth)
{ {
Bitmap *b = getPrivateData<Bitmap>(mrb, self); Bitmap *b = getPrivateData<Bitmap>(mrb, self);
@ -304,7 +304,7 @@ MRB_METHOD(bitmapSetFont)
INITCOPY_FUN(Bitmap) INITCOPY_FUN(Bitmap)
void void __attribute__ ((optnone))
bitmapBindingInit(mrb_state *mrb) bitmapBindingInit(mrb_state *mrb)
{ {
RClass *klass = defineClass(mrb, "Bitmap"); RClass *klass = defineClass(mrb, "Bitmap");

View File

@ -96,7 +96,7 @@ MRB_METHOD(disposableIsDisposed)
} }
template<class C> template<class C>
static void disposableBindingInit(mrb_state *mrb, RClass *klass) static __attribute__ ((optnone)) void disposableBindingInit(mrb_state *mrb, RClass *klass)
{ {
mrb_define_method(mrb, klass, "dispose", disposableDispose<C>, MRB_ARGS_NONE()); mrb_define_method(mrb, klass, "dispose", disposableDispose<C>, MRB_ARGS_NONE());
mrb_define_method(mrb, klass, "disposed?", disposableIsDisposed<C>, MRB_ARGS_NONE()); mrb_define_method(mrb, klass, "disposed?", disposableIsDisposed<C>, MRB_ARGS_NONE());

View File

@ -181,7 +181,7 @@ INITCOPY_FUN(Rect)
mrb_define_method(mrb, klass, "inspect", Klass##Stringify, MRB_ARGS_NONE()); \ mrb_define_method(mrb, klass, "inspect", Klass##Stringify, MRB_ARGS_NONE()); \
} }
void etcBindingInit(mrb_state *mrb) void __attribute__ ((optnone)) etcBindingInit(mrb_state *mrb)
{ {
RClass *klass; RClass *klass;

View File

@ -20,6 +20,7 @@
*/ */
#include "graphics.h" #include "graphics.h"
#include "bitmap.h"
#include "sharedstate.h" #include "sharedstate.h"
#include "binding-util.h" #include "binding-util.h"
#include "exception.h" #include "exception.h"
@ -104,6 +105,14 @@ DEF_GRA_PROP_B(ShowCursor)
mrb_define_module_function(mrb, module, prop_name_s "=", graphics##Set##PropName, MRB_ARGS_REQ(1)); \ mrb_define_module_function(mrb, module, prop_name_s "=", graphics##Set##PropName, MRB_ARGS_REQ(1)); \
} }
MRB_METHOD(graphicsGetXHR)
{
char *filename;
mrb_get_args(mrb, "z", &filename);
getXHR(filename);
return mrb_nil_value();
}
void graphicsBindingInit(mrb_state *mrb) void graphicsBindingInit(mrb_state *mrb)
{ {
RClass *module = mrb_define_module(mrb, "Graphics"); RClass *module = mrb_define_module(mrb, "Graphics");
@ -113,6 +122,8 @@ void graphicsBindingInit(mrb_state *mrb)
mrb_define_module_function(mrb, module, "transition", graphicsTransition, MRB_ARGS_OPT(3)); mrb_define_module_function(mrb, module, "transition", graphicsTransition, MRB_ARGS_OPT(3));
mrb_define_module_function(mrb, module, "frame_reset", graphicsFrameReset, MRB_ARGS_NONE()); mrb_define_module_function(mrb, module, "frame_reset", graphicsFrameReset, MRB_ARGS_NONE());
mrb_define_module_function(mrb, module, "get_xhr", graphicsGetXHR, MRB_ARGS_OPT(1));
INIT_GRA_PROP_BIND( FrameRate, "frame_rate" ); INIT_GRA_PROP_BIND( FrameRate, "frame_rate" );
INIT_GRA_PROP_BIND( FrameCount, "frame_count" ); INIT_GRA_PROP_BIND( FrameCount, "frame_count" );

View File

@ -1,9 +0,0 @@
#include <stdint.h>
const uint8_t
#if defined __GNUC__
__attribute__((aligned(4)))
#elif defined _MSC_VER
__declspec(align(4))
#endif
#include "module_rpg.xxd"

View File

@ -0,0 +1,2 @@
#include "mrpg.xxd"

View File

@ -1,7 +1,7 @@
mrbModuleRPG[] = { unsigned char rpg_mrb[] = {
0x52, 0x49, 0x54, 0x45, 0x30, 0x30, 0x30, 0x36, 0x95, 0x4b, 0x00, 0x00, 0x52, 0x49, 0x54, 0x45, 0x30, 0x30, 0x30, 0x36, 0x82, 0xd6, 0x00, 0x00,
0x85, 0xda, 0x4d, 0x41, 0x54, 0x5a, 0x30, 0x30, 0x30, 0x30, 0x49, 0x52, 0x86, 0x0e, 0x4d, 0x41, 0x54, 0x5a, 0x30, 0x30, 0x30, 0x30, 0x49, 0x52,
0x45, 0x50, 0x00, 0x00, 0x81, 0x6d, 0x30, 0x30, 0x30, 0x32, 0x00, 0x00, 0x45, 0x50, 0x00, 0x00, 0x81, 0x9d, 0x30, 0x30, 0x30, 0x32, 0x00, 0x00,
0x00, 0x4c, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x4c, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0b,
0x0f, 0x01, 0x5b, 0x01, 0x00, 0x5c, 0x01, 0x00, 0x37, 0x01, 0x67, 0x00, 0x0f, 0x01, 0x5b, 0x01, 0x00, 0x5c, 0x01, 0x00, 0x37, 0x01, 0x67, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x03, 0x52, 0x50, 0x47, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x03, 0x52, 0x50, 0x47,
@ -45,7 +45,7 @@ mrbModuleRPG[] = {
0x0b, 0x43, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x0b, 0x43, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x45, 0x76, 0x65, 0x6e, 0x74,
0x00, 0x00, 0x06, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x00, 0x00, 0x09, 0x00, 0x00, 0x06, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x00, 0x00, 0x09,
0x41, 0x75, 0x64, 0x69, 0x6f, 0x46, 0x69, 0x6c, 0x65, 0x00, 0x00, 0x00, 0x41, 0x75, 0x64, 0x69, 0x6f, 0x46, 0x69, 0x6c, 0x65, 0x00, 0x00, 0x00,
0x03, 0x72, 0x00, 0x01, 0x00, 0x02, 0x00, 0x10, 0x00, 0x00, 0x00, 0xab, 0x03, 0xa0, 0x00, 0x01, 0x00, 0x02, 0x00, 0x11, 0x00, 0x00, 0x00, 0xb5,
0x51, 0x01, 0x00, 0x18, 0x01, 0x00, 0x10, 0x01, 0x60, 0x01, 0x56, 0x02, 0x51, 0x01, 0x00, 0x18, 0x01, 0x00, 0x10, 0x01, 0x60, 0x01, 0x56, 0x02,
0x00, 0x5d, 0x01, 0x01, 0x10, 0x01, 0x60, 0x01, 0x56, 0x02, 0x01, 0x5d, 0x00, 0x5d, 0x01, 0x01, 0x10, 0x01, 0x60, 0x01, 0x56, 0x02, 0x01, 0x5d,
0x01, 0x02, 0x10, 0x01, 0x60, 0x01, 0x56, 0x02, 0x02, 0x5d, 0x01, 0x03, 0x01, 0x02, 0x10, 0x01, 0x60, 0x01, 0x56, 0x02, 0x02, 0x5d, 0x01, 0x03,
@ -59,24 +59,28 @@ mrbModuleRPG[] = {
0x56, 0x02, 0x0b, 0x5d, 0x01, 0x0c, 0x10, 0x01, 0x60, 0x01, 0x56, 0x02, 0x56, 0x02, 0x0b, 0x5d, 0x01, 0x0c, 0x10, 0x01, 0x60, 0x01, 0x56, 0x02,
0x0c, 0x5d, 0x01, 0x0d, 0x10, 0x01, 0x60, 0x01, 0x56, 0x02, 0x0d, 0x5d, 0x0c, 0x5d, 0x01, 0x0d, 0x10, 0x01, 0x60, 0x01, 0x56, 0x02, 0x0d, 0x5d,
0x01, 0x0e, 0x10, 0x01, 0x60, 0x01, 0x56, 0x02, 0x0e, 0x5d, 0x01, 0x0f, 0x01, 0x0e, 0x10, 0x01, 0x60, 0x01, 0x56, 0x02, 0x0e, 0x5d, 0x01, 0x0f,
0x10, 0x01, 0x60, 0x01, 0x56, 0x02, 0x0f, 0x5d, 0x01, 0x10, 0x0e, 0x01, 0x10, 0x01, 0x60, 0x01, 0x56, 0x02, 0x0f, 0x5d, 0x01, 0x10, 0x10, 0x01,
0x10, 0x37, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x00, 0x60, 0x01, 0x56, 0x02, 0x10, 0x5d, 0x01, 0x11, 0x0e, 0x01, 0x11, 0x37,
0x06, 0x40, 0x63, 0x61, 0x63, 0x68, 0x65, 0x00, 0x00, 0x0b, 0x6c, 0x6f, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x00, 0x06, 0x40,
0x61, 0x64, 0x5f, 0x62, 0x69, 0x74, 0x6d, 0x61, 0x70, 0x00, 0x00, 0x09, 0x63, 0x61, 0x63, 0x68, 0x65, 0x00, 0x00, 0x03, 0x78, 0x68, 0x72, 0x00,
0x61, 0x6e, 0x69, 0x6d, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x00, 0x00, 0x08, 0x00, 0x0b, 0x6c, 0x6f, 0x61, 0x64, 0x5f, 0x62, 0x69, 0x74, 0x6d, 0x61,
0x61, 0x75, 0x74, 0x6f, 0x74, 0x69, 0x6c, 0x65, 0x00, 0x00, 0x0a, 0x62, 0x70, 0x00, 0x00, 0x09, 0x61, 0x6e, 0x69, 0x6d, 0x61, 0x74, 0x69, 0x6f,
0x61, 0x74, 0x74, 0x6c, 0x65, 0x62, 0x61, 0x63, 0x6b, 0x00, 0x00, 0x07, 0x6e, 0x00, 0x00, 0x08, 0x61, 0x75, 0x74, 0x6f, 0x74, 0x69, 0x6c, 0x65,
0x62, 0x61, 0x74, 0x74, 0x6c, 0x65, 0x72, 0x00, 0x00, 0x09, 0x63, 0x68, 0x00, 0x00, 0x0a, 0x62, 0x61, 0x74, 0x74, 0x6c, 0x65, 0x62, 0x61, 0x63,
0x61, 0x72, 0x61, 0x63, 0x74, 0x65, 0x72, 0x00, 0x00, 0x03, 0x66, 0x6f, 0x6b, 0x00, 0x00, 0x07, 0x62, 0x61, 0x74, 0x74, 0x6c, 0x65, 0x72, 0x00,
0x67, 0x00, 0x00, 0x08, 0x67, 0x61, 0x6d, 0x65, 0x6f, 0x76, 0x65, 0x72, 0x00, 0x09, 0x63, 0x68, 0x61, 0x72, 0x61, 0x63, 0x74, 0x65, 0x72, 0x00,
0x00, 0x00, 0x04, 0x69, 0x63, 0x6f, 0x6e, 0x00, 0x00, 0x08, 0x70, 0x61, 0x00, 0x03, 0x66, 0x6f, 0x67, 0x00, 0x00, 0x08, 0x67, 0x61, 0x6d, 0x65,
0x6e, 0x6f, 0x72, 0x61, 0x6d, 0x61, 0x00, 0x00, 0x07, 0x70, 0x69, 0x63, 0x6f, 0x76, 0x65, 0x72, 0x00, 0x00, 0x04, 0x69, 0x63, 0x6f, 0x6e, 0x00,
0x74, 0x75, 0x72, 0x65, 0x00, 0x00, 0x07, 0x74, 0x69, 0x6c, 0x65, 0x73, 0x00, 0x08, 0x70, 0x61, 0x6e, 0x6f, 0x72, 0x61, 0x6d, 0x61, 0x00, 0x00,
0x65, 0x74, 0x00, 0x00, 0x05, 0x74, 0x69, 0x74, 0x6c, 0x65, 0x00, 0x00, 0x07, 0x70, 0x69, 0x63, 0x74, 0x75, 0x72, 0x65, 0x00, 0x00, 0x07, 0x74,
0x0a, 0x77, 0x69, 0x6e, 0x64, 0x6f, 0x77, 0x73, 0x6b, 0x69, 0x6e, 0x00, 0x69, 0x6c, 0x65, 0x73, 0x65, 0x74, 0x00, 0x00, 0x05, 0x74, 0x69, 0x74,
0x00, 0x04, 0x74, 0x69, 0x6c, 0x65, 0x00, 0x00, 0x05, 0x63, 0x6c, 0x65, 0x6c, 0x65, 0x00, 0x00, 0x0a, 0x77, 0x69, 0x6e, 0x64, 0x6f, 0x77, 0x73,
0x61, 0x72, 0x00, 0x00, 0x00, 0x04, 0x69, 0x00, 0x07, 0x00, 0x0c, 0x00, 0x6b, 0x69, 0x6e, 0x00, 0x00, 0x04, 0x74, 0x69, 0x6c, 0x65, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xfd, 0x00, 0x00, 0x00, 0x33, 0x08, 0x20, 0x00, 0x05, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x00, 0x00, 0x00, 0x00, 0x3a, 0x00,
0x02, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00,
0x33, 0x00, 0x00, 0x00, 0x0f, 0x02, 0x37, 0x02, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x69, 0x00, 0x07, 0x00, 0x0c,
0x00, 0x00, 0x00, 0x00, 0x00, 0xfd, 0x00, 0x00, 0x33, 0x08, 0x20, 0x00,
0x21, 0x00, 0x0a, 0x21, 0x00, 0x0c, 0x06, 0x03, 0x01, 0x07, 0x01, 0x01, 0x21, 0x00, 0x0a, 0x21, 0x00, 0x0c, 0x06, 0x03, 0x01, 0x07, 0x01, 0x01,
0x08, 0x02, 0x3b, 0x07, 0x01, 0x05, 0x07, 0x17, 0x07, 0x00, 0x01, 0x08, 0x08, 0x02, 0x3b, 0x07, 0x01, 0x05, 0x07, 0x17, 0x07, 0x00, 0x01, 0x08,
0x05, 0x2e, 0x07, 0x01, 0x01, 0x2e, 0x07, 0x02, 0x00, 0x22, 0x07, 0x00, 0x05, 0x2e, 0x07, 0x01, 0x01, 0x2e, 0x07, 0x02, 0x00, 0x22, 0x07, 0x00,
@ -2762,10 +2766,10 @@ mrbModuleRPG[] = {
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x05, 0x40, 0x6e, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x05, 0x40, 0x6e,
0x61, 0x6d, 0x65, 0x00, 0x00, 0x07, 0x40, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x61, 0x6d, 0x65, 0x00, 0x00, 0x07, 0x40, 0x76, 0x6f, 0x6c, 0x75, 0x6d,
0x65, 0x00, 0x00, 0x06, 0x40, 0x70, 0x69, 0x74, 0x63, 0x68, 0x00, 0x4c, 0x65, 0x00, 0x00, 0x06, 0x40, 0x70, 0x69, 0x74, 0x63, 0x68, 0x00, 0x4c,
0x56, 0x41, 0x52, 0x00, 0x00, 0x04, 0x4f, 0x00, 0x00, 0x00, 0x2d, 0x00, 0x56, 0x41, 0x52, 0x00, 0x00, 0x04, 0x53, 0x00, 0x00, 0x00, 0x2d, 0x00,
0x0b, 0x66, 0x6f, 0x6c, 0x64, 0x65, 0x72, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x01, 0x26, 0x00, 0x0b, 0x66, 0x6f, 0x6c, 0x64, 0x65, 0x72, 0x5f, 0x6e,
0x00, 0x08, 0x66, 0x69, 0x6c, 0x65, 0x6e, 0x61, 0x6d, 0x65, 0x00, 0x03, 0x61, 0x6d, 0x65, 0x00, 0x08, 0x66, 0x69, 0x6c, 0x65, 0x6e, 0x61, 0x6d,
0x68, 0x75, 0x65, 0x00, 0x01, 0x26, 0x00, 0x04, 0x70, 0x61, 0x74, 0x68, 0x65, 0x00, 0x03, 0x68, 0x75, 0x65, 0x00, 0x04, 0x70, 0x61, 0x74, 0x68,
0x00, 0x03, 0x6b, 0x65, 0x79, 0x00, 0x07, 0x74, 0x69, 0x6c, 0x65, 0x5f, 0x00, 0x03, 0x6b, 0x65, 0x79, 0x00, 0x07, 0x74, 0x69, 0x6c, 0x65, 0x5f,
0x69, 0x64, 0x00, 0x01, 0x78, 0x00, 0x01, 0x79, 0x00, 0x04, 0x72, 0x65, 0x69, 0x64, 0x00, 0x01, 0x78, 0x00, 0x01, 0x79, 0x00, 0x04, 0x72, 0x65,
0x63, 0x74, 0x00, 0x08, 0x76, 0x69, 0x65, 0x77, 0x70, 0x6f, 0x72, 0x74, 0x63, 0x74, 0x00, 0x08, 0x76, 0x69, 0x65, 0x77, 0x70, 0x6f, 0x72, 0x74,
@ -2792,68 +2796,68 @@ mrbModuleRPG[] = {
0x74, 0x00, 0x0a, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x65, 0x74, 0x65, 0x72, 0x74, 0x00, 0x0a, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x65, 0x74, 0x65, 0x72,
0x73, 0x00, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x00, 0x06, 0x76, 0x6f, 0x6c, 0x73, 0x00, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x00, 0x06, 0x76, 0x6f, 0x6c,
0x75, 0x6d, 0x65, 0x00, 0x05, 0x70, 0x69, 0x74, 0x63, 0x68, 0x00, 0x00, 0x75, 0x6d, 0x65, 0x00, 0x05, 0x70, 0x69, 0x74, 0x63, 0x68, 0x00, 0x00,
0x00, 0x01, 0x00, 0x01, 0x00, 0x02, 0x00, 0x02, 0x00, 0x03, 0x00, 0x03, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x02, 0x00, 0x02, 0x00, 0x03,
0x00, 0x04, 0x00, 0x04, 0x00, 0x05, 0x00, 0x05, 0x00, 0x06, 0x00, 0x01, 0x00, 0x03, 0x00, 0x00, 0x00, 0x04, 0x00, 0x04, 0x00, 0x05, 0x00, 0x05,
0x00, 0x01, 0x00, 0x02, 0x00, 0x02, 0x00, 0x03, 0x00, 0x03, 0x00, 0x01, 0x00, 0x06, 0x00, 0x02, 0x00, 0x01, 0x00, 0x03, 0x00, 0x02, 0x00, 0x00,
0x00, 0x01, 0x00, 0x03, 0x00, 0x02, 0x00, 0x01, 0x00, 0x01, 0x00, 0x03, 0x00, 0x03, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x02,
0x00, 0x02, 0x00, 0x01, 0x00, 0x01, 0x00, 0x02, 0x00, 0x02, 0x00, 0x03, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x02, 0x00, 0x01, 0x00, 0x03,
0x00, 0x03, 0x00, 0x01, 0x00, 0x01, 0x00, 0x02, 0x00, 0x02, 0x00, 0x03, 0x00, 0x02, 0x00, 0x00, 0x00, 0x03, 0x00, 0x02, 0x00, 0x01, 0x00, 0x03,
0x00, 0x03, 0x00, 0x01, 0x00, 0x01, 0x00, 0x02, 0x00, 0x02, 0x00, 0x03, 0x00, 0x02, 0x00, 0x00, 0x00, 0x03, 0x00, 0x02, 0x00, 0x01, 0x00, 0x03,
0x00, 0x03, 0x00, 0x01, 0x00, 0x01, 0x00, 0x03, 0x00, 0x02, 0x00, 0x01, 0x00, 0x02, 0x00, 0x00, 0x00, 0x03, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00,
0x00, 0x01, 0x00, 0x03, 0x00, 0x02, 0x00, 0x01, 0x00, 0x01, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x02,
0x00, 0x02, 0x00, 0x03, 0x00, 0x03, 0x00, 0x01, 0x00, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x03, 0x00, 0x02, 0x00, 0x00, 0x00, 0x03, 0x00, 0x02,
0x00, 0x02, 0x00, 0x01, 0x00, 0x01, 0x00, 0x03, 0x00, 0x02, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00,
0x00, 0x01, 0x00, 0x03, 0x00, 0x02, 0x00, 0x01, 0x00, 0x01, 0x00, 0x03, 0x00, 0x02, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x02,
0x00, 0x02, 0x00, 0x01, 0x00, 0x01, 0x00, 0x06, 0x00, 0x02, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x02, 0x00, 0x01, 0x00, 0x06,
0x00, 0x03, 0x00, 0x03, 0x00, 0x04, 0x00, 0x05, 0x00, 0x05, 0x00, 0x07, 0x00, 0x02, 0x00, 0x03, 0x00, 0x03, 0x00, 0x00, 0x00, 0x04, 0x00, 0x05,
0x00, 0x06, 0x00, 0x08, 0x00, 0x07, 0x00, 0x09, 0x00, 0x08, 0x00, 0x03, 0x00, 0x05, 0x00, 0x07, 0x00, 0x06, 0x00, 0x08, 0x00, 0x07, 0x00, 0x09,
0x00, 0x01, 0x00, 0x0a, 0x00, 0x01, 0x00, 0x03, 0x00, 0x02, 0x00, 0x03, 0x00, 0x08, 0x00, 0x00, 0x00, 0x01, 0x00, 0x0a, 0x00, 0x01, 0x00, 0x00,
0x00, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x03, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00,
0x00, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x0b, 0x00, 0x01, 0x00, 0x0c, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x0b,
0x00, 0x02, 0x00, 0x03, 0x00, 0x03, 0x00, 0x0d, 0x00, 0x04, 0x00, 0x0e, 0x00, 0x01, 0x00, 0x0c, 0x00, 0x02, 0x00, 0x00, 0x00, 0x03, 0x00, 0x0d,
0x00, 0x05, 0x00, 0x0f, 0x00, 0x01, 0x00, 0x10, 0x00, 0x02, 0x00, 0x03, 0x00, 0x04, 0x00, 0x0e, 0x00, 0x05, 0x00, 0x0f, 0x00, 0x01, 0x00, 0x10,
0x00, 0x03, 0x00, 0x11, 0x00, 0x04, 0x00, 0x12, 0x00, 0x05, 0x00, 0x0e, 0x00, 0x02, 0x00, 0x00, 0x00, 0x03, 0x00, 0x11, 0x00, 0x04, 0x00, 0x12,
0x00, 0x06, 0x00, 0x13, 0x00, 0x07, 0x00, 0x14, 0x00, 0x08, 0x00, 0x0f, 0x00, 0x05, 0x00, 0x0e, 0x00, 0x06, 0x00, 0x13, 0x00, 0x07, 0x00, 0x14,
0x00, 0x01, 0x00, 0x03, 0x00, 0x02, 0x00, 0x11, 0x00, 0x03, 0x00, 0x12, 0x00, 0x08, 0x00, 0x0f, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x11,
0x00, 0x04, 0x00, 0x0e, 0x00, 0x05, 0x00, 0x13, 0x00, 0x06, 0x00, 0x14, 0x00, 0x03, 0x00, 0x12, 0x00, 0x04, 0x00, 0x0e, 0x00, 0x05, 0x00, 0x13,
0x00, 0x07, 0x00, 0x03, 0x00, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x14, 0x00, 0x06, 0x00, 0x14, 0x00, 0x07, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00,
0x00, 0x02, 0x00, 0x03, 0x00, 0x01, 0x00, 0x14, 0x00, 0x02, 0x00, 0x03, 0x00, 0x01, 0x00, 0x14, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x14,
0x00, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x03, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00,
0x00, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x15, 0x00, 0x02, 0x00, 0x03, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x15,
0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x16, 0x00, 0x02, 0x00, 0x17,
0x00, 0x03, 0x00, 0x18, 0x00, 0x04, 0x00, 0x19, 0x00, 0x05, 0x00, 0x00,
0x00, 0x01, 0x00, 0x16, 0x00, 0x02, 0x00, 0x17, 0x00, 0x03, 0x00, 0x18, 0x00, 0x01, 0x00, 0x16, 0x00, 0x02, 0x00, 0x17, 0x00, 0x03, 0x00, 0x18,
0x00, 0x04, 0x00, 0x19, 0x00, 0x05, 0x00, 0x03, 0x00, 0x01, 0x00, 0x16, 0x00, 0x04, 0x00, 0x19, 0x00, 0x05, 0x00, 0x1a, 0x00, 0x01, 0x00, 0x17,
0x00, 0x02, 0x00, 0x17, 0x00, 0x03, 0x00, 0x18, 0x00, 0x04, 0x00, 0x19, 0x00, 0x02, 0x00, 0x18, 0x00, 0x03, 0x00, 0x00, 0x00, 0x04, 0x00, 0x13,
0x00, 0x05, 0x00, 0x1a, 0x00, 0x01, 0x00, 0x17, 0x00, 0x02, 0x00, 0x18, 0x00, 0x05, 0x00, 0x14, 0x00, 0x06, 0x00, 0x1b, 0x00, 0x07, 0x00, 0x19,
0x00, 0x03, 0x00, 0x03, 0x00, 0x04, 0x00, 0x13, 0x00, 0x05, 0x00, 0x14, 0x00, 0x01, 0x00, 0x10, 0x00, 0x02, 0x00, 0x00, 0x00, 0x03, 0x00, 0x1c,
0x00, 0x06, 0x00, 0x1b, 0x00, 0x07, 0x00, 0x19, 0x00, 0x01, 0x00, 0x10, 0x00, 0x04, 0x00, 0x07, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x1d,
0x00, 0x02, 0x00, 0x03, 0x00, 0x03, 0x00, 0x1c, 0x00, 0x04, 0x00, 0x07, 0x00, 0x03, 0x00, 0x13, 0x00, 0x04, 0x00, 0x08, 0x00, 0x01, 0x00, 0x00,
0x00, 0x01, 0x00, 0x03, 0x00, 0x02, 0x00, 0x1d, 0x00, 0x03, 0x00, 0x13, 0x00, 0x02, 0x00, 0x1e, 0x00, 0x03, 0x00, 0x13, 0x00, 0x04, 0x00, 0x0a,
0x00, 0x04, 0x00, 0x08, 0x00, 0x01, 0x00, 0x03, 0x00, 0x02, 0x00, 0x1e, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x1f, 0x00, 0x03, 0x00, 0x20,
0x00, 0x03, 0x00, 0x13, 0x00, 0x04, 0x00, 0x0a, 0x00, 0x01, 0x00, 0x03, 0x00, 0x04, 0x00, 0x13, 0x00, 0x05, 0x00, 0x14, 0x00, 0x06, 0x00, 0x00,
0x00, 0x02, 0x00, 0x1f, 0x00, 0x03, 0x00, 0x20, 0x00, 0x04, 0x00, 0x13, 0x00, 0x01, 0x00, 0x14, 0x00, 0x02, 0x00, 0x21, 0x00, 0x01, 0x00, 0x00,
0x00, 0x05, 0x00, 0x14, 0x00, 0x06, 0x00, 0x03, 0x00, 0x01, 0x00, 0x14, 0x00, 0x02, 0x00, 0x0e, 0x00, 0x03, 0x00, 0x13, 0x00, 0x04, 0x00, 0x14,
0x00, 0x02, 0x00, 0x21, 0x00, 0x01, 0x00, 0x03, 0x00, 0x02, 0x00, 0x0e, 0x00, 0x05, 0x00, 0x22, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x14,
0x00, 0x03, 0x00, 0x13, 0x00, 0x04, 0x00, 0x14, 0x00, 0x05, 0x00, 0x22, 0x00, 0x03, 0x00, 0x23, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x14,
0x00, 0x01, 0x00, 0x03, 0x00, 0x02, 0x00, 0x14, 0x00, 0x03, 0x00, 0x23, 0x00, 0x03, 0x00, 0x24, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x13,
0x00, 0x01, 0x00, 0x03, 0x00, 0x02, 0x00, 0x14, 0x00, 0x03, 0x00, 0x24, 0x00, 0x03, 0x00, 0x14, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x13,
0x00, 0x01, 0x00, 0x03, 0x00, 0x02, 0x00, 0x13, 0x00, 0x03, 0x00, 0x14, 0x00, 0x02, 0x00, 0x14, 0x00, 0x03, 0x00, 0x07, 0x00, 0x04, 0x00, 0x08,
0x00, 0x04, 0x00, 0x03, 0x00, 0x01, 0x00, 0x13, 0x00, 0x02, 0x00, 0x14, 0x00, 0x05, 0x00, 0x25, 0x00, 0x01, 0x00, 0x26, 0x00, 0x02, 0x00, 0x00,
0x00, 0x03, 0x00, 0x07, 0x00, 0x04, 0x00, 0x08, 0x00, 0x05, 0x00, 0x25, 0x00, 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00,
0x00, 0x01, 0x00, 0x26, 0x00, 0x02, 0x00, 0x03, 0x00, 0x03, 0x00, 0x03, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x07, 0x00, 0x01, 0x00, 0x08,
0x00, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x03, 0x00, 0x02, 0x00, 0x00, 0x00, 0x03, 0x00, 0x27, 0x00, 0x01, 0x00, 0x28,
0x00, 0x01, 0x00, 0x07, 0x00, 0x01, 0x00, 0x08, 0x00, 0x02, 0x00, 0x03, 0x00, 0x02, 0x00, 0x29, 0x00, 0x03, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00,
0x00, 0x03, 0x00, 0x27, 0x00, 0x01, 0x00, 0x28, 0x00, 0x02, 0x00, 0x29, 0x00, 0x01, 0x00, 0x27, 0x00, 0x01, 0x00, 0x29, 0x00, 0x02, 0x00, 0x00,
0x00, 0x03, 0x00, 0x03, 0x00, 0x04, 0x00, 0x03, 0x00, 0x01, 0x00, 0x27, 0x00, 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x13, 0x00, 0x02, 0x00, 0x00,
0x00, 0x01, 0x00, 0x29, 0x00, 0x02, 0x00, 0x03, 0x00, 0x03, 0x00, 0x03, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00,
0x00, 0x01, 0x00, 0x13, 0x00, 0x02, 0x00, 0x03, 0x00, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00,
0x00, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00,
0x00, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00,
0x00, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00,
0x00, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00,
0x00, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x2a,
0x00, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x2b, 0x00, 0x02, 0x00, 0x2c, 0x00, 0x03, 0x00, 0x00,
0x00, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x2a, 0x00, 0x01, 0x00, 0x2b, 0x00, 0x04, 0x45, 0x4e, 0x44, 0x00, 0x00, 0x00, 0x00, 0x08
0x00, 0x02, 0x00, 0x2c, 0x00, 0x03, 0x00, 0x03, 0x00, 0x04, 0x45, 0x4e,
0x44, 0x00, 0x00, 0x00, 0x00, 0x08
}; };
unsigned int rpg_mrb_len = 34266; unsigned int rpg_mrb_len = 34318;

Binary file not shown.

View File

@ -1,7 +0,0 @@
00000000: 5249 5445 3030 3034 5969 0000 0065 4d41 RITE0004Yi...eMA
00000010: 545a 3030 3030 4952 4550 0000 0047 3030 TZ0000IREP...G00
00000020: 3030 0000 003f 0001 0004 0000 0000 0004 00...?..........
00000030: 0080 0006 0100 003d 0080 00a0 0000 004a .......=.......J
00000040: 0000 0001 0000 0b48 656c 6c6f 2057 6f72 .......Hello Wor
00000050: 6c64 0000 0001 0004 7075 7473 0045 4e44 ld......puts.END
00000060: 0000 0000 08 .....

View File

@ -44,6 +44,13 @@
#include "font.h" #include "font.h"
#include "eventthread.h" #include "eventthread.h"
#ifdef __EMSCRIPTEN__
#include <emscripten.h>
#include <emscripten/fetch.h>
#include <string>
#include <fstream>
#endif
#define GUARD_MEGA \ #define GUARD_MEGA \
{ \ { \
if (p->megaSurface) \ if (p->megaSurface) \
@ -53,6 +60,45 @@
#define OUTLINE_SIZE 1 #define OUTLINE_SIZE 1
void reloadBitmap(void * arg) {
emscripten_fetch_t * fetch = (emscripten_fetch_t *) arg;
try {
SDL_Surface * imgSurf = IMG_LoadTyped_RW(SDL_RWFromConstMem(fetch->data, fetch->numBytes), 1, "");
Bitmap * bitmap = ((Bitmap*)fetch->userData);
bitmap->fromSurf(imgSurf, fetch->url);
if (bitmap->reloadCallback)
bitmap->reloadCallback(bitmap->reloadCallbackData);
} catch (const Exception &e) {}
emscripten_fetch_close(fetch);
}
void assetDownloadSucceeded(emscripten_fetch_t *fetch) {
emscripten_push_main_loop_blocker(reloadBitmap, (void *) fetch);
}
void assetDownloadFailed(emscripten_fetch_t *fetch) {
printf("Downloading %s failed, HTTP failure status code: %d.\n", fetch->url, fetch->status);
emscripten_fetch_close(fetch);
}
void addBitmapDownload(const char * filename, Bitmap * bitmap) {
const char *pfx = "async/";
char result[512];
strcpy(result, pfx);
strcat(result, filename);
emscripten_fetch_attr_t attr;
emscripten_fetch_attr_init(&attr);
strcpy(attr.requestMethod, "GET");
attr.attributes = EMSCRIPTEN_FETCH_LOAD_TO_MEMORY;
attr.onsuccess = assetDownloadSucceeded;
attr.onerror = assetDownloadFailed;
attr.userData = bitmap;
emscripten_fetch(&attr, result);
}
/* Normalize (= ensure width and /* Normalize (= ensure width and
* height are positive) */ * height are positive) */
static IntRect normalizedRect(const IntRect &rect) static IntRect normalizedRect(const IntRect &rect)
@ -86,7 +132,7 @@ struct BitmapPrivate
* whose Bitmaps don't fit into a regular texture. They're * whose Bitmaps don't fit into a regular texture. They're
* kept in RAM and will throw an error if they're used in * kept in RAM and will throw an error if they're used in
* any context other than as Tilesets */ * any context other than as Tilesets */
SDL_Surface *megaSurface; SDL_Surface *megaSurface = NULL;
/* A cached version of the bitmap in client memory, for /* A cached version of the bitmap in client memory, for
* getPixel calls. Is invalidated any time the bitmap * getPixel calls. Is invalidated any time the bitmap
@ -248,12 +294,7 @@ struct BitmapOpenHandler : FileSystem::OpenHandler
} }
}; };
Bitmap::Bitmap(const char *filename) void Bitmap::fromSurf(SDL_Surface *imgSurf, const char * filename) {
{
BitmapOpenHandler handler;
shState->fileSystem().openRead(handler, filename);
SDL_Surface *imgSurf = handler.surf;
if (!imgSurf) if (!imgSurf)
throw Exception(Exception::SDLError, "Error loading image '%s': %s", throw Exception(Exception::SDLError, "Error loading image '%s': %s",
filename, SDL_GetError()); filename, SDL_GetError());
@ -263,12 +304,15 @@ Bitmap::Bitmap(const char *filename)
if (imgSurf->w > glState.caps.maxTexSize || imgSurf->h > glState.caps.maxTexSize) if (imgSurf->w > glState.caps.maxTexSize || imgSurf->h > glState.caps.maxTexSize)
{ {
/* Mega surface */ /* Mega surface */
if (p) delete p;
p = new BitmapPrivate(this); p = new BitmapPrivate(this);
p->megaSurface = imgSurf; p->megaSurface = imgSurf;
SDL_SetSurfaceBlendMode(p->megaSurface, SDL_BLENDMODE_NONE); SDL_SetSurfaceBlendMode(p->megaSurface, SDL_BLENDMODE_NONE);
printf("MEGA SURFACE %s\n", filename);
} }
else else
{ {
if (!p) {
/* Regular surface */ /* Regular surface */
TEXFBO tex; TEXFBO tex;
@ -284,6 +328,7 @@ Bitmap::Bitmap(const char *filename)
p = new BitmapPrivate(this); p = new BitmapPrivate(this);
p->gl = tex; p->gl = tex;
}
TEX::bind(p->gl.tex); TEX::bind(p->gl.tex);
TEX::uploadImage(p->gl.width, p->gl.height, imgSurf->pixels, GL_RGBA); TEX::uploadImage(p->gl.width, p->gl.height, imgSurf->pixels, GL_RGBA);
@ -294,6 +339,17 @@ Bitmap::Bitmap(const char *filename)
p->addTaintedArea(rect()); p->addTaintedArea(rect());
} }
Bitmap::Bitmap(const char *filename)
{
BitmapOpenHandler handler;
shState->fileSystem().openRead(handler, filename);
SDL_Surface *imgSurf = handler.surf;
fromSurf(imgSurf, filename);
addBitmapDownload(filename, this);
}
Bitmap::Bitmap(int width, int height) Bitmap::Bitmap(int width, int height)
{ {
if (width <= 0 || height <= 0) if (width <= 0 || height <= 0)
@ -1322,3 +1378,8 @@ void Bitmap::releaseResources()
delete p; delete p;
} }
void getXHR(char * filename) {
}

View File

@ -48,6 +48,10 @@ public:
int height() const; int height() const;
IntRect rect() const; IntRect rect() const;
void (*reloadCallback)(void *) = NULL;
void * reloadCallbackData = NULL;
void fromSurf(SDL_Surface *, const char *);
void blt(int x, int y, void blt(int x, int y,
const Bitmap &source, IntRect rect, const Bitmap &source, IntRect rect,
int opacity = 255); int opacity = 255);
@ -123,7 +127,9 @@ private:
void releaseResources(); void releaseResources();
const char *klassName() const { return "bitmap"; } const char *klassName() const { return "bitmap"; }
BitmapPrivate *p; BitmapPrivate *p = NULL;
}; };
void getXHR(char * filename);
#endif // BITMAP_H #endif // BITMAP_H

View File

@ -51,6 +51,9 @@
#include <emscripten.h> #include <emscripten.h>
#endif #endif
static RGSSThreadData * staticUserData;
static EventThread * eventThread;
static void static void
rgssThreadError(RGSSThreadData *rtData, const std::string &msg) rgssThreadError(RGSSThreadData *rtData, const std::string &msg)
{ {
@ -326,32 +329,35 @@ int main(int argc, char *argv[])
SDL_GetDisplayMode(0, 0, &mode); SDL_GetDisplayMode(0, 0, &mode);
/* Can't sync to display refresh rate if its value is unknown */ /* Can't sync to display refresh rate if its value is unknown */
#ifndef __EMSCRIPTEN__
if (!mode.refresh_rate) if (!mode.refresh_rate)
#endif
conf.syncToRefreshrate = false; conf.syncToRefreshrate = false;
EventThread eventThread; eventThread = new EventThread();
RGSSThreadData rtData(&eventThread, argv[0], win, staticUserData = new RGSSThreadData(eventThread, argv[0], win,
alcDev, mode.refresh_rate, conf); alcDev, mode.refresh_rate, conf);
int winW, winH; int winW, winH;
SDL_GetWindowSize(win, &winW, &winH); SDL_GetWindowSize(win, &winW, &winH);
rtData.windowSizeMsg.post(Vec2i(winW, winH)); staticUserData->windowSizeMsg.post(Vec2i(winW, winH));
/* Load and post key bindings */ /* Load and post key bindings */
rtData.bindingUpdateMsg.post(loadBindings(conf)); staticUserData->bindingUpdateMsg.post(loadBindings(conf));
/* Start RGSS thread */ /* Start RGSS thread */
//SDL_Thread *rgssThread = //SDL_Thread *rgssThread =
// SDL_CreateThread(rgssThreadFun, "rgss", &rtData); // SDL_CreateThread(rgssThreadFun, "rgss", &rtData);
::rgssThreadFun(&rtData); ::rgssThreadFun(staticUserData);
/* Start event processing */ /* Start event processing */
eventThread.process(rtData); // eventThread.process(rtData);
#ifdef __EMSCRIPTEN__ #ifdef __EMSCRIPTEN__
printf("Exiting main function\n");
return 0; return 0;
#endif #endif
#ifndef __EMSCRIPTEN__
/* Request RGSS thread to stop */ /* Request RGSS thread to stop */
rtData.rqTerm.set(); rtData.rqTerm.set();
@ -398,4 +404,5 @@ int main(int argc, char *argv[])
SDL_Quit(); SDL_Quit();
return 0; return 0;
#endif
} }

View File

@ -331,6 +331,10 @@ DEF_ATTR_SIMPLE(Sprite, SrcRect, Rect&, *p->srcRect)
DEF_ATTR_SIMPLE(Sprite, Color, Color&, *p->color) DEF_ATTR_SIMPLE(Sprite, Color, Color&, *p->color)
DEF_ATTR_SIMPLE(Sprite, Tone, Tone&, *p->tone) DEF_ATTR_SIMPLE(Sprite, Tone, Tone&, *p->tone)
void updateSprite(void * sprite) {
((Sprite *) sprite)->update();
}
void Sprite::setBitmap(Bitmap *bitmap) void Sprite::setBitmap(Bitmap *bitmap)
{ {
guardDisposed(); guardDisposed();
@ -350,6 +354,9 @@ void Sprite::setBitmap(Bitmap *bitmap)
p->quad.setPosRect(p->srcRect->toFloatRect()); p->quad.setPosRect(p->srcRect->toFloatRect());
p->wave.dirty = true; p->wave.dirty = true;
//bitmap->reloadCallback = updateSprite;
//bitmap->reloadCallbackData = (void *) this;
} }
void Sprite::setX(int value) void Sprite::setX(int value)

View File

@ -1147,6 +1147,14 @@ DEF_ATTR_RD_SIMPLE(Tilemap, Visible, bool, p->visible)
DEF_ATTR_RD_SIMPLE(Tilemap, OX, int, p->origin.x) DEF_ATTR_RD_SIMPLE(Tilemap, OX, int, p->origin.x)
DEF_ATTR_RD_SIMPLE(Tilemap, OY, int, p->origin.y) DEF_ATTR_RD_SIMPLE(Tilemap, OY, int, p->origin.y)
void invalidateBitmap(void * tilemap) {
((Tilemap *) tilemap)->reloadBitmap();
}
void Tilemap::reloadBitmap() {
p->invalidateAtlasContents();
}
void Tilemap::setTileset(Bitmap *value) void Tilemap::setTileset(Bitmap *value)
{ {
guardDisposed(); guardDisposed();
@ -1159,6 +1167,9 @@ void Tilemap::setTileset(Bitmap *value)
if (!value) if (!value)
return; return;
value->reloadCallback = invalidateBitmap;
value->reloadCallbackData = (void *) this;
p->invalidateAtlasSize(); p->invalidateAtlasSize();
p->tilesetCon.disconnect(); p->tilesetCon.disconnect();
p->tilesetCon = value->modified.connect p->tilesetCon = value->modified.connect

View File

@ -66,6 +66,8 @@ public:
DECL_ATTR( OX, int ) DECL_ATTR( OX, int )
DECL_ATTR( OY, int ) DECL_ATTR( OY, int )
void reloadBitmap();
private: private:
TilemapPrivate *p; TilemapPrivate *p;
Autotiles atProxy; Autotiles atProxy;