Skip to main content

Game

Struct Game 

Source
pub struct Game<G>
where G: GameData,
{ /* private fields */ }
Expand description

Owns the screens, input state, shared context and the console buffer.

Implementations§

Source§

impl<G> Game<G>
where G: GameData,

Source

pub fn new( ctx: Ctx<G>, root: Box<dyn Screen<G>>, hooks: GameHooks<G>, ) -> Game<G>

A game showing root, with the game’s hooks.

Source

pub fn with_stack( ctx: Ctx<G>, stack: ScreenStack<G>, hooks: GameHooks<G>, ) -> Game<G>

A game showing the screens of stack, with the game’s hooks, already drawn. Music switches as the audio manifest’s default switch says (AudioManifest::music_switch).

Source

pub fn with_module(self, module: impl Module<G>) -> Result<Game<G>, ModuleError>

The same game with module installed after those it has: its install runs, and the frame is drawn again with what it draws. Refused for a name already installed or a state another module put on the context.

Source

pub fn with_modules( self, modules: impl IntoIterator<Item = Box<dyn Module<G>>>, ) -> Result<Game<G>, ModuleError>

The same game with modules installed in order, as with_module installs one.

Source

pub fn modules(&self) -> &[InstalledModule]

The installed modules, in install order, with what each declared.

Source

pub fn with_debug_screens(self, on: bool) -> Game<G>

Turns the debug tools (the Debug action) on or off (Ctx::debug_tools).

Source

pub fn guard_actions(&mut self, on: bool)

Turns the screens’ action guard on or off (ScreenStack::guard_actions): while it is on, a screen that declares its actions is handed only those. The test Harness turns it on.

Source

