Struct ggez::context::Context

source ·
pub struct Context {
    pub fs: Filesystem,
    pub gfx: GraphicsContext,
    pub time: TimeContext,
    pub audio: AudioContext,
    pub keyboard: KeyboardContext,
    pub mouse: MouseContext,
    pub gamepad: GamepadContext,
    pub continuing: bool,
    pub quit_requested: bool,
    /* private fields */
}
Expand description

A Context is an object that holds on to global resources. It basically tracks hardware state such as the screen, audio system, timers, and so on. Generally this type can not be shared/sent between threads and only one Context can exist at a time. Trying to create a second one will fail. It is fine to drop a Context and create a new one, but this will also close and re-open your game’s window.

Most functions that interact with the hardware, for instance drawing things, playing sounds, or loading resources will need to access one, or rarely even two, of its sub-contexts. It is an error to create some type that relies upon a Context, such as Image, and then drop the Context and try to draw the old Image with the new Context.

The fields in this struct used to be basically undocumented features, only here to make it easier to debug, or to let advanced users hook into the guts of ggez and make it do things it normally can’t. Now that ggez’s module-level functions, taking the whole Context have been deprecated, calling their methods directly is recommended.

Fields§

§fs: Filesystem

Filesystem state.

§gfx: GraphicsContext

Graphics state.

§time: TimeContext

Timer state.

§audio: AudioContext

Audio context.

§keyboard: KeyboardContext

Keyboard input context.

§mouse: MouseContext

Mouse input context.

§gamepad: GamepadContext

Gamepad input context.

§continuing: bool

Controls whether or not the event loop should be running. This is internally controlled by the outcome of quit_event, requested through event::request_quit().

§quit_requested: bool

Whether or not a quit_event has been requested. Set this with ggez::event::request_quit().

It’s exposed here for people who want to roll their own event loop.

Implementations§

source§

impl Context

source

pub fn request_quit(&mut self)

Attempts to terminate the ggez::event::run() loop by requesting a quit_event at the very start of the next frame. If this event returns Ok(false), then Context.continuing is set to false and the loop breaks.

Trait Implementations§

source§

impl Debug for Context

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Has<AudioContext> for Context

source§

fn retrieve(&self) -> &AudioContext

Method to retrieve the context type.
source§

impl Has<Filesystem> for Context

source§

fn retrieve(&self) -> &Filesystem

Method to retrieve the context type.
source§

impl Has<GraphicsContext> for Context

source§

fn retrieve(&self) -> &GraphicsContext

Method to retrieve the context type.
source§

impl HasMut<GraphicsContext> for Context

source§

fn retrieve_mut(&mut self) -> &mut GraphicsContext

Method to retrieve the context type as mutable.

Auto Trait Implementations§

§

impl !RefUnwindSafe for Context

§

impl !Send for Context

§

impl !Sync for Context

§

impl Unpin for Context

§

impl !UnwindSafe for Context

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

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> Has<T> for T

source§

fn retrieve(&self) -> &T

Method to retrieve the context type.
source§

impl<T> HasMut<T> for T

source§

fn retrieve_mut(&mut self) -> &mut T

Method to retrieve the context type as mutable.
source§

impl<T, U> Into<U> for Twhere 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<F, T> IntoSample<T> for Fwhere T: FromSample<F>,

§

fn into_sample(self) -> T

§

impl<T> Pointable for T

§

const ALIGN: usize = mem::align_of::<T>()

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

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

§

fn to_sample_(self) -> U

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.
§

impl<T> Upcast<T> for T

§

fn upcast(&self) -> Option<&T>

§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

§

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