pub struct InitContext<'a, G: Game> { /* private fields */ }Expand description
The work the startup closure run takes may do.
Implementations§
Source§impl<'a, G: Game> InitContext<'a, G>
impl<'a, G: Game> InitContext<'a, G>
Sourcepub fn startup(&mut self) -> &mut Startup<'a>
pub fn startup(&mut self) -> &mut Startup<'a>
The startup work that is typed by no vocabulary of the game’s own.
Required if you want to start two games the same way: Startup is
one type whatever the game, so code shared between them takes
&mut Startup<'_>.
Examples found in repository?
1007 fn init(ctx: &mut InitContext<'_, Keep>) -> Result<Self, Error> {
1008 let startup = ctx.startup();
1009 let gem_taken = startup.saved(Flag::GemTaken);
1010 let area = if startup.saved(Flag::InCave) {
1011 Area::Cave
1012 } else {
1013 Area::Overworld
1014 };
1015 let position = Vec3::new(
1016 startup.saved(Position::X) as f32,
1017 0.0,
1018 startup.saved(Position::Z) as f32,
1019 );
1020
1021 Ok(Self {
1022 area,
1023 position,
1024 previous: position,
1025 facing: Facing::Toward,
1026 walk_ticks: 0,
1027 simulated: Duration::ZERO,
1028 door_opening: gem_taken,
1029 swing_ticks: if gem_taken { DOOR_SWING_TICKS } else { 0 },
1030 gem_taken,
1031 ghost: 0.0,
1032 reset_requested: false,
1033 })
1034 }More examples
602 fn init(ctx: &mut InitContext<'_, Self>) -> Result<Self, Error> {
603 let startup = ctx.startup();
604 let mut fonts = egui::FontDefinitions::default();
605 for (family, names) in [
606 (egui::FontFamily::Proportional, &[PROPORTIONAL_FONT][..]),
607 (egui::FontFamily::Monospace, &[MONOSPACE_FONT][..]),
608 (
609 egui::FontFamily::Name(DISPLAY_FAMILY.into()),
610 &[DISPLAY_FONT][..],
611 ),
612 (
613 egui::FontFamily::Name(PIXEL_ONLY_FAMILY.into()),
614 &[PROPORTIONAL_FONT][..],
615 ),
616 (
617 egui::FontFamily::Name(PROMPT_FAMILY.into()),
618 &[PROMPT_FONT, PROPORTIONAL_FONT][..],
619 ),
620 ] {
621 install_family(&mut fonts, startup, family, names)?;
622 }
623 startup.set_fonts(fonts)?;
624
625 Ok(Self {
626 elapsed: Duration::ZERO,
627 orbit: Orbit::default(),
628 hailed: None,
629 dialogue: None,
630 sheet_open: false,
631 })
632 }Sourcepub fn duration(&mut self, sound: G::Sounds) -> Duration
pub fn duration(&mut self, sound: G::Sounds) -> Duration
How long sound plays for at its own pitch: the whole clip, before
any trim.
Required if you want to time a game against a sound. Every value the vocabulary catalogs is built before this runs, and a streamed one reports what the decode at startup measured.
Sourcepub fn durations(&mut self) -> HashMap<G::Sounds, Duration>
pub fn durations(&mut self) -> HashMap<G::Sounds, Duration>
How long each value that the vocabulary catalogs plays for, keyed by the value.
Required if you want to time a game against a whole vocabulary. A
value the catalog leaves out is absent from the map; read that one
through duration.
Examples found in repository?
412 fn init(ctx: &mut InitContext<'_, SoundCheck>) -> Result<Self, Error> {
413 let durations = ctx.durations();
414
415 let picked = Sound::Bounce;
416 let trim_end = durations.get(&picked).copied().unwrap_or_default();
417
418 Ok(Self {
419 master_volume: 1.0,
420
421 picked,
422 one_shot_gain: 1.0,
423 one_shot_pitch: 1.0,
424 one_shot_fade: SoundCue::<Sound>::DEFAULT_FADE.as_secs_f32(),
425 trim_start: 0.0,
426 trim_end: trim_end.as_secs_f32(),
427 one_shot_loop_from: 0.0,
428
429 theme_on: false,
430 menu_on: false,
431 pulse_on: false,
432 cue_fade: 1.0,
433
434 merge_demo: false,
435 ring_demo: false,
436
437 player: Vec2::ZERO,
438 player_prev: Vec2::ZERO,
439 sources: [
440 Source::new(-2.5, -2.0, Sound::Bounce, 4.0, false),
441 Source::new(2.5, -2.0, Sound::Serve, 4.0, false),
442 Source::new(0.0, 2.8, Sound::Theme, 7.0, true),
443 ],
444 dragging: None,
445
446 durations,
447 })
448 }Sourcepub fn prepare<M>(&mut self, mesh: M)
pub fn prepare<M>(&mut self, mesh: M)
Builds and uploads mesh now, instead of on its first draw; the
copy is then held like any drawn mesh’s under
Config::with_mesh_memory, and no longer than that.
Takes a mesh of Game::Meshes and no other.
Examples found in repository?
367 fn init(ctx: &mut InitContext<'_, Board>) -> Result<Self, Error> {
368 for &(_, _, seed, _) in &ROCKS {
369 ctx.prepare(Rock { seed });
370 }
371
372 let (sprite_lift, _) = unit_geometry(Turn::Sprite);
373 let (block_lift, _) = unit_geometry(Turn::Block);
374 Ok(Self {
375 sprite: Unit::resting((1, 1), sprite_lift),
376 block: Unit::resting((BOARD_TILES - 2, BOARD_TILES - 2), block_lift),
377 turn: Turn::Sprite,
378 selected: false,
379 })
380 }Auto Trait Implementations§
impl<'a, G> !RefUnwindSafe for InitContext<'a, G>
impl<'a, G> !UnwindSafe for InitContext<'a, G>
impl<'a, G> Freeze for InitContext<'a, G>
impl<'a, G> Send for InitContext<'a, G>
impl<'a, G> Sync for InitContext<'a, G>
impl<'a, G> Unpin for InitContext<'a, G>
impl<'a, G> UnsafeUnpin for InitContext<'a, G>where
&'a mut MeshCatalog<<G as Game>::Meshes>: UnsafeUnpin,
&'a mut Sounding<<G as Game>::Sounds>: UnsafeUnpin,
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.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
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