Fix emscripten support, for mruby

Gets to title screen, input works

Fix up repo, fix Graphics.cpp, add emscripten_sleep to audio files
This commit is contained in:
Varun Patil 2018-04-30 22:49:27 +05:30
parent 5b3c1d2b13
commit a997bcd67f
9 changed files with 57 additions and 9 deletions

View File

@ -49,6 +49,10 @@
#include "binding-types.h"
#include "mrb-ext/marshal.h"
#ifdef __EMSCRIPTEN__
#include <emscripten.h>
#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);

View File

@ -24,6 +24,7 @@
#include "exception.h"
#include "binding-util.h"
#include "util.h"
#include "eventthread.h"
#include <mruby/hash.h>
#include <string.h>
@ -33,6 +34,7 @@ MRB_FUNCTION(inputUpdate)
MRB_FUN_UNUSED_PARAM;
shState->input().update();
shState->eThread().process(shState->rtData());
return mrb_nil_value();
}

View File

@ -35,6 +35,10 @@
#include <SDL_thread.h>
#include <SDL_timer.h>
#ifdef __EMSCRIPTEN__
#include <emscripten.h>
#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
}
}

View File

@ -33,6 +33,10 @@
#include <SDL_thread.h>
#include <SDL_timer.h>
#ifdef __EMSCRIPTEN__
#include <emscripten.h>
#endif
struct AudioPrivate
{
AudioStream bgm;
@ -232,7 +236,11 @@ struct AudioPrivate
}
}
#ifdef __EMSCRIPTEN__
emscripten_sleep(AUDIO_SLEEP);
#else
SDL_Delay(AUDIO_SLEEP);
#endif
}
}
};

View File

@ -28,6 +28,10 @@
#include <SDL_thread.h>
#include <SDL_timer.h>
#ifdef __EMSCRIPTEN__
#include <emscripten.h>
#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
}
}

View File

@ -21,9 +21,10 @@
#ifndef BOOSTHASH_H
#define BOOSTHASH_H
#include <string>
#include <map>
#include <set>
#include <boost/unordered/unordered_map.hpp>
#include <boost/unordered/unordered_set.hpp>
#include <utility>
/* Wrappers around the boost unordered template classes,
@ -33,7 +34,7 @@ template<typename K, typename V>
class BoostHash
{
private:
typedef std::map<K, V> BoostType;
typedef boost::unordered_map<K, V> BoostType;
typedef std::pair<K, V> PairType;
BoostType p;
@ -97,7 +98,7 @@ template<typename K>
class BoostSet
{
private:
typedef std::set<K> BoostType;
typedef boost::unordered_set<K> BoostType;
BoostType p;
public:

View File

@ -43,7 +43,7 @@ struct Config
int defScreenH = 0;
int fixedFramerate = 0;
bool frameSkip =true;
bool frameSkip =false;
bool syncToRefreshrate = false;
bool solidFonts = false;

View File

@ -446,7 +446,7 @@ private:
SDL_Delay(ticks / tickFreqMS);
#endif
#endif
#ifdef __EMSCRIPTEN
#ifdef __EMSCRIPTEN__
emscripten_sleep(ticks /tickFreqMS);
#endif
}

View File

@ -46,6 +46,11 @@
#include "icon.png.xxd"
#ifdef __EMSCRIPTEN__
#include <emscripten.h>
#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)
{