Backward Compatibility

As development evolves on a plug-in, the use of its parameter blocks may change. For example, more parameters may be added or some may be deleted. 3ds Max files that were saved using the old version of the plug-in would not normally load properly under the new format. In order to provide backward compatibility with the older format a mechanism exists to allow the old format to be converted to the new format.

To accomplish the conversion you must define both the old and the new format of the parameter block.

static  ParamBlockDescID descVer0[] = {
 { TYPE_FLOAT, NULL, TRUE, 0 },
 { TYPE_INT, NULL, TRUE, 1 },
 { TYPE_INT, NULL, TRUE, 2 } };

static  ParamBlockDescID descVer1[] = {
 { TYPE_FLOAT, NULL, TRUE, 0 },
 { TYPE_INT, NULL, TRUE, 1 },
 { TYPE_INT, NULL, TRUE, 2 },
 { TYPE_FLOAT, NULL, TRUE, 3 },
 { TYPE_INT, NULL, FALSE, 4 },
 { TYPE_INT, NULL, FALSE, 5 } };

#define PBLOCK_LENGTH 6

The fourth argument of the ParamBlockDescID is the ID of the parameter. These are used to match the old version of the parameter to the new version. The code which does the conversion matches the IDs between the two versions, for example, it will match the ID=1 of the old version to the ID=1 of the new version.

You create an array of the class ParamVersionDesc, one element for each old version of the parameter block. This structure describes a version of the parameter block. You also create an instance of ParamVersionDesc for the new version.

// Array of old versions
static  ParamVersionDesc versions[] = {
 ParamVersionDesc(descVer0,3,0)
};
#define NUM_OLDVERSIONS 1

// Current version
static  ParamVersionDesc curVersion(descVer1,PBLOCK_LENGTH, 1);
#define CURRENT_VERSION 1

When the plug-in is loaded, its Load() method is called. From within this method you call a method of the ILoad class which registers the parameter block post load callback object. The callback object is an instance of the class ParamBlockPLCB. This callback creates a new parameter block. The new parameter block inherits any parameters from the old parameter block whose parameter IDs match. In this way the older format is automatically converted to the new format by matching the corresponding IDs.

IOResult SphereObject::Load(ILoad *iload)
{
 iload->RegisterPostLoadCallback(
  new ParamBlockPLCB(versions,NUM_OLDVERSIONS,&curVersion,this,0));
 return IO_OK;
}