--------------------------------------
| 156 | |
| 157 | //-------------------------------------- |
| 158 | bool MaterialList::read(Stream &stream) |
| 159 | { |
| 160 | free(); |
| 161 | |
| 162 | // check the stream version |
| 163 | U8 version; |
| 164 | if ( stream.read(&version) && version != BINARY_FILE_VERSION) |
| 165 | return readText(stream,version); |
| 166 | |
| 167 | // how many materials? |
| 168 | U32 count; |
| 169 | if ( !stream.read(&count) ) |
| 170 | return false; |
| 171 | |
| 172 | // pre-size the vectors for efficiency |
| 173 | mMaterialNames.reserve(count); |
| 174 | |
| 175 | // read in the materials |
| 176 | for (U32 i=0; i<count; i++) |
| 177 | { |
| 178 | // Load the bitmap name |
| 179 | char buffer[256]; |
| 180 | stream.readString(buffer); |
| 181 | if( !buffer[0] ) |
| 182 | { |
| 183 | AssertWarn(0, "MaterialList::read: error reading stream"); |
| 184 | return false; |
| 185 | } |
| 186 | |
| 187 | // Material paths are a legacy of Tribes tools, |
| 188 | // strip them off... |
| 189 | char *name = &buffer[dStrlen(buffer)]; |
| 190 | while (name != buffer && name[-1] != '/' && name[-1] != '\\') |
| 191 | name--; |
| 192 | |
| 193 | // Add it to the list |
| 194 | mMaterialNames.push_back(name); |
| 195 | mMatInstList.push_back(NULL); |
| 196 | } |
| 197 | |
| 198 | return (stream.getStatus() == Stream::Ok); |
| 199 | } |
| 200 | |
| 201 | //-------------------------------------- |
| 202 | bool MaterialList::write(Stream &stream) |