cargo fmt

This commit is contained in:
Carter Anderson 2020-07-10 01:37:06 -07:00
parent db3191e47b
commit c81ab99dac
101 changed files with 432 additions and 403 deletions

View file

@ -22,7 +22,8 @@ impl App {
pub fn run(mut self) {
self.startup_schedule.initialize(&mut self.resources);
self.startup_schedule.run(&mut self.world, &mut self.resources);
self.startup_schedule
.run(&mut self.world, &mut self.resources);
if let Some(run) = self.runner.take() {
run(self)
}

View file

@ -6,7 +6,7 @@ use crate::{
use bevy_ecs::{FromResources, IntoQuerySystem, Resources, System, World};
pub struct AppBuilder {
pub app: App,
pub app: App,
}
impl Default for AppBuilder {

View file

@ -3,6 +3,7 @@ use crate::{
Assets, Handle, HandleId, LoadRequest,
};
use anyhow::Result;
use bevy_ecs::{Res, Resource, Resources};
use crossbeam_channel::TryRecvError;
use std::{
collections::{HashMap, HashSet},
@ -12,7 +13,6 @@ use std::{
thread,
};
use thiserror::Error;
use bevy_ecs::{Res, Resources, Resource};
pub type AssetVersion = usize;
#[derive(Error, Debug)]

View file

@ -3,9 +3,9 @@ use crate::{
Handle, HandleId,
};
use bevy_app::{AppBuilder, Events};
use bevy_ecs::{FromResources, IntoQuerySystem, ResMut, Resource};
use bevy_type_registry::RegisterType;
use std::collections::HashMap;
use bevy_ecs::{Resource, ResMut, IntoQuerySystem, FromResources};
pub enum AssetEvent<T: Resource> {
Created { handle: Handle<T> },

View file

@ -13,8 +13,8 @@ pub use load_request::*;
pub use loader::*;
use bevy_app::{AppBuilder, AppPlugin};
use bevy_type_registry::RegisterType;
use bevy_ecs::IntoQuerySystem;
use bevy_type_registry::RegisterType;
pub mod stage {
pub const LOAD_ASSETS: &str = "load_assets";

View file

@ -1,5 +1,6 @@
use crate::{AssetServer, AssetVersion, Assets, Handle, LoadState};
use anyhow::Result;
use bevy_ecs::{Res, ResMut, Resource};
use crossbeam_channel::{Receiver, Sender, TryRecvError};
use fs::File;
use io::Read;
@ -8,7 +9,6 @@ use std::{
path::{Path, PathBuf},
};
use thiserror::Error;
use bevy_ecs::{ResMut, Res, Resource};
#[derive(Error, Debug)]
pub enum AssetLoadError {

View file

@ -171,8 +171,8 @@ where
#[cfg(test)]
mod tests {
use super::{FromBytes, Bytes};
use glam::{Vec3, Vec2, Vec4, Mat4};
use super::{Bytes, FromBytes};
use glam::{Mat4, Vec2, Vec3, Vec4};
fn test_round_trip<T: Bytes + FromBytes + std::fmt::Debug + PartialEq>(value: T) {
let mut bytes = vec![0; value.byte_len()];

View file

@ -4,16 +4,16 @@ pub mod time;
pub mod transform;
use bevy_app::{stage, startup_stage, AppBuilder, AppPlugin};
use bevy_ecs::IntoQuerySystem;
use bevy_transform::{
build_systems,
components::{
Children, LocalTransform, NonUniformScale, Rotation, Scale, Transform, Translation,
},
build_systems,
};
use bevy_type_registry::RegisterType;
use glam::{Mat3, Mat4, Quat, Vec2, Vec3};
use time::{time_system, timer_system, Time, Timer};
use bevy_ecs::IntoQuerySystem;
#[derive(Default)]
pub struct CorePlugin;

View file

@ -1,5 +1,5 @@
use std::time::{Duration, Instant};
use bevy_ecs::ResMut;
use std::time::{Duration, Instant};
pub struct Time {
pub delta: Duration,

View file

@ -1,7 +1,7 @@
use crate::time::Time;
use bevy_ecs::{Query, Res};
use bevy_property::Properties;
use std::time::Duration;
use bevy_ecs::{Query, Res};
#[derive(Clone, Debug, Default, Properties)]
pub struct Timer {

View file

@ -1,4 +1,4 @@
use glam::{Vec3, Mat4};
use glam::{Mat4, Vec3};
pub trait FaceToward {
fn face_toward(eye: Vec3, center: Vec3, up: Vec3) -> Self;

View file

@ -1,5 +1,5 @@
mod hierarchy;
mod face_toward;
mod hierarchy;
pub use hierarchy::*;
pub use face_toward::*;
pub use hierarchy::*;

View file

@ -17,7 +17,6 @@ impl Default for DiagnosticId {
fn default() -> Self {
DiagnosticId(Uuid::new_v4())
}
}
#[derive(Debug)]

View file

@ -1,7 +1,7 @@
use crate::{Diagnostic, DiagnosticId, Diagnostics};
use bevy_app::AppPlugin;
use bevy_core::time::Time;
use bevy_ecs::{Res, ResMut, IntoQuerySystem};
use bevy_ecs::{IntoQuerySystem, Res, ResMut};
#[derive(Default)]
pub struct FrameTimeDiagnosticsPlugin;

View file

@ -1,8 +1,8 @@
use super::{Diagnostic, DiagnosticId, Diagnostics};
use bevy_app::{stage, AppPlugin};
use bevy_core::time::{Time, Timer};
use bevy_ecs::{IntoQuerySystem, Res, ResMut};
use std::time::Duration;
use bevy_ecs::{Res, ResMut, IntoQuerySystem};
pub struct PrintDiagnosticsPlugin {
pub debug: bool,

View file

@ -18,9 +18,9 @@ extern crate proc_macro;
use proc_macro::TokenStream;
use proc_macro2::Span;
use proc_macro_crate::crate_name;
use quote::quote;
use syn::{parse_macro_input, DeriveInput, Path};
use proc_macro_crate::crate_name;
/// Implement `Bundle` for a monomorphic struct
///

View file

@ -14,19 +14,22 @@
// modified by Bevy contributors
use crate::alloc::alloc::{alloc, dealloc, Layout};
use crate::alloc::boxed::Box;
use crate::alloc::{vec, vec::Vec};
use core::any::{type_name, TypeId};
use core::cell::UnsafeCell;
use core::mem;
use core::ptr::{self, NonNull};
use crate::alloc::{
alloc::{alloc, dealloc, Layout},
boxed::Box,
vec,
vec::Vec,
};
use core::{
any::{type_name, TypeId},
cell::UnsafeCell,
mem,
ptr::{self, NonNull},
};
use hashbrown::HashMap;
use crate::borrow::AtomicBorrow;
use crate::query::Fetch;
use crate::{Access, Component, Query};
use crate::{borrow::AtomicBorrow, query::Fetch, Access, Component, Query};
/// A collection of entities having the same component types
///
@ -154,7 +157,7 @@ impl Archetype {
}
#[allow(missing_docs)]
pub fn iter_entities(&self) -> impl Iterator<Item=&u32> {
pub fn iter_entities(&self) -> impl Iterator<Item = &u32> {
self.entities.iter().take(self.len as usize)
}
@ -313,13 +316,7 @@ impl Archetype {
}
#[allow(missing_docs)]
pub unsafe fn put_dynamic(
&mut self,
component: *mut u8,
ty: TypeId,
size: usize,
index: u32,
) {
pub unsafe fn put_dynamic(&mut self, component: *mut u8, ty: TypeId, size: usize, index: u32) {
let ptr = self
.get_dynamic(ty, size, index)
.unwrap()

View file

@ -14,12 +14,13 @@
// modified by Bevy contributors
use core::ops::{Deref, DerefMut};
use core::ptr::NonNull;
use core::sync::atomic::{AtomicUsize, Ordering};
use core::{
ops::{Deref, DerefMut},
ptr::NonNull,
sync::atomic::{AtomicUsize, Ordering},
};
use crate::archetype::Archetype;
use crate::{Component, MissingComponent};
use crate::{archetype::Archetype, Component, MissingComponent};
pub struct AtomicBorrow(AtomicUsize);
@ -71,10 +72,7 @@ pub struct Ref<'a, T: Component> {
impl<'a, T: Component> Ref<'a, T> {
#[allow(missing_docs)]
pub unsafe fn new(
archetype: &'a Archetype,
index: u32,
) -> Result<Self, MissingComponent> {
pub unsafe fn new(archetype: &'a Archetype, index: u32) -> Result<Self, MissingComponent> {
let target = NonNull::new_unchecked(
archetype
.get::<T>()
@ -111,10 +109,7 @@ pub struct RefMut<'a, T: Component> {
impl<'a, T: Component> RefMut<'a, T> {
#[allow(missing_docs)]
pub unsafe fn new(
archetype: &'a Archetype,
index: u32,
) -> Result<Self, MissingComponent> {
pub unsafe fn new(archetype: &'a Archetype, index: u32) -> Result<Self, MissingComponent> {
let target = NonNull::new_unchecked(
archetype
.get::<T>()

View file

@ -15,12 +15,13 @@
// modified by Bevy contributors
use crate::alloc::{vec, vec::Vec};
use core::any::{type_name, TypeId};
use core::ptr::NonNull;
use core::{fmt, mem};
use core::{
any::{type_name, TypeId},
fmt, mem,
ptr::NonNull,
};
use crate::archetype::TypeInfo;
use crate::Component;
use crate::{archetype::TypeInfo, Component};
/// A dynamically typed collection of components
pub trait DynamicBundle {

View file

@ -67,7 +67,9 @@ impl Entities {
/// Access the location storage of an entity
pub fn get_mut(&mut self, entity: Entity) -> Result<&mut Location, NoSuchEntity> {
self.entity_locations.get_mut(&entity).ok_or_else(|| NoSuchEntity)
self.entity_locations
.get_mut(&entity)
.ok_or_else(|| NoSuchEntity)
}
/// Access the location storage of an entity
@ -76,7 +78,10 @@ impl Entities {
}
pub fn get(&self, entity: Entity) -> Result<Location, NoSuchEntity> {
self.entity_locations.get(&entity).cloned().ok_or_else(|| NoSuchEntity)
self.entity_locations
.get(&entity)
.cloned()
.ok_or_else(|| NoSuchEntity)
}
}

View file

@ -14,17 +14,21 @@
// modified by Bevy contributors
use crate::alloc::alloc::{alloc, dealloc, Layout};
use crate::alloc::boxed::Box;
use crate::alloc::{vec, vec::Vec};
use core::any::TypeId;
use core::mem::{self, MaybeUninit};
use core::ptr;
use crate::alloc::{
alloc::{alloc, dealloc, Layout},
boxed::Box,
vec,
vec::Vec,
};
use core::{
any::TypeId,
mem::{self, MaybeUninit},
ptr,
};
use hashbrown::HashSet;
use crate::archetype::TypeInfo;
use crate::{Component, DynamicBundle};
use crate::{archetype::TypeInfo, Component, DynamicBundle};
/// Helper for incrementally constructing a bundle of components with dynamic component types
///

View file

@ -71,14 +71,14 @@ mod entities;
mod entity_builder;
mod query;
mod query_one;
mod world;
#[cfg(feature = "serde")]
mod serde;
mod world;
pub use archetype::Archetype;
pub use borrow::{EntityRef, Ref, RefMut};
pub use bundle::{Bundle, DynamicBundle, MissingComponent};
pub use entities::{Entity, NoSuchEntity, Location};
pub use entities::{Entity, Location, NoSuchEntity};
pub use entity_builder::{BuiltEntity, EntityBuilder};
pub use query::{Access, BatchedIter, Query, QueryBorrow, QueryIter, With, Without};
pub use query_one::QueryOne;

View file

@ -14,11 +14,9 @@
// modified by Bevy contributors
use core::marker::PhantomData;
use core::ptr::NonNull;
use core::{marker::PhantomData, ptr::NonNull};
use crate::archetype::Archetype;
use crate::{Entity, Component};
use crate::{archetype::Archetype, Component, Entity};
/// A collection of component types to fetch from a `World`
pub trait Query {
@ -520,9 +518,7 @@ struct ChunkIter<Q: Query> {
impl<Q: Query> ChunkIter<Q> {
#[inline]
unsafe fn next<'a, 'w>(
&mut self,
) -> Option<<Q::Fetch as Fetch<'a>>::Item> {
unsafe fn next<'a, 'w>(&mut self) -> Option<<Q::Fetch as Fetch<'a>>::Item> {
if self.len == 0 {
return None;
}

View file

@ -2,8 +2,10 @@
use core::marker::PhantomData;
use crate::query::{Fetch, With, Without};
use crate::{Archetype, Component, Query};
use crate::{
query::{Fetch, With, Without},
Archetype, Component, Query,
};
/// A borrow of a `World` sufficient to execute the query `Q` on a single entity
pub struct QueryOne<'a, Q: Query> {

View file

@ -261,12 +261,7 @@ impl World {
/// ```
pub fn query_one<Q: Query>(&self, entity: Entity) -> Result<QueryOne<'_, Q>, NoSuchEntity> {
let loc = self.entities.get(entity)?;
Ok(unsafe {
QueryOne::new(
&self.archetypes[loc.archetype as usize],
loc.index,
)
})
Ok(unsafe { QueryOne::new(&self.archetypes[loc.archetype as usize], loc.index) })
}
/// Borrow the `T` component of `entity`
@ -740,10 +735,13 @@ where
self.archetype.put_dynamic(ptr, ty, size, index);
true
});
self.entities.insert(entity, Location {
archetype: self.archetype_id,
index,
});
self.entities.insert(
entity,
Location {
archetype: self.archetype_id,
index,
},
);
}
Some(entity)
}

View file

@ -315,11 +315,7 @@ fn query_batched() {
fn spawn_batch() {
let mut world = World::new();
world.spawn_batch((0..100).map(|x| (x, "abc")));
let entities = world
.query::<&i32>()
.iter()
.map(|&x| x)
.collect::<Vec<_>>();
let entities = world.query::<&i32>().iter().map(|&x| x).collect::<Vec<_>>();
assert_eq!(entities.len(), 100);
}

View file

@ -156,7 +156,10 @@ impl CommandsInternal {
self
}
pub fn with_bundle(&mut self, components: impl DynamicBundle + Send + Sync + 'static) -> &mut Self {
pub fn with_bundle(
&mut self,
components: impl DynamicBundle + Send + Sync + 'static,
) -> &mut Self {
let current_entity = self.current_entity.expect("Cannot add components because the 'current entity' is not set. You should spawn an entity first.");
self.commands.push(Command::WriteWorld(Box::new(Insert {
entity: current_entity,
@ -230,7 +233,10 @@ impl Commands {
self
}
pub fn with_bundle(&mut self, components: impl DynamicBundle + Send + Sync + 'static) -> &mut Self {
pub fn with_bundle(
&mut self,
components: impl DynamicBundle + Send + Sync + 'static,
) -> &mut Self {
{
let mut commands = self.commands.lock().unwrap();
commands.with_bundle(components);

View file

@ -1,10 +1,12 @@
use crate::{
resource_query::{FetchResource, ResourceQuery},
system::{System, ThreadLocalExecution, SystemId},
system::{System, SystemId, ThreadLocalExecution},
Commands, Resources,
};
use core::marker::PhantomData;
use hecs::{Fetch, Query as HecsQuery, QueryBorrow, World, Component, Ref, ComponentError, Entity, RefMut};
use hecs::{
Component, ComponentError, Entity, Fetch, Query as HecsQuery, QueryBorrow, Ref, RefMut, World,
};
use std::borrow::Cow;
pub struct SystemFn<F, Init>
@ -104,12 +106,12 @@ impl<'a, Q: HecsQuery> Query<'a, Q> {
self.world.query::<Q>()
}
pub fn get<T: Component>(&self, entity: Entity) -> Result<Ref<'_, T>, ComponentError> {
pub fn get<T: Component>(&self, entity: Entity) -> Result<Ref<'_, T>, ComponentError> {
// TODO: Check if request matches query
self.world.get(entity)
}
pub fn get_mut<T: Component>(&self, entity: Entity) -> Result<RefMut<'_, T>, ComponentError> {
pub fn get_mut<T: Component>(&self, entity: Entity) -> Result<RefMut<'_, T>, ComponentError> {
// TODO: Check if request matches query
self.world.get_mut(entity)
}
@ -262,7 +264,7 @@ where
Box::new(Self {
func,
name: core::any::type_name::<F>().into(),
id: SystemId::new()
id: SystemId::new(),
})
}
}

View file

@ -1,19 +1,19 @@
pub use hecs::{*, Query as HecsQuery};
pub use hecs::{Query as HecsQuery, *};
mod commands;
mod into_system;
#[cfg(feature = "profiler")]
pub mod profiler;
mod resource_query;
mod resources;
mod commands;
mod schedule;
mod system;
mod world_builder;
#[cfg(feature = "profiler")]
pub mod profiler;
pub use into_system::{IntoForEachSystem, IntoQuerySystem, Query, ThreadLocalSystem};
pub use resource_query::{Res, ResMut, ResourceQuery, Local, FetchResource};
pub use resources::{Resources, FromResources, Resource};
pub use commands::{Commands, CommandsInternal};
pub use into_system::{IntoForEachSystem, IntoQuerySystem, Query, ThreadLocalSystem};
pub use resource_query::{FetchResource, Local, Res, ResMut, ResourceQuery};
pub use resources::{FromResources, Resource, Resources};
pub use schedule::Schedule;
pub use system::{System, SystemId};
pub use world_builder::{WorldBuilder, WorldBuilderSource};

View file

@ -1,4 +1,4 @@
use crate::{resources::FromResources, Archetype, Component, Resources, system::SystemId};
use crate::{resources::FromResources, system::SystemId, Archetype, Component, Resources};
use core::{
any::TypeId,
ops::{Deref, DerefMut},
@ -222,7 +222,9 @@ impl<'a, T: Component + FromResources> FetchResource<'a> for FetchResourceLocalM
let archetype = resources
.resource_archetypes
.get(&TypeId::of::<T>())
.unwrap_or_else(|| panic!("Resource does not exist {}", std::any::type_name::<T>()));
.unwrap_or_else(|| {
panic!("Resource does not exist {}", std::any::type_name::<T>())
});
let index = resources
.system_id_to_archetype_index
.get(&system_id.0)

View file

@ -1,6 +1,7 @@
use crate::{
resource_query::{FetchResource, ResourceQuery},
ComponentError, TypeInfo, system::SystemId, Res, ResMut,
system::SystemId,
ComponentError, Res, ResMut, TypeInfo,
};
use core::any::TypeId;
use hecs::{Archetype, Ref, RefMut};
@ -198,13 +199,17 @@ mod tests {
assert!(resources.get_local::<i32>(SystemId(0)).is_err());
resources.insert_local(SystemId(0), 111);
assert_eq!(
*resources.get_local::<i32>(SystemId(0)).expect("resource exists"),
*resources
.get_local::<i32>(SystemId(0))
.expect("resource exists"),
111
);
assert_eq!(*resources.get::<i32>().expect("resource exists"), 123);
resources.insert_local(SystemId(0), 222);
assert_eq!(
*resources.get_local::<i32>(SystemId(0)).expect("resource exists"),
*resources
.get_local::<i32>(SystemId(0))
.expect("resource exists"),
222
);
assert_eq!(*resources.get::<i32>().expect("resource exists"), 123);

View file

@ -1,6 +1,6 @@
use crate::{
system::{System, ThreadLocalExecution},
Resources, World, SystemId,
Resources, SystemId, World,
};
use rayon::prelude::*;
use std::{
@ -84,7 +84,11 @@ impl Schedule {
.get_mut(&stage_name)
.unwrap_or_else(|| panic!("Stage does not exist: {}", stage_name));
if self.system_ids.contains(&system.id()) {
panic!("System with id {:?} ({}) already exists", system.id(), system.name());
panic!(
"System with id {:?} ({}) already exists",
system.id(),
system.name()
);
}
self.system_ids.insert(system.id());
systems.push(system);

View file

@ -1,8 +1,8 @@
use super::keyboard::ElementState;
use crate::Input;
use bevy_app::{EventReader, Events};
use glam::Vec2;
use bevy_ecs::{Res, ResMut};
use glam::Vec2;
#[derive(Debug, Clone)]
pub struct MouseButtonInput {

View file

@ -1,12 +1,12 @@
use crate::{light::Light, material::StandardMaterial, pipelines::FORWARD_PIPELINE_HANDLE};
use bevy_asset::Handle;
use bevy_ecs::Bundle;
use bevy_render::{
draw::Draw,
mesh::Mesh,
pipeline::{DynamicBinding, PipelineSpecialization, RenderPipeline, RenderPipelines},
};
use bevy_transform::prelude::{Rotation, Scale, Transform, Translation};
use bevy_ecs::Bundle;
#[derive(Bundle)]
pub struct PbrComponents {

View file

@ -1,5 +1,10 @@
use crate::{material::StandardMaterial, nodes::LightsNode, pipelines::{FORWARD_PIPELINE_HANDLE, build_forward_pipeline}};
use crate::{
material::StandardMaterial,
nodes::LightsNode,
pipelines::{build_forward_pipeline, FORWARD_PIPELINE_HANDLE},
};
use bevy_asset::Assets;
use bevy_ecs::Resources;
use bevy_render::{
base_render_graph,
pipeline::PipelineDescriptor,
@ -10,7 +15,6 @@ use bevy_render::{
shader::Shader,
};
use bevy_transform::prelude::Transform;
use bevy_ecs::Resources;
pub mod node {
pub const TRANSFORM: &str = "transform";
@ -36,7 +40,10 @@ impl ForwardPbrRenderGraphBuilder for RenderGraph {
self.add_system_node(node::LIGHTS, LightsNode::new(10));
let mut shaders = resources.get_mut::<Assets<Shader>>().unwrap();
let mut pipelines = resources.get_mut::<Assets<PipelineDescriptor>>().unwrap();
pipelines.set(FORWARD_PIPELINE_HANDLE, build_forward_pipeline(&mut shaders));
pipelines.set(
FORWARD_PIPELINE_HANDLE,
build_forward_pipeline(&mut shaders),
);
// TODO: replace these with "autowire" groups
self.add_node_edge(node::STANDARD_MATERIAL, base_render_graph::node::MAIN_PASS)

View file

@ -9,11 +9,11 @@ pub use forward_pbr_render_graph::*;
use bevy_app::{stage, AppBuilder, AppPlugin};
use bevy_asset::AddAsset;
use bevy_ecs::IntoQuerySystem;
use bevy_render::{render_graph::RenderGraph, shader};
use bevy_type_registry::RegisterType;
use light::Light;
use material::StandardMaterial;
use bevy_ecs::IntoQuerySystem;
/// NOTE: this isn't PBR yet. consider this name "aspirational" :)
#[derive(Default)]

View file

@ -1,6 +1,8 @@
use bevy_render::{
render_graph::{CommandQueue, Node, ResourceSlots, SystemNode},
render_resource::{BufferInfo, BufferUsage, RenderResourceBinding, RenderResourceBindings, BufferId},
render_resource::{
BufferId, BufferInfo, BufferUsage, RenderResourceBinding, RenderResourceBindings,
},
renderer::{RenderContext, RenderResourceContext},
};
@ -9,8 +11,8 @@ use crate::{
uniform,
};
use bevy_core::bytes::{AsBytes, Byteable};
use bevy_ecs::{Commands, IntoQuerySystem, Local, Query, Res, ResMut, Resources, System, World};
use bevy_transform::prelude::*;
use bevy_ecs::{Commands, Res, System, ResMut, Query, Local, World, Resources, IntoQuerySystem};
#[derive(Default)]
pub struct LightsNode {
@ -51,14 +53,17 @@ unsafe impl Byteable for LightCount {}
impl SystemNode for LightsNode {
fn get_system(&self, commands: &mut Commands) -> Box<dyn System> {
let system = lights_node_system.system();
commands.insert_local_resource(system.id(), LightsNodeSystemState {
command_queue: self.command_queue.clone(),
max_lights: self.max_lights,
tmp_count_buffer: None,
tmp_light_buffer: None,
light_buffer: None,
lights_are_dirty: true,
});
commands.insert_local_resource(
system.id(),
LightsNodeSystemState {
command_queue: self.command_queue.clone(),
max_lights: self.max_lights,
tmp_count_buffer: None,
tmp_light_buffer: None,
light_buffer: None,
lights_are_dirty: true,
},
);
system
}
}
@ -79,97 +84,95 @@ pub fn lights_node_system(
render_resource_context: Res<Box<dyn RenderResourceContext>>,
// TODO: this write on RenderResourceAssignments will prevent this system from running in parallel with other systems that do the same
mut render_resource_bindings: ResMut<RenderResourceBindings>,
mut query: Query<(&Light, &Transform, &Translation)>) {
let state = &mut state;
if !state.lights_are_dirty {
return;
}
mut query: Query<(&Light, &Transform, &Translation)>,
) {
let state = &mut state;
if !state.lights_are_dirty {
return;
}
let render_resource_context = &**render_resource_context;
if state.light_buffer.is_none() {
let light_uniform_size = std::mem::size_of::<LightCount>()
+ state.max_lights * std::mem::size_of::<LightRaw>();
let render_resource_context = &**render_resource_context;
if state.light_buffer.is_none() {
let light_uniform_size =
std::mem::size_of::<LightCount>() + state.max_lights * std::mem::size_of::<LightRaw>();
let buffer = render_resource_context.create_buffer(BufferInfo {
size: light_uniform_size,
buffer_usage: BufferUsage::UNIFORM
| BufferUsage::COPY_SRC
| BufferUsage::COPY_DST,
..Default::default()
});
render_resource_bindings.set(
uniform::LIGHTS,
RenderResourceBinding::Buffer {
buffer,
range: 0..light_uniform_size as u64,
dynamic_index: None,
},
);
state.light_buffer = Some(buffer);
}
let light_count = query.iter().iter().count();
if light_count == 0 {
return;
}
state.lights_are_dirty = false;
let size = std::mem::size_of::<LightRaw>();
let total_size = size * light_count;
let light_count_size = std::mem::size_of::<LightCount>();
if let Some(old_tmp_light_buffer) = state.tmp_light_buffer {
render_resource_context.remove_buffer(old_tmp_light_buffer);
}
if let Some(old_tmp_count_buffer) = state.tmp_count_buffer {
render_resource_context.remove_buffer(old_tmp_count_buffer);
}
state.tmp_light_buffer = Some(render_resource_context.create_buffer_mapped(
BufferInfo {
size: total_size,
buffer_usage: BufferUsage::COPY_SRC,
..Default::default()
let buffer = render_resource_context.create_buffer(BufferInfo {
size: light_uniform_size,
buffer_usage: BufferUsage::UNIFORM | BufferUsage::COPY_SRC | BufferUsage::COPY_DST,
..Default::default()
});
render_resource_bindings.set(
uniform::LIGHTS,
RenderResourceBinding::Buffer {
buffer,
range: 0..light_uniform_size as u64,
dynamic_index: None,
},
&mut |data, _renderer| {
for ((light, transform, translation), slot) in
query.iter().iter().zip(data.chunks_exact_mut(size))
{
slot.copy_from_slice(
LightRaw::from(&light, &transform.value, &translation).as_bytes(),
);
}
},
));
state.tmp_count_buffer = Some(render_resource_context.create_buffer_mapped(
BufferInfo {
size: light_count_size,
buffer_usage: BufferUsage::COPY_SRC,
..Default::default()
},
&mut |data, _renderer| {
data.copy_from_slice([light_count as u32, 0, 0, 0].as_bytes());
},
));
let tmp_count_buffer = state.tmp_count_buffer.unwrap();
let light_buffer = state.light_buffer.unwrap();
state.command_queue.copy_buffer_to_buffer(
tmp_count_buffer,
0,
light_buffer,
0,
light_count_size as u64,
);
state.light_buffer = Some(buffer);
}
let tmp_light_buffer = state.tmp_light_buffer.unwrap();
state.command_queue.copy_buffer_to_buffer(
tmp_light_buffer,
0,
light_buffer,
light_count_size as u64,
total_size as u64,
);
let light_count = query.iter().iter().count();
if light_count == 0 {
return;
}
state.lights_are_dirty = false;
let size = std::mem::size_of::<LightRaw>();
let total_size = size * light_count;
let light_count_size = std::mem::size_of::<LightCount>();
if let Some(old_tmp_light_buffer) = state.tmp_light_buffer {
render_resource_context.remove_buffer(old_tmp_light_buffer);
}
if let Some(old_tmp_count_buffer) = state.tmp_count_buffer {
render_resource_context.remove_buffer(old_tmp_count_buffer);
}
state.tmp_light_buffer = Some(render_resource_context.create_buffer_mapped(
BufferInfo {
size: total_size,
buffer_usage: BufferUsage::COPY_SRC,
..Default::default()
},
&mut |data, _renderer| {
for ((light, transform, translation), slot) in
query.iter().iter().zip(data.chunks_exact_mut(size))
{
slot.copy_from_slice(
LightRaw::from(&light, &transform.value, &translation).as_bytes(),
);
}
},
));
state.tmp_count_buffer = Some(render_resource_context.create_buffer_mapped(
BufferInfo {
size: light_count_size,
buffer_usage: BufferUsage::COPY_SRC,
..Default::default()
},
&mut |data, _renderer| {
data.copy_from_slice([light_count as u32, 0, 0, 0].as_bytes());
},
));
let tmp_count_buffer = state.tmp_count_buffer.unwrap();
let light_buffer = state.light_buffer.unwrap();
state.command_queue.copy_buffer_to_buffer(
tmp_count_buffer,
0,
light_buffer,
0,
light_count_size as u64,
);
let tmp_light_buffer = state.tmp_light_buffer.unwrap();
state.command_queue.copy_buffer_to_buffer(
tmp_light_buffer,
0,
light_buffer,
light_count_size as u64,
total_size as u64,
);
}

View file

@ -1,4 +1,4 @@
use bevy_asset::{Handle, Assets};
use bevy_asset::{Assets, Handle};
use bevy_render::{
pipeline::{
state_descriptors::{

View file

@ -1,6 +1,6 @@
use crate::{impl_property, property_serde::Serializable, Property, PropertyTypeRegistry};
use erased_serde::Deserializer;
use bevy_ecs::Entity;
use erased_serde::Deserializer;
use serde::Deserialize;
impl_property!(Entity, serialize_entity, deserialize_entity);

View file

@ -1,4 +1,4 @@
mod impl_property_glam;
mod impl_property_bevy_ecs;
mod impl_property_glam;
mod impl_property_smallvec;
mod impl_property_std;

View file

@ -94,7 +94,13 @@ impl PropertyTypeRegistration {
let mut split = full_name.splitn(2, "<");
// main type
let mut short_name = split.next().unwrap().split("::").last().unwrap().to_string();
let mut short_name = split
.next()
.unwrap()
.split("::")
.last()
.unwrap()
.to_string();
// process generics if they exist
if let Some(generics) = split.next() {
@ -104,7 +110,13 @@ impl PropertyTypeRegistration {
let generics = &generics[0..generics.len() - 1];
short_name.push('<');
short_name.push_str(&generics.split(',').map(|generic| Self::get_short_name(generic.trim())).collect::<Vec<String>>().join(", "));
short_name.push_str(
&generics
.split(',')
.map(|generic| Self::get_short_name(generic.trim()))
.collect::<Vec<String>>()
.join(", "),
);
short_name.push('>');
}
short_name

View file

@ -124,10 +124,7 @@ impl BaseRenderGraphBuilder for RenderGraph {
main_pass_node.add_camera(camera::CAMERA2D);
}
self.add_node(
node::MAIN_PASS,
main_pass_node
);
self.add_node(node::MAIN_PASS, main_pass_node);
self.add_node_edge(node::TEXTURE_COPY, node::MAIN_PASS)
.unwrap();

View file

@ -1,6 +1,6 @@
use crate::Camera;
use bevy_ecs::{Entity, Query, ResMut};
use std::collections::HashMap;
use bevy_ecs::{ResMut, Entity, Query};
#[derive(Default)]
pub struct ActiveCameras {

View file

@ -1,7 +1,7 @@
use crate::{draw::Draw, Camera};
use bevy_core::float_ord::FloatOrd;
use bevy_ecs::{Entity, Query};
use bevy_transform::prelude::Transform;
use bevy_ecs::{Query, Entity};
#[derive(Debug)]
pub struct VisibleEntity {
@ -15,7 +15,7 @@ pub struct VisibleEntities {
}
impl VisibleEntities {
pub fn iter(&self) -> impl DoubleEndedIterator<Item=&VisibleEntity> {
pub fn iter(&self) -> impl DoubleEndedIterator<Item = &VisibleEntity> {
self.value.iter()
}
}
@ -49,24 +49,17 @@ pub fn visible_entities_system(
};
if draw.is_transparent {
transparent_entities.push(VisibleEntity {
entity,
order,
})
transparent_entities.push(VisibleEntity { entity, order })
} else {
visible_entities.value.push(VisibleEntity {
entity,
order,
})
visible_entities.value.push(VisibleEntity { entity, order })
}
}
// sort opaque entities front-to-back
visible_entities.value.sort_by_key(|e| e.order);
// sort transparent entities front-to-back
transparent_entities.sort_by_key(|e|-e.order);
transparent_entities.sort_by_key(|e| -e.order);
visible_entities.value.extend(transparent_entities);
// TODO: check for big changes in visible entities len() vs capacity() (ex: 2x) and resize to prevent holding unneeded memory

View file

@ -1,10 +1,10 @@
use crate::{
base_render_graph, Camera,
OrthographicProjection, PerspectiveProjection, VisibleEntities, mesh::Mesh, draw::Draw, pipeline::RenderPipelines,
base_render_graph, draw::Draw, mesh::Mesh, pipeline::RenderPipelines, Camera,
OrthographicProjection, PerspectiveProjection, VisibleEntities,
};
use bevy_transform::components::{Rotation, Scale, Transform, Translation};
use bevy_ecs::Bundle;
use bevy_asset::Handle;
use bevy_ecs::Bundle;
use bevy_transform::components::{Rotation, Scale, Transform, Translation};
#[derive(Bundle, Default)]
pub struct MeshComponents {

View file

@ -34,8 +34,8 @@ use self::{
use base_render_graph::{BaseRenderGraphBuilder, BaseRenderGraphConfig};
use bevy_app::{AppBuilder, AppPlugin};
use bevy_asset::AddAsset;
use bevy_ecs::{IntoQuerySystem, ThreadLocalSystem};
use bevy_type_registry::RegisterType;
use bevy_ecs::{ThreadLocalSystem, IntoQuerySystem};
use draw::{clear_draw_system, Draw};
use mesh::mesh_resource_provider_system;
use pipeline::{draw_render_pipelines_system, RenderPipelines};
@ -114,7 +114,10 @@ impl AppPlugin for RenderPlugin {
visible_entities_system.system(),
)
// TODO: turn these "resource systems" into graph nodes and remove the RENDER_RESOURCE stage
.add_system_to_stage(stage::RENDER_RESOURCE, mesh_resource_provider_system.system())
.add_system_to_stage(
stage::RENDER_RESOURCE,
mesh_resource_provider_system.system(),
)
.add_system_to_stage(
stage::RENDER_RESOURCE,
Texture::texture_resource_system.system(),

View file

@ -38,11 +38,11 @@ pub enum BindType {
impl BindType {
pub fn get_uniform_size(&self) -> Option<u64> {
match self {
BindType::Uniform { properties, .. } => {
Some(properties.iter().fold(0, |total, property| {
total + property.get_size()
}))
}
BindType::Uniform { properties, .. } => Some(
properties
.iter()
.fold(0, |total, property| total + property.get_size()),
),
_ => None,
}
}

View file

@ -4,8 +4,8 @@ use crate::{
render_resource::RenderResourceBindings,
};
use bevy_asset::Handle;
use bevy_property::Properties;
use bevy_ecs::{Query, ResMut};
use bevy_property::Properties;
#[derive(Properties, Default, Clone)]
pub struct RenderPipeline {
pub pipeline: Handle<PipelineDescriptor>,

View file

@ -1,9 +1,9 @@
use super::{Edge, RenderGraphError, ResourceSlotInfo, ResourceSlots};
use crate::renderer::RenderContext;
use bevy_ecs::{Commands, Resources, System, World};
use downcast_rs::{impl_downcast, Downcast};
use std::{borrow::Cow, fmt::Debug};
use uuid::Uuid;
use bevy_ecs::{Resources, World, System, Commands};
#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub struct NodeId(Uuid);

View file

@ -8,7 +8,7 @@ use crate::{
};
use bevy_core::bytes::AsBytes;
use bevy_ecs::{IntoQuerySystem, Local, Query, Res, ResMut, Resources, System, World, Commands};
use bevy_ecs::{Commands, IntoQuerySystem, Local, Query, Res, ResMut, Resources, System, World};
use bevy_transform::prelude::*;
use std::borrow::Cow;
@ -45,11 +45,14 @@ impl Node for CameraNode {
impl SystemNode for CameraNode {
fn get_system(&self, commands: &mut Commands) -> Box<dyn System> {
let system = camera_node_system.system();
commands.insert_local_resource(system.id(), CameraNodeState {
camera_name: self.camera_name.clone(),
command_queue: self.command_queue.clone(),
camera_buffer: None,
});
commands.insert_local_resource(
system.id(),
CameraNodeState {
camera_name: self.camera_name.clone(),
command_queue: self.command_queue.clone(),
camera_buffer: None,
},
);
system
}
}
@ -117,12 +120,8 @@ pub fn camera_node_system(
);
let camera_buffer = state.camera_buffer.unwrap();
state.command_queue.copy_buffer_to_buffer(
tmp_buffer,
0,
camera_buffer,
0,
matrix_size as u64,
);
state
.command_queue
.copy_buffer_to_buffer(tmp_buffer, 0, camera_buffer, 0, matrix_size as u64);
state.command_queue.free_buffer(tmp_buffer);
}

View file

@ -11,7 +11,7 @@ use crate::{
};
use bevy_asset::{Assets, Handle};
use bevy_ecs::{IntoQuerySystem, Local, Query, Res, ResMut, Resources, System, World, Commands};
use bevy_ecs::{Commands, IntoQuerySystem, Local, Query, Res, ResMut, Resources, System, World};
use render_resource::{AssetRenderResourceBindings, BufferId, RenderResourceType, RenderResources};
use std::{collections::HashMap, marker::PhantomData, ops::DerefMut};

View file

@ -1,6 +1,7 @@
use crate::{
render_graph::{Node, ResourceSlots},
renderer::RenderContext, render_resource::SharedBuffers,
render_resource::SharedBuffers,
renderer::RenderContext,
};
use bevy_ecs::{Resources, World};

View file

@ -8,7 +8,6 @@ use bevy_app::{EventReader, Events};
use bevy_asset::{AssetEvent, Assets};
use bevy_ecs::{Resources, World};
#[derive(Default)]
pub struct TextureCopyNode {
pub texture_event_reader: EventReader<AssetEvent<Texture>>,

View file

@ -4,9 +4,9 @@ use crate::{
renderer::RenderContext,
};
use bevy_app::{EventReader, Events};
use bevy_ecs::{Resources, World};
use bevy_window::{WindowCreated, WindowReference, WindowResized, Windows};
use std::borrow::Cow;
use bevy_ecs::{Resources, World};
pub struct WindowSwapChainNode {
window_reference: WindowReference,

View file

@ -5,9 +5,9 @@ use crate::{
texture::TextureDescriptor,
};
use bevy_app::{EventReader, Events};
use bevy_ecs::{Resources, World};
use bevy_window::{WindowCreated, WindowReference, WindowResized, Windows};
use std::borrow::Cow;
use bevy_ecs::{Resources, World};
pub struct WindowTextureNode {
window_reference: WindowReference,

View file

@ -2,8 +2,8 @@ use super::{BufferId, BufferInfo, RenderResource, RenderResourceBinding};
use crate::{
render_graph::CommandQueue, render_resource::BufferUsage, renderer::RenderResourceContext,
};
use std::sync::{Arc, RwLock};
use bevy_ecs::Res;
use std::sync::{Arc, RwLock};
// TODO: Instead of allocating small "exact size" buffers each frame, this should use multiple large shared buffers and probably
// a long-living "cpu mapped" staging buffer. Im punting that for now because I don't know the best way to use wgpu's new async

View file

@ -120,8 +120,10 @@ impl RenderResourceContext for HeadlessRenderResourceContext {
fn get_buffer_info(&self, buffer: BufferId) -> Option<BufferInfo> {
self.buffer_info.read().unwrap().get(&buffer).cloned()
}
fn bind_group_descriptor_exists(&self, _bind_group_descriptor_id: BindGroupDescriptorId)
-> bool {
fn bind_group_descriptor_exists(
&self,
_bind_group_descriptor_id: BindGroupDescriptorId,
) -> bool {
false
}
}

View file

@ -2,7 +2,7 @@ use crate::{texture::Texture, RenderPipelines};
use bevy_asset::{Assets, Handle};
pub use bevy_derive::ShaderDefs;
use bevy_ecs::{Res, Query};
use bevy_ecs::{Query, Res};
pub trait ShaderDef {
fn is_defined(&self) -> bool;

View file

@ -5,9 +5,9 @@ use crate::{
};
use bevy_app::{EventReader, Events};
use bevy_asset::{AssetEvent, Assets, Handle};
use bevy_ecs::{Res, ResMut};
use glam::Vec2;
use std::collections::HashSet;
use bevy_ecs::{Res, ResMut};
pub const TEXTURE_ASSET_INDEX: usize = 0;
pub const SAMPLER_ASSET_INDEX: usize = 1;

View file

@ -27,7 +27,6 @@ impl From<&Texture> for TextureDescriptor {
}
}
impl Default for TextureDescriptor {
fn default() -> Self {
TextureDescriptor {
@ -43,5 +42,4 @@ impl Default for TextureDescriptor {
usage: TextureUsage::SAMPLED | TextureUsage::COPY_DST,
}
}
}

View file

@ -23,7 +23,7 @@ impl AppPlugin for ScenePlugin {
.init_resource::<SceneSpawner>()
.add_stage_after(stage::EVENT_UPDATE, SCENE_STAGE)
.add_system_to_stage(SCENE_STAGE, ThreadLocalSystem::new(scene_spawner_system));
// TODO: port scenes to bevy_ecs
// .add_system_to_stage_ecs(SCENE_STAGE, ThreadLocalSystem::new(scene_spawner_system));
// TODO: port scenes to bevy_ecs
// .add_system_to_stage_ecs(SCENE_STAGE, ThreadLocalSystem::new(scene_spawner_system));
}
}

View file

@ -1,10 +1,10 @@
use crate::{serde::SceneDeserializer, Scene};
use anyhow::Result;
use bevy_asset::AssetLoader;
use bevy_ecs::{FromResources, Resources};
use bevy_property::PropertyTypeRegistry;
use bevy_type_registry::TypeRegistry;
use serde::de::DeserializeSeed;
use bevy_ecs::{Resources, FromResources};
use std::{
path::Path,
sync::{Arc, RwLock},

View file

@ -1,4 +1,4 @@
use glam::{Vec3, Vec2};
use glam::{Vec2, Vec3};
#[derive(Debug)]
pub enum Collision {

View file

@ -3,13 +3,13 @@ use crate::{
TextureAtlasSprite, QUAD_HANDLE, SPRITE_SHEET_PIPELINE_HANDLE,
};
use bevy_asset::Handle;
use bevy_ecs::Bundle;
use bevy_render::{
draw::Draw,
mesh::Mesh,
pipeline::{DynamicBinding, PipelineSpecialization, RenderPipeline, RenderPipelines},
};
use bevy_transform::prelude::{Rotation, Scale, Transform, Translation};
use bevy_ecs::Bundle;
#[derive(Bundle)]
pub struct SpriteComponents {

View file

@ -1,7 +1,7 @@
pub mod collide_aabb;
mod color_material;
mod dynamic_texture_atlas_builder;
pub mod entity;
pub mod collide_aabb;
mod rect;
mod render;
mod sprite;
@ -18,12 +18,12 @@ pub use texture_atlas_builder::*;
use bevy_app::{stage, AppBuilder, AppPlugin};
use bevy_asset::{AddAsset, Assets, Handle};
use bevy_ecs::IntoQuerySystem;
use bevy_render::{
mesh::{shape, Mesh},
render_graph::RenderGraph,
shader::asset_shader_defs_system,
};
use bevy_ecs::IntoQuerySystem;
use glam::Vec2;
use sprite::sprite_system;

View file

@ -1,5 +1,6 @@
use crate::{ColorMaterial, TextureAtlas, TextureAtlasSprite, Sprite};
use crate::{ColorMaterial, Sprite, TextureAtlas, TextureAtlasSprite};
use bevy_asset::{Assets, Handle};
use bevy_ecs::Resources;
use bevy_render::{
base_render_graph,
pipeline::{state_descriptors::*, PipelineDescriptor},
@ -10,7 +11,6 @@ use bevy_render::{
shader::{Shader, ShaderStage, ShaderStages},
texture::TextureFormat,
};
use bevy_ecs::Resources;
pub const SPRITE_PIPELINE_HANDLE: Handle<PipelineDescriptor> =
Handle::from_u128(278534784033876544639935131272264723170);

View file

@ -1,12 +1,12 @@
use crate::ColorMaterial;
use bevy_asset::{Assets, Handle};
use bevy_core::bytes::Byteable;
use bevy_ecs::{Query, Res};
use bevy_render::{
render_resource::{RenderResource, RenderResources},
texture::Texture,
};
use glam::Vec2;
use bevy_ecs::{Res, Query};
#[repr(C)]
#[derive(Default, RenderResources, RenderResource)]

View file

@ -1,7 +1,7 @@
use bevy_ecs::Entity;
use bevy_property::Properties;
use shrinkwraprs::Shrinkwrap;
use smallvec::SmallVec;
use bevy_ecs::Entity;
#[derive(Shrinkwrap, Default, Clone, Properties, Debug)]
#[shrinkwrap(mutable)]

View file

@ -66,8 +66,7 @@ pub fn parent_update_system(
// Add to the parent's `Children` (either the real component, or
// `children_additions`).
log::trace!("Adding {:?} to it's new parent {:?}", entity, parent.0);
if let Ok(mut new_parent_children) = children_query.get_mut::<Children>(parent.0)
{
if let Ok(mut new_parent_children) = children_query.get_mut::<Children>(parent.0) {
// This is the parent
log::trace!(
" > The new parent {:?} already has a `Children`, adding to it.",
@ -110,8 +109,8 @@ pub fn hierarchy_maintenance_systems() -> Vec<Box<dyn System>> {
#[cfg(test)]
mod test {
use super::*;
use bevy_ecs::{Resources, World, Schedule};
use crate::build_systems;
use bevy_ecs::{Resources, Schedule, World};
#[test]
fn correct_children() {
@ -163,7 +162,6 @@ mod test {
// Parent `e1` to `e2`.
(*world.get_mut::<Parent>(children[0]).unwrap()).0 = children[1];
schedule.run(&mut world, &mut resources);
assert_eq!(

View file

@ -242,7 +242,10 @@ mod test {
Mat4::from_rotation_translation(r.0, t.0)
);
assert_eq!(
world.get::<LocalTransform>(translation_and_scale).unwrap().0,
world
.get::<LocalTransform>(translation_and_scale)
.unwrap()
.0,
Mat4::from_scale_rotation_translation(Vec3::new(s.0, s.0, s.0), Quat::default(), t.0)
);
assert_eq!(

View file

@ -201,7 +201,7 @@ pub fn transform_systems() -> Vec<Box<dyn System>> {
mod test {
use super::*;
use crate::math::{Mat4, Quat, Vec3};
use bevy_ecs::{Schedule, World, Resources};
use bevy_ecs::{Resources, Schedule, World};
#[test]
fn correct_world_transformation() {
@ -251,10 +251,7 @@ mod test {
Mat4::from_scale(Vec3::new(s.0, s.0, s.0))
);
assert_eq!(
world
.get::<Transform>(non_uniform_scale)
.unwrap()
.value,
world.get::<Transform>(non_uniform_scale).unwrap().value,
Mat4::from_scale(nus.0)
);
assert_eq!(
@ -265,24 +262,15 @@ mod test {
Mat4::from_rotation_translation(r.0, t.0)
);
assert_eq!(
world
.get::<Transform>(translation_and_scale)
.unwrap()
.value,
world.get::<Transform>(translation_and_scale).unwrap().value,
Mat4::from_scale_rotation_translation(Vec3::new(s.0, s.0, s.0), Quat::default(), t.0)
);
assert_eq!(
world
.get::<Transform>(translation_and_nus)
.unwrap()
.value,
world.get::<Transform>(translation_and_nus).unwrap().value,
Mat4::from_scale_rotation_translation(nus.0, Quat::default(), t.0)
);
assert_eq!(
world
.get::<Transform>(rotation_scale)
.unwrap()
.value,
world.get::<Transform>(rotation_scale).unwrap().value,
Mat4::from_scale_rotation_translation(Vec3::new(s.0, s.0, s.0), r.0, Vec3::default())
);
assert_eq!(

View file

@ -1,10 +1,14 @@
use super::Node;
use crate::{render::UI_PIPELINE_HANDLE, widget::Label};
use bevy_asset::Handle;
use bevy_render::{draw::Draw, mesh::Mesh, pipeline::{PipelineSpecialization, RenderPipelines, DynamicBinding, RenderPipeline}};
use bevy_sprite::{ColorMaterial, QUAD_HANDLE};
use bevy_transform::prelude::{Translation, Transform, Rotation, Scale};
use bevy_ecs::Bundle;
use bevy_render::{
draw::Draw,
mesh::Mesh,
pipeline::{DynamicBinding, PipelineSpecialization, RenderPipeline, RenderPipelines},
};
use bevy_sprite::{ColorMaterial, QUAD_HANDLE};
use bevy_transform::prelude::{Rotation, Scale, Transform, Translation};
#[derive(Bundle)]
pub struct UiComponents {

View file

@ -13,8 +13,8 @@ pub use render::*;
pub use ui_update_system::*;
use bevy_app::{stage, AppBuilder, AppPlugin};
use bevy_render::render_graph::RenderGraph;
use bevy_ecs::IntoQuerySystem;
use bevy_render::render_graph::RenderGraph;
use widget::Label;
#[derive(Default)]

View file

@ -1,6 +1,6 @@
use super::{Anchors, Margins};
use bevy_transform::prelude::Translation;
use bevy_render::render_resource::RenderResources;
use bevy_transform::prelude::Translation;
use glam::{Vec2, Vec3};
#[derive(Debug, Clone)]
@ -55,7 +55,8 @@ impl Node {
);
self.size = Vec2::new(quad_width, quad_height);
translation.0 = self.position.extend(0.0) + Vec3::new(quad_x, quad_y, z_offset) - (parent_size / 2.0).extend(0.0);
translation.0 = self.position.extend(0.0) + Vec3::new(quad_x, quad_y, z_offset)
- (parent_size / 2.0).extend(0.0);
}
fn compute_dimension_properties(

View file

@ -1,13 +1,17 @@
use crate::Node;
use bevy_asset::{Assets, Handle};
use bevy_ecs::Resources;
use bevy_render::{
base_render_graph,
pipeline::{state_descriptors::*, PipelineDescriptor},
render_graph::{nodes::{PassNode, CameraNode, RenderResourcesNode}, RenderGraph},
render_graph::{
nodes::{CameraNode, PassNode, RenderResourcesNode},
RenderGraph,
},
shader::{Shader, ShaderStage, ShaderStages},
texture::TextureFormat, ActiveCameras,
texture::TextureFormat,
ActiveCameras,
};
use crate::Node;
use bevy_ecs::Resources;
pub const UI_PIPELINE_HANDLE: Handle<PipelineDescriptor> =
Handle::from_u128(323432002226399387835192542539754486265);
@ -84,7 +88,9 @@ impl UiRenderGraphBuilder for RenderGraph {
self.add_node_edge(node::NODE, base_render_graph::node::MAIN_PASS)
.unwrap();
let mut active_cameras = resources.get_mut::<ActiveCameras>().unwrap();
let main_pass_node: &mut PassNode = self.get_node_mut(base_render_graph::node::MAIN_PASS).unwrap();
let main_pass_node: &mut PassNode = self
.get_node_mut(base_render_graph::node::MAIN_PASS)
.unwrap();
main_pass_node.add_camera(camera::UI_CAMERA);
active_cameras.add(camera::UI_CAMERA);
self

View file

@ -1,5 +1,6 @@
use crate::Node;
use bevy_asset::{Assets, Handle};
use bevy_ecs::{Query, Res, ResMut};
use bevy_render::{
draw::{Draw, DrawContext, Drawable},
render_resource::{AssetRenderResourceBindings, RenderResourceBindings},
@ -9,7 +10,6 @@ use bevy_render::{
use bevy_sprite::TextureAtlas;
use bevy_text::{DrawableText, Font, FontAtlasSet, TextStyle};
use bevy_transform::prelude::Transform;
use bevy_ecs::{Res, ResMut, Query};
pub struct Label {
pub text: String,

View file

@ -1,8 +1,8 @@
use crate::renderer::WgpuRenderResourceContext;
use bevy_app::{AppBuilder, AppPlugin};
use bevy_diagnostic::{Diagnostic, DiagnosticId, Diagnostics};
use bevy_ecs::{IntoQuerySystem, Res, ResMut};
use bevy_render::renderer::RenderResourceContext;
use bevy_ecs::{Res, ResMut, IntoQuerySystem};
#[derive(Default)]
pub struct WgpuResourceDiagnosticsPlugin;

View file

@ -10,12 +10,12 @@ pub use wgpu_renderer::*;
pub use wgpu_resources::*;
use bevy_app::{AppBuilder, AppPlugin};
use bevy_ecs::{IntoQuerySystem, Resources, ThreadLocalSystem, World};
use bevy_render::{
render_resource::{free_shared_buffers_system, SharedBuffers},
renderer::RenderResourceContext,
};
use renderer::WgpuRenderResourceContext;
use bevy_ecs::{World, Resources, ThreadLocalSystem, IntoQuerySystem};
#[derive(Default)]
pub struct WgpuPlugin;
@ -23,11 +23,14 @@ pub struct WgpuPlugin;
impl AppPlugin for WgpuPlugin {
fn build(&self, app: &mut AppBuilder) {
let render_system = wgpu_render_system(app.resources_mut());
app.add_system_to_stage(bevy_render::stage::RENDER, ThreadLocalSystem::new(render_system))
.add_system_to_stage(
bevy_render::stage::POST_RENDER,
free_shared_buffers_system.system(),
);
app.add_system_to_stage(
bevy_render::stage::RENDER,
ThreadLocalSystem::new(render_system),
)
.add_system_to_stage(
bevy_render::stage::POST_RENDER,
free_shared_buffers_system.system(),
);
}
}

View file

@ -1,4 +1,5 @@
use super::{WgpuRenderContext, WgpuRenderResourceContext};
use bevy_ecs::{Resources, World};
use bevy_render::{
render_graph::{Edge, NodeId, ResourceSlots, StageBorrow},
renderer::RenderResourceContext,
@ -7,7 +8,6 @@ use std::{
collections::HashMap,
sync::{Arc, RwLock},
};
use bevy_ecs::{Resources, World};
pub struct WgpuRenderGraphExecutor {
pub max_thread_count: usize,

View file

@ -56,7 +56,11 @@ impl<'a> RenderPass for WgpuRenderPass<'a> {
bind_group: BindGroupId,
dynamic_uniform_indices: Option<&[u32]>,
) {
if let Some(bind_group_info) = self.wgpu_resources.bind_groups.get(&bind_group_descriptor_id) {
if let Some(bind_group_info) = self
.wgpu_resources
.bind_groups
.get(&bind_group_descriptor_id)
{
if let Some(wgpu_bind_group) = bind_group_info.bind_groups.get(&bind_group) {
const EMPTY: &'static [u32] = &[];
let dynamic_uniform_indices =

View file

@ -1,12 +1,12 @@
use crate::renderer::{WgpuRenderGraphExecutor, WgpuRenderResourceContext};
use bevy_app::{EventReader, Events};
use bevy_ecs::{Resources, World};
use bevy_render::{
render_graph::{DependentNodeStager, RenderGraph, RenderGraphStager},
renderer::RenderResourceContext,
};
use bevy_window::{WindowCreated, WindowResized, Windows};
use std::{ops::Deref, sync::Arc};
use bevy_ecs::{World, Resources};
pub struct WgpuRenderer {
pub instance: wgpu::Instance,
pub device: Arc<wgpu::Device>,

View file

@ -36,8 +36,10 @@ impl AppPlugin for WindowPlugin {
.init_resource::<Windows>();
if let Some(ref primary_window_descriptor) = self.primary_window {
let mut create_window_event =
app.resources_mut().get_mut::<Events<CreateWindow>>().unwrap();
let mut create_window_event = app
.resources_mut()
.get_mut::<Events<CreateWindow>>()
.unwrap();
create_window_event.send(CreateWindow {
id: WindowId::new(),
descriptor: primary_window_descriptor.clone(),

View file

@ -10,7 +10,6 @@ impl Default for WindowReference {
fn default() -> Self {
WindowReference::Primary
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]

View file

@ -8,6 +8,7 @@ use bevy_input::{
};
use bevy_app::{App, AppBuilder, AppExit, AppPlugin, EventReader, Events};
use bevy_ecs::Resources;
use bevy_window::{
CreateWindow, CursorMoved, Window, WindowCloseRequested, WindowCreated, WindowResized, Windows,
};
@ -17,7 +18,6 @@ use winit::{
event::{DeviceEvent, WindowEvent},
event_loop::{ControlFlow, EventLoop, EventLoopWindowTarget},
};
use bevy_ecs::Resources;
#[derive(Default)]
pub struct WinitPlugin;

View file

@ -11,10 +11,7 @@ fn main() {
}
/// rotates the parent, which will result in the child also rotating
fn rotator_system(
time: Res<Time>,
mut query: Query<(&Rotator, &mut Rotation)>,
) {
fn rotator_system(time: Res<Time>, mut query: Query<(&Rotator, &mut Rotation)>) {
for (_rotator, rotation) in &mut query.iter() {
rotation.0 = rotation.0 * Quat::from_rotation_x(3.0 * time.delta_seconds);
}

View file

@ -172,19 +172,13 @@ fn paddle_movement_system(
}
}
fn ball_movement_system(
time: Res<Time>,
mut ball_query: Query<(&Ball, &mut Translation)>,
) {
fn ball_movement_system(time: Res<Time>, mut ball_query: Query<(&Ball, &mut Translation)>) {
for (ball, translation) in &mut ball_query.iter() {
translation.0 += ball.velocity * time.delta_seconds;
}
}
fn scoreboard_system(
scoreboard: Res<Scoreboard>,
mut query: Query<&mut Label>,
) {
fn scoreboard_system(scoreboard: Res<Scoreboard>, mut query: Query<&mut Label>) {
for mut label in &mut query.iter() {
label.text = format!("Score: {}", scoreboard.score);
}

View file

@ -1,5 +1,8 @@
use bevy::prelude::*;
use bevy_render::{pipeline::{PipelineSpecialization, RenderPipeline, DynamicBinding}, base_render_graph};
use bevy_render::{
base_render_graph,
pipeline::{DynamicBinding, PipelineSpecialization, RenderPipeline},
};
fn main() {
App::build()

View file

@ -1,5 +1,8 @@
use bevy::{prelude::*, render::shader};
use bevy_render::{pipeline::{PipelineSpecialization, RenderPipeline, DynamicBinding}, base_render_graph};
use bevy_render::{
base_render_graph,
pipeline::{DynamicBinding, PipelineSpecialization, RenderPipeline},
};
fn main() {
App::build()

View file

@ -12,10 +12,7 @@ fn main() {
.run();
}
fn text_update_system(
diagnostics: Res<Diagnostics>,
mut query: Query<&mut Label>,
) {
fn text_update_system(diagnostics: Res<Diagnostics>, mut query: Query<&mut Label>) {
for label in &mut query.iter() {
if let Some(fps) = diagnostics.get(FrameTimeDiagnosticsPlugin::FPS) {
if let Some(average) = fps.average() {

View file

@ -12,7 +12,7 @@ pub use crate::{
ecs::{
Bundle, Commands, Component, Entity, FromResources, IntoForEachSystem, IntoQuerySystem,
Local, Query, Ref, RefMut, Res, ResMut, Resource, Resources, System, ThreadLocalSystem,
World, WorldBuilderSource
World, WorldBuilderSource,
},
input::{keyboard::KeyCode, mouse::MouseButton, Input},
math::{self, Mat3, Mat4, Quat, Vec2, Vec3, Vec4},