Skip to content

Commit

Permalink
WASM fix (#57)
Browse files Browse the repository at this point in the history
* Add wasm32 workaround for missing `pipelined_rendering`

The `pipelined_rendering` export is no longer available in Bevy since
version 0.12 in wasm32 builds; it can no longer be used to select the
right subapp.

Add a dummy version of the `AppLabel` that targets the
`pipelined_rendering` subapp. Using a dummy app label allows to keep the
same code to get the right subapp to apply the framepace resources and
systems.

* Cleanup, fix warnings

---------

Co-authored-by: Tim <[email protected]>
  • Loading branch information
aevyrie and justim authored Jun 12, 2024
1 parent 4f7a18c commit 8989c30
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,13 @@
use bevy_app::prelude::*;
use bevy_ecs::prelude::*;
use bevy_reflect::prelude::*;
use bevy_render::{pipelined_rendering::RenderExtractApp, Render, RenderApp, RenderSet};
use bevy_render::{Render, RenderApp, RenderSet};
use bevy_utils::Instant;
use bevy_window::prelude::*;

#[cfg(not(target_arch = "wasm32"))]
use bevy_render::pipelined_rendering::RenderExtractApp;
#[cfg(not(target_arch = "wasm32"))]
use bevy_window::prelude::*;
#[cfg(not(target_arch = "wasm32"))]
use bevy_winit::WinitWindows;

Expand All @@ -45,6 +48,12 @@ use std::{
#[cfg(feature = "framepace_debug")]
pub mod debug;

/// Bevy does not export `RenderExtractApp` on wasm32, so we create a dummy label to ensure this
/// compiles on wasm32.
#[cfg(target_arch = "wasm32")]
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, bevy_app::AppLabel)]
struct RenderExtractApp;

/// Adds framepacing and framelimiting functionality to your [`App`].
#[derive(Debug, Clone, Component)]
pub struct FramepacePlugin;
Expand Down Expand Up @@ -117,6 +126,7 @@ struct FramepaceSettingsProxy {
limiter: Arc<Mutex<Limiter>>,
}

#[cfg(not(target_arch = "wasm32"))]
impl FramepaceSettingsProxy {
fn is_enabled(&self) -> bool {
self.limiter.try_lock().iter().any(|l| l.is_enabled())
Expand Down Expand Up @@ -251,6 +261,7 @@ pub struct FramePaceStats {
/// `spin_sleep` sleeps as long as possible given the platform's sleep accuracy, and spins for the
/// remainder. The dependency is however not WASM compatible, which is fine, because frame limiting
/// should not be used in a browser; this would compete with the browser's frame limiter.
#[allow(unused_variables)]
fn framerate_limiter(
mut timer: ResMut<FrameTimer>,
target_frametime: Res<FrametimeLimit>,
Expand Down

0 comments on commit 8989c30

Please sign in to comment.