make every bevy dependency optional in bevy crate

This commit is contained in:
Carter Anderson 2020-04-06 17:03:21 -07:00
parent b5d78477cf
commit 0af36cfaed
6 changed files with 115 additions and 87 deletions

View File

@ -5,24 +5,37 @@ authors = ["Carter Anderson <mcanders1@gmail.com>"]
edition = "2018"
[features]
default = ["bevy_wgpu", "bevy_winit"]
default = ["headless", "wgpu", "winit"]
headless = ["asset", "core", "derive", "diagnostic", "input", "render", "serialization", "transform", "ui", "window"]
asset = ["bevy_asset"]
core = ["bevy_core"]
derive = ["bevy_derive"]
diagnostic = ["bevy_diagnostic"]
input = ["bevy_input"]
render = ["bevy_render"]
serialization = ["bevy_serialization"]
transform = ["bevy_transform"]
ui = ["bevy_ui"]
window = ["bevy_window"]
wgpu = ["bevy_wgpu"]
winit = ["bevy_winit"]
[dependencies]
# bevy
bevy_app = { path = "bevy_app" }
bevy_asset = { path = "bevy_asset" }
bevy_core = { path = "bevy_core" }
bevy_derive = { path = "bevy_derive" }
bevy_diagnostic = { path = "bevy_diagnostic" }
bevy_input = { path = "bevy_input" }
bevy_render = { path = "bevy_render" }
bevy_serialization = { path = "bevy_serialization" }
bevy_transform = { path = "bevy_transform" }
bevy_ui = { path = "bevy_ui" }
bevy_window = { path = "bevy_window" }
bevy_asset = { path = "bevy_asset", optional = true }
bevy_core = { path = "bevy_core", optional = true }
bevy_derive = { path = "bevy_derive", optional = true }
bevy_diagnostic = { path = "bevy_diagnostic", optional = true }
bevy_input = { path = "bevy_input", optional = true }
bevy_render = { path = "bevy_render", optional = true }
bevy_serialization = { path = "bevy_serialization", optional = true }
bevy_transform = { path = "bevy_transform", optional = true }
bevy_ui = { path = "bevy_ui", optional = true }
bevy_window = { path = "bevy_window", optional = true }
bevy_wgpu = { path = "bevy_wgpu", optional = true }
bevy_winit = { path = "bevy_winit", optional = true }
legion = { path = "bevy_legion", features = ["serialize"] }
legion = { path = "bevy_legion" }
# other
log = { version = "0.4", features = ["release_max_level_info"] }

View File

