| 89 | //----------------------------------------------------------------------------- |
| 90 | |
| 91 | bool DecalDataFile::write( Stream& stream ) |
| 92 | { |
| 93 | // Write our identifier... so we have a better |
| 94 | // idea if we're reading pure garbage. |
| 95 | // This identifier stands for "Torque Decal Data File". |
| 96 | stream.write( 4, "TDDF" ); |
| 97 | |
| 98 | // Now the version number. |
| 99 | stream.write( (U8)FILE_VERSION ); |
| 100 | |
| 101 | Vector<DecalInstance*> allDecals; |
| 102 | |
| 103 | // Gather all DecalInstances that should be saved. |
| 104 | for ( U32 i = 0; i < mSphereList.size(); i++ ) |
| 105 | { |
| 106 | Vector<DecalInstance*>::const_iterator item = mSphereList[i]->mItems.begin(); |
| 107 | for ( ; item != mSphereList[i]->mItems.end(); item++ ) |
| 108 | { |
| 109 | if ( (*item)->mFlags & SaveDecal ) |
| 110 | allDecals.push_back( (*item) ); |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | // Gather all the DecalData datablocks used. |
| 115 | Vector<const DecalData*> allDatablocks; |
| 116 | for ( U32 i = 0; i < allDecals.size(); i++ ) |
| 117 | allDatablocks.push_back_unique( allDecals[i]->mDataBlock ); |
| 118 | |
| 119 | // Write out datablock lookupNames. |
| 120 | U32 count = allDatablocks.size(); |
| 121 | stream.write( count ); |
| 122 | for ( U32 i = 0; i < count; i++ ) |
| 123 | stream.write( allDatablocks[i]->lookupName ); |
| 124 | |
| 125 | Vector<const DecalData*>::iterator dataIter; |
| 126 | |
| 127 | // Write out the DecalInstance list. |
| 128 | count = allDecals.size(); |
| 129 | stream.write( count ); |
| 130 | for ( U32 i = 0; i < count; i++ ) |
| 131 | { |
| 132 | DecalInstance *inst = allDecals[i]; |
| 133 | |
| 134 | dataIter = T3D::find( allDatablocks.begin(), allDatablocks.end(), inst->mDataBlock ); |
| 135 | U8 dataIndex = dataIter - allDatablocks.begin(); |
| 136 | |
| 137 | stream.write( dataIndex ); |
| 138 | mathWrite( stream, inst->mPosition ); |
| 139 | mathWrite( stream, inst->mNormal ); |
| 140 | mathWrite( stream, inst->mTangent ); |
| 141 | stream.write( inst->mTextureRectIdx ); |
| 142 | stream.write( inst->mSize ); |
| 143 | stream.write( inst->mRenderPriority ); |
| 144 | } |
| 145 | |
| 146 | // Clear the dirty flag. |
| 147 | mIsDirty = false; |
| 148 |
no test coverage detected