mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[emscripten] Use emterpreter
This allows us to control the runloop
This commit is contained in:
committed by
EmilieNumworks
parent
fd7516f8ac
commit
67f082f4e8
2
Makefile
2
Makefile
@@ -125,3 +125,5 @@ endif
|
||||
clean:
|
||||
@echo "CLEAN"
|
||||
@rm -f $(products)
|
||||
|
||||
-include build/targets.$(PLATFORM).mak
|
||||
|
||||
@@ -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() ||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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 $@)
|
||||
|
||||
17
build/targets.emscripten.mak
Normal file
17
build/targets.emscripten.mak
Normal 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
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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++) {
|
||||
|
||||
Reference in New Issue
Block a user