NSMBW-Decomp
A decompilation of New Super Mario Bros. Wii
Loading...
Searching...
No Matches
dRes_c Class Reference

#include <game/bases/d_res.hpp>

Description

An archive resource management class.

The dRes_c class manages resource archives ( .arc files). It does so by storing multiple archive holders. The class is instantiated automatically by dResMng_c, whose usage is recommended for basic resource loading.

Path Notes

Resource paths are subject to the following restrictions:

  • The .arc extension is appended automatically to archive names and therefore must not be included.
  • The / character is prepended automatically to archive paths and therefore must not be included.
  • Archive names (excluding the file extension) cannot exceed 32 characters.
  • Full paths to archive files (including the appended extension and prepended slash) cannot exceed 80 characters.
  • Full paths to resources inside an archive should not exceed 250 characters.

Opening Archives

Use the setRes function to open an archive. For opening multiple archives at once, see the dResMng_c equivalent. Only up to mNumArcs archives can be open at the same time.

Note
Many kinds of assets are loaded automatically, therefore doing so manually is not necessary. These include:
  • Stages
  • Tilesets
  • Backgrounds
  • Actor resources
  • Worldmaps and their resources

Notes for BRRES Resources

The game automatically handles the initialization of any BRRES files within an archive, as long as their parent directory is named g3d .

Notes for Layout Resources

For layout archives, it's recommended to use the dedicated LytBase_c functions instead of this class.

Loading Archives

Use the syncAllRes function to perform the actual archive file loading. The function will return true until all opened archives are loaded successfully.

Getting Archive Resources

Use the getRes function to obtain a resource inside a specific archive once it has been loaded. Overloads are provided to obtain the size of the resource and optionally detect compressed resources.

If the file could not be found under the archive, a warning is printed to the console. Use getResSilently if this behaviour is undesired (such as with an optional file).

Note
No overload for getResSilently with compression support is available.

Compressed Resources

While the getRes function can detect compression and return the decompressed data size, it does not actually perform the decompression itself. This can be achieved by calling the copyRes function with the compressed data and the compression type returned by the previous function, plus a buffer to store the decompressed data into.

Note
Only LZ77 compression is supported.

Deleting Archives

Use the deleteRes function to mark an archive as no longer needed by the calling entity. This ensures that archives no longer in use are properly disposed of.

Unused Content

  • mSetCallback is an unused callback for when an archive is added to the class. It was probably used to debug resource loading.

Definition at line 77 of file d_res.hpp.

Classes

class  callback_c
 A callback class for processing resources. More...
 
class  info_c
 An archive holder. More...
 
class  searchCallback_c
 A callback class for EGG::Archive::searchInside. More...
 

Public Member Functions

 dRes_c ()
 Constructs a new manager.
 
 ~dRes_c ()
 Destroys the manager.
 
bool init (u16 maxCount, callback_c *callback)
 Initializes the manager by allocating the archive holders and setting the callback.
 
bool setRes (const char *arcName, const char *containingFolder, u8 allocDir, EGG::Heap *heap)
 Schedules an archive for loading.
 
bool deleteRes (const char *arcName)
 Marks an archive as no longer needed.
 
void * getRes (const char *arcName, const char *resPath) const
 Gets a resource.
 
void * getRes (const char *arcName, const char *resPath, unsigned long *size) const
 Gets a resource.
 
void * getRes (const char *arcName, const char *resPath, unsigned long *size, int *compressionType) const
 Gets a resource which may optionally be compressed.
 
void * getResSilently (const char *arcName, const char *resPath) const
 Gets a resource without logging a message if the resource is not found.
 
void * getResSilently (const char *arcName, const char *resPath, unsigned long *size) const
 Gets a resource without logging a message if the resource is not found.
 
bool syncAllRes ()
 Attempts to load the resources of an archive that has finished loading since the last call to this function. The callback is executed on all files and folders.
 

Static Public Member Functions

static void copyRes (const void *from, void *to, int size)
 Copies an uncompressed resource.
 
static void copyRes (const void *from, void *to, int size, int compressionType)
 Copies an optionally compressed resource.
 

Private Member Functions

info_cgetResInfo (const char *arcName) const
 Gets the holder for an archive.
 
info_cgetResInfoLoaded (const char *arcName) const
 Gets the holder for a loaded archive.
 
info_cnewResInfo ()
 Gets a free archive holder that can be used to store an archive reference.
 

Private Attributes

info_cmpArcInfos
 An array of archive holders.
 
u16 mNumArcs
 The number of archive holders.
 
callback_cmpCallback
 The callback for when a resource is loaded.
 

Static Private Attributes

static void(* mSetCallback )(const char *arcName, EGG::Heap *heap)
 [Unused]. The callback for when an archive is scheduled for loading.
 

Constructor & Destructor Documentation

◆ dRes_c()

dRes_c::dRes_c ( )

Constructs a new manager.

Definition at line 7 of file d_res.cpp.

◆ ~dRes_c()

dRes_c::~dRes_c ( )

Destroys the manager.

Definition at line 13 of file d_res.cpp.

Member Function Documentation

◆ init()

bool dRes_c::init ( u16 maxCount,
callback_c * callback )

Initializes the manager by allocating the archive holders and setting the callback.

Parameters
maxCountThe number of archive holders to allocate.
callbackThe resource loaded callback.
Returns
Whether the initialization was successful.