@ -12,16 +12,17 @@ pub fn ui_update_system() -> Box<dyn Schedulable> {
.write_component::<Node>()
.read_component::<Children>()
.build(move |_, world, windows, node_query| {
let window = windows.get_primary().unwrap();
let parent_size = glam::vec2(window.width as f32, window.height as f32);
let parent_position = glam::vec2(0.0, 0.0);
for (entity, _) in node_query.iter_entities_mut(world) {
run_on_hierarchy_subworld_mut(
world,
entity,
(parent_size, parent_position),
&mut update_node_entity,
);
if let Some(window) = windows.get_primary() {
let parent_size = glam::vec2(window.width as f32, window.height as f32);
let parent_position = glam::vec2(0.0, 0.0);
for (entity, _) in node_query.iter_entities_mut(world) {
run_on_hierarchy_subworld_mut(
world,
entity,
(parent_size, parent_position),
&mut update_node_entity,
);
}
}
})
}

View File

@ -4,6 +4,13 @@ use bevy::{
};
use std::time::Duration;
// This example disables the default plugins by not registering them during setup.
// You can also completely remove rendering / windowing Plugin code from bevy
// by making your import look like this in your Cargo.toml
//
// [dependencies]
// bevy = { version = "0.1.0", default-features = false, features = ["headless"] }
fn main() {
println!("This app runs once:");
App::build()

View File

@ -27,23 +27,13 @@ fn setup(world: &mut World, resources: &mut Resources) {
.add_entity(MeshEntity {
mesh: plane_handle,
material: plane_material_handle,
// renderable: Renderable::instanced(),
..Default::default()
})
// cube
.add_entity(MeshEntity {
mesh: cube_handle,
material: cube_material_handle,
// renderable: Renderable::instanced(),
translation: Translation::new(-1.5, 0.0, 1.0),
..Default::default()
})
// cube
.add_entity(MeshEntity {
mesh: cube_handle,
material: cube_material_handle,
// renderable: Renderable::instanced(),
translation: Translation::new(1.5, 0.0, 1.0),
translation: Translation::new(0.0, 0.0, 1.0),
..Default::default()
})
// light

View File

@ -2,19 +2,30 @@
pub mod prelude;
pub use bevy_app as app;
pub use bevy_asset as asset;
pub use bevy_core as core;
pub use bevy_diagnostic as diagnostic;
pub use bevy_input as input;
pub use bevy_render as render;
pub use bevy_serialization as serialization;
pub use bevy_transform as transform;
pub use bevy_ui as ui;
pub use bevy_window as window;
pub use glam as math;
pub use legion;
#[cfg(feature = "asset")]
pub use bevy_asset as asset;
#[cfg(feature = "core")]
pub use bevy_core as core;
#[cfg(feature = "derive")]
pub use bevy_derive as derive;
#[cfg(feature = "diagnostic")]
pub use bevy_diagnostic as diagnostic;
#[cfg(feature = "input")]
pub use bevy_input as input;
#[cfg(feature = "render")]
pub use bevy_render as render;
#[cfg(feature = "serialization")]
pub use bevy_serialization as serialization;
#[cfg(feature = "transform")]
pub use bevy_transform as transform;
#[cfg(feature = "ui")]
pub use bevy_ui as ui;
#[cfg(feature = "window")]
pub use bevy_window as window;
use app::AppBuilder;
pub trait AddDefaultPlugins {
@ -23,25 +34,28 @@ pub trait AddDefaultPlugins {
impl AddDefaultPlugins for AppBuilder {
fn add_default_plugins(&mut self) -> &mut Self {
self.add_plugin(bevy_core::CorePlugin::default())
.add_plugin(bevy_input::InputPlugin::default())
.add_plugin(bevy_window::WindowPlugin::default())
.add_plugin(bevy_render::RenderPlugin::default())
.add_plugin(ui::UiPlugin::default());
#[cfg(feature = "core")]
self.add_plugin(bevy_core::CorePlugin::default());
#[cfg(feature = "bevy_winit")]
{
self.add_plugin(bevy_winit::WinitPlugin::default());
}
#[cfg(not(feature = "bevy_winit"))]
{
self.add_plugin(bevy_app::schedule_run::ScheduleRunner::default());
}
#[cfg(feature = "input")]
self.add_plugin(bevy_input::InputPlugin::default());
#[cfg(feature = "bevy_wgpu")]
{
self.add_plugin(bevy_wgpu::WgpuRendererPlugin::default());
}
#[cfg(feature = "window")]
self.add_plugin(bevy_window::WindowPlugin::default());
#[cfg(feature = "render")]
self.add_plugin(bevy_render::RenderPlugin::default());
#[cfg(feature = "ui")]
self.add_plugin(ui::UiPlugin::default());
#[cfg(feature = "winit")]
self.add_plugin(bevy_winit::WinitPlugin::default());
#[cfg(not(feature = "winit"))]
self.add_plugin(bevy_app::schedule_runner::ScheduleRunnerPlugin::default());
#[cfg(feature = "wgpu")]
self.add_plugin(bevy_wgpu::WgpuRendererPlugin::default());
self
}

View File

@ -1,30 +1,18 @@
pub use crate::{
app::{App, AppBuilder, AppPlugin, EntityArchetype, EventReader, Events, GetEventReader},
asset::{Asset, AssetStorage, Handle},
core::{
time::Time,
transform::{CommandBufferBuilderSource, WorldBuilder, WorldBuilderSource},
},
diagnostic::DiagnosticsPlugin,
render::{
entity::*,
mesh::{Mesh, MeshType},
pipeline::PipelineDescriptor,
render_graph::RenderGraph,
render_resource::{
resource_name, resource_providers::UniformResourceProvider, AssetBatchers,
},
shader::{uniforms::StandardMaterial, Shader, ShaderDefSuffixProvider, ShaderStage},
texture::{Texture, TextureType},
ActiveCamera, ActiveCamera2d, Camera, CameraType, Color, ColorSource, Light, Renderable,
},
ui::{entity::*, Anchors, Margins, Node},
window::{Window, WindowDescriptor, WindowPlugin, Windows},
AddDefaultPlugins,
pub use crate::AddDefaultPlugins;
pub use crate::app::{App, AppBuilder, AppPlugin, EntityArchetype, EventReader, Events, GetEventReader};
#[cfg(feature = "asset")]
pub use crate::asset::{Asset, AssetStorage, Handle};
#[cfg(feature = "derive")]
pub use crate::derive::*;
#[cfg(feature = "transform")]
pub use crate::transform::prelude::*;
#[cfg(feature = "core")]
pub use crate::core::{
time::Time,
transform::{CommandBufferBuilderSource, WorldBuilder, WorldBuilderSource},
};
pub use bevy_derive::*;
pub use bevy_transform::prelude::*;
pub use glam as math;
#[cfg(feature = "diagnostic")]
pub use crate::diagnostic::DiagnosticsPlugin;
pub use legion::{
command::CommandBuffer,
entity::Entity,
@ -39,4 +27,19 @@ pub use legion::{
},
world::{Universe, World},
};
pub use math::{Mat3, Mat4, Quat, Vec2, Vec3, Vec4};
pub use crate::math::{self, Mat3, Mat4, Quat, Vec2, Vec3, Vec4};
#[cfg(feature = "render")]
pub use crate::render::{
entity::*,
mesh::{Mesh, MeshType},
pipeline::PipelineDescriptor,
render_graph::RenderGraph,
render_resource::{resource_name, resource_providers::UniformResourceProvider, AssetBatchers},
shader::{uniforms::StandardMaterial, Shader, ShaderDefSuffixProvider, ShaderStage},
texture::{Texture, TextureType},
ActiveCamera, ActiveCamera2d, Camera, CameraType, Color, ColorSource, Light, Renderable,
};
#[cfg(feature = "ui")]
pub use crate::ui::{entity::*, Anchors, Margins, Node};
#[cfg(feature = "window")]
pub use crate::window::{Window, WindowDescriptor, WindowPlugin, Windows};