pub struct Config { /* private fields */ }Expand description
Presentation settings for a game.
Implementations§
Source§impl Config
impl Config
Sourcepub const DEFAULT_SIZE: UVec2
pub const DEFAULT_SIZE: UVec2
The window size used when none is set, in logical pixels.
Sourcepub const DEFAULT_TICK_INTERVAL: Duration
pub const DEFAULT_TICK_INTERVAL: Duration
The simulation step used when none is set: a sixtieth of a second.
Sourcepub fn new(title: impl Into<String>) -> Self
pub fn new(title: impl Into<String>) -> Self
A configuration with title and the engine’s other defaults.
Examples found in repository?
More examples
Sourcepub fn with_assets(
self,
sources: impl IntoIterator<Item = impl Into<String>>,
) -> Self
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?
More examples
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}Sourcepub fn with_size(self, width: u32, height: u32) -> Self
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?
More examples
Sourcepub fn with_antialiasing(self, antialiasing: bool) -> Self
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.
Sourcepub fn with_tonemap(self, tonemap: Tonemap) -> Self
pub fn with_tonemap(self, tonemap: Tonemap) -> Self
Sets the curve the frame is drawn to the screen through;
Tonemap::Neutral by default.
Sourcepub fn with_shadow_resolution(self, texels: u32) -> Self
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.
Sourcepub fn with_mesh_memory(self, bytes: usize) -> Self
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.
Sourcepub fn with_tick_interval(self, interval: Duration) -> Self
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.
Sourcepub fn with_double_click_interval(self, interval: Duration) -> Self
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.
Sourcepub fn with_canvas_id(self, id: impl Into<String>) -> Self
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.
Sourcepub fn tick_interval(&self) -> Duration
pub fn tick_interval(&self) -> Duration
Simulated time one Game::tick covers.
Sourcepub fn asset_sources(&self) -> &[String]
pub fn asset_sources(&self) -> &[String]
The asset sources loaded before the game starts, in load order.
Sourcepub fn antialiasing(&self) -> bool
pub fn antialiasing(&self) -> bool
Whether edges are drawn smoothly.
Examples found in repository?
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 }Sourcepub fn tonemap(&self) -> Tonemap
pub fn tonemap(&self) -> Tonemap
The curve the frame is drawn to the screen through.
Examples found in repository?
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 }Sourcepub fn shadow_resolution(&self) -> u32
pub fn shadow_resolution(&self) -> u32
The side of one light’s depth map, in texels.
Examples found in repository?
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 }Sourcepub fn mesh_memory(&self) -> usize
pub fn mesh_memory(&self) -> usize
Memory the engine keeps built mesh data in, in bytes.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Config
impl RefUnwindSafe for Config
impl Send for Config
impl Sync for Config
impl Unpin for Config
impl UnsafeUnpin for Config
impl UnwindSafe for Config
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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