2024-11-16 21:33:37 +00:00
|
|
|
//! This example shows how to configure the `ScheduleRunnerPlugin` to run your
|
|
|
|
//! application without windowing. You can completely remove rendering / windowing
|
|
|
|
//! Plugin code from bevy by making your import look like this in your Cargo.toml.
|
2022-05-16 13:53:20 +00:00
|
|
|
//!
|
Fix intra-doc link warnings (#10445)
When `cargo doc -Zunstable-options -Zrustdoc-scrape-examples` (trying to
figure out why it doesn't work with bevy), I had the following warnings:
```
warning: unresolved link to `Quad`
--> examples/2d/mesh2d.rs:1:66
|
1 | //! Shows how to render a polygonal [`Mesh`], generated from a [`Quad`] primitive, in a 2D scene.
| ^^^^ no item named `Quad` in scope
|
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
= note: `#[warn(rustdoc::broken_intra_doc_links)]` on by default
warning: `bevy` (example "mesh2d") generated 1 warning
warning: unresolved link to `update_weights`
--> examples/animation/morph_targets.rs:6:17
|
6 | //! See the [`update_weights`] system for details.
| ^^^^^^^^^^^^^^ no item named `update_weights` in scope
|
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
= note: `#[warn(rustdoc::broken_intra_doc_links)]` on by default
warning: public documentation for `morph_targets` links to private item `name_morphs`
--> examples/animation/morph_targets.rs:7:43
|
7 | //! - How to read morph target names in [`name_morphs`].
| ^^^^^^^^^^^ this item is private
|
= note: this link will resolve properly if you pass `--document-private-items`
= note: `#[warn(rustdoc::private_intra_doc_links)]` on by default
warning: public documentation for `morph_targets` links to private item `setup_animations`
--> examples/animation/morph_targets.rs:8:48
|
8 | //! - How to play morph target animations in [`setup_animations`].
| ^^^^^^^^^^^^^^^^ this item is private
|
= note: this link will resolve properly if you pass `--document-private-items`
warning: `bevy` (example "morph_targets") generated 3 warnings
warning: unresolved link to `Quad`
--> examples/2d/mesh2d_vertex_color_texture.rs:1:66
|
1 | //! Shows how to render a polygonal [`Mesh`], generated from a [`Quad`] primitive, in a 2D scene.
| ^^^^ no item named `Quad` in scope
|
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
= note: `#[warn(rustdoc::broken_intra_doc_links)]` on by default
warning: `bevy` (example "mesh2d_vertex_color_texture") generated 1 warning
warning: unresolved link to `UIScale`
--> examples/ui/ui_scaling.rs:1:36
|
1 | //! This example illustrates the [`UIScale`] resource from `bevy_ui`.
| ^^^^^^^ no item named `UIScale` in scope
|
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
= note: `#[warn(rustdoc::broken_intra_doc_links)]` on by default
warning: `bevy` (example "ui_scaling") generated 1 warning
warning: unresolved link to `dependencies`
--> examples/app/headless.rs:5:6
|
5 | //! [dependencies]
| ^^^^^^^^^^^^ no item named `dependencies` in scope
|
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
= note: `#[warn(rustdoc::broken_intra_doc_links)]` on by default
warning: `bevy` (example "headless") generated 1 warning
warning: unresolved link to `Material2d`
--> examples/2d/mesh2d_manual.rs:3:26
|
3 | //! It doesn't use the [`Material2d`] abstraction, but changes the vertex buffer to include verte...
| ^^^^^^^^^^ no item named `Material2d` in scope
|
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
= note: `#[warn(rustdoc::broken_intra_doc_links)]` on by default
warning: `bevy` (example "mesh2d_manual") generated 1 warning
```
2023-11-08 14:33:46 +00:00
|
|
|
//! ```toml
|
2022-05-16 13:53:20 +00:00
|
|
|
//! [dependencies]
|
|
|
|
//! bevy = { version = "*", default-features = false }
|
|
|
|
//! # replace "*" with the most recent version of bevy
|
Fix intra-doc link warnings (#10445)
When `cargo doc -Zunstable-options -Zrustdoc-scrape-examples` (trying to
figure out why it doesn't work with bevy), I had the following warnings:
```
warning: unresolved link to `Quad`
--> examples/2d/mesh2d.rs:1:66
|
1 | //! Shows how to render a polygonal [`Mesh`], generated from a [`Quad`] primitive, in a 2D scene.
| ^^^^ no item named `Quad` in scope
|
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
= note: `#[warn(rustdoc::broken_intra_doc_links)]` on by default
warning: `bevy` (example "mesh2d") generated 1 warning
warning: unresolved link to `update_weights`
--> examples/animation/morph_targets.rs:6:17
|
6 | //! See the [`update_weights`] system for details.
| ^^^^^^^^^^^^^^ no item named `update_weights` in scope
|
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
= note: `#[warn(rustdoc::broken_intra_doc_links)]` on by default
warning: public documentation for `morph_targets` links to private item `name_morphs`
--> examples/animation/morph_targets.rs:7:43
|
7 | //! - How to read morph target names in [`name_morphs`].
| ^^^^^^^^^^^ this item is private
|
= note: this link will resolve properly if you pass `--document-private-items`
= note: `#[warn(rustdoc::private_intra_doc_links)]` on by default
warning: public documentation for `morph_targets` links to private item `setup_animations`
--> examples/animation/morph_targets.rs:8:48
|
8 | //! - How to play morph target animations in [`setup_animations`].
| ^^^^^^^^^^^^^^^^ this item is private
|
= note: this link will resolve properly if you pass `--document-private-items`
warning: `bevy` (example "morph_targets") generated 3 warnings
warning: unresolved link to `Quad`
--> examples/2d/mesh2d_vertex_color_texture.rs:1:66
|
1 | //! Shows how to render a polygonal [`Mesh`], generated from a [`Quad`] primitive, in a 2D scene.
| ^^^^ no item named `Quad` in scope
|
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
= note: `#[warn(rustdoc::broken_intra_doc_links)]` on by default
warning: `bevy` (example "mesh2d_vertex_color_texture") generated 1 warning
warning: unresolved link to `UIScale`
--> examples/ui/ui_scaling.rs:1:36
|
1 | //! This example illustrates the [`UIScale`] resource from `bevy_ui`.
| ^^^^^^^ no item named `UIScale` in scope
|
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
= note: `#[warn(rustdoc::broken_intra_doc_links)]` on by default
warning: `bevy` (example "ui_scaling") generated 1 warning
warning: unresolved link to `dependencies`
--> examples/app/headless.rs:5:6
|
5 | //! [dependencies]
| ^^^^^^^^^^^^ no item named `dependencies` in scope
|
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
= note: `#[warn(rustdoc::broken_intra_doc_links)]` on by default
warning: `bevy` (example "headless") generated 1 warning
warning: unresolved link to `Material2d`
--> examples/2d/mesh2d_manual.rs:3:26
|
3 | //! It doesn't use the [`Material2d`] abstraction, but changes the vertex buffer to include verte...
| ^^^^^^^^^^ no item named `Material2d` in scope
|
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
= note: `#[warn(rustdoc::broken_intra_doc_links)]` on by default
warning: `bevy` (example "mesh2d_manual") generated 1 warning
```
2023-11-08 14:33:46 +00:00
|
|
|
//! ```
|
2024-11-16 21:33:37 +00:00
|
|
|
//!
|
|
|
|
//! And then enabling the features you need.
|
|
|
|
//! See the full list: <https://docs.rs/bevy/latest/bevy/#cargo-features>
|
2024-09-19 16:44:43 +00:00
|
|
|
use bevy::{app::ScheduleRunnerPlugin, log::LogPlugin, prelude::*, utils::Duration};
|
2020-04-07 00:03:21 +00:00
|
|
|
|
2020-03-30 18:52:33 +00:00
|
|
|
fn main() {
|
2024-11-16 21:33:37 +00:00
|
|
|
if cfg!(feature = "bevy_window") {
|
|
|
|
println!("This example is running with the bevy_window feature enabled and will not run headless.");
|
|
|
|
println!("Disable the default features and rerun the example to run headless.");
|
|
|
|
println!("To do so, run:");
|
|
|
|
println!();
|
|
|
|
println!(" cargo run --example headless --no-default-features");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-05-10 16:46:21 +00:00
|
|
|
// This app runs once
|
2021-07-27 20:21:06 +00:00
|
|
|
App::new()
|
2024-11-16 21:33:37 +00:00
|
|
|
.add_plugins(DefaultPlugins.set(ScheduleRunnerPlugin::run_once()))
|
2023-03-18 01:45:34 +00:00
|
|
|
.add_systems(Update, hello_world_system)
|
2020-03-30 18:52:33 +00:00
|
|
|
.run();
|
|
|
|
|
2023-05-10 16:46:21 +00:00
|
|
|
// This app loops forever at 60 fps
|
2021-07-27 20:21:06 +00:00
|
|
|
App::new()
|
2023-05-10 16:46:21 +00:00
|
|
|
.add_plugins(
|
2024-11-16 21:33:37 +00:00
|
|
|
DefaultPlugins
|
2024-09-19 16:44:43 +00:00
|
|
|
.set(ScheduleRunnerPlugin::run_loop(Duration::from_secs_f64(
|
|
|
|
1.0 / 60.0,
|
|
|
|
)))
|
|
|
|
// The log and ctrl+c plugin can only be registered once globally,
|
|
|
|
// which means we need to disable it here, because it was already registered with the
|
|
|
|
// app that runs once.
|
|
|
|
.disable::<LogPlugin>(),
|
2023-05-10 16:46:21 +00:00
|
|
|
)
|
2023-03-18 01:45:34 +00:00
|
|
|
.add_systems(Update, counter)
|
2020-03-30 18:52:33 +00:00
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
2020-04-30 20:52:11 +00:00
|
|
|
fn hello_world_system() {
|
2020-04-30 17:42:22 +00:00
|
|
|
println!("hello world");
|
2020-03-30 18:52:33 +00:00
|
|
|
}
|
2020-05-01 20:55:07 +00:00
|
|
|
|
2020-09-10 19:56:37 +00:00
|
|
|
fn counter(mut state: Local<CounterState>) {
|
|
|
|
if state.count % 60 == 0 {
|
|
|
|
println!("{}", state.count);
|
|
|
|
}
|
|
|
|
state.count += 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Default)]
|
|
|
|
struct CounterState {
|
|
|
|
count: u32,
|
|
|
|
}
|