Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WASM fix #57

Merged
merged 3 commits into from
Jun 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading