Skip to content

no_std compatibility #703

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

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open

no_std compatibility #703

wants to merge 14 commits into from

Conversation

Jondolf
Copy link
Owner

@Jondolf Jondolf commented Apr 17, 2025

Objective

Add no_std compatibility.

Solution

TODO


Migration Guide

TODO

@Jondolf Jondolf added C-Breaking-Change This change removes or changes behavior or APIs, requiring users to adapt C-Dependencies A change to the crates that Avian depends on labels Apr 17, 2025
@Jondolf Jondolf added this to the 0.3 milestone Apr 17, 2025
@tapmondev
Copy link

tapmondev commented Apr 17, 2025

I'm not sure if this is the right place to document this, but I'm trying to run this pr in a pretty confined WASM env , where there is no time/rng access. I'm running into the following error:

2025-04-17T20:57:46.512Z panicC:\Users\tapmondev\.cargo\registry\src\index.crates.io-1949cf8c6b5b557f\bevy_ecs-0.16.0-rc.5\src\error\handler.rs:141: Encountered an error in system `bevy_transform_interpolation::hermite::ease_rotation_hermite<avian2d::interpolation::AngVelSource>`: Parameter `Res<Time<Fixed>>` failed validation: Resource does not exist

I'm running with bevy 0.16 rc5 and these plugins:

  let mut app = App::new();
    app.add_plugins(
        (
            // Use MinimalPlugins and disable features not needed for server-side logic.
            MinimalPlugins
            .build()
            .disable::<ScheduleRunnerPlugin>() // No need for Bevy to run its own schedule loop
            .disable::<TimePlugin>(), // SpacetimeDB handles time/ticks
            PhysicsPlugins::default(),
        )
    );

I manually call the bevy update by running app.update()

From what my gut tells me I can't use the default Physics Plugins, as there is the PhysicsSchedulePlugin ? I'm pretty to new bevy and rust in general. So not sure if I'm missing something obvious here. I'd love some pointers how to call updates to the physics system/world.

EDIT:

I got it running, I was able to use the time plugin by calling:

  unsafe {
        bevy_platform::time::Instant::set_elapsed(get_tick_based_elapsed_time);
    }
    
// --- Tick-Based Elapsed Time Tracking ---
const TICK_INTERVAL_NANOS: u64 = 16_000_000; // 16ms in nanoseconds
static ELAPSED_NANOS: AtomicU64 = AtomicU64::new(0);

// Function to provide elapsed time based on ticks
fn get_tick_based_elapsed_time() -> Duration {
    let nanos = ELAPSED_NANOS.load(Ordering::Relaxed);
    Duration::from_nanos(nanos)
}

However one quirk I noticed is that I manually need to init some resources, not sure this is due to no_std support.

app.init_resource::<avian2d::collision::CollisionDiagnostics>();
    app.init_resource::<SolverDiagnostics>();
    app.init_resource::<SpatialQueryDiagnostics>();
    

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-Breaking-Change This change removes or changes behavior or APIs, requiring users to adapt C-Dependencies A change to the crates that Avian depends on
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants