Commit graph

1735 commits

Author SHA1 Message Date
CGMossa
86ad5bf420 Adding WorldQuery for WithBundle (#2024)
In response to #2023, here is a draft for a PR. 

Fixes #2023

I've added an example to show how to use `WithBundle`, and also to test it out. 

Right now there is a bug: If a bundle and a query are "the same", then it doesn't filter out
what it needs to filter out. 

Example: 

```
Print component initated from bundle.
[examples/ecs/query_bundle.rs:57] x = Dummy( <========= This should not get printed
    111,
)
[examples/ecs/query_bundle.rs:57] x = Dummy(
    222,
)
Show all components
[examples/ecs/query_bundle.rs:50] x = Dummy(
    111,
)
[examples/ecs/query_bundle.rs:50] x = Dummy(
    222,
)
```

However, it behaves the right way, if I add one more component to the bundle,
so the query and the bundle doesn't look the same:

```
Print component initated from bundle.
[examples/ecs/query_bundle.rs:57] x = Dummy(
    222,
)
Show all components
[examples/ecs/query_bundle.rs:50] x = Dummy(
    111,
)
[examples/ecs/query_bundle.rs:50] x = Dummy(
    222,
)
```

I hope this helps. I'm definitely up for tinkering with this, and adding anything that I'm asked to add
or change. 





Co-authored-by: Carter Anderson <mcanders1@gmail.com>
2021-04-28 21:03:10 +00:00
deprilula28
cdb9097ed4 Make Command's public? (#2034)
I'm using Bevy ECS in a project of mine and I'd like to do world changes asynchronously. 

The current public API for creating entities, `Commands` , has a lifetime that restricts it from being sent across threads. `CommandQueue` on the other hand is a Vec of commands that can be later ran on a World. 

So far this is all public, but the commands themselves are private API. I know the intented use is with `Commands`, but that's not possible for my use case as I mentioned, and so I simply copied over the code for the commands I need and it works. Obviously, this isn't a nice solution, so I'd like to ask if it's not out of scope to make the commands public?
2021-04-28 20:08:33 +00:00
TehPers
cf40f4ab08 Fix mesh with no vertex attributes causing panic (#2036)
If a mesh without any vertex attributes is rendered (for example, one that only has indices), bevy will crash since the mesh still creates a vertex buffer even though it's empty. Later code assumes that there is vertex data, causing an index-out-of-bounds panic. This PR fixes the issue by adding a check that there is any vertex data before creating a vertex buffer.

I ran into this issue while rendering a tilemap without any vertex attributes (only indices).

Stack trace:
```
thread 'main' panicked at 'index out of bounds: the len is 0 but the index is 0', C:\Dev\Games\bevy\crates\bevy_render\src\render_graph\nodes\pass_node.rs:346:9
stack backtrace:
   0: std::panicking::begin_panic_handler
             at /rustc/bb491ed23937aef876622e4beb68ae95938b3bf9\/library\std\src\panicking.rs:493
   1: core::panicking::panic_fmt
             at /rustc/bb491ed23937aef876622e4beb68ae95938b3bf9\/library\core\src\panicking.rs:92
   2: core::panicking::panic_bounds_check
             at /rustc/bb491ed23937aef876622e4beb68ae95938b3bf9\/library\core\src\panicking.rs:69
   3: core::slice::index::{{impl}}::index<core::option::Option<tuple<bevy_render::renderer::render_resource::buffer::BufferId, u64>>>
             at C:\Users\tehpe\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core\src\slice\index.rs:184
   4: core::slice::index::{{impl}}::index<core::option::Option<tuple<bevy_render::renderer::render_resource::buffer::BufferId, u64>>,usize>
             at C:\Users\tehpe\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core\src\slice\index.rs:15
   5: alloc::vec::{{impl}}::index<core::option::Option<tuple<bevy_render::renderer::render_resource::buffer::BufferId, u64>>,usize,alloc::alloc::Global>
             at C:\Users\tehpe\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\alloc\src\vec\mod.rs:2386
   6: bevy_render::render_graph::nodes::pass_node::DrawState::is_vertex_buffer_set
             at C:\Dev\Games\bevy\crates\bevy_render\src\render_graph\nodes\pass_node.rs:346
   7: bevy_render::render_graph::nodes::pass_node::{{impl}}::update::{{closure}}<bevy_render::render_graph::base::MainPass*>
             at C:\Dev\Games\bevy\crates\bevy_render\src\render_graph\nodes\pass_node.rs:285
   8: bevy_wgpu::renderer::wgpu_render_context::{{impl}}::begin_pass
             at C:\Dev\Games\bevy\crates\bevy_wgpu\src\renderer\wgpu_render_context.rs:196
   9: bevy_render::render_graph::nodes::pass_node::{{impl}}::update<bevy_render::render_graph::base::MainPass*>
             at C:\Dev\Games\bevy\crates\bevy_render\src\render_graph\nodes\pass_node.rs:244
  10: bevy_wgpu::renderer::wgpu_render_graph_executor::WgpuRenderGraphExecutor::execute
             at C:\Dev\Games\bevy\crates\bevy_wgpu\src\renderer\wgpu_render_graph_executor.rs:75
  11: bevy_wgpu::wgpu_renderer::{{impl}}::run_graph::{{closure}}
             at C:\Dev\Games\bevy\crates\bevy_wgpu\src\wgpu_renderer.rs:115
  12: bevy_ecs::world::World::resource_scope<bevy_render::render_graph::graph::RenderGraph,tuple<>,closure-0>
             at C:\Dev\Games\bevy\crates\bevy_ecs\src\world\mod.rs:715
  13: bevy_wgpu::wgpu_renderer::WgpuRenderer::run_graph
             at C:\Dev\Games\bevy\crates\bevy_wgpu\src\wgpu_renderer.rs:104
  14: bevy_wgpu::wgpu_renderer::WgpuRenderer::update
             at C:\Dev\Games\bevy\crates\bevy_wgpu\src\wgpu_renderer.rs:121
  15: bevy_wgpu::get_wgpu_render_system::{{closure}}
             at C:\Dev\Games\bevy\crates\bevy_wgpu\src\lib.rs:112
  16: alloc::boxed::{{impl}}::call_mut<tuple<mut bevy_ecs::world::World*>,FnMut<tuple<mut bevy_ecs::world::World*>>,alloc::alloc::Global>
             at C:\Users\tehpe\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\alloc\src\boxed.rs:1553
  17: bevy_ecs::system::exclusive_system::{{impl}}::run
             at C:\Dev\Games\bevy\crates\bevy_ecs\src\system\exclusive_system.rs:41
  18: bevy_ecs::schedule::stage::{{impl}}::run
             at C:\Dev\Games\bevy\crates\bevy_ecs\src\schedule\stage.rs:812
  19: bevy_ecs::schedule::Schedule::run_once
             at C:\Dev\Games\bevy\crates\bevy_ecs\src\schedule\mod.rs:201
  20: bevy_ecs::schedule::{{impl}}::run
             at C:\Dev\Games\bevy\crates\bevy_ecs\src\schedule\mod.rs:219
  21: bevy_app::app::App::update
             at C:\Dev\Games\bevy\crates\bevy_app\src\app.rs:58
  22: bevy_winit::winit_runner_with::{{closure}}
             at C:\Dev\Games\bevy\crates\bevy_winit\src\lib.rs:485
  23: winit::platform_impl::platform::event_loop::{{impl}}::run_return::{{closure}}<tuple<>,closure-1>
             at C:\Users\tehpe\.cargo\registry\src\github.com-1ecc6299db9ec823\winit-0.24.0\src\platform_impl\windows\event_loop.rs:203
  24: alloc::boxed::{{impl}}::call_mut<tuple<winit::event::Event<tuple<>>, mut winit::event_loop::ControlFlow*>,FnMut<tuple<winit::event::Event<tuple<>>, mut winit::event_loop::ControlFlow*>>,alloc::alloc::Global>
             at C:\Users\tehpe\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\alloc\src\boxed.rs:1553
  25: winit::platform_impl::platform::event_loop:🏃:{{impl}}::call_event_handler::{{closure}}<tuple<>>
             at C:\Users\tehpe\.cargo\registry\src\github.com-1ecc6299db9ec823\winit-0.24.0\src\platform_impl\windows\event_loop\runner.rs:245
  26: std::panic::{{impl}}::call_once<tuple<>,closure-0>
             at C:\Users\tehpe\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\std\src\panic.rs:344
  27: std::panicking::try::do_call<std::panic::AssertUnwindSafe<closure-0>,tuple<>>
             at C:\Users\tehpe\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\std\src\panicking.rs:379
  28: hashbrown::set::HashSet<mut winapi::shared::windef::HWND__*, std::collections:#️⃣:map::RandomState, alloc::alloc::Global>::iter<mut winapi::shared::windef::HWND__*,std::collections:#️⃣:map::RandomState,alloc::alloc::Global>
  29: std::panicking::try<tuple<>,std::panic::AssertUnwindSafe<closure-0>>
             at C:\Users\tehpe\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\std\src\panicking.rs:343
  30: std::panic::catch_unwind<std::panic::AssertUnwindSafe<closure-0>,tuple<>>
             at C:\Users\tehpe\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\std\src\panic.rs:431
  31: winit::platform_impl::platform::event_loop:🏃:EventLoopRunner<tuple<>>::catch_unwind<tuple<>,tuple<>,closure-0>
             at C:\Users\tehpe\.cargo\registry\src\github.com-1ecc6299db9ec823\winit-0.24.0\src\platform_impl\windows\event_loop\runner.rs:152
  32: winit::platform_impl::platform::event_loop:🏃:EventLoopRunner<tuple<>>::call_event_handler<tuple<>>
             at C:\Users\tehpe\.cargo\registry\src\github.com-1ecc6299db9ec823\winit-0.24.0\src\platform_impl\windows\event_loop\runner.rs:239
  33: winit::platform_impl::platform::event_loop:🏃:EventLoopRunner<tuple<>>::move_state_to<tuple<>>
             at C:\Users\tehpe\.cargo\registry\src\github.com-1ecc6299db9ec823\winit-0.24.0\src\platform_impl\windows\event_loop\runner.rs:341
  34: winit::platform_impl::platform::event_loop:🏃:EventLoopRunner<tuple<>>::main_events_cleared<tuple<>>
             at C:\Users\tehpe\.cargo\registry\src\github.com-1ecc6299db9ec823\winit-0.24.0\src\platform_impl\windows\event_loop\runner.rs:227
  35: winit::platform_impl::platform::event_loop::flush_paint_messages<tuple<>>
             at C:\Users\tehpe\.cargo\registry\src\github.com-1ecc6299db9ec823\winit-0.24.0\src\platform_impl\windows\event_loop.rs:676
  36: winit::platform_impl::platform::event_loop::thread_event_target_callback::{{closure}}<tuple<>>
             at C:\Users\tehpe\.cargo\registry\src\github.com-1ecc6299db9ec823\winit-0.24.0\src\platform_impl\windows\event_loop.rs:1967
  37: std::panic::{{impl}}::call_once<isize,closure-0>
             at C:\Users\tehpe\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\std\src\panic.rs:344
  38: std::panicking::try::do_call<std::panic::AssertUnwindSafe<closure-0>,isize>
             at C:\Users\tehpe\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\std\src\panicking.rs:379
  39: hashbrown::set::HashSet<mut winapi::shared::windef::HWND__*, std::collections:#️⃣:map::RandomState, alloc::alloc::Global>::iter<mut winapi::shared::windef::HWND__*,std::collections:#️⃣:map::RandomState,alloc::alloc::Global>
  40: std::panicking::try<isize,std::panic::AssertUnwindSafe<closure-0>>
             at C:\Users\tehpe\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\std\src\panicking.rs:343
  41: std::panic::catch_unwind<std::panic::AssertUnwindSafe<closure-0>,isize>
             at C:\Users\tehpe\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\std\src\panic.rs:431
  42: winit::platform_impl::platform::event_loop:🏃:EventLoopRunner<tuple<>>::catch_unwind<tuple<>,isize,closure-0>
             at C:\Users\tehpe\.cargo\registry\src\github.com-1ecc6299db9ec823\winit-0.24.0\src\platform_impl\windows\event_loop\runner.rs:152
  43: winit::platform_impl::platform::event_loop::thread_event_target_callback<tuple<>>
             at C:\Users\tehpe\.cargo\registry\src\github.com-1ecc6299db9ec823\winit-0.24.0\src\platform_impl\windows\event_loop.rs:2151
  44: DefSubclassProc
  45: DefSubclassProc
  46: CallWindowProcW
  47: DispatchMessageW
  48: SendMessageTimeoutW
  49: KiUserCallbackDispatcher
  50: NtUserDispatchMessage
  51: DispatchMessageW
  52: winit::platform_impl::platform::event_loop::EventLoop<tuple<>>::run_return<tuple<>,closure-1>
             at C:\Users\tehpe\.cargo\registry\src\github.com-1ecc6299db9ec823\winit-0.24.0\src\platform_impl\windows\event_loop.rs:218
  53: winit::platform_impl::platform::event_loop::EventLoop<tuple<>>::run<tuple<>,closure-1>
             at C:\Users\tehpe\.cargo\registry\src\github.com-1ecc6299db9ec823\winit-0.24.0\src\platform_impl\windows\event_loop.rs:188
  54: winit::event_loop::EventLoop<tuple<>>::run<tuple<>,closure-1>
             at C:\Users\tehpe\.cargo\registry\src\github.com-1ecc6299db9ec823\winit-0.24.0\src\event_loop.rs:154
  55: bevy_winit::run<closure-1>
             at C:\Dev\Games\bevy\crates\bevy_winit\src\lib.rs:171
  56: bevy_winit::winit_runner_with
             at C:\Dev\Games\bevy\crates\bevy_winit\src\lib.rs:493
  57: bevy_winit::winit_runner
             at C:\Dev\Games\bevy\crates\bevy_winit\src\lib.rs:211
  58: core::ops::function::Fn::call<fn(bevy_app::app::App),tuple<bevy_app::app::App>>
             at C:\Users\tehpe\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core\src\ops\function.rs:70
  59: alloc::boxed::{{impl}}::call<tuple<bevy_app::app::App>,Fn<tuple<bevy_app::app::App>>,alloc::alloc::Global>
             at C:\Users\tehpe\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\alloc\src\boxed.rs:1560
  60: bevy_app::app::App::run
             at C:\Dev\Games\bevy\crates\bevy_app\src\app.rs:68
  61: bevy_app::app_builder::AppBuilder::run
             at C:\Dev\Games\bevy\crates\bevy_app\src\app_builder.rs:54
  62: game_main::main
             at .\crates\game_main\src\main.rs:23
  63: core::ops::function::FnOnce::call_once<fn(),tuple<>>
             at C:\Users\tehpe\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core\src\ops\function.rs:227
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
Apr 27 21:51:01.026 ERROR gpu_descriptor::allocator: `DescriptorAllocator` is dropped while some descriptor sets were not deallocated
error: process didn't exit successfully: `target/cargo\debug\game_main.exe` (exit code: 0xc000041d)
```
2021-04-28 19:04:01 +00:00
bjorn3
2fcd8a3fb0 Monomorphize various things (#1914)
Based on #1910

This shrinks breakout from 310k to 293k. Most of the win is in outlining the drop glue of `App`. The other two commits save about 800 bytes total when using two empty systems and two simple resources.

After this PR the full disassembly for

```rust
fn main() {
    App::build().run();
}
```

is about as minimal as it gets, so pretty much all other costs scale linear in the amount of resources, systems, etc.

```asm
0000000000001100 <_ZN4core3ptr54drop_in_place$LT$bevy_app..app_builder..AppBuilder$GT$17h76850422c20653deE>:
    1100:       ff 25 52 21 00 00       jmpq   *0x2152(%rip)        # 3258 <_ZN60_$LT$bevy_app..app..App$u20$as$u20$core..ops..drop..Drop$GT$4drop17h67d177ae549d917bE@Base>
    1106:       cc                      int3   
    1107:       cc                      int3   
    1108:       cc                      int3   
    1109:       cc                      int3   
    110a:       cc                      int3   
    110b:       cc                      int3   
    110c:       cc                      int3   
    110d:       cc                      int3   
    110e:       cc                      int3   
    110f:       cc                      int3   

0000000000001110 <_ZN8breakout4main17h7cbe07b319de1042E>:
    1110:       53                      push   %rbx
    1111:       48 81 ec 00 03 00 00    sub    $0x300,%rsp
    1118:       48 8d 5c 24 08          lea    0x8(%rsp),%rbx
    111d:       48 89 df                mov    %rbx,%rdi
    1120:       ff 15 3a 21 00 00       callq  *0x213a(%rip)        # 3260 <_ZN8bevy_app3app3App5build17h8b0ea6be9050d6ccE@Base>
    1126:       48 89 df                mov    %rbx,%rdi
    1129:       ff 15 39 21 00 00       callq  *0x2139(%rip)        # 3268 <_ZN8bevy_app11app_builder10AppBuilder3run17hfc8cf50692acdbdeE@Base>
    112f:       48 8d 7c 24 08          lea    0x8(%rsp),%rdi
    1134:       ff 15 1e 21 00 00       callq  *0x211e(%rip)        # 3258 <_ZN60_$LT$bevy_app..app..App$u20$as$u20$core..ops..drop..Drop$GT$4drop17h67d177ae549d917bE@Base>
    113a:       48 81 c4 00 03 00 00    add    $0x300,%rsp
    1141:       5b                      pop    %rbx
    1142:       c3                      retq   
    1143:       48 89 c3                mov    %rax,%rbx
    1146:       48 8d 7c 24 08          lea    0x8(%rsp),%rdi
    114b:       e8 b0 ff ff ff          callq  1100 <_ZN4core3ptr54drop_in_place$LT$bevy_app..app_builder..AppBuilder$GT$17h76850422c20653deE>
    1150:       48 89 df                mov    %rbx,%rdi
    1153:       e8 18 01 00 00          callq  1270 <_Unwind_Resume@plt>
    1158:       0f 0b                   ud2    
    115a:       cc                      int3   
    115b:       cc                      int3   
    115c:       cc                      int3   
    115d:       cc                      int3   
    115e:       cc                      int3   
    115f:       cc                      int3   

0000000000001160 <main>:
    1160:       48 83 ec 08             sub    $0x8,%rsp
    1164:       48 89 f1                mov    %rsi,%rcx
    1167:       48 63 d7                movslq %edi,%rdx
    116a:       48 8d 05 9f ff ff ff    lea    -0x61(%rip),%rax        # 1110 <_ZN8breakout4main17h7cbe07b319de1042E>
    1171:       48 89 04 24             mov    %rax,(%rsp)
    1175:       48 8d 35 94 1e 00 00    lea    0x1e94(%rip),%rsi        # 3010 <__init_array_end>
    117c:       48 89 e7                mov    %rsp,%rdi
    117f:       ff 15 eb 20 00 00       callq  *0x20eb(%rip)        # 3270 <_ZN3std2rt19lang_start_internal17he77194431b0ee4a2E@Base>
    1185:       59                      pop    %rcx
    1186:       c3                      retq   
    1187:       cc                      int3   
    1188:       cc                      int3   
    1189:       cc                      int3   
    118a:       cc                      int3   
    118b:       cc                      int3   
    118c:       cc                      int3   
    118d:       cc                      int3   
    118e:       cc                      int3   
    118f:       cc                      int3   

0000000000001190 <_ZN3std2rt10lang_start28_$u7b$$u7b$closure$u7d$$u7d$17h83a5b8d55f23dff8E.llvm.909376793398482062>:
    1190:       48 83 ec 08             sub    $0x8,%rsp
    1194:       48 8b 3f                mov    (%rdi),%rdi
    1197:       e8 54 ff ff ff          callq  10f0 <_ZN3std10sys_common9backtrace28__rust_begin_short_backtrace17h6e238af75680eb28E>
    119c:       31 c0                   xor    %eax,%eax
    119e:       59                      pop    %rcx
    119f:       c3                      retq   

00000000000011a0 <_ZN4core3ops8function6FnOnce40call_once$u7b$$u7b$vtable.shim$u7d$$u7d$17hb05d591cd29dea4fE.llvm.909376793398482062>:
    11a0:       48 83 ec 08             sub    $0x8,%rsp
    11a4:       48 8b 3f                mov    (%rdi),%rdi
    11a7:       e8 44 ff ff ff          callq  10f0 <_ZN3std10sys_common9backtrace28__rust_begin_short_backtrace17h6e238af75680eb28E>
    11ac:       31 c0                   xor    %eax,%eax
    11ae:       59                      pop    %rcx
    11af:       c3                      retq   

00000000000011b0 <_ZN4core3ptr85drop_in_place$LT$std..rt..lang_start$LT$$LP$$RP$$GT$..$u7b$$u7b$closure$u7d$$u7d$$GT$17he9aeeba375093b99E.llvm.909376793398482062>:
    11b0:       c3                      retq   
    11b1:       cc                      int3   
    11b2:       cc                      int3   
    11b3:       cc                      int3   
    11b4:       cc                      int3   
    11b5:       cc                      int3   
    11b6:       cc                      int3   
    11b7:       cc                      int3   
    11b8:       cc                      int3   
    11b9:       cc                      int3   
    11ba:       cc                      int3   
    11bb:       cc                      int3   
    11bc:       cc                      int3   
    11bd:       cc                      int3   
    11be:       cc                      int3   
    11bf:       cc                      int3
```
2021-04-28 19:04:00 +00:00
François
6f7da027c7 Automatic System Spans (#2033)
As mentioned in https://github.com/bevyengine/bevy/issues/2025#issuecomment-827867660, systems used to have spans by default.

* add spans by default for every system executed
* create folder if missing for feature `wgpu_trace`
2021-04-28 18:41:16 +00:00
Lucas Rocha
b1ed28e17e Hide re-exported docs (#1985)
Solves #1957 

Co-authored-by: caelumLaron <caelum.laron@gmail.com>
2021-04-27 18:29:33 +00:00
James Leflang
cc0ee536f0 Add note about linker errors for Fedora users (#2009)
This PR adds a note to the Fedora section of Linux Dependencies on solving linker errors.

Fixes #1815.

Co-authored-by: James Leflang <59455417+jleflang@users.noreply.github.com>
2021-04-27 02:41:34 +00:00
François
723fe91183 Fail CI on cargo doc warnings (#2012)
* makes CI fails on cargo doc warnings
* adds this check in bors

doc warnings are listed here: https://doc.rust-lang.org/rustdoc/lints.html

Currently the warnings emitted are:
* broken_intra_doc_links
* private_intra_doc_links
* invalid_codeblock_attributes
2021-04-27 02:17:12 +00:00
TheRawMeatball
c32c37d737 Detect camera projection changes (#2015) 2021-04-27 01:11:04 +00:00
Lukas Orsvärn
3f4d50bab9 Removed irrelevant note for Mac users (#2017)
The removed comment talks about something in the file that no longer exists.
2021-04-27 00:46:41 +00:00
François
fcf8fafa71 fix dead intra links in doc on Input and Reflect (#2007)
fix a few dead links

* Links in `Input` missed a refactor
* `Reflect::downcast` can't use the intra doc link format, as it's not a link to a trait function, but to a function implemented on `dyn Reflect`

noticed in https://github.com/bevyengine/bevy/pull/1781#discussion_r619777879
2021-04-25 17:24:09 +00:00
François
0a8576b710 support assets of any size (#1997)
Fixes #1892 

The following code is a cut down version of the issue, and crashes the same way:
```rust
enum AssetLifecycleEvent <T> {
    Create(T),
    Free
}

fn main() {
    let (sender, _receiver) = crossbeam_channel::unbounded();
    sender.send(AssetLifecycleEvent::<[u32; 32000]>::Free).unwrap();
}
```

- We're creating a channel that need to be able to hold `AssetLifecycleEvent::Create(T)` which has the size of our type `T`
- The two variants of the enums have a very different size

By keeping `T` boxed while sending through the channel, it doesn't crash
2021-04-24 18:14:04 +00:00
Grindv1k
38feddb878 Add system sets and run criteria example (#1909)
If accepted, fixes #1694 .

I wanted to explore system sets and run criteria a bit, so made an example expanding a bit on the snippets shown in the 0.5 release post.

Shows a couple of system sets, uses system labels, run criterion, and a use of the interesting `RunCriterion::pipe` functionality.
2021-04-23 19:08:16 +00:00
TehPers
d653ad2bda Updated docs for ShouldRun (#1987)
The documentation for `ShouldRun` doesn't completely explain what each of the variants you can return does. For instance, it isn't very clear that looping systems aren't executed again until after all the systems in a stage have had a chance to run.

This PR adds to the documentation for `ShouldRun`, and hopefully clarifies what is happening during a stage's execution when run criteria are checked and systems are being executed.
2021-04-23 18:38:18 +00:00
TehPers
0a587ac3b5 Updated remaining system panic messages to include the system name (#1986)
Some panic messages for systems include the system name, but there's a few panic messages which do not. This PR adds the system name for the remaining panic messages.

This is a continuation of the work done in #1864.
Related: #1846
2021-04-23 17:54:04 +00:00
François
e3fb23d4d3 add documentation on LogPlugin and more log usage (#1973)
Fixes #1895 

Changed most `println` to `info` in examples, some to `warn` when it was useful to differentiate from other more noisy logs.

Added doc on `LogPlugin`, how to configure it, and why (and how) you may need to disable it
2021-04-22 23:30:48 +00:00
Zicklag
6508b4ed25 Hide Derived SystemParam State Struct From Docs (#1984)
This makes sure the automatically generated MyStructState type is not
shown in the rustdoc when deriving SystemParam on MyStruct.
2021-04-22 23:09:59 +00:00
Martín Maita
391ccd0ad0 Adds docs deadlinks check on CI (#1590)
Closes https://github.com/bevyengine/bevy/issues/1579

This is my first contribution to this repository, feel free to correct anything that I'm missing and I'll address feedback as soon as possible!
2021-04-22 19:53:44 +00:00
bjorn3
6719c2c390 Extract monomorphic get_insert_bundle_info function (#1910)
This shrinks breakout from 316k to 310k when using `--feature dynamic`.

I haven't run the ecs benchmark to test performance as my laptop is too noisy for reliable benchmarking.
2021-04-22 19:34:34 +00:00
Lukas Wirth
7c274e5a44 Improve bevy_ecs query docs (#1935)
Mainly documents Query, WorldQuery and the various Query Filter types as well as some smaller doc changes.
2021-04-22 19:09:09 +00:00
Joshua Ols
19f467ebd0 Spherical Area Lights (#1901)
I still need to simplify and optimize the code, but here's a preliminary working version of Spherical Area Lights. See the example image below from a modified version of my [cubism-demo-rs](https://github.com/Josh015/cubism-demo-rs) app, which you can also clone and run to see them in action.

![Spherical Area Lights v1](https://user-images.githubusercontent.com/8846132/114491862-60df6000-9be5-11eb-8950-f039b74e1e96.jpg)
2021-04-22 18:49:02 +00:00
Carter Anderson
b9640243c6 Separate Query filter access from fetch access during initial evaluation (#1977)
Fixes #1955 

See this comment for implementation details / motivation: https://github.com/bevyengine/bevy/issues/1955#issuecomment-823600886
2021-04-22 02:16:09 +00:00
Carter Anderson
1248a639ee EnumVariantMeta derive (#1972)
There are cases where we want an enum variant name. Right now the only way to do that with rust's std is to derive Debug, but this will also print out the variant's fields. This creates the unfortunate situation where we need to manually write out each variant's string name (ex: in #1963), which is both boilerplate-ey and error-prone. Crates such as `strum` exist for this reason, but it includes a lot of code and complexity that we don't need.

This adds a dead-simple `EnumVariantMeta` derive that exposes `enum_variant_index` and `enum_variant_name` functions. This allows us to make cases like #1963 much cleaner (see the second commit). We might also be able to reuse this logic for `bevy_reflect` enum derives.
2021-04-21 23:46:54 +00:00
Alice Cecile
e4e32598a9 Cargo fmt with unstable features (#1903)
Fresh version of #1670 off the latest main.

Mostly fixing documentation wrapping.
2021-04-21 23:19:34 +00:00
François
30c6ca6166 don't panic when no RenderResourceContext can be found (#1971)
In bevy_webgl2, the `RenderResourceContext` is created after startup as it needs to first wait for an event from js side:
f31e5d49de/src/lib.rs (L117)

remove `panic` introduced in #1965 and log as a `warn` instead
2021-04-20 21:44:32 +00:00
MinerSebas
80df583a21 When missing a render backend also mention the bevy_wgpu feature (#1970) 2021-04-20 21:04:09 +00:00
Nathan Ward
cbfb456847 [bevy_core/bytes] Fix UB with accessing memory with incorrect alignment (#1966)
After running `bevy_core` through `miri`, errors were reported surrounding incorrect memory accesses within the `bytes` test suit. 

Specifically:
```
test bytes::tests::test_array_round_trip ... error: Undefined Behavior: accessing memory with alignment 1, but alignment 4 is required
   --> crates/bevy_core/src/bytes.rs:55:13
    |
55  |             (*ptr).clone()
    |             ^^^^^^ accessing memory with alignment 1, but alignment 4 is required
    |
```

and 

```
test bytes::tests::test_vec_bytes_round_trip ... error: Undefined Behavior: accessing memory with alignment 2, but alignment 4 is required
   --> /home/nward/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/slice/raw.rs:95:14
    |
95  |     unsafe { &*ptr::slice_from_raw_parts(data, len) }
    |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ accessing memory with alignment 2, but alignment 4 is required
    |
```

Solution:

The solution is to use `slice::align_to` method to ensure correct alignment.
2021-04-20 21:04:08 +00:00
simens_green
c74994ba69 Added TryFrom for VertexAttributeValues (#1963)
This implementations allows you
convert std::vec::Vec<T> to VertexAttributeValues::T and back.

# Examples

```rust
use std::convert::TryInto;
use bevy_render::mesh::VertexAttributeValues;

// creating vector of values
let before = vec![[0_u32; 4]; 10];
let values = VertexAttributeValues::from(before.clone());
let after: Vec<[u32; 4]> = values.try_into().unwrap();

assert_eq!(before, after);
```

Co-authored-by: aloucks <aloucks@cofront.net>
Co-authored-by: simens_green <34134129+simensgreen@users.noreply.github.com>
Co-authored-by: Carter Anderson <mcanders1@gmail.com>
2021-04-20 20:41:32 +00:00
François
4a477e762d update CHANGELOG for 0.5 (#1967)
mark version 0.5 as released in CHANGELOG
2021-04-19 22:41:19 +00:00
MinerSebas
ad43f52bd2 Provide better error message when missing a render backend (#1965)
Fixes #626
2021-04-19 22:16:24 +00:00
MinerSebas
458312236a Document setting "CARGO_MANIFEST_DIR" for asset root (#1950)
This was nowhere documented inside Bevy.
Should I also mention the use case of debugging a project?

Closes #810

Co-authored-by: MinerSebas <66798382+MinerSebas@users.noreply.github.com>
2021-04-19 22:16:23 +00:00
MinerSebas
e29a899b90 Added missing Component Bound to Res<> and ResMut<> (#1962)
Fixes #1838
2021-04-19 21:53:34 +00:00
François
f1ddd7a2ad change how to select bevy-glsl-to-spirv or shaderc (#1819)
`cfg` for `bevy-glsl-to-spirv` use now mimics https://github.com/cart/glsl-to-spirv/blob/master/Cargo.toml

fixes #898 
fixes #1348 
fixes #1942 
fixes #1078
2021-04-19 21:28:30 +00:00
dependabot[bot]
3eb828f234 Bump actions/cache from v2.1.4 to v2.1.5 (#1961)
Bumps [actions/cache](https://github.com/actions/cache) from v2.1.4 to v2.1.5.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a href="https://github.com/actions/cache/releases">actions/cache's releases</a>.</em></p>
<blockquote>
<h2>v2.1.5</h2>
<ul>
<li>Fix permissions error seen when extracting caches with GNU tar that were previously created using BSD tar (<a href="https://github-redirect.dependabot.com/actions/cache/issues/527">actions/cache#527</a>)</li>
</ul>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a href="1a9e2138d9"><code>1a9e213</code></a> Update cache module to v1.0.7 (<a href="https://github-redirect.dependabot.com/actions/cache/issues/562">#562</a>)</li>
<li><a href="981fa981ed"><code>981fa98</code></a> Merge pull request <a href="https://github-redirect.dependabot.com/actions/cache/issues/469">#469</a> from ericmj/patch-1</li>
<li><a href="4498c5b4d8"><code>4498c5b</code></a> Drop the example based on using pip's internals (<a href="https://github-redirect.dependabot.com/actions/cache/issues/519">#519</a>)</li>
<li><a href="4134e6de47"><code>4134e6d</code></a> It is not recommended to cache node_modules (<a href="https://github-redirect.dependabot.com/actions/cache/issues/537">#537</a>)</li>
<li><a href="62a4d75442"><code>62a4d75</code></a> Also cache _build for Elixir</li>
<li>See full diff in <a href="https://github.com/actions/cache/compare/v2.1.4...1a9e2138d905efd099035b49d8b7a3888c653ca8">compare view</a></li>
</ul>
</details>
<br />


Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
- `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)


</details>
2021-04-19 21:07:20 +00:00
Mariusz Kryński
fa6d4dbd53 add render_to_texture example (#1927)
Co-authored-by: Carter Anderson <mcanders1@gmail.com>
2021-04-19 21:07:19 +00:00
Alister Lee
3d4b1b9ff2 Fix alien_cake_addict: cake should not be at height of player's location (#1954)
Just to avoid confusion to close readers of the example, this fix ensures cake is transformed to the height at the cake's cell, rather than the height at the player's cell.

Without this, cake may be floating or buried, depending on where the player is standing at time of spawning.

Love your work!
2021-04-19 20:45:41 +00:00
Yoh Deadfall
4f1689ec37 Added example of entity sorting by components (#1817)
We discussed with @alice-i-cecile privately on iterators and agreed that making a custom ordered iterator over query makes no sense since materialization is required anyway and it's better to reuse existing components or code. Therefore, just adding an example to the documentation as requested.

Fixes #1470.

Co-authored-by: Carter Anderson <mcanders1@gmail.com>
2021-04-19 20:28:02 +00:00
François
07cf088f33 fix memory size for PointLightBundle (#1940)
Introduced in #1778, not fixed by #1931 

The size of `Lights` buffer currently is : 
```rust
    16 // (color, `[f32; 4]`)
    + 16 // (number of lights, `f32` encoded as a `[f32; 4]`)
    + 10 // (maximum number of lights)
        * ( 16 // (light position, `[f32; 4]`
          + 16 // (color, `[16; 4]`)
          + 4 // (inverse_range_squared, `f32`)
          )

-> 392
```

This makes the pbr shader crash when running with Xcode debugger or with the WebGL2 backend. They both expect a buffer sized 512. This can also be seen on desktop by adding a second light to a scene with a color, it's position and color will be wrong.

adding a second light to example `load_gltf`:
```rust
    commands
        .spawn_bundle(PointLightBundle {
            transform: Transform::from_xyz(-3.0, 5.0, -3.0),
            point_light: PointLight {
                color: Color::BLUE,
                ..Default::default()
            },
            ..Default::default()
        })
        .insert(Rotates);
```

before fix:
<img width="1392" alt="Screenshot 2021-04-16 at 19 14 59" src="https://user-images.githubusercontent.com/8672791/115060744-866fb080-9ee8-11eb-8915-f87cc872ad48.png">

after fix:
<img width="1392" alt="Screenshot 2021-04-16 at 19 16 44" src="https://user-images.githubusercontent.com/8672791/115060759-8cfe2800-9ee8-11eb-92c2-d79f39c7b36b.png">




This PR changes `inverse_range_squared` to be a `[f32; 4]` instead of a `f32` to have the expected alignement
2021-04-19 19:30:39 +00:00
James Higgins
2bc126e2ce Label for ui_focus_system (#1926)
Needed a label because of a conflict with some custom ui systems
2021-04-19 19:15:27 +00:00
François
97b26d7647 limit number of lights (#1946)
Fixes #1921 

Buffer was growing with the actual number of lights instead of being limited to the max number of lights.

As it's a query that can be exactly sized, I also switched `count()` to `len()`
2021-04-19 18:57:58 +00:00
François
2bd8ed57d0 par_for_each: split batches when iterating on a sparse query (#1945)
Fixes #1943 

Each batch was iterating over the complete query
2021-04-19 18:41:42 +00:00
MinerSebas
20673dbe0e Doctest improvments (#1937) 2021-04-16 19:13:08 +00:00
MinerSebas
4c86b99d2f Update cargo_features.md (#1939)
This adds missing features to the cargo_features.md file.

closes #1391
2021-04-16 18:57:08 +00:00
Logan Magee
d508923eb7 Allow deriving SystemParam on private types (#1936)
Examples creating a public type to derive `SystemParam` on were updated
to create a private type where a public one is no longer needed.

Resolves #1869
2021-04-16 18:40:49 +00:00
Jakob Hellermann
cf221f9659 calculate flat normals for mesh if missing (#1808)
If the gltf loader encounters a mesh without normal attributes, it will duplicate the vertex attributes and compute flat normals, as defined by https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#meshes:

> **Implementation Note**: When normals are not specified, client implementations should calculate flat normals.

![image](https://user-images.githubusercontent.com/22177966/113483243-bb204880-94a2-11eb-8fa1-c4828a4882c5.png)

Helps with #1802 

Co-authored-by: Carter Anderson <mcanders1@gmail.com>
2021-04-15 21:06:49 +00:00
Lukas Wirth
0a6fee5d17 Improve bevy_ecs::system module docs (#1932)
This includes a lot of single line comments where either saying more wasn't helpful or due to me not knowing enough about things yet to be able to go more indepth. Proofreading is very much welcome.
2021-04-15 20:36:16 +00:00
Boxy
9657f58f6a Fix unsoundness in query component access (#1929)
Pretty much does what it says in the title lol
2021-04-15 20:17:59 +00:00
Anselmo Sampietro
9b7ed18f72 Add animate shaders example (#1765)
This PR adds an example on how to animate a shader by passing the global `time.seconds_since_startup()` to a component, and accessing that component inside the shader.

Hopefully this is the current proper solution, please let me know if it should be solved in another way.

Co-authored-by: Carter Anderson <mcanders1@gmail.com>
2021-04-15 19:49:31 +00:00
François
8a6b92991e fix markdownlint ci after master branch deletion (#1933)
remove reference to master branch
2021-04-15 19:29:47 +00:00
François
86f3308308 examples on how to tests systems (#1714)
well... those are examples on how to tests systems despawning entities, modifying components, accessing resources, spawning entities
2021-04-15 00:57:37 +00:00