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