Changes to Chromium B.S.U. 0.9.16.1 for the fredygames.com build, 2026-10-23. Each changed source file below carries a notice saying how and when it was changed. One data file is replaced as well, which a text patch cannot carry: data/png/powerUpShield.png, the icon of the shield, repair and super-shield power-ups (originally the Tux penguin), is replaced by a shield drawn by make-shield-icon.py (FredyGames, 2026-10-23; the PNG carries the same notice in a text chunk). build-chromium-bsu.sh copies it over the original after applying this patch. diff --git a/src/Config.cpp b/src/Config.cpp index 6bda90b..d4497f1 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -4,6 +4,9 @@ * "Chromium B.S.U." is free software; you can redistribute * it and/or use it and/or modify it under the terms of the * "Clarified Artistic License" + * + * Changed for the fredygames.com build of Chromium B.S.U. on 2026-10-23 (only when + * compiled with Emscripten, under __EMSCRIPTEN__): the default screen size is 1024x768. */ #ifdef HAVE_CONFIG_H @@ -49,8 +52,13 @@ Config *Config::m_instance = 0; Config::Config() { //-- setup defaults +#ifdef __EMSCRIPTEN__ + m_screenW = 1024; + m_screenH = 768; +#else m_screenW = 800; m_screenH = 600; +#endif m_screenA = 1.3333333f; m_screenFOV = 30.0f; m_screenNear = 10.0; diff --git a/src/Image.cpp b/src/Image.cpp index 266de49..c67d155 100644 --- a/src/Image.cpp +++ b/src/Image.cpp @@ -5,6 +5,11 @@ * "Chromium B.S.U." is free software; you can redistribute * it and/or use it and/or modify it under the terms of the * "Clarified Artistic License" + * + * Changed for the fredygames.com build of Chromium B.S.U. on 2026-10-23 (only when + * compiled with Emscripten, under __EMSCRIPTEN__): every image is + * converted to RGBA before upload (grayscale and palette PNGs were uploaded as luminance), and the + * blend modes walk the real image height. */ #ifdef HAVE_CONFIG_H @@ -65,6 +70,38 @@ GLuint Image::load(const char *filename, ImageMipMap mipmap, ImageBlend trans, G glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, magfilter); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, minfilter); +#ifdef __EMSCRIPTEN__ + // Every image becomes RGBA; SOLID drops the alpha channel, as glpng does, and the BLEND modes + // derive it from the color. + { + SDL_Surface *rgba = SDL_ConvertSurfaceFormat(image, SDL_PIXELFORMAT_RGBA32, 0); + SDL_FreeSurface(image); + if (!rgba) + { + fprintf(stderr, "Failed to convert %s: %s\n", filename, SDL_GetError()); + return texture; + } + image = rgba; + SDL_LockSurface(image); + for(int y = 0; y < image->h; y++) + { + Uint8 *p = (Uint8 *)image->pixels + y*image->pitch; + for(int x = 0; x < image->w; x++, p += 4) + { + Uint32 a = p[0]+p[1]+p[2]; + switch ( trans ) + { + case IMG_SOLID: p[3] = 0xFF; break; + case IMG_BLEND1: p[3] = a > 0xFF ? 0xFF : a; break; + case IMG_BLEND2: p[3] = a > 0x1FE ? 0xFF : a/2; break; + case IMG_BLEND3: p[3] = a/3; break; + default: break; + } + } + } + SDL_UnlockSurface(image); + } +#else // For the blend types, we need to convert to RGBA if( trans != IMG_SOLID && trans != IMG_ALPHA ) { @@ -147,6 +184,7 @@ GLuint Image::load(const char *filename, ImageMipMap mipmap, ImageBlend trans, G image = tmp; } } +#endif GLenum format; switch ( image->format->BytesPerPixel ) diff --git a/src/MainSDL.cpp b/src/MainSDL.cpp index 88f65e8..9e33d9e 100644 --- a/src/MainSDL.cpp +++ b/src/MainSDL.cpp @@ -4,6 +4,11 @@ * "Chromium B.S.U." is free software; you can redistribute * it and/or use it and/or modify it under the terms of the * "Clarified Artistic License" + * + * Changed for the fredygames.com build of Chromium B.S.U. on 2026-10-23 (only when + * compiled with Emscripten, under __EMSCRIPTEN__): changing the screen size resizes the existing + * canvas instead of opening a second window, and full screen is refused (the page has its own + * full-screen button; a browser only goes full screen from inside an input event). */ #ifdef HAVE_CONFIG_H @@ -55,6 +60,9 @@ MainSDL::MainSDL(int argc, char **argv) xjoy = yjoy = xjNow = yjNow = 0; adjCount = 0; key_speed_x = key_speed_y = 0; +#ifdef __EMSCRIPTEN__ + window = 0; +#endif Uint32 initOpts; @@ -367,6 +375,22 @@ bool MainSDL::setVideoMode() SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); #if SDL_VERSION_ATLEAST(2,0,0) +#ifdef __EMSCRIPTEN__ + if(config->fullScreen()) + { + if(window) + return false; + config->setFullScreen(false); + } + video_flags &= ~SDL_FULLSCREEN; + if(window) + { + SDL_SetWindowSize(window, w, h); + if(game->mainGL) + game->mainGL->initGL(); + return true; + } +#endif window = SDL_CreateWindow("Chromium B.S.U.", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, w, h, video_flags); if (!window) { fprintf(stderr, _("Couldn't create window: %s\n"), SDL_GetError()); diff --git a/src/MainSDL_Event.cpp b/src/MainSDL_Event.cpp index 117982b..eb2662c 100644 --- a/src/MainSDL_Event.cpp +++ b/src/MainSDL_Event.cpp @@ -4,6 +4,11 @@ * "Chromium B.S.U." is free software; you can redistribute * it and/or use it and/or modify it under the terms of the * "Clarified Artistic License" + * + * Changed for the fredygames.com build of Chromium B.S.U. on 2026-10-23 (only when + * compiled with Emscripten, under __EMSCRIPTEN__): the ship follows the relative mouse motion of the + * browser's pointer lock, since a page cannot move the mouse pointer, and Q no longer quits (the menu + * still has quit). */ #ifdef HAVE_CONFIG_H @@ -344,7 +349,9 @@ void MainSDL::keyDown(SDL_Event *event) switch(event->key.keysym.sym) { case SDL_QUIT: +#ifndef __EMSCRIPTEN__ case SDLK_q: +#endif game->game_quit = true; break; case SDLK_g: @@ -539,6 +546,14 @@ void MainSDL::mouseMotion(SDL_Event *event) int yNow; int xDiff; int yDiff; +#ifdef __EMSCRIPTEN__ + if(mouseToggle) + { + if(event->motion.xrel || event->motion.yrel) + game->hero->moveEvent(event->motion.xrel, event->motion.yrel); + } + return; +#endif if(mouseToggle) { xNow = event->motion.x; @@ -640,6 +655,10 @@ void MainSDL::grabMouse(bool status, bool warpmouse) if( config->debug() ) fprintf(stderr, _("MainSDL::grabMouse(%d)\n"), status); mouseToggle = status; +#ifdef __EMSCRIPTEN__ + SDL_SetRelativeMouseMode(status ? SDL_TRUE : SDL_FALSE); + return; +#endif if(status) SDL_ShowCursor(0); else diff --git a/src/main.cpp b/src/main.cpp index 5129bdc..9128f94 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4,6 +4,11 @@ * "Chromium B.S.U." is free software; you can redistribute * it and/or use it and/or modify it under the terms of the * "Clarified Artistic License" + * + * Changed for the fredygames.com build of Chromium B.S.U. on 2026-10-23 (only when + * compiled with Emscripten, under __EMSCRIPTEN__): high scores are signed "player" (the browser has no + * user name), and fredygames_save() lets the page write the options when the tab is hidden or closed, + * since the game only writes them when it exits. */ #ifdef HAVE_CONFIG_H @@ -50,6 +55,15 @@ #include "EnemyAircraft.h" +#ifdef __EMSCRIPTEN__ +#include + +extern "C" EMSCRIPTEN_KEEPALIVE void fredygames_save() +{ + Config::instance()->saveFile(); +} +#endif + //---------------------------------------------------------- int main(int argc, char **argv) { @@ -57,6 +71,10 @@ int main(int argc, char **argv) int tmp; int vm = 2; +#ifdef __EMSCRIPTEN__ + setenv("USER", "player", 1); +#endif + #ifdef ENABLE_NLS setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR);