From 19d24e92aa69e0ceda20b1b23e59246efb125a79 Mon Sep 17 00:00:00 2001 From: Carter Anderson Date: Tue, 21 Jul 2020 22:02:18 -0700 Subject: [PATCH] transform: immediately set localltransform value --- crates/bevy_ecs/hecs/README.md | 1 + .../hierarchy/hierarchy_maintenance_system.rs | 1 - .../src/local_transform_systems.rs | 2 -- .../src/transform_propagate_system.rs | 32 ++++++------------- .../bevy_transform/src/transform_systems.rs | 2 -- 5 files changed, 10 insertions(+), 28 deletions(-) diff --git a/crates/bevy_ecs/hecs/README.md b/crates/bevy_ecs/hecs/README.md index 949bc64d05..d3e6ed3958 100644 --- a/crates/bevy_ecs/hecs/README.md +++ b/crates/bevy_ecs/hecs/README.md @@ -15,6 +15,7 @@ This is the Bevy project's fork of hecs with changes that accommodate the needs * Entity indices are now queryable and are not returned in queries by default. This both improves ergonomics and significantly boosts performance in some cases. * Entity indices are now UUIDs and are no longer generational. This allows apps to use Entity ids as stable ids during serialization and networking. This also improves query performance because we don't need to look up entity generation information while iterating. It also removes ~300 lines of code dedicated to entity index maintenance. However this new model does come at a small cost: entity creation + `world.get::(entity)` lookup now requires hashing, which by our benchmarks is about 5x slower than the previous array indexing implementation. Given that this is an uncommon pattern and the major benefits the new design yields, we consider this small corner-case performance cost worth it. * 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? diff --git a/crates/bevy_transform/src/hierarchy/hierarchy_maintenance_system.rs b/crates/bevy_transform/src/hierarchy/hierarchy_maintenance_system.rs index d769774843..539f2e0582 100644 --- a/crates/bevy_transform/src/hierarchy/hierarchy_maintenance_system.rs +++ b/crates/bevy_transform/src/hierarchy/hierarchy_maintenance_system.rs @@ -1,4 +1,3 @@ -#![allow(dead_code)] use crate::components::*; use bevy_ecs::{Commands, Entity, IntoQuerySystem, Query, System, Without}; use smallvec::SmallVec; diff --git a/crates/bevy_transform/src/local_transform_systems.rs b/crates/bevy_transform/src/local_transform_systems.rs index 17439f5af1..938aa87b3c 100644 --- a/crates/bevy_transform/src/local_transform_systems.rs +++ b/crates/bevy_transform/src/local_transform_systems.rs @@ -1,6 +1,4 @@ -#![allow(dead_code)] use crate::components::*; - use bevy_ecs::prelude::*; use bevy_math::{Mat4, Quat, Vec3}; diff --git a/crates/bevy_transform/src/transform_propagate_system.rs b/crates/bevy_transform/src/transform_propagate_system.rs index 30cfc9c463..cf9eac8dbf 100644 --- a/crates/bevy_transform/src/transform_propagate_system.rs +++ b/crates/bevy_transform/src/transform_propagate_system.rs @@ -1,14 +1,11 @@ -#![allow(dead_code)] use crate::components::*; use bevy_ecs::prelude::*; pub fn transform_propagate_system( - mut commands: Commands, mut root_query: Query< Without, &mut Transform, Option<&LocalTransform>)>, >, - mut children_query: Query<&Children>, - mut local_transform_query: Query<&LocalTransform>, + mut local_transform_query: Query<(&mut Transform, &LocalTransform, Option<&Children>)>, ) { for (children, mut transform, local_transform) in &mut root_query.iter() { if let Some(local_transform) = local_transform { @@ -17,13 +14,7 @@ pub fn transform_propagate_system( if let Some(children) = children { for child in children.0.iter() { - propagate_recursive( - *transform, - &mut children_query, - &mut local_transform_query, - *child, - &mut commands, - ); + propagate_recursive(*transform, &mut local_transform_query, *child); } } } @@ -31,10 +22,8 @@ pub fn transform_propagate_system( fn propagate_recursive( parent_local_to_world: Transform, - children_query: &mut Query<&Children>, - local_transform_query: &mut Query<&LocalTransform>, + local_transform_query: &mut Query<(&mut Transform, &LocalTransform, Option<&Children>)>, entity: Entity, - commands: &mut Commands, ) { log::trace!("Updating Transform for {:?}", entity); let local_transform = { @@ -54,22 +43,19 @@ fn propagate_recursive( sync: true, }; - commands.insert_one(entity, new_transform); + { + let mut transform = local_transform_query.get_mut::(entity).unwrap(); + transform.value = new_transform.value; + } // Collect children - let children = children_query + let children = local_transform_query .get::(entity) .map(|e| e.0.iter().cloned().collect::>()) .unwrap_or_default(); for child in children { - propagate_recursive( - new_transform, - children_query, - local_transform_query, - child, - commands, - ); + propagate_recursive(new_transform, local_transform_query, child); } } diff --git a/crates/bevy_transform/src/transform_systems.rs b/crates/bevy_transform/src/transform_systems.rs index 3398ac95e8..ba0a7fc4cb 100644 --- a/crates/bevy_transform/src/transform_systems.rs +++ b/crates/bevy_transform/src/transform_systems.rs @@ -1,6 +1,4 @@ -#![allow(dead_code)] use crate::components::*; - use bevy_ecs::prelude::*; use bevy_math::{Mat4, Quat, Vec3};