cargo fmt

This commit is contained in:
Carter Anderson 2020-05-16 00:27:30 -07:00
parent fcc0a6303b
commit b1f07e3749
19 changed files with 58 additions and 50 deletions

View File

@ -1,4 +1,7 @@
use crate::{Assets, Handle, HandleId, LoadRequest, AssetLoadError, AssetLoadRequestHandler, AssetLoader, AssetPath}; use crate::{
AssetLoadError, AssetLoadRequestHandler, AssetLoader, AssetPath, Assets, Handle, HandleId,
LoadRequest,
};
use anyhow::Result; use anyhow::Result;
use legion::prelude::Resources; use legion::prelude::Resources;
use std::{ use std::{

View File

@ -122,10 +122,7 @@ impl AddAsset for AppBuilder {
T: Send + Sync + 'static, T: Send + Sync + 'static,
{ {
self.init_resource::<Assets<T>>() self.init_resource::<Assets<T>>()
.add_system_to_stage( .add_system_to_stage(stage::POST_UPDATE, Assets::<T>::asset_event_system.system())
stage::POST_UPDATE,
Assets::<T>::asset_event_system.system(),
)
.add_event::<AssetEvent<T>>() .add_event::<AssetEvent<T>>()
} }

View File

@ -97,7 +97,6 @@ where
} }
} }
impl<T> Hash for Handle<T> { impl<T> Hash for Handle<T> {
fn hash<H: Hasher>(&self, state: &mut H) { fn hash<H: Hasher>(&self, state: &mut H) {
self.id.hash(state); self.id.hash(state);

View File

@ -1,16 +1,16 @@
mod asset_path;
mod asset_server;
mod assets; mod assets;
mod handle; mod handle;
mod loader;
mod asset_server;
mod load_request; mod load_request;
mod asset_path; mod loader;
pub use asset_path::*;
pub use asset_server::*;
pub use assets::*; pub use assets::*;
pub use handle::*; pub use handle::*;
pub use loader::*;
pub use asset_server::*;
pub use load_request::*; pub use load_request::*;
pub use asset_path::*; pub use loader::*;
use bevy_app::{AppBuilder, AppPlugin}; use bevy_app::{AppBuilder, AppPlugin};
@ -23,6 +23,7 @@ pub struct AssetPlugin;
impl AppPlugin for AssetPlugin { impl AppPlugin for AssetPlugin {
fn build(&self, app: &mut AppBuilder) { fn build(&self, app: &mut AppBuilder) {
app.add_stage(stage::LOAD_ASSETS).init_resource::<AssetServer>(); app.add_stage(stage::LOAD_ASSETS)
.init_resource::<AssetServer>();
} }
} }

View File

@ -1,8 +1,8 @@
mod loader; mod loader;
pub use loader::*; pub use loader::*;
use bevy_app::{AppPlugin, AppBuilder}; use bevy_app::{AppBuilder, AppPlugin};
use bevy_asset::{AddAsset}; use bevy_asset::AddAsset;
#[derive(Default)] #[derive(Default)]
pub struct GltfPlugin; pub struct GltfPlugin;

View File

@ -3,11 +3,11 @@ use bevy_render::{
pipeline::state_descriptors::PrimitiveTopology, pipeline::state_descriptors::PrimitiveTopology,
}; };
use anyhow::Result;
use bevy_asset::{AssetLoader, AssetPath}; use bevy_asset::{AssetLoader, AssetPath};
use gltf::{buffer::Source, iter, mesh::Mode}; use gltf::{buffer::Source, iter, mesh::Mode};
use std::{fs, io, path::Path}; use std::{fs, io, path::Path};
use thiserror::Error; use thiserror::Error;
use anyhow::Result;
#[derive(Clone)] #[derive(Clone)]
pub struct GltfLoader; pub struct GltfLoader;
@ -18,9 +18,7 @@ impl AssetLoader<Mesh> for GltfLoader {
Ok(mesh) Ok(mesh)
} }
fn extensions(&self) -> &[&str] { fn extensions(&self) -> &[&str] {
static EXTENSIONS: &[&str] = &[ static EXTENSIONS: &[&str] = &["gltf"];
"gltf"
];
EXTENSIONS EXTENSIONS
} }
} }

View File

