mirror of
https://github.com/bevyengine/bevy
synced 2024-11-22 04:33:37 +00:00
cargo fmt
This commit is contained in:
parent
fcc0a6303b
commit
b1f07e3749
19 changed files with 58 additions and 50 deletions
|
@ -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 legion::prelude::Resources;
|
||||
use std::{
|
||||
|
|
|
@ -122,10 +122,7 @@ impl AddAsset for AppBuilder {
|
|||
T: Send + Sync + 'static,
|
||||
{
|
||||
self.init_resource::<Assets<T>>()
|
||||
.add_system_to_stage(
|
||||
stage::POST_UPDATE,
|
||||
Assets::<T>::asset_event_system.system(),
|
||||
)
|
||||
.add_system_to_stage(stage::POST_UPDATE, Assets::<T>::asset_event_system.system())
|
||||
.add_event::<AssetEvent<T>>()
|
||||
}
|
||||
|
||||
|
|
|
@ -97,7 +97,6 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
impl<T> Hash for Handle<T> {
|
||||
fn hash<H: Hasher>(&self, state: &mut H) {
|
||||
self.id.hash(state);
|
||||
|
@ -160,4 +159,4 @@ where
|
|||
type_id: TypeId::of::<T>(),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
mod asset_path;
|
||||
mod asset_server;
|
||||
mod assets;
|
||||
mod handle;
|
||||
mod loader;
|
||||
mod asset_server;
|
||||
mod load_request;
|
||||
mod asset_path;
|
||||
mod loader;
|
||||
|
||||
pub use asset_path::*;
|
||||
pub use asset_server::*;
|
||||
pub use assets::*;
|
||||
pub use handle::*;
|
||||
pub use loader::*;
|
||||
pub use asset_server::*;
|
||||
pub use load_request::*;
|
||||
pub use asset_path::*;
|
||||
pub use loader::*;
|
||||
|
||||
use bevy_app::{AppBuilder, AppPlugin};
|
||||
|
||||
|
@ -23,6 +23,7 @@ pub struct AssetPlugin;
|
|||
|
||||
impl AppPlugin for AssetPlugin {
|
||||
fn build(&self, app: &mut AppBuilder) {
|
||||
app.add_stage(stage::LOAD_ASSETS).init_resource::<AssetServer>();
|
||||
app.add_stage(stage::LOAD_ASSETS)
|
||||
.init_resource::<AssetServer>();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
mod loader;
|
||||
pub use loader::*;
|
||||
|
||||
use bevy_app::{AppPlugin, AppBuilder};
|
||||
use bevy_asset::{AddAsset};
|
||||
use bevy_app::{AppBuilder, AppPlugin};
|
||||
use bevy_asset::AddAsset;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct GltfPlugin;
|
||||
|
@ -11,4 +11,4 @@ impl AppPlugin for GltfPlugin {
|
|||
fn build(&self, app: &mut AppBuilder) {
|
||||
app.add_asset_loader(GltfLoader);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,11 +3,11 @@ use bevy_render::{
|
|||
pipeline::state_descriptors::PrimitiveTopology,
|
||||
};
|
||||
|
||||
use anyhow::Result;
|
||||
use bevy_asset::{AssetLoader, AssetPath};
|
||||
use gltf::{buffer::Source, iter, mesh::Mode};
|
||||
use std::{fs, io, path::Path};
|
||||
use thiserror::Error;
|
||||
use anyhow::Result;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct GltfLoader;
|
||||
|
@ -18,9 +18,7 @@ impl AssetLoader<Mesh> for GltfLoader {
|
|||
Ok(mesh)
|
||||
}
|
||||
fn extensions(&self) -> &[&str] {
|
||||
static EXTENSIONS: &[&str] = &[
|
||||
"gltf"
|
||||
];
|
||||
static EXTENSIONS: &[&str] = &["gltf"];
|
||||
EXTENSIONS
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,8 @@ use crate::{
|
|||
pass::RenderPass,
|
||||
pipeline::{PipelineAssignments, PipelineDescriptor},
|
||||
render_resource::{
|
||||
resource_name, EntityRenderResourceAssignments, RenderResourceAssignments, ResourceInfo, EntitiesWaitingForAssets,
|
||||
resource_name, EntitiesWaitingForAssets, EntityRenderResourceAssignments,
|
||||
RenderResourceAssignments, ResourceInfo,
|
||||
},
|
||||
renderer::RenderContext,
|
||||
Renderable,
|
||||
|
@ -46,7 +47,10 @@ impl DrawTarget for AssignedMeshesDrawTarget {
|
|||
.get(*assignment_id)
|
||||
.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;
|
||||
}
|
||||
|
||||
|
|
|
@ -42,11 +42,11 @@ use self::{
|
|||
use base_render_graph::{BaseRenderGraphBuilder, BaseRenderGraphConfig};
|
||||
use bevy_app::{stage, AppBuilder, AppPlugin};
|
||||
use bevy_asset::AddAsset;
|
||||
use legion::prelude::IntoSystem;
|
||||
use mesh::mesh_resource_provider_system;
|
||||
use render_graph::RenderGraph;
|
||||
use texture::PngTextureLoader;
|
||||
use render_resource::EntitiesWaitingForAssets;
|
||||
use legion::prelude::IntoSystem;
|
||||
use texture::PngTextureLoader;
|
||||
|
||||
pub static RENDER_RESOURCE_STAGE: &str = "render_resource";
|
||||
pub static RENDER_STAGE: &str = "render";
|
||||
|
@ -87,7 +87,10 @@ impl AppPlugin for RenderPlugin {
|
|||
.init_resource::<EntitiesWaitingForAssets>()
|
||||
.add_system(entity_render_resource_assignments_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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -403,10 +403,7 @@ pub fn mesh_resource_provider_system(resources: &mut Resources) -> Box<dyn Sched
|
|||
.read_resource::<Events<AssetEvent<Mesh>>>()
|
||||
.with_query(<(Read<Handle<Mesh>>, Write<Renderable>)>::query())
|
||||
.build(
|
||||
move |_,
|
||||
world,
|
||||
(render_resource_context, meshes, mesh_events),
|
||||
query| {
|
||||
move |_, world, (render_resource_context, meshes, mesh_events), query| {
|
||||
let render_resources = &*render_resource_context.context;
|
||||
let changed_meshes = mesh_event_reader
|
||||
.iter(&mesh_events)
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use legion::prelude::{Entity, Res};
|
||||
use std::{sync::RwLock, collections::HashSet};
|
||||
use std::{collections::HashSet, sync::RwLock};
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct EntitiesWaitingForAssets {
|
||||
|
@ -8,11 +8,17 @@ pub struct EntitiesWaitingForAssets {
|
|||
|
||||
impl EntitiesWaitingForAssets {
|
||||
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 {
|
||||
self.entities.read().expect("RwLock poisoned").contains(entity)
|
||||
self.entities
|
||||
.read()
|
||||
.expect("RwLock poisoned")
|
||||
.contains(entity)
|
||||
}
|
||||
|
||||
pub fn clear(&self) {
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
mod buffer;
|
||||
mod entity_render_resource_assignments;
|
||||
mod entities_waiting_for_assets;
|
||||
mod entity_render_resource_assignments;
|
||||
mod render_resource;
|
||||
mod render_resource_assignments;
|
||||
mod resource_info;
|
||||
pub mod resource_name;
|
||||
|
||||
pub use buffer::*;
|
||||
pub use entity_render_resource_assignments::*;
|
||||
pub use entities_waiting_for_assets::*;
|
||||
pub use entity_render_resource_assignments::*;
|
||||
pub use render_resource::*;
|
||||
pub use render_resource_assignments::*;
|
||||
pub use resource_info::*;
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
mod png_texture_loader;
|
||||
mod sampler_descriptor;
|
||||
mod texture;
|
||||
mod texture_descriptor;
|
||||
mod texture_dimension;
|
||||
mod png_texture_loader;
|
||||
|
||||
pub use png_texture_loader::*;
|
||||
pub use sampler_descriptor::*;
|
||||
pub use texture::*;
|
||||
pub use texture_descriptor::*;
|
||||
pub use texture_dimension::*;
|
||||
pub use png_texture_loader::*;
|
|
@ -1,6 +1,6 @@
|
|||
use bevy_asset::{AssetPath, AssetLoader};
|
||||
use super::Texture;
|
||||
use anyhow::Result;
|
||||
use bevy_asset::{AssetLoader, AssetPath};
|
||||
|
||||
#[derive(Clone, Default)]
|
||||
pub struct PngTextureLoader;
|
||||
|
@ -18,9 +18,7 @@ impl AssetLoader<Texture> for PngTextureLoader {
|
|||
})
|
||||
}
|
||||
fn extensions(&self) -> &[&str] {
|
||||
static EXTENSIONS: &[&str] = &[
|
||||
"png"
|
||||
];
|
||||
static EXTENSIONS: &[&str] = &["png"];
|
||||
EXTENSIONS
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use crate::Font;
|
||||
use bevy_asset::{AssetLoader, AssetPath};
|
||||
use anyhow::Result;
|
||||
use bevy_asset::{AssetLoader, AssetPath};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct FontLoader;
|
||||
|
|
|
@ -13,8 +13,6 @@ pub struct TextPlugin;
|
|||
|
||||
impl AppPlugin for TextPlugin {
|
||||
fn build(&self, app: &mut AppBuilder) {
|
||||
app
|
||||
.add_asset::<Font>()
|
||||
.add_asset_loader(FontLoader);
|
||||
app.add_asset::<Font>().add_asset_loader(FontLoader);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,7 +16,9 @@ fn setup(
|
|||
mut materials: ResMut<Assets<StandardMaterial>>,
|
||||
) {
|
||||
// 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 aspect = texture.aspect();
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ fn main() {
|
|||
.run();
|
||||
}
|
||||
|
||||
// This "print message plugin" prints a `message` every `wait_duration`
|
||||
// This "print message plugin" prints a `message` every `wait_duration`
|
||||
pub struct PrintMessagePlugin {
|
||||
// Put your plugin configuration here
|
||||
wait_duration: Duration,
|
||||
|
|
|
@ -14,7 +14,9 @@ fn setup(
|
|||
mut textures: ResMut<Assets<Texture>>,
|
||||
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 texture = font.render_text("Hello from Bevy!", Color::rgba(0.9, 0.9, 0.9, 1.0), 500, 60);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#[cfg(feature = "asset")]
|
||||
pub use crate::asset::{AddAsset, AssetEvent, Assets, Handle, AssetServer};
|
||||
pub use crate::asset::{AddAsset, AssetEvent, AssetServer, Assets, Handle};
|
||||
#[cfg(feature = "core")]
|
||||
pub use crate::core::{
|
||||
time::Time,
|
||||
|
|
Loading…
Reference in a new issue