Skip to content

Commit a6c55b6

Browse files
authored
Web Optimizations and Fixes (#108)
Issue: ============== N/A What was done: ============== * Added a web profile for optimized release builds. * Switches Web API to WebGL2 for better compatibility. * Fixed a potential issue that could freeze the game while loading assets. * Removed RenderPlugin backend setup in Web builds.
1 parent 77c2726 commit a6c55b6

File tree

7 files changed

+48
-9
lines changed

7 files changed

+48
-9
lines changed

.cargo/config.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
1+
[profile.web]
2+
inherits = "release"
3+
opt-level = "s"
4+
lto = "thin"
5+
16
[target.wasm32-unknown-unknown]
27
runner = "wasm-server-runner"

Cargo.lock

Lines changed: 27 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ bevy = { version = "0.12.0", default-features = false, features = [
2222
"multi-threaded",
2323
"png",
2424
"vorbis",
25+
"webgl2",
2526
"x11",
2627
] }
2728
bevy_rapier2d = { version = "0.23.0", features = ["debug-render-2d"] }

src/audio.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ impl Plugin for AudioPlugin {
3333
update_sound_effect_assets_load_state,
3434
)
3535
.chain()
36-
.run_if(resource_equals(AudioLoadStates::default())),
36+
.run_if(not(resource_equals(AudioLoadStates::LOADED))),
3737
);
3838
}
3939
}

src/fonts.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ impl Plugin for FontsPlugin {
1414
app.add_systems(Startup, load_fonts);
1515
app.add_systems(
1616
Update,
17-
update_font_assets_load_state.run_if(resource_equals(FontsLoadState::default())),
17+
update_font_assets_load_state.run_if(not(resource_equals(FontsLoadState::Loaded))),
1818
);
1919
}
2020
}

src/main.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,17 @@ fn main() {
4141
DefaultPlugins
4242
// FIXME: Remove setting the backend explicitly to avoid noisy warnings
4343
// when https://github.com/gfx-rs/wgpu/issues/3959 gets fixed.
44-
.set(RenderPlugin {
45-
render_creation: RenderCreation::Automatic(WgpuSettings {
46-
backends: Some(Backends::DX12),
47-
..default()
48-
}),
49-
})
44+
.set(
45+
#[cfg(not(target_family = "wasm"))]
46+
RenderPlugin {
47+
render_creation: RenderCreation::Automatic(WgpuSettings {
48+
backends: Some(Backends::DX12),
49+
..default()
50+
}),
51+
},
52+
#[cfg(target_family = "wasm")]
53+
RenderPlugin::default(),
54+
)
5055
.set(ImagePlugin::default_nearest())
5156
.set(AssetPlugin {
5257
mode: AssetMode::Unprocessed,

src/textures.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ impl Plugin for TexturesPlugin {
1414
app.add_systems(Startup, load_textures);
1515
app.add_systems(
1616
Update,
17-
update_texture_assets_load_state.run_if(resource_equals(TexturesLoadState::default())),
17+
update_texture_assets_load_state
18+
.run_if(not(resource_equals(TexturesLoadState::Loaded))),
1819
);
1920
}
2021
}

0 commit comments

Comments
 (0)