#include #include #include template T readType(char* data, size_t* offset) { size_t orgoff = *offset; *offset += sizeof(T); return *reinterpret_cast(data+orgoff); } bool LoaderCOL::load(const std::string& file) { std::ifstream dfile(file.c_str()); if ( ! dfile.is_open()) { return false; } dfile.seekg(0, std::ios_base::end); size_t length = dfile.tellg(); dfile.seekg(0); char* data = new char[length]; dfile.read(data, length); char* dataptr = data; int version = 1; std::string verstr(dataptr, 4); if(verstr == "COLL") { } else if(verstr == "COL2") { version = 2; } else if(verstr == "COL3") { version = 3; } size_t dataI = 4; auto filesize = readType(data, &dataI); CollTHeader head = readType(data, &dataI); CollTHeaderV2 head2; CollTHeaderV3 head3; if(version >= 2) { head2 = readType(data, &dataI); if(version >= 3) { head3 = readType(data, &dataI); } } if(version == 1) { head2.numspheres = readType(data, &dataI); head2.offsetspheres = dataI-4; } // Read spheres dataI += sizeof(CollTSphere) * head2.numspheres; if(version == 1) { // skip unused bytes dataI += sizeof(uint32_t); } if(version == 1) { head2.numboxes = readType(data, &dataI); head2.offsetboxes = dataI-4; } dataI += sizeof(CollTBox) * head2.numboxes; if(version == 1) { uint32_t numverts = readType(data, &dataI); dataI += sizeof(CollTVertex) * numverts; } return true; }