diff --git a/Makefile.emscripten b/Makefile.emscripten new file mode 100644 index 000000000..603ee279e --- /dev/null +++ b/Makefile.emscripten @@ -0,0 +1,8 @@ +CC=emcc +CXX=emcc +LD=emcc +SIZE=size +DEBUG=0 + +USE_LIBA=0 +EXE=html diff --git a/escher/src/container.cpp b/escher/src/container.cpp index 88d5b8d16..e2f19247d 100644 --- a/escher/src/container.cpp +++ b/escher/src/container.cpp @@ -1,5 +1,8 @@ #include #include +#ifdef __EMSCRIPTEN__ +#include +#endif Container::Container() : m_activeApp(nullptr) @@ -23,9 +26,13 @@ void Container::run() { m_window.setFrame(KDRect(0, 0, Ion::Display::Width, Ion::Display::Height)); m_window.redraw(); +#ifdef __EMSCRIPTEN__ + emscripten_set_main_loop_arg([](void * ctx){ ((Container *)ctx)->step(); }, this, 0, 1); +#else while (true) { step(); } +#endif } void Container::step() { diff --git a/ion/src/emscripten/Makefile b/ion/src/emscripten/Makefile new file mode 100644 index 000000000..d6745de7a --- /dev/null +++ b/ion/src/emscripten/Makefile @@ -0,0 +1,3 @@ +objs += $(addprefix ion/src/emscripten/, \ + main.o\ +) diff --git a/ion/src/emscripten/main.cpp b/ion/src/emscripten/main.cpp new file mode 100644 index 000000000..04986bd37 --- /dev/null +++ b/ion/src/emscripten/main.cpp @@ -0,0 +1,75 @@ +#include +extern "C" { +#include +#include +#include +#include +} + +SDL_Surface * screen = nullptr; + +int main(int argc, char * argv[]) { + SDL_Init(SDL_INIT_VIDEO); + screen = SDL_SetVideoMode(Ion::Display::Width, Ion::Display::Height, 32, SDL_HWSURFACE); + 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(); jpixels + 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) { +} + +Ion::Events::Event Ion::Events::getEvent() { + SDL_Event event; + if (SDL_PollEvent(&event)) { + if (event.type == SDL_KEYDOWN) { + switch(event.key.keysym.sym) { + case SDLK_UP: + return Ion::Events::Event::UP_ARROW; + case SDLK_DOWN: + return Ion::Events::Event::DOWN_ARROW; + case SDLK_LEFT: + return Ion::Events::Event::LEFT_ARROW; + case SDLK_RIGHT: + return Ion::Events::Event::RIGHT_ARROW; + case SDLK_RETURN: + return Ion::Events::Event::ENTER; + case SDLK_ESCAPE: + return Ion::Events::Event::ESC; + } + } + } + return Ion::Events::Event::SHIFT; +} + +bool Ion::Keyboard::keyDown(Ion::Keyboard::Key key) { + //SDL_Quit(); + return false; +} + +void Ion::msleep(long ms) { + usleep(1000*ms); +}