| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | #include "Exception.h" |
|---|
| 16 | #include "Sequence.h" |
|---|
| 17 | #include "Group.h" |
|---|
| 18 | |
|---|
| 19 | using namespace ive; |
|---|
| 20 | |
|---|
| 21 | void Sequence::write(DataOutputStream* out) |
|---|
| 22 | { |
|---|
| 23 | |
|---|
| 24 | out->writeInt(IVESEQUENCE); |
|---|
| 25 | |
|---|
| 26 | osg::Group* group = dynamic_cast<osg::Group*>(this); |
|---|
| 27 | if(group) |
|---|
| 28 | { |
|---|
| 29 | ((ive::Group*)(group))->write(out); |
|---|
| 30 | } |
|---|
| 31 | else |
|---|
| 32 | { |
|---|
| 33 | out_THROW_EXCEPTION("Sequence::write(): Could not cast this osg::Sequence to an osg::Group."); |
|---|
| 34 | } |
|---|
| 35 | |
|---|
| 36 | |
|---|
| 37 | |
|---|
| 38 | if (out->getVersion() >= VERSION_0022) |
|---|
| 39 | { |
|---|
| 40 | |
|---|
| 41 | out->writeFloat(getDefaultTime()) ; |
|---|
| 42 | } |
|---|
| 43 | |
|---|
| 44 | |
|---|
| 45 | int size = getNumChildren(); |
|---|
| 46 | out->writeInt(size); |
|---|
| 47 | for(int i=0;i<size;i++) |
|---|
| 48 | { |
|---|
| 49 | out->writeFloat(getTime(i)); |
|---|
| 50 | } |
|---|
| 51 | |
|---|
| 52 | if (out->getVersion() >= VERSION_0022) |
|---|
| 53 | { |
|---|
| 54 | |
|---|
| 55 | out->writeFloat(getLastFrameTime()) ; |
|---|
| 56 | } |
|---|
| 57 | |
|---|
| 58 | |
|---|
| 59 | osg::Sequence::LoopMode mode; |
|---|
| 60 | int begin, end; |
|---|
| 61 | getInterval(mode, begin, end); |
|---|
| 62 | out->writeInt(mode); |
|---|
| 63 | out->writeInt(begin); |
|---|
| 64 | out->writeInt(end); |
|---|
| 65 | |
|---|
| 66 | |
|---|
| 67 | float speed; |
|---|
| 68 | int nreps; |
|---|
| 69 | getDuration(speed, nreps); |
|---|
| 70 | out->writeFloat(speed); |
|---|
| 71 | out->writeInt(nreps); |
|---|
| 72 | |
|---|
| 73 | |
|---|
| 74 | out->writeInt(getMode()); |
|---|
| 75 | |
|---|
| 76 | if (out->getVersion() >= VERSION_0022) |
|---|
| 77 | { |
|---|
| 78 | |
|---|
| 79 | out->writeInt((int)getSync()) ; |
|---|
| 80 | |
|---|
| 81 | |
|---|
| 82 | out->writeInt((int)getClearOnStop()) ; |
|---|
| 83 | } |
|---|
| 84 | |
|---|
| 85 | } |
|---|
| 86 | |
|---|
| 87 | void Sequence::read(DataInputStream* in) |
|---|
| 88 | { |
|---|
| 89 | |
|---|
| 90 | int id = in->peekInt(); |
|---|
| 91 | if(id == IVESEQUENCE) |
|---|
| 92 | { |
|---|
| 93 | |
|---|
| 94 | id = in->readInt(); |
|---|
| 95 | |
|---|
| 96 | osg::Group* group = dynamic_cast<osg::Group*>(this); |
|---|
| 97 | if(group) |
|---|
| 98 | { |
|---|
| 99 | ((ive::Group*)(group))->read(in); |
|---|
| 100 | } |
|---|
| 101 | else |
|---|
| 102 | { |
|---|
| 103 | in_THROW_EXCEPTION("Sequence::read(): Could not cast this osg::Sequence to an osg::Group."); |
|---|
| 104 | } |
|---|
| 105 | |
|---|
| 106 | |
|---|
| 107 | |
|---|
| 108 | if (in->getVersion() >= VERSION_0022) |
|---|
| 109 | { |
|---|
| 110 | |
|---|
| 111 | setDefaultTime(in->readFloat()); |
|---|
| 112 | } |
|---|
| 113 | |
|---|
| 114 | |
|---|
| 115 | int size = in->readInt(); |
|---|
| 116 | for(int i=0;i<size;i++) |
|---|
| 117 | { |
|---|
| 118 | setTime(i, in->readFloat()); |
|---|
| 119 | } |
|---|
| 120 | |
|---|
| 121 | if (in->getVersion() >= VERSION_0022) |
|---|
| 122 | { |
|---|
| 123 | |
|---|
| 124 | setLastFrameTime(in->readFloat()); |
|---|
| 125 | } |
|---|
| 126 | |
|---|
| 127 | |
|---|
| 128 | int mode = in->readInt(); |
|---|
| 129 | int begin = in->readInt(); |
|---|
| 130 | int end = in->readInt(); |
|---|
| 131 | setInterval((osg::Sequence::LoopMode)mode, begin, end); |
|---|
| 132 | |
|---|
| 133 | |
|---|
| 134 | float speed = in->readFloat(); |
|---|
| 135 | int nreps = in->readInt(); |
|---|
| 136 | setDuration(speed, nreps); |
|---|
| 137 | |
|---|
| 138 | |
|---|
| 139 | setMode((osg::Sequence::SequenceMode)in->readInt()); |
|---|
| 140 | |
|---|
| 141 | if (in->getVersion() >= VERSION_0022) |
|---|
| 142 | { |
|---|
| 143 | |
|---|
| 144 | setSync((in->readInt())!=0) ; |
|---|
| 145 | |
|---|
| 146 | |
|---|
| 147 | setClearOnStop((in->readInt())!=0) ; |
|---|
| 148 | } |
|---|
| 149 | } |
|---|
| 150 | else |
|---|
| 151 | { |
|---|
| 152 | in_THROW_EXCEPTION("Sequence::read(): Expected Sequence identification."); |
|---|
| 153 | } |
|---|
| 154 | } |
|---|