diff --git a/Cargo.toml b/Cargo.toml index 06bb807..1ba2a73 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,5 +11,6 @@ default = ["tolk"] tolk = ["tts/tolk"] [dependencies] -bevy = "0.4" +bevy = { git = "https://github.com/bevyengine/bevy" } +crossbeam-channel = "0.5" tts = { version = "0.14" } \ No newline at end of file diff --git a/examples/hello_world.rs b/examples/hello_world.rs index fdef438..c22f1bb 100644 --- a/examples/hello_world.rs +++ b/examples/hello_world.rs @@ -63,11 +63,8 @@ fn setup(mut tts: ResMut) { } // Reports events from TTS subsystem. -fn event_poll( - mut tts_event_reader: Local>, - tts_events: Res>, -) { - for event in tts_event_reader.iter(&tts_events) { +fn event_poll(mut events: EventReader) { + for event in events.iter() { println!("{:?}", event); } } diff --git a/src/lib.rs b/src/lib.rs index ca2b6e2..9a90dda 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,6 +1,5 @@ -use std::sync::mpsc::{channel, Receiver}; - use bevy::prelude::*; +use crossbeam_channel::{unbounded, Receiver}; pub use tts::{Error, Features, UtteranceId, TTS}; #[derive(Clone, Copy, Debug)] @@ -12,10 +11,8 @@ pub enum TtsEvent { struct TtsChannel(Receiver); -fn poll_callbacks(_: &mut World, resources: &mut Resources) { - let channel = resources.get_thread_local::().unwrap(); +fn poll_callbacks(channel: Res, mut events: ResMut>) { if let Ok(msg) = channel.0.try_recv() { - let mut events = resources.get_mut::>().unwrap(); events.send(msg); } } @@ -25,7 +22,7 @@ pub struct TtsPlugin; impl Plugin for TtsPlugin { fn build(&self, app: &mut AppBuilder) { let tts = TTS::default().unwrap(); - let (tx, rx) = channel(); + let (tx, rx) = unbounded(); let tx_begin = tx.clone(); let tx_end = tx.clone(); let tx_stop = tx; @@ -48,8 +45,8 @@ impl Plugin for TtsPlugin { .unwrap(); } app.add_event::() - .add_thread_local_resource(TtsChannel(rx)) - .add_resource(tts) + .insert_resource(TtsChannel(rx)) + .insert_resource(tts) .add_system(poll_callbacks.system()); } }