@ -7,7 +7,8 @@ use crate::{
pass::RenderPass, pass::RenderPass,
pipeline::{PipelineAssignments, PipelineDescriptor}, pipeline::{PipelineAssignments, PipelineDescriptor},
render_resource::{ render_resource::{
resource_name, EntityRenderResourceAssignments, RenderResourceAssignments, ResourceInfo, EntitiesWaitingForAssets, resource_name, EntitiesWaitingForAssets, EntityRenderResourceAssignments,
RenderResourceAssignments, ResourceInfo,
}, },
renderer::RenderContext, renderer::RenderContext,
Renderable, Renderable,
@ -46,7 +47,10 @@ impl DrawTarget for AssignedMeshesDrawTarget {
.get(*assignment_id) .get(*assignment_id)
.unwrap(); .unwrap();
let renderable = world.get_component::<Renderable>(*entity).unwrap(); let renderable = world.get_component::<Renderable>(*entity).unwrap();
if !renderable.is_visible || renderable.is_instanced || entities_waiting_for_assets.contains(entity) { if !renderable.is_visible
|| renderable.is_instanced
|| entities_waiting_for_assets.contains(entity)
{
continue; continue;
} }

View File

@ -42,11 +42,11 @@ use self::{
use base_render_graph::{BaseRenderGraphBuilder, BaseRenderGraphConfig}; use base_render_graph::{BaseRenderGraphBuilder, BaseRenderGraphConfig};
use bevy_app::{stage, AppBuilder, AppPlugin}; use bevy_app::{stage, AppBuilder, AppPlugin};
use bevy_asset::AddAsset; use bevy_asset::AddAsset;
use legion::prelude::IntoSystem;
use mesh::mesh_resource_provider_system; use mesh::mesh_resource_provider_system;
use render_graph::RenderGraph; use render_graph::RenderGraph;
use texture::PngTextureLoader;
use render_resource::EntitiesWaitingForAssets; use render_resource::EntitiesWaitingForAssets;
use legion::prelude::IntoSystem; use texture::PngTextureLoader;
pub static RENDER_RESOURCE_STAGE: &str = "render_resource"; pub static RENDER_RESOURCE_STAGE: &str = "render_resource";
pub static RENDER_STAGE: &str = "render"; pub static RENDER_STAGE: &str = "render";
@ -87,7 +87,10 @@ impl AppPlugin for RenderPlugin {
.init_resource::<EntitiesWaitingForAssets>() .init_resource::<EntitiesWaitingForAssets>()
.add_system(entity_render_resource_assignments_system()) .add_system(entity_render_resource_assignments_system())
.init_system_to_stage(stage::POST_UPDATE, camera::camera_update_system) .init_system_to_stage(stage::POST_UPDATE, camera::camera_update_system)
.add_system_to_stage(stage::PRE_UPDATE, EntitiesWaitingForAssets::clear_system.system()) .add_system_to_stage(
stage::PRE_UPDATE,
EntitiesWaitingForAssets::clear_system.system(),
)
.init_system_to_stage(RENDER_RESOURCE_STAGE, mesh_resource_provider_system); .init_system_to_stage(RENDER_RESOURCE_STAGE, mesh_resource_provider_system);
} }
} }

View File

