Skip to main content

Config

Struct Config 

Source
pub struct Config { /* private fields */ }
Expand description

Presentation settings for a game.

Implementations§

Source§

impl Config

Source

pub const DEFAULT_SIZE: UVec2

The window size used when none is set, in logical pixels.

Source

pub const DEFAULT_TICK_INTERVAL: Duration

The simulation step used when none is set: a sixtieth of a second.

Source

pub fn new(title: impl Into<String>) -> Self

A configuration with title and the engine’s other defaults.

Examples found in repository?
examples/input-lab.rs (line 532)
530fn main() {
531    run(
532        Config::new("Mirage: every control as an action"),
533        InputLab::init,
534    );
535}
More examples
Hide additional examples
examples/stress-preview.rs (line 105)
103fn main() {
104    run(
105        Config::new("Mirage: stress preview").with_size(1280, 720),
106        StressPreview::init,
107    );
108}
examples/post-effects.rs (line 170)
168fn main() {
169    run(
170        Config::new("Mirage: screen effects").with_size(1280, 720),
171        PostEffectEffects::init,
172    );
173}
examples/sound-lab.rs (line 115)
113fn main() {
114    run(
115        Config::new("Mirage: sound lab")
116            .with_size(1280, 720)
117            .with_assets(ASSET_FILES),
118        SoundCheck::init,
119    );
120}
examples/flock-parallelism.rs (line 758)
756fn main() {
757    run(
758        Config::new("Mirage: flock parallelism")
759            .with_size(1280, 720)
760            .with_assets([BUTTERFLY_SOURCE]),
761        Flock::init,
762    );
763}
examples/breakout-game.rs (line 159)
157fn main() {
158    run(
159        Config::new("Mirage: breakout game")
160            .with_size(1280, 720)
161            .with_assets([MODEL].into_iter().chain(SOUNDS)),
162        Breakout::init,
163    );
164}
Source

pub fn with_assets( self, sources: impl IntoIterator<Item = impl Into<String>>, ) -> Self

Loads these sources before the game starts, into the Assets its meshes build from.

Sources are file paths on the desktop, relative to the working directory the game runs in, and URLs relative to the page in the browser. Anything that fails to load, decode, or match a cataloged mesh’s slots stops startup with an error.

Examples found in repository?
examples/sound-lab.rs (line 117)
113fn main() {
114    run(
115        Config::new("Mirage: sound lab")
116            .with_size(1280, 720)
117            .with_assets(ASSET_FILES),
118        SoundCheck::init,
119    );
120}
More examples
Hide additional examples
examples/flock-parallelism.rs (line 760)
756fn main() {
757    run(
758        Config::new("Mirage: flock parallelism")
759            .with_size(1280, 720)
760            .with_assets([BUTTERFLY_SOURCE]),
761        Flock::init,
762    );
763}
examples/breakout-game.rs (line 161)
157fn main() {
158    run(
159        Config::new("Mirage: breakout game")
160            .with_size(1280, 720)
161            .with_assets([MODEL].into_iter().chain(SOUNDS)),
162        Breakout::init,
163    );
164}
examples/animation.rs (line 1048)
1044fn main() {
1045    run(
1046        Config::new("Mirage: animation")
1047            .with_size(WINDOW_WIDTH, WINDOW_HEIGHT)
1048            .with_assets([ELF_SOURCE, BUTTERFLY_SOURCE]),
1049        Scene::init,
1050    );
1051}
examples/isometric-board.rs (line 172)
168fn main() {
169    run(
170        Config::new("Mirage: isometric board")
171            .with_size(1280, 720)
172            .with_assets([SPRITE_SOURCE, CLICK_SOURCE])
173            .with_tick_interval(TICK_INTERVAL),
174        Board::init,
175    );
176}
examples/ui-fonts.rs (lines 859-864)
855fn main() {
856    run(
857        Config::new("Mirage: a game's own fonts")
858            .with_size(1280, 720)
859            .with_assets([
860                "examples/assets/pixel-operator.ttf",
861                "examples/assets/pixel-operator-mono.ttf",
862                "examples/assets/ferrum.otf",
863                "examples/assets/kenney-input-keyboard-mouse.ttf",
864            ]),
865        WatchRoom::init,
866    );
867}
Source

pub fn with_size(self, width: u32, height: u32) -> Self

Requests an initial window size in logical pixels.

The browser ignores it: the canvas fills the page, so the page sizes the game.

