Merge pull request #108 from caelunshun/feature-gated-deps

Make audio/image dependencies optional through feature flags
This commit is contained in:
Carter Anderson 2020-08-11 15:31:39 -07:00 committed by GitHub
commit 00a887214e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 43 additions and 8 deletions

View file

@ -13,9 +13,19 @@ readme = "README.md"
exclude = ["assets/**/*", "tools/**/*", ".github/**/*", "crates/**/*"] exclude = ["assets/**/*", "tools/**/*", ".github/**/*", "crates/**/*"]
[features] [features]
default = ["bevy_audio", "bevy_gltf", "bevy_wgpu", "bevy_winit"] default = ["bevy_audio", "bevy_gltf", "bevy_wgpu", "bevy_winit", "png", "hdr", "mp3"]
profiler = ["bevy_ecs/profiler", "bevy_diagnostic/profiler"] profiler = ["bevy_ecs/profiler", "bevy_diagnostic/profiler"]
# Image format support for texture loading (PNG and HDR are enabled by default)
png = ["bevy_render/png"]
hdr = ["bevy_render/hdr"]
# Audio format support (MP3 is enabled by default)
mp3 = ["bevy_audio/mp3"]
flac = ["bevy_audio/flac"]
wav = ["bevy_audio/wav"]
vorbis = ["bevy_audio/vorbis"]
[workspace] [workspace]
members = [ members = [
"crates/*", "crates/*",

View file

@ -17,4 +17,10 @@ bevy_ecs = {path = "../bevy_ecs", version = "0.1"}
# other # other
anyhow = "1.0" anyhow = "1.0"
rodio = {version = "0.11", default-features = false, features = ["mp3"]} rodio = {version = "0.11", default-features = false}
[features]
mp3 = ["rodio/mp3"]
flac = ["rodio/flac"]
wav = ["rodio/wav"]
vorbis = ["rodio/vorbis"]

View file

@ -26,7 +26,7 @@ impl AssetLoader<AudioSource> for Mp3Loader {
} }
fn extensions(&self) -> &[&str] { fn extensions(&self) -> &[&str] {
static EXTENSIONS: &[&str] = &["mp3"]; static EXTENSIONS: &[&str] = &["mp3", "flac", "wav", "ogg"];
EXTENSIONS EXTENSIONS
} }
} }

View file

@ -25,7 +25,7 @@ bevy_window = { path = "../bevy_window", version = "0.1" }
# rendering # rendering
spirv-reflect = "0.2.3" spirv-reflect = "0.2.3"
bevy-glsl-to-spirv = "0.1.7" bevy-glsl-to-spirv = "0.1.7"
image = { version = "0.23", default-features = false, features = ["png", "hdr"] } image = { version = "0.23", default-features = false }
# misc # misc
log = { version = "0.4", features = ["release_max_level_info"] } log = { version = "0.4", features = ["release_max_level_info"] }
@ -38,3 +38,7 @@ once_cell = "1.4.0"
downcast-rs = "1.1.1" downcast-rs = "1.1.1"
thiserror = "1.0" thiserror = "1.0"
anyhow = "1.0" anyhow = "1.0"
[features]
png = ["image/png"]
hdr = ["image/hdr"]

View file

@ -45,7 +45,11 @@ use render_graph::{
}; };
use renderer::{AssetRenderResourceBindings, RenderResourceBindings}; use renderer::{AssetRenderResourceBindings, RenderResourceBindings};
use std::ops::Range; use std::ops::Range;
use texture::{HdrTextureLoader, ImageTextureLoader, TextureResourceSystemState}; #[cfg(feature = "hdr")]
use texture::HdrTextureLoader;
#[cfg(feature = "png")]
use texture::ImageTextureLoader;
use texture::TextureResourceSystemState;
/// The names of "render" App stages /// The names of "render" App stages
pub mod stage { pub mod stage {
@ -75,6 +79,15 @@ impl Default for RenderPlugin {
impl Plugin for RenderPlugin { impl Plugin for RenderPlugin {
fn build(&self, app: &mut AppBuilder) { fn build(&self, app: &mut AppBuilder) {
#[cfg(feature = "png")]
{
app.add_asset_loader::<Texture, ImageTextureLoader>();
}
#[cfg(feature = "hdr")]
{
app.add_asset_loader::<Texture, HdrTextureLoader>();
}
app.add_stage_after(bevy_asset::stage::ASSET_EVENTS, stage::RENDER_RESOURCE) app.add_stage_after(bevy_asset::stage::ASSET_EVENTS, stage::RENDER_RESOURCE)
.add_stage_after(stage::RENDER_RESOURCE, stage::RENDER_GRAPH_SYSTEMS) .add_stage_after(stage::RENDER_RESOURCE, stage::RENDER_GRAPH_SYSTEMS)
.add_stage_after(stage::RENDER_GRAPH_SYSTEMS, stage::DRAW) .add_stage_after(stage::RENDER_GRAPH_SYSTEMS, stage::DRAW)
@ -84,8 +97,6 @@ impl Plugin for RenderPlugin {
.add_asset::<Texture>() .add_asset::<Texture>()
.add_asset::<Shader>() .add_asset::<Shader>()
.add_asset::<PipelineDescriptor>() .add_asset::<PipelineDescriptor>()
.add_asset_loader::<Texture, HdrTextureLoader>()
.add_asset_loader::<Texture, ImageTextureLoader>()
.register_component::<Camera>() .register_component::<Camera>()
.register_component::<Draw>() .register_component::<Draw>()
.register_component::<RenderPipelines>() .register_component::<RenderPipelines>()

View file

@ -1,11 +1,15 @@
#[cfg(feature = "hdr")]
mod hdr_texture_loader; mod hdr_texture_loader;
#[cfg(feature = "png")]
mod image_texture_loader; mod image_texture_loader;
mod sampler_descriptor; mod sampler_descriptor;
mod texture; mod texture;
mod texture_descriptor; mod texture_descriptor;
mod texture_dimension; mod texture_dimension;
#[cfg(feature = "hdr")]
pub use hdr_texture_loader::*; pub use hdr_texture_loader::*;
#[cfg(feature = "png")]
pub use image_texture_loader::*; pub use image_texture_loader::*;
pub use sampler_descriptor::*; pub use sampler_descriptor::*;
pub use texture::*; pub use texture::*;