Merge branch 'main' into transmission

This commit is contained in:
Marco Buono 2023-05-28 16:44:36 -03:00
commit 521426047f
25 changed files with 70 additions and 49 deletions

View file

@ -404,7 +404,7 @@ path = "examples/2d/texture_atlas.rs"
name = "Texture Atlas"
description = "Generates a texture atlas (sprite sheet) from individual sprites"
category = "2D Rendering"
wasm = true
wasm = false
[[example]]
name = "transparency_2d"
@ -916,7 +916,7 @@ path = "examples/asset/asset_loading.rs"
name = "Asset Loading"
description = "Demonstrates various methods to load assets"
category = "Assets"
wasm = true
wasm = false
[[example]]
name = "custom_asset"

View file

@ -11,7 +11,7 @@ fn fragment(
@builtin(position) position: vec4<f32>,
#import bevy_pbr::mesh_vertex_output
) -> @location(0) vec4<f32> {
let uv = coords_to_viewport_uv(position.xy, view.viewport);
let color = textureSample(texture, texture_sampler, uv);
let viewport_uv = coords_to_viewport_uv(position.xy, view.viewport);
let color = textureSample(texture, texture_sampler, viewport_uv);
return color;
}

View file

@ -144,7 +144,7 @@ impl PluginGroupBuilder {
/// opt back in to a [`Plugin`] after [disabling](Self::disable) it. If there are no plugins
/// of type `T` in this group, it will panic.
pub fn enable<T: Plugin>(mut self) -> Self {
let mut plugin_entry = self
let plugin_entry = self
.plugins
.get_mut(&TypeId::of::<T>())
.expect("Cannot enable a plugin that does not exist.");
@ -158,7 +158,7 @@ impl PluginGroupBuilder {
/// [`add_after`](Self::add_after), or it can be [re-enabled](Self::enable). If there are no
/// plugins of type `T` in this group, it will panic.
pub fn disable<T: Plugin>(mut self) -> Self {
let mut plugin_entry = self
let plugin_entry = self
.plugins
.get_mut(&TypeId::of::<T>())
.expect("Cannot disable a plugin that does not exist.");

View file

@ -133,12 +133,12 @@ impl<T: Asset> Assets<T> {
/// This is the main method for accessing asset data from an [Assets] collection. If you need
/// mutable access to the asset, use [`get_mut`](Assets::get_mut).
pub fn get(&self, handle: &Handle<T>) -> Option<&T> {
self.assets.get(&handle.into())
self.assets.get::<HandleId>(&handle.into())
}
/// Checks if an asset exists for the given handle
pub fn contains(&self, handle: &Handle<T>) -> bool {
self.assets.contains_key(&handle.into())
self.assets.contains_key::<HandleId>(&handle.into())
}
/// Get mutable access to the asset for the given handle.

View file

@ -1,11 +1,11 @@
use bevy_reflect::{
FromReflect, Reflect, ReflectDeserialize, ReflectFromReflect, ReflectSerialize,
};
use bevy_utils::AHasher;
use bevy_utils::{AHasher, RandomState};
use serde::{Deserialize, Serialize};
use std::{
borrow::Cow,
hash::{Hash, Hasher},
hash::{BuildHasher, Hash, Hasher},
path::{Path, PathBuf},
};
@ -130,7 +130,7 @@ impl AssetPathId {
/// this hasher provides consistent results across runs
pub(crate) fn get_hasher() -> AHasher {
AHasher::new_with_keys(42, 23)
RandomState::with_seeds(42, 23, 13, 8).build_hasher()
}
impl<'a, T> From<T> for AssetPathId

View file

@ -24,7 +24,7 @@ bevy_utils = { path = "../bevy_utils", version = "0.11.0-dev" }
# MacOS
[target.'cfg(all(target_os="macos"))'.dependencies]
# Some features of sysinfo are not supported by apple. This will disable those features on apple devices
sysinfo = { version = "0.28.1", default-features = false, features = [
sysinfo = { version = "0.29.0", default-features = false, features = [
"apple-app-store",
] }

View file

@ -15,5 +15,5 @@ keywords = ["bevy"]
bevy_app = { path = "../bevy_app", version = "0.11.0-dev" }
# other
libloading = { version = "0.7" }
libloading = { version = "0.8" }
thiserror = "1.0"

View file

@ -1,6 +1,7 @@
use std::fmt::Debug;
use std::hash::Hash;
use std::mem;
use std::ops::Deref;
use crate as bevy_ecs;
use crate::change_detection::DetectChangesMut;
@ -95,6 +96,14 @@ impl<S: States> PartialEq<S> for State<S> {
}
}
impl<S: States> Deref for State<S> {
type Target = S;
fn deref(&self) -> &Self::Target {
self.get()
}
}
/// The next state of [`State<S>`].
///
/// To queue a transition, just set the contained value to `Some(next_state)`.

View file

@ -1472,7 +1472,7 @@ impl World {
}
}
/// Increments the world's current change tick, and returns the old value.
/// Increments the world's current change tick and returns the old value.
#[inline]
pub fn increment_change_tick(&self) -> Tick {
let prev_tick = self.change_tick.fetch_add(1, Ordering::AcqRel);

View file

@ -253,6 +253,7 @@ impl<'w> UnsafeWorldCell<'w> {
unsafe { self.world_metadata() }.last_change_tick()
}
/// Increments the world's current change tick and returns the old value.
#[inline]
pub fn increment_change_tick(self) -> Tick {
// SAFETY:

View file

@ -102,7 +102,7 @@ pub struct LogPlugin {
impl Default for LogPlugin {
fn default() -> Self {
Self {
filter: "wgpu=error".to_string(),
filter: "wgpu=error,naga=warn".to_string(),
level: Level::INFO,
}
}

View file

@ -123,7 +123,7 @@ fn extract_windows(
window.resolution.physical_height().max(1),
);
let mut extracted_window = extracted_windows.entry(entity).or_insert(ExtractedWindow {
let extracted_window = extracted_windows.entry(entity).or_insert(ExtractedWindow {
entity,
handle: handle.clone(),
physical_width: new_width,

View file

@ -432,7 +432,7 @@ pub struct PreparedMaterial2d<T: Material2d> {
}
#[derive(Resource)]
struct ExtractedMaterials2d<M: Material2d> {
pub struct ExtractedMaterials2d<M: Material2d> {
extracted: Vec<(Handle<M>, M)>,
removed: Vec<Handle<M>>,
}
@ -458,7 +458,7 @@ impl<T: Material2d> Default for RenderMaterials2d<T> {
/// This system extracts all created or modified assets of the corresponding [`Material2d`] type
/// into the "render world".
fn extract_materials_2d<M: Material2d>(
pub fn extract_materials_2d<M: Material2d>(
mut commands: Commands,
mut events: Extract<EventReader<AssetEvent<M>>>,
assets: Extract<Res<Assets<M>>>,
@ -505,7 +505,7 @@ impl<M: Material2d> Default for PrepareNextFrameMaterials<M> {
/// This system prepares all assets of the corresponding [`Material2d`] type
/// which where extracted this frame for the GPU.
fn prepare_materials_2d<M: Material2d>(
pub fn prepare_materials_2d<M: Material2d>(
mut prepare_next_frame: Local<PrepareNextFrameMaterials<M>>,
mut extracted_assets: ResMut<ExtractedMaterials2d<M>>,
mut render_materials: ResMut<RenderMaterials2d<M>>,

View file

@ -20,7 +20,7 @@ pub struct TextureAtlas {
/// The specific areas of the atlas where each texture can be found
pub textures: Vec<Rect>,
/// Mapping from texture handle to index
pub(crate) texture_handles: Option<HashMap<Handle<Image>, usize>>,
pub texture_handles: Option<HashMap<Handle<Image>, usize>>,
}
#[derive(Component, Debug, Clone, Reflect, FromReflect)]

View file

@ -23,7 +23,7 @@ use bevy_utils::Duration;
/// assert!(stopwatch.paused());
/// assert_eq!(stopwatch.elapsed_secs(), 0.0);
/// ```
#[derive(Clone, Debug, Default, Reflect, FromReflect)]
#[derive(Clone, Debug, Default, PartialEq, Eq, Reflect, FromReflect)]
#[cfg_attr(feature = "serialize", derive(serde::Deserialize, serde::Serialize))]
#[reflect(Default)]
pub struct Stopwatch {

View file

@ -9,7 +9,7 @@ use bevy_utils::Duration;
/// exceeded, and can still be reset at any given point.
///
/// Paused timers will not have elapsed time increased.
#[derive(Clone, Debug, Default, Reflect, FromReflect)]
#[derive(Clone, Debug, Default, PartialEq, Eq, Reflect, FromReflect)]
#[cfg_attr(feature = "serialize", derive(serde::Deserialize, serde::Serialize))]
#[reflect(Default)]
pub struct Timer {

View file

@ -349,19 +349,19 @@ impl Transform {
/// and [`Transform::up`] points towards `up`.
///
/// In some cases it's not possible to construct a rotation. Another axis will be picked in those cases:
/// * if `direction` is zero, `Vec3::Z` is used instead
/// * if `direction` is zero, `Vec3::NEG_Z` is used instead
/// * if `up` is zero, `Vec3::Y` is used instead
/// * if `direction` is parallel with `up`, an orthogonal vector is used as the "right" direction
#[inline]
pub fn look_to(&mut self, direction: Vec3, up: Vec3) {
let forward = -direction.try_normalize().unwrap_or(Vec3::Z);
let back = -direction.try_normalize().unwrap_or(Vec3::NEG_Z);
let up = up.try_normalize().unwrap_or(Vec3::Y);
let right = up
.cross(forward)
.cross(back)
.try_normalize()
.unwrap_or_else(|| up.any_orthonormal_vector());
let up = forward.cross(right);
self.rotation = Quat::from_mat3(&Mat3::from_cols(right, up, forward));
let up = back.cross(right);
self.rotation = Quat::from_mat3(&Mat3::from_cols(right, up, back));
}
/// Multiplies `self` with `transform` component by component, returning the

View file

@ -6,10 +6,11 @@ use bevy_a11y::{
accesskit::{NodeBuilder, Rect, Role},
AccessibilityNode,
};
use bevy_app::{App, Plugin, Update};
use bevy_app::{App, Plugin, PostUpdate};
use bevy_ecs::{
prelude::{DetectChanges, Entity},
query::{Changed, Without},
schedule::IntoSystemConfigs,
system::{Commands, Query},
world::Ref,
};
@ -147,8 +148,13 @@ pub(crate) struct AccessibilityPlugin;
impl Plugin for AccessibilityPlugin {
fn build(&self, app: &mut App) {
app.add_systems(
Update,
(calc_bounds, button_changed, image_changed, label_changed),
PostUpdate,
(
calc_bounds.after(bevy_transform::TransformSystem::TransformPropagate),
button_changed,
image_changed,
label_changed,
),
);
}
}

View file

@ -12,11 +12,11 @@ keywords = ["bevy"]
detailed_trace = []
[dependencies]
ahash = "0.7.0"
ahash = "0.8.3"
tracing = { version = "0.1", default-features = false, features = ["std"] }
instant = { version = "0.1", features = ["wasm-bindgen"] }
uuid = { version = "1.1", features = ["v4", "serde"] }
hashbrown = { version = "0.12", features = ["serde"] }
hashbrown = { version = "0.13", features = ["serde"] }
bevy_utils_proc_macros = {version = "0.11.0-dev", path = "macros"}
petgraph = "0.6"
thiserror = "1.0"

View file

@ -21,7 +21,7 @@ pub mod syncunsafecell;
mod default;
mod float_ord;
pub use ahash::AHasher;
pub use ahash::{AHasher, RandomState};
pub use bevy_utils_proc_macros::*;
pub use default::default;
pub use float_ord::*;
@ -32,12 +32,11 @@ pub use thiserror;
pub use tracing;
pub use uuid::Uuid;
use ahash::RandomState;
use hashbrown::hash_map::RawEntryMut;
use std::{
fmt::Debug,
future::Future,
hash::{BuildHasher, Hash, Hasher},
hash::{BuildHasher, BuildHasherDefault, Hash, Hasher},
marker::PhantomData,
mem::ManuallyDrop,
ops::Deref,
@ -48,11 +47,12 @@ use std::{
#[cfg(not(target_arch = "wasm32"))]
pub type BoxedFuture<'a, T> = Pin<Box<dyn Future<Output = T> + Send + 'a>>;
#[allow(missing_docs)]
#[cfg(target_arch = "wasm32")]
pub type BoxedFuture<'a, T> = Pin<Box<dyn Future<Output = T> + 'a>>;
/// A shortcut alias for [`hashbrown::hash_map::Entry`].
pub type Entry<'a, K, V> = hashbrown::hash_map::Entry<'a, K, V, RandomState>;
pub type Entry<'a, K, V> = hashbrown::hash_map::Entry<'a, K, V, BuildHasherDefault<AHasher>>;
/// A hasher builder that will create a fixed hasher.
#[derive(Debug, Clone, Default)]
@ -63,10 +63,13 @@ impl std::hash::BuildHasher for FixedState {
#[inline]
fn build_hasher(&self) -> AHasher {
AHasher::new_with_keys(
0b1001010111101110000001001100010000000011001001101011001001111000,
0b1100111101101011011110001011010100000100001111100011010011010101,
RandomState::with_seeds(
0b10010101111011100000010011000100,
0b00000011001001101011001001111000,
0b11001111011010110111100010110101,
0b00000100001111100011010011010101,
)
.build_hasher()
}
}
@ -74,7 +77,7 @@ impl std::hash::BuildHasher for FixedState {
/// speed keyed hashing algorithm intended for use in in-memory hashmaps.
///
/// aHash is designed for performance and is NOT cryptographically secure.
pub type HashMap<K, V> = hashbrown::HashMap<K, V, RandomState>;
pub type HashMap<K, V> = hashbrown::HashMap<K, V, BuildHasherDefault<AHasher>>;
/// A stable hash map implementing aHash, a high speed keyed hashing algorithm
/// intended for use in in-memory hashmaps.
@ -89,7 +92,7 @@ pub type StableHashMap<K, V> = hashbrown::HashMap<K, V, FixedState>;
/// speed keyed hashing algorithm intended for use in in-memory hashmaps.
///
/// aHash is designed for performance and is NOT cryptographically secure.
pub type HashSet<K> = hashbrown::HashSet<K, RandomState>;
pub type HashSet<K> = hashbrown::HashSet<K, BuildHasherDefault<AHasher>>;
/// A stable hash set implementing aHash, a high speed keyed hashing algorithm
/// intended for use in in-memory hashmaps.

View file

@ -24,9 +24,8 @@ pub struct WindowResized {
pub height: f32,
}
// TODO: This would redraw all windows ? If yes, update docs to reflect this
/// An event that indicates the window should redraw, even if its control flow is set to `Wait` and
/// there have been no window events.
/// An event that indicates all of the application's windows should be redrawn,
/// even if their control flow is set to `Wait` and there have been no window events.
#[derive(Debug, Clone, PartialEq, Eq, Reflect, FromReflect)]
#[reflect(Debug, PartialEq)]
#[cfg_attr(

View file

@ -10,7 +10,7 @@ use bevy_a11y::{
accesskit::{ActionHandler, ActionRequest, NodeBuilder, NodeClassSet, Role, TreeUpdate},
AccessKitEntityExt, AccessibilityNode, AccessibilityRequested, Focus,
};
use bevy_app::{App, Plugin, Update};
use bevy_app::{App, Plugin, PostUpdate};
use bevy_derive::{Deref, DerefMut};
use bevy_ecs::{
prelude::{DetectChanges, Entity, EventReader, EventWriter},
@ -166,7 +166,7 @@ impl Plugin for AccessibilityPlugin {
.init_resource::<WinitActionHandlers>()
.add_event::<ActionRequest>()
.add_systems(
Update,
PostUpdate,
(
handle_window_focus,
window_closed,

View file

@ -400,7 +400,10 @@ fn toggle_tonemapping_method(
*method = Tonemapping::BlenderFilmic;
}
*color_grading = *per_method_settings.settings.get(&method).unwrap();
*color_grading = *per_method_settings
.settings
.get::<Tonemapping>(&method)
.unwrap();
}
#[derive(Resource)]

View file

@ -25,7 +25,7 @@ fn main() {
app.add_plugins(DefaultPlugins.set(WindowPlugin {
primary_window: Some(Window {
present_mode: PresentMode::Immediate,
present_mode: PresentMode::AutoNoVsync,
..default()
}),
..default()

View file

@ -16,7 +16,7 @@ fn main() {
let mut app = App::new();
app.add_plugins(DefaultPlugins.set(WindowPlugin {
primary_window: Some(Window {
present_mode: PresentMode::Immediate,
present_mode: PresentMode::AutoNoVsync,
..default()
}),
..default()