Examples found in repository?
examples/stress-preview.rs (line 105)
103fn main() {
104    run(
105        Config::new("Mirage: stress preview").with_size(1280, 720),
106        StressPreview::init,
107    );
108}
More examples
Hide additional examples
examples/post-effects.rs (line 170)
168fn main() {
169    run(
170        Config::new("Mirage: screen effects").with_size(1280, 720),
171        PostEffectEffects::init,
172    );
173}
examples/sound-lab.rs (line 116)
113fn main() {
114    run(
115        Config::new("Mirage: sound lab")
116            .with_size(1280, 720)
117            .with_assets(ASSET_FILES),
118        SoundCheck::init,
119    );
120}
examples/flock-parallelism.rs (line 759)
756fn main() {
757    run(
758        Config::new("Mirage: flock parallelism")
759            .with_size(1280, 720)
760            .with_assets([BUTTERFLY_SOURCE]),
761        Flock::init,
762    );
763}
examples/breakout-game.rs (line 160)
157fn main() {
158    run(
159        Config::new("Mirage: breakout game")
160            .with_size(1280, 720)
161            .with_assets([MODEL].into_iter().chain(SOUNDS)),
162        Breakout::init,
163    );
164}
examples/animation.rs (line 1047)
1044fn main() {
1045    run(
1046        Config::new("Mirage: animation")
1047            .with_size(WINDOW_WIDTH, WINDOW_HEIGHT)
1048            .with_assets([ELF_SOURCE, BUTTERFLY_SOURCE]),
1049        Scene::init,
1050    );
1051}
Source

pub fn with_antialiasing(self, antialiasing: bool) -> Self

Draws edges smoothly, over four samples per pixel; on by default.

Off draws one sample per pixel, which is less work.

Source

pub fn with_tonemap(self, tonemap: Tonemap) -> Self

Sets the curve the frame is drawn to the screen through; Tonemap::Neutral by default.

Source

pub fn with_shadow_resolution(self, texels: u32) -> Self

Sets the side of the depth map a light flagged with Light::shadow draws into, in texels; 2048 by default.

Held within 256..=4096. A larger map has denser shadow edges and costs more memory; each of a point light’s six faces is half this side. The maps live in arrays that grow to the most a frame ever requested and never give it back — casting lights hold the most memory they ever took for the whole run.

Source

pub fn with_mesh_memory(self, bytes: usize) -> Self

Sets the memory the engine keeps built mesh data in, in bytes; 256 MB by default.

Past it the engine drops the copies used least and builds them again when the game draws those meshes; a game whose meshes fit never builds one twice. It bounds the system memory the copies hold, not what the meshes take on the GPU. A mesh built through prepare is held like any other: past the cap it too can be dropped and built again.

Source

pub fn with_tick_interval(self, interval: Duration) -> Self

Sets the simulated time one Game::tick covers, held to at least Duration::from_micros(1); Config::DEFAULT_TICK_INTERVAL by default.

Examples found in repository?
examples/isometric-board.rs (line 173)
168fn main() {
169    run(
170        Config::new("Mirage: isometric board")
171            .with_size(1280, 720)
172            .with_assets([SPRITE_SOURCE, CLICK_SOURCE])
173            .with_tick_interval(TICK_INTERVAL),
174        Board::init,
175    );
176}
Source

pub fn with_double_click_interval(self, interval: Duration) -> Self

Sets how long after a press a second one still counts as a double click, which FrameContext::clicks counts by.

Without this the engine counts by what the desktop states, and by 400 milliseconds where the desktop states none; no browser states one. A windowless session counts by those 400 milliseconds until this sets another.

Source

pub fn with_canvas_id(self, id: impl Into<String>) -> Self

Draws into the page’s <canvas> with this id, instead of the one the engine creates to fill the viewport.

Ignored outside the browser; startup fails if the page has no such canvas. A page of the game’s own carries data-mirage-worker="<the worker script>" on its <body> beside that canvas, naming the script every worker of the run is started on — the game thread and each worker of the pool; startup stops naming the attribute where the page carries none.

Source

pub fn title(&self) -> &str

The window title.

Source

pub fn size(&self) -> UVec2

The requested initial window size, in logical pixels.

Source

pub fn tick_interval(&self) -> Duration

Simulated time one Game::tick covers.

Source

pub fn canvas_id(&self) -> Option<&str>

The page canvas to draw into, if the game named one.

Source

pub fn asset_sources(&self) -> &[String]

The asset sources loaded before the game starts, in load order.

Source

pub fn antialiasing(&self) -> bool

Whether edges are drawn smoothly.

