Skip to content

Commit

Permalink
Web Optimizations and Fixes (#108)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mnmaita authored Dec 8, 2023
1 parent 77c2726 commit a6c55b6
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
[profile.web]
inherits = "release"
opt-level = "s"
lto = "thin"

[target.wasm32-unknown-unknown]
runner = "wasm-server-runner"
27 changes: 27 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ bevy = { version = "0.12.0", default-features = false, features = [
"multi-threaded",
"png",
"vorbis",
"webgl2",
"x11",
] }
bevy_rapier2d = { version = "0.23.0", features = ["debug-render-2d"] }
Expand Down
2 changes: 1 addition & 1 deletion src/audio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl Plugin for AudioPlugin {
update_sound_effect_assets_load_state,
)
.chain()
.run_if(resource_equals(AudioLoadStates::default())),
.run_if(not(resource_equals(AudioLoadStates::LOADED))),
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/fonts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ impl Plugin for FontsPlugin {
app.add_systems(Startup, load_fonts);
app.add_systems(
Update,
update_font_assets_load_state.run_if(resource_equals(FontsLoadState::default())),
update_font_assets_load_state.run_if(not(resource_equals(FontsLoadState::Loaded))),
);
}
}
Expand Down
17 changes: 11 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,17 @@ fn main() {
DefaultPlugins
// FIXME: Remove setting the backend explicitly to avoid noisy warnings
// when https://github.com/gfx-rs/wgpu/issues/3959 gets fixed.
.set(RenderPlugin {
render_creation: RenderCreation::Automatic(WgpuSettings {
backends: Some(Backends::DX12),
..default()
}),
})
.set(
#[cfg(not(target_family = "wasm"))]
RenderPlugin {
render_creation: RenderCreation::Automatic(WgpuSettings {
backends: Some(Backends::DX12),
..default()
}),
},
#[cfg(target_family = "wasm")]
RenderPlugin::default(),
)
.set(ImagePlugin::default_nearest())
.set(AssetPlugin {
mode: AssetMode::Unprocessed,
Expand Down
3 changes: 2 additions & 1 deletion src/textures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ impl Plugin for TexturesPlugin {
app.add_systems(Startup, load_textures);
app.add_systems(
Update,
update_texture_assets_load_state.run_if(resource_equals(TexturesLoadState::default())),
update_texture_assets_load_state
.run_if(not(resource_equals(TexturesLoadState::Loaded))),
);
}
}
Expand Down

0 comments on commit a6c55b6

Please sign in to comment.