From c426e34af0bd2494d569c4fd973dfc6801886f1d Mon Sep 17 00:00:00 2001 From: Carter Anderson Date: Thu, 12 Nov 2020 20:00:43 -0800 Subject: [PATCH] combine bevy_ecs and bevy_hecs crates. rename XComponents to XBundle --- Cargo.toml | 2 +- crates/bevy_ecs/Cargo.toml | 16 +- .../bevy_ecs/{hecs/LICENSE => LICENSE_APACHE} | 0 crates/bevy_ecs/LICENSE_MIT | 202 ++++++++++++++++++ crates/bevy_ecs/README.md | 7 + crates/bevy_ecs/{hecs => }/benches/bench.rs | 2 +- crates/bevy_ecs/hecs/.gitignore | 3 - crates/bevy_ecs/hecs/CONTRIBUTING.md | 23 -- crates/bevy_ecs/hecs/Cargo.toml | 41 ---- crates/bevy_ecs/hecs/README.md | 88 -------- crates/bevy_ecs/{hecs => }/macros/Cargo.toml | 4 +- crates/bevy_ecs/{hecs => }/macros/src/lib.rs | 8 +- .../bevy_ecs/{hecs/src => src/core}/access.rs | 22 +- .../{hecs/src => src/core}/archetype.rs | 15 +- .../bevy_ecs/{hecs/src => src/core}/borrow.rs | 2 +- .../bevy_ecs/{hecs/src => src/core}/bundle.rs | 6 +- .../{hecs/src => src/core}/entities.rs | 5 +- .../{hecs/src => src/core}/entity_builder.rs | 14 +- .../src/{world => core}/entity_map.rs | 5 +- .../bevy_ecs/{hecs/src => src/core}/filter.rs | 32 ++- .../{hecs/src/lib.rs => src/core/mod.rs} | 46 +--- .../bevy_ecs/{hecs/src => src/core}/query.rs | 61 +++--- .../bevy_ecs/{hecs/src => src/core}/serde.rs | 2 +- .../bevy_ecs/{hecs/src => src/core}/world.rs | 69 +++--- .../src/{world => core}/world_builder.rs | 2 +- crates/bevy_ecs/src/lib.rs | 9 +- crates/bevy_ecs/src/resource/resources.rs | 3 +- .../src/schedule/parallel_executor.rs | 5 +- crates/bevy_ecs/src/schedule/schedule.rs | 2 +- crates/bevy_ecs/src/system/commands.rs | 10 +- crates/bevy_ecs/src/system/into_system.rs | 9 +- .../bevy_ecs/src/system/into_thread_local.rs | 3 +- crates/bevy_ecs/src/system/query/mod.rs | 17 +- crates/bevy_ecs/src/system/query/query_set.rs | 7 +- crates/bevy_ecs/src/system/system.rs | 3 +- crates/bevy_ecs/src/system/system_param.rs | 11 +- crates/bevy_ecs/{hecs => src}/tests/tests.rs | 2 +- crates/bevy_ecs/src/world/mod.rs | 5 - crates/bevy_gltf/src/loader.rs | 4 +- crates/bevy_pbr/src/entity.rs | 6 +- crates/bevy_render/src/entity.rs | 14 +- .../src/render_graph/nodes/pass_node.rs | 10 +- crates/bevy_sprite/src/entity.rs | 8 +- crates/bevy_sprite/src/lib.rs | 2 +- crates/bevy_ui/src/entity.rs | 30 +-- examples/2d/contributors.rs | 8 +- examples/2d/sprite.rs | 4 +- examples/2d/sprite_sheet.rs | 4 +- examples/2d/texture_atlas.rs | 6 +- examples/3d/3d_scene.rs | 8 +- examples/3d/load_gltf.rs | 4 +- examples/3d/msaa.rs | 6 +- examples/3d/parenting.rs | 8 +- examples/3d/spawner.rs | 6 +- examples/3d/texture.rs | 8 +- examples/3d/z_sort_debug.rs | 8 +- examples/android/android.rs | 8 +- examples/asset/asset_loading.rs | 10 +- examples/asset/hot_asset_reloading.rs | 4 +- examples/ecs/hierarchy.rs | 10 +- examples/ecs/parallel_query.rs | 4 +- examples/game/breakout.rs | 20 +- examples/ios/src/lib.rs | 10 +- examples/scene/scene.rs | 30 ++- examples/shader/mesh_custom_attribute.rs | 4 +- examples/shader/shader_custom_material.rs | 4 +- examples/shader/shader_defs.rs | 6 +- examples/tools/bevymark.rs | 8 +- examples/ui/button.rs | 6 +- examples/ui/font_atlas_debug.rs | 26 ++- examples/ui/text.rs | 4 +- examples/ui/text_debug.rs | 147 ++++++------- examples/ui/ui.rs | 32 +-- examples/window/multiple_windows.rs | 6 +- 74 files changed, 628 insertions(+), 618 deletions(-) rename crates/bevy_ecs/{hecs/LICENSE => LICENSE_APACHE} (100%) create mode 100644 crates/bevy_ecs/LICENSE_MIT create mode 100644 crates/bevy_ecs/README.md rename crates/bevy_ecs/{hecs => }/benches/bench.rs (99%) delete mode 100644 crates/bevy_ecs/hecs/.gitignore delete mode 100644 crates/bevy_ecs/hecs/CONTRIBUTING.md delete mode 100644 crates/bevy_ecs/hecs/Cargo.toml delete mode 100644 crates/bevy_ecs/hecs/README.md rename crates/bevy_ecs/{hecs => }/macros/Cargo.toml (68%) rename crates/bevy_ecs/{hecs => }/macros/src/lib.rs (97%) rename crates/bevy_ecs/{hecs/src => src/core}/access.rs (95%) rename crates/bevy_ecs/{hecs/src => src/core}/archetype.rs (98%) rename crates/bevy_ecs/{hecs/src => src/core}/borrow.rs (98%) rename crates/bevy_ecs/{hecs/src => src/core}/bundle.rs (98%) rename crates/bevy_ecs/{hecs/src => src/core}/entities.rs (99%) rename crates/bevy_ecs/{hecs/src => src/core}/entity_builder.rs (97%) rename crates/bevy_ecs/src/{world => core}/entity_map.rs (97%) rename crates/bevy_ecs/{hecs/src => src/core}/filter.rs (90%) rename crates/bevy_ecs/{hecs/src/lib.rs => src/core/mod.rs} (58%) rename crates/bevy_ecs/{hecs/src => src/core}/query.rs (91%) rename crates/bevy_ecs/{hecs/src => src/core}/serde.rs (89%) rename crates/bevy_ecs/{hecs/src => src/core}/world.rs (95%) rename crates/bevy_ecs/src/{world => core}/world_builder.rs (96%) rename crates/bevy_ecs/{hecs => src}/tests/tests.rs (99%) delete mode 100644 crates/bevy_ecs/src/world/mod.rs diff --git a/Cargo.toml b/Cargo.toml index 1d3a8561908535..2db7dbf7f5f86c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,7 +17,7 @@ repository = "https://github.com/bevyengine/bevy" [workspace] exclude = ["benches"] -members = ["crates/*", "crates/bevy_ecs/hecs", "examples/ios"] +members = ["crates/*", "examples/ios"] [features] default = [ diff --git a/crates/bevy_ecs/Cargo.toml b/crates/bevy_ecs/Cargo.toml index 8707da006b095a..776d14415338bf 100644 --- a/crates/bevy_ecs/Cargo.toml +++ b/crates/bevy_ecs/Cargo.toml @@ -6,10 +6,10 @@ authors = [ "Bevy Contributors ", "Carter Anderson ", ] -description = "Bevy Engine's custom entity component system" +description = "Bevy Engine's entity component system" homepage = "https://bevyengine.org" repository = "https://github.com/bevyengine/bevy" -license = "MIT" +license = "Apache-2.0" keywords = ["ecs", "game", "bevy"] categories = ["game-engines", "data-structures"] @@ -17,11 +17,21 @@ categories = ["game-engines", "data-structures"] trace = [] [dependencies] -bevy_hecs = { path = "hecs", features = ["macros", "serialize"], version = "0.3.0" } bevy_tasks = { path = "../bevy_tasks", version = "0.3.0" } bevy_utils = { path = "../bevy_utils", version = "0.3.0" } +bevy_ecs_macros = { path = "macros", version = "0.3.0" } rand = "0.7.3" +serde = "1.0" thiserror = "1.0" fixedbitset = "0.3.1" downcast-rs = "1.2.0" parking_lot = "0.11.0" +lazy_static = { version = "1.4.0" } + +[dev-dependencies] +bencher = "0.1.5" + +[[bench]] +name = "bench" +harness = false +required-features = ["macros"] diff --git a/crates/bevy_ecs/hecs/LICENSE b/crates/bevy_ecs/LICENSE_APACHE similarity index 100% rename from crates/bevy_ecs/hecs/LICENSE rename to crates/bevy_ecs/LICENSE_APACHE diff --git a/crates/bevy_ecs/LICENSE_MIT b/crates/bevy_ecs/LICENSE_MIT new file mode 100644 index 00000000000000..d645695673349e --- /dev/null +++ b/crates/bevy_ecs/LICENSE_MIT @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/crates/bevy_ecs/README.md b/crates/bevy_ecs/README.md new file mode 100644 index 00000000000000..8522a0e5ea4af0 --- /dev/null +++ b/crates/bevy_ecs/README.md @@ -0,0 +1,7 @@ +# Bevy ECS + +Bevy Engine's entity component system + +## Licensing + +Bevy ECS has its roots in hecs, which is licensed as Apache 2.0. All original hecs code is licensed under Apache 2.0. All added/modified code is dual licensed under MIT and Apache 2.0. Files with an Apache 2.0 license header (with Google LLC as the copyright holder) were from the "original hecs" codebase. Files without the header were created by Bevy contributors. \ No newline at end of file diff --git a/crates/bevy_ecs/hecs/benches/bench.rs b/crates/bevy_ecs/benches/bench.rs similarity index 99% rename from crates/bevy_ecs/hecs/benches/bench.rs rename to crates/bevy_ecs/benches/bench.rs index 90b9634f1e6aee..4547af2a918ab7 100644 --- a/crates/bevy_ecs/hecs/benches/bench.rs +++ b/crates/bevy_ecs/benches/bench.rs @@ -15,7 +15,7 @@ // modified by Bevy contributors use bencher::{benchmark_group, benchmark_main, Bencher}; -use bevy_hecs::*; +use bevy_ecs::*; struct Position(f32); struct Velocity(f32); diff --git a/crates/bevy_ecs/hecs/.gitignore b/crates/bevy_ecs/hecs/.gitignore deleted file mode 100644 index 693699042b1a8c..00000000000000 --- a/crates/bevy_ecs/hecs/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -/target -**/*.rs.bk -Cargo.lock diff --git a/crates/bevy_ecs/hecs/CONTRIBUTING.md b/crates/bevy_ecs/hecs/CONTRIBUTING.md deleted file mode 100644 index ef4500bd751633..00000000000000 --- a/crates/bevy_ecs/hecs/CONTRIBUTING.md +++ /dev/null @@ -1,23 +0,0 @@ -# How to Contribute - -We'd love to accept your patches and contributions to this project. There are -just a few small guidelines you need to follow. - -## Contributor License Agreement - -Contributions to this project must be accompanied by a Contributor License -Agreement. You (or your employer) retain the copyright to your contribution; -this simply gives us permission to use and redistribute your contributions as -part of the project. Head over to to see -your current agreements on file or to sign a new one. - -You generally only need to submit a CLA once, so if you've already submitted one -(even if it was for a different project), you probably don't need to do it -again. - -## Code reviews - -All submissions require review. We use GitHub pull requests for this -purpose. Consult [GitHub -Help](https://help.github.com/articles/about-pull-requests/) for more -information on using pull requests. diff --git a/crates/bevy_ecs/hecs/Cargo.toml b/crates/bevy_ecs/hecs/Cargo.toml deleted file mode 100644 index 5c39508749d3a7..00000000000000 --- a/crates/bevy_ecs/hecs/Cargo.toml +++ /dev/null @@ -1,41 +0,0 @@ -[package] -name = "bevy_hecs" -version = "0.3.0" -description = "Bevy fork of hecs: a fast, minimal, and ergonomic entity-component-system" -authors = [ - "Benjamin Saunders ", - "Bevy Contributors ", - "Carter Anderson "] -edition = "2018" -license = "Apache-2.0" -repository = "https://github.com/Ralith/hecs" -readme = "README.md" -keywords = ["ecs", "entity"] -categories = ["data-structures", "game-engines", "no-std"] - -[package.metadata.docs.rs] -all-features = true - -[badges] -maintenance = { status = "actively-developed" } - -[features] -default = ["std"] -std = [] -# Enables derive(Bundle) -macros = ["bevy_hecs_macros", "lazy_static"] -serialize = ["serde"] - -[dependencies] -bevy_hecs_macros = { path = "macros", version = "0.3.0", optional = true } -bevy_utils = { path = "../../bevy_utils", version = "0.3.0" } -lazy_static = { version = "1.4.0", optional = true, features = ["spin_no_std"] } -serde = { version = "1", features = ["derive"], optional = true} - -[dev-dependencies] -bencher = "0.1.5" - -[[bench]] -name = "bench" -harness = false -required-features = ["macros"] diff --git a/crates/bevy_ecs/hecs/README.md b/crates/bevy_ecs/hecs/README.md deleted file mode 100644 index 52452c7ecf9dfb..00000000000000 --- a/crates/bevy_ecs/hecs/README.md +++ /dev/null @@ -1,88 +0,0 @@ -# hecs - -[![Documentation](https://docs.rs/hecs/badge.svg)](https://docs.rs/hecs/) -[![Crates.io](https://img.shields.io/crates/v/hecs.svg)](https://crates.io/crates/hecs) -[![License: Apache 2.0](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](LICENSE-APACHE) - -hecs provides a high-performance, minimalist entity-component-system (ECS) -world. It is a library, not a framework. In place of an explicit "System" -abstraction, a `World`'s entities are easily queried from regular code. Organize -your application however you like! - -### Bevy Fork Information - -This is the Bevy project's fork of hecs with changes that accommodate the needs of the Bevy game engine. Some notable changes: -* Entity indices are now queryable and are not returned in queries by default. This both improves ergonomics and significantly boosts performance in some cases. -* Expose more interfaces as public so that we can build higher-level apis on top of the core hecs codebase (multithreading, functions-as-systems, world builders, schedules, etc) -* Change Tracking - -### Why ECS? - -Entity-component-system architecture makes it easy to compose loosely-coupled -state and behavior. An ECS world consists of: - -- any number of **entities**, which represent distinct objects -- a collection of **component** data associated with each entity, where each - entity has at most one component of any type, and two entities may have - different components - -That world is then manipulated by **systems**, each of which accesses all -entities having a particular set of component types. Systems implement -self-contained behavior like physics (e.g. by accessing "position", "velocity", -and "collision" components) or rendering (e.g. by accessing "position" and -"sprite" components). - -New components and systems can be added to a complex application without -interfering with existing logic, making the ECS paradigm well suited to -applications where many layers of overlapping behavior will be defined on the -same set of objects, particularly if new behaviors will be added in the -future. This flexibility sets it apart from traditional approaches based on -heterogeneous collections of explicitly defined object types, where implementing -new combinations of behaviors (e.g. a vehicle which is also a questgiver) can -require far-reaching changes. - -#### Performance - -In addition to having excellent composability, the ECS paradigm can also provide -exceptional speed and cache locality. `hecs` internally tracks groups of -entities which all have the same components. Each group has a dense, contiguous -array for each type of component. When a system accesses all entities with a -certain set of components, a fast linear traversal can be made through each -group having a superset of those components. This is effectively a columnar -database, and has the same benefits: the CPU can accurately predict memory -accesses, bypassing unneeded data, maximizing cache use and minimizing latency. - -### Why Not ECS? - -An ECS world is not a be-all end-all data structure. Most games will store -significant amounts of state in other structures. For example, many games -maintain a spatial index structure (e.g. a tile map or bounding volume -hierarchy) used to find entities and obstacles near a certain location for -efficient collision detection without searching the entire world. - -If you need to search for specific entities using criteria other than the types -of their components, consider maintaining a specialized index beside your world, -storing `Entity` handles and whatever other data is necessary. Insert into the -index when spawning relevant entities, and include a component with that allows -efficiently removing them from the index when despawning. - -### Other Libraries - -hecs would not exist if not for the great work done by others to introduce and -develop the ECS paradigm in the Rust ecosystem. In particular: - -- [specs] played a key role in popularizing ECS in Rust -- [legion] reduced boilerplate and improved cache locality with sparse - components - -hecs builds on these successes by focusing on further simplification, boiling -the paradigm down to a minimal, light-weight and ergonomic core, without -compromising on performance or flexibility. - -### Disclaimer - -This is not an official Google product (experimental or otherwise), it is just -code that happens to be owned by Google. - -[specs]: https://github.com/amethyst/specs -[legion]: https://github.com/TomGillen/legion diff --git a/crates/bevy_ecs/hecs/macros/Cargo.toml b/crates/bevy_ecs/macros/Cargo.toml similarity index 68% rename from crates/bevy_ecs/hecs/macros/Cargo.toml rename to crates/bevy_ecs/macros/Cargo.toml index de487b768fe7f0..6e5c8d9f4adf7a 100644 --- a/crates/bevy_ecs/hecs/macros/Cargo.toml +++ b/crates/bevy_ecs/macros/Cargo.toml @@ -1,7 +1,7 @@ [package] -name = "bevy_hecs_macros" +name = "bevy_ecs_macros" version = "0.3.0" -description = "Bevy fork of hecs-macros: procedural macro definitions for hecs" +description = "Bevy ECS Macros" authors = ["Benjamin Saunders "] edition = "2018" license = "Apache-2.0" diff --git a/crates/bevy_ecs/hecs/macros/src/lib.rs b/crates/bevy_ecs/macros/src/lib.rs similarity index 97% rename from crates/bevy_ecs/hecs/macros/src/lib.rs rename to crates/bevy_ecs/macros/src/lib.rs index 58df575d26b85e..44d605aa8c9d30 100644 --- a/crates/bevy_ecs/hecs/macros/src/lib.rs +++ b/crates/bevy_ecs/macros/src/lib.rs @@ -57,10 +57,12 @@ fn derive_bundle_(input: DeriveInput) -> Result { let manifest = Manifest::new().unwrap(); let path_str = if let Some(package) = manifest.find(|name| name == "bevy") { format!("{}::ecs", package.name) + } else if let Some(package) = manifest.find(|name| name == "bevy_internal") { + format!("{}::ecs", package.name) } else if let Some(package) = manifest.find(|name| name == "bevy_ecs") { package.name } else { - "bevy_hecs".to_string() + "bevy_ecs".to_string() }; let crate_path: Path = syn::parse(path_str.parse::().unwrap()).unwrap(); let field_idents = member_as_idents(&field_members); @@ -311,7 +313,7 @@ pub fn impl_query_set(_input: TokenStream) -> TokenStream { let query_fn = &query_fns[0..query_count]; let query_fn_mut = &query_fn_muts[0..query_count]; tokens.extend(TokenStream::from(quote! { - impl<#(#lifetime,)* #(#query: HecsQuery,)* #(#filter: QueryFilter,)*> QueryTuple for (#(Query<#lifetime, #query, #filter>,)*) { + impl<#(#lifetime,)* #(#query: WorldQuery,)* #(#filter: QueryFilter,)*> QueryTuple for (#(Query<#lifetime, #query, #filter>,)*) { unsafe fn new(world: &World, component_access: &TypeAccess) -> Self { ( #( @@ -330,7 +332,7 @@ pub fn impl_query_set(_input: TokenStream) -> TokenStream { } } - impl<#(#lifetime,)* #(#query: HecsQuery,)* #(#filter: QueryFilter,)*> QuerySet<(#(Query<#lifetime, #query, #filter>,)*)> { + impl<#(#lifetime,)* #(#query: WorldQuery,)* #(#filter: QueryFilter,)*> QuerySet<(#(Query<#lifetime, #query, #filter>,)*)> { #(#query_fn)* #(#query_fn_mut)* } diff --git a/crates/bevy_ecs/hecs/src/access.rs b/crates/bevy_ecs/src/core/access.rs similarity index 95% rename from crates/bevy_ecs/hecs/src/access.rs rename to crates/bevy_ecs/src/core/access.rs index 258e27570d0357..938a159500837d 100644 --- a/crates/bevy_ecs/hecs/src/access.rs +++ b/crates/bevy_ecs/src/core/access.rs @@ -1,8 +1,7 @@ -use core::{any::TypeId, hash::Hash}; -use std::{boxed::Box, vec::Vec}; - -use crate::{Archetype, World}; use bevy_utils::HashSet; +use std::{any::TypeId, boxed::Box, hash::Hash, vec::Vec}; + +use super::{Archetype, World}; #[derive(Debug, Copy, Clone, Ord, PartialOrd, Eq, PartialEq)] pub enum Access { @@ -282,7 +281,8 @@ impl TypeAccess { #[cfg(test)] mod tests { - use crate::{ArchetypeComponent, Entity, Fetch, Query, QueryAccess, TypeAccess, World}; + use super::{ArchetypeComponent, TypeAccess}; + use crate::{core::World, Entity, Fetch, QueryAccess, WorldQuery}; use std::vec; struct A; @@ -309,7 +309,7 @@ mod tests { let e3_c = ArchetypeComponent::new::(e3_archetype); let mut a_type_access = TypeAccess::default(); - <(&A,) as Query>::Fetch::access() + <(&A,) as WorldQuery>::Fetch::access() .get_world_archetype_access(&world, Some(&mut a_type_access)); assert_eq!( @@ -318,7 +318,7 @@ mod tests { ); let mut a_b_type_access = TypeAccess::default(); - <(&A, &B) as Query>::Fetch::access() + <(&A, &B) as WorldQuery>::Fetch::access() .get_world_archetype_access(&world, Some(&mut a_b_type_access)); assert_eq!( @@ -327,7 +327,7 @@ mod tests { ); let mut a_bmut_type_access = TypeAccess::default(); - <(&A, &mut B) as Query>::Fetch::access() + <(&A, &mut B) as WorldQuery>::Fetch::access() .get_world_archetype_access(&world, Some(&mut a_bmut_type_access)); assert_eq!( @@ -336,7 +336,7 @@ mod tests { ); let mut a_option_bmut_type_access = TypeAccess::default(); - <(Entity, &A, Option<&mut B>) as Query>::Fetch::access() + <(Entity, &A, Option<&mut B>) as WorldQuery>::Fetch::access() .get_world_archetype_access(&world, Some(&mut a_option_bmut_type_access)); assert_eq!( @@ -345,7 +345,7 @@ mod tests { ); let mut a_with_b_type_access = TypeAccess::default(); - QueryAccess::with::(<&A as Query>::Fetch::access()) + QueryAccess::with::(<&A as WorldQuery>::Fetch::access()) .get_world_archetype_access(&world, Some(&mut a_with_b_type_access)); assert_eq!( @@ -354,7 +354,7 @@ mod tests { ); let mut a_with_b_option_c_type_access = TypeAccess::default(); - QueryAccess::with::(<(&A, Option<&mut C>) as Query>::Fetch::access()) + QueryAccess::with::(<(&A, Option<&mut C>) as WorldQuery>::Fetch::access()) .get_world_archetype_access(&world, Some(&mut a_with_b_option_c_type_access)); assert_eq!( diff --git a/crates/bevy_ecs/hecs/src/archetype.rs b/crates/bevy_ecs/src/core/archetype.rs similarity index 98% rename from crates/bevy_ecs/hecs/src/archetype.rs rename to crates/bevy_ecs/src/core/archetype.rs index a95eabafd85291..ea06b31ce0923a 100644 --- a/crates/bevy_ecs/hecs/src/archetype.rs +++ b/crates/bevy_ecs/src/core/archetype.rs @@ -14,24 +14,17 @@ // modified by Bevy contributors -use crate::{ - alloc::{ - alloc::{alloc, dealloc, Layout}, - vec::Vec, - }, - Entity, -}; +use crate::{AtomicBorrow, Component, Entity}; use bevy_utils::AHasher; -use core::{ +use std::{ + alloc::{alloc, dealloc, Layout}, any::{type_name, TypeId}, cell::UnsafeCell, + collections::HashMap, hash::{BuildHasherDefault, Hasher}, mem, ptr::{self, NonNull}, }; -use std::collections::HashMap; - -use crate::{borrow::AtomicBorrow, Component}; /// A collection of entities having the same component types /// diff --git a/crates/bevy_ecs/hecs/src/borrow.rs b/crates/bevy_ecs/src/core/borrow.rs similarity index 98% rename from crates/bevy_ecs/hecs/src/borrow.rs rename to crates/bevy_ecs/src/core/borrow.rs index 7f500098c17f41..5420b94704c26e 100644 --- a/crates/bevy_ecs/hecs/src/borrow.rs +++ b/crates/bevy_ecs/src/core/borrow.rs @@ -20,7 +20,7 @@ use core::{ sync::atomic::{AtomicUsize, Ordering}, }; -use crate::{archetype::Archetype, Component, MissingComponent}; +use crate::{Archetype, Component, MissingComponent}; /// Atomically enforces Rust-style borrow checking at runtime #[derive(Debug)] diff --git a/crates/bevy_ecs/hecs/src/bundle.rs b/crates/bevy_ecs/src/core/bundle.rs similarity index 98% rename from crates/bevy_ecs/hecs/src/bundle.rs rename to crates/bevy_ecs/src/core/bundle.rs index 87b5f05667e3cd..e69eecb14a4ffb 100644 --- a/crates/bevy_ecs/hecs/src/bundle.rs +++ b/crates/bevy_ecs/src/core/bundle.rs @@ -14,15 +14,13 @@ // modified by Bevy contributors -use crate::alloc::{vec, vec::Vec}; -use core::{ +use crate::{Component, TypeInfo}; +use std::{ any::{type_name, TypeId}, fmt, mem, ptr::NonNull, }; -use crate::{archetype::TypeInfo, Component}; - /// A dynamically typed collection of components pub trait DynamicBundle { /// Invoke a callback on the fields' type IDs, sorted by descending alignment then id diff --git a/crates/bevy_ecs/hecs/src/entities.rs b/crates/bevy_ecs/src/core/entities.rs similarity index 99% rename from crates/bevy_ecs/hecs/src/entities.rs rename to crates/bevy_ecs/src/core/entities.rs index 4e06aabee68910..2a5cc637481bb3 100644 --- a/crates/bevy_ecs/hecs/src/entities.rs +++ b/crates/bevy_ecs/src/core/entities.rs @@ -1,11 +1,8 @@ -use alloc::{boxed::Box, vec::Vec}; -use core::{ +use std::{ convert::TryFrom, fmt, mem, sync::atomic::{AtomicU32, Ordering}, }; -#[cfg(feature = "std")] -use std::error::Error; /// Lightweight unique ID of an entity /// diff --git a/crates/bevy_ecs/hecs/src/entity_builder.rs b/crates/bevy_ecs/src/core/entity_builder.rs similarity index 97% rename from crates/bevy_ecs/hecs/src/entity_builder.rs rename to crates/bevy_ecs/src/core/entity_builder.rs index a27d7722cc1fbf..d366738f2fba86 100644 --- a/crates/bevy_ecs/hecs/src/entity_builder.rs +++ b/crates/bevy_ecs/src/core/entity_builder.rs @@ -14,28 +14,22 @@ // modified by Bevy contributors -use crate::alloc::{ - alloc::{alloc, dealloc, Layout}, - boxed::Box, - vec, - vec::Vec, -}; - use bevy_utils::HashSet; -use core::{ +use std::{ + alloc::{alloc, dealloc, Layout}, any::TypeId, mem::{self, MaybeUninit}, ptr, }; -use crate::{archetype::TypeInfo, Component, DynamicBundle}; +use crate::{Component, DynamicBundle, TypeInfo}; /// Helper for incrementally constructing a bundle of components with dynamic component types /// /// Prefer reusing the same builder over creating new ones repeatedly. /// /// ``` -/// # use bevy_hecs::*; +/// # use bevy_ecs::*; /// let mut world = World::new(); /// let mut builder = EntityBuilder::new(); /// builder.add(123).add("abc"); diff --git a/crates/bevy_ecs/src/world/entity_map.rs b/crates/bevy_ecs/src/core/entity_map.rs similarity index 97% rename from crates/bevy_ecs/src/world/entity_map.rs rename to crates/bevy_ecs/src/core/entity_map.rs index a188156c7c6b74..6834dd8bfafd4e 100644 --- a/crates/bevy_ecs/src/world/entity_map.rs +++ b/crates/bevy_ecs/src/core/entity_map.rs @@ -1,7 +1,6 @@ -use std::collections::hash_map::Entry; - -use bevy_hecs::Entity; +use crate::Entity; use bevy_utils::HashMap; +use std::collections::hash_map::Entry; use thiserror::Error; #[derive(Error, Debug)] diff --git a/crates/bevy_ecs/hecs/src/filter.rs b/crates/bevy_ecs/src/core/filter.rs similarity index 90% rename from crates/bevy_ecs/hecs/src/filter.rs rename to crates/bevy_ecs/src/core/filter.rs index a237f1607a5da5..6a126f5eda7d24 100644 --- a/crates/bevy_ecs/hecs/src/filter.rs +++ b/crates/bevy_ecs/src/core/filter.rs @@ -1,6 +1,5 @@ -use crate::{archetype::Archetype, Component, QueryAccess}; -use core::{any::TypeId, marker::PhantomData, ptr::NonNull}; -use std::{boxed::Box, vec}; +use crate::{Archetype, Bundle, Component, QueryAccess}; +use std::{any::TypeId, marker::PhantomData, ptr::NonNull}; pub trait QueryFilter: Sized { type EntityFilter: EntityFilter; @@ -162,6 +161,33 @@ impl QueryFilter for With { } } +pub struct WithType(PhantomData); + +impl QueryFilter for WithType { + type EntityFilter = AnyEntityFilter; + + fn access() -> QueryAccess { + QueryAccess::union( + T::static_type_info() + .iter() + .map(|info| QueryAccess::With(info.id(), Box::new(QueryAccess::None))) + .collect::>(), + ) + } + + #[inline] + fn get_entity_filter(archetype: &Archetype) -> Option { + if T::static_type_info() + .iter() + .all(|info| archetype.has_type(info.id())) + { + Some(AnyEntityFilter) + } else { + None + } + } +} + macro_rules! impl_query_filter_tuple { ($($filter: ident),*) => { #[allow(unused_variables)] diff --git a/crates/bevy_ecs/hecs/src/lib.rs b/crates/bevy_ecs/src/core/mod.rs similarity index 58% rename from crates/bevy_ecs/hecs/src/lib.rs rename to crates/bevy_ecs/src/core/mod.rs index a754857f447ed5..028806430483c9 100644 --- a/crates/bevy_ecs/hecs/src/lib.rs +++ b/crates/bevy_ecs/src/core/mod.rs @@ -14,39 +14,6 @@ // modified by Bevy contributors -//! A handy ECS -//! -//! hecs provides a high-performance, minimalist entity-component-system (ECS) world. It is a -//! library, not a framework. In place of an explicit "System" abstraction, a `World`'s entities are -//! easily queried from regular code. Organize your application however you like! -//! -//! In order of importance, hecs pursues: -//! - fast traversals -//! - a simple interface -//! - a small dependency closure -//! - exclusion of externally-implementable functionality -//! -//! ``` -//! # use bevy_hecs::*; -//! let mut world = World::new(); -//! // Nearly any type can be used as a component with zero boilerplate -//! let a = world.spawn((123, true, "abc")); -//! let b = world.spawn((42, false)); -//! // Systems can be simple for loops -//! for (id, mut number, &flag) in &mut world.query_mut::<(Entity, &mut i32, &bool)>() { -//! if flag { *number *= 2; } -//! } -//! assert_eq!(*world.get::(a).unwrap(), 246); -//! assert_eq!(*world.get::(b).unwrap(), 42); -//! ``` - -#![no_std] - -#[cfg(feature = "std")] -extern crate std; - -extern crate alloc; - /// Imagine macro parameters, but more like those Russian dolls. /// /// Calls m!(A, B, C), m!(A, B), m!(B), and m!() for i.e. (m, A, B, C) @@ -69,11 +36,12 @@ mod borrow; mod bundle; mod entities; mod entity_builder; +mod entity_map; mod filter; mod query; -#[cfg(feature = "serde")] mod serde; mod world; +mod world_builder; pub use access::{ArchetypeComponent, QueryAccess, TypeAccess}; pub use archetype::{Archetype, TypeState}; @@ -81,20 +49,16 @@ pub use borrow::{AtomicBorrow, Ref, RefMut}; pub use bundle::{Bundle, DynamicBundle, MissingComponent}; pub use entities::{Entity, EntityReserver, Location, NoSuchEntity}; pub use entity_builder::{BuiltEntity, EntityBuilder}; +pub use entity_map::*; pub use filter::{Added, Changed, EntityFilter, Mutated, Or, QueryFilter, With, Without}; -pub use query::{Batch, BatchedIter, Mut, Query, QueryIter, ReadOnlyFetch}; +pub use query::{Batch, BatchedIter, Mut, QueryIter, ReadOnlyFetch, WorldQuery}; pub use world::{ArchetypesGeneration, Component, ComponentError, SpawnBatchIter, World}; +pub use world_builder::*; // Unstable implementation details needed by the macros #[doc(hidden)] pub use archetype::TypeInfo; #[doc(hidden)] pub use bevy_utils; -#[cfg(feature = "macros")] -#[doc(hidden)] -pub use lazy_static; #[doc(hidden)] pub use query::Fetch; - -#[cfg(feature = "macros")] -pub use bevy_hecs_macros::{impl_query_set, Bundle, SystemParam}; diff --git a/crates/bevy_ecs/hecs/src/query.rs b/crates/bevy_ecs/src/core/query.rs similarity index 91% rename from crates/bevy_ecs/hecs/src/query.rs rename to crates/bevy_ecs/src/core/query.rs index d4c494a998baf1..b71e3945783758 100644 --- a/crates/bevy_ecs/hecs/src/query.rs +++ b/crates/bevy_ecs/src/core/query.rs @@ -14,19 +14,18 @@ // modified by Bevy contributors -use crate::{ - access::QueryAccess, archetype::Archetype, Component, Entity, EntityFilter, MissingComponent, - QueryFilter, -}; -use core::{ +use crate::EntityFilter; + +use super::{Archetype, Component, Entity, MissingComponent, QueryAccess, QueryFilter}; +use std::{ marker::PhantomData, ops::{Deref, DerefMut}, ptr::NonNull, + vec, }; -use std::vec; /// A collection of component types to fetch from a `World` -pub trait Query { +pub trait WorldQuery { #[doc(hidden)] type Fetch: for<'a> Fetch<'a>; } @@ -66,7 +65,7 @@ pub trait Fetch<'a>: Sized { pub struct EntityFetch(NonNull); unsafe impl ReadOnlyFetch for EntityFetch {} -impl Query for Entity { +impl WorldQuery for Entity { type Fetch = EntityFetch; } @@ -93,7 +92,7 @@ impl<'a> Fetch<'a> for EntityFetch { } } -impl<'a, T: Component> Query for &'a T { +impl<'a, T: Component> WorldQuery for &'a T { type Fetch = FetchRead; } @@ -124,11 +123,11 @@ impl<'a, T: Component> Fetch<'a> for FetchRead { } } -impl<'a, T: Component> Query for &'a mut T { +impl<'a, T: Component> WorldQuery for &'a mut T { type Fetch = FetchMut; } -impl Query for Option { +impl WorldQuery for Option { type Fetch = TryFetch; } @@ -180,7 +179,7 @@ impl<'a, T: Component + core::fmt::Debug> core::fmt::Debug for Mut<'a, T> { } } -impl<'a, T: Component> Query for Mut<'a, T> { +impl<'a, T: Component> WorldQuery for Mut<'a, T> { type Fetch = FetchMut; } #[doc(hidden)] @@ -239,21 +238,21 @@ impl<'a, T: Fetch<'a>> Fetch<'a> for TryFetch { } } -struct ChunkInfo { +struct ChunkInfo { fetch: Q::Fetch, filter: F::EntityFilter, len: usize, } /// Iterator over the set of entities with the components in `Q` -pub struct QueryIter<'w, Q: Query, F: QueryFilter> { +pub struct QueryIter<'w, Q: WorldQuery, F: QueryFilter> { archetypes: &'w [Archetype], archetype_index: usize, chunk_info: ChunkInfo, chunk_position: usize, } -impl<'w, Q: Query, F: QueryFilter> QueryIter<'w, Q, F> { +impl<'w, Q: WorldQuery, F: QueryFilter> QueryIter<'w, Q, F> { const EMPTY: ChunkInfo = ChunkInfo { fetch: Q::Fetch::DANGLING, len: 0, @@ -272,7 +271,7 @@ impl<'w, Q: Query, F: QueryFilter> QueryIter<'w, Q, F> { } } -impl<'w, Q: Query, F: QueryFilter> Iterator for QueryIter<'w, Q, F> { +impl<'w, Q: WorldQuery, F: QueryFilter> Iterator for QueryIter<'w, Q, F> { type Item = >::Item; #[inline] @@ -314,7 +313,7 @@ impl<'w, Q: Query, F: QueryFilter> Iterator for QueryIter<'w, Q, F> { // if the Fetch is an UnfilteredFetch, then we can cheaply compute the length of the query by getting // the length of each matching archetype -impl<'w, Q: Query> ExactSizeIterator for QueryIter<'w, Q, ()> { +impl<'w, Q: WorldQuery> ExactSizeIterator for QueryIter<'w, Q, ()> { fn len(&self) -> usize { self.archetypes .iter() @@ -324,14 +323,14 @@ impl<'w, Q: Query> ExactSizeIterator for QueryIter<'w, Q, ()> { } } -struct ChunkIter { +struct ChunkIter { fetch: Q::Fetch, filter: F::EntityFilter, position: usize, len: usize, } -impl ChunkIter { +impl ChunkIter { unsafe fn next<'a>(&mut self) -> Option<>::Item> { loop { if self.position == self.len { @@ -351,7 +350,7 @@ impl ChunkIter { } /// Batched version of `QueryIter` -pub struct BatchedIter<'w, Q: Query, F: QueryFilter> { +pub struct BatchedIter<'w, Q: WorldQuery, F: QueryFilter> { archetypes: &'w [Archetype], archetype_index: usize, batch_size: usize, @@ -359,7 +358,7 @@ pub struct BatchedIter<'w, Q: Query, F: QueryFilter> { _marker: PhantomData<(Q, F)>, } -impl<'w, Q: Query, F: QueryFilter> BatchedIter<'w, Q, F> { +impl<'w, Q: WorldQuery, F: QueryFilter> BatchedIter<'w, Q, F> { pub(crate) fn new(archetypes: &'w [Archetype], batch_size: usize) -> Self { Self { archetypes, @@ -371,10 +370,10 @@ impl<'w, Q: Query, F: QueryFilter> BatchedIter<'w, Q, F> { } } -unsafe impl<'w, Q: Query, F: QueryFilter> Send for BatchedIter<'w, Q, F> {} -unsafe impl<'w, Q: Query, F: QueryFilter> Sync for BatchedIter<'w, Q, F> {} +unsafe impl<'w, Q: WorldQuery, F: QueryFilter> Send for BatchedIter<'w, Q, F> {} +unsafe impl<'w, Q: WorldQuery, F: QueryFilter> Sync for BatchedIter<'w, Q, F> {} -impl<'w, Q: Query, F: QueryFilter> Iterator for BatchedIter<'w, Q, F> { +impl<'w, Q: WorldQuery, F: QueryFilter> Iterator for BatchedIter<'w, Q, F> { type Item = Batch<'w, Q, F>; fn next(&mut self) -> Option { @@ -413,12 +412,12 @@ impl<'w, Q: Query, F: QueryFilter> Iterator for BatchedIter<'w, Q, F> { } /// A sequence of entities yielded by `BatchedIter` -pub struct Batch<'q, Q: Query, F: QueryFilter> { +pub struct Batch<'q, Q: WorldQuery, F: QueryFilter> { _marker: PhantomData<&'q ()>, state: ChunkIter, } -impl<'q, 'w, Q: Query, F: QueryFilter> Iterator for Batch<'q, Q, F> { +impl<'q, 'w, Q: WorldQuery, F: QueryFilter> Iterator for Batch<'q, Q, F> { type Item = >::Item; fn next(&mut self) -> Option { @@ -427,8 +426,8 @@ impl<'q, 'w, Q: Query, F: QueryFilter> Iterator for Batch<'q, Q, F> { } } -unsafe impl<'q, Q: Query, F: QueryFilter> Send for Batch<'q, Q, F> {} -unsafe impl<'q, Q: Query, F: QueryFilter> Sync for Batch<'q, Q, F> {} +unsafe impl<'q, Q: WorldQuery, F: QueryFilter> Send for Batch<'q, Q, F> {} +unsafe impl<'q, Q: WorldQuery, F: QueryFilter> Sync for Batch<'q, Q, F> {} macro_rules! tuple_impl { ($($name: ident),*) => { @@ -456,7 +455,7 @@ macro_rules! tuple_impl { } } - impl<$($name: Query),*> Query for ($($name,)*) { + impl<$($name: WorldQuery),*> WorldQuery for ($($name,)*) { type Fetch = ($($name::Fetch,)*); } @@ -468,10 +467,10 @@ smaller_tuples_too!(tuple_impl, O, N, M, L, K, J, I, H, G, F, E, D, C, B, A); #[cfg(test)] mod tests { - use crate::{Added, Changed, Entity, Mut, Mutated, Or, World}; + use crate::core::{Added, Changed, Component, Entity, Mutated, Or, QueryFilter, World}; use std::{vec, vec::Vec}; - use super::*; + use super::Mut; struct A(usize); struct B(usize); diff --git a/crates/bevy_ecs/hecs/src/serde.rs b/crates/bevy_ecs/src/core/serde.rs similarity index 89% rename from crates/bevy_ecs/hecs/src/serde.rs rename to crates/bevy_ecs/src/core/serde.rs index cddb1060ad4656..680215d8f92f2b 100644 --- a/crates/bevy_ecs/hecs/src/serde.rs +++ b/crates/bevy_ecs/src/core/serde.rs @@ -1,6 +1,6 @@ // modified by Bevy contributors -use crate::entities::Entity; +use crate::Entity; use serde::{Serialize, Serializer}; impl Serialize for Entity { diff --git a/crates/bevy_ecs/hecs/src/world.rs b/crates/bevy_ecs/src/core/world.rs similarity index 95% rename from crates/bevy_ecs/hecs/src/world.rs rename to crates/bevy_ecs/src/core/world.rs index 0f32f08e887087..942e50fd118299 100644 --- a/crates/bevy_ecs/hecs/src/world.rs +++ b/crates/bevy_ecs/src/core/world.rs @@ -15,20 +15,14 @@ // modified by Bevy contributors use crate::{ - alloc::vec::Vec, borrow::EntityRef, filter::EntityFilter, query::ReadOnlyFetch, BatchedIter, - EntityReserver, Fetch, Mut, QueryFilter, QueryIter, RefMut, + core::entities::Entities, Archetype, BatchedIter, Bundle, DynamicBundle, Entity, EntityFilter, + EntityReserver, Fetch, Location, MissingComponent, Mut, NoSuchEntity, QueryFilter, QueryIter, + ReadOnlyFetch, Ref, RefMut, WorldQuery, }; use bevy_utils::{HashMap, HashSet}; -use core::{any::TypeId, fmt, mem, ptr}; +use std::{any::TypeId, fmt, mem, ptr}; -#[cfg(feature = "std")] -use std::error::Error; - -use crate::{ - archetype::Archetype, - entities::{Entities, Location}, - Bundle, DynamicBundle, Entity, MissingComponent, NoSuchEntity, Query, Ref, -}; +use super::borrow::EntityRef; /// An unordered collection of entities, each having any number of distinctly typed components /// @@ -77,7 +71,7 @@ impl World { /// /// # Example /// ``` - /// # use bevy_hecs::*; + /// # use bevy_ecs::*; /// let mut world = World::new(); /// let a = world.spawn((123, "abc")); /// let b = world.spawn((456, true)); @@ -120,7 +114,7 @@ impl World { /// /// # Example /// ``` - /// # use bevy_hecs::*; + /// # use bevy_ecs::*; /// let mut world = World::new(); /// let entities = world.spawn_batch((0..1_000).map(|i| (i, "abc"))).collect::>(); /// for i in 0..1_000 { @@ -237,7 +231,7 @@ impl World { /// /// # Example /// ``` - /// # use bevy_hecs::*; + /// # use bevy_ecs::*; /// let mut world = World::new(); /// let a = world.spawn((123, true, "abc")); /// let b = world.spawn((456, false)); @@ -250,7 +244,7 @@ impl World { /// assert!(entities.contains(&(b, 456, false))); /// ``` #[inline] - pub fn query(&self) -> QueryIter<'_, Q, ()> + pub fn query(&self) -> QueryIter<'_, Q, ()> where Q::Fetch: ReadOnlyFetch, { @@ -259,7 +253,7 @@ impl World { } #[inline] - pub fn query_filtered(&self) -> QueryIter<'_, Q, F> + pub fn query_filtered(&self) -> QueryIter<'_, Q, F> where Q::Fetch: ReadOnlyFetch, { @@ -279,7 +273,7 @@ impl World { /// /// # Example /// ``` - /// # use bevy_hecs::*; + /// # use bevy_ecs::*; /// let mut world = World::new(); /// let a = world.spawn((123, true, "abc")); /// let b = world.spawn((456, false)); @@ -292,13 +286,13 @@ impl World { /// assert!(entities.contains(&(b, 456, false))); /// ``` #[inline] - pub fn query_mut(&mut self) -> QueryIter<'_, Q, ()> { + pub fn query_mut(&mut self) -> QueryIter<'_, Q, ()> { // SAFE: unique mutable access unsafe { self.query_unchecked() } } #[inline] - pub fn query_filtered_mut(&mut self) -> QueryIter<'_, Q, F> { + pub fn query_filtered_mut(&mut self) -> QueryIter<'_, Q, F> { // SAFE: unique mutable access unsafe { self.query_unchecked() } } @@ -306,7 +300,7 @@ impl World { /// Like `query`, but instead of returning a single iterator it returns a "batched iterator", /// where each batch is `batch_size`. This is generally used for parallel iteration. #[inline] - pub fn query_batched(&self, batch_size: usize) -> BatchedIter<'_, Q, ()> + pub fn query_batched(&self, batch_size: usize) -> BatchedIter<'_, Q, ()> where Q::Fetch: ReadOnlyFetch, { @@ -315,7 +309,7 @@ impl World { } #[inline] - pub fn query_batched_filtered( + pub fn query_batched_filtered( &self, batch_size: usize, ) -> BatchedIter<'_, Q, F> @@ -329,13 +323,16 @@ impl World { /// Like `query`, but instead of returning a single iterator it returns a "batched iterator", /// where each batch is `batch_size`. This is generally used for parallel iteration. #[inline] - pub fn query_batched_mut(&mut self, batch_size: usize) -> BatchedIter<'_, Q, ()> { + pub fn query_batched_mut( + &mut self, + batch_size: usize, + ) -> BatchedIter<'_, Q, ()> { // SAFE: unique mutable access unsafe { self.query_batched_unchecked(batch_size) } } #[inline] - pub fn query_batched_filtered_mut( + pub fn query_batched_filtered_mut( &mut self, batch_size: usize, ) -> BatchedIter<'_, Q, F> { @@ -357,7 +354,7 @@ impl World { /// This does not check for mutable query correctness. To be safe, make sure mutable queries /// have unique access to the components they query. #[inline] - pub unsafe fn query_unchecked(&self) -> QueryIter<'_, Q, F> { + pub unsafe fn query_unchecked(&self) -> QueryIter<'_, Q, F> { QueryIter::new(&self.archetypes) } @@ -368,7 +365,7 @@ impl World { /// This does not check for mutable query correctness. To be safe, make sure mutable queries /// have unique access to the components they query. #[inline] - pub unsafe fn query_batched_unchecked( + pub unsafe fn query_batched_unchecked( &self, batch_size: usize, ) -> BatchedIter<'_, Q, F> { @@ -381,7 +378,7 @@ impl World { /// /// # Example /// ``` - /// # use bevy_hecs::*; + /// # use bevy_ecs::*; /// let mut world = World::new(); /// let a = world.spawn((123, true, "abc")); /// // The returned query must outlive the borrow made by `get` @@ -389,7 +386,7 @@ impl World { /// assert_eq!(*number, 123); /// ``` #[inline] - pub fn query_one( + pub fn query_one( &self, entity: Entity, ) -> Result<::Item, NoSuchEntity> @@ -401,7 +398,7 @@ impl World { } #[inline] - pub fn query_one_filtered( + pub fn query_one_filtered( &self, entity: Entity, ) -> Result<::Item, NoSuchEntity> @@ -418,7 +415,7 @@ impl World { /// /// # Example /// ``` - /// # use bevy_hecs::*; + /// # use bevy_ecs::*; /// let mut world = World::new(); /// let a = world.spawn((123, true, "abc")); /// // The returned query must outlive the borrow made by `get` @@ -427,7 +424,7 @@ impl World { /// assert_eq!(*number, 246); /// ``` #[inline] - pub fn query_one_mut( + pub fn query_one_mut( &mut self, entity: Entity, ) -> Result<::Item, NoSuchEntity> { @@ -436,7 +433,7 @@ impl World { } #[inline] - pub fn query_one_filtered_mut( + pub fn query_one_filtered_mut( &mut self, entity: Entity, ) -> Result<::Item, NoSuchEntity> { @@ -452,7 +449,7 @@ impl World { /// This does not check for mutable query correctness. To be safe, make sure mutable queries /// have unique access to the components they query. #[inline] - pub unsafe fn query_one_unchecked( + pub unsafe fn query_one_unchecked( &self, entity: Entity, ) -> Result<::Item, NoSuchEntity> { @@ -530,7 +527,7 @@ impl World { /// /// # Example /// ``` - /// # use bevy_hecs::*; + /// # use bevy_ecs::*; /// let mut world = World::new(); /// let a = world.spawn(()); /// let b = world.spawn(()); @@ -559,7 +556,7 @@ impl World { /// /// # Example /// ``` - /// # use bevy_hecs::*; + /// # use bevy_ecs::*; /// let mut world = World::new(); /// let e = world.spawn((123, "abc")); /// world.insert(e, (456, true)); @@ -662,7 +659,7 @@ impl World { /// /// # Example /// ``` - /// # use bevy_hecs::*; + /// # use bevy_ecs::*; /// let mut world = World::new(); /// let e = world.spawn((123, "abc", true)); /// assert_eq!(world.remove::<(i32, &str)>(e), Ok((123, "abc"))); @@ -873,7 +870,7 @@ impl World { /// /// # Example /// ``` - /// # use bevy_hecs::*; + /// # use bevy_ecs::*; /// let mut world = World::new(); /// let initial_gen = world.archetypes_generation(); /// world.spawn((123, "abc")); diff --git a/crates/bevy_ecs/src/world/world_builder.rs b/crates/bevy_ecs/src/core/world_builder.rs similarity index 96% rename from crates/bevy_ecs/src/world/world_builder.rs rename to crates/bevy_ecs/src/core/world_builder.rs index 3fbb42184b718a..18c450583160c7 100644 --- a/crates/bevy_ecs/src/world/world_builder.rs +++ b/crates/bevy_ecs/src/core/world_builder.rs @@ -1,4 +1,4 @@ -use bevy_hecs::{Bundle, Component, DynamicBundle, Entity, World}; +use crate::{Bundle, Component, DynamicBundle, Entity, World}; /// Converts a reference to `Self` to a [WorldBuilder] pub trait WorldBuilderSource { diff --git a/crates/bevy_ecs/src/lib.rs b/crates/bevy_ecs/src/lib.rs index b48f77be5bbaa7..c90bf23688ada2 100644 --- a/crates/bevy_ecs/src/lib.rs +++ b/crates/bevy_ecs/src/lib.rs @@ -1,19 +1,20 @@ -pub use bevy_hecs::{Query as HecsQuery, *}; +mod core; mod resource; mod schedule; mod system; -mod world; +pub use crate::core::*; +pub use bevy_ecs_macros::*; +pub use lazy_static; pub use resource::*; pub use schedule::*; pub use system::{Query, *}; -pub use world::*; pub mod prelude { pub use crate::{ + core::WorldBuilderSource, resource::{ChangedRes, FromResources, Local, Res, ResMut, Resource, Resources}, system::{Commands, IntoSystem, IntoThreadLocalSystem, Query, System}, - world::WorldBuilderSource, Added, Bundle, Changed, Component, Entity, Mut, Mutated, Or, QuerySet, Ref, RefMut, With, Without, World, }; diff --git a/crates/bevy_ecs/src/resource/resources.rs b/crates/bevy_ecs/src/resource/resources.rs index fc0c9c5a6bcf31..5a67d8af7c0876 100644 --- a/crates/bevy_ecs/src/resource/resources.rs +++ b/crates/bevy_ecs/src/resource/resources.rs @@ -1,5 +1,4 @@ -use crate::system::SystemId; -use bevy_hecs::{Archetype, AtomicBorrow, Entity, Ref, RefMut, TypeInfo, TypeState}; +use crate::{system::SystemId, Archetype, AtomicBorrow, Entity, Ref, RefMut, TypeInfo, TypeState}; use bevy_utils::HashMap; use core::any::TypeId; use downcast_rs::{impl_downcast, Downcast}; diff --git a/crates/bevy_ecs/src/schedule/parallel_executor.rs b/crates/bevy_ecs/src/schedule/parallel_executor.rs index fa9aca958b5977..d0b9aec1af403d 100644 --- a/crates/bevy_ecs/src/schedule/parallel_executor.rs +++ b/crates/bevy_ecs/src/schedule/parallel_executor.rs @@ -2,8 +2,8 @@ use super::Schedule; use crate::{ resource::Resources, system::{System, ThreadLocalExecution}, + ArchetypesGeneration, TypeAccess, World, }; -use bevy_hecs::{ArchetypesGeneration, TypeAccess, World}; use bevy_tasks::{ComputeTaskPool, CountdownEvent, TaskPool}; #[cfg(feature = "trace")] use bevy_utils::tracing::info_span; @@ -553,9 +553,8 @@ mod tests { resource::{Res, ResMut, Resources}, schedule::Schedule, system::{IntoSystem, IntoThreadLocalSystem, Query}, - Commands, + Commands, Entity, World, }; - use bevy_hecs::{Entity, World}; use bevy_tasks::{ComputeTaskPool, TaskPool}; use fixedbitset::FixedBitSet; use parking_lot::Mutex; diff --git a/crates/bevy_ecs/src/schedule/schedule.rs b/crates/bevy_ecs/src/schedule/schedule.rs index 87339caaca36f2..881991c282f8c6 100644 --- a/crates/bevy_ecs/src/schedule/schedule.rs +++ b/crates/bevy_ecs/src/schedule/schedule.rs @@ -1,8 +1,8 @@ use crate::{ resource::Resources, system::{System, SystemId, ThreadLocalExecution}, + World, }; -use bevy_hecs::World; use bevy_utils::{HashMap, HashSet}; use std::{borrow::Cow, fmt}; diff --git a/crates/bevy_ecs/src/system/commands.rs b/crates/bevy_ecs/src/system/commands.rs index 95dbe93e854cef..6e563ac29365f0 100644 --- a/crates/bevy_ecs/src/system/commands.rs +++ b/crates/bevy_ecs/src/system/commands.rs @@ -1,6 +1,8 @@ use super::SystemId; -use crate::resource::{Resource, Resources}; -use bevy_hecs::{Bundle, Component, DynamicBundle, Entity, EntityReserver, World}; +use crate::{ + resource::{Resource, Resources}, + Bundle, Component, DynamicBundle, Entity, EntityReserver, World, +}; use bevy_utils::tracing::debug; use std::marker::PhantomData; @@ -299,9 +301,7 @@ impl Commands { #[cfg(test)] mod tests { - use super::Commands; - use crate::resource::Resources; - use bevy_hecs::World; + use crate::{resource::Resources, Commands, World}; #[test] fn command_buffer() { diff --git a/crates/bevy_ecs/src/system/into_system.rs b/crates/bevy_ecs/src/system/into_system.rs index 548f25a7e7ca5a..a3786b16c58689 100644 --- a/crates/bevy_ecs/src/system/into_system.rs +++ b/crates/bevy_ecs/src/system/into_system.rs @@ -1,5 +1,7 @@ -use crate::{Commands, Resources, System, SystemId, SystemParam, ThreadLocalExecution}; -use bevy_hecs::{ArchetypeComponent, QueryAccess, TypeAccess, World}; +use crate::{ + ArchetypeComponent, Commands, QueryAccess, Resources, System, SystemId, SystemParam, + ThreadLocalExecution, TypeAccess, World, +}; use parking_lot::Mutex; use std::{any::TypeId, borrow::Cow, sync::Arc}; @@ -206,9 +208,8 @@ mod tests { use crate::{ resource::{ResMut, Resources}, schedule::Schedule, - ChangedRes, Query, QuerySet, System, + ChangedRes, Entity, Or, Query, QuerySet, System, With, World, }; - use bevy_hecs::{Entity, Or, With, World}; #[derive(Debug, Eq, PartialEq)] struct A; diff --git a/crates/bevy_ecs/src/system/into_thread_local.rs b/crates/bevy_ecs/src/system/into_thread_local.rs index f029af89b3ef01..876cd94798b3f1 100644 --- a/crates/bevy_ecs/src/system/into_thread_local.rs +++ b/crates/bevy_ecs/src/system/into_thread_local.rs @@ -2,9 +2,8 @@ pub use super::Query; use crate::{ resource::Resources, system::{System, SystemId, ThreadLocalExecution}, - TypeAccess, + ArchetypeComponent, TypeAccess, World, }; -use bevy_hecs::{ArchetypeComponent, World}; use std::{any::TypeId, borrow::Cow}; #[derive(Debug)] diff --git a/crates/bevy_ecs/src/system/query/mod.rs b/crates/bevy_ecs/src/system/query/mod.rs index da4745f20013a8..5fa89aa9d0f1d7 100644 --- a/crates/bevy_ecs/src/system/query/mod.rs +++ b/crates/bevy_ecs/src/system/query/mod.rs @@ -1,17 +1,16 @@ mod query_set; - pub use query_set::*; -use bevy_hecs::{ +use crate::{ ArchetypeComponent, Batch, BatchedIter, Component, ComponentError, Entity, Fetch, Mut, - Query as HecsQuery, QueryFilter, QueryIter, ReadOnlyFetch, TypeAccess, World, + QueryFilter, QueryIter, ReadOnlyFetch, TypeAccess, World, WorldQuery, }; use bevy_tasks::ParallelIterator; use std::marker::PhantomData; /// Provides scoped access to a World according to a given [HecsQuery] #[derive(Debug)] -pub struct Query<'a, Q: HecsQuery, F: QueryFilter = ()> { +pub struct Query<'a, Q: WorldQuery, F: QueryFilter = ()> { pub(crate) world: &'a World, pub(crate) component_access: &'a TypeAccess, _marker: PhantomData<(Q, F)>, @@ -26,7 +25,7 @@ pub enum QueryError { NoSuchEntity, } -impl<'a, Q: HecsQuery, F: QueryFilter> Query<'a, Q, F> { +impl<'a, Q: WorldQuery, F: QueryFilter> Query<'a, Q, F> { /// # Safety /// This will create a Query that could violate memory safety rules. Make sure that this is only called in /// ways that ensure the Queries have unique mutable access. @@ -196,19 +195,19 @@ impl<'a, Q: HecsQuery, F: QueryFilter> Query<'a, Q, F> { } /// Parallel version of QueryIter -pub struct ParIter<'w, Q: HecsQuery, F: QueryFilter> { +pub struct ParIter<'w, Q: WorldQuery, F: QueryFilter> { batched_iter: BatchedIter<'w, Q, F>, } -impl<'w, Q: HecsQuery, F: QueryFilter> ParIter<'w, Q, F> { +impl<'w, Q: WorldQuery, F: QueryFilter> ParIter<'w, Q, F> { pub fn new(batched_iter: BatchedIter<'w, Q, F>) -> Self { Self { batched_iter } } } -unsafe impl<'w, Q: HecsQuery, F: QueryFilter> Send for ParIter<'w, Q, F> {} +unsafe impl<'w, Q: WorldQuery, F: QueryFilter> Send for ParIter<'w, Q, F> {} -impl<'w, Q: HecsQuery, F: QueryFilter> ParallelIterator> for ParIter<'w, Q, F> { +impl<'w, Q: WorldQuery, F: QueryFilter> ParallelIterator> for ParIter<'w, Q, F> { type Item = >::Item; #[inline] diff --git a/crates/bevy_ecs/src/system/query/query_set.rs b/crates/bevy_ecs/src/system/query/query_set.rs index c9b570055be519..5ee1e1f11fa801 100644 --- a/crates/bevy_ecs/src/system/query/query_set.rs +++ b/crates/bevy_ecs/src/system/query/query_set.rs @@ -1,7 +1,6 @@ -use crate::Query; -use bevy_hecs::{ - impl_query_set, ArchetypeComponent, Fetch, Query as HecsQuery, QueryAccess, QueryFilter, - TypeAccess, World, +use crate::{ + impl_query_set, ArchetypeComponent, Fetch, Query, QueryAccess, QueryFilter, TypeAccess, World, + WorldQuery, }; pub struct QuerySet { diff --git a/crates/bevy_ecs/src/system/system.rs b/crates/bevy_ecs/src/system/system.rs index d2f1600df40f40..24a5e015f99698 100644 --- a/crates/bevy_ecs/src/system/system.rs +++ b/crates/bevy_ecs/src/system/system.rs @@ -1,5 +1,4 @@ -use crate::resource::Resources; -use bevy_hecs::{ArchetypeComponent, TypeAccess, World}; +use crate::{ArchetypeComponent, Resources, TypeAccess, World}; use std::{any::TypeId, borrow::Cow}; /// Determines the strategy used to run the `run_thread_local` function in a [System] diff --git a/crates/bevy_ecs/src/system/system_param.rs b/crates/bevy_ecs/src/system/system_param.rs index 047778d56e1279..4ecb22a5092697 100644 --- a/crates/bevy_ecs/src/system/system_param.rs +++ b/crates/bevy_ecs/src/system/system_param.rs @@ -1,10 +1,7 @@ use crate::{ - ChangedRes, Commands, FromResources, Local, Query, QueryAccess, QuerySet, QueryTuple, Res, - ResMut, Resource, ResourceIndex, Resources, SystemState, -}; -pub use bevy_hecs::SystemParam; -use bevy_hecs::{ - ArchetypeComponent, Fetch, Or, Query as HecsQuery, QueryFilter, TypeAccess, World, + ArchetypeComponent, ChangedRes, Commands, Fetch, FromResources, Local, Or, Query, QueryAccess, + QueryFilter, QuerySet, QueryTuple, Res, ResMut, Resource, ResourceIndex, Resources, + SystemState, TypeAccess, World, WorldQuery, }; use parking_lot::Mutex; use std::{any::TypeId, sync::Arc}; @@ -21,7 +18,7 @@ pub trait SystemParam: Sized { ) -> Option; } -impl<'a, Q: HecsQuery, F: QueryFilter> SystemParam for Query<'a, Q, F> { +impl<'a, Q: WorldQuery, F: QueryFilter> SystemParam for Query<'a, Q, F> { #[inline] unsafe fn get_param( system_state: &mut SystemState, diff --git a/crates/bevy_ecs/hecs/tests/tests.rs b/crates/bevy_ecs/src/tests/tests.rs similarity index 99% rename from crates/bevy_ecs/hecs/tests/tests.rs rename to crates/bevy_ecs/src/tests/tests.rs index e0f9920ee9ed7a..8054d8444ec08e 100644 --- a/crates/bevy_ecs/hecs/tests/tests.rs +++ b/crates/bevy_ecs/src/tests/tests.rs @@ -14,7 +14,7 @@ // modified by Bevy contributors -use bevy_hecs::*; +use bevy_ecs::*; #[test] fn random_access() { diff --git a/crates/bevy_ecs/src/world/mod.rs b/crates/bevy_ecs/src/world/mod.rs deleted file mode 100644 index 3e59bd70aea1b0..00000000000000 --- a/crates/bevy_ecs/src/world/mod.rs +++ /dev/null @@ -1,5 +0,0 @@ -mod entity_map; -mod world_builder; - -pub use entity_map::*; -pub use world_builder::*; diff --git a/crates/bevy_gltf/src/loader.rs b/crates/bevy_gltf/src/loader.rs index 5131ab4dc0855f..454159b181d519 100644 --- a/crates/bevy_gltf/src/loader.rs +++ b/crates/bevy_gltf/src/loader.rs @@ -2,7 +2,7 @@ use anyhow::Result; use bevy_asset::{AssetIoError, AssetLoader, AssetPath, LoadContext, LoadedAsset}; use bevy_ecs::{bevy_utils::BoxedFuture, World, WorldBuilderSource}; use bevy_math::Mat4; -use bevy_pbr::prelude::{PbrComponents, StandardMaterial}; +use bevy_pbr::prelude::{PbrBundle, StandardMaterial}; use bevy_render::{ camera::{ Camera, CameraProjection, OrthographicProjection, PerspectiveProjection, VisibleEntities, @@ -280,7 +280,7 @@ fn load_node( let material_label = material_label(&material); let material_asset_path = AssetPath::new_ref(load_context.path(), Some(&material_label)); - parent.spawn(PbrComponents { + parent.spawn(PbrBundle { mesh: load_context.get_handle(mesh_asset_path), material: load_context.get_handle(material_asset_path), ..Default::default() diff --git a/crates/bevy_pbr/src/entity.rs b/crates/bevy_pbr/src/entity.rs index eab323b091c9b5..4c355e90b2d892 100644 --- a/crates/bevy_pbr/src/entity.rs +++ b/crates/bevy_pbr/src/entity.rs @@ -11,7 +11,7 @@ use bevy_transform::prelude::{GlobalTransform, Transform}; /// A component bundle for "pbr mesh" entities #[derive(Bundle)] -pub struct PbrComponents { +pub struct PbrBundle { pub mesh: Handle, pub material: Handle, pub main_pass: MainPass, @@ -21,7 +21,7 @@ pub struct PbrComponents { pub global_transform: GlobalTransform, } -impl Default for PbrComponents { +impl Default for PbrBundle { fn default() -> Self { Self { render_pipelines: RenderPipelines::from_pipelines(vec![RenderPipeline::new( @@ -39,7 +39,7 @@ impl Default for PbrComponents { /// A component bundle for "light" entities #[derive(Debug, Bundle, Default)] -pub struct LightComponents { +pub struct LightBundle { pub light: Light, pub transform: Transform, pub global_transform: GlobalTransform, diff --git a/crates/bevy_render/src/entity.rs b/crates/bevy_render/src/entity.rs index 384f66b638d721..efc65ca7c97abb 100644 --- a/crates/bevy_render/src/entity.rs +++ b/crates/bevy_render/src/entity.rs @@ -12,7 +12,7 @@ use bevy_transform::components::{GlobalTransform, Transform}; /// A component bundle for "mesh" entities #[derive(Bundle, Default)] -pub struct MeshComponents { +pub struct MeshBundle { pub mesh: Handle, pub draw: Draw, pub render_pipelines: RenderPipelines, @@ -23,7 +23,7 @@ pub struct MeshComponents { /// A component bundle for "3d camera" entities #[derive(Bundle)] -pub struct Camera3dComponents { +pub struct Camera3dBundle { pub camera: Camera, pub perspective_projection: PerspectiveProjection, pub visible_entities: VisibleEntities, @@ -31,9 +31,9 @@ pub struct Camera3dComponents { pub global_transform: GlobalTransform, } -impl Default for Camera3dComponents { +impl Default for Camera3dBundle { fn default() -> Self { - Camera3dComponents { + Camera3dBundle { camera: Camera { name: Some(base::camera::CAMERA3D.to_string()), ..Default::default() @@ -48,7 +48,7 @@ impl Default for Camera3dComponents { /// A component bundle for "2d camera" entities #[derive(Bundle)] -pub struct Camera2dComponents { +pub struct Camera2dBundle { pub camera: Camera, pub orthographic_projection: OrthographicProjection, pub visible_entities: VisibleEntities, @@ -56,12 +56,12 @@ pub struct Camera2dComponents { pub global_transform: GlobalTransform, } -impl Default for Camera2dComponents { +impl Default for Camera2dBundle { fn default() -> Self { // we want 0 to be "closest" and +far to be "farthest" in 2d, so we offset // the camera's translation by far and use a right handed coordinate system let far = 1000.0; - Camera2dComponents { + Camera2dBundle { camera: Camera { name: Some(base::camera::CAMERA2D.to_string()), ..Default::default() diff --git a/crates/bevy_render/src/render_graph/nodes/pass_node.rs b/crates/bevy_render/src/render_graph/nodes/pass_node.rs index aefe11f92b062e..d0c130d14c45fd 100644 --- a/crates/bevy_render/src/render_graph/nodes/pass_node.rs +++ b/crates/bevy_render/src/render_graph/nodes/pass_node.rs @@ -12,7 +12,7 @@ use crate::{ }, }; use bevy_asset::{Assets, Handle}; -use bevy_ecs::{HecsQuery, ReadOnlyFetch, Resources, World}; +use bevy_ecs::{ReadOnlyFetch, Resources, World, WorldQuery}; use bevy_utils::tracing::debug; use std::{fmt, marker::PhantomData, ops::Deref}; @@ -22,7 +22,7 @@ struct CameraInfo { bind_group_id: Option, } -pub struct PassNode { +pub struct PassNode { descriptor: PassDescriptor, inputs: Vec, cameras: Vec, @@ -34,7 +34,7 @@ pub struct PassNode { _marker: PhantomData, } -impl fmt::Debug for PassNode { +impl fmt::Debug for PassNode { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.debug_struct("PassNose") .field("descriptor", &self.descriptor) @@ -64,7 +64,7 @@ impl fmt::Debug for PassNode { } } -impl PassNode { +impl PassNode { pub fn new(descriptor: PassDescriptor) -> Self { let mut inputs = Vec::new(); let mut color_attachment_input_indices = Vec::new(); @@ -140,7 +140,7 @@ impl PassNode { } } -impl Node for PassNode +impl Node for PassNode where Q::Fetch: ReadOnlyFetch, { diff --git a/crates/bevy_sprite/src/entity.rs b/crates/bevy_sprite/src/entity.rs index 2296796a23450f..ace55688b503a0 100644 --- a/crates/bevy_sprite/src/entity.rs +++ b/crates/bevy_sprite/src/entity.rs @@ -13,7 +13,7 @@ use bevy_render::{ use bevy_transform::prelude::{GlobalTransform, Transform}; #[derive(Bundle)] -pub struct SpriteComponents { +pub struct SpriteBundle { pub sprite: Sprite, pub mesh: Handle, // TODO: maybe abstract this out pub material: Handle, @@ -24,7 +24,7 @@ pub struct SpriteComponents { pub global_transform: GlobalTransform, } -impl Default for SpriteComponents { +impl Default for SpriteBundle { fn default() -> Self { Self { mesh: QUAD_HANDLE, @@ -47,7 +47,7 @@ impl Default for SpriteComponents { /// A Bundle of components for drawing a single sprite from a sprite sheet (also referred /// to as a `TextureAtlas`) #[derive(Bundle)] -pub struct SpriteSheetComponents { +pub struct SpriteSheetBundle { /// The specific sprite from the texture atlas to be drawn pub sprite: TextureAtlasSprite, /// A handle to the texture atlas that holds the sprite images @@ -61,7 +61,7 @@ pub struct SpriteSheetComponents { pub global_transform: GlobalTransform, } -impl Default for SpriteSheetComponents { +impl Default for SpriteSheetBundle { fn default() -> Self { Self { render_pipelines: RenderPipelines::from_pipelines(vec![RenderPipeline::new( diff --git a/crates/bevy_sprite/src/lib.rs b/crates/bevy_sprite/src/lib.rs index d7107e2e2415fa..4fecd67d29006c 100644 --- a/crates/bevy_sprite/src/lib.rs +++ b/crates/bevy_sprite/src/lib.rs @@ -19,7 +19,7 @@ pub use texture_atlas_builder::*; pub mod prelude { pub use crate::{ - entity::{SpriteComponents, SpriteSheetComponents}, + entity::{SpriteBundle, SpriteSheetBundle}, ColorMaterial, Sprite, SpriteResizeMode, TextureAtlas, TextureAtlasSprite, }; } diff --git a/crates/bevy_ui/src/entity.rs b/crates/bevy_ui/src/entity.rs index a0c050e7aafc88..41c01b30e11753 100644 --- a/crates/bevy_ui/src/entity.rs +++ b/crates/bevy_ui/src/entity.rs @@ -17,7 +17,7 @@ use bevy_sprite::{ColorMaterial, QUAD_HANDLE}; use bevy_transform::prelude::{GlobalTransform, Transform}; #[derive(Bundle, Clone, Debug)] -pub struct NodeComponents { +pub struct NodeBundle { pub node: Node, pub style: Style, pub mesh: Handle, // TODO: maybe abstract this out @@ -28,9 +28,9 @@ pub struct NodeComponents { pub global_transform: GlobalTransform, } -impl Default for NodeComponents { +impl Default for NodeBundle { fn default() -> Self { - NodeComponents { + NodeBundle { mesh: QUAD_HANDLE, render_pipelines: RenderPipelines::from_pipelines(vec![RenderPipeline::new( UI_PIPELINE_HANDLE, @@ -46,7 +46,7 @@ impl Default for NodeComponents { } #[derive(Bundle, Clone, Debug)] -pub struct ImageComponents { +pub struct ImageBundle { pub node: Node, pub style: Style, pub image: Image, @@ -59,9 +59,9 @@ pub struct ImageComponents { pub global_transform: GlobalTransform, } -impl Default for ImageComponents { +impl Default for ImageBundle { fn default() -> Self { - ImageComponents { + ImageBundle { mesh: QUAD_HANDLE, render_pipelines: RenderPipelines::from_pipelines(vec![RenderPipeline::new( UI_PIPELINE_HANDLE, @@ -79,7 +79,7 @@ impl Default for ImageComponents { } #[derive(Bundle, Clone, Debug)] -pub struct TextComponents { +pub struct TextBundle { pub node: Node, pub style: Style, pub draw: Draw, @@ -90,9 +90,9 @@ pub struct TextComponents { pub global_transform: GlobalTransform, } -impl Default for TextComponents { +impl Default for TextBundle { fn default() -> Self { - TextComponents { + TextBundle { focus_policy: FocusPolicy::Pass, draw: Draw { is_transparent: true, @@ -109,7 +109,7 @@ impl Default for TextComponents { } #[derive(Bundle, Clone, Debug)] -pub struct ButtonComponents { +pub struct ButtonBundle { pub node: Node, pub button: Button, pub style: Style, @@ -123,9 +123,9 @@ pub struct ButtonComponents { pub global_transform: GlobalTransform, } -impl Default for ButtonComponents { +impl Default for ButtonBundle { fn default() -> Self { - ButtonComponents { + ButtonBundle { button: Button, mesh: QUAD_HANDLE, render_pipelines: RenderPipelines::from_pipelines(vec![RenderPipeline::new( @@ -144,7 +144,7 @@ impl Default for ButtonComponents { } #[derive(Bundle, Debug)] -pub struct UiCameraComponents { +pub struct UiCameraBundle { pub camera: Camera, pub orthographic_projection: OrthographicProjection, pub visible_entities: VisibleEntities, @@ -152,12 +152,12 @@ pub struct UiCameraComponents { pub global_transform: GlobalTransform, } -impl Default for UiCameraComponents { +impl Default for UiCameraBundle { fn default() -> Self { // we want 0 to be "closest" and +far to be "farthest" in 2d, so we offset // the camera's translation by far and use a right handed coordinate system let far = 1000.0; - UiCameraComponents { + UiCameraBundle { camera: Camera { name: Some(crate::camera::UI_CAMERA.to_string()), ..Default::default() diff --git a/examples/2d/contributors.rs b/examples/2d/contributors.rs index c11322a2942ddd..ec326bc39e107e 100644 --- a/examples/2d/contributors.rs +++ b/examples/2d/contributors.rs @@ -55,8 +55,8 @@ fn setup( let texture_handle = asset_server.load("branding/icon.png"); commands - .spawn(Camera2dComponents::default()) - .spawn(UiCameraComponents::default()); + .spawn(Camera2dBundle::default()) + .spawn(UiCameraBundle::default()); let mut sel = ContributorSelection { order: vec![], @@ -83,7 +83,7 @@ fn setup( translation: velocity, rotation: -dir * 5.0, }) - .with_bundle(SpriteComponents { + .with_bundle(SpriteBundle { sprite: Sprite { size: Vec2::new(1.0, 1.0) * SPRITE_SIZE, resize_mode: SpriteResizeMode::Manual, @@ -107,7 +107,7 @@ fn setup( commands .spawn((ContributorDisplay,)) - .with_bundle(TextComponents { + .with_bundle(TextBundle { style: Style { align_self: AlignSelf::FlexEnd, ..Default::default() diff --git a/examples/2d/sprite.rs b/examples/2d/sprite.rs index 3e12a7068fb13a..2d8f298c3e1da1 100644 --- a/examples/2d/sprite.rs +++ b/examples/2d/sprite.rs @@ -14,8 +14,8 @@ fn setup( ) { let texture_handle = asset_server.load("branding/icon.png"); commands - .spawn(Camera2dComponents::default()) - .spawn(SpriteComponents { + .spawn(Camera2dBundle::default()) + .spawn(SpriteBundle { material: materials.add(texture_handle.into()), ..Default::default() }); diff --git a/examples/2d/sprite_sheet.rs b/examples/2d/sprite_sheet.rs index 4af3f2aab18935..91a38bd541d70c 100644 --- a/examples/2d/sprite_sheet.rs +++ b/examples/2d/sprite_sheet.rs @@ -29,8 +29,8 @@ fn setup( let texture_atlas = TextureAtlas::from_grid(texture_handle, Vec2::new(24.0, 24.0), 7, 1); let texture_atlas_handle = texture_atlases.add(texture_atlas); commands - .spawn(Camera2dComponents::default()) - .spawn(SpriteSheetComponents { + .spawn(Camera2dBundle::default()) + .spawn(SpriteSheetBundle { texture_atlas: texture_atlas_handle, transform: Transform::from_scale(Vec3::splat(6.0)), ..Default::default() diff --git a/examples/2d/texture_atlas.rs b/examples/2d/texture_atlas.rs index 564ce5d8a74ac9..3a324b2c266ce1 100644 --- a/examples/2d/texture_atlas.rs +++ b/examples/2d/texture_atlas.rs @@ -50,9 +50,9 @@ fn load_atlas( // set up a scene to display our texture atlas commands - .spawn(Camera2dComponents::default()) + .spawn(Camera2dBundle::default()) // draw a sprite from the atlas - .spawn(SpriteSheetComponents { + .spawn(SpriteSheetBundle { transform: Transform { translation: Vec3::new(150.0, 0.0, 0.0), scale: Vec3::splat(4.0), @@ -63,7 +63,7 @@ fn load_atlas( ..Default::default() }) // draw the atlas itself - .spawn(SpriteComponents { + .spawn(SpriteBundle { material: materials.add(texture_atlas_texture.into()), transform: Transform::from_translation(Vec3::new(-300.0, 0.0, 0.0)), ..Default::default() diff --git a/examples/3d/3d_scene.rs b/examples/3d/3d_scene.rs index 5d42e4a903b2c9..4a47609c31531c 100644 --- a/examples/3d/3d_scene.rs +++ b/examples/3d/3d_scene.rs @@ -17,25 +17,25 @@ fn setup( // add entities to the world commands // plane - .spawn(PbrComponents { + .spawn(PbrBundle { mesh: meshes.add(Mesh::from(shape::Plane { size: 10.0 })), material: materials.add(Color::rgb(0.3, 0.5, 0.3).into()), ..Default::default() }) // cube - .spawn(PbrComponents { + .spawn(PbrBundle { mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), material: materials.add(Color::rgb(0.8, 0.7, 0.6).into()), transform: Transform::from_translation(Vec3::new(0.0, 1.0, 0.0)), ..Default::default() }) // light - .spawn(LightComponents { + .spawn(LightBundle { transform: Transform::from_translation(Vec3::new(4.0, 8.0, 4.0)), ..Default::default() }) // camera - .spawn(Camera3dComponents { + .spawn(Camera3dBundle { transform: Transform::from_translation(Vec3::new(-3.0, 5.0, 8.0)) .looking_at(Vec3::default(), Vec3::unit_y()), ..Default::default() diff --git a/examples/3d/load_gltf.rs b/examples/3d/load_gltf.rs index f8786c0c210c76..e374970f3038de 100644 --- a/examples/3d/load_gltf.rs +++ b/examples/3d/load_gltf.rs @@ -11,11 +11,11 @@ fn main() { fn setup(commands: &mut Commands, asset_server: Res) { commands .spawn_scene(asset_server.load("models/FlightHelmet/FlightHelmet.gltf")) - .spawn(LightComponents { + .spawn(LightBundle { transform: Transform::from_translation(Vec3::new(4.0, 5.0, 4.0)), ..Default::default() }) - .spawn(Camera3dComponents { + .spawn(Camera3dBundle { transform: Transform::from_translation(Vec3::new(0.7, 0.7, 1.0)) .looking_at(Vec3::new(0.0, 0.3, 0.0), Vec3::unit_y()), ..Default::default() diff --git a/examples/3d/msaa.rs b/examples/3d/msaa.rs index 43b6d1b1c4fa86..f3c2f51584cbe4 100644 --- a/examples/3d/msaa.rs +++ b/examples/3d/msaa.rs @@ -20,18 +20,18 @@ fn setup( // add entities to the world commands // cube - .spawn(PbrComponents { + .spawn(PbrBundle { mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), material: materials.add(Color::rgb(0.8, 0.7, 0.6).into()), ..Default::default() }) // light - .spawn(LightComponents { + .spawn(LightBundle { transform: Transform::from_translation(Vec3::new(4.0, 8.0, 4.0)), ..Default::default() }) // camera - .spawn(Camera3dComponents { + .spawn(Camera3dBundle { transform: Transform::from_translation(Vec3::new(-3.0, 3.0, 5.0)) .looking_at(Vec3::default(), Vec3::unit_y()), ..Default::default() diff --git a/examples/3d/parenting.rs b/examples/3d/parenting.rs index facd2fce78ea4d..5d2f6425135e83 100644 --- a/examples/3d/parenting.rs +++ b/examples/3d/parenting.rs @@ -35,7 +35,7 @@ fn setup( commands // parent cube - .spawn(PbrComponents { + .spawn(PbrBundle { mesh: cube_handle.clone(), material: cube_material_handle.clone(), transform: Transform::from_translation(Vec3::new(0.0, 0.0, 1.0)), @@ -44,7 +44,7 @@ fn setup( .with(Rotator) .with_children(|parent| { // child cube - parent.spawn(PbrComponents { + parent.spawn(PbrBundle { mesh: cube_handle, material: cube_material_handle, transform: Transform::from_translation(Vec3::new(0.0, 0.0, 3.0)), @@ -52,12 +52,12 @@ fn setup( }); }) // light - .spawn(LightComponents { + .spawn(LightBundle { transform: Transform::from_translation(Vec3::new(4.0, 5.0, -4.0)), ..Default::default() }) // camera - .spawn(Camera3dComponents { + .spawn(Camera3dBundle { transform: Transform::from_translation(Vec3::new(5.0, 10.0, 10.0)) .looking_at(Vec3::default(), Vec3::unit_y()), ..Default::default() diff --git a/examples/3d/spawner.rs b/examples/3d/spawner.rs index 3555eade2c642f..242ef42efe2094 100644 --- a/examples/3d/spawner.rs +++ b/examples/3d/spawner.rs @@ -38,12 +38,12 @@ fn setup( ) { commands // light - .spawn(LightComponents { + .spawn(LightBundle { transform: Transform::from_translation(Vec3::new(4.0, -4.0, 5.0)), ..Default::default() }) // camera - .spawn(Camera3dComponents { + .spawn(Camera3dBundle { transform: Transform::from_translation(Vec3::new(0.0, 15.0, 150.0)) .looking_at(Vec3::default(), Vec3::unit_y()), ..Default::default() @@ -52,7 +52,7 @@ fn setup( let mut rng = StdRng::from_entropy(); let cube_handle = meshes.add(Mesh::from(shape::Cube { size: 1.0 })); for _ in 0..10000 { - commands.spawn(PbrComponents { + commands.spawn(PbrBundle { mesh: cube_handle.clone(), material: materials.add(StandardMaterial { albedo: Color::rgb( diff --git a/examples/3d/texture.rs b/examples/3d/texture.rs index a510c7dded481e..8a3b20eb40b6b1 100644 --- a/examples/3d/texture.rs +++ b/examples/3d/texture.rs @@ -50,7 +50,7 @@ fn setup( // add entities to the world commands // textured quad - normal - .spawn(PbrComponents { + .spawn(PbrBundle { mesh: quad_handle.clone(), material: material_handle, transform: Transform { @@ -65,7 +65,7 @@ fn setup( ..Default::default() }) // textured quad - modulated - .spawn(PbrComponents { + .spawn(PbrBundle { mesh: quad_handle.clone(), material: red_material_handle, transform: Transform { @@ -80,7 +80,7 @@ fn setup( ..Default::default() }) // textured quad - modulated - .spawn(PbrComponents { + .spawn(PbrBundle { mesh: quad_handle, material: blue_material_handle, transform: Transform { @@ -95,7 +95,7 @@ fn setup( ..Default::default() }) // camera - .spawn(Camera3dComponents { + .spawn(Camera3dBundle { transform: Transform::from_translation(Vec3::new(3.0, 5.0, 8.0)) .looking_at(Vec3::default(), Vec3::unit_y()), ..Default::default() diff --git a/examples/3d/z_sort_debug.rs b/examples/3d/z_sort_debug.rs index 598b6c0793110c..215e32eea86e4e 100644 --- a/examples/3d/z_sort_debug.rs +++ b/examples/3d/z_sort_debug.rs @@ -49,7 +49,7 @@ fn setup( let cube_handle = meshes.add(Mesh::from(shape::Cube { size: 1.0 })); commands // parent cube - .spawn(PbrComponents { + .spawn(PbrBundle { mesh: cube_handle.clone(), material: materials.add(StandardMaterial { shaded: false, @@ -62,7 +62,7 @@ fn setup( .with_children(|parent| { // child cubes parent - .spawn(PbrComponents { + .spawn(PbrBundle { mesh: cube_handle.clone(), material: materials.add(StandardMaterial { shaded: false, @@ -71,7 +71,7 @@ fn setup( transform: Transform::from_translation(Vec3::new(0.0, 3.0, 0.0)), ..Default::default() }) - .spawn(PbrComponents { + .spawn(PbrBundle { mesh: cube_handle, material: materials.add(StandardMaterial { shaded: false, @@ -82,7 +82,7 @@ fn setup( }); }) // camera - .spawn(Camera3dComponents { + .spawn(Camera3dBundle { transform: Transform::from_translation(Vec3::new(5.0, 10.0, 10.0)) .looking_at(Vec3::default(), Vec3::unit_y()), ..Default::default() diff --git a/examples/android/android.rs b/examples/android/android.rs index 242c16c6987c30..915c6c870eda96 100644 --- a/examples/android/android.rs +++ b/examples/android/android.rs @@ -19,25 +19,25 @@ fn setup( // add entities to the world commands // plane - .spawn(PbrComponents { + .spawn(PbrBundle { mesh: meshes.add(Mesh::from(shape::Plane { size: 10.0 })), material: materials.add(Color::rgb(0.3, 0.5, 0.3).into()), ..Default::default() }) // cube - .spawn(PbrComponents { + .spawn(PbrBundle { mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), material: materials.add(Color::rgb(0.8, 0.7, 0.6).into()), transform: Transform::from_translation(Vec3::new(0.0, 1.0, 0.0)), ..Default::default() }) // light - .spawn(LightComponents { + .spawn(LightBundle { transform: Transform::from_translation(Vec3::new(4.0, 8.0, 4.0)), ..Default::default() }) // camera - .spawn(Camera3dComponents { + .spawn(Camera3dBundle { transform: Transform::from_translation(Vec3::new(-3.0, 5.0, 8.0)) .looking_at(Vec3::default(), Vec3::unit_y()), ..Default::default() diff --git a/examples/asset/asset_loading.rs b/examples/asset/asset_loading.rs index 6f8921527c3552..793f4685046e05 100644 --- a/examples/asset/asset_loading.rs +++ b/examples/asset/asset_loading.rs @@ -44,33 +44,33 @@ fn setup( // Add entities to the world: commands // monkey - .spawn(PbrComponents { + .spawn(PbrBundle { mesh: monkey_handle, material: material_handle.clone(), transform: Transform::from_translation(Vec3::new(-3.0, 0.0, 0.0)), ..Default::default() }) // cube - .spawn(PbrComponents { + .spawn(PbrBundle { mesh: cube_handle, material: material_handle.clone(), transform: Transform::from_translation(Vec3::new(0.0, 0.0, 0.0)), ..Default::default() }) // sphere - .spawn(PbrComponents { + .spawn(PbrBundle { mesh: sphere_handle, material: material_handle, transform: Transform::from_translation(Vec3::new(3.0, 0.0, 0.0)), ..Default::default() }) // light - .spawn(LightComponents { + .spawn(LightBundle { transform: Transform::from_translation(Vec3::new(4.0, 5.0, 4.0)), ..Default::default() }) // camera - .spawn(Camera3dComponents { + .spawn(Camera3dBundle { transform: Transform::from_translation(Vec3::new(0.0, 3.0, 10.0)) .looking_at(Vec3::default(), Vec3::unit_y()), ..Default::default() diff --git a/examples/asset/hot_asset_reloading.rs b/examples/asset/hot_asset_reloading.rs index dd2b42719811a4..cf542a48e9355c 100644 --- a/examples/asset/hot_asset_reloading.rs +++ b/examples/asset/hot_asset_reloading.rs @@ -25,12 +25,12 @@ fn setup(commands: &mut Commands, asset_server: Res) { // mesh .spawn_scene(scene_handle) // light - .spawn(LightComponents { + .spawn(LightBundle { transform: Transform::from_translation(Vec3::new(4.0, 5.0, 4.0)), ..Default::default() }) // camera - .spawn(Camera3dComponents { + .spawn(Camera3dBundle { transform: Transform::from_translation(Vec3::new(2.0, 2.0, 6.0)) .looking_at(Vec3::default(), Vec3::unit_y()), ..Default::default() diff --git a/examples/ecs/hierarchy.rs b/examples/ecs/hierarchy.rs index 00a50ffa67b784..5de54e1ad14c87 100644 --- a/examples/ecs/hierarchy.rs +++ b/examples/ecs/hierarchy.rs @@ -13,12 +13,12 @@ fn setup( asset_server: Res, mut materials: ResMut>, ) { - commands.spawn(Camera2dComponents::default()); + commands.spawn(Camera2dBundle::default()); let texture = asset_server.load("branding/icon.png"); // Spawn a root entity with no parent let parent = commands - .spawn(SpriteComponents { + .spawn(SpriteBundle { transform: Transform::from_scale(Vec3::splat(0.75)), material: materials.add(ColorMaterial { color: Color::WHITE, @@ -29,7 +29,7 @@ fn setup( // With that entity as a parent, run a lambda that spawns its children .with_children(|parent| { // parent is a ChildBuilder, which has a similar API to Commands - parent.spawn(SpriteComponents { + parent.spawn(SpriteBundle { transform: Transform { translation: Vec3::new(250.0, 0.0, 0.0), scale: Vec3::splat(0.75), @@ -50,7 +50,7 @@ fn setup( // which would be added automatically to parents with other methods. // Similarly, adding a Parent component will automatically add a Children component to the parent. commands - .spawn(SpriteComponents { + .spawn(SpriteBundle { transform: Transform { translation: Vec3::new(-250.0, 0.0, 0.0), scale: Vec3::splat(0.75), @@ -68,7 +68,7 @@ fn setup( // Another way is to use the push_children function to add children after the parent // entity has already been spawned. let child = commands - .spawn(SpriteComponents { + .spawn(SpriteBundle { transform: Transform { translation: Vec3::new(0.0, 250.0, 0.0), scale: Vec3::splat(0.75), diff --git a/examples/ecs/parallel_query.rs b/examples/ecs/parallel_query.rs index af9be4e7a6c5a3..4d74fac3fb2b7f 100644 --- a/examples/ecs/parallel_query.rs +++ b/examples/ecs/parallel_query.rs @@ -8,12 +8,12 @@ fn spawn_system( asset_server: Res, mut materials: ResMut>, ) { - commands.spawn(Camera2dComponents::default()); + commands.spawn(Camera2dBundle::default()); let texture_handle = asset_server.load("branding/icon.png"); let material = materials.add(texture_handle.into()); for _ in 0..128 { commands - .spawn(SpriteComponents { + .spawn(SpriteBundle { material: material.clone(), transform: Transform::from_scale(Vec3::splat(0.1)), ..Default::default() diff --git a/examples/game/breakout.rs b/examples/game/breakout.rs index 2fd3d8331b1d7a..918f264b05b620 100644 --- a/examples/game/breakout.rs +++ b/examples/game/breakout.rs @@ -44,10 +44,10 @@ fn setup( // Add the game's entities to our world commands // cameras - .spawn(Camera2dComponents::default()) - .spawn(UiCameraComponents::default()) + .spawn(Camera2dBundle::default()) + .spawn(UiCameraBundle::default()) // paddle - .spawn(SpriteComponents { + .spawn(SpriteBundle { material: materials.add(Color::rgb(0.5, 0.5, 1.0).into()), transform: Transform::from_translation(Vec3::new(0.0, -215.0, 0.0)), sprite: Sprite::new(Vec2::new(120.0, 30.0)), @@ -56,7 +56,7 @@ fn setup( .with(Paddle { speed: 500.0 }) .with(Collider::Paddle) // ball - .spawn(SpriteComponents { + .spawn(SpriteBundle { material: materials.add(Color::rgb(1.0, 0.5, 0.5).into()), transform: Transform::from_translation(Vec3::new(0.0, -50.0, 1.0)), sprite: Sprite::new(Vec2::new(30.0, 30.0)), @@ -66,7 +66,7 @@ fn setup( velocity: 400.0 * Vec3::new(0.5, -0.5, 0.0).normalize(), }) // scoreboard - .spawn(TextComponents { + .spawn(TextBundle { text: Text { font: asset_server.load("fonts/FiraSans-Bold.ttf"), value: "Score:".to_string(), @@ -95,7 +95,7 @@ fn setup( commands // left - .spawn(SpriteComponents { + .spawn(SpriteBundle { material: wall_material.clone(), transform: Transform::from_translation(Vec3::new(-bounds.x() / 2.0, 0.0, 0.0)), sprite: Sprite::new(Vec2::new(wall_thickness, bounds.y() + wall_thickness)), @@ -103,7 +103,7 @@ fn setup( }) .with(Collider::Solid) // right - .spawn(SpriteComponents { + .spawn(SpriteBundle { material: wall_material.clone(), transform: Transform::from_translation(Vec3::new(bounds.x() / 2.0, 0.0, 0.0)), sprite: Sprite::new(Vec2::new(wall_thickness, bounds.y() + wall_thickness)), @@ -111,7 +111,7 @@ fn setup( }) .with(Collider::Solid) // bottom - .spawn(SpriteComponents { + .spawn(SpriteBundle { material: wall_material.clone(), transform: Transform::from_translation(Vec3::new(0.0, -bounds.y() / 2.0, 0.0)), sprite: Sprite::new(Vec2::new(bounds.x() + wall_thickness, wall_thickness)), @@ -119,7 +119,7 @@ fn setup( }) .with(Collider::Solid) // top - .spawn(SpriteComponents { + .spawn(SpriteBundle { material: wall_material, transform: Transform::from_translation(Vec3::new(0.0, bounds.y() / 2.0, 0.0)), sprite: Sprite::new(Vec2::new(bounds.x() + wall_thickness, wall_thickness)), @@ -146,7 +146,7 @@ fn setup( ) + bricks_offset; commands // brick - .spawn(SpriteComponents { + .spawn(SpriteBundle { material: brick_material.clone(), sprite: Sprite::new(brick_size), transform: Transform::from_translation(brick_position), diff --git a/examples/ios/src/lib.rs b/examples/ios/src/lib.rs index 7822af3d4453d1..47b5fe673ac81b 100644 --- a/examples/ios/src/lib.rs +++ b/examples/ios/src/lib.rs @@ -24,20 +24,20 @@ fn setup( // add entities to the world commands // plane - .spawn(PbrComponents { + .spawn(PbrBundle { mesh: meshes.add(Mesh::from(shape::Plane { size: 10.0 })), material: materials.add(Color::rgb(0.1, 0.2, 0.1).into()), ..Default::default() }) // cube - .spawn(PbrComponents { + .spawn(PbrBundle { mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), material: materials.add(Color::rgb(0.5, 0.4, 0.3).into()), transform: Transform::from_translation(Vec3::new(0.0, 1.0, 0.0)), ..Default::default() }) // sphere - .spawn(PbrComponents { + .spawn(PbrBundle { mesh: meshes.add(Mesh::from(shape::Icosphere { subdivisions: 4, radius: 0.5, @@ -47,12 +47,12 @@ fn setup( ..Default::default() }) // light - .spawn(LightComponents { + .spawn(LightBundle { transform: Transform::from_translation(Vec3::new(4.0, 8.0, 4.0)), ..Default::default() }) // camera - .spawn(Camera3dComponents { + .spawn(Camera3dBundle { transform: Transform::from_translation(Vec3::new(-3.0, 5.0, 8.0)) .looking_at(Vec3::default(), Vec3::unit_y()), ..Default::default() diff --git a/examples/scene/scene.rs b/examples/scene/scene.rs index e74b77ddc952e8..d8fb3e2a4b93c5 100644 --- a/examples/scene/scene.rs +++ b/examples/scene/scene.rs @@ -102,22 +102,20 @@ fn save_scene_system(_world: &mut World, resources: &mut Resources) { // This is only necessary for the info message in the UI. See examples/ui/text.rs for a standalone text example. fn infotext_system(commands: &mut Commands, asset_server: Res) { - commands - .spawn(UiCameraComponents::default()) - .spawn(TextComponents { - style: Style { - align_self: AlignSelf::FlexEnd, + commands.spawn(UiCameraBundle::default()).spawn(TextBundle { + style: Style { + align_self: AlignSelf::FlexEnd, + ..Default::default() + }, + text: Text { + value: "Nothing to see in this window! Check the console output!".to_string(), + font: asset_server.load("fonts/FiraSans-Bold.ttf"), + style: TextStyle { + font_size: 50.0, + color: Color::WHITE, ..Default::default() }, - text: Text { - value: "Nothing to see in this window! Check the console output!".to_string(), - font: asset_server.load("fonts/FiraSans-Bold.ttf"), - style: TextStyle { - font_size: 50.0, - color: Color::WHITE, - ..Default::default() - }, - }, - ..Default::default() - }); + }, + ..Default::default() + }); } diff --git a/examples/shader/mesh_custom_attribute.rs b/examples/shader/mesh_custom_attribute.rs index dd888bf995f306..30cf4e0b2bad3e 100644 --- a/examples/shader/mesh_custom_attribute.rs +++ b/examples/shader/mesh_custom_attribute.rs @@ -127,7 +127,7 @@ fn setup( // Setup our world commands // cube - .spawn(MeshComponents { + .spawn(MeshBundle { mesh: meshes.add(cube_with_vertex_colors), // use our cube with vertex colors render_pipelines: RenderPipelines::from_pipelines(vec![RenderPipeline::new( pipeline_handle, @@ -137,7 +137,7 @@ fn setup( }) .with(material) // camera - .spawn(Camera3dComponents { + .spawn(Camera3dBundle { transform: Transform::from_translation(Vec3::new(3.0, 5.0, -8.0)) .looking_at(Vec3::default(), Vec3::unit_y()), ..Default::default() diff --git a/examples/shader/shader_custom_material.rs b/examples/shader/shader_custom_material.rs index 30da872aa73b74..aef71801a718b1 100644 --- a/examples/shader/shader_custom_material.rs +++ b/examples/shader/shader_custom_material.rs @@ -83,7 +83,7 @@ fn setup( // Setup our world commands // cube - .spawn(MeshComponents { + .spawn(MeshBundle { mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), render_pipelines: RenderPipelines::from_pipelines(vec![RenderPipeline::new( pipeline_handle, @@ -93,7 +93,7 @@ fn setup( }) .with(material) // camera - .spawn(Camera3dComponents { + .spawn(Camera3dBundle { transform: Transform::from_translation(Vec3::new(3.0, 5.0, -8.0)) .looking_at(Vec3::default(), Vec3::unit_y()), ..Default::default() diff --git a/examples/shader/shader_defs.rs b/examples/shader/shader_defs.rs index 0dfce5cdff374f..e68127dc07272e 100644 --- a/examples/shader/shader_defs.rs +++ b/examples/shader/shader_defs.rs @@ -104,7 +104,7 @@ fn setup( commands // cube - .spawn(MeshComponents { + .spawn(MeshBundle { mesh: cube_handle.clone(), render_pipelines: RenderPipelines::from_pipelines(vec![RenderPipeline::new( pipeline_handle.clone(), @@ -114,7 +114,7 @@ fn setup( }) .with(green_material) // cube - .spawn(MeshComponents { + .spawn(MeshBundle { mesh: cube_handle, render_pipelines: RenderPipelines::from_pipelines(vec![RenderPipeline::new( pipeline_handle, @@ -124,7 +124,7 @@ fn setup( }) .with(blue_material) // camera - .spawn(Camera3dComponents { + .spawn(Camera3dBundle { transform: Transform::from_translation(Vec3::new(3.0, 5.0, -8.0)) .looking_at(Vec3::default(), Vec3::unit_y()), ..Default::default() diff --git a/examples/tools/bevymark.rs b/examples/tools/bevymark.rs index 632dfa443b3afb..0a91f7e8e018b6 100644 --- a/examples/tools/bevymark.rs +++ b/examples/tools/bevymark.rs @@ -50,9 +50,9 @@ fn main() { fn setup(commands: &mut Commands, asset_server: Res) { commands - .spawn(Camera2dComponents::default()) - .spawn(UiCameraComponents::default()) - .spawn(TextComponents { + .spawn(Camera2dBundle::default()) + .spawn(UiCameraBundle::default()) + .spawn(TextBundle { text: Text { font: asset_server.load("fonts/FiraSans-Bold.ttf"), value: "Bird Count:".to_string(), @@ -94,7 +94,7 @@ fn mouse_handler( transform.scale = Vec3::new(BIRD_SCALE, BIRD_SCALE, BIRD_SCALE); commands - .spawn(SpriteComponents { + .spawn(SpriteBundle { material: bird_material.0.clone(), transform, draw: Draw { diff --git a/examples/ui/button.rs b/examples/ui/button.rs index be377b1dacd871..7dde7534ce914b 100644 --- a/examples/ui/button.rs +++ b/examples/ui/button.rs @@ -61,8 +61,8 @@ fn setup( ) { commands // ui camera - .spawn(UiCameraComponents::default()) - .spawn(ButtonComponents { + .spawn(UiCameraBundle::default()) + .spawn(ButtonBundle { style: Style { size: Size::new(Val::Px(150.0), Val::Px(65.0)), // center button @@ -77,7 +77,7 @@ fn setup( ..Default::default() }) .with_children(|parent| { - parent.spawn(TextComponents { + parent.spawn(TextBundle { text: Text { value: "Button".to_string(), font: asset_server.load("fonts/FiraSans-Bold.ttf"), diff --git a/examples/ui/font_atlas_debug.rs b/examples/ui/font_atlas_debug.rs index 1a5d455b2cce1a..014519318c92dc 100644 --- a/examples/ui/font_atlas_debug.rs +++ b/examples/ui/font_atlas_debug.rs @@ -44,7 +44,7 @@ fn atlas_render_system( .get(&font_atlas[state.atlas_count as usize].texture_atlas) .unwrap(); state.atlas_count += 1; - commands.spawn(ImageComponents { + commands.spawn(ImageBundle { material: materials.add(texture_atlas.texture.clone().into()), style: Style { position_type: PositionType::Absolute, @@ -77,18 +77,16 @@ fn text_update_system(mut state: ResMut, time: Res