Plasma Engine  2.0
Loading...
Searching...
No Matches
plResourceLoaderFromMemory Class Reference

A resource loader that is mainly used to update a resource on the fly with custom data, e.g. in an editor. More...

#include <ResourceTypeLoader.h>

Inheritance diagram for plResourceLoaderFromMemory:

Public Member Functions

virtual plResourceLoadData OpenDataStream (const plResource *pResource) override
 Override this function to implement the resource loading.
 
virtual void CloseDataStream (const plResource *pResource, const plResourceLoadData &loaderData) override
 This function is called when the resource has been updated with the data from the resource loader and the loader can deallocate any temporary memory.
 
virtual bool IsResourceOutdated (const plResource *pResource) const override
 If this function returns true, a resource is unloaded and loaded again to update its content.
 

Public Attributes

plString m_sResourceDescription
 
plTimestamp m_ModificationTimestamp
 
plDefaultMemoryStreamStorage m_CustomData
 

Detailed Description

A resource loader that is mainly used to update a resource on the fly with custom data, e.g. in an editor.

Use like this: Allocate a plResourceLoaderFromMemory instance on the heap, using PL_DEFAULT_NEW and store the result in a plUniquePtr<plResourceTypeLoader>. Then set the description, the modification time (simply use plTimestamp::CurrentTimestamp()), and the custom data. Use a plMemoryStreamWriter to write your custom data. Make sure to write EXACTLY the same format that the targeted resource type would read, including all data that would typically be written by outside code, e.g. the default plResourceLoaderFromFile additionally writes the path to the resource at the start of the stream. If such data is usually present in the stream, you must write this yourself. Then call plResourceManager::UpdateResourceWithCustomLoader(), specify the target resource and std::move your created loader in there.

Member Function Documentation

◆ CloseDataStream()

void plResourceLoaderFromMemory::CloseDataStream ( const plResource * pResource,
const plResourceLoadData & loaderData )
overridevirtual

This function is called when the resource has been updated with the data from the resource loader and the loader can deallocate any temporary memory.

Implements plResourceTypeLoader.

◆ IsResourceOutdated()

bool plResourceLoaderFromMemory::IsResourceOutdated ( const plResource * pResource) const
overridevirtual

If this function returns true, a resource is unloaded and loaded again to update its content.

Call plResource::GetLoadedFileModificationTime() to query the file modification time that was returned through plResourceLoadData::m_LoadedFileModificationDate.

Reimplemented from plResourceTypeLoader.

◆ OpenDataStream()

plResourceLoadData plResourceLoaderFromMemory::OpenDataStream ( const plResource * pResource)
overridevirtual

Override this function to implement the resource loading.

This function should take the information from pResource, e.g. which file to load, and do the loading work. It should allocate temporary storage for the loaded data and encode it in a memory stream, such that the resource can read all necessary information from the stream.

See also
plResourceLoadData

Implements plResourceTypeLoader.


The documentation for this class was generated from the following files: