I'm confused as to what exactly is going on in this code
Here is some code I found for loading Milkshape3f files (ms3d).
When I found it, it was for the most part uncommented, so I added some before posting.
Code:
ifstream inputFile( filename, ios::in | ios::binary | ios::nocreate );
if ( inputFile.fail())
return false; // "Couldn't open the model file."
inputFile.seekg( 0, ios::end ); //GO TO THE END OF THE FILE
long fileSize = inputFile.tellg(); //SEE HOW BIG THE FILE IS
inputFile.seekg( 0, ios::beg ); //POSITION BACK TO THE BEGINNING SO YOU CAN READ EVERYTHING IN
byte *pBuffer = new byte[fileSize]; //CREATE A BUFFER TO HOLD EVERYTHING IN THE FILE
inputFile.read( pBuffer, fileSize ); //READ EVERYTHING INTO PBUFFER UNTIL FILESIZE IS REACHED
inputFile.close();
const byte *pPtr = pBuffer;
MS3DHeader *pHeader = ( MS3DHeader* )pPtr;
//pPTR CONTAINS EVERYTHING IN THE MS3D FILE
pPtr += sizeof( MS3DHeader );
if ( strncmp( pHeader->m_ID, "MS3D000000", 10 ) != 0 )
return false; // "Not a valid Milkshape3D model file."
So basically the buffer contains everything that was stored in the ms3d file. Everything in the ms3d file is read into pBuffer until the filesize is reached (the end of the file).
pPtr is assigned to everything in pBuffer. pHeader (which is a milkshape 3d header) is assigned to pPtr. the sizeof a milkshape 3d header is added to pPtr. Then information in the header is checked to make sure it is a valid ms3d file. The thing I dont' get is why is the sizeof a header added to pPtr (pPtr is everything in pBuffer, pBuffer is everything that is in the file). Shouldn't the header information already be in the file without having to modify any of the buffers?