From Sebastien Grignard, add writing out/reading in of drawable components of

a ShapeDrawable.

From Robert, add versioning of the above change to allow old files to still
work.
This commit is contained in:
Robert Osfield
2004-09-15 19:14:00 +00:00
parent b25c08bca4
commit e68cfd1965
5 changed files with 46 additions and 14 deletions

View File

@@ -74,7 +74,7 @@ DataOutputStream::DataOutputStream(std::ostream * ostream)
if(!_ostream)
throw Exception("DataOutputStream::DataOutputStream(): null pointer exception in argument.");
writeUInt(ENDIAN_TYPE) ;
writeUInt(VERSION);
writeUInt(getVersion());
}
DataOutputStream::~DataOutputStream(){}

View File

@@ -28,6 +28,9 @@ class DataOutputStream{
public:
DataOutputStream(std::ostream* ostream);
~DataOutputStream();
unsigned int getVersion() { return VERSION; }
void writeBool(bool b);
void writeChar(char c);
void writeUChar(unsigned char c);

View File

@@ -9,7 +9,9 @@
stored in the 2nd 4 bytes of the file */
#define VERSION_0002 0x00000002
#define VERSION 0x00000003
#define VERSION_0003 0x00000003
#define VERSION_0004 0x00000004
#define VERSION VERSION_0004
/* The BYTE_SEX tag is used to check the endian

View File

@@ -12,4 +12,4 @@ namespace ive{
};
}
#endif
#endif

View File

@@ -12,6 +12,7 @@
* Copyright 2003 VR-C
**********************************************************************/
#include "Drawable.h"
#include "Exception.h"
#include "ShapeDrawable.h"
#include "Object.h"
@@ -22,14 +23,27 @@ void ShapeDrawable::write(DataOutputStream* out)
{
// Write CullFace's identification.
out->writeInt(IVESHAPEDRAWABLE);
// If the osg class is inherited by any other class we should also write this to file.
osg::Object* obj = dynamic_cast<osg::Object*>(this);
if(obj)
if ( out->getVersion() >= VERSION_0004 )
{
((ive::Object*)(obj))->write(out);
// If the osg class is inherited by any other class we should also write this to file.
osg::Drawable* drawable = dynamic_cast<osg::Drawable*>(this);
if(drawable){
((ive::Drawable*)(drawable))->write(out);
}
else
throw Exception("ShapeDrawable::write(): Could not cast this osg::ShapeDrawable to an osg::Object.");
}
else
throw Exception("ShapeDrawable::write(): Could not cast this osg::ShapeDrawable to an osg::Object.");
{
osg::Object* obj = dynamic_cast<osg::Object*>(this);
if(obj){
((ive::Object*)(obj))->write(out);
}
else
throw Exception("ShapeDrawable::write(): Could not cast this osg::ShapeDrawable to an osg::Object.");
}
// Write ShapeDrawable's properties.
out->writeVec4(getColor());
@@ -53,15 +67,28 @@ void ShapeDrawable::read(DataInputStream* in)
{
// Read ShapeDrawable's identification.
id = in->readInt();
// If the osg class is inherited by any other class we should also read this from file.
osg::Object* obj = dynamic_cast<osg::Object*>(this);
if(obj)
if ( in->getVersion() >= VERSION_0004 )
{
((ive::Object*)(obj))->read(in);
// If the osg class is inherited by any other class we should also read this from file.
osg::Drawable* drawable = dynamic_cast<osg::Drawable*>(this);
if(drawable){
((ive::Drawable*)(drawable))->read(in);
}
else
throw Exception("ShapeDrawable::read(): Could not cast this osg::ShapeDrawable to an osg::Object.");
}
else
throw Exception("ShapeDrawable::read(): Could not cast this osg::ShapeDrawable to an osg::Object.");
{
// If the osg class is inherited by any other class we should also read this from file.
osg::Object* obj = dynamic_cast<osg::Object*>(this);
if(obj){
((ive::Object*)(obj))->read(in);
}
else
throw Exception("ShapeDrawable::read(): Could not cast this osg::ShapeDrawable to an osg::Object.");
}
// Read ShapeDrawable's properties
setColor(in->readVec4());