Definition at line 21 of file d_res.cpp.

◆ setRes()

bool dRes_c::setRes ( const char * arcName,
const char * containingFolder,
u8 allocDir,
EGG::Heap * heap )

Schedules an archive for loading.

Parameters
arcNameThe name of the archive to load. See the path notes.
containingFolderThe path to the folder the archive is in. See the path notes.
allocDirThe allocation direction. See MEMExpHeapAllocDir.
heapThe heap to load the archive into, or nullptr to use the default archive heap.
Returns
Whether the operation was successful.

Definition at line 32 of file d_res.cpp.

◆ deleteRes()

bool dRes_c::deleteRes ( const char * arcName)

Marks an archive as no longer needed.

Parameters
arcNameThe name of the archive to unload. See the path notes.
Returns
Whether the operation was successful.

Definition at line 50 of file d_res.cpp.

◆ getRes() [1/3]

void * dRes_c::getRes ( const char * arcName,
const char * resPath ) const

Gets a resource.

Parameters
arcNameThe name of the archive which contains the resource. See the path notes.
resPathThe path to the resource within the archive. See the path notes.
Returns
A pointer to the contents of the resource.

Definition at line 64 of file d_res.cpp.

◆ getRes() [2/3]

void * dRes_c::getRes ( const char * arcName,
const char * resPath,
unsigned long * size ) const

Gets a resource.

Parameters
arcNameThe name of the archive which contains the resource. See the path notes.
resPathThe path to the resource within the archive. See the path notes.
sizeA pointer where the size of the resource will be written to.
Returns
A pointer to the contents of the resource.

Definition at line 73 of file d_res.cpp.

◆ getRes() [3/3]

void * dRes_c::getRes ( const char * arcName,
const char * resPath,
unsigned long * size,
int * compressionType ) const

Gets a resource which may optionally be compressed.

If the resource is available in both compressed and uncompressed form, the latter is prioritized. Only LZ77 compression is supported (the resource must be named <resPath>.LZ for it to be found).

Parameters
arcNameThe name of the archive which contains the resource. See the path notes.
resPathThe path to the resource within the archive. See the path notes.
sizeA pointer where the uncompressed size of the resource will be written to, or nullptr .
compressionTypeA pointer where the compression type of the resource will be written to, or nullptr . See CXCompressionType.
Returns
A pointer to the compressed contents of the resource.

Definition at line 87 of file d_res.cpp.

◆ getResSilently() [1/2]

void * dRes_c::getResSilently ( const char * arcName,
const char * resPath ) const

Gets a resource without logging a message if the resource is not found.

See also
getRes(const char*, const char*) const

Definition at line 142 of file d_res.cpp.

◆ getResSilently() [2/2]

void * dRes_c::getResSilently ( const char * arcName,
const char * resPath,
unsigned long * size ) const

Gets a resource without logging a message if the resource is not found.

See also
getRes(const char*, const char*, unsigned long*) const

Definition at line 159 of file d_res.cpp.

◆ syncAllRes()

bool dRes_c::syncAllRes ( )

Attempts to load the resources of an archive that has finished loading since the last call to this function. The callback is executed on all files and folders.

Returns
Whether such an archive was found.

Definition at line 181 of file d_res.cpp.

◆ getResInfo()

dRes_c::info_c * dRes_c::getResInfo ( const char * arcName) const
private

Gets the holder for an archive.

Parameters
arcNameThe name of the archive.
Returns
The holder for the archive, or nullptr if the holder doesn't exist.

Definition at line 194 of file d_res.cpp.

◆ getResInfoLoaded()

dRes_c::info_c * dRes_c::getResInfoLoaded ( const char * arcName) const
private

Gets the holder for a loaded archive.

Parameters
arcNameThe name of the archive.
Returns
The holder for the archive, or nullptr if the holder doesn't exist or the archive hasn't been loaded into memory yet.

Definition at line 218 of file d_res.cpp.

◆ newResInfo()

dRes_c::info_c * dRes_c::newResInfo ( )
private

Gets a free archive holder that can be used to store an archive reference.

Returns
The free archive holder, or nullptr if none is available.

Definition at line 206 of file d_res.cpp.

◆ copyRes() [1/2]

void dRes_c::copyRes ( const void * from,
void * to,
int size )
static

Copies an uncompressed resource.

Definition at line 130 of file d_res.cpp.

◆ copyRes() [2/2]

void dRes_c::copyRes ( const void * from,
void * to,
int size,
int compressionType )
static

Copies an optionally compressed resource.

Parameters
sizeThe size of the data. Only used for uncompressed resources.
compressionTypeThe compression type. See CXCompressionType for the possible values.

Definition at line 134 of file d_res.cpp.

Member Data Documentation

◆ mpArcInfos

info_c* dRes_c::mpArcInfos
private

An array of archive holders.

Definition at line 329 of file d_res.hpp.

◆ mNumArcs

u16 dRes_c::mNumArcs
private

The number of archive holders.

Definition at line 330 of file d_res.hpp.

◆ mpCallback

callback_c* dRes_c::mpCallback
private

The callback for when a resource is loaded.

Definition at line 331 of file d_res.hpp.

◆ mSetCallback

void(* dRes_c::mSetCallback)(const char *arcName, EGG::Heap *heap)
staticprivate

[Unused]. The callback for when an archive is scheduled for loading.

Definition at line 334 of file d_res.hpp.