Skip to content

Commit

Permalink
Merge #225
Browse files Browse the repository at this point in the history
225: Make audio support optional r=kvark a=linkmauve

This reduces the amount of dependencies of 16 if audio support isn’t required by the game.

Co-authored-by: Emmanuel Gil Peyrot <[email protected]>
  • Loading branch information
bors[bot] and linkmauve committed Apr 23, 2019
2 parents 2cf5333 + 0400522 commit 02a6fc8
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ notifications:
on_start: never

script:
- cargo test
- cargo test --no-default-features --features opengl
- cargo test --all-features
- cargo doc
# - if [ "$TRAVIS_RUST_VERSION" == "nightly" ]; then (cargo bench); fi
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ exclude = ["doc/*", "bors.toml", ".travis.yml", "test_data/*"]
[lib]

[features]
default = ["opengl"]
default = ["opengl", "audio"]
opengl = ["gfx_device_gl", "gfx_window_glutin", "glutin"]
audio = ["rodio"]

[build-dependencies]
includedir_codegen = "0.5"
Expand All @@ -38,7 +39,7 @@ log = "0.4"
obj = { version = "0.9", features = ["genmesh"] }
phf = "0.7.12"
quick-error = "1.2"
rodio = "0.8"
rodio = { version = "0.8", optional = true }
mint = "0.5"
vec_map = "0.8"

Expand Down
8 changes: 5 additions & 3 deletions src/factory/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ use itertools::Either;
use mint;
use obj;

use animation;
#[cfg(feature = "audio")]
use audio;

use animation;
use camera::{Camera, Projection, ZRange};
use color::{BLACK, Color};
use geometry::Geometry;
Expand Down Expand Up @@ -913,7 +915,6 @@ impl Factory {
depth_state: gfx::state::Depth,
stencil_state: gfx::state::Stencil,
) -> Result<BasicPipelineState, PipelineCreationError> {
use gfx::traits::FactoryExt;
let vs = Source::user(&dir, name, "vs")?;
let ps = Source::user(&dir, name, "ps")?;
let shaders = self.backend
Expand All @@ -939,6 +940,7 @@ impl Factory {
Text::with_object(object)
}

#[cfg(feature = "audio")]
/// Create new audio source.
pub fn audio_source(&mut self) -> audio::Source {
let sub = SubNode::Audio(audio::AudioData::new());
Expand Down Expand Up @@ -991,7 +993,6 @@ impl Factory {
&mut self,
file_path: P,
) -> Font {
use self::io::Read;
let file_path = file_path.as_ref();
let mut buffer = Vec::new();
let file = fs::File::open(&file_path).expect(&format!(
Expand Down Expand Up @@ -1317,6 +1318,7 @@ impl Factory {
(groups, meshes)
}

#[cfg(feature = "audio")]
/// Load audio from file. Supported formats are Flac, Vorbis and WAV.
pub fn load_audio<P: AsRef<Path>>(
&self,
Expand Down
6 changes: 6 additions & 0 deletions src/hub.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#[cfg(feature = "audio")]
use audio::{AudioData, Operation as AudioOperation};

use camera::Projection;
use color::{self, Color};
use light::{LightOperation, ShadowMap, ShadowProjection};
Expand Down Expand Up @@ -56,6 +58,7 @@ pub(crate) enum SubNode {
Camera(Projection),
/// Group can be a parent to other objects.
Group { first_child: Option<NodePointer> },
#[cfg(feature = "audio")]
/// Audio data.
Audio(AudioData),
/// Renderable text for 2D user interface.
Expand All @@ -76,6 +79,7 @@ pub(crate) type Message = (froggy::WeakPointer<NodeInternal>, Operation);
pub(crate) enum Operation {
AddChild(NodePointer),
RemoveChild(NodePointer),
#[cfg(feature = "audio")]
SetAudio(AudioOperation),
SetVisible(bool),
SetLight(LightOperation),
Expand Down Expand Up @@ -176,6 +180,7 @@ impl Hub {
Err(_) => continue,
};
match operation {
#[cfg(feature = "audio")]
Operation::SetAudio(operation) => {
if let SubNode::Audio(ref mut data) = self.nodes[&ptr].sub_node {
Hub::process_audio(operation, data);
Expand Down Expand Up @@ -335,6 +340,7 @@ impl Hub {
self.nodes.sync_pending();
}

#[cfg(feature = "audio")]
fn process_audio(
operation: AudioOperation,
data: &mut AudioData,
Expand Down
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ extern crate obj;
extern crate phf;
#[macro_use]
extern crate quick_error;
#[cfg(feature = "audio")]
extern crate rodio;
extern crate vec_map;

Expand All @@ -279,7 +280,9 @@ extern crate glutin;
#[macro_use]
mod macros;

#[cfg(feature = "audio")]
pub mod audio;

pub mod animation;
pub mod camera;
pub mod color;
Expand Down
4 changes: 4 additions & 0 deletions src/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ use std::sync::mpsc;

use mint;

#[cfg(feature = "audio")]
use audio;

use camera::Camera;
use hub::{Hub, Message, Operation, SubLight, SubNode};
use light;
Expand Down Expand Up @@ -219,6 +221,7 @@ impl Object for Base {
object: self.clone(),
}),

#[cfg(feature = "audio")]
SubNode::Audio(..) => ObjectType::AudioSource(audio::Source {
object: self.clone(),
}),
Expand Down Expand Up @@ -270,6 +273,7 @@ impl Object for Base {
/// [`SyncGuard::resolve_data`]: ../scene/struct.SyncGuard.html#method.resolve_data
#[derive(Debug, Clone)]
pub enum ObjectType {
#[cfg(feature = "audio")]
/// An audio source.
AudioSource(audio::Source),

Expand Down

0 comments on commit 02a6fc8

Please sign in to comment.