/* ************************ Copyright Terrain Experts Inc. Terrain Experts Inc (TERREX) reserves all rights to this source code unless otherwise specified in writing by the President of TERREX. This copyright may be updated in the future, in which case that version supercedes this one. ------------------- Terrex Experts Inc. 4400 East Broadway #314 Tucson, AZ 85711 info@terrex.com Tel: (520) 323-7990 ************************ */ #include #include #include /* trpage_compat.cpp This file and the accompanying trpage_compat.h contain objects and procedures used to maintain compatibility between versions of TerraPage. In particular, the ability to read older versions of TerraPage and newer applications. */ #include #include #include /* Old short Material definition from 1.0. {secret} */ class trpgShortMaterial { public: // Full trpgMaterial definition this one is based on int baseMat; // Currently the only thing a short material overrides is texture std::vector texids; }; trpgMatTable1_0::trpgMatTable1_0(const trpgMatTable &inTbl) { *((trpgMatTable *)this) = inTbl; } bool trpgMatTable1_0::Read(trpgReadBuffer &buf) { trpgMaterial mat; trpgToken matTok; int32 len; bool status; unsigned int i,j,k; std::vector shortTable; std::vector baseMats; try { buf.Get(numTable); buf.Get(numMat); if (numTable <= 0 || numMat < 0) throw 1; // Short material tables are always full size shortTable.resize(numTable*numMat); // Look for short material table buf.GetToken(matTok,len); if (matTok == TRPGSHORTMATTABLE) { int32 numTex,texId; buf.PushLimit(len); for (i=0;i<(unsigned int)numTable;i++) for (j=0;j<(unsigned int)numMat;j++) { trpgShortMaterial &smat = shortTable[i*numMat+j]; buf.Get(smat.baseMat); buf.Get(numTex); for (k=0;k<(unsigned int)numTex;k++) { buf.Get(texId); smat.texids.push_back(texId); } } buf.PopLimit(); // Now read the base materials int32 numBaseMat; buf.Get(numBaseMat); if (numBaseMat < 0) throw 1; baseMats.resize(numBaseMat); for (i=0;i<(unsigned int)numBaseMat;i++) { buf.GetToken(matTok,len); if (matTok != TRPGMATERIAL) throw 1; buf.PushLimit(len); mat.Reset(); status = mat.Read(buf); buf.PopLimit(); if (!status) throw 1; baseMats[i] = mat; } } } catch (...) { return false; } // Now convert to the new style material table for (i=0;i shortMats; shortMats.resize(numTable*numMat); // Iterate over the existing materials int i; for (i=0;i