Skip to content

Commit

Permalink
Merge branch 'main' into new_specialize
Browse files Browse the repository at this point in the history
  • Loading branch information
ecoskey authored Jan 18, 2025
2 parents 41a98bd + b66c3ce commit ceb777e
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 19 deletions.
7 changes: 6 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -1249,10 +1249,15 @@ description = "Meshlet rendering for dense high-poly scenes (experimental)"
category = "3D Rendering"
wasm = false
setup = [
[
"mkdir",
"-p",
"assets/external/models",
],
[
"curl",
"-o",
"assets/models/bunny.meshlet_mesh",
"assets/external/models/bunny.meshlet_mesh",
"https://raw.githubusercontent.com/JMS55/bevy_meshlet_asset/7a7c14138021f63904b584d5f7b73b695c7f4bbf/bunny.meshlet_mesh",
],
]
Expand Down
2 changes: 2 additions & 0 deletions assets/external/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!.gitignore
12 changes: 12 additions & 0 deletions crates/bevy_ecs/src/schedule/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,12 @@ impl<T> NodeConfigs<T> {
/// [`SystemParam`](crate::system::SystemParam)), or tuples thereof.
/// It is a common entry point for system configurations.
///
/// # Usage notes
///
/// This trait should only be used as a bound for trait implementations or as an
/// argument to a function. If system configs need to be returned from a
/// function or stored somewhere, use [`SystemConfigs`] instead of this trait.
///
/// # Examples
///
/// ```
Expand Down Expand Up @@ -617,6 +623,12 @@ impl SystemSetConfig {
pub type SystemSetConfigs = NodeConfigs<InternedSystemSet>;

/// Types that can convert into a [`SystemSetConfigs`].
///
/// # Usage notes
///
/// This trait should only be used as a bound for trait implementations or as an
/// argument to a function. If system set configs need to be returned from a
/// function or stored somewhere, use [`SystemSetConfigs`] instead of this trait.
#[diagnostic::on_unimplemented(
message = "`{Self}` does not describe a valid system set configuration",
label = "invalid system set configuration"
Expand Down
6 changes: 6 additions & 0 deletions crates/bevy_ecs/src/schedule/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,12 @@ impl SystemSet for AnonymousSet {
}

/// Types that can be converted into a [`SystemSet`].
///
/// # Usage notes
///
/// This trait should only be used as a bound for trait implementations or as an
/// argument to a function. If a system set needs to be returned from a function
/// or stored somewhere, use [`SystemSet`] instead of this trait.
#[diagnostic::on_unimplemented(
message = "`{Self}` is not a system set",
label = "invalid system set"
Expand Down
6 changes: 6 additions & 0 deletions crates/bevy_ecs/src/system/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,12 @@ use crate::world::World;
/// Use this to get a system from a function. Also note that every system implements this trait as
/// well.
///
/// # Usage notes
///
/// This trait should only be used as a bound for trait implementations or as an
/// argument to a function. If a system needs to be returned from a function or
/// stored somewhere, use [`System`] instead of this trait.
///
/// # Examples
///
/// ```
Expand Down
6 changes: 6 additions & 0 deletions crates/bevy_ecs/src/system/observer_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ impl<
}

/// Implemented for systems that convert into [`ObserverSystem`].
///
/// # Usage notes
///
/// This trait should only be used as a bound for trait implementations or as an
/// argument to a function. If an observer system needs to be returned from a
/// function or stored somewhere, use [`ObserverSystem`] instead of this trait.
#[diagnostic::on_unimplemented(
message = "`{Self}` cannot become an `ObserverSystem`",
label = "the trait `IntoObserverSystem` is not implemented",
Expand Down
27 changes: 18 additions & 9 deletions crates/bevy_input_focus/src/directional_navigation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,11 @@ impl DirectionalNavigationMap {
///
/// This is useful for creating a circular navigation path between a set of entities, such as a menu.
pub fn add_looping_edges(&mut self, entities: &[Entity], direction: CompassOctant) {
for i in 0..entities.len() {
let a = entities[i];
let b = entities[(i + 1) % entities.len()];
self.add_symmetrical_edge(a, b, direction);
self.add_edges(entities, direction);
if let Some((first_entity, rest)) = entities.split_first() {
if let Some(last_entity) = rest.last() {
self.add_symmetrical_edge(*last_entity, *first_entity, direction);
}
}
}

Expand Down Expand Up @@ -227,14 +228,17 @@ impl DirectionalNavigation<'_> {
/// If the result was `Ok`, the [`InputFocus`] resource is updated to the new focus as part of this method call.
pub fn navigate(
&mut self,
octant: CompassOctant,
direction: CompassOctant,
) -> Result<Entity, DirectionalNavigationError> {
if let Some(current_focus) = self.focus.0 {
if let Some(new_focus) = self.map.get_neighbor(current_focus, octant) {
if let Some(new_focus) = self.map.get_neighbor(current_focus, direction) {
self.focus.set(new_focus);
Ok(new_focus)
} else {
Err(DirectionalNavigationError::NoNeighborInDirection)
Err(DirectionalNavigationError::NoNeighborInDirection {
current_focus,
direction,
})
}
} else {
Err(DirectionalNavigationError::NoFocus)
Expand All @@ -249,8 +253,13 @@ pub enum DirectionalNavigationError {
#[error("No focusable entity is currently set.")]
NoFocus,
/// No neighbor in the requested direction.
#[error("No neighbor in the requested direction.")]
NoNeighborInDirection,
#[error("No neighbor from {current_focus} in the {direction:?} direction.")]
NoNeighborInDirection {
/// The entity that was the focus when the error occurred.
current_focus: Entity,
/// The direction in which the navigation was attempted.
direction: CompassOctant,
},
}

#[cfg(test)]
Expand Down
9 changes: 9 additions & 0 deletions crates/bevy_state/src/state_scoped.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,15 @@ use crate::state::{StateTransitionEvent, States};
#[cfg_attr(feature = "bevy_reflect", derive(Reflect), reflect(Component))]
pub struct StateScoped<S: States>(pub S);

impl<S> Default for StateScoped<S>
where
S: States + Default,
{
fn default() -> Self {
Self(S::default())
}
}

/// Removes entities marked with [`StateScoped<S>`]
/// when their state no longer matches the world state.
///
Expand Down
6 changes: 3 additions & 3 deletions examples/3d/meshlet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ const ASSET_URL: &str =
"https://raw.githubusercontent.com/JMS55/bevy_meshlet_asset/7a7c14138021f63904b584d5f7b73b695c7f4bbf/bunny.meshlet_mesh";

fn main() -> ExitCode {
if !Path::new("./assets/models/bunny.meshlet_mesh").exists() {
eprintln!("ERROR: Asset at path <bevy>/assets/models/bunny.meshlet_mesh is missing. Please download it from {ASSET_URL}");
if !Path::new("./assets/external/models/bunny.meshlet_mesh").exists() {
eprintln!("ERROR: Asset at path <bevy>/assets/external/models/bunny.meshlet_mesh is missing. Please download it from {ASSET_URL}");
return ExitCode::FAILURE;
}

Expand Down Expand Up @@ -80,7 +80,7 @@ fn setup(
// that has been converted to a [`bevy_pbr::meshlet::MeshletMesh`]
// using [`bevy_pbr::meshlet::MeshletMesh::from_mesh`], which is
// a function only available when the `meshlet_processor` cargo feature is enabled.
let meshlet_mesh_handle = asset_server.load("models/bunny.meshlet_mesh");
let meshlet_mesh_handle = asset_server.load("external/models/bunny.meshlet_mesh");
let debug_material = debug_materials.add(MeshletDebugMaterial::default());

for x in -2..=2 {
Expand Down
13 changes: 7 additions & 6 deletions examples/ui/directional_navigation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
//!
//! In this example, we will set up a simple UI with a grid of buttons that can be navigated using the arrow keys or gamepad input.
use std::time::Duration;

use bevy::{
input_focus::{
directional_navigation::{
Expand Down Expand Up @@ -65,9 +67,7 @@ const FOCUSED_BORDER: Srgba = bevy::color::palettes::tailwind::BLUE_50;
// In a real project, each button would also have its own unique behavior,
// to capture the actual intent of the user
fn universal_button_click_behavior(
// We're using an on-mouse-down trigger to improve responsiveness;
// Clicked is better when you want roll-off cancellation
mut trigger: Trigger<Pointer<Pressed>>,
mut trigger: Trigger<Pointer<Click>>,
mut button_query: Query<(&mut BackgroundColor, &mut ResetTimer)>,
) {
let button_entity = trigger.target();
Expand Down Expand Up @@ -368,7 +368,7 @@ fn highlight_focused_element(
}
}

// By sending a Pointer<Pressed> trigger rather than directly handling button-like interactions,
// By sending a Pointer<Click> trigger rather than directly handling button-like interactions,
// we can unify our handling of pointer and keyboard/gamepad interactions
fn interact_with_focused_button(
action_state: Res<ActionState>,
Expand All @@ -381,7 +381,7 @@ fn interact_with_focused_button(
{
if let Some(focused_entity) = input_focus.0 {
commands.trigger_targets(
Pointer::<Pressed> {
Pointer::<Click> {
target: focused_entity,
// We're pretending that we're a mouse
pointer_id: PointerId::Mouse,
Expand All @@ -395,7 +395,7 @@ fn interact_with_focused_button(
),
position: Vec2::ZERO,
},
event: Pressed {
event: Click {
button: PointerButton::Primary,
// This field isn't used, so we're just setting it to a placeholder value
hit: HitData {
Expand All @@ -404,6 +404,7 @@ fn interact_with_focused_button(
position: None,
normal: None,
},
duration: Duration::from_secs_f32(0.1),
},
},
focused_entity,
Expand Down

0 comments on commit ceb777e

Please sign in to comment.