unified naming for field fetching via reflection

- previous approach with `ComponentProvider` trait was quite misleading, it didn't return a "component" - it simply returned marked fieds
- the new approach is more explicit - method names tells exactly what they do
This commit is contained in:
Dmitry Stepanov
2026-05-10 18:28:18 +03:00
parent fcd280057b
commit 1c0cf15c50
52 changed files with 216 additions and 203 deletions
+2 -2
View File
@@ -912,7 +912,7 @@ impl RenderDataBundleStorage {
}
}
if let Some(reflection_probe) = node.component_ref::<ReflectionProbe>() {
if let Some(reflection_probe) = node.self_or_field_ref::<ReflectionProbe>() {
if (reflection_probe as &dyn NodeTrait)
.world_bounding_box()
.is_contains_point(observer_position.translation)
@@ -922,7 +922,7 @@ impl RenderDataBundleStorage {
}
if options.collect_lights {
if let Some(base_light) = node.component_ref::<BaseLight>() {
if let Some(base_light) = node.self_or_field_ref::<BaseLight>() {
if frustum.is_intersects_aabb(&node.world_bounding_box())
&& base_light.global_visibility()
&& base_light.is_globally_enabled()
+3 -3
View File
@@ -243,7 +243,7 @@ pub trait AnimationSource {
let model_graph = self.inner_graph();
for src_node_ref in model_graph.linear_iter() {
if let Some(src_animations) = src_node_ref
.component_ref::<InheritableVariable<AnimationContainer<Handle<Self::Node>>>>()
.self_or_field_ref::<InheritableVariable<AnimationContainer<Handle<Self::Node>>>>()
{
for src_anim in src_animations.iter() {
let mut anim_copy = src_anim.clone();
@@ -316,7 +316,7 @@ pub trait AnimationSource {
let dest_animations = graph
.node_mut(dest_animation_player)
.component_mut::<InheritableVariable<AnimationContainer<Handle<Self::Node>>>>()
.self_or_field_mut::<InheritableVariable<AnimationContainer<Handle<Self::Node>>>>()
.unwrap();
for animation in animations {
@@ -340,7 +340,7 @@ pub trait AnimationSource {
self_kind: ResourceKind,
) -> Vec<Handle<fyrox_animation::Animation<Handle<Self::Node>>>> {
if let Some((animation_player, _)) = graph.find(root, &mut |n| {
n.component_ref::<InheritableVariable<AnimationContainer<Handle<Self::Node>>>>()
n.self_or_field_ref::<InheritableVariable<AnimationContainer<Handle<Self::Node>>>>()
.is_some()
}) {
self.retarget_animations_to_player(root, animation_player, graph, self_kind)
+2 -2
View File
@@ -1003,7 +1003,7 @@ impl Base {
{
self.scripts
.iter()
.find_map(|s| s.as_ref().and_then(|s| s.query_component_ref::<C>()))
.find_map(|s| s.as_ref().and_then(|s| s.self_or_field_ref::<C>()))
}
/// Tries find a component of the given type `C` across **all** available scripts of the node.
@@ -1016,7 +1016,7 @@ impl Base {
{
self.scripts
.iter_mut()
.find_map(|s| s.as_mut().and_then(|s| s.query_component_mut::<C>()))
.find_map(|s| s.as_mut().and_then(|s| s.self_or_field_mut::<C>()))
}
/// Returns total count of scripts assigned to the node.
+6 -3
View File
@@ -371,7 +371,7 @@ fn tile_map_to_collider_shape(
let tile_map = nodes
.try_borrow(tile_map.0)
.ok()?
.component_ref::<TileMap>()?;
.self_or_field_ref::<TileMap>()?;
let tile_set_resource = tile_map.tile_set()?.data_ref();
let tile_set = tile_set_resource.as_loaded_ref()?;
@@ -842,7 +842,10 @@ impl PhysicsWorld {
let h = Handle::decode_from_u128(self.colliders.get(handle).unwrap().user_data);
pred(
h,
graph.node(h).component_ref::<collider::Collider>().unwrap(),
graph
.node(h)
.self_or_field_ref::<collider::Collider>()
.unwrap(),
)
} else {
true
@@ -1180,7 +1183,7 @@ impl PhysicsWorld {
}
}
} else if let Ok(parent_body) =
nodes.try_get_component_of_type::<dim2::rigidbody::RigidBody>(collider_node.parent())
nodes.try_get_or_field_ref::<dim2::rigidbody::RigidBody>(collider_node.parent())
{
if parent_body.native.get() != RigidBodyHandle::invalid() {
let rigid_body_native = parent_body.native.get();
+8 -5
View File
@@ -525,7 +525,7 @@ fn make_trimesh(
let root_inv_transform = owner_inv_transform;
for &source in sources {
if let Ok(mesh) = nodes.try_get_component_of_type::<Mesh>(source.0) {
if let Ok(mesh) = nodes.try_get_or_field_ref::<Mesh>(source.0) {
let global_transform = root_inv_transform * mesh.global_transform();
for surface in mesh.surfaces() {
@@ -810,11 +810,11 @@ fn collider_shape_into_native_shape(
}
}
ColliderShape::Heightfield(heightfield) => pool
.try_get_component_of_type::<Terrain>(heightfield.geometry_source.0)
.try_get_or_field_ref::<Terrain>(heightfield.geometry_source.0)
.ok()
.and_then(make_heightfield),
ColliderShape::Polyhedron(polyhedron) => pool
.try_get_component_of_type::<Mesh>(polyhedron.geometry_source.0)
.try_get_or_field_ref::<Mesh>(polyhedron.geometry_source.0)
.ok()
.map(|mesh| make_polyhedron_shape(owner_inv_global_transform, mesh)),
}
@@ -1300,7 +1300,10 @@ impl PhysicsWorld {
let h = Handle::decode_from_u128(self.colliders.get(handle).unwrap().user_data);
pred(
h,
graph.node(h).component_ref::<collider::Collider>().unwrap(),
graph
.node(h)
.self_or_field_ref::<collider::Collider>()
.unwrap(),
)
} else {
true
@@ -1712,7 +1715,7 @@ impl PhysicsWorld {
}
}
} else if let Ok(parent_body) =
nodes.try_get_component_of_type::<scene::rigidbody::RigidBody>(collider_node.parent())
nodes.try_get_or_field_ref::<scene::rigidbody::RigidBody>(collider_node.parent())
{
if parent_body.native.get() != RigidBodyHandle::invalid() {
let inv_global_transform = isometric_global_transform(nodes, handle)
+2 -2
View File
@@ -269,11 +269,11 @@ pub trait NodeTrait: BaseNodeTrait + Reflect + Visit {
// See ObjectOrVariantHelper for the cause of the indirection.
impl<T: NodeTrait> ObjectOrVariantHelper<Node, T> for PhantomData<T> {
fn convert_to_dest_type_helper(node: &Node) -> Option<&T> {
(node.0.deref() as &dyn Reflect).self_or_field_ref_of_type()
(node.0.deref() as &dyn Reflect).self_or_field_ref()
}
fn convert_to_dest_type_helper_mut(node: &mut Node) -> Option<&mut T> {
(node.0.deref_mut() as &mut dyn Reflect).self_or_field_mut_of_type()
(node.0.deref_mut() as &mut dyn Reflect).self_or_field_mut()
}
}
+2 -6
View File
@@ -187,9 +187,7 @@ impl NodeTrait for Ragdoll {
if *self.deactivate_colliders {
for child in limb_body.children() {
if let Ok(mut collider) =
mbc.try_get_component_of_type_mut::<Collider>(*child)
{
if let Ok(mut collider) = mbc.try_get_or_field_mut::<Collider>(*child) {
collider.set_is_sensor(false);
}
}
@@ -226,9 +224,7 @@ impl NodeTrait for Ragdoll {
if *self.deactivate_colliders {
for child in limb_body.children() {
if let Ok(mut collider) =
mbc.try_get_component_of_type_mut::<Collider>(*child)
{
if let Ok(mut collider) = mbc.try_get_or_field_mut::<Collider>(*child) {
collider.set_is_sensor(true);
}
}
+4 -4
View File
@@ -924,14 +924,14 @@ impl Script {
/// Tries to borrow a component of given type.
#[inline]
pub fn query_component_ref<T: Reflect>(&self) -> Option<&T> {
(self.instance.deref() as &dyn Reflect).self_or_field_ref_of_type()
pub fn self_or_field_ref<T: Reflect>(&self) -> Option<&T> {
(self.instance.deref() as &dyn Reflect).self_or_field_ref()
}
/// Tries to borrow a component of given type.
#[inline]
pub fn query_component_mut<T: Reflect>(&mut self) -> Option<&mut T> {
(self.instance.deref_mut() as &mut dyn Reflect).self_or_field_mut_of_type()
pub fn self_or_field_mut<T: Reflect>(&mut self) -> Option<&mut T> {
(self.instance.deref_mut() as &mut dyn Reflect).self_or_field_mut()
}
}