mirror of
https://github.com/bevyengine/bevy
synced 2024-11-10 07:04:33 +00:00
Add comments to examples and fix example_showcase script timing
This commit is contained in:
parent
67b9d182ed
commit
bd97da3a51
10 changed files with 33 additions and 11 deletions
|
@ -13,6 +13,7 @@ fn main() {
|
|||
.run();
|
||||
}
|
||||
|
||||
// sends MyEvent every second
|
||||
fn event_trigger_system() -> Box<dyn Schedulable> {
|
||||
let mut elapsed = 0.0;
|
||||
SystemBuilder::new("event_trigger")
|
||||
|
@ -30,6 +31,7 @@ fn event_trigger_system() -> Box<dyn Schedulable> {
|
|||
})
|
||||
}
|
||||
|
||||
// prints events as they come in
|
||||
fn event_listener_system(resources: &mut Resources) -> Box<dyn Schedulable> {
|
||||
let mut my_event_reader = resources.get_event_reader::<MyEvent>();
|
||||
SystemBuilder::new("event_listener")
|
||||
|
|
|
@ -12,7 +12,7 @@ use std::time::Duration;
|
|||
// bevy = { version = "0.1.0", default-features = false, features = ["headless"] }
|
||||
|
||||
fn main() {
|
||||
println!("This app runs once:");
|
||||
// this app runs once
|
||||
App::build()
|
||||
.add_plugin(ScheduleRunnerPlugin {
|
||||
run_mode: RunMode::Once,
|
||||
|
@ -20,7 +20,7 @@ fn main() {
|
|||
.add_system(hello_world_system())
|
||||
.run();
|
||||
|
||||
println!("This app loops forever at 60 fps:");
|
||||
// this app loops forever at 60 fps
|
||||
App::build()
|
||||
.add_plugin(ScheduleRunnerPlugin {
|
||||
run_mode: RunMode::Loop {
|
||||
|
|
|
@ -11,6 +11,7 @@ fn main() {
|
|||
.run();
|
||||
}
|
||||
|
||||
/// moves our cube left when the "left" key is pressed. moves it right when the "right" key is pressed
|
||||
pub fn move_on_input_system(resources: &mut Resources) -> Box<dyn Schedulable> {
|
||||
let mut keyboard_input_event_reader = resources.get_event_reader::<KeyboardInput>();
|
||||
let mut moving_left = false;
|
||||
|
@ -54,6 +55,7 @@ pub fn move_on_input_system(resources: &mut Resources) -> Box<dyn Schedulable> {
|
|||
)
|
||||
}
|
||||
|
||||
/// creates a simple scene
|
||||
fn setup(world: &mut World, resources: &mut Resources) {
|
||||
let mut mesh_storage = resources.get_mut::<AssetStorage<Mesh>>().unwrap();
|
||||
let mut material_storage = resources
|
||||
|
|
|
@ -10,6 +10,7 @@ fn main() {
|
|||
.run();
|
||||
}
|
||||
|
||||
/// prints out mouse events as they come in
|
||||
pub fn mouse_input_system(resources: &mut Resources) -> Box<dyn Schedulable> {
|
||||
let mut mouse_button_input_event_reader = resources.get_event_reader::<MouseButtonInput>();
|
||||
let mut mouse_motion_event_reader = resources.get_event_reader::<MouseMotion>();
|
||||
|
|
|
@ -5,6 +5,7 @@ fn main() {
|
|||
}
|
||||
|
||||
fn setup(_world: &mut World, resources: &mut Resources) {
|
||||
// sends out a "CreateWindow" event, which will be received by the windowing backend
|
||||
let mut create_window_events = resources.get_mut::<Events<CreateWindow>>().unwrap();
|
||||
create_window_events.send(CreateWindow {
|
||||
descriptor: WindowDescriptor {
|
||||
|
|
|
@ -10,7 +10,7 @@ fn main() {
|
|||
.run();
|
||||
}
|
||||
|
||||
// rotates the parent, which will result in the child also rotating
|
||||
/// rotates the parent, which will result in the child also rotating
|
||||
fn build_rotator_system() -> Box<dyn Schedulable> {
|
||||
SystemBuilder::new("rotator")
|
||||
.read_resource::<Time>()
|
||||
|
@ -22,6 +22,7 @@ fn build_rotator_system() -> Box<dyn Schedulable> {
|
|||
})
|
||||
}
|
||||
|
||||
/// set up a simple scene with a "parent" cube and a "child" cube
|
||||
fn setup(world: &mut World, resources: &mut Resources) {
|
||||
let mut mesh_storage = resources.get_mut::<AssetStorage<Mesh>>().unwrap();
|
||||
let mut material_storage = resources
|
||||
|
@ -45,7 +46,7 @@ fn setup(world: &mut World, resources: &mut Resources) {
|
|||
})
|
||||
.add(Rotator)
|
||||
.add_children(|builder| {
|
||||
// cube
|
||||
// child cube
|
||||
builder.add_entity(MeshEntity {
|
||||
mesh: cube_handle,
|
||||
material: cube_material_handle,
|
||||
|
|
|
@ -4,23 +4,27 @@ fn main() {
|
|||
App::build().add_default_plugins().setup(setup).run();
|
||||
}
|
||||
|
||||
/// set up a simple scene
|
||||
fn setup(world: &mut World, resources: &mut Resources) {
|
||||
// create a cube and a plane mesh
|
||||
let mut mesh_storage = resources.get_mut::<AssetStorage<Mesh>>().unwrap();
|
||||
let cube_handle = mesh_storage.add(Mesh::load(MeshType::Cube));
|
||||
let plane_handle = mesh_storage.add(Mesh::load(MeshType::Plane { size: 10.0 }));
|
||||
|
||||
// create materials for our cube and plane
|
||||
let mut material_storage = resources
|
||||
.get_mut::<AssetStorage<StandardMaterial>>()
|
||||
.unwrap();
|
||||
let cube_handle = mesh_storage.add(Mesh::load(MeshType::Cube));
|
||||
let plane_handle = mesh_storage.add(Mesh::load(MeshType::Plane { size: 10.0 }));
|
||||
let cube_material_handle = material_storage.add(StandardMaterial {
|
||||
albedo: Color::rgb(0.5, 0.4, 0.3),
|
||||
..Default::default()
|
||||
});
|
||||
|
||||
let plane_material_handle = material_storage.add(StandardMaterial {
|
||||
albedo: Color::rgb(0.1, 0.2, 0.1),
|
||||
..Default::default()
|
||||
});
|
||||
|
||||
// add entities to the world
|
||||
world
|
||||
.build()
|
||||
// plane
|
||||
|
|
|
@ -7,8 +7,11 @@ fn main() {
|
|||
.run();
|
||||
}
|
||||
|
||||
/// Set up a simple scene using a "startup system".
|
||||
/// Startup systems are run exactly once when the app starts up.
|
||||
/// They run right before "normal" systems run.
|
||||
pub fn startup_system() -> Box<dyn Schedulable> {
|
||||
SystemBuilder::new("setup")
|
||||
SystemBuilder::new("startup")
|
||||
.write_resource::<AssetStorage<Mesh>>()
|
||||
.write_resource::<AssetStorage<StandardMaterial>>()
|
||||
.build(move |command_buffer, _, (meshes, materials), _| {
|
||||
|
|
|
@ -4,7 +4,9 @@ fn main() {
|
|||
App::build().add_default_plugins().setup(setup).run();
|
||||
}
|
||||
|
||||
/// sets up a scene with textured entities
|
||||
fn setup(world: &mut World, resources: &mut Resources) {
|
||||
// load a texture
|
||||
let mut texture_storage = resources.get_mut::<AssetStorage<Texture>>().unwrap();
|
||||
let texture = Texture::load(TextureType::Png(
|
||||
concat!(env!("CARGO_MANIFEST_DIR"), "/assets/bevy_logo_dark_big.png").to_string(),
|
||||
|
@ -12,30 +14,35 @@ fn setup(world: &mut World, resources: &mut Resources) {
|
|||
let aspect = texture.height as f32 / texture.width as f32;
|
||||
let texture_handle = texture_storage.add(texture);
|
||||
|
||||
// create a new quad mesh. this is what we will apply the texture to
|
||||
let mut mesh_storage = resources.get_mut::<AssetStorage<Mesh>>().unwrap();
|
||||
let quad_width = 8.0;
|
||||
let quad_handle = mesh_storage.add(Mesh::load(MeshType::Quad {
|
||||
size: Vec2::new(quad_width, quad_width * aspect),
|
||||
}));
|
||||
|
||||
// create materials that use our new texture
|
||||
let mut material_storage = resources
|
||||
.get_mut::<AssetStorage<StandardMaterial>>()
|
||||
.unwrap();
|
||||
|
||||
// this material renders the texture normally
|
||||
let material_handle = material_storage.add(StandardMaterial {
|
||||
albedo_texture: Some(texture_handle),
|
||||
..Default::default()
|
||||
});
|
||||
|
||||
// this material modulates the texture to make it red
|
||||
let modulated_material_handle = material_storage.add(StandardMaterial {
|
||||
albedo: Color::rgba(1.0, 0.0, 0.0, 0.5),
|
||||
albedo_texture: Some(texture_handle),
|
||||
..Default::default()
|
||||
});
|
||||
|
||||
// add entities to the world
|
||||
world
|
||||
.build()
|
||||
// textured quad
|
||||
// textured quad - normal
|
||||
.add_entity(MeshEntity {
|
||||
mesh: quad_handle,
|
||||
material: material_handle,
|
||||
|
@ -43,7 +50,7 @@ fn setup(world: &mut World, resources: &mut Resources) {
|
|||
rotation: Rotation::from_euler_angles(0.0, std::f32::consts::PI / 3.0, 0.0),
|
||||
..Default::default()
|
||||
})
|
||||
// textured quad modulated
|
||||
// textured quad - modulated
|
||||
.add_entity(MeshEntity {
|
||||
mesh: quad_handle,
|
||||
material: modulated_material_handle,
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
#!/bin/bash
|
||||
|
||||
duration='3'
|
||||
duration='2'
|
||||
run_example() {
|
||||
cargo build --example $1
|
||||
timeout "$duration" cargo run --example $1
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue