diff --git a/binding-mri/binding-mri.cpp b/binding-mri/binding-mri.cpp index c8b3b02..21537f7 100644 --- a/binding-mri/binding-mri.cpp +++ b/binding-mri/binding-mri.cpp @@ -31,6 +31,12 @@ #include "audio.h" #include "boost-hash.h" +#ifdef __EMSCRIPTEN__ +#include +#endif + +#include + #include #ifndef RUBY_LEGACY_VERSION #include @@ -277,8 +283,8 @@ RB_METHOD(mriRgssMain) { VALUE exc = Qnil; - rb_rescue2((VALUE(*)(VALUE *)) rgssMainCb, rb_block_proc(), - (VALUE(*)(VALUE, VALUE)) rgssMainRescue, (VALUE) &exc, + rb_rescue2((VALUE(*)(ANYARGS)) rgssMainCb, rb_block_proc(), + (VALUE(*)(ANYARGS)) rgssMainRescue, (VALUE) &exc, rb_eException, (VALUE) 0); if (NIL_P(exc)) @@ -352,9 +358,6 @@ static VALUE evalHelper(evalArg *arg) return rb_funcall2(Qnil, rb_intern("eval"), ARRAY_SIZE(argv), argv); } -#ifdef __EMSCRIPTEN__ -#include -#endif static VALUE evalString(VALUE string, VALUE filename, int *state) { evalArg arg = { string, filename }; @@ -385,6 +388,12 @@ struct BacktraceData #define SCRIPT_SECTION_FMT (rgssVer >= 3 ? "{%04ld}" : "Section%03ld") +void main_update_loop() { + int state; + VALUE result; + result = rb_eval_string_protect("main_update_loop", &state); +} + static void __attribute__ ((optnone)) runRMXPScripts(BacktraceData &btData) { const Config &conf = shState->rtData().config; @@ -485,7 +494,8 @@ static void __attribute__ ((optnone)) runRMXPScripts(BacktraceData &btData) if (exc != Qnil) return; - while (true) + + /* Execute scripts */ { for (long i = 0; i < scriptCount; ++i) { @@ -513,6 +523,17 @@ static void __attribute__ ((optnone)) runRMXPScripts(BacktraceData &btData) break; } +#ifdef __EMSCRIPTEN__ + /* Use loop for emscripten */ + emscripten_set_main_loop(main_update_loop,0, 0); +#else + while(true) { + int state; + VALUE result; + result = rb_eval_string_protect("main_update_loop", &state); + if (state) break; + } + printf("tick\n"); shState->eThread().process(shState->rtData()); @@ -521,6 +542,7 @@ static void __attribute__ ((optnone)) runRMXPScripts(BacktraceData &btData) break; processReset(); +#endif } } @@ -628,6 +650,7 @@ static void mriBindingExecute() else runRMXPScripts(btData); +#ifndef __EMSCRIPTEN__ VALUE exc = rb_errinfo(); if (!NIL_P(exc) && !rb_obj_is_kind_of(exc, rb_eSystemExit)) showExc(exc, btData); @@ -635,6 +658,7 @@ static void mriBindingExecute() ruby_cleanup(0); shState->rtData().rqTermAck.set(); +#endif } static void mriBindingTerminate() diff --git a/src/eventthread.cpp b/src/eventthread.cpp index 89704d0..b021732 100644 --- a/src/eventthread.cpp +++ b/src/eventthread.cpp @@ -294,7 +294,6 @@ void EventThread::process(RGSSThreadData &rtData) rtData.rqReset.set(); break; } - keyStates[event.key.keysym.scancode] = true; break; diff --git a/src/graphics.cpp b/src/graphics.cpp index e640042..bad6eb8 100644 --- a/src/graphics.cpp +++ b/src/graphics.cpp @@ -420,6 +420,10 @@ struct FPSLimiter private: void delayTicks(uint64_t ticks) { + + /* RETURN WITHOUT DOING ANYTHING */ + return; + #ifndef __EMSCRIPTEN__ #if defined(HAVE_NANOSLEEP) struct timespec req; diff --git a/src/input.cpp b/src/input.cpp index 22dab5d..73014c0 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -358,6 +358,17 @@ struct InputPrivate void checkBindingChange(const RGSSThreadData &rtData) { + +#ifdef __EMSCRIPTEN__ + /* Run only once for emscripten. This is necessary due to * + * a bug (in mutable?) that keeps reinitializing bindings */ + static bool once = false; + if (!once) + once = true; + else + return; +#endif + BDescVec d; if (!rtData.bindingUpdateMsg.poll(d)) diff --git a/src/main.cpp b/src/main.cpp index fcf03f2..ee06135 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -150,13 +150,16 @@ int rgssThreadFun(void *userdata) /* Start script execution */ scriptBinding->execute(); +#ifndef __EMSCRIPTEN__ threadData->rqTermAck.set(); + threadData->ethread->requestTerminate(); SharedState::finiInstance(); alcDestroyContext(alcCtx); SDL_GL_DeleteContext(glCtx); +#endif return 0; } @@ -345,6 +348,10 @@ int main(int argc, char *argv[]) /* Start event processing */ eventThread.process(rtData); +#ifdef __EMSCRIPTEN__ + return 0; +#endif + /* Request RGSS thread to stop */ rtData.rqTerm.set();