Compare commits

...

3 Commits

Author SHA1 Message Date
8cc4c0ee94 Add Drone configuration.
Some checks failed
continuous-integration/drone/push Build is failing
2022-12-06 17:11:09 -06:00
b4d298636d Reflection integration for more types. 2022-12-06 16:59:49 -06:00
3fecb314f6 Upgrade to Bevy 0.9. 2022-12-06 16:43:37 -06:00
4 changed files with 86 additions and 25 deletions

44
.drone.yml Normal file
View File

@ -0,0 +1,44 @@
kind: pipeline
type: docker
name: default
steps:
- name: test
image: rust
pull: always
commands:
- rustup component add clippy rustfmt
- apt-get update -qq
- apt-get install -qqy llvm-dev libclang-dev clang cmake pkg-config libx11-dev libasound2-dev libudev-dev libxcb-xfixes0-dev libwayland-dev libxkbcommon-dev libvulkan-dev libpulse-dev
- cargo fmt --check
- cargo test
- cargo clippy
- name: release
image: rust
pull: always
commands:
- apt-get update -qq
- apt-get install -qqy llvm-dev libclang-dev clang cmake pkg-config libx11-dev libasound2-dev libudev-dev libxcb-xfixes0-dev libwayland-dev libxkbcommon-dev libvulkan-dev libpulse-dev
- cargo publish --no-verify
when:
ref:
- refs/tags/v*
environment:
CARGO_REGISTRY_TOKEN:
from_secret: cargo_registry_token
- name: discord notification
image: appleboy/drone-discord
when:
status: [success, failure]
settings:
webhook_id:
from_secret: discord_webhook_id
webhook_token:
from_secret: discord_webhook_token
tts: true
message: >
{{#success build.status}}
{{repo.name}} build {{build.number}} succeeded: <{{build.link}}>
{{else}}
{{repo.name}} build {{build.number}} failed: <{{build.link}}>
{{/success}}

View File

@ -4,13 +4,14 @@ version = "0.1.0"
authors = ["Nolan Darilek <nolan@thewordnerd.info>"]
license = "MIT OR Apache-2.0"
edition = "2021"
repository = "https://labs.lightsout.games/projects/bevy_synthizer"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
anyhow = "1"
bevy = { version = "0.8", default-features = false, features = ["bevy_asset"] }
bevy = { version = "0.9", default-features = false, features = ["bevy_asset"] }
synthizer = "0.5"
[dev-dependencies]
bevy = { version = "0.8", default-features = true }
bevy = { version = "0.9", default-features = true }

View File

@ -8,11 +8,11 @@ struct RotationTimer(Timer);
impl Default for RotationTimer {
fn default() -> Self {
Self(Timer::from_seconds(30., true))
Self(Timer::from_seconds(30., TimerMode::Repeating))
}
}
#[derive(Default)]
#[derive(Resource, Default)]
struct AssetHandles {
sounds: Vec<HandleUntyped>,
loaded: bool,
@ -34,22 +34,22 @@ fn load_and_create(
.get_group_load_state(handles.sounds.iter().map(|handle| handle.id))
== LoadState::Loaded;
if handles.loaded {
commands
.spawn_bundle(TransformBundle::default())
.insert(Listener)
.insert(RotationTimer::default());
commands.spawn((
TransformBundle::default(),
Listener,
RotationTimer::default(),
));
let handle = handles.sounds[0].clone();
let buffer = asset_server.get_handle(handle);
commands
.spawn_bundle(TransformBundle::from(Transform::from_translation(
Vec3::new(10., 0., 0.),
)))
.insert(Source::default())
.insert(Sound {
commands.spawn((
TransformBundle::from(Transform::from_translation(Vec3::new(10., 0., 0.))),
Source::default(),
Sound {
buffer,
looping: true,
..default()
});
},
));
}
}

View File

@ -10,7 +10,7 @@ use bevy::{
};
pub use synthizer as syz;
#[derive(Clone, Debug, Deref, DerefMut, PartialEq, TypeUuid)]
#[derive(Clone, Debug, Deref, DerefMut, PartialEq, Eq, TypeUuid)]
#[uuid = "6b6b533a-bb1f-11ec-bda2-00155d8fdde9"]
pub struct Buffer(syz::Buffer);
@ -43,6 +43,9 @@ impl AssetLoader for BufferAssetLoader {
}
}
#[derive(Resource, Clone, Debug, Deref, DerefMut)]
pub struct Context(syz::Context);
#[derive(Component, Clone, Debug, Reflect)]
#[reflect(Component)]
pub struct Source {
@ -157,7 +160,7 @@ pub enum SynthizerEvent {
pub struct Listener;
fn update_listener(
context: ResMut<syz::Context>,
context: ResMut<Context>,
listener: Query<Option<&GlobalTransform>, With<Listener>>,
) {
if let Ok(transform) = listener.get_single() {
@ -192,7 +195,7 @@ fn update_listener(
}
fn add_source_handle(
context: Res<syz::Context>,
context: Res<Context>,
mut query: Query<(
&mut Source,
Option<&PannerStrategy>,
@ -241,7 +244,7 @@ fn add_source_handle(
}
fn add_generator(
context: Res<syz::Context>,
context: Res<Context>,
buffers: Res<Assets<Buffer>>,
mut query: Query<(Entity, Option<&Parent>, &mut Sound)>,
mut sources: Query<&mut Source>,
@ -313,7 +316,7 @@ fn add_sound_without_source(
}
}
#[derive(Default, Deref, DerefMut)]
#[derive(Resource, Default, Deref, DerefMut)]
struct LastBuffer(HashMap<Entity, Handle<Buffer>>);
fn swap_buffers(
@ -354,7 +357,7 @@ fn change_panner_strategy(
}
fn update_source_properties(
context: Res<syz::Context>,
context: Res<Context>,
mut query: Query<(
&mut Source,
Option<&DistanceModel>,
@ -561,7 +564,7 @@ fn remove_sound(mut last_buffer: ResMut<LastBuffer>, removed: RemovedComponents<
}
}
#[derive(Clone, Default, Debug)]
#[derive(Resource, Clone, Default, Debug)]
pub struct SynthizerConfig {
pub default_panner_strategy: Option<syz::PannerStrategy>,
pub default_distance_model: Option<syz::DistanceModel>,
@ -574,7 +577,7 @@ pub struct SynthizerConfig {
pub log_to_stderr: bool,
}
#[derive(Debug)]
#[derive(Resource, Debug)]
pub struct SynthizerDefaults {
pub panner_strategy: syz::PannerStrategy,
pub distance_model: syz::DistanceModel,
@ -586,7 +589,7 @@ pub struct SynthizerDefaults {
}
fn sync_config(
context: Res<syz::Context>,
context: Res<Context>,
config: Res<SynthizerConfig>,
defaults: Res<SynthizerDefaults>,
) {
@ -639,7 +642,7 @@ fn sync_config(
}
fn events(
context: Res<syz::Context>,
context: Res<Context>,
sounds: Query<(Entity, &Sound)>,
mut output: EventWriter<SynthizerEvent>,
) {
@ -677,6 +680,9 @@ pub enum SynthizerSystems {
UpdateState,
}
#[derive(Resource)]
struct InitializationGuard(syz::InitializationGuard);
pub struct SynthizerPlugin;
impl Plugin for SynthizerPlugin {
@ -693,6 +699,7 @@ impl Plugin for SynthizerPlugin {
let guard = syz_config
.initialize()
.expect("Failed to initialize Synthizer");
let guard = InitializationGuard(guard);
let context = syz::Context::new().expect("Failed to create Synthizer context");
let defaults = SynthizerDefaults {
panner_strategy: context.default_panner_strategy().get().unwrap(),
@ -704,8 +711,17 @@ impl Plugin for SynthizerPlugin {
closeness_boost_distance: context.default_closeness_boost_distance().get().unwrap(),
};
context.enable_events().expect("Failed to enable events");
let context = Context(context);
app.add_asset::<Buffer>()
.init_asset_loader::<BufferAssetLoader>()
.register_type::<Source>()
.register_type::<DistanceRef>()
.register_type::<DistanceMax>()
.register_type::<Rolloff>()
.register_type::<ClosenessBoostDistance>()
.register_type::<AngularPan>()
.register_type::<ScalarPan>()
.register_type::<Sound>()
.register_type::<Listener>()
.insert_resource(guard)
.insert_resource(context)