diff -ruN a/src/domino-chain/fribidi.h b/src/domino-chain/fribidi.h --- a/src/domino-chain/fribidi.h +++ b/src/domino-chain/fribidi.h @@ -0,0 +1,63 @@ +/* + * Minimal stand-in for the FriBidi calls Domino Chain makes (fredygames.com browser build). + * It handles left-to-right text only, which is all the English interface needs: the text is + * converted from UTF-8 to UTF-32, every character gets the left-to-right level 0 and the line + * reordering leaves the line as it is. + */ +#ifndef FRIBIDI_SHIM_H +#define FRIBIDI_SHIM_H + +#include +#include + +typedef uint32_t FriBidiChar; +typedef uint32_t FriBidiCharType; +typedef int8_t FriBidiLevel; +typedef int FriBidiStrIndex; + +#define FRIBIDI_TYPE_ON 0 +#define FRIBIDI_TYPE_LTR 0 +#define FRIBIDI_CHAR_SET_UTF8 1 +#define FRIBIDI_FLAGS_DEFAULT 0 + +static inline FriBidiStrIndex fribidi_charset_to_unicode(int, const char *s, FriBidiStrIndex len, FriBidiChar *out) +{ + FriBidiStrIndex n = 0; + for (FriBidiStrIndex i = 0; i < len;) + { + unsigned char c = (unsigned char)s[i]; + uint32_t cp; + int extra; + if (c < 0x80) { cp = c; extra = 0; } + else if ((c >> 5) == 6) { cp = c & 0x1F; extra = 1; } + else if ((c >> 4) == 14) { cp = c & 0x0F; extra = 2; } + else if ((c >> 3) == 30) { cp = c & 0x07; extra = 3; } + else { cp = 0xFFFD; extra = 0; } + i++; + for (int k = 0; k < extra && i < len && ((unsigned char)s[i] >> 6) == 2; k++, i++) + cp = (cp << 6) | ((unsigned char)s[i] & 0x3F); + out[n++] = cp; + } + return n; +} + +static inline void fribidi_get_bidi_types(const FriBidiChar *, FriBidiStrIndex len, FriBidiCharType *types) +{ + for (FriBidiStrIndex i = 0; i < len; i++) types[i] = FRIBIDI_TYPE_LTR; +} + +static inline FriBidiLevel fribidi_get_par_embedding_levels(const FriBidiCharType *, FriBidiStrIndex len, + FriBidiCharType *base, FriBidiLevel *levels) +{ + *base = FRIBIDI_TYPE_LTR; + for (FriBidiStrIndex i = 0; i < len; i++) levels[i] = 0; + return 1; +} + +static inline FriBidiLevel fribidi_reorder_line(int, const FriBidiCharType *, FriBidiStrIndex, FriBidiStrIndex, + FriBidiCharType, FriBidiLevel *, FriBidiChar *, FriBidiStrIndex *) +{ + return 1; +} + +#endif diff -ruN a/src/domino-chain/graphicsn.cpp b/src/domino-chain/graphicsn.cpp --- a/src/domino-chain/graphicsn.cpp +++ b/src/domino-chain/graphicsn.cpp @@ -36,7 +36,7 @@ #include -#include +#include // the following array contains the y offset to use for the different // images of the different figure animation images @@ -314,7 +314,7 @@ // constant care std::string figurefile; - if (boost::filesystem::exists(getHome() + "figure.png")) + if (std::filesystem::exists(getHome() + "figure.png")) figurefile = getHome() + "figure.png"; else figurefile = dataPath+"/images/figure.png"; diff -ruN a/src/domino-chain/main.cpp b/src/domino-chain/main.cpp --- a/src/domino-chain/main.cpp +++ b/src/domino-chain/main.cpp @@ -37,6 +37,9 @@ #include #include +#ifdef __EMSCRIPTEN__ +#include +#endif static std::string getDataDir(void) { @@ -261,6 +264,10 @@ while (SDL_GetTicks() < ticks) SDL_Delay(ticks-SDL_GetTicks()); } +#ifdef __EMSCRIPTEN__ + // hand the turn back to the browser, which paints and delivers input in between + emscripten_sleep(0); +#endif while (true) { diff -ruN a/src/domino-chain/screen.cpp b/src/domino-chain/screen.cpp --- a/src/domino-chain/screen.cpp +++ b/src/domino-chain/screen.cpp @@ -204,6 +204,16 @@ { SDL_UpdateTexture(sdlTexture, NULL, video->pixels, video->pitch); +#ifdef __EMSCRIPTEN__ + // the canvas does not keep the previous frame after presenting it, so the changed blocks + // alone would leave everything else black: copy the whole picture every time + (void)dirty; + SDL_RenderCopy(sdlRenderer, sdlTexture, NULL, NULL); + SDL_RenderPresent(sdlRenderer); + animationState = 0; + return; +#endif + for (int y = 0; y < 25; y++) { int rowStart = -1; @@ -630,10 +640,15 @@ } SDL_UpdateTexture(sdlTexture, NULL, video->pixels, video->pitch); +#ifdef __EMSCRIPTEN__ + // see flipDirty + SDL_RenderCopy(sdlRenderer, sdlTexture, NULL, NULL); +#else for (int i = 0; i < count; i++) { SDL_RenderCopy(sdlRenderer, sdlTexture, &rects[i], &rects[i]); } +#endif SDL_RenderPresent(sdlRenderer); if (animationState == 64) diff -ruN a/src/domino-chain/tools.cpp b/src/domino-chain/tools.cpp --- a/src/domino-chain/tools.cpp +++ b/src/domino-chain/tools.cpp @@ -46,7 +46,7 @@ #include -#include +#include uint64_t getTime(void) { @@ -160,19 +160,19 @@ std::string findFileInDirectory(const std::string & path, const std::string name, uint16_t depth) { - boost::filesystem::path p (path); // p reads clearer than argv[1] in the following code + std::filesystem::path p (path); // p reads clearer than argv[1] in the following code if (depth > 0) { - if (boost::filesystem::exists(p)) + if (std::filesystem::exists(p)) { - if (boost::filesystem::is_regular_file(p) && p.filename() == name) + if (std::filesystem::is_regular_file(p) && p.filename() == name) { return p.string(); } - else if (boost::filesystem::is_directory(p)) + else if (std::filesystem::is_directory(p)) { - for (boost::filesystem::directory_iterator i(p); i != boost::filesystem::directory_iterator(); ++i) + for (std::filesystem::directory_iterator i(p); i != std::filesystem::directory_iterator(); ++i) { std::string f = findFileInDirectory(i->path().string(), name, depth-1);