rustfmt changes

This commit is contained in:
Carter Anderson 2020-07-28 14:24:03 -07:00
parent 6dadf34401
commit 7212b70478
58 changed files with 216 additions and 67 deletions

View file

@ -61,6 +61,7 @@ where
.send(asset_result)
.expect("loaded asset should have been sent");
}
fn extensions(&self) -> &[&str] {
self.loader.extensions()
}

View file

@ -22,6 +22,7 @@ impl AssetLoader<AudioSource> for Mp3Loader {
bytes: Arc::new(bytes),
})
}
fn extensions(&self) -> &[&str] {
static EXTENSIONS: &[&str] = &["mp3"];
EXTENSIONS

View file

@ -102,6 +102,7 @@ impl Bytes for Mat4 {
let array = self.to_cols_array();
array.write_bytes(buffer);
}
fn byte_len(&self) -> usize {
std::mem::size_of::<Self>()
}
@ -123,6 +124,7 @@ where
val.write_bytes(buffer)
}
}
fn byte_len(&self) -> usize {
self.as_ref().map_or(0, |val| val.byte_len())
}
@ -149,6 +151,7 @@ where
let bytes = self.as_slice().as_bytes();
buffer[0..self.byte_len()].copy_from_slice(bytes)
}
fn byte_len(&self) -> usize {
self.as_slice().as_bytes().len()
}

View file

