2020-11-13 00:21:48 +00:00
|
|
|
mod error;
|
2020-05-13 20:09:32 +00:00
|
|
|
mod font;
|
2020-06-14 01:53:31 +00:00
|
|
|
mod font_atlas;
|
|
|
|
mod font_atlas_set;
|
2020-06-15 19:47:35 +00:00
|
|
|
mod font_loader;
|
2020-11-13 00:21:48 +00:00
|
|
|
mod glyph_brush;
|
|
|
|
mod pipeline;
|
2020-12-27 19:19:03 +00:00
|
|
|
mod text;
|
|
|
|
mod text2d;
|
2020-05-13 20:09:32 +00:00
|
|
|
|
2020-11-13 00:21:48 +00:00
|
|
|
pub use error::*;
|
2020-05-13 20:09:32 +00:00
|
|
|
pub use font::*;
|
2020-06-14 01:53:31 +00:00
|
|
|
pub use font_atlas::*;
|
|
|
|
pub use font_atlas_set::*;
|
2020-06-15 19:47:35 +00:00
|
|
|
pub use font_loader::*;
|
2020-11-13 00:21:48 +00:00
|
|
|
pub use glyph_brush::*;
|
|
|
|
pub use pipeline::*;
|
2020-12-27 19:19:03 +00:00
|
|
|
pub use text::*;
|
|
|
|
pub use text2d::*;
|
2020-05-16 02:46:09 +00:00
|
|
|
|
2020-07-17 02:34:18 +00:00
|
|
|
pub mod prelude {
|
2021-04-27 18:29:33 +00:00
|
|
|
#[doc(hidden)]
|
2021-12-14 03:58:23 +00:00
|
|
|
pub use crate::{
|
|
|
|
Font, HorizontalAlign, Text, Text2dBundle, TextAlignment, TextError, TextSection,
|
|
|
|
TextStyle, VerticalAlign,
|
|
|
|
};
|
2020-07-17 02:34:18 +00:00
|
|
|
}
|
|
|
|
|
2020-07-17 01:47:51 +00:00
|
|
|
use bevy_app::prelude::*;
|
2020-05-16 02:46:09 +00:00
|
|
|
use bevy_asset::AddAsset;
|
Exclusive Systems Now Implement `System`. Flexible Exclusive System Params (#6083)
# Objective
The [Stageless RFC](https://github.com/bevyengine/rfcs/pull/45) involves allowing exclusive systems to be referenced and ordered relative to parallel systems. We've agreed that unifying systems under `System` is the right move.
This is an alternative to #4166 (see rationale in the comments I left there). Note that this builds on the learnings established there (and borrows some patterns).
## Solution
This unifies parallel and exclusive systems under the shared `System` trait, removing the old `ExclusiveSystem` trait / impls. This is accomplished by adding a new `ExclusiveFunctionSystem` impl similar to `FunctionSystem`. It is backed by `ExclusiveSystemParam`, which is similar to `SystemParam`. There is a new flattened out SystemContainer api (which cuts out a lot of trait and type complexity).
This means you can remove all cases of `exclusive_system()`:
```rust
// before
commands.add_system(some_system.exclusive_system());
// after
commands.add_system(some_system);
```
I've also implemented `ExclusiveSystemParam` for `&mut QueryState` and `&mut SystemState`, which makes this possible in exclusive systems:
```rust
fn some_exclusive_system(
world: &mut World,
transforms: &mut QueryState<&Transform>,
state: &mut SystemState<(Res<Time>, Query<&Player>)>,
) {
for transform in transforms.iter(world) {
println!("{transform:?}");
}
let (time, players) = state.get(world);
for player in players.iter() {
println!("{player:?}");
}
}
```
Note that "exclusive function systems" assume `&mut World` is present (and the first param). I think this is a fair assumption, given that the presence of `&mut World` is what defines the need for an exclusive system.
I added some targeted SystemParam `static` constraints, which removed the need for this:
``` rust
fn some_exclusive_system(state: &mut SystemState<(Res<'static, Time>, Query<&'static Player>)>) {}
```
## Related
- #2923
- #3001
- #3946
## Changelog
- `ExclusiveSystem` trait (and implementations) has been removed in favor of sharing the `System` trait.
- `ExclusiveFunctionSystem` and `ExclusiveSystemParam` were added, enabling flexible exclusive function systems
- `&mut SystemState` and `&mut QueryState` now implement `ExclusiveSystemParam`
- Exclusive and parallel System configuration is now done via a unified `SystemDescriptor`, `IntoSystemDescriptor`, and `SystemContainer` api.
## Migration Guide
Calling `.exclusive_system()` is no longer required (or supported) for converting exclusive system functions to exclusive systems:
```rust
// Old (0.8)
app.add_system(some_exclusive_system.exclusive_system());
// New (0.9)
app.add_system(some_exclusive_system);
```
Converting "normal" parallel systems to exclusive systems is done by calling the exclusive ordering apis:
```rust
// Old (0.8)
app.add_system(some_system.exclusive_system().at_end());
// New (0.9)
app.add_system(some_system.at_end());
```
Query state in exclusive systems can now be cached via ExclusiveSystemParams, which should be preferred for clarity and performance reasons:
```rust
// Old (0.8)
fn some_system(world: &mut World) {
let mut transforms = world.query::<&Transform>();
for transform in transforms.iter(world) {
}
}
// New (0.9)
fn some_system(world: &mut World, transforms: &mut QueryState<&Transform>) {
for transform in transforms.iter(world) {
}
}
```
2022-09-26 23:57:07 +00:00
|
|
|
use bevy_ecs::{schedule::IntoSystemDescriptor, system::Resource};
|
2021-12-14 03:58:23 +00:00
|
|
|
use bevy_render::{RenderApp, RenderStage};
|
|
|
|
use bevy_sprite::SpriteSystem;
|
2022-04-25 14:32:56 +00:00
|
|
|
use bevy_window::ModifiesWindows;
|
2022-09-19 16:12:12 +00:00
|
|
|
use std::num::NonZeroUsize;
|
2020-11-13 00:21:48 +00:00
|
|
|
|
2020-05-16 02:46:09 +00:00
|
|
|
#[derive(Default)]
|
|
|
|
pub struct TextPlugin;
|
|
|
|
|
2022-09-19 16:12:12 +00:00
|
|
|
/// [`TextPlugin`] settings
|
|
|
|
#[derive(Resource)]
|
|
|
|
pub struct TextSettings {
|
|
|
|
/// Maximum number of font atlases supported in a ['FontAtlasSet']
|
|
|
|
pub max_font_atlases: NonZeroUsize,
|
|
|
|
/// Allows font size to be set dynamically exceeding the amount set in max_font_atlases.
|
|
|
|
/// Note each font size has to be generated which can have a strong performance impact.
|
|
|
|
pub allow_dynamic_font_size: bool,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for TextSettings {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self {
|
|
|
|
max_font_atlases: NonZeroUsize::new(16).unwrap(),
|
|
|
|
allow_dynamic_font_size: false,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-08 03:22:17 +00:00
|
|
|
impl Plugin for TextPlugin {
|
2021-07-27 20:21:06 +00:00
|
|
|
fn build(&self, app: &mut App) {
|
2020-05-22 00:21:33 +00:00
|
|
|
app.add_asset::<Font>()
|
2020-06-14 01:53:31 +00:00
|
|
|
.add_asset::<FontAtlasSet>()
|
Add FromReflect trait to convert dynamic types to concrete types (#1395)
Dynamic types (`DynamicStruct`, `DynamicTupleStruct`, `DynamicTuple`, `DynamicList` and `DynamicMap`) are used when deserializing scenes, but currently they can only be applied to existing concrete types. This leads to issues when trying to spawn non trivial deserialized scene.
For components, the issue is avoided by requiring that reflected components implement ~~`FromResources`~~ `FromWorld` (or `Default`). When spawning, a new concrete type is created that way, and the dynamic type is applied to it. Unfortunately, some components don't have any valid implementation of these traits.
In addition, any `Vec` or `HashMap` inside a component will panic when a dynamic type is pushed into it (for instance, `Text` panics when adding a text section).
To solve this issue, this PR adds the `FromReflect` trait that creates a concrete type from a dynamic type that represent it, derives the trait alongside the `Reflect` trait, drops the ~~`FromResources`~~ `FromWorld` requirement on reflected components, ~~and enables reflection for UI and Text bundles~~. It also adds the requirement that fields ignored with `#[reflect(ignore)]` implement `Default`, since we need to initialize them somehow.
Co-authored-by: Carter Anderson <mcanders1@gmail.com>
2021-12-26 18:49:01 +00:00
|
|
|
.register_type::<Text>()
|
register missing reflect types (#5747)
# Objective
- While generating https://github.com/jakobhellermann/bevy_reflect_ts_type_export/blob/main/generated/types.ts, I noticed that some types that implement `Reflect` did not register themselves
- `Viewport` isn't reflect but can be (there's a TODO)
## Solution
- register all reflected types
- derive `Reflect` for `Viewport`
## Changelog
- more types are not registered in the type registry
- remove `Serialize`, `Deserialize` impls from `Viewport`
I also decided to remove the `Serialize, Deserialize` from the `Viewport`, since they were (AFAIK) only used for reflection, which now is done without serde. So this is technically a breaking change for people who relied on that impl directly.
Personally I don't think that every bevy type should implement `Serialize, Deserialize`, as that would lead to a ton of code generation that mostly isn't necessary because we can do the same with `Reflect`, but if this is deemed controversial I can remove it from this PR.
## Migration Guide
- `KeyCode` now implements `Reflect` not as `reflect_value`, but with proper struct reflection. The `Serialize` and `Deserialize` impls were removed, now that they are no longer required for scene serialization.
2022-08-23 17:41:39 +00:00
|
|
|
.register_type::<TextSection>()
|
2022-09-19 22:50:35 +00:00
|
|
|
.register_type::<Vec<TextSection>>()
|
|
|
|
.register_type::<TextStyle>()
|
register missing reflect types (#5747)
# Objective
- While generating https://github.com/jakobhellermann/bevy_reflect_ts_type_export/blob/main/generated/types.ts, I noticed that some types that implement `Reflect` did not register themselves
- `Viewport` isn't reflect but can be (there's a TODO)
## Solution
- register all reflected types
- derive `Reflect` for `Viewport`
## Changelog
- more types are not registered in the type registry
- remove `Serialize`, `Deserialize` impls from `Viewport`
I also decided to remove the `Serialize, Deserialize` from the `Viewport`, since they were (AFAIK) only used for reflection, which now is done without serde. So this is technically a breaking change for people who relied on that impl directly.
Personally I don't think that every bevy type should implement `Serialize, Deserialize`, as that would lead to a ton of code generation that mostly isn't necessary because we can do the same with `Reflect`, but if this is deemed controversial I can remove it from this PR.
## Migration Guide
- `KeyCode` now implements `Reflect` not as `reflect_value`, but with proper struct reflection. The `Serialize` and `Deserialize` impls were removed, now that they are no longer required for scene serialization.
2022-08-23 17:41:39 +00:00
|
|
|
.register_type::<TextAlignment>()
|
2021-12-14 03:58:23 +00:00
|
|
|
.register_type::<VerticalAlign>()
|
|
|
|
.register_type::<HorizontalAlign>()
|
2020-11-13 00:21:48 +00:00
|
|
|
.init_asset_loader::<FontLoader>()
|
2022-09-19 16:12:12 +00:00
|
|
|
.init_resource::<TextSettings>()
|
2022-09-06 20:03:40 +00:00
|
|
|
.insert_resource(TextPipeline::default())
|
2022-05-09 14:18:02 +00:00
|
|
|
.add_system_to_stage(
|
|
|
|
CoreStage::PostUpdate,
|
|
|
|
update_text2d_layout.after(ModifiesWindows),
|
|
|
|
);
|
2021-12-14 03:58:23 +00:00
|
|
|
|
2022-01-08 10:39:43 +00:00
|
|
|
if let Ok(render_app) = app.get_sub_app_mut(RenderApp) {
|
|
|
|
render_app.add_system_to_stage(
|
|
|
|
RenderStage::Extract,
|
|
|
|
extract_text2d_sprite.after(SpriteSystem::ExtractSprites),
|
|
|
|
);
|
|
|
|
}
|
2020-05-16 02:46:09 +00:00
|
|
|
}
|
2020-06-04 03:08:20 +00:00
|
|
|
}
|