#include "Object.h" #include ///////////////////////////////////////////////////////////////////////// // public constructor/destructor Object::Object(const char* path) { // open file fsMesh.open(path, std::ios::in | std::ios::binary); if (!fsMesh.is_open()) throw std::invalid_argument(std::string("file not found: ") += path); fsMesh.seekg(8); char tempChunkName[5] = { 0 }; fsMesh.read(reinterpret_cast(&tempChunkName[0]), sizeof(tempChunkName) - 1); if (strcmp(tempChunkName, "MSH2")) throw std::invalid_argument(std::string("corrupted file MSH2 expected instead of ") += tempChunkName); fsMesh.seekg(4, std::ios_base::cur); loadChunks(lChunkMsh2, fsMesh.tellg(), "CL1L"); for (std::list::iterator it = lChunkMsh2.begin(); it != lChunkMsh2.end(); it++) { if (!strcmp("MODL", (*it)->name)) { loadChunks(lChunkModl, (*it)->position, "CL1L"); } } // close file fsMesh.close(); } Object::~Object() { //delete Chunk list; } ///////////////////////////////////////////////////////////////////////// // private functions void Object::loadChunks(std::list& destination, std::streampos start, const char end[5]) { // Jump into Mesh2 fsMesh.seekg(start); do { chunkHeader* tempHeader = new chunkHeader(); fsMesh.read(reinterpret_cast(&tempHeader->name[0]), sizeof(tempHeader->name) - 1); fsMesh.read(reinterpret_cast(&tempHeader->size), sizeof(tempHeader->size)); tempHeader->position = fsMesh.tellg(); destination.push_back(tempHeader); fsMesh.seekg(tempHeader->size, std::ios_base::cur); if (!std::strcmp(tempHeader->name, end)) break; } while (fsMesh.good()); std::cout << "got all chunks, totaly found: " << destination.size() << std::endl; } ///////////////////////////////////////////////////////////////////////// // public getter ///////////////////////////////////////////////////////////////////////// // public functions