mirror of
https://github.com/bevyengine/bevy
synced 2025-01-23 02:15:15 +00:00
76d12fa2b3
# Objective Part of https://github.com/bevyengine/bevy/issues/13529 Helps https://github.com/bevyengine/bevy/pull/13533 Splitting up `bevy_transform` makes it easier to selectively include or exclude parts of it in such a way that it's possible to include only a small part with a small dependency tree. ## Solution Make the crate more modular. --------- Signed-off-by: Torstein Grindvik <torstein.grindvik@muybridge.com> Co-authored-by: Torstein Grindvik <torstein.grindvik@muybridge.com>
62 lines
2.5 KiB
Rust
62 lines
2.5 KiB
Rust
use bevy_app::{App, Plugin, PostStartup, PostUpdate};
|
|
use bevy_ecs::schedule::{IntoSystemConfigs, IntoSystemSetConfigs, SystemSet};
|
|
use bevy_hierarchy::ValidParentCheckPlugin;
|
|
|
|
use crate::{
|
|
prelude::{GlobalTransform, Transform},
|
|
systems::{propagate_transforms, sync_simple_transforms},
|
|
};
|
|
|
|
/// Set enum for the systems relating to transform propagation
|
|
#[derive(Debug, Hash, PartialEq, Eq, Clone, SystemSet)]
|
|
pub enum TransformSystem {
|
|
/// Propagates changes in transform to children's [`GlobalTransform`]
|
|
TransformPropagate,
|
|
}
|
|
|
|
/// The base plugin for handling [`Transform`] components
|
|
#[derive(Default)]
|
|
pub struct TransformPlugin;
|
|
|
|
impl Plugin for TransformPlugin {
|
|
fn build(&self, app: &mut App) {
|
|
// A set for `propagate_transforms` to mark it as ambiguous with `sync_simple_transforms`.
|
|
// Used instead of the `SystemTypeSet` as that would not allow multiple instances of the system.
|
|
#[derive(Debug, Hash, PartialEq, Eq, Clone, SystemSet)]
|
|
struct PropagateTransformsSet;
|
|
|
|
app.register_type::<Transform>()
|
|
.register_type::<GlobalTransform>()
|
|
.add_plugins(ValidParentCheckPlugin::<GlobalTransform>::default())
|
|
.configure_sets(
|
|
PostStartup,
|
|
PropagateTransformsSet.in_set(TransformSystem::TransformPropagate),
|
|
)
|
|
// add transform systems to startup so the first update is "correct"
|
|
.add_systems(
|
|
PostStartup,
|
|
(
|
|
sync_simple_transforms
|
|
.in_set(TransformSystem::TransformPropagate)
|
|
// FIXME: https://github.com/bevyengine/bevy/issues/4381
|
|
// These systems cannot access the same entities,
|
|
// due to subtle query filtering that is not yet correctly computed in the ambiguity detector
|
|
.ambiguous_with(PropagateTransformsSet),
|
|
propagate_transforms.in_set(PropagateTransformsSet),
|
|
),
|
|
)
|
|
.configure_sets(
|
|
PostUpdate,
|
|
PropagateTransformsSet.in_set(TransformSystem::TransformPropagate),
|
|
)
|
|
.add_systems(
|
|
PostUpdate,
|
|
(
|
|
sync_simple_transforms
|
|
.in_set(TransformSystem::TransformPropagate)
|
|
.ambiguous_with(PropagateTransformsSet),
|
|
propagate_transforms.in_set(PropagateTransformsSet),
|
|
),
|
|
);
|
|
}
|
|
}
|