forked from bevyengine/bevy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split bevy_hierarchy out from bevy_transform (bevyengine#4168)
# Objective - Hierarchy tools are not just used for `Transform`: they are also used for scenes. - In the future there's interest in using them for other features, such as visiibility inheritance. - The fact that these tools are found in `bevy_transform` causes a great deal of user and developer confusion - Fixes bevyengine#2758. ## Solution - Split `bevy_transform` into two! - Make everything work again. Note that this is a very tightly scoped PR: I *know* there are code quality and docs issues that existed in bevy_transform that I've just moved around. We should fix those in a seperate PR and try to merge this ASAP to reduce the bitrot involved in splitting an entire crate. ## Frustrations The API around `GlobalTransform` is a mess: we have massive code and docs duplication, no link between the two types and no clear way to extend this to other forms of inheritance. In the medium-term, I feel pretty strongly that `GlobalTransform` should be replaced by something like `Inherited<Transform>`, which lives in `bevy_hierarchy`: - avoids code duplication - makes the inheritance pattern extensible - links the types at the type-level - allows us to remove all references to inheritance from `bevy_transform`, making it more useful as a standalone crate and cleaning up its docs ## Additional context - double-blessed by @cart in bevyengine#4141 (comment) and bevyengine#2758 (comment) - preparation for more advanced / cleaner hierarchy tools: go read bevyengine/rfcs#53 ! - originally attempted by @finegeometer in bevyengine#2789. It was a great idea, just needed more discussion! Co-authored-by: Carter Anderson <mcanders1@gmail.com>
- Loading branch information
Showing
29 changed files
with
225 additions
and
205 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
[package] | ||
name = "bevy_hierarchy" | ||
version = "0.6.0" | ||
edition = "2021" | ||
description = "Provides hierarchy functionality for Bevy Engine" | ||
homepage = "https://bevyengine.org" | ||
repository = "https://github.com/bevyengine/bevy" | ||
license = "MIT OR Apache-2.0" | ||
keywords = ["bevy"] | ||
|
||
[dependencies] | ||
# bevy | ||
bevy_app = { path = "../bevy_app", version = "0.6.0" } | ||
bevy_ecs = { path = "../bevy_ecs", version = "0.6.0", features = ["bevy_reflect"] } | ||
bevy_reflect = { path = "../bevy_reflect", version = "0.6.0", features = ["bevy"] } | ||
bevy_utils = { path = "../bevy_utils", version = "0.6.0" } | ||
|
||
# other | ||
smallvec = { version = "1.6", features = ["serde", "union", "const_generics"] } |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
mod children; | ||
mod parent; | ||
|
||
pub use children::Children; | ||
pub use parent::{Parent, PreviousParent}; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#![warn(missing_docs)] | ||
//! `bevy_hierarchy` can be used to define hierarchies of entities. | ||
//! | ||
//! Most commonly, these hierarchies are used for inheriting `Transform` values | ||
//! from the [`Parent`] to its [`Children`]. | ||
mod components; | ||
pub use components::*; | ||
|
||
mod hierarchy; | ||
pub use hierarchy::*; | ||
|
||
mod child_builder; | ||
pub use child_builder::*; | ||
|
||
mod systems; | ||
pub use systems::*; | ||
|
||
#[doc(hidden)] | ||
pub mod prelude { | ||
#[doc(hidden)] | ||
pub use crate::{child_builder::*, components::*, hierarchy::*, HierarchyPlugin}; | ||
} | ||
|
||
use bevy_app::prelude::*; | ||
use bevy_ecs::prelude::*; | ||
|
||
/// The base plugin for handling [`Parent`] and [`Children`] components | ||
#[derive(Default)] | ||
pub struct HierarchyPlugin; | ||
|
||
/// Label enum for the systems relating to hierarchy upkeep | ||
#[derive(Debug, Hash, PartialEq, Eq, Clone, SystemLabel)] | ||
pub enum HierarchySystem { | ||
/// Updates [`Parent`] when changes in the hierarchy occur | ||
ParentUpdate, | ||
} | ||
|
||
impl Plugin for HierarchyPlugin { | ||
fn build(&self, app: &mut App) { | ||
app.register_type::<Children>() | ||
.register_type::<Parent>() | ||
.register_type::<PreviousParent>() | ||
.add_startup_system_to_stage( | ||
StartupStage::PostStartup, | ||
parent_update_system.label(HierarchySystem::ParentUpdate), | ||
) | ||
.add_system_to_stage( | ||
CoreStage::PostUpdate, | ||
parent_update_system.label(HierarchySystem::ParentUpdate), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,5 @@ | ||
mod children; | ||
mod global_transform; | ||
mod parent; | ||
mod transform; | ||
|
||
pub use children::Children; | ||
pub use global_transform::*; | ||
pub use parent::{Parent, PreviousParent}; | ||
pub use transform::*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.