transform: immediately set localltransform value
This commit is contained in:
parent
ae30175e18
commit
19d24e92aa
@ -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 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::<Component>(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.
|
* 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::<Component>(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)
|
* 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?
|
### Why ECS?
|
||||||
|
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
#![allow(dead_code)]
|
|
||||||
use crate::components::*;
|
use crate::components::*;
|
||||||
use bevy_ecs::{Commands, Entity, IntoQuerySystem, Query, System, Without};
|
use bevy_ecs::{Commands, Entity, IntoQuerySystem, Query, System, Without};
|
||||||
use smallvec::SmallVec;
|
use smallvec::SmallVec;
|
||||||
|
@ -1,6 +1,4 @@
|
|||||||
#![allow(dead_code)]
|
|
||||||
use crate::components::*;
|
use crate::components::*;
|
||||||
|
|
||||||
use bevy_ecs::prelude::*;
|
use bevy_ecs::prelude::*;
|
||||||
use bevy_math::{Mat4, Quat, Vec3};
|
use bevy_math::{Mat4, Quat, Vec3};
|
||||||
|
|
||||||
|
@ -1,14 +1,11 @@
|
|||||||
#![allow(dead_code)]
|
|
||||||
use crate::components::*;
|
use crate::components::*;
|
||||||
use bevy_ecs::prelude::*;
|
use bevy_ecs::prelude::*;
|
||||||
|
|
||||||
pub fn transform_propagate_system(
|
pub fn transform_propagate_system(
|
||||||
mut commands: Commands,
|
|
||||||
mut root_query: Query<
|
mut root_query: Query<
|
||||||
Without<Parent, (Option<&Children>, &mut Transform, Option<&LocalTransform>)>,
|
Without<Parent, (Option<&Children>, &mut Transform, Option<&LocalTransform>)>,
|
||||||
>,
|
>,
|
||||||
mut children_query: Query<&Children>,
|
mut local_transform_query: Query<(&mut Transform, &LocalTransform, Option<&Children>)>,
|
||||||
mut local_transform_query: Query<&LocalTransform>,
|
|
||||||
) {
|
) {
|
||||||
for (children, mut transform, local_transform) in &mut root_query.iter() {
|
for (children, mut transform, local_transform) in &mut root_query.iter() {
|
||||||
if let Some(local_transform) = local_transform {
|
if let Some(local_transform) = local_transform {
|
||||||
@ -17,13 +14,7 @@ pub fn transform_propagate_system(
|
|||||||
|
|
||||||
if let Some(children) = children {
|
if let Some(children) = children {
|
||||||
for child in children.0.iter() {
|
for child in children.0.iter() {
|
||||||
propagate_recursive(
|
propagate_recursive(*transform, &mut local_transform_query, *child);
|
||||||
*transform,
|
|
||||||
&mut children_query,
|
|
||||||
&mut local_transform_query,
|
|
||||||
*child,
|
|
||||||
&mut commands,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -31,10 +22,8 @@ pub fn transform_propagate_system(
|
|||||||
|
|
||||||
fn propagate_recursive(
|
fn propagate_recursive(
|
||||||
parent_local_to_world: Transform,
|
parent_local_to_world: Transform,
|
||||||
children_query: &mut Query<&Children>,
|
local_transform_query: &mut Query<(&mut Transform, &LocalTransform, Option<&Children>)>,
|
||||||
local_transform_query: &mut Query<&LocalTransform>,
|
|
||||||
entity: Entity,
|
entity: Entity,
|
||||||
commands: &mut Commands,
|
|
||||||
) {
|
) {
|
||||||
log::trace!("Updating Transform for {:?}", entity);
|
log::trace!("Updating Transform for {:?}", entity);
|
||||||
let local_transform = {
|
let local_transform = {
|
||||||
@ -54,22 +43,19 @@ fn propagate_recursive(
|
|||||||
sync: true,
|
sync: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
commands.insert_one(entity, new_transform);
|
{
|
||||||
|
let mut transform = local_transform_query.get_mut::<Transform>(entity).unwrap();
|
||||||
|
transform.value = new_transform.value;
|
||||||
|
}
|
||||||
|
|
||||||
// Collect children
|
// Collect children
|
||||||
let children = children_query
|
let children = local_transform_query
|
||||||
.get::<Children>(entity)
|
.get::<Children>(entity)
|
||||||
.map(|e| e.0.iter().cloned().collect::<Vec<_>>())
|
.map(|e| e.0.iter().cloned().collect::<Vec<_>>())
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
|
|
||||||
for child in children {
|
for child in children {
|
||||||
propagate_recursive(
|
propagate_recursive(new_transform, local_transform_query, child);
|
||||||
new_transform,
|
|
||||||
children_query,
|
|
||||||
local_transform_query,
|
|
||||||
child,
|
|
||||||
commands,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,4 @@
|
|||||||
#![allow(dead_code)]
|
|
||||||
use crate::components::*;
|
use crate::components::*;
|
||||||
|
|
||||||
use bevy_ecs::prelude::*;
|
use bevy_ecs::prelude::*;
|
||||||
use bevy_math::{Mat4, Quat, Vec3};
|
use bevy_math::{Mat4, Quat, Vec3};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user