==================== idMD5Anim::LoadAnim ==================== */
| 159 | ==================== |
| 160 | */ |
| 161 | bool idMD5Anim::LoadAnim( const char *filename ) { |
| 162 | int version; |
| 163 | idLexer parser( LEXFL_ALLOWPATHNAMES | LEXFL_NOSTRINGESCAPECHARS | LEXFL_NOSTRINGCONCAT ); |
| 164 | idToken token; |
| 165 | int i, j; |
| 166 | int num; |
| 167 | |
| 168 | if ( !parser.LoadFile( filename ) ) { |
| 169 | return false; |
| 170 | } |
| 171 | |
| 172 | Free(); |
| 173 | |
| 174 | name = filename; |
| 175 | |
| 176 | parser.ExpectTokenString( MD5_VERSION_STRING ); |
| 177 | version = parser.ParseInt(); |
| 178 | if ( version != MD5_VERSION ) { |
| 179 | parser.Error( "Invalid version %d. Should be version %d\n", version, MD5_VERSION ); |
| 180 | } |
| 181 | |
| 182 | // skip the commandline |
| 183 | parser.ExpectTokenString( "commandline" ); |
| 184 | parser.ReadToken( &token ); |
| 185 | |
| 186 | // parse num frames |
| 187 | parser.ExpectTokenString( "numFrames" ); |
| 188 | numFrames = parser.ParseInt(); |
| 189 | if ( numFrames <= 0 ) { |
| 190 | parser.Error( "Invalid number of frames: %d", numFrames ); |
| 191 | } |
| 192 | |
| 193 | // parse num joints |
| 194 | parser.ExpectTokenString( "numJoints" ); |
| 195 | numJoints = parser.ParseInt(); |
| 196 | if ( numJoints <= 0 ) { |
| 197 | parser.Error( "Invalid number of joints: %d", numJoints ); |
| 198 | } |
| 199 | |
| 200 | // parse frame rate |
| 201 | parser.ExpectTokenString( "frameRate" ); |
| 202 | frameRate = parser.ParseInt(); |
| 203 | if ( frameRate < 0 ) { |
| 204 | parser.Error( "Invalid frame rate: %d", frameRate ); |
| 205 | } |
| 206 | |
| 207 | // parse number of animated components |
| 208 | parser.ExpectTokenString( "numAnimatedComponents" ); |
| 209 | numAnimatedComponents = parser.ParseInt(); |
| 210 | if ( ( numAnimatedComponents < 0 ) || ( numAnimatedComponents > numJoints * 6 ) ) { |
| 211 | parser.Error( "Invalid number of animated components: %d", numAnimatedComponents ); |
| 212 | } |
| 213 | |
| 214 | // parse the hierarchy |
| 215 | jointInfo.SetGranularity( 1 ); |
| 216 | jointInfo.SetNum( numJoints ); |
| 217 | parser.ExpectTokenString( "hierarchy" ); |
| 218 | parser.ExpectTokenString( "{" ); |
no test coverage detected