pub trait Plugin {
// Required methods
fn prepare(
&mut self,
dependencies: HashMap<String, &AtomicRefCell<Box<dyn Resource>>>,
) -> Result<()>;
fn update(&mut self, delta_time: f64) -> Result<()>;
fn resource_dependencies(&mut self) -> HashMap<String, ResourceId>;
fn name(&self) -> &'static str;
}Expand description
A trait that all plugins must implement in order to be inserted into App
§Example
use specs::World;
use fennel_plugins::Plugin;
struct MyCoolPlugin;
impl Plugin for MyCoolPlugin {
fn prepare(&mut self, _world: *mut World) -> anyhow::Result<()> {
// initialize your plugin here
Ok(())
}
fn update(&mut self, delta_time: f64) -> anyhow::Result<()> {
// update your plugin state
Ok(())
}
fn name(&self) -> &'static str {
"my_cool_plugin"
}
}Required Methods§
Sourcefn prepare(
&mut self,
dependencies: HashMap<String, &AtomicRefCell<Box<dyn Resource>>>,
) -> Result<()>
fn prepare( &mut self, dependencies: HashMap<String, &AtomicRefCell<Box<dyn Resource>>>, ) -> Result<()>
Prepare/initialize the plugin, return a result of this
Sourcefn update(&mut self, delta_time: f64) -> Result<()>
fn update(&mut self, delta_time: f64) -> Result<()>
Update the plugin state, return a result of this
Sourcefn resource_dependencies(&mut self) -> HashMap<String, ResourceId>
fn resource_dependencies(&mut self) -> HashMap<String, ResourceId>
Return a list of your resource dependencies here or an empty Vec if you don’t need any resources.
Use the ResourceId::new function to acquire a ResourceId instance.
Usually you want the dependency to be an [Arc], [Rc] or some sort of channel receiver/sender,
as under the hood fennel_engine clones the resource.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".