Skip to content

Commit

Permalink
Remove crossbeam-channel dependency (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
rparrett authored Nov 30, 2024
1 parent 7079f76 commit dc85237
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 28 deletions.
3 changes: 0 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ version = "0.15"
default-features = false
features = ["bevy_render"]

[dependencies]
crossbeam-channel = "0.5.0"

[dev-dependencies.bevy]
version = "0.15"
default-features = false
Expand Down
40 changes: 15 additions & 25 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use bevy::{
prelude::*,
render::{
render_resource::{CachedPipelineState, PipelineCache},
Render, RenderApp,
MainWorld, RenderApp,
},
};

Expand All @@ -20,34 +20,24 @@ impl PipelinesReady {

impl Plugin for PipelinesReadyPlugin {
fn build(&self, app: &mut App) {
let (tx, rx) = crossbeam_channel::bounded(1);

app.init_resource::<PipelinesReady>();

app.add_systems(Update, move |mut ready: ResMut<PipelinesReady>| {
let Ok(num) = rx.try_recv() else {
return;
};

ready.0 = num;
});

let renderer_app = app.sub_app_mut(RenderApp);

let mut current = 0;
renderer_app.add_systems(Render, move |cache: Res<PipelineCache>| {
let count = cache
.pipelines()
.filter(|pipeline| matches!(pipeline.state, CachedPipelineState::Ok(_)))
.count();
app.sub_app_mut(RenderApp)
.add_systems(ExtractSchedule, update_pipelines_ready);
}
}

if current == count {
return;
}
fn update_pipelines_ready(mut main_world: ResMut<MainWorld>, cache: Res<PipelineCache>) {
if let Some(mut pipelines_ready) = main_world.get_resource_mut::<PipelinesReady>() {
let count = cache
.pipelines()
.filter(|pipeline| matches!(pipeline.state, CachedPipelineState::Ok(_)))
.count();

let _ = tx.send(count);
if pipelines_ready.0 == count {
return;
}

current = count;
});
pipelines_ready.0 = count;
}
}

0 comments on commit dc85237

Please sign in to comment.