mirror of
https://github.com/bevyengine/bevy
synced 2024-11-28 23:50:20 +00:00
cargo fmt
This commit is contained in:
parent
db3191e47b
commit
c81ab99dac
101 changed files with 432 additions and 403 deletions
|
@ -22,7 +22,8 @@ impl App {
|
||||||
|
|
||||||
pub fn run(mut self) {
|
pub fn run(mut self) {
|
||||||
self.startup_schedule.initialize(&mut self.resources);
|
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() {
|
if let Some(run) = self.runner.take() {
|
||||||
run(self)
|
run(self)
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@ use crate::{
|
||||||
use bevy_ecs::{FromResources, IntoQuerySystem, Resources, System, World};
|
use bevy_ecs::{FromResources, IntoQuerySystem, Resources, System, World};
|
||||||
|
|
||||||
pub struct AppBuilder {
|
pub struct AppBuilder {
|
||||||
pub app: App,
|
pub app: App,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for AppBuilder {
|
impl Default for AppBuilder {
|
||||||
|
|
|
@ -2,4 +2,4 @@
|
||||||
pub const STARTUP: &str = "startup";
|
pub const STARTUP: &str = "startup";
|
||||||
|
|
||||||
/// Name of app stage that runs once after startup
|
/// Name of app stage that runs once after startup
|
||||||
pub const POST_STARTUP: &str = "post_startup";
|
pub const POST_STARTUP: &str = "post_startup";
|
||||||
|
|
|
@ -3,6 +3,7 @@ use crate::{
|
||||||
Assets, Handle, HandleId, LoadRequest,
|
Assets, Handle, HandleId, LoadRequest,
|
||||||
};
|
};
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
|
use bevy_ecs::{Res, Resource, Resources};
|
||||||
use crossbeam_channel::TryRecvError;
|
use crossbeam_channel::TryRecvError;
|
||||||
use std::{
|
use std::{
|
||||||
collections::{HashMap, HashSet},
|
collections::{HashMap, HashSet},
|
||||||
|
@ -12,7 +13,6 @@ use std::{
|
||||||
thread,
|
thread,
|
||||||
};
|
};
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
use bevy_ecs::{Res, Resources, Resource};
|
|
||||||
|
|
||||||
pub type AssetVersion = usize;
|
pub type AssetVersion = usize;
|
||||||
#[derive(Error, Debug)]
|
#[derive(Error, Debug)]
|
||||||
|
|
|
@ -3,9 +3,9 @@ use crate::{
|
||||||
Handle, HandleId,
|
Handle, HandleId,
|
||||||
};
|
};
|
||||||
use bevy_app::{AppBuilder, Events};
|
use bevy_app::{AppBuilder, Events};
|
||||||
|
use bevy_ecs::{FromResources, IntoQuerySystem, ResMut, Resource};
|
||||||
use bevy_type_registry::RegisterType;
|
use bevy_type_registry::RegisterType;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use bevy_ecs::{Resource, ResMut, IntoQuerySystem, FromResources};
|
|
||||||
|
|
||||||
pub enum AssetEvent<T: Resource> {
|
pub enum AssetEvent<T: Resource> {
|
||||||
Created { handle: Handle<T> },
|
Created { handle: Handle<T> },
|
||||||
|
|
|
@ -13,8 +13,8 @@ pub use load_request::*;
|
||||||
pub use loader::*;
|
pub use loader::*;
|
||||||
|
|
||||||
use bevy_app::{AppBuilder, AppPlugin};
|
use bevy_app::{AppBuilder, AppPlugin};
|
||||||
use bevy_type_registry::RegisterType;
|
|
||||||
use bevy_ecs::IntoQuerySystem;
|
use bevy_ecs::IntoQuerySystem;
|
||||||
|
use bevy_type_registry::RegisterType;
|
||||||
|
|
||||||
pub mod stage {
|
pub mod stage {
|
||||||
pub const LOAD_ASSETS: &str = "load_assets";
|
pub const LOAD_ASSETS: &str = "load_assets";
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
use crate::{AssetServer, AssetVersion, Assets, Handle, LoadState};
|
use crate::{AssetServer, AssetVersion, Assets, Handle, LoadState};
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
|
use bevy_ecs::{Res, ResMut, Resource};
|
||||||
use crossbeam_channel::{Receiver, Sender, TryRecvError};
|
use crossbeam_channel::{Receiver, Sender, TryRecvError};
|
||||||
use fs::File;
|
use fs::File;
|
||||||
use io::Read;
|
use io::Read;
|
||||||
|
@ -8,7 +9,6 @@ use std::{
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
};
|
};
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
use bevy_ecs::{ResMut, Res, Resource};
|
|
||||||
|
|
||||||
#[derive(Error, Debug)]
|
#[derive(Error, Debug)]
|
||||||
pub enum AssetLoadError {
|
pub enum AssetLoadError {
|
||||||
|
|
|
@ -93,7 +93,7 @@ unsafe impl Byteable for f32 {}
|
||||||
unsafe impl Byteable for f64 {}
|
unsafe impl Byteable for f64 {}
|
||||||
unsafe impl Byteable for Vec2 {}
|
unsafe impl Byteable for Vec2 {}
|
||||||
// NOTE: Vec3 actually takes up the size of 4 floats / 16 bytes due to SIMD. This is actually convenient because GLSL
|
// NOTE: Vec3 actually takes up the size of 4 floats / 16 bytes due to SIMD. This is actually convenient because GLSL
|
||||||
// uniform buffer objects pad Vec3s to be 16 bytes.
|
// uniform buffer objects pad Vec3s to be 16 bytes.
|
||||||
unsafe impl Byteable for Vec3 {}
|
unsafe impl Byteable for Vec3 {}
|
||||||
unsafe impl Byteable for Vec4 {}
|
unsafe impl Byteable for Vec4 {}
|
||||||
|
|
||||||
|
@ -171,8 +171,8 @@ where
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
|
||||||
use super::{FromBytes, Bytes};
|
use super::{Bytes, FromBytes};
|
||||||
use glam::{Vec3, Vec2, Vec4, Mat4};
|
use glam::{Mat4, Vec2, Vec3, Vec4};
|
||||||
|
|
||||||
fn test_round_trip<T: Bytes + FromBytes + std::fmt::Debug + PartialEq>(value: T) {
|
fn test_round_trip<T: Bytes + FromBytes + std::fmt::Debug + PartialEq>(value: T) {
|
||||||
let mut bytes = vec![0; value.byte_len()];
|
let mut bytes = vec![0; value.byte_len()];
|
||||||
|
|
|
@ -46,4 +46,4 @@ impl Neg for FloatOrd {
|
||||||
fn neg(self) -> Self::Output {
|
fn neg(self) -> Self::Output {
|
||||||
FloatOrd(-self.0)
|
FloatOrd(-self.0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,16 +4,16 @@ pub mod time;
|
||||||
pub mod transform;
|
pub mod transform;
|
||||||
|
|
||||||
use bevy_app::{stage, startup_stage, AppBuilder, AppPlugin};
|
use bevy_app::{stage, startup_stage, AppBuilder, AppPlugin};
|
||||||
|
use bevy_ecs::IntoQuerySystem;
|
||||||
use bevy_transform::{
|
use bevy_transform::{
|
||||||
|
build_systems,
|
||||||
components::{
|
components::{
|
||||||
Children, LocalTransform, NonUniformScale, Rotation, Scale, Transform, Translation,
|
Children, LocalTransform, NonUniformScale, Rotation, Scale, Transform, Translation,
|
||||||
},
|
},
|
||||||
build_systems,
|
|
||||||
};
|
};
|
||||||
use bevy_type_registry::RegisterType;
|
use bevy_type_registry::RegisterType;
|
||||||
use glam::{Mat3, Mat4, Quat, Vec2, Vec3};
|
use glam::{Mat3, Mat4, Quat, Vec2, Vec3};
|
||||||
use time::{time_system, timer_system, Time, Timer};
|
use time::{time_system, timer_system, Time, Timer};
|
||||||
use bevy_ecs::IntoQuerySystem;
|
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct CorePlugin;
|
pub struct CorePlugin;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use std::time::{Duration, Instant};
|
|
||||||
use bevy_ecs::ResMut;
|
use bevy_ecs::ResMut;
|
||||||
|
use std::time::{Duration, Instant};
|
||||||
|
|
||||||
pub struct Time {
|
pub struct Time {
|
||||||
pub delta: Duration,
|
pub delta: Duration,
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use crate::time::Time;
|
use crate::time::Time;
|
||||||
|
use bevy_ecs::{Query, Res};
|
||||||
use bevy_property::Properties;
|
use bevy_property::Properties;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use bevy_ecs::{Query, Res};
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, Default, Properties)]
|
#[derive(Clone, Debug, Default, Properties)]
|
||||||
pub struct Timer {
|
pub struct Timer {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use glam::{Vec3, Mat4};
|
use glam::{Mat4, Vec3};
|
||||||
|
|
||||||
pub trait FaceToward {
|
pub trait FaceToward {
|
||||||
fn face_toward(eye: Vec3, center: Vec3, up: Vec3) -> Self;
|
fn face_toward(eye: Vec3, center: Vec3, up: Vec3) -> Self;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
mod hierarchy;
|
|
||||||
mod face_toward;
|
mod face_toward;
|
||||||
|
mod hierarchy;
|
||||||
|
|
||||||
pub use hierarchy::*;
|
|
||||||
pub use face_toward::*;
|
pub use face_toward::*;
|
||||||
|
pub use hierarchy::*;
|
||||||
|
|
|
@ -17,7 +17,6 @@ impl Default for DiagnosticId {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
DiagnosticId(Uuid::new_v4())
|
DiagnosticId(Uuid::new_v4())
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use crate::{Diagnostic, DiagnosticId, Diagnostics};
|
use crate::{Diagnostic, DiagnosticId, Diagnostics};
|
||||||
use bevy_app::AppPlugin;
|
use bevy_app::AppPlugin;
|
||||||
use bevy_core::time::Time;
|
use bevy_core::time::Time;
|
||||||
use bevy_ecs::{Res, ResMut, IntoQuerySystem};
|
use bevy_ecs::{IntoQuerySystem, Res, ResMut};
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct FrameTimeDiagnosticsPlugin;
|
pub struct FrameTimeDiagnosticsPlugin;
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
use super::{Diagnostic, DiagnosticId, Diagnostics};
|
use super::{Diagnostic, DiagnosticId, Diagnostics};
|
||||||
use bevy_app::{stage, AppPlugin};
|
use bevy_app::{stage, AppPlugin};
|
||||||
use bevy_core::time::{Time, Timer};
|
use bevy_core::time::{Time, Timer};
|
||||||
|
use bevy_ecs::{IntoQuerySystem, Res, ResMut};
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use bevy_ecs::{Res, ResMut, IntoQuerySystem};
|
|
||||||
|
|
||||||
pub struct PrintDiagnosticsPlugin {
|
pub struct PrintDiagnosticsPlugin {
|
||||||
pub debug: bool,
|
pub debug: bool,
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
// modified by Bevy contributors
|
// modified by Bevy contributors
|
||||||
|
|
||||||
use bencher::{benchmark_group, benchmark_main, Bencher};
|
use bencher::{benchmark_group, benchmark_main, Bencher};
|
||||||
use hecs::*;
|
use hecs::*;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// modified by Bevy contributors
|
// modified by Bevy contributors
|
||||||
|
|
||||||
//! One way to the contents of an entity, as you might do for debugging. A similar pattern could
|
//! One way to the contents of an entity, as you might do for debugging. A similar pattern could
|
||||||
//! also be useful for serialization, or other row-oriented generic operations.
|
//! also be useful for serialization, or other row-oriented generic operations.
|
||||||
|
|
|
@ -12,15 +12,15 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
// modified by Bevy contributors
|
// modified by Bevy contributors
|
||||||
|
|
||||||
extern crate proc_macro;
|
extern crate proc_macro;
|
||||||
|
|
||||||
use proc_macro::TokenStream;
|
use proc_macro::TokenStream;
|
||||||
use proc_macro2::Span;
|
use proc_macro2::Span;
|
||||||
|
use proc_macro_crate::crate_name;
|
||||||
use quote::quote;
|
use quote::quote;
|
||||||
use syn::{parse_macro_input, DeriveInput, Path};
|
use syn::{parse_macro_input, DeriveInput, Path};
|
||||||
use proc_macro_crate::crate_name;
|
|
||||||
|
|
||||||
/// Implement `Bundle` for a monomorphic struct
|
/// Implement `Bundle` for a monomorphic struct
|
||||||
///
|
///
|
||||||
|
|
|
@ -12,21 +12,24 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
// modified by Bevy contributors
|
// modified by Bevy contributors
|
||||||
|
|
||||||
use crate::alloc::alloc::{alloc, dealloc, Layout};
|
use crate::alloc::{
|
||||||
use crate::alloc::boxed::Box;
|
alloc::{alloc, dealloc, Layout},
|
||||||
use crate::alloc::{vec, vec::Vec};
|
boxed::Box,
|
||||||
use core::any::{type_name, TypeId};
|
vec,
|
||||||
use core::cell::UnsafeCell;
|
vec::Vec,
|
||||||
use core::mem;
|
};
|
||||||
use core::ptr::{self, NonNull};
|
use core::{
|
||||||
|
any::{type_name, TypeId},
|
||||||
|
cell::UnsafeCell,
|
||||||
|
mem,
|
||||||
|
ptr::{self, NonNull},
|
||||||
|
};
|
||||||
|
|
||||||
use hashbrown::HashMap;
|
use hashbrown::HashMap;
|
||||||
|
|
||||||
use crate::borrow::AtomicBorrow;
|
use crate::{borrow::AtomicBorrow, query::Fetch, Access, Component, Query};
|
||||||
use crate::query::Fetch;
|
|
||||||
use crate::{Access, Component, Query};
|
|
||||||
|
|
||||||
/// A collection of entities having the same component types
|
/// A collection of entities having the same component types
|
||||||
///
|
///
|
||||||
|
@ -45,7 +48,7 @@ pub struct Archetype {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Archetype {
|
impl Archetype {
|
||||||
#[allow(missing_docs)]
|
#[allow(missing_docs)]
|
||||||
pub fn new(types: Vec<TypeInfo>) -> Self {
|
pub fn new(types: Vec<TypeInfo>) -> Self {
|
||||||
debug_assert!(
|
debug_assert!(
|
||||||
types.windows(2).all(|x| x[0] < x[1]),
|
types.windows(2).all(|x| x[0] < x[1]),
|
||||||
|
@ -62,7 +65,7 @@ impl Archetype {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(missing_docs)]
|
#[allow(missing_docs)]
|
||||||
pub fn with_grow(types: Vec<TypeInfo>, grow_size: u32) -> Self {
|
pub fn with_grow(types: Vec<TypeInfo>, grow_size: u32) -> Self {
|
||||||
debug_assert!(
|
debug_assert!(
|
||||||
types.windows(2).all(|x| x[0] < x[1]),
|
types.windows(2).all(|x| x[0] < x[1]),
|
||||||
|
@ -102,7 +105,7 @@ impl Archetype {
|
||||||
self.state.contains_key(&id)
|
self.state.contains_key(&id)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(missing_docs)]
|
#[allow(missing_docs)]
|
||||||
pub fn get<T: Component>(&self) -> Option<NonNull<T>> {
|
pub fn get<T: Component>(&self) -> Option<NonNull<T>> {
|
||||||
let state = self.state.get(&TypeId::of::<T>())?;
|
let state = self.state.get(&TypeId::of::<T>())?;
|
||||||
Some(unsafe {
|
Some(unsafe {
|
||||||
|
@ -112,7 +115,7 @@ impl Archetype {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(missing_docs)]
|
#[allow(missing_docs)]
|
||||||
pub fn borrow<T: Component>(&self) {
|
pub fn borrow<T: Component>(&self) {
|
||||||
if self
|
if self
|
||||||
.state
|
.state
|
||||||
|
@ -123,7 +126,7 @@ impl Archetype {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(missing_docs)]
|
#[allow(missing_docs)]
|
||||||
pub fn borrow_mut<T: Component>(&self) {
|
pub fn borrow_mut<T: Component>(&self) {
|
||||||
if self
|
if self
|
||||||
.state
|
.state
|
||||||
|
@ -134,27 +137,27 @@ impl Archetype {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(missing_docs)]
|
#[allow(missing_docs)]
|
||||||
pub fn release<T: Component>(&self) {
|
pub fn release<T: Component>(&self) {
|
||||||
if let Some(x) = self.state.get(&TypeId::of::<T>()) {
|
if let Some(x) = self.state.get(&TypeId::of::<T>()) {
|
||||||
x.borrow.release();
|
x.borrow.release();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(missing_docs)]
|
#[allow(missing_docs)]
|
||||||
pub fn release_mut<T: Component>(&self) {
|
pub fn release_mut<T: Component>(&self) {
|
||||||
if let Some(x) = self.state.get(&TypeId::of::<T>()) {
|
if let Some(x) = self.state.get(&TypeId::of::<T>()) {
|
||||||
x.borrow.release_mut();
|
x.borrow.release_mut();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(missing_docs)]
|
#[allow(missing_docs)]
|
||||||
pub fn len(&self) -> u32 {
|
pub fn len(&self) -> u32 {
|
||||||
self.len
|
self.len
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(missing_docs)]
|
#[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)
|
self.entities.iter().take(self.len as usize)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -166,7 +169,7 @@ impl Archetype {
|
||||||
self.entities[index as usize]
|
self.entities[index as usize]
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(missing_docs)]
|
#[allow(missing_docs)]
|
||||||
pub fn types(&self) -> &[TypeInfo] {
|
pub fn types(&self) -> &[TypeInfo] {
|
||||||
&self.types
|
&self.types
|
||||||
}
|
}
|
||||||
|
@ -312,14 +315,8 @@ impl Archetype {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(missing_docs)]
|
#[allow(missing_docs)]
|
||||||
pub unsafe fn put_dynamic(
|
pub unsafe fn put_dynamic(&mut self, component: *mut u8, ty: TypeId, size: usize, index: u32) {
|
||||||
&mut self,
|
|
||||||
component: *mut u8,
|
|
||||||
ty: TypeId,
|
|
||||||
size: usize,
|
|
||||||
index: u32,
|
|
||||||
) {
|
|
||||||
let ptr = self
|
let ptr = self
|
||||||
.get_dynamic(ty, size, index)
|
.get_dynamic(ty, size, index)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
@ -387,12 +384,12 @@ impl TypeInfo {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(missing_docs)]
|
#[allow(missing_docs)]
|
||||||
pub fn id(&self) -> TypeId {
|
pub fn id(&self) -> TypeId {
|
||||||
self.id
|
self.id
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(missing_docs)]
|
#[allow(missing_docs)]
|
||||||
pub fn layout(&self) -> Layout {
|
pub fn layout(&self) -> Layout {
|
||||||
self.layout
|
self.layout
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,14 +12,15 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
// modified by Bevy contributors
|
// modified by Bevy contributors
|
||||||
|
|
||||||
use core::ops::{Deref, DerefMut};
|
use core::{
|
||||||
use core::ptr::NonNull;
|
ops::{Deref, DerefMut},
|
||||||
use core::sync::atomic::{AtomicUsize, Ordering};
|
ptr::NonNull,
|
||||||
|
sync::atomic::{AtomicUsize, Ordering},
|
||||||
|
};
|
||||||
|
|
||||||
use crate::archetype::Archetype;
|
use crate::{archetype::Archetype, Component, MissingComponent};
|
||||||
use crate::{Component, MissingComponent};
|
|
||||||
|
|
||||||
pub struct AtomicBorrow(AtomicUsize);
|
pub struct AtomicBorrow(AtomicUsize);
|
||||||
|
|
||||||
|
@ -70,11 +71,8 @@ pub struct Ref<'a, T: Component> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, T: Component> Ref<'a, T> {
|
impl<'a, T: Component> Ref<'a, T> {
|
||||||
#[allow(missing_docs)]
|
#[allow(missing_docs)]
|
||||||
pub unsafe fn new(
|
pub unsafe fn new(archetype: &'a Archetype, index: u32) -> Result<Self, MissingComponent> {
|
||||||
archetype: &'a Archetype,
|
|
||||||
index: u32,
|
|
||||||
) -> Result<Self, MissingComponent> {
|
|
||||||
let target = NonNull::new_unchecked(
|
let target = NonNull::new_unchecked(
|
||||||
archetype
|
archetype
|
||||||
.get::<T>()
|
.get::<T>()
|
||||||
|
@ -110,11 +108,8 @@ pub struct RefMut<'a, T: Component> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, T: Component> RefMut<'a, T> {
|
impl<'a, T: Component> RefMut<'a, T> {
|
||||||
#[allow(missing_docs)]
|
#[allow(missing_docs)]
|
||||||
pub unsafe fn new(
|
pub unsafe fn new(archetype: &'a Archetype, index: u32) -> Result<Self, MissingComponent> {
|
||||||
archetype: &'a Archetype,
|
|
||||||
index: u32,
|
|
||||||
) -> Result<Self, MissingComponent> {
|
|
||||||
let target = NonNull::new_unchecked(
|
let target = NonNull::new_unchecked(
|
||||||
archetype
|
archetype
|
||||||
.get::<T>()
|
.get::<T>()
|
||||||
|
|
|
@ -12,15 +12,16 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
// modified by Bevy contributors
|
// modified by Bevy contributors
|
||||||
|
|
||||||
use crate::alloc::{vec, vec::Vec};
|
use crate::alloc::{vec, vec::Vec};
|
||||||
use core::any::{type_name, TypeId};
|
use core::{
|
||||||
use core::ptr::NonNull;
|
any::{type_name, TypeId},
|
||||||
use core::{fmt, mem};
|
fmt, mem,
|
||||||
|
ptr::NonNull,
|
||||||
|
};
|
||||||
|
|
||||||
use crate::archetype::TypeInfo;
|
use crate::{archetype::TypeInfo, Component};
|
||||||
use crate::Component;
|
|
||||||
|
|
||||||
/// A dynamically typed collection of components
|
/// A dynamically typed collection of components
|
||||||
pub trait DynamicBundle {
|
pub trait DynamicBundle {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// modified by Bevy contributors
|
// modified by Bevy contributors
|
||||||
|
|
||||||
use core::fmt;
|
use core::fmt;
|
||||||
use hashbrown::HashMap;
|
use hashbrown::HashMap;
|
||||||
|
@ -67,7 +67,9 @@ impl Entities {
|
||||||
|
|
||||||
/// Access the location storage of an entity
|
/// Access the location storage of an entity
|
||||||
pub fn get_mut(&mut self, entity: Entity) -> Result<&mut Location, NoSuchEntity> {
|
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
|
/// Access the location storage of an entity
|
||||||
|
@ -76,7 +78,10 @@ impl Entities {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get(&self, entity: Entity) -> Result<Location, NoSuchEntity> {
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,19 +12,23 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
// modified by Bevy contributors
|
// modified by Bevy contributors
|
||||||
|
|
||||||
use crate::alloc::alloc::{alloc, dealloc, Layout};
|
use crate::alloc::{
|
||||||
use crate::alloc::boxed::Box;
|
alloc::{alloc, dealloc, Layout},
|
||||||
use crate::alloc::{vec, vec::Vec};
|
boxed::Box,
|
||||||
use core::any::TypeId;
|
vec,
|
||||||
use core::mem::{self, MaybeUninit};
|
vec::Vec,
|
||||||
use core::ptr;
|
};
|
||||||
|
use core::{
|
||||||
|
any::TypeId,
|
||||||
|
mem::{self, MaybeUninit},
|
||||||
|
ptr,
|
||||||
|
};
|
||||||
|
|
||||||
use hashbrown::HashSet;
|
use hashbrown::HashSet;
|
||||||
|
|
||||||
use crate::archetype::TypeInfo;
|
use crate::{archetype::TypeInfo, Component, DynamicBundle};
|
||||||
use crate::{Component, DynamicBundle};
|
|
||||||
|
|
||||||
/// Helper for incrementally constructing a bundle of components with dynamic component types
|
/// Helper for incrementally constructing a bundle of components with dynamic component types
|
||||||
///
|
///
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
// modified by Bevy contributors
|
// modified by Bevy contributors
|
||||||
|
|
||||||
//! A handy ECS
|
//! A handy ECS
|
||||||
//!
|
//!
|
||||||
|
@ -71,14 +71,14 @@ mod entities;
|
||||||
mod entity_builder;
|
mod entity_builder;
|
||||||
mod query;
|
mod query;
|
||||||
mod query_one;
|
mod query_one;
|
||||||
mod world;
|
|
||||||
#[cfg(feature = "serde")]
|
#[cfg(feature = "serde")]
|
||||||
mod serde;
|
mod serde;
|
||||||
|
mod world;
|
||||||
|
|
||||||
pub use archetype::Archetype;
|
pub use archetype::Archetype;
|
||||||
pub use borrow::{EntityRef, Ref, RefMut};
|
pub use borrow::{EntityRef, Ref, RefMut};
|
||||||
pub use bundle::{Bundle, DynamicBundle, MissingComponent};
|
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 entity_builder::{BuiltEntity, EntityBuilder};
|
||||||
pub use query::{Access, BatchedIter, Query, QueryBorrow, QueryIter, With, Without};
|
pub use query::{Access, BatchedIter, Query, QueryBorrow, QueryIter, With, Without};
|
||||||
pub use query_one::QueryOne;
|
pub use query_one::QueryOne;
|
||||||
|
@ -94,4 +94,4 @@ pub use lazy_static;
|
||||||
pub use query::Fetch;
|
pub use query::Fetch;
|
||||||
|
|
||||||
#[cfg(feature = "macros")]
|
#[cfg(feature = "macros")]
|
||||||
pub use hecs_macros::Bundle;
|
pub use hecs_macros::Bundle;
|
||||||
|
|
|
@ -12,13 +12,11 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
// modified by Bevy contributors
|
// modified by Bevy contributors
|
||||||
|
|
||||||
use core::marker::PhantomData;
|
use core::{marker::PhantomData, ptr::NonNull};
|
||||||
use core::ptr::NonNull;
|
|
||||||
|
|
||||||
use crate::archetype::Archetype;
|
use crate::{archetype::Archetype, Component, Entity};
|
||||||
use crate::{Entity, Component};
|
|
||||||
|
|
||||||
/// A collection of component types to fetch from a `World`
|
/// A collection of component types to fetch from a `World`
|
||||||
pub trait Query {
|
pub trait Query {
|
||||||
|
@ -520,9 +518,7 @@ struct ChunkIter<Q: Query> {
|
||||||
|
|
||||||
impl<Q: Query> ChunkIter<Q> {
|
impl<Q: Query> ChunkIter<Q> {
|
||||||
#[inline]
|
#[inline]
|
||||||
unsafe fn next<'a, 'w>(
|
unsafe fn next<'a, 'w>(&mut self) -> Option<<Q::Fetch as Fetch<'a>>::Item> {
|
||||||
&mut self,
|
|
||||||
) -> Option<<Q::Fetch as Fetch<'a>>::Item> {
|
|
||||||
if self.len == 0 {
|
if self.len == 0 {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
// modified by Bevy contributors
|
// modified by Bevy contributors
|
||||||
|
|
||||||
use core::marker::PhantomData;
|
use core::marker::PhantomData;
|
||||||
|
|
||||||
use crate::query::{Fetch, With, Without};
|
use crate::{
|
||||||
use crate::{Archetype, Component, Query};
|
query::{Fetch, With, Without},
|
||||||
|
Archetype, Component, Query,
|
||||||
|
};
|
||||||
|
|
||||||
/// A borrow of a `World` sufficient to execute the query `Q` on a single entity
|
/// A borrow of a `World` sufficient to execute the query `Q` on a single entity
|
||||||
pub struct QueryOne<'a, Q: Query> {
|
pub struct QueryOne<'a, Q: Query> {
|
||||||
|
@ -20,7 +22,7 @@ impl<'a, Q: Query> QueryOne<'a, Q> {
|
||||||
///
|
///
|
||||||
/// `index` must be in-bounds for `archetype`
|
/// `index` must be in-bounds for `archetype`
|
||||||
pub(crate) unsafe fn new(archetype: &'a Archetype, index: u32) -> Self {
|
pub(crate) unsafe fn new(archetype: &'a Archetype, index: u32) -> Self {
|
||||||
Self {
|
Self {
|
||||||
archetype,
|
archetype,
|
||||||
index,
|
index,
|
||||||
borrowed: false,
|
borrowed: false,
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// modified by Bevy contributors
|
// modified by Bevy contributors
|
||||||
|
|
||||||
use crate::entities::Entity;
|
use crate::entities::Entity;
|
||||||
use serde::{Serialize, Serializer};
|
use serde::{Serialize, Serializer};
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
// modified by Bevy contributors
|
// modified by Bevy contributors
|
||||||
|
|
||||||
use crate::alloc::vec::Vec;
|
use crate::alloc::vec::Vec;
|
||||||
use core::{any::TypeId, convert::TryFrom, fmt, mem, ptr};
|
use core::{any::TypeId, convert::TryFrom, fmt, mem, ptr};
|
||||||
|
@ -261,12 +261,7 @@ impl World {
|
||||||
/// ```
|
/// ```
|
||||||
pub fn query_one<Q: Query>(&self, entity: Entity) -> Result<QueryOne<'_, Q>, NoSuchEntity> {
|
pub fn query_one<Q: Query>(&self, entity: Entity) -> Result<QueryOne<'_, Q>, NoSuchEntity> {
|
||||||
let loc = self.entities.get(entity)?;
|
let loc = self.entities.get(entity)?;
|
||||||
Ok(unsafe {
|
Ok(unsafe { QueryOne::new(&self.archetypes[loc.archetype as usize], loc.index) })
|
||||||
QueryOne::new(
|
|
||||||
&self.archetypes[loc.archetype as usize],
|
|
||||||
loc.index,
|
|
||||||
)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Borrow the `T` component of `entity`
|
/// Borrow the `T` component of `entity`
|
||||||
|
@ -740,10 +735,13 @@ where
|
||||||
self.archetype.put_dynamic(ptr, ty, size, index);
|
self.archetype.put_dynamic(ptr, ty, size, index);
|
||||||
true
|
true
|
||||||
});
|
});
|
||||||
self.entities.insert(entity, Location {
|
self.entities.insert(
|
||||||
archetype: self.archetype_id,
|
entity,
|
||||||
index,
|
Location {
|
||||||
});
|
archetype: self.archetype_id,
|
||||||
|
index,
|
||||||
|
},
|
||||||
|
);
|
||||||
}
|
}
|
||||||
Some(entity)
|
Some(entity)
|
||||||
}
|
}
|
||||||
|
@ -761,4 +759,4 @@ where
|
||||||
fn len(&self) -> usize {
|
fn len(&self) -> usize {
|
||||||
self.inner.len()
|
self.inner.len()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
// modified by Bevy contributors
|
// modified by Bevy contributors
|
||||||
|
|
||||||
use hecs::*;
|
use hecs::*;
|
||||||
|
|
||||||
|
@ -315,11 +315,7 @@ fn query_batched() {
|
||||||
fn spawn_batch() {
|
fn spawn_batch() {
|
||||||
let mut world = World::new();
|
let mut world = World::new();
|
||||||
world.spawn_batch((0..100).map(|x| (x, "abc")));
|
world.spawn_batch((0..100).map(|x| (x, "abc")));
|
||||||
let entities = world
|
let entities = world.query::<&i32>().iter().map(|&x| x).collect::<Vec<_>>();
|
||||||
.query::<&i32>()
|
|
||||||
.iter()
|
|
||||||
.map(|&x| x)
|
|
||||||
.collect::<Vec<_>>();
|
|
||||||
assert_eq!(entities.len(), 100);
|
assert_eq!(entities.len(), 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -338,4 +334,4 @@ fn query_one() {
|
||||||
);
|
);
|
||||||
world.despawn(a).unwrap();
|
world.despawn(a).unwrap();
|
||||||
assert!(world.query_one::<&i32>(a).is_err());
|
assert!(world.query_one::<&i32>(a).is_err());
|
||||||
}
|
}
|
||||||
|
|
|
@ -156,7 +156,10 @@ impl CommandsInternal {
|
||||||
self
|
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.");
|
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 {
|
self.commands.push(Command::WriteWorld(Box::new(Insert {
|
||||||
entity: current_entity,
|
entity: current_entity,
|
||||||
|
@ -230,7 +233,10 @@ impl Commands {
|
||||||
self
|
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();
|
let mut commands = self.commands.lock().unwrap();
|
||||||
commands.with_bundle(components);
|
commands.with_bundle(components);
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
resource_query::{FetchResource, ResourceQuery},
|
resource_query::{FetchResource, ResourceQuery},
|
||||||
system::{System, ThreadLocalExecution, SystemId},
|
system::{System, SystemId, ThreadLocalExecution},
|
||||||
Commands, Resources,
|
Commands, Resources,
|
||||||
};
|
};
|
||||||
use core::marker::PhantomData;
|
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;
|
use std::borrow::Cow;
|
||||||
|
|
||||||
pub struct SystemFn<F, Init>
|
pub struct SystemFn<F, Init>
|
||||||
|
@ -104,12 +106,12 @@ impl<'a, Q: HecsQuery> Query<'a, Q> {
|
||||||
self.world.query::<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
|
// TODO: Check if request matches query
|
||||||
self.world.get(entity)
|
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
|
// TODO: Check if request matches query
|
||||||
self.world.get_mut(entity)
|
self.world.get_mut(entity)
|
||||||
}
|
}
|
||||||
|
@ -262,7 +264,7 @@ where
|
||||||
Box::new(Self {
|
Box::new(Self {
|
||||||
func,
|
func,
|
||||||
name: core::any::type_name::<F>().into(),
|
name: core::any::type_name::<F>().into(),
|
||||||
id: SystemId::new()
|
id: SystemId::new(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,19 +1,19 @@
|
||||||
pub use hecs::{*, Query as HecsQuery};
|
pub use hecs::{Query as HecsQuery, *};
|
||||||
|
|
||||||
|
mod commands;
|
||||||
mod into_system;
|
mod into_system;
|
||||||
|
#[cfg(feature = "profiler")]
|
||||||
|
pub mod profiler;
|
||||||
mod resource_query;
|
mod resource_query;
|
||||||
mod resources;
|
mod resources;
|
||||||
mod commands;
|
|
||||||
mod schedule;
|
mod schedule;
|
||||||
mod system;
|
mod system;
|
||||||
mod world_builder;
|
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 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 schedule::Schedule;
|
||||||
pub use system::{System, SystemId};
|
pub use system::{System, SystemId};
|
||||||
pub use world_builder::{WorldBuilder, WorldBuilderSource};
|
pub use world_builder::{WorldBuilder, WorldBuilderSource};
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::{resources::FromResources, Archetype, Component, Resources, system::SystemId};
|
use crate::{resources::FromResources, system::SystemId, Archetype, Component, Resources};
|
||||||
use core::{
|
use core::{
|
||||||
any::TypeId,
|
any::TypeId,
|
||||||
ops::{Deref, DerefMut},
|
ops::{Deref, DerefMut},
|
||||||
|
@ -222,7 +222,9 @@ impl<'a, T: Component + FromResources> FetchResource<'a> for FetchResourceLocalM
|
||||||
let archetype = resources
|
let archetype = resources
|
||||||
.resource_archetypes
|
.resource_archetypes
|
||||||
.get(&TypeId::of::<T>())
|
.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
|
let index = resources
|
||||||
.system_id_to_archetype_index
|
.system_id_to_archetype_index
|
||||||
.get(&system_id.0)
|
.get(&system_id.0)
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
resource_query::{FetchResource, ResourceQuery},
|
resource_query::{FetchResource, ResourceQuery},
|
||||||
ComponentError, TypeInfo, system::SystemId, Res, ResMut,
|
system::SystemId,
|
||||||
|
ComponentError, Res, ResMut, TypeInfo,
|
||||||
};
|
};
|
||||||
use core::any::TypeId;
|
use core::any::TypeId;
|
||||||
use hecs::{Archetype, Ref, RefMut};
|
use hecs::{Archetype, Ref, RefMut};
|
||||||
|
@ -198,13 +199,17 @@ mod tests {
|
||||||
assert!(resources.get_local::<i32>(SystemId(0)).is_err());
|
assert!(resources.get_local::<i32>(SystemId(0)).is_err());
|
||||||
resources.insert_local(SystemId(0), 111);
|
resources.insert_local(SystemId(0), 111);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
*resources.get_local::<i32>(SystemId(0)).expect("resource exists"),
|
*resources
|
||||||
|
.get_local::<i32>(SystemId(0))
|
||||||
|
.expect("resource exists"),
|
||||||
111
|
111
|
||||||
);
|
);
|
||||||
assert_eq!(*resources.get::<i32>().expect("resource exists"), 123);
|
assert_eq!(*resources.get::<i32>().expect("resource exists"), 123);
|
||||||
resources.insert_local(SystemId(0), 222);
|
resources.insert_local(SystemId(0), 222);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
*resources.get_local::<i32>(SystemId(0)).expect("resource exists"),
|
*resources
|
||||||
|
.get_local::<i32>(SystemId(0))
|
||||||
|
.expect("resource exists"),
|
||||||
222
|
222
|
||||||
);
|
);
|
||||||
assert_eq!(*resources.get::<i32>().expect("resource exists"), 123);
|
assert_eq!(*resources.get::<i32>().expect("resource exists"), 123);
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
system::{System, ThreadLocalExecution},
|
system::{System, ThreadLocalExecution},
|
||||||
Resources, World, SystemId,
|
Resources, SystemId, World,
|
||||||
};
|
};
|
||||||
use rayon::prelude::*;
|
use rayon::prelude::*;
|
||||||
use std::{
|
use std::{
|
||||||
|
@ -84,7 +84,11 @@ impl Schedule {
|
||||||
.get_mut(&stage_name)
|
.get_mut(&stage_name)
|
||||||
.unwrap_or_else(|| panic!("Stage does not exist: {}", stage_name));
|
.unwrap_or_else(|| panic!("Stage does not exist: {}", stage_name));
|
||||||
if self.system_ids.contains(&system.id()) {
|
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());
|
self.system_ids.insert(system.id());
|
||||||
systems.push(system);
|
systems.push(system);
|
||||||
|
|
|
@ -5,7 +5,7 @@ use std::borrow::Cow;
|
||||||
pub enum ThreadLocalExecution {
|
pub enum ThreadLocalExecution {
|
||||||
Immediate,
|
Immediate,
|
||||||
NextFlush,
|
NextFlush,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
|
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
|
||||||
pub struct SystemId(pub u32);
|
pub struct SystemId(pub u32);
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
use super::keyboard::ElementState;
|
use super::keyboard::ElementState;
|
||||||
use crate::Input;
|
use crate::Input;
|
||||||
use bevy_app::{EventReader, Events};
|
use bevy_app::{EventReader, Events};
|
||||||
use glam::Vec2;
|
|
||||||
use bevy_ecs::{Res, ResMut};
|
use bevy_ecs::{Res, ResMut};
|
||||||
|
use glam::Vec2;
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct MouseButtonInput {
|
pub struct MouseButtonInput {
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
use crate::{light::Light, material::StandardMaterial, pipelines::FORWARD_PIPELINE_HANDLE};
|
use crate::{light::Light, material::StandardMaterial, pipelines::FORWARD_PIPELINE_HANDLE};
|
||||||
use bevy_asset::Handle;
|
use bevy_asset::Handle;
|
||||||
|
use bevy_ecs::Bundle;
|
||||||
use bevy_render::{
|
use bevy_render::{
|
||||||
draw::Draw,
|
draw::Draw,
|
||||||
mesh::Mesh,
|
mesh::Mesh,
|
||||||
pipeline::{DynamicBinding, PipelineSpecialization, RenderPipeline, RenderPipelines},
|
pipeline::{DynamicBinding, PipelineSpecialization, RenderPipeline, RenderPipelines},
|
||||||
};
|
};
|
||||||
use bevy_transform::prelude::{Rotation, Scale, Transform, Translation};
|
use bevy_transform::prelude::{Rotation, Scale, Transform, Translation};
|
||||||
use bevy_ecs::Bundle;
|
|
||||||
|
|
||||||
#[derive(Bundle)]
|
#[derive(Bundle)]
|
||||||
pub struct PbrComponents {
|
pub struct PbrComponents {
|
||||||
|
|
|
@ -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_asset::Assets;
|
||||||
|
use bevy_ecs::Resources;
|
||||||
use bevy_render::{
|
use bevy_render::{
|
||||||
base_render_graph,
|
base_render_graph,
|
||||||
pipeline::PipelineDescriptor,
|
pipeline::PipelineDescriptor,
|
||||||
|
@ -10,7 +15,6 @@ use bevy_render::{
|
||||||
shader::Shader,
|
shader::Shader,
|
||||||
};
|
};
|
||||||
use bevy_transform::prelude::Transform;
|
use bevy_transform::prelude::Transform;
|
||||||
use bevy_ecs::Resources;
|
|
||||||
|
|
||||||
pub mod node {
|
pub mod node {
|
||||||
pub const TRANSFORM: &str = "transform";
|
pub const TRANSFORM: &str = "transform";
|
||||||
|
@ -36,7 +40,10 @@ impl ForwardPbrRenderGraphBuilder for RenderGraph {
|
||||||
self.add_system_node(node::LIGHTS, LightsNode::new(10));
|
self.add_system_node(node::LIGHTS, LightsNode::new(10));
|
||||||
let mut shaders = resources.get_mut::<Assets<Shader>>().unwrap();
|
let mut shaders = resources.get_mut::<Assets<Shader>>().unwrap();
|
||||||
let mut pipelines = resources.get_mut::<Assets<PipelineDescriptor>>().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
|
// TODO: replace these with "autowire" groups
|
||||||
self.add_node_edge(node::STANDARD_MATERIAL, base_render_graph::node::MAIN_PASS)
|
self.add_node_edge(node::STANDARD_MATERIAL, base_render_graph::node::MAIN_PASS)
|
||||||
|
|
|
@ -9,11 +9,11 @@ pub use forward_pbr_render_graph::*;
|
||||||
|
|
||||||
use bevy_app::{stage, AppBuilder, AppPlugin};
|
use bevy_app::{stage, AppBuilder, AppPlugin};
|
||||||
use bevy_asset::AddAsset;
|
use bevy_asset::AddAsset;
|
||||||
|
use bevy_ecs::IntoQuerySystem;
|
||||||
use bevy_render::{render_graph::RenderGraph, shader};
|
use bevy_render::{render_graph::RenderGraph, shader};
|
||||||
use bevy_type_registry::RegisterType;
|
use bevy_type_registry::RegisterType;
|
||||||
use light::Light;
|
use light::Light;
|
||||||
use material::StandardMaterial;
|
use material::StandardMaterial;
|
||||||
use bevy_ecs::IntoQuerySystem;
|
|
||||||
|
|
||||||
/// NOTE: this isn't PBR yet. consider this name "aspirational" :)
|
/// NOTE: this isn't PBR yet. consider this name "aspirational" :)
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
use bevy_render::{
|
use bevy_render::{
|
||||||
render_graph::{CommandQueue, Node, ResourceSlots, SystemNode},
|
render_graph::{CommandQueue, Node, ResourceSlots, SystemNode},
|
||||||
render_resource::{BufferInfo, BufferUsage, RenderResourceBinding, RenderResourceBindings, BufferId},
|
render_resource::{
|
||||||
|
BufferId, BufferInfo, BufferUsage, RenderResourceBinding, RenderResourceBindings,
|
||||||
|
},
|
||||||
renderer::{RenderContext, RenderResourceContext},
|
renderer::{RenderContext, RenderResourceContext},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -9,8 +11,8 @@ use crate::{
|
||||||
uniform,
|
uniform,
|
||||||
};
|
};
|
||||||
use bevy_core::bytes::{AsBytes, Byteable};
|
use bevy_core::bytes::{AsBytes, Byteable};
|
||||||
|
use bevy_ecs::{Commands, IntoQuerySystem, Local, Query, Res, ResMut, Resources, System, World};
|
||||||
use bevy_transform::prelude::*;
|
use bevy_transform::prelude::*;
|
||||||
use bevy_ecs::{Commands, Res, System, ResMut, Query, Local, World, Resources, IntoQuerySystem};
|
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct LightsNode {
|
pub struct LightsNode {
|
||||||
|
@ -51,14 +53,17 @@ unsafe impl Byteable for LightCount {}
|
||||||
impl SystemNode for LightsNode {
|
impl SystemNode for LightsNode {
|
||||||
fn get_system(&self, commands: &mut Commands) -> Box<dyn System> {
|
fn get_system(&self, commands: &mut Commands) -> Box<dyn System> {
|
||||||
let system = lights_node_system.system();
|
let system = lights_node_system.system();
|
||||||
commands.insert_local_resource(system.id(), LightsNodeSystemState {
|
commands.insert_local_resource(
|
||||||
command_queue: self.command_queue.clone(),
|
system.id(),
|
||||||
max_lights: self.max_lights,
|
LightsNodeSystemState {
|
||||||
tmp_count_buffer: None,
|
command_queue: self.command_queue.clone(),
|
||||||
tmp_light_buffer: None,
|
max_lights: self.max_lights,
|
||||||
light_buffer: None,
|
tmp_count_buffer: None,
|
||||||
lights_are_dirty: true,
|
tmp_light_buffer: None,
|
||||||
});
|
light_buffer: None,
|
||||||
|
lights_are_dirty: true,
|
||||||
|
},
|
||||||
|
);
|
||||||
system
|
system
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -79,97 +84,95 @@ pub fn lights_node_system(
|
||||||
render_resource_context: Res<Box<dyn RenderResourceContext>>,
|
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
|
// 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 render_resource_bindings: ResMut<RenderResourceBindings>,
|
||||||
mut query: Query<(&Light, &Transform, &Translation)>) {
|
mut query: Query<(&Light, &Transform, &Translation)>,
|
||||||
let state = &mut state;
|
) {
|
||||||
if !state.lights_are_dirty {
|
let state = &mut state;
|
||||||
return;
|
if !state.lights_are_dirty {
|
||||||
}
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
let render_resource_context = &**render_resource_context;
|
let render_resource_context = &**render_resource_context;
|
||||||
if state.light_buffer.is_none() {
|
if state.light_buffer.is_none() {
|
||||||
let light_uniform_size = std::mem::size_of::<LightCount>()
|
let light_uniform_size =
|
||||||
+ state.max_lights * std::mem::size_of::<LightRaw>();
|
std::mem::size_of::<LightCount>() + state.max_lights * std::mem::size_of::<LightRaw>();
|
||||||
|
|
||||||
let buffer = render_resource_context.create_buffer(BufferInfo {
|
let buffer = render_resource_context.create_buffer(BufferInfo {
|
||||||
size: light_uniform_size,
|
size: light_uniform_size,
|
||||||
buffer_usage: BufferUsage::UNIFORM
|
buffer_usage: BufferUsage::UNIFORM | BufferUsage::COPY_SRC | BufferUsage::COPY_DST,
|
||||||
| BufferUsage::COPY_SRC
|
..Default::default()
|
||||||
| BufferUsage::COPY_DST,
|
});
|
||||||
..Default::default()
|
render_resource_bindings.set(
|
||||||
});
|
uniform::LIGHTS,
|
||||||
render_resource_bindings.set(
|
RenderResourceBinding::Buffer {
|
||||||
uniform::LIGHTS,
|
buffer,
|
||||||
RenderResourceBinding::Buffer {
|
range: 0..light_uniform_size as u64,
|
||||||
buffer,
|
dynamic_index: None,
|
||||||
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()
|
|
||||||
},
|
},
|
||||||
&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();
|
let light_count = query.iter().iter().count();
|
||||||
state.command_queue.copy_buffer_to_buffer(
|
|
||||||
tmp_light_buffer,
|
|
||||||
0,
|
|
||||||
light_buffer,
|
|
||||||
light_count_size as u64,
|
|
||||||
total_size as u64,
|
|
||||||
);
|
|
||||||
|
|
||||||
}
|
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,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use bevy_asset::{Handle, Assets};
|
use bevy_asset::{Assets, Handle};
|
||||||
use bevy_render::{
|
use bevy_render::{
|
||||||
pipeline::{
|
pipeline::{
|
||||||
state_descriptors::{
|
state_descriptors::{
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use crate::{impl_property, property_serde::Serializable, Property, PropertyTypeRegistry};
|
use crate::{impl_property, property_serde::Serializable, Property, PropertyTypeRegistry};
|
||||||
use erased_serde::Deserializer;
|
|
||||||
use bevy_ecs::Entity;
|
use bevy_ecs::Entity;
|
||||||
|
use erased_serde::Deserializer;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
|
||||||
impl_property!(Entity, serialize_entity, deserialize_entity);
|
impl_property!(Entity, serialize_entity, deserialize_entity);
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
mod impl_property_glam;
|
|
||||||
mod impl_property_bevy_ecs;
|
mod impl_property_bevy_ecs;
|
||||||
|
mod impl_property_glam;
|
||||||
mod impl_property_smallvec;
|
mod impl_property_smallvec;
|
||||||
mod impl_property_std;
|
mod impl_property_std;
|
||||||
|
|
|
@ -94,7 +94,13 @@ impl PropertyTypeRegistration {
|
||||||
let mut split = full_name.splitn(2, "<");
|
let mut split = full_name.splitn(2, "<");
|
||||||
|
|
||||||
// main type
|
// 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
|
// process generics if they exist
|
||||||
if let Some(generics) = split.next() {
|
if let Some(generics) = split.next() {
|
||||||
|
@ -104,7 +110,13 @@ impl PropertyTypeRegistration {
|
||||||
|
|
||||||
let generics = &generics[0..generics.len() - 1];
|
let generics = &generics[0..generics.len() - 1];
|
||||||
short_name.push('<');
|
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.push('>');
|
||||||
}
|
}
|
||||||
short_name
|
short_name
|
||||||
|
|
|
@ -124,10 +124,7 @@ impl BaseRenderGraphBuilder for RenderGraph {
|
||||||
main_pass_node.add_camera(camera::CAMERA2D);
|
main_pass_node.add_camera(camera::CAMERA2D);
|
||||||
}
|
}
|
||||||
|
|
||||||
self.add_node(
|
self.add_node(node::MAIN_PASS, main_pass_node);
|
||||||
node::MAIN_PASS,
|
|
||||||
main_pass_node
|
|
||||||
);
|
|
||||||
|
|
||||||
self.add_node_edge(node::TEXTURE_COPY, node::MAIN_PASS)
|
self.add_node_edge(node::TEXTURE_COPY, node::MAIN_PASS)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use crate::Camera;
|
use crate::Camera;
|
||||||
|
use bevy_ecs::{Entity, Query, ResMut};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use bevy_ecs::{ResMut, Entity, Query};
|
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct ActiveCameras {
|
pub struct ActiveCameras {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use crate::{draw::Draw, Camera};
|
use crate::{draw::Draw, Camera};
|
||||||
use bevy_core::float_ord::FloatOrd;
|
use bevy_core::float_ord::FloatOrd;
|
||||||
|
use bevy_ecs::{Entity, Query};
|
||||||
use bevy_transform::prelude::Transform;
|
use bevy_transform::prelude::Transform;
|
||||||
use bevy_ecs::{Query, Entity};
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct VisibleEntity {
|
pub struct VisibleEntity {
|
||||||
|
@ -15,7 +15,7 @@ pub struct VisibleEntities {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl VisibleEntities {
|
impl VisibleEntities {
|
||||||
pub fn iter(&self) -> impl DoubleEndedIterator<Item=&VisibleEntity> {
|
pub fn iter(&self) -> impl DoubleEndedIterator<Item = &VisibleEntity> {
|
||||||
self.value.iter()
|
self.value.iter()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,7 @@ pub fn visible_entities_system(
|
||||||
|
|
||||||
let order = if let Ok(transform) = transform_query.get::<Transform>(entity) {
|
let order = if let Ok(transform) = transform_query.get::<Transform>(entity) {
|
||||||
let position = transform.value.w_axis().truncate();
|
let position = transform.value.w_axis().truncate();
|
||||||
// smaller distances are sorted to lower indices by using the distance from the camera
|
// smaller distances are sorted to lower indices by using the distance from the camera
|
||||||
FloatOrd((camera_position - position).length())
|
FloatOrd((camera_position - position).length())
|
||||||
} else {
|
} else {
|
||||||
let order = FloatOrd(no_transform_order);
|
let order = FloatOrd(no_transform_order);
|
||||||
|
@ -49,24 +49,17 @@ pub fn visible_entities_system(
|
||||||
};
|
};
|
||||||
|
|
||||||
if draw.is_transparent {
|
if draw.is_transparent {
|
||||||
transparent_entities.push(VisibleEntity {
|
transparent_entities.push(VisibleEntity { entity, order })
|
||||||
entity,
|
|
||||||
order,
|
|
||||||
})
|
|
||||||
} else {
|
} else {
|
||||||
visible_entities.value.push(VisibleEntity {
|
visible_entities.value.push(VisibleEntity { entity, order })
|
||||||
entity,
|
|
||||||
order,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// sort opaque entities front-to-back
|
// sort opaque entities front-to-back
|
||||||
visible_entities.value.sort_by_key(|e| e.order);
|
visible_entities.value.sort_by_key(|e| e.order);
|
||||||
|
|
||||||
// sort transparent entities front-to-back
|
// 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);
|
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
|
// TODO: check for big changes in visible entities len() vs capacity() (ex: 2x) and resize to prevent holding unneeded memory
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
base_render_graph, Camera,
|
base_render_graph, draw::Draw, mesh::Mesh, pipeline::RenderPipelines, Camera,
|
||||||
OrthographicProjection, PerspectiveProjection, VisibleEntities, mesh::Mesh, draw::Draw, pipeline::RenderPipelines,
|
OrthographicProjection, PerspectiveProjection, VisibleEntities,
|
||||||
};
|
};
|
||||||
use bevy_transform::components::{Rotation, Scale, Transform, Translation};
|
|
||||||
use bevy_ecs::Bundle;
|
|
||||||
use bevy_asset::Handle;
|
use bevy_asset::Handle;
|
||||||
|
use bevy_ecs::Bundle;
|
||||||
|
use bevy_transform::components::{Rotation, Scale, Transform, Translation};
|
||||||
|
|
||||||
#[derive(Bundle, Default)]
|
#[derive(Bundle, Default)]
|
||||||
pub struct MeshComponents {
|
pub struct MeshComponents {
|
||||||
|
|
|
@ -34,8 +34,8 @@ use self::{
|
||||||
use base_render_graph::{BaseRenderGraphBuilder, BaseRenderGraphConfig};
|
use base_render_graph::{BaseRenderGraphBuilder, BaseRenderGraphConfig};
|
||||||
use bevy_app::{AppBuilder, AppPlugin};
|
use bevy_app::{AppBuilder, AppPlugin};
|
||||||
use bevy_asset::AddAsset;
|
use bevy_asset::AddAsset;
|
||||||
|
use bevy_ecs::{IntoQuerySystem, ThreadLocalSystem};
|
||||||
use bevy_type_registry::RegisterType;
|
use bevy_type_registry::RegisterType;
|
||||||
use bevy_ecs::{ThreadLocalSystem, IntoQuerySystem};
|
|
||||||
use draw::{clear_draw_system, Draw};
|
use draw::{clear_draw_system, Draw};
|
||||||
use mesh::mesh_resource_provider_system;
|
use mesh::mesh_resource_provider_system;
|
||||||
use pipeline::{draw_render_pipelines_system, RenderPipelines};
|
use pipeline::{draw_render_pipelines_system, RenderPipelines};
|
||||||
|
@ -114,7 +114,10 @@ impl AppPlugin for RenderPlugin {
|
||||||
visible_entities_system.system(),
|
visible_entities_system.system(),
|
||||||
)
|
)
|
||||||
// TODO: turn these "resource systems" into graph nodes and remove the RENDER_RESOURCE stage
|
// 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(
|
.add_system_to_stage(
|
||||||
stage::RENDER_RESOURCE,
|
stage::RENDER_RESOURCE,
|
||||||
Texture::texture_resource_system.system(),
|
Texture::texture_resource_system.system(),
|
||||||
|
|
|
@ -38,11 +38,11 @@ pub enum BindType {
|
||||||
impl BindType {
|
impl BindType {
|
||||||
pub fn get_uniform_size(&self) -> Option<u64> {
|
pub fn get_uniform_size(&self) -> Option<u64> {
|
||||||
match self {
|
match self {
|
||||||
BindType::Uniform { properties, .. } => {
|
BindType::Uniform { properties, .. } => Some(
|
||||||
Some(properties.iter().fold(0, |total, property| {
|
properties
|
||||||
total + property.get_size()
|
.iter()
|
||||||
}))
|
.fold(0, |total, property| total + property.get_size()),
|
||||||
}
|
),
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,8 +4,8 @@ use crate::{
|
||||||
render_resource::RenderResourceBindings,
|
render_resource::RenderResourceBindings,
|
||||||
};
|
};
|
||||||
use bevy_asset::Handle;
|
use bevy_asset::Handle;
|
||||||
use bevy_property::Properties;
|
|
||||||
use bevy_ecs::{Query, ResMut};
|
use bevy_ecs::{Query, ResMut};
|
||||||
|
use bevy_property::Properties;
|
||||||
#[derive(Properties, Default, Clone)]
|
#[derive(Properties, Default, Clone)]
|
||||||
pub struct RenderPipeline {
|
pub struct RenderPipeline {
|
||||||
pub pipeline: Handle<PipelineDescriptor>,
|
pub pipeline: Handle<PipelineDescriptor>,
|
||||||
|
|
|
@ -83,7 +83,7 @@ impl CommandQueue {
|
||||||
pub fn clear(&mut self) {
|
pub fn clear(&mut self) {
|
||||||
self.queue.lock().unwrap().clear();
|
self.queue.lock().unwrap().clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn execute(&mut self, render_context: &mut dyn RenderContext) {
|
pub fn execute(&mut self, render_context: &mut dyn RenderContext) {
|
||||||
for command in self.queue.lock().unwrap().drain(..) {
|
for command in self.queue.lock().unwrap().drain(..) {
|
||||||
match command {
|
match command {
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
use super::{Edge, RenderGraphError, ResourceSlotInfo, ResourceSlots};
|
use super::{Edge, RenderGraphError, ResourceSlotInfo, ResourceSlots};
|
||||||
use crate::renderer::RenderContext;
|
use crate::renderer::RenderContext;
|
||||||
|
use bevy_ecs::{Commands, Resources, System, World};
|
||||||
use downcast_rs::{impl_downcast, Downcast};
|
use downcast_rs::{impl_downcast, Downcast};
|
||||||
use std::{borrow::Cow, fmt::Debug};
|
use std::{borrow::Cow, fmt::Debug};
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
use bevy_ecs::{Resources, World, System, Commands};
|
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
|
#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
|
||||||
pub struct NodeId(Uuid);
|
pub struct NodeId(Uuid);
|
||||||
|
|
|
@ -8,7 +8,7 @@ use crate::{
|
||||||
};
|
};
|
||||||
use bevy_core::bytes::AsBytes;
|
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 bevy_transform::prelude::*;
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
|
|
||||||
|
@ -45,11 +45,14 @@ impl Node for CameraNode {
|
||||||
impl SystemNode for CameraNode {
|
impl SystemNode for CameraNode {
|
||||||
fn get_system(&self, commands: &mut Commands) -> Box<dyn System> {
|
fn get_system(&self, commands: &mut Commands) -> Box<dyn System> {
|
||||||
let system = camera_node_system.system();
|
let system = camera_node_system.system();
|
||||||
commands.insert_local_resource(system.id(), CameraNodeState {
|
commands.insert_local_resource(
|
||||||
camera_name: self.camera_name.clone(),
|
system.id(),
|
||||||
command_queue: self.command_queue.clone(),
|
CameraNodeState {
|
||||||
camera_buffer: None,
|
camera_name: self.camera_name.clone(),
|
||||||
});
|
command_queue: self.command_queue.clone(),
|
||||||
|
camera_buffer: None,
|
||||||
|
},
|
||||||
|
);
|
||||||
system
|
system
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -117,12 +120,8 @@ pub fn camera_node_system(
|
||||||
);
|
);
|
||||||
|
|
||||||
let camera_buffer = state.camera_buffer.unwrap();
|
let camera_buffer = state.camera_buffer.unwrap();
|
||||||
state.command_queue.copy_buffer_to_buffer(
|
state
|
||||||
tmp_buffer,
|
.command_queue
|
||||||
0,
|
.copy_buffer_to_buffer(tmp_buffer, 0, camera_buffer, 0, matrix_size as u64);
|
||||||
camera_buffer,
|
|
||||||
0,
|
|
||||||
matrix_size as u64,
|
|
||||||
);
|
|
||||||
state.command_queue.free_buffer(tmp_buffer);
|
state.command_queue.free_buffer(tmp_buffer);
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ use crate::{
|
||||||
};
|
};
|
||||||
|
|
||||||
use bevy_asset::{Assets, Handle};
|
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 render_resource::{AssetRenderResourceBindings, BufferId, RenderResourceType, RenderResources};
|
||||||
use std::{collections::HashMap, marker::PhantomData, ops::DerefMut};
|
use std::{collections::HashMap, marker::PhantomData, ops::DerefMut};
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
render_graph::{Node, ResourceSlots},
|
render_graph::{Node, ResourceSlots},
|
||||||
renderer::RenderContext, render_resource::SharedBuffers,
|
render_resource::SharedBuffers,
|
||||||
|
renderer::RenderContext,
|
||||||
};
|
};
|
||||||
use bevy_ecs::{Resources, World};
|
use bevy_ecs::{Resources, World};
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,6 @@ use bevy_app::{EventReader, Events};
|
||||||
use bevy_asset::{AssetEvent, Assets};
|
use bevy_asset::{AssetEvent, Assets};
|
||||||
use bevy_ecs::{Resources, World};
|
use bevy_ecs::{Resources, World};
|
||||||
|
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct TextureCopyNode {
|
pub struct TextureCopyNode {
|
||||||
pub texture_event_reader: EventReader<AssetEvent<Texture>>,
|
pub texture_event_reader: EventReader<AssetEvent<Texture>>,
|
||||||
|
|
|
@ -4,9 +4,9 @@ use crate::{
|
||||||
renderer::RenderContext,
|
renderer::RenderContext,
|
||||||
};
|
};
|
||||||
use bevy_app::{EventReader, Events};
|
use bevy_app::{EventReader, Events};
|
||||||
|
use bevy_ecs::{Resources, World};
|
||||||
use bevy_window::{WindowCreated, WindowReference, WindowResized, Windows};
|
use bevy_window::{WindowCreated, WindowReference, WindowResized, Windows};
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
use bevy_ecs::{Resources, World};
|
|
||||||
|
|
||||||
pub struct WindowSwapChainNode {
|
pub struct WindowSwapChainNode {
|
||||||
window_reference: WindowReference,
|
window_reference: WindowReference,
|
||||||
|
|
|
@ -5,9 +5,9 @@ use crate::{
|
||||||
texture::TextureDescriptor,
|
texture::TextureDescriptor,
|
||||||
};
|
};
|
||||||
use bevy_app::{EventReader, Events};
|
use bevy_app::{EventReader, Events};
|
||||||
|
use bevy_ecs::{Resources, World};
|
||||||
use bevy_window::{WindowCreated, WindowReference, WindowResized, Windows};
|
use bevy_window::{WindowCreated, WindowReference, WindowResized, Windows};
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
use bevy_ecs::{Resources, World};
|
|
||||||
|
|
||||||
pub struct WindowTextureNode {
|
pub struct WindowTextureNode {
|
||||||
window_reference: WindowReference,
|
window_reference: WindowReference,
|
||||||
|
|
|
@ -2,8 +2,8 @@ use super::{BufferId, BufferInfo, RenderResource, RenderResourceBinding};
|
||||||
use crate::{
|
use crate::{
|
||||||
render_graph::CommandQueue, render_resource::BufferUsage, renderer::RenderResourceContext,
|
render_graph::CommandQueue, render_resource::BufferUsage, renderer::RenderResourceContext,
|
||||||
};
|
};
|
||||||
use std::sync::{Arc, RwLock};
|
|
||||||
use bevy_ecs::Res;
|
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
|
// 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
|
// 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
|
||||||
|
|
|
@ -120,8 +120,10 @@ impl RenderResourceContext for HeadlessRenderResourceContext {
|
||||||
fn get_buffer_info(&self, buffer: BufferId) -> Option<BufferInfo> {
|
fn get_buffer_info(&self, buffer: BufferId) -> Option<BufferInfo> {
|
||||||
self.buffer_info.read().unwrap().get(&buffer).cloned()
|
self.buffer_info.read().unwrap().get(&buffer).cloned()
|
||||||
}
|
}
|
||||||
fn bind_group_descriptor_exists(&self, _bind_group_descriptor_id: BindGroupDescriptorId)
|
fn bind_group_descriptor_exists(
|
||||||
-> bool {
|
&self,
|
||||||
|
_bind_group_descriptor_id: BindGroupDescriptorId,
|
||||||
|
) -> bool {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ use crate::{texture::Texture, RenderPipelines};
|
||||||
use bevy_asset::{Assets, Handle};
|
use bevy_asset::{Assets, Handle};
|
||||||
|
|
||||||
pub use bevy_derive::ShaderDefs;
|
pub use bevy_derive::ShaderDefs;
|
||||||
use bevy_ecs::{Res, Query};
|
use bevy_ecs::{Query, Res};
|
||||||
|
|
||||||
pub trait ShaderDef {
|
pub trait ShaderDef {
|
||||||
fn is_defined(&self) -> bool;
|
fn is_defined(&self) -> bool;
|
||||||
|
|
|
@ -5,9 +5,9 @@ use crate::{
|
||||||
};
|
};
|
||||||
use bevy_app::{EventReader, Events};
|
use bevy_app::{EventReader, Events};
|
||||||
use bevy_asset::{AssetEvent, Assets, Handle};
|
use bevy_asset::{AssetEvent, Assets, Handle};
|
||||||
|
use bevy_ecs::{Res, ResMut};
|
||||||
use glam::Vec2;
|
use glam::Vec2;
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
use bevy_ecs::{Res, ResMut};
|
|
||||||
|
|
||||||
pub const TEXTURE_ASSET_INDEX: usize = 0;
|
pub const TEXTURE_ASSET_INDEX: usize = 0;
|
||||||
pub const SAMPLER_ASSET_INDEX: usize = 1;
|
pub const SAMPLER_ASSET_INDEX: usize = 1;
|
||||||
|
|
|
@ -27,7 +27,6 @@ impl From<&Texture> for TextureDescriptor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
impl Default for TextureDescriptor {
|
impl Default for TextureDescriptor {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
TextureDescriptor {
|
TextureDescriptor {
|
||||||
|
@ -43,5 +42,4 @@ impl Default for TextureDescriptor {
|
||||||
usage: TextureUsage::SAMPLED | TextureUsage::COPY_DST,
|
usage: TextureUsage::SAMPLED | TextureUsage::COPY_DST,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
|
||||||
|
|
|
@ -23,7 +23,7 @@ impl AppPlugin for ScenePlugin {
|
||||||
.init_resource::<SceneSpawner>()
|
.init_resource::<SceneSpawner>()
|
||||||
.add_stage_after(stage::EVENT_UPDATE, SCENE_STAGE)
|
.add_stage_after(stage::EVENT_UPDATE, SCENE_STAGE)
|
||||||
.add_system_to_stage(SCENE_STAGE, ThreadLocalSystem::new(scene_spawner_system));
|
.add_system_to_stage(SCENE_STAGE, ThreadLocalSystem::new(scene_spawner_system));
|
||||||
// TODO: port scenes to bevy_ecs
|
// TODO: port scenes to bevy_ecs
|
||||||
// .add_system_to_stage_ecs(SCENE_STAGE, ThreadLocalSystem::new(scene_spawner_system));
|
// .add_system_to_stage_ecs(SCENE_STAGE, ThreadLocalSystem::new(scene_spawner_system));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
use crate::{serde::SceneDeserializer, Scene};
|
use crate::{serde::SceneDeserializer, Scene};
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use bevy_asset::AssetLoader;
|
use bevy_asset::AssetLoader;
|
||||||
|
use bevy_ecs::{FromResources, Resources};
|
||||||
use bevy_property::PropertyTypeRegistry;
|
use bevy_property::PropertyTypeRegistry;
|
||||||
use bevy_type_registry::TypeRegistry;
|
use bevy_type_registry::TypeRegistry;
|
||||||
use serde::de::DeserializeSeed;
|
use serde::de::DeserializeSeed;
|
||||||
use bevy_ecs::{Resources, FromResources};
|
|
||||||
use std::{
|
use std::{
|
||||||
path::Path,
|
path::Path,
|
||||||
sync::{Arc, RwLock},
|
sync::{Arc, RwLock},
|
||||||
|
|
|
@ -7,7 +7,7 @@ use serde::Serialize;
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct Scene {
|
pub struct Scene {
|
||||||
pub entities: Vec<Entity>,
|
pub entities: Vec<Entity>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Entity {
|
pub struct Entity {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use glam::{Vec3, Vec2};
|
use glam::{Vec2, Vec3};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum Collision {
|
pub enum Collision {
|
||||||
|
|
|
@ -3,13 +3,13 @@ use crate::{
|
||||||
TextureAtlasSprite, QUAD_HANDLE, SPRITE_SHEET_PIPELINE_HANDLE,
|
TextureAtlasSprite, QUAD_HANDLE, SPRITE_SHEET_PIPELINE_HANDLE,
|
||||||
};
|
};
|
||||||
use bevy_asset::Handle;
|
use bevy_asset::Handle;
|
||||||
|
use bevy_ecs::Bundle;
|
||||||
use bevy_render::{
|
use bevy_render::{
|
||||||
draw::Draw,
|
draw::Draw,
|
||||||
mesh::Mesh,
|
mesh::Mesh,
|
||||||
pipeline::{DynamicBinding, PipelineSpecialization, RenderPipeline, RenderPipelines},
|
pipeline::{DynamicBinding, PipelineSpecialization, RenderPipeline, RenderPipelines},
|
||||||
};
|
};
|
||||||
use bevy_transform::prelude::{Rotation, Scale, Transform, Translation};
|
use bevy_transform::prelude::{Rotation, Scale, Transform, Translation};
|
||||||
use bevy_ecs::Bundle;
|
|
||||||
|
|
||||||
#[derive(Bundle)]
|
#[derive(Bundle)]
|
||||||
pub struct SpriteComponents {
|
pub struct SpriteComponents {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
|
pub mod collide_aabb;
|
||||||
mod color_material;
|
mod color_material;
|
||||||
mod dynamic_texture_atlas_builder;
|
mod dynamic_texture_atlas_builder;
|
||||||
pub mod entity;
|
pub mod entity;
|
||||||
pub mod collide_aabb;
|
|
||||||
mod rect;
|
mod rect;
|
||||||
mod render;
|
mod render;
|
||||||
mod sprite;
|
mod sprite;
|
||||||
|
@ -18,12 +18,12 @@ pub use texture_atlas_builder::*;
|
||||||
|
|
||||||
use bevy_app::{stage, AppBuilder, AppPlugin};
|
use bevy_app::{stage, AppBuilder, AppPlugin};
|
||||||
use bevy_asset::{AddAsset, Assets, Handle};
|
use bevy_asset::{AddAsset, Assets, Handle};
|
||||||
|
use bevy_ecs::IntoQuerySystem;
|
||||||
use bevy_render::{
|
use bevy_render::{
|
||||||
mesh::{shape, Mesh},
|
mesh::{shape, Mesh},
|
||||||
render_graph::RenderGraph,
|
render_graph::RenderGraph,
|
||||||
shader::asset_shader_defs_system,
|
shader::asset_shader_defs_system,
|
||||||
};
|
};
|
||||||
use bevy_ecs::IntoQuerySystem;
|
|
||||||
use glam::Vec2;
|
use glam::Vec2;
|
||||||
use sprite::sprite_system;
|
use sprite::sprite_system;
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@ impl AppPlugin for SpritePlugin {
|
||||||
let mut meshes = resources.get_mut::<Assets<Mesh>>().unwrap();
|
let mut meshes = resources.get_mut::<Assets<Mesh>>().unwrap();
|
||||||
meshes.set(
|
meshes.set(
|
||||||
QUAD_HANDLE,
|
QUAD_HANDLE,
|
||||||
// Use a flipped quad because the camera is facing "forward" but quads should face backward
|
// Use a flipped quad because the camera is facing "forward" but quads should face backward
|
||||||
Mesh::from(shape::Quad::flipped(Vec2::new(1.0, 1.0))),
|
Mesh::from(shape::Quad::flipped(Vec2::new(1.0, 1.0))),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
use crate::{ColorMaterial, TextureAtlas, TextureAtlasSprite, Sprite};
|
use crate::{ColorMaterial, Sprite, TextureAtlas, TextureAtlasSprite};
|
||||||
use bevy_asset::{Assets, Handle};
|
use bevy_asset::{Assets, Handle};
|
||||||
|
use bevy_ecs::Resources;
|
||||||
use bevy_render::{
|
use bevy_render::{
|
||||||
base_render_graph,
|
base_render_graph,
|
||||||
pipeline::{state_descriptors::*, PipelineDescriptor},
|
pipeline::{state_descriptors::*, PipelineDescriptor},
|
||||||
|
@ -10,7 +11,6 @@ use bevy_render::{
|
||||||
shader::{Shader, ShaderStage, ShaderStages},
|
shader::{Shader, ShaderStage, ShaderStages},
|
||||||
texture::TextureFormat,
|
texture::TextureFormat,
|
||||||
};
|
};
|
||||||
use bevy_ecs::Resources;
|
|
||||||
|
|
||||||
pub const SPRITE_PIPELINE_HANDLE: Handle<PipelineDescriptor> =
|
pub const SPRITE_PIPELINE_HANDLE: Handle<PipelineDescriptor> =
|
||||||
Handle::from_u128(278534784033876544639935131272264723170);
|
Handle::from_u128(278534784033876544639935131272264723170);
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
use crate::ColorMaterial;
|
use crate::ColorMaterial;
|
||||||
use bevy_asset::{Assets, Handle};
|
use bevy_asset::{Assets, Handle};
|
||||||
use bevy_core::bytes::Byteable;
|
use bevy_core::bytes::Byteable;
|
||||||
|
use bevy_ecs::{Query, Res};
|
||||||
use bevy_render::{
|
use bevy_render::{
|
||||||
render_resource::{RenderResource, RenderResources},
|
render_resource::{RenderResource, RenderResources},
|
||||||
texture::Texture,
|
texture::Texture,
|
||||||
};
|
};
|
||||||
use glam::Vec2;
|
use glam::Vec2;
|
||||||
use bevy_ecs::{Res, Query};
|
|
||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
#[derive(Default, RenderResources, RenderResource)]
|
#[derive(Default, RenderResources, RenderResource)]
|
||||||
|
|
|
@ -98,4 +98,4 @@ impl TextureAtlas {
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.and_then(|texture_handles| texture_handles.get(&texture).cloned())
|
.and_then(|texture_handles| texture_handles.get(&texture).cloned())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
|
use bevy_ecs::Entity;
|
||||||
use bevy_property::Properties;
|
use bevy_property::Properties;
|
||||||
use shrinkwraprs::Shrinkwrap;
|
use shrinkwraprs::Shrinkwrap;
|
||||||
use smallvec::SmallVec;
|
use smallvec::SmallVec;
|
||||||
use bevy_ecs::Entity;
|
|
||||||
|
|
||||||
#[derive(Shrinkwrap, Default, Clone, Properties, Debug)]
|
#[derive(Shrinkwrap, Default, Clone, Properties, Debug)]
|
||||||
#[shrinkwrap(mutable)]
|
#[shrinkwrap(mutable)]
|
||||||
|
|
|
@ -66,8 +66,7 @@ pub fn parent_update_system(
|
||||||
// Add to the parent's `Children` (either the real component, or
|
// Add to the parent's `Children` (either the real component, or
|
||||||
// `children_additions`).
|
// `children_additions`).
|
||||||
log::trace!("Adding {:?} to it's new parent {:?}", entity, parent.0);
|
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
|
// This is the parent
|
||||||
log::trace!(
|
log::trace!(
|
||||||
" > The new parent {:?} already has a `Children`, adding to it.",
|
" > 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)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use super::*;
|
use super::*;
|
||||||
use bevy_ecs::{Resources, World, Schedule};
|
|
||||||
use crate::build_systems;
|
use crate::build_systems;
|
||||||
|
use bevy_ecs::{Resources, Schedule, World};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn correct_children() {
|
fn correct_children() {
|
||||||
|
@ -163,7 +162,6 @@ mod test {
|
||||||
// Parent `e1` to `e2`.
|
// Parent `e1` to `e2`.
|
||||||
(*world.get_mut::<Parent>(children[0]).unwrap()).0 = children[1];
|
(*world.get_mut::<Parent>(children[0]).unwrap()).0 = children[1];
|
||||||
|
|
||||||
|
|
||||||
schedule.run(&mut world, &mut resources);
|
schedule.run(&mut world, &mut resources);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
|
|
@ -242,7 +242,10 @@ mod test {
|
||||||
Mat4::from_rotation_translation(r.0, t.0)
|
Mat4::from_rotation_translation(r.0, t.0)
|
||||||
);
|
);
|
||||||
assert_eq!(
|
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)
|
Mat4::from_scale_rotation_translation(Vec3::new(s.0, s.0, s.0), Quat::default(), t.0)
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
|
|
@ -105,7 +105,7 @@ mod test {
|
||||||
),
|
),
|
||||||
])
|
])
|
||||||
.collect::<Vec<Entity>>();
|
.collect::<Vec<Entity>>();
|
||||||
|
|
||||||
// TODO: ideally we dont need three runs to keep transforms in sync.
|
// TODO: ideally we dont need three runs to keep transforms in sync.
|
||||||
// command buffers should be flushed in the appropriate places
|
// command buffers should be flushed in the appropriate places
|
||||||
schedule.run(&mut world, &mut resources);
|
schedule.run(&mut world, &mut resources);
|
||||||
|
|
|
@ -201,7 +201,7 @@ pub fn transform_systems() -> Vec<Box<dyn System>> {
|
||||||
mod test {
|
mod test {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::math::{Mat4, Quat, Vec3};
|
use crate::math::{Mat4, Quat, Vec3};
|
||||||
use bevy_ecs::{Schedule, World, Resources};
|
use bevy_ecs::{Resources, Schedule, World};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn correct_world_transformation() {
|
fn correct_world_transformation() {
|
||||||
|
@ -251,10 +251,7 @@ mod test {
|
||||||
Mat4::from_scale(Vec3::new(s.0, s.0, s.0))
|
Mat4::from_scale(Vec3::new(s.0, s.0, s.0))
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
world
|
world.get::<Transform>(non_uniform_scale).unwrap().value,
|
||||||
.get::<Transform>(non_uniform_scale)
|
|
||||||
.unwrap()
|
|
||||||
.value,
|
|
||||||
Mat4::from_scale(nus.0)
|
Mat4::from_scale(nus.0)
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
@ -265,24 +262,15 @@ mod test {
|
||||||
Mat4::from_rotation_translation(r.0, t.0)
|
Mat4::from_rotation_translation(r.0, t.0)
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
world
|
world.get::<Transform>(translation_and_scale).unwrap().value,
|
||||||
.get::<Transform>(translation_and_scale)
|
|
||||||
.unwrap()
|
|
||||||
.value,
|
|
||||||
Mat4::from_scale_rotation_translation(Vec3::new(s.0, s.0, s.0), Quat::default(), t.0)
|
Mat4::from_scale_rotation_translation(Vec3::new(s.0, s.0, s.0), Quat::default(), t.0)
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
world
|
world.get::<Transform>(translation_and_nus).unwrap().value,
|
||||||
.get::<Transform>(translation_and_nus)
|
|
||||||
.unwrap()
|
|
||||||
.value,
|
|
||||||
Mat4::from_scale_rotation_translation(nus.0, Quat::default(), t.0)
|
Mat4::from_scale_rotation_translation(nus.0, Quat::default(), t.0)
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
world
|
world.get::<Transform>(rotation_scale).unwrap().value,
|
||||||
.get::<Transform>(rotation_scale)
|
|
||||||
.unwrap()
|
|
||||||
.value,
|
|
||||||
Mat4::from_scale_rotation_translation(Vec3::new(s.0, s.0, s.0), r.0, Vec3::default())
|
Mat4::from_scale_rotation_translation(Vec3::new(s.0, s.0, s.0), r.0, Vec3::default())
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
|
|
@ -1,10 +1,14 @@
|
||||||
use super::Node;
|
use super::Node;
|
||||||
use crate::{render::UI_PIPELINE_HANDLE, widget::Label};
|
use crate::{render::UI_PIPELINE_HANDLE, widget::Label};
|
||||||
use bevy_asset::Handle;
|
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_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)]
|
#[derive(Bundle)]
|
||||||
pub struct UiComponents {
|
pub struct UiComponents {
|
||||||
|
|
|
@ -13,8 +13,8 @@ pub use render::*;
|
||||||
pub use ui_update_system::*;
|
pub use ui_update_system::*;
|
||||||
|
|
||||||
use bevy_app::{stage, AppBuilder, AppPlugin};
|
use bevy_app::{stage, AppBuilder, AppPlugin};
|
||||||
use bevy_render::render_graph::RenderGraph;
|
|
||||||
use bevy_ecs::IntoQuerySystem;
|
use bevy_ecs::IntoQuerySystem;
|
||||||
|
use bevy_render::render_graph::RenderGraph;
|
||||||
use widget::Label;
|
use widget::Label;
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use super::{Anchors, Margins};
|
use super::{Anchors, Margins};
|
||||||
use bevy_transform::prelude::Translation;
|
|
||||||
use bevy_render::render_resource::RenderResources;
|
use bevy_render::render_resource::RenderResources;
|
||||||
|
use bevy_transform::prelude::Translation;
|
||||||
use glam::{Vec2, Vec3};
|
use glam::{Vec2, Vec3};
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
|
@ -55,7 +55,8 @@ impl Node {
|
||||||
);
|
);
|
||||||
|
|
||||||
self.size = Vec2::new(quad_width, quad_height);
|
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(
|
fn compute_dimension_properties(
|
||||||
|
|
|
@ -1,13 +1,17 @@
|
||||||
|
use crate::Node;
|
||||||
use bevy_asset::{Assets, Handle};
|
use bevy_asset::{Assets, Handle};
|
||||||
|
use bevy_ecs::Resources;
|
||||||
use bevy_render::{
|
use bevy_render::{
|
||||||
base_render_graph,
|
base_render_graph,
|
||||||
pipeline::{state_descriptors::*, PipelineDescriptor},
|
pipeline::{state_descriptors::*, PipelineDescriptor},
|
||||||
render_graph::{nodes::{PassNode, CameraNode, RenderResourcesNode}, RenderGraph},
|
render_graph::{
|
||||||
|
nodes::{CameraNode, PassNode, RenderResourcesNode},
|
||||||
|
RenderGraph,
|
||||||
|
},
|
||||||
shader::{Shader, ShaderStage, ShaderStages},
|
shader::{Shader, ShaderStage, ShaderStages},
|
||||||
texture::TextureFormat, ActiveCameras,
|
texture::TextureFormat,
|
||||||
|
ActiveCameras,
|
||||||
};
|
};
|
||||||
use crate::Node;
|
|
||||||
use bevy_ecs::Resources;
|
|
||||||
|
|
||||||
pub const UI_PIPELINE_HANDLE: Handle<PipelineDescriptor> =
|
pub const UI_PIPELINE_HANDLE: Handle<PipelineDescriptor> =
|
||||||
Handle::from_u128(323432002226399387835192542539754486265);
|
Handle::from_u128(323432002226399387835192542539754486265);
|
||||||
|
@ -84,7 +88,9 @@ impl UiRenderGraphBuilder for RenderGraph {
|
||||||
self.add_node_edge(node::NODE, base_render_graph::node::MAIN_PASS)
|
self.add_node_edge(node::NODE, base_render_graph::node::MAIN_PASS)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let mut active_cameras = resources.get_mut::<ActiveCameras>().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);
|
main_pass_node.add_camera(camera::UI_CAMERA);
|
||||||
active_cameras.add(camera::UI_CAMERA);
|
active_cameras.add(camera::UI_CAMERA);
|
||||||
self
|
self
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
use crate::Node;
|
use crate::Node;
|
||||||
use bevy_asset::{Assets, Handle};
|
use bevy_asset::{Assets, Handle};
|
||||||
|
use bevy_ecs::{Query, Res, ResMut};
|
||||||
use bevy_render::{
|
use bevy_render::{
|
||||||
draw::{Draw, DrawContext, Drawable},
|
draw::{Draw, DrawContext, Drawable},
|
||||||
render_resource::{AssetRenderResourceBindings, RenderResourceBindings},
|
render_resource::{AssetRenderResourceBindings, RenderResourceBindings},
|
||||||
|
@ -9,7 +10,6 @@ use bevy_render::{
|
||||||
use bevy_sprite::TextureAtlas;
|
use bevy_sprite::TextureAtlas;
|
||||||
use bevy_text::{DrawableText, Font, FontAtlasSet, TextStyle};
|
use bevy_text::{DrawableText, Font, FontAtlasSet, TextStyle};
|
||||||
use bevy_transform::prelude::Transform;
|
use bevy_transform::prelude::Transform;
|
||||||
use bevy_ecs::{Res, ResMut, Query};
|
|
||||||
|
|
||||||
pub struct Label {
|
pub struct Label {
|
||||||
pub text: String,
|
pub text: String,
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
use crate::renderer::WgpuRenderResourceContext;
|
use crate::renderer::WgpuRenderResourceContext;
|
||||||
use bevy_app::{AppBuilder, AppPlugin};
|
use bevy_app::{AppBuilder, AppPlugin};
|
||||||
use bevy_diagnostic::{Diagnostic, DiagnosticId, Diagnostics};
|
use bevy_diagnostic::{Diagnostic, DiagnosticId, Diagnostics};
|
||||||
|
use bevy_ecs::{IntoQuerySystem, Res, ResMut};
|
||||||
use bevy_render::renderer::RenderResourceContext;
|
use bevy_render::renderer::RenderResourceContext;
|
||||||
use bevy_ecs::{Res, ResMut, IntoQuerySystem};
|
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct WgpuResourceDiagnosticsPlugin;
|
pub struct WgpuResourceDiagnosticsPlugin;
|
||||||
|
|
|
@ -10,12 +10,12 @@ pub use wgpu_renderer::*;
|
||||||
pub use wgpu_resources::*;
|
pub use wgpu_resources::*;
|
||||||
|
|
||||||
use bevy_app::{AppBuilder, AppPlugin};
|
use bevy_app::{AppBuilder, AppPlugin};
|
||||||
|
use bevy_ecs::{IntoQuerySystem, Resources, ThreadLocalSystem, World};
|
||||||
use bevy_render::{
|
use bevy_render::{
|
||||||
render_resource::{free_shared_buffers_system, SharedBuffers},
|
render_resource::{free_shared_buffers_system, SharedBuffers},
|
||||||
renderer::RenderResourceContext,
|
renderer::RenderResourceContext,
|
||||||
};
|
};
|
||||||
use renderer::WgpuRenderResourceContext;
|
use renderer::WgpuRenderResourceContext;
|
||||||
use bevy_ecs::{World, Resources, ThreadLocalSystem, IntoQuerySystem};
|
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct WgpuPlugin;
|
pub struct WgpuPlugin;
|
||||||
|
@ -23,11 +23,14 @@ pub struct WgpuPlugin;
|
||||||
impl AppPlugin for WgpuPlugin {
|
impl AppPlugin for WgpuPlugin {
|
||||||
fn build(&self, app: &mut AppBuilder) {
|
fn build(&self, app: &mut AppBuilder) {
|
||||||
let render_system = wgpu_render_system(app.resources_mut());
|
let render_system = wgpu_render_system(app.resources_mut());
|
||||||
app.add_system_to_stage(bevy_render::stage::RENDER, ThreadLocalSystem::new(render_system))
|
app.add_system_to_stage(
|
||||||
.add_system_to_stage(
|
bevy_render::stage::RENDER,
|
||||||
bevy_render::stage::POST_RENDER,
|
ThreadLocalSystem::new(render_system),
|
||||||
free_shared_buffers_system.system(),
|
)
|
||||||
);
|
.add_system_to_stage(
|
||||||
|
bevy_render::stage::POST_RENDER,
|
||||||
|
free_shared_buffers_system.system(),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use super::{WgpuRenderContext, WgpuRenderResourceContext};
|
use super::{WgpuRenderContext, WgpuRenderResourceContext};
|
||||||
|
use bevy_ecs::{Resources, World};
|
||||||
use bevy_render::{
|
use bevy_render::{
|
||||||
render_graph::{Edge, NodeId, ResourceSlots, StageBorrow},
|
render_graph::{Edge, NodeId, ResourceSlots, StageBorrow},
|
||||||
renderer::RenderResourceContext,
|
renderer::RenderResourceContext,
|
||||||
|
@ -7,7 +8,6 @@ use std::{
|
||||||
collections::HashMap,
|
collections::HashMap,
|
||||||
sync::{Arc, RwLock},
|
sync::{Arc, RwLock},
|
||||||
};
|
};
|
||||||
use bevy_ecs::{Resources, World};
|
|
||||||
|
|
||||||
pub struct WgpuRenderGraphExecutor {
|
pub struct WgpuRenderGraphExecutor {
|
||||||
pub max_thread_count: usize,
|
pub max_thread_count: usize,
|
||||||
|
|
|
@ -56,7 +56,11 @@ impl<'a> RenderPass for WgpuRenderPass<'a> {
|
||||||
bind_group: BindGroupId,
|
bind_group: BindGroupId,
|
||||||
dynamic_uniform_indices: Option<&[u32]>,
|
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) {
|
if let Some(wgpu_bind_group) = bind_group_info.bind_groups.get(&bind_group) {
|
||||||
const EMPTY: &'static [u32] = &[];
|
const EMPTY: &'static [u32] = &[];
|
||||||
let dynamic_uniform_indices =
|
let dynamic_uniform_indices =
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
use crate::renderer::{WgpuRenderGraphExecutor, WgpuRenderResourceContext};
|
use crate::renderer::{WgpuRenderGraphExecutor, WgpuRenderResourceContext};
|
||||||
use bevy_app::{EventReader, Events};
|
use bevy_app::{EventReader, Events};
|
||||||
|
use bevy_ecs::{Resources, World};
|
||||||
use bevy_render::{
|
use bevy_render::{
|
||||||
render_graph::{DependentNodeStager, RenderGraph, RenderGraphStager},
|
render_graph::{DependentNodeStager, RenderGraph, RenderGraphStager},
|
||||||
renderer::RenderResourceContext,
|
renderer::RenderResourceContext,
|
||||||
};
|
};
|
||||||
use bevy_window::{WindowCreated, WindowResized, Windows};
|
use bevy_window::{WindowCreated, WindowResized, Windows};
|
||||||
use std::{ops::Deref, sync::Arc};
|
use std::{ops::Deref, sync::Arc};
|
||||||
use bevy_ecs::{World, Resources};
|
|
||||||
pub struct WgpuRenderer {
|
pub struct WgpuRenderer {
|
||||||
pub instance: wgpu::Instance,
|
pub instance: wgpu::Instance,
|
||||||
pub device: Arc<wgpu::Device>,
|
pub device: Arc<wgpu::Device>,
|
||||||
|
|
|
@ -36,8 +36,10 @@ impl AppPlugin for WindowPlugin {
|
||||||
.init_resource::<Windows>();
|
.init_resource::<Windows>();
|
||||||
|
|
||||||
if let Some(ref primary_window_descriptor) = self.primary_window {
|
if let Some(ref primary_window_descriptor) = self.primary_window {
|
||||||
let mut create_window_event =
|
let mut create_window_event = app
|
||||||
app.resources_mut().get_mut::<Events<CreateWindow>>().unwrap();
|
.resources_mut()
|
||||||
|
.get_mut::<Events<CreateWindow>>()
|
||||||
|
.unwrap();
|
||||||
create_window_event.send(CreateWindow {
|
create_window_event.send(CreateWindow {
|
||||||
id: WindowId::new(),
|
id: WindowId::new(),
|
||||||
descriptor: primary_window_descriptor.clone(),
|
descriptor: primary_window_descriptor.clone(),
|
||||||
|
|
|
@ -10,7 +10,6 @@ impl Default for WindowReference {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
WindowReference::Primary
|
WindowReference::Primary
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
|
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
|
||||||
|
|
|
@ -8,6 +8,7 @@ use bevy_input::{
|
||||||
};
|
};
|
||||||
|
|
||||||
use bevy_app::{App, AppBuilder, AppExit, AppPlugin, EventReader, Events};
|
use bevy_app::{App, AppBuilder, AppExit, AppPlugin, EventReader, Events};
|
||||||
|
use bevy_ecs::Resources;
|
||||||
use bevy_window::{
|
use bevy_window::{
|
||||||
CreateWindow, CursorMoved, Window, WindowCloseRequested, WindowCreated, WindowResized, Windows,
|
CreateWindow, CursorMoved, Window, WindowCloseRequested, WindowCreated, WindowResized, Windows,
|
||||||
};
|
};
|
||||||
|
@ -17,7 +18,6 @@ use winit::{
|
||||||
event::{DeviceEvent, WindowEvent},
|
event::{DeviceEvent, WindowEvent},
|
||||||
event_loop::{ControlFlow, EventLoop, EventLoopWindowTarget},
|
event_loop::{ControlFlow, EventLoop, EventLoopWindowTarget},
|
||||||
};
|
};
|
||||||
use bevy_ecs::Resources;
|
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct WinitPlugin;
|
pub struct WinitPlugin;
|
||||||
|
|
|
@ -11,10 +11,7 @@ fn main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// rotates the parent, which will result in the child also rotating
|
/// rotates the parent, which will result in the child also rotating
|
||||||
fn rotator_system(
|
fn rotator_system(time: Res<Time>, mut query: Query<(&Rotator, &mut Rotation)>) {
|
||||||
time: Res<Time>,
|
|
||||||
mut query: Query<(&Rotator, &mut Rotation)>,
|
|
||||||
) {
|
|
||||||
for (_rotator, rotation) in &mut query.iter() {
|
for (_rotator, rotation) in &mut query.iter() {
|
||||||
rotation.0 = rotation.0 * Quat::from_rotation_x(3.0 * time.delta_seconds);
|
rotation.0 = rotation.0 * Quat::from_rotation_x(3.0 * time.delta_seconds);
|
||||||
}
|
}
|
||||||
|
|
|
@ -221,7 +221,7 @@ fn thread_local_system(world: &mut World, resources: &mut Resources) {
|
||||||
|
|
||||||
// Sometimes systems need their own unique "local" state. Bevy's ECS provides Local<T> resources for this case.
|
// Sometimes systems need their own unique "local" state. Bevy's ECS provides Local<T> resources for this case.
|
||||||
// Local<T> resources are unique to their system and are automatically initialized on your behalf (if they don't already exist).
|
// Local<T> resources are unique to their system and are automatically initialized on your behalf (if they don't already exist).
|
||||||
// If you have a system's id, you can also access local resources directly in the Resources collection using `Resources::get_local()`.
|
// If you have a system's id, you can also access local resources directly in the Resources collection using `Resources::get_local()`.
|
||||||
// In general you should only need this feature in the following cases:
|
// In general you should only need this feature in the following cases:
|
||||||
// 1. You have multiple instances of the same system and they each need their own unique state
|
// 1. You have multiple instances of the same system and they each need their own unique state
|
||||||
// 2. You already have a global version of a resource that you don't want to overwrite for your current system
|
// 2. You already have a global version of a resource that you don't want to overwrite for your current system
|
||||||
|
|
|
@ -172,19 +172,13 @@ fn paddle_movement_system(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn ball_movement_system(
|
fn ball_movement_system(time: Res<Time>, mut ball_query: Query<(&Ball, &mut Translation)>) {
|
||||||
time: Res<Time>,
|
|
||||||
mut ball_query: Query<(&Ball, &mut Translation)>,
|
|
||||||
) {
|
|
||||||
for (ball, translation) in &mut ball_query.iter() {
|
for (ball, translation) in &mut ball_query.iter() {
|
||||||
translation.0 += ball.velocity * time.delta_seconds;
|
translation.0 += ball.velocity * time.delta_seconds;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn scoreboard_system(
|
fn scoreboard_system(scoreboard: Res<Scoreboard>, mut query: Query<&mut Label>) {
|
||||||
scoreboard: Res<Scoreboard>,
|
|
||||||
mut query: Query<&mut Label>,
|
|
||||||
) {
|
|
||||||
for mut label in &mut query.iter() {
|
for mut label in &mut query.iter() {
|
||||||
label.text = format!("Score: {}", scoreboard.score);
|
label.text = format!("Score: {}", scoreboard.score);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
use bevy::prelude::*;
|
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() {
|
fn main() {
|
||||||
App::build()
|
App::build()
|
||||||
|
@ -79,7 +82,7 @@ fn setup(
|
||||||
mesh: cube_handle,
|
mesh: cube_handle,
|
||||||
render_pipelines: RenderPipelines::from_pipelines(vec![RenderPipeline::specialized(
|
render_pipelines: RenderPipelines::from_pipelines(vec![RenderPipeline::specialized(
|
||||||
pipeline_handle,
|
pipeline_handle,
|
||||||
// NOTE: in the future you wont need to manually declare dynamic bindings
|
// NOTE: in the future you wont need to manually declare dynamic bindings
|
||||||
PipelineSpecialization {
|
PipelineSpecialization {
|
||||||
dynamic_bindings: vec![
|
dynamic_bindings: vec![
|
||||||
// Transform
|
// Transform
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
use bevy::{prelude::*, render::shader};
|
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() {
|
fn main() {
|
||||||
App::build()
|
App::build()
|
||||||
|
@ -96,7 +99,7 @@ fn setup(
|
||||||
mesh: cube_handle,
|
mesh: cube_handle,
|
||||||
render_pipelines: RenderPipelines::from_pipelines(vec![RenderPipeline::specialized(
|
render_pipelines: RenderPipelines::from_pipelines(vec![RenderPipeline::specialized(
|
||||||
pipeline_handle,
|
pipeline_handle,
|
||||||
// NOTE: in the future you wont need to manually declare dynamic bindings
|
// NOTE: in the future you wont need to manually declare dynamic bindings
|
||||||
PipelineSpecialization {
|
PipelineSpecialization {
|
||||||
dynamic_bindings: vec![
|
dynamic_bindings: vec![
|
||||||
// Transform
|
// Transform
|
||||||
|
@ -122,7 +125,7 @@ fn setup(
|
||||||
mesh: cube_handle,
|
mesh: cube_handle,
|
||||||
render_pipelines: RenderPipelines::from_pipelines(vec![RenderPipeline::specialized(
|
render_pipelines: RenderPipelines::from_pipelines(vec![RenderPipeline::specialized(
|
||||||
pipeline_handle,
|
pipeline_handle,
|
||||||
// NOTE: in the future you wont need to manually declare dynamic bindings
|
// NOTE: in the future you wont need to manually declare dynamic bindings
|
||||||
PipelineSpecialization {
|
PipelineSpecialization {
|
||||||
dynamic_bindings: vec![
|
dynamic_bindings: vec![
|
||||||
// Transform
|
// Transform
|
||||||
|
|
|
@ -12,10 +12,7 @@ fn main() {
|
||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn text_update_system(
|
fn text_update_system(diagnostics: Res<Diagnostics>, mut query: Query<&mut Label>) {
|
||||||
diagnostics: Res<Diagnostics>,
|
|
||||||
mut query: Query<&mut Label>,
|
|
||||||
) {
|
|
||||||
for label in &mut query.iter() {
|
for label in &mut query.iter() {
|
||||||
if let Some(fps) = diagnostics.get(FrameTimeDiagnosticsPlugin::FPS) {
|
if let Some(fps) = diagnostics.get(FrameTimeDiagnosticsPlugin::FPS) {
|
||||||
if let Some(average) = fps.average() {
|
if let Some(average) = fps.average() {
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue