Skip to content

Commit

Permalink
refactor hot reload to allow custom dynamic plugins besides dylib-based
Browse files Browse the repository at this point in the history
  • Loading branch information
kkolyan authored and Nikolay Plekhanov committed Oct 13, 2024
1 parent f0c6568 commit 89371e0
Show file tree
Hide file tree
Showing 4 changed files with 355 additions and 262 deletions.
22 changes: 15 additions & 7 deletions editor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ use crate::{
shader::{ShaderResource, ShaderResourceExtension},
Material, MaterialResource,
},
plugin::{Plugin, PluginContainer},
plugin::{Plugin, PluginContainer, AbstractDynamicPlugin, dynamic::DyLibPlugin},
resource::texture::{
CompressionOptions, TextureImportOptions, TextureKind, TextureMinificationFilter,
TextureResource, TextureResourceExtension,
Expand Down Expand Up @@ -2641,10 +2641,20 @@ impl Editor {
) -> Result<(), String>
where
P: AsRef<Path> + 'static,
{
self.add_dynamic_plugin_custom(DyLibPlugin::new(path, reload_when_changed, use_relative_paths)?)
}

pub fn add_dynamic_plugin_custom<P>(
&mut self,
plugin: P,
) -> Result<(), String>
where
P: AbstractDynamicPlugin + 'static,
{
let plugin =
self.engine
.add_dynamic_plugin(path, reload_when_changed, use_relative_paths)?;
.add_dynamic_plugin(plugin);
*self.inspector.property_editors.context_type_id.lock() = plugin.type_id();
self.inspector
.property_editors
Expand Down Expand Up @@ -2946,13 +2956,11 @@ fn update(editor: &mut Editor, window_target: &EventLoopWindowTarget<()>) {
for plugin_index in 0..editor.engine.plugins().len() {
let plugin = &editor.engine.plugins()[plugin_index];

if let PluginContainer::Dynamic {
need_reload, state, ..
} = plugin
if let PluginContainer::Dynamic(plugin) = plugin
{
let plugin_type_id = state.as_loaded_ref().plugin().type_id();
let plugin_type_id = plugin.as_loaded_ref().type_id();

if need_reload.load(Ordering::SeqCst) {
if plugin.is_reload_needed_now() {
// Clear command stacks for scenes. This is mandatory step, because command stack
// could contain objects from plugins and any attempt to use them after the plugin is
// unloaded will cause crash.
Expand Down
Loading

0 comments on commit 89371e0

Please sign in to comment.