Skip to content

Commit 6502c58

Browse files
Merge branch 'main' into set-if-differs
2 parents bd1e44b + d478711 commit 6502c58

File tree

99 files changed

+2958
-1063
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+2958
-1063
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ on:
99

1010
env:
1111
CARGO_TERM_COLOR: always
12-
NIGHTLY_TOOLCHAIN: nightly-2022-07-13
12+
NIGHTLY_TOOLCHAIN: nightly
1313

1414
jobs:
1515
build:

CONTRIBUTING.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ PRs are controversial if there is serious design discussion required, or a large
119119
7. Large-scale code reorganization.
120120
8. High levels of technical complexity.
121121
9. Adding a dependency.
122+
10. Touching licensing information (due to the level of precision required).
123+
11. Adding root-level files (due to the high level of visibility).
122124

123125
Finally, changes are "relatively uncontroversial" if they are neither trivial or controversial.
124126
Most PRs should fall into this category.

Cargo.toml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@ members = [
2626
[features]
2727
default = [
2828
"animation",
29+
"bevy_asset",
2930
"bevy_audio",
3031
"bevy_gilrs",
32+
"bevy_scene",
3133
"bevy_winit",
3234
"render",
3335
"png",
@@ -53,13 +55,15 @@ render = [
5355

5456
# Optional bevy crates
5557
bevy_animation = ["bevy_internal/bevy_animation"]
58+
bevy_asset = ["bevy_internal/bevy_asset"]
5659
bevy_audio = ["bevy_internal/bevy_audio"]
5760
bevy_core_pipeline = ["bevy_internal/bevy_core_pipeline"]
5861
bevy_dynamic_plugin = ["bevy_internal/bevy_dynamic_plugin"]
5962
bevy_gilrs = ["bevy_internal/bevy_gilrs"]
6063
bevy_gltf = ["bevy_internal/bevy_gltf"]
6164
bevy_pbr = ["bevy_internal/bevy_pbr"]
6265
bevy_render = ["bevy_internal/bevy_render"]
66+
bevy_scene = ["bevy_internal/bevy_scene"]
6367
bevy_sprite = ["bevy_internal/bevy_sprite"]
6468
bevy_text = ["bevy_internal/bevy_text"]
6569
bevy_ui = ["bevy_internal/bevy_ui"]
@@ -1254,6 +1258,16 @@ description = "Displays many animated sprites in a grid arrangement with slight
12541258
category = "Stress Tests"
12551259
wasm = true
12561260

1261+
[[example]]
1262+
name = "many_buttons"
1263+
path = "examples/stress_tests/many_buttons.rs"
1264+
1265+
[package.metadata.example.many_buttons]
1266+
name = "Many Buttons"
1267+
description = "Test rendering of many UI elements"
1268+
category = "Stress Tests"
1269+
wasm = true
1270+
12571271
[[example]]
12581272
name = "many_cubes"
12591273
path = "examples/stress_tests/many_cubes.rs"
@@ -1524,3 +1538,9 @@ target_sdk_version = 31
15241538
[package.metadata.android.application]
15251539
icon = "@mipmap/ic_launcher"
15261540
label = "Bevy Example"
1541+
1542+
[profile.wasm-release]
1543+
inherits = "release"
1544+
opt-level = "z"
1545+
lto = "fat"
1546+
codegen-units = 1

README.md

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,31 @@ Additionally, we would like to thank the [Amethyst](https://github.com/amethyst/
109109

110110
## License
111111

112-
Bevy is free and open source! All code in this repository is dual-licensed under either:
112+
Bevy is free, open source and permissively licensed!
113+
Except where noted (below and/or in individual files), all code in this repository is dual-licensed under either:
113114

114115
* MIT License ([LICENSE-MIT](LICENSE-MIT) or [http://opensource.org/licenses/MIT](http://opensource.org/licenses/MIT))
115116
* Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or [http://www.apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0))
116117

117-
at your option. This means you can select the license you prefer! This dual-licensing approach is the de-facto standard in the Rust ecosystem and there are [very good reasons](https://github.com/bevyengine/bevy/issues/2373) to include both.
118+
at your option.
119+
This means you can select the license you prefer!
120+
This dual-licensing approach is the de-facto standard in the Rust ecosystem and there are [very good reasons](https://github.com/bevyengine/bevy/issues/2373) to include both.
118121

119-
Unless you explicitly state otherwise, any contribution intentionally submitted
120-
for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any
121-
additional terms or conditions.
122+
Some of the engine's code carries additional copyright notices and license terms due to their external origins.
123+
These are generally BSD-like, but exact details vary by crate:
124+
If the README of a crate contains a 'License' header (or similar), the additional copyright notices and license terms applicable to that crate will be listed.
125+
The above licensing requirement still applies to contributions to those crates, and sections of those crates will carry those license terms.
126+
The [license](https://doc.rust-lang.org/cargo/reference/manifest.html#the-license-and-license-file-fields) field of each crate will also reflect this.
127+
For example, [`bevy_mikktspace`](./crates/bevy_mikktspace/README.md#license-agreement) has code under the Zlib license (as well as a copyright notice when choosing the MIT license).
128+
129+
The [assets](assets) included in this repository (for our [examples](./examples/README.md)) typically fall under different open licenses.
130+
These will not be included in your game (unless copied in by you), and they are not distributed in the published bevy crates.
131+
See [CREDITS.md](CREDITS.md) for the details of the licenses of those files.
132+
133+
### Your contributions
134+
135+
Unless you explicitly state otherwise,
136+
any contribution intentionally submitted for inclusion in the work by you,
137+
as defined in the Apache-2.0 license,
138+
shall be dual licensed as above,
139+
without any additional terms or conditions.

crates/bevy_app/src/app.rs

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@ use std::fmt::Debug;
1515

1616
#[cfg(feature = "trace")]
1717
use bevy_utils::tracing::info_span;
18-
bevy_utils::define_label!(AppLabel);
18+
bevy_utils::define_label!(
19+
/// A strongly-typed class of labels used to identify an [`App`].
20+
AppLabel,
21+
/// A strongly-typed identifier for an [`AppLabel`].
22+
AppLabelId,
23+
);
1924

2025
#[allow(clippy::needless_doctest_main)]
2126
/// A container of app logic and data.
@@ -857,7 +862,14 @@ impl App {
857862
self
858863
}
859864

860-
/// Adds the type `T` to the type registry [`Resource`].
865+
/// Registers the type `T` in the [`TypeRegistry`](bevy_reflect::TypeRegistry) resource,
866+
/// adding reflect data as specified in the [`Reflect`](bevy_reflect::Reflect) derive:
867+
/// ```rust,ignore
868+
/// #[derive(Reflect)]
869+
/// #[reflect(Component, Serialize, Deserialize)] // will register ReflectComponent, ReflectSerialize, ReflectDeserialize
870+
/// ```
871+
///
872+
/// See [`bevy_reflect::TypeRegistry::register`].
861873
#[cfg(feature = "bevy_reflect")]
862874
pub fn register_type<T: bevy_reflect::GetTypeRegistration>(&mut self) -> &mut Self {
863875
{
@@ -867,6 +879,39 @@ impl App {
867879
self
868880
}
869881

882+
/// Adds the type data `D` to type `T` in the [`TypeRegistry`](bevy_reflect::TypeRegistry) resource.
883+
///
884+
/// Most of the time [`App::register_type`] can be used instead to register a type you derived [`Reflect`](bevy_reflect::Reflect) for.
885+
/// However, in cases where you want to add a piece of type data that was not included in the list of `#[reflect(...)]` type data in the derive,
886+
/// or where the type is generic and cannot register e.g. `ReflectSerialize` unconditionally without knowing the specific type parameters,
887+
/// this method can be used to insert additional type data.
888+
///
889+
/// # Example
890+
/// ```rust
891+
/// use bevy_app::App;
892+
/// use bevy_reflect::{ReflectSerialize, ReflectDeserialize};
893+
///
894+
/// App::new()
895+
/// .register_type::<Option<String>>()
896+
/// .register_type_data::<Option<String>, ReflectSerialize>()
897+
/// .register_type_data::<Option<String>, ReflectDeserialize>();
898+
/// ```
899+
///
900+
/// See [`bevy_reflect::TypeRegistry::register_type_data`].
901+
#[cfg(feature = "bevy_reflect")]
902+
pub fn register_type_data<
903+
T: bevy_reflect::Reflect + 'static,
904+
D: bevy_reflect::TypeData + bevy_reflect::FromType<T>,
905+
>(
906+
&mut self,
907+
) -> &mut Self {
908+
{
909+
let registry = self.world.resource_mut::<bevy_reflect::TypeRegistryArc>();
910+
registry.write().register_type_data::<T, D>();
911+
}
912+
self
913+
}
914+
870915
/// Adds an [`App`] as a child of the current one.
871916
///
872917
/// The provided function `f` is called by the [`update`](Self::update) method. The [`World`]

crates/bevy_asset/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ anyhow = "1.0.4"
3030
thiserror = "1.0"
3131
downcast-rs = "1.2.0"
3232
fastrand = "1.7.0"
33-
notify = { version = "=5.0.0-pre.11", optional = true }
33+
notify = { version = "=5.0.0-pre.15", optional = true }
3434
parking_lot = "0.12.1"
3535

3636
[target.'cfg(target_arch = "wasm32")'.dependencies]

crates/bevy_asset/src/asset_server.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ pub struct AssetServerInternal {
8181
/// of the assets it manages and can even reload them from the filesystem with
8282
/// [`AssetServer::watch_for_changes`]!
8383
///
84-
/// The asset server is a _resource_, so in order to accesss it in a system you need a `Res`
84+
/// The asset server is a _resource_, so in order to access it in a system you need a `Res`
8585
/// accessor, like this:
8686
///
8787
/// ```rust,no_run
@@ -256,7 +256,7 @@ impl AssetServer {
256256
/// Gets the overall load state of a group of assets from the provided handles.
257257
///
258258
/// This method will only return [`LoadState::Loaded`] if all assets in the
259-
/// group were loaded succesfully.
259+
/// group were loaded successfully.
260260
pub fn get_group_load_state(&self, handles: impl IntoIterator<Item = HandleId>) -> LoadState {
261261
let mut load_state = LoadState::Loaded;
262262
for handle_id in handles {

crates/bevy_asset/src/debug_asset_server.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ pub(crate) fn sync_debug_assets<T: Asset + Clone>(
116116
/// Uses the return type of the given loader to register the given handle with the appropriate type
117117
/// and load the asset with the given `path` and parent `file_path`.
118118
///
119-
/// If this feels a bit odd ... thats because it is. This was built to improve the UX of the
119+
/// If this feels a bit odd ... that's because it is. This was built to improve the UX of the
120120
/// `load_internal_asset` macro.
121121
pub fn register_handle_with_loader<A: Asset>(
122122
_loader: fn(&'static str) -> A,

crates/bevy_asset/src/io/android_asset_io.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use std::{
1212
/// Implementation details:
1313
///
1414
/// - `load_path` uses the [AssetManager] to load files.
15-
/// - `read_directory` always returns an empty itrator.
15+
/// - `read_directory` always returns an empty iterator.
1616
/// - `get_metadata` will probably return an error.
1717
/// - Watching for changes is not supported. The watcher methods will do nothing.
1818
///

crates/bevy_asset/src/io/wasm_asset_io.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ pub struct WasmAssetIo {
2525
}
2626

2727
impl WasmAssetIo {
28+
/// Creates a new `WasmAssetIo`. The path provided will be used to build URLs to query for assets.
2829
pub fn new<P: AsRef<Path>>(path: P) -> Self {
2930
WasmAssetIo {
3031
root_path: path.as_ref().to_owned(),

crates/bevy_asset/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ pub mod prelude {
3232
pub use crate::{AddAsset, AssetEvent, AssetServer, Assets, Handle, HandleUntyped};
3333
}
3434

35+
pub use anyhow::Error;
3536
pub use asset_server::*;
3637
pub use assets::*;
3738
pub use bevy_utils::BoxedFuture;

crates/bevy_asset/src/loader.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use crate::{
22
path::AssetPath, AssetIo, AssetIoError, AssetMeta, AssetServer, Assets, Handle, HandleId,
33
RefChangeChannel,
44
};
5+
use anyhow::Error;
56
use anyhow::Result;
67
use bevy_ecs::system::{Res, ResMut};
78
use bevy_reflect::{TypeUuid, TypeUuidDynamic};
@@ -20,7 +21,7 @@ pub trait AssetLoader: Send + Sync + 'static {
2021
&'a self,
2122
bytes: &'a [u8],
2223
load_context: &'a mut LoadContext,
23-
) -> BoxedFuture<'a, Result<(), anyhow::Error>>;
24+
) -> BoxedFuture<'a, Result<(), Error>>;
2425

2526
/// Returns a list of extensions supported by this asset loader, without the preceding dot.
2627
fn extensions(&self) -> &[&str];

crates/bevy_audio/src/audio_source.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ impl AssetLoader for AudioLoader {
5757

5858
/// A type implementing this trait can be decoded as a rodio source
5959
pub trait Decodable: Send + Sync + 'static {
60-
/// The decoder that can decode the implemeting type
60+
/// The decoder that can decode the implementing type
6161
type Decoder: rodio::Source + Send + Sync + Iterator<Item = Self::DecoderItem>;
6262
/// A single value given by the decoder
6363
type DecoderItem: rodio::Sample + Send + Sync;

crates/bevy_derive/src/lib.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,14 @@ pub fn derive_enum_variant_meta(input: TokenStream) -> TokenStream {
8080
enum_variant_meta::derive_enum_variant_meta(input)
8181
}
8282

83-
#[proc_macro_derive(AppLabel)]
83+
/// Generates an impl of the `AppLabel` trait.
84+
///
85+
/// This works only for unit structs, or enums with only unit variants.
86+
/// You may force a struct or variant to behave as if it were fieldless with `#[app_label(ignore_fields)]`.
87+
#[proc_macro_derive(AppLabel, attributes(app_label))]
8488
pub fn derive_app_label(input: TokenStream) -> TokenStream {
8589
let input = syn::parse_macro_input!(input as syn::DeriveInput);
8690
let mut trait_path = BevyManifest::default().get_path("bevy_app");
8791
trait_path.segments.push(format_ident!("AppLabel").into());
88-
derive_label(input, &trait_path)
92+
derive_label(input, &trait_path, "app_label")
8993
}

crates/bevy_ecs/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,7 @@ path = "examples/resources.rs"
4141
[[example]]
4242
name = "change_detection"
4343
path = "examples/change_detection.rs"
44+
45+
[[example]]
46+
name = "derive_label"
47+
path = "examples/derive_label.rs"
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
use std::marker::PhantomData;
2+
3+
use bevy_ecs::prelude::*;
4+
5+
fn main() {
6+
// Unit labels are always equal.
7+
assert_eq!(UnitLabel.as_label(), UnitLabel.as_label());
8+
9+
// Enum labels depend on the variant.
10+
assert_eq!(EnumLabel::One.as_label(), EnumLabel::One.as_label());
11+
assert_ne!(EnumLabel::One.as_label(), EnumLabel::Two.as_label());
12+
13+
// Labels annotated with `ignore_fields` ignore their fields.
14+
assert_eq!(WeirdLabel(1).as_label(), WeirdLabel(2).as_label());
15+
16+
// Labels don't depend only on the variant name but on the full type
17+
assert_ne!(
18+
GenericLabel::<f64>::One.as_label(),
19+
GenericLabel::<char>::One.as_label(),
20+
);
21+
}
22+
23+
#[derive(SystemLabel)]
24+
pub struct UnitLabel;
25+
26+
#[derive(SystemLabel)]
27+
pub enum EnumLabel {
28+
One,
29+
Two,
30+
}
31+
32+
#[derive(SystemLabel)]
33+
#[system_label(ignore_fields)]
34+
pub struct WeirdLabel(i32);
35+
36+
#[derive(SystemLabel)]
37+
pub enum GenericLabel<T> {
38+
One,
39+
#[system_label(ignore_fields)]
40+
Two(PhantomData<T>),
41+
}
42+
43+
// FIXME: this should be a compile_fail test
44+
/*#[derive(SystemLabel)]
45+
pub union Foo {
46+
x: i32,
47+
}*/
48+
49+
// FIXME: this should be a compile_fail test
50+
/*#[derive(SystemLabel)]
51+
#[system_label(ignore_fields)]
52+
pub enum BadLabel {
53+
One,
54+
Two,
55+
}*/
56+
57+
// FIXME: this should be a compile_fail test
58+
/*#[derive(SystemLabel)]
59+
pub struct BadLabel2 {
60+
#[system_label(ignore_fields)]
61+
x: (),
62+
}*/

0 commit comments

Comments
 (0)