Skip to content

Commit

Permalink
replaced component querying from nodes with ComponentProvider trait
Browse files Browse the repository at this point in the history
- component querying is now less confusing
  • Loading branch information
mrDIMAS committed Oct 28, 2024
1 parent ecddff7 commit 6f6b105
Show file tree
Hide file tree
Showing 25 changed files with 56 additions and 150 deletions.
11 changes: 4 additions & 7 deletions fyrox-impl/src/scene/animation/absm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ use crate::{
math::aabb::AxisAlignedBoundingBox,
pool::Handle,
reflect::prelude::*,
type_traits::prelude::*,
uuid::{uuid, Uuid},
variable::InheritableVariable,
visitor::prelude::*,
TypeUuidProvider,
},
scene::{
animation::prelude::*,
Expand Down Expand Up @@ -210,10 +210,12 @@ impl LayerMaskExt for LayerMask {
/// .build(graph)
/// }
/// ```
#[derive(Visit, Reflect, Clone, Debug, Default)]
#[derive(Visit, Reflect, Clone, Debug, Default, ComponentProvider)]
pub struct AnimationBlendingStateMachine {
base: Base,
#[component(include)]
machine: InheritableVariable<Machine>,
#[component(include)]
animation_player: InheritableVariable<Handle<Node>>,
}

Expand Down Expand Up @@ -267,11 +269,6 @@ impl DerefMut for AnimationBlendingStateMachine {
}

impl NodeTrait for AnimationBlendingStateMachine {
crate::impl_query_component!(
machine: InheritableVariable<Machine>,
animation_player: InheritableVariable<Handle<Node>>
);

fn local_bounding_box(&self) -> AxisAlignedBoundingBox {
self.base.local_bounding_box()
}
Expand Down
11 changes: 4 additions & 7 deletions fyrox-impl/src/scene/animation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ use crate::{
math::aabb::AxisAlignedBoundingBox,
pool::Handle,
reflect::prelude::*,
type_traits::prelude::*,
uuid::{uuid, Uuid},
variable::InheritableVariable,
visitor::prelude::*,
TypeUuidProvider,
},
generic_animation::value::{BoundValueCollection, TrackValue, ValueBinding},
scene::{
Expand Down Expand Up @@ -242,10 +242,12 @@ impl BoundValueCollectionExt for BoundValueCollection {
/// The example creates a bounce animation first - it is a simple animation that animates position of a given node
/// (`animated_node`). Only then it creates an animation player node with an animation container with a single animation.
/// To understand why this is so complicated, see the docs of [`Animation`].
#[derive(Visit, Reflect, Clone, Debug)]
#[derive(Visit, Reflect, Clone, Debug, ComponentProvider)]
pub struct AnimationPlayer {
base: Base,
#[component(include)]
animations: InheritableVariable<AnimationContainer>,
#[component(include)]
auto_apply: bool,
}

Expand Down Expand Up @@ -317,11 +319,6 @@ impl DerefMut for AnimationPlayer {
}

impl NodeTrait for AnimationPlayer {
crate::impl_query_component!(
animations: InheritableVariable<AnimationContainer>,
auto_apply: bool
);

fn local_bounding_box(&self) -> AxisAlignedBoundingBox {
self.base.local_bounding_box()
}
Expand Down
6 changes: 2 additions & 4 deletions fyrox-impl/src/scene/camera.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ use crate::{
math::{aabb::AxisAlignedBoundingBox, frustum::Frustum, ray::Ray, Rect},
pool::Handle,
reflect::prelude::*,
type_traits::prelude::*,
uuid::{uuid, Uuid},
uuid_provider,
variable::InheritableVariable,
visitor::{Visit, VisitResult, Visitor},
TypeUuidProvider,
},
graph::BaseSceneGraph,
resource::texture::{
Expand Down Expand Up @@ -352,7 +352,7 @@ impl Default for Exposure {
///
/// Each camera forces engine to re-render same scene one more time, which may cause almost double load
/// of your GPU.
#[derive(Debug, Visit, Reflect, Clone)]
#[derive(Debug, Visit, Reflect, Clone, ComponentProvider)]
pub struct Camera {
base: Base,

Expand Down Expand Up @@ -735,8 +735,6 @@ impl Camera {
}

impl NodeTrait for Camera {
crate::impl_query_component!();

/// Returns current **local-space** bounding box.
#[inline]
fn local_bounding_box(&self) -> AxisAlignedBoundingBox {
Expand Down
6 changes: 2 additions & 4 deletions fyrox-impl/src/scene/collider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ use crate::{
num_traits::{NumCast, One, ToPrimitive, Zero},
pool::Handle,
reflect::prelude::*,
type_traits::prelude::*,
uuid::{uuid, Uuid},
variable::InheritableVariable,
visitor::prelude::*,
TypeUuidProvider,
},
scene::{
base::{Base, BaseBuilder},
Expand Down Expand Up @@ -545,7 +545,7 @@ impl ColliderShape {

/// Collider is a geometric entity that can be attached to a rigid body to allow participate it
/// participate in contact generation, collision response and proximity queries.
#[derive(Reflect, Visit, Debug)]
#[derive(Reflect, Visit, Debug, ComponentProvider)]
pub struct Collider {
base: Base,

Expand Down Expand Up @@ -850,8 +850,6 @@ impl Collider {
}

impl NodeTrait for Collider {
crate::impl_query_component!();

fn local_bounding_box(&self) -> AxisAlignedBoundingBox {
self.base.local_bounding_box()
}
Expand Down
6 changes: 2 additions & 4 deletions fyrox-impl/src/scene/decal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ use crate::{
math::aabb::AxisAlignedBoundingBox,
pool::Handle,
reflect::prelude::*,
type_traits::prelude::*,
uuid::{uuid, Uuid},
variable::InheritableVariable,
visitor::prelude::*,
TypeUuidProvider,
},
resource::texture::TextureResource,
scene::{
Expand Down Expand Up @@ -104,7 +104,7 @@ use std::ops::{Deref, DerefMut};
/// .build(graph)
/// }
/// ```
#[derive(Debug, Visit, Default, Clone, Reflect)]
#[derive(Debug, Visit, Default, Clone, Reflect, ComponentProvider)]
pub struct Decal {
base: Base,

Expand Down Expand Up @@ -211,8 +211,6 @@ impl Decal {
}

impl NodeTrait for Decal {
crate::impl_query_component!();

/// Returns current **local-space** bounding box.
#[inline]
fn local_bounding_box(&self) -> AxisAlignedBoundingBox {
Expand Down
6 changes: 2 additions & 4 deletions fyrox-impl/src/scene/dim2/collider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ use crate::{
math::aabb::AxisAlignedBoundingBox,
pool::Handle,
reflect::prelude::*,
type_traits::prelude::*,
uuid::{uuid, Uuid},
variable::InheritableVariable,
visitor::prelude::*,
TypeUuidProvider,
},
scene::{
base::{Base, BaseBuilder},
Expand Down Expand Up @@ -262,7 +262,7 @@ impl ColliderShape {

/// Collider is a geometric entity that can be attached to a rigid body to allow participate it
/// participate in contact generation, collision response and proximity queries.
#[derive(Reflect, Visit, Debug)]
#[derive(Reflect, Visit, Debug, ComponentProvider)]
pub struct Collider {
base: Base,

Expand Down Expand Up @@ -567,8 +567,6 @@ impl Collider {
}

impl NodeTrait for Collider {
crate::impl_query_component!();

fn local_bounding_box(&self) -> AxisAlignedBoundingBox {
self.base.local_bounding_box()
}
Expand Down
6 changes: 2 additions & 4 deletions fyrox-impl/src/scene/dim2/joint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ use crate::{
math::{aabb::AxisAlignedBoundingBox, m4x4_approx_eq},
pool::Handle,
reflect::prelude::*,
type_traits::prelude::*,
uuid::{uuid, Uuid},
variable::InheritableVariable,
visitor::prelude::*,
TypeUuidProvider,
},
scene::{
base::{Base, BaseBuilder},
Expand Down Expand Up @@ -156,7 +156,7 @@ impl JointLocalFrames {

/// Joint is used to restrict motion of two rigid bodies. There are numerous examples of joints in
/// real life: door hinge, ball joints in human arms, etc.
#[derive(Visit, Reflect, Debug)]
#[derive(Visit, Reflect, Debug, ComponentProvider)]
pub struct Joint {
base: Base,

Expand Down Expand Up @@ -282,8 +282,6 @@ impl Joint {
}

impl NodeTrait for Joint {
crate::impl_query_component!();

fn local_bounding_box(&self) -> AxisAlignedBoundingBox {
self.base.local_bounding_box()
}
Expand Down
9 changes: 3 additions & 6 deletions fyrox-impl/src/scene/dim2/rectangle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,17 @@
//!
//! See [`Rectangle`] docs for more info.

use crate::scene::node::RdcControlFlow;
use crate::{
core::{
algebra::{Point3, Vector2, Vector3},
color::Color,
math::{aabb::AxisAlignedBoundingBox, Rect, TriangleDefinition},
pool::Handle,
reflect::prelude::*,
type_traits::prelude::*,
uuid::{uuid, Uuid},
variable::InheritableVariable,
visitor::prelude::*,
TypeUuidProvider,
},
material::{self, Material, MaterialResource},
renderer::{self, bundle::RenderContext},
Expand All @@ -45,7 +44,7 @@ use crate::{
VertexAttributeDataType, VertexAttributeDescriptor, VertexAttributeUsage, VertexTrait,
},
mesh::RenderPath,
node::{Node, NodeTrait},
node::{Node, NodeTrait, RdcControlFlow},
},
};
use bytemuck::{Pod, Zeroable};
Expand Down Expand Up @@ -163,7 +162,7 @@ impl Hash for RectangleVertex {
/// image, but just changing portion for rendering. Keep in mind that the coordinates are normalized
/// which means `[0; 0]` corresponds to top-left corner of the texture and `[1; 1]` corresponds to
/// right-bottom corner.
#[derive(Reflect, Debug, Clone)]
#[derive(Reflect, Debug, Clone, ComponentProvider)]
pub struct Rectangle {
base: Base,

Expand Down Expand Up @@ -276,8 +275,6 @@ impl Rectangle {
}

impl NodeTrait for Rectangle {
crate::impl_query_component!();

fn local_bounding_box(&self) -> AxisAlignedBoundingBox {
AxisAlignedBoundingBox::unit()
}
Expand Down
6 changes: 2 additions & 4 deletions fyrox-impl/src/scene/dim2/rigidbody.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ use crate::{
parking_lot::Mutex,
pool::Handle,
reflect::prelude::*,
type_traits::prelude::*,
uuid::{uuid, Uuid},
variable::InheritableVariable,
visitor::prelude::*,
TypeUuidProvider,
},
scene::{
base::{Base, BaseBuilder},
Expand Down Expand Up @@ -83,7 +83,7 @@ pub(crate) enum ApplyAction {
///
/// Rigid body that does not move for some time will go asleep. This means that the body will not
/// move unless it is woken up by some other moving body. This feature allows to save CPU resources.
#[derive(Visit, Reflect)]
#[derive(Visit, Reflect, ComponentProvider)]
pub struct RigidBody {
base: Base,

Expand Down Expand Up @@ -423,8 +423,6 @@ impl RigidBody {
}

impl NodeTrait for RigidBody {
crate::impl_query_component!();

fn local_bounding_box(&self) -> AxisAlignedBoundingBox {
self.base.local_bounding_box()
}
Expand Down
6 changes: 2 additions & 4 deletions fyrox-impl/src/scene/joint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ use crate::{
math::{aabb::AxisAlignedBoundingBox, m4x4_approx_eq},
pool::Handle,
reflect::prelude::*,
type_traits::prelude::*,
uuid::{uuid, Uuid},
variable::InheritableVariable,
visitor::prelude::*,
TypeUuidProvider,
},
scene::{
base::{Base, BaseBuilder},
Expand Down Expand Up @@ -212,7 +212,7 @@ impl JointLocalFrames {

/// Joint is used to restrict motion of two rigid bodies. There are numerous examples of joints in
/// real life: door hinge, ball joints in human arms, etc.
#[derive(Visit, Reflect, Debug)]
#[derive(Visit, Reflect, Debug, ComponentProvider)]
pub struct Joint {
base: Base,

Expand Down Expand Up @@ -355,8 +355,6 @@ impl Joint {
}

impl NodeTrait for Joint {
crate::impl_query_component!();

fn local_bounding_box(&self) -> AxisAlignedBoundingBox {
self.base.local_bounding_box()
}
Expand Down
7 changes: 3 additions & 4 deletions fyrox-impl/src/scene/light/directional.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ use crate::{
math::aabb::AxisAlignedBoundingBox,
pool::Handle,
reflect::prelude::*,
type_traits::prelude::*,
uuid::{uuid, Uuid},
variable::InheritableVariable,
visitor::{Visit, VisitResult, Visitor},
TypeUuidProvider,
},
scene::{
base::Base,
Expand Down Expand Up @@ -125,8 +125,9 @@ impl CsmOptions {
}

/// See module docs.
#[derive(Default, Debug, Visit, Reflect, Clone)]
#[derive(Default, Debug, Visit, Reflect, Clone, ComponentProvider)]
pub struct DirectionalLight {
#[component(include)]
base_light: BaseLight,
/// See [`CsmOptions`].
pub csm_options: InheritableVariable<CsmOptions>,
Expand Down Expand Up @@ -174,8 +175,6 @@ impl DirectionalLight {
}

impl NodeTrait for DirectionalLight {
crate::impl_query_component!(base_light: BaseLight);

fn local_bounding_box(&self) -> AxisAlignedBoundingBox {
AxisAlignedBoundingBox::default()
}
Expand Down
7 changes: 3 additions & 4 deletions fyrox-impl/src/scene/light/point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ use crate::{
math::aabb::AxisAlignedBoundingBox,
pool::Handle,
reflect::prelude::*,
type_traits::prelude::*,
uuid::{uuid, Uuid},
variable::InheritableVariable,
visitor::{Visit, VisitResult, Visitor},
TypeUuidProvider,
},
scene::{
base::Base,
Expand All @@ -60,8 +60,9 @@ use fyrox_graph::BaseSceneGraph;
use std::ops::{Deref, DerefMut};

/// See module docs.
#[derive(Debug, Reflect, Clone, Visit)]
#[derive(Debug, Reflect, Clone, Visit, ComponentProvider)]
pub struct PointLight {
#[component(include)]
base_light: BaseLight,

#[reflect(min_value = 0.0, step = 0.001)]
Expand Down Expand Up @@ -130,8 +131,6 @@ impl PointLight {
}

impl NodeTrait for PointLight {
crate::impl_query_component!(base_light: BaseLight);

fn local_bounding_box(&self) -> AxisAlignedBoundingBox {
AxisAlignedBoundingBox::from_radius(*self.radius)
}
Expand Down
Loading

0 comments on commit 6f6b105

Please sign in to comment.