Skip to main content

AppConfig

Struct AppConfig 

Source
pub struct AppConfig {
Show 23 fields pub title: String, pub width: u32, pub height: u32, pub vsync: bool, pub fixed_timestep: Option<Duration>, pub max_frame_time: Duration, pub asset_root: PathBuf, pub web_preload: Option<Vec<String>>, pub canvas_id: Option<String>, pub random_seed: u64, pub depth_format: Option<TextureFormat>, pub msaa_samples: u32, pub touch_emulates_mouse: bool, pub required_limits: Option<Limits>, pub required_features: Features, pub preferred_limits: Option<Limits>, pub preferred_features: Features, pub continue_without_requirements: bool, pub device_hook: Option<Arc<dyn Fn(&Adapter, &mut DeviceDescriptor<Option<&str>>) + Send + Sync>>, pub virtual_resolution: Option<(u32, u32)>, pub scale_mode: ScaleMode, pub scale_filter: ScaleFilter, pub border_color: Color,
}
Expand description

Runtime configuration passed to run.

Construct it with ..Default::default() so new fields added in future minor releases don’t break your call site: AppConfig { title: "game".into(), ..Default::default() }.

Fields§

§title: String§width: u32§height: u32§vsync: bool§fixed_timestep: Option<Duration>

Some(step) calls update with a fixed dt of step: zero, one or several times per frame, as many as the real time elapsed allows. None (default) calls it once per frame with the frame’s dt. Either way render runs once per frame; with a fixed step, Time::alpha says how far the frame is into the next step, for interpolating motion between steps.

Leave this None if the game steps a simulation itself, e.g. a sillyecs world whose apply_system_phases runs its own fixed phases from real time; otherwise those fixed phases nest inside the toolkit’s steps.

Input edges (key_pressed, mouse_delta, …) are seen by the first update of a frame and carried over to the next frame when no step ran, so presses aren’t dropped.

§max_frame_time: Duration

Upper bound on the time one frame advances the game (default 250 ms). After a long frame - the window was dragged, the tab was in the background, a breakpoint hit - the game slows down for that frame instead of fast-forwarding through the gap: dt is capped at this, and with a fixed timestep at most max_frame_time / step updates run. Time::delta still reports the real frame time. Duration::ZERO disables the cap.

§asset_root: PathBuf

Asset root directory. Defaults to ./assets. On the web it is a URL path relative to the page, and the files listed in its manifest.txt are fetched before Game::init.

§web_preload: Option<Vec<String>>

Web only: asset paths to preload instead of reading manifest.txt. Ignored natively.

§canvas_id: Option<String>

Web only: id of an existing <canvas> to render into. None (default) appends a new canvas to <body>. Ignored natively.

§random_seed: u64

Seed for deterministic runtime RNG (ctx.rng).

§depth_format: Option<TextureFormat>

Depth attachment format. None (default) keeps the 2D path depth-less; Some(fmt) (e.g. wgpu::TextureFormat::Depth32Float) allocates a depth buffer for depth-tested rendering. The built-in 2D pipelines never write depth, so enabling it is harmless.

§msaa_samples: u32

MSAA sample count for the surface. 1 (default) disables MSAA; 2/4/8 enable it (the value must be supported by the adapter for the surface format).

§touch_emulates_mouse: bool

Let the first finger on a touchscreen act as the mouse: it moves the cursor and presses, holds and releases MouseButton::Left, so a game written for the mouse also works on a phone. Off by default; toggle later with Input::set_touch_emulates_mouse, which has the details. No effect on Windows, where the OS already does this.

§required_limits: Option<Limits>

Device limits the game needs beyond the toolkit’s own, for compute or render passes it records itself through ctx.gfx.device(). None (default) requests only what the toolkit needs (Limits::downlevel_defaults(), or Limits::default() with the vector feature); with Some, each limit is the better of the two, e.g. Some(wgpu::Limits { max_storage_buffers_per_shader_stage: 8, ..wgpu::Limits::downlevel_defaults() }). Init fails with a DeviceRequirementsError naming any limit the adapter can’t provide. WebGL2 has no compute at all; to fall back gracefully instead, use Self::preferred_limits and check Graphics::supports_compute in Game::init, or set Self::continue_without_requirements.

§required_features: Features

Optional device features the game needs (SHADER_F16, TIMESTAMP_QUERY, …). Default empty. Missing ones fail init like missing limits.

§preferred_limits: Option<Limits>

Device limits the game would like but can do without: each is requested up to what the adapter offers, so init never fails on them. Read what you got from ctx.gfx.device().limits(). E.g. Some(wgpu::Limits { max_storage_buffers_per_shader_stage: 8, ..wgpu::Limits::downlevel_defaults() }) gets 8 on WebGPU and native and stays at WebGL2’s 0 there. See GraphicsConfig::preferred_limits.

§preferred_features: Features

Device features the game would like but can do without; enabled where the adapter has them. Check ctx.gfx.device().features().

§continue_without_requirements: bool

true: when the adapter can’t meet required_limits / required_features, start anyway without them and report it through Graphics::unmet_requirements, so Game::init can draw a “WebGPU required” screen. false (default): init fails.

§device_hook: Option<Arc<dyn Fn(&Adapter, &mut DeviceDescriptor<Option<&str>>) + Send + Sync>>

Last look at the device request, with the adapter at hand, for decisions the fields above can’t express; see DeviceHook.

§virtual_resolution: Option<(u32, u32)>

Draw into a fixed-size canvas of (width, height) pixels (e.g. (320, 180)) and scale it onto the window, for crisp pixel art. None (default) draws straight into the window. With a canvas, ctx.gfx.size(), the cameras and everything the painter draws use canvas pixels, and so do Input::mouse_pos and touch positions; see GraphicsConfig::virtual_resolution.

§scale_mode: ScaleMode

How the canvas is scaled onto the window: ScaleMode::Integer (default; whole multiples, the rest is border), Fit (fractional) or Stretch.

§scale_filter: ScaleFilter

Nearest (default) or linear filtering when scaling the canvas.

§border_color: Color

Colour of the border around the canvas (default black).

Implementations§

Source§

impl AppConfig

Source

pub fn graphics_config(&self) -> GraphicsConfig

The GraphicsConfig this config creates the renderer with.

Trait Implementations§

Source§

impl Clone for AppConfig

Source§

fn clone(&self) -> AppConfig

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Default for AppConfig

Source§

fn default() -> AppConfig

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert 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>

Convert 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)

Convert &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)

Convert &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> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync> ⓘ

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

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.

Source§

impl<S> FromSample<S> for S

Source§

fn from_sample_(s: S) -> S

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.

Source§

impl<F, T> IntoSample<T> for F
where T: FromSample<F>,

Source§

fn into_sample(self) -> T

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

fn to_sample_(self) -> U

Source§

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

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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

impl<T> Upcast<T> for T

Source§

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

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more