Skip to content

Commit e86787b

Browse files
committed
some fixes
1 parent 491a9a8 commit e86787b

File tree

2 files changed

+10
-10
lines changed
  • content/blog/2024/12-30-bevy-mobile-framerate
  • docs/blog/2024/12-30-bevy-mobile-framerate

2 files changed

+10
-10
lines changed

content/blog/2024/12-30-bevy-mobile-framerate/index.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ On the one hand a game is supposed to run smoothly which requires a high enough
1515

1616
In this short post we talk about how to balance the two and how to adapt the balance based on your specific apps needs.
1717

18-
We will also find out why the default settings of Bevy on mobile used to lead to the worrysome statistics in the xcode debugger you see on the right - indicating that we run at ∞ fps and using 200% CPU 🥵.
18+
We will also find out why the default settings of Bevy on mobile used to lead to the worrisome statistics in the xcode debugger you see on the right - indicating that we run at ∞ fps and using 200% CPU 🥵.
1919

2020
# Why mobile has to be treated differently
2121

@@ -31,9 +31,9 @@ The Bevy engine is a general purpose game engine. It is not specifically designe
3131

3232
So how to fix this problem? The short answer is: Limit the framerate.
3333

34-
The catch is though that your device might vsync at 60Hz already making you think the problem lies somewhere else. The footgun is that even if the rendering is limited to 60Hz Bevy will - by default - still update all your systems as often as it possibly can even if rendering updates are only happening in a 60 fps rate.
34+
The catch is though that your device might VSync at 60Hz already making you think the problem lies somewhere else. The foot-gun is that even if the rendering is limited to 60Hz Bevy will - by default - still update all your systems as often as it possibly can even if rendering updates are only happening in a 60 fps rate.
3535

36-
The solution is to configure the refresh rate of winit:
36+
The solution is to configure the refresh rate of *winit*:
3737

3838
```rust
3939
app.add_systems(Startup, init_refresh_rate);
@@ -43,15 +43,15 @@ fn init_refresh_rate(mut winit: ResMut<WinitSettings>) {
4343
}
4444
```
4545

46-
Using `UpdateMode::reactive` will lead to bevy refreshing our systems also based on user input like mouse events as they happen but in an abscence of any event to *react* to it will limit the refresh rate to 60Hz. This is a sensible default for most mobile games.
46+
Using `UpdateMode::reactive` will lead to bevy refreshing our systems also based on user input like mouse events as they happen but in an absence of any event to *react* to it will limit the refresh rate to 60Hz. This is a sensible default for most mobile games.
4747

4848
But we can do better. We can adapt this at runtime.
4949

5050
# Adaptable framerate
5151

5252
In the above example we simply configure this 60Hz rate on startup. But you can adapt this at any time. This allows you to reduce the refresh rate in menus or more static situations and increase it during action phases where a low fps would lead to a reduced user experience.
5353

54-
A simple way would be to tie it to gamestates:
54+
A simple way would be to tie it to game states:
5555

