mirror of
https://github.com/bevyengine/bevy
synced 2024-11-22 04:33:37 +00:00
cargo fmt
This commit is contained in:
parent
1d5388c4f0
commit
b5d78477cf
44 changed files with 169 additions and 202 deletions
|
@ -1,8 +1,7 @@
|
|||
use crate::{
|
||||
stage,
|
||||
plugin::{load_plugin, AppPlugin},
|
||||
schedule_plan::SchedulePlan,
|
||||
App, Events,
|
||||
stage, App, Events,
|
||||
};
|
||||
|
||||
use legion::prelude::{Resources, Runnable, Schedulable, Universe, World};
|
||||
|
@ -34,7 +33,7 @@ impl AppBuilder {
|
|||
app: Some(App::default()),
|
||||
schedule_plan: SchedulePlan::default(),
|
||||
startup_schedule_plan: SchedulePlan::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn app(&self) -> &App {
|
||||
|
@ -188,10 +187,7 @@ impl AppBuilder {
|
|||
T: Send + Sync + 'static,
|
||||
{
|
||||
self.add_resource(Events::<T>::default())
|
||||
.add_system_to_stage(
|
||||
stage::EVENT_UPDATE,
|
||||
Events::<T>::build_update_system(),
|
||||
)
|
||||
.add_system_to_stage(stage::EVENT_UPDATE, Events::<T>::build_update_system())
|
||||
}
|
||||
|
||||
pub fn add_resource<T>(&mut self, resource: T) -> &mut Self
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use legion::prelude::{Schedulable, SystemBuilder, Resources};
|
||||
use legion::prelude::{Resources, Schedulable, SystemBuilder};
|
||||
use std::marker::PhantomData;
|
||||
|
||||
struct EventInstance<T> {
|
||||
|
|
|
@ -23,4 +23,4 @@ pub fn load_plugin(path: &str) -> (Library, Box<dyn AppPlugin>) {
|
|||
|
||||
fn type_name_of_val<T: ?Sized>(_val: &T) -> &'static str {
|
||||
std::any::type_name::<T>()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,4 +45,3 @@ pub fn stop_timer_system() -> Box<dyn Schedulable> {
|
|||
time.stop();
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -2,4 +2,4 @@ mod hierarchy;
|
|||
mod world_builder;
|
||||
|
||||
pub use hierarchy::*;
|
||||
pub use world_builder::*;
|
||||
pub use world_builder::*;
|
||||
|
|
|
@ -47,7 +47,7 @@ impl Modules {
|
|||
bevy_core: "bevy::core".to_string(),
|
||||
bevy_app: "bevy::app".to_string(),
|
||||
legion: "bevy".to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn external() -> Modules {
|
||||
|
@ -77,7 +77,8 @@ impl Default for ModuleAttributeArgs {
|
|||
static MODULE_ATTRIBUTE_NAME: &'static str = "module";
|
||||
|
||||
fn get_modules(ast: &DeriveInput) -> Modules {
|
||||
let module_attribute_args = ast.attrs
|
||||
let module_attribute_args = ast
|
||||
.attrs
|
||||
.iter()
|
||||
.find(|a| a.path.get_ident().as_ref().unwrap().to_string() == MODULE_ATTRIBUTE_NAME)
|
||||
.map(|a| {
|
||||
|
@ -86,9 +87,9 @@ fn get_modules(ast: &DeriveInput) -> Modules {
|
|||
});
|
||||
if let Some(module_attribute_args) = module_attribute_args {
|
||||
let mut modules = if module_attribute_args.meta {
|
||||
Modules::meta()
|
||||
Modules::meta()
|
||||
} else {
|
||||
Modules::external()
|
||||
Modules::external()
|
||||
};
|
||||
|
||||
if let Some(path) = module_attribute_args.bevy_asset {
|
||||
|
|
|
@ -2,9 +2,9 @@ mod diagnostic;
|
|||
pub mod diagnostics;
|
||||
pub use diagnostic::*;
|
||||
|
||||
use bevy_app::{AppPlugin, AppBuilder};
|
||||
use bevy_app::{AppBuilder, AppPlugin};
|
||||
use diagnostics::{frame_time_diagnostic_system, print_diagnostics_system};
|
||||
use std::time::Duration;
|
||||
use diagnostics::{print_diagnostics_system, frame_time_diagnostic_system};
|
||||
|
||||
pub struct DiagnosticsPlugin {
|
||||
pub print_wait_duration: Duration,
|
||||
|
|
|
@ -215,4 +215,4 @@ pub enum VirtualKeyCode {
|
|||
Copy,
|
||||
Paste,
|
||||
Cut,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,4 +17,4 @@ pub enum MouseButton {
|
|||
#[derive(Debug, Clone)]
|
||||
pub struct MouseMotion {
|
||||
pub delta: (f64, f64),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
//! Atomic runtime borrow checking module.
|
||||
//! These types implement something akin to `RefCell`, but are atomically handled allowing them to
|
||||
//! cross thread boundaries.
|
||||
use std::any::{type_name, Any};
|
||||
use std::cell::UnsafeCell;
|
||||
use std::hash::{Hash, Hasher};
|
||||
use std::any::{Any, type_name};
|
||||
use std::ops::Deref;
|
||||
use std::ops::DerefMut;
|
||||
use std::sync::atomic::AtomicIsize;
|
||||
|
@ -17,9 +17,7 @@ pub trait DowncastTypename {
|
|||
fn is_typename<T: Any>(&self) -> bool;
|
||||
}
|
||||
|
||||
pub fn type_name_of_val<T: ?Sized>(_val: &T) -> &'static str {
|
||||
type_name::<T>()
|
||||
}
|
||||
pub fn type_name_of_val<T: ?Sized>(_val: &T) -> &'static str { type_name::<T>() }
|
||||
/// A `RefCell` implementation which is thread safe. This type performs all the standard runtime
|
||||
/// borrow checking which would be familiar from using `RefCell`.
|
||||
///
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
use legion_core::borrow::DowncastTypename;
|
||||
use downcast_rs::{impl_downcast, Downcast};
|
||||
use fxhash::FxHashMap;
|
||||
use legion_core::borrow::DowncastTypename;
|
||||
use legion_core::borrow::{AtomicRefCell, Ref, RefMut};
|
||||
use legion_core::query::{Read, ReadOnly, Write};
|
||||
use std::{
|
||||
any::{Any, type_name},
|
||||
any::{type_name, Any},
|
||||
marker::PhantomData,
|
||||
ops::{Deref, DerefMut},
|
||||
};
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
use bevy_derive::EntityArchetype;
|
||||
use crate::{
|
||||
mesh::Mesh, shader::uniforms::StandardMaterial, ActiveCamera, ActiveCamera2d, Camera,
|
||||
CameraType, Light, Renderable,
|
||||
};
|
||||
use bevy_asset::Handle;
|
||||
use crate::{shader::uniforms::StandardMaterial, mesh::Mesh, Renderable, Light, Camera, ActiveCamera, ActiveCamera2d, CameraType};
|
||||
use bevy_transform::components::{Translation, LocalToWorld, Rotation, Scale};
|
||||
use bevy_derive::EntityArchetype;
|
||||
use bevy_transform::components::{LocalToWorld, Rotation, Scale, Translation};
|
||||
|
||||
#[derive(EntityArchetype, Default)]
|
||||
#[module(meta = false)]
|
||||
|
@ -60,4 +63,4 @@ impl Default for Camera2dEntity {
|
|||
active_camera_2d: ActiveCamera2d,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
#![feature(min_specialization)]
|
||||
mod camera;
|
||||
pub mod entity;
|
||||
pub mod mesh;
|
||||
pub mod render_graph;
|
||||
pub mod shader;
|
||||
pub mod entity;
|
||||
|
||||
mod color;
|
||||
mod light;
|
||||
|
@ -30,14 +30,12 @@ use self::{
|
|||
draw_target::draw_targets::{
|
||||
AssignedBatchesDrawTarget, AssignedMeshesDrawTarget, MeshesDrawTarget, UiDrawTarget,
|
||||
},
|
||||
mesh::Mesh,
|
||||
pass::passes::ForwardPassBuilder,
|
||||
pipeline::{
|
||||
pipelines::ForwardPipelineBuilder, PipelineCompiler, ShaderPipelineAssignments,
|
||||
VertexBufferDescriptors, PipelineDescriptor
|
||||
pipelines::ForwardPipelineBuilder, PipelineCompiler, PipelineDescriptor,
|
||||
ShaderPipelineAssignments, VertexBufferDescriptors,
|
||||
},
|
||||
shader::{Shader, uniforms::StandardMaterial},
|
||||
texture::Texture,
|
||||
mesh::Mesh,
|
||||
render_graph::RenderGraph,
|
||||
render_resource::{
|
||||
build_entity_render_resource_assignments_system,
|
||||
|
@ -47,11 +45,13 @@ use self::{
|
|||
},
|
||||
AssetBatchers, EntityRenderResourceAssignments, RenderResourceAssignments,
|
||||
},
|
||||
shader::{uniforms::StandardMaterial, Shader},
|
||||
texture::Texture,
|
||||
};
|
||||
|
||||
use bevy_app::{AppBuilder, AppPlugin, GetEventReader, stage};
|
||||
use bevy_transform::prelude::LocalToWorld;
|
||||
use bevy_app::{stage, AppBuilder, AppPlugin, GetEventReader};
|
||||
use bevy_asset::AssetStorage;
|
||||
use bevy_transform::prelude::LocalToWorld;
|
||||
use bevy_window::WindowResized;
|
||||
|
||||
pub static RENDER_STAGE: &str = "render";
|
||||
|
@ -95,8 +95,7 @@ impl AppPlugin for RenderPlugin {
|
|||
fn build(&self, app: &mut AppBuilder) {
|
||||
let mut asset_batchers = AssetBatchers::default();
|
||||
asset_batchers.batch_types2::<Mesh, StandardMaterial>();
|
||||
app
|
||||
.add_system(build_entity_render_resource_assignments_system())
|
||||
app.add_system(build_entity_render_resource_assignments_system())
|
||||
.add_stage_after(stage::UPDATE, RENDER_STAGE)
|
||||
.add_resource(RenderGraph::default())
|
||||
.add_resource(AssetStorage::<Mesh>::new())
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
use super::{Color, PerspectiveCamera};
|
||||
use bevy_transform::components::Translation;
|
||||
use glam::Mat4;
|
||||
use std::ops::Range;
|
||||
use zerocopy::{AsBytes, FromBytes};
|
||||
use glam::Mat4;
|
||||
use bevy_transform::components::Translation;
|
||||
|
||||
pub struct Light {
|
||||
pub color: Color,
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use crate::{Vertex};
|
||||
use crate::Vertex;
|
||||
use bevy_asset::Asset;
|
||||
use glam::*;
|
||||
|
||||
|
|
|
@ -1,13 +1,15 @@
|
|||
use super::{BindType, PipelineDescriptor, PipelineLayout, PipelineLayoutType, VertexBufferDescriptors};
|
||||
use bevy_asset::{AssetStorage, Handle};
|
||||
use super::{
|
||||
BindType, PipelineDescriptor, PipelineLayout, PipelineLayoutType, VertexBufferDescriptors,
|
||||
};
|
||||
use crate::{
|
||||
render_resource::{
|
||||
BufferInfo, RenderResourceAssignments, RenderResourceAssignmentsId, ResourceInfo,
|
||||
},
|
||||
renderer::Renderer,
|
||||
Renderable,
|
||||
shader::{Shader, ShaderSource},
|
||||
Renderable,
|
||||
};
|
||||
use bevy_asset::{AssetStorage, Handle};
|
||||
use std::collections::{HashMap, HashSet};
|
||||
|
||||
use legion::prelude::*;
|
||||
|
|
|
@ -1,14 +1,12 @@
|
|||
use super::RenderGraphBuilder;
|
||||
use crate::{
|
||||
{
|
||||
draw_target::DrawTarget,
|
||||
pass::PassDescriptor,
|
||||
pipeline::{PipelineCompiler, PipelineDescriptor},
|
||||
render_resource::ResourceProvider,
|
||||
renderer::Renderer,
|
||||
texture::TextureDescriptor,
|
||||
shader::Shader,
|
||||
},
|
||||
draw_target::DrawTarget,
|
||||
pass::PassDescriptor,
|
||||
pipeline::{PipelineCompiler, PipelineDescriptor},
|
||||
render_resource::ResourceProvider,
|
||||
renderer::Renderer,
|
||||
shader::Shader,
|
||||
texture::TextureDescriptor,
|
||||
};
|
||||
use bevy_asset::{AssetStorage, Handle};
|
||||
use legion::prelude::*;
|
||||
|
|
|
@ -1,13 +1,11 @@
|
|||
use super::RenderGraph;
|
||||
use crate::{
|
||||
{
|
||||
draw_target::DrawTarget,
|
||||
pass::PassDescriptor,
|
||||
pipeline::{PipelineBuilder, PipelineDescriptor},
|
||||
render_resource::ResourceProvider,
|
||||
texture::TextureDescriptor,
|
||||
shader::Shader,
|
||||
},
|
||||
draw_target::DrawTarget,
|
||||
pass::PassDescriptor,
|
||||
pipeline::{PipelineBuilder, PipelineDescriptor},
|
||||
render_resource::ResourceProvider,
|
||||
shader::Shader,
|
||||
texture::TextureDescriptor,
|
||||
};
|
||||
|
||||
use bevy_asset::AssetStorage;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use bevy_asset::{Handle, HandleUntyped};
|
||||
use crate::render_resource::RenderResourceAssignments;
|
||||
use bevy_asset::{Handle, HandleUntyped};
|
||||
use legion::prelude::Entity;
|
||||
use std::collections::{HashMap, HashSet};
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use bevy_asset::Handle;
|
||||
use crate::{mesh::Mesh, texture::Texture};
|
||||
use bevy_asset::Handle;
|
||||
use std::collections::HashMap;
|
||||
|
||||
#[derive(Copy, Clone, Hash, Debug, Eq, PartialEq)]
|
||||
|
|
|
@ -9,9 +9,9 @@ use crate::{
|
|||
ActiveCamera, Camera,
|
||||
};
|
||||
|
||||
use bevy_app::{Events, EventReader};
|
||||
use legion::prelude::*;
|
||||
use bevy_app::{EventReader, Events};
|
||||
use bevy_transform::prelude::*;
|
||||
use legion::prelude::*;
|
||||
use zerocopy::AsBytes;
|
||||
|
||||
pub struct CameraResourceProvider {
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
use bevy_window::Windows;
|
||||
use crate::{
|
||||
render_resource::{RenderResourceAssignments, ResourceProvider},
|
||||
renderer::Renderer,
|
||||
texture::TextureDescriptor,
|
||||
};
|
||||
use bevy_window::Windows;
|
||||
use legion::prelude::*;
|
||||
|
||||
pub struct FrameTextureResourceProvider {
|
||||
|
|
|
@ -6,8 +6,7 @@ use crate::{
|
|||
},
|
||||
renderer::Renderer,
|
||||
shader::AsUniforms,
|
||||
Renderable,
|
||||
Vertex,
|
||||
Renderable, Vertex,
|
||||
};
|
||||
use bevy_asset::{AssetStorage, Handle};
|
||||
use legion::{filter::*, prelude::*};
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
use bevy_asset::{AssetStorage, Handle};
|
||||
use legion::prelude::*;
|
||||
use crate::{
|
||||
pipeline::PipelineDescriptor,
|
||||
render_resource::{
|
||||
|
@ -8,6 +6,8 @@ use crate::{
|
|||
shader::Shader,
|
||||
texture::{SamplerDescriptor, TextureDescriptor},
|
||||
};
|
||||
use bevy_asset::{AssetStorage, Handle};
|
||||
use legion::prelude::*;
|
||||
use std::ops::Range;
|
||||
|
||||
pub trait Renderer {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use crate::shader::ShaderDefSuffixProvider;
|
||||
use bevy_asset::{Asset, Handle};
|
||||
use std::fs::File;
|
||||
use crate::shader::ShaderDefSuffixProvider;
|
||||
|
||||
pub enum TextureType {
|
||||
Data(Vec<u8>, usize, usize),
|
||||
|
@ -64,4 +64,4 @@ impl ShaderDefSuffixProvider for Option<Handle<Texture>> {
|
|||
None => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
use std::convert::From;
|
||||
use zerocopy::{AsBytes, FromBytes};
|
||||
|
||||
use bevy_derive::Uniforms;
|
||||
use bevy_core;
|
||||
use bevy_asset;
|
||||
use bevy_core;
|
||||
use bevy_derive::Uniforms;
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, AsBytes, FromBytes, Uniforms)]
|
||||
|
|
|
@ -33,10 +33,6 @@ impl From<&mut Vec3> for NonUniformScale {
|
|||
impl fmt::Display for NonUniformScale {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
let (x, y, z) = self.0.into();
|
||||
write!(
|
||||
f,
|
||||
"NonUniformScale({}, {}, {})",
|
||||
x, y, z
|
||||
)
|
||||
write!(f, "NonUniformScale({}, {}, {})", x, y, z)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,4 +27,4 @@ impl From<Vec3> for Translation {
|
|||
fn from(translation: Vec3) -> Self {
|
||||
Self(Vec3::from(translation))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,9 +6,7 @@ use std::collections::HashMap;
|
|||
pub fn build(_: &mut World) -> Vec<Box<dyn Schedulable>> {
|
||||
let missing_previous_parent_system = SystemBuilder::<()>::new("MissingPreviousParentSystem")
|
||||
// Entities with missing `PreviousParent`
|
||||
.with_query(<Read<Parent>>::query().filter(
|
||||
!component::<PreviousParent>(),
|
||||
))
|
||||
.with_query(<Read<Parent>>::query().filter(!component::<PreviousParent>()))
|
||||
.build(move |commands, world, _resource, query| {
|
||||
// Add missing `PreviousParent` components
|
||||
for (entity, _parent) in query.iter_entities(world) {
|
||||
|
@ -21,9 +19,7 @@ pub fn build(_: &mut World) -> Vec<Box<dyn Schedulable>> {
|
|||
// Entities with a removed `Parent`
|
||||
.with_query(<Read<PreviousParent>>::query().filter(!component::<Parent>()))
|
||||
// Entities with a changed `Parent`
|
||||
.with_query(<(Read<Parent>, Write<PreviousParent>)>::query().filter(
|
||||
changed::<Parent>(),
|
||||
))
|
||||
.with_query(<(Read<Parent>, Write<PreviousParent>)>::query().filter(changed::<Parent>()))
|
||||
// Deleted Parents (ie Entities with `Children` and without a `LocalToWorld`).
|
||||
.write_component::<Children>()
|
||||
.build(move |commands, world, _resource, queries| {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
pub use legion as ecs;
|
||||
pub use glam as math;
|
||||
pub use legion as ecs;
|
||||
|
||||
pub mod components;
|
||||
pub mod hierarchy_maintenance_system;
|
||||
|
@ -9,10 +9,8 @@ pub mod local_to_world_system;
|
|||
pub mod transform_system_bundle;
|
||||
|
||||
pub mod prelude {
|
||||
pub use crate::components::*;
|
||||
pub use crate::hierarchy_maintenance_system;
|
||||
pub use crate::local_to_parent_system;
|
||||
pub use crate::local_to_world_propagate_system;
|
||||
pub use crate::local_to_world_system;
|
||||
pub use crate::transform_system_bundle;
|
||||
pub use crate::{
|
||||
components::*, hierarchy_maintenance_system, local_to_parent_system,
|
||||
local_to_world_propagate_system, local_to_world_system, transform_system_bundle,
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
#![allow(dead_code)]
|
||||
use crate::{components::*, ecs::prelude::*, math::{Mat4, Vec3, Quat}};
|
||||
use crate::{
|
||||
components::*,
|
||||
ecs::prelude::*,
|
||||
math::{Mat4, Quat, Vec3},
|
||||
};
|
||||
|
||||
pub fn build(_: &mut World) -> Box<dyn Schedulable> {
|
||||
SystemBuilder::<()>::new("LocalToParentUpdateSystem")
|
||||
|
@ -126,7 +130,8 @@ pub fn build(_: &mut World) -> Box<dyn Schedulable> {
|
|||
s.spawn(|_| unsafe {
|
||||
// Scale
|
||||
c.for_each_unchecked(world, |(mut ltw, scale)| {
|
||||
*ltw = LocalToParent(Mat4::from_scale(Vec3::new(scale.0, scale.0, scale.0)));
|
||||
*ltw =
|
||||
LocalToParent(Mat4::from_scale(Vec3::new(scale.0, scale.0, scale.0)));
|
||||
});
|
||||
});
|
||||
s.spawn(|_| unsafe {
|
||||
|
@ -137,9 +142,10 @@ pub fn build(_: &mut World) -> Box<dyn Schedulable> {
|
|||
|
||||
// Translation + Rotation
|
||||
e.for_each_unchecked(world, |(mut ltw, translation, rotation)| {
|
||||
*ltw = LocalToParent(
|
||||
Mat4::from_rotation_translation(rotation.0, translation.0)
|
||||
);
|
||||
*ltw = LocalToParent(Mat4::from_rotation_translation(
|
||||
rotation.0,
|
||||
translation.0,
|
||||
));
|
||||
});
|
||||
});
|
||||
s.spawn(|_| unsafe {
|
||||
|
@ -196,11 +202,11 @@ pub fn build(_: &mut World) -> Box<dyn Schedulable> {
|
|||
k.for_each_unchecked(
|
||||
world,
|
||||
|(mut ltw, translation, rotation, non_uniform_scale)| {
|
||||
*ltw = LocalToParent(Mat4::from_scale_rotation_translation(
|
||||
non_uniform_scale.0,
|
||||
rotation.0,
|
||||
translation.0,
|
||||
));
|
||||
*ltw = LocalToParent(Mat4::from_scale_rotation_translation(
|
||||
non_uniform_scale.0,
|
||||
rotation.0,
|
||||
translation.0,
|
||||
));
|
||||
},
|
||||
);
|
||||
});
|
||||
|
@ -282,63 +288,42 @@ mod test {
|
|||
.get_component::<LocalToParent>(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!(
|
||||
world
|
||||
.get_component::<LocalToParent>(translation_and_nus)
|
||||
.unwrap()
|
||||
.0,
|
||||
Mat4::from_scale_rotation_translation(
|
||||
nus.0,
|
||||
Quat::default(),
|
||||
t.0
|
||||
)
|
||||
Mat4::from_scale_rotation_translation(nus.0, Quat::default(), t.0)
|
||||
);
|
||||
assert_eq!(
|
||||
world
|
||||
.get_component::<LocalToParent>(rotation_scale)
|
||||
.unwrap()
|
||||
.0,
|
||||
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!(
|
||||
world.get_component::<LocalToParent>(rotation_nus).unwrap().0,
|
||||
Mat4::from_scale_rotation_translation(
|
||||
nus.0,
|
||||
r.0,
|
||||
Vec3::default()
|
||||
)
|
||||
world
|
||||
.get_component::<LocalToParent>(rotation_nus)
|
||||
.unwrap()
|
||||
.0,
|
||||
Mat4::from_scale_rotation_translation(nus.0, r.0, Vec3::default())
|
||||
);
|
||||
assert_eq!(
|
||||
world
|
||||
.get_component::<LocalToParent>(translation_rotation_scale)
|
||||
.unwrap()
|
||||
.0,
|
||||
Mat4::from_scale_rotation_translation(
|
||||
Vec3::new(s.0, s.0, s.0),
|
||||
r.0,
|
||||
t.0
|
||||
)
|
||||
Mat4::from_scale_rotation_translation(Vec3::new(s.0, s.0, s.0), r.0, t.0)
|
||||
);
|
||||
assert_eq!(
|
||||
world
|
||||
.get_component::<LocalToParent>(translation_rotation_nus)
|
||||
.unwrap()
|
||||
.0,
|
||||
Mat4::from_scale_rotation_translation(
|
||||
nus.0,
|
||||
r.0,
|
||||
t.0
|
||||
)
|
||||
Mat4::from_scale_rotation_translation(nus.0, r.0, t.0)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
#![allow(dead_code)]
|
||||
use crate::{components::*, ecs::{prelude::*, systems::SubWorld}};
|
||||
use crate::{
|
||||
components::*,
|
||||
ecs::{prelude::*, systems::SubWorld},
|
||||
};
|
||||
|
||||
pub fn build(_: &mut World) -> Box<dyn Schedulable> {
|
||||
SystemBuilder::<()>::new("LocalToWorldPropagateSystem")
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
#![allow(dead_code)]
|
||||
use crate::{components::*, ecs::prelude::*, math::{Mat4, Vec3, Quat}};
|
||||
use crate::{
|
||||
components::*,
|
||||
ecs::prelude::*,
|
||||
math::{Mat4, Quat, Vec3},
|
||||
};
|
||||
|
||||
pub fn build(_: &mut World) -> Box<dyn Schedulable> {
|
||||
SystemBuilder::<()>::new("LocalToWorldUpdateSystem")
|
||||
|
@ -152,9 +156,10 @@ pub fn build(_: &mut World) -> Box<dyn Schedulable> {
|
|||
s.spawn(|_| unsafe {
|
||||
// Translation + Rotation
|
||||
e.for_each_unchecked(world, |(mut ltw, translation, rotation)| {
|
||||
*ltw = LocalToWorld(
|
||||
Mat4::from_rotation_translation(rotation.0, translation.0)
|
||||
);
|
||||
*ltw = LocalToWorld(Mat4::from_rotation_translation(
|
||||
rotation.0,
|
||||
translation.0,
|
||||
));
|
||||
});
|
||||
});
|
||||
s.spawn(|_| unsafe {
|
||||
|
@ -304,63 +309,39 @@ mod test {
|
|||
.get_component::<LocalToWorld>(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!(
|
||||
world
|
||||
.get_component::<LocalToWorld>(translation_and_nus)
|
||||
.unwrap()
|
||||
.0,
|
||||
Mat4::from_scale_rotation_translation(
|
||||
nus.0,
|
||||
Quat::default(),
|
||||
t.0
|
||||
)
|
||||
Mat4::from_scale_rotation_translation(nus.0, Quat::default(), t.0)
|
||||
);
|
||||
assert_eq!(
|
||||
world
|
||||
.get_component::<LocalToWorld>(rotation_scale)
|
||||
.unwrap()
|
||||
.0,
|
||||
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!(
|
||||
world.get_component::<LocalToWorld>(rotation_nus).unwrap().0,
|
||||
Mat4::from_scale_rotation_translation(
|
||||
nus.0,
|
||||
r.0,
|
||||
Vec3::default()
|
||||
)
|
||||
Mat4::from_scale_rotation_translation(nus.0, r.0, Vec3::default())
|
||||
);
|
||||
assert_eq!(
|
||||
world
|
||||
.get_component::<LocalToWorld>(translation_rotation_scale)
|
||||
.unwrap()
|
||||
.0,
|
||||
Mat4::from_scale_rotation_translation(
|
||||
Vec3::new(s.0, s.0, s.0),
|
||||
r.0,
|
||||
t.0
|
||||
)
|
||||
Mat4::from_scale_rotation_translation(Vec3::new(s.0, s.0, s.0), r.0, t.0)
|
||||
);
|
||||
assert_eq!(
|
||||
world
|
||||
.get_component::<LocalToWorld>(translation_rotation_nus)
|
||||
.unwrap()
|
||||
.0,
|
||||
Mat4::from_scale_rotation_translation(
|
||||
nus.0,
|
||||
r.0,
|
||||
t.0
|
||||
)
|
||||
Mat4::from_scale_rotation_translation(nus.0, r.0, t.0)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use bevy_derive::EntityArchetype;
|
||||
use super::Node;
|
||||
use bevy_derive::EntityArchetype;
|
||||
|
||||
#[derive(EntityArchetype)]
|
||||
#[module(meta = false)]
|
||||
|
|
|
@ -7,7 +7,7 @@ pub use wgpu_render_pass::*;
|
|||
pub use wgpu_renderer::*;
|
||||
pub use wgpu_resources::*;
|
||||
|
||||
use bevy_app::{AppPlugin, AppBuilder, Events};
|
||||
use bevy_app::{AppBuilder, AppPlugin, Events};
|
||||
use bevy_render::{renderer::Renderer, RENDER_STAGE};
|
||||
use bevy_window::{WindowCreated, WindowResized};
|
||||
use legion::prelude::*;
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
use super::{wgpu_type_converter::{OwnedWgpuVertexBufferDescriptor, WgpuInto}, WgpuRenderPass, WgpuResources};
|
||||
use super::{
|
||||
wgpu_type_converter::{OwnedWgpuVertexBufferDescriptor, WgpuInto},
|
||||
WgpuRenderPass, WgpuResources,
|
||||
};
|
||||
use bevy_app::{EventReader, Events};
|
||||
use bevy_asset::{AssetStorage, Handle};
|
||||
use bevy_render::{
|
||||
|
@ -201,10 +204,18 @@ impl WgpuRenderer {
|
|||
attachment,
|
||||
clear_depth: depth_stencil_attachment_descriptor.clear_depth,
|
||||
clear_stencil: depth_stencil_attachment_descriptor.clear_stencil,
|
||||
depth_load_op: depth_stencil_attachment_descriptor.depth_load_op.wgpu_into(),
|
||||
depth_store_op: depth_stencil_attachment_descriptor.depth_store_op.wgpu_into(),
|
||||
stencil_load_op: depth_stencil_attachment_descriptor.stencil_load_op.wgpu_into(),
|
||||
stencil_store_op: depth_stencil_attachment_descriptor.stencil_store_op.wgpu_into(),
|
||||
depth_load_op: depth_stencil_attachment_descriptor
|
||||
.depth_load_op
|
||||
.wgpu_into(),
|
||||
depth_store_op: depth_stencil_attachment_descriptor
|
||||
.depth_store_op
|
||||
.wgpu_into(),
|
||||
stencil_load_op: depth_stencil_attachment_descriptor
|
||||
.stencil_load_op
|
||||
.wgpu_into(),
|
||||
stencil_store_op: depth_stencil_attachment_descriptor
|
||||
.stencil_store_op
|
||||
.wgpu_into(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -198,8 +198,10 @@ impl WgpuResources {
|
|||
let device_rc = renderer.device.clone();
|
||||
let device = device_rc.borrow();
|
||||
|
||||
let mut mapped =
|
||||
device.create_buffer_mapped(buffer_info.size as usize, buffer_info.buffer_usage.wgpu_into());
|
||||
let mut mapped = device.create_buffer_mapped(
|
||||
buffer_info.size as usize,
|
||||
buffer_info.buffer_usage.wgpu_into(),
|
||||
);
|
||||
setup_data(&mut mapped.data, renderer);
|
||||
mapped.finish()
|
||||
}
|
||||
|
|
|
@ -22,19 +22,19 @@ pub trait WgpuFrom<T> {
|
|||
fn from(val: T) -> Self;
|
||||
}
|
||||
|
||||
pub trait WgpuInto<U>
|
||||
{
|
||||
pub trait WgpuInto<U> {
|
||||
fn wgpu_into(self) -> U;
|
||||
}
|
||||
|
||||
impl<T, U> WgpuInto<U> for T where U: WgpuFrom<T>
|
||||
impl<T, U> WgpuInto<U> for T
|
||||
where
|
||||
U: WgpuFrom<T>,
|
||||
{
|
||||
fn wgpu_into(self) -> U {
|
||||
U::from(self)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
impl WgpuFrom<VertexFormat> for wgpu::VertexFormat {
|
||||
fn from(val: VertexFormat) -> Self {
|
||||
match val {
|
||||
|
|
|
@ -1,14 +1,12 @@
|
|||
mod events;
|
||||
mod window;
|
||||
mod windows;
|
||||
#[cfg(feature = "winit")]
|
||||
pub mod winit;
|
||||
|
||||
pub use events::*;
|
||||
pub use window::*;
|
||||
pub use windows::*;
|
||||
|
||||
use bevy_app::{AppPlugin, AppBuilder, Events};
|
||||
use bevy_app::{AppBuilder, AppPlugin, Events};
|
||||
|
||||
pub struct WindowPlugin {
|
||||
pub primary_window: Option<WindowDescriptor>,
|
||||
|
@ -24,17 +22,17 @@ impl Default for WindowPlugin {
|
|||
|
||||
impl AppPlugin for WindowPlugin {
|
||||
fn build(&self, app: &mut AppBuilder) {
|
||||
app
|
||||
.add_event::<WindowResized>()
|
||||
app.add_event::<WindowResized>()
|
||||
.add_event::<CreateWindow>()
|
||||
.add_event::<WindowCreated>()
|
||||
.add_resource(Windows::default());
|
||||
|
||||
if let Some(ref primary_window_descriptor) = self.primary_window {
|
||||
let mut create_window_event = app.resources().get_mut::<Events<CreateWindow>>().unwrap();
|
||||
let mut create_window_event =
|
||||
app.resources().get_mut::<Events<CreateWindow>>().unwrap();
|
||||
create_window_event.send(CreateWindow {
|
||||
descriptor: primary_window_descriptor.clone(),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,4 +46,4 @@ impl Default for WindowDescriptor {
|
|||
vsync: true,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,9 @@ pub fn convert_keyboard_input(keyboard_input: &winit::event::KeyboardInput) -> K
|
|||
KeyboardInput {
|
||||
scan_code: keyboard_input.scancode,
|
||||
state: convert_element_state(keyboard_input.state),
|
||||
virtual_key_code: keyboard_input.virtual_keycode.map(|v| convert_virtual_key_code(v)),
|
||||
virtual_key_code: keyboard_input
|
||||
.virtual_keycode
|
||||
.map(|v| convert_virtual_key_code(v)),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
use bevy::{input::mouse::{MouseButtonInput, MouseMotion}, prelude::*};
|
||||
use bevy::{
|
||||
input::mouse::{MouseButtonInput, MouseMotion},
|
||||
prelude::*,
|
||||
};
|
||||
|
||||
fn main() {
|
||||
App::build()
|
||||
|
@ -14,7 +17,10 @@ pub fn mouse_input_system(resources: &mut Resources) -> Box<dyn Schedulable> {
|
|||
.read_resource::<Events<MouseButtonInput>>()
|
||||
.read_resource::<Events<MouseMotion>>()
|
||||
.build(
|
||||
move |_command_buffer, _world, (mouse_button_input_events, mouse_motion_events), _queries| {
|
||||
move |_command_buffer,
|
||||
_world,
|
||||
(mouse_button_input_events, mouse_motion_events),
|
||||
_queries| {
|
||||
for event in mouse_button_input_events.iter(&mut mouse_button_input_event_reader) {
|
||||
println!("{:?}", event);
|
||||
}
|
||||
|
@ -24,4 +30,4 @@ pub fn mouse_input_system(resources: &mut Resources) -> Box<dyn Schedulable> {
|
|||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ fn setup(world: &mut World, resources: &mut Resources) {
|
|||
albedo: Color::rgb(0.1, 0.2, 0.1),
|
||||
..Default::default()
|
||||
});
|
||||
|
||||
|
||||
world
|
||||
.build()
|
||||
// plane
|
||||
|
|
|
@ -23,8 +23,7 @@ pub trait AddDefaultPlugins {
|
|||
|
||||
impl AddDefaultPlugins for AppBuilder {
|
||||
fn add_default_plugins(&mut self) -> &mut Self {
|
||||
self
|
||||
.add_plugin(bevy_core::CorePlugin::default())
|
||||
self.add_plugin(bevy_core::CorePlugin::default())
|
||||
.add_plugin(bevy_input::InputPlugin::default())
|
||||
.add_plugin(bevy_window::WindowPlugin::default())
|
||||
.add_plugin(bevy_render::RenderPlugin::default())
|
||||
|
@ -41,12 +40,9 @@ impl AddDefaultPlugins for AppBuilder {
|
|||
|
||||
#[cfg(feature = "bevy_wgpu")]
|
||||
{
|
||||
self.add_plugin(
|
||||
bevy_wgpu::WgpuRendererPlugin::default(),
|
||||
);
|
||||
self.add_plugin(bevy_wgpu::WgpuRendererPlugin::default());
|
||||
}
|
||||
|
||||
self
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue