pub struct Game { /* private fields */ }Expand description
A running guest. gasm_frame guests are called once per frame; gasm_run
guests run in one suspended call (stack switching) that each Game::frame
resumes until its next yield_frame.
Implementations§
Source§impl Game
impl Game
pub fn load(wasm: &[u8], host: Host, opts: LoadOptions) -> Result<Game, Stop>
Sourcepub fn set_asset(&mut self, name: &str, bytes: Vec<u8>) -> u32
pub fn set_asset(&mut self, name: &str, bytes: Vec<u8>) -> u32
Add or replace an asset between frames: the guest sees it from the next
frame on, with a new gasm.asset_version. Returns that version.
Sourcepub fn remove_asset(&mut self, name: &str) -> bool
pub fn remove_asset(&mut self, name: &str) -> bool
Remove an asset between frames. False if there was none.
Sourcepub fn watch_asset(&mut self, name: &str, path: &Path)
pub fn watch_asset(&mut self, name: &str, path: &Path)
Re-read path as asset name whenever the file changes (in place or by a
rename), checked before each frame.
Sourcepub fn add_watch(&mut self, watch: AssetWatch)
pub fn add_watch(&mut self, watch: AssetWatch)
Game::watch_asset with a watch made earlier (when the asset was first opened).
Sourcepub fn switching(&self) -> bool
pub fn switching(&self) -> bool
Whether the guest runs through gasm_run (the runner switches stacks).
Sourcepub fn frame(&mut self) -> Result<(), Stop>
pub fn frame(&mut self) -> Result<(), Stop>
One frame: call gasm_frame, or resume gasm_run until its next yield_frame.
Sourcepub fn exit(&mut self)
pub fn exit(&mut self)
Best-effort “the player is quitting” notification (optional gasm_exit export).
A suspended gasm_run guest gets it on top of its run, which then ends.
Sourcepub fn with_host<R>(&mut self, f: impl FnOnce(&mut Host) -> R) -> R
pub fn with_host<R>(&mut self, f: impl FnOnce(&mut Host) -> R) -> R
Run f on the host: directly, or (a suspended gasm_run guest) through
the guest’s yield_frame, which owns the store meanwhile. Runners use this
between frames for everything they read or set.
Sourcepub fn host(&self) -> &Host
pub fn host(&self) -> &Host
The host of a guest that isn’t suspended in gasm_run (every gasm_frame
guest; a gasm_run guest before its first frame and after it ended).
Otherwise use Game::with_host.
pub fn host_mut(&mut self) -> &mut Host
Auto Trait Implementations§
impl !RefUnwindSafe for Game
impl !Send for Game
impl !Sync for Game
impl !UnwindSafe for Game
impl Freeze for Game
impl Unpin for Game
impl UnsafeUnpin for Game
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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.impl<S, T> Duplex<S> for Twhere
T: FromSample<S> + ToSample<S>,
Source§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> 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> 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 more