NvAssetLoader.h File Reference

Cross-platform binary asset loader. More...

#include <NvFoundation.h>

Go to the source code of this file.

Functions

bool NvAssetLoaderInit (void *platform)
 Initializes the loader at application start.
bool NvAssetLoaderShutdown ()
 Shuts down the system.
bool NvAssetLoaderAddSearchPath (const char *path)
 Adds a search path for finding the root of the assets tree.
bool NvAssetLoaderRemoveSearchPath (const char *path)
 Removes a search path from the lists.
char * NvAssetLoaderRead (const char *filePath, int32_t &length)
 Reads an asset file as a block.
bool NvAssetLoaderFree (char *asset)
 Frees a block returned from NvAssetLoaderRead.


Detailed Description

Cross-platform binary asset loader.

Cross-platform binary asset loader. Requires files to be located in a subdirectory of the application's source tree named "assets" in order to be able to find them. This is enforced so that assets will be automatically packed into the application's APK on Android (ANT defaults to packing the tree under "assets" into the binary assets of the APK).

On platforms that use file trees for storage (Windows and Linux), the search method for finding each file passed in as the partial path <filepath> is as follows:

On Android, the file opened is always <filepath>, since the "assets" directory is known (it is the APK's assets).


Function Documentation

bool NvAssetLoaderAddSearchPath ( const char *  path  ) 

Adds a search path for finding the root of the assets tree.

Adds a search path to be prepended to "assets" when searching for the correct assets tree. Note that this must be a relative path, and it is not used directly to find the file. It is only used on path-based platforms (Linux and Windows) to find the "assets" directory.

Parameters:
[in] The relative path to add to the set of paths used to find the "assets" tree. See the package description for the file search methods
Returns:
true on success and false on failure

bool NvAssetLoaderFree ( char *  asset  ) 

Frees a block returned from NvAssetLoaderRead.

Parameters:
[in] asset a pointer returned from NvAssetLoaderRead
Returns:
true on success and false on failure

bool NvAssetLoaderInit ( void *  platform  ) 

Initializes the loader at application start.

Initializes the loader. In most cases, the platform-specific application framework or main loop should make this call. It requires a different argument on each platform param[in] platform a platform-specific context pointer used by the implementation

  • On Android, this should be the app's AssetManager instance
  • On Windows and Linux, this is currently ignored and should be NULL

Returns:
true on success and false on failure

char* NvAssetLoaderRead ( const char *  filePath,
int32_t &  length 
)

Reads an asset file as a block.

Reads an asset file, returning a pointer to a block of memory that contains the entire file, along with the length. The block is null-terminated for safety

Parameters:
[in] filePath the partial path (below "assets") to the file
[out] length the length of the file in bytes
Returns:
a pointer to a null-terminated block containing the contents of the file or NULL on error. This block should be freed with a call to NvAssetLoaderFree when no longer needed. Do NOT delete the block with free or delete[]

bool NvAssetLoaderRemoveSearchPath ( const char *  path  ) 

Removes a search path from the lists.

Parameters:
[in] the path to remove
Returns:
true on success and false on failure (not finding the path on the list is considered success)

bool NvAssetLoaderShutdown (  ) 

Shuts down the system.

Returns:
true on success and false on failure