mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[ion] Add an event journal
It's pretty much just two callbacks that one can hook into to get some events in or out of Ion. It adds a couple useless checks and pointers to any build and could be hidden behind a feature flag, but the extra weight is minimal.
This commit is contained in:
@@ -53,6 +53,15 @@ enum class ShiftAlphaStatus {
|
||||
// Timeout is decremented
|
||||
Event getEvent(int * timeout);
|
||||
|
||||
class Journal {
|
||||
public:
|
||||
virtual void pushEvent(Event e) = 0;
|
||||
virtual Event popEvent() = 0;
|
||||
};
|
||||
|
||||
void replayFrom(Journal * l);
|
||||
void logTo(Journal * l);
|
||||
|
||||
ShiftAlphaStatus shiftAlphaStatus();
|
||||
void setShiftAlphaStatus(ShiftAlphaStatus s);
|
||||
void removeShift();
|
||||
|
||||
@@ -50,7 +50,11 @@ void resetLongRepetition() {
|
||||
ComputeAndSetRepetionFactor(sEventRepetitionCount);
|
||||
}
|
||||
|
||||
Event getEvent(int * timeout) {
|
||||
static Keyboard::Key keyFromState(Keyboard::State state) {
|
||||
return static_cast<Keyboard::Key>(63 - __builtin_clzll(state));
|
||||
}
|
||||
|
||||
static inline Event innerGetEvent(int * timeout) {
|
||||
assert(*timeout > delayBeforeRepeat);
|
||||
assert(*timeout > delayBetweenRepeat);
|
||||
int time = 0;
|
||||
@@ -114,5 +118,27 @@ Event getEvent(int * timeout) {
|
||||
}
|
||||
}
|
||||
|
||||
static Journal * sSourceJournal = nullptr;
|
||||
static Journal * sDestinationJournal = nullptr;
|
||||
void replayFrom(Journal * l) { sSourceJournal = l; }
|
||||
void logTo(Journal * l) { sDestinationJournal = l; }
|
||||
|
||||
Event getEvent(int * timeout) {
|
||||
if (sSourceJournal != nullptr) {
|
||||
Event e = sSourceJournal->popEvent();
|
||||
if (e == None) {
|
||||
sSourceJournal = nullptr;
|
||||
} else {
|
||||
return e;
|
||||
}
|
||||
}
|
||||
Event e = innerGetEvent(timeout);
|
||||
if (sDestinationJournal != nullptr && e != None) {
|
||||
sDestinationJournal->pushEvent(e);
|
||||
}
|
||||
return e;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user