pub struct Engine {
pub graphics_context: GraphicsContext,
pub resource_manager: ResourceManager,
pub user_interfaces: UiContainer,
pub scenes: SceneContainer,
pub async_scene_loader: AsyncSceneLoader,
pub task_pool: TaskPoolHandler,
pub serialization_context: Arc<SerializationContext>,
pub widget_constructors: Arc<WidgetConstructorContainer>,
pub script_processor: ScriptProcessor,
/* private fields */
}
Expand description
See module docs.
Fields§
§graphics_context: GraphicsContext
Graphics context of the engine. See GraphicsContext
docs for more info.
resource_manager: ResourceManager
Current resource manager. Resource manager can be cloned (it does clone only ref) to be able to use resource manager from any thread, this is useful to load resources from multiple threads to decrease loading times of your game by utilizing all available power of your CPU.
user_interfaces: UiContainer
All available user interfaces in the engine.
scenes: SceneContainer
All available scenes in the engine.
async_scene_loader: AsyncSceneLoader
An instance of the async scene loader. See AsyncSceneLoader
docs for usage example.
task_pool: TaskPoolHandler
Task pool for asynchronous task management.
serialization_context: Arc<SerializationContext>
A special container that is able to create nodes by their type UUID. Use a copy of this value whenever you need it as a parameter in other parts of the engine.
widget_constructors: Arc<WidgetConstructorContainer>
A container with widget constructors.
script_processor: ScriptProcessor
Script processor is used to run script methods in a strict order.
Implementations§
Source§impl Engine
impl Engine
Sourcepub fn new(params: EngineInitParams) -> Result<Self, EngineError>
pub fn new(params: EngineInitParams) -> Result<Self, EngineError>
Creates new instance of engine from given initialization parameters. Automatically creates all sub-systems
(sound, ui, resource manager, etc.) except graphics context. Graphics context should be created manually
only on Event::Resumed
by calling Engine::initialize_graphics_context
and destroyed on Event::Suspended
by calling Engine::destroy_graphics_context
. If you don’t need a graphics context (for example if you’re
making a game server), then you can ignore these methods.
§Examples
use fyrox_ui::constructor::new_widget_constructor_container;
let mut window_attributes = WindowAttributes::default();
window_attributes.title = "Some title".to_string();
let graphics_context_params = GraphicsContextParams {
window_attributes,
vsync: true,
msaa_sample_count: None,
graphics_server_constructor: Default::default()
};
let task_pool = Arc::new(TaskPool::new());
Engine::new(EngineInitParams {
graphics_context_params,
resource_manager: ResourceManager::new(task_pool.clone()),
serialization_context: Arc::new(SerializationContext::new()),
task_pool,
widget_constructors: Arc::new(new_widget_constructor_container()),
})
.unwrap();
Sourcepub fn initialize_graphics_context(
&mut self,
window_target: &EventLoopWindowTarget<()>,
) -> Result<(), EngineError>
pub fn initialize_graphics_context( &mut self, window_target: &EventLoopWindowTarget<()>, ) -> Result<(), EngineError>
Tries to initialize the graphics context. The method will attempt to use the info stored in graphics_context
variable of the engine to attempt to initialize the graphics context. It will fail if the graphics context is
already initialized as well as if there any platform-dependent error (for example your hardware does not support
OpenGL 3.3 Core or OpenGL ES 3.0).
This method should be called on Event::Resumed
of your game loop, however you can ignore it if you don’t need
graphics context at all (for example - if you’re making game server).
Sourcepub fn destroy_graphics_context(&mut self) -> Result<(), EngineError>
pub fn destroy_graphics_context(&mut self) -> Result<(), EngineError>
Tries to destroy current graphics context. It will succeed only if the graphics_context
is fully initialized.
The method will try to save all possible runtime changes of the window, so the next Engine::initialize_graphics_context
will result in the almost exact copy of the context that was made before destruction.
This method should be called on Event::Suspended
of your game loop, however if you do not use any graphics context
(for example - if you’re making a game server), then you can ignore this method completely.
Sourcepub fn set_frame_size(
&mut self,
new_size: (u32, u32),
) -> Result<(), FrameworkError>
pub fn set_frame_size( &mut self, new_size: (u32, u32), ) -> Result<(), FrameworkError>
Adjust size of the frame to be rendered. Must be called after the window size changes. Will update the renderer and GL context frame size.
Sourcepub fn elapsed_time(&self) -> f32
pub fn elapsed_time(&self) -> f32
Amount of time (in seconds) that passed from creation of the engine. Keep in mind, that this value is not guaranteed to match real time. A user can change delta time with which the engine “ticks” and this delta time affects elapsed time.
Sourcepub fn update(
&mut self,
dt: f32,
window_target: &EventLoopWindowTarget<()>,
lag: &mut f32,
switches: FxHashMap<Handle<Scene>, GraphUpdateSwitches>,
)
pub fn update( &mut self, dt: f32, window_target: &EventLoopWindowTarget<()>, lag: &mut f32, switches: FxHashMap<Handle<Scene>, GraphUpdateSwitches>, )
Performs single update tick with given time delta. Engine internally will perform update of all scenes, sub-systems, user interface, etc. Must be called in order to get engine functioning.
§Parameters
lag
- is a reference to time accumulator, that holds remaining amount of time that should be used
to update a plugin. A caller splits lag
into multiple sub-steps using dt
and thus stabilizes
update rate. The main use of this variable, is to be able to reset lag
when you doing some heavy
calculations in a your game loop (i.e. loading a new level) so the engine won’t try to “catch up” with
all the time that was spent in heavy calculation. The engine does not use this variable itself,
but the plugins attach may use it, that’s why you need to provide it. If you don’t use plugins, then
put &mut 0.0
here.
Sourcepub fn handle_plugins_hot_reloading<F>(
&mut self,
dt: f32,
window_target: &EventLoopWindowTarget<()>,
lag: &mut f32,
on_reloaded: F,
)
pub fn handle_plugins_hot_reloading<F>( &mut self, dt: f32, window_target: &EventLoopWindowTarget<()>, lag: &mut f32, on_reloaded: F, )
Tries to hot-reload dynamic plugins marked for reloading.
§Platform-specific
- Windows, Unix-like systems (Linux, macOS, FreeBSD, etc) - fully supported.
- WebAssembly - not supported
- Android - not supported
Sourcepub fn pre_update(
&mut self,
dt: f32,
window_target: &EventLoopWindowTarget<()>,
lag: &mut f32,
switches: FxHashMap<Handle<Scene>, GraphUpdateSwitches>,
)
pub fn pre_update( &mut self, dt: f32, window_target: &EventLoopWindowTarget<()>, lag: &mut f32, switches: FxHashMap<Handle<Scene>, GraphUpdateSwitches>, )
Performs pre update for the engine.
Normally, this is called from Engine::update()
.
You should only call this manually if you don’t use that method.
§Parameters
lag
- is a reference to time accumulator, that holds remaining amount of time that should be used
to update a plugin. A caller splits lag
into multiple sub-steps using dt
and thus stabilizes
update rate. The main use of this variable, is to be able to reset lag
when you doing some heavy
calculations in a your game loop (i.e. loading a new level) so the engine won’t try to “catch up” with
all the time that was spent in heavy calculation. The engine does not use this variable itself,
but the plugins attach may use it, that’s why you need to provide it. If you don’t use plugins, then
put &mut 0.0
here.
Sourcepub fn post_update(
&mut self,
dt: f32,
ui_update_switches: &UiUpdateSwitches,
lag: &mut f32,
window_target: &EventLoopWindowTarget<()>,
)
pub fn post_update( &mut self, dt: f32, ui_update_switches: &UiUpdateSwitches, lag: &mut f32, window_target: &EventLoopWindowTarget<()>, )
Performs post update for the engine.
Normally, this is called from Engine::update()
.
You should only call this manually if you don’t use that method.
Sourcepub fn has_scripted_scene(&self, scene: Handle<Scene>) -> bool
pub fn has_scripted_scene(&self, scene: Handle<Scene>) -> bool
Returns true if the scene is registered for script processing.
Sourcepub fn register_scripted_scene(&mut self, scene: Handle<Scene>)
pub fn register_scripted_scene(&mut self, scene: Handle<Scene>)
Registers a scene for script processing.
Sourcepub fn handle_model_events(&mut self)
pub fn handle_model_events(&mut self)
Handle hot-reloading of resources.
Normally, this is called from Engine::update()
.
You should only call this manually if you don’t use that method.
Sourcepub fn render(&mut self) -> Result<(), FrameworkError>
pub fn render(&mut self) -> Result<(), FrameworkError>
Performs rendering of single frame, must be called from your game loop, otherwise you won’t see anything.
Sourcepub fn add_plugin<P>(&mut self, plugin: P)where
P: Plugin + 'static,
pub fn add_plugin<P>(&mut self, plugin: P)where
P: Plugin + 'static,
Adds a new static plugin.
Sourcepub fn add_dynamic_plugin<P>(
&mut self,
path: P,
reload_when_changed: bool,
use_relative_paths: bool,
) -> Result<&dyn Plugin, String>
pub fn add_dynamic_plugin<P>( &mut self, path: P, reload_when_changed: bool, use_relative_paths: bool, ) -> Result<&dyn Plugin, String>
Tries to add a new dynamic plugin. This method attempts to load a dynamic library by the
given path and searches for fyrox_plugin
function. This function is called to create a
plugin instance. This method will fail if there’s no dynamic library at the given path or
the fyrox_plugin
function is not found.
§Hot reloading
This method can enable hot reloading for the plugin, by setting reload_when_changed
parameter
to true
. When enabled, the engine will clone the library to implementation-defined path
and load it. It will setup file system watcher to receive changes from the OS and reload
the plugin.
Sourcepub fn add_dynamic_plugin_custom<P>(&mut self, plugin: P) -> &dyn Pluginwhere
P: DynamicPlugin + 'static,
pub fn add_dynamic_plugin_custom<P>(&mut self, plugin: P) -> &dyn Pluginwhere
P: DynamicPlugin + 'static,
Adds a new abstract dynamic plugin
Sourcepub fn reload_plugin(
&mut self,
plugin_index: usize,
dt: f32,
window_target: &EventLoopWindowTarget<()>,
lag: &mut f32,
) -> Result<(), String>
pub fn reload_plugin( &mut self, plugin_index: usize, dt: f32, window_target: &EventLoopWindowTarget<()>, lag: &mut f32, ) -> Result<(), String>
Tries to reload a specified plugin. This method tries to perform least invasive reloading, by only detaching parts from the scenes and engine internals, that belongs to reloadable plugin.
Sourcepub fn plugins(&self) -> &[PluginContainer]
pub fn plugins(&self) -> &[PluginContainer]
Returns a reference to the plugins.
Sourcepub fn plugins_mut(&mut self) -> &mut [PluginContainer]
pub fn plugins_mut(&mut self) -> &mut [PluginContainer]
Returns a mutable reference to the plugins.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for Engine
impl !RefUnwindSafe for Engine
impl !Send for Engine
impl !Sync for Engine
impl Unpin for Engine
impl !UnwindSafe for Engine
Blanket Implementations§
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 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> 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> 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.