pub struct ResourceLoader { /* private fields */ }
Expand description
Asynchronous loader for resource chunks.
Holds some staging memory where the chunk data is written by
platform-defined asynchronous file reading utilities after
ResourceLoader::dispatch_reads
. The chunk data is read later to
initialize chunks in ResourceLoader::finish_reads
. Chunks are loaded in
the order ResourceLoader::queue_chunk
and
ResourceLoader::queue_sprite_chunk
are called.
Many asset usage related functions take this struct as a parameter for queueing up relevant chunks to be loaded.
Implementations§
Source§impl ResourceLoader
impl ResourceLoader
Sourcepub fn new(
arena: &'static LinearAllocator<'_>,
file_reader: FileReader,
resource_db: &ResourceDatabase,
) -> Option<ResourceLoader>
pub fn new( arena: &'static LinearAllocator<'_>, file_reader: FileReader, resource_db: &ResourceDatabase, ) -> Option<ResourceLoader>
Creates a resource loader around the file reader.
The file reader’s staging_buffer_size
should be at least
ResourceDatabase::largest_chunk_source
.
Sourcepub fn queue_chunk(&mut self, chunk_index: u32, resources: &ResourceDatabase)
pub fn queue_chunk(&mut self, chunk_index: u32, resources: &ResourceDatabase)
Queues the regular chunk at chunk_index
to be loaded.
Note that this doesn’t necessarily actually queue up a read operation, the chunk might not be queued for read if e.g. it’s already been loaded, it’s already been queued, or if the queue can’t fit the request.
Sourcepub fn queue_sprite_chunk(
&mut self,
chunk_index: u32,
resources: &ResourceDatabase,
)
pub fn queue_sprite_chunk( &mut self, chunk_index: u32, resources: &ResourceDatabase, )
Queues the sprite chunk at chunk_index
to be loaded.
Note that this doesn’t necessarily actually queue up a read operation, the chunk might not be queued for read if e.g. it’s already been loaded, it’s already been queued, or if the queue can’t fit the request.
Sourcepub fn dispatch_reads(&mut self, platform: &dyn Platform)
pub fn dispatch_reads(&mut self, platform: &dyn Platform)
Starts file read operations for the queued up chunk loading requests.
Sourcepub fn finish_reads(
&mut self,
resources: &mut ResourceDatabase,
platform: &dyn Platform,
max_reads: usize,
)
pub fn finish_reads( &mut self, resources: &mut ResourceDatabase, platform: &dyn Platform, max_reads: usize, )
Checks for finished file read requests and writes their results into the resource database.
The max_readers
parameter can be used to limit the time it takes to
run this function when the queue has a lot of reads to process.