mirror of
https://github.com/bevyengine/bevy
synced 2024-11-25 14:10:19 +00:00
combine bevy_ecs and bevy_hecs crates. rename XComponents to XBundle (#863)
combine bevy_ecs and bevy_hecs crates. rename XComponents to XBundle
This commit is contained in:
parent
02f543eca3
commit
7628f4a64e
74 changed files with 629 additions and 619 deletions
|
@ -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 = [
|
||||
|
|
|
@ -6,10 +6,10 @@ authors = [
|
|||
"Bevy Contributors <bevyengine@gmail.com>",
|
||||
"Carter Anderson <mcanders1@gmail.com>",
|
||||
]
|
||||
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"]
|
||||
|
|
202
crates/bevy_ecs/LICENSE_MIT
Normal file
202
crates/bevy_ecs/LICENSE_MIT
Normal file
|
@ -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.
|
7
crates/bevy_ecs/README.md
Normal file
7
crates/bevy_ecs/README.md
Normal file
|
@ -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.
|
|
@ -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);
|
3
crates/bevy_ecs/hecs/.gitignore
vendored
3
crates/bevy_ecs/hecs/.gitignore
vendored
|
@ -1,3 +0,0 @@
|
|||
/target
|
||||
**/*.rs.bk
|
||||
Cargo.lock
|
|
@ -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 <https://cla.developers.google.com/> 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.
|
|
@ -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 <ben.e.saunders@gmail.com>",
|
||||
"Bevy Contributors <bevyengine@gmail.com>",
|
||||
"Carter Anderson <mcanders1@gmail.com>"]
|
||||
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"]
|
|
@ -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
|
|
@ -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 <ben.e.saunders@gmail.com>"]
|
||||
edition = "2018"
|
||||
license = "Apache-2.0"
|
|
@ -57,10 +57,12 @@ fn derive_bundle_(input: DeriveInput) -> Result<TokenStream2> {
|
|||
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::<TokenStream>().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<ArchetypeComponent>) -> 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)*
|
||||
}
|
|
@ -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<T: Hash + Eq + PartialEq + Copy> TypeAccess<T> {
|
|||
|
||||
#[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::<C>(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::<B>(<&A as Query>::Fetch::access())
|
||||
QueryAccess::with::<B>(<&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::<B>(<(&A, Option<&mut C>) as Query>::Fetch::access())
|
||||
QueryAccess::with::<B>(<(&A, Option<&mut C>) as WorldQuery>::Fetch::access())
|
||||
.get_world_archetype_access(&world, Some(&mut a_with_b_option_c_type_access));
|
||||
|
||||
assert_eq!(
|
|
@ -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
|
||||
///
|
|
@ -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)]
|
|
@ -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
|
|
@ -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
|
||||
///
|
|
@ -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");
|
|
@ -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)]
|
|
@ -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<T: Component> QueryFilter for With<T> {
|
|||
}
|
||||
}
|
||||
|
||||
pub struct WithType<T: Bundle>(PhantomData<T>);
|
||||
|
||||
impl<T: Bundle> QueryFilter for WithType<T> {
|
||||
type EntityFilter = AnyEntityFilter;
|
||||
|
||||
fn access() -> QueryAccess {
|
||||
QueryAccess::union(
|
||||
T::static_type_info()
|
||||
.iter()
|
||||
.map(|info| QueryAccess::With(info.id(), Box::new(QueryAccess::None)))
|
||||
.collect::<Vec<QueryAccess>>(),
|
||||
)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn get_entity_filter(archetype: &Archetype) -> Option<Self::EntityFilter> {
|
||||
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)]
|
|
@ -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::<i32>(a).unwrap(), 246);
|
||||
//! assert_eq!(*world.get::<i32>(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};
|
|
@ -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<Entity>);
|
||||
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<T>;
|
||||
}
|
||||
|
||||
|
@ -124,11 +123,11 @@ impl<'a, T: Component> Fetch<'a> for FetchRead<T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, T: Component> Query for &'a mut T {
|
||||
impl<'a, T: Component> WorldQuery for &'a mut T {
|
||||
type Fetch = FetchMut<T>;
|
||||
}
|
||||
|
||||
impl<T: Query> Query for Option<T> {
|
||||
impl<T: WorldQuery> WorldQuery for Option<T> {
|
||||
type Fetch = TryFetch<T::Fetch>;
|
||||
}
|
||||
|
||||
|
@ -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<T>;
|
||||
}
|
||||
#[doc(hidden)]
|
||||
|
@ -239,21 +238,21 @@ impl<'a, T: Fetch<'a>> Fetch<'a> for TryFetch<T> {
|
|||
}
|
||||
}
|
||||
|
||||
struct ChunkInfo<Q: Query, F: QueryFilter> {
|
||||
struct ChunkInfo<Q: WorldQuery, F: QueryFilter> {
|
||||
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<Q, F>,
|
||||
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<Q, F> = 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 = <Q::Fetch as Fetch<'w>>::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<Q: Query, F: QueryFilter> {
|
||||
struct ChunkIter<Q: WorldQuery, F: QueryFilter> {
|
||||
fetch: Q::Fetch,
|
||||
filter: F::EntityFilter,
|
||||
position: usize,
|
||||
len: usize,
|
||||
}
|
||||
|
||||
impl<Q: Query, F: QueryFilter> ChunkIter<Q, F> {
|
||||
impl<Q: WorldQuery, F: QueryFilter> ChunkIter<Q, F> {
|
||||
unsafe fn next<'a>(&mut self) -> Option<<Q::Fetch as Fetch<'a>>::Item> {
|
||||
loop {
|
||||
if self.position == self.len {
|
||||
|
@ -351,7 +350,7 @@ impl<Q: Query, F: QueryFilter> ChunkIter<Q, F> {
|
|||
}
|
||||
|
||||
/// 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<Self::Item> {
|
||||
|
@ -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<Q, F>,
|
||||
}
|
||||
|
||||
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 = <Q::Fetch as Fetch<'q>>::Item;
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
|
@ -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);
|
|
@ -1,6 +1,6 @@
|
|||
// modified by Bevy contributors
|
||||
|
||||
use crate::entities::Entity;
|
||||
use crate::Entity;
|
||||
use serde::{Serialize, Serializer};
|
||||
|
||||
impl Serialize for Entity {
|
|
@ -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::<Vec<_>>();
|
||||
/// 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<Q: Query>(&self) -> QueryIter<'_, Q, ()>
|
||||
pub fn query<Q: WorldQuery>(&self) -> QueryIter<'_, Q, ()>
|
||||
where
|
||||
Q::Fetch: ReadOnlyFetch,
|
||||
{
|
||||
|
@ -259,7 +253,7 @@ impl World {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pub fn query_filtered<Q: Query, F: QueryFilter>(&self) -> QueryIter<'_, Q, F>
|
||||
pub fn query_filtered<Q: WorldQuery, F: QueryFilter>(&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<Q: Query>(&mut self) -> QueryIter<'_, Q, ()> {
|
||||
pub fn query_mut<Q: WorldQuery>(&mut self) -> QueryIter<'_, Q, ()> {
|
||||
// SAFE: unique mutable access
|
||||
unsafe { self.query_unchecked() }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn query_filtered_mut<Q: Query, F: QueryFilter>(&mut self) -> QueryIter<'_, Q, F> {
|
||||
pub fn query_filtered_mut<Q: WorldQuery, F: QueryFilter>(&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<Q: Query>(&self, batch_size: usize) -> BatchedIter<'_, Q, ()>
|
||||
pub fn query_batched<Q: WorldQuery>(&self, batch_size: usize) -> BatchedIter<'_, Q, ()>
|
||||
where
|
||||
Q::Fetch: ReadOnlyFetch,
|
||||
{
|
||||
|
@ -315,7 +309,7 @@ impl World {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pub fn query_batched_filtered<Q: Query, F: QueryFilter>(
|
||||
pub fn query_batched_filtered<Q: WorldQuery, F: QueryFilter>(
|
||||
&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<Q: Query>(&mut self, batch_size: usize) -> BatchedIter<'_, Q, ()> {
|
||||
pub fn query_batched_mut<Q: WorldQuery>(
|
||||
&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<Q: Query, F: QueryFilter>(
|
||||
pub fn query_batched_filtered_mut<Q: WorldQuery, F: QueryFilter>(
|
||||
&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<Q: Query, F: QueryFilter>(&self) -> QueryIter<'_, Q, F> {
|
||||
pub unsafe fn query_unchecked<Q: WorldQuery, F: QueryFilter>(&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<Q: Query, F: QueryFilter>(
|
||||
pub unsafe fn query_batched_unchecked<Q: WorldQuery, F: QueryFilter>(
|
||||
&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<Q: Query>(
|
||||
pub fn query_one<Q: WorldQuery>(
|
||||
&self,
|
||||
entity: Entity,
|
||||
) -> Result<<Q::Fetch as Fetch>::Item, NoSuchEntity>
|
||||
|
@ -401,7 +398,7 @@ impl World {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pub fn query_one_filtered<Q: Query, F: QueryFilter>(
|
||||
pub fn query_one_filtered<Q: WorldQuery, F: QueryFilter>(
|
||||
&self,
|
||||
entity: Entity,
|
||||
) -> Result<<Q::Fetch as Fetch>::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<Q: Query>(
|
||||
pub fn query_one_mut<Q: WorldQuery>(
|
||||
&mut self,
|
||||
entity: Entity,
|
||||
) -> Result<<Q::Fetch as Fetch>::Item, NoSuchEntity> {
|
||||
|
@ -436,7 +433,7 @@ impl World {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pub fn query_one_filtered_mut<Q: Query, F: QueryFilter>(
|
||||
pub fn query_one_filtered_mut<Q: WorldQuery, F: QueryFilter>(
|
||||
&mut self,
|
||||
entity: Entity,
|
||||
) -> Result<<Q::Fetch as Fetch>::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<Q: Query, F: QueryFilter>(
|
||||
pub unsafe fn query_one_unchecked<Q: WorldQuery, F: QueryFilter>(
|
||||
&self,
|
||||
entity: Entity,
|
||||
) -> Result<<Q::Fetch as Fetch>::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")));
|
||||
|
@ -913,7 +910,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"));
|
|
@ -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 {
|
|
@ -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,
|
||||
};
|
||||
|
|
|
@ -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};
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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};
|
||||
|
||||
|
|
|
@ -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, ComponentError, DynamicBundle, Entity, EntityReserver, World,
|
||||
};
|
||||
use bevy_utils::tracing::{debug, warn};
|
||||
use std::marker::PhantomData;
|
||||
|
||||
|
@ -128,7 +130,7 @@ where
|
|||
fn write(self: Box<Self>, world: &mut World, _resources: &mut Resources) {
|
||||
match world.remove::<T>(self.entity) {
|
||||
Ok(_) => (),
|
||||
Err(bevy_hecs::ComponentError::MissingComponent(e)) => {
|
||||
Err(ComponentError::MissingComponent(e)) => {
|
||||
warn!(
|
||||
"Failed to remove components {:?} with error: {}. Falling back to inefficient one-by-one component removing.",
|
||||
std::any::type_name::<T>(),
|
||||
|
@ -322,9 +324,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() {
|
||||
|
|
|
@ -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};
|
||||
|
||||
|
@ -208,9 +210,8 @@ mod tests {
|
|||
use crate::{
|
||||
resource::{Res, ResMut, Resources},
|
||||
schedule::Schedule,
|
||||
ChangedRes, Local, Query, QuerySet, System,
|
||||
ChangedRes, Entity, Local, Or, Query, QuerySet, System, With, World,
|
||||
};
|
||||
use bevy_hecs::{Entity, Or, With, World};
|
||||
|
||||
#[derive(Debug, Eq, PartialEq, Default)]
|
||||
struct A;
|
||||
|
|
|
@ -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)]
|
||||
|
|
|
@ -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<ArchetypeComponent>,
|
||||
_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<Batch<'w, Q, F>> for ParIter<'w, Q, F> {
|
||||
impl<'w, Q: WorldQuery, F: QueryFilter> ParallelIterator<Batch<'w, Q, F>> for ParIter<'w, Q, F> {
|
||||
type Item = <Q::Fetch as Fetch<'w>>::Item;
|
||||
|
||||
#[inline]
|
||||
|
|
|
@ -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<T: QueryTuple> {
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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<Self>;
|
||||
}
|
||||
|
||||
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,
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
// modified by Bevy contributors
|
||||
|
||||
use bevy_hecs::*;
|
||||
use bevy_ecs::*;
|
||||
|
||||
#[test]
|
||||
fn random_access() {
|
|
@ -1,5 +0,0 @@
|
|||
mod entity_map;
|
||||
mod world_builder;
|
||||
|
||||
pub use entity_map::*;
|
||||
pub use world_builder::*;
|
|
@ -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()
|
||||
|
|
|
@ -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<Mesh>,
|
||||
pub material: Handle<StandardMaterial>,
|
||||
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,
|
||||
|
|
|
@ -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<Mesh>,
|
||||
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()
|
||||
|
|
|
@ -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<BindGroupId>,
|
||||
}
|
||||
|
||||
pub struct PassNode<Q: HecsQuery> {
|
||||
pub struct PassNode<Q: WorldQuery> {
|
||||
descriptor: PassDescriptor,
|
||||
inputs: Vec<ResourceSlotInfo>,
|
||||
cameras: Vec<CameraInfo>,
|
||||
|
@ -34,7 +34,7 @@ pub struct PassNode<Q: HecsQuery> {
|
|||
_marker: PhantomData<Q>,
|
||||
}
|
||||
|
||||
impl<Q: HecsQuery> fmt::Debug for PassNode<Q> {
|
||||
impl<Q: WorldQuery> fmt::Debug for PassNode<Q> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
f.debug_struct("PassNose")
|
||||
.field("descriptor", &self.descriptor)
|
||||
|
@ -64,7 +64,7 @@ impl<Q: HecsQuery> fmt::Debug for PassNode<Q> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<Q: HecsQuery> PassNode<Q> {
|
||||
impl<Q: WorldQuery> PassNode<Q> {
|
||||
pub fn new(descriptor: PassDescriptor) -> Self {
|
||||
let mut inputs = Vec::new();
|
||||
let mut color_attachment_input_indices = Vec::new();
|
||||
|
@ -140,7 +140,7 @@ impl<Q: HecsQuery> PassNode<Q> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<Q: HecsQuery + Send + Sync + 'static> Node for PassNode<Q>
|
||||
impl<Q: WorldQuery + Send + Sync + 'static> Node for PassNode<Q>
|
||||
where
|
||||
Q::Fetch: ReadOnlyFetch,
|
||||
{
|
||||
|
|
|
@ -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<Mesh>, // TODO: maybe abstract this out
|
||||
pub material: Handle<ColorMaterial>,
|
||||
|
@ -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(
|
||||
|
|
|
@ -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,
|
||||
};
|
||||
}
|
||||
|
|
|
@ -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<Mesh>, // 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()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
});
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -11,11 +11,11 @@ fn main() {
|
|||
fn setup(commands: &mut Commands, asset_server: Res<AssetServer>) {
|
||||
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()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -25,12 +25,12 @@ fn setup(commands: &mut Commands, asset_server: Res<AssetServer>) {
|
|||
// 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()
|
||||
|
|
|
@ -13,12 +13,12 @@ fn setup(
|
|||
asset_server: Res<AssetServer>,
|
||||
mut materials: ResMut<Assets<ColorMaterial>>,
|
||||
) {
|
||||
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),
|
||||
|
|
|
@ -8,12 +8,12 @@ fn spawn_system(
|
|||
asset_server: Res<AssetServer>,
|
||||
mut materials: ResMut<Assets<ColorMaterial>>,
|
||||
) {
|
||||
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()
|
||||
|
|
|
@ -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),
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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<AssetServer>) {
|
||||
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()
|
||||
});
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -50,9 +50,9 @@ fn main() {
|
|||
|
||||
fn setup(commands: &mut Commands, asset_server: Res<AssetServer>) {
|
||||
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 {
|
||||
|
|
|
@ -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"),
|
||||
|
|
|
@ -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<State>, time: Res<Time>, mut query: Quer
|
|||
fn setup(commands: &mut Commands, asset_server: Res<AssetServer>, mut state: ResMut<State>) {
|
||||
let font_handle = asset_server.load("fonts/FiraSans-Bold.ttf");
|
||||
state.handle = font_handle.clone();
|
||||
commands
|
||||
.spawn(UiCameraComponents::default())
|
||||
.spawn(TextComponents {
|
||||
text: Text {
|
||||
value: "a".to_string(),
|
||||
font: font_handle,
|
||||
style: TextStyle {
|
||||
font_size: 60.0,
|
||||
color: Color::WHITE,
|
||||
..Default::default()
|
||||
},
|
||||
commands.spawn(UiCameraBundle::default()).spawn(TextBundle {
|
||||
text: Text {
|
||||
value: "a".to_string(),
|
||||
font: font_handle,
|
||||
style: TextStyle {
|
||||
font_size: 60.0,
|
||||
color: Color::WHITE,
|
||||
..Default::default()
|
||||
},
|
||||
..Default::default()
|
||||
});
|
||||
},
|
||||
..Default::default()
|
||||
});
|
||||
}
|
||||
|
|
|
@ -29,9 +29,9 @@ fn text_update_system(diagnostics: Res<Diagnostics>, mut query: Query<&mut Text,
|
|||
fn setup(commands: &mut Commands, asset_server: Res<AssetServer>) {
|
||||
commands
|
||||
// 2d camera
|
||||
.spawn(UiCameraComponents::default())
|
||||
.spawn(UiCameraBundle::default())
|
||||
// texture
|
||||
.spawn(TextComponents {
|
||||
.spawn(TextBundle {
|
||||
style: Style {
|
||||
align_self: AlignSelf::FlexEnd,
|
||||
..Default::default()
|
||||
|
|
|
@ -14,66 +14,61 @@ struct TextChanges;
|
|||
|
||||
fn infotext_system(commands: &mut Commands, asset_server: Res<AssetServer>) {
|
||||
let font = asset_server.load("fonts/FiraSans-Bold.ttf");
|
||||
commands
|
||||
.spawn(UiCameraComponents::default())
|
||||
.spawn(TextComponents {
|
||||
style: Style {
|
||||
align_self: AlignSelf::FlexEnd,
|
||||
position_type: PositionType::Absolute,
|
||||
position: Rect {
|
||||
top: Val::Px(5.0),
|
||||
left: Val::Px(15.0),
|
||||
..Default::default()
|
||||
},
|
||||
commands.spawn(UiCameraBundle::default()).spawn(TextBundle {
|
||||
style: Style {
|
||||
align_self: AlignSelf::FlexEnd,
|
||||
position_type: PositionType::Absolute,
|
||||
position: Rect {
|
||||
top: Val::Px(5.0),
|
||||
left: Val::Px(15.0),
|
||||
..Default::default()
|
||||
},
|
||||
text: Text {
|
||||
value: "This is\ntext with\nline breaks\nin the top left".to_string(),
|
||||
font: font.clone(),
|
||||
style: TextStyle {
|
||||
font_size: 50.0,
|
||||
color: Color::WHITE,
|
||||
alignment: TextAlignment::default(),
|
||||
},
|
||||
},
|
||||
..Default::default()
|
||||
});
|
||||
commands
|
||||
.spawn(UiCameraComponents::default())
|
||||
.spawn(TextComponents {
|
||||
style: Style {
|
||||
align_self: AlignSelf::FlexEnd,
|
||||
position_type: PositionType::Absolute,
|
||||
position: Rect {
|
||||
top: Val::Px(5.0),
|
||||
right: Val::Px(15.0),
|
||||
..Default::default()
|
||||
},
|
||||
max_size: Size {
|
||||
width: Val::Px(400.),
|
||||
height: Val::Undefined,
|
||||
},
|
||||
},
|
||||
text: Text {
|
||||
value: "This is\ntext with\nline breaks\nin the top left".to_string(),
|
||||
font: font.clone(),
|
||||
style: TextStyle {
|
||||
font_size: 50.0,
|
||||
color: Color::WHITE,
|
||||
alignment: TextAlignment::default(),
|
||||
},
|
||||
},
|
||||
..Default::default()
|
||||
});
|
||||
commands.spawn(UiCameraBundle::default()).spawn(TextBundle {
|
||||
style: Style {
|
||||
align_self: AlignSelf::FlexEnd,
|
||||
position_type: PositionType::Absolute,
|
||||
position: Rect {
|
||||
top: Val::Px(5.0),
|
||||
right: Val::Px(15.0),
|
||||
..Default::default()
|
||||
},
|
||||
text: Text {
|
||||
value:
|
||||
"This is very long text with limited width in the top right and is also pink"
|
||||
.to_string(),
|
||||
font: font.clone(),
|
||||
style: TextStyle {
|
||||
font_size: 50.0,
|
||||
color: Color::rgb(0.8, 0.2, 0.7),
|
||||
alignment: TextAlignment {
|
||||
horizontal: HorizontalAlign::Center,
|
||||
vertical: VerticalAlign::Center,
|
||||
},
|
||||
},
|
||||
max_size: Size {
|
||||
width: Val::Px(400.),
|
||||
height: Val::Undefined,
|
||||
},
|
||||
..Default::default()
|
||||
});
|
||||
},
|
||||
text: Text {
|
||||
value: "This is very long text with limited width in the top right and is also pink"
|
||||
.to_string(),
|
||||
font: font.clone(),
|
||||
style: TextStyle {
|
||||
font_size: 50.0,
|
||||
color: Color::rgb(0.8, 0.2, 0.7),
|
||||
alignment: TextAlignment {
|
||||
horizontal: HorizontalAlign::Center,
|
||||
vertical: VerticalAlign::Center,
|
||||
},
|
||||
},
|
||||
},
|
||||
..Default::default()
|
||||
});
|
||||
commands
|
||||
.spawn(UiCameraComponents::default())
|
||||
.spawn(TextComponents {
|
||||
.spawn(UiCameraBundle::default())
|
||||
.spawn(TextBundle {
|
||||
style: Style {
|
||||
align_self: AlignSelf::FlexEnd,
|
||||
position_type: PositionType::Absolute,
|
||||
|
@ -96,35 +91,33 @@ fn infotext_system(commands: &mut Commands, asset_server: Res<AssetServer>) {
|
|||
..Default::default()
|
||||
})
|
||||
.with(TextChanges);
|
||||
commands
|
||||
.spawn(UiCameraComponents::default())
|
||||
.spawn(TextComponents {
|
||||
style: Style {
|
||||
align_self: AlignSelf::FlexEnd,
|
||||
position_type: PositionType::Absolute,
|
||||
position: Rect {
|
||||
bottom: Val::Px(5.0),
|
||||
left: Val::Px(15.0),
|
||||
..Default::default()
|
||||
},
|
||||
size: Size {
|
||||
width: Val::Px(200.0),
|
||||
..Default::default()
|
||||
},
|
||||
commands.spawn(UiCameraBundle::default()).spawn(TextBundle {
|
||||
style: Style {
|
||||
align_self: AlignSelf::FlexEnd,
|
||||
position_type: PositionType::Absolute,
|
||||
position: Rect {
|
||||
bottom: Val::Px(5.0),
|
||||
left: Val::Px(15.0),
|
||||
..Default::default()
|
||||
},
|
||||
text: Text {
|
||||
value: "This\ntext has\nline breaks and also a set width in the bottom left"
|
||||
.to_string(),
|
||||
font,
|
||||
style: TextStyle {
|
||||
font_size: 50.0,
|
||||
color: Color::WHITE,
|
||||
alignment: TextAlignment::default(),
|
||||
},
|
||||
size: Size {
|
||||
width: Val::Px(200.0),
|
||||
..Default::default()
|
||||
},
|
||||
..Default::default()
|
||||
});
|
||||
},
|
||||
text: Text {
|
||||
value: "This\ntext has\nline breaks and also a set width in the bottom left"
|
||||
.to_string(),
|
||||
font,
|
||||
style: TextStyle {
|
||||
font_size: 50.0,
|
||||
color: Color::WHITE,
|
||||
alignment: TextAlignment::default(),
|
||||
},
|
||||
},
|
||||
..Default::default()
|
||||
});
|
||||
}
|
||||
|
||||
fn change_text_system(mut query: Query<(&mut Text, &TextChanges)>) {
|
||||
|
|
|
@ -15,9 +15,9 @@ fn setup(
|
|||
) {
|
||||
commands
|
||||
// ui camera
|
||||
.spawn(UiCameraComponents::default())
|
||||
.spawn(UiCameraBundle::default())
|
||||
// root node
|
||||
.spawn(NodeComponents {
|
||||
.spawn(NodeBundle {
|
||||
style: Style {
|
||||
size: Size::new(Val::Percent(100.0), Val::Percent(100.0)),
|
||||
justify_content: JustifyContent::SpaceBetween,
|
||||
|
@ -29,7 +29,7 @@ fn setup(
|
|||
.with_children(|parent| {
|
||||
parent
|
||||
// left vertical fill (border)
|
||||
.spawn(NodeComponents {
|
||||
.spawn(NodeBundle {
|
||||
style: Style {
|
||||
size: Size::new(Val::Px(200.0), Val::Percent(100.0)),
|
||||
border: Rect::all(Val::Px(2.0)),
|
||||
|
@ -41,7 +41,7 @@ fn setup(
|
|||
.with_children(|parent| {
|
||||
parent
|
||||
// left vertical fill (content)
|
||||
.spawn(NodeComponents {
|
||||
.spawn(NodeBundle {
|
||||
style: Style {
|
||||
size: Size::new(Val::Percent(100.0), Val::Percent(100.0)),
|
||||
align_items: AlignItems::FlexEnd,
|
||||
|
@ -52,7 +52,7 @@ fn setup(
|
|||
})
|
||||
.with_children(|parent| {
|
||||
// text
|
||||
parent.spawn(TextComponents {
|
||||
parent.spawn(TextBundle {
|
||||
style: Style {
|
||||
margin: Rect::all(Val::Px(5.0)),
|
||||
..Default::default()
|
||||
|
@ -71,7 +71,7 @@ fn setup(
|
|||
});
|
||||
})
|
||||
// right vertical fill
|
||||
.spawn(NodeComponents {
|
||||
.spawn(NodeBundle {
|
||||
style: Style {
|
||||
size: Size::new(Val::Px(200.0), Val::Percent(100.0)),
|
||||
..Default::default()
|
||||
|
@ -80,7 +80,7 @@ fn setup(
|
|||
..Default::default()
|
||||
})
|
||||
// absolute positioning
|
||||
.spawn(NodeComponents {
|
||||
.spawn(NodeBundle {
|
||||
style: Style {
|
||||
size: Size::new(Val::Px(200.0), Val::Px(200.0)),
|
||||
position_type: PositionType::Absolute,
|
||||
|
@ -96,7 +96,7 @@ fn setup(
|
|||
..Default::default()
|
||||
})
|
||||
.with_children(|parent| {
|
||||
parent.spawn(NodeComponents {
|
||||
parent.spawn(NodeBundle {
|
||||
style: Style {
|
||||
size: Size::new(Val::Percent(100.0), Val::Percent(100.0)),
|
||||
..Default::default()
|
||||
|
@ -106,7 +106,7 @@ fn setup(
|
|||
});
|
||||
})
|
||||
// render order test: reddest in the back, whitest in the front (flex center)
|
||||
.spawn(NodeComponents {
|
||||
.spawn(NodeBundle {
|
||||
style: Style {
|
||||
size: Size::new(Val::Percent(100.0), Val::Percent(100.0)),
|
||||
position_type: PositionType::Absolute,
|
||||
|
@ -123,7 +123,7 @@ fn setup(
|
|||
})
|
||||
.with_children(|parent| {
|
||||
parent
|
||||
.spawn(NodeComponents {
|
||||
.spawn(NodeBundle {
|
||||
style: Style {
|
||||
size: Size::new(Val::Px(100.0), Val::Px(100.0)),
|
||||
..Default::default()
|
||||
|
@ -133,7 +133,7 @@ fn setup(
|
|||
})
|
||||
.with_children(|parent| {
|
||||
parent
|
||||
.spawn(NodeComponents {
|
||||
.spawn(NodeBundle {
|
||||
style: Style {
|
||||
size: Size::new(Val::Px(100.0), Val::Px(100.0)),
|
||||
position_type: PositionType::Absolute,
|
||||
|
@ -147,7 +147,7 @@ fn setup(
|
|||
material: materials.add(Color::rgb(1.0, 0.3, 0.3).into()),
|
||||
..Default::default()
|
||||
})
|
||||
.spawn(NodeComponents {
|
||||
.spawn(NodeBundle {
|
||||
style: Style {
|
||||
size: Size::new(Val::Px(100.0), Val::Px(100.0)),
|
||||
position_type: PositionType::Absolute,
|
||||
|
@ -161,7 +161,7 @@ fn setup(
|
|||
material: materials.add(Color::rgb(1.0, 0.5, 0.5).into()),
|
||||
..Default::default()
|
||||
})
|
||||
.spawn(NodeComponents {
|
||||
.spawn(NodeBundle {
|
||||
style: Style {
|
||||
size: Size::new(Val::Px(100.0), Val::Px(100.0)),
|
||||
position_type: PositionType::Absolute,
|
||||
|
@ -176,7 +176,7 @@ fn setup(
|
|||
..Default::default()
|
||||
})
|
||||
// alpha test
|
||||
.spawn(NodeComponents {
|
||||
.spawn(NodeBundle {
|
||||
style: Style {
|
||||
size: Size::new(Val::Px(100.0), Val::Px(100.0)),
|
||||
position_type: PositionType::Absolute,
|
||||
|
@ -197,7 +197,7 @@ fn setup(
|
|||
});
|
||||
})
|
||||
// bevy logo (flex center)
|
||||
.spawn(NodeComponents {
|
||||
.spawn(NodeBundle {
|
||||
style: Style {
|
||||
size: Size::new(Val::Percent(100.0), Val::Percent(100.0)),
|
||||
position_type: PositionType::Absolute,
|
||||
|
@ -214,7 +214,7 @@ fn setup(
|
|||
})
|
||||
.with_children(|parent| {
|
||||
// bevy logo (image)
|
||||
parent.spawn(ImageComponents {
|
||||
parent.spawn(ImageBundle {
|
||||
style: Style {
|
||||
size: Size::new(Val::Px(500.0), Val::Auto),
|
||||
..Default::default()
|
||||
|
|
|
@ -156,18 +156,18 @@ fn setup(
|
|||
commands
|
||||
.spawn_scene(asset_server.load("models/monkey/Monkey.gltf"))
|
||||
// light
|
||||
.spawn(LightComponents {
|
||||
.spawn(LightBundle {
|
||||
transform: Transform::from_translation(Vec3::new(4.0, 5.0, 4.0)),
|
||||
..Default::default()
|
||||
})
|
||||
// main camera
|
||||
.spawn(Camera3dComponents {
|
||||
.spawn(Camera3dBundle {
|
||||
transform: Transform::from_translation(Vec3::new(0.0, 0.0, 6.0))
|
||||
.looking_at(Vec3::default(), Vec3::unit_y()),
|
||||
..Default::default()
|
||||
})
|
||||
// second window camera
|
||||
.spawn(Camera3dComponents {
|
||||
.spawn(Camera3dBundle {
|
||||
camera: Camera {
|
||||
name: Some("Secondary".to_string()),
|
||||
window: window_id,
|
||||
|
|
Loading…
Reference in a new issue