mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-18 16:27:34 +01:00
[ion/simulator/web] Implement a custom journal with callbacks
This journal adds two new callbacks: - onIonEvent - onEpsilonIdle
This commit is contained in:
@@ -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
|
||||
|
||||
58
ion/src/simulator/web/journal.cpp
Normal file
58
ion/src/simulator/web/journal.cpp
Normal 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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user