Torque2D Reference
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
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

ResourceObjectmSourceResource
 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:

... 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 ( )
inlinevirtual

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: