pub struct Engine {
pub renderer: Renderer,
pub scene_manager: SceneManager,
pub assets: AssetServer,
pub input: Input,
/* private fields */
}Expand description
The core engine instance that orchestrates all rendering subsystems.
Engine is a pure engine implementation without window management,
making it suitable for integration with various windowing systems and platforms.
§Components
renderer: The rendering subsystem handling GPU operationsscene_manager: Manages multiple scenes and active scene selectionassets: Central asset storage for geometries, materials, textures, etc.input: Unified input state (keyboard, mouse, touch)
§Lifecycle
- Create with
Engine::neworEngine::default - Initialize GPU with
Engine::init - Update each frame with
Engine::update - Render using
Renderer::begin_frame
Fields§
§renderer: Renderer§scene_manager: SceneManager§assets: AssetServer§input: InputImplementations§
Source§impl Engine
impl Engine
Sourcepub fn new(
init_config: RendererInitConfig,
settings: RendererSettings,
) -> Engine
pub fn new( init_config: RendererInitConfig, settings: RendererSettings, ) -> Engine
Sourcepub async fn init<W>(
&mut self,
window: W,
width: u32,
height: u32,
) -> Result<(), Error>
pub async fn init<W>( &mut self, window: W, width: u32, height: u32, ) -> Result<(), Error>
Initializes GPU resources with the given window.
This method must be called before any rendering can occur. It accepts any type that implements the raw window handle traits, making it compatible with various windowing libraries.
§Arguments
window- A window that provides display and window handleswidth- Initial surface width in pixelsheight- Initial surface height in pixels
§Errors
Returns an error if GPU initialization fails due to:
- No compatible GPU adapter found
- Device request failed (unsupported features/limits)
- Surface configuration failed
pub fn frame_time(&self) -> FrameTime
Sourcepub fn frame_count(&self) -> u64
pub fn frame_count(&self) -> u64
Returns the total number of frames rendered since startup.
Sourcepub fn size(&self) -> (u32, u32)
pub fn size(&self) -> (u32, u32)
Returns the current surface/window size in pixels as (width, height).
Sourcepub fn resize(&mut self, width: u32, height: u32)
pub fn resize(&mut self, width: u32, height: u32)
Handles window resize events.
This method should be called whenever the window size changes. It updates the renderer’s surface configuration and camera aspect ratios.
§Arguments
width- New width in pixelsheight- New height in pixels
Sourcepub fn update(&mut self, dt: f32)
pub fn update(&mut self, dt: f32)
Updates the engine state for the current frame.
This method should be called once per frame before rendering. It:
- Updates the total elapsed time and frame counter
- Runs scene logic and animations
- Resets per-frame input state
§Arguments
dt- Delta time since the last frame in seconds
Sourcepub fn maybe_prune(&mut self)
pub fn maybe_prune(&mut self)
Performs periodic resource cleanup.
This method should be called after each frame to release unused GPU resources and prevent memory leaks. It uses internal heuristics to avoid expensive cleanup operations on every frame.
Sourcepub fn render_active_scene(&mut self) -> bool
pub fn render_active_scene(&mut self) -> bool
Renders the active scene using the active camera.
This is a convenience method that combines scene lookup, camera extraction, and frame rendering into a single call. It avoids the split-borrow issues that arise when accessing the renderer and scene manager separately.
Returns true if a frame was successfully rendered, false if rendering
was skipped (no active scene, no active camera, etc.).
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 UnsafeUnpin 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 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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().