torque Torque Game Engine Documentation
TGE Version 1.5.2

ResManager Class Reference

#include <resManager.h>


Detailed Description

A virtual file system for the storage and retrieval of ResourceObjects.

Basic resource manager behavior:

  • Set the mod path.
    • ResManager scans directory tree under listed base directories
    • Any volume (.zip) file in the root directory of a mod is scanned for resources.
    • Any files currently in the resource manager become memory resources.
    • They can be "reattached" to the first file that matches the file name.

All classes which wish to be handled by the resource manager need:

  1. To be derived from ResourceInstance.
  2. To register a creation function and file extension with the manager.


Global Control

These are called to initialize/destroy the resource manager at runtime.

static void create ()
static void destroy ()
static void initExcludedDirectories ()
 Load the excluded directories from the resource manager pref and stuff it into the platform layer.

Public Member Functions

RESOURCE_CREATE_FN getCreateFunction (const char *name)
 ~ResManager ()
void setFileNameEcho (bool on)
 Sets whether or not to echo filenames that have been accessed by means of openStream.
void setModPaths (U32 numPaths, const char **dirs)
 Sets the path for the current game mod.
const char * getModPaths ()
 Gets the path for the current game mod.
void setMissingFileLogging (bool log)
 Should we log missing files?
bool getMissingFileList (Vector< char * > &list)
 Gets which files are missing.
void clearMissingFileList ()
 Clears the missing file list.
void registerExtension (const char *extension, RESOURCE_CREATE_FN create_fn)
 Tells the resource manager what to do with a resource that it loads.
S32 getSize (const char *filename)
 Gets the size of the file.
const char * getFullPath (const char *filename, char *path, U32 pathLen)
 Gets the full path of the file.
const char * getModPathOf (const char *fileName)
 Gets the path of the file local to the mod.
const char * getPathOf (const char *filename)
 Gets the path of the file from the base directory.
const char * getBasePath ()
 Gets the base path.
ResourceObjectload (const char *fileName, bool computeCRC=false)
 loads an instance of an object
StreamopenStream (const char *fileName)
 Opens a stream for an object.
StreamopenStream (ResourceObject *object)
 Opens a stream for an object.
void closeStream (Stream *stream)
 Closes the stream.
void unlock (ResourceObject *)
 Decrements the lock count of an object.
bool add (const char *name, ResourceInstance *addInstance, bool extraLock=false)
 Add a new resource instance.
ResourceObjectfind (const char *fileName)
 Searches the hash list for the filename and returns it's object if found, otherwise NULL.
ResourceInstanceloadInstance (const char *fileName, bool computeCRC=false)
 Loads a new instance of an object by means of a filename.
ResourceInstanceloadInstance (ResourceObject *object, bool computeCRC=false)
 Loads a new instance of an object by means of a resource object.
ResourceObjectfind (const char *fileName, U32 flags)
 Searches the hash list for the filename and returns it's object if found, otherwise NULL.
ResourceObjectfindMatch (const char *expression, const char **fn, ResourceObject *start=NULL)
 Finds a resource object with given expression.
ResourceObjectfindMatchMultiExprs (const char *multiExpression, const char **fn, ResourceObject *start=NULL)
 Finds a resource object with given expressions, seperated by " ".
void purge ()
 Goes through the timeoutList and deletes it all. BURN!!!
void purge (ResourceObject *obj)
 Deletes one resource object.
void freeResource (ResourceObject *resObject)
 Frees a resource!
void serialize (VectorPtr< const char * > &filenames)
 Sorts the resource objects.
S32 findMatches (FindMatch *pFM)
 Finds multiple matches to an expression.
bool findFile (const char *name)
 Checks to see if a file exists.
bool getCrc (const char *fileName, U32 &crcVal, const U32 crcInitialVal=INITIAL_CRC_VALUE)
 Computes the CRC of a file.
void setWriteablePath (const char *path)
 Sets the writable path for a file to the one given.
bool isValidWriteFileName (const char *fn)
 Checks to see if the given path is valid for writing.
bool openFileForWrite (FileStream &fs, const char *fileName, U32 accessMode=1)
 Opens a file for writing!
void dumpLoadedResources ()
 Dumps all loaded resources to the console.

Private Member Functions

bool isIgnoredSubdirectoryName (const char *name) const
bool scanZip (ResourceObject *zipObject)
 Scan a zip file for resources.
ResourceObjectcreateResource (StringTableEntry path, StringTableEntry file)
 Create a ResourceObject from the given file.
ResourceObjectcreateZipResource (StringTableEntry path, StringTableEntry file, StringTableEntry zipPath, StringTableEntry zipFle)
 Create a ResourceObject from the given file in a zip file.
void searchPath (const char *pathStart)
bool setModZip (const char *path)
void fileIsMissing (const char *fileName)
 Called when a file is missing.
 ResManager ()

Private Attributes

char writeablePath [1024]
 Path to which we will write data.
char primaryPath [1024]
 Primary path from which we load data.
char * pathList
 List of secondary paths to search.
ResourceObject timeoutList
ResourceObject resourceList
ResDictionary dictionary
bool echoFileNames
Vector< char * > mMissingFileList
 List of missing files.
bool mLoggingMissingFiles
 Are there any missing files?
RegisteredExtensionregisteredList

Static Private Attributes

static char * smExcludedDirectories

Data Structures

struct  RegisteredExtension


Constructor & Destructor Documentation

ResManager::ResManager (  )  [private]

ResManager::~ResManager (  ) 


Member Function Documentation

bool ResManager::isIgnoredSubdirectoryName ( const char *  name  )  const [private]

bool ResManager::scanZip ( ResourceObject zipObject  )  [private]

