split SceneGraph trait into object-safe and object-non-safe parts

- `BaseSceneGraph` is object safe, which allows to pass it using `&dyn BaseSceneGraph<..>` references
This commit is contained in:
Dmitry Stepanov
2024-02-11 15:24:33 +03:00
parent 7b56cd6942
commit 6499937553
126 changed files with 288 additions and 269 deletions
+1 -1
View File
@@ -10,7 +10,7 @@ use crate::{
message::MessageSender,
send_sync_message,
};
use fyrox::graph::SceneGraph;
use fyrox::graph::BaseSceneGraph;
use fyrox::{
core::{
algebra::Vector2,
+1 -1
View File
@@ -9,7 +9,7 @@ use crate::{
},
utils::fetch_node_screen_center_ui,
};
use fyrox::graph::SceneGraph;
use fyrox::graph::BaseSceneGraph;
use fyrox::{
core::{
algebra::{Matrix3, Point2, Vector2},
+1 -1
View File
@@ -13,7 +13,7 @@ use crate::{
scene::{GameScene, Selection},
Message,
};
use fyrox::graph::SceneGraph;
use fyrox::graph::BaseSceneGraph;
use fyrox::{
core::{color::Color, pool::Handle},
engine::Engine,
+1 -1
View File
@@ -2,7 +2,7 @@ use crate::absm::{
selectable::{Selectable, SelectableMessage},
BORDER_COLOR, NORMAL_BACKGROUND, SELECTED_BACKGROUND,
};
use fyrox::graph::SceneGraph;
use fyrox::graph::BaseSceneGraph;
use fyrox::{
core::{
color::Color,
+1 -1
View File
@@ -4,7 +4,7 @@ use crate::message::MessageSender;
use crate::{
inspector::editors::make_property_editors_container, Message, MessageDirection, MSG_SYNC_FLAG,
};
use fyrox::graph::SceneGraph;
use fyrox::graph::BaseSceneGraph;
use fyrox::{
core::{log::Log, pool::Handle},
gui::{
+1 -1
View File
@@ -14,7 +14,7 @@ use crate::{
message::MessageSender,
scene::{commands::ChangeSelectionCommand, Selection},
};
use fyrox::graph::SceneGraph;
use fyrox::graph::BaseSceneGraph;
use fyrox::{
core::pool::Handle,
gui::{
+1 -1
View File
@@ -14,7 +14,7 @@ use crate::{
scene::{commands::ChangeSelectionCommand, Selection},
send_sync_message,
};
use fyrox::graph::SceneGraph;
use fyrox::graph::BaseSceneGraph;
use fyrox::{
core::pool::Handle,
gui::{
+1 -1
View File
@@ -16,7 +16,7 @@ use crate::{
message::MessageSender,
scene::{commands::ChangeSelectionCommand, Selection},
};
use fyrox::graph::SceneGraph;
use fyrox::graph::BaseSceneGraph;
use fyrox::{
core::{algebra::Vector2, pool::Handle},
gui::{
+1 -1
View File
@@ -21,7 +21,7 @@ use crate::{
scene::{commands::ChangeSelectionCommand, Selection},
send_sync_message,
};
use fyrox::graph::SceneGraph;
use fyrox::graph::{BaseSceneGraph, SceneGraph};
use fyrox::{
core::pool::Handle,
gui::{
+1 -1
View File
@@ -15,7 +15,7 @@ use crate::{
},
send_sync_message,
};
use fyrox::graph::SceneGraph;
use fyrox::graph::{BaseSceneGraph, SceneGraph};
use fyrox::{
core::{pool::ErasedHandle, pool::Handle},
fxhash::FxHashSet,
+1 -1
View File
@@ -14,7 +14,7 @@ use crate::{
scene::{commands::ChangeSelectionCommand, GameScene, Selection},
send_sync_message, Message,
};
use fyrox::graph::SceneGraph;
use fyrox::graph::{BaseSceneGraph, SceneGraph};
use fyrox::{
core::{algebra::Vector2, math::Rect, pool::Handle, uuid::Uuid},
engine::Engine,
+1 -1
View File
@@ -1,5 +1,5 @@
use crate::menu::create_menu_item;
use fyrox::graph::SceneGraph;
use fyrox::graph::BaseSceneGraph;
use fyrox::{
core::{
algebra::{Matrix3, Point2, Vector2},
+1 -1
View File
@@ -19,7 +19,7 @@ use crate::{
},
send_sync_message,
};
use fyrox::graph::SceneGraph;
use fyrox::graph::BaseSceneGraph;
use fyrox::{
asset::manager::ResourceManager,
core::{algebra::Vector2, futures::executor::block_on, log::Log, math::Rect, pool::Handle},
+1 -1
View File
@@ -24,7 +24,7 @@ use crate::{
},
send_sync_message, utils,
};
use fyrox::graph::SceneGraph;
use fyrox::graph::BaseSceneGraph;
use fyrox::{
core::{
algebra::{UnitQuaternion, Vector2, Vector3, Vector4},
+1 -1
View File
@@ -2,7 +2,7 @@ use crate::{
inspector::editors::make_property_editors_container, message::MessageSender, MSG_SYNC_FLAG,
};
use fyrox::core::reflect::Reflect;
use fyrox::graph::SceneGraph;
use fyrox::graph::BaseSceneGraph;
use fyrox::{
asset::{manager::ResourceManager, options::BaseImportOptions},
core::{append_extension, futures::executor::block_on, log::Log, pool::Handle},
+1 -1
View File
@@ -9,7 +9,7 @@ use crate::{
utils::window_content,
AssetItem, Message, Mode,
};
use fyrox::graph::SceneGraph;
use fyrox::graph::BaseSceneGraph;
use fyrox::{
asset::{
manager::ResourceManager,
+1 -1
View File
@@ -17,7 +17,7 @@ use crate::{
};
use fyrox::asset::manager::ResourceManager;
use fyrox::core::parking_lot::Mutex;
use fyrox::graph::SceneGraph;
use fyrox::graph::BaseSceneGraph;
use fyrox::{
core::{futures::executor::block_on, pool::Handle},
engine::Engine,
+1 -1
View File
@@ -4,7 +4,7 @@ use crate::settings::{
scene::{SceneCameraSettings, SceneSettings},
Settings,
};
use fyrox::graph::SceneGraph;
use fyrox::graph::BaseSceneGraph;
use fyrox::{
core::{
algebra::{Matrix4, Point3, UnitQuaternion, Vector2, Vector3},
+1 -1
View File
@@ -1,4 +1,4 @@
use fyrox::graph::SceneGraph;
use fyrox::graph::BaseSceneGraph;
use fyrox::{
core::{
algebra::{Matrix4, Vector3},
+1 -1
View File
@@ -1,5 +1,5 @@
use crate::{asset::item::AssetItem, inspector::EditorEnvironment};
use fyrox::graph::SceneGraph;
use fyrox::graph::BaseSceneGraph;
use fyrox::{
asset::{manager::ResourceManager, untyped::ResourceKind},
core::{
+1 -1
View File
@@ -5,7 +5,7 @@ use crate::{
world::graph::item::SceneItem,
Message, UiMessage, UiNode, UserInterface, VerticalAlignment,
};
use fyrox::graph::SceneGraph;
use fyrox::graph::BaseSceneGraph;
use fyrox::{
core::{
color::Color, pool::ErasedHandle, pool::Handle, reflect::prelude::*,
+1 -1
View File
@@ -2,7 +2,7 @@ use crate::{
asset::item::AssetItem, inspector::EditorEnvironment, message::MessageSender, Message,
MessageDirection,
};
use fyrox::graph::SceneGraph;
use fyrox::graph::BaseSceneGraph;
use fyrox::{
asset::{core::pool::Handle, manager::ResourceManager, state::ResourceState},
core::{
+1 -1
View File
@@ -2,7 +2,7 @@ use crate::{
asset::item::AssetItem, inspector::EditorEnvironment, load_image, message::MessageSender,
Message,
};
use fyrox::graph::SceneGraph;
use fyrox::graph::BaseSceneGraph;
use fyrox::{
asset::{manager::ResourceManager, state::LoadError, Resource, TypedResourceData},
core::{
+1 -1
View File
@@ -11,7 +11,7 @@ use fyrox::{
uuid::Uuid, uuid_provider, visitor::prelude::*,
},
engine::SerializationContext,
graph::SceneGraph,
graph::BaseSceneGraph,
gui::{
button::{ButtonBuilder, ButtonMessage},
define_constructor,
@@ -1,5 +1,5 @@
use crate::inspector::editors::spritesheet::SpriteSheetFramesPropertyEditorMessage;
use fyrox::graph::SceneGraph;
use fyrox::graph::BaseSceneGraph;
use fyrox::{
core::{
algebra::Vector2, color::Color, parking_lot::Mutex, pool::Handle, reflect::prelude::*,
+1 -1
View File
@@ -1,5 +1,5 @@
use crate::{asset::item::AssetItem, inspector::EditorEnvironment};
use fyrox::graph::SceneGraph;
use fyrox::graph::BaseSceneGraph;
use fyrox::{
asset::manager::ResourceManager,
asset::untyped::UntypedResource,
+1 -1
View File
@@ -9,7 +9,7 @@ use crate::{
Brush, Engine, Message, Mode, WidgetMessage, WrapMode, MSG_SYNC_FLAG,
};
use fyrox::core::pool::ErasedHandle;
use fyrox::graph::SceneGraph;
use fyrox::graph::BaseSceneGraph;
use fyrox::{
asset::manager::ResourceManager,
core::{
+1 -1
View File
@@ -4,7 +4,7 @@ use crate::{
scene::{GameScene, Selection},
set_mesh_diffuse_color, Engine,
};
use fyrox::graph::SceneGraph;
use fyrox::graph::BaseSceneGraph;
use fyrox::{
core::{
algebra::{Matrix4, UnitQuaternion, Vector2, Vector3},
+1 -1
View File
@@ -2,7 +2,7 @@ use crate::{
make_color_material, scene::GameScene, set_mesh_diffuse_color,
world::graph::selection::GraphSelection, Engine,
};
use fyrox::graph::SceneGraph;
use fyrox::graph::BaseSceneGraph;
use fyrox::{
core::{
algebra::{Matrix4, UnitQuaternion, Vector2, Vector3},
+1 -1
View File
@@ -2,7 +2,7 @@ use crate::{
make_color_material, scene::GameScene, set_mesh_diffuse_color,
world::graph::selection::GraphSelection, Engine,
};
use fyrox::graph::SceneGraph;
use fyrox::graph::BaseSceneGraph;
use fyrox::{
core::{
algebra::{Matrix4, UnitQuaternion, Vector2, Vector3},
+1 -1
View File
@@ -18,7 +18,7 @@ use crate::{
};
use fyrox::core::uuid::{uuid, Uuid};
use fyrox::core::TypeUuidProvider;
use fyrox::graph::SceneGraph;
use fyrox::graph::BaseSceneGraph;
use fyrox::gui::{BuildContext, UiNode};
use fyrox::{
core::{
+1 -1
View File
@@ -10,7 +10,7 @@ use crate::{
};
use fyrox::core::uuid::{uuid, Uuid};
use fyrox::core::TypeUuidProvider;
use fyrox::graph::SceneGraph;
use fyrox::graph::BaseSceneGraph;
use fyrox::gui::BuildContext;
use fyrox::{
core::{algebra::Vector2, pool::Handle},
+1 -1
View File
@@ -14,7 +14,7 @@ use crate::{
};
use fyrox::core::uuid::{uuid, Uuid};
use fyrox::core::TypeUuidProvider;
use fyrox::graph::SceneGraph;
use fyrox::graph::BaseSceneGraph;
use fyrox::gui::{HorizontalAlignment, Thickness, VerticalAlignment};
use fyrox::{
core::{
+1 -1
View File
@@ -87,7 +87,7 @@ use crate::{
world::{graph::menu::SceneNodeContextMenu, graph::EditorSceneWrapper, WorldViewer},
};
use fyrox::dpi::LogicalSize;
use fyrox::graph::SceneGraph;
use fyrox::graph::BaseSceneGraph;
use fyrox::{
asset::{io::FsResourceIo, manager::ResourceManager, untyped::UntypedResource},
core::{
+1 -1
View File
@@ -2,7 +2,7 @@ use crate::{
gui::{make_dropdown_list_option, make_image_button_with_tooltip},
load_image, Brush, Color, DropdownListBuilder, Engine,
};
use fyrox::graph::SceneGraph;
use fyrox::graph::BaseSceneGraph;
use fyrox::{
core::{
log::{LogMessage, MessageKind},
+1 -1
View File
@@ -8,7 +8,7 @@ use crate::{
};
use fyrox::asset::manager::ResourceManager;
use fyrox::core::parking_lot::Mutex;
use fyrox::graph::SceneGraph;
use fyrox::graph::BaseSceneGraph;
use fyrox::{
core::{
algebra::{Matrix4, Vector2, Vector3, Vector4},
+1 -1
View File
@@ -3,7 +3,7 @@ use crate::{
message::MessageSender,
Message,
};
use fyrox::graph::SceneGraph;
use fyrox::graph::BaseSceneGraph;
use fyrox::{
core::pool::Handle,
gui::{
+1 -1
View File
@@ -5,7 +5,7 @@ use crate::{
scene::{GameScene, Selection},
Message,
};
use fyrox::graph::SceneGraph;
use fyrox::graph::{BaseSceneGraph, SceneGraph};
use fyrox::{
core::{algebra::Vector3, pool::Handle, reflect::Reflect},
engine::Engine,
+1 -1
View File
@@ -1,5 +1,5 @@
use crate::{load_image, Engine};
use fyrox::graph::SceneGraph;
use fyrox::graph::BaseSceneGraph;
use fyrox::scene::SceneRenderingOptions;
use fyrox::{
core::{
+1 -1
View File
@@ -3,7 +3,7 @@ use crate::{
command::CommandTrait, scene::commands::GameSceneContext, scene::Selection,
world::graph::selection::GraphSelection, Message,
};
use fyrox::graph::{LinkScheme, SceneGraph, SceneGraphNode};
use fyrox::graph::{BaseSceneGraph, LinkScheme, SceneGraphNode};
use fyrox::{
core::{
algebra::{UnitQuaternion, Vector3},
+1 -1
View File
@@ -12,7 +12,7 @@ use fyrox::{
asset::manager::ResourceManager,
core::{log::Log, pool::Handle, reflect::prelude::*, type_traits::prelude::*},
engine::SerializationContext,
graph::{SceneGraph, SceneGraphNode},
graph::{BaseSceneGraph, SceneGraphNode},
scene::{graph::SubGraph, node::Node, Scene},
};
use std::sync::Arc;
+1 -1
View File
@@ -7,7 +7,7 @@ use crate::{
},
Message,
};
use fyrox::graph::SceneGraph;
use fyrox::graph::BaseSceneGraph;
use fyrox::{
core::pool::Handle,
engine::Engine,
+1
View File
@@ -29,6 +29,7 @@ use crate::{
world::graph::selection::GraphSelection,
Message, Settings,
};
use fyrox::graph::BaseSceneGraph;
use fyrox::scene::sound::AudioBus;
use fyrox::{
core::{
+1 -1
View File
@@ -1,4 +1,4 @@
use fyrox::graph::SceneGraph;
use fyrox::graph::BaseSceneGraph;
use fyrox::{
core::{
algebra::Vector2, make_pretty_type_name, parking_lot::Mutex, pool::Handle,
+1 -1
View File
@@ -1,5 +1,5 @@
use crate::utils::make_node_name;
use fyrox::graph::SceneGraph;
use fyrox::graph::BaseSceneGraph;
use fyrox::{
core::{
algebra::Vector2, parking_lot::Mutex, pool::ErasedHandle, pool::Handle,
+1 -1
View File
@@ -9,7 +9,7 @@ use crate::{
BuildProfile, DropdownListBuilder, GameScene, Message, Mode, SaveSceneConfirmationDialogAction,
SceneContainer, Settings,
};
use fyrox::graph::SceneGraph;
use fyrox::graph::BaseSceneGraph;
use fyrox::{
core::{color::Color, math::Rect, pool::Handle, uuid::Uuid},
engine::Engine,
+1 -1
View File
@@ -1,6 +1,6 @@
use crate::ui_scene::selection::UiSelection;
use fyrox::core::pool::Handle;
use fyrox::graph::SceneGraph;
use fyrox::graph::BaseSceneGraph;
use fyrox::gui::{UiNode, UserInterface};
use std::collections::HashMap;
+1 -1
View File
@@ -7,7 +7,7 @@ use crate::{
ui_scene::{commands::UiSceneContext, UiSelection},
Message,
};
use fyrox::graph::{LinkScheme, SceneGraph, SceneGraphNode};
use fyrox::graph::{BaseSceneGraph, LinkScheme, SceneGraphNode};
use fyrox::{
core::pool::Handle,
gui::{SubGraph, UiNode, UserInterface},
+1 -1
View File
@@ -6,7 +6,7 @@ use crate::{
settings::Settings,
ui_scene::{UiScene, UiSelection},
};
use fyrox::graph::SceneGraph;
use fyrox::graph::BaseSceneGraph;
use fyrox::{
core::{
algebra::Vector2,
+1 -1
View File
@@ -12,7 +12,7 @@ use fyrox::{
TypeUuidProvider,
},
engine::Engine,
graph::SceneGraph,
graph::BaseSceneGraph,
gui::{BuildContext, UiNode},
};
+1 -1
View File
@@ -10,7 +10,7 @@ use crate::{
world::WorldViewerItemContextMenu,
Engine, Message, MessageDirection,
};
use fyrox::graph::{SceneGraph, SceneGraphNode};
use fyrox::graph::{BaseSceneGraph, SceneGraphNode};
use fyrox::{
core::pool::Handle,
gui::{
+1 -1
View File
@@ -37,7 +37,7 @@ use fyrox::{
},
engine::Engine,
fxhash::FxHashSet,
graph::{SceneGraph, SceneGraphNode},
graph::{BaseSceneGraph, SceneGraphNode},
gui::{
brush::Brush,
draw::{CommandTexture, Draw},
+1 -1
View File
@@ -5,7 +5,7 @@ use crate::{
};
use fyrox::{
core::pool::Handle,
graph::SceneGraph,
graph::BaseSceneGraph,
gui::{UiNode, UserInterface},
};
+2 -1
View File
@@ -9,13 +9,14 @@ use crate::{
},
world::{graph::item::DropAnchor, WorldViewerDataProvider},
};
use fyrox::graph::SceneGraphNode;
use fyrox::{
asset::{manager::ResourceManager, untyped::UntypedResource},
core::{
futures::executor::block_on, make_pretty_type_name, make_relative_path, pool::ErasedHandle,
pool::Handle, reflect::Reflect,
},
graph::{SceneGraph, SceneGraphNode},
graph::{BaseSceneGraph, SceneGraph},
gui::{
button::Button, canvas::Canvas, grid::Grid, screen::Screen, text::Text, UiNode,
UserInterface, UserInterfaceResourceExtension,
+1 -1
View File
@@ -1,4 +1,4 @@
use fyrox::graph::SceneGraph;
use fyrox::graph::BaseSceneGraph;
use fyrox::{
core::{algebra::Vector2, pool::ErasedHandle, pool::Handle, visitor::Visitor},
gui::{
+1 -1
View File
@@ -3,7 +3,7 @@
use crate::{make_scene_file_filter, Message};
use fyrox::asset::untyped::ResourceKind;
use fyrox::graph::SceneGraph;
use fyrox::graph::{BaseSceneGraph, SceneGraph};
use fyrox::{
asset::{manager::ResourceManager, untyped::UntypedResource},
core::{
+1 -1
View File
@@ -9,7 +9,7 @@ use crate::{
world::graph::selection::GraphSelection,
MSG_SYNC_FLAG,
};
use fyrox::graph::SceneGraph;
use fyrox::graph::{BaseSceneGraph, SceneGraph};
use fyrox::{
core::{
algebra::{UnitQuaternion, Vector3},
+1 -1
View File
@@ -1,6 +1,6 @@
use crate::{load_image, message::MessageSender, utils::make_node_name, Message};
use fyrox::core::color::Color;
use fyrox::graph::SceneGraph;
use fyrox::graph::BaseSceneGraph;
use fyrox::gui::draw::{CommandTexture, Draw};
use fyrox::{
asset::untyped::UntypedResource,
+1 -1
View File
@@ -16,7 +16,7 @@ use crate::{
world::WorldViewerItemContextMenu,
Engine, Message, MessageDirection, PasteCommand,
};
use fyrox::graph::SceneGraph;
use fyrox::graph::BaseSceneGraph;
use fyrox::{
asset::untyped::UntypedResource,
core::{algebra::Vector2, pool::Handle, reflect::Reflect, scope_profile},
+1 -1
View File
@@ -15,7 +15,7 @@ use crate::{
WorldViewerDataProvider,
},
};
use fyrox::graph::SceneGraphNode;
use fyrox::graph::{BaseSceneGraph, SceneGraphNode};
use fyrox::{
asset::{manager::ResourceManager, untyped::UntypedResource},
core::{
+1
View File
@@ -8,6 +8,7 @@ use crate::{
world::graph::item::{DropAnchor, SceneItem, SceneItemBuilder, SceneItemMessage},
Mode, Settings,
};
use fyrox::graph::BaseSceneGraph;
use fyrox::{
asset::untyped::UntypedResource,
core::{
+131 -124
View File
@@ -558,7 +558,7 @@ impl<N> Default for LinkScheme<N> {
}
}
pub trait SceneGraph: Sized + 'static {
pub trait BaseSceneGraph: 'static {
type Prefab: PrefabData<Graph = Self>;
type Node: SceneGraphNode<SceneGraph = Self, ResourceData = Self::Prefab>;
@@ -568,12 +568,11 @@ pub trait SceneGraph: Sized + 'static {
/// Sets the new root of the graph. If used incorrectly, it may create isolated sub-graphs.
fn set_root(&mut self, root: Handle<Self::Node>);
/// Creates new iterator that iterates over internal collection giving (handle; node) pairs.
fn pair_iter(&self) -> impl Iterator<Item = (Handle<Self::Node>, &Self::Node)>;
/// Tries to borrow a node, returns Some(node) if the handle is valid, None - otherwise.
fn try_get(&self, handle: Handle<Self::Node>) -> Option<&Self::Node>;
/// Creates an iterator that has linear iteration order over internal collection
/// of nodes. It does *not* perform any tree traversal!
fn linear_iter_mut(&mut self) -> impl Iterator<Item = &mut Self::Node>;
/// Tries to borrow a node, returns Some(node) if the handle is valid, None - otherwise.
fn try_get_mut(&mut self, handle: Handle<Self::Node>) -> Option<&mut Self::Node>;
/// Checks whether the given node handle is valid or not.
fn is_valid_handle(&self, handle: Handle<Self::Node>) -> bool;
@@ -594,12 +593,6 @@ pub trait SceneGraph: Sized + 'static {
/// graph.
fn isolate_node(&mut self, node_handle: Handle<Self::Node>);
/// Tries to borrow a node, returns Some(node) if the handle is valid, None - otherwise.
fn try_get(&self, handle: Handle<Self::Node>) -> Option<&Self::Node>;
/// Tries to borrow a node, returns Some(node) if the handle is valid, None - otherwise.
fn try_get_mut(&mut self, handle: Handle<Self::Node>) -> Option<&mut Self::Node>;
/// Borrows a node by its handle.
fn node(&self, handle: Handle<Self::Node>) -> &Self::Node {
self.try_get(handle).expect("The handle must be valid!")
@@ -610,6 +603,117 @@ pub trait SceneGraph: Sized + 'static {
self.try_get_mut(handle).expect("The handle must be valid!")
}
/// Reorders the node hierarchy so the `new_root` becomes the root node for the entire hierarchy
/// under the `prev_root` node. For example, if we have this hierarchy and want to set `C` as
/// the new root:
///
/// ```text
/// Root_
/// |_A_
/// |_B
/// |_C_
/// |_D
/// ```
///
/// The new hierarchy will become:
///
/// ```text
/// C_
/// |_D
/// |_A_
/// | |_B
/// |_Root
/// ```
///
/// This method returns an instance of [`LinkScheme`], that could be used to revert the hierarchy
/// back to its original. See [`Self::apply_link_scheme`] for more info.
#[inline]
#[allow(clippy::unnecessary_to_owned)] // False-positive
fn change_hierarchy_root(
&mut self,
prev_root: Handle<Self::Node>,
new_root: Handle<Self::Node>,
) -> LinkScheme<Self::Node> {
let mut scheme = LinkScheme::default();
if prev_root == new_root {
return scheme;
}
scheme
.links
.push((prev_root, self.node(prev_root).parent()));
scheme.links.push((new_root, self.node(new_root).parent()));
self.isolate_node(new_root);
for prev_root_child in self.node(prev_root).children().to_vec() {
self.link_nodes(prev_root_child, new_root);
scheme.links.push((prev_root_child, prev_root));
}
self.link_nodes(prev_root, new_root);
if prev_root == self.root() {
self.set_root(new_root);
scheme.root = prev_root;
} else {
scheme.root = self.root();
}
scheme
}
/// Applies the given link scheme to the graph, basically reverting graph structure to the one
/// that was before the call of [`Self::change_hierarchy_root`].
#[inline]
fn apply_link_scheme(&mut self, mut scheme: LinkScheme<Self::Node>) {
for (child, parent) in scheme.links.drain(..) {
if parent.is_some() {
self.link_nodes(child, parent);
} else {
self.isolate_node(child);
}
}
if scheme.root.is_some() {
self.set_root(scheme.root);
}
}
/// Create a graph depth traversal iterator.
#[inline]
fn traverse_iter(
&self,
from: Handle<Self::Node>,
) -> GraphTraverseIterator<'_, Self, Self::Node> {
GraphTraverseIterator {
graph: self,
stack: vec![from],
}
}
/// Create a graph depth traversal iterator.
#[inline]
fn traverse_handle_iter(
&self,
from: Handle<Self::Node>,
) -> GraphHandleTraverseIterator<'_, Self, Self::Node> {
GraphHandleTraverseIterator {
graph: self,
stack: vec![from],
}
}
}
pub trait SceneGraph: BaseSceneGraph {
/// Creates new iterator that iterates over internal collection giving (handle; node) pairs.
fn pair_iter(&self) -> impl Iterator<Item = (Handle<Self::Node>, &Self::Node)>;
/// Creates an iterator that has linear iteration order over internal collection
/// of nodes. It does *not* perform any tree traversal!
fn linear_iter_mut(&mut self) -> impl Iterator<Item = &mut Self::Node>;
/// Tries to borrow a node and fetch its component of specified type.
#[inline]
fn try_get_of_type<T>(&self, handle: Handle<Self::Node>) -> Option<&T>
@@ -800,84 +904,6 @@ pub trait SceneGraph: Sized + 'static {
})
}
/// Reorders the node hierarchy so the `new_root` becomes the root node for the entire hierarchy
/// under the `prev_root` node. For example, if we have this hierarchy and want to set `C` as
/// the new root:
///
/// ```text
/// Root_
/// |_A_
/// |_B
/// |_C_
/// |_D
/// ```
///
/// The new hierarchy will become:
///
/// ```text
/// C_
/// |_D
/// |_A_
/// | |_B
/// |_Root
/// ```
///
/// This method returns an instance of [`LinkScheme`], that could be used to revert the hierarchy
/// back to its original. See [`Self::apply_link_scheme`] for more info.
#[inline]
#[allow(clippy::unnecessary_to_owned)] // False-positive
fn change_hierarchy_root(
&mut self,
prev_root: Handle<Self::Node>,
new_root: Handle<Self::Node>,
) -> LinkScheme<Self::Node> {
let mut scheme = LinkScheme::default();
if prev_root == new_root {
return scheme;
}
scheme
.links
.push((prev_root, self.node(prev_root).parent()));
scheme.links.push((new_root, self.node(new_root).parent()));
self.isolate_node(new_root);
for prev_root_child in self.node(prev_root).children().to_vec() {
self.link_nodes(prev_root_child, new_root);
scheme.links.push((prev_root_child, prev_root));
}
self.link_nodes(prev_root, new_root);
if prev_root == self.root() {
self.set_root(new_root);
scheme.root = prev_root;
} else {
scheme.root = self.root();
}
scheme
}
/// Applies the given link scheme to the graph, basically reverting graph structure to the one
/// that was before the call of [`Self::change_hierarchy_root`].
#[inline]
fn apply_link_scheme(&mut self, mut scheme: LinkScheme<Self::Node>) {
for (child, parent) in scheme.links.drain(..) {
if parent.is_some() {
self.link_nodes(child, parent);
} else {
self.isolate_node(child);
}
}
if scheme.root.is_some() {
self.set_root(scheme.root);
}
}
/// The same as [`Self::find`], but only returns node handle which will be [`Handle::NONE`]
/// if nothing is found.
#[inline]
@@ -890,27 +916,6 @@ pub trait SceneGraph: Sized + 'static {
.unwrap_or_default()
}
/// Create a graph depth traversal iterator.
#[inline]
fn traverse_iter(&self, from: Handle<Self::Node>) -> impl Iterator<Item = &Self::Node> {
GraphTraverseIterator {
graph: self,
stack: vec![from],
}
}
/// Create a graph depth traversal iterator.
#[inline]
fn traverse_handle_iter(
&self,
from: Handle<Self::Node>,
) -> impl Iterator<Item = Handle<Self::Node>> {
GraphHandleTraverseIterator {
graph: self,
stack: vec![from],
}
}
/// Returns position of the node in its parent children list and the handle to the parent. Adds
/// given `offset` to the position. For example, if you have the following hierarchy:
///
@@ -1247,12 +1252,12 @@ pub trait SceneGraph: Sized + 'static {
}
/// Iterator that traverses tree in depth and returns shared references to nodes.
pub struct GraphTraverseIterator<'a, G, N> {
pub struct GraphTraverseIterator<'a, G: ?Sized, N> {
graph: &'a G,
stack: Vec<Handle<N>>,
}
impl<'a, G, N> Iterator for GraphTraverseIterator<'a, G, N>
impl<'a, G: ?Sized, N> Iterator for GraphTraverseIterator<'a, G, N>
where
G: SceneGraph<Node = N>,
N: SceneGraphNode,
@@ -1276,7 +1281,7 @@ where
}
/// Iterator that traverses tree in depth and returns handles to nodes.
pub struct GraphHandleTraverseIterator<'a, G, N> {
pub struct GraphHandleTraverseIterator<'a, G: ?Sized, N> {
graph: &'a G,
stack: Vec<Handle<N>>,
}
@@ -1303,7 +1308,7 @@ where
#[cfg(test)]
mod test {
use crate::{NodeMapping, PrefabData, SceneGraph, SceneGraphNode};
use crate::{BaseSceneGraph, NodeMapping, PrefabData, SceneGraph, SceneGraphNode};
use fyrox_core::{
pool::{Handle, Pool},
reflect::prelude::*,
@@ -1458,7 +1463,7 @@ mod test {
}
}
impl SceneGraph for Graph {
impl BaseSceneGraph for Graph {
type Prefab = Graph;
type Node = Node;
@@ -1470,14 +1475,6 @@ mod test {
self.root = root;
}
fn pair_iter(&self) -> impl Iterator<Item = (Handle<Self::Node>, &Self::Node)> {
self.nodes.pair_iter()
}
fn linear_iter_mut(&mut self) -> impl Iterator<Item = &mut Self::Node> {
self.nodes.iter_mut()
}
fn is_valid_handle(&self, handle: Handle<Self::Node>) -> bool {
self.nodes.is_valid_handle(handle)
}
@@ -1542,6 +1539,16 @@ mod test {
}
}
impl SceneGraph for Graph {
fn pair_iter(&self) -> impl Iterator<Item = (Handle<Self::Node>, &Self::Node)> {
self.nodes.pair_iter()
}
fn linear_iter_mut(&mut self) -> impl Iterator<Item = &mut Self::Node> {
self.nodes.iter_mut()
}
}
#[test]
fn test_set_child_position() {
let mut graph = Graph::default();
+1 -1
View File
@@ -16,7 +16,7 @@ use crate::{
widget::{Widget, WidgetBuilder},
BuildContext, Control, UiNode, UserInterface,
};
use fyrox_graph::SceneGraph;
use fyrox_graph::BaseSceneGraph;
use std::ops::{Deref, DerefMut};
/// UI-specific animation.
+1 -1
View File
@@ -19,7 +19,7 @@ use crate::{
BuildContext, Control, MessageDirection, MouseButton, Orientation, Thickness, UiNode,
UserInterface, WidgetMessage,
};
use fyrox_graph::SceneGraph;
use fyrox_graph::BaseSceneGraph;
use std::{
fmt::Debug,
mem,
+1 -1
View File
@@ -5,7 +5,7 @@ use crate::{
core::pool::Handle, font::FontResource, message::UiMessage, RestrictionEntry, UiNode,
UserInterface,
};
use fyrox_graph::SceneGraph;
use fyrox_graph::BaseSceneGraph;
use std::{
ops::{Index, IndexMut},
sync::mpsc::Sender,
+1 -1
View File
@@ -21,7 +21,7 @@ use crate::{
widget::{Widget, WidgetBuilder, WidgetMessage},
BuildContext, Control, RcUiNodeHandle, UiNode, UserInterface,
};
use fyrox_graph::SceneGraph;
use fyrox_graph::BaseSceneGraph;
use std::{
cell::Cell,
ops::{Deref, DerefMut},
+1 -1
View File
@@ -21,7 +21,7 @@ use crate::{
BuildContext, Control, Orientation, Thickness, UiNode, UserInterface, VerticalAlignment,
};
use fyrox_core::uuid_provider;
use fyrox_graph::SceneGraph;
use fyrox_graph::BaseSceneGraph;
use std::{
ops::{Deref, DerefMut},
sync::mpsc::Sender,
+1 -1
View File
@@ -83,7 +83,7 @@ pub trait Control:
/// # ops::{Deref, DerefMut},
/// # };
/// # use fyrox_core::uuid_provider;
/// # use fyrox_graph::SceneGraph;
/// # use fyrox_graph::BaseSceneGraph;
/// #
/// #[derive(Clone, Visit, Reflect, Debug, ComponentProvider)]
/// struct MyWidget {
+1 -1
View File
@@ -26,7 +26,7 @@ use crate::{
};
use fxhash::FxHashSet;
use fyrox_core::uuid_provider;
use fyrox_graph::SceneGraph;
use fyrox_graph::BaseSceneGraph;
use std::sync::mpsc::Sender;
use std::{
cell::{Cell, RefCell},
+1 -1
View File
@@ -6,7 +6,7 @@ use crate::{
window::WindowMessage,
Orientation, UiNode, UserInterface,
};
use fyrox_graph::SceneGraph;
use fyrox_graph::{BaseSceneGraph, SceneGraph};
use serde::{Deserialize, Serialize};
#[derive(Debug, PartialEq, Clone, Default, Serialize, Deserialize)]
+1 -1
View File
@@ -7,7 +7,7 @@
use crate::core::{reflect::prelude::*, type_traits::prelude::*, visitor::prelude::*};
use fyrox_core::uuid_provider;
use fyrox_graph::SceneGraph;
use fyrox_graph::{BaseSceneGraph, SceneGraph};
use std::{
cell::RefCell,
ops::{Deref, DerefMut},
+1 -1
View File
@@ -12,7 +12,7 @@ use crate::{
BuildContext, Control, Thickness, UiNode, UserInterface,
};
use fyrox_core::uuid_provider;
use fyrox_graph::SceneGraph;
use fyrox_graph::{BaseSceneGraph, SceneGraph};
use std::{
cell::Cell,
ops::{Deref, DerefMut},
+1 -1
View File
@@ -16,7 +16,7 @@ use crate::{
};
use fyrox_core::uuid_provider;
use fyrox_core::variable::InheritableVariable;
use fyrox_graph::SceneGraph;
use fyrox_graph::BaseSceneGraph;
use std::{
ops::{Deref, DerefMut},
sync::mpsc::Sender,
+1 -1
View File
@@ -18,7 +18,7 @@ use crate::{
BuildContext, Control, HorizontalAlignment, Orientation, Thickness, UiNode, UserInterface,
};
use fyrox_core::uuid_provider;
use fyrox_graph::SceneGraph;
use fyrox_graph::BaseSceneGraph;
use std::{
cell::{Cell, RefCell},
ops::{Deref, DerefMut},
+1 -1
View File
@@ -37,7 +37,7 @@ mod selector;
use fyrox_core::parking_lot::Mutex;
use fyrox_core::uuid_provider;
use fyrox_graph::SceneGraph;
use fyrox_graph::BaseSceneGraph;
use notify::Watcher;
pub use selector::*;
#[cfg(not(target_arch = "wasm32"))]
+1 -1
View File
@@ -18,7 +18,7 @@ use crate::{
VerticalAlignment,
};
use fyrox_core::uuid_provider;
use fyrox_graph::SceneGraph;
use fyrox_graph::BaseSceneGraph;
use std::{
ops::{Deref, DerefMut},
path::{Path, PathBuf},
+1 -1
View File
@@ -13,7 +13,7 @@ use crate::{
widget::{Widget, WidgetBuilder},
BuildContext, Control, UiNode, UserInterface,
};
use fyrox_graph::SceneGraph;
use fyrox_graph::BaseSceneGraph;
use std::{
cell::RefCell,
ops::{Deref, DerefMut},
+1 -1
View File
@@ -19,7 +19,7 @@ use crate::{
widget::{Widget, WidgetBuilder},
BuildContext, Control, Thickness, UiNode, UserInterface,
};
use fyrox_graph::SceneGraph;
use fyrox_graph::BaseSceneGraph;
use std::sync::Arc;
use std::{
any::TypeId,
+1 -1
View File
@@ -26,7 +26,7 @@ use crate::{
BuildContext, Control, HorizontalAlignment, Thickness, UiNode, UserInterface,
VerticalAlignment,
};
use fyrox_graph::SceneGraph;
use fyrox_graph::BaseSceneGraph;
use std::{
any::TypeId,
fmt::Debug,
@@ -28,7 +28,7 @@ use crate::{
VerticalAlignment,
};
use fyrox_core::ComponentProvider;
use fyrox_graph::SceneGraph;
use fyrox_graph::BaseSceneGraph;
use std::{
any::TypeId,
fmt::{Debug, Formatter},
+1 -1
View File
@@ -23,7 +23,7 @@ use crate::{
BuildContext, Control, MessageDirection, Thickness, UiNode, UserInterface, VerticalAlignment,
Widget, WidgetMessage,
};
use fyrox_graph::SceneGraph;
use fyrox_graph::BaseSceneGraph;
use std::{
any::TypeId,
fmt::{Debug, Formatter},
@@ -13,7 +13,7 @@ use crate::{
};
use fyrox_core::pool::Handle;
use fyrox_core::PhantomDataSendSync;
use fyrox_graph::SceneGraph;
use fyrox_graph::BaseSceneGraph;
use std::{
any::TypeId,
fmt::{Debug, Formatter},
+1 -1
View File
@@ -32,7 +32,7 @@ use crate::{
};
use copypasta::ClipboardProvider;
use fyrox_core::uuid_provider;
use fyrox_graph::SceneGraph;
use fyrox_graph::BaseSceneGraph;
use std::sync::Arc;
use std::{
any::{Any, TypeId},
+15 -11
View File
@@ -293,7 +293,9 @@ pub use build::*;
pub use control::*;
use fyrox_core::futures::future::join_all;
use fyrox_core::log::Log;
use fyrox_graph::{NodeHandleMap, NodeMapping, PrefabData, SceneGraph, SceneGraphNode};
use fyrox_graph::{
BaseSceneGraph, NodeHandleMap, NodeMapping, PrefabData, SceneGraph, SceneGraphNode,
};
pub use node::*;
pub use thickness::*;
@@ -2800,7 +2802,7 @@ impl PrefabData for UserInterface {
}
}
impl SceneGraph for UserInterface {
impl BaseSceneGraph for UserInterface {
type Prefab = Self;
type Node = UiNode;
@@ -2815,13 +2817,13 @@ impl SceneGraph for UserInterface {
}
#[inline]
fn pair_iter(&self) -> impl Iterator<Item = (Handle<Self::Node>, &Self::Node)> {
self.nodes.pair_iter()
fn try_get(&self, handle: Handle<Self::Node>) -> Option<&Self::Node> {
self.nodes.try_borrow(handle)
}
#[inline]
fn linear_iter_mut(&mut self) -> impl Iterator<Item = &mut Self::Node> {
self.nodes.iter_mut()
fn try_get_mut(&mut self, handle: Handle<Self::Node>) -> Option<&mut Self::Node> {
self.nodes.try_borrow_mut(handle)
}
#[inline]
@@ -2906,15 +2908,17 @@ impl SceneGraph for UserInterface {
self.nodes[parent_handle].remove_child(node_handle);
}
}
}
impl SceneGraph for UserInterface {
#[inline]
fn try_get(&self, handle: Handle<Self::Node>) -> Option<&Self::Node> {
self.nodes.try_borrow(handle)
fn pair_iter(&self) -> impl Iterator<Item = (Handle<Self::Node>, &Self::Node)> {
self.nodes.pair_iter()
}
#[inline]
fn try_get_mut(&mut self, handle: Handle<Self::Node>) -> Option<&mut Self::Node> {
self.nodes.try_borrow_mut(handle)
fn linear_iter_mut(&mut self) -> impl Iterator<Item = &mut Self::Node> {
self.nodes.iter_mut()
}
}
@@ -3163,7 +3167,7 @@ mod test {
widget::{WidgetBuilder, WidgetMessage},
OsEvent, UserInterface,
};
use fyrox_graph::SceneGraph;
use fyrox_graph::BaseSceneGraph;
#[test]
fn test_transform_size() {
+1 -1
View File
@@ -21,7 +21,7 @@ use crate::{
};
use fyrox_core::uuid_provider;
use fyrox_core::variable::InheritableVariable;
use fyrox_graph::SceneGraph;
use fyrox_graph::BaseSceneGraph;
use std::ops::{Deref, DerefMut};
/// A set of messages that can be used to modify/fetch the state of a [`ListView`] widget at runtime.
+1 -1
View File
@@ -24,7 +24,7 @@ use crate::{
UserInterface, VerticalAlignment, BRUSH_BRIGHT, BRUSH_BRIGHT_BLUE, BRUSH_PRIMARY,
};
use fyrox_core::variable::InheritableVariable;
use fyrox_graph::SceneGraph;
use fyrox_graph::{BaseSceneGraph, SceneGraph};
use std::{
ops::{Deref, DerefMut},
sync::mpsc::Sender,
+1 -1
View File
@@ -12,7 +12,7 @@ use crate::{
BuildContext, Control, UiNode, UserInterface,
};
use fyrox_core::variable::InheritableVariable;
use fyrox_graph::SceneGraph;
use fyrox_graph::BaseSceneGraph;
use fyrox_resource::untyped::UntypedResource;
use std::ops::{Deref, DerefMut};
+1 -1
View File
@@ -30,7 +30,7 @@ use crate::{
VerticalAlignment, BRUSH_DARK, BRUSH_LIGHT,
};
use fyrox_core::variable::InheritableVariable;
use fyrox_graph::SceneGraph;
use fyrox_graph::BaseSceneGraph;
use std::{
cmp::Ordering,
fmt::{Debug, Display},
+1 -1
View File
@@ -17,7 +17,7 @@ use crate::{
};
use fyrox_core::uuid_provider;
use fyrox_core::variable::InheritableVariable;
use fyrox_graph::SceneGraph;
use fyrox_graph::BaseSceneGraph;
use std::ops::{Deref, DerefMut};
/// A set of messages for [`Popup`] widget.
+1 -1
View File
@@ -24,7 +24,7 @@ use crate::{
};
use fyrox_core::uuid_provider;
use fyrox_core::variable::InheritableVariable;
use fyrox_graph::SceneGraph;
use fyrox_graph::BaseSceneGraph;
use std::ops::{Deref, DerefMut};
/// A set of messages that can be accepted by [`ScrollBar`] widget.
+1 -1
View File
@@ -17,7 +17,7 @@ use crate::{
BuildContext, Control, UiNode, UserInterface,
};
use fyrox_core::uuid_provider;
use fyrox_graph::SceneGraph;
use fyrox_graph::BaseSceneGraph;
use std::ops::{Deref, DerefMut};
/// A set of messages, that is used to modify the state of a scroll panel.
+1 -1
View File
@@ -18,7 +18,7 @@ use crate::{
widget::{Widget, WidgetBuilder, WidgetMessage},
BuildContext, Control, Orientation, UiNode, UserInterface,
};
use fyrox_graph::SceneGraph;
use fyrox_graph::BaseSceneGraph;
use std::ops::{Deref, DerefMut};
/// A set of messages that could be used to alternate the state of a [`ScrollViewer`] widget.
+1 -1
View File
@@ -15,7 +15,7 @@ use crate::{
};
use fyrox_core::uuid_provider;
use fyrox_core::variable::InheritableVariable;
use fyrox_graph::SceneGraph;
use fyrox_graph::BaseSceneGraph;
use std::ops::{Deref, DerefMut};
/// A set of possible [`StackPanel`] widget messages.
+1 -1
View File
@@ -22,7 +22,7 @@ use crate::{
BRUSH_DARK, BRUSH_DARKEST,
};
use fyrox_core::uuid_provider;
use fyrox_graph::SceneGraph;
use fyrox_graph::{BaseSceneGraph, SceneGraph};
use std::ops::{Deref, DerefMut};
/// Opaque selection state of a tree.
+1 -1
View File
@@ -19,7 +19,7 @@ use crate::{
UserInterface, VerticalAlignment, BRUSH_FOREGROUND, BRUSH_PRIMARY,
};
use fyrox_core::{parking_lot::Mutex, variable::InheritableVariable};
use fyrox_graph::SceneGraph;
use fyrox_graph::BaseSceneGraph;
use fyrox_resource::Resource;
use std::{
any::Any,
+1 -1
View File
@@ -20,7 +20,7 @@ use crate::{
VerticalAlignment, BRUSH_BRIGHT, BRUSH_LIGHT, BRUSH_LIGHTEST,
};
use fyrox_core::uuid_provider;
use fyrox_graph::SceneGraph;
use fyrox_graph::BaseSceneGraph;
use std::{
cell::RefCell,
ops::{Deref, DerefMut},
+1 -1
View File
@@ -16,7 +16,7 @@ use crate::{
};
use fyrox_core::uuid_provider;
use fyrox_core::variable::InheritableVariable;
use fyrox_graph::SceneGraph;
use fyrox_graph::BaseSceneGraph;
use std::{
cell::RefCell,
ops::{Deref, DerefMut, Range},
+2 -2
View File
@@ -77,7 +77,7 @@ use crate::resource::texture;
use crate::scene::navmesh;
use crate::script::PluginsRefMut;
use fyrox_core::task::TaskPool;
use fyrox_graph::NodeMapping;
use fyrox_graph::{BaseSceneGraph, NodeMapping};
use fyrox_resource::Resource;
use fyrox_ui::font::BUILT_IN_FONT;
use fyrox_ui::loader::UserInterfaceLoader;
@@ -2278,7 +2278,7 @@ mod test {
};
use std::sync::Arc;
use crate::graph::SceneGraph;
use crate::graph::BaseSceneGraph;
use fyrox_ui::UserInterface;
use std::sync::mpsc::{self, Sender, TryRecvError};
+1
View File
@@ -22,6 +22,7 @@ use crate::{
};
use fxhash::{FxBuildHasher, FxHashMap, FxHasher};
use fyrox_graph::BaseSceneGraph;
use std::{
any::TypeId,
collections::hash_map::DefaultHasher,
+1 -1
View File
@@ -21,7 +21,7 @@ use crate::{
pool::Handle,
sstorage::ImmutableString,
},
graph::SceneGraph,
graph::BaseSceneGraph,
material::{shader::SamplerFallback, PropertyValue},
resource::{
fbx::{

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