Skip to content

Conversation

moufmouf
Copy link
Collaborator

For each requested animation frame (RAF) in Phaser, Phaser calls the "update" method, then the "render" method of each scenes.
The "render" method takes some time (and energy) to perform the rendering.

The fact is we probably don't need to call "render" if nothing changed on the screen (which happens most of the frames in a typical WorkAdventure game).

This commit is therefore overloading the "Game" class of Phaser to add a "dirty" flag.

Scenes can now add a "isDirty()" method. If all displayed scenes are pristine (not dirty), Phaser will skip rendering the frame altogether.

This saves "a lot" of energy, resulting in laptops that are not overheating when using WorkAdventure \o/

This reverts commit f2c3d6f. Also, updates all dependencies to their latest allowed version. # Conflicts: #	front/package.json #	front/yarn.lock
This commit adds a new optimization. Tiles are now not rendered directly on screen, but in 2 intermediate textures (one for the floor and one for elements above players) The textures are then rendered. While this adds an extra layer, the good thing is that the textures don't need to be redrawn unless we move! This means that we can completely bypass the drawing of each single tile most of the time (and only draw the big texture instead). As a result, CPU consumption goes from ~50% to ~25% (this is a big boost). Beware, this optimization will make implementing animations slightly trickier. We will probably want to isolate tiles and not draw them in the texture but keep drawing them directly on screen.
@moufmouf moufmouf changed the title Skip "render" if nothing changed on screen [WIP] Skip "render" if nothing changed on screen Apr 23, 2021
For each requested animation frame (RAF) in Phaser, Phaser calls the "update" method, then the "render" method of each scenes. The "render" method takes some time (and energy) to perform the rendering. The fact is we probably don't need to call "render" if nothing changed on the screen (which happens most of the frames in a typical WorkAdventure game). This commit is therefore overloading the "Game" class of Phaser to add a "dirty" flag. Scenes can now add a "isDirty()" method. If all displayed scenes are pristine (not dirty), Phaser will skip rendering the frame altogether. This saves "a lot" of energy, resulting in laptops that are not overheating when using WorkAdventure \o/
@moufmouf moufmouf added the deploy Create a deploy environment label Apr 27, 2021
@moufmouf
Copy link
Collaborator Author

moufmouf commented May 7, 2021

Superseded by #998

@moufmouf moufmouf closed this May 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

deploy Create a deploy environment

1 participant