Torque2D Reference

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes

- Class List
- Class Index
- Class Hierarchy
- Class Members

Public Member Functions | Public Attributes | List of all members
ResourceInstance Class Reference

`#include <resourceManager.h>`

Inheritance diagram for ResourceInstance:

## Public Member Functions
| ResourceInstance ()
virtual | ~ResourceInstance ()

## Public Attributes
ResourceObject * | mSourceResource
| Pointer to the ResourceObject that stores all our book-keeping data. More...

## Detailed Description

The base class for all resources.

This must be subclassed to implement a resource that can be managed.

Creating a new resource type is very simple. First, you need a function which can create a new instance of the resource given a stream:

ResourceInstance* constructBitmapPNG(Stream &stream)
{
GBitmap *bmp = new GBitmap;
if(bmp->readPNG(stream))
return bmp;
else
{
delete bmp;
return NULL;
}
}

Then you need to register the extension of your resource type with the resource manager:

ResourceManager->registerExtension(".png", constructBitmapPNG);

And, of course, you need to provide a subclass of ResourceInstance:

class GBitmap : ResourceInstance {
... whatever you need for your resource goes in here ...
}

ResourceInstance imposes very few requirements on you as the resource type implementor. All you "have" to provide is a destructor to deallocate whatever storage your resource might allocate. The ResourceManager will ensure that there is only one instance of the ResourceInstance for each file, and that it is only destroyed when no more references to it remain.

See also
  TerrainFile, GBitmap, AudioBuffer for more examples.

## Constructor & Destructor Documentation

ResourceInstance | ( |  | ) |
| inline

virtual ~ResourceInstance | ( |  | ) |
| inline virtual

## Member Data Documentation

ResourceObject* mSourceResource

Pointer to the ResourceObject that stores all our book-keeping data.

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

- io/resource/resourceManager.h