From John Kelso, Added support for new Sequence options.

From Robert Osfield, updated the above changes to the .ive loader so that the new addition were tested against the IVE version number
This commit is contained in:
Robert Osfield 2007-05-15 14:55:02 +00:00
parent 7b644e6d82
commit 6468905e42
3 changed files with 124 additions and 22 deletions

View File

@ -29,8 +29,9 @@
#define VERSION_0018 18 #define VERSION_0018 18
#define VERSION_0019 19 #define VERSION_0019 19
#define VERSION_0020 20 #define VERSION_0020 20
#define VERSION_0021 21
#define VERSION VERSION_0020 #define VERSION VERSION_0021
/* The BYTE_SEX tag is used to check the endian /* The BYTE_SEX tag is used to check the endian
of the IVE file being read in. The IVE format of the IVE file being read in. The IVE format

View File

@ -18,22 +18,28 @@
using namespace ive; using namespace ive;
void Sequence::write(DataOutputStream* out){ void Sequence::write(DataOutputStream* out)
{
// Write Sequence's identification. // Write Sequence's identification.
out->writeInt(IVESEQUENCE); out->writeInt(IVESEQUENCE);
// If the osg class is inherited by any other class we should also write this to file. // If the osg class is inherited by any other class we should also write this to file.
osg::Group* group = dynamic_cast<osg::Group*>(this); osg::Group* group = dynamic_cast<osg::Group*>(this);
if(group){ if(group)
{
((ive::Group*)(group))->write(out); ((ive::Group*)(group))->write(out);
} }
else else
{
throw Exception("Sequence::write(): Could not cast this osg::Sequence to an osg::Group."); throw Exception("Sequence::write(): Could not cast this osg::Sequence to an osg::Group.");
}
// Write Sequence's properties. // Write Sequence's properties.
// Write frame times. // Write frame times.
int size = getNumChildren(); int size = getNumChildren();
out->writeInt(size); out->writeInt(size);
for(int i=0;i<size;i++){ for(int i=0;i<size;i++)
{
out->writeFloat(getTime(i)); out->writeFloat(getTime(i));
} }
// Write loop mode & interval // Write loop mode & interval
@ -43,34 +49,43 @@ void Sequence::write(DataOutputStream* out){
out->writeInt(mode); out->writeInt(mode);
out->writeInt(begin); out->writeInt(begin);
out->writeInt(end); out->writeInt(end);
// Write duration // Write duration
float speed; float speed;
int nreps; int nreps;
getDuration(speed, nreps); getDuration(speed, nreps);
out->writeFloat(speed); out->writeFloat(speed);
out->writeInt(nreps); out->writeInt(nreps);
// Write sequence mode // Write sequence mode
out->writeInt(getMode()); out->writeInt(getMode());
} }
void Sequence::read(DataInputStream* in){ void Sequence::read(DataInputStream* in)
{
// Peek on Sequence's identification. // Peek on Sequence's identification.
int id = in->peekInt(); int id = in->peekInt();
if(id == IVESEQUENCE){ if(id == IVESEQUENCE)
{
// Read Sequence's identification. // Read Sequence's identification.
id = in->readInt(); id = in->readInt();
// If the osg class is inherited by any other class we should also read this from file. // If the osg class is inherited by any other class we should also read this from file.
osg::Group* group = dynamic_cast<osg::Group*>(this); osg::Group* group = dynamic_cast<osg::Group*>(this);
if(group){ if(group)
{
((ive::Group*)(group))->read(in); ((ive::Group*)(group))->read(in);
} }
else else
{
throw Exception("Sequence::read(): Could not cast this osg::Sequence to an osg::Group."); throw Exception("Sequence::read(): Could not cast this osg::Sequence to an osg::Group.");
}
// Read Sequence's properties // Read Sequence's properties
// Read frame times. // Read frame times.
int size = in->readInt(); int size = in->readInt();
for(int i=0;i<size;i++){ for(int i=0;i<size;i++)
{
setTime(i, in->readFloat()); setTime(i, in->readFloat());
} }
// Read loop mode & interval // Read loop mode & interval
@ -78,14 +93,17 @@ void Sequence::read(DataInputStream* in){
int begin = in->readInt(); int begin = in->readInt();
int end = in->readInt(); int end = in->readInt();
setInterval((osg::Sequence::LoopMode)mode, begin, end); setInterval((osg::Sequence::LoopMode)mode, begin, end);
// Read duration // Read duration
float speed = in->readFloat(); float speed = in->readFloat();
int nreps = in->readInt(); int nreps = in->readInt();
setDuration(speed, nreps); setDuration(speed, nreps);
// Read sequence mode // Read sequence mode
setMode((osg::Sequence::SequenceMode)in->readInt()); setMode((osg::Sequence::SequenceMode)in->readInt());
} }
else{ else
{
throw Exception("Sequence::read(): Expected Sequence identification."); throw Exception("Sequence::read(): Expected Sequence identification.");
} }
} }

View File

@ -25,11 +25,17 @@ static bool Sequence_matchLoopMode(const char* str,
Sequence::LoopMode& mode) Sequence::LoopMode& mode)
{ {
if (strcmp(str, "LOOP") == 0) if (strcmp(str, "LOOP") == 0)
{
mode = Sequence::LOOP; mode = Sequence::LOOP;
}
else if (strcmp(str, "SWING") == 0) else if (strcmp(str, "SWING") == 0)
{
mode = Sequence::SWING; mode = Sequence::SWING;
}
else else
{
return false; return false;
}
return true; return true;
} }
@ -50,11 +56,17 @@ static bool Sequence_matchSeqMode(const char* str,
Sequence::SequenceMode& mode) Sequence::SequenceMode& mode)
{ {
if (strcmp(str, "START") == 0) if (strcmp(str, "START") == 0)
{
mode = Sequence::START; mode = Sequence::START;
}
else if (strcmp(str, "STOP") == 0) else if (strcmp(str, "STOP") == 0)
{
mode = Sequence::STOP; mode = Sequence::STOP;
}
else else
{
return false; return false;
}
return true; return true;
} }
@ -75,14 +87,28 @@ bool Sequence_readLocalData(Object& obj, Input& fr)
Sequence& sw = static_cast<Sequence&>(obj); Sequence& sw = static_cast<Sequence&>(obj);
if (fr.matchSequence("frameTime {")) { if (fr.matchSequence("defaultTime"))
{
if (fr[1].isFloat())
{
float t;
fr[1].getFloat(t) ;
sw.setDefaultTime(t) ;
iteratorAdvanced = true;
fr += 2;
}
}
else if (fr.matchSequence("frameTime {"))
{
int entry = fr[0].getNoNestedBrackets(); int entry = fr[0].getNoNestedBrackets();
fr += 2; fr += 2;
int i = 0; int i = 0;
while (!fr.eof() && fr[0].getNoNestedBrackets() > entry) { while (!fr.eof() && fr[0].getNoNestedBrackets() > entry)
{
float t; float t;
if (fr[0].getFloat(t)) { if (fr[0].getFloat(t))
{
sw.setTime(i, t); sw.setTime(i, t);
++fr; ++fr;
i++; i++;
@ -92,18 +118,33 @@ bool Sequence_readLocalData(Object& obj, Input& fr)
iteratorAdvanced = true; iteratorAdvanced = true;
++fr; ++fr;
} }
else if (fr.matchSequence("interval")) { else if (fr.matchSequence("lastFrameTime"))
{
if (fr[1].isFloat())
{
float t;
fr[1].getFloat(t) ;
sw.setLastFrameTime(t) ;
iteratorAdvanced = true;
fr += 2;
}
}
else if (fr.matchSequence("interval"))
{
Sequence::LoopMode mode; Sequence::LoopMode mode;
int begin, end; int begin, end;
if (Sequence_matchLoopMode(fr[1].getStr(), mode) && if (Sequence_matchLoopMode(fr[1].getStr(), mode) &&
fr[2].getInt(begin) && fr[3].getInt(end)) { fr[2].getInt(begin) && fr[3].getInt(end))
{
sw.setInterval(mode, begin, end); sw.setInterval(mode, begin, end);
iteratorAdvanced = true; iteratorAdvanced = true;
fr += 4; fr += 4;
} }
} }
else if (fr.matchSequence("duration")) { else if (fr.matchSequence("duration"))
if (fr[1].isFloat() && fr[2].isInt()) { {
if (fr[1].isFloat() && fr[2].isInt())
{
float speed; float speed;
int nreps; int nreps;
fr[1].getFloat(speed); fr[1].getFloat(speed);
@ -113,14 +154,38 @@ bool Sequence_readLocalData(Object& obj, Input& fr)
fr += 3; fr += 3;
} }
} }
else if (fr.matchSequence("mode")) { else if (fr.matchSequence("mode"))
{
Sequence::SequenceMode mode; Sequence::SequenceMode mode;
if (Sequence_matchSeqMode(fr[1].getStr(), mode)) { if (Sequence_matchSeqMode(fr[1].getStr(), mode))
{
sw.setMode(mode); sw.setMode(mode);
iteratorAdvanced = true; iteratorAdvanced = true;
fr += 2; fr += 2;
} }
} }
else if (fr.matchSequence("sync"))
{
if (fr[1].isInt())
{
int sync ;
fr[1].getInt(sync) ;
sw.setSync((bool)sync) ;
iteratorAdvanced = true;
fr += 2;
}
}
else if (fr.matchSequence("clearOnStop"))
{
if (fr[1].isInt())
{
int clearOnStop ;
fr[1].getInt(clearOnStop) ;
sw.setClearOnStop((bool)clearOnStop) ;
iteratorAdvanced = true;
fr += 2;
}
}
return iteratorAdvanced; return iteratorAdvanced;
} }
@ -129,15 +194,23 @@ bool Sequence_writeLocalData(const Object& obj, Output& fw)
{ {
const Sequence& sw = static_cast<const Sequence&>(obj); const Sequence& sw = static_cast<const Sequence&>(obj);
// default frame time
fw.indent() << "defaultTime " << sw.getDefaultTime() << std::endl;
// frame times // frame times
fw.indent() << "frameTime {" << std::endl; fw.indent() << "frameTime {" << std::endl;
fw.moveIn(); fw.moveIn();
for (unsigned int i = 0; i < sw.getNumChildren(); i++) { for (unsigned int i = 0; i < sw.getNumChildren(); i++)
{
fw.indent() << sw.getTime(i) << std::endl; fw.indent() << sw.getTime(i) << std::endl;
} }
fw.moveOut(); fw.moveOut();
fw.indent() << "}" << std::endl; fw.indent() << "}" << std::endl;
// last frame time
fw.indent() << "lastFrameTime " << sw.getLastFrameTime() << std::endl;
// loop mode & interval // loop mode & interval
Sequence::LoopMode mode; Sequence::LoopMode mode;
int begin, end; int begin, end;
@ -153,5 +226,15 @@ bool Sequence_writeLocalData(const Object& obj, Output& fw)
// sequence mode // sequence mode
fw.indent() << "mode " << Sequence_getSeqMode(sw.getMode()) << std::endl; fw.indent() << "mode " << Sequence_getSeqMode(sw.getMode()) << std::endl;
// sync
bool sync ;
sw.getSync(sync);
fw.indent() << "sync " << (int) sync << std::endl;
// clearOnStop
bool clearOnStop ;
sw.getClearOnStop(clearOnStop);
fw.indent() << "clearOnStop " << (int) clearOnStop << std::endl;
return true; return true;
} }