| 84 | } |
| 85 | |
| 86 | bool ForestData::read( Stream &stream ) |
| 87 | { |
| 88 | // Read our identifier... so we know we're |
| 89 | // not reading in pure garbage. |
| 90 | char id[4] = { 0 }; |
| 91 | stream.read( 4, id ); |
| 92 | if ( dMemcmp( id, "FKDF", 4 ) != 0 ) |
| 93 | { |
| 94 | Con::errorf( "ForestDataFile::read() - This is not a Forest planting file!" ); |
| 95 | return false; |
| 96 | } |
| 97 | |
| 98 | // Empty ourselves before we really begin reading. |
| 99 | clear(); |
| 100 | |
| 101 | // Now the version number. |
| 102 | U8 version; |
| 103 | stream.read( &version ); |
| 104 | if ( version > (U8)FILE_VERSION ) |
| 105 | { |
| 106 | Con::errorf( "ForestDataFile::read() - This file was created with an newer version of Forest!" ); |
| 107 | return false; |
| 108 | } |
| 109 | |
| 110 | // Read in the names of the ForestItemData datablocks |
| 111 | // and recover the datablock. |
| 112 | Vector<ForestItemData*> allDatablocks; |
| 113 | U32 count; |
| 114 | stream.read( &count ); |
| 115 | allDatablocks.setSize( count ); |
| 116 | for ( U32 i=0; i < count; i++ ) |
| 117 | { |
| 118 | StringTableEntry name = stream.readSTString(); |
| 119 | ForestItemData* data = ForestItemData::find( name ); |
| 120 | |
| 121 | // TODO: Change this to instead create a dummy forest data |
| 122 | // for each so that the user can swap it with the right one. |
| 123 | if ( data == NULL ) |
| 124 | { |
| 125 | Con::warnf( "ForestData::read - ForestItemData named %s was not found.", name ); |
| 126 | Con::warnf( "Note this can occur if you have deleted or renamed datablocks prior to loading this forest and is not an 'error' in this scenario." ); |
| 127 | } |
| 128 | |
| 129 | allDatablocks[ i ] = data; |
| 130 | } |
| 131 | |
| 132 | U8 dataIndex; |
| 133 | Point3F pos; |
| 134 | QuatF rot; |
| 135 | F32 scale; |
| 136 | ForestItemData* data; |
| 137 | MatrixF xfm; |
| 138 | |
| 139 | U32 skippedItems = 0; |
| 140 | |
| 141 | // Read in the items. |
| 142 | stream.read( &count ); |
| 143 | for ( U32 i=0; i < count; i++ ) |
no test coverage detected