5656
```rust
5757
app.add_systems(OnEnter(GameState::FastAction), high_fps);

docs/blog/2024/12-30-bevy-mobile-framerate/index.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ <h1 class="title">
3535
<p>Mobile Games have to walk a fine line between rendering performance and energy conservation.</p>
3636
<p>On the one hand a game is supposed to run smoothly which requires a high enough framerate and yet not to consume too much energy and therefore draining battery too quickly.</p>
3737
<p>In this short post we talk about how to balance the two and how to adapt the balance based on your specific apps needs.</p>
38-
<p>We will also find out why the default settings of Bevy on mobile used to lead to the worrysome statistics in the xcode debugger you see on the right - indicating that we run at ∞ fps and using 200% CPU 🥵.</p>
38+
<p>We will also find out why the default settings of Bevy on mobile used to lead to the worrisome statistics in the xcode debugger you see on the right - indicating that we run at ∞ fps and using 200% CPU 🥵.</p>
3939
<h1 id="why-mobile-has-to-be-treated-differently">Why mobile has to be treated differently</h1>
4040
<p>Traditionally games are rendered at the highest possible framerate. In case of PC and console games this means utilizing the hardware to the fullest maximizing fidelity, image and effect quality and overall richness of the experience.</p>
4141
<p>On mobile however, the situation is different. The hardware is not only less powerful but also the device is not designed to be cooled actively. Instead the heat has to be dissipated through the case and the screen. This means that the device can get <strong>hot</strong> quickly. On the other hand the phone battery is another limiting factor. The more energy the game consumes the quicker the <strong>battery</strong> will be drained. As a phone user I don't want to suddenly change my charging habits just because I played my game.</p>
@@ -45,19 +45,19 @@ <h1 id="why-mobile-has-to-be-treated-differently">Why mobile has to be treated d
4545
<p>The Bevy engine is a general purpose game engine. It is not specifically designed for mobile games. This means that the default settings are not optimized for mobile. This is not a problem as long as you are aware of it and know how to adjust the settings.</p>
4646
<h1 id="how-to-limit-processing">How to limit processing</h1>
4747
<p>So how to fix this problem? The short answer is: Limit the framerate.</p>
48-
<p>The catch is though that your device might vsync at 60Hz already making you think the problem lies somewhere else. The footgun is that even if the rendering is limited to 60Hz Bevy will - by default - still update all your systems as often as it possibly can even if rendering updates are only happening in a 60 fps rate.</p>
49-
<p>The solution is to configure the refresh rate of winit:</p>
48+
<p>The catch is though that your device might VSync at 60Hz already making you think the problem lies somewhere else. The foot-gun is that even if the rendering is limited to 60Hz Bevy will - by default - still update all your systems as often as it possibly can even if rendering updates are only happening in a 60 fps rate.</p>
49+
<p>The solution is to configure the refresh rate of <em>winit</em>:</p>
5050
<pre data-lang="rust" style="background-color:#212121;color:#eeffff;" class="language-rust "><code class="language-rust" data-lang="rust"><span>app</span><span style="color:#89ddff;">.</span><span style="color:#82aaff;">add_systems</span><span style="color:#89ddff;">(</span><span>Startup</span><span style="color:#89ddff;">,</span><span> init_refresh_rate</span><span style="color:#89ddff;">);
5151
</span><span>
5252
</span><span style="font-style:italic;color:#c792ea;">fn </span><span style="color:#82aaff;">init_refresh_rate</span><span style="color:#89ddff;">(</span><span style="color:#c792ea;">mut </span><span style="color:#f78c6c;">winit</span><span style="color:#89ddff;">: </span><span>ResMut</span><span style="color:#89ddff;">&lt;</span><span>WinitSettings</span><span style="color:#89ddff;">&gt;) {
5353
</span><span> winit</span><span style="color:#89ddff;">.</span><span>focused_mode </span><span style="color:#89ddff;">= </span><span>UpdateMode</span><span style="color:#89ddff;">::</span><span>reactive</span><span style="color:#89ddff;">(</span><span>Duration</span><span style="color:#89ddff;">::</span><span>from_secs_f32</span><span style="color:#89ddff;">(</span><span style="color:#f78c6c;">1.0 </span><span style="color:#89ddff;">/ </span><span style="color:#f78c6c;">60.0</span><span style="color:#89ddff;">));
5454
</span><span style="color:#89ddff;">}
5555
</span></code></pre>
56-
<p>Using <code>UpdateMode::reactive</code> will lead to bevy refreshing our systems also based on user input like mouse events as they happen but in an abscence of any event to <em>react</em> to it will limit the refresh rate to 60Hz. This is a sensible default for most mobile games.</p>
56+
<p>Using <code>UpdateMode::reactive</code> will lead to bevy refreshing our systems also based on user input like mouse events as they happen but in an absence of any event to <em>react</em> to it will limit the refresh rate to 60Hz. This is a sensible default for most mobile games.</p>
5757
<p>But we can do better. We can adapt this at runtime.</p>
5858
<h1 id="adaptable-framerate">Adaptable framerate</h1>
5959
<p>In the above example we simply configure this 60Hz rate on startup. But you can adapt this at any time. This allows you to reduce the refresh rate in menus or more static situations and increase it during action phases where a low fps would lead to a reduced user experience.</p>
60-
<p>A simple way would be to tie it to gamestates:</p>
60+
<p>A simple way would be to tie it to game states:</p>
6161
<pre data-lang="rust" style="background-color:#212121;color:#eeffff;" class="language-rust "><code class="language-rust" data-lang="rust"><span>app</span><span style="color:#89ddff;">.</span><span style="color:#82aaff;">add_systems</span><span style="color:#89ddff;">(</span><span>OnEnter</span><span style="color:#89ddff;">(</span><span>GameState</span><span style="color:#89ddff;">::</span><span>FastAction</span><span style="color:#89ddff;">),</span><span> high_fps</span><span style="color:#89ddff;">);
6262
</span><span>app</span><span style="color:#89ddff;">.</span><span style="color:#82aaff;">add_systems</span><span style="color:#89ddff;">(</span><span>OnExit</span><span style="color:#89ddff;">(</span><span>GameState</span><span style="color:#89ddff;">::</span><span>FastAction</span><span style="color:#89ddff;">),</span><span> low_fps</span><span style="color:#89ddff;">);
6363
</span><span>

0 commit comments

Comments
 (0)