Skip to main content

SM64Game

Struct SM64Game 

Source
pub struct SM64Game { /* private fields */ }
Expand description

A single playable instance of the game, made by SM64GameGenerator::create_game (sm64/generator.rs).

Its memory is handled in sm64/memory.rs (reads, copies), sm64/save_state.rs (SaveState) and sm64/sync.rs (SM64Game::sync_from).

Implementations§

Source§

impl SM64Game

Source

pub fn read_only_memory(&self) -> Range<usize> ⓘ

The part of linear memory that holds the game’s constant data (.rodata), which never changes while playing. Save states and copies leave it out: they are the bytes before it (the stack) and from its end onwards. Read from the WASM, so it follows rebuilds.

Source

pub fn with_memory<R>(&self, f: impl FnOnce(&[u8]) -> R) -> R

Calls f with all of linear memory, without copying it.

Source

pub fn read_memory(&self, addr: u32, buf: &mut [u8]) -> Result<()>

Copies buf.len() bytes of linear memory starting at addr into buf.

Source

pub fn copy_from(&mut self, source: &SM64Game) -> Result<(), Error>

Makes this game a copy of source: copies its mutable regions, without materialising a save state in between.

If you repeatedly load from a previous state (like a tree search), SM64Game::sync_from is faster: it copies back only the pages that have changed.

Fails if source is a different build of the game.

Source§

impl SM64Game

Source

pub fn load_mupen_state(&mut self, st: &MupenState) -> Result<MupenLoadReport>

Loads the game state of a Mupen64 savestate (US ROM) into this game.

This game must already be in the state’s level and area (play or replay to it first): the level’s geometry, collision and spawn lists stay this game’s own, and everything that changes while playing is copied over (Mario, objects, camera, save file, HUD, timers, RNG, …). Fails, without changing anything, if the state is from another level or area, or this game is not the build the tables were made for. MupenLoadReport says what could not be translated.

Source§

impl SM64Game

Source

pub fn warp_to_mupen_area( &mut self, st: &MupenState, max_frames: u32, ) -> Result<u32>

Brings this game to the level and area of st, so that SM64Game::load_mupen_state can load it, by starting the warp the game itself would use (a level change to one of the area’s warp nodes, as a checkpoint so no act select interrupts it) and playing with no input until the area has loaded. The game must be playing a level (past the file select); if it is in the middle of a transition (a fade, an area change) it plays on with no input until that ends. Returns the frames played: 0 if the game was already there.

Source§

impl SM64Game

Source

pub fn export_portable(&self) -> Result<Portable>

This game’s state in portable form: what SM64Game::load_portable of any build loads, so the game goes on identically.

Source

pub fn load_portable(&mut self, state: &Portable) -> Result<PortableLoadReport>

Makes this game the one state was exported from, by either build.

The game’s variables are overwritten, and its heap blocks are reused (or, for the ones that do not fit, allocated with the game’s malloc) to hold the state’s. Display lists, audio output and the like are not part of a state: the next frame rebuilds them.

Source§

impl SM64Game

Source

pub fn save_state(&self) -> SaveState

This game’s state: its stack and heap, which are everything that changes as it plays.

Source

pub fn load_state(&mut self, state: &SaveState) -> Result<()>

Makes this game the one state was saved from. Fails, leaving the game as it was, if state came from a different build of the game.

Source§

impl SM64Game

Source

pub fn sync_from(&mut self, base: &SM64Game) -> Result<()>

Makes this game a copy of base, like SM64Game::copy_from does, but cheaper when called repeatedly with the same base.

The first call does a full copy and starts tracking which pages this game writes. Later calls copy back only those pages, as long as base has not changed since the previous sync (anything that could change its memory, such as stepping it, counts as a change). Otherwise they compare every page with base and copy the ones that differ. The result is the same either way. Page tracking needs Linux 6.7+ (see SM64Game::dirty_tracking_active); elsewhere every call is a full copy.

When base changes between calls (eg if it isn’t a tree search), SM64Game::copy_from is faster: comparing every page costs more than copying them.

With SM64_VERIFY_SYNC=1 in the environment, every sync is checked byte for byte against base and fails if they differ.

Source

pub fn dirty_tracking_active(&self) -> bool

Whether SM64Game::sync_from is tracking written pages, rather than doing full copies.

Source§

impl SM64Game

Source

pub fn backend(&self) -> &'static str

Which way this game’s code was compiled: "precompiled" (ahead of time, shipped in the crate) or "cranelift" (when it was loaded).

Source

pub fn step_game(&mut self, pad: GamePad) -> Result<()>

Source

pub fn get_game_state(&mut self) -> Result<GameState, Error>

Source

pub fn set_render_enabled(&mut self, enabled: bool) -> Result<()>

Turns the display-list interpreter on or off.

Headless builds start with it off: the game never reads its output, so it only costs time. Turning it on is for checking exactly that. The setting lives in linear memory, so copies and save states carry it. Fails on WASM built before the export existed.

Source

pub fn set_audio_enabled(&mut self, enabled: bool) -> Result<()>

Turns audio synthesis on or off. Headless builds start with it off.

Like SM64Game::set_render_enabled, the setting is part of the game’s memory and so travels with copies and save states.

Source

pub fn set_object_freeze(&mut self, mode: FreezeMode) -> Result<()>

Freezes objects so frames are cheaper, at the cost of exactness.

A frozen game no longer plays like the real one: frozen enemies can’t be defeated, ! boxes and red coins don’t spawn stars, and so on. Use it to screen candidates, then replay the ones that matter on an exact game. Switching back to FreezeMode::Off does not make a game exact again. The mode is stored in linear memory, so copies inherit it. Needs a headless build with the set_object_freeze export.

Source

pub fn is_exact(&mut self) -> Result<bool>

False once objects have been frozen in this game, or in the game (or save state) it was copied from. The marker lives in linear memory, so it travels with the state. Builds without freezing are always exact.

Source

pub fn call_export_u32(&mut self, name: &str) -> Result<u32>

Calls a zero-argument export that returns an i32 (typically a pointer into linear memory) and returns it as a u32.

Looked up by name on every call, so this is for occasional use (such as get_mario_state), not hot paths. Fails if the WASM lacks the export.

Source

pub fn has_export(&self, name: &str) -> bool

Whether the loaded WASM has an export called name.

Source

pub fn wasm_parts(&mut self) -> (&mut Store, &Instance, &Memory)

Low-level escape hatch: the wasmer store and instance, for calling exports with signatures the typed methods above don’t cover. Re-exported as sm64_binds::wasmer so callers use the same wasmer version.

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> ArchivePointee for T

Source§

type ArchivedMetadata = ()

The archived version of the pointer metadata for this type.
Source§

fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata

Converts some archived metadata to the pointer metadata for itself.
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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> LayoutRaw for T

Source§

fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>

Returns the layout of the type.
Source§

impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
where T: SharedNiching<N1, N2>, N1: Niching<T>, N2: Niching<T>,

Source§

unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool

Returns whether the given value has been niched. Read more
Source§

fn resolve_niched(out: Place<NichedOption<T, N1>>)

Writes data to out indicating that a T is niched.
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> Pointee for T

Source§

type Metadata = ()

The metadata type for pointers and references to this type.
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 = !

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

fn try_from(value: U) -> Result<T, !>

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<T> Upcastable for T
where T: Any + Send + Sync + 'static,

Source§

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

upcast ref
Source§

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

upcast mut ref
Source§

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

upcast boxed dyn
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more