mirror of
https://github.com/FyroxEngine/Fyrox.git
synced 2026-10-12 02:02:20 +00:00
removed ComponentProvider, merged its functionality into Reflect
- chained component fetching isn't supported yet, so it is not one-to-one merge
This commit is contained in:
@@ -46,6 +46,7 @@ use crate::{
|
||||
instant,
|
||||
log::Log,
|
||||
pool::Handle,
|
||||
reflect::prelude::*,
|
||||
reflect::Reflect,
|
||||
task::TaskPool,
|
||||
warn, SafeLock,
|
||||
@@ -117,6 +118,7 @@ use fyrox_sound::{
|
||||
buffer::{loader::SoundBufferLoader, SoundBuffer},
|
||||
renderer::hrtf::{HrirSphereLoader, HrirSphereResourceData},
|
||||
};
|
||||
use std::fmt::Debug;
|
||||
use std::{
|
||||
any::TypeId,
|
||||
cell::Cell,
|
||||
@@ -143,6 +145,8 @@ use winit::{
|
||||
|
||||
/// Serialization context holds runtime type information that allows to create unknown types using
|
||||
/// their UUIDs and a respective constructors.
|
||||
#[derive(Reflect)]
|
||||
#[reflect(hide_all, non_cloneable)] // TODO
|
||||
pub struct SerializationContext {
|
||||
/// A node constructor container.
|
||||
pub node_constructors: NodeConstructorContainer,
|
||||
@@ -150,6 +154,12 @@ pub struct SerializationContext {
|
||||
pub script_constructors: ScriptConstructorContainer,
|
||||
}
|
||||
|
||||
impl Debug for SerializationContext {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "SerializationContext")
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for SerializationContext {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
@@ -2916,7 +2926,7 @@ mod test {
|
||||
EventReceived(Source),
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Reflect, Visit, TypeUuidProvider, ComponentProvider)]
|
||||
#[derive(Debug, Clone, Reflect, Visit, TypeUuidProvider)]
|
||||
#[type_uuid(id = "2569de84-d4b2-427d-969b-d5c7b31a0ba6")]
|
||||
struct MyScript {
|
||||
#[reflect(hidden)]
|
||||
@@ -2983,7 +2993,7 @@ mod test {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Reflect, Visit, TypeUuidProvider, ComponentProvider)]
|
||||
#[derive(Debug, Clone, Reflect, Visit, TypeUuidProvider)]
|
||||
#[type_uuid(id = "1cebacd9-b500-4753-93be-39db344add21")]
|
||||
struct MySubScript {
|
||||
#[reflect(hidden)]
|
||||
@@ -3142,7 +3152,7 @@ mod test {
|
||||
Bar(String),
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Reflect, Visit, TypeUuidProvider, ComponentProvider)]
|
||||
#[derive(Debug, Clone, Reflect, Visit, TypeUuidProvider)]
|
||||
#[type_uuid(id = "bf2976ad-f41d-4de6-9a32-b1a293956058")]
|
||||
struct ScriptListeningToMessages {
|
||||
index: u32,
|
||||
@@ -3193,7 +3203,7 @@ mod test {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Reflect, Visit, TypeUuidProvider, ComponentProvider)]
|
||||
#[derive(Debug, Clone, Reflect, Visit, TypeUuidProvider)]
|
||||
#[type_uuid(id = "6bcbf9b4-9546-42d3-965a-de055ab85475")]
|
||||
struct ScriptSendingMessages {
|
||||
index: u32,
|
||||
@@ -3282,7 +3292,7 @@ mod test {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Reflect, Visit, TypeUuidProvider, ComponentProvider)]
|
||||
#[derive(Clone, Debug, PartialEq, Reflect, Visit, TypeUuidProvider)]
|
||||
#[type_uuid(id = "7bcbf9b4-9546-42d3-965a-de055ab85475")]
|
||||
pub struct ScriptSpawningAsyncTasks {
|
||||
num: Option<u32>,
|
||||
@@ -3305,7 +3315,7 @@ mod test {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Reflect, Visit, TypeUuidProvider, ComponentProvider)]
|
||||
#[derive(Clone, Debug, PartialEq, Reflect, Visit, TypeUuidProvider)]
|
||||
#[type_uuid(id = "8bcbf9b4-9546-42d3-965a-de055ab85475")]
|
||||
pub struct ScriptWithoutAsyncTasks {}
|
||||
|
||||
@@ -3382,7 +3392,7 @@ mod test {
|
||||
);
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Reflect, Visit, TypeUuidProvider, ComponentProvider)]
|
||||
#[derive(Clone, Debug, Reflect, Visit, TypeUuidProvider)]
|
||||
#[type_uuid(id = "9bcbf9b4-9546-42d3-965a-de055ab85475")]
|
||||
pub struct ScriptThatDeletesItself {
|
||||
#[reflect(hidden)]
|
||||
@@ -3423,7 +3433,7 @@ mod test {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Reflect, Visit, TypeUuidProvider, ComponentProvider)]
|
||||
#[derive(Clone, Debug, Reflect, Visit, TypeUuidProvider)]
|
||||
#[type_uuid(id = "9bcbf9b4-9546-42d3-965a-de055ab85475")]
|
||||
pub struct ScriptThatAddsScripts {
|
||||
num: usize,
|
||||
@@ -3472,7 +3482,7 @@ mod test {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Reflect, Visit, TypeUuidProvider, ComponentProvider)]
|
||||
#[derive(Clone, Debug, Reflect, Visit, TypeUuidProvider)]
|
||||
#[type_uuid(id = "9bcbf9b4-9546-42d3-965a-de055ab85475")]
|
||||
pub struct SimpleScript {
|
||||
stuff: usize,
|
||||
|
||||
@@ -42,7 +42,6 @@ use crate::{
|
||||
};
|
||||
use fyrox_graph::constructor::ConstructorProvider;
|
||||
use fyrox_graph::SceneGraph;
|
||||
use std::any::{Any, TypeId};
|
||||
use std::ops::{Deref, DerefMut};
|
||||
|
||||
/// Scene specific root motion settings.
|
||||
@@ -139,7 +138,6 @@ impl LayerMaskExt for LayerMask {
|
||||
|
||||
type MachineType = InheritableVariable<Machine>;
|
||||
type AnimationPlayerHandle = InheritableVariable<Handle<AnimationPlayer>>;
|
||||
type AnimationPlayerUntypedHandle = InheritableVariable<Handle<Node>>;
|
||||
|
||||
/// Animation blending state machine (ABSM) is a node that takes multiple animations from an animation player and
|
||||
/// mixes them in arbitrary way into one animation. Usually, ABSMs are used to animate humanoid characters in games,
|
||||
@@ -230,40 +228,6 @@ pub struct AnimationBlendingStateMachine {
|
||||
animation_player: AnimationPlayerHandle,
|
||||
}
|
||||
|
||||
impl ComponentProvider for AnimationBlendingStateMachine {
|
||||
fn query_component_ref(&self, type_id: TypeId) -> Option<&dyn Any> {
|
||||
if type_id == TypeId::of::<Self>() {
|
||||
Some(self)
|
||||
} else if type_id == TypeId::of::<MachineType>() {
|
||||
Some(&self.machine)
|
||||
} else if type_id == TypeId::of::<AnimationPlayerUntypedHandle>() {
|
||||
Some(unsafe {
|
||||
std::mem::transmute::<&AnimationPlayerHandle, &AnimationPlayerUntypedHandle>(
|
||||
&self.animation_player,
|
||||
)
|
||||
})
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
fn query_component_mut(&mut self, type_id: TypeId) -> Option<&mut dyn Any> {
|
||||
if type_id == TypeId::of::<Self>() {
|
||||
Some(self)
|
||||
} else if type_id == TypeId::of::<MachineType>() {
|
||||
Some(&mut self.machine)
|
||||
} else if type_id == TypeId::of::<AnimationPlayerUntypedHandle>() {
|
||||
Some(unsafe {
|
||||
std::mem::transmute::<&mut AnimationPlayerHandle, &mut AnimationPlayerUntypedHandle>(
|
||||
&mut self.animation_player,
|
||||
)
|
||||
})
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl AnimationBlendingStateMachine {
|
||||
/// Sets new state machine to the node.
|
||||
pub fn set_machine(&mut self, machine: Machine) {
|
||||
|
||||
@@ -243,13 +243,11 @@ 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, ComponentProvider)]
|
||||
#[derive(Visit, Reflect, Clone, Debug)]
|
||||
#[reflect(derived_type = "Node")]
|
||||
pub struct AnimationPlayer {
|
||||
base: Base,
|
||||
#[component(include)]
|
||||
animations: InheritableVariable<AnimationContainer>,
|
||||
#[component(include)]
|
||||
auto_apply: bool,
|
||||
}
|
||||
|
||||
|
||||
@@ -46,7 +46,6 @@ use fyrox_core::pool::ObjectOrVariant;
|
||||
use fyrox_core::visitor::error::VisitError;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::{
|
||||
any::Any,
|
||||
cell::Cell,
|
||||
ops::{Deref, DerefMut},
|
||||
sync::mpsc::Sender,
|
||||
@@ -1000,7 +999,7 @@ impl Base {
|
||||
#[inline]
|
||||
pub fn try_get_script_component<C>(&self) -> Option<&C>
|
||||
where
|
||||
C: Any,
|
||||
C: Reflect,
|
||||
{
|
||||
self.scripts
|
||||
.iter()
|
||||
@@ -1013,7 +1012,7 @@ impl Base {
|
||||
#[inline]
|
||||
pub fn try_get_script_component_mut<C>(&mut self) -> Option<&mut C>
|
||||
where
|
||||
C: Any,
|
||||
C: Reflect,
|
||||
{
|
||||
self.scripts
|
||||
.iter_mut()
|
||||
|
||||
@@ -353,7 +353,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, ComponentProvider)]
|
||||
#[derive(Debug, Visit, Reflect, Clone)]
|
||||
#[reflect(derived_type = "Node")]
|
||||
pub struct Camera {
|
||||
base: Base,
|
||||
|
||||
@@ -611,7 +611,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, ComponentProvider)]
|
||||
#[derive(Reflect, Visit, Debug)]
|
||||
#[reflect(derived_type = "Node")]
|
||||
pub struct Collider {
|
||||
base: Base,
|
||||
|
||||
@@ -108,7 +108,7 @@ use std::ops::{Deref, DerefMut};
|
||||
/// .build(graph)
|
||||
/// }
|
||||
/// ```
|
||||
#[derive(Debug, Visit, Default, Clone, Reflect, ComponentProvider)]
|
||||
#[derive(Debug, Visit, Default, Clone, Reflect)]
|
||||
#[reflect(derived_type = "Node")]
|
||||
pub struct Decal {
|
||||
base: Base,
|
||||
|
||||
@@ -29,7 +29,6 @@ use crate::{
|
||||
math::aabb::AxisAlignedBoundingBox,
|
||||
pool::Handle,
|
||||
reflect::prelude::*,
|
||||
type_traits::prelude::*,
|
||||
uuid::{uuid, Uuid},
|
||||
uuid_provider,
|
||||
variable::InheritableVariable,
|
||||
@@ -268,7 +267,7 @@ impl ColliderShape {
|
||||
|
||||
/// Collider is a geometric entity that can be attached to a rigid body to allow to participate in
|
||||
/// contact generation, collision response and proximity queries.
|
||||
#[derive(Reflect, Visit, Debug, ComponentProvider)]
|
||||
#[derive(Reflect, Visit, Debug)]
|
||||
#[reflect(derived_type = "Node")]
|
||||
pub struct Collider {
|
||||
base: Base,
|
||||
|
||||
@@ -164,7 +164,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, ComponentProvider)]
|
||||
#[derive(Visit, Reflect, Debug)]
|
||||
#[reflect(derived_type = "Node")]
|
||||
pub struct Joint {
|
||||
base: Base,
|
||||
|
||||
@@ -171,7 +171,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, Visit, ComponentProvider)]
|
||||
#[derive(Reflect, Debug, Clone, Visit)]
|
||||
#[reflect(derived_type = "Node")]
|
||||
pub struct Rectangle {
|
||||
base: Base,
|
||||
|
||||
@@ -90,7 +90,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, ComponentProvider)]
|
||||
#[derive(Visit, Reflect)]
|
||||
#[reflect(derived_type = "Node")]
|
||||
pub struct RigidBody {
|
||||
base: Base,
|
||||
|
||||
@@ -78,7 +78,7 @@ use bitflags::bitflags;
|
||||
use fxhash::{FxHashMap, FxHashSet};
|
||||
use fyrox_material::MaterialResourceExtension;
|
||||
use std::{
|
||||
any::{Any, TypeId},
|
||||
any::TypeId,
|
||||
fmt::{Debug, Display, Formatter, Write},
|
||||
ops::{Deref, Index, IndexMut},
|
||||
sync::mpsc::{channel, Receiver, Sender},
|
||||
@@ -1915,7 +1915,7 @@ impl Graph {
|
||||
handle: Handle<impl ObjectOrVariant<Node>>,
|
||||
) -> Result<&C, GraphError>
|
||||
where
|
||||
C: Any,
|
||||
C: Reflect,
|
||||
{
|
||||
let handle = handle.to_base();
|
||||
let node = self.try_get_node(handle)?;
|
||||
@@ -1935,7 +1935,7 @@ impl Graph {
|
||||
handle: Handle<impl ObjectOrVariant<Node>>,
|
||||
) -> Result<&mut C, GraphError>
|
||||
where
|
||||
C: Any,
|
||||
C: Reflect,
|
||||
{
|
||||
let handle = handle.to_base();
|
||||
let node = self.try_get_node_mut(handle)?;
|
||||
@@ -2242,7 +2242,7 @@ mod test {
|
||||
use fyrox_resource::untyped::ResourceKind;
|
||||
use std::{fs, path::Path, sync::Arc};
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Reflect, Visit, TypeUuidProvider, ComponentProvider)]
|
||||
#[derive(Clone, Debug, PartialEq, Reflect, Visit, TypeUuidProvider)]
|
||||
#[type_uuid(id = "722feb80-a10b-4ee0-8cef-5d1473df8457")]
|
||||
struct MyScript {
|
||||
foo: String,
|
||||
@@ -2251,7 +2251,7 @@ mod test {
|
||||
|
||||
impl ScriptTrait for MyScript {}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Reflect, Visit, TypeUuidProvider, ComponentProvider)]
|
||||
#[derive(Clone, Debug, PartialEq, Reflect, Visit, TypeUuidProvider)]
|
||||
#[type_uuid(id = "722feb80-a10b-4ee0-8cef-5d1473df8458")]
|
||||
struct MyOtherScript {
|
||||
baz: u32,
|
||||
|
||||
@@ -205,7 +205,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, ComponentProvider)]
|
||||
#[derive(Visit, Reflect, Debug)]
|
||||
#[reflect(derived_type = "Node")]
|
||||
pub struct Joint {
|
||||
base: Base,
|
||||
|
||||
@@ -127,10 +127,9 @@ impl CsmOptions {
|
||||
}
|
||||
|
||||
/// See module docs.
|
||||
#[derive(Default, Debug, Visit, Reflect, Clone, ComponentProvider)]
|
||||
#[derive(Default, Debug, Visit, Reflect, Clone)]
|
||||
#[reflect(derived_type = "Node")]
|
||||
pub struct DirectionalLight {
|
||||
#[component(include)]
|
||||
base_light: BaseLight,
|
||||
/// See [`CsmOptions`].
|
||||
pub csm_options: InheritableVariable<CsmOptions>,
|
||||
|
||||
@@ -63,10 +63,9 @@ use fyrox_graph::SceneGraph;
|
||||
use std::ops::{Deref, DerefMut};
|
||||
|
||||
/// See module docs.
|
||||
#[derive(Debug, Reflect, Clone, Visit, ComponentProvider)]
|
||||
#[derive(Debug, Reflect, Clone, Visit)]
|
||||
#[reflect(derived_type = "Node")]
|
||||
pub struct PointLight {
|
||||
#[component(include)]
|
||||
base_light: BaseLight,
|
||||
|
||||
#[reflect(min_value = 0.0, step = 0.001)]
|
||||
|
||||
@@ -70,10 +70,9 @@ use fyrox_graph::SceneGraph;
|
||||
use std::ops::{Deref, DerefMut};
|
||||
|
||||
/// See module docs.
|
||||
#[derive(Debug, Reflect, Clone, Visit, ComponentProvider)]
|
||||
#[derive(Debug, Reflect, Clone, Visit)]
|
||||
#[reflect(derived_type = "Node")]
|
||||
pub struct SpotLight {
|
||||
#[component(include)]
|
||||
base_light: BaseLight,
|
||||
|
||||
#[reflect(min_value = 0.0, max_value = 3.14159, step = 0.1)]
|
||||
|
||||
@@ -317,7 +317,7 @@ impl RenderDataBundleStorageTrait for BatchContainer {
|
||||
///
|
||||
/// This example creates a unit cube surface with default material and then creates a mesh with this surface. If you need to create
|
||||
/// custom surface, see [`crate::scene::mesh::surface::SurfaceData`] docs for more info.
|
||||
#[derive(Debug, Reflect, Clone, Visit, ComponentProvider)]
|
||||
#[derive(Debug, Reflect, Clone, Visit)]
|
||||
#[reflect(derived_type = "Node")]
|
||||
pub struct Mesh {
|
||||
#[visit(rename = "Common")]
|
||||
|
||||
@@ -78,6 +78,7 @@ use crate::{
|
||||
utils::navmesh::Navmesh,
|
||||
};
|
||||
use fxhash::FxHashSet;
|
||||
use fyrox_core::blank_reflect_ref;
|
||||
use fyrox_core::dyntype::DynTypeConstructorContainer;
|
||||
use fyrox_core::pool::PoolError;
|
||||
use std::{
|
||||
@@ -280,6 +281,10 @@ pub struct Scene {
|
||||
pub enabled: InheritableVariable<bool>,
|
||||
}
|
||||
|
||||
impl Reflect for &'static mut Scene {
|
||||
blank_reflect_ref!();
|
||||
}
|
||||
|
||||
impl Clone for Scene {
|
||||
fn clone(&self) -> Self {
|
||||
self.clone_one_to_one().0
|
||||
|
||||
@@ -156,7 +156,7 @@ impl Visit for Container {
|
||||
/// scene.graph[handle].as_navigational_mesh_mut()
|
||||
/// }
|
||||
/// ```
|
||||
#[derive(Debug, Clone, Visit, Reflect, Default, ComponentProvider)]
|
||||
#[derive(Debug, Clone, Visit, Reflect, Default)]
|
||||
#[reflect(derived_type = "Node")]
|
||||
pub struct NavigationalMesh {
|
||||
base: Base,
|
||||
|
||||
@@ -36,7 +36,7 @@ use crate::{
|
||||
uuid_provider, variable,
|
||||
variable::mark_inheritable_properties_non_modified,
|
||||
visitor::{Visit, VisitResult, Visitor},
|
||||
ComponentProvider, NameProvider,
|
||||
NameProvider,
|
||||
},
|
||||
graph::SceneGraphNode,
|
||||
renderer::bundle::RenderContext,
|
||||
@@ -132,7 +132,7 @@ pub enum RdcControlFlow {
|
||||
}
|
||||
|
||||
/// A main trait for any scene graph node.
|
||||
pub trait NodeTrait: BaseNodeTrait + Reflect + Visit + ComponentProvider {
|
||||
pub trait NodeTrait: BaseNodeTrait + Reflect + Visit {
|
||||
/// Brief debugging information about this node.
|
||||
fn summary(&self) -> String {
|
||||
use std::fmt::Write;
|
||||
@@ -269,11 +269,11 @@ pub trait NodeTrait: BaseNodeTrait + Reflect + Visit + ComponentProvider {
|
||||
// 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 ComponentProvider).component_ref()
|
||||
(node.0.deref() as &dyn Reflect).self_or_field_ref_of_type()
|
||||
}
|
||||
|
||||
fn convert_to_dest_type_helper_mut(node: &mut Node) -> Option<&mut T> {
|
||||
(node.0.deref_mut() as &mut dyn ComponentProvider).component_mut()
|
||||
(node.0.deref_mut() as &mut dyn Reflect).self_or_field_mut_of_type()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -428,16 +428,6 @@ impl NameProvider for Node {
|
||||
}
|
||||
}
|
||||
|
||||
impl ComponentProvider for Node {
|
||||
fn query_component_ref(&self, type_id: TypeId) -> Option<&dyn Any> {
|
||||
self.0.query_component_ref(type_id)
|
||||
}
|
||||
|
||||
fn query_component_mut(&mut self, type_id: TypeId) -> Option<&mut dyn Any> {
|
||||
self.0.query_component_mut(type_id)
|
||||
}
|
||||
}
|
||||
|
||||
uuid_provider!(Node = "a9bc5231-155c-4564-b0ca-f23972673925");
|
||||
|
||||
impl Deref for Node {
|
||||
@@ -669,6 +659,14 @@ impl Reflect for Node {
|
||||
fn field_direct_mut(&mut self, index: usize) -> Option<FieldMut> {
|
||||
self.0.deref_mut().field_direct_mut(index)
|
||||
}
|
||||
|
||||
fn as_reflect_direct(&self) -> &dyn Reflect {
|
||||
self.0.as_reflect_direct()
|
||||
}
|
||||
|
||||
fn as_reflect_mut_direct(&mut self) -> &mut dyn Reflect {
|
||||
self.0.as_reflect_mut_direct()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -678,7 +676,6 @@ mod test {
|
||||
core::{
|
||||
algebra::{Matrix4, Vector3},
|
||||
futures::executor::block_on,
|
||||
impl_component_provider,
|
||||
reflect::prelude::*,
|
||||
uuid::{uuid, Uuid},
|
||||
variable::InheritableVariable,
|
||||
@@ -710,8 +707,6 @@ mod test {
|
||||
some_collection: InheritableVariable<Vec<u32>>,
|
||||
}
|
||||
|
||||
impl_component_provider!(MyScript);
|
||||
|
||||
impl TypeUuidProvider for MyScript {
|
||||
fn type_uuid() -> Uuid {
|
||||
uuid!("d3f66902-803f-4ace-8170-0aa485d98b40")
|
||||
|
||||
@@ -218,7 +218,7 @@ impl Visit for ParticleSystemRng {
|
||||
/// .build(graph);
|
||||
/// }
|
||||
/// ```
|
||||
#[derive(Debug, Clone, Reflect, ComponentProvider)]
|
||||
#[derive(Debug, Clone, Reflect)]
|
||||
#[reflect(derived_type = "Node")]
|
||||
pub struct ParticleSystem {
|
||||
base: Base,
|
||||
|
||||
@@ -40,7 +40,7 @@ use fyrox_graph::SceneGraph;
|
||||
use std::ops::{Deref, DerefMut};
|
||||
|
||||
/// A simplest possible node which represents point in space.
|
||||
#[derive(Clone, Reflect, Default, Debug, ComponentProvider)]
|
||||
#[derive(Clone, Reflect, Default, Debug)]
|
||||
#[reflect(derived_type = "Node")]
|
||||
pub struct Pivot {
|
||||
base: Base,
|
||||
|
||||
@@ -140,7 +140,7 @@ pub enum UpdateMode {
|
||||
/// .build(graph)
|
||||
/// }
|
||||
/// ```
|
||||
#[derive(Clone, Reflect, Debug, Visit, ComponentProvider, TypeUuidProvider)]
|
||||
#[derive(Clone, Reflect, Debug, Visit, TypeUuidProvider)]
|
||||
#[type_uuid(id = "7e0c138f-e371-4045-bd2c-ff5b165c7ee6")]
|
||||
#[reflect(derived_type = "Node")]
|
||||
#[visit(optional, post_visit_method = "on_visited")]
|
||||
|
||||
@@ -88,7 +88,7 @@ impl Limb {
|
||||
/// to create a ragdoll is to use the editor, and the ragdoll wizard in particular. However, if
|
||||
/// you're brave enough you can read this code <https://github.com/FyroxEngine/Fyrox/blob/master/editor/src/utils/ragdoll.rs> -
|
||||
/// it creates a ragdoll using a humanoid skeleton.
|
||||
#[derive(Clone, Reflect, Visit, Debug, Default, ComponentProvider)]
|
||||
#[derive(Clone, Reflect, Visit, Debug, Default)]
|
||||
#[reflect(derived_type = "Node")]
|
||||
#[visit(optional)]
|
||||
pub struct Ragdoll {
|
||||
|
||||
@@ -168,7 +168,7 @@ uuid_provider!(RigidBodyMassPropertiesType = "663b6a92-9c0f-4f47-b66a-6b4293312a
|
||||
///
|
||||
/// 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, ComponentProvider)]
|
||||
#[derive(Visit, Reflect)]
|
||||
#[reflect(derived_type = "Node")]
|
||||
pub struct RigidBody {
|
||||
base: Base,
|
||||
|
||||
@@ -57,7 +57,7 @@ use std::ops::{Deref, DerefMut};
|
||||
///
|
||||
/// 2D sound sources (with spatial blend == 0.0) are not influenced by listener's position and
|
||||
/// orientation.
|
||||
#[derive(Visit, Reflect, Default, Clone, Debug, ComponentProvider)]
|
||||
#[derive(Visit, Reflect, Default, Clone, Debug)]
|
||||
#[reflect(derived_type = "Node")]
|
||||
pub struct Listener {
|
||||
base: Base,
|
||||
|
||||
@@ -73,7 +73,7 @@ pub mod context;
|
||||
pub mod listener;
|
||||
|
||||
/// Sound source.
|
||||
#[derive(Visit, Reflect, Debug, ComponentProvider)]
|
||||
#[derive(Visit, Reflect, Debug)]
|
||||
#[reflect(derived_type = "Node")]
|
||||
pub struct Sound {
|
||||
base: Base,
|
||||
|
||||
@@ -154,7 +154,7 @@ impl VertexTrait for SpriteVertex {
|
||||
/// **does not** reuse it. Ideally, you should reuse the shared material across multiple instances
|
||||
/// to get the best possible performance. Otherwise, each your sprite will be put in a separate batch
|
||||
/// which will force your GPU to render a single sprite in dedicated draw call which is quite slow.
|
||||
#[derive(Debug, Reflect, Clone, ComponentProvider, Visit)]
|
||||
#[derive(Debug, Reflect, Clone, Visit)]
|
||||
#[reflect(derived_type = "Node")]
|
||||
pub struct Sprite {
|
||||
base: Base,
|
||||
|
||||
@@ -1032,7 +1032,7 @@ impl BrushContext {
|
||||
/// count the number of pixels needed to render the vertices of that part of the terrain, which means that they
|
||||
/// overlap with their neighbors just as chunks overlap. Two adjacent blocks share vertices along their edge,
|
||||
/// so they also share pixels in the height map data.
|
||||
#[derive(Debug, Reflect, Clone, ComponentProvider)]
|
||||
#[derive(Debug, Reflect, Clone)]
|
||||
#[reflect(derived_type = "Node")]
|
||||
pub struct Terrain {
|
||||
base: Base,
|
||||
|
||||
@@ -177,7 +177,7 @@ impl<'a, P: FnMut(Vector2<i32>) -> bool> TileMapDataIterator<'a, P> {
|
||||
}
|
||||
|
||||
/// Asset containing the tile handles of a tile map.
|
||||
#[derive(Clone, Default, Debug, Reflect, TypeUuidProvider, ComponentProvider)]
|
||||
#[derive(Clone, Default, Debug, Reflect, TypeUuidProvider)]
|
||||
#[type_uuid(id = "a8e4b6b4-c1bd-4ed9-a753-0d5a3dfe1729")]
|
||||
pub struct TileMapData {
|
||||
content: FxHashMap<Vector2<i32>, Chunk>,
|
||||
|
||||
@@ -487,7 +487,7 @@ impl ResourceTilePosition {
|
||||
|
||||
/// Tile is a base block of a tile map. It has a position and a handle of tile definition, stored
|
||||
/// in the respective tile set.
|
||||
#[derive(Clone, Reflect, Default, Debug, PartialEq, Visit, ComponentProvider, TypeUuidProvider)]
|
||||
#[derive(Clone, Reflect, Default, Debug, PartialEq, Visit, TypeUuidProvider)]
|
||||
#[type_uuid(id = "e429ca1b-a311-46c3-b580-d5a2f49db7e2")]
|
||||
pub struct Tile {
|
||||
/// Position of the tile (in grid coordinates).
|
||||
@@ -951,7 +951,7 @@ impl OrthoTransform for TileRenderData {
|
||||
/// which contains all the pages that may be referenced by the tile map's handles.
|
||||
///
|
||||
/// Optional [`TileMapEffect`] objects may be included in the `TileMap` to change how it renders.
|
||||
#[derive(Reflect, Debug, ComponentProvider, TypeUuidProvider)]
|
||||
#[derive(Reflect, Debug, TypeUuidProvider)]
|
||||
#[reflect(derived_type = "Node")]
|
||||
#[type_uuid(id = "aa9a3385-a4af-4faf-a69a-8d3af1a3aa67")]
|
||||
pub struct TileMap {
|
||||
|
||||
@@ -1323,7 +1323,7 @@ impl AnimationCache {
|
||||
/// Each layer has a name and a color. The color is used to allow the user to quickly
|
||||
/// identify which shapes correspond to which layers while in the tile set editor.
|
||||
/// See [`TileSetColliderLayer`] for more information.
|
||||
#[derive(Clone, Default, Debug, Visit, Reflect, TypeUuidProvider, ComponentProvider)]
|
||||
#[derive(Clone, Default, Debug, Visit, Reflect, TypeUuidProvider)]
|
||||
#[type_uuid(id = "7b7e057b-a41e-4150-ab3b-0ae99f4024f0")]
|
||||
pub struct TileSet {
|
||||
/// A mapping from animated tiles to the corresponding cells on animation pages.
|
||||
|
||||
@@ -29,7 +29,6 @@ use crate::{
|
||||
log::Log,
|
||||
pool::{Handle, PoolError},
|
||||
reflect::{FieldMut, FieldRef, Reflect, ReflectArray, ReflectList},
|
||||
type_traits::ComponentProvider,
|
||||
uuid::Uuid,
|
||||
visitor::{Visit, VisitResult, Visitor},
|
||||
TypeUuidProvider,
|
||||
@@ -609,7 +608,7 @@ impl UniversalScriptContext for ScriptDeinitContext<'_, '_, '_> {
|
||||
|
||||
/// Script is a set predefined methods that are called on various stages by the engine. It is used to add
|
||||
/// custom behaviour to game entities.
|
||||
pub trait ScriptTrait: BaseScript + ComponentProvider {
|
||||
pub trait ScriptTrait: BaseScript {
|
||||
/// The method is called when the script wasn't initialized yet. It is guaranteed to be called once,
|
||||
/// and before any other methods of the script.
|
||||
///
|
||||
@@ -819,6 +818,14 @@ impl Reflect for Script {
|
||||
fn field_direct_mut(&mut self, index: usize) -> Option<FieldMut> {
|
||||
self.instance.deref_mut().field_direct_mut(index)
|
||||
}
|
||||
|
||||
fn as_reflect_direct(&self) -> &dyn Reflect {
|
||||
self.instance.as_reflect_direct()
|
||||
}
|
||||
|
||||
fn as_reflect_mut_direct(&mut self) -> &mut dyn Reflect {
|
||||
self.instance.as_reflect_mut_direct()
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for Script {
|
||||
@@ -917,18 +924,14 @@ impl Script {
|
||||
|
||||
/// Tries to borrow a component of given type.
|
||||
#[inline]
|
||||
pub fn query_component_ref<T: Any>(&self) -> Option<&T> {
|
||||
self.instance
|
||||
.query_component_ref(TypeId::of::<T>())
|
||||
.and_then(|c| c.downcast_ref())
|
||||
pub fn query_component_ref<T: Reflect>(&self) -> Option<&T> {
|
||||
(self.instance.deref() as &dyn Reflect).self_or_field_ref_of_type()
|
||||
}
|
||||
|
||||
/// Tries to borrow a component of given type.
|
||||
#[inline]
|
||||
pub fn query_component_mut<T: Any>(&mut self) -> Option<&mut T> {
|
||||
self.instance
|
||||
.query_component_mut(TypeId::of::<T>())
|
||||
.and_then(|c| c.downcast_mut())
|
||||
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()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -937,8 +940,8 @@ mod test {
|
||||
use crate::scene::base::ScriptRecord;
|
||||
use crate::{
|
||||
core::{
|
||||
impl_component_provider, reflect::prelude::*, variable::try_inherit_properties,
|
||||
variable::InheritableVariable, visitor::prelude::*,
|
||||
reflect::prelude::*, variable::try_inherit_properties, variable::InheritableVariable,
|
||||
visitor::prelude::*,
|
||||
},
|
||||
scene::base::Base,
|
||||
script::{Script, ScriptTrait},
|
||||
@@ -950,7 +953,6 @@ mod test {
|
||||
field: InheritableVariable<f32>,
|
||||
}
|
||||
|
||||
impl_component_provider!(MyScript);
|
||||
uuid_provider!(MyScript = "eed9bf56-7d71-44a0-ba8e-0f3163c59669");
|
||||
|
||||
impl ScriptTrait for MyScript {}
|
||||
|
||||
Reference in New Issue
Block a user