| 171 | } |
| 172 | |
| 173 | bool ForestData::write( const char *path ) |
| 174 | { |
| 175 | // Open the stream. |
| 176 | FileStream stream; |
| 177 | if ( !stream.open( path, Torque::FS::File::Write ) ) |
| 178 | { |
| 179 | Con::errorf( "ForestDataFile::write() - Failed opening stream!" ); |
| 180 | return false; |
| 181 | } |
| 182 | |
| 183 | // Write our identifier... so we have a better |
| 184 | // idea if we're reading pure garbage. |
| 185 | stream.write( 4, "FKDF" ); |
| 186 | |
| 187 | // Now the version number. |
| 188 | stream.write( (U8)FILE_VERSION ); |
| 189 | |
| 190 | // First gather all the ForestItemData datablocks |
| 191 | // used by the items in the forest. |
| 192 | Vector<ForestItemData*> allDatablocks; |
| 193 | getDatablocks( &allDatablocks ); |
| 194 | |
| 195 | // Write out the datablock list. |
| 196 | U32 count = allDatablocks.size(); |
| 197 | stream.write( count ); |
| 198 | for ( U32 i=0; i < count; i++ ) |
| 199 | { |
| 200 | StringTableEntry localName = allDatablocks[i]->getInternalName(); |
| 201 | AssertFatal( localName != NULL && localName[0] != '\0', "ForestData::write - ForestItemData had no internal name set!" ); |
| 202 | stream.writeString( allDatablocks[i]->getInternalName() ); |
| 203 | } |
| 204 | |
| 205 | // Get a copy of all the items. |
| 206 | Vector<ForestItem> items; |
| 207 | getItems( &items ); |
| 208 | |
| 209 | // Save the item count. |
| 210 | stream.write( (U32)items.size() ); |
| 211 | |
| 212 | // Save the items. |
| 213 | Vector<ForestItem>::const_iterator iter = items.begin(); |
| 214 | for ( ; iter != items.end(); iter++ ) |
| 215 | { |
| 216 | U8 dataIndex = T3D::find( allDatablocks.begin(), allDatablocks.end(), iter->getData() ) - allDatablocks.begin(); |
| 217 | |
| 218 | stream.write( dataIndex ); |
| 219 | |
| 220 | mathWrite( stream, iter->getPosition() ); |
| 221 | |
| 222 | QuatF quat; |
| 223 | quat.set( iter->getTransform() ); |
| 224 | mathWrite( stream, quat ); |
| 225 | |
| 226 | stream.write( iter->getScale() ); |
| 227 | } |
| 228 | |
| 229 | // Clear the dirty flag. |
| 230 | mIsDirty = false; |
no test coverage detected