7 #include <emscripten.h> 9 template<
typename T,
int N>
12 Queue() : m_first(&m_elements[0]), m_last(&m_elements[0]) {}
14 if (m_last >= m_first) {
15 return m_last - m_first;
17 return m_last - (m_first -
N);
27 m_last = next(m_last);
36 m_first = next(m_first);
42 if (p >= m_elements +
N) {
61 sEventQueue.enqueue(event);
87 static constexpr Event sEventForASCIICharAbove32[95] = {
102 static bool sleepWithTimeout(
int duration,
int * timeout) {
103 if (*timeout >= duration) {
104 emscripten_sleep(duration);
105 *timeout -= duration;
108 emscripten_sleep(*timeout);
114 static Event eventFromSDLEvent(SDL_Event sdlEvent) {
115 if (sdlEvent.type != SDL_KEYDOWN) {
118 if (sdlEvent.key.keysym.mod & KMOD_CTRL) {
119 switch (sdlEvent.key.keysym.sym) {
130 if (sdlEvent.key.keysym.mod & KMOD_ALT) {
131 if (sdlEvent.key.keysym.mod & KMOD_SHIFT) {
132 switch (sdlEvent.key.keysym.sym) {
141 switch (sdlEvent.key.keysym.sym) {
178 switch(sdlEvent.key.keysym.sym) {
196 if (sdlEvent.key.keysym.unicode >= 32 && sdlEvent.key.keysym.unicode < 127) {
197 return sEventForASCIICharAbove32[sdlEvent.key.keysym.unicode-32];
204 if (sEventQueue.size() <= 1) {
210 if (sEventQueue.size() > 0) {
211 Event
event = sEventQueue.dequeue();
212 if (event.isKeyboardEvent()) {
220 SDL_PollEvent(&sdlEvent);
221 Event eventFromSDL = eventFromSDLEvent(sdlEvent);
222 if (eventFromSDL !=
None) {
226 if (sleepWithTimeout(10, timeout)) {
238 namespace Emscripten {
241 SDL_EnableUNICODE(1);
constexpr Event DoubleQuotes
Event getEvent(int *timeout)
constexpr Event Underscore
constexpr Event Arctangent
constexpr Event LeftParenthesis
void updateModifiersFromEvent(Event e)
constexpr Event Exclamation
constexpr Event RightParenthesis
constexpr Event RightBrace
constexpr Event LeftBracket
constexpr Event SemiColon
void IonEventsEmscriptenPushKey(int keyNumber)
constexpr Event Arccosine
constexpr Event Imaginary
constexpr Event Multiplication
constexpr Event LeftBrace
void IonEventsEmscriptenPushEvent(int eventNumber)
constexpr Event Backspace
constexpr Event RightBracket