Examples found in repository?
examples/material-playground.rs (line 1039)
1037    fn controls(&mut self, ctx: &mut FrameContext<'_, Self>) {
1038        let tonemap = ctx.config().tonemap();
1039        let antialiasing = ctx.config().antialiasing();
1040        let shadow_resolution = ctx.config().shadow_resolution();
1041
1042        ctx.ui(|ui| {
1043            egui::Panel::right("controls")
1044                .resizable(false)
1045                .default_size(300.0)
1046                .show(ui, |ui| {
1047                    egui::ScrollArea::vertical().show(ui, |ui| {
1048                        ui.label(
1049                            "right mouse button to look, W/A/S/D to move, \
1050                             space/shift up and down, wheel to scale speed",
1051                        );
1052                        ui.separator();
1053                        self.lighting_controls(ui);
1054                        ui.separator();
1055                        self.light_controls(ui);
1056                        ui.separator();
1057                        self.material_controls(ui);
1058                        ui.separator();
1059                        ui.label(format!(
1060                            "tone map {tonemap:?} \u{b7} antialiasing {antialiasing} \u{b7} \
1061                             shadow {shadow_resolution}px: set at startup, not live"
1062                        ));
1063                        ui.add(egui::Slider::new(&mut self.exposure, 0.1..=3.0).text("exposure"));
1064                        ui.add(egui::Slider::new(&mut self.bloom, 0.0..=1.0).text("bloom"));
1065                    });
1066                });
1067        });
1068    }
Source

pub fn tonemap(&self) -> Tonemap

The curve the frame is drawn to the screen through.

Examples found in repository?
examples/material-playground.rs (line 1038)
1037    fn controls(&mut self, ctx: &mut FrameContext<'_, Self>) {
1038        let tonemap = ctx.config().tonemap();
1039        let antialiasing = ctx.config().antialiasing();
1040        let shadow_resolution = ctx.config().shadow_resolution();
1041
1042        ctx.ui(|ui| {
1043            egui::Panel::right("controls")
1044                .resizable(false)
1045                .default_size(300.0)
1046                .show(ui, |ui| {
1047                    egui::ScrollArea::vertical().show(ui, |ui| {
1048                        ui.label(
1049                            "right mouse button to look, W/A/S/D to move, \
1050                             space/shift up and down, wheel to scale speed",
1051                        );
1052                        ui.separator();
1053                        self.lighting_controls(ui);
1054                        ui.separator();
1055                        self.light_controls(ui);
1056                        ui.separator();
1057                        self.material_controls(ui);
1058                        ui.separator();
1059                        ui.label(format!(
1060                            "tone map {tonemap:?} \u{b7} antialiasing {antialiasing} \u{b7} \
1061                             shadow {shadow_resolution}px: set at startup, not live"
1062                        ));
1063                        ui.add(egui::Slider::new(&mut self.exposure, 0.1..=3.0).text("exposure"));
1064                        ui.add(egui::Slider::new(&mut self.bloom, 0.0..=1.0).text("bloom"));
1065                    });
1066                });
1067        });
1068    }
Source

pub fn shadow_resolution(&self) -> u32

The side of one light’s depth map, in texels.

Examples found in repository?
examples/material-playground.rs (line 1040)
1037    fn controls(&mut self, ctx: &mut FrameContext<'_, Self>) {
1038        let tonemap = ctx.config().tonemap();
1039        let antialiasing = ctx.config().antialiasing();
1040        let shadow_resolution = ctx.config().shadow_resolution();
1041
1042        ctx.ui(|ui| {
1043            egui::Panel::right("controls")
1044                .resizable(false)
1045                .default_size(300.0)
1046                .show(ui, |ui| {
1047                    egui::ScrollArea::vertical().show(ui, |ui| {
1048                        ui.label(
1049                            "right mouse button to look, W/A/S/D to move, \
1050                             space/shift up and down, wheel to scale speed",
1051                        );
1052                        ui.separator();
1053                        self.lighting_controls(ui);
1054                        ui.separator();
1055                        self.light_controls(ui);
1056                        ui.separator();
1057                        self.material_controls(ui);
1058                        ui.separator();
1059                        ui.label(format!(
1060                            "tone map {tonemap:?} \u{b7} antialiasing {antialiasing} \u{b7} \
1061                             shadow {shadow_resolution}px: set at startup, not live"
1062                        ));
1063                        ui.add(egui::Slider::new(&mut self.exposure, 0.1..=3.0).text("exposure"));
1064                        ui.add(egui::Slider::new(&mut self.bloom, 0.0..=1.0).text("bloom"));
1065                    });
1066                });
1067        });
1068    }
Source

pub fn mesh_memory(&self) -> usize

Memory the engine keeps built mesh data in, in bytes.

Trait Implementations§

Source§

impl Clone for Config

Source§

fn clone(&self) -> Self

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 Debug for Config

Source§

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

Formats the value using the given formatter. 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 + Sync + Send>

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

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

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

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

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

Initializes a with the given initializer. Read more
Source§

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

Dereferences the given pointer. Read more
Source§

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

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

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

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

Source§

impl<T> SerializableAny for T
where T: 'static + Any + Clone + for<'a> Send + Sync,

Source§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

Source§

fn simd_from(_simd: S, value: T) -> T

Source§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

Source§

fn simd_into(self, simd: S) -> T

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