From a997bcd67f8712bfe88b731f9cdc969e881a6611 Mon Sep 17 00:00:00 2001 From: Varun Patil Date: Mon, 30 Apr 2018 22:49:27 +0530 Subject: [PATCH] Fix emscripten support, for mruby Gets to title screen, input works Fix up repo, fix Graphics.cpp, add emscripten_sleep to audio files --- binding-mruby/binding-mruby.cpp | 11 +++++++++-- binding-mruby/input-binding.cpp | 2 ++ src/alstream.cpp | 9 +++++++++ src/audio.cpp | 8 ++++++++ src/audiostream.cpp | 12 ++++++++++++ src/boost-hash.h | 11 ++++++----- src/config.h | 2 +- src/graphics.cpp | 2 +- src/main.cpp | 9 +++++++++ 9 files changed, 57 insertions(+), 9 deletions(-) diff --git a/binding-mruby/binding-mruby.cpp b/binding-mruby/binding-mruby.cpp index 867d2d6..d09c876 100644 --- a/binding-mruby/binding-mruby.cpp +++ b/binding-mruby/binding-mruby.cpp @@ -49,6 +49,10 @@ #include "binding-types.h" #include "mrb-ext/marshal.h" +#ifdef __EMSCRIPTEN__ +#include +#endif + static void mrbBindingExecute(); static void mrbBindingTerminate(); static void mrbBindingReset(); @@ -164,7 +168,7 @@ showExcMessageBox(mrb_state *mrb, mrb_value exc) snprintf(msgBoxText, sizeof(msgBoxText), "Script '%s' line %d: %s occured.\n\n%s", mrbValueString(file), mrb_fixnum(line), excClass, mrbValueString(mesg)); - shState->eThread().showMessageBox(msgBoxText, SDL_MESSAGEBOX_ERROR); + printf("Alert - %s\n", msgBoxText); } static void @@ -289,13 +293,16 @@ runRMXPScripts(mrb_state *mrb, mrbc_context *ctx) return; } - int scriptCount = mrb_ary_len(scriptMrb, scriptArray); + int scriptCount = mrb_arY_len(scriptMrb, scriptArray); std::string decodeBuffer; decodeBuffer.resize(0x1000); for (int i = 0; i < scriptCount; ++i) { +#ifdef __EMSCRIPTEN + emscripten_sleep(10); +#endif mrb_value script = mrb_ary_entry(scriptArray, i); mrb_value scriptChksum = mrb_ary_entry(script, 0); diff --git a/binding-mruby/input-binding.cpp b/binding-mruby/input-binding.cpp index 921ca7f..112de59 100644 --- a/binding-mruby/input-binding.cpp +++ b/binding-mruby/input-binding.cpp @@ -24,6 +24,7 @@ #include "exception.h" #include "binding-util.h" #include "util.h" +#include "eventthread.h" #include #include @@ -33,6 +34,7 @@ MRB_FUNCTION(inputUpdate) MRB_FUN_UNUSED_PARAM; shState->input().update(); + shState->eThread().process(shState->rtData()); return mrb_nil_value(); } diff --git a/src/alstream.cpp b/src/alstream.cpp index 487f09f..61587c6 100644 --- a/src/alstream.cpp +++ b/src/alstream.cpp @@ -35,6 +35,10 @@ #include #include +#ifdef __EMSCRIPTEN__ +#include +#endif + ALStream::ALStream(LoopMode loopMode, const std::string &threadId) : looped(loopMode == Looped), @@ -474,6 +478,11 @@ void ALStream::streamData() if (threadTermReq) break; +#ifdef __EMSCRIPTEN__ + emscripten_sleep(AUDIO_SLEEP); +#else SDL_Delay(AUDIO_SLEEP); +#endif + } } diff --git a/src/audio.cpp b/src/audio.cpp index d536c70..8f00165 100644 --- a/src/audio.cpp +++ b/src/audio.cpp @@ -33,6 +33,10 @@ #include #include +#ifdef __EMSCRIPTEN__ +#include +#endif + struct AudioPrivate { AudioStream bgm; @@ -232,7 +236,11 @@ struct AudioPrivate } } +#ifdef __EMSCRIPTEN__ + emscripten_sleep(AUDIO_SLEEP); +#else SDL_Delay(AUDIO_SLEEP); +#endif } } }; diff --git a/src/audiostream.cpp b/src/audiostream.cpp index 1d96553..af58938 100644 --- a/src/audiostream.cpp +++ b/src/audiostream.cpp @@ -28,6 +28,10 @@ #include #include +#ifdef __EMSCRIPTEN__ +#include +#endif + AudioStream::AudioStream(ALStream::LoopMode loopMode, const std::string &threadId) : extPaused(false), @@ -323,7 +327,11 @@ void AudioStream::fadeOutThread() unlockStream(); +#ifdef __EMSCRIPTEN__ + emscripten_sleep(AUDIO_SLEEP); +#else SDL_Delay(AUDIO_SLEEP); +#endif } fade.active.clear(); @@ -360,6 +368,10 @@ void AudioStream::fadeInThread() unlockStream(); +#ifdef __EMSCRIPTEN__ + emscripten_sleep(AUDIO_SLEEP); +#else SDL_Delay(AUDIO_SLEEP); +#endif } } diff --git a/src/boost-hash.h b/src/boost-hash.h index 9d65958..3ce746a 100644 --- a/src/boost-hash.h +++ b/src/boost-hash.h @@ -21,9 +21,10 @@ #ifndef BOOSTHASH_H #define BOOSTHASH_H -#include -#include -#include + +#include +#include + #include /* Wrappers around the boost unordered template classes, @@ -33,7 +34,7 @@ template class BoostHash { private: - typedef std::map BoostType; + typedef boost::unordered_map BoostType; typedef std::pair PairType; BoostType p; @@ -97,7 +98,7 @@ template class BoostSet { private: - typedef std::set BoostType; + typedef boost::unordered_set BoostType; BoostType p; public: diff --git a/src/config.h b/src/config.h index 272337a..2889b6a 100644 --- a/src/config.h +++ b/src/config.h @@ -43,7 +43,7 @@ struct Config int defScreenH = 0; int fixedFramerate = 0; - bool frameSkip =true; + bool frameSkip =false; bool syncToRefreshrate = false; bool solidFonts = false; diff --git a/src/graphics.cpp b/src/graphics.cpp index c8e66d1..df194cf 100644 --- a/src/graphics.cpp +++ b/src/graphics.cpp @@ -446,7 +446,7 @@ private: SDL_Delay(ticks / tickFreqMS); #endif #endif -#ifdef __EMSCRIPTEN +#ifdef __EMSCRIPTEN__ emscripten_sleep(ticks /tickFreqMS); #endif } diff --git a/src/main.cpp b/src/main.cpp index 2db1ed9..fc61f26 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -46,6 +46,11 @@ #include "icon.png.xxd" + +#ifdef __EMSCRIPTEN__ +#include +#endif + static void rgssThreadError(RGSSThreadData *rtData, const std::string &msg) { @@ -335,6 +340,10 @@ int main(int argc, char *argv[]) /* Wait for RGSS thread response */ for (int i = 0; i < 1000; ++i) { +#ifdef __EMSCRIPTEN + emscripten_sleep(10); +#endif + /* We can stop waiting when the request was ack'd */ if (rtData.rqTermAck) {