writeObject fix for datablocks
by Peter Simard · 01/03/2008 (9:45 am) · 1 comments
When saving a datablock via a writeObject() call, the datablock will be saved with "new" insead of "datablock". This fix was intended for TGE 1.5 but should work across other versions.
Example:
Datablocks need to be defined with the datablock prefix. This fix will make it correctly save like this:
Installation
Add to the end of GameBase.cc
Add to the public block of GameBaseData in GameBase.h
Example:
new ShapeBaseData(myObj)
{
};Datablocks need to be defined with the datablock prefix. This fix will make it correctly save like this:
datablock ShapeBaseData(myObj)
{
};Installation
Add to the end of GameBase.cc
static void writeTabs(Stream &stream, U32 count)
{
char tab[] = " ";
while(count--)
stream.write(3, (void*)tab);
}
void GameBaseData::write(Stream &stream, U32 tabStop, U32 flags)
{
// Only output selected objects if they want that.
if((flags & SelectedOnly) && !isSelected())
return;
writeTabs(stream, tabStop);
char buffer[1024];
dSprintf(buffer, sizeof(buffer), "datablock %s(%s) {\r\n", getClassName(), getName() ? getName() : "");
stream.write(dStrlen(buffer), buffer);
writeFields(stream, tabStop + 1);
writeTabs(stream, tabStop);
stream.write(4, "};\r\n");
}Add to the public block of GameBaseData in GameBase.h
virtual void write(Stream &stream, U32 tabStop, U32 flags = 0);

Torque Owner Daniel Buckmaster
T3D Steering Committee
Dropped in perfectly. As if I doubted you for a second ;)