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
impl EngineLimits
Sourcepub const DEFAULT: EngineLimits
pub const DEFAULT: EngineLimits
The default configuration for the engine used in its unit tests.
Trait Implementations§
Source§impl Clone for EngineLimits
impl Clone for EngineLimits
Source§fn clone(&self) -> EngineLimits
fn clone(&self) -> EngineLimits
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more