- Timestamp:
- 03/21/12 18:36:20 (14 months ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/src/osgPlugins/txp/trpage_rarchive.cpp
r12597 r13041 136 136 trpgHeader blockHeader; 137 137 trpgr_Parser bparser; 138 138 139 139 char blockpath[1024]; 140 140 //open the block archive … … 152 152 if ( (bmagic != GetMagicNumber()) && (trpg_byteswap_int(bmagic) != GetMagicNumber()) ) 153 153 return false; 154 154 155 155 int32 bheaderSize=0; 156 if (fread(&bheaderSize,sizeof(int32),1,bfp) != 1) 156 if (fread(&bheaderSize,sizeof(int32),1,bfp) != 1) 157 157 return false; 158 158 if (ness != cpuNess) 159 159 bheaderSize = trpg_byteswap_int(bheaderSize); 160 160 int bheadLen = bheaderSize; 161 if (bheadLen < 0) 161 if (bheadLen < 0) 162 162 return false; 163 163 … … 166 166 bbuf.SetLength(bheadLen); 167 167 char *bdata = bbuf.GetDataPtr(); 168 if ((ret = GetHeaderData(bdata,bheadLen,bfp)) != bheadLen) 169 return false; 170 //keep track of where this came from in the master table. 168 if ((ret = GetHeaderData(bdata,bheadLen,bfp)) != bheadLen) 169 return false; 170 //keep track of where this came from in the master table. 171 171 tileTable.SetCurrentBlock(row,col,true); 172 172 texTable.SetCurrentBlock(row,col); 173 173 174 174 bparser.AddCallback(TRPGHEADER,&blockHeader); 175 175 bparser.AddCallback(TRPGMATTABLE,&materialTable); // Went back to oldest style for 2.0 … … 181 181 bparser.AddCallback(TRPGRANGETABLE,&rangeTable); // Added for 2.0 182 182 bparser.AddCallback(TRPG_TEXT_STYLE_TABLE,&textStyleTable); // Added for 2.1 183 bparser.AddCallback(TRPG_SUPPORT_STYLE_TABLE,&supportStyleTable); 184 bparser.AddCallback(TRPG_LABEL_PROPERTY_TABLE,&labelPropertyTable); 183 bparser.AddCallback(TRPG_SUPPORT_STYLE_TABLE,&supportStyleTable); 184 bparser.AddCallback(TRPG_LABEL_PROPERTY_TABLE,&labelPropertyTable); 185 185 // Don't read the tile table for v1.0 archives 186 186 // It's only really used for 2.0 archives … … 217 217 trpgEndian cpuNess = trpg_cpu_byte_order(); 218 218 int32 headerSize; 219 if (fread(&headerSize,sizeof(int32),1,fp) != 1) 219 if (fread(&headerSize,sizeof(int32),1,fp) != 1) 220 220 return false; 221 221 if (ness != cpuNess) 222 222 headerSize = trpg_byteswap_int(headerSize); 223 223 int headLen = headerSize; 224 if (headLen < 0) 224 if (headLen < 0) 225 225 return false; 226 226 … … 229 229 buf.SetLength(headLen); 230 230 char *data = buf.GetDataPtr(); 231 if ((ret = GetHeaderData(data,headLen,fp)) != headLen) 231 if ((ret = GetHeaderData(data,headLen,fp)) != headLen) 232 232 return false; 233 233 … … 246 246 parser.AddCallback(TRPGRANGETABLE,&rangeTable); // Added for 2.0 247 247 parser.AddCallback(TRPG_TEXT_STYLE_TABLE,&textStyleTable); // Added for 2.1 248 parser.AddCallback(TRPG_SUPPORT_STYLE_TABLE,&supportStyleTable); 249 parser.AddCallback(TRPG_LABEL_PROPERTY_TABLE,&labelPropertyTable); 248 parser.AddCallback(TRPG_SUPPORT_STYLE_TABLE,&supportStyleTable); 249 parser.AddCallback(TRPG_LABEL_PROPERTY_TABLE,&labelPropertyTable); 250 250 // Don't read the tile table for v1.0 archives 251 251 // It's only really used for 2.0 archives … … 256 256 return false; 257 257 258 if(header.GetIsMaster()) 258 if(header.GetIsMaster()) 259 259 { 260 260 // bool firstBlock = true; … … 316 316 bool trpgr_Archive::ReadTile(uint32 x,uint32 y,uint32 lod,trpgMemReadBuffer &buf) 317 317 { 318 if (!isValid()) 318 if (!isValid()) 319 319 return false; 320 320 … … 322 322 int32 numLods; 323 323 header.GetNumLods(numLods); 324 if (static_cast<int>(lod) >= numLods) 324 if (static_cast<int>(lod) >= numLods) 325 325 return false; 326 326 trpg2iPoint lodSize; 327 327 header.GetLodSize(lod,lodSize); 328 if (static_cast<int>(x) >= lodSize.x || static_cast<int>(y) >= lodSize.y) 328 if (static_cast<int>(x) >= lodSize.x || static_cast<int>(y) >= lodSize.y) 329 329 return false; 330 330 … … 335 335 if (tileMode == trpgTileTable::External || tileMode == trpgTileTable::ExternalSaved) { 336 336 status = ReadExternalTile(x, y, lod, buf); 337 337 338 338 } else { 339 339 // Local tile. Figure out where it is (which file) … … 387 387 } 388 388 // Find the file end 389 if (fseek(fp,0,SEEK_END)) 389 if (fseek(fp,0,SEEK_END)) 390 390 throw 1; 391 391 // Note: This means tile is capped at 2 gigs 392 392 long pos = ftell(fp); 393 if (fseek(fp,0,SEEK_SET)) 393 if (fseek(fp,0,SEEK_SET)) 394 394 throw 1; 395 395 // Now we know the size. Read the whole file 396 396 buf.SetLength(pos); 397 397 char *data = buf.GetDataPtr(); 398 if (fread(data,pos,1,fp) != 1) 398 if (fread(data,pos,1,fp) != 1) 399 399 throw 1; 400 fclose(fp); 400 fclose(fp); 401 401 fp = NULL; 402 402 } … … 413 413 // Fetch the appendable file from the cache 414 414 trpgrAppFile *tf = tileCache->GetFile(ness,addr.file,addr.col,addr.row); 415 if (!tf) 415 if (!tf) 416 416 return false; 417 417 … … 432 432 return &materialTable; 433 433 } 434 trpgTexTable *trpgr_Archive::GetTexTable() 434 trpgTexTable *trpgr_Archive::GetTexTable() 435 435 { 436 436 return &texTable; … … 532 532 geotypCache = texCache; 533 533 } 534 534 535 535 } 536 536 … … 614 614 // or overhaul this in some other fashion. 615 615 int numTables; 616 if (!matTable->GetNumTable(numTables)) 617 return false; 618 if (index>=numTables) 616 if (!matTable->GetNumTable(numTables)) 617 return false; 618 if (index>=numTables) 619 619 return false; 620 620 if (index>0) matSubTable=index; // otherwise, leave it alone - could be nonzero 621 621 const trpgMaterial *mat = matTable->GetMaterialRef(matSubTable,matID); 622 if (!mat) 622 if (!mat) 623 623 return false; 624 624 … … 626 626 trpgTextureEnv texEnv; 627 627 int32 texID; 628 if (!mat->GetTexture(0,texID,texEnv)) 628 if (!mat->GetTexture(0,texID,texEnv)) 629 629 return false; 630 630 const trpgTexture *tex = texTable->GetTextureRef(texID); 631 if (!tex) 631 if (!tex) 632 632 return false; 633 633 … … 646 646 bool trpgrImageHelper::GetNthImageForLocalMat(const trpgLocalMaterial *locMat,int index, char *data,int dataSize) 647 647 { 648 if (!locMat->isValid()) 648 if (!locMat->isValid()) 649 649 return false; 650 650 … … 665 665 if (!locMat->GetNthAddr(index,addr)) return false; 666 666 trpgrAppFile *af = texCache->GetFile(ness,addr.file,addr.col,addr.row); 667 if (!af) 667 if (!af) 668 668 return false; 669 669 if (!af->Read(data,addr.offset,0,dataSize))
