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:
parent
7b644e6d82
commit
6468905e42
@ -29,8 +29,9 @@
|
||||
#define VERSION_0018 18
|
||||
#define VERSION_0019 19
|
||||
#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
|
||||
of the IVE file being read in. The IVE format
|
||||
|
@ -18,22 +18,28 @@
|
||||
|
||||
using namespace ive;
|
||||
|
||||
void Sequence::write(DataOutputStream* out){
|
||||
void Sequence::write(DataOutputStream* out)
|
||||
{
|
||||
// Write Sequence's identification.
|
||||
out->writeInt(IVESEQUENCE);
|
||||
// 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);
|
||||
if(group){
|
||||
if(group)
|
||||
{
|
||||
((ive::Group*)(group))->write(out);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw Exception("Sequence::write(): Could not cast this osg::Sequence to an osg::Group.");
|
||||
}
|
||||
|
||||
// Write Sequence's properties.
|
||||
|
||||
// Write frame times.
|
||||
int size = getNumChildren();
|
||||
out->writeInt(size);
|
||||
for(int i=0;i<size;i++){
|
||||
for(int i=0;i<size;i++)
|
||||
{
|
||||
out->writeFloat(getTime(i));
|
||||
}
|
||||
// Write loop mode & interval
|
||||
@ -43,34 +49,43 @@ void Sequence::write(DataOutputStream* out){
|
||||
out->writeInt(mode);
|
||||
out->writeInt(begin);
|
||||
out->writeInt(end);
|
||||
|
||||
// Write duration
|
||||
float speed;
|
||||
int nreps;
|
||||
getDuration(speed, nreps);
|
||||
out->writeFloat(speed);
|
||||
out->writeInt(nreps);
|
||||
|
||||
// Write sequence mode
|
||||
out->writeInt(getMode());
|
||||
|
||||
}
|
||||
|
||||
void Sequence::read(DataInputStream* in){
|
||||
void Sequence::read(DataInputStream* in)
|
||||
{
|
||||
// Peek on Sequence's identification.
|
||||
int id = in->peekInt();
|
||||
if(id == IVESEQUENCE){
|
||||
if(id == IVESEQUENCE)
|
||||
{
|
||||
// Read Sequence's identification.
|
||||
id = in->readInt();
|
||||
// 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);
|
||||
if(group){
|
||||
if(group)
|
||||
{
|
||||
((ive::Group*)(group))->read(in);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw Exception("Sequence::read(): Could not cast this osg::Sequence to an osg::Group.");
|
||||
}
|
||||
|
||||
// Read Sequence's properties
|
||||
// Read frame times.
|
||||
int size = in->readInt();
|
||||
for(int i=0;i<size;i++){
|
||||
for(int i=0;i<size;i++)
|
||||
{
|
||||
setTime(i, in->readFloat());
|
||||
}
|
||||
// Read loop mode & interval
|
||||
@ -78,14 +93,17 @@ void Sequence::read(DataInputStream* in){
|
||||
int begin = in->readInt();
|
||||
int end = in->readInt();
|
||||
setInterval((osg::Sequence::LoopMode)mode, begin, end);
|
||||
|
||||
// Read duration
|
||||
float speed = in->readFloat();
|
||||
int nreps = in->readInt();
|
||||
setDuration(speed, nreps);
|
||||
|
||||
// Read sequence mode
|
||||
setMode((osg::Sequence::SequenceMode)in->readInt());
|
||||
}
|
||||
else{
|
||||
else
|
||||
{
|
||||
throw Exception("Sequence::read(): Expected Sequence identification.");
|
||||
}
|
||||
}
|
||||
|
@ -25,11 +25,17 @@ static bool Sequence_matchLoopMode(const char* str,
|
||||
Sequence::LoopMode& mode)
|
||||
{
|
||||
if (strcmp(str, "LOOP") == 0)
|
||||
{
|
||||
mode = Sequence::LOOP;
|
||||
}
|
||||
else if (strcmp(str, "SWING") == 0)
|
||||
{
|
||||
mode = Sequence::SWING;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -50,11 +56,17 @@ static bool Sequence_matchSeqMode(const char* str,
|
||||
Sequence::SequenceMode& mode)
|
||||
{
|
||||
if (strcmp(str, "START") == 0)
|
||||
{
|
||||
mode = Sequence::START;
|
||||
}
|
||||
else if (strcmp(str, "STOP") == 0)
|
||||
{
|
||||
mode = Sequence::STOP;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -75,35 +87,64 @@ bool Sequence_readLocalData(Object& obj, Input& fr)
|
||||
|
||||
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();
|
||||
fr += 2;
|
||||
|
||||
|
||||
int i = 0;
|
||||
while (!fr.eof() && fr[0].getNoNestedBrackets() > entry) {
|
||||
while (!fr.eof() && fr[0].getNoNestedBrackets() > entry)
|
||||
{
|
||||
float t;
|
||||
if (fr[0].getFloat(t)) {
|
||||
if (fr[0].getFloat(t))
|
||||
{
|
||||
sw.setTime(i, t);
|
||||
++fr;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
iteratorAdvanced = true;
|
||||
++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;
|
||||
int begin, end;
|
||||
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);
|
||||
iteratorAdvanced = true;
|
||||
fr += 4;
|
||||
}
|
||||
}
|
||||
else if (fr.matchSequence("duration")) {
|
||||
if (fr[1].isFloat() && fr[2].isInt()) {
|
||||
else if (fr.matchSequence("duration"))
|
||||
{
|
||||
if (fr[1].isFloat() && fr[2].isInt())
|
||||
{
|
||||
float speed;
|
||||
int nreps;
|
||||
fr[1].getFloat(speed);
|
||||
@ -113,15 +154,39 @@ bool Sequence_readLocalData(Object& obj, Input& fr)
|
||||
fr += 3;
|
||||
}
|
||||
}
|
||||
else if (fr.matchSequence("mode")) {
|
||||
else if (fr.matchSequence("mode"))
|
||||
{
|
||||
Sequence::SequenceMode mode;
|
||||
if (Sequence_matchSeqMode(fr[1].getStr(), mode)) {
|
||||
if (Sequence_matchSeqMode(fr[1].getStr(), mode))
|
||||
{
|
||||
sw.setMode(mode);
|
||||
iteratorAdvanced = true;
|
||||
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;
|
||||
}
|
||||
|
||||
@ -129,15 +194,23 @@ bool Sequence_writeLocalData(const Object& obj, Output& fw)
|
||||
{
|
||||
const Sequence& sw = static_cast<const Sequence&>(obj);
|
||||
|
||||
// default frame time
|
||||
fw.indent() << "defaultTime " << sw.getDefaultTime() << std::endl;
|
||||
|
||||
// frame times
|
||||
fw.indent() << "frameTime {" << std::endl;
|
||||
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.moveOut();
|
||||
fw.indent() << "}" << std::endl;
|
||||
|
||||
// last frame time
|
||||
fw.indent() << "lastFrameTime " << sw.getLastFrameTime() << std::endl;
|
||||
|
||||
// loop mode & interval
|
||||
Sequence::LoopMode mode;
|
||||
int begin, end;
|
||||
@ -153,5 +226,15 @@ bool Sequence_writeLocalData(const Object& obj, Output& fw)
|
||||
// sequence mode
|
||||
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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user