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,
impl<G> Game<G>where
G: GameData,
Sourcepub fn new(
ctx: Ctx<G>,
root: Box<dyn Screen<G>>,
hooks: GameHooks<G>,
) -> Game<G>
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.
Sourcepub fn with_stack(
ctx: Ctx<G>,
stack: ScreenStack<G>,
hooks: GameHooks<G>,
) -> Game<G>
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).
Sourcepub fn with_module(self, module: impl Module<G>) -> Result<Game<G>, ModuleError>
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.
Sourcepub fn with_modules(
self,
modules: impl IntoIterator<Item = Box<dyn Module<G>>>,
) -> Result<Game<G>, ModuleError>
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.
Sourcepub fn modules(&self) -> &[InstalledModule]
pub fn modules(&self) -> &[InstalledModule]
The installed modules, in install order, with what each declared.
Sourcepub fn with_debug_screens(self, on: bool) -> Game<G>
pub fn with_debug_screens(self, on: bool) -> Game<G>
Turns the debug tools (the Debug action) on or off
(Ctx::debug_tools).
Sourcepub fn guard_actions(&mut self, on: bool)
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.
Sourcepub fn undeclared_actions(&self) -> &[(&'static str, <G as GameData>::Action)]
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).
Sourcepub fn set_music_playing(&mut self, playing: Option<(&str, f64)>)
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).
Sourcepub fn set_voice_playing(&mut self, line: Option<&LineId>)
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.
Sourcepub fn set_pacing(&mut self, report: Pacing)
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).
Sourcepub fn set_ticks(&mut self, ticks: u32)
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.
Sourcepub fn set_resumed(&mut self)
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.
Sourcepub fn forget_held_input(&mut self)
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.
Sourcepub fn toggle_fullscreen(&mut self)
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.
Sourcepub fn reloaded(&mut self, changed: &[String])
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.
Sourcepub fn frame(
&mut self,
events: &[RawInputEvent],
dt: f32,
) -> FrameOutput<'_, <G as GameData>::Voice>
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).
Sourcepub fn act(&mut self, action: <G as GameData>::Action)
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.
Sourcepub fn set_widths(&mut self, widths: CellWidths)
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.
Sourcepub fn redraw(&mut self)
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).
Sourcepub fn screen<T>(&self) -> Option<&T>where
T: Any,
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).
Sourcepub fn state_hash(&self) -> Option<StateHash>
pub fn state_hash(&self) -> Option<StateHash>
The state hash of the top-most screen that has one
(Screen::state_hash).
Sourcepub fn screen_mut<T>(&mut self) -> Option<&mut T>where
T: Any,
pub fn screen_mut<T>(&mut self) -> Option<&mut T>where
T: Any,
screen, mutable, for scripted tests.
Sourcepub fn music(&self) -> &MusicState
pub fn music(&self) -> &MusicState
The music state machine (which track plays).
Sourcepub fn input(&self) -> &InputState<<G as GameData>::Action>
pub fn input(&self) -> &InputState<<G as GameData>::Action>
The input state (held keys, the keymap in use).
Sourcepub fn buffer(&self) -> &GlyphBuffer
pub fn buffer(&self) -> &GlyphBuffer
The last frame drawn.
Sourcepub fn quit_requested(&self) -> bool
pub fn quit_requested(&self) -> bool
Whether the game has asked to quit.
Sourcepub fn ctx_mut(&mut self) -> &mut Ctx<G>
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).
Sourcepub fn into_ctx(self) -> Ctx<G>
pub fn into_ctx(self) -> Ctx<G>
Ends the game, handing back the shared context (and so its storage).
Sourcepub fn top_screen(&self) -> Option<&'static str>
pub fn top_screen(&self) -> Option<&'static str>
Name of the top screen, or None once the last one has closed.