pub struct TransformSyncSystem;
impl gizmo_core::system::System for TransformSyncSystem {
fn access_info(&self) -> gizmo_core::system::AccessInfo {
let mut info = gizmo_core::system::AccessInfo::new();
info.is_exclusive = true;
info
}
fn run(&mut self, world: &gizmo_core::world::World, _dt: f32) {
let transforms = world.borrow_mut::<crate::physics::Transform>();
for (_, trans) in transforms.iter_mut() {
trans.update_local_matrix();
}
}
}
pub struct TransformPropagateSystem;
impl gizmo_core::system::System for TransformPropagateSystem {
fn access_info(&self) -> gizmo_core::system::AccessInfo {
let mut info = gizmo_core::system::AccessInfo::new();
info.is_exclusive = true; info
}
fn run(&mut self, world: &gizmo_core::world::World, _dt: f32) {
let locals = world.borrow::<crate::physics::Transform>();
let mut globals = world.borrow_mut::<crate::physics::GlobalTransform>();
let parents = world.borrow::<gizmo_core::component::Parent>();
let children_storage = world.borrow::<gizmo_core::component::Children>();
let mut queue = Vec::new();
for (id, local) in locals.iter() {
if parents.get(id).is_none() {
if let Some(global) = globals.get_mut(id) {
global.matrix = local.local_matrix;
if let Some(children) = children_storage.get(id) {
for &child_id in &children.0 {
queue.push((global.matrix, child_id));
}
}
}
}
}
let mut head = 0;
while head < queue.len() {
let (parent_matrix, current_id) = queue[head];
head += 1;
if let Some(local) = locals.get(current_id) {
if let Some(global) = globals.get_mut(current_id) {
global.matrix = parent_matrix * local.local_matrix;
if let Some(children) = children_storage.get(current_id) {
for &child_id in &children.0 {
queue.push((global.matrix, child_id));
}
}
}
}
}
}
}