Torque2D Reference
Loading...
Searching...
No Matches
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.
 

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;
}
}
Definition gBitmap.h:54
bool readPNG(Stream &io_rStream)
Definition bitmapPng.cc:125
Definition resourceManager.h:103
Base stream class for streaming data across a specific media.
Definition stream.h:73

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

ResourceManager->registerExtension(".png", constructBitmapPNG);
void registerExtension(const char *extension, RESOURCE_CREATE_FN create_fn)
Tells the resource manager what to do with a resource that it loads.
Definition resourceManager.cc:712

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

ResourceInstance ( )
inline

◆ ~ResourceInstance()

virtual ~ResourceInstance ( )
inlinevirtual

Member Data Documentation

◆ mSourceResource

ResourceObject* mSourceResource

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


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