Skip to main content

ExecutionEngine

Struct ExecutionEngine 

Source
pub struct ExecutionEngine {
    pub emu: Nes,
    pub config: ExecutionConfig,
    pub savestate_config: SavestateConfig,
    pub frames: Vec<Vec<u16>>,
    /* private fields */
}
Expand description

The main execution engine for CLI-driven emulation.

This struct manages the emulator lifecycle and provides a clean API for running emulation with various configurations.

§Video Export Modes

  • Buffered mode (default): All frames are stored in memory, then encoded at the end. Suitable for small exports or when you need access to all frames.

  • Streaming mode: Frames are encoded immediately as they are generated. Use run_with_video_encoder() for this mode. Significantly reduces memory usage for long recordings.

Fields§

§emu: Nes

The emulator instance

§config: ExecutionConfig

Execution configuration

§savestate_config: SavestateConfig

Savestate configuration

§frames: Vec<Vec<u16>>

Collected frames (used in buffered mode) - raw palette indices

Implementations§

Source§

impl ExecutionEngine

Source

pub fn new() -> Self

Create a new execution engine with default emulator

Source

pub fn with_emulator(emu: Nes) -> Self

Create execution engine with existing emulator

Source

pub fn with_config(self, config: ExecutionConfig) -> Self

Set execution configuration

Source

pub fn with_savestate_config(self, config: SavestateConfig) -> Self

Set savestate configuration

Source

pub fn load_rom(&mut self, path: &Path) -> Result<(), String>

Load ROM from path

Source

pub fn power_on(&mut self)

Power on the emulator

Source

pub fn power_off(&mut self)

Power off the emulator

Source

pub fn reset(&mut self)

Reset the emulator

Source

pub fn load_savestate(&mut self) -> Result<(), String>

Load savestate based on configuration

Source

pub fn save_savestate(&self) -> Result<(), String>

Save savestate based on configuration

Source

pub fn run(&mut self) -> Result<ExecutionResult, String>

Run execution until a stop condition is met

Source

pub fn run_with_video_encoder( &mut self, encoder: &mut StreamingVideoEncoder, renderer: &mut Box<dyn ScreenRenderer>, ) -> Result<ExecutionResult, String>

Run execution with streaming video export.

This mode writes frames directly to the video encoder as they are generated, instead of buffering all frames in memory. This significantly reduces memory usage for long recordings.

§Arguments
  • encoder - A streaming video encoder that will receive frames as they’re generated
§Performance
  • Uses parallel upscaling via rayon (if encoder has upscaling enabled)
  • O(1) memory usage per frame instead of O(n) for all frames
  • Frames are written immediately, reducing peak memory usage
§FPS Multipliers

When the encoder’s FPS config specifies a multiplier > 1 (e.g., 2x, 3x), this method captures frames at sub-frame intervals. For example:

  • 2x: Captures at mid-frame and end of frame (2 captures per PPU frame)
  • 3x: Captures at 1/3, 2/3, and end of frame (3 captures per PPU frame)

This produces true intermediate states showing partial rendering progress.

Source

pub fn set_collect_frames(&mut self, collect: bool)

Enable or disable frame collection.

When disabled, frames are not stored in memory during execution. Use this for streaming mode or when you don’t need frame data.

Source

pub fn emulator(&self) -> &Nes

Get reference to the emulator

Source

pub fn emulator_mut(&mut self) -> &mut Nes

Get mutable reference to the emulator

Trait Implementations§

Source§

impl Default for ExecutionEngine

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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> 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<R, P> ReadPrimitive<R> for P
where R: Read + ReadEndian<P>, P: Default,

Source§

fn read_from_little_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_little_endian().
Source§

fn read_from_big_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_big_endian().
Source§

fn read_from_native_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_native_endian().
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.