libultraship
Reimplementations of libultra (N64 SDK) functions for modern hardware
Loading...
Searching...
No Matches
Ship::ResourceFactory Class Referenceabstract

Abstract factory interface for deserializing a specific resource type and format. More...

#include <ResourceFactory.h>

Inheritance diagram for Ship::ResourceFactory:
[legend]

Public Member Functions

virtual std::shared_ptr< IResourceReadResource (std::shared_ptr< File > file, std::shared_ptr< ResourceInitData > initData)=0
 Deserializes a File into an IResource.
 

Protected Member Functions

virtual bool FileHasValidFormatAndReader (std::shared_ptr< File > file, std::shared_ptr< Ship::ResourceInitData > initData)=0
 Validates that the file's format tag and reader type are compatible with this factory.
 

Detailed Description

Abstract factory interface for deserializing a specific resource type and format.

Implement this class to add support for a new resource type. Register the implementation with ResourceLoader::RegisterResourceFactory() so that it is invoked automatically when a matching file is encountered.

Example skeleton:

class TextureFactory : public Ship::ResourceFactory {
public:
std::shared_ptr<Ship::IResource> ReadResource(std::shared_ptr<Ship::File> file,
std::shared_ptr<Ship::ResourceInitData> initData) override;
protected:
bool FileHasValidFormatAndReader(std::shared_ptr<Ship::File> file,
std::shared_ptr<Ship::ResourceInitData> initData) override;
};
Abstract factory interface for deserializing a specific resource type and format.
Definition ResourceFactory.h:27

Member Function Documentation

◆ FileHasValidFormatAndReader()

virtual bool Ship::ResourceFactory::FileHasValidFormatAndReader ( std::shared_ptr< File file,
std::shared_ptr< Ship::ResourceInitData initData 
)
protectedpure virtual

Validates that the file's format tag and reader type are compatible with this factory.

ResourceLoader calls this before invoking ReadResource(). Return false to signal that the file is malformed or in an unexpected format, which will abort loading.

Parameters
fileRaw file data to inspect.
initDataMetadata from the file header.
Returns
true if the file is valid and can be processed by this factory.

Implemented in Ship::ResourceFactoryBinary, and Ship::ResourceFactoryXML.

◆ ReadResource()

virtual std::shared_ptr< IResource > Ship::ResourceFactory::ReadResource ( std::shared_ptr< File file,
std::shared_ptr< ResourceInitData initData 
)
pure virtual

Deserializes a File into an IResource.

Called by ResourceLoader after it has selected this factory as the best match for the file's (format, type, version) triple.

Parameters
fileRaw file data with a populated Reader (BinaryReader or XMLDocument).
initDataMetadata parsed from the file header.
Returns
Fully constructed IResource, or nullptr if deserialization failed.

Implemented in Fast::ResourceFactoryBinaryDisplayListV0, Fast::ResourceFactoryXMLDisplayListV0, Fast::ResourceFactoryBinaryLightV0, Fast::ResourceFactoryBinaryMatrixV0, Fast::ResourceFactoryBinaryTextureV0, Fast::ResourceFactoryBinaryTextureV1, Fast::ResourceFactoryBinaryVertexV0, and Fast::ResourceFactoryXMLVertexV0.


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