-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fallible systems #16589
Merged
Merged
Fallible systems #16589
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
b80265b
Allow systems to return results
NthTensor 1d5f7b9
Fix typo
NthTensor f7bbc21
Fix formatting
NthTensor abd9e91
Cleanup pass
NthTensor 63a01b0
Merge branch 'main' into fallible_systems
NthTensor add1247
Replace ok function with const
NthTensor 00df090
Suppress warning about never
NthTensor abe7c3a
Fix tests
NthTensor 311a30f
Fix formatting
NthTensor fa753a7
Move lint allow to module
NthTensor 1136dd1
Fix doclink
NthTensor fde9764
Add note to suppressed warning
NthTensor 2ad1b7b
Update crates/bevy_ecs/src/schedule/executor/mod.rs
NthTensor ecce62b
Update crates/bevy_ecs/src/schedule/executor/mod.rs
NthTensor 0b0d60d
Implement first pass of reviewer feadback
NthTensor 2bffe65
Fix prelude
NthTensor 7e6c84b
Add basic fallible systems example
NthTensor 2e884b5
Fix typo
NthTensor 193684a
Merge branch 'main' into fallible_systems
NthTensor 3636a91
Fix example comments
NthTensor 4786816
Add basic fallible system test
NthTensor 189ee7d
Add docs for system return type
NthTensor 95b64c0
Hide fallible/infallible marker types
NthTensor 151b7ba
Merge remote-tracking branch 'upstream/main' into fallible_systems
NthTensor 5afedeb
Merge branch 'main' into fallible_systems
NthTensor File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
use bevy::math::sampling::UniformMeshSampler; | ||
use bevy::prelude::*; | ||
|
||
use rand::distributions::Distribution; | ||
|
||
fn main() { | ||
App::new() | ||
.add_plugins(DefaultPlugins) | ||
.add_systems(Startup, setup) | ||
.run(); | ||
} | ||
|
||
/// An example of a system that calls several fallible functions with the questionmark operator. | ||
fn setup( | ||
mut commands: Commands, | ||
mut meshes: ResMut<Assets<Mesh>>, | ||
mut materials: ResMut<Assets<StandardMaterial>>, | ||
) -> Result { | ||
let mut rng = rand::thread_rng(); | ||
|
||
// Make a plane for establishing space. | ||
commands.spawn(( | ||
Mesh3d(meshes.add(Plane3d::default().mesh().size(12.0, 12.0))), | ||
MeshMaterial3d(materials.add(Color::srgb(0.3, 0.5, 0.3))), | ||
Transform::from_xyz(0.0, -2.5, 0.0), | ||
)); | ||
|
||
// Spawn a light: | ||
commands.spawn(( | ||
PointLight { | ||
shadows_enabled: true, | ||
..default() | ||
}, | ||
Transform::from_xyz(4.0, 8.0, 4.0), | ||
)); | ||
|
||
// Spawn a camera: | ||
commands.spawn(( | ||
Camera3d::default(), | ||
Transform::from_xyz(-2.0, 3.0, 5.0).looking_at(Vec3::ZERO, Vec3::Y), | ||
)); | ||
|
||
// Create a new sphere mesh: | ||
let mut sphere_mesh = Sphere::new(1.0).mesh().ico(7)?; | ||
sphere_mesh.generate_tangents()?; | ||
|
||
// Spawn the mesh into the scene: | ||
let mut sphere = commands.spawn(( | ||
Mesh3d(meshes.add(sphere_mesh.clone())), | ||
MeshMaterial3d(materials.add(StandardMaterial::default())), | ||
Transform::from_xyz(-1.0, 1.0, 0.0), | ||
)); | ||
|
||
// Generate random sample points: | ||
let triangles = sphere_mesh.triangles()?; | ||
let distribution = UniformMeshSampler::try_new(triangles)?; | ||
|
||
// Setup sample points: | ||
let point_mesh = meshes.add(Sphere::new(0.01).mesh().ico(3)?); | ||
let point_material = materials.add(StandardMaterial { | ||
base_color: Srgba::RED.into(), | ||
emissive: LinearRgba::rgb(1.0, 0.0, 0.0), | ||
..default() | ||
}); | ||
|
||
/// Add sample points as children of the sphere: | ||
for point in distribution.sample_iter(&mut rng).take(10000) { | ||
sphere.with_child(( | ||
Mesh3d(point_mesh.clone()), | ||
MeshMaterial3d(point_material.clone()), | ||
Transform::from_translation(point), | ||
)); | ||
} | ||
|
||
/// Indicate the system completed sucsessfully: | ||
NthTensor marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Ok(()) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What a sight to behold. Once proper (user configurable) handlers are added in a follow-up this will be perfect. Bevy APIs can be simplified and made more reliable without any loss in ergonomics (IMO). Adding
Ok(())
at the end of a system is a small price to pay that (hopefully) Rust will solve on its own (since the issue isn't specific to Bevy)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah :) this example is really just a minimal placeholder. Once we have handlers hooked up, I intend to go through and update all the examples to use this style (where it makes sense).