[ion] Fix the emscripten build

Change-Id: Ia54c5de4191c47d9840854d9aad12f87a9110da3
This commit is contained in:
Romain Goyet
2017-05-15 22:04:37 +02:00
parent 739c362ff0
commit a1552b2fa1
15 changed files with 226 additions and 135 deletions

View File

@@ -19,7 +19,7 @@ Timer * RunLoop::timerAtIndex(int i) {
void RunLoop::run() {
#ifdef __EMSCRIPTEN__
emscripten_set_main_loop_arg([](void * ctx){ ((Container *)ctx)->step(); }, this, 0, 1);
emscripten_set_main_loop_arg([](void * ctx){ ((RunLoop *)ctx)->step(); }, this, 0, 1);
#else
while(step()) {
}

View File

@@ -3,7 +3,6 @@ objs += $(addprefix ion/src/blackbox/, \
ion.o \
display.o \
events.o \
keyboard.o \
)
objs += $(addprefix ion/src/shared/, \
@@ -14,6 +13,11 @@ objs += $(addprefix ion/src/shared/, \
power.o \
dummy/backlight.o \
dummy/battery.o \
dummy/events_modifier.o \
dummy/led.o \
dummy/keyboard.o \
dummy/serial_number.o \
dummy/usb.o \
)
ion/src/shared/log_printf.o: SFLAGS=-Iion/include

View File

@@ -9,7 +9,7 @@ namespace Events {
static int sLogAfterNumberOfEvents = -1;
static int sEventCount = 0;
Ion::Events::Event Ion::Events::getEvent(int * timeout) {
Event getEvent(int * timeout) {
Ion::Events::Event event = Ion::Events::None;
while (!(event.isDefined() && event.isKeyboardEvent())) {
int c = getchar();
@@ -29,22 +29,6 @@ Ion::Events::Event Ion::Events::getEvent(int * timeout) {
return event;
}
bool isShiftActive() {
return false;
}
bool isAlphaActive() {
return false;
}
bool isAlphaLocked() {
return false;
}
bool isShiftAlphaLocked() {
return false;
}
namespace Blackbox {
void dumpEventCount(int i) {

View File

@@ -1,16 +1,5 @@
#include <stdint.h>
#include <ion.h>
bool Ion::USB::isPlugged() {
return false;
}
void Ion::msleep(long ms) {
}
const char * Ion::serialNumber() {
return "123";
}
void Ion::LED::setColor(KDColor) {
}

View File

@@ -1,10 +1,18 @@
objs += $(addprefix ion/src/emscripten/, \
main.o\
display.o \
events.o \
main.o \
)
objs += $(addprefix ion/src/shared/, \
crc32.o \
events.o \
events_keyboard.o \
power.o \
dummy/backlight.o \
dummy/battery.o \
dummy/events_modifier.o \
dummy/keyboard.o \
dummy/led.o \
dummy/serial_number.o \
dummy/usb.o \
)

View File

@@ -0,0 +1,56 @@
#include "display.h"
extern "C" {
#include <SDL/SDL.h>
#include <assert.h>
}
SDL_Surface * screen = nullptr;
namespace Ion {
namespace Display {
void pushRect(KDRect r, const KDColor * pixels) {
if (SDL_MUSTLOCK(screen)) {
SDL_LockSurface(screen);
}
int pixelNumber = 0;
for (int j=r.top(); j<r.bottom(); j++) {
for (int i=r.left(); i<r.right(); i++) {
KDColor c = pixels[pixelNumber++];
*((Uint32*)screen->pixels + j * Ion::Display::Width + i) = SDL_MapRGB(screen->format, c.red(), c.green(), c.blue());
}
}
if (SDL_MUSTLOCK(screen)) {
SDL_UnlockSurface(screen);
}
SDL_UpdateRect(screen, r.x(), r.y(), r.width(), r.height());
}
void pushRectUniform(KDRect r, KDColor c) {
Uint32 sdlColor = SDL_MapRGB(screen->format, c.red(), c.green(), c.blue());
SDL_Rect sdlRect = { r.x(), r.y(), r.width(), r.height() };
SDL_FillRect(screen, &sdlRect, sdlColor);
SDL_UpdateRect(screen, r.x(), r.y(), r.width(), r.height());
}
void pullRect(KDRect r, KDColor * pixels) {
}
void waitForVBlank() {
}
}
}
namespace Ion {
namespace Display {
namespace Emscripten {
void init() {
SDL_Init(SDL_INIT_VIDEO);
screen = SDL_SetVideoMode(Ion::Display::Width, Ion::Display::Height, 32, SDL_HWSURFACE);
}
}
}
}

View File

@@ -0,0 +1,16 @@
#ifndef ION_EMSCRIPTEN_DISPLAY_H
#define ION_EMSCRIPTEN_DISPLAY_H
#include <ion/display.h>
namespace Ion {
namespace Display {
namespace Emscripten {
void init();
}
}
}
#endif

View File

@@ -0,0 +1,76 @@
#include <ion/events.h>
extern "C" {
#include <SDL/SDL.h>
}
Ion::Events::Event sEvent = Ion::Events::None;
void IonEventsEmscriptenPushEvent(int eventNumber) {
sEvent = Ion::Events::Event(eventNumber);
}
namespace Ion {
namespace Events {
static constexpr Event sEventForASCIICharAbove32[95] = {
Space, Exclamation, DoubleQuotes, None, None, None, None, None,
LeftParenthesis, RightParenthesis, Multiplication, Plus, Comma, Minus, Dot, Division,
Zero, One, Two, Three, Four, Five, Six, Seven,
Eight, Nine, Colon, SemiColon, Lower, Equal, Greater, Question,
None, UpperA, UpperB, UpperC, UpperD, UpperE, UpperF, UpperG,
UpperH, UpperI, UpperJ, UpperK, UpperL, UpperM, UpperN, UpperO,
UpperP, UpperQ, UpperR, UpperS, UpperT, UpperU, UpperV, UpperW,
UpperX, UpperY, UpperZ, LeftBracket, None, RightBracket, Power, Underscore,
None, LowerA, LowerB, LowerC, LowerD, LowerE, LowerF, LowerG,
LowerH, LowerI, LowerJ, LowerK, LowerL, LowerM, LowerN, LowerO,
LowerP, LowerQ, LowerR, LowerS, LowerT, LowerU, LowerV, LowerW,
LowerX, LowerY, LowerZ, LeftBrace, None, RightBrace, None
};
Event getEvent(int * timeout) {
if (sEvent != Ion::Events::None) {
Ion::Events::Event event = sEvent;
sEvent = Ion::Events::None;
return event;
}
SDL_Event event;
if (SDL_PollEvent(&event)) {
if (event.type == SDL_KEYDOWN) {
switch(event.key.keysym.sym) {
case SDLK_UP:
return Ion::Events::Up;
case SDLK_DOWN:
return Ion::Events::Down;
case SDLK_LEFT:
return Ion::Events::Left;
case SDLK_RIGHT:
return Ion::Events::Right;
case SDLK_RETURN:
return Ion::Events::OK;
case SDLK_ESCAPE:
return Ion::Events::Back;
case SDLK_BACKSPACE:
return Ion::Events::Backspace;
}
if (event.key.keysym.unicode >= 32 && event.key.keysym.unicode < 127) {
return sEventForASCIICharAbove32[event.key.keysym.unicode-32];
}
}
}
return Ion::Events::None;
}
}
}
namespace Ion {
namespace Events {
namespace Emscripten {
void init() {
SDL_EnableUNICODE(1); // We're using Unicode values from Keyboard input
}
}
}
}

View File

@@ -0,0 +1,20 @@
#ifndef ION_EMSCRIPTEN_EVENTS_H
#define ION_EMSCRIPTEN_EVENTS_H
#include <ion/events.h>
extern "C" {
void IonEventsEmscriptenPushEvent(int e);
}
namespace Ion {
namespace Events {
namespace Emscripten {
void init();
}
}
}
#endif

View File

@@ -1,112 +1,13 @@
#include <ion.h>
extern "C" {
#include <assert.h>
#include <stdio.h>
#include <unistd.h>
#include <SDL/SDL.h>
}
extern "C" {
void IonEmscriptenPushEvent(int e);
}
SDL_Surface * screen = nullptr;
Ion::Events::Event sEvent = Ion::Events::None;
void IonEmscriptenPushEvent(int eventNumber) {
sEvent = Ion::Events::Event(eventNumber);
}
#include "display.h"
#include "events.h"
int main(int argc, char * argv[]) {
SDL_EnableUNICODE(1); // We're using Unicode values from Keyboard input
SDL_Init(SDL_INIT_VIDEO);
screen = SDL_SetVideoMode(Ion::Display::Width, Ion::Display::Height, 32, SDL_HWSURFACE);
Ion::Display::Emscripten::init();
Ion::Events::Emscripten::init();
ion_app();
return 0;
}
void Ion::Display::pushRect(KDRect r, const KDColor * pixels) {
if (SDL_MUSTLOCK(screen)) {
SDL_LockSurface(screen);
}
int pixelNumber = 0;
for (int j=r.top(); j<r.bottom(); j++) {
for (int i=r.left(); i<r.right(); i++) {
KDColor c = pixels[pixelNumber++];
*((Uint32*)screen->pixels + j * Ion::Display::Width + i) = SDL_MapRGB(screen->format, c.red(), c.green(), c.blue());
}
}
if (SDL_MUSTLOCK(screen)) {
SDL_UnlockSurface(screen);
}
SDL_UpdateRect(screen, r.x(), r.y(), r.width(), r.height());
}
void Ion::Display::pushRectUniform(KDRect r, KDColor c) {
Uint32 sdlColor = SDL_MapRGB(screen->format, c.red(), c.green(), c.blue());
SDL_Rect sdlRect = { r.x(), r.y(), r.width(), r.height() };
SDL_FillRect(screen, &sdlRect, sdlColor);
SDL_UpdateRect(screen, r.x(), r.y(), r.width(), r.height());
}
void Ion::Display::pullRect(KDRect r, KDColor * pixels) {
}
using namespace Ion::Events;
static constexpr Event sEventForASCIICharAbove32[95] = {
Space, Exclamation, DoubleQuotes, None, None, None, None, None,
LeftParenthesis, RightParenthesis, Multiplication, Plus, Comma, Minus, Dot, Division,
Zero, One, Two, Three, Four, Five, Six, Seven,
Eight, Nine, Colon, SemiColon, Lower, Equal, Greater, Question,
None, UpperA, UpperB, UpperC, UpperD, UpperE, UpperF, UpperG,
UpperH, UpperI, UpperJ, UpperK, UpperL, UpperM, UpperN, UpperO,
UpperP, UpperQ, UpperR, UpperS, UpperT, UpperU, UpperV, UpperW,
UpperX, UpperY, UpperZ, LeftBracket, None, RightBracket, Power, Underscore,
None, LowerA, LowerB, LowerC, LowerD, LowerE, LowerF, LowerG,
LowerH, LowerI, LowerJ, LowerK, LowerL, LowerM, LowerN, LowerO,
LowerP, LowerQ, LowerR, LowerS, LowerT, LowerU, LowerV, LowerW,
LowerX, LowerY, LowerZ, LeftBrace, None, RightBrace, None
};
Ion::Events::Event Ion::Events::getEvent() {
if (sEvent != Ion::Events::None) {
Ion::Events::Event event = sEvent;
sEvent = Ion::Events::None;
return event;
}
SDL_Event event;
if (SDL_PollEvent(&event)) {
if (event.type == SDL_KEYDOWN) {
switch(event.key.keysym.sym) {
case SDLK_UP:
return Ion::Events::Up;
case SDLK_DOWN:
return Ion::Events::Down;
case SDLK_LEFT:
return Ion::Events::Left;
case SDLK_RIGHT:
return Ion::Events::Right;
case SDLK_RETURN:
return Ion::Events::OK;
case SDLK_ESCAPE:
return Ion::Events::Back;
case SDLK_BACKSPACE:
return Ion::Events::Backspace;
}
if (event.key.keysym.unicode >= 32 && event.key.keysym.unicode < 127) {
return sEventForASCIICharAbove32[event.key.keysym.unicode-32];
}
}
}
return Ion::Events::None;
}
bool Ion::Keyboard::keyDown(Ion::Keyboard::Key key) {
//SDL_Quit();
return false;
}
void Ion::msleep(long ms) {
usleep(1000*ms);
}

View File

@@ -0,0 +1,23 @@
#include <ion/events.h>
namespace Ion {
namespace Events {
bool isShiftActive() {
return false;
}
bool isAlphaActive() {
return false;
}
bool isAlphaLocked() {
return false;
}
bool isShiftAlphaLocked() {
return false;
}
}
}

View File

@@ -0,0 +1,4 @@
#include <ion/led.h>
void Ion::LED::setColor(KDColor c) {
}

View File

@@ -0,0 +1,5 @@
#include <ion.h>
const char * Ion::serialNumber() {
return "UNKNOWN";
}

View File

@@ -0,0 +1,5 @@
#include <ion/usb.h>
bool Ion::USB::isPlugged() {
return false;
}