Store and update PannerStrategy directly in config.

This commit is contained in:
Nolan Darilek 2022-05-18 19:56:41 -05:00
parent 6b4daf5764
commit 58e2c9b860
2 changed files with 17 additions and 14 deletions

View File

@ -63,7 +63,9 @@ fn rotate_listener(time: Res<Time>, mut query: Query<(&mut RotationTimer, &mut T
fn main() { fn main() {
App::new() App::new()
.add_plugins(DefaultPlugins) .add_plugins(DefaultPlugins)
.insert_resource(SynthizerConfig { hrtf: true }) .insert_resource(SynthizerConfig {
default_panner_strategy: bevy_synthizer::syz::PannerStrategy::Hrtf,
})
.add_plugin(SynthizerPlugin) .add_plugin(SynthizerPlugin)
.add_system(bevy::input::system::exit_on_esc_system) .add_system(bevy::input::system::exit_on_esc_system)
.init_resource::<AssetHandles>() .init_resource::<AssetHandles>()

View File

@ -329,9 +329,17 @@ fn remove_sound(mut last_buffer: ResMut<LastBuffer>, removed: RemovedComponents<
} }
} }
#[derive(Clone, Copy, Debug, Default)] #[derive(Clone, Copy, Debug)]
pub struct SynthizerConfig { pub struct SynthizerConfig {
pub hrtf: bool, pub default_panner_strategy: syz::PannerStrategy,
}
impl Default for SynthizerConfig {
fn default() -> Self {
Self {
default_panner_strategy: syz::PannerStrategy::Stereo,
}
}
} }
pub struct SynthizerPlugin; pub struct SynthizerPlugin;
@ -344,17 +352,10 @@ impl Plugin for SynthizerPlugin {
app.insert_resource(SynthizerConfig::default()); app.insert_resource(SynthizerConfig::default());
} }
let config = *app.world.get_resource::<SynthizerConfig>().unwrap(); let config = *app.world.get_resource::<SynthizerConfig>().unwrap();
if config.hrtf {
context context
.default_panner_strategy() .default_panner_strategy()
.set(syz::PannerStrategy::Hrtf) .set(config.default_panner_strategy)
.expect("Failed to set panner strategy"); .expect("Failed to set panner strategy");
} else {
context
.default_panner_strategy()
.set(syz::PannerStrategy::Stereo)
.expect("Failed to set panner strategy");
}
app.add_asset::<Buffer>() app.add_asset::<Buffer>()
.init_asset_loader::<BufferAssetLoader>() .init_asset_loader::<BufferAssetLoader>()
.register_type::<Listener>() .register_type::<Listener>()