mirror of
https://github.com/FyroxEngine/Fyrox.git
synced 2026-10-12 02:02:20 +00:00
plugin type enum
This commit is contained in:
@@ -91,6 +91,7 @@ use std::{
|
||||
time::Duration,
|
||||
};
|
||||
|
||||
use crate::plugin::PluginContainer;
|
||||
use winit::{
|
||||
dpi::{Position, Size},
|
||||
event_loop::EventLoopWindowTarget,
|
||||
@@ -422,7 +423,7 @@ pub struct Engine {
|
||||
sound_engine: SoundEngine,
|
||||
|
||||
// A set of plugins used by the engine.
|
||||
plugins: Vec<Box<dyn Plugin>>,
|
||||
plugins: Vec<PluginContainer>,
|
||||
|
||||
plugins_enabled: bool,
|
||||
|
||||
@@ -480,7 +481,7 @@ impl ScriptMessageDispatcher {
|
||||
&self,
|
||||
scene: &mut Scene,
|
||||
scene_handle: Handle<Scene>,
|
||||
plugins: &mut [Box<dyn Plugin>],
|
||||
plugins: &mut [PluginContainer],
|
||||
resource_manager: &ResourceManager,
|
||||
dt: f32,
|
||||
elapsed_time: f32,
|
||||
@@ -652,7 +653,7 @@ impl ScriptProcessor {
|
||||
fn handle_scripts(
|
||||
&mut self,
|
||||
scenes: &mut SceneContainer,
|
||||
plugins: &mut [Box<dyn Plugin>],
|
||||
plugins: &mut [PluginContainer],
|
||||
resource_manager: &ResourceManager,
|
||||
task_pool: &mut TaskPoolHandler,
|
||||
graphics_context: &mut GraphicsContext,
|
||||
@@ -1086,7 +1087,7 @@ where
|
||||
pub(crate) fn process_scripts<T>(
|
||||
scene: &mut Scene,
|
||||
scene_handle: Handle<Scene>,
|
||||
plugins: &mut [Box<dyn Plugin>],
|
||||
plugins: &mut [PluginContainer],
|
||||
resource_manager: &ResourceManager,
|
||||
message_sender: &ScriptMessageSender,
|
||||
message_dispatcher: &mut ScriptMessageDispatcher,
|
||||
@@ -2305,7 +2306,7 @@ impl Engine {
|
||||
resource_manager: &self.resource_manager,
|
||||
});
|
||||
|
||||
self.plugins.push(Box::new(plugin));
|
||||
self.plugins.push(PluginContainer::Static(Box::new(plugin)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
//! Asynchronous task handler. See [`TaskPoolHandler`] for more info and usage examples.
|
||||
|
||||
use crate::plugin::PluginContainer;
|
||||
use crate::{
|
||||
core::{
|
||||
pool::Handle,
|
||||
@@ -24,7 +25,7 @@ pub(crate) type NodeTaskHandlerClosure = Box<
|
||||
pub(crate) type PluginTaskHandler = Box<
|
||||
dyn for<'a, 'b> Fn(
|
||||
Box<dyn AsyncTaskResult>,
|
||||
&'a mut [Box<dyn Plugin>],
|
||||
&'a mut [PluginContainer],
|
||||
&mut PluginContext<'a, 'b>,
|
||||
),
|
||||
>;
|
||||
|
||||
@@ -7,8 +7,7 @@ use std::ffi::OsStr;
|
||||
/// it is strongly advised not to use it in production builds, because it is slower than statically
|
||||
/// linked plugins and it could be unsafe if different compiler versions are used.
|
||||
pub struct DynamicPlugin {
|
||||
/// Loaded plugin.
|
||||
pub plugin: Box<dyn Plugin>,
|
||||
pub(super) plugin: Box<dyn Plugin>,
|
||||
// Keep the library loaded.
|
||||
// Must be last!
|
||||
#[allow(dead_code)]
|
||||
|
||||
@@ -13,11 +13,45 @@ use crate::{
|
||||
},
|
||||
event::Event,
|
||||
gui::{message::UiMessage, UserInterface},
|
||||
plugin::dynamic::DynamicPlugin,
|
||||
scene::{Scene, SceneContainer},
|
||||
};
|
||||
use std::{any::Any, path::Path, sync::Arc};
|
||||
use std::{
|
||||
any::Any,
|
||||
ops::{Deref, DerefMut},
|
||||
path::Path,
|
||||
sync::Arc,
|
||||
};
|
||||
use winit::event_loop::EventLoopWindowTarget;
|
||||
|
||||
/// A wrapper for various plugin types.
|
||||
pub enum PluginContainer {
|
||||
/// Statically linked plugin.
|
||||
Static(Box<dyn Plugin>),
|
||||
/// Dynamically linked plugin.
|
||||
Dynamic(DynamicPlugin),
|
||||
}
|
||||
|
||||
impl Deref for PluginContainer {
|
||||
type Target = dyn Plugin;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
match self {
|
||||
PluginContainer::Static(plugin) => &**plugin,
|
||||
PluginContainer::Dynamic(dynamic) => &*dynamic.plugin,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl DerefMut for PluginContainer {
|
||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||
match self {
|
||||
PluginContainer::Static(plugin) => &mut **plugin,
|
||||
PluginContainer::Dynamic(dynamic) => &mut *dynamic.plugin,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Contains plugin environment for the registration stage.
|
||||
pub struct PluginRegistrationContext<'a> {
|
||||
/// A reference to serialization context of the engine. See [`SerializationContext`] for more
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
//! Script is used to add custom logic to scene nodes. See [ScriptTrait] for more info.
|
||||
|
||||
use crate::plugin::PluginContainer;
|
||||
use crate::scene::base::NodeScriptMessage;
|
||||
use crate::{
|
||||
asset::manager::ResourceManager,
|
||||
@@ -239,10 +240,10 @@ where
|
||||
|
||||
/// A simple wrapper for a reference to plugins container. It has some useful methods to fetch
|
||||
/// a plugin of certain type. See [`PluginsRefMut::of_type_ref`] and [`PluginsRefMut::of_type_mut`].
|
||||
pub struct PluginsRefMut<'a>(pub &'a mut [Box<dyn Plugin>]);
|
||||
pub struct PluginsRefMut<'a>(pub &'a mut [PluginContainer]);
|
||||
|
||||
impl<'a> Deref for PluginsRefMut<'a> {
|
||||
type Target = [Box<dyn Plugin>];
|
||||
type Target = [PluginContainer];
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
self.0
|
||||
|
||||
Reference in New Issue
Block a user