Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/bevyengine/bevy into intera…
Browse files Browse the repository at this point in the history
…ction-policy
  • Loading branch information
Pietrek14 committed Jul 6, 2023
2 parents ba242a8 + 9655ace commit 2c39e68
Show file tree
Hide file tree
Showing 25 changed files with 223 additions and 153 deletions.
1 change: 1 addition & 0 deletions crates/bevy_animation/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,7 @@ impl Plugin for AnimationPlugin {
app.add_asset::<AnimationClip>()
.register_asset_reflect::<AnimationClip>()
.register_type::<AnimationPlayer>()
.register_type::<PlayingAnimation>()
.add_systems(
PostUpdate,
animation_player.before(TransformSystem::TransformPropagate),
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_ecs/src/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ impl Components {

/// A value that tracks when a system ran relative to other systems.
/// This is used to power change detection.
#[derive(Copy, Clone, Debug)]
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub struct Tick {
tick: u32,
}
Expand Down
1 change: 0 additions & 1 deletion crates/bevy_ecs/src/schedule/graph_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ pub(crate) struct GraphInfo {
pub(crate) sets: Vec<BoxedSystemSet>,
pub(crate) dependencies: Vec<Dependency>,
pub(crate) ambiguous_with: Ambiguity,
pub(crate) base_set: Option<BoxedSystemSet>,
}

/// Converts 2D row-major pair of indices into a 1D array index.
Expand Down
4 changes: 0 additions & 4 deletions crates/bevy_ecs/src/schedule/schedule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -747,10 +747,6 @@ impl ScheduleGraph {
self.check_set(id, &**set)?;
}

if let Some(base_set) = &graph_info.base_set {
self.check_set(id, &**base_set)?;
}

Ok(())
}

Expand Down
11 changes: 5 additions & 6 deletions crates/bevy_gizmos/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
//!
//! See the documentation on [`Gizmos`](crate::gizmos::Gizmos) for more examples.

use std::hash::{Hash, Hasher};
use std::mem;

use bevy_app::{Last, Plugin, Update};
Expand Down Expand Up @@ -52,7 +51,6 @@ use bevy_render::{
Extract, ExtractSchedule, Render, RenderApp, RenderSet,
};
use bevy_transform::components::{GlobalTransform, Transform};
use bevy_utils::AHasher;

pub mod gizmos;

Expand Down Expand Up @@ -235,12 +233,13 @@ fn draw_all_aabbs(
}

fn color_from_entity(entity: Entity) -> Color {
use bevy_utils::RandomState;
const U64_TO_DEGREES: f32 = 360.0 / u64::MAX as f32;
const STATE: RandomState =
RandomState::with_seeds(5952553601252303067, 16866614500153072625, 0, 0);

let mut hasher = AHasher::default();
entity.hash(&mut hasher);

let hue = hasher.finish() as f32 * U64_TO_DEGREES;
let hash = STATE.hash_one(entity);
let hue = hash as f32 * U64_TO_DEGREES;
Color::hsl(hue, 1., 0.5)
}

Expand Down
1 change: 0 additions & 1 deletion crates/bevy_gizmos/src/pipeline_3d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ impl SpecializedRenderPipeline for LineGizmoPipeline {

fn specialize(&self, key: Self::Key) -> RenderPipelineDescriptor {
let mut shader_defs = vec![
"GIZMO_3D".into(),
#[cfg(feature = "webgl")]
"SIXTEEN_BYTE_ALIGNMENT".into(),
];
Expand Down
12 changes: 9 additions & 3 deletions crates/bevy_pbr/src/prepass/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use bevy_app::{Plugin, PreUpdate, Update};
use bevy_app::{Plugin, PreUpdate};
use bevy_asset::{load_internal_asset, AssetServer, Handle, HandleUntyped};
use bevy_core_pipeline::{
prelude::Camera3d,
Expand Down Expand Up @@ -141,9 +141,15 @@ where

if no_prepass_plugin_loaded {
app.insert_resource(AnyPrepassPluginLoaded)
.add_systems(Update, update_previous_view_projections)
// At the start of each frame, last frame's GlobalTransforms become this frame's PreviousGlobalTransforms
.add_systems(PreUpdate, update_mesh_previous_global_transforms);
// and last frame's view projection matrices become this frame's PreviousViewProjections
.add_systems(
PreUpdate,
(
update_mesh_previous_global_transforms,
update_previous_view_projections,
),
);
}

let Ok(render_app) = app.get_sub_app_mut(RenderApp) else {
Expand Down
10 changes: 5 additions & 5 deletions crates/bevy_pbr/src/prepass/prepass.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,18 @@ struct VertexOutput {
#ifdef MORPH_TARGETS
fn morph_vertex(vertex_in: Vertex) -> Vertex {
var vertex = vertex_in;
let weight_count = layer_count();
let weight_count = bevy_pbr::morph::layer_count();
for (var i: u32 = 0u; i < weight_count; i ++) {
let weight = weight_at(i);
let weight = bevy_pbr::morph::weight_at(i);
if weight == 0.0 {
continue;
}
vertex.position += weight * morph(vertex.index, position_offset, i);
vertex.position += weight * bevy_pbr::morph::morph(vertex.index, bevy_pbr::morph::position_offset, i);
#ifdef VERTEX_NORMALS
vertex.normal += weight * morph(vertex.index, normal_offset, i);
vertex.normal += weight * bevy_pbr::morph::morph(vertex.index, bevy_pbr::morph::normal_offset, i);
#endif
#ifdef VERTEX_TANGENTS
vertex.tangent += vec4(weight * morph(vertex.index, tangent_offset, i), 0.0);
vertex.tangent += vec4(weight * bevy_pbr::morph::morph(vertex.index, bevy_pbr::morph::tangent_offset, i), 0.0);
#endif
}
return vertex;
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_pbr/src/prepass/prepass_utils.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ fn prepass_normal(frag_coord: vec4<f32>, sample_index: u32) -> vec3<f32> {
#else
let normal_sample = textureLoad(view_bindings::normal_prepass_texture, vec2<i32>(frag_coord.xy), 0);
#endif // MULTISAMPLED
return normal_sample.xyz * 2.0 - vec3(1.0);
return normalize(normal_sample.xyz * 2.0 - vec3(1.0));
}
#endif // NORMAL_PREPASS

Expand Down
8 changes: 4 additions & 4 deletions crates/bevy_pbr/src/render/pbr.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ fn fragment(
#endif
#ifdef VERTEX_UVS
if ((pbr_bindings::material.flags & pbr_types::STANDARD_MATERIAL_FLAGS_BASE_COLOR_TEXTURE_BIT) != 0u) {
output_color = output_color * textureSampleBias(pbr_bindings::base_color_texture, pbr_bindings::base_color_sampler, in.uv, view.mip_bias);
output_color = output_color * textureSampleBias(pbr_bindings::base_color_texture, pbr_bindings::base_color_sampler, uv, view.mip_bias);
}
#endif

Expand All @@ -74,7 +74,7 @@ fn fragment(
var emissive: vec4<f32> = pbr_bindings::material.emissive;
#ifdef VERTEX_UVS
if ((pbr_bindings::material.flags & pbr_types::STANDARD_MATERIAL_FLAGS_EMISSIVE_TEXTURE_BIT) != 0u) {
emissive = vec4<f32>(emissive.rgb * textureSampleBias(pbr_bindings::emissive_texture, pbr_bindings::emissive_sampler, in.uv, view.mip_bias).rgb, 1.0);
emissive = vec4<f32>(emissive.rgb * textureSampleBias(pbr_bindings::emissive_texture, pbr_bindings::emissive_sampler, uv, view.mip_bias).rgb, 1.0);
}
#endif
pbr_input.material.emissive = emissive;
Expand All @@ -83,7 +83,7 @@ fn fragment(
var perceptual_roughness: f32 = pbr_bindings::material.perceptual_roughness;
#ifdef VERTEX_UVS
if ((pbr_bindings::material.flags & pbr_types::STANDARD_MATERIAL_FLAGS_METALLIC_ROUGHNESS_TEXTURE_BIT) != 0u) {
let metallic_roughness = textureSampleBias(pbr_bindings::metallic_roughness_texture, pbr_bindings::metallic_roughness_sampler, in.uv, view.mip_bias);
let metallic_roughness = textureSampleBias(pbr_bindings::metallic_roughness_texture, pbr_bindings::metallic_roughness_sampler, uv, view.mip_bias);
// Sampling from GLTF standard channels for now
metallic = metallic * metallic_roughness.b;
perceptual_roughness = perceptual_roughness * metallic_roughness.g;
Expand All @@ -96,7 +96,7 @@ fn fragment(
var occlusion: vec3<f32> = vec3(1.0);
#ifdef VERTEX_UVS
if ((pbr_bindings::material.flags & pbr_types::STANDARD_MATERIAL_FLAGS_OCCLUSION_TEXTURE_BIT) != 0u) {
occlusion = vec3(textureSampleBias(pbr_bindings::occlusion_texture, pbr_bindings::occlusion_sampler, in.uv, view.mip_bias).r);
occlusion = vec3(textureSampleBias(pbr_bindings::occlusion_texture, pbr_bindings::occlusion_sampler, uv, view.mip_bias).r);
}
#endif
#ifdef SCREEN_SPACE_AMBIENT_OCCLUSION
Expand Down
1 change: 0 additions & 1 deletion crates/bevy_render/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ serde = { version = "1", features = ["derive"] }
bitflags = "2.3"
bytemuck = { version = "1.5", features = ["derive"] }
smallvec = { version = "1.6", features = ["union", "const_generics"] }
once_cell = "1.4.1" # TODO: replace once_cell with std equivalent if/when this lands: https://github.com/rust-lang/rfcs/pull/2788
downcast-rs = "1.2.0"
thread_local = "1.1"
thiserror = "1.0"
Expand Down
1 change: 0 additions & 1 deletion crates/bevy_render/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ pub mod prelude {

use bevy_window::{PrimaryWindow, RawHandleWrapper};
use globals::GlobalsPlugin;
pub use once_cell;
use renderer::{RenderAdapter, RenderAdapterInfo, RenderDevice, RenderQueue};
use wgpu::Instance;

Expand Down
12 changes: 8 additions & 4 deletions crates/bevy_ui/src/focus.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{camera_config::UiCameraConfig, CalculatedClip, Node, UiStack};
use crate::{camera_config::UiCameraConfig, CalculatedClip, Node, UiScale, UiStack};
use bevy_derive::{Deref, DerefMut};
use bevy_ecs::{
change_detection::DetectChangesMut,
Expand Down Expand Up @@ -206,6 +206,7 @@ pub fn ui_focus_system(
windows: Query<&Window>,
mouse_button_input: Res<Input<MouseButton>>,
touches_input: Res<Touches>,
ui_scale: Res<UiScale>,
ui_stack: Res<UiStack>,
mut node_query: Query<NodeQuery>,
primary_window: Query<Entity, With<PrimaryWindow>>,
Expand Down Expand Up @@ -255,7 +256,10 @@ pub fn ui_focus_system(
.ok()
.and_then(|window| window.cursor_position())
})
.or_else(|| touches_input.first_pressed_position());
.or_else(|| touches_input.first_pressed_position())
// The cursor position returned by `Window` only takes into account the window scale factor and not `UiScale`.
// To convert the cursor position to logical UI viewport coordinates we have to divide it by `UiScale`.
.map(|cursor_position| cursor_position / ui_scale.scale as f32);

// prepare an iterator that contains all the nodes that have the cursor in their rect,
// from the top node to the bottom one. this will also reset the interaction to `None`
Expand Down Expand Up @@ -336,7 +340,7 @@ pub fn ui_focus_system(
.collect::<Vec<Entity>>()
.into_iter();

// set Clicked or Hovered on top nodes. as soon as a node with a `Block` focus policy is detected,
// set Pressed or Hovered on top nodes. as soon as a node with a `Block` focus policy is detected,
// the iteration will stop on it because it "captures" the interaction.
let mut iter = node_query.iter_many_mut(hovered_nodes.by_ref());
while let Some(node) = iter.fetch_next() {
Expand All @@ -355,7 +359,7 @@ pub fn ui_focus_system(
FocusPolicy::Block => {
break;
}
FocusPolicy::Pass => { /* allow the next node to be hovered/clicked */ }
FocusPolicy::Pass => { /* allow the next node to be hovered/pressed */ }
}
}
// reset `Interaction` for the remaining lower nodes to `None`. those are the nodes that remain in
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_ui/src/layout/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ pub fn ui_layout_system(
// compute layouts
ui_surface.compute_window_layouts();

let physical_to_logical_factor = 1. / logical_to_physical_factor;
let physical_to_logical_factor = 1. / scale_factor;

let to_logical = |v| (physical_to_logical_factor * v as f64) as f32;

Expand Down
27 changes: 11 additions & 16 deletions crates/bevy_ui/src/measurement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use bevy_math::Vec2;
use bevy_reflect::Reflect;
use std::fmt::Formatter;
pub use taffy::style::AvailableSpace;
use taffy::{node::MeasureFunc, prelude::Size as TaffySize};

impl std::fmt::Debug for ContentSize {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
Expand Down Expand Up @@ -50,33 +51,27 @@ impl Measure for FixedMeasure {
pub struct ContentSize {
/// The `Measure` used to compute the intrinsic size
#[reflect(ignore)]
pub(crate) measure_func: Option<taffy::node::MeasureFunc>,
pub(crate) measure_func: Option<MeasureFunc>,
}

impl ContentSize {
/// Set a `Measure` for this function
pub fn set(&mut self, measure: impl Measure) {
let measure_func =
move |size: taffy::prelude::Size<Option<f32>>,
available: taffy::prelude::Size<AvailableSpace>| {
let size =
measure.measure(size.width, size.height, available.width, available.height);
taffy::prelude::Size {
width: size.x,
height: size.y,
}
};
self.measure_func = Some(taffy::node::MeasureFunc::Boxed(Box::new(measure_func)));
let measure_func = move |size: TaffySize<_>, available: TaffySize<_>| {
let size = measure.measure(size.width, size.height, available.width, available.height);
TaffySize {
width: size.x,
height: size.y,
}
};
self.measure_func = Some(MeasureFunc::Boxed(Box::new(measure_func)));
}
}

#[allow(clippy::derivable_impls)]
impl Default for ContentSize {
fn default() -> Self {
Self {
measure_func: Some(taffy::node::MeasureFunc::Raw(|_, _| {
taffy::prelude::Size::ZERO
})),
measure_func: Some(MeasureFunc::Raw(|_, _| TaffySize::ZERO)),
}
}
}
Loading

0 comments on commit 2c39e68

Please sign in to comment.