[ion/simulator/web] Implement a custom journal with callbacks

This journal adds two new callbacks:
 - onIonEvent
 - onEpsilonIdle
This commit is contained in:
Romain Goyet
2021-02-25 15:32:43 -05:00
committed by Léa Saviot
parent c66db8c98d
commit 2ebff40c62
2 changed files with 59 additions and 1 deletions

View File

@@ -16,6 +16,7 @@ LDFLAGS += --pre-js ion/src/simulator/web/preamble_env.js
ion_src += $(addprefix ion/src/simulator/web/, \
clipboard_helper.cpp \
exports.cpp \
journal.cpp \
keyboard_callback.cpp \
window_callback.cpp \
)
@@ -24,7 +25,6 @@ ion_src += $(addprefix ion/src/simulator/shared/, \
dummy/language.cpp \
dummy/haptics_enabled.cpp \
haptics.cpp \
journal.cpp \
)
ion_src += ion/src/shared/collect_registers.cpp

View File

@@ -0,0 +1,58 @@
#include "../shared/journal.h"
#include "../shared/journal/queue_journal.h"
#include <emscripten.h>
namespace Ion {
namespace Simulator {
namespace Journal {
using Ion::Events::Event;
using Ion::Events::None;
class LogJournal : public Ion::Events::Journal {
public:
void pushEvent(Event e) override {
static bool lastEventWasNone = false;
if (e != None) {
EM_ASM({
if (typeof Module.onIonEvent === "function") {
Module.onIonEvent($0);
}
}, static_cast<uint8_t>(e));
lastEventWasNone = true;
} else {
if (!lastEventWasNone) {
EM_ASM({
if (typeof Module.onEpsilonIdle === "function") {
Module.onEpsilonIdle();
}
});
}
lastEventWasNone = true;
}
}
Event popEvent() override {
return None;
}
bool isEmpty() override {
return true;
}
};
void init() {
Events::logTo(logJournal());
}
Events::Journal * replayJournal() {
static QueueJournal journal;
return &journal;
}
Ion::Events::Journal * logJournal() {
static LogJournal journal;
return &journal;
}
}
}
}