@ -403,10 +403,7 @@ pub fn mesh_resource_provider_system(resources: &mut Resources) -> Box<dyn Sched
.read_resource::<Events<AssetEvent<Mesh>>>() .read_resource::<Events<AssetEvent<Mesh>>>()
.with_query(<(Read<Handle<Mesh>>, Write<Renderable>)>::query()) .with_query(<(Read<Handle<Mesh>>, Write<Renderable>)>::query())
.build( .build(
move |_, move |_, world, (render_resource_context, meshes, mesh_events), query| {
world,
(render_resource_context, meshes, mesh_events),
query| {
let render_resources = &*render_resource_context.context; let render_resources = &*render_resource_context.context;
let changed_meshes = mesh_event_reader let changed_meshes = mesh_event_reader
.iter(&mesh_events) .iter(&mesh_events)

View File

@ -1,5 +1,5 @@
use legion::prelude::{Entity, Res}; use legion::prelude::{Entity, Res};
use std::{sync::RwLock, collections::HashSet}; use std::{collections::HashSet, sync::RwLock};
#[derive(Default)] #[derive(Default)]
pub struct EntitiesWaitingForAssets { pub struct EntitiesWaitingForAssets {
@ -8,11 +8,17 @@ pub struct EntitiesWaitingForAssets {
impl EntitiesWaitingForAssets { impl EntitiesWaitingForAssets {
pub fn add(&self, entity: Entity) { pub fn add(&self, entity: Entity) {
self.entities.write().expect("RwLock poisoned").insert(entity); self.entities
.write()
.expect("RwLock poisoned")
.insert(entity);
} }
pub fn contains(&self, entity: &Entity) -> bool { pub fn contains(&self, entity: &Entity) -> bool {
self.entities.read().expect("RwLock poisoned").contains(entity) self.entities
.read()
.expect("RwLock poisoned")
.contains(entity)
} }
pub fn clear(&self) { pub fn clear(&self) {

View File

@ -1,14 +1,14 @@
mod buffer; mod buffer;
mod entity_render_resource_assignments;
mod entities_waiting_for_assets; mod entities_waiting_for_assets;
mod entity_render_resource_assignments;
mod render_resource; mod render_resource;
mod render_resource_assignments; mod render_resource_assignments;
mod resource_info; mod resource_info;
pub mod resource_name; pub mod resource_name;
pub use buffer::*; pub use buffer::*;
pub use entity_render_resource_assignments::*;
pub use entities_waiting_for_assets::*; pub use entities_waiting_for_assets::*;
pub use entity_render_resource_assignments::*;
pub use render_resource::*; pub use render_resource::*;
pub use render_resource_assignments::*; pub use render_resource_assignments::*;
pub use resource_info::*; pub use resource_info::*;

View File

@ -1,11 +1,11 @@
mod png_texture_loader;
mod sampler_descriptor; mod sampler_descriptor;
mod texture; mod texture;
mod texture_descriptor; mod texture_descriptor;
mod texture_dimension; mod texture_dimension;
mod png_texture_loader;
pub use png_texture_loader::*;
pub use sampler_descriptor::*; pub use sampler_descriptor::*;
pub use texture::*; pub use texture::*;
pub use texture_descriptor::*; pub use texture_descriptor::*;
pub use texture_dimension::*; pub use texture_dimension::*;
pub use png_texture_loader::*;

View File

@ -1,6 +1,6 @@
use bevy_asset::{AssetPath, AssetLoader};
use super::Texture; use super::Texture;
use anyhow::Result; use anyhow::Result;
use bevy_asset::{AssetLoader, AssetPath};
#[derive(Clone, Default)] #[derive(Clone, Default)]
pub struct PngTextureLoader; pub struct PngTextureLoader;
@ -18,9 +18,7 @@ impl AssetLoader<Texture> for PngTextureLoader {
}) })
} }
fn extensions(&self) -> &[&str] { fn extensions(&self) -> &[&str] {
static EXTENSIONS: &[&str] = &[ static EXTENSIONS: &[&str] = &["png"];
"png"
];
EXTENSIONS EXTENSIONS
} }
} }

View File

@ -1,6 +1,6 @@
use crate::Font; use crate::Font;
use bevy_asset::{AssetLoader, AssetPath};
use anyhow::Result; use anyhow::Result;
use bevy_asset::{AssetLoader, AssetPath};
#[derive(Clone)] #[derive(Clone)]
pub struct FontLoader; pub struct FontLoader;

View File

@ -13,8 +13,6 @@ pub struct TextPlugin;
impl AppPlugin for TextPlugin { impl AppPlugin for TextPlugin {
fn build(&self, app: &mut AppBuilder) { fn build(&self, app: &mut AppBuilder) {
app app.add_asset::<Font>().add_asset_loader(FontLoader);
.add_asset::<Font>()
.add_asset_loader(FontLoader);
} }
} }

View File

@ -16,7 +16,9 @@ fn setup(
mut materials: ResMut<Assets<StandardMaterial>>, mut materials: ResMut<Assets<StandardMaterial>>,
) { ) {
// load a texture // load a texture
let texture_handle = asset_server.load_sync(&mut textures, "assets/branding/bevy_logo_dark_big.png").unwrap(); let texture_handle = asset_server
.load_sync(&mut textures, "assets/branding/bevy_logo_dark_big.png")
.unwrap();
let texture = textures.get(&texture_handle).unwrap(); let texture = textures.get(&texture_handle).unwrap();
let aspect = texture.aspect(); let aspect = texture.aspect();

View File

@ -14,7 +14,9 @@ fn setup(
mut textures: ResMut<Assets<Texture>>, mut textures: ResMut<Assets<Texture>>,
mut materials: ResMut<Assets<ColorMaterial>>, mut materials: ResMut<Assets<ColorMaterial>>,
) { ) {
let font_handle = asset_server.load_sync(&mut fonts, "assets/fonts/FiraSans-Bold.ttf").unwrap(); let font_handle = asset_server
.load_sync(&mut fonts, "assets/fonts/FiraSans-Bold.ttf")
.unwrap();
let font = fonts.get(&font_handle).unwrap(); let font = fonts.get(&font_handle).unwrap();
let texture = font.render_text("Hello from Bevy!", Color::rgba(0.9, 0.9, 0.9, 1.0), 500, 60); let texture = font.render_text("Hello from Bevy!", Color::rgba(0.9, 0.9, 0.9, 1.0), 500, 60);

View File

@ -1,5 +1,5 @@
#[cfg(feature = "asset")] #[cfg(feature = "asset")]
pub use crate::asset::{AddAsset, AssetEvent, Assets, Handle, AssetServer}; pub use crate::asset::{AddAsset, AssetEvent, AssetServer, Assets, Handle};
#[cfg(feature = "core")] #[cfg(feature = "core")]
pub use crate::core::{ pub use crate::core::{
time::Time, time::Time,