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: NesThe emulator instance
config: ExecutionConfigExecution configuration
savestate_config: SavestateConfigSavestate configuration
frames: Vec<Vec<u16>>Collected frames (used in buffered mode) - raw palette indices
Implementations§
Source§impl ExecutionEngine
impl ExecutionEngine
Sourcepub fn with_emulator(emu: Nes) -> Self
pub fn with_emulator(emu: Nes) -> Self
Create execution engine with existing emulator
Sourcepub fn with_config(self, config: ExecutionConfig) -> Self
pub fn with_config(self, config: ExecutionConfig) -> Self
Set execution configuration
Sourcepub fn with_savestate_config(self, config: SavestateConfig) -> Self
pub fn with_savestate_config(self, config: SavestateConfig) -> Self
Set savestate configuration
Sourcepub fn load_savestate(&mut self) -> Result<(), String>
pub fn load_savestate(&mut self) -> Result<(), String>
Load savestate based on configuration
Sourcepub fn save_savestate(&self) -> Result<(), String>
pub fn save_savestate(&self) -> Result<(), String>
Save savestate based on configuration
Sourcepub fn run(&mut self) -> Result<ExecutionResult, String>
pub fn run(&mut self) -> Result<ExecutionResult, String>
Run execution until a stop condition is met
Sourcepub fn run_with_video_encoder(
&mut self,
encoder: &mut StreamingVideoEncoder,
renderer: &mut Box<dyn ScreenRenderer>,
) -> Result<ExecutionResult, String>
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.
Sourcepub fn set_collect_frames(&mut self, collect: bool)
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.
Sourcepub fn emulator_mut(&mut self) -> &mut Nes
pub fn emulator_mut(&mut self) -> &mut Nes
Get mutable reference to the emulator
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for ExecutionEngine
impl !RefUnwindSafe for ExecutionEngine
impl !Send for ExecutionEngine
impl !Sync for ExecutionEngine
impl Unpin for ExecutionEngine
impl UnsafeUnpin for ExecutionEngine
impl !UnwindSafe for ExecutionEngine
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> 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<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().