diff --git a/editor/src/inspector/editors/script.rs b/editor/src/inspector/editors/script.rs index 698de3aa1..2ffe5d1c9 100644 --- a/editor/src/inspector/editors/script.rs +++ b/editor/src/inspector/editors/script.rs @@ -272,7 +272,7 @@ fn create_items( ctx[item].user_data = Some(Arc::new(Mutex::new(( *type_uuid, - Some(constructor.source_path.clone()), + Some(constructor.source_path.to_string()), )))); item diff --git a/fyrox-impl/src/engine/mod.rs b/fyrox-impl/src/engine/mod.rs index 40b51a41b..188309bcb 100644 --- a/fyrox-impl/src/engine/mod.rs +++ b/fyrox-impl/src/engine/mod.rs @@ -2450,14 +2450,6 @@ impl Engine { resource_manager: &ResourceManager, plugin: &dyn Plugin, ) { - *serialization_context - .script_constructors - .context_type_id - .lock() = plugin.type_id(); - *serialization_context - .node_constructors - .context_type_id - .lock() = plugin.type_id(); *widget_constructors.context_type_id.lock() = plugin.type_id(); plugin.register(PluginRegistrationContext { serialization_context, @@ -2594,7 +2586,6 @@ impl Engine { script: &Script, plugin: &dyn Plugin, ) -> bool { - let plugin_type_id = plugin.type_id(); let script_id = script.deref().id(); if let Some(constructor) = serialization_context @@ -2602,7 +2593,7 @@ impl Engine { .map() .get(&script_id) { - if constructor.source_type_id == plugin_type_id { + if constructor.assembly_name == plugin.assembly_name() { return true; } } @@ -2614,11 +2605,10 @@ impl Engine { node: &Node, plugin: &dyn Plugin, ) -> bool { - let plugin_type_id = plugin.type_id(); let node_id = (*node).id(); if let Some(constructor) = serialization_context.node_constructors.map().get(&node_id) { - if constructor.source_type_id == plugin_type_id { + if constructor.assembly_name == plugin.assembly_name() { return true; } } @@ -2674,6 +2664,7 @@ impl Engine { } let plugin_type_id = state.as_loaded_ref().plugin().type_id(); + let plugin_assembly_name = state.as_loaded_ref().plugin().assembly_name(); // Collect all the data that belongs to the plugin struct ScriptState { @@ -2770,7 +2761,7 @@ impl Engine { let mut constructors = FxHashSet::default(); for (type_uuid, constructor) in self.serialization_context.script_constructors.map().iter() { - if constructor.source_type_id == plugin_type_id { + if constructor.assembly_name == plugin_assembly_name { constructors.insert(*type_uuid); } } @@ -2783,7 +2774,7 @@ impl Engine { // Search for node constructors, that belongs to dynamic plugins and remove them. let mut constructors = FxHashSet::default(); for (type_uuid, constructor) in self.serialization_context.node_constructors.map().iter() { - if constructor.source_type_id == plugin_type_id { + if constructor.assembly_name == plugin_assembly_name { constructors.insert(*type_uuid); } } @@ -2796,7 +2787,7 @@ impl Engine { // Search for widget constructors, that belongs to dynamic plugins and remove them. let mut constructors = FxHashSet::default(); for (type_uuid, constructor) in self.widget_constructors.map().iter() { - if constructor.source_type_id == plugin_type_id { + if constructor.assembly_name == plugin_assembly_name { constructors.insert(*type_uuid); } } diff --git a/fyrox-impl/src/scene/node/constructor.rs b/fyrox-impl/src/scene/node/constructor.rs index a66a8468a..9a7217182 100644 --- a/fyrox-impl/src/scene/node/constructor.rs +++ b/fyrox-impl/src/scene/node/constructor.rs @@ -25,28 +25,25 @@ use crate::{ }, }; use fxhash::FxHashMap; -use std::any::{Any, TypeId}; /// Node constructor. pub struct NodeConstructor { /// A simple type alias for boxed node constructor. closure: Box Node + Send>, - /// A type of the source of the script constructor. - pub source_type_id: TypeId, + /// A name of the assembly this node constructor is from. + pub assembly_name: &'static str, } /// A special container that is able to create nodes by their type UUID. pub struct NodeConstructorContainer { - pub(crate) context_type_id: Mutex, map: Mutex>, } impl Default for NodeConstructorContainer { fn default() -> Self { Self { - context_type_id: Mutex::new(().type_id()), map: Default::default(), } } @@ -94,7 +91,7 @@ impl NodeConstructorContainer { T::type_uuid(), NodeConstructor { closure: Box::new(|| Node::new(T::default())), - source_type_id: *self.context_type_id.lock(), + assembly_name: T::type_assembly_name(), }, ); diff --git a/fyrox-impl/src/scene/node/mod.rs b/fyrox-impl/src/scene/node/mod.rs index 81423b270..a69e30da3 100644 --- a/fyrox-impl/src/scene/node/mod.rs +++ b/fyrox-impl/src/scene/node/mod.rs @@ -781,7 +781,7 @@ mod test { .script_constructors .map() .iter() - .any(|s| &s.1.source_path == file!())); + .any(|s| s.1.source_path == file!())); engine::initialize_resource_manager_loaders( &resource_manager, diff --git a/fyrox-impl/src/script/constructor.rs b/fyrox-impl/src/script/constructor.rs index 9afb8c27a..99ad8f35f 100644 --- a/fyrox-impl/src/script/constructor.rs +++ b/fyrox-impl/src/script/constructor.rs @@ -8,7 +8,6 @@ use crate::{ }, script::{Script, ScriptTrait}, }; -use std::any::{Any, TypeId}; use std::collections::BTreeMap; /// Script constructor contains all required data and methods to create script instances @@ -21,15 +20,14 @@ pub struct ScriptConstructor { pub name: String, /// Script source path. - pub source_path: String, + pub source_path: &'static str, - /// A type of the source of the script constructor. - pub source_type_id: TypeId, + /// A name of the assembly this script constructor belongs to. + pub assembly_name: &'static str, } /// A special container that is able to create nodes by their type UUID. pub struct ScriptConstructorContainer { - pub(crate) context_type_id: Mutex, // BTreeMap allows to have sorted list of constructors. map: Mutex>, } @@ -37,7 +35,6 @@ pub struct ScriptConstructorContainer { impl Default for ScriptConstructorContainer { fn default() -> Self { Self { - context_type_id: Mutex::new(().type_id()), map: Default::default(), } } @@ -63,8 +60,8 @@ impl ScriptConstructorContainer { ScriptConstructor { constructor: Box::new(|| Script::new(T::default())), name: name.to_owned(), - source_path: T::source_path().to_owned(), - source_type_id: *self.context_type_id.lock(), + source_path: T::source_path(), + assembly_name: T::type_assembly_name(), }, ); diff --git a/fyrox-ui/src/node/constructor.rs b/fyrox-ui/src/node/constructor.rs index 6f28857ce..9d32d64d4 100644 --- a/fyrox-ui/src/node/constructor.rs +++ b/fyrox-ui/src/node/constructor.rs @@ -57,8 +57,8 @@ pub struct WidgetConstructor { /// A simple type alias for boxed widget constructor. closure: Box UiNode + Send>, - /// A type of the source of the script constructor. - pub source_type_id: TypeId, + /// A name of the assembly this widget constructor belongs to. + pub assembly_name: &'static str, } /// A special container that is able to create widgets by their type UUID. @@ -233,7 +233,7 @@ impl WidgetConstructorContainer { T::type_uuid(), WidgetConstructor { closure: Box::new(|| UiNode::new(T::default())), - source_type_id: *self.context_type_id.lock(), + assembly_name: T::type_assembly_name(), }, );