pub fn undeclared_actions(&self) -> &[(&'static str, <G as GameData>::Action)]

Every action held back from a screen that doesn’t declare it, with the screen’s name (ScreenStack::undeclared).

Source

pub fn set_music_playing(&mut self, playing: Option<(&str, f64)>)

Tells the game what music is sounding, for Ctx::music_clock: the cue and the seconds since the track really started, or None in silence. The platform knows (a track starts once its file has loaded) and calls this before every frame, so screens read a clock at most one frame old. The music’s fades learn from it when a new track sounds (MusicState::heard).

Source

pub fn set_voice_playing(&mut self, line: Option<&LineId>)

Tells the game which line’s voice clip is sounding, for Ctx::voice_playing, or None in silence. The platform knows (a clip sounds once its file has loaded, and until it ends) and calls this before every frame, as it does set_music_playing.

Source

pub fn set_pacing(&mut self, report: Pacing)

Tells the game how the platform paces its frames: the frame cap it applied with its serial, and the frames a second it measured (Pacing). The platform calls this before every frame, as it does set_music_playing, so a request for a cap is confirmed (Ctx::frame_cap_status) and a screen can show the frame rate (Ctx::pacing).

Source

pub fn set_ticks(&mut self, ticks: u32)

Says how many fixed simulation steps are due in the next frame (ADR-0003 §2): its screen reads them as FrameInput::ticks. The platform’s App counts them from its clock and calls this before every frame; a frame after none has 0.

Source

pub fn set_resumed(&mut self)

Says the system resumed the game from a suspend before the next frame: its screen reads it as FrameInput::resumed, and a tick stage’s TickDriver forgets the presses it kept from before. That frame lets go of every key and button held before the suspend (InputState::release_all) before it applies its events, so a key let go while suspended doesn’t stay held, and one pressed in that frame counts. The platform’s App calls it on the system’s Resume.

Source

pub fn forget_held_input(&mut self)

Lets go of every key and button held now (InputState::release_all): the next frame reports their actions let go, and one still down counts once it is pressed again. The platform’s App calls it on the system’s FocusLost, since a window without focus hears no release.

Source

pub fn toggle_fullscreen(&mut self)

Flips the Fullscreen setting, as a window’s own shortcut does. The platform then switches the window on the next frame, and an options screen shows the new value. Does nothing where the game isn’t in a window (PlatformFacts::windowed false): a device that is always full screen.

Source

pub fn reloaded(&mut self, changed: &[String])

Tells the modules that declared Hook::Reloaded, in install order, that the files at changed changed on disk (paths in the bundle). The platform’s App calls it before the frame’s update, in a build with debug tools on. After a quit, nothing.

Source

pub fn frame( &mut self, events: &[RawInputEvent], dt: f32, ) -> FrameOutput<'_, <G as GameData>::Voice>

Runs one frame: applies events (in order), advances input by dt seconds, updates the top screen with the resulting actions, collects its audio requests and redraws. After a quit, frames do nothing. In a frame the platform measures (Ctx::begin_perf_frame) it times the update and the drawing, and with memory scopes (Ctx::set_memory_scopes) it tags what each allocates update and draw (crate::perf).

Source

pub fn act(&mut self, action: <G as GameData>::Action)

Hands the top screen action alone, in an update of its own with no time passing, as if a key bound to it had just been pressed: an action from outside the keys and buttons, such as an entry of the platform’s own menu (the Playdate’s system menu, ticket 1035). The screen does with it what it does with the key, or nothing. Its sounds come out with the next frame. No step is due in it: a tick stage keeps it as a tap (pressed, and let go unless a key holds it) for its next step. After a quit, nothing.

Source

pub fn set_widths(&mut self, widths: CellWidths)

Prints the characters widths has wide in two cells, as the font atlas the frame is drawn with has them (CellWidths::of), in the language text is shown in (Ctx::widths, which the frame’s GlyphBuffer::widths follow). The frame is drawn again if that changed them. The platform calls it once the game has loaded, with its look’s atlas, and again after its files change.

Source

pub fn redraw(&mut self)

Clears the buffer and draws the stack into it, then the modules over it, then, with debug tools on, the debug view’s gizmos over everything: after a change made from outside the frame loop (a test changing the context). The buffer takes the widths of the language text is shown in first (Ctx::widths).

Source

pub fn screen<T>(&self) -> Option<&T>
where T: Any,

The top-most screen of type T on the stack, if it opts in (Screen::as_any).

Source

pub fn state_hash(&self) -> Option<StateHash>

The state hash of the top-most screen that has one (Screen::state_hash).

Source

pub fn screen_mut<T>(&mut self) -> Option<&mut T>
where T: Any,

screen, mutable, for scripted tests.

Source

pub fn music(&self) -> &MusicState

The music state machine (which track plays).

Source

pub fn input(&self) -> &InputState<<G as GameData>::Action>

The input state (held keys, the keymap in use).

Source

pub fn buffer(&self) -> &GlyphBuffer

The last frame drawn.

Source

pub fn quit_requested(&self) -> bool

Whether the game has asked to quit.

Source

pub fn ctx(&self) -> &Ctx<G>

The shared context.

Source

pub fn ctx_mut(&mut self) -> &mut Ctx<G>

The shared context, to change settings mid-run (tests and tools; screens get theirs in Screen::update).

Source

pub fn into_ctx(self) -> Ctx<G>

Ends the game, handing back the shared context (and so its storage).

Source

pub fn top_screen(&self) -> Option<&'static str>

Name of the top screen, or None once the last one has closed.

Source

pub fn screens(&self) -> Vec<&'static str>

Names of the open screens, bottom first.

Auto Trait Implementations§

§

impl<G> !RefUnwindSafe for Game<G>

§

impl<G> !Send for Game<G>

§

impl<G> !Sync for Game<G>

§

impl<G> !UnwindSafe for Game<G>

§

impl<G> Freeze for Game<G>

§

impl<G> Unpin for Game<G>
where G: Unpin, <<G as GameData>::Settings as GameSettings>::Theme: Unpin, <G as GameData>::Settings: Unpin, <G as GameData>::Action: Unpin, <G as GameData>::Voice: Unpin,

§

impl<G> UnsafeUnpin for Game<G>

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
§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<S> FromSample<S> for S

§

fn from_sample_(s: S) -> S

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.

§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

§

fn to_sample_(self) -> U

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.