Scan a zip file for resources.

ResourceObject* ResManager::createResource ( StringTableEntry  path,
StringTableEntry  file 
) [private]

Create a ResourceObject from the given file.

ResourceObject* ResManager::createZipResource ( StringTableEntry  path,
StringTableEntry  file,
StringTableEntry  zipPath,
StringTableEntry  zipFle 
) [private]

Create a ResourceObject from the given file in a zip file.

void ResManager::searchPath ( const char *  pathStart  )  [private]

bool ResManager::setModZip ( const char *  path  )  [private]

void ResManager::fileIsMissing ( const char *  fileName  )  [private]

Called when a file is missing.

RESOURCE_CREATE_FN ResManager::getCreateFunction ( const char *  name  ) 

static void ResManager::create (  )  [static]

static void ResManager::destroy (  )  [static]

static void ResManager::initExcludedDirectories (  )  [static]

Load the excluded directories from the resource manager pref and stuff it into the platform layer.

void ResManager::setFileNameEcho ( bool  on  ) 

Sets whether or not to echo filenames that have been accessed by means of openStream.

void ResManager::setModPaths ( U32  numPaths,
const char **  dirs 
)

Sets the path for the current game mod.

const char* ResManager::getModPaths (  ) 

Gets the path for the current game mod.

void ResManager::setMissingFileLogging ( bool  log  ) 

Should we log missing files?

bool ResManager::getMissingFileList ( Vector< char * > &  list  ) 

Gets which files are missing.

void ResManager::clearMissingFileList (  ) 

Clears the missing file list.

void ResManager::registerExtension ( const char *  extension,
RESOURCE_CREATE_FN  create_fn 
)

Tells the resource manager what to do with a resource that it loads.

S32 ResManager::getSize ( const char *  filename  ) 

Gets the size of the file.

const char* ResManager::getFullPath ( const char *  filename,
char *  path,
U32  pathLen 
)

Gets the full path of the file.

const char* ResManager::getModPathOf ( const char *  fileName  ) 

Gets the path of the file local to the mod.

const char* ResManager::getPathOf ( const char *  filename  ) 

Gets the path of the file from the base directory.

const char* ResManager::getBasePath (  ) 

Gets the base path.

ResourceObject* ResManager::load ( const char *  fileName,
bool  computeCRC = false 
)

loads an instance of an object

Stream* ResManager::openStream ( const char *  fileName  ) 

Opens a stream for an object.

Stream* ResManager::openStream ( ResourceObject object  ) 

Opens a stream for an object.

void ResManager::closeStream ( Stream stream  ) 

Closes the stream.

void ResManager::unlock ( ResourceObject  ) 

Decrements the lock count of an object.

If the lock count is zero post-decrement, the object is added to the timeoutList for deletion upon call of flush.

bool ResManager::add ( const char *  name,
ResourceInstance addInstance,
bool  extraLock = false 
)

Add a new resource instance.

ResourceObject* ResManager::find ( const char *  fileName  ) 

Searches the hash list for the filename and returns it's object if found, otherwise NULL.

ResourceInstance* ResManager::loadInstance ( const char *  fileName,
bool  computeCRC = false 
)

Loads a new instance of an object by means of a filename.

ResourceInstance* ResManager::loadInstance ( ResourceObject object,
bool  computeCRC = false 
)

Loads a new instance of an object by means of a resource object.

ResourceObject* ResManager::find ( const char *  fileName,
U32  flags 
)

Searches the hash list for the filename and returns it's object if found, otherwise NULL.

ResourceObject* ResManager::findMatch ( const char *  expression,
const char **  fn,
ResourceObject start = NULL 
)

Finds a resource object with given expression.

ResourceObject* ResManager::findMatchMultiExprs ( const char *  multiExpression,
const char **  fn,
ResourceObject start = NULL 
)

Finds a resource object with given expressions, seperated by " ".

void ResManager::purge (  ) 

Goes through the timeoutList and deletes it all. BURN!!!

void ResManager::purge ( ResourceObject obj  ) 

Deletes one resource object.

void ResManager::freeResource ( ResourceObject resObject  ) 

Frees a resource!

void ResManager::serialize ( VectorPtr< const char * > &  filenames  ) 

Sorts the resource objects.

S32 ResManager::findMatches ( FindMatch pFM  ) 

Finds multiple matches to an expression.

bool ResManager::findFile ( const char *  name  ) 

Checks to see if a file exists.

bool ResManager::getCrc ( const char *  fileName,
U32 crcVal,
const U32  crcInitialVal = INITIAL_CRC_VALUE 
)

Computes the CRC of a file.

By passing a different crcInitialVal, you can take the CRC of multiple files.

void ResManager::setWriteablePath ( const char *  path  ) 

Sets the writable path for a file to the one given.

bool ResManager::isValidWriteFileName ( const char *  fn  ) 

Checks to see if the given path is valid for writing.

bool ResManager::openFileForWrite ( FileStream fs,
const char *  fileName,
U32  accessMode = 1 
)

Opens a file for writing!

void ResManager::dumpLoadedResources (  ) 

Dumps all loaded resources to the console.


Field Documentation

char ResManager::writeablePath[1024] [private]

Path to which we will write data.

This is used when, for instance, we download files from a server.

char ResManager::primaryPath[1024] [private]

Primary path from which we load data.

char* ResManager::pathList [private]

List of secondary paths to search.

bool ResManager::echoFileNames [private]

List of missing files.

Are there any missing files?

char* ResManager::smExcludedDirectories [static, private]




All Rights Reserved GarageGames.com, Inc. 1999-2005
Auto-magically Generated with Doxygen