Commit graph

2341 commits

Author SHA1 Message Date
Jakob Hellermann
66b517ef81 fix shader compilation error reporting for non-wgsl shaders (#3441)
in #3289 I accidentally only logged errors for wgsl shaders, this PR expands the error reporting the the other supported shader types.
2021-12-29 21:04:27 +00:00
Jonathan Cornaz
d07c8a8fa7 Implement ReflectValue serialization for Duration (#3318)
# Objective

Resolves #3277 

Currenty if we try to serialize a scene that contains a `Duration` (which is very common, since `Timer` contains one), we get an error saying:

> Type 'core::time::Duration' does not support ReflectValue serialization


## Solution

Let `Duration` implement `SerializeValue`.



Co-authored-by: Jonathan Cornaz <jcornaz@users.noreply.github.com>
2021-12-29 21:04:26 +00:00
David Sugar
8a8293b266 Renamed Entity::new to Entity::from_raw (#3465)
# Objective

- Rename `Entity::new(id: u32)` to `Entity::from_raw(id: u32)`.
- Add further documentation.
- fixes #3108

## Solution

- Renamed `Entity::new(id: u32)` to `Entity::from_raw(id: u32)`.
- Docs extended.

I derived the examples from the discussion of issue #3108 .

The [first case](https://github.com/bevyengine/bevy/issues/3108#issuecomment-966669781) mentioned in the linked issue is quite obvious but the [second one](https://github.com/bevyengine/bevy/issues/3108#issuecomment-967093902) probably needs further explanation.


Co-authored-by: r4gus <david@thesugar.de>
2021-12-29 20:49:00 +00:00
Michael Dorst
fd743ec57f Fix doc_markdown lints in bevy_pbr (#3477)
#3457 adds the `doc_markdown` clippy lint, which checks doc comments to make sure code identifiers are escaped with backticks. This causes a lot of lint errors, so this is one of a number of PR's that will fix those lint errors one crate at a time.

This PR fixes lints in the `bevy_pbr` crate.
2021-12-29 19:04:18 +00:00
Michael Dorst
455ab65bce Fix doc_markdown lints in bevy_sprite (#3480)
#3457 adds the `doc_markdown` clippy lint, which checks doc comments to make sure code identifiers are escaped with backticks. This causes a lot of lint errors, so this is one of a number of PR's that will fix those lint errors one crate at a time.

This PR fixes lints in the `bevy_sprite` crate.
2021-12-29 18:49:43 +00:00
Michael Dorst
608e63a5bc Fix doc_markdown lints in bevy_audio (#3469)
#3457 adds the `doc_markdown` clippy lint, which checks doc comments to make sure code identifiers are escaped with backticks. This causes a lot of lint errors, so this is one of a number of PR's that will fix those lint errors one crate at a time.

This PR fixes lints in the `bevy_audio` crate.
2021-12-29 17:52:42 +00:00
Michael Dorst
32d88c7d23 Fix doc_markdown lints in bevy_asset (#3468)
#3457 adds the `doc_markdown` clippy lint, which checks doc comments to make sure code identifiers are escaped with backticks. This causes a lot of lint errors, so this is one of a number of PR's that will fix those lint errors one crate at a time.

This PR fixes lints in the `bevy_asset` crate.
2021-12-29 17:52:39 +00:00
Michael Dorst
b32770d303 Fix doc_markdown lints in bevy_tasks (#3481)
#3457 adds the `doc_markdown` clippy lint, which checks doc comments to make sure code identifiers are escaped with backticks. This causes a lot of lint errors, so this is one of a number of PR's that will fix those lint errors one crate at a time.

This PR fixes lints in the `bevy_tasks` crate.
2021-12-29 17:38:13 +00:00
Michael Dorst
b1e4984c55 Fix doc_markdown lints in bevy_reflect (#3478)
#3457 adds the `doc_markdown` clippy lint, which checks doc comments to make sure code identifiers are escaped with backticks. This causes a lot of lint errors, so this is one of a number of PR's that will fix those lint errors one crate at a time.

This PR fixes lints in the `bevy_reflect` crate.
2021-12-29 17:38:12 +00:00
Michael Dorst
a90c080659 Fix doc_markdown lints in bevy_log (#3476)
#3457 adds the `doc_markdown` clippy lint, which checks doc comments to make sure code identifiers are escaped with backticks. This causes a lot of lint errors, so this is one of a number of PR's that will fix those lint errors one crate at a time.

This PR fixes lints in the `bevy_log` crate.
2021-12-29 17:38:11 +00:00
Michael Dorst
8aff7262d6 Fix doc_markdown lints in bevy_input (#3475)
#3457 adds the `doc_markdown` clippy lint, which checks doc comments to make sure code identifiers are escaped with backticks. This causes a lot of lint errors, so this is one of a number of PR's that will fix those lint errors one crate at a time.

This PR fixes lints in the `bevy_input` crate.
2021-12-29 17:38:10 +00:00
Michael Dorst
2790b9d240 Fix doc_markdown lints in bevy_gltf (#3474)
#3457 adds the `doc_markdown` clippy lint, which checks doc comments to make sure code identifiers are escaped with backticks. This causes a lot of lint errors, so this is one of a number of PR's that will fix those lint errors one crate at a time.

This PR fixes lints in the `bevy_gltf` crate.
2021-12-29 17:38:09 +00:00
Michael Dorst
b65a1cadb7 Fix doc_markdown lints in bevy_diagnostic (#3472)
#3457 adds the `doc_markdown` clippy lint, which checks doc comments to make sure code identifiers are escaped with backticks. This causes a lot of lint errors, so this is one of a number of PR's that will fix those lint errors one crate at a time.

This PR fixes lints in the `bevy_diagnostic` crate.
2021-12-29 17:38:08 +00:00
Michael Dorst
e6bce74220 Fix doc_markdown lints in examples (#3486)
#3457 adds the `doc_markdown` clippy lint, which checks doc comments to make sure code identifiers are escaped with backticks. This causes a lot of lint errors, so this is one of a number of PR's that will fix those lint errors one crate at a time.

This PR fixes lints in the `examples` folder.
2021-12-29 17:25:34 +00:00
davier
601cc0cbe3 bevy_ui: Check clip when handling interactions (#3461)
# Objective

Fix a bug: UI nodes that are clipped could still be interacted with in the clipped area.

## Solution

Clip the position calculation in `ui_focus_system`
2021-12-28 20:47:45 +00:00
David Sugar
3a9d5a63c9 bevy::scene::Entity renamed to bevy::scene::DynamicEntity. (#3448)
Basic documentation added to bevy::scene::DynamicEntity and bevy::scene::DynamicScene.

# Objective

- Rename bevy::scene::Entity to bevy::scene::DynamicEntity
- fixes #3233

## Solution

- Renamed the struct as requested.
- Added basic documentation.

Co-authored-by: r4gus <david@thesugar.de>
2021-12-27 21:24:18 +00:00
davier
959a845704 bevy_ui: register Overflow type (#3443)
I forgot to register the new `Overflow` type in #3296.
2021-12-27 19:46:25 +00:00
François
f3b053d11f crevice derive macro: fix path to render_resource when importing from bevy (#3438)
# Objective

- Fix #3436 

## Solution

- Do not add twice `render_resource` when coming from `bevy`


Co-authored-by: François <8672791+mockersf@users.noreply.github.com>
2021-12-26 19:04:02 +00:00
davier
06d9384447 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
François
585d0b8467 remove some mut in queries (#3437)
# Objective

- While reading code, found some queries that are `mut` and not used as such

## Solution

- Remove `mut` when possible


Co-authored-by: François <8672791+mockersf@users.noreply.github.com>
2021-12-26 05:39:46 +00:00
Carter Anderson
963e2f08a2 Materials and MaterialPlugin (#3428)
This adds "high level" `Material` and `SpecializedMaterial` traits, which can be used with a `MaterialPlugin<T: SpecializedMaterial>`. `MaterialPlugin` automatically registers the appropriate resources, draw functions, and queue systems. The `Material` trait is simpler, and should cover most use cases. `SpecializedMaterial` is like `Material`, but it also requires defining a "specialization key" (see #3031). `Material` has a trivial blanket impl of `SpecializedMaterial`, which allows us to use the same types + functions for both.

This makes defining custom 3d materials much simpler (see the `shader_material` example diff) and ensures consistent behavior across all 3d materials (both built in and custom). I ported the built in `StandardMaterial` to `MaterialPlugin`. There is also a new `MaterialMeshBundle<T: SpecializedMaterial>`, which `PbrBundle` aliases to.
2021-12-25 21:45:43 +00:00
François
22c665fa39 re-export BufferBinding and BufferDescriptor (#3429)
# Objective

- I want to port `bevy_egui` to Bevy main and only reuse re-exports from Bevy

## Solution

- Add exports for `BufferBinding` and `BufferDescriptor`


Co-authored-by: François <8672791+mockersf@users.noreply.github.com>
2021-12-24 16:53:49 +00:00
davier
76ec709ede Add Visibility component to UI (#3426)
# Objective

Fixes #3422 

## Solution

Adds the existing `Visibility` component to UI bundles and checks for it in the extract phase of the render app.

The `ComputedVisibility` component was not added. I don't think the UI camera needs frustum culling, but having `RenderLayers` work may be desirable. However I think we would need to change `check_visibility()` to differentiate between 2d, 3d and UI entities.
2021-12-24 07:10:12 +00:00
Jakob Hellermann
adb3ad399c make sub_app return an &App and add sub_app_mut() -> &mut App (#3309)
It's sometimes useful to have a reference to an app a sub app at the same time, which is only possible with an immutable reference.
2021-12-24 06:57:30 +00:00
François
5d5d7833f0 fix parenting of scenes (#2410)
# Objective

Fix #2406 

Scene parenting was not done completely, leaving the hierarchy maintenance to the standard system. As scene spawning happens in stage `PreUpdate` and hierarchy maintenance in stage `PostUpdate`, this left the scene in an invalid state parent wise for part of a frame

## Solution

Also add/update the `Children` component when spawning the scene.

I kept the `Children` component as a `SmallVec`, it could be moved to an `HashSet` to guarantee uniqueness


Co-authored-by: François <8672791+mockersf@users.noreply.github.com>
2021-12-24 06:57:28 +00:00
Carter Anderson
08b5234582 Disable nightly rust checks for bors (#3427)
This is a temporary measure while we wait for https://github.com/rust-lang/rust/issues/92163 to be resolved.
2021-12-24 01:11:51 +00:00
François
79d36e7c28 Prepare crevice for vendored release (#3394)
# Objective

- Our crevice is still called "crevice", which we can't use for a release
- Users would need to use our "crevice" directly to be able to use the derive macro

## Solution

- Rename crevice to bevy_crevice, and crevice-derive to bevy-crevice-derive
- Re-export it from bevy_render, and use it from bevy_render everywhere
- Fix derive macro to work either from bevy_render, from bevy_crevice, or from bevy

## Remaining

- It is currently re-exported as `bevy::render::bevy_crevice`, is it the path we want?
- After a brief suggestion to Cart, I changed the version to follow Bevy version instead of crevice, do we want that?
- Crevice README.md need to be updated
- in the `Cargo.toml`, there are a few things to change. How do we want to change them? How do we keep attributions to original Crevice?
```
authors = ["Lucien Greathouse <me@lpghatguy.com>"]
documentation = "https://docs.rs/crevice"
homepage = "https://github.com/LPGhatguy/crevice"
repository = "https://github.com/LPGhatguy/crevice"
```


Co-authored-by: François <8672791+mockersf@users.noreply.github.com>
Co-authored-by: Carter Anderson <mcanders1@gmail.com>
2021-12-23 22:49:12 +00:00
François
aeba9faf04 use ogg by default instead of mp3 (#3421)
# Objective

- mp3 feature of rodio has dependencies that are not maintained with security issues
- mp3 feature of rodio doesn't build in wasm
- mp3 feature of rodio uses internal memory allocation that cause rejection from Apple appstore

## Solution

- Use vorbis instead of mp3 by default


Co-authored-by: François <8672791+mockersf@users.noreply.github.com>
2021-12-23 19:19:15 +00:00
Jakob Hellermann
c6d4c63f42 enable wasm-bindgen feature on gilrs (#3420)
WIthout the feature, `gilrs` uses `stdweb` instead of `wasm-bindgen` which isn't compatible with the rest of bevy.

Unfortunately, the `stdweb` dependency is still in the dependency tree, it just isn't used (https://gitlab.com/gilrs-project/gilrs/-/issues/101). This will be fixed in `gilrs 0.9` when it releases.
2021-12-23 19:19:14 +00:00
Nicola Papale
035ec7b763 Implement non-indexed mesh rendering (#3415)
# Objective

Instead of panicking when the `indices` field of a mesh is `None`, actually manage it.

This is just a question of keeping track of the vertex buffer size.

## Notes

* Relying on this change to improve performance on [bevy_debug_lines using the new renderer](https://github.com/Toqozz/bevy_debug_lines/pull/10)
* I'm still new to rendering, my only expertise with wgpu is the learn-wgpu tutorial, likely I'm overlooking something.
2021-12-23 19:19:13 +00:00
Mike
851b5939ce add tracing spans for parallel executor and system overhead (#3416)
This PR adds tracing spans for the parallel executor and system overhead.

![image](https://user-images.githubusercontent.com/2180432/147172747-b78026e3-1c30-4120-92c8-693c6f1564cd.png)
2021-12-23 19:03:44 +00:00
James Higgins
0936f4ca9d RemoveChildren command (#1925) 2021-12-23 09:04:55 +00:00
Jakob Hellermann
081350916c report shader processing errors in RenderPipelineCache (#3289)
### Problem
- shader processing errors are not displayed
- during hot reloading when encountering a shader with errors, the whole app crashes

### Solution
- log `error!`s for shader processing errors 
- when `cfg(debug_assertions)` is enabled (i.e. you're running in `debug` mode), parse shaders before passing them to wgpu. This lets us handle errors early.
2021-12-22 22:16:42 +00:00
François
6c479649bf enable Webgl2 optimisation in pbr under feature (#3291)
# Objective

- 3d examples fail to run in webgl2 because of unsupported texture formats or texture too large

## Solution

- switch to supported formats if a feature is enabled. I choose a feature instead of a build target to not conflict with a potential webgpu support

Very inspired by 6813b2edc5, and need #3290 to work.

I named the feature `webgl2`, but it's only needed if one want to use PBR in webgl2. Examples using only 2D already work.

Co-authored-by: François <8672791+mockersf@users.noreply.github.com>
2021-12-22 20:59:48 +00:00
François
a3c53e689d Shader Processor: process imported shader (#3290)
# Objective

- I want to be able to use `#ifdef` and other processor directives in an imported shader

## Solution

- Process imported shader strings


Co-authored-by: François <8672791+mockersf@users.noreply.github.com>
2021-12-22 01:01:39 +00:00
Alice Cecile
b5d7ff2d75 Do not panic on failed setting of GameOver state in AlienCakeAddict (#3411)
# Objective

- Tentatively fixes #2525.

## Solution

- The panic seems to occur when the game-over state occurs nearly instantly.
- Discard the `Result`, rather than panicking. We could probably handle this better, but I want to see if this works first. Ping @qarmin.
2021-12-22 00:49:15 +00:00
PaperCow
004bbe9f04 Use EventWriter for gilrs_system (#3413)
# Objective

- fixes #3397 

## Solution

- Uses EventWriter instead of ResMut<Event> in gilrs_system.rs.

I also renamed the argument from `event` to `events` for consistency. All other instances I could find in the engine of EventWriter use a plural argument name. Happy to undo or modify this change if desired.
2021-12-21 23:56:58 +00:00
aloucks
c04dfc1174 Add some of the missing methods to TrackedRenderPass (#3401)
# Objective

Add missing methods to `TrackedRenderPass`

- `set_push_constants`
- `set_viewport`
- `insert_debug_marker`
- `push_debug_group`
- `pop_debug_group`
- `set_blend_constant`

https://docs.rs/wgpu/0.12.0/wgpu/struct.RenderPass.html

I need `set_push_constants` but started adding the others as I noticed they were also missing. The `draw indirect` family of methods are still missing as are the `timestamp query` methods.
2021-12-20 23:16:54 +00:00
MrGVSV
5479047aa2 Added set_cursor_icon(...) to Window (#3395)
# Objective

The window's cursor should be settable without having to implement a custom cursor icon solution. This will especially be helpful when creating user-interfaces that might like to use the cursor to denote some meaning (e.g., _clickable_, _resizable_, etc.).

## Solution

Added a `CursorIcon` enum that maps one-to-one to winit's `CursorIcon` enum, as well as a method to set/get it for the given `Window`.
2021-12-20 22:04:45 +00:00
John
3443cc77cb Fixes minimization crash because of cluster updates. (#3369)
# Objective
Fixes: #3368

Issue was caused by screen size being: `(0, 0)`.

## Solution
Don't update clusters if the screen size is zero. A better solution might be to not render when minimized, but this works in the meantime.


Co-authored-by: John <startoaster23@gmail.com>
2021-12-20 21:43:55 +00:00
François
c61fbcb7db Only bevy_render should depend directly on wgpu (#3393)
# Objective

- Only bevy_render should depend directly on wgpu
- This helps to make sure bevy_render re-exports everything needed from wgpu

## Solution

- Remove bevy_pbr, bevy_sprite and bevy_ui dependency on wgpu


Co-authored-by: François <8672791+mockersf@users.noreply.github.com>
2021-12-20 20:50:52 +00:00
Alice Cecile
1ef028d2af Basic docs for Storages (#3391)
# Objective

- Storages are used to store the ECS data.
- They're undocumented.

## Solution

- Add some very basic docs.

## Notes
- Some of this was hard to immediately understand when reading the code, so suggestions on improvements / things to add are particularly welcome.
2021-12-20 20:50:51 +00:00
davier
c79ec9cad6 Fix custom mesh pipelines (#3381)
# Objective

Fixes #3379 

## Solution

The custom mesh pipelines needed to be specialized on each mesh's primitive topology, as done in `queue_meshes()`

Co-authored-by: Carter Anderson <mcanders1@gmail.com>
2021-12-20 20:33:39 +00:00
研究社交
46c1480f42 Fix hierarchy example panic (#3378)
# Objective
Fixes #3321 

## Solution
Uses `despawn_recursive()` instead of `despawn()` when removing children.
2021-12-20 20:33:38 +00:00
davier
340957994d Implement the Overflow::Hidden style property for UI (#3296)
# Objective

This PR implements the `overflow` style property in `bevy_ui`. When set to `Overflow::Hidden`, the children of that node are clipped so that overflowing parts are not rendered. This is an important building block for UI widgets.

## Solution

Clipping is done on the CPU so that it does not break batching.

The clip regions update was implemented as a separate system for clarity, but it could be merged with the other UI systems to avoid doing an additional tree traversal. (I don't think it's important until we fix the layout performance issues though).

A scrolling list was added to the `ui_pipelined` example to showcase `Overflow::Hidden`. For the sake of simplicity, it can only be scrolled with a mouse.
2021-12-19 05:44:28 +00:00
Vabka
9a89295a17 Update wgpu to 0.12 and naga to 0.8 (#3375)
# Objective

Fixes #3352
Fixes #3208

## Solution

- Update wgpu to 0.12
- Update naga to 0.8
- Resolve compilation errors
- Remove [[block]] from WGSL shaders (because it is depracated and now wgpu cant parse it)
- Replace `elseif` with `else if` in pbr.wgsl
2021-12-19 03:03:06 +00:00
Hoidigan
e018ac838d Add readme as docs to relevant crates. (#2575)
Fixes #2566
Fixes #3005 

There are only READMEs in the 4 crates here (with the exception of bevy itself).
Those 4 crates are ecs, reflect, tasks, and transform.
These should each now include their respective README files.

Co-authored-by: Hoidigan <57080125+Hoidigan@users.noreply.github.com>
Co-authored-by: Daniel Nelsen <57080125+Hoidigan@users.noreply.github.com>
2021-12-18 22:59:55 +00:00
sapir
8c250919e3 Fix double drop in BlobVec::replace_unchecked (#2597) (#2848)
# Objective

I thought I'd have a go a trying to fix #2597.

Hopefully fixes #2597.

## Solution

I reused the memory pointed to by the value parameter, that is already required by `insert` to not be dropped, to contain the extracted value while dropping it.
2021-12-18 21:29:24 +00:00
Dusty DeWeese
73f524f61c Support topologies other than TriangleList (#3349)
# Objective

Fixes https://github.com/bevyengine/bevy/issues/3346

## Solution

I've encoded the topology in the `MeshKey` similar to how MSAA samples are handled.
2021-12-18 20:55:40 +00:00
François
6eb8e15e3d Improved bevymark: no bouncing offscreen and spawn waves from CLI (#3364)
# Objective

- In bevymark, bevies were very bouncy and could go off screen after a while, skewing the FPS

https://user-images.githubusercontent.com/8672791/146540848-282fa11b-d058-4da9-8e95-688ae67d9406.mp4

## Solution

- Make bevies bounce also on top of the screen
- I also changed how the examples read args from CLI to be able to spawn waves: `cargo run --example bevymark --release -- 5 100` (first is number of bevy per wave, second is number of wave, with one wave every 0.2 seconds). This makes it easier to reproduce some exact situations

https://user-images.githubusercontent.com/8672791/146542857-2f953fa0-7b8d-4772-93f8-b8d7a31259dc.mp4




Co-authored-by: François <8672791+mockersf@users.noreply.github.com>
2021-12-18 20:13:59 +00:00