more grammer

master
masterex1000 7 months ago
parent
commit
3919bda4c2
1 changed files with 3 additions and 3 deletions
  1. +3
    -3
      Working-for-Web-(HTML5).md

+ 3
- 3
Working-for-Web-(HTML5).md

@ -169,17 +169,17 @@ To setup your own game to compile for web there are two possible options:
### 4.1 Avoid raylib `while(!WindowShouldClose())` loop
Main reason to avoid the standard game `while()` loop is related to the way browsers work; the browser needs to control the executed process and just allow a single Update-Draw execution in a time-frame, so execution could be controlled and locked when required (i.e. when the tab is not active or browser is minimized). More details [here](https://emscripten.org/docs/porting/emscripten-runtime-environment.html#browser-main-loop)
The main reason to avoid the standard game `while()` loop is related to the way browsers work; the browser needs to control the executed process and just allow a single Update-Draw execution in a time-frame, so execution could be controlled and locked when required (i.e. when the tab is not active or browser is minimized). More details [here](https://emscripten.org/docs/porting/emscripten-runtime-environment.html#browser-main-loop)
To avoid the loop, code must be **slightly adapted**. Basically it implies moving all your `Update` and `Draw` code to an external function, possibly called `UpdateDrawFrame()`, and consequently manage all required variables from a global context.
For a simple example on code refactoring for web, check [`core_basic_window_web.c`](https://github.com/raysan5/raylib/blob/master/examples/core/core_basic_window_web.c) example. For a more complex example, just check [`raylib-game-template`](https://github.com/raysan5/raylib-game-template), game template includes an already configured `Makefile` ready to compile it for web.
Avoiding `while()` loop will give better control of the program to the browser and it will run at full speed in the web.
Avoiding the game `while()` loop will give better control of the program to the browser and it will run at full speed in the web.
### 4.2 Use standard raylib `while(!WindowShouldClose())` loop
There could be some situations where the game `while()` loop could not be avoided and users need to deal with it. For those situations, emscripten implemented [`ASYNCIFY`](https://emscripten.org/docs/porting/asyncify.html). `ASYNCIFY` basically detect synchronous code and allows it to run asynchronous. Enabling ASYNCIFY just requires an additional compilation flag passed to `emcc` when compiling game code.
There could be some situations where the game `while()` loop could not be avoided and users need to deal with it. For those situations, emscripten implemented [`ASYNCIFY`](https://emscripten.org/docs/porting/asyncify.html). `ASYNCIFY` allows emscripten to detect synchronous code and run it asynchronously. Enabling ASYNCIFY just requires an additional compilation flag passed to `emcc` when compiling game code.
raylib examples [`Makefile`](https://github.com/raysan5/raylib/blob/master/examples/Makefile) has been adapted to use [`ASYNCIFY`](https://github.com/raysan5/raylib/blob/master/examples/Makefile#L310) by default, they work great but note that there is a small performance penalization.

Loading…
Cancel
Save