Struct EngineLimits

Source
pub struct EngineLimits {
    pub frame_arena_size: usize,
    pub resource_database_loaded_chunks_count: u32,
    pub resource_database_loaded_sprite_chunks_count: u32,
    pub resource_database_read_queue_capacity: usize,
    pub resource_database_buffer_size: usize,
    pub audio_channel_count: usize,
    pub audio_concurrent_sounds_count: usize,
    pub audio_window_length: usize,
}
Expand description

Parameters affecting the memory usage of the engine, used in Engine::new.

Note that while this does cover most persistent memory allocations made by the engine during initialization, it doesn’t (currently) cover everything. For example, the memory required by asset metadata is entirely dependent on the amount of assets in the resource database.

Fields§

§frame_arena_size: usize

The size of the frame arena allocator, in bytes. The frame arena is used for per-frame memory allocations in rendering, audio playback, and game-specific uses.

Defaults to 8 MiB (8 * 1024 * 1024).

§resource_database_loaded_chunks_count: u32

The maximum amount of concurrently loaded resource chunks. This count, multiplied by CHUNK_SIZE, is the amount of bytes allocated for non-VRAM based asset memory, like audio clips being played.

Defaults to 128.

§resource_database_loaded_sprite_chunks_count: u32

The maximum amount of concurrently loaded sprite chunks. This, depending on the platform, will control the amount of VRAM required by the engine. Each sprite chunk’s memory requirements depend on the platform, but each chunk contains sprite data with the format and resolution defined by SPRITE_CHUNK_FORMAT and SPRITE_CHUNK_DIMENSIONS.

Defaults to 1024.

Rationale for the default, just for reference: 1024 sprite chunks with 128x128 resolution, if stored in a tightly packed sprite atlas, would fit exactly in 4096x4096, which is a low enough resolution to be supported pretty much anywhere with hardware acceleration (Vulkan’s minimum allowed limit is 4096, so any Vulkan-backed platform could provide this).

§resource_database_read_queue_capacity: usize

The maximum amount of queued resource database reading operations. This will generally increase disk read performance by having file reading operations always queued up, but costs memory and might cause lagspikes if there’s too many chunks to load during a particular frame.

Defaults to 128.

§resource_database_buffer_size: usize

The size of the buffer used to read data from the resource database, in bytes. Must be at least ResourceDatabase::largest_chunk_source, but ideally many times larger, to avoid capping out the buffer before the read queue is even full.

Defaults to 8 MiB (8 * 1024 * 1024).

§audio_channel_count: usize

The amount of channels the engine’s Mixer has. Each channel can be individually controlled volume-wise, and all played sounds play on a specific channel.

Tip: create an enum for your game’s audio channels, and use that enum when playing back sounds, to have easily refactorable and semantically meaningful channels. This count should cover all of the enum variants, e.g. 3 for an enum with 3 variants for 0, 1, and 2.

Defaults to 1.

§audio_concurrent_sounds_count: usize

The maximum amount of concurrently playing sounds. If more than this amount of sounds are playing at a time, new sounds might displace old sounds, or be ignored completely, depending on the parameters of the sound playback function.

Defaults to 64.

§audio_window_length: usize

The amount of samples of audio rendered each frame. Note that this isn’t a traditional “buffer size”, where increasing this would increase latency: the engine can render a lot of audio ahead of time, to avoid audio cutting off even if the game has lagspikes. In a normal 60 FPS situation, this length could be 48000, but only the first 800 samples would be used each frame. The sample rate of the audio is AUDIO_SAMPLE_RATE.

Note that this window should be at least long enough to cover audio for two frames, to avoid audio cutting off due to the platform’s audio callbacks outpacing the once-per-frame audio rendering we do. For a pessimistic 30 FPS, this would be 3200. The default length is half a second, i.e. AUDIO_SAMPLE_RATE / 2.

Implementations§

Source§

impl EngineLimits

Source

pub const DEFAULT: EngineLimits

The default configuration for the engine used in its unit tests.

Trait Implementations§

Source§

impl Clone for EngineLimits

Source§

fn clone(&self) -> EngineLimits

Returns a copy of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Default for EngineLimits

Source§

fn default() -> Self

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

impl Copy for EngineLimits

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

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> 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> TryFrom<U> for T
where U: Into<T>,

Source§

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