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:
Dmitry Stepanov
2026-05-09 19:55:11 +03:00
parent e553174d5d
commit c03e4aa7e9
160 changed files with 635 additions and 891 deletions
+3 -3
View File
@@ -26,8 +26,8 @@ use crate::{
asset::{manager::ResourceManager, untyped::UntypedResource, Resource, TypedResourceData},
core::{
algebra::Vector2, color::Color, futures::executor::block_on, make_relative_path,
parking_lot::lock_api::Mutex, pool::Handle, reflect::prelude::*,
type_traits::prelude::*, uuid_provider, visitor::prelude::*,
parking_lot::lock_api::Mutex, pool::Handle, reflect::prelude::*, uuid_provider,
visitor::prelude::*,
},
graph::SceneGraph,
gui::{
@@ -80,7 +80,7 @@ pub enum AssetItemMessage {
impl MessageData for AssetItemMessage {}
#[allow(dead_code)]
#[derive(Debug, Clone, Visit, Reflect, ComponentProvider)]
#[derive(Debug, Clone, Visit, Reflect)]
#[reflect(derived_type = "UiNode")]
pub struct AssetItem {
widget: Widget,
+1 -1
View File
@@ -62,7 +62,7 @@ use std::{
path::PathBuf,
};
#[derive(Clone, Visit, Reflect, Debug, ComponentProvider, TypeUuidProvider)]
#[derive(Clone, Visit, Reflect, Debug, TypeUuidProvider)]
#[reflect(derived_type = "UiNode")]
#[type_uuid(id = "8c9934ad-b4e1-4c68-9876-f253e34c6667")]
struct AssetRenameDialog {
+3 -3
View File
@@ -79,7 +79,7 @@ pub enum AssetSelectorMessage {
}
impl MessageData for AssetSelectorMessage {}
#[derive(Clone, Debug, Reflect, Visit, TypeUuidProvider, ComponentProvider)]
#[derive(Clone, Debug, Reflect, Visit, TypeUuidProvider)]
#[type_uuid(id = "aa4f0726-8d25-4c90-add1-92ba392310c6")]
struct Item {
pub widget: Widget,
@@ -230,7 +230,7 @@ impl ItemBuilder {
}
}
#[derive(Clone, Debug, Reflect, Visit, TypeUuidProvider, ComponentProvider)]
#[derive(Clone, Debug, Reflect, Visit, TypeUuidProvider)]
#[type_uuid(id = "970bb83b-51e8-48e7-8050-f97bf0ac470b")]
pub struct AssetSelector {
pub widget: Widget,
@@ -384,7 +384,7 @@ impl<'a> AssetSelectorBuilder<'a> {
}
}
#[derive(Clone, Debug, Reflect, Visit, TypeUuidProvider, ComponentProvider)]
#[derive(Clone, Debug, Reflect, Visit, TypeUuidProvider)]
#[type_uuid(id = "c348ad3d-52a6-40ad-a5e4-bf63fefe1906")]
pub struct AssetSelectorWindow {
pub window: Window,
+2 -5
View File
@@ -19,10 +19,7 @@
// SOFTWARE.
use crate::fyrox::{
core::{
pool::Handle, reflect::prelude::*, type_traits::prelude::*, uuid_provider,
visitor::prelude::*,
},
core::{pool::Handle, reflect::prelude::*, uuid_provider, visitor::prelude::*},
gui::{
border::BorderBuilder,
decorator::DecoratorBuilder,
@@ -56,7 +53,7 @@ pub enum AudioBusViewMessage {
}
impl MessageData for AudioBusViewMessage {}
#[derive(Clone, Visit, Reflect, Debug, ComponentProvider)]
#[derive(Clone, Visit, Reflect, Debug)]
#[reflect(derived_type = "UiNode")]
pub struct AudioBusView {
widget: Widget,
+9 -11
View File
@@ -24,40 +24,38 @@ use crate::fyrox::{
reflect::{
is_path_to_array_element, Reflect, ResolvePath, SetFieldByPathError, SetFieldError,
},
some_or_return, ComponentProvider,
some_or_return,
},
gui::inspector::{PropertyAction, PropertyChanged},
};
use std::{
any::{type_name, TypeId},
any::type_name,
fmt::{Debug, Formatter},
ops::{Deref, DerefMut, RangeBounds},
};
pub mod panel;
pub trait CommandContext: ComponentProvider {}
pub trait CommandContext: Reflect {}
impl dyn CommandContext + '_ {
pub fn component_ref<T>(&self) -> Option<&T>
where
T: 'static,
T: Reflect,
{
self.query_component_ref(TypeId::of::<T>())
.and_then(|c| c.downcast_ref())
(self as &dyn Reflect).self_or_field_ref_of_type()
}
pub fn component_mut<T>(&mut self) -> Option<&mut T>
where
T: 'static,
T: Reflect,
{
self.query_component_mut(TypeId::of::<T>())
.and_then(|c| c.downcast_mut())
(self as &mut dyn Reflect).self_or_field_mut_of_type()
}
pub fn get<T>(&self) -> &T
where
T: 'static,
T: Reflect,
{
self.component_ref().unwrap_or_else(|| {
panic!(
@@ -69,7 +67,7 @@ impl dyn CommandContext + '_ {
pub fn get_mut<T>(&mut self) -> &mut T
where
T: 'static,
T: Reflect,
{
self.component_mut().unwrap_or_else(|| {
panic!(
+3 -1
View File
@@ -24,6 +24,7 @@ use crate::{
core::{
log::Log,
pool::{ErasedHandle, Handle},
reflect::prelude::*,
uuid::Uuid,
},
gui::{inspector::PropertyChanged, UiNode},
@@ -123,7 +124,8 @@ pub enum Message {
SetAssetBrowserCurrentDir(PathBuf),
}
#[derive(Clone, Debug)]
#[derive(Clone, Debug, Reflect)]
#[reflect(hide_all)]
pub struct MessageSender(pub Sender<Message>);
impl Default for MessageSender {
+2 -2
View File
@@ -108,7 +108,7 @@ enum DragContext {
Point { point: usize },
}
#[derive(Clone, Visit, Reflect, ComponentProvider)]
#[derive(Clone, Visit, Reflect)]
#[reflect(derived_type = "UiNode")]
struct BlendSpaceField {
widget: Widget,
@@ -557,7 +557,7 @@ pub enum BlendSpaceFieldPointMessage {
}
impl MessageData for BlendSpaceFieldPointMessage {}
#[derive(Clone, Visit, Reflect, Debug, ComponentProvider)]
#[derive(Clone, Visit, Reflect, Debug)]
#[reflect(derived_type = "UiNode")]
struct BlendSpaceFieldPoint {
widget: Widget,
+2 -3
View File
@@ -25,7 +25,6 @@ use crate::fyrox::{
math::Rect,
pool::Handle,
reflect::prelude::*,
type_traits::prelude::*,
uuid_provider,
visitor::prelude::*,
},
@@ -112,7 +111,7 @@ impl MessageData for AbsmCanvasMessage {
}
}
#[derive(Clone, Visit, Reflect, Debug, ComponentProvider)]
#[derive(Clone, Visit, Reflect, Debug)]
#[reflect(derived_type = "UiNode")]
pub struct AbsmCanvas {
widget: Widget,
@@ -194,7 +193,7 @@ impl AbsmCanvas {
ui: &UserInterface,
) -> Handle<UiNode>
where
T: 'static,
T: Reflect,
{
if ui
.try_get_node(node_handle)
+2 -2
View File
@@ -21,7 +21,7 @@
use crate::fyrox::{
core::{
algebra::Vector2, color::Color, math::Rect, pool::Handle, reflect::prelude::*,
type_traits::prelude::*, uuid_provider, visitor::prelude::*,
uuid_provider, visitor::prelude::*,
},
gui::{
brush::Brush,
@@ -43,7 +43,7 @@ use fyrox::material::MaterialResource;
const PICKED_BRUSH: Brush = Brush::Solid(Color::opaque(100, 100, 100));
const NORMAL_BRUSH: Brush = Brush::Solid(Color::opaque(80, 80, 80));
#[derive(Debug, Clone, Visit, Reflect, ComponentProvider)]
#[derive(Debug, Clone, Visit, Reflect)]
#[reflect(derived_type = "UiNode")]
pub struct Connection {
widget: Widget,
+1 -3
View File
@@ -57,7 +57,7 @@ pub struct AbsmBaseNode {
pub output_socket: Handle<Socket>,
}
#[derive(Visit, Reflect, ComponentProvider)]
#[derive(Visit, Reflect)]
#[reflect(derived_type = "UiNode")]
pub struct AbsmNode<T>
where
@@ -65,11 +65,9 @@ where
{
widget: Widget,
background: Handle<Border>,
#[component(include)]
selectable: Selectable,
pub name_value: String,
pub model_handle: Handle<T>,
#[component(include)]
pub base: AbsmBaseNode,
pub add_input: Handle<Button>,
input_sockets_panel: Handle<StackPanel>,
+2 -3
View File
@@ -21,8 +21,7 @@
use crate::fyrox::core::pool::ErasedHandle;
use crate::fyrox::{
core::{
algebra::Vector2, pool::Handle, reflect::prelude::*, type_traits::prelude::*,
uuid_provider, visitor::prelude::*,
algebra::Vector2, pool::Handle, reflect::prelude::*, uuid_provider, visitor::prelude::*,
},
gui::{
define_widget_deref,
@@ -55,7 +54,7 @@ pub enum SocketDirection {
Output,
}
#[derive(Clone, Debug, Visit, Reflect, ComponentProvider)]
#[derive(Clone, Debug, Visit, Reflect)]
#[reflect(derived_type = "UiNode")]
pub struct Socket {
widget: Widget,
+1 -3
View File
@@ -26,7 +26,6 @@ use crate::fyrox::{
math::Rect,
pool::Handle,
reflect::prelude::*,
type_traits::prelude::*,
uuid_provider,
visitor::prelude::*,
},
@@ -56,13 +55,12 @@ pub enum TransitionMessage {
}
impl MessageData for TransitionMessage {}
#[derive(Clone, Debug, Visit, Reflect, ComponentProvider)]
#[derive(Clone, Debug, Visit, Reflect)]
#[reflect(derived_type = "UiNode")]
pub struct TransitionView {
widget: Widget,
pub segment: Segment,
pub model_handle: ErasedHandle,
#[component(include)]
selectable: Selectable,
activity_factor: f32,
}
+3 -5
View File
@@ -67,7 +67,7 @@ use crate::{
};
use fyrox::gui::UiNode;
use fyrox::scene::node::Node;
use std::any::{Any, TypeId};
use std::any::Any;
pub mod command;
mod ruler;
@@ -229,11 +229,9 @@ where
.try_get_node(handle)
.ok()
.and_then(|n| {
n.query_component_ref(TypeId::of::<
InheritableVariable<AnimationContainer<Handle<N>>>,
>())
(n as &dyn Reflect)
.first_field_ref_of_type::<InheritableVariable<AnimationContainer<Handle<N>>>>()
})
.and_then(|a| a.downcast_ref::<InheritableVariable<AnimationContainer<Handle<N>>>>())
.map(|v| v.get_value_ref())
}
+1 -1
View File
@@ -161,7 +161,7 @@ struct DragContext {
entity: DragEntity,
}
#[derive(Clone, Visit, Reflect, ComponentProvider)]
#[derive(Clone, Visit, Reflect)]
#[reflect(derived_type = "UiNode")]
pub struct Ruler {
widget: Widget,
+1 -2
View File
@@ -27,7 +27,6 @@ use crate::fyrox::{
algebra::{Point2, Vector2},
pool::Handle,
reflect::prelude::*,
type_traits::prelude::*,
uuid_provider,
visitor::prelude::*,
},
@@ -53,7 +52,7 @@ pub enum ThumbMessage {
}
impl MessageData for ThumbMessage {}
#[derive(Clone, Visit, Reflect, Debug, ComponentProvider)]
#[derive(Clone, Visit, Reflect, Debug)]
#[reflect(derived_type = "UiNode")]
pub struct Thumb {
widget: Widget,
+1 -2
View File
@@ -348,10 +348,9 @@ pub enum TrackViewMessage {
}
impl MessageData for TrackViewMessage {}
#[derive(Clone, Debug, Reflect, Visit, ComponentProvider)]
#[derive(Clone, Debug, Reflect, Visit)]
#[reflect(derived_type = "UiNode")]
struct TrackView {
#[component(include)]
pub tree: Tree,
id: Uuid,
target: ErasedHandle,
+14 -13
View File
@@ -21,10 +21,11 @@
use crate::{
command::{Command, CommandContext, CommandStack, CommandTrait},
fyrox::{
asset::manager::ResourceManager,
asset::Resource,
core::{
futures::executor::block_on, math::curve::Curve, pool::Handle, type_traits::prelude::*,
visitor::prelude::*,
futures::executor::block_on, math::curve::Curve, pool::Handle, reflect::prelude::*,
some_or_return, type_traits::prelude::*, visitor::prelude::*,
},
engine::Engine,
gui::{
@@ -41,6 +42,16 @@ use crate::{
window::{WindowBuilder, WindowMessage, WindowTitle},
BuildContext, HorizontalAlignment, Orientation, Thickness, UserInterface,
},
gui::{
button::Button,
curve::CurveEditor,
file_browser::{FileSelector, FileSelectorMode, FileType},
menu::MenuItem,
messagebox::MessageBox,
style::resource::StyleResourceExt,
style::Style,
window::{Window, WindowAlignment},
},
resource::curve::{CurveResource, CurveResourceState},
},
menu::create_menu_item,
@@ -48,19 +59,9 @@ use crate::{
utils::create_file_selector,
Editor, MessageBoxButtons, MessageBoxMessage,
};
use fyrox::asset::manager::ResourceManager;
use fyrox::core::some_or_return;
use fyrox::gui::button::Button;
use fyrox::gui::curve::CurveEditor;
use fyrox::gui::file_browser::{FileSelector, FileSelectorMode, FileType};
use fyrox::gui::menu::MenuItem;
use fyrox::gui::messagebox::MessageBox;
use fyrox::gui::style::resource::StyleResourceExt;
use fyrox::gui::style::Style;
use fyrox::gui::window::{Window, WindowAlignment};
use std::{fmt::Debug, path::PathBuf};
#[derive(Debug, ComponentProvider)]
#[derive(Reflect, Clone, Debug)]
pub struct CurveEditorContext {}
impl CommandContext for CurveEditorContext {}
@@ -64,7 +64,7 @@ pub enum DynTypePropertyEditorMessage {
}
impl MessageData for DynTypePropertyEditorMessage {}
#[derive(Clone, Debug, Visit, Reflect, ComponentProvider)]
#[derive(Clone, Debug, Visit, Reflect)]
#[reflect(derived_type = "UiNode")]
pub struct DynTypePropertyEditor {
widget: Widget,
+3 -3
View File
@@ -22,8 +22,8 @@ use crate::{
asset::item::AssetItem,
fyrox::{
core::{
algebra::Vector2, color::Color, pool::Handle, reflect::prelude::*,
type_traits::prelude::*, uuid_provider, visitor::prelude::*,
algebra::Vector2, color::Color, pool::Handle, reflect::prelude::*, uuid_provider,
visitor::prelude::*,
},
graph::SceneGraph,
gui::{
@@ -55,7 +55,7 @@ use std::{
ops::{Deref, DerefMut},
};
#[derive(Clone, Visit, Reflect, ComponentProvider)]
#[derive(Clone, Visit, Reflect)]
#[reflect(derived_type = "UiNode")]
pub struct FontField {
widget: Widget,
@@ -104,7 +104,7 @@ impl MessageData for HandlePropertyEditorNameMessage {}
pub struct HandlePropertyEditorHierarchyMessage(pub HierarchyNode);
impl MessageData for HandlePropertyEditorHierarchyMessage {}
#[derive(Visit, Reflect, TypeUuidProvider, ComponentProvider)]
#[derive(Visit, Reflect, TypeUuidProvider)]
#[type_uuid(id = "3ceca8c1-c365-4f03-a413-062f8f3cd685")]
#[reflect(derived_type = "UiNode")]
pub struct HandlePropertyEditor<T: Reflect> {
@@ -114,7 +114,7 @@ pub type ResourceLoaderCallback<T> = Arc<
>,
>;
#[derive(Visit, Reflect, ComponentProvider)]
#[derive(Visit, Reflect)]
#[reflect(derived_type = "UiNode")]
pub struct ResourceField<T>
where
@@ -72,7 +72,7 @@ pub enum ScriptPropertyEditorMessage {
}
impl MessageData for ScriptPropertyEditorMessage {}
#[derive(Clone, Debug, Visit, Reflect, ComponentProvider)]
#[derive(Clone, Debug, Visit, Reflect)]
#[reflect(derived_type = "UiNode")]
pub struct ScriptPropertyEditor {
widget: Widget,
@@ -45,7 +45,7 @@ use crate::{
use fyrox::gui::button::Button;
use std::{any::TypeId, cell::RefCell};
#[derive(Default, Clone, Visit, Reflect, Debug, TypeUuidProvider, ComponentProvider)]
#[derive(Default, Clone, Visit, Reflect, Debug, TypeUuidProvider)]
#[type_uuid(id = "f2024683-812e-4e0d-8065-7d168a82cce6")]
#[reflect(derived_type = "UiNode")]
pub struct ShaderSourceCodeEditorField {
@@ -42,7 +42,7 @@ pub enum ShaderSourceCodeEditorMessage {
}
impl MessageData for ShaderSourceCodeEditorMessage {}
#[derive(Default, Clone, Visit, Reflect, Debug, TypeUuidProvider, ComponentProvider)]
#[derive(Default, Clone, Visit, Reflect, Debug, TypeUuidProvider)]
#[type_uuid(id = "c2e0bdcc-28a6-4141-93b5-5dad50c8b29c")]
#[reflect(derived_type = "UiNode")]
pub struct ShaderSourceCodeEditor {
@@ -19,10 +19,7 @@
// SOFTWARE.
use crate::fyrox::{
core::{
pool::Handle, reflect::prelude::*, type_traits::prelude::*, uuid_provider,
visitor::prelude::*,
},
core::{pool::Handle, reflect::prelude::*, uuid_provider, visitor::prelude::*},
gui::{
button::{ButtonBuilder, ButtonMessage},
define_widget_deref,
@@ -60,7 +57,7 @@ pub enum SpriteSheetFramesPropertyEditorMessage {
}
impl MessageData for SpriteSheetFramesPropertyEditorMessage {}
#[derive(Clone, Debug, Reflect, Visit, ComponentProvider)]
#[derive(Clone, Debug, Reflect, Visit)]
#[reflect(derived_type = "UiNode")]
pub struct SpriteSheetFramesPropertyEditor {
widget: Widget,
@@ -21,8 +21,8 @@
use crate::fyrox::graph::SceneGraph;
use crate::fyrox::{
core::{
algebra::Vector2, parking_lot::Mutex, pool::Handle, reflect::prelude::*,
type_traits::prelude::*, uuid_provider, visitor::prelude::*,
algebra::Vector2, parking_lot::Mutex, pool::Handle, reflect::prelude::*, uuid_provider,
visitor::prelude::*,
},
gui::{
border::BorderBuilder,
@@ -59,10 +59,9 @@ use std::{
sync::{mpsc::Sender, Arc},
};
#[derive(Clone, Visit, Reflect, Debug, ComponentProvider)]
#[derive(Clone, Visit, Reflect, Debug)]
#[reflect(derived_type = "UiNode")]
pub struct SpriteSheetFramesEditorWindow {
#[component(include)]
window: Window,
editor: Handle<UiNode>,
ok: Handle<Button>,
@@ -67,7 +67,7 @@ pub enum SurfaceDataPropertyEditorMessage {
}
impl MessageData for SurfaceDataPropertyEditorMessage {}
#[derive(Clone, Visit, Reflect, Debug, ComponentProvider, TypeUuidProvider)]
#[derive(Clone, Visit, Reflect, Debug, TypeUuidProvider)]
#[type_uuid(id = "8461a183-4fd4-4f74-a4f4-7fd8e84bf423")]
#[reflect(derived_type = "UiNode")]
#[allow(dead_code)]
@@ -24,7 +24,7 @@ use crate::{
asset::{manager::ResourceManager, untyped::UntypedResource},
core::{
algebra::Vector2, color::Color, make_relative_path, pool::Handle, reflect::prelude::*,
type_traits::prelude::*, uuid_provider, visitor::prelude::*,
uuid_provider, visitor::prelude::*,
},
graph::SceneGraph,
gui::{
@@ -58,7 +58,7 @@ use std::{
sync::mpsc::Sender,
};
#[derive(Clone, Visit, Reflect, ComponentProvider)]
#[derive(Clone, Visit, Reflect)]
#[reflect(derived_type = "UiNode")]
pub struct TextureEditor {
widget: Widget,
+15 -22
View File
@@ -23,30 +23,31 @@ use crate::{
fyrox::{
asset::manager::ResourceManager,
core::{
color::Color,
dyntype::DynTypeConstructorContainer,
err,
log::{Log, MessageKind},
pool::{ErasedHandle, Handle},
reflect::prelude::*,
type_traits::prelude::*,
},
engine::SerializationContext,
graph::SceneGraph,
gui::{
border::BorderBuilder,
button::ButtonMessage,
button::{Button, ButtonMessage},
grid::{Column, GridBuilder, Row},
inspector::InspectorContextArgs,
inspector::{
editors::PropertyEditorDefinitionContainer, InspectorBuilder, InspectorContext,
InspectorEnvironment, InspectorError, InspectorMessage,
InspectorContextArgs, InspectorEnvironment, InspectorError, InspectorMessage,
},
message::{MessageDirection, UiMessage},
scroll_viewer::ScrollViewerBuilder,
stack_panel::StackPanelBuilder,
stack_panel::{StackPanel, StackPanelBuilder},
style::{resource::StyleResource, resource::StyleResourceExt, Style},
text::{TextBuilder, TextMessage},
text::{Text, TextBuilder, TextMessage},
utils::ImageButtonBuilder,
widget::WidgetBuilder,
window::{WindowBuilder, WindowTitle},
window::{Window, WindowBuilder, WindowTitle},
BuildContext, Thickness, UiNode, UserInterface,
},
scene::SceneContainer,
@@ -60,35 +61,31 @@ use crate::{
utils::window_content,
Editor, Message, WidgetMessage, WrapMode,
};
use fyrox::core::color::Color;
use fyrox::core::err;
use fyrox::gui::button::Button;
use fyrox::gui::stack_panel::StackPanel;
use fyrox::gui::text::Text;
use fyrox::gui::utils::ImageButtonBuilder;
use fyrox::gui::window::Window;
use std::{any::Any, sync::mpsc::Sender, sync::Arc};
pub mod editors;
pub mod handlers;
#[derive(Clone, Debug)]
#[derive(Clone, Reflect, Debug)]
pub struct AnimationDefinition {
name: String,
handle: ErasedHandle,
}
#[derive(ComponentProvider)]
#[derive(Reflect, Clone, Debug)]
#[reflect(non_cloneable)]
pub struct EditorEnvironment {
pub resource_manager: ResourceManager,
#[reflect(hidden)]
pub serialization_context: Arc<SerializationContext>,
#[reflect(hidden)]
pub dyn_type_constructors: Arc<DynTypeConstructorContainer>,
/// List of animations definitions (name + handle). It is filled only if current selection
/// is `AnimationBlendingStateMachine`. The list is filled using ABSM's animation player.
pub available_animations: Vec<AnimationDefinition>,
pub sender: MessageSender,
#[reflect(hidden)]
pub icon_request_sender: Sender<IconRequest>,
#[component(include)]
pub style: Option<StyleResource>,
}
@@ -99,8 +96,7 @@ impl EditorEnvironment {
let environment = &**environment.as_ref().ok_or(InspectorError::Custom(
"Missing InspectorEnvironment".into(),
))?;
environment
.as_any()
(environment as &dyn Any)
.downcast_ref::<Self>()
.ok_or(InspectorError::Custom(format!(
"Expected InspectorEnvironment to be EditorEnvironment, found: {}",
@@ -113,9 +109,6 @@ impl InspectorEnvironment for EditorEnvironment {
fn name(&self) -> String {
format!("EditorEnvironment:{:?}", self.type_id())
}
fn as_any(&self) -> &dyn Any {
self
}
}
pub struct InspectorPlugin {
+3 -3
View File
@@ -27,8 +27,8 @@ use crate::{
fyrox::{
asset::{core::pool::Handle, manager::ResourceManager, state::ResourceState},
core::{
color::Color, log::Log, parking_lot::Mutex, reflect::prelude::*,
type_traits::prelude::*, uuid_provider, visitor::prelude::*, SafeLock,
color::Color, log::Log, parking_lot::Mutex, reflect::prelude::*, uuid_provider,
visitor::prelude::*, SafeLock,
},
graph::SceneGraph,
gui::{
@@ -71,7 +71,7 @@ pub enum MaterialFieldMessage {
}
impl MessageData for MaterialFieldMessage {}
#[derive(Clone, Visit, Reflect, ComponentProvider)]
#[derive(Clone, Visit, Reflect)]
#[reflect(derived_type = "UiNode")]
pub struct MaterialFieldEditor {
widget: Widget,
+1 -1
View File
@@ -79,7 +79,7 @@ impl MessageData for TileDefinitionHandleEditorMessage {}
/// pair is the page coordinates and the second pair is the tile coordinates.
/// When editing the handle, one need merely type four integers. Whatever
/// characters separate the integers are ignored, so "1 2 3 4" would be accepted.
#[derive(Clone, Debug, Visit, Reflect, TypeUuidProvider, ComponentProvider)]
#[derive(Clone, Debug, Visit, Reflect, TypeUuidProvider)]
#[reflect(derived_type = "UiNode")]
#[type_uuid(id = "60146cf0-33e3-4757-8e66-e7196324271f")]
pub struct TileDefinitionHandleEditor {
+1 -1
View File
@@ -53,7 +53,7 @@ impl MessageData for TileHandleEditorMessage {}
/// pair is the page coordinates and the second pair is the tile coordinates.
/// When editing the handle, one need merely type four integers. Whatever
/// characters separate the integers are ignored, so "1 2 3 4" would be accepted.
#[derive(Debug, Default, Clone, Visit, Reflect, TypeUuidProvider, ComponentProvider)]
#[derive(Debug, Default, Clone, Visit, Reflect, TypeUuidProvider)]
#[type_uuid(id = "86513074-461d-4583-a214-fb84f5aacac1")]
#[reflect(derived_type = "UiNode")]
pub struct TileHandleField {
+1 -1
View File
@@ -165,7 +165,7 @@ fn calc_slice_coord(position: f32, step: f32) -> usize {
/// Displays a scrollable grid of till cells, with options to allow the tiles
/// to be selected, dragged, and edits in various ways.
#[derive(Clone, Visit, Reflect, TypeUuidProvider, ComponentProvider)]
#[derive(Clone, Visit, Reflect, TypeUuidProvider)]
#[type_uuid(id = "5356a864-c026-4bd7-a4b1-30bacf77d8fa")]
#[reflect(derived_type = "UiNode")]
pub struct PaletteWidget {
+1 -1
View File
@@ -50,7 +50,7 @@ use fyrox::material::MaterialResource;
/// The preview widget of the tile map control panel. This allows the user to see the
/// currently selected tile stamp, including whatever transformations have been applied
/// to the stamp.
#[derive(Clone, Debug, Visit, Reflect, TypeUuidProvider, ComponentProvider)]
#[derive(Clone, Debug, Visit, Reflect, TypeUuidProvider)]
#[type_uuid(id = "5356a864-c026-4bd7-a4b1-30bacf77d8fa")]
#[reflect(derived_type = "UiNode")]
pub struct PanelPreview {
@@ -46,7 +46,7 @@ pub enum TileBoundsMessage {
}
impl MessageData for TileBoundsMessage {}
#[derive(Clone, Default, Debug, Visit, Reflect, TypeUuidProvider, ComponentProvider)]
#[derive(Clone, Default, Debug, Visit, Reflect, TypeUuidProvider)]
#[type_uuid(id = "1e600103-6516-4c5a-a30b-f90f64fc9623")]
#[reflect(derived_type = "UiNode")]
pub struct TileBoundsEditor {
+7
View File
@@ -20,16 +20,23 @@
use crate::fyrox::{
core::pool::Handle,
core::reflect::prelude::*,
scene::{graph::Graph, node::Node, Scene},
};
use crate::{scene::GraphSelection, Engine};
use fyrox::core::blank_reflect_ref;
use std::collections::HashMap;
#[derive(Debug)]
pub struct Clipboard {
graph: Graph,
empty: bool,
}
impl Reflect for &'static mut Clipboard {
blank_reflect_ref!();
}
impl Default for Clipboard {
fn default() -> Self {
Self {
+5 -4
View File
@@ -20,7 +20,7 @@
use crate::fyrox::{
asset::manager::ResourceManager,
core::{log::Log, pool::Handle, reflect::prelude::*, type_traits::prelude::*},
core::{log::Log, pool::Handle, reflect::prelude::*},
engine::SerializationContext,
graph::{SceneGraph, SceneGraphNode},
scene::{graph::SubGraph, node::Node, Scene},
@@ -45,16 +45,17 @@ pub mod navmesh;
pub mod sound_context;
pub mod terrain;
#[derive(ComponentProvider)]
#[derive(Reflect, Debug)]
#[reflect(non_cloneable)]
pub struct GameSceneContext {
#[component(include)]
pub selection: &'static mut Selection,
pub scene: &'static mut Scene,
#[reflect(hidden)]
pub scene_content_root: &'static mut Handle<Node>,
pub clipboard: &'static mut Clipboard,
#[component(include)]
pub message_sender: MessageSender,
pub resource_manager: ResourceManager,
#[reflect(hidden)]
pub serialization_context: Arc<SerializationContext>,
}
+5
View File
@@ -96,6 +96,7 @@ use crate::{
world::selection::GraphSelection,
Message, Settings,
};
use fyrox::core::blank_reflect_ref;
use fyrox::engine::GraphicsContext;
use fyrox::gui::file_browser::FileType;
use fyrox::scene::collider::BitMask;
@@ -1205,6 +1206,10 @@ impl dyn SelectionContainer {
#[derive(Debug, Default)]
pub struct Selection(pub Option<Box<dyn SelectionContainer>>);
impl Reflect for &'static mut Selection {
blank_reflect_ref!();
}
impl PartialEq for Selection {
fn eq(&self, other: &Self) -> bool {
if let (Some(this), Some(other)) = (self.0.as_ref(), other.0.as_ref()) {
+3 -5
View File
@@ -22,20 +22,18 @@
//! there is no scene to control.
use crate::command::CommandContext;
use fyrox::core::ComponentProvider;
use crate::fyrox::core::reflect::prelude::*;
use fyrox::gui::file_browser::FileType;
use super::*;
/// The [`CommandContext`] that is used when the current scene is the
/// null scene.
#[derive(ComponentProvider)]
#[derive(Reflect, Debug)]
#[reflect(non_cloneable)]
pub struct NullSceneContext {
#[component(include)]
pub selection: &'static mut Selection,
#[component(include)]
pub message_sender: MessageSender,
#[component(include)]
pub resource_manager: ResourceManager,
}
+3 -4
View File
@@ -21,7 +21,7 @@
use crate::fyrox::{
core::{
make_pretty_type_name, parking_lot::Mutex, pool::Handle, reflect::prelude::*,
sstorage::ImmutableString, type_traits::prelude::*, uuid_provider, visitor::prelude::*,
sstorage::ImmutableString, uuid_provider, visitor::prelude::*,
},
fxhash::FxHashSet,
graph::SceneGraph,
@@ -295,7 +295,7 @@ where
descriptors
}
#[derive(Clone, Visit, Reflect, Debug, ComponentProvider)]
#[derive(Clone, Visit, Reflect, Debug)]
#[reflect(derived_type = "UiNode")]
pub struct PropertySelector {
widget: Widget,
@@ -484,10 +484,9 @@ impl PropertySelectorBuilder {
}
}
#[derive(Clone, Visit, Reflect, Debug, ComponentProvider)]
#[derive(Clone, Visit, Reflect, Debug)]
#[reflect(derived_type = "UiNode")]
pub struct PropertySelectorWindow {
#[component(include)]
window: Window,
selector: Handle<PropertySelector>,
ok: Handle<Button>,
+2 -3
View File
@@ -206,7 +206,7 @@ struct TreeData {
pub derived_type_ids: Vec<TypeId>,
}
#[derive(Debug, Clone, Visit, Reflect, TypeUuidProvider, ComponentProvider)]
#[derive(Debug, Clone, Visit, Reflect, TypeUuidProvider)]
#[reflect(derived_type = "UiNode")]
#[type_uuid(id = "1d718f90-323c-492d-b057-98d47495900a")]
pub struct NodeSelector {
@@ -427,11 +427,10 @@ impl NodeSelectorBuilder {
}
}
#[derive(Debug, Clone, Visit, Reflect, TypeUuidProvider, ComponentProvider)]
#[derive(Debug, Clone, Visit, Reflect, TypeUuidProvider)]
#[type_uuid(id = "5bb00f15-d6ec-4f0e-af7e-9472b0e290b4")]
#[reflect(derived_type = "UiNode")]
pub struct NodeSelectorWindow {
#[component(include)]
window: Window,
selector: Handle<NodeSelector>,
ok: Handle<Button>,
+13 -4
View File
@@ -18,17 +18,26 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
use crate::fyrox::core::pool::Handle;
use crate::fyrox::graph::SceneGraph;
use crate::fyrox::gui::{UiNode, UserInterface};
use crate::ui_scene::selection::UiSelection;
use crate::{
fyrox::{
core::{blank_reflect_ref, pool::Handle, reflect::prelude::*},
graph::SceneGraph,
gui::{UiNode, UserInterface},
},
ui_scene::selection::UiSelection,
};
use std::collections::HashMap;
#[derive(Debug)]
pub struct Clipboard {
ui: UserInterface,
empty: bool,
}
impl Reflect for &'static mut Clipboard {
blank_reflect_ref!();
}
impl Default for Clipboard {
fn default() -> Self {
Self {
+3 -4
View File
@@ -21,18 +21,17 @@
pub mod graph;
pub mod widget;
use crate::fyrox::{core::type_traits::prelude::*, gui::UserInterface};
use crate::fyrox::{core::reflect::prelude::*, gui::UserInterface};
use crate::{
command::CommandContext, message::MessageSender, scene::Selection,
ui_scene::clipboard::Clipboard,
};
#[derive(ComponentProvider)]
#[derive(Reflect, Debug)]
#[reflect(non_cloneable)]
pub struct UiSceneContext {
pub ui: &'static mut UserInterface,
#[component(include)]
pub selection: &'static mut Selection,
#[component(include)]
pub message_sender: MessageSender,
pub clipboard: &'static mut Clipboard,
}
+2 -3
View File
@@ -22,7 +22,7 @@ use crate::{
fyrox::{
core::{
algebra::Vector2, color::Color, pool::ErasedHandle, pool::Handle, reflect::prelude::*,
type_traits::prelude::*, uuid_provider, visitor::prelude::*,
uuid_provider, visitor::prelude::*,
},
graph::SceneGraph,
gui::{
@@ -71,10 +71,9 @@ pub enum DropAnchor {
OnTop,
}
#[derive(Visit, Reflect, ComponentProvider)]
#[derive(Visit, Reflect)]
#[reflect(derived_type = "UiNode")]
pub struct SceneItem {
#[component(include)]
pub tree: Tree,
text_name: Handle<Text>,
name_value: String,
-160
View File
@@ -1,160 +0,0 @@
// Copyright (c) 2019-present Dmitry Stepanov and Fyrox Engine contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
use darling::*;
use proc_macro2::{TokenStream as TokenStream2, TokenStream};
use quote::*;
use syn::*;
#[derive(FromDeriveInput)]
#[darling(attributes(component), supports(struct_any, enum_any))]
pub struct TypeArgs {
pub ident: Ident,
pub generics: Generics,
pub data: ast::Data<VariantArgs, FieldArgs>,
}
#[derive(FromField, Clone)]
#[darling(attributes(component))]
pub struct FieldArgs {
pub ident: Option<Ident>,
pub ty: Type,
#[darling(default)]
pub include: bool,
#[darling(default)]
pub path: Option<String>,
#[darling(default)]
pub dest_type: Option<Type>,
}
#[derive(FromVariant)]
#[darling(attributes(component))]
#[allow(dead_code)] // TODO: Add support for enum variants.
pub struct VariantArgs {
pub ident: Ident,
pub fields: ast::Fields<FieldArgs>,
}
pub fn impl_type_uuid_provider(ast: DeriveInput) -> TokenStream2 {
let ty_args = TypeArgs::from_derive_input(&ast).unwrap();
match &ty_args.data {
ast::Data::Struct(ref field_args) => impl_type_uuid_provider_struct(&ty_args, field_args),
ast::Data::Enum(_) => unimplemented!(),
}
}
fn create_field_components(
// false if enum variant
is_struct: bool,
fields: &[FieldArgs],
field_style: ast::Style,
mutable: bool,
) -> Vec<TokenStream2> {
if field_style == ast::Style::Unit {
// `Unit` struct/enum variant has no components.
return Default::default();
}
let prefix = if is_struct {
if mutable {
Some(quote!(&mut self.))
} else {
Some(quote!(&self.))
}
} else {
None
};
fields
.iter()
.filter(|arg| arg.include)
.map(|arg| {
let ident = &arg.ident;
let ty = &arg.ty;
if let Some(path) = &arg.path {
let path: TokenStream = parse_str(path).unwrap();
if let Some(dest_type) = arg.dest_type.as_ref() {
quote! {
if type_id == std::any::TypeId::of::<#dest_type>() {
return Some(#prefix #path);
}
}
} else {
quote! {
if type_id == std::any::TypeId::of::<#ty>() {
return Some(#prefix #path);
}
}
}
} else {
quote! {
if type_id == std::any::TypeId::of::<#ty>() {
return Some(#prefix #ident);
}
}
}
})
.collect::<Vec<_>>()
}
fn impl_type_uuid_provider_struct(
ty_args: &TypeArgs,
field_args: &ast::Fields<FieldArgs>,
) -> TokenStream2 {
let (field_refs, field_ref_muts) = if field_args.style == ast::Style::Unit {
(quote! {}, quote! {})
} else {
let field_refs = create_field_components(true, &field_args.fields, field_args.style, false);
let field_ref_muts =
create_field_components(true, &field_args.fields, field_args.style, true);
(quote! { #(#field_refs)* }, quote! { #(#field_ref_muts)* })
};
let ty_ident = &ty_args.ident;
let (impl_generics, ty_generics, where_clause) = ty_args.generics.split_for_impl();
quote! {
impl #impl_generics ComponentProvider for #ty_ident #ty_generics #where_clause {
fn query_component_ref(&self, type_id: std::any::TypeId) -> Option<&dyn std::any::Any> {
if type_id == std::any::TypeId::of::<Self>() {
return Some(self);
}
#field_refs
None
}
fn query_component_mut(
&mut self,
type_id: std::any::TypeId,
) -> Option<&mut dyn std::any::Any> {
if type_id == std::any::TypeId::of::<Self>() {
return Some(self);
}
#field_ref_muts
None
}
}
}
}
-10
View File
@@ -20,7 +20,6 @@
#![allow(clippy::manual_unwrap_or_default)]
mod component;
mod reflect;
mod script_message_payload;
mod uuid;
@@ -183,15 +182,6 @@ pub fn type_uuid(input: TokenStream) -> TokenStream {
TokenStream::from(uuid::impl_type_uuid_provider(ast))
}
/// Implements `ComponentProvider` trait
///
/// User has to import `ComponentProvider` trait to use this macro.
#[proc_macro_derive(ComponentProvider, attributes(component))]
pub fn component(input: TokenStream) -> TokenStream {
let ast = parse_macro_input!(input as DeriveInput);
TokenStream::from(component::impl_type_uuid_provider(ast))
}
/// Implements `ScriptMessagePayload` trait
///
/// User has to import `ScriptMessagePayload` trait to use this macro.
+8
View File
@@ -500,10 +500,18 @@ fn gen_impl(
func(self)
}
fn as_reflect_direct(&self) -> &dyn Reflect {
self
}
fn as_reflect(&self, func: &mut dyn FnMut(&dyn Reflect)) {
func(self as &dyn Reflect)
}
fn as_reflect_mut_direct(&mut self) -> &mut dyn Reflect {
self
}
fn as_reflect_mut(&mut self, func: &mut dyn FnMut(&mut dyn Reflect)) {
func(self as &mut dyn Reflect)
}
-99
View File
@@ -1,99 +0,0 @@
// Copyright (c) 2019-present Dmitry Stepanov and Fyrox Engine contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
use fyrox_core::type_traits::prelude::*;
#[derive(ComponentProvider)]
pub struct Foo {
#[component(include)]
component: Component,
#[component(include)]
other_component: OtherComponent,
#[component(
include,
path = "wrapper.some_other_component",
dest_type = "SomeOtherComponent"
)]
wrapper: Wrapper,
#[allow(dead_code)]
non_component: String,
}
#[derive(PartialEq, Debug)]
pub struct Component {
stuff: f32,
}
#[derive(PartialEq, Debug)]
pub struct OtherComponent {
other_stuff: u32,
}
pub struct Wrapper {
some_other_component: SomeOtherComponent,
}
#[derive(PartialEq, Debug)]
pub struct SomeOtherComponent {
other_stuff: u8,
}
#[test]
fn test_component_provider() {
#[allow(clippy::disallowed_names)] // Stupid fucking clippy
let mut foo = Foo {
component: Component { stuff: 123.321 },
other_component: OtherComponent { other_stuff: 123 },
wrapper: Wrapper {
some_other_component: SomeOtherComponent { other_stuff: 77 },
},
non_component: Default::default(),
};
assert_eq!(
(&foo as &dyn ComponentProvider).component_ref::<Component>(),
Some(Component { stuff: 123.321 }).as_ref()
);
assert_eq!(
(&foo as &dyn ComponentProvider).component_ref::<OtherComponent>(),
Some(OtherComponent { other_stuff: 123 }).as_ref()
);
assert_eq!(
(&foo as &dyn ComponentProvider).component_ref::<SomeOtherComponent>(),
Some(SomeOtherComponent { other_stuff: 77 }).as_ref()
);
assert_eq!(
(&mut foo as &mut dyn ComponentProvider).component_mut::<Component>(),
Some(Component { stuff: 123.321 }).as_mut()
);
assert_eq!(
(&mut foo as &mut dyn ComponentProvider).component_mut::<OtherComponent>(),
Some(OtherComponent { other_stuff: 123 }).as_mut()
);
assert_eq!(
(&mut foo as &mut dyn ComponentProvider).component_mut::<SomeOtherComponent>(),
Some(SomeOtherComponent { other_stuff: 77 }).as_mut()
);
assert_eq!(
(&foo as &dyn ComponentProvider).component_ref::<String>(),
None
);
}
-1
View File
@@ -25,7 +25,6 @@
// #![feature(trace_macros)]
// trace_macros!(true);
pub mod component;
pub mod reflect;
pub mod uuid;
pub mod visit;
+16 -1
View File
@@ -264,6 +264,14 @@ impl Reflect for DynTypeWrapper {
None
}
}
fn as_reflect_direct(&self) -> &dyn Reflect {
self
}
fn as_reflect_mut_direct(&mut self) -> &mut dyn Reflect {
self
}
}
/// "Nullable" container for a dyntype. This container is essentially a wrapper for [`Option`] that
@@ -379,11 +387,18 @@ pub struct DynTypeConstructorDefinition {
}
/// A set of constructors that allows to create a dyntype by its type uuid.
#[derive(Default)]
#[derive(Default, Reflect)]
#[reflect(hide_all, non_cloneable)] // TODO
pub struct DynTypeConstructorContainer {
map: Mutex<FxHashMap<Uuid, DynTypeConstructorDefinition>>,
}
impl Debug for DynTypeConstructorContainer {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "DynTypeConstructorContainer")
}
}
impl DynTypeConstructorContainer {
/// Tries to create a dyntype by its type uuid. Returns [`None`] if there's no constructor
/// for the given uuid.
+8
View File
@@ -244,6 +244,14 @@ impl<T: Reflect> Reflect for Handle<T> {
None
}
}
fn as_reflect_direct(&self) -> &dyn Reflect {
self
}
fn as_reflect_mut_direct(&mut self) -> &mut dyn Reflect {
self
}
}
impl<T> Copy for Handle<T> {}
+22 -22
View File
@@ -40,7 +40,7 @@
//! indirections that might cause cache invalidation. This is the so called cache
//! friendliness.
use crate::{reflect::prelude::*, visitor::prelude::*, ComponentProvider};
use crate::{reflect::prelude::*, visitor::prelude::*};
use std::cell::UnsafeCell;
use std::fmt::{Display, Formatter};
use std::{
@@ -202,6 +202,14 @@ where
func(self)
}
fn as_reflect_direct(&self) -> &dyn Reflect {
self
}
fn as_reflect_mut_direct(&mut self) -> &mut dyn Reflect {
self
}
#[inline]
fn as_reflect(&self, func: &mut dyn FnMut(&dyn Reflect)) {
func(self)
@@ -1414,24 +1422,20 @@ where
impl<T, P> Pool<T, P>
where
T: ComponentProvider,
T: Reflect,
P: PayloadContainer<Element = T> + 'static,
{
/// Tries to mutably borrow an object and fetch its component of specified type.
#[inline]
pub fn try_get_component_of_type<C>(&self, handle: Handle<T>) -> Result<&C, PoolError>
where
C: 'static,
C: Reflect,
{
self.try_borrow(handle)
.and_then(|n| {
n.query_component_ref(TypeId::of::<C>())
.ok_or(PoolError::NoSuchComponent(handle.into()))
})
.and_then(|c| {
c.downcast_ref()
.ok_or(PoolError::InvalidType(handle.into()))
})
self.try_borrow(handle).and_then(|n| {
(n as &dyn Reflect)
.self_or_field_ref_of_type::<C>()
.ok_or(PoolError::NoSuchComponent(handle.into()))
})
}
/// Tries to mutably borrow an object and fetch its component of specified type.
@@ -1441,17 +1445,13 @@ where
handle: Handle<T>,
) -> Result<&mut C, PoolError>
where
C: 'static,
C: Reflect,
{
self.try_borrow_mut(handle)
.and_then(|n| {
n.query_component_mut(TypeId::of::<C>())
.ok_or(PoolError::NoSuchComponent(handle.into()))
})
.and_then(|c| {
c.downcast_mut()
.ok_or(PoolError::InvalidType(handle.into()))
})
self.try_borrow_mut(handle).and_then(|n| {
(n as &mut dyn Reflect)
.self_or_field_mut_of_type::<C>()
.ok_or(PoolError::NoSuchComponent(handle.into()))
})
}
}
+8 -9
View File
@@ -19,9 +19,8 @@
// SOFTWARE.
use super::{Handle, ObjectOrVariant, PayloadContainer, Pool, PoolError, RefCounter};
use crate::ComponentProvider;
use crate::reflect::Reflect;
use std::{
any::TypeId,
cell::RefCell,
cmp::Ordering,
fmt::{Debug, Formatter},
@@ -329,7 +328,7 @@ where
impl<'a, T, P> MultiBorrowContext<'a, T, P>
where
T: Sized + ComponentProvider,
T: Sized + Reflect,
P: PayloadContainer<Element = T> + 'static,
{
/// Tries to mutably borrow an object and fetch its component of specified type.
@@ -339,11 +338,11 @@ where
handle: Handle<T>,
) -> Result<Ref<'a, 'b, C>, PoolError>
where
C: 'static,
C: Reflect,
{
self.try_get_internal(handle, move |obj| {
obj.query_component_ref(TypeId::of::<C>())
.and_then(|c| c.downcast_ref())
(obj as &dyn Reflect)
.self_or_field_ref_of_type::<C>()
.ok_or(PoolError::NoSuchComponent(handle.into()))
})
}
@@ -355,11 +354,11 @@ where
handle: Handle<T>,
) -> Result<RefMut<'a, 'b, C>, PoolError>
where
C: 'static,
C: Reflect,
{
self.try_get_mut_internal(handle, move |obj| {
obj.query_component_mut(TypeId::of::<C>())
.and_then(|c| c.downcast_mut())
(obj as &mut dyn Reflect)
.self_or_field_mut_of_type::<C>()
.ok_or(PoolError::NoSuchComponent(handle.into()))
})
}
+13 -7
View File
@@ -25,7 +25,7 @@ use crate::{
reflect::{blank_reflect, prelude::*},
sstorage::ImmutableString,
uuid::Uuid,
warn, SafeLock,
SafeLock,
};
use fyrox_core_derive::impl_reflect;
use nalgebra::*;
@@ -205,20 +205,26 @@ macro_rules! impl_reflect_inner_mutability {
(*guard).as_reflect_mut(func)
}
fn as_reflect_direct(&self) -> &dyn $crate::reflect::Reflect {
// xxx_direct methods cannot hold the lock, so return self here.
self
}
fn as_reflect_mut_direct(&mut self) -> &mut dyn $crate::reflect::Reflect {
// xxx_direct methods cannot hold the lock, so return self here.
self
}
fn set(&mut $self, value: Box<dyn Reflect>) -> Result<Box<dyn Reflect>, Box<dyn Reflect>> {
let mut guard = $acquire_lock_guard;
guard.set(value)
}
fn field_direct_ref(&self, index: usize) -> Option<FieldRef> {
warn!("Cannot get a direct field ref {index}, because it is \
not supported for types with interior mutability.");
fn field_direct_ref(&self, _index: usize) -> Option<FieldRef> {
None
}
fn field_direct_mut(&mut self, index: usize) -> Option<FieldMut> {
warn!("Cannot get a direct field ref {index}, because it is \
not supported for types with interior mutability.");
fn field_direct_mut(&mut self, _index: usize) -> Option<FieldMut> {
None
}
+129
View File
@@ -200,6 +200,14 @@ macro_rules! delegate_reflect {
self.deref_mut().as_reflect_mut(func)
}
fn as_reflect_direct(&self) -> &dyn $crate::reflect::Reflect {
self.deref().as_reflect_direct()
}
fn as_reflect_mut_direct(&mut self) -> &mut dyn $crate::reflect::Reflect {
self.deref_mut().as_reflect_mut_direct()
}
fn field_direct_ref(&self, index: usize) -> Option<FieldRef> {
self.deref().field_direct_ref(index)
}
@@ -288,6 +296,10 @@ macro_rules! delegate_reflect {
) {
self.deref_mut().as_hash_map_mut(func)
}
fn fields_count(&self) -> usize {
self.deref().fields_count()
}
};
}
@@ -358,6 +370,115 @@ macro_rules! blank_reflect {
func(self)
}
fn as_reflect_direct(&self) -> &dyn $crate::reflect::Reflect {
self
}
fn as_reflect_mut_direct(&mut self) -> &mut dyn $crate::reflect::Reflect {
self
}
fn find_field(
&self,
name: &str,
func: &mut dyn FnMut(Option<&dyn $crate::reflect::Reflect>),
) {
func(if name == "self" { Some(self) } else { None })
}
fn find_field_mut(
&mut self,
name: &str,
func: &mut dyn FnMut(Option<&mut dyn $crate::reflect::Reflect>),
) {
func(if name == "self" { Some(self) } else { None })
}
fn field_direct_ref(&self, _index: usize) -> Option<$crate::reflect::FieldRef> {
None
}
fn field_direct_mut(&mut self, _index: usize) -> Option<$crate::reflect::FieldMut> {
None
}
fn set(
&mut self,
value: Box<dyn $crate::reflect::Reflect>,
) -> Result<Box<dyn $crate::reflect::Reflect>, Box<dyn $crate::reflect::Reflect>> {
let this = std::mem::replace(self, value.take()?);
Ok(Box::new(this))
}
};
}
#[macro_export]
macro_rules! blank_reflect_ref {
() => {
fn source_path() -> &'static str {
file!()
}
fn derived_types() -> &'static [std::any::TypeId]
where
Self: Sized,
{
&[]
}
fn try_clone_box(&self) -> Option<Box<dyn $crate::reflect::Reflect>> {
None
}
fn query_derived_types(&self) -> &'static [std::any::TypeId] {
Self::derived_types()
}
fn type_name(&self) -> &'static str {
std::any::type_name::<Self>()
}
fn doc(&self) -> &'static str {
""
}
fn assembly_name(&self) -> &'static str {
env!("CARGO_PKG_NAME")
}
fn type_assembly_name() -> &'static str {
env!("CARGO_PKG_NAME")
}
fn fields_ref(&self, func: &mut dyn FnMut(&[$crate::reflect::FieldRef])) {
func(&[])
}
#[inline]
fn fields_mut(&mut self, func: &mut dyn FnMut(&mut [$crate::reflect::FieldMut])) {
func(&mut [])
}
fn into_any(self: Box<Self>) -> Box<dyn std::any::Any> {
self
}
fn as_any(&self, func: &mut dyn FnMut(&dyn std::any::Any)) {
func(self)
}
fn as_any_mut(&mut self, func: &mut dyn FnMut(&mut dyn std::any::Any)) {
func(self)
}
fn as_reflect(&self, func: &mut dyn FnMut(&dyn $crate::reflect::Reflect)) {
func(self)
}
fn as_reflect_mut(&mut self, func: &mut dyn FnMut(&mut dyn $crate::reflect::Reflect)) {
func(self)
}
fn find_field(
&self,
name: &str,
@@ -389,6 +510,14 @@ macro_rules! blank_reflect {
let this = std::mem::replace(self, value.take()?);
Ok(Box::new(this))
}
fn as_reflect_direct(&self) -> &dyn $crate::reflect::Reflect {
self
}
fn as_reflect_mut_direct(&mut self) -> &mut dyn $crate::reflect::Reflect {
self
}
};
}
+6 -2
View File
@@ -135,6 +135,10 @@ pub trait Reflect: Any + Debug {
fn as_any_mut(&mut self, func: &mut dyn FnMut(&mut dyn Any));
fn as_reflect_direct(&self) -> &dyn Reflect;
fn as_reflect_mut_direct(&mut self) -> &mut dyn Reflect;
fn as_reflect(&self, func: &mut dyn FnMut(&dyn Reflect));
fn as_reflect_mut(&mut self, func: &mut dyn FnMut(&mut dyn Reflect));
@@ -350,7 +354,7 @@ impl dyn Reflect {
/// Tries to downcast self to the specified type, or if it is not possible, tries to find a
/// field of the specified type.
pub fn self_or_field_ref_of_type<T: Reflect>(&self) -> Option<&T> {
if let Some(value) = (self as &dyn Any).downcast_ref::<T>() {
if let Some(value) = (self.as_reflect_direct() as &dyn Any).downcast_ref::<T>() {
Some(value)
} else {
self.first_field_ref_of_type()
@@ -362,7 +366,7 @@ impl dyn Reflect {
pub fn self_or_field_mut_of_type<T: Reflect>(&mut self) -> Option<&mut T> {
// SAFETY: See the comment in `first_field_mut_of_type` method.
let this = unsafe { &mut *(self as *mut Self) };
if let Some(value) = (self as &mut dyn Any).downcast_mut::<T>() {
if let Some(value) = (self.as_reflect_mut_direct() as &mut dyn Any).downcast_mut::<T>() {
Some(value)
} else {
this.first_field_mut_of_type()
+1 -89
View File
@@ -19,15 +19,13 @@
// SOFTWARE.
use crate::math::Rect;
pub use fyrox_core_derive::ComponentProvider;
pub use fyrox_core_derive::TypeUuidProvider;
use nalgebra::{SMatrix, Vector2, Vector3, Vector4};
use std::any::{Any, TypeId};
use std::path::PathBuf;
use uuid::Uuid;
pub mod prelude {
pub use super::{combine_uuids, ComponentProvider, TypeUuidProvider};
pub use super::{combine_uuids, TypeUuidProvider};
pub use uuid::{uuid, Uuid};
}
@@ -124,89 +122,3 @@ pub fn combine_uuids(a: Uuid, b: Uuid) -> Uuid {
Uuid::from_bytes(combined_bytes)
}
/// Component provider provides dynamic access to inner components of an object by their type id.
pub trait ComponentProvider {
/// Allows an object to provide access to inner components.
fn query_component_ref(&self, type_id: TypeId) -> Option<&dyn Any>;
/// Allows an object to provide access to inner components.
fn query_component_mut(&mut self, type_id: TypeId) -> Option<&mut dyn Any>;
}
impl dyn ComponentProvider {
/// Tries to borrow a component of given type.
#[inline]
pub fn component_ref<T: Any>(&self) -> Option<&T> {
ComponentProvider::query_component_ref(self, TypeId::of::<T>())
.and_then(|c| c.downcast_ref())
}
/// Tries to borrow a component of given type.
#[inline]
pub fn component_mut<T: Any>(&mut self) -> Option<&mut T> {
ComponentProvider::query_component_mut(self, TypeId::of::<T>())
.and_then(|c| c.downcast_mut())
}
}
/// Implements [`ComponentProvider::query_component_ref`] and [`ComponentProvider::query_component_mut`] in a much
/// shorter way.
#[macro_export]
macro_rules! impl_component_provider {
($dest_type:ty) => {
impl $crate::type_traits::ComponentProvider for $dest_type {
fn query_component_ref(&self, type_id: std::any::TypeId) -> Option<&dyn std::any::Any> {
if type_id == std::any::TypeId::of::<Self>() {
return Some(self);
}
None
}
fn query_component_mut(
&mut self,
type_id: std::any::TypeId,
) -> Option<&mut dyn std::any::Any> {
if type_id == std::any::TypeId::of::<Self>() {
return Some(self);
}
None
}
}
};
($dest_type:ty, $($($comp_field:ident).*: $comp_type:ty),*) => {
impl $crate::type_traits::ComponentProvider for $dest_type {
fn query_component_ref(&self, type_id: std::any::TypeId) -> Option<&dyn std::any::Any> {
if type_id == std::any::TypeId::of::<Self>() {
return Some(self);
}
$(
if type_id == std::any::TypeId::of::<$comp_type>() {
return Some(&self.$($comp_field).*)
}
)*
None
}
fn query_component_mut(
&mut self,
type_id: std::any::TypeId,
) -> Option<&mut dyn std::any::Any> {
if type_id == std::any::TypeId::of::<Self>() {
return Some(self);
}
$(
if type_id == std::any::TypeId::of::<$comp_type>() {
return Some(&mut self.$($comp_field).*)
}
)*
None
}
}
};
}
+8
View File
@@ -550,6 +550,14 @@ where
fn field_direct_mut(&mut self, index: usize) -> Option<FieldMut> {
self.value.field_direct_mut(index)
}
fn as_reflect_direct(&self) -> &dyn Reflect {
self.value.as_reflect_direct()
}
fn as_reflect_mut_direct(&mut self) -> &mut dyn Reflect {
self.value.as_reflect_mut_direct()
}
}
impl<T> ReflectInheritableVariable for InheritableVariable<T>
+43 -42
View File
@@ -36,10 +36,9 @@ use fyrox_core::{
pool::Handle,
reflect::prelude::*,
variable::{self, InheritableVariable},
ComponentProvider, NameProvider, Uuid,
NameProvider, Uuid,
};
use fyrox_resource::{untyped::UntypedResource, Resource, TypedResourceData};
use std::any::Any;
use std::cmp::Ordering;
use std::fmt::{Debug, Formatter};
use std::{
@@ -468,7 +467,7 @@ fn reset_property_modified_flag(entity: &mut dyn Reflect, path: &str) {
})
}
pub trait SceneGraphNode: ComponentProvider + Reflect + NameProvider + Clone + 'static {
pub trait SceneGraphNode: Reflect + NameProvider + Clone + 'static {
type Base: Clone;
type SceneGraph: SceneGraph<Node = Self>;
type ResourceData: PrefabData<Graph = Self::SceneGraph>;
@@ -630,21 +629,19 @@ pub trait SceneGraphNode: ComponentProvider + Reflect + NameProvider + Clone + '
/// Tries to borrow a component of given type.
#[inline]
fn component_ref<T: Any>(&self) -> Option<&T> {
ComponentProvider::query_component_ref(self, TypeId::of::<T>())
.and_then(|c| c.downcast_ref())
fn component_ref<T: Reflect>(&self) -> Option<&T> {
(self as &dyn Reflect).self_or_field_ref_of_type::<T>()
}
/// Tries to borrow a component of given type.
#[inline]
fn component_mut<T: Any>(&mut self) -> Option<&mut T> {
ComponentProvider::query_component_mut(self, TypeId::of::<T>())
.and_then(|c| c.downcast_mut())
fn component_mut<T: Reflect>(&mut self) -> Option<&mut T> {
(self as &mut dyn Reflect).self_or_field_mut_of_type::<T>()
}
/// Checks if the node has a component of given type.
#[inline]
fn has_component<T: Any>(&self) -> bool {
fn has_component<T: Reflect>(&self) -> bool {
self.component_ref::<T>().is_some()
}
}
@@ -885,34 +882,26 @@ pub trait SceneGraph: 'static {
#[inline]
fn try_get_of_type<T>(&self, handle: Handle<Self::Node>) -> Result<&T, PoolError>
where
T: 'static,
T: Reflect,
{
self.try_get_node(handle)
.and_then(|n| {
n.query_component_ref(TypeId::of::<T>())
.ok_or(PoolError::NoSuchComponent(handle.into()))
})
.and_then(|c| {
c.downcast_ref()
.ok_or(PoolError::InvalidType(handle.into()))
})
self.try_get_node(handle).and_then(|n| {
(n as &dyn Reflect)
.self_or_field_ref_of_type()
.ok_or(PoolError::NoSuchComponent(handle.into()))
})
}
/// Tries to mutably borrow a node and fetch its component of specified type.
#[inline]
fn try_get_mut_of_type<T>(&mut self, handle: Handle<Self::Node>) -> Result<&mut T, PoolError>
where
T: 'static,
T: Reflect,
{
self.try_get_node_mut(handle)
.and_then(|n| {
n.query_component_mut(TypeId::of::<T>())
.ok_or(PoolError::NoSuchComponent(handle.into()))
})
.and_then(|c| {
c.downcast_mut()
.ok_or(PoolError::InvalidType(handle.into()))
})
self.try_get_node_mut(handle).and_then(|n| {
(n as &mut dyn Reflect)
.self_or_field_mut_of_type()
.ok_or(PoolError::NoSuchComponent(handle.into()))
})
}
/// Tries to borrow a node by the given handle and checks if it has a component of the specified
@@ -920,7 +909,7 @@ pub trait SceneGraph: 'static {
#[inline]
fn has_component<T>(&self, handle: Handle<impl ObjectOrVariant<Self::Node>>) -> bool
where
T: 'static,
T: Reflect,
{
self.try_get_of_type::<T>(handle.to_base()).is_ok()
}
@@ -990,12 +979,11 @@ pub trait SceneGraph: 'static {
node_handle: Handle<impl ObjectOrVariant<Self::Node>>,
) -> Option<(Handle<Self::Node>, &T)>
where
T: 'static,
T: Reflect,
{
self.find_up_map(node_handle, &mut |node| {
node.query_component_ref(TypeId::of::<T>())
(node as &dyn Reflect).self_or_field_ref_of_type::<T>()
})
.and_then(|(handle, c)| c.downcast_ref::<T>().map(|typed| (handle, typed)))
}
#[inline]
@@ -1004,12 +992,11 @@ pub trait SceneGraph: 'static {
node_handle: Handle<impl ObjectOrVariant<Self::Node>>,
) -> Option<(Handle<Self::Node>, &T)>
where
T: 'static,
T: Reflect,
{
self.find_map(node_handle, &mut |node| {
node.query_component_ref(TypeId::of::<T>())
(node as &dyn Reflect).self_or_field_ref_of_type::<T>()
})
.and_then(|(handle, c)| c.downcast_ref::<T>().map(|typed| (handle, typed)))
}
/// Searches for a node up the tree starting from the specified node using the specified closure. Returns a tuple
@@ -1699,7 +1686,7 @@ mod test {
define_as_any_trait!(NodeAsAny => NodeTrait);
pub trait NodeTrait: BaseNodeTrait + Reflect + Visit + ComponentProvider + NodeAsAny {}
pub trait NodeTrait: BaseNodeTrait + Reflect + Visit + NodeAsAny {}
// Essentially implements ObjectOrVariant for NodeTrait types.
// See ObjectOrVariantHelper for the cause of the indirection.
@@ -1712,7 +1699,7 @@ mod test {
}
}
#[derive(ComponentProvider, Debug)]
#[derive(Debug)]
pub struct Node(Box<dyn NodeTrait>);
impl Clone for Node {
@@ -1822,6 +1809,18 @@ mod test {
fn field_direct_mut(&mut self, index: usize) -> Option<FieldMut<'_, '_>> {
self.0.deref_mut().field_direct_mut(index)
}
fn fields_count(&self) -> usize {
self.0.fields_count()
}
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()
}
}
impl NameProvider for Node {
@@ -2185,7 +2184,7 @@ mod test {
}
}
#[derive(Clone, Reflect, Visit, Default, Debug, ComponentProvider)]
#[derive(Clone, Reflect, Visit, Default, Debug)]
#[reflect(derived_type = "Node")]
pub struct Pivot {
base: Base,
@@ -2207,7 +2206,7 @@ mod test {
}
}
#[derive(Clone, Reflect, Visit, Default, Debug, ComponentProvider)]
#[derive(Clone, Reflect, Visit, Default, Debug)]
#[reflect(derived_type = "Node")]
pub struct RigidBody {
base: Base,
@@ -2229,7 +2228,7 @@ mod test {
}
}
#[derive(Clone, Reflect, Visit, Default, Debug, ComponentProvider)]
#[derive(Clone, Reflect, Visit, Default, Debug)]
#[reflect(derived_type = "Node")]
pub struct Joint {
base: Base,
@@ -2267,6 +2266,8 @@ mod test {
graph.link_nodes(c, root);
graph.link_nodes(d, root);
assert!(graph.try_get_of_type::<Pivot>(a).is_ok());
let root_ref = &mut graph[root];
assert_eq!(root_ref.set_child_position(a, 0), Some(0));
assert_eq!(root_ref.set_child_position(b, 1), Some(1));
+19 -9
View File
@@ -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,
-36
View File
@@ -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) {
+1 -3
View File
@@ -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,
}
+2 -3
View File
@@ -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()
+1 -1
View File
@@ -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,
+1 -1
View File
@@ -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,
+1 -1
View File
@@ -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,
+1 -2
View File
@@ -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,
+1 -1
View File
@@ -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,
+1 -1
View File
@@ -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,
+1 -1
View File
@@ -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,
+5 -5
View File
@@ -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,
+1 -1
View File
@@ -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,
+1 -2
View File
@@ -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>,
+1 -2
View File
@@ -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)]
+1 -2
View File
@@ -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)]
+1 -1
View File
@@ -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")]
+5
View File
@@ -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
+1 -1
View File
@@ -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,
+12 -17
View File
@@ -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")
+1 -1
View File
@@ -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,
+1 -1
View File
@@ -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,
+1 -1
View File
@@ -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")]
+1 -1
View File
@@ -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 {
+1 -1
View File
@@ -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,
+1 -1
View File
@@ -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,
+1 -1
View File
@@ -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,
+1 -1
View File
@@ -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,
+1 -1
View File
@@ -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,
+1 -1
View File
@@ -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>,
+2 -2
View File
@@ -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 {
+1 -1
View File
@@ -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.
+15 -13
View File
@@ -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 {}
+3 -2
View File
@@ -32,6 +32,7 @@ use crate::{
log::Log,
notify, ok_or_continue,
parking_lot::{Mutex, MutexGuard},
reflect::prelude::*,
task::TaskPool,
watcher::FileSystemWatcher,
SafeLock, TypeUuidProvider, Uuid,
@@ -116,7 +117,8 @@ pub struct ResourceManagerState {
///
/// It is a simple wrapper over [`ResourceManagerState`] that can be shared (cloned). In other words,
/// it is just a strong reference to the inner state.
#[derive(Clone)]
#[derive(Clone, Reflect)]
#[reflect(hide_all)] // Inner content is hidden.
pub struct ResourceManager {
state: Arc<Mutex<ResourceManagerState>>,
}
@@ -2082,7 +2084,6 @@ mod test {
ResourceData,
};
use fyrox_core::{
reflect::prelude::*,
uuid::{uuid, Uuid},
visitor::{Visit, VisitResult, Visitor},
TypeUuidProvider,
+8
View File
@@ -138,6 +138,14 @@ impl Reflect for ResourceDataWrapper {
self.deref_mut().as_any_mut(func)
}
fn as_reflect_direct(&self) -> &dyn Reflect {
self.deref().as_reflect_direct()
}
fn as_reflect_mut_direct(&mut self) -> &mut dyn Reflect {
self.deref_mut().as_reflect_mut_direct()
}
fn as_reflect(&self, func: &mut dyn FnMut(&dyn Reflect)) {
self.deref().as_reflect(func)
}
-2
View File
@@ -26,7 +26,6 @@ use fyrox::plugin::error::GameResult;
use fyrox::{
core::{
algebra::{UnitQuaternion, UnitVector3, Vector3},
impl_component_provider,
math::curve::{Curve, CurveKey, CurveKeyKind},
math::Vector3Ext,
reflect::prelude::*,
@@ -201,7 +200,6 @@ impl Default for FlyingCameraController {
}
}
impl_component_provider!(FlyingCameraController);
uuid_provider!(FlyingCameraController = "8d9e2feb-8c61-482c-8ba4-b0b13b201113");
impl ScriptTrait for FlyingCameraController {
+2 -4
View File
@@ -121,14 +121,12 @@ pub mod prelude {
///
/// The node does **not** contain any animations, instead it just takes animations from an animation
/// player node and mixes them.
#[derive(Visit, Reflect, Clone, Debug, Default, ComponentProvider, TypeUuidProvider)]
#[derive(Visit, Reflect, Clone, Debug, Default, TypeUuidProvider)]
#[type_uuid(id = "4b08c753-2a10-41e3-8fb2-4fd0517e86bc")]
#[reflect(derived_type = "UiNode")]
pub struct AnimationBlendingStateMachine {
widget: Widget,
#[component(include)]
machine: InheritableVariable<Machine>,
#[component(include)]
animation_player: InheritableVariable<Handle<UiNode>>,
}
@@ -292,7 +290,7 @@ pub struct EventAction {
}
/// A widget that listens for particular events and sets parameters in an ABSM accordingly.
#[derive(Visit, Reflect, Clone, Debug, Default, ComponentProvider, TypeUuidProvider)]
#[derive(Visit, Reflect, Clone, Debug, Default, TypeUuidProvider)]
#[type_uuid(id = "15f306b8-3bb8-4b35-87bd-6e9e5d748455")]
#[reflect(derived_type = "UiNode")]
pub struct AbsmEventProvider {
+1 -3
View File
@@ -143,13 +143,11 @@ impl BoundValueCollectionExt for BoundValueCollection {
/// Animation player is a node that contains multiple animations. It updates and plays all the animations.
/// The node could be a source of animations for animation blending state machines. To learn more about
/// animations, see [`Animation`] docs.
#[derive(Visit, Reflect, Clone, Debug, ComponentProvider)]
#[derive(Visit, Reflect, Clone, Debug)]
#[reflect(derived_type = "UiNode")]
pub struct AnimationPlayer {
widget: Widget,
#[component(include)]
pub(crate) animations: InheritableVariable<AnimationContainer>,
#[component(include)]
auto_apply: bool,
}
+1 -1
View File
@@ -116,7 +116,7 @@ impl<T: BitContainer> ConstructorProvider<UiNode, UserInterface> for BitField<T>
}
}
#[derive(Default, Clone, Reflect, Visit, Debug, ComponentProvider)]
#[derive(Default, Clone, Reflect, Visit, Debug)]
#[reflect(derived_type = "UiNode")]
pub struct BitField<T>
where
+1 -1
View File
@@ -99,7 +99,7 @@ use fyrox_graph::constructor::{ConstructorProvider, GraphNodeConstructor};
/// .with_stroke_thickness(Thickness {left: 2.0, right: 2.0, top: 2.0, bottom: 2.0}.into())
/// .build(&mut ui.build_ctx());
/// ```
#[derive(Default, Clone, Visit, Reflect, Debug, TypeUuidProvider, ComponentProvider)]
#[derive(Default, Clone, Visit, Reflect, Debug, TypeUuidProvider)]
#[type_uuid(id = "6aba3dc5-831d-481a-bc83-ec10b2b2bf12")]
#[reflect(derived_type = "UiNode")]
pub struct Border {
+1 -1
View File
@@ -93,7 +93,7 @@ impl MessageData for ButtonMessage {}
/// }
/// }
/// ```
#[derive(Default, Clone, Visit, Reflect, Debug, TypeUuidProvider, ComponentProvider)]
#[derive(Default, Clone, Visit, Reflect, Debug, TypeUuidProvider)]
#[type_uuid(id = "2abcf12b-2f19-46da-b900-ae8890f7c9c6")]
#[reflect(derived_type = "UiNode")]
pub struct Button {

Some files were not shown because too many files have changed in this diff Show More