Struct Engine

Source
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

Source

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();
Source

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).

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn handle_plugins_hot_reloading<F>( &mut self, dt: f32, window_target: &EventLoopWindowTarget<()>, lag: &mut f32, on_reloaded: F, )
where F: FnMut(&dyn Plugin),

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
Source

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.

Source

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.

Source

pub fn has_scripted_scene(&self, scene: Handle<Scene>) -> bool

Returns true if the scene is registered for script processing.

Source

pub fn register_scripted_scene(&mut self, scene: Handle<Scene>)

Registers a scene for script processing.

Source

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.

Source

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.

Source

pub fn add_plugin<P>(&mut self, plugin: P)
where P: Plugin + 'static,

Adds a new static plugin.

Source

pub fn add_dynamic_plugin<P>( &mut self, path: P, reload_when_changed: bool, use_relative_paths: bool, ) -> Result<&dyn Plugin, String>
where P: AsRef<Path> + 'static,

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.

Source

pub fn add_dynamic_plugin_custom<P>(&mut self, plugin: P) -> &dyn Plugin
where P: DynamicPlugin + 'static,

Adds a new abstract dynamic plugin

Source

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.

Source

pub fn plugins(&self) -> &[PluginContainer]

Returns a reference to the plugins.

Source

pub fn plugins_mut(&mut self) -> &mut [PluginContainer]

Returns a mutable reference to the plugins.

Source

pub fn reload_dynamic_plugins<F>( &mut self, dt: f32, window_target: &EventLoopWindowTarget<()>, lag: &mut f32, on_reloaded: F, ) -> Result<(), String>
where F: FnMut(&dyn Plugin),

Tries to reload all dynamic plugins registered in the engine, that needs to be reloaded.

Trait Implementations§

Source§

impl Drop for Engine

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> Downcast for T
where T: Any,

Source§

fn as_any(&self) -> &(dyn Any + 'static)

Converts self reference as a reference to Any. Could be used to downcast a trait object to a particular type.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Converts self reference as a reference to Any. Could be used to downcast a trait object to a particular type.
Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert 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>

Convert 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)

Convert &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)

Convert &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 T
where T: 'static,

Source§

fn as_any(&self) -> &(dyn Any + 'static)

Casts self to a &dyn Any
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V