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
impl SM64Game
Sourcepub fn read_only_memory(&self) -> Range<usize> ⓘ
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.
Sourcepub fn with_memory<R>(&self, f: impl FnOnce(&[u8]) -> R) -> R
pub fn with_memory<R>(&self, f: impl FnOnce(&[u8]) -> R) -> R
Calls f with all of linear memory, without copying it.
Sourcepub fn read_memory(&self, addr: u32, buf: &mut [u8]) -> Result<()>
pub fn read_memory(&self, addr: u32, buf: &mut [u8]) -> Result<()>
Copies buf.len() bytes of linear memory starting at addr into buf.
Sourcepub fn copy_from(&mut self, source: &SM64Game) -> Result<(), Error>
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
impl SM64Game
Sourcepub fn load_mupen_state(&mut self, st: &MupenState) -> Result<MupenLoadReport>
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
impl SM64Game
Sourcepub fn warp_to_mupen_area(
&mut self,
st: &MupenState,
max_frames: u32,
) -> Result<u32>
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
impl SM64Game
Sourcepub fn export_portable(&self) -> Result<Portable>
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.
Sourcepub fn load_portable(&mut self, state: &Portable) -> Result<PortableLoadReport>
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
impl SM64Game
Sourcepub fn save_state(&self) -> SaveState
pub fn save_state(&self) -> SaveState
This game’s state: its stack and heap, which are everything that changes as it plays.
Sourcepub fn load_state(&mut self, state: &SaveState) -> Result<()>
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
impl SM64Game
Sourcepub fn sync_from(&mut self, base: &SM64Game) -> Result<()>
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.
Sourcepub fn dirty_tracking_active(&self) -> bool
pub fn dirty_tracking_active(&self) -> bool
Whether SM64Game::sync_from is tracking written pages, rather
than doing full copies.
Source§impl SM64Game
impl SM64Game
Sourcepub fn backend(&self) -> &'static str
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).
pub fn step_game(&mut self, pad: GamePad) -> Result<()>
pub fn get_game_state(&mut self) -> Result<GameState, Error>
Sourcepub fn set_render_enabled(&mut self, enabled: bool) -> Result<()>
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.
Sourcepub fn set_audio_enabled(&mut self, enabled: bool) -> Result<()>
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.
Sourcepub fn set_object_freeze(&mut self, mode: FreezeMode) -> Result<()>
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.
Sourcepub fn is_exact(&mut self) -> Result<bool>
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.
Sourcepub fn call_export_u32(&mut self, name: &str) -> Result<u32>
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.
Sourcepub fn has_export(&self, name: &str) -> bool
pub fn has_export(&self, name: &str) -> bool
Whether the loaded WASM has an export called name.
Sourcepub fn wasm_parts(&mut self) -> (&mut Store, &Instance, &Memory)
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§
impl !RefUnwindSafe for SM64Game
impl !UnwindSafe for SM64Game
impl Forget for SM64Game
impl Freeze for SM64Game
impl Move for SM64Game
impl Send for SM64Game
impl Sync for SM64Game
impl Unpin for SM64Game
impl UnsafeUnpin for SM64Game
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
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> 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> 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> LayoutRaw for T
impl<T> LayoutRaw for T
Source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
Source§impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
Source§unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
Source§fn resolve_niched(out: Place<NichedOption<T, N1>>)
fn resolve_niched(out: Place<NichedOption<T, N1>>)
out indicating that a T is niched.