Skip to content

Commit

Permalink
reload resources that belongs to plugins when hot reloading
Browse files Browse the repository at this point in the history
  • Loading branch information
mrDIMAS committed May 15, 2024
1 parent 3b6eecb commit d298976
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions fyrox-impl/src/engine/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,12 @@ use crate::plugin::dynamic::DynamicPlugin;
use crate::plugin::{DynamicPluginState, PluginContainer};
use crate::scene::base::visit_opt_script;
use crate::scene::node::container::NodeContainer;
use fyrox_core::futures::future::join_all;
use fyrox_core::notify;
use fyrox_core::notify::{EventKind, RecursiveMode, Watcher};
use fyrox_core::pool::{PayloadContainer, Ticket};
use fyrox_core::visitor::{Visit, Visitor, VisitorFlags};
use fyrox_resource::state::ResourceState;
use fyrox_ui::constructor::WidgetConstructorContainer;
use fyrox_ui::UiContainer;
use winit::{
Expand Down Expand Up @@ -2795,6 +2797,35 @@ impl Engine {
self.widget_constructors.remove(*type_uuid);
}

// Reload resources, that belongs to the plugin.
{
let mut resources_to_reload = FxHashSet::default();
let mut state = self.resource_manager.state();
for resource in state.resources().iter() {
let data = resource.0.lock();
if let ResourceState::Ok(ref data) = data.state {
data.as_reflect(&mut |reflect| {
if reflect.assembly_name() == plugin_assembly_name {
resources_to_reload.insert(resource.clone());
}
})
}
}

for resource_to_reload in resources_to_reload.iter() {
Log::info(format!(
"Reloading {} resource, because it is used in plugin {plugin_assembly_name}",
resource_to_reload.kind()
));

state.reload_resource(resource_to_reload.clone());
}

drop(state);

block_on(join_all(resources_to_reload));
}

// Unload custom render passes (if any).
if let GraphicsContext::Initialized(ref mut graphics_context) = self.graphics_context {
let render_passes = graphics_context.renderer.render_passes().to_vec();
Expand Down

0 comments on commit d298976

Please sign in to comment.