mirror of
https://github.com/bevyengine/bevy
synced 2024-11-10 07:04:33 +00:00
cargo fmt
This commit is contained in:
parent
339e9ad52d
commit
b4c185eb0c
44 changed files with 205 additions and 124 deletions
|
@ -1,6 +1,8 @@
|
|||
use crate::{
|
||||
app::{App, AppExit},
|
||||
event::Events,
|
||||
plugin::{load_plugin, AppPlugin},
|
||||
stage, startup_stage, app::{AppExit, App}, event::Events
|
||||
stage, startup_stage,
|
||||
};
|
||||
use bevy_ecs::{FromResources, IntoQuerySystem, Resources, System, World};
|
||||
|
||||
|
@ -169,7 +171,9 @@ impl AppBuilder {
|
|||
stage_name: &'static str,
|
||||
system: Box<dyn System>,
|
||||
) -> &mut Self {
|
||||
self.app.schedule.add_system_to_stage_front(stage_name, system);
|
||||
self.app
|
||||
.schedule
|
||||
.add_system_to_stage_front(stage_name, system);
|
||||
self
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use crate::AppBuilder;
|
||||
use libloading::{Library, Symbol};
|
||||
use std::any::Any;
|
||||
use crate::AppBuilder;
|
||||
|
||||
pub trait AppPlugin: Any + Send + Sync {
|
||||
fn build(&self, app: &mut AppBuilder);
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
use super::{App, AppBuilder};
|
||||
use crate::{
|
||||
app::AppExit,
|
||||
event::{EventReader, Events},
|
||||
plugin::AppPlugin,
|
||||
};
|
||||
use std::{thread, time::Duration};
|
||||
use crate::{event::{Events, EventReader}, plugin::AppPlugin, app::AppExit};
|
||||
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub enum RunMode {
|
||||
|
|
|
@ -8,7 +8,6 @@ pub mod prelude {
|
|||
pub use crate::{AudioOutput, AudioSource};
|
||||
}
|
||||
|
||||
|
||||
use bevy_app::prelude::*;
|
||||
use bevy_asset::AddAsset;
|
||||
use bevy_ecs::IntoQuerySystem;
|
||||
|
|
|
@ -2,7 +2,9 @@ use bevy_ecs::prelude::*;
|
|||
use bevy_property::Properties;
|
||||
use std::{
|
||||
borrow::Cow,
|
||||
collections::{HashMap, HashSet}, ops::{DerefMut, Deref}, fmt::Debug,
|
||||
collections::{HashMap, HashSet},
|
||||
fmt::Debug,
|
||||
ops::{Deref, DerefMut},
|
||||
};
|
||||
|
||||
#[derive(Default, Properties)]
|
||||
|
@ -21,15 +23,16 @@ impl Debug for Labels {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, T, L: Into<Cow<'static, str>>> From<T> for Labels where T: IntoIterator<Item=L> {
|
||||
impl<'a, T, L: Into<Cow<'static, str>>> From<T> for Labels
|
||||
where
|
||||
T: IntoIterator<Item = L>,
|
||||
{
|
||||
fn from(value: T) -> Self {
|
||||
let mut labels = HashSet::new();
|
||||
for label in value {
|
||||
labels.insert(label.into());
|
||||
}
|
||||
Self {
|
||||
labels,
|
||||
}
|
||||
Self { labels }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
mod bytes;
|
||||
mod float_ord;
|
||||
mod time;
|
||||
mod label;
|
||||
mod time;
|
||||
|
||||
pub use bytes::*;
|
||||
pub use float_ord::*;
|
||||
pub use time::*;
|
||||
pub use label::*;
|
||||
pub use time::*;
|
||||
|
||||
pub mod prelude {
|
||||
pub use crate::{Time, Timer, Labels, EntityLabels};
|
||||
pub use crate::{EntityLabels, Labels, Time, Timer};
|
||||
}
|
||||
|
||||
use bevy_app::prelude::*;
|
||||
|
|
|
@ -140,7 +140,9 @@ impl Archetype {
|
|||
|
||||
#[allow(missing_docs)]
|
||||
#[inline]
|
||||
pub fn get_with_added_and_mutated<T: Component>(&self) -> Option<(NonNull<T>, NonNull<bool>, NonNull<bool>)> {
|
||||
pub fn get_with_added_and_mutated<T: Component>(
|
||||
&self,
|
||||
) -> Option<(NonNull<T>, NonNull<bool>, NonNull<bool>)> {
|
||||
let state = self.state.get(&TypeId::of::<T>())?;
|
||||
Some(unsafe {
|
||||
(
|
||||
|
@ -351,8 +353,10 @@ impl Archetype {
|
|||
);
|
||||
|
||||
let type_state = self.state.get_mut(&ty.id).unwrap();
|
||||
type_state.mutated_entities[index as usize] = type_state.mutated_entities[last as usize];
|
||||
type_state.added_entities[index as usize] = type_state.added_entities[last as usize];
|
||||
type_state.mutated_entities[index as usize] =
|
||||
type_state.mutated_entities[last as usize];
|
||||
type_state.added_entities[index as usize] =
|
||||
type_state.added_entities[last as usize];
|
||||
}
|
||||
}
|
||||
self.len = last;
|
||||
|
@ -377,7 +381,7 @@ impl Archetype {
|
|||
.unwrap()
|
||||
.as_ptr();
|
||||
let type_state = self.state.get(&ty.id).unwrap();
|
||||
let is_added= type_state.added_entities[index as usize];
|
||||
let is_added = type_state.added_entities[index as usize];
|
||||
let is_mutated = type_state.mutated_entities[index as usize];
|
||||
f(moved, ty.id(), ty.layout().size(), is_added, is_mutated);
|
||||
if index != last {
|
||||
|
@ -389,8 +393,10 @@ impl Archetype {
|
|||
ty.layout.size(),
|
||||
);
|
||||
let type_state = self.state.get_mut(&ty.id).unwrap();
|
||||
type_state.added_entities[index as usize] = type_state.added_entities[last as usize];
|
||||
type_state.mutated_entities[index as usize] = type_state.mutated_entities[last as usize];
|
||||
type_state.added_entities[index as usize] =
|
||||
type_state.added_entities[last as usize];
|
||||
type_state.mutated_entities[index as usize] =
|
||||
type_state.mutated_entities[last as usize];
|
||||
}
|
||||
}
|
||||
self.len -= 1;
|
||||
|
@ -403,15 +409,22 @@ impl Archetype {
|
|||
}
|
||||
|
||||
#[allow(missing_docs)]
|
||||
pub unsafe fn put_dynamic(&mut self, component: *mut u8, ty: TypeId, size: usize, index: u32, added: bool) {
|
||||
pub unsafe fn put_dynamic(
|
||||
&mut self,
|
||||
component: *mut u8,
|
||||
ty: TypeId,
|
||||
size: usize,
|
||||
index: u32,
|
||||
added: bool,
|
||||
) {
|
||||
let state = self.state.get_mut(&ty).unwrap();
|
||||
if added {
|
||||
state.added_entities[index as usize] = true;
|
||||
}
|
||||
let ptr = (*self.data.get())
|
||||
.as_ptr()
|
||||
.add(state.offset + size * index as usize)
|
||||
.cast::<u8>();
|
||||
.as_ptr()
|
||||
.add(state.offset + size * index as usize)
|
||||
.cast::<u8>();
|
||||
ptr::copy_nonoverlapping(component, ptr, size);
|
||||
}
|
||||
|
||||
|
|
|
@ -15,9 +15,10 @@
|
|||
// modified by Bevy contributors
|
||||
|
||||
use core::{
|
||||
fmt::Debug,
|
||||
ops::{Deref, DerefMut},
|
||||
ptr::NonNull,
|
||||
sync::atomic::{AtomicUsize, Ordering}, fmt::Debug,
|
||||
sync::atomic::{AtomicUsize, Ordering},
|
||||
};
|
||||
|
||||
use crate::{archetype::Archetype, Component, MissingComponent};
|
||||
|
@ -101,7 +102,10 @@ impl<'a, T: Component> Deref for Ref<'a, T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, T: Component> Debug for Ref<'a,T> where T: Debug {
|
||||
impl<'a, T: Component> Debug for Ref<'a, T>
|
||||
where
|
||||
T: Debug,
|
||||
{
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
||||
self.deref().fmt(f)
|
||||
}
|
||||
|
@ -161,7 +165,10 @@ impl<'a, T: Component> DerefMut for RefMut<'a, T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, T: Component> Debug for RefMut<'a,T> where T: Debug {
|
||||
impl<'a, T: Component> Debug for RefMut<'a, T>
|
||||
where
|
||||
T: Debug,
|
||||
{
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
||||
self.deref().fmt(f)
|
||||
}
|
||||
|
|
|
@ -319,14 +319,12 @@ impl<'a, T: Component> Fetch<'a> for FetchAdded<T> {
|
|||
archetype.borrow::<T>();
|
||||
}
|
||||
unsafe fn get(archetype: &'a Archetype, offset: usize) -> Option<Self> {
|
||||
archetype
|
||||
.get_with_added::<T>()
|
||||
.map(|(components, added)| {
|
||||
Self(
|
||||
NonNull::new_unchecked(components.as_ptr().add(offset)),
|
||||
NonNull::new_unchecked(added.as_ptr().add(offset)),
|
||||
)
|
||||
})
|
||||
archetype.get_with_added::<T>().map(|(components, added)| {
|
||||
Self(
|
||||
NonNull::new_unchecked(components.as_ptr().add(offset)),
|
||||
NonNull::new_unchecked(added.as_ptr().add(offset)),
|
||||
)
|
||||
})
|
||||
}
|
||||
fn release(archetype: &Archetype) {
|
||||
archetype.release::<T>();
|
||||
|
@ -346,7 +344,6 @@ impl<'a, T: Component> Fetch<'a> for FetchAdded<T> {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
#[allow(missing_docs)]
|
||||
pub struct Changed<'a, T> {
|
||||
value: &'a T,
|
||||
|
@ -412,7 +409,6 @@ impl<'a, T: Component> Fetch<'a> for FetchChanged<T> {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
#[doc(hidden)]
|
||||
pub struct TryFetch<T>(Option<T>);
|
||||
|
||||
|
|
|
@ -336,7 +336,9 @@ impl World {
|
|||
|
||||
#[allow(missing_docs)]
|
||||
pub fn removed<C: Component>(&self) -> &[Entity] {
|
||||
self.removed_components.get(&TypeId::of::<C>()).map_or(&[], |entities| entities.as_slice())
|
||||
self.removed_components
|
||||
.get(&TypeId::of::<C>())
|
||||
.map_or(&[], |entities| entities.as_slice())
|
||||
}
|
||||
|
||||
/// Add `components` to `entity`
|
||||
|
@ -501,7 +503,8 @@ impl World {
|
|||
state.added_entities[target_index as usize] = is_added;
|
||||
state.mutated_entities[target_index as usize] = is_mutated;
|
||||
} else {
|
||||
let removed_entities = removed_components.entry(ty).or_insert_with(|| Vec::new());
|
||||
let removed_entities =
|
||||
removed_components.entry(ty).or_insert_with(|| Vec::new());
|
||||
removed_entities.push(entity);
|
||||
}
|
||||
})
|
||||
|
|
|
@ -343,24 +343,64 @@ fn remove_tracking() {
|
|||
let b = world.spawn(("abc", 123));
|
||||
|
||||
world.despawn(a).unwrap();
|
||||
assert_eq!(world.removed::<i32>(), &[a], "despawning results in 'removed component' state");
|
||||
assert_eq!(world.removed::<&'static str>(), &[a], "despawning results in 'removed component' state");
|
||||
assert_eq!(
|
||||
world.removed::<i32>(),
|
||||
&[a],
|
||||
"despawning results in 'removed component' state"
|
||||
);
|
||||
assert_eq!(
|
||||
world.removed::<&'static str>(),
|
||||
&[a],
|
||||
"despawning results in 'removed component' state"
|
||||
);
|
||||
|
||||
world.insert_one(b, 10.0).unwrap();
|
||||
assert_eq!(world.removed::<i32>(), &[a], "archetype moves does not result in 'removed component' state");
|
||||
assert_eq!(
|
||||
world.removed::<i32>(),
|
||||
&[a],
|
||||
"archetype moves does not result in 'removed component' state"
|
||||
);
|
||||
|
||||
world.remove_one::<i32>(b).unwrap();
|
||||
assert_eq!(world.removed::<i32>(), &[a, b], "removing a component results in a 'removed component' state");
|
||||
assert_eq!(
|
||||
world.removed::<i32>(),
|
||||
&[a, b],
|
||||
"removing a component results in a 'removed component' state"
|
||||
);
|
||||
|
||||
world.clear_trackers();
|
||||
assert_eq!(world.removed::<i32>(), &[], "clearning trackers clears removals");
|
||||
assert_eq!(world.removed::<&'static str>(), &[], "clearning trackers clears removals");
|
||||
assert_eq!(world.removed::<f64>(), &[], "clearning trackers clears removals");
|
||||
assert_eq!(
|
||||
world.removed::<i32>(),
|
||||
&[],
|
||||
"clearning trackers clears removals"
|
||||
);
|
||||
assert_eq!(
|
||||
world.removed::<&'static str>(),
|
||||
&[],
|
||||
"clearning trackers clears removals"
|
||||
);
|
||||
assert_eq!(
|
||||
world.removed::<f64>(),
|
||||
&[],
|
||||
"clearning trackers clears removals"
|
||||
);
|
||||
|
||||
let c = world.spawn(("abc", 123));
|
||||
let d = world.spawn(("abc", 123));
|
||||
world.clear();
|
||||
assert_eq!(world.removed::<i32>(), &[c, d], "world clears result in 'removed component' states");
|
||||
assert_eq!(world.removed::<&'static str>(), &[c, d, b], "world clears result in 'removed component' states");
|
||||
assert_eq!(world.removed::<f64>(), &[b], "world clears result in 'removed component' states");
|
||||
}
|
||||
assert_eq!(
|
||||
world.removed::<i32>(),
|
||||
&[c, d],
|
||||
"world clears result in 'removed component' states"
|
||||
);
|
||||
assert_eq!(
|
||||
world.removed::<&'static str>(),
|
||||
&[c, d, b],
|
||||
"world clears result in 'removed component' states"
|
||||
);
|
||||
assert_eq!(
|
||||
world.removed::<f64>(),
|
||||
&[b],
|
||||
"world clears result in 'removed component' states"
|
||||
);
|
||||
}
|
||||
|
|
|
@ -2,4 +2,4 @@ mod resource_query;
|
|||
mod resources;
|
||||
|
||||
pub use resource_query::*;
|
||||
pub use resources::*;
|
||||
pub use resources::*;
|
||||
|
|
|
@ -67,11 +67,17 @@ impl Resources {
|
|||
let archetype = &mut data.archetype;
|
||||
let mut added = false;
|
||||
let index = match resource_index {
|
||||
ResourceIndex::Global => *data.default_index.get_or_insert_with(|| { added = true; archetype.len() }),
|
||||
ResourceIndex::Global => *data.default_index.get_or_insert_with(|| {
|
||||
added = true;
|
||||
archetype.len()
|
||||
}),
|
||||
ResourceIndex::System(id) => *data
|
||||
.system_id_to_archetype_index
|
||||
.entry(id.0)
|
||||
.or_insert_with(|| { added = true; archetype.len() }),
|
||||
.or_insert_with(|| {
|
||||
added = true;
|
||||
archetype.len()
|
||||
}),
|
||||
};
|
||||
|
||||
if index == archetype.len() {
|
||||
|
@ -82,7 +88,13 @@ impl Resources {
|
|||
|
||||
unsafe {
|
||||
let resource_ptr = (&mut resource as *mut T).cast::<u8>();
|
||||
archetype.put_dynamic(resource_ptr, type_id, core::mem::size_of::<T>(), index, added);
|
||||
archetype.put_dynamic(
|
||||
resource_ptr,
|
||||
type_id,
|
||||
core::mem::size_of::<T>(),
|
||||
index,
|
||||
added,
|
||||
);
|
||||
std::mem::forget(resource);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,4 +2,4 @@ mod parallel_executor;
|
|||
mod schedule;
|
||||
|
||||
pub use parallel_executor::*;
|
||||
pub use schedule::*;
|
||||
pub use schedule::*;
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
use crate::{
|
||||
system::{System, ThreadLocalExecution, SystemId}, resource::Resources,
|
||||
resource::Resources,
|
||||
system::{System, SystemId, ThreadLocalExecution},
|
||||
};
|
||||
use hecs::World;
|
||||
use std::{
|
||||
borrow::Cow,
|
||||
collections::{HashMap, HashSet},
|
||||
sync::{Arc, Mutex},
|
||||
};
|
||||
use hecs::World;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct Schedule {
|
||||
|
|
|
@ -157,10 +157,11 @@ impl<'a, Q: HecsQuery> Query<'a, Q> {
|
|||
if self
|
||||
.archetype_access
|
||||
.immutable
|
||||
.contains(location.archetype as usize) || self
|
||||
.archetype_access
|
||||
.mutable
|
||||
.contains(location.archetype as usize)
|
||||
|| self
|
||||
.archetype_access
|
||||
.mutable
|
||||
.contains(location.archetype as usize)
|
||||
{
|
||||
self.world
|
||||
.get(entity)
|
||||
|
|
|
@ -8,4 +8,4 @@ pub use commands::*;
|
|||
pub use into_system::*;
|
||||
#[cfg(feature = "profiler")]
|
||||
pub use profiler::*;
|
||||
pub use system::*;
|
||||
pub use system::*;
|
||||
|
|
|
@ -100,9 +100,9 @@ impl TypeAccess {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::{ArchetypeAccess, TypeAccess};
|
||||
use crate::resource::{FetchResource, Res, ResMut, ResourceQuery};
|
||||
use hecs::World;
|
||||
use std::any::TypeId;
|
||||
use crate::resource::{Res, ResourceQuery, ResMut, FetchResource};
|
||||
|
||||
struct A;
|
||||
struct B;
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
mod world_builder;
|
||||
|
||||
pub use world_builder::*;
|
||||
pub use world_builder::*;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use crate::Input;
|
||||
use bevy_ecs::{Res, ResMut};
|
||||
use bevy_app::prelude::*;
|
||||
use bevy_ecs::{Res, ResMut};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct KeyboardInput {
|
||||
|
|
|
@ -9,7 +9,7 @@ impl PerspectiveRh for Mat4 {
|
|||
fn perspective_rh(fov_y_radians: f32, aspect_ratio: f32, z_near: f32, z_far: f32) -> Self {
|
||||
let (sin_fov, cos_fov) = (0.5 * fov_y_radians).sin_cos();
|
||||
let h = cos_fov / sin_fov;
|
||||
let w = h /aspect_ratio;
|
||||
let w = h / aspect_ratio;
|
||||
let r = z_far / (z_near - z_far);
|
||||
Mat4::from_cols(
|
||||
Vec4::new(w, 0.0, 0.0, 0.0),
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use bevy_math::{PerspectiveRh, Mat4};
|
||||
use bevy_math::{Mat4, PerspectiveRh};
|
||||
use bevy_property::{Properties, Property};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
|
|
|
@ -61,7 +61,7 @@ pub struct Camera2dComponents {
|
|||
impl Default for Camera2dComponents {
|
||||
fn default() -> Self {
|
||||
// we want 0 to be "closest" and +far to be "farthest" in 2d, so we offset
|
||||
// the camera's translation by far and use a right handed coordinate system
|
||||
// the camera's translation by far and use a right handed coordinate system
|
||||
let far = 1000.0;
|
||||
Camera2dComponents {
|
||||
camera: Camera {
|
||||
|
|
|
@ -2,4 +2,4 @@ mod mesh;
|
|||
mod vertex;
|
||||
|
||||
pub use mesh::*;
|
||||
pub use vertex::*;
|
||||
pub use vertex::*;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use crate::{Font, FontAtlasSet};
|
||||
use ab_glyph::{FontVec, Glyph, PxScale, PxScaleFont, ScaleFont};
|
||||
use bevy_asset::Assets;
|
||||
use bevy_math::{Mat4, Vec3, Vec2};
|
||||
use bevy_math::{Mat4, Vec2, Vec3};
|
||||
use bevy_render::{
|
||||
color::Color,
|
||||
draw::{Draw, DrawContext, DrawError, Drawable},
|
||||
|
@ -112,9 +112,12 @@ impl<'a> Drawable for DrawableText<'a> {
|
|||
match self.style.align {
|
||||
TextAlign::Left => { /* already aligned left by default */ }
|
||||
TextAlign::Center => {
|
||||
*caret.x_mut() += self.container_size.x() / 2.0 - get_text_width(&self.text, &scaled_font) / 2.0
|
||||
*caret.x_mut() +=
|
||||
self.container_size.x() / 2.0 - get_text_width(&self.text, &scaled_font) / 2.0
|
||||
}
|
||||
TextAlign::Right => {
|
||||
*caret.x_mut() += self.container_size.x() - get_text_width(&self.text, &scaled_font)
|
||||
}
|
||||
TextAlign::Right => *caret.x_mut() += self.container_size.x() - get_text_width(&self.text, &scaled_font),
|
||||
}
|
||||
|
||||
let mut last_glyph: Option<Glyph> = None;
|
||||
|
|
|
@ -11,7 +11,7 @@ pub use font_atlas_set::*;
|
|||
pub use font_loader::*;
|
||||
|
||||
pub mod prelude {
|
||||
pub use crate::{Font, TextStyle, TextAlign};
|
||||
pub use crate::{Font, TextAlign, TextStyle};
|
||||
}
|
||||
|
||||
use bevy_app::prelude::*;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use bevy_ecs::Entity;
|
||||
use bevy_property::Properties;
|
||||
use smallvec::SmallVec;
|
||||
use std::ops::{DerefMut, Deref};
|
||||
use std::ops::{Deref, DerefMut};
|
||||
|
||||
#[derive(Default, Clone, Properties, Debug)]
|
||||
pub struct Children(pub SmallVec<[Entity; 8]>);
|
||||
|
@ -23,4 +23,4 @@ impl DerefMut for Children {
|
|||
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||
&mut self.0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
use bevy_math::Mat4;
|
||||
use bevy_property::Properties;
|
||||
use std::{ops::{DerefMut, Deref}, fmt};
|
||||
use std::{
|
||||
fmt,
|
||||
ops::{Deref, DerefMut},
|
||||
};
|
||||
|
||||
#[derive(Debug, PartialEq, Clone, Copy, Properties)]
|
||||
pub struct LocalTransform(pub Mat4);
|
||||
|
@ -34,4 +37,4 @@ impl DerefMut for LocalTransform {
|
|||
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||
&mut self.0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
use bevy_math::Vec3;
|
||||
use bevy_property::Properties;
|
||||
use std::{ops::{DerefMut, Deref}, fmt};
|
||||
use std::{
|
||||
fmt,
|
||||
ops::{Deref, DerefMut},
|
||||
};
|
||||
|
||||
#[derive(Debug, PartialEq, Clone, Copy, Properties)]
|
||||
pub struct NonUniformScale(pub Vec3);
|
||||
|
@ -53,4 +56,4 @@ impl DerefMut for NonUniformScale {
|
|||
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||
&mut self.0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use bevy_ecs::{FromResources, Entity};
|
||||
use bevy_ecs::{Entity, FromResources};
|
||||
use bevy_property::Properties;
|
||||
use std::ops::{DerefMut, Deref};
|
||||
use std::ops::{Deref, DerefMut};
|
||||
|
||||
#[derive(Debug, Copy, Clone, Eq, PartialEq, Properties)]
|
||||
pub struct Parent(pub Entity);
|
||||
|
@ -11,7 +11,7 @@ pub struct Parent(pub Entity);
|
|||
// ways to handle cases like this.
|
||||
impl FromResources for Parent {
|
||||
fn from_resources(_resources: &bevy_ecs::Resources) -> Self {
|
||||
Parent(Entity::from_id(u32::MAX))
|
||||
Parent(Entity::from_id(u32::MAX))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -29,4 +29,4 @@ impl DerefMut for Parent {
|
|||
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||
&mut self.0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,4 +34,4 @@ impl DerefMut for Rotation {
|
|||
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||
&mut self.0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
use bevy_property::Properties;
|
||||
use std::{ops::{DerefMut, Deref}, fmt};
|
||||
use std::{
|
||||
fmt,
|
||||
ops::{Deref, DerefMut},
|
||||
};
|
||||
|
||||
#[derive(Debug, PartialEq, Clone, Copy, Properties)]
|
||||
pub struct Scale(pub f32);
|
||||
|
@ -41,4 +44,4 @@ impl DerefMut for Scale {
|
|||
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||
&mut self.0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use bevy_math::Vec3;
|
||||
use bevy_property::Properties;
|
||||
use std::ops::{DerefMut, Deref};
|
||||
use std::ops::{Deref, DerefMut};
|
||||
|
||||
#[derive(Debug, PartialEq, Copy, Clone, Properties)]
|
||||
pub struct Translation(pub Vec3);
|
||||
|
@ -40,4 +40,4 @@ impl DerefMut for Translation {
|
|||
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||
&mut self.0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use crate::prelude::{LocalTransform, Parent, PreviousParent, Children};
|
||||
use crate::prelude::{Children, LocalTransform, Parent, PreviousParent};
|
||||
use bevy_ecs::{Component, DynamicBundle, Entity, WorldBuilder};
|
||||
|
||||
pub struct WorldChildBuilder<'a, 'b> {
|
||||
|
|
|
@ -11,7 +11,9 @@ pub mod prelude {
|
|||
use bevy_app::prelude::*;
|
||||
use bevy_ecs::prelude::*;
|
||||
use bevy_type_registry::RegisterType;
|
||||
use prelude::{Children, LocalTransform, NonUniformScale, Rotation, Scale, Transform, Translation, Parent};
|
||||
use prelude::{
|
||||
Children, LocalTransform, NonUniformScale, Parent, Rotation, Scale, Transform, Translation,
|
||||
};
|
||||
|
||||
pub(crate) fn transform_systems() -> Vec<Box<dyn System>> {
|
||||
let mut systems = Vec::with_capacity(5);
|
||||
|
|
|
@ -50,4 +50,4 @@ impl AppPlugin for UiPlugin {
|
|||
let mut render_graph = resources.get_mut::<RenderGraph>().unwrap();
|
||||
render_graph.add_ui_graph(resources);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1 +1 @@
|
|||
pub struct Button;
|
||||
pub struct Button;
|
||||
|
|
|
@ -72,4 +72,4 @@ pub fn draw_text_system(
|
|||
};
|
||||
drawable_text.draw(&mut draw, &mut draw_context).unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -267,9 +267,14 @@ impl RenderResourceContext for WgpuRenderResourceContext {
|
|||
if let Some(texture_id) = self.try_next_swap_chain_texture(window.id) {
|
||||
texture_id
|
||||
} else {
|
||||
self.resources.window_swap_chains.write().unwrap().remove(&window.id);
|
||||
self.resources
|
||||
.window_swap_chains
|
||||
.write()
|
||||
.unwrap()
|
||||
.remove(&window.id);
|
||||
self.create_swap_chain(window);
|
||||
self.try_next_swap_chain_texture(window.id).expect("Failed to acquire next swap chain texture!")
|
||||
self.try_next_swap_chain_texture(window.id)
|
||||
.expect("Failed to acquire next swap chain texture!")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ impl WindowId {
|
|||
}
|
||||
|
||||
pub fn is_primary(&self) -> bool {
|
||||
*self == WindowId::primary()
|
||||
*self == WindowId::primary()
|
||||
}
|
||||
|
||||
pub fn to_string(&self) -> String {
|
||||
|
|
|
@ -91,9 +91,7 @@ pub fn winit_runner(mut app: App) {
|
|||
let windows = app.resources.get_mut::<Windows>().unwrap();
|
||||
let winit_windows = app.resources.get_mut::<WinitWindows>().unwrap();
|
||||
let window_id = winit_windows.get_window_id(winit_window_id).unwrap();
|
||||
window_close_requested_events.send(WindowCloseRequested {
|
||||
id: window_id,
|
||||
});
|
||||
window_close_requested_events.send(WindowCloseRequested { id: window_id });
|
||||
}
|
||||
WindowEvent::KeyboardInput { ref input, .. } => {
|
||||
let mut keyboard_input_events =
|
||||
|
@ -108,7 +106,7 @@ pub fn winit_runner(mut app: App) {
|
|||
let window = winit_windows.get_window(window_id).unwrap();
|
||||
let inner_size = window.inner_size();
|
||||
// move origin to bottom left
|
||||
let y_position = inner_size.height as f32 - position.y as f32;
|
||||
let y_position = inner_size.height as f32 - position.y as f32;
|
||||
cursor_moved_events.send(CursorMoved {
|
||||
id: window_id,
|
||||
position: Vec2::new(position.x as f32, y_position as f32),
|
||||
|
@ -161,8 +159,6 @@ fn handle_create_window_events(
|
|||
winit_windows.create_window(event_loop, &window);
|
||||
let window_id = window.id;
|
||||
windows.add(window);
|
||||
window_created_events.send(WindowCreated {
|
||||
id: window_id,
|
||||
});
|
||||
window_created_events.send(WindowCreated { id: window_id });
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
use bevy::prelude::*;
|
||||
|
||||
fn main() {
|
||||
App::build()
|
||||
.add_system(hello_world_system.system())
|
||||
.run();
|
||||
App::build().add_system(hello_world_system.system()).run();
|
||||
}
|
||||
|
||||
fn hello_world_system() {
|
||||
|
|
|
@ -239,6 +239,5 @@ fn setup(
|
|||
.spawn(NodeComponents {
|
||||
material: materials.add(Color::rgb(1.0, 0.0, 0.0).into()),
|
||||
..Default::default()
|
||||
})
|
||||
;
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,20 +1,6 @@
|
|||
pub use crate::{
|
||||
app::prelude::*,
|
||||
asset::prelude::*,
|
||||
audio::prelude::*,
|
||||
core::prelude::*,
|
||||
ecs::prelude::*,
|
||||
input::prelude::*,
|
||||
math::prelude::*,
|
||||
pbr::prelude::*,
|
||||
property::prelude::*,
|
||||
render::prelude::*,
|
||||
scene::prelude::*,
|
||||
sprite::prelude::*,
|
||||
text::prelude::*,
|
||||
transform::prelude::*,
|
||||
type_registry::RegisterType,
|
||||
window::prelude::*,
|
||||
ui::prelude::*,
|
||||
AddDefaultPlugins,
|
||||
app::prelude::*, asset::prelude::*, audio::prelude::*, core::prelude::*, ecs::prelude::*,
|
||||
input::prelude::*, math::prelude::*, pbr::prelude::*, property::prelude::*, render::prelude::*,
|
||||
scene::prelude::*, sprite::prelude::*, text::prelude::*, transform::prelude::*,
|
||||
type_registry::RegisterType, ui::prelude::*, window::prelude::*, AddDefaultPlugins,
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue