pub struct AsyncSceneLoader { /* private fields */ }Expand description
A helper that is used to load scenes asynchronously.
§Examples
use fyrox_impl::{
core::{color::Color, visitor::prelude::*, reflect::prelude::*, log::Log, pool::Handle},
plugin::{Plugin, PluginContext},
scene::Scene,
};
use std::path::Path;
#[derive(Visit, Reflect, Debug)]
struct MyGame {
scene: Handle<Scene>,
}
impl MyGame {
pub fn new(scene_path: Option<&str>, context: PluginContext) -> Self {
context
.async_scene_loader
.request(scene_path.unwrap_or("data/scene.rgs"));
Self {
scene: Handle::NONE,
}
}
}
impl Plugin for MyGame {
fn on_scene_begin_loading(&mut self, path: &Path, _context: &mut PluginContext) {
Log::info(format!("{} scene has started loading.", path.display()));
// Use this method if you need to so something when a scene started loading.
}
fn on_scene_loaded(
&mut self,
path: &Path,
scene: Handle<Scene>,
data: &[u8],
context: &mut PluginContext,
) {
// Optionally remove previous scene.
if self.scene.is_some() {
context.scenes.remove(self.scene);
}
// Remember new scene handle.
self.scene = scene;
Log::info(format!("{} scene was loaded!", path.display()));
// Do something with a newly loaded scene.
let scene_ref = &mut context.scenes[scene];
scene_ref.rendering_options.ambient_lighting_color = Color::opaque(20, 20, 20);
}
}This example shows a typical usage of the loader, an instance of which is available in the
plugin context. Game::new requests a new scene, which internally asks a resource manager to
load the scene. Then, when the scene is fully loaded, the engine calls Plugin::on_scene_loaded
method which allows you to do something with the newly loaded scene by taking a reference of it.
Implementations§
Source§impl AsyncSceneLoader
impl AsyncSceneLoader
Sourcepub fn request<P: AsRef<Path>>(&mut self, path: P)
pub fn request<P: AsRef<Path>>(&mut self, path: P)
Requests a scene for loading as derived scene. See AsyncSceneLoader for usage example.
§Raw vs Derived Scene
Derived scene means its nodes will derive their properties from the nodes from the source
scene. Derived scene is useful for saved games - you can serialize your scene as usual and
it will only contain a “difference” between the original scene and yours. To load the same
scene as raw scene use Self::request_raw method.
Raw scene, on other hand, loads the scene as-is without any additional markings for the scene nodes. It could be useful to load saved games.
Sourcepub fn request_raw<P: AsRef<Path>>(&mut self, path: P)
pub fn request_raw<P: AsRef<Path>>(&mut self, path: P)
Requests a scene for loading in raw mode. See Self::request docs for more info.
Auto Trait Implementations§
impl Freeze for AsyncSceneLoader
impl !RefUnwindSafe for AsyncSceneLoader
impl Send for AsyncSceneLoader
impl !Sync for AsyncSceneLoader
impl Unpin for AsyncSceneLoader
impl !UnwindSafe for AsyncSceneLoader
Blanket Implementations§
Source§impl<T> AsyncTaskResult for T
impl<T> AsyncTaskResult for T
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Any. Could be used to downcast a trait object
to a particular type.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Any. Could be used to downcast a trait object
to a particular type.fn into_any(self: Box<T>) -> Box<dyn Any>
Source§impl<T> FieldValue for Twhere
T: 'static,
impl<T> FieldValue for Twhere
T: 'static,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.