@ -43,6 +43,7 @@ impl Hash for FloatOrd {
impl Neg for FloatOrd {
type Output = FloatOrd;
fn neg(self) -> Self::Output {
FloatOrd(-self.0)
}

View file

@ -17,6 +17,7 @@ impl Timer {
..Default::default()
}
}
pub fn new(duration: Duration) -> Self {
Timer {
duration: duration.as_secs_f32(),

View file

@ -97,6 +97,7 @@ impl<'a, T: Component> Drop for Ref<'a, T> {
impl<'a, T: Component> Deref for Ref<'a, T> {
type Target = T;
fn deref(&self) -> &T {
unsafe { self.target.as_ref() }
}
@ -153,6 +154,7 @@ impl<'a, T: Component> Drop for RefMut<'a, T> {
impl<'a, T: Component> Deref for RefMut<'a, T> {
type Target = T;
fn deref(&self) -> &T {
unsafe { self.target.as_ref() }
}

View file

@ -81,18 +81,22 @@ impl Query for Entity {
impl<'a> Fetch<'a> for EntityFetch {
type Item = Entity;
#[inline]
fn access(_archetype: &Archetype) -> Option<Access> {
Some(Access::Iterate)
}
#[inline]
fn borrow(_archetype: &Archetype) {}
#[inline]
unsafe fn get(archetype: &'a Archetype, offset: usize) -> Option<Self> {
Some(EntityFetch(NonNull::new_unchecked(
archetype.entities().as_ptr().add(offset),
)))
}
#[inline]
fn release(_archetype: &Archetype) {}
@ -125,11 +129,13 @@ impl<'a, T: Component> Fetch<'a> for FetchRead<T> {
fn borrow(archetype: &Archetype) {
archetype.borrow::<T>();
}
unsafe fn get(archetype: &'a Archetype, offset: usize) -> Option<Self> {
archetype
.get::<T>()
.map(|x| Self(NonNull::new_unchecked(x.as_ptr().add(offset))))
}
fn release(archetype: &Archetype) {
archetype.release::<T>();
}
@ -161,6 +167,7 @@ unsafe impl<T: Component> Sync for Mut<'_, T> {}
impl<'a, T: Component> Deref for Mut<'a, T> {
type Target = T;
#[inline]
fn deref(&self) -> &T {
self.value
@ -195,6 +202,7 @@ impl<'a, T: Component> Fetch<'a> for FetchMut<T> {
fn borrow(archetype: &Archetype) {
archetype.borrow_mut::<T>();
}
unsafe fn get(archetype: &'a Archetype, offset: usize) -> Option<Self> {
archetype
.get_with_mutated::<T>()
@ -205,6 +213,7 @@ impl<'a, T: Component> Fetch<'a> for FetchMut<T> {
)
})
}
fn release(archetype: &Archetype) {
archetype.release_mut::<T>();
}
@ -229,6 +238,7 @@ pub struct Mutated<'a, T> {
impl<'a, T: Component> Deref for Mutated<'a, T> {
type Target = T;
#[inline]
fn deref(&self) -> &T {
self.value
@ -256,6 +266,7 @@ impl<'a, T: Component> Fetch<'a> for FetchMutated<T> {
fn borrow(archetype: &Archetype) {
archetype.borrow::<T>();
}
unsafe fn get(archetype: &'a Archetype, offset: usize) -> Option<Self> {
archetype
.get_with_mutated::<T>()
@ -266,6 +277,7 @@ impl<'a, T: Component> Fetch<'a> for FetchMutated<T> {
)
})
}
fn release(archetype: &Archetype) {
archetype.release::<T>();
}
@ -291,6 +303,7 @@ pub struct Added<'a, T> {
impl<'a, T: Component> Deref for Added<'a, T> {
type Target = T;
#[inline]
fn deref(&self) -> &T {
self.value
@ -318,6 +331,7 @@ impl<'a, T: Component> Fetch<'a> for FetchAdded<T> {
fn borrow(archetype: &Archetype) {
archetype.borrow::<T>();
}
unsafe fn get(archetype: &'a Archetype, offset: usize) -> Option<Self> {
archetype.get_with_added::<T>().map(|(components, added)| {
Self(
@ -326,6 +340,7 @@ impl<'a, T: Component> Fetch<'a> for FetchAdded<T> {
)
})
}
fn release(archetype: &Archetype) {
archetype.release::<T>();
}
@ -351,6 +366,7 @@ pub struct Changed<'a, T> {
impl<'a, T: Component> Deref for Changed<'a, T> {
type Target = T;
#[inline]
fn deref(&self) -> &T {
self.value
@ -390,6 +406,7 @@ impl<'a, T: Component> Fetch<'a> for FetchChanged<T> {
)
})
}
fn release(archetype: &Archetype) {
archetype.release::<T>();
}
@ -422,9 +439,11 @@ impl<'a, T: Fetch<'a>> Fetch<'a> for TryFetch<T> {
fn borrow(archetype: &Archetype) {
T::borrow(archetype)
}
unsafe fn get(archetype: &'a Archetype, offset: usize) -> Option<Self> {
Some(Self(T::get(archetype, offset)))
}
fn release(archetype: &Archetype) {
T::release(archetype)
}
@ -478,12 +497,14 @@ impl<'a, T: Component, F: Fetch<'a>> Fetch<'a> for FetchWithout<T, F> {
fn borrow(archetype: &Archetype) {
F::borrow(archetype)
}
unsafe fn get(archetype: &'a Archetype, offset: usize) -> Option<Self> {
if archetype.has::<T>() {
return None;
}
Some(Self(F::get(archetype, offset)?, PhantomData))
}
fn release(archetype: &Archetype) {
F::release(archetype)
}
@ -539,12 +560,14 @@ impl<'a, T: Component, F: Fetch<'a>> Fetch<'a> for FetchWith<T, F> {
fn borrow(archetype: &Archetype) {
F::borrow(archetype)
}
unsafe fn get(archetype: &'a Archetype, offset: usize) -> Option<Self> {
if !archetype.has::<T>() {
return None;
}
Some(Self(F::get(archetype, offset)?, PhantomData))
}
fn release(archetype: &Archetype) {
F::release(archetype)
}
@ -693,8 +716,8 @@ impl<'w, Q: Query> Drop for QueryBorrow<'w, Q> {
}
impl<'q, 'w, Q: Query> IntoIterator for &'q mut QueryBorrow<'w, Q> {
type Item = <Q::Fetch as Fetch<'q>>::Item;
type IntoIter = QueryIter<'q, 'w, Q>;
type Item = <Q::Fetch as Fetch<'q>>::Item;
fn into_iter(self) -> Self::IntoIter {
self.iter()

View file

@ -622,6 +622,7 @@ impl Default for World {
impl<'a> IntoIterator for &'a World {
type IntoIter = Iter<'a>;
type Item = (Entity, EntityRef<'a>);
fn into_iter(self) -> Iter<'a> {
self.iter()
}
@ -700,6 +701,7 @@ unsafe impl Sync for Iter<'_> {}
impl<'a> Iterator for Iter<'a> {
type Item = (Entity, EntityRef<'a>);
fn next(&mut self) -> Option<Self::Item> {
loop {
match self.current {

View file

@ -39,6 +39,7 @@ unsafe impl<T: Component> Sync for Res<'_, T> {}
impl<'a, T: Component> Deref for Res<'a, T> {
type Target = T;
fn deref(&self) -> &T {
self.value
}
@ -64,6 +65,7 @@ unsafe impl<T: Component> Sync for ResMut<'_, T> {}
impl<'a, T: Component> Deref for ResMut<'a, T> {
type Target = T;
fn deref(&self) -> &T {
unsafe { &*self.value }
}
@ -100,6 +102,7 @@ impl<'a, T: Component + FromResources> UnsafeClone for Local<'a, T> {
impl<'a, T: Component + FromResources> Deref for Local<'a, T> {
type Target = T;
fn deref(&self) -> &T {
unsafe { &*self.value }
}
@ -142,6 +145,7 @@ pub struct FetchResourceRead<T>(NonNull<T>);
impl<'a, T: Component> FetchResource<'a> for FetchResourceRead<T> {
type Item = Res<'a, T>;
unsafe fn get(resources: &'a Resources, _system_id: Option<SystemId>) -> Self::Item {
Res::new(resources.get_unsafe_ref::<T>(ResourceIndex::Global))
}
@ -169,6 +173,7 @@ pub struct FetchResourceWrite<T>(NonNull<T>);
impl<'a, T: Component> FetchResource<'a> for FetchResourceWrite<T> {
type Item = ResMut<'a, T>;
unsafe fn get(resources: &'a Resources, _system_id: Option<SystemId>) -> Self::Item {
ResMut::new(resources.get_unsafe_ref::<T>(ResourceIndex::Global))
}
@ -202,6 +207,7 @@ pub struct FetchResourceLocalMut<T>(NonNull<T>);
impl<'a, T: Component + FromResources> FetchResource<'a> for FetchResourceLocalMut<T> {
type Item = Local<'a, T>;
unsafe fn get(resources: &'a Resources, system_id: Option<SystemId>) -> Self::Item {
let id = system_id.expect("Local<T> resources can only be used by systems");
Local {

View file

@ -32,6 +32,7 @@ impl ParallelExecutor {
..Default::default()
}
}
pub fn prepare(&mut self, schedule: &mut Schedule, world: &World) {
let schedule_generation = schedule.generation();
let schedule_changed = schedule_generation != self.last_schedule_generation;

View file

@ -70,6 +70,7 @@ where
fn initialize(&mut self, resources: &mut Resources) {
(self.init_func)(resources);
}
fn id(&self) -> SystemId {
self.id
}

View file

@ -17,6 +17,7 @@ impl AssetLoader<Mesh> for GltfLoader {
let mesh = load_gltf(asset_path, bytes)?;
Ok(mesh)
}
fn extensions(&self) -> &[&str] {
static EXTENSIONS: &[&str] = &["gltf"];
EXTENSIONS

View file

@ -1,8 +1,8 @@
use std::ops::{Add, AddAssign};
use glam::Vec2;
use std::ops::{Add, AddAssign};
#[derive(Copy, Clone, PartialEq, Debug)]
pub struct Size<T=f32> {
pub struct Size<T = f32> {
pub width: T,
pub height: T,
}
@ -31,7 +31,10 @@ pub struct Rect<T> {
}
impl<T> Rect<T> {
pub fn all(value: T) -> Self where T: Clone{
pub fn all(value: T) -> Self
where
T: Clone,
{
Rect {
left: value.clone(),
right: value.clone(),
@ -52,8 +55,12 @@ impl<T: Default> Default for Rect<T> {
}
}
impl<T> Add<Vec2> for Size<T> where T: Add<f32, Output=T> {
impl<T> Add<Vec2> for Size<T>
where
T: Add<f32, Output = T>,
{
type Output = Size<T>;
fn add(self, rhs: Vec2) -> Self::Output {
Self {
width: self.width + rhs.x(),
@ -62,9 +69,12 @@ impl<T> Add<Vec2> for Size<T> where T: Add<f32, Output=T> {
}
}
impl<T> AddAssign<Vec2> for Size<T> where T: AddAssign<f32> {
impl<T> AddAssign<Vec2> for Size<T>
where
T: AddAssign<f32>,
{
fn add_assign(&mut self, rhs: Vec2) {
self.width += rhs.x();
self.height += rhs.y();
}
}
}

View file

@ -43,6 +43,7 @@ impl DynamicProperties {
self.prop_indices.insert(cow_name, self.props.len() - 1);
}
}
pub fn set<T: Property>(&mut self, name: &str, prop: T) {
// TODO: validate map / seq operations
if let Some(index) = self.prop_indices.get(name) {
@ -51,6 +52,7 @@ impl DynamicProperties {
self.push(Box::new(prop), Some(name));
}
}
pub fn set_box(&mut self, name: &str, prop: Box<dyn Property>) {
// TODO: validate map / seq operations
if let Some(index) = self.prop_indices.get(name) {
@ -122,14 +124,17 @@ impl Property for DynamicProperties {
fn any(&self) -> &dyn Any {
self
}
#[inline]
fn any_mut(&mut self) -> &mut dyn Any {
self
}
#[inline]
fn clone_prop(&self) -> Box<dyn Property> {
Box::new(self.to_dynamic())
}
#[inline]
fn set(&mut self, value: &dyn Property) {
if let Some(properties) = value.as_properties() {

View file

@ -18,21 +18,27 @@ where
fn prop(&self, _name: &str) -> Option<&dyn Property> {
None
}
fn prop_mut(&mut self, _name: &str) -> Option<&mut dyn Property> {
None
}
fn prop_with_index(&self, index: usize) -> Option<&dyn Property> {
Some(&self[index])
}
fn prop_with_index_mut(&mut self, index: usize) -> Option<&mut dyn Property> {
Some(&mut self[index])
}
fn prop_name(&self, _index: usize) -> Option<&str> {
None
}
fn prop_len(&self) -> usize {
self.len()
}
fn iter_props(&self) -> PropertyIter {
PropertyIter::new(self)
}
@ -45,9 +51,11 @@ where
fn type_name(&self) -> &str {
std::any::type_name::<Self>()
}
fn any(&self) -> &dyn Any {
self
}
fn any_mut(&mut self) -> &mut dyn Any {
self
}
@ -55,6 +63,7 @@ where
fn clone_prop(&self) -> Box<dyn Property> {
Box::new(self.clone())
}
fn set(&mut self, value: &dyn Property) {
if let Some(properties) = value.as_properties() {
if properties.property_type() != self.property_type() {
@ -71,6 +80,7 @@ where
panic!("attempted to apply non-Properties type to Properties type");
}
}
fn apply(&mut self, value: &dyn Property) {
self.set(value);
}

View file

@ -55,6 +55,7 @@ impl<'a> PropertyIter<'a> {
impl<'a> Iterator for PropertyIter<'a> {
type Item = &'a dyn Property;
fn next(&mut self) -> Option<Self::Item> {
if self.index < self.props.prop_len() {
let prop = self.props.prop_with_index(self.index).unwrap();
@ -79,6 +80,7 @@ where
fn prop_val<T: 'static>(&self, name: &str) -> Option<&T> {
self.prop(name).and_then(|p| p.any().downcast_ref::<T>())
}
#[inline]
fn set_prop_val<T: 'static>(&mut self, name: &str, value: T) {
if let Some(prop) = self.prop_mut(name) {

View file

@ -223,6 +223,7 @@ impl<'a> DynamicPropertiesDeserializer<'a> {
impl<'a, 'de> DeserializeSeed<'de> for DynamicPropertiesDeserializer<'a> {
type Value = DynamicProperties;
fn deserialize<D>(self, deserializer: D) -> Result<Self::Value, D::Error>
where
D: serde::Deserializer<'de>,
@ -239,6 +240,7 @@ struct DynamicPropertiesVisiter<'a> {
impl<'a, 'de> Visitor<'de> for DynamicPropertiesVisiter<'a> {
type Value = DynamicProperties;
fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
formatter.write_str("dynamic property")
}
@ -261,6 +263,7 @@ pub struct PropertyDeserializer<'a> {
impl<'a, 'de> DeserializeSeed<'de> for PropertyDeserializer<'a> {
type Value = Box<dyn Property>;
fn deserialize<D>(self, deserializer: D) -> Result<Self::Value, D::Error>
where
D: serde::Deserializer<'de>,
@ -283,6 +286,7 @@ pub struct SeqPropertyDeserializer<'a> {
impl<'a, 'de> DeserializeSeed<'de> for SeqPropertyDeserializer<'a> {
type Value = DynamicProperties;
fn deserialize<D>(self, deserializer: D) -> Result<Self::Value, D::Error>
where
D: serde::Deserializer<'de>,
@ -299,6 +303,7 @@ pub struct SeqPropertyVisiter<'a> {
impl<'a, 'de> Visitor<'de> for SeqPropertyVisiter<'a> {
type Value = DynamicProperties;
fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
formatter.write_str("property value")
}
@ -330,6 +335,7 @@ impl<'a> MapPropertyDeserializer<'a> {
impl<'a, 'de> DeserializeSeed<'de> for MapPropertyDeserializer<'a> {
type Value = DynamicProperties;
fn deserialize<D>(self, deserializer: D) -> Result<Self::Value, D::Error>
where
D: serde::Deserializer<'de>,
@ -346,6 +352,7 @@ struct MapPropertyVisiter<'a> {
impl<'a, 'de> Visitor<'de> for MapPropertyVisiter<'a> {
type Value = DynamicProperties;
fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
formatter.write_str("map value")
}
@ -373,6 +380,7 @@ struct AnyPropVisiter<'a> {
impl<'a, 'de> Visitor<'de> for AnyPropVisiter<'a> {
type Value = Box<dyn Property>;
fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
formatter.write_str("property value")
}

View file

@ -19,6 +19,7 @@ impl CameraProjection for PerspectiveProjection {
fn get_projection_matrix(&self) -> Mat4 {
Mat4::perspective_rh(self.fov, self.aspect_ratio, self.near, self.far)
}
fn update(&mut self, width: usize, height: usize) {
self.aspect_ratio = width as f32 / height as f32;
}
@ -64,6 +65,7 @@ impl CameraProjection for OrthographicProjection {
self.far,
)
}
fn update(&mut self, width: usize, height: usize) {
match self.window_origin {
WindowOrigin::Center => {

View file

@ -22,12 +22,12 @@ pub struct Color {
unsafe impl Byteable for Color {}
impl Color {
pub const WHITE: Color = Color::rgb(1.0, 1.0, 1.0);
pub const BLACK: Color = Color::rgb(0.0, 0.0, 0.0);
pub const RED: Color = Color::rgb(1.0, 0.0, 0.0);
pub const GREEN: Color = Color::rgb(0.0, 1.0, 0.0);
pub const BLUE: Color = Color::rgb(0.0, 0.0, 1.0);
pub const GREEN: Color = Color::rgb(0.0, 1.0, 0.0);
pub const NONE: Color = Color::rgba(0.0, 0.0, 0.0, 0.0);
pub const RED: Color = Color::rgb(1.0, 0.0, 0.0);
pub const WHITE: Color = Color::rgb(1.0, 1.0, 1.0);
pub const fn rgb(r: f32, g: f32, b: f32) -> Color {
Color { r, g, b, a: 1.0 }
@ -57,6 +57,7 @@ impl AddAssign<Color> for Color {
impl Add<Color> for Color {
type Output = Color;
fn add(self, rhs: Color) -> Self::Output {
Color {
r: self.r + rhs.r,
@ -69,6 +70,7 @@ impl Add<Color> for Color {
impl Add<Vec4> for Color {
type Output = Color;
fn add(self, rhs: Vec4) -> Self::Output {
Color {
r: self.r + rhs.x(),
@ -97,6 +99,7 @@ impl Into<[f32; 4]> for Color {
}
impl Mul<f32> for Color {
type Output = Color;
fn mul(self, rhs: f32) -> Self::Output {
Color {
r: self.r * rhs,
@ -118,6 +121,7 @@ impl MulAssign<f32> for Color {
impl Mul<Vec4> for Color {
type Output = Color;
fn mul(self, rhs: Vec4) -> Self::Output {
Color {
r: self.r * rhs.x(),
@ -139,12 +143,13 @@ impl MulAssign<Vec4> for Color {
impl Mul<Vec3> for Color {
type Output = Color;
fn mul(self, rhs: Vec3) -> Self::Output {
Color {
r: self.r * rhs.x(),
g: self.g * rhs.y(),
b: self.b * rhs.z(),
a: self.a
a: self.a,
}
}
}
@ -164,6 +169,7 @@ impl Bytes for ColorSource {
ColorSource::Texture(_) => {} // Texture is not a uniform
}
}
fn byte_len(&self) -> usize {
match *self {
ColorSource::Color(ref color) => color.byte_len(),

View file

@ -150,6 +150,7 @@ pub struct FetchDrawContext;
// TODO: derive this impl
impl<'a> FetchResource<'a> for FetchDrawContext {
type Item = DrawContext<'a>;
fn borrow(resources: &Resources) {
resources.borrow_mut::<Assets<PipelineDescriptor>>();
resources.borrow_mut::<Assets<Shader>>();
@ -158,6 +159,7 @@ impl<'a> FetchResource<'a> for FetchDrawContext {
resources.borrow::<VertexBufferDescriptors>();
resources.borrow::<SharedBuffers>();
}
fn release(resources: &Resources) {
resources.release_mut::<Assets<PipelineDescriptor>>();
resources.release_mut::<Assets<Shader>>();
@ -166,6 +168,7 @@ impl<'a> FetchResource<'a> for FetchDrawContext {
resources.release::<VertexBufferDescriptors>();
resources.release::<SharedBuffers>();
}
unsafe fn get(resources: &'a Resources, _system_id: Option<SystemId>) -> Self::Item {
DrawContext {
pipelines: ResMut::new(

View file

@ -63,8 +63,8 @@ pub struct VertexAttribute {
}
impl VertexAttribute {
pub const POSITION: &'static str = "Vertex_Position";
pub const NORMAL: &'static str = "Vertex_Normal";
pub const POSITION: &'static str = "Vertex_Position";
pub const UV: &'static str = "Vertex_Uv";
pub fn position(positions: Vec<[f32; 3]>) -> Self {

View file

@ -335,6 +335,7 @@ mod tests {
fn output(&self) -> &[ResourceSlotInfo] {
&self.outputs
}
fn update(
&mut self,
_: &World,

View file

@ -86,6 +86,7 @@ impl ResourceSlots {
.ok_or_else(|| RenderGraphError::InvalidNodeSlot(label)),
}
}
pub fn iter(&self) -> impl Iterator<Item = &ResourceSlot> {
self.slots.iter()
}

View file

@ -186,6 +186,7 @@ where
buffer_array_status.buffer = Some(buffer);
}
}
fn update_staging_buffer(&mut self, render_resource_context: &dyn RenderResourceContext) {
let mut size = 0;
for dynamic_buffer_array_status in self.uniform_arrays.iter_mut() {

View file

@ -15,6 +15,7 @@ pub struct WindowSwapChainNode {
impl WindowSwapChainNode {
pub const OUT_TEXTURE: &'static str = "texture";
pub fn new(window_id: WindowId) -> Self {
WindowSwapChainNode {
window_id,

View file

@ -17,6 +17,7 @@ pub struct WindowTextureNode {
impl WindowTextureNode {
pub const OUT_TEXTURE: &'static str = "texture";
pub fn new(window_id: WindowId, descriptor: TextureDescriptor) -> Self {
WindowTextureNode {
window_id,

View file

@ -300,6 +300,7 @@ mod tests {
fn output(&self) -> &[ResourceSlotInfo] {
&self.outputs
}
fn update(
&mut self,
_: &World,

View file

@ -35,24 +35,31 @@ impl HeadlessRenderResourceContext {
impl RenderResourceContext for HeadlessRenderResourceContext {
fn create_swap_chain(&self, _window: &Window) {}
fn next_swap_chain_texture(&self, _window: &Window) -> TextureId {
TextureId::new()
}
fn drop_swap_chain_texture(&self, _render_resource: TextureId) {}
fn drop_all_swap_chain_textures(&self) {}
fn create_sampler(&self, _sampler_descriptor: &SamplerDescriptor) -> SamplerId {
SamplerId::new()
}
fn create_texture(&self, texture_descriptor: TextureDescriptor) -> TextureId {
let texture = TextureId::new();
self.add_texture_descriptor(texture, texture_descriptor);
texture
}
fn create_buffer(&self, buffer_info: BufferInfo) -> BufferId {
let buffer = BufferId::new();
self.add_buffer_info(buffer, buffer_info);
buffer
}
fn write_mapped_buffer(
&self,
id: BufferId,
@ -63,21 +70,29 @@ impl RenderResourceContext for HeadlessRenderResourceContext {
let mut buffer = vec![0; size];
write(&mut buffer, self);
}
fn map_buffer(&self, _id: BufferId) {}
fn unmap_buffer(&self, _id: BufferId) {}
fn create_buffer_with_data(&self, buffer_info: BufferInfo, _data: &[u8]) -> BufferId {
let buffer = BufferId::new();
self.add_buffer_info(buffer, buffer_info);
buffer
}
fn create_shader_module(&self, _shader_handle: Handle<Shader>, _shaders: &Assets<Shader>) {}
fn remove_buffer(&self, buffer: BufferId) {
self.buffer_info.write().unwrap().remove(&buffer);
}
fn remove_texture(&self, texture: TextureId) {
self.texture_descriptors.write().unwrap().remove(&texture);
}
fn remove_sampler(&self, _sampler: SamplerId) {}
fn set_asset_resource_untyped(
&self,
handle: HandleUntyped,
@ -89,6 +104,7 @@ impl RenderResourceContext for HeadlessRenderResourceContext {
.unwrap()
.insert((handle, index), render_resource);
}
fn get_asset_resource_untyped(
&self,
handle: HandleUntyped,
@ -100,6 +116,7 @@ impl RenderResourceContext for HeadlessRenderResourceContext {
.get(&(handle, index))
.cloned()
}
fn create_render_pipeline(
&self,
_pipeline_handle: Handle<PipelineDescriptor>,
@ -107,23 +124,29 @@ impl RenderResourceContext for HeadlessRenderResourceContext {
_shaders: &Assets<Shader>,
) {
}
fn create_bind_group(
&self,
_bind_group_descriptor_id: BindGroupDescriptorId,
_bind_group: &BindGroup,
) {
}
fn create_shader_module_from_source(&self, _shader_handle: Handle<Shader>, _shader: &Shader) {}
fn remove_asset_resource_untyped(&self, handle: HandleUntyped, index: usize) {
self.asset_resources
.write()
.unwrap()
.remove(&(handle, index));
}
fn clear_bind_groups(&self) {}
fn get_buffer_info(&self, buffer: BufferId) -> Option<BufferInfo> {
self.buffer_info.read().unwrap().get(&buffer).cloned()
}
fn bind_group_descriptor_exists(
&self,
_bind_group_descriptor_id: BindGroupDescriptorId,

View file

@ -104,6 +104,7 @@ impl<'a> RenderResourceIterator<'a> {
}
impl<'a> Iterator for RenderResourceIterator<'a> {
type Item = &'a dyn RenderResource;
fn next(&mut self) -> Option<Self::Item> {
if self.index == self.render_resources.render_resources_len() {
None
@ -125,12 +126,15 @@ macro_rules! impl_render_resource_bytes {
fn resource_type(&self) -> Option<RenderResourceType> {
Some(RenderResourceType::Buffer)
}
fn write_buffer_bytes(&self, buffer: &mut [u8]) {
self.write_bytes(buffer);
}
fn buffer_byte_len(&self) -> Option<usize> {
Some(self.byte_len())
}
fn texture(&self) -> Option<Handle<Texture>> {
None
}
@ -161,12 +165,15 @@ where
fn resource_type(&self) -> Option<RenderResourceType> {
Some(RenderResourceType::Buffer)
}
fn write_buffer_bytes(&self, buffer: &mut [u8]) {
self.write_bytes(buffer);
}
fn buffer_byte_len(&self) -> Option<usize> {
Some(self.byte_len())
}
fn texture(&self) -> Option<Handle<Texture>> {
None
}

View file

@ -69,12 +69,14 @@ impl dyn RenderResourceContext {
{
self.set_asset_resource_untyped(handle.into(), resource, index);
}
pub fn get_asset_resource<T>(&self, handle: Handle<T>, index: usize) -> Option<RenderResourceId>
where
T: 'static,
{
self.get_asset_resource_untyped(handle.into(), index)
}
pub fn remove_asset_resource<T>(&self, handle: Handle<T>, index: usize)
where
T: 'static,

View file

@ -64,6 +64,7 @@ impl Shader {
pub fn new(stage: ShaderStage, source: ShaderSource) -> Shader {
Shader { stage, source }
}
pub fn from_glsl(stage: ShaderStage, glsl: &str) -> Shader {
Shader {
source: ShaderSource::Glsl(glsl.to_string()),

View file

@ -29,6 +29,7 @@ impl<'a> ShaderDefIterator<'a> {
}
impl<'a> Iterator for ShaderDefIterator<'a> {
type Item = &'a str;
fn next(&mut self) -> Option<Self::Item> {
loop {
if self.index == self.shader_defs.shader_defs_len() {

View file

@ -36,6 +36,7 @@ impl AssetLoader<Texture> for HdrTextureLoader {
format,
))
}
fn extensions(&self) -> &[&str] {
static EXTENSIONS: &[&str] = &["hdr"];
EXTENSIONS

View file

@ -148,6 +148,7 @@ impl AssetLoader<Texture> for ImageTextureLoader {
format,
))
}
fn extensions(&self) -> &[&str] {
static EXTENSIONS: &[&str] = &["png"];
EXTENSIONS

View file

@ -147,10 +147,13 @@ impl RenderResource for Option<Handle<Texture>> {
fn resource_type(&self) -> Option<RenderResourceType> {
self.map(|_texture| RenderResourceType::Texture)
}
fn write_buffer_bytes(&self, _buffer: &mut [u8]) {}
fn buffer_byte_len(&self) -> Option<usize> {
None
}
fn texture(&self) -> Option<Handle<Texture>> {
self.clone()
}
@ -160,10 +163,13 @@ impl RenderResource for Handle<Texture> {
fn resource_type(&self) -> Option<RenderResourceType> {
Some(RenderResourceType::Texture)
}
fn write_buffer_bytes(&self, _buffer: &mut [u8]) {}
fn buffer_byte_len(&self) -> Option<usize> {
None
}
fn texture(&self) -> Option<Handle<Texture>> {
Some(self.clone())
}

View file

@ -33,6 +33,7 @@ impl AssetLoader<Scene> for SceneLoader {
let scene = scene_deserializer.deserialize(&mut deserializer)?;
Ok(scene)
}
fn extensions(&self) -> &[&str] {
static EXTENSIONS: &[&str] = &["scn"];
EXTENSIONS

View file

@ -87,6 +87,7 @@ pub struct SceneDeserializer<'a> {
impl<'a, 'de> DeserializeSeed<'de> for SceneDeserializer<'a> {
type Value = Scene;
fn deserialize<D>(self, deserializer: D) -> Result<Self::Value, D::Error>
where
D: serde::Deserializer<'de>,
@ -106,6 +107,7 @@ struct SceneEntitySeqVisiter<'a> {
impl<'a, 'de> Visitor<'de> for SceneEntitySeqVisiter<'a> {
type Value = Vec<Entity>;
fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
formatter.write_str("list of entities")
}
@ -131,6 +133,7 @@ pub struct SceneEntityDeserializer<'a> {
impl<'a, 'de> DeserializeSeed<'de> for SceneEntityDeserializer<'a> {
type Value = Entity;
fn deserialize<D>(self, deserializer: D) -> Result<Self::Value, D::Error>
where
D: serde::Deserializer<'de>,
@ -162,6 +165,7 @@ struct SceneEntityVisiter<'a> {
impl<'a, 'de> Visitor<'de> for SceneEntityVisiter<'a> {
type Value = Entity;
fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
formatter.write_str("entities")
}
@ -212,6 +216,7 @@ pub struct ComponentVecDeserializer<'a> {
impl<'a, 'de> DeserializeSeed<'de> for ComponentVecDeserializer<'a> {
type Value = Vec<DynamicProperties>;
fn deserialize<D>(self, deserializer: D) -> Result<Self::Value, D::Error>
where
D: serde::Deserializer<'de>,
@ -228,6 +233,7 @@ struct ComponentSeqVisiter<'a> {
impl<'a, 'de> Visitor<'de> for ComponentSeqVisiter<'a> {
type Value = Vec<DynamicProperties>;
fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
formatter.write_str("list of components")
}

View file

@ -10,6 +10,7 @@ impl AssetLoader<Font> for FontLoader {
fn from_bytes(&self, _asset_path: &Path, bytes: Vec<u8>) -> Result<Font> {
Ok(Font::try_from_bytes(bytes)?)
}
fn extensions(&self) -> &[&str] {
static EXTENSIONS: &[&str] = &["ttf"];
EXTENSIONS

View file

@ -14,6 +14,7 @@ impl Children {
impl Deref for Children {
type Target = SmallVec<[Entity; 8]>;
fn deref(&self) -> &Self::Target {
&self.0
}

View file

@ -28,6 +28,7 @@ impl fmt::Display for LocalTransform {
impl Deref for LocalTransform {
type Target = Mat4;
fn deref(&self) -> &Self::Target {
&self.0
}

View file

@ -47,6 +47,7 @@ impl fmt::Display for NonUniformScale {
impl Deref for NonUniformScale {
type Target = Vec3;
fn deref(&self) -> &Self::Target {
&self.0
}

View file

@ -20,6 +20,7 @@ pub struct PreviousParent(pub Option<Entity>);
impl Deref for Parent {
type Target = Entity;
fn deref(&self) -> &Self::Target {
&self.0
}

View file

@ -25,6 +25,7 @@ impl From<Quat> for Rotation {
impl Deref for Rotation {
type Target = Quat;
fn deref(&self) -> &Self::Target {
&self.0
}

View file

@ -35,6 +35,7 @@ impl fmt::Display for Scale {
impl Deref for Scale {
type Target = f32;
fn deref(&self) -> &Self::Target {
&self.0
}

View file

@ -31,6 +31,7 @@ impl From<Vec3> for Translation {
impl Deref for Translation {
type Target = Vec3;
fn deref(&self) -> &Self::Target {
&self.0
}

View file

@ -147,6 +147,7 @@ impl BuildChildren for Commands {
}
self
}
fn push_children(&mut self, parent: Entity, children: &[Entity]) -> &mut Self {
{
let mut commands = self.commands.lock().unwrap();
@ -157,6 +158,7 @@ impl BuildChildren for Commands {
}
self
}
fn insert_children(&mut self, parent: Entity, index: usize, children: &[Entity]) -> &mut Self {
{
let mut commands = self.commands.lock().unwrap();
@ -199,6 +201,7 @@ impl<'a> BuildChildren for ChildBuilder<'a> {
});
self
}
fn insert_children(&mut self, parent: Entity, index: usize, children: &[Entity]) -> &mut Self {
self.commands.write_world(InsertChildren {
children: SmallVec::from(children),

View file

@ -7,22 +7,22 @@ pub struct Anchors {
}
impl Anchors {
pub const CENTER: Anchors = Anchors::new(0.5, 0.5, 0.5, 0.5);
pub const CENTER_LEFT: Anchors = Anchors::new(0.0, 0.0, 0.5, 0.5);
pub const CENTER_RIGHT: Anchors = Anchors::new(1.0, 1.0, 0.5, 0.5);
pub const CENTER_TOP: Anchors = Anchors::new(0.5, 0.5, 1.0, 1.0);
pub const CENTER_BOTTOM: Anchors = Anchors::new(0.5, 0.5, 0.0, 0.0);
pub const CENTER_FULL_VERTICAL: Anchors = Anchors::new(0.5, 0.5, 0.0, 1.0);
pub const CENTER_FULL_HORIZONTAL: Anchors = Anchors::new(0.0, 1.0, 0.5, 0.5);
pub const LEFT_FULL: Anchors = Anchors::new(0.0, 0.0, 0.0, 1.0);
pub const RIGHT_FULL: Anchors = Anchors::new(1.0, 1.0, 0.0, 1.0);
pub const TOP_FULL: Anchors = Anchors::new(0.0, 1.0, 1.0, 1.0);
pub const BOTTOM_FULL: Anchors = Anchors::new(0.0, 1.0, 0.0, 0.0);
pub const BOTTOM_LEFT: Anchors = Anchors::new(0.0, 0.0, 0.0, 0.0);
pub const BOTTOM_RIGHT: Anchors = Anchors::new(1.0, 1.0, 0.0, 0.0);
pub const TOP_RIGHT: Anchors = Anchors::new(1.0, 1.0, 1.0, 1.0);
pub const TOP_LEFT: Anchors = Anchors::new(0.0, 0.0, 1.0, 1.0);
pub const CENTER: Anchors = Anchors::new(0.5, 0.5, 0.5, 0.5);
pub const CENTER_BOTTOM: Anchors = Anchors::new(0.5, 0.5, 0.0, 0.0);
pub const CENTER_FULL_HORIZONTAL: Anchors = Anchors::new(0.0, 1.0, 0.5, 0.5);
pub const CENTER_FULL_VERTICAL: Anchors = Anchors::new(0.5, 0.5, 0.0, 1.0);
pub const CENTER_LEFT: Anchors = Anchors::new(0.0, 0.0, 0.5, 0.5);
pub const CENTER_RIGHT: Anchors = Anchors::new(1.0, 1.0, 0.5, 0.5);
pub const CENTER_TOP: Anchors = Anchors::new(0.5, 0.5, 1.0, 1.0);
pub const FULL: Anchors = Anchors::new(0.0, 1.0, 0.0, 1.0);
pub const LEFT_FULL: Anchors = Anchors::new(0.0, 0.0, 0.0, 1.0);
pub const RIGHT_FULL: Anchors = Anchors::new(1.0, 1.0, 0.0, 1.0);
pub const TOP_FULL: Anchors = Anchors::new(0.0, 1.0, 1.0, 1.0);
pub const TOP_LEFT: Anchors = Anchors::new(0.0, 0.0, 1.0, 1.0);
pub const TOP_RIGHT: Anchors = Anchors::new(1.0, 1.0, 1.0, 1.0);
pub const fn new(left: f32, right: f32, bottom: f32, top: f32) -> Self {
Anchors {

View file

@ -1,8 +1,8 @@
use super::Node;
use crate::{
render::UI_PIPELINE_HANDLE,
widget::{Button, Text, Image},
FocusPolicy, Interaction, Style, CalculatedSize,
widget::{Button, Image, Text},
CalculatedSize, FocusPolicy, Interaction, Style,
};
use bevy_asset::Handle;
use bevy_ecs::Bundle;
@ -110,7 +110,6 @@ impl Default for ImageComponents {
}
}
#[derive(Bundle)]
pub struct TextComponents {
pub node: Node,

View file

@ -1,6 +1,6 @@
use bevy_math::{Rect, Size, Vec2};
use bevy_render::renderer::RenderResources;
use std::ops::{AddAssign, Add};
use std::ops::{Add, AddAssign};
#[derive(Debug, Clone, Default, RenderResources)]
pub struct Node {
@ -23,6 +23,7 @@ impl Default for Val {
impl Add<f32> for Val {
type Output = Val;
fn add(self, rhs: f32) -> Self::Output {
match self {
Val::Undefined => Val::Undefined,
@ -36,7 +37,7 @@ impl Add<f32> for Val {
impl AddAssign<f32> for Val {
fn add_assign(&mut self, rhs: f32) {
match self {
Val::Undefined | Val::Auto => {},
Val::Undefined | Val::Auto => {}
Val::Px(value) => *value += rhs,
Val::Percent(value) => *value += rhs,
}
@ -238,4 +239,4 @@ impl Default for FlexWrap {
fn default() -> FlexWrap {
FlexWrap::NoWrap
}
}
}

View file

@ -1,7 +1,7 @@
mod button;
mod text;
mod image;
mod text;
pub use button::*;
pub use text::*;
pub use image::*;
pub use text::*;

View file

@ -15,41 +15,30 @@ impl AppPlugin for WgpuResourceDiagnosticsPlugin {
}
impl WgpuResourceDiagnosticsPlugin {
pub const WINDOW_SURFACES: DiagnosticId =
DiagnosticId::from_u128(108237028251680341878766034324149135605);
pub const SWAP_CHAINS: DiagnosticId =
DiagnosticId::from_u128(199253035828743332241465305105689014605);
pub const SWAP_CHAIN_OUTPUTS: DiagnosticId =
DiagnosticId::from_u128(112048874168736161226721327099863374234);
pub const BUFFERS: DiagnosticId =
DiagnosticId::from_u128(133146619577893994787249934474491530491);
pub const TEXTURES: DiagnosticId =
DiagnosticId::from_u128(305955424195390184883220102469231911115);
pub const TEXTURE_VIEWS: DiagnosticId =
DiagnosticId::from_u128(257307432866562594739240898780307437578);
pub const SAMPLERS: DiagnosticId =
DiagnosticId::from_u128(305855369913076220671125671543184691267);
pub const BIND_GROUP_IDS: DiagnosticId =
DiagnosticId::from_u128(283571569334075937453357861280307923122);
pub const BIND_GROUPS: DiagnosticId =
DiagnosticId::from_u128(21302464753369276741568507794995836890);
pub const BIND_GROUP_IDS: DiagnosticId =
DiagnosticId::from_u128(283571569334075937453357861280307923122);
pub const BIND_GROUP_LAYOUTS: DiagnosticId =
DiagnosticId::from_u128(96406067032931216377076410852598331304);
pub const SHADER_MODULES: DiagnosticId =
DiagnosticId::from_u128(287681470908132753275843248383768232237);
pub const BUFFERS: DiagnosticId =
DiagnosticId::from_u128(133146619577893994787249934474491530491);
pub const RENDER_PIPELINES: DiagnosticId =
DiagnosticId::from_u128(278527620040377353875091478462209885377);
pub const SAMPLERS: DiagnosticId =
DiagnosticId::from_u128(305855369913076220671125671543184691267);
pub const SHADER_MODULES: DiagnosticId =
DiagnosticId::from_u128(287681470908132753275843248383768232237);
pub const SWAP_CHAINS: DiagnosticId =
DiagnosticId::from_u128(199253035828743332241465305105689014605);
pub const SWAP_CHAIN_OUTPUTS: DiagnosticId =
DiagnosticId::from_u128(112048874168736161226721327099863374234);
pub const TEXTURES: DiagnosticId =
DiagnosticId::from_u128(305955424195390184883220102469231911115);
pub const TEXTURE_VIEWS: DiagnosticId =
DiagnosticId::from_u128(257307432866562594739240898780307437578);
pub const WINDOW_SURFACES: DiagnosticId =
DiagnosticId::from_u128(108237028251680341878766034324149135605);
pub fn setup_system(mut diagnostics: ResMut<Diagnostics>) {
diagnostics.add(Diagnostic::new(

View file

@ -116,6 +116,7 @@ impl RenderContext for WgpuRenderContext {
fn resources(&self) -> &dyn RenderResourceContext {
&self.render_resource_context
}
fn resources_mut(&mut self) -> &mut dyn RenderResourceContext {
&mut self.render_resource_context
}

View file

@ -496,6 +496,7 @@ impl RenderResourceContext for WgpuRenderResourceContext {
fn clear_bind_groups(&self) {
self.resources.bind_groups.write().unwrap().clear();
}
fn get_buffer_info(&self, buffer: BufferId) -> Option<BufferInfo> {
self.resources
.buffer_infos
@ -504,6 +505,7 @@ impl RenderResourceContext for WgpuRenderResourceContext {
.get(&buffer)
.cloned()
}
fn write_mapped_buffer(
&self,
id: BufferId,
@ -529,6 +531,7 @@ impl RenderResourceContext for WgpuRenderResourceContext {
panic!("failed to map buffer to host");
}
}
fn unmap_buffer(&self, id: BufferId) {
let buffers = self.resources.buffers.read().unwrap();
let buffer = buffers.get(&id).unwrap();

View file

@ -28,8 +28,7 @@ fn setup(
rpg_sprite_handles.handles = asset_server
.load_asset_folder("assets/textures/rpg")
.unwrap();
commands
.spawn(Camera2dComponents::default());
commands.spawn(Camera2dComponents::default());
}
fn load_atlas(

View file

@ -8,7 +8,7 @@ use serde::{Deserialize, Serialize};
/// This example illustrates how Properties work. Properties provide a way to dynamically interact with Rust struct fields using
/// their names. Properties are a core part of Bevy and enable a number of interesting scenarios (like scenes). If you are
/// familiar with "reflection" in other languages, Properties are very similar to that concept.
/// familiar with "reflection" in other languages, Properties are very similar to that concept.
fn main() {
App::build()
.add_default_plugins()

View file

@ -1,6 +1,6 @@
use bevy::{prelude::*, text::FontAtlasSet};
/// This example illustrates how FontAtlases are populated. Bevy uses FontAtlases under the hood to optimize text rendering.
/// This example illustrates how FontAtlases are populated. Bevy uses FontAtlases under the hood to optimize text rendering.
fn main() {
App::build()
.init_resource::<State>()

View file

@ -9,7 +9,7 @@ use bevy::{
window::{CreateWindow, WindowDescriptor, WindowId},
};
/// This example creates a second window and draws a mesh from two different cameras.
/// This example creates a second window and draws a mesh from two different cameras.
fn main() {
App::build()
.add_default_plugins()

View file

@ -1,2 +1,4 @@
merge_imports = true
use_field_init_shorthand = true
use_field_init_shorthand = true
reorder_impl_items = true
newline_style = "Unix"