Skip to content

Added WebAssembly fixes, the game can run now in any internet browser - #80

Open
BloodSharp-HvH wants to merge 5 commits into
sergiou87:masterfrom
BloodSharp-HvH:feature/webassembly-fixes
Open

BloodSharp-HvH wants to merge 5 commits into
sergiou87:masterfrom
BloodSharp-HvH:feature/webassembly-fixes

Conversation

@BloodSharp-HvH

Copy link
Copy Markdown

¡Hola buen día Sergio!

Este pull request corrige problemas para compilar y ejecutar el juego con webassembly.

  • Reemplazada la función SDL_Delay con la función emscripten_sleep si la toolchain es emscripten, la cual es equivalente a un delay común y corriente pero además permite al navegador recuperar el control en los casos de los bucles que congelan el videojuego en un loop infinito
  • Deshabilitada la aceleración gráfica si la toolchain es emscripten debido a que si se habilita puede llamar funciones de timing cuando no hay una función de bucle principal de emscripten lo cual generará error en tiempo de ejecución.
  • Agregada la función waitTime en prácticamente casi todos los while y do-while la cual permite al navegador recuperar el control temporalmente en los casos que se necesiten verificar cosas como estado de los controles de entrada. Probablemente algunos estén de más, pero por las dudas también pueden servir...
  • Agregado un archivo shell minimalista html que permite jugar a ventana completa de la página web.
  • Agregados flags de linker necesarios, como librerías adicionales para SDL_mixer, flag de ASYNCIFY para operaciones asincrónicas (como la función mencionada anteriormente de emscripten_sleep) y el flag del archivo shell minimalista html.

Si se quiere probar el juego en WebAssembly lo subí a mi página de github pages para una pequeña demostración:

https://bloodsharp-hvh.github.io/games/supaplex/

Nota: El enlace de arriba también tiene un parche adicional para desbloquear todos los niveles al registrar un usuario porque quería probar todos los niveles en Wasm, este Pull Request no incluye dicho parche específico para emscripten, salvo que quieras que se lo agregue.

Saludos cordiales.
Agustín.

B#

- Add support for ogg and mod to SDL2 mixer library format
- Add 'ASYNCIFY' flag to enable 'emscripten_sleep' function support
- Add 'webassembly-minimal-page-template.html' shell html file

@sergiou87 sergiou87 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Muchas gracias! A priori los cambios tienen buena pinta, pero tengo una duda sobre los waitTime que has introducido y si se pueden reemplazar por waitTime(0)

Comment thread src/supaplex.c
do
{
int9handler(1);
waitTime(1);

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Por curiosidad: funciona igual si haces waitTime(0)?

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Browser-yield gaps and per-object sleeps leave input responsiveness and gameplay timing regressions unresolved.

6 open issues
What changed in this PR

Updates the SDL-based game’s WebAssembly support to improve browser execution, rendering, and input responsiveness.

Changes:

  • Uses Emscripten-compatible waits and adds yielding calls throughout gameplay and menu loops.
  • Selects software rendering for WebAssembly builds.
  • Adds a full-page HTML canvas shell and enables Asyncify and SDL_mixer formats.
File Description
wasm/​webassembly-minimal-page-template.html Adds the browser canvas host and runtime logging.
wasm/​Makefile Enables Asyncify, mixer formats, and the custom HTML shell.
src/​supaplex.c Adds waits to gameplay, input, and menu code paths.
src/​sdl2/​video.c Selects software rendering under Emscripten.
src/​sdl_common/​system.c Uses emscripten_sleep for WebAssembly waits while retaining native delays.

Review effort: Max

Comment thread src/supaplex.c
{
break;
}
waitTime(1);
Comment thread src/supaplex.c
newPlayerName[gNewPlayerNameLength] = character; // mov [bx+si], al
gNewPlayerNameLength++;
drawTextWithChars6FontWithOpaqueBackgroundIfPossible(232, 127, 6, newPlayerName);
waitTime(1);
Comment thread src/supaplex.c
}
}

waitTime(1);
Comment thread src/supaplex.c
Comment on lines +7553 to 7554
waitTime(1);
} while (file == NULL);
Comment thread src/supaplex.c
Comment on lines +7951 to 7952
waitTime(1);
} while (numberOfChanges > 0);
<html lang="en-us">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no"/>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants