--- a/gamma256/gameSource/game.cpp +++ b/gamma256/gameSource/game.cpp @@ -30,6 +30,7 @@ #include +#include #include "blowUp.h" #include "World.h" @@ -118,8 +119,8 @@ char getKeyDown( int inKeyCode ) { SDL_PumpEvents(); - Uint8 *keys = SDL_GetKeyState( NULL ); - return keys[ inKeyCode ] == SDL_PRESSED; + const Uint8 *keys = SDL_GetKeyboardState( NULL ); + return keys[ SDL_GetScancodeFromKey( inKeyCode ) ] != 0; } @@ -176,7 +177,8 @@ SDL_Event event; while( true ) { - while( SDL_WaitEvent( &event ) ) { + // the browser build has no blocking wait: poll and give the page the turn + while( SDL_PollEvent( &event ) || ( emscripten_sleep( 20 ), true ) ) { switch( event.type ) { case SDL_JOYHATMOTION: case SDL_JOYBUTTONDOWN: @@ -205,37 +207,25 @@ -// flips back buffer onto screen (or updates rect) -void flipScreen( SDL_Surface *inScreen ) { +// SDL 2: the game draws on a software surface and this copies it to the window +SDL_Window *window = NULL; - // unlock the screen if necessary - if( SDL_MUSTLOCK( inScreen ) ) { - SDL_UnlockSurface( inScreen ); - } - - if( ( inScreen->flags & SDL_DOUBLEBUF ) == SDL_DOUBLEBUF ) { - // need to flip buffer - SDL_Flip( inScreen ); - } - else if( !blowUpChanged ) { - // just update center - - // small area in center that we actually draw in, black around it - int yOffset = ( inScreen->h - totalImageHeight * blowUpFactor ) / 2; - int xOffset = ( inScreen->w - width * blowUpFactor ) / 2; - - SDL_UpdateRect( inScreen, xOffset, yOffset, - width * blowUpFactor, - totalImageHeight * blowUpFactor ); - } - else { - // update the whole thing - SDL_UpdateRect( inScreen, 0, 0, inScreen->w, inScreen->h ); - - // reset flag - blowUpChanged = false; +// flips back buffer onto screen +void flipScreen( SDL_Surface *inScreen ) { + // the game draws 0x00RRGGBB; the window surface of the browser build is 0x00BBGGRR + SDL_Surface *windowSurface = SDL_GetWindowSurface( window ); + for( int y=0; yh; y++ ) { + Uint32 *from = (Uint32 *)( (char *)inScreen->pixels + + y * inScreen->pitch ); + Uint32 *to = (Uint32 *)( (char *)windowSurface->pixels + + y * windowSurface->pitch ); + for( int x=0; xw; x++ ) { + Uint32 p = from[x]; + to[x] = ( ( p & 0xFF ) << 16 ) | ( p & 0xFF00 ) + | ( ( p >> 16 ) & 0xFF ); + } } - + SDL_UpdateWindowSurface( window ); } @@ -311,22 +301,18 @@ int displayW = width * blowUpFactor; int displayH = totalImageHeight * blowUpFactor; - - Uint32 flags = SDL_HWSURFACE | SDL_DOUBLEBUF; - if( fullScreen ) { - flags = flags | SDL_FULLSCREEN; - - // use letterbox mode in full screen - displayW = screenWidth; - displayH = screenHeight; + if( window == NULL ) { + window = SDL_CreateWindow( "Passage", SDL_WINDOWPOS_UNDEFINED, + SDL_WINDOWPOS_UNDEFINED, + displayW, displayH, 0 ); + } + else { + SDL_SetWindowSize( window, displayW, displayH ); } - - - screen = SDL_SetVideoMode( displayW, displayH, - 32, - flags ); - + screen = SDL_CreateRGBSurface( 0, displayW, displayH, 32, + 0x00FF0000, 0x0000FF00, 0x000000FF, 0 ); + if ( screen == NULL ) { printf( "Couldn't set %dx%dx32 video mode: %s\n", displayW, displayH, @@ -966,38 +952,7 @@ } - if( getKeyDown( SDLK_b ) ) { - // adjust blowup factor - blowUpFactor += blowUpStep; - - if( blowUpFactor > maxBlowUpFactor ) { - blowUpStep *= -1; - blowUpFactor = maxBlowUpFactor - 1; - } - - if( blowUpFactor < 1 ) { - blowUpStep *= -1; - blowUpFactor = 2; - } - - if( fullScreen ) { - // force redraw of whole screen - blowUpChanged = true; - } - else { - // create a new screen using the new size - createScreen(); - } - - } - - if( getKeyDown( SDLK_f ) ) { - // toggle fullscreen mode - fullScreen = ! fullScreen; - - // create a new screen surface (and destroy old one) - createScreen(); - } + // (the B key for zoom and the F key for full screen are off in the browser build) @@ -1131,8 +1086,7 @@ switch( event.key.keysym.sym ) { case SDLK_q: case SDLK_ESCAPE: - done = true; - quit = true; + // no quitting in the browser (it would leave a dead page) break; default: break; --- a/minorGems/system/linux/ThreadLinux.cpp 2005-01-22 19:15:06.000000000 -0200 +++ b/minorGems/system/linux/ThreadLinux.cpp 2026-11-01 20:48:37.855771112 -0300 @@ -31,6 +31,9 @@ #include #include +#ifdef __EMSCRIPTEN__ +#include +#endif #include @@ -116,6 +119,12 @@ void Thread::staticSleep( unsigned long inTimeInMilliseconds ) { +#ifdef __EMSCRIPTEN__ + // the browser build sleeps by giving the turn back to the page (Asyncify) + emscripten_sleep( inTimeInMilliseconds ); + return; +#endif + unsigned long seconds = inTimeInMilliseconds / 1000; unsigned long milliseconds = inTimeInMilliseconds % 1000;