fix: make the dirty flag work
Signed-off-by: Schmarni <marnistromer@gmail.com>
This commit is contained in:
@@ -132,7 +132,10 @@ impl Node {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn set_enabled(&self, enabled: bool) {
|
pub fn set_enabled(&self, enabled: bool) {
|
||||||
self.enabled.store(enabled, Ordering::Relaxed)
|
self.enabled.store(enabled, Ordering::Relaxed);
|
||||||
|
if let Ok(spatial) = self.get_aspect::<Spatial>() {
|
||||||
|
spatial.bevy_dirty.store(true, Ordering::Relaxed);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
pub fn destroy(&self) {
|
pub fn destroy(&self) {
|
||||||
if let Some(client) = self.get_client() {
|
if let Some(client) = self.get_client() {
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ use crate::core::entity_handle::EntityHandle;
|
|||||||
use crate::core::error::Result;
|
use crate::core::error::Result;
|
||||||
use crate::core::registry::Registry;
|
use crate::core::registry::Registry;
|
||||||
use crate::nodes::{Node, OWNED_ASPECT_ALIAS_INFO};
|
use crate::nodes::{Node, OWNED_ASPECT_ALIAS_INFO};
|
||||||
|
use bevy::platform::collections::HashMap;
|
||||||
use bevy::prelude::Transform as BevyTransform;
|
use bevy::prelude::Transform as BevyTransform;
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use bevy::render::primitives::Aabb;
|
use bevy::render::primitives::Aabb;
|
||||||
@@ -90,17 +91,16 @@ fn despawn_unneeded_spatial_nodes(query: Query<(Entity, &SpatialNode)>, cmds: Pa
|
|||||||
fn update_spatial_nodes(
|
fn update_spatial_nodes(
|
||||||
mut query: Query<(Entity, &mut BevyTransform, &SpatialNode, &mut Visibility)>,
|
mut query: Query<(Entity, &mut BevyTransform, &SpatialNode, &mut Visibility)>,
|
||||||
) {
|
) {
|
||||||
|
let mut spatials = HashMap::new();
|
||||||
for (entity, mut transform, spatial_node, mut vis) in query.iter_mut() {
|
for (entity, mut transform, spatial_node, mut vis) in query.iter_mut() {
|
||||||
let _span = debug_span!("updating spatial node").entered();
|
let _span = debug_span!("updating spatial node").entered();
|
||||||
let Some(spatial) = spatial_node.0.upgrade() else {
|
let Some(spatial) = spatial_node.0.upgrade() else {
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
if !spatial.bevy_dirty.swap(false, Ordering::Relaxed) {
|
if !spatial.bevy_dirty.load(Ordering::Relaxed) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
println!("Spatial node was dirty on entity `{}`", entity);
|
|
||||||
|
|
||||||
// Set visibility based on node enabled state
|
// Set visibility based on node enabled state
|
||||||
if spatial
|
if spatial
|
||||||
.node()
|
.node()
|
||||||
@@ -112,6 +112,10 @@ fn update_spatial_nodes(
|
|||||||
*vis = Visibility::Hidden;
|
*vis = Visibility::Hidden;
|
||||||
}
|
}
|
||||||
*transform = BevyTransform::from_matrix(spatial.local_transform());
|
*transform = BevyTransform::from_matrix(spatial.local_transform());
|
||||||
|
spatials.insert(Arc::as_ptr(&spatial) as usize, spatial);
|
||||||
|
}
|
||||||
|
for spatial in spatials.into_values() {
|
||||||
|
spatial.bevy_dirty.store(false, Ordering::Relaxed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -164,7 +168,7 @@ static ZONEABLE_REGISTRY: Registry<Spatial> = Registry::new();
|
|||||||
|
|
||||||
pub struct Spatial {
|
pub struct Spatial {
|
||||||
pub node: Weak<Node>,
|
pub node: Weak<Node>,
|
||||||
bevy_dirty: AtomicBool,
|
pub(super) bevy_dirty: AtomicBool,
|
||||||
entity: RwLock<Option<EntityHandle>>,
|
entity: RwLock<Option<EntityHandle>>,
|
||||||
parent: RwLock<Option<Arc<Spatial>>>,
|
parent: RwLock<Option<Arc<Spatial>>>,
|
||||||
old_parent: RwLock<Option<Arc<Spatial>>>,
|
old_parent: RwLock<Option<Arc<Spatial>>>,
|
||||||
@@ -190,6 +194,8 @@ impl Spatial {
|
|||||||
}
|
}
|
||||||
pub fn set_entity(&self, entity: Entity) {
|
pub fn set_entity(&self, entity: Entity) {
|
||||||
self.entity.write().replace(entity.into());
|
self.entity.write().replace(entity.into());
|
||||||
|
self.bevy_dirty.store(true, Ordering::Relaxed);
|
||||||
|
println!("setting entity dirty: {entity}");
|
||||||
}
|
}
|
||||||
pub fn add_to(
|
pub fn add_to(
|
||||||
node: &Arc<Node>,
|
node: &Arc<Node>,
|
||||||
@@ -277,8 +283,8 @@ impl Spatial {
|
|||||||
parent_transform * self.local_transform()
|
parent_transform * self.local_transform()
|
||||||
}
|
}
|
||||||
pub fn set_local_transform(&self, transform: Mat4) {
|
pub fn set_local_transform(&self, transform: Mat4) {
|
||||||
self.bevy_dirty.store(true, Ordering::Relaxed);
|
|
||||||
*self.transform.write() = transform;
|
*self.transform.write() = transform;
|
||||||
|
self.bevy_dirty.store(true, Ordering::Relaxed);
|
||||||
}
|
}
|
||||||
pub fn set_local_transform_components(
|
pub fn set_local_transform_components(
|
||||||
&self,
|
&self,
|
||||||
|
|||||||
Reference in New Issue
Block a user