Struct ResourceLoader

Source
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

Source

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.

Source

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.

Source

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.

Source

pub fn dispatch_reads(&mut self, platform: &dyn Platform)

Starts file read operations for the queued up chunk loading requests.

Source

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.

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