diff --git a/JLib/JLib/Graphics/JImage.cpp b/JLib/JLib/Graphics/JImage.cpp index 99a8d91..79ebef5 100644 --- a/JLib/JLib/Graphics/JImage.cpp +++ b/JLib/JLib/Graphics/JImage.cpp @@ -317,6 +317,11 @@ u32 JImage::Load(JRW &f) u32 JImage::Save(JRW &f) { u32 sz = Size(); +#ifdef __EMSCRIPTEN__ + u32 colorkey = hc_ColorKey(surface); +#else + u32 colorkey = surface->format->colorkey; +#endif if (f.WriteLE32(&surface->w) && f.WriteLE32(&surface->h) && f.Write8(&surface->format->BitsPerPixel) && @@ -324,7 +329,7 @@ u32 JImage::Save(JRW &f) f.WriteLE32(&surface->format->Gmask) && f.WriteLE32(&surface->format->Bmask) && f.WriteLE32(&surface->format->Amask) && - f.WriteLE32(&surface->format->colorkey) && + f.WriteLE32(&colorkey) && f.WriteLE32(&sz)) { if (0 == Lock()) @@ -400,7 +405,7 @@ JImage * JImage::Scale(float xp, float yp) { for (float nx = nx0; nx < nx0 + dx; ++nx) { - SDL_GetRGBA(GetPixel((s32)nx, (s32)ny), surface->format, &samp.r, &samp.g, &samp.b, &samp.unused); + SDL_GetRGBA(GetPixel((s32)nx, (s32)ny), surface->format, &samp.r, &samp.g, &samp.b, &samp.a); // Averigua la cuota de participación del pixel. // Para ello vemos el cociente entre la superficie de pixel original en la nueva imagen @@ -417,7 +422,7 @@ JImage * JImage::Scale(float xp, float yp) rAccum += float(samp.r) * ratio; gAccum += float(samp.g) * ratio; bAccum += float(samp.b) * ratio; - aAccum += float(samp.unused) * ratio; + aAccum += float(samp.a) * ratio; } } @@ -497,7 +502,12 @@ JString JImage::DumpFromSurface(SDL_Surface *s) JString s1, s2, s3, s4, s5, s6; SDL_PixelFormat *fmt = s->format; - s1.Format("%dx%d@%d COLOR_KEY: %08x SURFACE_ALPHA: %d\n", s->w, s->h, fmt->BitsPerPixel, fmt->colorkey, fmt->alpha); + s1.Format("%dx%d@%d COLOR_KEY: %08x SURFACE_ALPHA: %d\n", s->w, s->h, fmt->BitsPerPixel, +#ifdef __EMSCRIPTEN__ + hc_ColorKey(s), hc_SurfaceAlpha(s)); +#else + fmt->colorkey, fmt->alpha); +#endif s2.Format("pitch: %d clip_rect: x%d y%d w%d h%d pixels: %p\n", s->pitch, s->clip_rect.x, s->clip_rect.y, s->clip_rect.w, s->clip_rect.h, s->pixels); s3.Format("RGBAmask: R: 0x%08x G: 0x%08x B: 0x%08x A: 0x%08x\n", fmt->Rmask, fmt->Gmask, fmt->Bmask, fmt->Amask); s4.Format("RGBAshift: R: 0x%08x G: 0x%08x B: 0x%08x A: 0x%08x\n", fmt->Rshift, fmt->Gshift, fmt->Bshift, fmt->Ashift); diff --git a/JLib/JLib/Graphics/JImage.h b/JLib/JLib/Graphics/JImage.h index 5e4d433..b78fd54 100644 --- a/JLib/JLib/Graphics/JImage.h +++ b/JLib/JLib/Graphics/JImage.h @@ -159,7 +159,11 @@ public: /** Devuelve el alfa asociado a la superficie * @return Alfa de la superficie. */ + #ifdef __EMSCRIPTEN__ + u8 Alpha() {return hc_SurfaceAlpha(surface);} +#else u8 Alpha() {return surface->format->alpha;} +#endif /** Establece el color transparente y habilita el uso de color transparente en la superficie. * @param key Color transparente. @@ -170,7 +174,11 @@ public: /** Devuelve el color transparente * @return Color transparente. */ + #ifdef __EMSCRIPTEN__ + u32 ColorKey() {return hc_ColorKey(surface);} +#else u32 ColorKey() {return surface->format->colorkey;} +#endif /** Pega el contenido de una imagen en esta. No comprueba que * no se sobrepasen los límites de la imagen. diff --git a/JLib/JLib/Util/JApp.cpp b/JLib/JLib/Util/JApp.cpp index f130faa..e2d9dea 100644 --- a/JLib/JLib/Util/JApp.cpp +++ b/JLib/JLib/Util/JApp.cpp @@ -28,6 +28,9 @@ */ #include +#ifdef __EMSCRIPTEN__ +#include +#endif JApp * JApp::thisApp = 0; @@ -141,6 +144,7 @@ bool JApp::UpdateEvents() { switch(e.type) { +#ifndef __EMSCRIPTEN__ case SDL_ACTIVEEVENT: // Pasamos a estado de pausa switch (e.active.state) @@ -168,6 +172,7 @@ bool JApp::UpdateEvents() } break; +#endif case SDL_KEYDOWN: // Actualiza el estado del teclado @@ -294,6 +299,7 @@ bool JApp::UpdateEvents() } break; +#ifndef __EMSCRIPTEN__ case SDL_VIDEORESIZE: if (__OnResize) @@ -313,6 +319,7 @@ bool JApp::UpdateEvents() } break; +#endif case SDL_USEREVENT: if (__OnUser) { @@ -349,6 +356,13 @@ s32 JApp::MainLoop() printf("Error updating the app.\n"); } } +#ifdef __EMSCRIPTEN__ + else + { + // gives the browser a turn while waiting for the next frame + emscripten_sleep(1); + } +#endif } else { @@ -541,8 +555,10 @@ void JApp::DumpVideoInfo() fprintf(stdout, " RGBAloss: R: 0x%08x G: 0x%08x B: 0x%08x A: 0x%08x\n", vi->vfmt->Rloss, vi->vfmt->Gloss, vi->vfmt->Bloss, vi->vfmt->Aloss); +#ifndef __EMSCRIPTEN__ fprintf(stdout, " ColorKey: 0x%08x\n", vi->vfmt->colorkey); fprintf(stdout, " Alpha: 0x%02x\n", vi->vfmt->alpha); +#endif } void JApp::Icon(const char *filename) diff --git a/JLib/JLib/Util/JRW.h b/JLib/JLib/Util/JRW.h index 43c44e2..13af3fd 100644 --- a/JLib/JLib/Util/JRW.h +++ b/JLib/JLib/Util/JRW.h @@ -71,7 +71,7 @@ class JRW : public JObject { Destroy(); - return (0 != (rwops = SDL_RWFromFP(fp, autoclose))); + return (0 != (rwops = SDL_RWFromFP(fp, autoclose ? SDL_TRUE : SDL_FALSE))); } /** Creates (and destroys any existing) SDL_RWops structure to access a memory block. diff --git a/JLib/JLib/Util/JTextFile.cpp b/JLib/JLib/Util/JTextFile.cpp index 7689b24..feba4d1 100644 --- a/JLib/JLib/Util/JTextFile.cpp +++ b/JLib/JLib/Util/JTextFile.cpp @@ -349,7 +349,12 @@ u32 JTextFile::Printf(const s8 *fmt, ... ) vsprintf(str, fmt, vlist); va_end(vlist); +#ifdef __EMSCRIPTEN__ + // musl's fputs returns 0 on success, which the callers take as an error + return (fputs(str, file) >= 0) ? 1 : 0; +#else return(fputs(str, file)); +#endif } // Lectura tipo scanf diff --git a/JLib/JLib/Util/JUtil.cpp b/JLib/JLib/Util/JUtil.cpp index adf1ef3..f8b8a1f 100644 --- a/JLib/JLib/Util/JUtil.cpp +++ b/JLib/JLib/Util/JUtil.cpp @@ -206,7 +206,13 @@ void JDumpImage(JImage *img, s32 n) fprintf(stderr, "%dx%d@%d CKEY: %08x ALPHA: %d SRCALPHA: %s SRCCOLORKEY: %s RLE: %s\n", - s->w, s->h, fmt->BitsPerPixel, fmt->colorkey, fmt->alpha, + s->w, s->h, fmt->BitsPerPixel, +#ifdef __EMSCRIPTEN__ + hc_ColorKey(s), hc_SurfaceAlpha(s), +#else + fmt->colorkey, fmt->alpha, +#endif + s->flags & SDL_SRCALPHA ? "yes" : "no", s->flags & SDL_SRCCOLORKEY ? "yes" : "no", s->flags & SDL_RLEACCEL ? "yes" : "no"); @@ -242,7 +248,11 @@ void JDumpImage(JImage *img, s32 n) { for (s32 i = 0; count <= n && i < s->w; ++i) { + #ifdef __EMSCRIPTEN__ + if (img->GetPixel(i, j) != hc_ColorKey(s)) +#else if (img->GetPixel(i, j) != fmt->colorkey) +#endif { fprintf(stderr, "%08x ", img->GetPixel(i, j)); diff --git a/res/playlist.txt b/res/playlist.txt index 252a04e..a6b55f4 100644 --- a/res/playlist.txt +++ b/res/playlist.txt @@ -1,2 +1 @@ holotzcastle -milanb diff --git a/src/HolotzCastle.cpp b/src/HolotzCastle.cpp index f599bed..253b58e 100644 --- a/src/HolotzCastle.cpp +++ b/src/HolotzCastle.cpp @@ -366,6 +366,15 @@ bool HCApp::InitMenu() if (f.ReadLine(str)) it->AddNodeGo(new JTextMenuEntry(str, &OnHelp, 0)); else return false; // Help if (f.ReadLine(str)) it->AddNodeGo(new JTextMenuEntry(str, 0, 0)); else return false; // Options { +#ifdef __EMSCRIPTEN__ + // fredygames.com: no video options (the page scales a fixed 640x480 screen and has its own + // fullscreen button); their seven lines of menu.txt are skipped + for (s32 skip = 0; skip < 7; ++skip) + { + if (!f.ReadLine(str)) return false; + } + if (f.ReadLine(str)) it->AddBranchGo(new JTextMenuEntry(str, 0, 0)); else return false; // Sound +#else if (f.ReadLine(str)) it->AddBranchGo(new JTextMenuEntry(str, 0, 0)); else return false; // Video { if (f.ReadLine(str)) it->AddBranchGo(new JTextMenuEntry(str, 0, 0)); else return false; // Size @@ -414,6 +423,7 @@ bool HCApp::InitMenu() } if (f.ReadLine(str)) it->AddNodeGo(new JTextMenuEntry(str, 0, 0)); else return false; // Sound +#endif { if (f.ReadLine(str)) it->AddBranchGo(new JTextMenuEntry(str, &OnSound, (void*)1)); else return false;// On if (f.ReadLine(str)) it->AddNodeGo(new JTextMenuEntry(str, &OnSound, (void*)0)); else return false; // Off