[emscripten] Use emterpreter

This allows us to control the runloop
This commit is contained in:
Romain Goyet
2018-02-01 12:01:12 +01:00
committed by EmilieNumworks
parent fd7516f8ac
commit 67f082f4e8
10 changed files with 31 additions and 25 deletions

View File

@@ -125,3 +125,5 @@ endif
clean:
@echo "CLEAN"
@rm -f $(products)
-include build/targets.$(PLATFORM).mak

View File

@@ -136,11 +136,6 @@ void AppsContainer::run() {
switchTo(nullptr);
}
void AppsContainer::runWhile(bool (*callback)(void * ctx), void * ctx) {
while (callback(ctx) && RunLoop::step()) {
}
}
bool AppsContainer::updateBatteryState() {
if (m_window.updateBatteryLevel() ||
m_window.updateIsChargingState() ||

View File

@@ -39,7 +39,6 @@ public:
virtual bool dispatchEvent(Ion::Events::Event event) override;
void switchTo(App::Snapshot * snapshot) override;
void run() override;
void runWhile(bool (*callback)(void * ctx), void * ctx);
bool updateBatteryState();
void refreshPreferences();
void displayExamModePopUp(bool activate);

View File

@@ -3,14 +3,3 @@ USE_LIBA = 0
EXE = js
OS_WITH_ONBOARDING_APP ?= 0
OS_WITH_SOFTWARE_UPDATE_PROMPT ?= 0
numworks_simulator.zip: LDFLAGS += --memory-init-file 0
numworks_simulator.zip: app.js
@rm -rf $(basename $@)
@mkdir $(basename $@)
@cp app.js $(basename $@)/firmware.js
@cp ion/src/emscripten/background.jpg $(basename $@)/
@cp ion/src/emscripten/simulator.html $(basename $@)/
@echo "ZIP $@"
@zip -r -9 $@ $(basename $@) > /dev/null
@rm -rf $(basename $@)

View File

@@ -0,0 +1,17 @@
app.js: LDFLAGS += -s 'EMTERPRETIFY_FILE="app.etb"'
app.js: $(app_objs) $(app_image_objs)
app.packed.js: LDFLAGS += --memory-init-file 0
app.packed.js: $(app_objs) $(app_image_objs)
numworks_simulator.zip: app.packed.js
@rm -rf $(basename $@)
@mkdir $(basename $@)
@cp app.packed.js $(basename $@)/epsilon.js
@cp ion/src/emscripten/background.jpg $(basename $@)/
@cp ion/src/emscripten/simulator.html $(basename $@)/
@echo "ZIP $@"
@zip -r -9 $@ $(basename $@) > /dev/null
@rm -rf $(basename $@)
products += $(addprefix app.,js mem etb) app.packed.js numworks_simulator.zip

View File

@@ -1,5 +1,6 @@
CC = emcc
CXX = emcc
LD = emcc
LDFLAGS = -s EXPORTED_FUNCTIONS="['_main', '_IonEventsEmscriptenPushEvent']" -Os
SFLAGS = -s EMTERPRETIFY=1 -s EMTERPRETIFY_ASYNC=1
LDFLAGS = -Oz -s EMTERPRETIFY=1 -s EMTERPRETIFY_ASYNC=1 -s EXPORTED_FUNCTIONS="['_main', '_IonEventsEmscriptenPushEvent']"
SIZE = size

View File

@@ -8,12 +8,13 @@ class RunLoop {
public:
RunLoop();
void run();
void runWhile(bool (*callback)(void * ctx), void * ctx);
protected:
virtual bool dispatchEvent(Ion::Events::Event e) = 0;
virtual int numberOfTimers();
virtual Timer * timerAtIndex(int i);
bool step();
private:
bool step();
int m_time;
};

View File

@@ -18,12 +18,12 @@ Timer * RunLoop::timerAtIndex(int i) {
}
void RunLoop::run() {
#ifdef __EMSCRIPTEN__
emscripten_set_main_loop_arg([](void * ctx){ ((RunLoop *)ctx)->step(); }, this, 0, 1);
#else
while(step()) {
runWhile(nullptr, nullptr);
}
void RunLoop::runWhile(bool (*callback)(void * ctx), void * ctx) {
while ((callback == nullptr || callback(ctx)) && step()) {
}
#endif
}
bool RunLoop::step() {

View File

@@ -4,6 +4,7 @@
extern "C" {
#include <SDL/SDL.h>
}
#include <emscripten.h>
static Ion::Events::Event sEvent = Ion::Events::None;
@@ -47,6 +48,7 @@ static constexpr Event sEventForASCIICharAbove32[95] = {
Event getEvent(int * timeout) {
Ion::Display::Emscripten::refresh();
emscripten_sleep(1);
if (sEvent != None) {
Event event = sEvent;
updateModifiersFromEvent(event);

View File

@@ -197,7 +197,7 @@ var Module = {
canvas: document.getElementById("screen")
};
</script>
<script src="firmware.js"></script>
<script src="epsilon.js"></script>
<script>
var buttons = document.querySelectorAll(".calculator .keyboard a");
for (var i=0; i< buttons.length; i++) {