Replaced tabs with four spaces

This commit is contained in:
Robert Osfield
2011-06-16 08:59:48 +00:00
parent 14b12f94e5
commit d0ccbf8219
30 changed files with 5395 additions and 5395 deletions

View File

@@ -11,8 +11,8 @@
* OpenSceneGraph Public License for more details.
*/
/* Dec 2010 - TileMapper was fixed and simplified
Nick
/* Dec 2010 - TileMapper was fixed and simplified
Nick
*/
#include "TileMapper.h"

View File

@@ -35,20 +35,20 @@ struct TileIdentifier : public osg::Referenced
x(-1),
y(-1),
lod(-1)
{}
{}
TileIdentifier(int ax, int ay, int alod):
x(ax),
y(ay),
lod(alod)
{}
{}
TileIdentifier(const TileIdentifier& rhs):
osg::Referenced(),
x(rhs.x),
y(rhs.y),
lod(rhs.lod)
{}
{}
TileIdentifier& operator = (const TileIdentifier& rhs)
{

View File

@@ -14,9 +14,9 @@
*/
/* trdll.h
Windows Only
Windows Only
This header file defines the declaration macros for DLLs.
This header file defines the declaration macros for DLLs.
*/
// Export/import declaration for classes and functions

View File

@@ -14,8 +14,8 @@
*/
/* trpage_basic.cpp
Methods for checkable base class.
*/
Methods for checkable base class.
*/
#include <stdlib.h>
#include <stdio.h>
@@ -23,22 +23,22 @@
#include <trpage_io.h>
/* Checkable
This is just a class that checks validity.
Starts out invalid.
*/
This is just a class that checks validity.
Starts out invalid.
*/
trpgCheckable::trpgCheckable()
{
valid = false;
handle = -1;
writeHandle = false;
valid = false;
handle = -1;
writeHandle = false;
}
trpgCheckable::~trpgCheckable()
{
valid = false;
valid = false;
}
bool trpgCheckable::isValid() const
{
return valid;
return valid;
}

View File

@@ -56,65 +56,65 @@ bool trpgMatTable1_0::Read(trpgReadBuffer &buf)
std::vector<trpgMaterial> baseMats;
try {
buf.Get(numTable);
buf.Get(numMat);
if (numTable <= 0 || numMat < 0) throw 1;
buf.Get(numTable);
buf.Get(numMat);
if (numTable <= 0 || numMat < 0) throw 1;
// Short material tables are always full size
shortTable.resize(numTable*numMat);
// 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);
// 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);
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();
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);
// 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;
}
}
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;
return false;
}
// Now convert to the new style material table
for (i=0;i<shortTable.size();i++) {
trpgShortMaterial &shortMat = shortTable[i];
trpgMaterial &baseMat = baseMats[shortMat.baseMat];
AddMaterial(baseMat,false);
trpgMaterial newMat = baseMat;
newMat.SetNumTexture(shortMat.texids.size());
for (j=0;j<shortMat.texids.size();j++) {
int texId;
trpgTextureEnv texEnv;
baseMat.GetTexture(j,texId,texEnv);
newMat.SetTexture(j,shortMat.texids[j],texEnv);
}
trpgShortMaterial &shortMat = shortTable[i];
trpgMaterial &baseMat = baseMats[shortMat.baseMat];
AddMaterial(baseMat,false);
trpgMaterial newMat = baseMat;
newMat.SetNumTexture(shortMat.texids.size());
for (j=0;j<shortMat.texids.size();j++) {
int texId;
trpgTextureEnv texEnv;
baseMat.GetTexture(j,texId,texEnv);
newMat.SetTexture(j,shortMat.texids[j],texEnv);
}
}
valid = true;
@@ -124,7 +124,7 @@ bool trpgMatTable1_0::Read(trpgReadBuffer &buf)
bool trpgMatTable1_0::Write(trpgWriteBuffer &buf)
{
if (!isValid())
return false;
return false;
// Create one short material for every material
std::vector<trpgShortMaterial> shortMats;
@@ -134,21 +134,21 @@ bool trpgMatTable1_0::Write(trpgWriteBuffer &buf)
MaterialMapType::iterator itr = materialMap.begin();
for ( ; itr != materialMap.end( ); itr++) {
//for (i=0;i<numTable*numMat;i++) {
trpgMaterial &mat = itr->second; //matTables[i];
// Fill in the short material
trpgShortMaterial &sMat = shortMats[i];
sMat.baseMat = 0;
int numTex;
mat.GetNumTexture(numTex);
for (int j=0;j<numTex;j++) {
int texId;
trpgTextureEnv texEnv;
mat.GetTexture(j,texId,texEnv);
sMat.texids.push_back(texId);
sMat.baseMat = i;
}
i++;
//for (i=0;i<numTable*numMat;i++) {
trpgMaterial &mat = itr->second; //matTables[i];
// Fill in the short material
trpgShortMaterial &sMat = shortMats[i];
sMat.baseMat = 0;
int numTex;
mat.GetNumTexture(numTex);
for (int j=0;j<numTex;j++) {
int texId;
trpgTextureEnv texEnv;
mat.GetTexture(j,texId,texEnv);
sMat.texids.push_back(texId);
sMat.baseMat = i;
}
i++;
}
// Write the 1.0 material table
@@ -159,12 +159,12 @@ bool trpgMatTable1_0::Write(trpgWriteBuffer &buf)
// Write the short materials
buf.Begin(TRPGSHORTMATTABLE);
for (i=0;i<static_cast<int>(shortMats.size());i++) {
trpgShortMaterial &sMat = shortMats[i];
buf.Add(sMat.baseMat);
buf.Add((int)(sMat.texids.size()));
unsigned int j;
for (j=0;j<sMat.texids.size();j++)
buf.Add(sMat.texids[j]);
trpgShortMaterial &sMat = shortMats[i];
buf.Add(sMat.baseMat);
buf.Add((int)(sMat.texids.size()));
unsigned int j;
for (j=0;j<sMat.texids.size();j++)
buf.Add(sMat.texids[j]);
}
buf.End();
@@ -174,11 +174,11 @@ bool trpgMatTable1_0::Write(trpgWriteBuffer &buf)
itr = materialMap.begin();
for ( ; itr != materialMap.end( ); itr++) {
trpgMaterial &mat = itr->second; //matTables[i];
trpgMaterial &mat = itr->second; //matTables[i];
// This will be bigger than the old 1.0 material, but it doesn't matter since
// the new stuff is on the end.
mat.Write(buf);
// This will be bigger than the old 1.0 material, but it doesn't matter since
// the new stuff is on the end.
mat.Write(buf);
}
// Close Mat Table
@@ -199,13 +199,13 @@ bool trpgTexture1_0::Read(trpgReadBuffer &buf)
mode = External;
try {
char texName[1024];
buf.Get(texName,1023);
SetName(texName);
buf.Get(useCount);
char texName[1024];
buf.Get(texName,1023);
SetName(texName);
buf.Get(useCount);
}
catch (...) {
return false;
return false;
}
return true;
@@ -215,7 +215,7 @@ bool trpgTexture1_0::Write(trpgWriteBuffer &buf)
{
// Can only deal with external textures in 1.0
if (mode != External)
return false;
return false;
// Write the name and use count
buf.Add(name);
@@ -234,17 +234,17 @@ bool trpgTexTable1_0::Read(trpgReadBuffer &buf)
int32 numTex;
try {
buf.Get(numTex);
//texList.resize(numTex);
for (int i=0;i<numTex;i++) {
trpgTexture1_0 tex1_0;
tex1_0.Read(buf);
AddTexture(tex1_0);
//texList[i] = tex1_0;
}
buf.Get(numTex);
//texList.resize(numTex);
for (int i=0;i<numTex;i++) {
trpgTexture1_0 tex1_0;
tex1_0.Read(buf);
AddTexture(tex1_0);
//texList[i] = tex1_0;
}
}
catch (...) {
return false;
return false;
}
valid = true;
@@ -256,7 +256,7 @@ bool trpgTexTable1_0::Write(trpgWriteBuffer &buf)
int32 numTex;
if (!isValid())
return false;
return false;
buf.Begin(TRPGTEXTABLE);
@@ -264,10 +264,10 @@ bool trpgTexTable1_0::Write(trpgWriteBuffer &buf)
buf.Add(numTex);
TextureMapType::const_iterator itr = textureMap.begin();
for ( ; itr != textureMap.end( ); itr++) {
trpgTexture1_0 tex1_0;
tex1_0 = itr->second;
if (!tex1_0.Write(buf))
return false;
trpgTexture1_0 tex1_0;
tex1_0 = itr->second;
if (!tex1_0.Write(buf))
return false;
}
buf.End();
@@ -283,12 +283,12 @@ trpgTileTable1_0::trpgTileTable1_0(const trpgTileTable& /*inTable*/)
bool trpgTileTable1_0::Write(trpgWriteBuffer &buf)
{
try {
buf.Begin(TRPGTILETABLE);
buf.Add("");
buf.End();
buf.Begin(TRPGTILETABLE);
buf.Add("");
buf.End();
}
catch (...) {
return false;
return false;
}
return true;

View File

@@ -34,13 +34,13 @@ public:
trpgMatTable1_0(const trpgMatTable &);
/* This read method overrides the one from trpgMatTable and knows
how to read the old school material tables.
how to read the old school material tables.
*/
bool Read(trpgReadBuffer &);
bool Read(trpgReadBuffer &);
/* This write method can write a 2.0 material table as 1.0
style for backward compatibility.
style for backward compatibility.
*/
bool Write(trpgWriteBuffer &);
bool Write(trpgWriteBuffer &);
protected:
};
@@ -56,13 +56,13 @@ public:
trpgTexTable1_0(const trpgTexTable &);
/* This read method overrides the one from trpgTexTable and
knows how to read the old style texture table.
knows how to read the old style texture table.
*/
bool Read(trpgReadBuffer &);
bool Read(trpgReadBuffer &);
/* The write method can write a 2.0 texture table as 1.0
style for backward compatibility.
style for backward compatibility.
*/
bool Write(trpgWriteBuffer &);
bool Write(trpgWriteBuffer &);
protected:
};
@@ -76,9 +76,9 @@ public:
trpgTexture1_0 operator = (const trpgTexture &);
// Knows how to read old style textures
bool Read(trpgReadBuffer &);
bool Read(trpgReadBuffer &);
// Can write old style textures
bool Write(trpgWriteBuffer &);
bool Write(trpgWriteBuffer &);
protected:
};
@@ -90,7 +90,7 @@ class trpgTileTable1_0 : public trpgTileTable {
public:
trpgTileTable1_0(const trpgTileTable &);
// Can write old style tile table
bool Write(trpgWriteBuffer &);
bool Write(trpgWriteBuffer &);
};
#endif

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -18,22 +18,22 @@
#include <string.h>
/* trpage_header.cpp
Source for trpgHeader methods.
The only reason to change this is if you want to add something
to the header definition.
*/
Source for trpgHeader methods.
The only reason to change this is if you want to add something
to the header definition.
*/
#include <trpage_geom.h>
#include <trpage_read.h>
/* Write Header class
Fill it in and write it out.
*/
Fill it in and write it out.
*/
// Constructor
trpgHeader::trpgHeader()
{
Reset();
Reset();
}
trpgHeader::~trpgHeader()
{
@@ -42,181 +42,181 @@ trpgHeader::~trpgHeader()
// Validity check
bool trpgHeader::isValid() const
{
// We also need to check that this is a 'master' archive here.
if((verMajor>=TRPG_NOMERGE_VERSION_MAJOR) && (verMinor>=TRPG_NOMERGE_VERSION_MINOR))
{
return true;
}
else {
if (numLods <= 0)
{
strcpy(errMess, "Number of LOD <= 0");
return false;
}
if (sw.x == ne.x && sw.y == ne.y)
{
strcpy(errMess, "Mbr is invalid");
// We also need to check that this is a 'master' archive here.
if((verMajor>=TRPG_NOMERGE_VERSION_MAJOR) && (verMinor>=TRPG_NOMERGE_VERSION_MINOR))
{
return true;
}
else {
if (numLods <= 0)
{
strcpy(errMess, "Number of LOD <= 0");
return false;
}
if (sw.x == ne.x && sw.y == ne.y)
{
strcpy(errMess, "Mbr is invalid");
return false;
}
}
return false;
}
}
return true;
return true;
}
// Reset contents
void trpgHeader::Reset()
{
// Initialize to a default state
verMinor = TRPG_VERSION_MINOR;
verMajor = TRPG_VERSION_MAJOR;
dbVerMinor = 0;
dbVerMajor = 0;
origin = trpg3dPoint(0,0,0);
sw = ne = trpg2dPoint(0,0);
tileType = DatabaseLocal;
// Initialize to a default state
verMinor = TRPG_VERSION_MINOR;
verMajor = TRPG_VERSION_MAJOR;
dbVerMinor = 0;
dbVerMajor = 0;
origin = trpg3dPoint(0,0,0);
sw = ne = trpg2dPoint(0,0);
tileType = DatabaseLocal;
numLods = 0;
lodSizes.resize(0);
lodRanges.resize(0);
tileSize.resize(0);
maxGroupID = -1;
flags = 0;
errMess[0] = '\0';
cols = -1;
rows = -1;
numLods = 0;
lodSizes.resize(0);
lodRanges.resize(0);
tileSize.resize(0);
maxGroupID = -1;
flags = 0;
errMess[0] = '\0';
cols = -1;
rows = -1;
}
// Set functions
void trpgHeader::SetVersion(int32 vmaj,int32 vmin)
{
verMinor = vmin;
verMajor = vmaj;
verMinor = vmin;
verMajor = vmaj;
}
void trpgHeader::SetDbVersion(int32 vmaj,int32 vmin)
{
dbVerMinor = vmin;
dbVerMajor = vmaj;
dbVerMinor = vmin;
dbVerMajor = vmaj;
}
void trpgHeader::SetTileSize(int id,const trpg2dPoint &pt)
{
if (id < 0 || id >= (int)tileSize.size()) return;
tileSize[id] = pt;
if (id < 0 || id >= (int)tileSize.size()) return;
tileSize[id] = pt;
}
void trpgHeader::SetOrigin(const trpg3dPoint &pt)
{
origin = pt;
origin = pt;
}
void trpgHeader::SetExtents(const trpg2dPoint &in_sw,const trpg2dPoint &in_ne)
{
sw = in_sw;
ne = in_ne;
sw = in_sw;
ne = in_ne;
}
void trpgHeader::SetTileOriginType(trpgTileType type)
{
tileType = type;
tileType = type;
}
void trpgHeader::SetNumLods(int no)
{
if (no < 0) return;
numLods = no;
if (no < 0) return;
numLods = no;
lodSizes.resize(no);
lodRanges.resize(no);
lodSizes.resize(no);
lodRanges.resize(no);
}
void trpgHeader::SetLodSize(int no,const trpg2iPoint &pt)
{
if (no < 0 || no >= numLods)
return;
if (no < 0 || no >= numLods)
return;
lodSizes[no] = pt;
lodSizes[no] = pt;
}
void trpgHeader::SetLodSize(const trpg2iPoint *pt)
{
for (int i=0;i<numLods;i++)
lodSizes[i] = pt[i];
for (int i=0;i<numLods;i++)
lodSizes[i] = pt[i];
}
void trpgHeader::SetLodRange(int no,float64 r)
{
if (no < 0 || no >= numLods)
return;
if (no < 0 || no >= numLods)
return;
lodRanges[no] = r;
lodRanges[no] = r;
}
void trpgHeader::SetLodRange(const float64 *r)
{
for (int i=0;i<numLods;i++)
lodRanges[i] = r[i];
for (int i=0;i<numLods;i++)
lodRanges[i] = r[i];
}
void trpgHeader::AddLod(const trpg2iPoint &pt,const trpg2dPoint &sz,float64 r)
{
lodRanges.push_back(r);
lodSizes.push_back(pt);
tileSize.push_back(sz);
numLods++;
lodRanges.push_back(r);
lodSizes.push_back(pt);
tileSize.push_back(sz);
numLods++;
}
void trpgHeader::SetLod(const trpg2iPoint &pt,const trpg2dPoint &sz,float64 r,unsigned int lod)
{
if (lodRanges.size()<=lod)
lodRanges.resize(lod+1);
lodRanges[lod]=r;
if (lodSizes.size()<=lod)
lodSizes.resize(lod+1);
lodSizes[lod]=pt;
if (tileSize.size()<=lod)
tileSize.resize(lod+1);
tileSize[lod]=sz;
if (numLods<=static_cast<int>(lod))
numLods=lod+1;
if (lodRanges.size()<=lod)
lodRanges.resize(lod+1);
lodRanges[lod]=r;
if (lodSizes.size()<=lod)
lodSizes.resize(lod+1);
lodSizes[lod]=pt;
if (tileSize.size()<=lod)
tileSize.resize(lod+1);
tileSize[lod]=sz;
if (numLods<=static_cast<int>(lod))
numLods=lod+1;
}
void trpgHeader::SetMaxGroupID(int id)
{
maxGroupID = id;
maxGroupID = id;
}
int trpgHeader::AddGroupID(void)
{
maxGroupID++;
return maxGroupID;
maxGroupID++;
return maxGroupID;
}
// Write out to a buffer
bool trpgHeader::Write(trpgWriteBuffer &buf)
{
if (!isValid())
return false;
if (!isValid())
return false;
buf.Begin(TRPGHEADER);
buf.Add((int32)verMajor);
buf.Add((int32)verMinor);
buf.Add((int32)dbVerMajor);
buf.Add((int32)dbVerMinor);
buf.Add(origin);
buf.Add(sw);
buf.Add(ne);
buf.Add((uint8)tileType);
buf.Begin(TRPGHEADER);
buf.Add((int32)verMajor);
buf.Add((int32)verMinor);
buf.Add((int32)dbVerMajor);
buf.Add((int32)dbVerMinor);
buf.Add(origin);
buf.Add(sw);
buf.Add(ne);
buf.Add((uint8)tileType);
buf.Add((int32)numLods);
buf.Add((int32)numLods);
buf.Begin(TRPGHEAD_LODINFO);
for (int i=0;i<numLods;i++) {
buf.Add(lodSizes[i]);
buf.Add(lodRanges[i]);
buf.Add(tileSize[i]);
}
buf.End();
buf.Begin(TRPGHEAD_LODINFO);
for (int i=0;i<numLods;i++) {
buf.Add(lodSizes[i]);
buf.Add(lodRanges[i]);
buf.Add(tileSize[i]);
}
buf.End();
buf.Add(maxGroupID);
buf.Add(maxGroupID);
if((verMajor >= TRPG_NOMERGE_VERSION_MAJOR) && (verMinor >=TRPG_NOMERGE_VERSION_MINOR)) {
buf.Add(flags);
buf.Add(rows);
buf.Add(cols);
}
if((verMajor >= TRPG_NOMERGE_VERSION_MAJOR) && (verMinor >=TRPG_NOMERGE_VERSION_MINOR)) {
buf.Add(flags);
buf.Add(rows);
buf.Add(cols);
}
buf.End();
buf.End();
return true;
return true;
}
/* ********
@@ -226,133 +226,133 @@ bool trpgHeader::Write(trpgWriteBuffer &buf)
// Get Functions
bool trpgHeader::GetVersion(int32 &vmaj,int32 &vmin) const
{
if (!isValid()) return false;
vmin = verMinor;
vmaj = verMajor;
return true;
if (!isValid()) return false;
vmin = verMinor;
vmaj = verMajor;
return true;
}
bool trpgHeader::GetDbVersion(int32 &vmaj,int32 &vmin) const
{
if (!isValid()) return false;
vmaj = dbVerMajor;
vmin = dbVerMinor;
return true;
if (!isValid()) return false;
vmaj = dbVerMajor;
vmin = dbVerMinor;
return true;
}
bool trpgHeader::GetTileSize(int id,trpg2dPoint &pt) const
{
if (!isValid()) return false;
if (id < 0 || id >= (int)tileSize.size()) return false;
pt = tileSize[id];
return true;
if (!isValid()) return false;
if (id < 0 || id >= (int)tileSize.size()) return false;
pt = tileSize[id];
return true;
}
bool trpgHeader::GetOrigin(trpg3dPoint &pt) const
{
if (!isValid()) return false;
pt = origin;
return true;
if (!isValid()) return false;
pt = origin;
return true;
}
bool trpgHeader::GetTileOriginType(trpgTileType &type) const
{
if (!isValid()) return false;
type = tileType;
return true;
if (!isValid()) return false;
type = tileType;
return true;
}
bool trpgHeader::GetNumLods(int32 &no) const
{
if (!isValid()) return false;
no = numLods;
return true;
if (!isValid()) return false;
no = numLods;
return true;
}
bool trpgHeader::GetLodSize(int32 id,trpg2iPoint &pt) const
{
if (!isValid() || (id < 0 || id >= numLods)) return false;
pt = lodSizes[id];
return true;
if (!isValid() || (id < 0 || id >= numLods)) return false;
pt = lodSizes[id];
return true;
}
bool trpgHeader::GetLodRange(int32 id,float64 &range) const
{
if (!isValid() || (id < 0 || id >= numLods)) return false;
range = lodRanges[id];
return true;
if (!isValid() || (id < 0 || id >= numLods)) return false;
range = lodRanges[id];
return true;
}
bool trpgHeader::GetExtents(trpg2dPoint &osw,trpg2dPoint &one) const
{
if (!isValid()) return false;
osw = sw;
one = ne;
return true;
if (!isValid()) return false;
osw = sw;
one = ne;
return true;
}
bool trpgHeader::GetMaxGroupID(int &id) const
{
id = maxGroupID;
return true;
id = maxGroupID;
return true;
}
// Read in the header
bool trpgHeader::Read(trpgReadBuffer &buf)
{
uint8 i8;
trpgToken tok;
bool status;
int32 len;
uint8 i8;
trpgToken tok;
bool status;
int32 len;
try {
buf.Get(verMajor);
buf.Get(verMinor);
buf.Get(dbVerMajor);
buf.Get(dbVerMinor);
buf.Get(origin);
buf.Get(sw);
buf.Get(ne);
buf.Get(i8); tileType = (trpgTileType)i8;
buf.Get(numLods);
if (numLods < 0) throw 1;
try {
buf.Get(verMajor);
buf.Get(verMinor);
buf.Get(dbVerMajor);
buf.Get(dbVerMinor);
buf.Get(origin);
buf.Get(sw);
buf.Get(ne);
buf.Get(i8); tileType = (trpgTileType)i8;
buf.Get(numLods);
if (numLods < 0) throw 1;
// Read in the LOD range info
buf.GetToken(tok,len);
if (tok != TRPGHEAD_LODINFO) throw 1;
buf.PushLimit(len);
status = ReadLodInfo(buf);
buf.PopLimit();
if (!status) throw 1;
// Read in the LOD range info
buf.GetToken(tok,len);
if (tok != TRPGHEAD_LODINFO) throw 1;
buf.PushLimit(len);
status = ReadLodInfo(buf);
buf.PopLimit();
if (!status) throw 1;
// Added after the first version (but still in 1.0)
buf.Get(maxGroupID);
if((verMajor >= TRPG_NOMERGE_VERSION_MAJOR) && (verMinor >=TRPG_NOMERGE_VERSION_MINOR)) {
buf.Get(flags);
buf.Get(rows);
buf.Get(cols);
}
}
// Added after the first version (but still in 1.0)
buf.Get(maxGroupID);
if((verMajor >= TRPG_NOMERGE_VERSION_MAJOR) && (verMinor >=TRPG_NOMERGE_VERSION_MINOR)) {
buf.Get(flags);
buf.Get(rows);
buf.Get(cols);
}
}
catch (...) {
return false;
}
catch (...) {
return false;
}
return isValid();
return isValid();
}
// Read the LOD info (seperate token)
bool trpgHeader::ReadLodInfo(trpgReadBuffer &buf)
{
float64 range;
trpg2iPoint pt;
trpg2dPoint sz;
float64 range;
trpg2iPoint pt;
trpg2dPoint sz;
try {
for (int i=0;i<numLods;i++) {
buf.Get(pt);
buf.Get(range);
buf.Get(sz);
lodSizes.push_back(pt);
lodRanges.push_back(range);
tileSize.push_back(sz);
}
}
catch (...) {
return false;
}
try {
for (int i=0;i<numLods;i++) {
buf.Get(pt);
buf.Get(range);
buf.Get(sz);
lodSizes.push_back(pt);
lodRanges.push_back(range);
tileSize.push_back(sz);
}
}
catch (...) {
return false;
}
return true;
return true;
}

File diff suppressed because it is too large Load Diff

View File

@@ -309,7 +309,7 @@ bool trpgTextStyleTable::Read(trpgReadBuffer &buf)
int32 len;
bool status;
int numStyle;
int i;
int i;
Reset();
@@ -319,7 +319,7 @@ bool trpgTextStyleTable::Read(trpgReadBuffer &buf)
if (numStyle < 0)
throw 1;
for (i=0;i<numStyle;i++) {
for (i=0;i<numStyle;i++) {
buf.GetToken(styleTok,len);
if (styleTok != TRPG_TEXT_STYLE) throw 1;
buf.PushLimit(len);
@@ -554,7 +554,7 @@ bool trpgSupportStyleTable::Read(trpgReadBuffer &buf)
int32 len;
bool status;
int numStyle;
int i;
int i;
Reset();
@@ -564,7 +564,7 @@ bool trpgSupportStyleTable::Read(trpgReadBuffer &buf)
if (numStyle < 0)
throw 1;
//styles.resize(numStyle);
for (i=0;i<numStyle;i++) {
for (i=0;i<numStyle;i++) {
buf.GetToken(styleTok,len);
if (styleTok != TRPG_SUPPORT_STYLE) throw 1;
buf.PushLimit(len);
@@ -814,7 +814,7 @@ bool trpgLabelPropertyTable::Read(trpgReadBuffer &buf)
int32 len;
bool status;
int numProperty;
int i;
int i;
Reset();
@@ -824,7 +824,7 @@ bool trpgLabelPropertyTable::Read(trpgReadBuffer &buf)
if (numProperty < 0)
throw 1;
//properties.resize(numProperty);
for (i=0;i<numProperty;i++) {
for (i=0;i<numProperty;i++) {
buf.GetToken(propertyTok,len);
if (propertyTok != TRPG_LABEL_PROPERTY) throw 1;
buf.PushLimit(len);
@@ -985,7 +985,7 @@ const std::vector<trpg3dPoint> *trpgLabel::GetSupports() const
bool trpgLabel::Write(trpgWriteBuffer &buf)
{
unsigned int i;
unsigned int i;
buf.Begin(TRPG_LABEL);
buf.Add(propertyId);
@@ -998,7 +998,7 @@ bool trpgLabel::Write(trpgWriteBuffer &buf)
buf.Add(url);
buf.Add(location);
buf.Add((int)supports.size());
for (i=0;i<supports.size();i++)
for (i=0;i<supports.size();i++)
buf.Add(supports[i]);
buf.End();
@@ -1007,7 +1007,7 @@ bool trpgLabel::Write(trpgWriteBuffer &buf)
bool trpgLabel::Read(trpgReadBuffer &buf)
{
int numSupport,i;
int numSupport,i;
trpg3dPoint support;
int iVal;
@@ -1026,7 +1026,7 @@ bool trpgLabel::Read(trpgReadBuffer &buf)
buf.Get(location);
buf.Get(numSupport);
if (numSupport < 0) throw 1;
for (i=0;i<numSupport;i++) {
for (i=0;i<numSupport;i++) {
buf.Get(support);
supports.push_back(support);
}

File diff suppressed because it is too large Load Diff

View File

@@ -14,9 +14,9 @@
*/
/* trpage_main.cpp
This file is here to provide a DLL Main.
Note: #ifdef this out on non-windows machines
*/
This file is here to provide a DLL Main.
Note: #ifdef this out on non-windows machines
*/
#if defined(_WIN32)
#define WIN32_LEAN_AND_MEAN
#include <windows.h>

File diff suppressed because it is too large Load Diff

View File

@@ -19,10 +19,10 @@
#include <deque>
/* This file contains class definitions for managers
that help you keep track of data related to
paging. For instance, which tiles to load
in at any given time and what textures you need
to read for a given tile.
that help you keep track of data related to
paging. For instance, which tiles to load
in at any given time and what textures you need
to read for a given tile.
*/
class trpgPageManager;
@@ -37,8 +37,8 @@ struct TileLocationInfo
};
/* Managed Tiles are used by the trpgPageManager to keep
track of which tiles are loaded and what textures (and
models) they need loaded into memory with them.
track of which tiles are loaded and what textures (and
models) they need loaded into memory with them.
*/
TX_EXDECL class TX_CLDECL trpgManagedTile
{
@@ -136,7 +136,7 @@ TX_EXDECL class TX_CLDECL trpgManagedTile
// Children info, will throw exception if child index is out of bound
unsigned int GetNbChildren() const
{
return (unsigned int)childLocationInfo.size();
return (unsigned int)childLocationInfo.size();
}
bool SetChildLocationInfo(int childIdx, int x, int y, const trpgwAppAddress& addr);
bool SetChildLocationInfo(int childIdx, const TileLocationInfo& info);
@@ -207,15 +207,15 @@ TX_EXDECL class TX_CLDECL trpgPageManager
*/
virtual trpgManagedTile *GetNextLoad(void);
/* Acknowledge Tile Load.
This method should be called when a tile has been
loaded by the caller. This method is used in conjunction
with GetNextLoad().
This method should be called when a tile has been
loaded by the caller. This method is used in conjunction
with GetNextLoad().
Version 2.1 and over supports variable lod so that we cannot know
from the tile table if a tile exist or not. So to manage this
the user must parse the loaded tile and extract its list of children
and pass it on to AckLoad() which will add to the appropriate lod list
the children info. If this is not done then only lod 0 will be pageable.
Version 2.1 and over supports variable lod so that we cannot know
from the tile table if a tile exist or not. So to manage this
the user must parse the loaded tile and extract its list of children
and pass it on to AckLoad() which will add to the appropriate lod list
the children info. If this is not done then only lod 0 will be pageable.
*/
virtual void AckLoad(std::vector<TileLocationInfo> const& children);
@@ -272,156 +272,156 @@ TX_EXDECL class TX_CLDECL trpgPageManager
detail as related to paging.
*/
TX_EXDECL class TX_CLDECL LodPageInfo {
friend class trpgPageManager;
friend class trpgPageManager;
public:
LodPageInfo(void);
virtual ~LodPageInfo(void);
LodPageInfo(void);
virtual ~LodPageInfo(void);
/* Initializes the class with its current LOD.
It figures out all the rest.
*/
virtual bool Init(trpgr_Archive *, int myLod, double scale, int freeListDivider = 1);
/* Initializes the class with its current LOD.
It figures out all the rest.
*/
virtual bool Init(trpgr_Archive *, int myLod, double scale, int freeListDivider = 1);
/* Reset the location. This forces a recalculation
of what to load and unload if the cell has changed
or if this is the first SetLocation.
The location passed in must be relative to the southwest
corner of the TerraPage archive.
*/
virtual bool SetLocation(trpg2dPoint &);
/* Reset the location. This forces a recalculation
of what to load and unload if the cell has changed
or if this is the first SetLocation.
The location passed in must be relative to the southwest
corner of the TerraPage archive.
*/
virtual bool SetLocation(trpg2dPoint &);
// Return the next tile to load for this terrain lod
virtual trpgManagedTile *GetNextLoad(void);
// Acknowledge the load. Move the active tile to the
// loaded list.
virtual void AckLoad();
// Return the next tile to load for this terrain lod
virtual trpgManagedTile *GetNextLoad(void);
// Acknowledge the load. Move the active tile to the
// loaded list.
virtual void AckLoad();
// Get the lsit of
//bool GetLoadedTile
// Get the lsit of
//bool GetLoadedTile
// Return the next tile to unload for this terrain lod
virtual trpgManagedTile *GetNextUnload(void);
// Acknowledge the unload. Move the active tile to the
// free list.
virtual void AckUnload(void);
// Called to stop paging. Everything active is dumped on
// the unload list.
virtual bool Stop(void);
// Print current status and content information
virtual void Print(trpgPrintBuffer &);
// Return the next tile to unload for this terrain lod
virtual trpgManagedTile *GetNextUnload(void);
// Acknowledge the unload. Move the active tile to the
// free list.
virtual void AckUnload(void);
// Called to stop paging. Everything active is dumped on
// the unload list.
virtual bool Stop(void);
// Print current status and content information
virtual void Print(trpgPrintBuffer &);
const trpg2iPoint& GetLodSize() const
{
return lodSize;
}
const trpg2iPoint& GetLodSize() const
{
return lodSize;
}
int GetLod() const
{
return lod;
}
int GetLod() const
{
return lod;
}
double GetPageDistance() const
{
return pageDist;
}
double GetPageDistance() const
{
return pageDist;
}
const trpg2dPoint& GetCellSize() const
{
return cellSize;
}
const trpg2dPoint& GetCellSize() const
{
return cellSize;
}
// The unit are cellSize
const trpg2iPoint& GetAreaOfInterest() const
{
return aoiSize;
}
// The unit are cellSize
const trpg2iPoint& GetAreaOfInterest() const
{
return aoiSize;
}
// The middle of this cell correspond to our paging
// location
const trpg2iPoint& GetCellPagingLocation() const
{
return cell;
}
// The middle of this cell correspond to our paging
// location
const trpg2iPoint& GetCellPagingLocation() const
{
return cell;
}
protected:
virtual void Clean(void);
virtual void Update(void);
virtual void Clean(void);
virtual void Update(void);
// Add to the load list the given tile if it is within the proper
// bound
bool AddToLoadList(int x, int y, const trpgwAppAddress& addr);
// Add to the load list the given tile if it is within the proper
// bound
bool AddToLoadList(int x, int y, const trpgwAppAddress& addr);
// Add the children of the given parent list
// to the load list if it it not already loaded
// or if it is not already in the list
void AddChildrenToLoadList(std::vector<trpgManagedTile*>& parentList);
// Add the children of the given parent list
// to the load list if it it not already loaded
// or if it is not already in the list
void AddChildrenToLoadList(std::vector<trpgManagedTile*>& parentList);
// Check if the given tile is within the area we care about
bool isWithin(trpgManagedTile *,trpg2iPoint &sw,trpg2iPoint &ne);
// Check if the given tile is within the area we care about
bool isWithin(trpgManagedTile *,trpg2iPoint &sw,trpg2iPoint &ne);
// Get the list of currently loaded tiles that fall within
// the region calculated from the given paging distance.
void GetLoadedTileWithin(double pagingDistance, std::vector<trpgManagedTile*>& tileList);
// Get the list of currently loaded tiles that fall within
// the region calculated from the given paging distance.
void GetLoadedTileWithin(double pagingDistance, std::vector<trpgManagedTile*>& tileList);
bool valid;
bool valid;
// Terrain LOD we're responsible for
int lod;
// Terrain LOD we're responsible for
int lod;
/* Adjusted (e.g. paranoid) distance outward from
which to page this terrain LOD. This takes into
account the distance in the header as well as
any factor the user may have added.
*/
double pageDist;
/* Adjusted (e.g. paranoid) distance outward from
which to page this terrain LOD. This takes into
account the distance in the header as well as
any factor the user may have added.
*/
double pageDist;
/* Max tiles we could have loaded in at any given time.
This is just a guess because it's up to the user
to load (and, more importantly) unload.
*/
int maxNumTiles;
/* Max tiles we could have loaded in at any given time.
This is just a guess because it's up to the user
to load (and, more importantly) unload.
*/
int maxNumTiles;
// Size of a single cell. Copied from the archive.
trpg2dPoint cellSize;
// Size of a single cell. Copied from the archive.
trpg2dPoint cellSize;
// Number of tiles (cells) in each direction
trpg2iPoint lodSize;
// Number of tiles (cells) in each direction
trpg2iPoint lodSize;
/* Area of interest size in cells
This is a linear distance "ahead" of the center cell.
*/
trpg2iPoint aoiSize;
/* Area of interest size in cells
This is a linear distance "ahead" of the center cell.
*/
trpg2iPoint aoiSize;
/* Our effective paging location sits at the middle
of this cell. We don't recalculate unless the
cell changes. */
trpg2iPoint cell;
/* Our effective paging location sits at the middle
of this cell. We don't recalculate unless the
cell changes. */
trpg2iPoint cell;
// List of tiles to load
std::deque<trpgManagedTile *> load;
// List of tiles to unload
std::deque<trpgManagedTile *> unload;
// List of currently loaded tiles
std::deque<trpgManagedTile *> current;
// List of tiles to load
std::deque<trpgManagedTile *> load;
// List of tiles to unload
std::deque<trpgManagedTile *> unload;
// List of currently loaded tiles
std::deque<trpgManagedTile *> current;
// Used by Update. Here because we want to avoid memory allocs, if possible.
std::vector<bool> tmpCurrent;
// Used by Update. Here because we want to avoid memory allocs, if possible.
std::vector<bool> tmpCurrent;
// Set if a load is in progress
// Load w/o ACK
bool activeLoad;
// Set if an unload is in progress
// Unload w/o ACK
bool activeUnload;
// Set if a load is in progress
// Load w/o ACK
bool activeLoad;
// Set if an unload is in progress
// Unload w/o ACK
bool activeUnload;
// List of tile pointers we can reuse
std::deque<trpgManagedTile *> freeList;
// List of tile pointers we can reuse
std::deque<trpgManagedTile *> freeList;
// TerraPage version
int majorVersion, minorVersion;
// TerraPage version
int majorVersion, minorVersion;
const trpgTileTable *tileTable;
const trpgTileTable *tileTable;
};
// Per terrain lod paging information

File diff suppressed because it is too large Load Diff

View File

@@ -20,285 +20,285 @@
#define OLDMODELSTYLE
/* trpage_model.cpp
This source file contains the methods trpgModel and trpgModelTable.
You should only modify this code if you want to add data to these classes.
*/
This source file contains the methods trpgModel and trpgModelTable.
You should only modify this code if you want to add data to these classes.
*/
#include <trpage_geom.h>
#include <trpage_read.h>
/* Write Model class
Represents a model reference.
*/
Represents a model reference.
*/
trpgModel::trpgModel()
{
name = NULL;
type = External;
useCount = 0;
diskRef = -1;
handle = -1;
writeHandle = false;
name = NULL;
type = External;
useCount = 0;
diskRef = -1;
handle = -1;
writeHandle = false;
}
trpgModel::trpgModel(const trpgModel &in):
trpgReadWriteable(in)
{
if (in.name)
{
name = new char[strlen(in.name)+1];
strcpy(name,in.name);
}
else
name = NULL;
if (in.name)
{
name = new char[strlen(in.name)+1];
strcpy(name,in.name);
}
else
name = NULL;
type=in.type;
useCount=in.useCount;
diskRef=in.diskRef;
handle = in.handle;
writeHandle = in.writeHandle;
type=in.type;
useCount=in.useCount;
diskRef=in.diskRef;
handle = in.handle;
writeHandle = in.writeHandle;
}
// Reset function
void trpgModel::Reset()
{
if (name)
delete [] name;
name = NULL;
useCount = 0;
diskRef = -1;
handle = -1;
writeHandle = false;
if (name)
delete [] name;
name = NULL;
useCount = 0;
diskRef = -1;
handle = -1;
writeHandle = false;
}
trpgModel::~trpgModel()
{
Reset();
Reset();
}
// Set functions
void trpgModel::SetType(int t)
{
type = t;
type = t;
}
void trpgModel::SetName(const char *nm)
{
if (name)
delete [] name;
if (name)
delete [] name;
if (nm)
{
name = new char[(nm ? strlen(nm) : 0)+1];
strcpy(name,nm);
}
if (nm)
{
name = new char[(nm ? strlen(nm) : 0)+1];
strcpy(name,nm);
}
}
void trpgModel::SetReference(trpgDiskRef pos)
{
diskRef = pos;
diskRef = pos;
}
void trpgModel::SetNumTiles(int num)
{
useCount = num;
useCount = num;
}
void trpgModel::AddTile()
{
useCount++;
useCount++;
}
// Validity check
bool trpgModel::isValid() const
{
if (type == External && !name)
{
strcpy(errMess, "Model is external with no name");
return false;
}
if (type == External && !name)
{
strcpy(errMess, "Model is external with no name");
return false;
}
return true;
return true;
}
// Copy from one to another
trpgModel& trpgModel::operator = (const trpgModel &in)
{
if (name) {
delete [] name;
name = NULL;
}
if (name) {
delete [] name;
name = NULL;
}
type = in.type;
if (in.name)
SetName(in.name);
diskRef = in.diskRef;
useCount = in.useCount;
writeHandle = in.writeHandle;
handle = in.handle;
return *this;
type = in.type;
if (in.name)
SetName(in.name);
diskRef = in.diskRef;
useCount = in.useCount;
writeHandle = in.writeHandle;
handle = in.handle;
return *this;
}
// Compare two models
int trpgModel::operator == (const trpgModel &in) const
{
if (type != in.type)
return 0;
if (type != in.type)
return 0;
switch (type) {
case Local:
if (diskRef == in.diskRef)
return 1;
else
return 0;
break;
case External:
if (!name && !in.name)
return 1;
if (!name || !in.name)
return 0;
if (strcmp(name,in.name))
return 0;
break;
}
switch (type) {
case Local:
if (diskRef == in.diskRef)
return 1;
else
return 0;
break;
case External:
if (!name && !in.name)
return 1;
if (!name || !in.name)
return 0;
if (strcmp(name,in.name))
return 0;
break;
}
return 1;
return 1;
}
// Write a model reference out
bool trpgModel::Write(trpgWriteBuffer &buf)
{
if (!isValid())
return false;
if (!isValid())
return false;
// We will use two different tokens to track the
// format used in terrapage 2.2, and older versions
int tok = TRPGMODELREF;
if(writeHandle)
tok = TRPGMODELREF2;
// We will use two different tokens to track the
// format used in terrapage 2.2, and older versions
int tok = TRPGMODELREF;
if(writeHandle)
tok = TRPGMODELREF2;
// Nick messed up the model entries when checking into txv4; now we're
// a bit stuck because U3 dbs don't have models in the U2 viewer.
// This will force the old behavior.
#ifdef OLDMODELSTYLE
buf.Begin(tok);
buf.Add(type);
//writeHandle is only set for terrapage 2.2, and we use the different token.
if(writeHandle) {
buf.Add((int)handle);
}
if (name)
buf.Add(name);
else
buf.Begin(tok);
buf.Add(type);
//writeHandle is only set for terrapage 2.2, and we use the different token.
if(writeHandle) {
buf.Add((int)handle);
}
if (name)
buf.Add(name);
else
buf.Add(diskRef);
buf.Add(useCount);
buf.Add(useCount);
#else
buf.Begin(tok);
if(writeHandle) {
buf.Add((int)handle);
}
buf.Add(type);
buf.Add(name);
buf.Add(diskRef);
buf.Add(useCount);
buf.Begin(tok);
if(writeHandle) {
buf.Add((int)handle);
}
buf.Add(type);
buf.Add(name);
buf.Add(diskRef);
buf.Add(useCount);
#endif
buf.End();
buf.End();
return true;
return true;
}
/* *******************
Model Read Methods
*******************
*/
/* *******************
Model Read Methods
*******************
*/
// Get methods
bool trpgModel::GetType(int &t)
{
if (!isValid()) return false;
t = type;
return true;
if (!isValid()) return false;
t = type;
return true;
}
bool trpgModel::GetName(char *str,int strLen) const
{
if (!isValid()) return false;
int len = (name ? strlen(name) : 0);
strncpy(str,name,MIN(len,strLen)+1);
return true;
if (!isValid()) return false;
int len = (name ? strlen(name) : 0);
strncpy(str,name,MIN(len,strLen)+1);
return true;
}
bool trpgModel::GetNumTiles(int &ret) const
{
if (!isValid()) return false;
if (!isValid()) return false;
ret = useCount;
return true;
ret = useCount;
return true;
}
bool trpgModel::GetReference(trpgDiskRef &ref) const
{
if (!isValid() || type != Local) return false;
ref = diskRef;
return true;
if (!isValid() || type != Local) return false;
ref = diskRef;
return true;
}
bool trpgModel::Read(trpgReadBuffer &buf, bool hasHandle)
{
// MD: added complexity here - written multiple ways by
// mistake, unraveling the various cases.
char tmpName[1024];
// MD: added complexity here - written multiple ways by
// mistake, unraveling the various cases.
char tmpName[1024];
try {
buf.Get(type);
// TerraPage 2.2 will store the unique handle after the type
// we use a different token, so this is backwards compatible.
if(hasHandle) {
try {
buf.Get(type);
// TerraPage 2.2 will store the unique handle after the type
// we use a different token, so this is backwards compatible.
if(hasHandle) {
int32 tempHandle;
if(buf.Get(tempHandle))
if(buf.Get(tempHandle))
{
handle = tempHandle;
}
else
{
handle = -1;
}
}
else
handle = -1;
if (type == Local) {
// two possibilities:
// name, diskRef, useCount
// diskRef, useCount
// diskRef + useCount = 12 bytes...
if (buf.TestLimit(13))
{
buf.Get(tmpName,1023);
SetName(tmpName);
}
buf.Get(diskRef);
buf.Get(useCount);
}
else
{
// two possibilities:
// name, diskRef, useCount
// name, useCount
buf.Get(tmpName,1023);
SetName(tmpName);
// useCount = 4 bytes...
if (buf.TestLimit(5))
buf.Get(diskRef);
buf.Get(useCount);
}
}
catch(...) {
return false;
}
handle = -1;
}
}
else
handle = -1;
if (type == Local) {
// two possibilities:
// name, diskRef, useCount
// diskRef, useCount
// diskRef + useCount = 12 bytes...
if (buf.TestLimit(13))
{
buf.Get(tmpName,1023);
SetName(tmpName);
}
buf.Get(diskRef);
buf.Get(useCount);
}
else
{
// two possibilities:
// name, diskRef, useCount
// name, useCount
buf.Get(tmpName,1023);
SetName(tmpName);
// useCount = 4 bytes...
if (buf.TestLimit(5))
buf.Get(diskRef);
buf.Get(useCount);
}
}
catch(...) {
return false;
}
// going to make this fail if the buffer isn't empty.
if (buf.TestLimit(1)) return false;
// going to make this fail if the buffer isn't empty.
if (buf.TestLimit(1)) return false;
return isValid();
return isValid();
}
/* Write Model Reference table
Groups of models for the entire file.
*/
Groups of models for the entire file.
*/
// Constructor
trpgModelTable::trpgModelTable()
@@ -311,73 +311,73 @@ trpgModelTable::~trpgModelTable()
// Reset function
void trpgModelTable::Reset()
{
modelsMap.clear();
modelsMap.clear();
}
// Set functions
void trpgModelTable::SetNumModels(int /*no*/)
{
// This method isn't needed with a map
//models.resize(no);
// This method isn't needed with a map
//models.resize(no);
}
void trpgModelTable::SetModel(int id,const trpgModel &mod)
{
if (id < 0)
return;
if (id < 0)
return;
modelsMap[id] = mod;
//models[id] = mod;
modelsMap[id] = mod;
//models[id] = mod;
}
int trpgModelTable::AddModel(trpgModel &mod)
{
int hdl = modelsMap.size();
if(mod.GetHandle()==-1) {
modelsMap[hdl] = mod;
return hdl;
}
modelsMap[mod.GetHandle()] = mod;
return mod.GetHandle();
int hdl = modelsMap.size();
if(mod.GetHandle()==-1) {
modelsMap[hdl] = mod;
return hdl;
}
modelsMap[mod.GetHandle()] = mod;
return mod.GetHandle();
}
int trpgModelTable::FindAddModel(trpgModel &mod)
{
ModelMapType::iterator itr = modelsMap.begin();
for ( ; itr != modelsMap.end( ); itr++) {
if(itr->second == mod) {
return itr->first;
}
}
return AddModel(mod);
ModelMapType::iterator itr = modelsMap.begin();
for ( ; itr != modelsMap.end( ); itr++) {
if(itr->second == mod) {
return itr->first;
}
}
return AddModel(mod);
}
bool trpgModelTable::FindByName(const char *name, unsigned int &mId)
{
ModelMapType::const_iterator itr = modelsMap.begin();
for ( ; itr != modelsMap.end( ); itr++) {
char theName[1023];
itr->second.GetName(theName,1023);
if(strcmp(name,theName)==0) {
mId = itr->first;
return true;
}
}
return false;
ModelMapType::const_iterator itr = modelsMap.begin();
for ( ; itr != modelsMap.end( ); itr++) {
char theName[1023];
itr->second.GetName(theName,1023);
if(strcmp(name,theName)==0) {
mId = itr->first;
return true;
}
}
return false;
}
// Validity check
bool trpgModelTable::isValid() const
{
ModelMapType::const_iterator itr = modelsMap.begin();
for ( ; itr != modelsMap.end( ); itr++) {
if(!itr->second.isValid()) {
if(itr->second.getErrMess())
strcpy(errMess, itr->second.getErrMess());
return false;
}
}
return true;
ModelMapType::const_iterator itr = modelsMap.begin();
for ( ; itr != modelsMap.end( ); itr++) {
if(!itr->second.isValid()) {
if(itr->second.getErrMess())
strcpy(errMess, itr->second.getErrMess());
return false;
}
}
return true;
}
@@ -385,85 +385,85 @@ bool trpgModelTable::isValid() const
// Write out the model table
bool trpgModelTable::Write(trpgWriteBuffer &buf)
{
if (!isValid())
return false;
if (!isValid())
return false;
buf.Begin(TRPGMODELTABLE);
buf.Add((int32)modelsMap.size());
ModelMapType::iterator itr = modelsMap.begin();
for ( ; itr != modelsMap.end( ); itr++) {
itr->second.Write(buf);
}
buf.End();
buf.Begin(TRPGMODELTABLE);
buf.Add((int32)modelsMap.size());
ModelMapType::iterator itr = modelsMap.begin();
for ( ; itr != modelsMap.end( ); itr++) {
itr->second.Write(buf);
}
buf.End();
return true;
return true;
}
/* ***************
Model Table Read methods
***************
*/
/* ***************
Model Table Read methods
***************
*/
// Get methods
bool trpgModelTable::GetNumModels(int &nm) const
{
if (!isValid()) return false;
nm = modelsMap.size();
return true;
if (!isValid()) return false;
nm = modelsMap.size();
return true;
}
bool trpgModelTable::GetModel(int id,trpgModel &model) const
{
if (!isValid() || id < 0 ) //|| id >= models.size())
return false;
//model = models[id];
ModelMapType::const_iterator itr = modelsMap.find(id);
if(itr == modelsMap.end()) {
return false;
}
model = itr->second;
return true;
if (!isValid() || id < 0 ) //|| id >= models.size())
return false;
//model = models[id];
ModelMapType::const_iterator itr = modelsMap.find(id);
if(itr == modelsMap.end()) {
return false;
}
model = itr->second;
return true;
}
trpgModel *trpgModelTable::GetModelRef(int id)
{
if (id < 0 ) //|| id >= models.size())
return NULL;
//return &models[id];
ModelMapType::iterator itr = modelsMap.find(id);
if(itr == modelsMap.end()) {
return false;
}
return &(itr->second);
if (id < 0 ) //|| id >= models.size())
return NULL;
//return &models[id];
ModelMapType::iterator itr = modelsMap.find(id);
if(itr == modelsMap.end()) {
return false;
}
return &(itr->second);
}
bool trpgModelTable::Read(trpgReadBuffer &buf)
{
int32 numModel;
trpgToken tok;
int32 len;
bool status;
int32 numModel;
trpgToken tok;
int32 len;
bool status;
try {
buf.Get(numModel);
for (int i=0;i<numModel;i++) {
trpgModel model;
buf.GetToken(tok,len);
bool readHandle;
if (tok == TRPGMODELREF)
readHandle = false;
else if (tok == TRPGMODELREF2)
readHandle = true;
else
throw 1;
buf.PushLimit(len);
status = model.Read(buf,readHandle);
buf.PopLimit();
if (!status) throw 1;
AddModel(model);
}
}
catch (...) {
return false;
}
try {
buf.Get(numModel);
for (int i=0;i<numModel;i++) {
trpgModel model;
buf.GetToken(tok,len);
bool readHandle;
if (tok == TRPGMODELREF)
readHandle = false;
else if (tok == TRPGMODELREF2)
readHandle = true;
else
throw 1;
buf.PushLimit(len);
status = model.Read(buf,readHandle);
buf.PopLimit();
if (!status) throw 1;
AddModel(model);
}
}
catch (...) {
return false;
}
return isValid();
return isValid();
}

View File

@@ -49,8 +49,8 @@ void trpgGroup::Reset()
numChild = 0;
id = -1;
if ( name ) {
delete [] name;
name = 0;
delete [] name;
name = 0;
}
}
@@ -73,16 +73,16 @@ void trpgGroup::SetName(const char* newname )
{
if ( name )
{
delete [] name;
name = 0;
delete [] name;
name = 0;
}
if (newname)
{
if ( strlen(newname) )
{
name = new char[strlen(newname)+1];
strcpy(name,newname);
}
if ( strlen(newname) )
{
name = new char[strlen(newname)+1];
strcpy(name,newname);
}
}
}
@@ -118,14 +118,14 @@ bool trpgGroup::isValid() const
bool trpgGroup::Write(trpgWriteBuffer &buf)
{
if (!isValid())
return false;
return false;
buf.Begin(TRPG_GROUP);
buf.Add(numChild);
buf.Add(id);
if ( name && strlen(name) ) {
buf.Add(name);
buf.Add(name);
}
buf.End();
@@ -137,19 +137,19 @@ bool trpgGroup::Write(trpgWriteBuffer &buf)
bool trpgGroup::Read(trpgReadBuffer &buf)
{
try {
buf.Get(numChild);
if (numChild < 0) throw 1;
buf.Get(id);
if (id < 0) throw 1;
if ( !buf.isEmpty() ) {
char nm[1024] = {0};
buf.Get(nm,1024);
SetName(nm);
}
buf.Get(numChild);
if (numChild < 0) throw 1;
buf.Get(id);
if (id < 0) throw 1;
if ( !buf.isEmpty() ) {
char nm[1024] = {0};
buf.Get(nm,1024);
SetName(nm);
}
}
catch (...) {
return false;
return false;
}
return isValid();
@@ -181,8 +181,8 @@ void trpgBillboard::Reset()
numChild = 0;
if ( name )
{
delete [] name;
name = 0;
delete [] name;
name = 0;
}
}
@@ -235,7 +235,7 @@ bool trpgBillboard::GetType(int &t) const
bool trpgBillboard::Write(trpgWriteBuffer &buf)
{
if (!isValid())
return false;
return false;
buf.Begin(TRPG_BILLBOARD);
buf.Add(numChild);
@@ -246,7 +246,7 @@ bool trpgBillboard::Write(trpgWriteBuffer &buf)
buf.Add(axis);
if ( name && strlen(name) ) {
buf.Add(name);
buf.Add(name);
}
buf.End();
@@ -259,20 +259,20 @@ bool trpgBillboard::Read(trpgReadBuffer &buf)
uint8 uChar;
try {
buf.Get(numChild);
buf.Get(id);
buf.Get(uChar); type = uChar;
buf.Get(uChar); mode = uChar;
buf.Get(center);
buf.Get(axis);
if ( !buf.isEmpty() ) {
char nm[1024] = {0};
buf.Get(nm,1024);
SetName(nm);
}
buf.Get(numChild);
buf.Get(id);
buf.Get(uChar); type = uChar;
buf.Get(uChar); mode = uChar;
buf.Get(center);
buf.Get(axis);
if ( !buf.isEmpty() ) {
char nm[1024] = {0};
buf.Get(nm,1024);
SetName(nm);
}
}
catch (...) {
return false;
return false;
}
return isValid();
@@ -303,8 +303,8 @@ void trpgLod::Reset()
rangeIndex = -1;
valid = true;
if ( name ) {
delete [] name;
name = 0;
delete [] name;
name = 0;
}
}
@@ -317,7 +317,7 @@ void trpgLod::SetCenter(const trpg3dPoint &pt)
void trpgLod::SetNumChild(int no)
{
if (no < 0)
return;
return;
numRange = no;
}
@@ -335,14 +335,14 @@ void trpgLod::SetID(int inID)
void trpgLod::SetName(const char* newname )
{
if ( name ) {
delete [] name;
name = 0;
delete [] name;
name = 0;
}
if (newname) {
if ( strlen(newname) ) {
name = new char[strlen(newname)+1];
strcpy(name,newname);
}
if ( strlen(newname) ) {
name = new char[strlen(newname)+1];
strcpy(name,newname);
}
}
}
@@ -397,7 +397,7 @@ bool trpgLod::GetRangeIndex(int &ri) const
bool trpgLod::Write(trpgWriteBuffer &buf)
{
if (!isValid())
return false;
return false;
buf.Begin(TRPG_LOD);
buf.Add(id);
@@ -408,9 +408,9 @@ bool trpgLod::Write(trpgWriteBuffer &buf)
buf.Add(width);
if ( name && strlen(name) ) {
buf.Add(name);
buf.Add(name);
} else
buf.Add("");
buf.Add("");
buf.End();
@@ -422,25 +422,25 @@ bool trpgLod::Write(trpgWriteBuffer &buf)
bool trpgLod::Read(trpgReadBuffer &buf)
{
try {
buf.Get(id);
buf.Get(numRange);
if (numRange < 0) throw 1;
buf.Get(center);
buf.Get(switchIn);
buf.Get(switchOut);
buf.Get(width);
if ( !buf.isEmpty() ) {
char nm[1024] = {0};
buf.Get(nm,1024);
if (*nm)
SetName(nm);
// Look for a range index
if (!buf.isEmpty())
buf.Get(rangeIndex);
}
buf.Get(id);
buf.Get(numRange);
if (numRange < 0) throw 1;
buf.Get(center);
buf.Get(switchIn);
buf.Get(switchOut);
buf.Get(width);
if ( !buf.isEmpty() ) {
char nm[1024] = {0};
buf.Get(nm,1024);
if (*nm)
SetName(nm);
// Look for a range index
if (!buf.isEmpty())
buf.Get(rangeIndex);
}
}
catch (...) {
return false;
return false;
}
return isValid();
@@ -465,17 +465,17 @@ trpgLayer::~trpgLayer()
bool trpgLayer::Write(trpgWriteBuffer &buf)
{
if (!isValid())
return false;
return false;
buf.Begin(TRPG_LAYER);
buf.Add(numChild);
buf.Add(id);
if ( name && strlen(name) ) {
buf.Add(name);
buf.Add(name);
}
buf.End();
buf.End();
return true;
}
@@ -484,18 +484,18 @@ bool trpgLayer::Write(trpgWriteBuffer &buf)
bool trpgLayer::Read(trpgReadBuffer &buf)
{
try {
buf.Get(numChild);
if (numChild < 0) throw 1;
buf.Get(id);
if (id < 0) throw 1;
if ( !buf.isEmpty() ) {
char nm[1024] = {0};
buf.Get(nm,1024);
SetName(nm);
}
buf.Get(numChild);
if (numChild < 0) throw 1;
buf.Get(id);
if (id < 0) throw 1;
if ( !buf.isEmpty() ) {
char nm[1024] = {0};
buf.Get(nm,1024);
SetName(nm);
}
}
catch (...) {
return false;
return false;
}
return isValid();
@@ -506,8 +506,8 @@ void trpgLayer::Reset()
{
numChild = 0;
if ( name ) {
delete [] name;
name = 0;
delete [] name;
name = 0;
}
}
@@ -537,8 +537,8 @@ void trpgTransform::Reset()
m[3][0] = 0; m[3][1] = 0; m[3][2] = 0; m[3][3] = 1;
if ( name ) {
delete [] name;
name = 0;
delete [] name;
name = 0;
}
}
@@ -556,9 +556,9 @@ bool trpgTransform::GetMatrix(float64 *rm) const
{
if (!isValid()) return false;
for (int i=0;i<4;i++)
for (int j=0;j<4;j++)
// Note: is this right?
rm[i*4+j] = m[i][j];
for (int j=0;j<4;j++)
// Note: is this right?
rm[i*4+j] = m[i][j];
return true;
}
@@ -566,17 +566,17 @@ bool trpgTransform::GetMatrix(float64 *rm) const
bool trpgTransform::Write(trpgWriteBuffer &buf)
{
if (!isValid())
return false;
return false;
buf.Begin(TRPG_TRANSFORM);
buf.Add(numChild);
buf.Add(id);
for (int i=0;i<4;i++)
for (int j=0;j<4;j++)
buf.Add(m[i][j]);
for (int j=0;j<4;j++)
buf.Add(m[i][j]);
if ( name && strlen(name) ) {
buf.Add(name);
buf.Add(name);
}
buf.End();
@@ -587,20 +587,20 @@ bool trpgTransform::Write(trpgWriteBuffer &buf)
bool trpgTransform::Read(trpgReadBuffer &buf)
{
try {
buf.Get(numChild);
buf.Get(id);
if (numChild < 0) throw 1;
for (int i=0;i<4;i++)
for (int j=0;j<4;j++)
buf.Get(m[i][j]);
if ( !buf.isEmpty() ) {
char nm[1024] = {0};
buf.Get(nm,1024);
SetName(nm);
}
buf.Get(numChild);
buf.Get(id);
if (numChild < 0) throw 1;
for (int i=0;i<4;i++)
for (int j=0;j<4;j++)
buf.Get(m[i][j]);
if ( !buf.isEmpty() ) {
char nm[1024] = {0};
buf.Get(nm,1024);
SetName(nm);
}
}
catch (...) {
return false;
return false;
}
return isValid();
@@ -654,9 +654,9 @@ bool trpgModelRef::GetMatrix(float64 *rm) const
{
if (!isValid()) return false;
for (int i=0;i<4;i++)
for (int j=0;j<4;j++)
// Note: is this right?
rm[i*4+j] = m[i][j];
for (int j=0;j<4;j++)
// Note: is this right?
rm[i*4+j] = m[i][j];
return true;
}
@@ -664,13 +664,13 @@ bool trpgModelRef::GetMatrix(float64 *rm) const
bool trpgModelRef::Write(trpgWriteBuffer &buf)
{
if (!isValid())
return false;
return false;
buf.Begin(TRPG_MODELREF);
buf.Add(modelRef);
for (int i=0;i<4;i++)
for (int j=0;j<4;j++)
buf.Add(m[i][j]);
for (int j=0;j<4;j++)
buf.Add(m[i][j]);
buf.End();
return true;
@@ -680,15 +680,15 @@ bool trpgModelRef::Write(trpgWriteBuffer &buf)
bool trpgModelRef::Read(trpgReadBuffer &buf)
{
try {
buf.Get(modelRef);
if (modelRef < 0)
throw 1;
for (int i=0;i<4;i++)
for (int j=0;j<4;j++)
buf.Get(m[i][j]);
buf.Get(modelRef);
if (modelRef < 0)
throw 1;
for (int i=0;i<4;i++)
for (int j=0;j<4;j++)
buf.Get(m[i][j]);
}
catch (...) {
return false;
return false;
}
valid = true;
@@ -718,8 +718,8 @@ void trpgAttach::Reset()
parentID = -1;
childPos = -1;
if ( name ) {
delete [] name;
name = 0;
delete [] name;
name = 0;
}
}
@@ -767,7 +767,7 @@ bool trpgAttach::Write(trpgWriteBuffer &buf)
buf.Add(childPos);
if ( name && strlen(name) ) {
buf.Add(name);
buf.Add(name);
}
buf.End();
@@ -779,21 +779,21 @@ bool trpgAttach::Write(trpgWriteBuffer &buf)
bool trpgAttach::Read(trpgReadBuffer &buf)
{
try {
buf.Get(numChild);
buf.Get(id);
if (id < 0) throw 1;
buf.Get(parentID);
if (parentID < 0) throw 1;
buf.Get(childPos);
if (childPos < 0) throw 1;
if ( !buf.isEmpty() ) {
char nm[1024] = {0};
buf.Get(nm,1024);
SetName(nm);
}
buf.Get(numChild);
buf.Get(id);
if (id < 0) throw 1;
buf.Get(parentID);
if (parentID < 0) throw 1;
buf.Get(childPos);
if (childPos < 0) throw 1;
if ( !buf.isEmpty() ) {
char nm[1024] = {0};
buf.Get(nm,1024);
SetName(nm);
}
}
catch (...) {
return false;
return false;
}
return true;
@@ -892,7 +892,7 @@ bool trpgChildRef::GetTileZValue( float& gZmin, float& gZmax) const
bool trpgChildRef::isValid() const
{
if (lod < 0)
return false;
return false;
return true;
}
@@ -923,19 +923,19 @@ bool trpgChildRef::Read(trpgReadBuffer &buf)
try
{
buf.Get(lod);
if (lod < 0) throw 1;
buf.Get(x);
buf.Get(y);
buf.Get(addr.file);
buf.Get(addr.offset);
buf.Get(zmin);
buf.Get(zmax);
buf.Get(lod);
if (lod < 0) throw 1;
buf.Get(x);
buf.Get(y);
buf.Get(addr.file);
buf.Get(addr.offset);
buf.Get(zmin);
buf.Get(zmax);
}
catch (...)
{
return false;
return false;
}
return true;

View File

@@ -33,7 +33,7 @@
#include <trpage_read.h>
/* ***************************
Paging token callback structure
Paging token callback structure
***************************
*/
trpgr_Token::trpgr_Token()
@@ -59,7 +59,7 @@ void trpgr_Token::init(int in_tok,trpgr_Callback *in_cb,bool in_dest)
void trpgr_Token::Destruct()
{
if (cb && destroy)
delete cb;
delete cb;
cb = NULL;
destroy = true;
}
@@ -98,10 +98,10 @@ class WriteWrapper : public trpgr_Callback {
public:
WriteWrapper(trpgReadWriteable *in_wr) { wr = in_wr; };
void *Parse(trpgToken,trpgReadBuffer &buf) {
if (wr->Read(buf))
return wr;
else
return NULL;
if (wr->Read(buf))
return wr;
else
return NULL;
}
protected:
trpgReadWriteable *wr;
@@ -119,17 +119,17 @@ const trpgr_Callback *trpgr_Parser::GetCallback(trpgToken tok) const
{
tok_map::const_iterator iter = tokenMap.find(tok);
if(iter != tokenMap.end())
return iter->second.cb;
return iter->second.cb;
else
return 0;
return 0;
}
trpgr_Callback *trpgr_Parser::GetCallback(trpgToken tok)
{
tok_map::iterator iter = tokenMap.find(tok);
if(iter != tokenMap.end())
return iter->second.cb;
return iter->second.cb;
else
return 0;
return 0;
}
@@ -154,7 +154,7 @@ void trpgr_Parser::SetDefaultCallback(trpgr_Callback *cb,bool in_dest)
bool trpgr_Parser::TokenIsValid(trpgToken tok)
{
if (tok < 0)
return false;
return false;
return true;
}
@@ -170,67 +170,67 @@ bool trpgr_Parser::Parse(trpgReadBuffer &buf)
try
{
while (!buf.isEmpty())
{
/* We're expecting the following
Token (int32)
Length (int32)
Data (variable)
*/
trpgToken tok;
int32 len;
if (!buf.Get(tok)) throw 1;
// Push and Pop are special - no data
if (tok != TRPG_PUSH && tok != TRPG_POP)
{
if (!buf.Get(len)) throw 1;
if (!TokenIsValid(tok)) throw 1;
if (len < 0) throw 1;
// Limit what we're reading to the length of this
buf.PushLimit(len);
}
while (!buf.isEmpty())
{
/* We're expecting the following
Token (int32)
Length (int32)
Data (variable)
*/
trpgToken tok;
int32 len;
if (!buf.Get(tok)) throw 1;
// Push and Pop are special - no data
if (tok != TRPG_PUSH && tok != TRPG_POP)
{
if (!buf.Get(len)) throw 1;
if (!TokenIsValid(tok)) throw 1;
if (len < 0) throw 1;
// Limit what we're reading to the length of this
buf.PushLimit(len);
}
// Call our token handler for this one
try
{
const trpgr_Token *tcb = NULL;
tok_map::const_iterator p = tokenMap.find(tok);
if (p != tokenMap.end())
tcb = &(*p).second;
if (!tcb)
// No such token, call the default
tcb = &defCb;
// Call our token handler for this one
try
{
const trpgr_Token *tcb = NULL;
tok_map::const_iterator p = tokenMap.find(tok);
if (p != tokenMap.end())
tcb = &(*p).second;
if (!tcb)
// No such token, call the default
tcb = &defCb;
// Run the callback
if (tcb->cb)
{
void *ret = tcb->cb->Parse(tok,buf);
// Note: Do something with the return value
lastObject = ret;
}
}
catch (...)
{
// Don't want to screw up the limit stack
}
// No limit to worry about with push and pop
if (tok != TRPG_PUSH && tok != TRPG_POP)
{
buf.SkipToLimit();
buf.PopLimit();
}
}
// Run the callback
if (tcb->cb)
{
void *ret = tcb->cb->Parse(tok,buf);
// Note: Do something with the return value
lastObject = ret;
}
}
catch (...)
{
// Don't want to screw up the limit stack
}
// No limit to worry about with push and pop
if (tok != TRPG_PUSH && tok != TRPG_POP)
{
buf.SkipToLimit();
buf.PopLimit();
}
}
}
catch (...)
{
// Failed to parse.
ret = false;
// Failed to parse.
ret = false;
}
return ret;
}
/* ****************
/* ****************
Scene Parser
****************
*/
@@ -239,14 +239,14 @@ class trpgSceneHelperPush : public trpgr_Callback
{
public:
trpgSceneHelperPush(trpgSceneParser *in_parse)
{ parse = in_parse; };
{ parse = in_parse; };
void *Parse(trpgToken /*tok*/,trpgReadBuffer& /*buf*/)
{
// Call the start children callback
parse->StartChildren(parse->lastObject);
parse->parents.push_back(parse->lastObject);
return (void *)1;
// Call the start children callback
parse->StartChildren(parse->lastObject);
parse->parents.push_back(parse->lastObject);
return (void *)1;
}
protected:
trpgSceneParser *parse;
@@ -257,18 +257,18 @@ class trpgSceneHelperPop : public trpgr_Callback
{
public:
trpgSceneHelperPop(trpgSceneParser *in_parse)
{ parse = in_parse; };
{ parse = in_parse; };
void *Parse(trpgToken /*tok*/,trpgReadBuffer& /*buf*/)
{
// Make sure we don't have an extra pop
if (parse->parents.size() == 0)
// Note: let someone know about the extra pop
return NULL;
// Call the end children callback
int len = parse->parents.size();
parse->EndChildren(parse->parents[len-1]);
parse->parents.resize(len-1);
return (void *)1;
// Make sure we don't have an extra pop
if (parse->parents.size() == 0)
// Note: let someone know about the extra pop
return NULL;
// Call the end children callback
int len = parse->parents.size();
parse->EndChildren(parse->parents[len-1]);
parse->parents.resize(len-1);
return (void *)1;
}
protected:
trpgSceneParser *parse;
@@ -283,8 +283,8 @@ public:
trpgSceneHelperDefault(trpgSceneParser *in_parse) { parse = in_parse; }
void *Parse(trpgToken /*tok*/,trpgReadBuffer& /*buf*/)
{
// Absorb it quietly
return (void *)1;
// Absorb it quietly
return (void *)1;
}
protected:
trpgSceneParser *parse;

View File

@@ -18,8 +18,8 @@
#include <string.h>
/* trpage_pparse.cpp
This file contains classes that can parse a TerraPage
archive for the purpose of printing it out.
This file contains classes that can parse a TerraPage
archive for the purpose of printing it out.
*/
#include <trpage_print.h>
@@ -33,8 +33,8 @@ namespace
void printBuf(int lod, int x, int y, trpgr_Archive *archive, trpgPrintGraphParser& parser, trpgMemReadBuffer &buf, trpgPrintBuffer &pBuf)
{
char ls[1024];
sprintf(ls,"Tile (lod) (x,y) = (%d) (%d,%d)", lod, x, y);
pBuf.prnLine(ls);
sprintf(ls,"Tile (lod) (x,y) = (%d) (%d,%d)", lod, x, y);
pBuf.prnLine(ls);
pBuf.IncreaseIndent();
parser.Reset();
parser.Parse(buf);
@@ -86,49 +86,49 @@ namespace
/* Set up the callbacks for the scene graph parser.
In our case this is just one read helper with
a switch statement.
In our case this is just one read helper with
a switch statement.
*/
trpgPrintGraphParser::trpgPrintGraphParser(trpgr_Archive *inArch,trpgrImageHelper *inImg,trpgPrintBuffer *inBuf):printBuf(inBuf), archive(inArch), imageHelp(inImg), childRefCB(0)
{
// Register the readers
AddCallback(TRPG_GEOMETRY,new ReadHelper(this,printBuf));
AddCallback(TRPG_GROUP,new ReadHelper(this,printBuf));
AddCallback(TRPG_ATTACH,new ReadHelper(this,printBuf));
// Register the readers
AddCallback(TRPG_GEOMETRY,new ReadHelper(this,printBuf));
AddCallback(TRPG_GROUP,new ReadHelper(this,printBuf));
AddCallback(TRPG_ATTACH,new ReadHelper(this,printBuf));
AddCallback(TRPG_CHILDREF,new ReadHelper(this,printBuf));
AddCallback(TRPG_BILLBOARD,new ReadHelper(this,printBuf));
AddCallback(TRPG_LOD,new ReadHelper(this,printBuf));
AddCallback(TRPG_TRANSFORM,new ReadHelper(this,printBuf));
AddCallback(TRPG_MODELREF,new ReadHelper(this,printBuf));
AddCallback(TRPG_LAYER,new ReadHelper(this,printBuf));
AddCallback(TRPG_LIGHT,new ReadHelper(this,printBuf));
AddCallback(TRPG_LABEL,new ReadHelper(this,printBuf));
AddCallback(TRPGTILEHEADER,new ReadHelper(this,printBuf));
AddCallback(TRPG_BILLBOARD,new ReadHelper(this,printBuf));
AddCallback(TRPG_LOD,new ReadHelper(this,printBuf));
AddCallback(TRPG_TRANSFORM,new ReadHelper(this,printBuf));
AddCallback(TRPG_MODELREF,new ReadHelper(this,printBuf));
AddCallback(TRPG_LAYER,new ReadHelper(this,printBuf));
AddCallback(TRPG_LIGHT,new ReadHelper(this,printBuf));
AddCallback(TRPG_LABEL,new ReadHelper(this,printBuf));
AddCallback(TRPGTILEHEADER,new ReadHelper(this,printBuf));
childRefCB = dynamic_cast<ReadHelper *>(GetCallback(TRPG_CHILDREF));
}
/* Start Children is called when the parser hits a Push
in the read buffer. We just want to indent further when
that happens.
in the read buffer. We just want to indent further when
that happens.
*/
bool trpgPrintGraphParser::StartChildren(void *)
{
printBuf->IncreaseIndent();
printBuf->IncreaseIndent();
return true;
return true;
}
/* End Children is called when the parser hits a Pop
in the read buffer. We just want to reduce the indent
when that happens.
in the read buffer. We just want to reduce the indent
when that happens.
*/
bool trpgPrintGraphParser::EndChildren(void *)
{
printBuf->DecreaseIndent();
printBuf->DecreaseIndent();
return true;
return true;
}
unsigned int trpgPrintGraphParser::GetNbChildrenRef() const
@@ -174,137 +174,137 @@ const trpgChildRef* trpgPrintGraphParser::ReadHelper::GetChildRef(unsigned int i
}
/* Read Helper parse method sets up the correct class depending
on the token and asks it to read and print itself. It will save
on the token and asks it to read and print itself. It will save
any child ref node encountered that a user can access to continue
traversal.
*/
void *trpgPrintGraphParser::ReadHelper::Parse(trpgToken tok,trpgReadBuffer &buf)
{
// This will celar any child ref list from a previous parse.
trpgReadWriteable *obj = NULL;
trpgTileHeader *tileHead = NULL;
trpgReadWriteable *obj = NULL;
trpgTileHeader *tileHead = NULL;
switch (tok) {
case TRPG_GEOMETRY:
obj = new trpgGeometry();
break;
case TRPG_GROUP:
obj = new trpgGroup();
break;
case TRPG_ATTACH:
obj = new trpgAttach();
break;
switch (tok) {
case TRPG_GEOMETRY:
obj = new trpgGeometry();
break;
case TRPG_GROUP:
obj = new trpgGroup();
break;
case TRPG_ATTACH:
obj = new trpgAttach();
break;
case TRPG_CHILDREF:
childRefList.push_back(trpgChildRef());
obj = &childRefList.back();
break;
case TRPG_BILLBOARD:
obj = new trpgBillboard();
break;
case TRPG_LOD:
obj = new trpgLod();
break;
case TRPG_TRANSFORM:
obj = new trpgTransform();
break;
case TRPG_MODELREF:
obj = new trpgModelRef();
break;
case TRPG_LAYER:
obj = new trpgLayer();
break;
case TRPG_LIGHT:
obj = new trpgLight();
break;
case TRPG_LABEL:
obj = new trpgLabel();
break;
break;
case TRPG_BILLBOARD:
obj = new trpgBillboard();
break;
case TRPG_LOD:
obj = new trpgLod();
break;
case TRPG_TRANSFORM:
obj = new trpgTransform();
break;
case TRPG_MODELREF:
obj = new trpgModelRef();
break;
case TRPG_LAYER:
obj = new trpgLayer();
break;
case TRPG_LIGHT:
obj = new trpgLight();
break;
case TRPG_LABEL:
obj = new trpgLabel();
break;
case TRPGTILEHEADER:
obj = tileHead = new trpgTileHeader();
break;
};
case TRPGTILEHEADER:
obj = tileHead = new trpgTileHeader();
break;
};
if (obj) {
if (obj->Read(buf))
obj->Print(*pBuf);
// For the tile header, do a little more work
if (tok == TRPGTILEHEADER) {
int numMat;
tileHead->GetNumLocalMaterial(numMat);
for (int i=0;i<numMat;i++) {
trpgLocalMaterial locMat;
tileHead->GetLocalMaterial(i,locMat);
const trpgMaterial *baseMat;
const trpgTexture *baseTex;
int totSize;
trpgrImageHelper *imageHelp = parse->GetImageHelp();
int numImages=1;
locMat.GetNumLocals(numImages);
for (int imgN=0;imgN<numImages;imgN++) {
// read all the images for each local material
imageHelp->GetNthImageInfoForLocalMat(&locMat,imgN,&baseMat,&baseTex,totSize);
if (obj) {
if (obj->Read(buf))
obj->Print(*pBuf);
// For the tile header, do a little more work
if (tok == TRPGTILEHEADER) {
int numMat;
tileHead->GetNumLocalMaterial(numMat);
for (int i=0;i<numMat;i++) {
trpgLocalMaterial locMat;
tileHead->GetLocalMaterial(i,locMat);
const trpgMaterial *baseMat;
const trpgTexture *baseTex;
int totSize;
trpgrImageHelper *imageHelp = parse->GetImageHelp();
int numImages=1;
locMat.GetNumLocals(numImages);
for (int imgN=0;imgN<numImages;imgN++) {
// read all the images for each local material
imageHelp->GetNthImageInfoForLocalMat(&locMat,imgN,&baseMat,&baseTex,totSize);
// Fetch the whole image
{
char *pixels = new char[totSize];
bool failed = false;
try {
failed = !imageHelp->GetNthImageForLocalMat(&locMat,imgN,pixels,totSize);
}
catch (...) {
failed = true;
}
if (failed) {
fprintf(stderr,"Failed to read local image %d from local material %d.\n",imgN,i);
} else
fprintf(stderr,"Read local image %d from local material %d successfully.\n",imgN,i);
delete [] pixels;
}
// Fetch the whole image
{
char *pixels = new char[totSize];
bool failed = false;
try {
failed = !imageHelp->GetNthImageForLocalMat(&locMat,imgN,pixels,totSize);
}
catch (...) {
failed = true;
}
if (failed) {
fprintf(stderr,"Failed to read local image %d from local material %d.\n",imgN,i);
} else
fprintf(stderr,"Read local image %d from local material %d successfully.\n",imgN,i);
delete [] pixels;
}
// Fetch the individual mipmap levels
{
bool hasMipmap = false;
baseTex->GetIsMipmap(hasMipmap);
int numMipmap = hasMipmap ? baseTex->CalcNumMipmaps() : 0;
for (int j=1;j<numMipmap;j++) {
//int mipOffset = (const_cast<trpgTexture *>(baseTex))->MipLevelOffset(j);
int mipSize = (const_cast<trpgTexture *>(baseTex))->MipLevelSize(j);
if (mipSize) {
char *pixels = new char[mipSize];
bool failed = false;
try {
failed = !imageHelp->GetNthImageMipLevelForLocalMat(j,&locMat,imgN,pixels,mipSize);
}
catch (...) {
failed = true;
}
if (failed)
fprintf(stderr,"Failed to read mipmap level %d for local image %d from local material %d.\n",j,imgN,i);
else
fprintf(stderr,"Read mipmap level %d for local image %d from local material %d.\n",j,imgN,i);
delete [] pixels;
}
}
}
}
}
}
// Fetch the individual mipmap levels
{
bool hasMipmap = false;
baseTex->GetIsMipmap(hasMipmap);
int numMipmap = hasMipmap ? baseTex->CalcNumMipmaps() : 0;
for (int j=1;j<numMipmap;j++) {
//int mipOffset = (const_cast<trpgTexture *>(baseTex))->MipLevelOffset(j);
int mipSize = (const_cast<trpgTexture *>(baseTex))->MipLevelSize(j);
if (mipSize) {
char *pixels = new char[mipSize];
bool failed = false;
try {
failed = !imageHelp->GetNthImageMipLevelForLocalMat(j,&locMat,imgN,pixels,mipSize);
}
catch (...) {
failed = true;
}
if (failed)
fprintf(stderr,"Failed to read mipmap level %d for local image %d from local material %d.\n",j,imgN,i);
else
fprintf(stderr,"Read mipmap level %d for local image %d from local material %d.\n",j,imgN,i);
delete [] pixels;
}
}
}
}
}
}
// We delete all object except the child ref node
if(tok != TRPG_CHILDREF)
delete obj;
}
delete obj;
}
// Need to return non-zero. Otherwise it's interpreted as an error
return (void *)1;
// Need to return non-zero. Otherwise it's interpreted as an error
return (void *)1;
}
// The following routine is not compiled if there's no _splitpath
#ifdef _splitpath
/* This is a convenience function to print out the contents
of an entire TerraPage archive.
of an entire TerraPage archive.
There are two versions of this function. The first takes
a file name and the second an opened archive where the header
@@ -312,74 +312,74 @@ void *trpgPrintGraphParser::ReadHelper::Parse(trpgToken tok,trpgReadBuffer &buf)
*/
bool trpgPrintArchive(char *filename,trpgPrintBuffer &pBuf,int flags)
{
trpgr_Archive archive;
trpgr_Archive archive;
// Break path apart so we can find the directory
char drive[100],dir[1024],fname[1024],ext[1024];
_splitpath(filename,drive,dir,fname,ext);
// Break path apart so we can find the directory
char drive[100],dir[1024],fname[1024],ext[1024];
_splitpath(filename,drive,dir,fname,ext);
char rname[1024],baseDir[1024];
sprintf(baseDir,"%s%s",drive,dir);
sprintf(rname,"%s%s",fname,ext);
char rname[1024],baseDir[1024];
sprintf(baseDir,"%s%s",drive,dir);
sprintf(rname,"%s%s",fname,ext);
if (!*baseDir) strcpy(baseDir,".");
archive.SetDirectory(baseDir);
if (!archive.OpenFile(rname)) {
fprintf(stdout,"Failed to open archive.\n");
return false;
}
if (!archive.ReadHeader()) {
fprintf(stdout,"Failed to read header.\n");
return false;
}
if (!*baseDir) strcpy(baseDir,".");
archive.SetDirectory(baseDir);
if (!archive.OpenFile(rname)) {
fprintf(stdout,"Failed to open archive.\n");
return false;
}
if (!archive.ReadHeader()) {
fprintf(stdout,"Failed to read header.\n");
return false;
}
bool status = trpgPrintArchive(&archive,pBuff,flags);
return status;
bool status = trpgPrintArchive(&archive,pBuff,flags);
return status;
}
#endif
bool trpgPrintArchive(trpgr_Archive *archive,trpgPrintBuffer &pBuf,int flags)
{
char ls[1024];
char ls[1024];
if (!archive->isValid()) return false;
pBuf.prnLine("====Header Structures====");
if (!archive->isValid()) return false;
pBuf.prnLine("====Header Structures====");
// Print out the header portion
archive->GetHeader()->Print(pBuf);
archive->GetMaterialTable()->Print(pBuf);
archive->GetTexTable()->Print(pBuf);
archive->GetModelTable()->Print(pBuf);
archive->GetTileTable()->Print(pBuf);
archive->GetLightTable()->Print(pBuf);
archive->GetRangeTable()->Print(pBuf);
archive->GetTextStyleTable()->Print(pBuf);
archive->GetSupportStyleTable()->Print(pBuf);
archive->GetLabelPropertyTable()->Print(pBuf);
pBuf.prnLine();
// Print out the header portion
archive->GetHeader()->Print(pBuf);
archive->GetMaterialTable()->Print(pBuf);
archive->GetTexTable()->Print(pBuf);
archive->GetModelTable()->Print(pBuf);
archive->GetTileTable()->Print(pBuf);
archive->GetLightTable()->Print(pBuf);
archive->GetRangeTable()->Print(pBuf);
archive->GetTextStyleTable()->Print(pBuf);
archive->GetSupportStyleTable()->Print(pBuf);
archive->GetLabelPropertyTable()->Print(pBuf);
pBuf.prnLine();
// Read the local images and do the math for the templates
// Read the local images and do the math for the templates
// Now do the tiles
if (!archive->isValid()) return false;
// Now do the tiles
if (!archive->isValid()) return false;
int majorVersion, minorVersion;
archive->GetHeader()->GetVersion(majorVersion, minorVersion);
// Parser that prints out a tile scene graph
trpgrImageHelper* imageHelp=archive->GetNewRImageHelper(archive->GetEndian(),archive->getDir(),
*archive->GetMaterialTable(),*archive->GetTexTable());
// Parser that prints out a tile scene graph
trpgrImageHelper* imageHelp=archive->GetNewRImageHelper(archive->GetEndian(),archive->getDir(),
*archive->GetMaterialTable(),*archive->GetTexTable());
trpgPrintGraphParser parser(archive,imageHelp,&pBuf);
trpgPrintGraphParser parser(archive,imageHelp,&pBuf);
pBuf.prnLine("====Tile Data====");
int nl,x,y;
trpgMemReadBuffer buf(archive->GetEndian());
// Iterate over the terrain lods
int numLod;
archive->GetHeader()->GetNumLods(numLod);
trpg2iPoint tileSize;
pBuf.prnLine("====Tile Data====");
int nl,x,y;
trpgMemReadBuffer buf(archive->GetEndian());
// Iterate over the terrain lods
int numLod;
archive->GetHeader()->GetNumLods(numLod);
trpg2iPoint tileSize;
if(majorVersion == 2 && minorVersion >= 1)
{
// Version 2.1
@@ -389,43 +389,43 @@ bool trpgPrintArchive(trpgr_Archive *archive,trpgPrintBuffer &pBuf,int flags)
// Also the tile table only contains lod 0 tiles so we can no longer access
// the tile directly from its grid location. So we have to traverse.
trpg2iPoint blockTileSize;
if(archive->GetHeader()->GetLodSize(0,blockTileSize)) {
for(x = 0; x < blockTileSize.x; x++)
for( y = 0; y < blockTileSize.y; y++)
if (archive->ReadTile(x,y,0,buf))
printBuf(0, x, y, archive, parser, buf, pBuf);
if(archive->GetHeader()->GetLodSize(0,blockTileSize)) {
for(x = 0; x < blockTileSize.x; x++)
for( y = 0; y < blockTileSize.y; y++)
if (archive->ReadTile(x,y,0,buf))
printBuf(0, x, y, archive, parser, buf, pBuf);
}
}
}
else
{
for (nl=0;nl<numLod;nl++) {
archive->GetHeader()->GetLodSize(nl,tileSize);
// Iterate over the tiles
for (x=tileSize.x-1;x>=0;x--)
for (y=0;y<tileSize.y;y++) {
sprintf(ls,"Tile (lod) (x,y) = (%d) (%d,%d)",nl,x,y);
pBuf.prnLine(ls);
if (archive->ReadTile(x,y,nl,buf)) {
if (flags & TRPGPRN_BODY) {
pBuf.IncreaseIndent();
// Parse it (also prints it
if (!parser.Parse(buf))
{
char errString[80];
sprintf(errString, "**** Warning: tile anomaly detected: (%d) (%d,%d) ****",nl,x,y);
// send it both ways so it's easier to spot
pBuf.prnLine(errString);
fprintf(stderr,"%s\n",errString);
}
pBuf.DecreaseIndent();
}
} else
pBuf.prnLine(" Couldn't read tile.");
}
}
for (nl=0;nl<numLod;nl++) {
archive->GetHeader()->GetLodSize(nl,tileSize);
// Iterate over the tiles
for (x=tileSize.x-1;x>=0;x--)
for (y=0;y<tileSize.y;y++) {
sprintf(ls,"Tile (lod) (x,y) = (%d) (%d,%d)",nl,x,y);
pBuf.prnLine(ls);
if (archive->ReadTile(x,y,nl,buf)) {
if (flags & TRPGPRN_BODY) {
pBuf.IncreaseIndent();
// Parse it (also prints it
if (!parser.Parse(buf))
{
char errString[80];
sprintf(errString, "**** Warning: tile anomaly detected: (%d) (%d,%d) ****",nl,x,y);
// send it both ways so it's easier to spot
pBuf.prnLine(errString);
fprintf(stderr,"%s\n",errString);
}
pBuf.DecreaseIndent();
}
} else
pBuf.prnLine(" Couldn't read tile.");
}
}
}
return true;
return true;
}

View File

@@ -14,9 +14,9 @@
*/
/* trpage_range.cpp
Methods for the Range Table. Consult trpg_geom.h for details
on what this is and how it works.
*/
Methods for the Range Table. Consult trpg_geom.h for details
on what this is and how it works.
*/
#include <stdlib.h>
#include <stdio.h>
@@ -26,334 +26,334 @@
#include <trpage_read.h>
/* *******************
Range Methods
Range Methods
*******************
*/
trpgRange::trpgRange(void)
{
category = NULL;
subCategory = NULL;
Reset();
category = NULL;
subCategory = NULL;
Reset();
}
trpgRange::~trpgRange(void)
{
Reset();
Reset();
}
trpgRange::trpgRange(const trpgRange &in):
trpgReadWriteable(in)
{
category = NULL;
subCategory = NULL;
*this = in;
category = NULL;
subCategory = NULL;
*this = in;
}
void trpgRange::Reset(void)
{
errMess[0] = '\0';
if (category)
delete [] category;
category = NULL;
if (subCategory)
delete [] subCategory;
subCategory = NULL;
errMess[0] = '\0';
if (category)
delete [] category;
category = NULL;
if (subCategory)
delete [] subCategory;
subCategory = NULL;
inLod = outLod = 0.0;
priority = 0;
handle = -1;
writeHandle = false;
inLod = outLod = 0.0;
priority = 0;
handle = -1;
writeHandle = false;
}
void trpgRange::SetCategory(const char *cat,const char *subCat)
{
if (category) delete [] category;
category = NULL;
if (cat) {
category = new char[strlen(cat)+1];
strcpy(category,cat);
}
if (category) delete [] category;
category = NULL;
if (cat) {
category = new char[strlen(cat)+1];
strcpy(category,cat);
}
if (subCategory) delete [] subCategory;
subCategory = NULL;
if (subCat) {
subCategory = new char[strlen(subCat)+1];
strcpy(subCategory,subCat);
}
if (subCategory) delete [] subCategory;
subCategory = NULL;
if (subCat) {
subCategory = new char[strlen(subCat)+1];
strcpy(subCategory,subCat);
}
}
void trpgRange::GetCategory(char *cat,int catLen,char *subCat,int subCatLen) const
{
if (category && cat) {
strncpy(cat,category,catLen);
} else
*cat = 0;
if (subCategory && subCat) {
strncpy(subCat,subCategory,subCatLen);
} else
*subCat = 0;
if (category && cat) {
strncpy(cat,category,catLen);
} else
*cat = 0;
if (subCategory && subCat) {
strncpy(subCat,subCategory,subCatLen);
} else
*subCat = 0;
}
void trpgRange::SetLodInfo(double in,double out)
{
inLod = in;
outLod = out;
inLod = in;
outLod = out;
}
void trpgRange::GetLodInfo(double &in,double &out) const
{
in = inLod;
out = outLod;
in = inLod;
out = outLod;
}
void trpgRange::SetPriority(int prior)
{
priority = prior;
priority = prior;
}
void trpgRange::GetPriority(int &prior) const
{
prior = priority;
prior = priority;
}
trpgRange & trpgRange::operator = (const trpgRange &other)
{
Reset();
inLod = other.inLod;
outLod = other.outLod;
SetCategory(other.category,other.subCategory);
priority = other.priority;
handle = other.handle;
writeHandle = other.writeHandle;
return *this;
Reset();
inLod = other.inLod;
outLod = other.outLod;
SetCategory(other.category,other.subCategory);
priority = other.priority;
handle = other.handle;
writeHandle = other.writeHandle;
return *this;
}
bool trpgRange::operator == (const trpgRange &in) const
{
if (inLod != in.inLod || outLod != in.outLod)
return false;
if (priority != in.priority) return false;
if (inLod != in.inLod || outLod != in.outLod)
return false;
if (priority != in.priority) return false;
if (category && in.category) {
if (strcmp(category,in.category))
return false;
} else {
if ((category && !in.category) ||
(!category && in.category) )
return false;
}
if (category && in.category) {
if (strcmp(category,in.category))
return false;
} else {
if ((category && !in.category) ||
(!category && in.category) )
return false;
}
if (subCategory && in.subCategory) {
if (strcmp(subCategory,in.subCategory))
return false;
} else {
if ((subCategory && !in.subCategory) ||
(subCategory && in.subCategory))
return false;
}
if(handle != in.handle)
return false;
if(writeHandle != in.writeHandle)
return false;
return true;
if (subCategory && in.subCategory) {
if (strcmp(subCategory,in.subCategory))
return false;
} else {
if ((subCategory && !in.subCategory) ||
(subCategory && in.subCategory))
return false;
}
if(handle != in.handle)
return false;
if(writeHandle != in.writeHandle)
return false;
return true;
}
bool trpgRange::Write(trpgWriteBuffer &buf)
{
buf.Begin(TRPG_RANGE);
buf.Add(inLod);
buf.Add(outLod);
buf.Add(priority);
buf.Add((category ? category : ""));
buf.Add((subCategory ? subCategory : ""));
if(writeHandle) {
buf.Add((int32)handle);
}
buf.End();
buf.Begin(TRPG_RANGE);
buf.Add(inLod);
buf.Add(outLod);
buf.Add(priority);
buf.Add((category ? category : ""));
buf.Add((subCategory ? subCategory : ""));
if(writeHandle) {
buf.Add((int32)handle);
}
buf.End();
return true;
return true;
}
bool trpgRange::Read(trpgReadBuffer &buf)
{
char catStr[1024],subStr[1024];
char catStr[1024],subStr[1024];
Reset();
valid = false;
Reset();
valid = false;
try {
buf.Get(inLod);
buf.Get(outLod);
buf.Get(priority);
buf.Get(catStr,1024);
buf.Get(subStr,1024);
SetCategory(catStr,subStr);
try {
buf.Get(inLod);
buf.Get(outLod);
buf.Get(priority);
buf.Get(catStr,1024);
buf.Get(subStr,1024);
SetCategory(catStr,subStr);
// Read the handle if we can..
try {
// Read the handle if we can..
try {
int32 tempHandle;
if(buf.Get(tempHandle))
if(buf.Get(tempHandle))
{
handle = tempHandle;
}
else
{
handle = -1;
}
}
catch (...) {
handle = -1;
}
valid = true;
}
handle = -1;
}
}
catch (...) {
handle = -1;
}
valid = true;
}
catch (...) {
return false;
}
catch (...) {
return false;
}
return isValid();
return isValid();
}
/* ***************
Range Table methods
***************
Range Table methods
***************
*/
trpgRangeTable::trpgRangeTable(void)
{
valid = true;
valid = true;
}
trpgRangeTable::~trpgRangeTable(void)
{
// vector cleans up itself
// vector cleans up itself
}
void trpgRangeTable::Reset(void)
{
rangeMap.clear();
valid = true;
rangeMap.clear();
valid = true;
}
bool trpgRangeTable::GetRange(int id,trpgRange &ret) const
{
if (!isValid())
return false;
if (!isValid())
return false;
if (id < 0)// || id >= rangeList.size())
return false;
if (id < 0)// || id >= rangeList.size())
return false;
RangeMapType::const_iterator itr = rangeMap.find(id);
if(itr == rangeMap.end()) {
return false;
}
ret = itr->second;
return true;
RangeMapType::const_iterator itr = rangeMap.find(id);
if(itr == rangeMap.end()) {
return false;
}
ret = itr->second;
return true;
}
bool trpgRangeTable::SetRange(int id,trpgRange &inRange)
{
if (!isValid())
return false;
if (!isValid())
return false;
if (id < 0)// || id >= rangeList.size())
return false;
if (id < 0)// || id >= rangeList.size())
return false;
rangeMap[id] = inRange;
rangeMap[id] = inRange;
return true;
return true;
}
int trpgRangeTable::AddRange(trpgRange &range)
{
int handle = range.GetHandle();
if(handle==-1) {
handle = rangeMap.size();
}
rangeMap[handle] = range;
return handle;
int handle = range.GetHandle();
if(handle==-1) {
handle = rangeMap.size();
}
rangeMap[handle] = range;
return handle;
}
int trpgRangeTable::FindAddRange(trpgRange &range)
{
RangeMapType::iterator itr = rangeMap.begin();
for ( ; itr != rangeMap.end( ); itr++) {
if(itr->second==range)
return itr->first;
}
RangeMapType::iterator itr = rangeMap.begin();
for ( ; itr != rangeMap.end( ); itr++) {
if(itr->second==range)
return itr->first;
}
#if 0
for (int i=0;i<rangeList.size();i++) {
if (range == rangeList[i])
return i;
}
for (int i=0;i<rangeList.size();i++) {
if (range == rangeList[i])
return i;
}
#endif
return AddRange(range);
return AddRange(range);
}
bool trpgRangeTable::Write(trpgWriteBuffer &buf)
{
if (!isValid())
return false;
if (!isValid())
return false;
buf.Begin(TRPGRANGETABLE);
buf.Add((int32)rangeMap.size());
buf.Begin(TRPGRANGETABLE);
buf.Add((int32)rangeMap.size());
RangeMapType::iterator itr = rangeMap.begin();
for ( ; itr != rangeMap.end( ); itr++) {
trpgRange &range = itr->second;
range.Write(buf);
}
RangeMapType::iterator itr = rangeMap.begin();
for ( ; itr != rangeMap.end( ); itr++) {
trpgRange &range = itr->second;
range.Write(buf);
}
buf.End();
buf.End();
return true;
return true;
}
bool trpgRangeTable::Read(trpgReadBuffer &buf)
{
int32 numRange;
trpgToken tok;
int32 len;
valid = false;
int32 numRange;
trpgToken tok;
int32 len;
valid = false;
try {
buf.Get(numRange);
if (numRange < 0) throw 1;
for (int i=0;i<numRange;i++) {
// Read in the individual range
buf.GetToken(tok,len);
if (tok != TRPG_RANGE) throw 1;
buf.PushLimit(len);
trpgRange range;
bool status = range.Read(buf);
buf.PopLimit();
if (!status) throw 1;
AddRange(range);
}
try {
buf.Get(numRange);
if (numRange < 0) throw 1;
for (int i=0;i<numRange;i++) {
// Read in the individual range
buf.GetToken(tok,len);
if (tok != TRPG_RANGE) throw 1;
buf.PushLimit(len);
trpgRange range;
bool status = range.Read(buf);
buf.PopLimit();
if (!status) throw 1;
AddRange(range);
}
valid = true;
}
valid = true;
}
catch (...) {
return false;
}
catch (...) {
return false;
}
return isValid();
return isValid();
}
trpgRangeTable & trpgRangeTable::operator = (const trpgRangeTable &inTab)
{
Reset();
RangeMapType::const_iterator itr = inTab.rangeMap.begin();
for ( ; itr != inTab.rangeMap.end( ); itr++)
rangeMap[itr->first] = itr->second;
Reset();
RangeMapType::const_iterator itr = inTab.rangeMap.begin();
for ( ; itr != inTab.rangeMap.end( ); itr++)
rangeMap[itr->first] = itr->second;
#if 0
for (int i=0;i<inTab.rangeList.size();i++)
rangeList.push_back(inTab.rangeList[i]);
for (int i=0;i<inTab.rangeList.size();i++)
rangeList.push_back(inTab.rangeList[i]);
#endif
return *this;
return *this;
}

View File

@@ -47,7 +47,7 @@ TX_EXDECL class TX_CLDECL trpgr_Token
trpgr_Token(int,trpgr_Callback *,bool destroy=true);
~trpgr_Token(void);
void init(int,trpgr_Callback *,bool destroy=true);
int Token; // Constant token value
int Token; // Constant token value
trpgr_Callback *cb; // Callback when we hit this token
bool destroy; // Should we call delete on the callback or not
void Destruct(void); // Not quite like delete
@@ -78,7 +78,7 @@ TX_EXDECL class TX_CLDECL trpgr_Parser
void *lastObject;
private:
// Note: Just how slow is a map<> anyway?
// This usage is self-contained and could be replaced with an array
// This usage is self-contained and could be replaced with an array
#if defined(_WIN32)
typedef std::map<trpgToken,trpgr_Token> tok_map;
#else
@@ -121,14 +121,14 @@ TX_EXDECL class TX_CLDECL trpgrImageHelper
This routine also calculates the total size, including mipmaps if they're there.
*/
virtual bool GetImageInfoForLocalMat(const trpgLocalMaterial *locMat,
const trpgMaterial **retMat,const trpgTexture **retTex,
int &totSize);
const trpgMaterial **retMat,const trpgTexture **retTex,
int &totSize);
/* Same as above, but gets info for nth image associated with this local material
*/
virtual bool GetNthImageInfoForLocalMat(const trpgLocalMaterial *locMat, int index,
const trpgMaterial **retMat,const trpgTexture **retTex,
int &totSize);
const trpgMaterial **retMat,const trpgTexture **retTex,
int &totSize);
/* Fetch the bytes for the given Local Material (and
associated texture). This is for Tile Local and
@@ -160,11 +160,11 @@ TX_EXDECL class TX_CLDECL trpgrImageHelper
trpgrAppFileCache *GetGeoTypCache()
{
return geotypCache;
return geotypCache;
}
void SetTexTable(trpgTexTable *texTable)
{
this->texTable = texTable;
this->texTable = texTable;
}
protected:
char dir[1024];
@@ -189,9 +189,9 @@ TX_EXDECL class TX_CLDECL trpgr_Archive : public trpgCheckable
virtual ~trpgr_Archive(void);
virtual void SetDirectory(const char *);
virtual bool OpenFile(const char *); // Open File
virtual bool OpenFile(const char *); // Open File
virtual void CloseFile(void);
virtual bool ReadHeader(void); // Read header (materials, tile table. etc..)
virtual bool ReadHeader(void); // Read header (materials, tile table. etc..)
//overload that lets you specify if you want to read all the blocks now,
//or defer reading them for later.
virtual bool ReadHeader(bool readAllBlocks);
@@ -215,7 +215,7 @@ TX_EXDECL class TX_CLDECL trpgr_Archive : public trpgCheckable
// Utility routine to calculate the MBR of a given tile
virtual bool trpgGetTileMBR(uint32 x,uint32 y,uint32 lod,
trpg3dPoint &ll,trpg3dPoint &ur) const;
trpg3dPoint &ll,trpg3dPoint &ur) const;
trpgEndian GetEndian(void) const;
char* getDir(void){return dir;};

View File

@@ -19,473 +19,473 @@
#include <string.h>
/* trpage_scene.cpp
This file implements a bunch of stuff, all of it optional. See trpage_scene.h
for more information.
Scene Graph nodes -
All the methods for the simple scene graph are here.
trpgSceneGraphParser -
This is a subclass of trpgSceneParser. It uses that utility class to keep track
of pushes and pops. It also registers an interest in all the node types it
knows about (Geometry,Group,LOD,ModelRef). When one of those is encountered
by the trpgr_Parser (which it's also a subclass of) it reads it into the
appropriate trpgRead* type.
Unless you're reading into the scene graph defined in trpage_scene.h, you won't
use this class directly. Instead, copy it and use it as a template for how
to read into a scene graph. You'll need to replace the helpers, primarily.
*/
This file implements a bunch of stuff, all of it optional. See trpage_scene.h
for more information.
Scene Graph nodes -
All the methods for the simple scene graph are here.
trpgSceneGraphParser -
This is a subclass of trpgSceneParser. It uses that utility class to keep track
of pushes and pops. It also registers an interest in all the node types it
knows about (Geometry,Group,LOD,ModelRef). When one of those is encountered
by the trpgr_Parser (which it's also a subclass of) it reads it into the
appropriate trpgRead* type.
Unless you're reading into the scene graph defined in trpage_scene.h, you won't
use this class directly. Instead, copy it and use it as a template for how
to read into a scene graph. You'll need to replace the helpers, primarily.
*/
#include <trpage_read.h>
#include <trpage_scene.h>
/* ****************
MBR Calculation and handling
****************
*/
MBR Calculation and handling
****************
*/
trpgMBR::trpgMBR()
{
valid = false;
valid = false;
}
bool trpgMBR::isValid() const
{
return valid;
return valid;
}
void trpgMBR::Reset()
{
valid = false;
valid = false;
}
trpg3dPoint trpgMBR::GetLL() const
{
return ll;
return ll;
}
trpg3dPoint trpgMBR::GetUR() const
{
return ur;
return ur;
}
void trpgMBR::AddPoint(const trpg3dPoint &pt)
{
if (valid) {
ll.x = MIN(pt.x,ll.x);
ll.y = MIN(pt.y,ll.y);
ll.z = MIN(pt.z,ll.z);
ur.x = MAX(pt.x,ur.x);
ur.y = MAX(pt.y,ur.y);
ur.z = MAX(pt.z,ur.z);
} else {
valid = true;
ll = ur = pt;
}
if (valid) {
ll.x = MIN(pt.x,ll.x);
ll.y = MIN(pt.y,ll.y);
ll.z = MIN(pt.z,ll.z);
ur.x = MAX(pt.x,ur.x);
ur.y = MAX(pt.y,ur.y);
ur.z = MAX(pt.z,ur.z);
} else {
valid = true;
ll = ur = pt;
}
}
void trpgMBR::AddPoint(double x,double y,double z)
{
AddPoint(trpg3dPoint(x,y,z));
AddPoint(trpg3dPoint(x,y,z));
}
void trpgMBR::GetMBR(trpg3dPoint &oll,trpg3dPoint &our) const
{
oll = ll;
our = ur;
oll = ll;
our = ur;
}
// Add the input MBR to this one
void trpgMBR::Union(const trpgMBR &in)
{
if (valid) {
if (in.isValid()) {
AddPoint(in.GetLL());
AddPoint(in.GetUR());
}
} else {
valid = true;
*this = in;
}
if (valid) {
if (in.isValid()) {
AddPoint(in.GetLL());
AddPoint(in.GetUR());
}
} else {
valid = true;
*this = in;
}
}
// See if there's any overlap between the two MBRs
bool trpgMBR::Overlap(const trpg2dPoint &ill, const trpg2dPoint &iur) const
{
if (!isValid()) return false;
if (!isValid()) return false;
trpg2dPoint ilr = trpg2dPoint(iur.x,ill.y);
trpg2dPoint iul = trpg2dPoint(ill.x,iur.y);
trpg2dPoint ilr = trpg2dPoint(iur.x,ill.y);
trpg2dPoint iul = trpg2dPoint(ill.x,iur.y);
// B MBR falls within A
if (Within(ill) || Within(iur) || Within(ilr) || Within(iul))
return true;
// B MBR falls within A
if (Within(ill) || Within(iur) || Within(ilr) || Within(iul))
return true;
// A MBR falls within B
if ((inRange(ill.x,iur.x,ll.x) && inRange(ill.y,iur.y,ll.y)) ||
(inRange(ill.x,iur.x,ur.x) && inRange(ill.y,iur.y,ll.y)) ||
(inRange(ill.x,iur.x,ur.x) && inRange(ill.y,iur.y,ur.y)) ||
(inRange(ill.x,iur.x,ll.x) && inRange(ill.y,iur.y,ur.y)))
return true;
// A MBR falls within B
if ((inRange(ill.x,iur.x,ll.x) && inRange(ill.y,iur.y,ll.y)) ||
(inRange(ill.x,iur.x,ur.x) && inRange(ill.y,iur.y,ll.y)) ||
(inRange(ill.x,iur.x,ur.x) && inRange(ill.y,iur.y,ur.y)) ||
(inRange(ill.x,iur.x,ll.x) && inRange(ill.y,iur.y,ur.y)))
return true;
if ((inRange(ll.x,ur.x,ill.x) && ill.y < ll.y && iur.y > ur.y) ||
(inRange(ll.y,ur.y,ill.y) && ill.x < ll.x && iur.x > ur.x))
return true;
if ((inRange(ll.x,ur.x,ill.x) && ill.y < ll.y && iur.y > ur.y) ||
(inRange(ll.y,ur.y,ill.y) && ill.x < ll.x && iur.x > ur.x))
return true;
return false;
return false;
}
// Check if a given 2d point is within the MBR
bool trpgMBR::Within(const trpg2dPoint &pt) const
{
if (inRange(ll.x,ur.x,pt.x) && inRange(ll.y,ur.y,pt.y))
return true;
return false;
if (inRange(ll.x,ur.x,pt.x) && inRange(ll.y,ur.y,pt.y))
return true;
return false;
}
/* ****************
Read Group Base
Base class for all group structures.
****************
*/
/* ****************
Read Group Base
Base class for all group structures.
****************
*/
// Destructor
trpgReadGroupBase::~trpgReadGroupBase()
{
DeleteChildren();
DeleteChildren();
}
// Delete all children
void trpgReadGroupBase::DeleteChildren()
{
for (unsigned int i=0;i<children.size();i++)
if (children[i])
delete children[i];
for (unsigned int i=0;i<children.size();i++)
if (children[i])
delete children[i];
}
// Add a child to the list
void trpgReadGroupBase::AddChild(trpgReadNode *n)
{
children.push_back(n);
children.push_back(n);
}
// Unref a child (but don't delete it)
void trpgReadGroupBase::unRefChild(int id)
{
if (id < 0 || id >= (int)children.size())
return;
children[id] = NULL;
if (id < 0 || id >= (int)children.size())
return;
children[id] = NULL;
}
// Unref all the children (they've probably been moved elsewhere)
void trpgReadGroupBase::unRefChildren()
{
for (unsigned int i=0;i<children.size();i++)
unRefChild(i);
for (unsigned int i=0;i<children.size();i++)
unRefChild(i);
}
// Calculate an MBR
trpgMBR trpgReadGroupBase::GetMBR() const
{
if (mbr.isValid())
return mbr;
else {
// Calculate and cache a new MBR
trpgMBR *cmbr = const_cast<trpgMBR *>(&mbr);
trpgMBR kmbr;
// Ask the kids
for (unsigned int i=0;i<children.size();i++) {
kmbr = children[i]->GetMBR();
cmbr->Union(kmbr);
}
return *cmbr;
}
if (mbr.isValid())
return mbr;
else {
// Calculate and cache a new MBR
trpgMBR *cmbr = const_cast<trpgMBR *>(&mbr);
trpgMBR kmbr;
// Ask the kids
for (unsigned int i=0;i<children.size();i++) {
kmbr = children[i]->GetMBR();
cmbr->Union(kmbr);
}
return *cmbr;
}
}
/* ****************
Read Geometry
****************
*/
Read Geometry
****************
*/
// Calculate an MBR
trpgMBR trpgReadGeometry::GetMBR() const
{
if (mbr.isValid())
return mbr;
if (mbr.isValid())
return mbr;
trpgMBR *pmbr = const_cast<trpgMBR *>(&mbr);
trpgMBR *pmbr = const_cast<trpgMBR *>(&mbr);
int numVert,i;
trpg3dPoint pt;
data.GetNumVertex(numVert);
numVert /= 3;
for (i=0;i<numVert;i++) {
data.GetVertex(i,pt);
pmbr->AddPoint(pt);
}
int numVert,i;
trpg3dPoint pt;
data.GetNumVertex(numVert);
numVert /= 3;
for (i=0;i<numVert;i++) {
data.GetVertex(i,pt);
pmbr->AddPoint(pt);
}
return mbr;
return mbr;
}
/* ****************
Scene Graph Parser
****************
*/
/* ****************
Scene Graph Parser
****************
*/
/* Scene Graph Parser Helpers
Each of these classes reads a certain kind of data (e.g. a group)
and creates the appropriate trpgrRead* form and returns that.
*/
Each of these classes reads a certain kind of data (e.g. a group)
and creates the appropriate trpgrRead* form and returns that.
*/
/* This is a helper registered by trpgSceneGraphParser that readers trpgGeometry
nodes and adds them to the current scene graph. trpgGeometry nodes are
always leaves so there should be no pushes after this node. The Parse method
also adds the new node as a child to any existing (e.g. top) group.
{group:Demonstration Scene Graph}
nodes and adds them to the current scene graph. trpgGeometry nodes are
always leaves so there should be no pushes after this node. The Parse method
also adds the new node as a child to any existing (e.g. top) group.
{group:Demonstration Scene Graph}
*/
class trpgReadGeometryHelper : public trpgr_Callback {
public:
trpgReadGeometryHelper(trpgSceneGraphParser *in_parse) { parse = in_parse;}
void *Parse(trpgToken /*tok*/,trpgReadBuffer &buf) {
trpgReadGeometry *geom = new trpgReadGeometry();
trpgGeometry *data = geom->GetData();
if (!data->Read(buf)) {
delete geom;
return NULL;
}
trpgReadGroupBase *top = parse->GetCurrTop();
if (top)
top->AddChild(geom);
else
delete geom;
trpgReadGeometryHelper(trpgSceneGraphParser *in_parse) { parse = in_parse;}
void *Parse(trpgToken /*tok*/,trpgReadBuffer &buf) {
trpgReadGeometry *geom = new trpgReadGeometry();
trpgGeometry *data = geom->GetData();
if (!data->Read(buf)) {
delete geom;
return NULL;
}
trpgReadGroupBase *top = parse->GetCurrTop();
if (top)
top->AddChild(geom);
else
delete geom;
return geom;
}
return geom;
}
protected:
trpgSceneGraphParser *parse;
trpgSceneGraphParser *parse;
};
/* This helper is registered by trpgSceneGraphParser. It reads a trpgGroup
from the trpgReadBuffer. It then adds it to our current scene graph.
It also adds an index corresponding to the group's group ID in our group
mapping in trpgSceneGraphParser. The new group becomes the top one
after returning from the Parse call.
{group:Demonstration Scene Graph}
from the trpgReadBuffer. It then adds it to our current scene graph.
It also adds an index corresponding to the group's group ID in our group
mapping in trpgSceneGraphParser. The new group becomes the top one
after returning from the Parse call.
{group:Demonstration Scene Graph}
*/
class trpgReadGroupHelper : public trpgr_Callback {
public:
trpgReadGroupHelper(trpgSceneGraphParser *in_parse) { parse = in_parse; }
void *Parse(trpgToken /*tok*/,trpgReadBuffer &buf) {
trpgReadGroup *group = new trpgReadGroup();
trpgGroup *data = group->GetData();
if (!data->Read(buf)) {
delete group;
return NULL;
}
trpgReadGroupBase *top = parse->GetCurrTop();
if (top)
top->AddChild(group);
else
delete group;
// Add to the group map
int id;
data->GetID(id);
trpgSceneGraphParser::GroupMap *gmap = parse->GetGroupMap();
(*gmap)[id] = group;
return group;
}
trpgReadGroupHelper(trpgSceneGraphParser *in_parse) { parse = in_parse; }
void *Parse(trpgToken /*tok*/,trpgReadBuffer &buf) {
trpgReadGroup *group = new trpgReadGroup();
trpgGroup *data = group->GetData();
if (!data->Read(buf)) {
delete group;
return NULL;
}
trpgReadGroupBase *top = parse->GetCurrTop();
if (top)
top->AddChild(group);
else
delete group;
// Add to the group map
int id;
data->GetID(id);
trpgSceneGraphParser::GroupMap *gmap = parse->GetGroupMap();
(*gmap)[id] = group;
return group;
}
protected:
trpgSceneGraphParser *parse;
trpgSceneGraphParser *parse;
};
class trpgReadBillboardHelper : public trpgr_Callback {
public:
trpgReadBillboardHelper(trpgSceneGraphParser *in_parse) { parse = in_parse; }
void *Parse(trpgToken /*tok*/,trpgReadBuffer &buf) {
trpgReadBillboard *group = new trpgReadBillboard();
trpgBillboard *data = group->GetData();
if (!data->Read(buf)) {
delete group;
return NULL;
}
trpgReadGroupBase *top = parse->GetCurrTop();
if (top)
top->AddChild(group);
else
delete group;
// Add to the group map
int id;
data->GetID(id);
trpgSceneGraphParser::GroupMap *gmap = parse->GetGroupMap();
(*gmap)[id] = group;
return group;
}
trpgReadBillboardHelper(trpgSceneGraphParser *in_parse) { parse = in_parse; }
void *Parse(trpgToken /*tok*/,trpgReadBuffer &buf) {
trpgReadBillboard *group = new trpgReadBillboard();
trpgBillboard *data = group->GetData();
if (!data->Read(buf)) {
delete group;
return NULL;
}
trpgReadGroupBase *top = parse->GetCurrTop();
if (top)
top->AddChild(group);
else
delete group;
// Add to the group map
int id;
data->GetID(id);
trpgSceneGraphParser::GroupMap *gmap = parse->GetGroupMap();
(*gmap)[id] = group;
return group;
}
protected:
trpgSceneGraphParser *parse;
trpgSceneGraphParser *parse;
};
class trpgReadAttachHelper : public trpgr_Callback {
public:
trpgReadAttachHelper(trpgSceneGraphParser *in_parse) { parse = in_parse; }
void *Parse(trpgToken /*tok*/,trpgReadBuffer &buf) {
trpgReadAttach *attach = new trpgReadAttach();
trpgAttach *data = attach->GetData();
if (!data->Read(buf)) {
delete attach;
return NULL;
}
trpgReadGroupBase *top = parse->GetCurrTop();
if (top)
top->AddChild(attach);
else
delete attach;
// Add to the group map
int id;
data->GetID(id);
trpgSceneGraphParser::GroupMap *gmap = parse->GetGroupMap();
(*gmap)[id] = attach;
return attach;
}
trpgReadAttachHelper(trpgSceneGraphParser *in_parse) { parse = in_parse; }
void *Parse(trpgToken /*tok*/,trpgReadBuffer &buf) {
trpgReadAttach *attach = new trpgReadAttach();
trpgAttach *data = attach->GetData();
if (!data->Read(buf)) {
delete attach;
return NULL;
}
trpgReadGroupBase *top = parse->GetCurrTop();
if (top)
top->AddChild(attach);
else
delete attach;
// Add to the group map
int id;
data->GetID(id);
trpgSceneGraphParser::GroupMap *gmap = parse->GetGroupMap();
(*gmap)[id] = attach;
return attach;
}
protected:
trpgSceneGraphParser *parse;
trpgSceneGraphParser *parse;
};
class trpgReadChildRefHelper : public trpgr_Callback {
public:
trpgReadChildRefHelper(trpgSceneGraphParser *in_parse) { parse = in_parse; }
void *Parse(trpgToken /*tok*/,trpgReadBuffer &buf) {
trpgReadChildRef *childRef = new trpgReadChildRef();
trpgChildRef *data = childRef->GetData();
if (!data->Read(buf)) {
delete childRef;
return NULL;
}
trpgReadGroupBase *top = parse->GetCurrTop();
// NOTE: this is bad, we delete the pointer then we save it.
trpgReadChildRefHelper(trpgSceneGraphParser *in_parse) { parse = in_parse; }
void *Parse(trpgToken /*tok*/,trpgReadBuffer &buf) {
trpgReadChildRef *childRef = new trpgReadChildRef();
trpgChildRef *data = childRef->GetData();
if (!data->Read(buf)) {
delete childRef;
return NULL;
}
trpgReadGroupBase *top = parse->GetCurrTop();
// NOTE: this is bad, we delete the pointer then we save it.
// this is done everywhere and should be corrected
if (top)
top->AddChild(childRef);
else
delete childRef;
return childRef;
}
top->AddChild(childRef);
else
delete childRef;
return childRef;
}
protected:
trpgSceneGraphParser *parse;
trpgSceneGraphParser *parse;
};
class trpgReadLodHelper : public trpgr_Callback {
public:
trpgReadLodHelper(trpgSceneGraphParser *in_parse) { parse = in_parse; }
void *Parse(trpgToken /*tok*/,trpgReadBuffer &buf) {
trpgReadLod *lod = new trpgReadLod();
trpgLod *data = lod->GetData();
if (!data->Read(buf)) {
delete lod;
return NULL;
}
trpgReadGroupBase *top = parse->GetCurrTop();
if (top)
top->AddChild(lod);
else
delete lod;
// Add to the group map
int id;
data->GetID(id);
trpgSceneGraphParser::GroupMap *gmap = parse->GetGroupMap();
(*gmap)[id] = lod;
return lod;
}
trpgReadLodHelper(trpgSceneGraphParser *in_parse) { parse = in_parse; }
void *Parse(trpgToken /*tok*/,trpgReadBuffer &buf) {
trpgReadLod *lod = new trpgReadLod();
trpgLod *data = lod->GetData();
if (!data->Read(buf)) {
delete lod;
return NULL;
}
trpgReadGroupBase *top = parse->GetCurrTop();
if (top)
top->AddChild(lod);
else
delete lod;
// Add to the group map
int id;
data->GetID(id);
trpgSceneGraphParser::GroupMap *gmap = parse->GetGroupMap();
(*gmap)[id] = lod;
return lod;
}
protected:
trpgSceneGraphParser *parse;
trpgSceneGraphParser *parse;
};
class trpgReadModelRefHelper : public trpgr_Callback {
public:
trpgReadModelRefHelper(trpgSceneGraphParser *in_parse) { parse = in_parse; }
void *Parse(trpgToken /*tok*/,trpgReadBuffer &buf) {
trpgReadModelRef *mod = new trpgReadModelRef();
trpgModelRef *data = mod->GetData();
if (!data->Read(buf)) {
delete mod;
return NULL;
}
trpgReadGroupBase *top = parse->GetCurrTop();
if (top)
top->AddChild(mod);
else
delete mod;
return mod;
}
trpgReadModelRefHelper(trpgSceneGraphParser *in_parse) { parse = in_parse; }
void *Parse(trpgToken /*tok*/,trpgReadBuffer &buf) {
trpgReadModelRef *mod = new trpgReadModelRef();
trpgModelRef *data = mod->GetData();
if (!data->Read(buf)) {
delete mod;
return NULL;
}
trpgReadGroupBase *top = parse->GetCurrTop();
if (top)
top->AddChild(mod);
else
delete mod;
return mod;
}
protected:
trpgSceneGraphParser *parse;
trpgSceneGraphParser *parse;
};
class trpgReadTileHeaderHelper : public trpgr_Callback {
public:
trpgReadTileHeaderHelper(trpgSceneGraphParser *in_parse) { parse = in_parse; }
void *Parse(trpgToken /*tok*/,trpgReadBuffer &buf) {
trpgReadTileHeader *th = parse->GetTileHeaderRef();
trpgTileHeader *data = th->GetData();
if (!data->Read(buf))
return NULL;
return th;
}
trpgReadTileHeaderHelper(trpgSceneGraphParser *in_parse) { parse = in_parse; }
void *Parse(trpgToken /*tok*/,trpgReadBuffer &buf) {
trpgReadTileHeader *th = parse->GetTileHeaderRef();
trpgTileHeader *data = th->GetData();
if (!data->Read(buf))
return NULL;
return th;
}
protected:
trpgSceneGraphParser *parse;
trpgSceneGraphParser *parse;
};
/* The Scene Graph Parser constructor does two things. First, it sets
up any internal variables like a normal constructor. Then it registers
an interest in all the node types it knows how to parse. It does this
by calling AddCallback, which is a method of its parent. It passes in
a token representing the node type (see trpg_io.h) and an object that
is capable of parsing the given type.
up any internal variables like a normal constructor. Then it registers
an interest in all the node types it knows how to parse. It does this
by calling AddCallback, which is a method of its parent. It passes in
a token representing the node type (see trpg_io.h) and an object that
is capable of parsing the given type.
The objects we pass in here are called helpers. They parse specific
objects and add them to the user defined scene graph. Examples include
trpgReadGeometryHelper, trpgReadGroupHelper, trpgReadAttachHelper,
trpgReadBillboardHelper, trpgReadLodHelper, trpgReadModelRefHelper,
trpgReadTileHeaderHelper. These are all derived from trpgr_Callback.
You should not use any of these yourself. Instead look at these classes
as examples of how to implement your own subclass of trpgSceneParser.
*/
The objects we pass in here are called helpers. They parse specific
objects and add them to the user defined scene graph. Examples include
trpgReadGeometryHelper, trpgReadGroupHelper, trpgReadAttachHelper,
trpgReadBillboardHelper, trpgReadLodHelper, trpgReadModelRefHelper,
trpgReadTileHeaderHelper. These are all derived from trpgr_Callback.
You should not use any of these yourself. Instead look at these classes
as examples of how to implement your own subclass of trpgSceneParser.
*/
trpgSceneGraphParser::trpgSceneGraphParser()
{
top = currTop = NULL;
top = currTop = NULL;
// Register the readers
AddCallback(TRPG_GEOMETRY,new trpgReadGeometryHelper(this));
AddCallback(TRPG_GROUP,new trpgReadGroupHelper(this));
AddCallback(TRPG_ATTACH,new trpgReadAttachHelper(this));
// Register the readers
AddCallback(TRPG_GEOMETRY,new trpgReadGeometryHelper(this));
AddCallback(TRPG_GROUP,new trpgReadGroupHelper(this));
AddCallback(TRPG_ATTACH,new trpgReadAttachHelper(this));
AddCallback(TRPG_CHILDREF,new trpgReadChildRefHelper(this));
AddCallback(TRPG_BILLBOARD,new trpgReadBillboardHelper(this));
AddCallback(TRPG_LOD,new trpgReadLodHelper(this));
// AddCallback(TRPG_TRANSFORM,new trpgReadTransformHelper(this));
AddCallback(TRPG_MODELREF,new trpgReadModelRefHelper(this));
// AddCallback(TRPG_LAYER,new trpgReadLayerHelper(this));
AddCallback(TRPGTILEHEADER,new trpgReadTileHeaderHelper(this));
AddCallback(TRPG_BILLBOARD,new trpgReadBillboardHelper(this));
AddCallback(TRPG_LOD,new trpgReadLodHelper(this));
// AddCallback(TRPG_TRANSFORM,new trpgReadTransformHelper(this));
AddCallback(TRPG_MODELREF,new trpgReadModelRefHelper(this));
// AddCallback(TRPG_LAYER,new trpgReadLayerHelper(this));
AddCallback(TRPGTILEHEADER,new trpgReadTileHeaderHelper(this));
}
// Get Current Top node
trpgReadGroupBase *trpgSceneGraphParser::GetCurrTop()
{
if (!currTop)
return NULL;
if (currTop->isGroupType())
return (trpgReadGroupBase *)currTop;
if (!currTop)
return NULL;
if (currTop->isGroupType())
return (trpgReadGroupBase *)currTop;
return NULL;
return NULL;
}
// Return a pointer to the tile header record
trpgReadTileHeader *trpgSceneGraphParser::GetTileHeaderRef()
{
return &tileHead;
return &tileHead;
}
// Parse Scene
// Parse a buffer and return the resulting scene graph
trpgReadNode *trpgSceneGraphParser::ParseScene(trpgReadBuffer &buf,GroupMap &inGmap)
{
gmap = &inGmap;
trpgTileHeader *data = tileHead.GetData();
data->Reset();
gmap = &inGmap;
trpgTileHeader *data = tileHead.GetData();
data->Reset();
// Always put a group up top, since there might be more than
// one node at the top level in the file.
top = currTop = new trpgReadGroup();
// Always put a group up top, since there might be more than
// one node at the top level in the file.
top = currTop = new trpgReadGroup();
// All the setup for tokens is handled in the constructor
// Just call parse
if (!Parse(buf)) {
// Failed to parse correctly. Give up.
delete top;
return NULL;
}
// All the setup for tokens is handled in the constructor
// Just call parse
if (!Parse(buf)) {
// Failed to parse correctly. Give up.
delete top;
return NULL;
}
return top;
return top;
}
// Start Children
@@ -493,19 +493,19 @@ trpgReadNode *trpgSceneGraphParser::ParseScene(trpgReadBuffer &buf,GroupMap &inG
// We'll want to make the node it's handing us the "top" node
bool trpgSceneGraphParser::StartChildren(void *in_node)
{
trpgReadNode *node = (trpgReadNode *)in_node;
trpgReadNode *node = (trpgReadNode *)in_node;
if (!node || !node->isGroupType()) {
// Looks like there's a push in the wrong place
// Make the current "top" NULL.
// This will drop all node until we pop back above
currTop = NULL;
} else {
// This node is our new "top"
currTop = node;
}
if (!node || !node->isGroupType()) {
// Looks like there's a push in the wrong place
// Make the current "top" NULL.
// This will drop all node until we pop back above
currTop = NULL;
} else {
// This node is our new "top"
currTop = node;
}
return true;
return true;
}
/* This is called whent he parser hits a pop.
@@ -515,65 +515,65 @@ bool trpgSceneGraphParser::StartChildren(void *in_node)
*/
bool trpgSceneGraphParser::EndChildren(void* /*in_node*/)
{
// We don't need it here, but this is the node we just
// finished putting children under. If you need to close
// it out in some way, do that here
//trpgReadNode *node = (trpgReadNode *)in_node;
// We don't need it here, but this is the node we just
// finished putting children under. If you need to close
// it out in some way, do that here
//trpgReadNode *node = (trpgReadNode *)in_node;
// Get the parent above the current one
int pos = parents.size()-2;
if (pos < 0)
// Nothing above the current one. Fall back on our top group
currTop = top;
else
currTop = (trpgReadNode *)parents[pos];
// Get the parent above the current one
int pos = parents.size()-2;
if (pos < 0)
// Nothing above the current one. Fall back on our top group
currTop = top;
else
currTop = (trpgReadNode *)parents[pos];
return true;
return true;
}
// Return group map (for use by helpers)
trpgSceneGraphParser::GroupMap *trpgSceneGraphParser::GetGroupMap()
{
return gmap;
return gmap;
}
/* ***********
Test functions
***********
*/
Test functions
***********
*/
// Test all the tiles in an archive
bool trpgTestArchive(trpgr_Archive &archive)
{
int numLod;
trpg2iPoint tileSize;
trpgSceneGraphParser parse;
trpgReadNode *scene;
trpgSceneGraphParser::GroupMap gmap;
int numLod;
trpg2iPoint tileSize;
trpgSceneGraphParser parse;
trpgReadNode *scene;
trpgSceneGraphParser::GroupMap gmap;
if (!archive.isValid()) return false;
if (!archive.isValid()) return false;
const trpgHeader *head = archive.GetHeader();
head->GetNumLods(numLod);
const trpgHeader *head = archive.GetHeader();
head->GetNumLods(numLod);
// Iterate over the lods
int nl,x,y;
trpgMemReadBuffer buf(archive.GetEndian());
trpg3dPoint ll,ur;
for (nl = 0;nl < numLod;nl++) {
head->GetLodSize(nl,tileSize);
// Iterate over the tiles within those
for (x = 0; x < tileSize.x; x++)
for (y = 0; y < tileSize.y; y++) {
archive.trpgGetTileMBR(x,y,nl,ll,ur);
if (archive.ReadTile(x,y,nl,buf)) {
// Parse it
scene = parse.ParseScene(buf,gmap);
if (scene)
delete scene;
}
}
}
// Iterate over the lods
int nl,x,y;
trpgMemReadBuffer buf(archive.GetEndian());
trpg3dPoint ll,ur;
for (nl = 0;nl < numLod;nl++) {
head->GetLodSize(nl,tileSize);
// Iterate over the tiles within those
for (x = 0; x < tileSize.x; x++)
for (y = 0; y < tileSize.y; y++) {
archive.trpgGetTileMBR(x,y,nl,ll,ur);
if (archive.ReadTile(x,y,nl,buf)) {
// Parse it
scene = parse.ParseScene(buf,gmap);
if (scene)
delete scene;
}
}
}
return true;
return true;
}

View File

@@ -18,234 +18,234 @@
#define _txpage_scene_h_
/* trpage_scene.h
Scene Graph definition.
This is a small scene graph we use for testing.
It's not intended to replace the scene graph you may already be using.
You do not need to translate from this scene graph structure to your own,
at run-time. Instead, use this file and trpage_scene.cpp as a guideline
for how to read TerraPage format into your own scene graph.
Scene Graph definition.
This is a small scene graph we use for testing.
It's not intended to replace the scene graph you may already be using.
You do not need to translate from this scene graph structure to your own,
at run-time. Instead, use this file and trpage_scene.cpp as a guideline
for how to read TerraPage format into your own scene graph.
*/
#include <trpage_geom.h>
/*
{group:Demonstration Scene Graph}
*/
{group:Demonstration Scene Graph}
*/
TX_EXDECL class TX_CLDECL trpgMBR {
public:
trpgMBR(void);
~trpgMBR(void) { };
bool isValid(void) const;
void Reset(void);
void AddPoint(const trpg3dPoint &);
void AddPoint(double,double,double);
void GetMBR(trpg3dPoint &ll,trpg3dPoint &ur) const;
trpg3dPoint GetLL(void) const;
trpg3dPoint GetUR(void) const;
void Union(const trpgMBR &);
// bool Overlap(const trpgMBR &) const;
bool Overlap(const trpg2dPoint &ll, const trpg2dPoint &ur) const;
// bool Within(const trpg3dPoint &) const
bool Within(const trpg2dPoint &) const;
trpgMBR(void);
~trpgMBR(void) { };
bool isValid(void) const;
void Reset(void);
void AddPoint(const trpg3dPoint &);
void AddPoint(double,double,double);
void GetMBR(trpg3dPoint &ll,trpg3dPoint &ur) const;
trpg3dPoint GetLL(void) const;
trpg3dPoint GetUR(void) const;
void Union(const trpgMBR &);
// bool Overlap(const trpgMBR &) const;
bool Overlap(const trpg2dPoint &ll, const trpg2dPoint &ur) const;
// bool Within(const trpg3dPoint &) const
bool Within(const trpg2dPoint &) const;
protected:
inline bool inRange(double minv,double maxv,double val) const { return (val >= minv && val <= maxv); }
bool valid;
trpg3dPoint ll,ur;
inline bool inRange(double minv,double maxv,double val) const { return (val >= minv && val <= maxv); }
bool valid;
trpg3dPoint ll,ur;
};
// Read Node
// Simple Scenegraph node used for read testing
// {group:Demonstration Scene Graph}
// {group:Demonstration Scene Graph}
TX_EXDECL class TX_CLDECL trpgReadNode {
public:
virtual ~trpgReadNode(void) { };
virtual bool isGroupType(void) = 0;
virtual int GetType(void) { return type; }
virtual trpgMBR GetMBR(void) const { return trpgMBR(); }
virtual ~trpgReadNode(void) { };
virtual bool isGroupType(void) = 0;
virtual int GetType(void) { return type; }
virtual trpgMBR GetMBR(void) const { return trpgMBR(); }
protected:
int type;
int type;
};
// Read Group Base
// Base class for all group nodes
// {group:Demonstration Scene Graph}
// {group:Demonstration Scene Graph}
TX_EXDECL class TX_CLDECL trpgReadGroupBase : public trpgReadNode {
public:
virtual ~trpgReadGroupBase(void);
void AddChild(trpgReadNode *);
bool isGroupType(void) { return true; }
int GetNumChildren(void) { return int(children.size()); }
trpgReadNode *GetChild(int i) { return children[i]; }
trpgMBR GetMBR(void) const;
void unRefChild(int i);
void unRefChildren(void);
virtual ~trpgReadGroupBase(void);
void AddChild(trpgReadNode *);
bool isGroupType(void) { return true; }
int GetNumChildren(void) { return int(children.size()); }
trpgReadNode *GetChild(int i) { return children[i]; }
trpgMBR GetMBR(void) const;
void unRefChild(int i);
void unRefChildren(void);
protected:
trpgMBR mbr;
void DeleteChildren(void);
std::vector<trpgReadNode *> children;
trpgMBR mbr;
void DeleteChildren(void);
std::vector<trpgReadNode *> children;
};
// Read Geometry
// The leaf for this scene graph
// {group:Demonstration Scene Graph}
// {group:Demonstration Scene Graph}
TX_EXDECL class TX_CLDECL trpgReadGeometry : public trpgReadNode {
public:
trpgReadGeometry(void) { type = TRPG_GEOMETRY; }
~trpgReadGeometry(void) { };
bool isGroupType(void) { return false; }
trpgGeometry *GetData(void) { return &data; }
trpgMBR GetMBR(void) const;
trpgReadGeometry(void) { type = TRPG_GEOMETRY; }
~trpgReadGeometry(void) { };
bool isGroupType(void) { return false; }
trpgGeometry *GetData(void) { return &data; }
trpgMBR GetMBR(void) const;
protected:
trpgMBR mbr;
trpgGeometry data;
trpgMBR mbr;
trpgGeometry data;
};
// Read Tile Header
// One per tile. Info about what materials and models are used
// {group:Demonstration Scene Graph}
// {group:Demonstration Scene Graph}
TX_EXDECL class TX_CLDECL trpgReadTileHeader : public trpgReadNode {
public:
trpgReadTileHeader(void) { type = TRPGTILEHEADER; }
~trpgReadTileHeader(void) { };
bool isGroupType(void) { return false; }
trpgTileHeader *GetData(void) { return &data; }
trpgMBR GetMBR(void) const { trpgMBR mbr; return mbr; };
trpgReadTileHeader(void) { type = TRPGTILEHEADER; }
~trpgReadTileHeader(void) { };
bool isGroupType(void) { return false; }
trpgTileHeader *GetData(void) { return &data; }
trpgMBR GetMBR(void) const { trpgMBR mbr; return mbr; };
protected:
trpgTileHeader data;
trpgTileHeader data;
};
// Read Group
// Simple group structure
// {group:Demonstration Scene Graph}
// {group:Demonstration Scene Graph}
TX_EXDECL class TX_CLDECL trpgReadGroup : public trpgReadGroupBase {
public:
trpgReadGroup(void) { type = TRPG_GROUP; }
~trpgReadGroup(void) { };
trpgGroup *GetData(void) { return &data; }
trpgReadGroup(void) { type = TRPG_GROUP; }
~trpgReadGroup(void) { };
trpgGroup *GetData(void) { return &data; }
protected:
trpgGroup data;
trpgGroup data;
};
// Read Attach
// Should be the top of a higher LOD tile
// {group:Demonstration Scene Graph}
// {group:Demonstration Scene Graph}
TX_EXDECL class TX_CLDECL trpgReadAttach : public trpgReadGroupBase {
public:
trpgReadAttach(void) { type = TRPG_ATTACH; }
~trpgReadAttach(void) { };
trpgAttach *GetData(void) { return &data; }
trpgReadAttach(void) { type = TRPG_ATTACH; }
~trpgReadAttach(void) { };
trpgAttach *GetData(void) { return &data; }
protected:
trpgAttach data;
trpgAttach data;
};
// Read ChildRef
// Should point to a block tile
// {group:Demonstration Scene Graph}
// {group:Demonstration Scene Graph}
TX_EXDECL class TX_CLDECL trpgReadChildRef : public trpgReadGroupBase {
public:
trpgReadChildRef(void) { type = TRPG_CHILDREF; }
~trpgReadChildRef(void) { };
trpgReadChildRef(void) { type = TRPG_CHILDREF; }
~trpgReadChildRef(void) { };
bool isGroupType(void) { return false;}
trpgChildRef *GetData(void) { return &data; }
trpgChildRef *GetData(void) { return &data; }
protected:
trpgChildRef data;
trpgChildRef data;
};
// Read billboard
// {group:Demonstration Scene Graph}
// {group:Demonstration Scene Graph}
TX_EXDECL class TX_CLDECL trpgReadBillboard : public trpgReadGroupBase {
public:
trpgReadBillboard(void) { type = TRPG_BILLBOARD; }
~trpgReadBillboard(void) { };
trpgBillboard *GetData(void) { return &data; }
trpgReadBillboard(void) { type = TRPG_BILLBOARD; }
~trpgReadBillboard(void) { };
trpgBillboard *GetData(void) { return &data; }
protected:
trpgBillboard data;
trpgBillboard data;
};
// Read LOD
// {group:Demonstration Scene Graph}
// {group:Demonstration Scene Graph}
TX_EXDECL class TX_CLDECL trpgReadLod : public trpgReadGroupBase {
public:
trpgReadLod(void) { type = TRPG_LOD; }
~trpgReadLod(void) { };
trpgLod *GetData(void) { return &data; }
trpgReadLod(void) { type = TRPG_LOD; }
~trpgReadLod(void) { };
trpgLod *GetData(void) { return &data; }
protected:
trpgLod data;
trpgLod data;
};
// Read Layer
// {group:Demonstration Scene Graph}
// {group:Demonstration Scene Graph}
TX_EXDECL class TX_CLDECL trpgReadLayer : public trpgReadGroupBase {
public:
trpgReadLayer(void) { type = TRPG_LAYER; }
~trpgReadLayer(void) { };
trpgLayer *GetData(void) { return &data; }
trpgReadLayer(void) { type = TRPG_LAYER; }
~trpgReadLayer(void) { };
trpgLayer *GetData(void) { return &data; }
protected:
trpgLayer data;
trpgLayer data;
};
// Read Transform
// {group:Demonstration Scene Graph}
// {group:Demonstration Scene Graph}
TX_EXDECL class TX_CLDECL trpgReadTransform : public trpgReadGroupBase {
public:
trpgReadTransform(void) { type = TRPG_TRANSFORM; }
~trpgReadTransform(void) { };
trpgTransform *GetData(void) { return &data; }
trpgReadTransform(void) { type = TRPG_TRANSFORM; }
~trpgReadTransform(void) { };
trpgTransform *GetData(void) { return &data; }
protected:
trpgTransform data;
trpgTransform data;
};
// Read Model Reference
// {group:Demonstration Scene Graph}
// {group:Demonstration Scene Graph}
TX_EXDECL class TX_CLDECL trpgReadModelRef : public trpgReadGroupBase {
public:
trpgReadModelRef(void) { type = TRPG_MODELREF; }
~trpgReadModelRef(void) { };
trpgModelRef *GetData(void) { return &data; }
trpgReadModelRef(void) { type = TRPG_MODELREF; }
~trpgReadModelRef(void) { };
trpgModelRef *GetData(void) { return &data; }
protected:
trpgModelRef data;
trpgModelRef data;
};
/* Scene Graph Parser
Parses a read buffer and returns a full scenegraph.
You don't want to use this if you're reading into your own scenegraph.
Instead, you'll want to sublcass trpgSceneParser, which is a helper
class to keep track of pushes and pops and implement the same functionality
that trpgSceneGraphParser has for your own scene graph.
*/
// {group:Demonstration Scene Graph}
Parses a read buffer and returns a full scenegraph.
You don't want to use this if you're reading into your own scenegraph.
Instead, you'll want to sublcass trpgSceneParser, which is a helper
class to keep track of pushes and pops and implement the same functionality
that trpgSceneGraphParser has for your own scene graph.
*/
// {group:Demonstration Scene Graph}
TX_EXDECL class TX_CLDECL trpgSceneGraphParser : public trpgSceneParser {
public:
#if defined(_WIN32)
typedef std::map<int,trpgReadGroupBase *> GroupMap;
typedef std::map<int,trpgReadGroupBase *> GroupMap;
#else
typedef std::map< int,trpgReadGroupBase *,std::less<int> > GroupMap;
typedef std::map< int,trpgReadGroupBase *,std::less<int> > GroupMap;
#endif
trpgSceneGraphParser(void);
virtual ~trpgSceneGraphParser(void) { };
// Call this instead of Parse()
// Deleting it is your responsibility
trpgReadNode *ParseScene(trpgReadBuffer &,GroupMap &);
trpgReadGroupBase *GetCurrTop(void); // Get the current parent object
trpgReadTileHeader *GetTileHeaderRef(void);
trpgSceneGraphParser(void);
virtual ~trpgSceneGraphParser(void) { };
// Call this instead of Parse()
// Deleting it is your responsibility
trpgReadNode *ParseScene(trpgReadBuffer &,GroupMap &);
trpgReadGroupBase *GetCurrTop(void); // Get the current parent object
trpgReadTileHeader *GetTileHeaderRef(void);
// For use by the helpers only
GroupMap *GetGroupMap(void);
// For use by the helpers only
GroupMap *GetGroupMap(void);
protected:
bool StartChildren(void *);
bool EndChildren(void *);
trpgReadNode *currTop; // Current parent group
trpgReadNode *top; // Top of everything
GroupMap *gmap;
trpgReadTileHeader tileHead; // Tile header gets read into here
bool StartChildren(void *);
bool EndChildren(void *);
trpgReadNode *currTop; // Current parent group
trpgReadNode *top; // Top of everything
GroupMap *gmap;
trpgReadTileHeader tileHead; // Tile header gets read into here
};
/* Test Archive
Utility function that loads and tests all tiles.
The only reason you'd want to call this is to test a TerraPage archive
you'd written.
*/
// {group:Demonstration Scene Graph}
Utility function that loads and tests all tiles.
The only reason you'd want to call this is to test a TerraPage archive
you'd written.
*/
// {group:Demonstration Scene Graph}
TX_CPPDECL bool trpgTestArchive(trpgr_Archive &);
#endif

View File

@@ -17,7 +17,7 @@
#define trpage_swap_h_
/* trpage_swap.h
Byte swapping utility functions.
Byte swapping utility functions.
*/
#include <trpage_sys.h>
@@ -29,7 +29,7 @@
short trpg_byteswap_short( short number );
// Byte swap and return an integer
// {group:Byte Ordering Utilities}
TX_CPPDECL int trpg_byteswap_int( int number );
TX_CPPDECL int trpg_byteswap_int( int number );
// Byte swap and return a long
// {group:Byte Ordering Utilities}
long trpg_byteswap_long( long number );

View File

@@ -14,8 +14,8 @@
*/
/* trpage_sys.h
System specific declarations.
*/
System specific declarations.
*/
#ifndef trpage_sys_h_
#define trpage_sys_h_
@@ -29,11 +29,11 @@
#endif
#if defined(_WIN32)
/* *********************
System Specific Section.
This is currently set up for win32.
*********************
*/
/* *********************
System Specific Section.
This is currently set up for win32.
*********************
*/
#include <windows.h>

View File

@@ -19,34 +19,34 @@
/* trpage_tile.cpp
This source file contains the implementation of trpgTileTable and trpgTileHeader.
You'll need to edit these if you want to add something to the Tile Table (at
the front of an archive) or the Tile Header (at the beginning of each tile).
*/
This source file contains the implementation of trpgTileTable and trpgTileHeader.
You'll need to edit these if you want to add something to the Tile Table (at
the front of an archive) or the Tile Header (at the beginning of each tile).
*/
#include <trpage_geom.h>
#include <trpage_read.h>
/* Write Tile Table
Keeps track of tiles written to disk.
*/
Keeps track of tiles written to disk.
*/
// Constructor
trpgTileTable::trpgTileTable()
{
localBlock = false;
Reset();
localBlock = false;
Reset();
}
// Reset function
void trpgTileTable::Reset()
{
errMess[0] = '\0';
mode = External;
lodInfo.resize(0);
valid = true;
currentRow = -1;
currentCol = -1;
errMess[0] = '\0';
mode = External;
lodInfo.resize(0);
valid = true;
currentRow = -1;
currentCol = -1;
}
@@ -59,274 +59,274 @@ trpgTileTable::~trpgTileTable()
void trpgTileTable::SetMode(TileMode inMode)
{
Reset();
mode = inMode;
Reset();
mode = inMode;
}
void trpgTileTable::SetNumLod(int numLod)
{
lodInfo.resize(numLod);
lodInfo.resize(numLod);
}
void trpgTileTable::SetNumTiles(int nx,int ny,int lod)
{
if(localBlock) {
LodInfo &li = lodInfo[lod];
li.numX = nx; li.numY = ny;
li.addr.resize(1);
li.elev_min.resize(1,0.0);
li.elev_max.resize(1,0.0);
valid = true;
// no need to do anything else if we only have one block.
return;
}
if (nx <= 0 || ny <= 0 || lod < 0 || lod >= static_cast<int>(lodInfo.size()))
return;
if(localBlock) {
LodInfo &li = lodInfo[lod];
li.numX = nx; li.numY = ny;
li.addr.resize(1);
li.elev_min.resize(1,0.0);
li.elev_max.resize(1,0.0);
valid = true;
// no need to do anything else if we only have one block.
return;
}
if (nx <= 0 || ny <= 0 || lod < 0 || lod >= static_cast<int>(lodInfo.size()))
return;
// Got a table we need to maintain
if (mode == Local || mode == ExternalSaved) {
// If there's a pre-existing table, we need to preserve the entries
LodInfo oldLodInfo = lodInfo[lod];
// Got a table we need to maintain
if (mode == Local || mode == ExternalSaved) {
// If there's a pre-existing table, we need to preserve the entries
LodInfo oldLodInfo = lodInfo[lod];
LodInfo &li = lodInfo[lod];
li.numX = nx; li.numY = ny;
int numTile = li.numX*li.numY;
li.addr.resize(numTile);
li.elev_min.resize(numTile,0.0);
li.elev_max.resize(numTile,0.0);
LodInfo &li = lodInfo[lod];
li.numX = nx; li.numY = ny;
int numTile = li.numX*li.numY;
li.addr.resize(numTile);
li.elev_min.resize(numTile,0.0);
li.elev_max.resize(numTile,0.0);
// Copy pre-existing data if it's there
if (oldLodInfo.addr.size() > 0) {
for (int x=0;x<oldLodInfo.numX;x++) {
for (int y=0;y<oldLodInfo.numY;y++) {
int oldLoc = y*oldLodInfo.numX + x;
int newLoc = y*li.numX + x;
li.addr[newLoc] = oldLodInfo.addr[oldLoc];
li.elev_min[newLoc] = oldLodInfo.elev_min[oldLoc];
li.elev_max[newLoc] = oldLodInfo.elev_max[oldLoc];
}
}
}
}
valid = true;
// Copy pre-existing data if it's there
if (oldLodInfo.addr.size() > 0) {
for (int x=0;x<oldLodInfo.numX;x++) {
for (int y=0;y<oldLodInfo.numY;y++) {
int oldLoc = y*oldLodInfo.numX + x;
int newLoc = y*li.numX + x;
li.addr[newLoc] = oldLodInfo.addr[oldLoc];
li.elev_min[newLoc] = oldLodInfo.elev_min[oldLoc];
li.elev_max[newLoc] = oldLodInfo.elev_max[oldLoc];
}
}
}
}
valid = true;
}
void trpgTileTable::SetTile(int x,int y,int lod,trpgwAppAddress &ref,float32 zmin,float32 zmax)
{
if (lod < 0 || lod >= static_cast<int>(lodInfo.size()))
return;
if (mode == External)
return;
LodInfo &li = lodInfo[lod];
int loc;
if(localBlock) {
loc = 0;
}
else {
if (x < 0 || x >= li.numX || y < 0 || y >= li.numY)
return;
loc = y*li.numX + x;
}
li.addr[loc] = ref;
li.elev_min[loc] = zmin;
li.elev_max[loc] = zmax;
if (lod < 0 || lod >= static_cast<int>(lodInfo.size()))
return;
if (mode == External)
return;
LodInfo &li = lodInfo[lod];
int loc;
if(localBlock) {
loc = 0;
}
else {
if (x < 0 || x >= li.numX || y < 0 || y >= li.numY)
return;
loc = y*li.numX + x;
}
li.addr[loc] = ref;
li.elev_min[loc] = zmin;
li.elev_max[loc] = zmax;
}
bool trpgTileTable::isValid() const
{
return valid;
return valid;
}
// Get methods
bool trpgTileTable::GetMode(TileMode &outMode) const
{
if (!isValid()) return false;
if (!isValid()) return false;
outMode = mode;
return true;
outMode = mode;
return true;
}
bool trpgTileTable::GetTile(int x,int y,int lod,trpgwAppAddress &ref,float32 &zmin,float32 &zmax) const
{
if (!isValid()) return false;
if (!isValid()) return false;
if (lod < 0 || lod >= static_cast<int>(lodInfo.size())) return false;
if (mode == External)
return false;
if (lod < 0 || lod >= static_cast<int>(lodInfo.size())) return false;
if (mode == External)
return false;
const LodInfo &li = lodInfo[lod];
int loc;
if(localBlock) {
loc = 0;
}
else {
if (x < 0 || x >= li.numX || y < 0 || y >= li.numY)
return false;
loc = y*li.numX + x;
}
ref = li.addr[loc];
zmin = li.elev_min[loc];
zmax = li.elev_max[loc];
const LodInfo &li = lodInfo[lod];
int loc;
if(localBlock) {
loc = 0;
}
else {
if (x < 0 || x >= li.numX || y < 0 || y >= li.numY)
return false;
loc = y*li.numX + x;
}
ref = li.addr[loc];
zmin = li.elev_min[loc];
zmax = li.elev_max[loc];
return true;
return true;
}
// Write tile table
bool trpgTileTable::Write(trpgWriteBuffer &buf)
{
if (!isValid())
return false;
if (!isValid())
return false;
buf.Begin(TRPGTILETABLE2);
// Write the mode
buf.Add(mode);
buf.Begin(TRPGTILETABLE2);
// Write the mode
buf.Add(mode);
// Depending on the mode we'll have a lot or a little data
if (mode == Local || mode == ExternalSaved) {
// The lod sizing is redundant, but it's convenient here
int numLod = lodInfo.size();
buf.Add(numLod);
// Depending on the mode we'll have a lot or a little data
if (mode == Local || mode == ExternalSaved) {
// The lod sizing is redundant, but it's convenient here
int numLod = lodInfo.size();
buf.Add(numLod);
// Write each terrain LOD set
for (int i=0;i<numLod;i++) {
LodInfo &li = lodInfo[i];
if(localBlock) {
// only one x and one y in a local archive
buf.Add(1);
buf.Add(1);
// local blocks always use index 0
trpgwAppAddress &ref = li.addr[0];
buf.Add((int32)ref.file);
buf.Add((int32)ref.offset);
// Write each terrain LOD set
for (int i=0;i<numLod;i++) {
LodInfo &li = lodInfo[i];
if(localBlock) {
// only one x and one y in a local archive
buf.Add(1);
buf.Add(1);
// local blocks always use index 0
trpgwAppAddress &ref = li.addr[0];
buf.Add((int32)ref.file);
buf.Add((int32)ref.offset);
buf.Add(li.elev_min[0]);
buf.Add(li.elev_max[0]);
}
else {
buf.Add(li.numX);
buf.Add(li.numY);
// Now for the interesting stuff
unsigned int j;
for (j=0;j<li.addr.size();j++) {
trpgwAppAddress &ref = li.addr[j];
buf.Add((int32)ref.file);
buf.Add((int32)ref.offset);
}
for (j=0;j<li.elev_min.size();j++) {
buf.Add(li.elev_min[j]);
buf.Add(li.elev_max[j]);
}
}
}
}
buf.Add(li.elev_min[0]);
buf.Add(li.elev_max[0]);
}
else {
buf.Add(li.numX);
buf.Add(li.numY);
// Now for the interesting stuff
unsigned int j;
for (j=0;j<li.addr.size();j++) {
trpgwAppAddress &ref = li.addr[j];
buf.Add((int32)ref.file);
buf.Add((int32)ref.offset);
}
for (j=0;j<li.elev_min.size();j++) {
buf.Add(li.elev_min[j]);
buf.Add(li.elev_max[j]);
}
}
}
}
buf.End();
buf.End();
return true;
return true;
}
/* **************
Tile Table Read method
**************
*/
/* **************
Tile Table Read method
**************
*/
bool trpgTileTable::Read(trpgReadBuffer &buf)
{
valid = false;
valid = false;
try {
int imode;
buf.Get(imode); mode = (TileMode)imode;
if (mode != External && mode != Local && mode != ExternalSaved) throw 1;
if (mode == Local || mode == ExternalSaved) {
int numLod;
buf.Get(numLod);
if (numLod <= 0) throw 1;
lodInfo.resize(numLod);
try {
int imode;
buf.Get(imode); mode = (TileMode)imode;
if (mode != External && mode != Local && mode != ExternalSaved) throw 1;
if (mode == Local || mode == ExternalSaved) {
int numLod;
buf.Get(numLod);
if (numLod <= 0) throw 1;
lodInfo.resize(numLod);
for (int i=0;i<numLod;i++) {
for (int i=0;i<numLod;i++) {
LodInfo &li = lodInfo[i];
if(localBlock) {
if(li.addr.size()==0) {
li.addr.resize(1);
li.elev_min.resize(1,0.0);
li.elev_max.resize(1,0.0);
}
int32 x,y;
buf.Get(x);
buf.Get(y);
int pos = (currentRow * li.numX) + currentCol;
int32 file,offset;
buf.Get(file);
buf.Get(offset);
trpgwAppAddress &ref = li.addr[pos];
ref.file = file;
ref.offset = offset;
ref.col = currentCol;
ref.row = currentRow;
float emin,emax;
buf.Get(emin);
buf.Get(emax);
LodInfo &li = lodInfo[i];
if(localBlock) {
if(li.addr.size()==0) {
li.addr.resize(1);
li.elev_min.resize(1,0.0);
li.elev_max.resize(1,0.0);
}
int32 x,y;
buf.Get(x);
buf.Get(y);
int pos = (currentRow * li.numX) + currentCol;
int32 file,offset;
buf.Get(file);
buf.Get(offset);
trpgwAppAddress &ref = li.addr[pos];
ref.file = file;
ref.offset = offset;
ref.col = currentCol;
ref.row = currentRow;
float emin,emax;
buf.Get(emin);
buf.Get(emax);
li.elev_max[pos] = emax;
li.elev_min[pos] = emin;
}
else {
buf.Get(li.numX);
buf.Get(li.numY);
if (li.numX <= 0 || li.numY <= 0)
throw 1;
int numTile = li.numX*li.numY;
li.addr.resize(numTile);
li.elev_min.resize(numTile);
li.elev_max.resize(numTile);
int j;
for (j=0;j<numTile;j++) {
int32 file,offset;
buf.Get(file);
buf.Get(offset);
trpgwAppAddress &ref = li.addr[j];
ref.file = file;
ref.offset = offset;
}
for (j=0;j<numTile;j++) {
float emin,emax;
buf.Get(emin);
buf.Get(emax);
li.elev_max[j] = emax;
li.elev_min[j] = emin;
}
}
}
}
li.elev_max[pos] = emax;
li.elev_min[pos] = emin;
}
else {
buf.Get(li.numX);
buf.Get(li.numY);
if (li.numX <= 0 || li.numY <= 0)
throw 1;
int numTile = li.numX*li.numY;
li.addr.resize(numTile);
li.elev_min.resize(numTile);
li.elev_max.resize(numTile);
int j;
for (j=0;j<numTile;j++) {
int32 file,offset;
buf.Get(file);
buf.Get(offset);
trpgwAppAddress &ref = li.addr[j];
ref.file = file;
ref.offset = offset;
}
for (j=0;j<numTile;j++) {
float emin,emax;
buf.Get(emin);
buf.Get(emax);
li.elev_max[j] = emax;
li.elev_min[j] = emin;
}
}
}
}
valid = true;
}
catch (...) {
printf("Caught an exception\n");
return false;
}
valid = true;
}
catch (...) {
printf("Caught an exception\n");
return false;
}
return isValid();
return isValid();
}
/* Tile Header
Each distinct tile (or model) must have a header
which tells you what models and materials are
referenced in that tile.
*/
Each distinct tile (or model) must have a header
which tells you what models and materials are
referenced in that tile.
*/
// Constructor
trpgTileHeader::trpgTileHeader()
{
col = -1;
row = -1;
col = -1;
row = -1;
}
trpgTileHeader::~trpgTileHeader()
{
@@ -334,47 +334,47 @@ trpgTileHeader::~trpgTileHeader()
void trpgTileHeader::Reset()
{
matList.resize(0);
modelList.resize(0);
locMats.resize(0);
col = -1;
row = -1;
matList.resize(0);
modelList.resize(0);
locMats.resize(0);
col = -1;
row = -1;
}
// Set functions
void trpgTileHeader::SetMaterial(int no,int id)
{
if (no < 0 || no >= static_cast<int>(matList.size()))
return;
matList[no] = id;
if (no < 0 || no >= static_cast<int>(matList.size()))
return;
matList[no] = id;
}
void trpgTileHeader::SetModel(int no,int id)
{
if (no < 0 || no >= static_cast<int>(modelList.size()))
return;
modelList[no] = id;
if (no < 0 || no >= static_cast<int>(modelList.size()))
return;
modelList[no] = id;
}
// Set functions
void trpgTileHeader::AddMaterial(int id)
{
// Look for it first
// Look for it first
for (unsigned int i=0;i<matList.size();i++)
if (matList[i] == id)
return;
// Didn't find it, add it.
matList.push_back(id);
if (matList[i] == id)
return;
// Didn't find it, add it.
matList.push_back(id);
}
void trpgTileHeader::AddModel(int id)
{
for (unsigned int i=0;i<modelList.size();i++)
if (modelList[i] == id)
return;
modelList.push_back(id);
if (modelList[i] == id)
return;
modelList.push_back(id);
}
void trpgTileHeader::SetDate(int32 d)
{
date = d;
date = d;
}
// Local material methods
@@ -395,7 +395,7 @@ bool trpgTileHeader::GetNumLocalMaterial(int32 &retNum) const
bool trpgTileHeader::GetLocalMaterial(int32 id,trpgLocalMaterial &retMat) const
{
if (id < 0 || id >= static_cast<int>(locMats.size()))
return false;
return false;
retMat = locMats[id];
@@ -412,78 +412,78 @@ const std::vector<trpgLocalMaterial> *trpgTileHeader::GetLocalMaterialList() con
// Get methods
bool trpgTileHeader::GetNumMaterial(int32 &no) const
{
if (!isValid()) return false;
no = matList.size();
return true;
if (!isValid()) return false;
no = matList.size();
return true;
}
bool trpgTileHeader::GetMaterial(int32 id,int32 &mat) const
{
if (!isValid() || id < 0 || id >= static_cast<int>(matList.size()))
return false;
mat = matList[id];
return true;
if (!isValid() || id < 0 || id >= static_cast<int>(matList.size()))
return false;
mat = matList[id];
return true;
}
bool trpgTileHeader::GetNumModel(int32 &no) const
{
if (!isValid()) return false;
no = modelList.size();
return true;
if (!isValid()) return false;
no = modelList.size();
return true;
}
bool trpgTileHeader::GetModel(int32 id,int32 &m) const
{
if (!isValid() || id < 0 || id >= static_cast<int>(modelList.size()))
return false;
m = modelList[id];
return true;
if (!isValid() || id < 0 || id >= static_cast<int>(modelList.size()))
return false;
m = modelList[id];
return true;
}
bool trpgTileHeader::GetDate(int32 &d) const
{
if (!isValid()) return false;
d = date;
return true;
if (!isValid()) return false;
d = date;
return true;
}
// Validity check
bool trpgTileHeader::isValid() const
{
return true;
return true;
}
// Write to a buffer
bool trpgTileHeader::Write(trpgWriteBuffer &buf)
{
unsigned int i;
unsigned int i;
if (!isValid())
return false;
for (i=0;i<locMats.size();i++)
if (!locMats[i].isValid())
return false;
if (!isValid())
return false;
for (i=0;i<locMats.size();i++)
if (!locMats[i].isValid())
return false;
buf.Begin(TRPGTILEHEADER);
buf.Begin(TRPGTILEHEADER);
buf.Begin(TRPG_TILE_MATLIST);
buf.Add((int32)matList.size());
for (i=0;i<matList.size();i++)
buf.Add(matList[i]);
buf.End();
buf.Begin(TRPG_TILE_MODELLIST);
buf.Add((int32)modelList.size());
for (i=0;i<modelList.size();i++)
buf.Add(modelList[i]);
buf.End();
buf.Begin(TRPG_TILE_DATE);
buf.Add(date);
buf.End();
buf.Begin(TRPG_TILE_LOCMATLIST);
buf.Add((int32)locMats.size());
for (i=0;i<locMats.size();i++)
locMats[i].Write(buf);
buf.End();
buf.Begin(TRPG_TILE_MATLIST);
buf.Add((int32)matList.size());
for (i=0;i<matList.size();i++)
buf.Add(matList[i]);
buf.End();
buf.Begin(TRPG_TILE_MODELLIST);
buf.Add((int32)modelList.size());
for (i=0;i<modelList.size();i++)
buf.Add(modelList[i]);
buf.End();
buf.Begin(TRPG_TILE_DATE);
buf.Add(date);
buf.End();
buf.Begin(TRPG_TILE_LOCMATLIST);
buf.Add((int32)locMats.size());
for (i=0;i<locMats.size();i++)
locMats[i].Write(buf);
buf.End();
buf.End();
buf.End();
return true;
return true;
}
// Tile Header CB
@@ -491,87 +491,87 @@ bool trpgTileHeader::Write(trpgWriteBuffer &buf)
// We want the tile header to be expandable, so be careful here
class tileHeaderCB : public trpgr_Callback {
public:
void * Parse(trpgToken,trpgReadBuffer &);
trpgTileHeader *head;
void * Parse(trpgToken,trpgReadBuffer &);
trpgTileHeader *head;
};
void * tileHeaderCB::Parse(trpgToken tok,trpgReadBuffer &buf)
{
int32 no,id,date,i;
int32 no,id,date,i;
try {
switch (tok) {
case TRPG_TILE_MATLIST:
buf.Get(no);
if (no < 0) throw 1;
for (i = 0;i < no; i++) {
buf.Get(id);
head->AddMaterial(id);
}
break;
case TRPG_TILE_MODELLIST:
buf.Get(no);
if (no < 0) throw 1;
for (i=0;i<no;i++) {
buf.Get(id);
head->AddModel(id);
}
break;
case TRPG_TILE_DATE:
buf.Get(date);
head->SetDate(date);
break;
case TRPG_TILE_LOCMATLIST:
{
int32 numLocMat;
buf.Get(numLocMat);
if (numLocMat < 0) throw 1;
std::vector<trpgLocalMaterial> *locMats;
locMats = const_cast<std::vector<trpgLocalMaterial> *> (head->GetLocalMaterialList());
locMats->resize(numLocMat);
for (i=0;i<numLocMat;i++) {
trpgToken matTok;
int32 len;
buf.GetToken(matTok,len);
if (matTok != TRPGLOCALMATERIAL) throw 1;
buf.PushLimit(len);
trpgLocalMaterial &locMat = (*locMats)[i];
locMat.Read(buf);
// Set the row/col for later finding
trpgwAppAddress addr;
locMat.GetAddr(addr);
head->GetBlockNo(addr.row,addr.col);
locMat.SetAddr(addr);
try {
switch (tok) {
case TRPG_TILE_MATLIST:
buf.Get(no);
if (no < 0) throw 1;
for (i = 0;i < no; i++) {
buf.Get(id);
head->AddMaterial(id);
}
break;
case TRPG_TILE_MODELLIST:
buf.Get(no);
if (no < 0) throw 1;
for (i=0;i<no;i++) {
buf.Get(id);
head->AddModel(id);
}
break;
case TRPG_TILE_DATE:
buf.Get(date);
head->SetDate(date);
break;
case TRPG_TILE_LOCMATLIST:
{
int32 numLocMat;
buf.Get(numLocMat);
if (numLocMat < 0) throw 1;
std::vector<trpgLocalMaterial> *locMats;
locMats = const_cast<std::vector<trpgLocalMaterial> *> (head->GetLocalMaterialList());
locMats->resize(numLocMat);
for (i=0;i<numLocMat;i++) {
trpgToken matTok;
int32 len;
buf.GetToken(matTok,len);
if (matTok != TRPGLOCALMATERIAL) throw 1;
buf.PushLimit(len);
trpgLocalMaterial &locMat = (*locMats)[i];
locMat.Read(buf);
// Set the row/col for later finding
trpgwAppAddress addr;
locMat.GetAddr(addr);
head->GetBlockNo(addr.row,addr.col);
locMat.SetAddr(addr);
buf.PopLimit();
}
}
break;
default:
// Don't care
break;
}
}
catch (...) {
return NULL;
}
buf.PopLimit();
}
}
break;
default:
// Don't care
break;
}
}
catch (...) {
return NULL;
}
return head;
return head;
}
// Read tile header
bool trpgTileHeader::Read(trpgReadBuffer &buf)
{
tileHeaderCB tcb;
trpgr_Parser parse;
tileHeaderCB tcb;
trpgr_Parser parse;
tcb.head = this;
parse.AddCallback(TRPG_TILE_MATLIST,&tcb,false);
parse.AddCallback(TRPG_TILE_MODELLIST,&tcb,false);
parse.AddCallback(TRPG_TILE_DATE,&tcb,false);
// New for 2.0
parse.AddCallback(TRPG_TILE_LOCMATLIST,&tcb,false);
parse.Parse(buf);
tcb.head = this;
parse.AddCallback(TRPG_TILE_MATLIST,&tcb,false);
parse.AddCallback(TRPG_TILE_MODELLIST,&tcb,false);
parse.AddCallback(TRPG_TILE_DATE,&tcb,false);
// New for 2.0
parse.AddCallback(TRPG_TILE_LOCMATLIST,&tcb,false);
parse.Parse(buf);
return isValid();
return isValid();
}

View File

@@ -16,8 +16,8 @@
#include <trpage_util.h>
/* trpage_util.cpp
This source file implements various utility routines for paging archive
*/
This source file implements various utility routines for paging archive
*/
/* The merge routine used to be in here.
However, merge isn't actually general enough to be part of the library.

View File

@@ -14,8 +14,8 @@
*/
/* trpage_sys.h
System specific declarations.
*/
System specific declarations.
*/
#ifndef trpage_util_h_
#define trpage_util_h_
@@ -26,7 +26,7 @@
TX_EXDECL class TX_CLDECL trpgUtil {
public:
enum {DoReport = 1<<0,DoCopy = 1<<1, DoTileOpt = 1<<2};
int merge(trpgr_Archive &inArch1,trpgr_Archive &inArch2,trpgwArchive &outArch, int flags = 0);
enum {DoReport = 1<<0,DoCopy = 1<<1, DoTileOpt = 1<<2};
int merge(trpgr_Archive &inArch1,trpgr_Archive &inArch2,trpgwArchive &outArch, int flags = 0);
};
#endif

View File

@@ -18,8 +18,8 @@
#define _txpage_write_h_
/* trpage_write.h
Classes that are used to write paging archives.
*/
Classes that are used to write paging archives.
*/
#include <trpage_sys.h>
#include <trpage_io.h>
@@ -27,333 +27,333 @@
#include <trpage_read.h>
/* Geometry Stats
Used with a Geometry Helper to keep track of what go built.
{group:Archive Writing}
*/
Used with a Geometry Helper to keep track of what go built.
{group:Archive Writing}
*/
TX_EXDECL class TX_CLDECL trpgwGeomStats {
public:
trpgwGeomStats(void);
~trpgwGeomStats(void);
trpgwGeomStats(void);
~trpgwGeomStats(void);
int totalTri; // Total # of triangles
int totalTri; // Total # of triangles
int totalQuad; // Total # of quads
int totalQuad; // Total # of quads
// Add up to totalTri
int totalStripTri; // triangles in strips
int totalFanTri; // triangles in fans
int totalBagTri; // loose triangles
// Add up to totalTri
int totalStripTri; // triangles in strips
int totalFanTri; // triangles in fans
int totalBagTri; // loose triangles
int numStrip; // Number of distinct strips
int numFan; // Number of distinct fans
int numStrip; // Number of distinct strips
int numFan; // Number of distinct fans
int stripStat[15]; // Strip length stats
int fanStat[15]; // Fan length stats
int stripStat[15]; // Strip length stats
int fanStat[15]; // Fan length stats
int stripGeom; // Number of seperate trpgGeometry nodes for strips
int fanGeom; // Same for fans
int bagGeom; // Same for bags
int stripGeom; // Number of seperate trpgGeometry nodes for strips
int fanGeom; // Same for fans
int bagGeom; // Same for bags
int stateChanges; // Number of distinct material switches
int stateChanges; // Number of distinct material switches
// Helper functions
inline void AddStripStat(int val) { stripStat[MIN(14,val)]++; totalStripTri += val; totalTri += val; numStrip++;}
inline void AddFanStat(int val) { fanStat[MIN(14,val)]++; totalFanTri += val; totalTri += val; numFan++;}
inline void AddBagStat(int val) { totalBagTri += val; totalTri += val;}
// Helper functions
inline void AddStripStat(int val) { stripStat[MIN(14,val)]++; totalStripTri += val; totalTri += val; numStrip++;}
inline void AddFanStat(int val) { fanStat[MIN(14,val)]++; totalFanTri += val; totalTri += val; numFan++;}
inline void AddBagStat(int val) { totalBagTri += val; totalTri += val;}
inline void AddQuadStat(int val) { totalQuad += val; }
};
/* Geometry Helper
Collects up geometry and tries to form triangle strips, fans,
and groups of triangles.
Right now this looks for a very careful ordering. If that ordering
isn't there you won't get useful tristrips or fans. You can, however
use this class as a starting point and build something more akin
to the geometry builder in Performer.
{group:Archive Writing}
Collects up geometry and tries to form triangle strips, fans,
and groups of triangles.
Right now this looks for a very careful ordering. If that ordering
isn't there you won't get useful tristrips or fans. You can, however
use this class as a starting point and build something more akin
to the geometry builder in Performer.
{group:Archive Writing}
*/
TX_EXDECL class TX_CLDECL trpgwGeomHelper {
public:
trpgwGeomHelper(void);
virtual ~trpgwGeomHelper(void);
enum {UseDouble,UseFloat};
trpgwGeomHelper(trpgWriteBuffer *,int dataType=UseDouble);
void init(trpgWriteBuffer *,int dataType=UseDouble);
virtual void SetMode(int); // Takes a trpgGeometry primitive type (triangle by default)
virtual void Reset(void);
// Start/End polygon definition
virtual void StartPolygon(void);
virtual void EndPolygon(void);
virtual void ResetPolygon(void); // If you change your mind about the current poly
// Set the current state
// Note: Currently you *must* set all of these
virtual void SetColor(trpgColor &);
virtual void SetTexCoord(trpg2dPoint &);
virtual void AddTexCoord(trpg2dPoint &); // for multiple textures
virtual void SetNormal(trpg3dPoint &);
virtual void SetMaterial(int32);
virtual void AddMaterial(int32); // for multiple textures
// Pull the state info together and add a vertex
virtual void AddVertex(trpg3dPoint &);
trpgwGeomHelper(void);
virtual ~trpgwGeomHelper(void);
enum {UseDouble,UseFloat};
trpgwGeomHelper(trpgWriteBuffer *,int dataType=UseDouble);
void init(trpgWriteBuffer *,int dataType=UseDouble);
virtual void SetMode(int); // Takes a trpgGeometry primitive type (triangle by default)
virtual void Reset(void);
// Start/End polygon definition
virtual void StartPolygon(void);
virtual void EndPolygon(void);
virtual void ResetPolygon(void); // If you change your mind about the current poly
// Set the current state
// Note: Currently you *must* set all of these
virtual void SetColor(trpgColor &);
virtual void SetTexCoord(trpg2dPoint &);
virtual void AddTexCoord(trpg2dPoint &); // for multiple textures
virtual void SetNormal(trpg3dPoint &);
virtual void SetMaterial(int32);
virtual void AddMaterial(int32); // for multiple textures
// Pull the state info together and add a vertex
virtual void AddVertex(trpg3dPoint &);
// Dump whatever we're doing and move on
virtual void FlushGeom(void);
// Dump whatever we're doing and move on
virtual void FlushGeom(void);
// Get the Min and Max Z values
virtual void GetZMinMax(double &min,double &max);
// Get the Min and Max Z values
virtual void GetZMinMax(double &min,double &max);
// Get statistics for whatever we built
trpgwGeomStats *GetStats(void) { return &stats; }
// Get statistics for whatever we built
trpgwGeomStats *GetStats(void) { return &stats; }
protected:
int mode;
int dataType;
trpgWriteBuffer *buf;
int mode;
int dataType;
trpgWriteBuffer *buf;
/* Builds strips and fans from the triangle array.
We (TERREX) are assuming a certain ordering in our vertex array
because we do this optimization elsewhere. This won't work well
for anyone else. What you will need to do if you want good
performance is to implement a more generic form of this method.
All you should have to do is override Optimize(). You've
got the triangle arrays and a guarantee that the triangles
have the same material. All you really need is a decent fan/strip
algorithm.
*/
virtual void Optimize(void);
/* Builds strips and fans from the triangle array.
We (TERREX) are assuming a certain ordering in our vertex array
because we do this optimization elsewhere. This won't work well
for anyone else. What you will need to do if you want good
performance is to implement a more generic form of this method.
All you should have to do is override Optimize(). You've
got the triangle arrays and a guarantee that the triangles
have the same material. All you really need is a decent fan/strip
algorithm.
*/
virtual void Optimize(void);
// Reset Triangle arrays
virtual void ResetTri(void);
// Reset Triangle arrays
virtual void ResetTri(void);
// Collections of geometry
trpgGeometry strips,fans,bags;
// Collections of geometry
trpgGeometry strips,fans,bags;
// Temporary data arrays for triangles/quads
std::vector<int32> matTri;
std::vector<trpg2dPoint> tex;
std::vector<trpg3dPoint> norm,vert;
// Data arrays for a polygon
std::vector<int32> matPoly;
std::vector<trpg2dPoint> polyTex;
std::vector<trpg3dPoint> polyNorm,polyVert;
// Single points
std::vector<trpg2dPoint> tmpTex;
trpg3dPoint tmpNorm;
trpgColor tmpCol;
// Temporary data arrays for triangles/quads
std::vector<int32> matTri;
std::vector<trpg2dPoint> tex;
std::vector<trpg3dPoint> norm,vert;
// Data arrays for a polygon
std::vector<int32> matPoly;
std::vector<trpg2dPoint> polyTex;
std::vector<trpg3dPoint> polyNorm,polyVert;
// Single points
std::vector<trpg2dPoint> tmpTex;
trpg3dPoint tmpNorm;
trpgColor tmpCol;
// Geometry status built up as we go
trpgwGeomStats stats;
// Geometry status built up as we go
trpgwGeomStats stats;
// Keeps track of min and max z values
double zmin,zmax;
// Keeps track of min and max z values
double zmin,zmax;
};
/* Image Write Helper.
Used to manage textures being added to a TerraPage archive.
It can write Local and Tile Local textures and also manages
the names of External textures (but you have to write those yourself).
Used to manage textures being added to a TerraPage archive.
It can write Local and Tile Local textures and also manages
the names of External textures (but you have to write those yourself).
*/
TX_EXDECL class TX_CLDECL trpgwImageHelper {
public:
trpgwImageHelper() {;};
trpgwImageHelper(trpgEndian ness,char *dir,trpgTexTable &,bool separateGeoTypical);
// construction is really here
virtual void Init(trpgEndian ness,char *dir,trpgTexTable &,bool separateGeoTypical);
trpgwImageHelper() {;};
trpgwImageHelper(trpgEndian ness,char *dir,trpgTexTable &,bool separateGeoTypical);
// construction is really here
virtual void Init(trpgEndian ness,char *dir,trpgTexTable &,bool separateGeoTypical);
virtual ~trpgwImageHelper(void);
virtual ~trpgwImageHelper(void);
// Adds an entry to the texture table for an external texture
virtual bool AddExternal(char *name,int &texID,bool lookForExisting=true);
// Adds an entry to the texture table for an external texture
virtual bool AddExternal(char *name,int &texID,bool lookForExisting=true);
/* Adds an entry to the texture table for a local texture and
writes the data for that texture out to one of our texture
archive files.
*/
virtual bool AddLocal(char *name,trpgTexture::ImageType type,int sizeX,int sizeY,bool isMipmap,char *data,int &texID,bool deferWrite);
/* Adds an entry to the texture table for a local texture and
writes the data for that texture out to one of our texture
archive files.
*/
virtual bool AddLocal(char *name,trpgTexture::ImageType type,int sizeX,int sizeY,bool isMipmap,char *data,int &texID,bool deferWrite);
/* Replaces texture table information for a local texture and
writes the data for that texture out to one of our texture
archive files.
Up to you to ensure data is appropriate for the texture.
*/
virtual bool ReplaceLocal(char *data,int &texID);
/* Replaces texture table information for a local texture and
writes the data for that texture out to one of our texture
archive files.
Up to you to ensure data is appropriate for the texture.
*/
virtual bool ReplaceLocal(char *data,int &texID);
/* Write a Tile Local texture out to one of our texture archive files.
Also creates a texture template, if necessary.
Caller is responsible for creating the Tile Local material and
placing it in the appropriate tile.
*/
virtual bool AddTileLocal(char *name,trpgTexture::ImageType type,int sizeX,int sizeY,bool isMipmap,char *data, int &texID,trpgwAppAddress &addr);
/* Write a Tile Local texture out to one of our texture archive files.
Also creates a texture template, if necessary.
Caller is responsible for creating the Tile Local material and
placing it in the appropriate tile.
*/
virtual bool AddTileLocal(char *name,trpgTexture::ImageType type,int sizeX,int sizeY,bool isMipmap,char *data, int &texID,trpgwAppAddress &addr);
/* Sets the maximum advised length for a texture archive file.
Once the length is exceeded, the image write helper will move
on to the next tex file.
*/
virtual void SetMaxTexFileLength(int len);
/* Sets the maximum advised length for a texture archive file.
Once the length is exceeded, the image write helper will move
on to the next tex file.
*/
virtual void SetMaxTexFileLength(int len);
/* Texture archive files are managed by this class and will
be created as needed. This method will increment to
the next texture file.
Note: This may create more files than we really need.
*/
virtual trpgwAppFile * IncrementTextureFile(bool geotyp);
/* Texture archive files are managed by this class and will
be created as needed. This method will increment to
the next texture file.
Note: This may create more files than we really need.
*/
virtual trpgwAppFile * IncrementTextureFile(bool geotyp);
/* Close the current texture file and go on to one with the
given base name. This is used for regenerate.
*/
virtual bool DesignateTextureFile(int);
/* Close the current texture file and go on to one with the
given base name. This is used for regenerate.
*/
virtual bool DesignateTextureFile(int);
// Flush current texture output files
virtual bool Flush(void);
// Flush current texture output files
virtual bool Flush(void);
// Get a new appendable file
virtual trpgwAppFile* GetNewWAppFile(trpgEndian inNess,const char *fileName,bool reuse=false);
// Write the given texture data into one our local archives
bool WriteToArchive(const trpgTexture &tex,char *data,trpgwAppAddress &addr,bool geotyp=false);
// Merge block textable into a master.
// Get a new appendable file
virtual trpgwAppFile* GetNewWAppFile(trpgEndian inNess,const char *fileName,bool reuse=false);
// Write the given texture data into one our local archives
bool WriteToArchive(const trpgTexture &tex,char *data,trpgwAppAddress &addr,bool geotyp=false);
// Merge block textable into a master.
protected:
trpgEndian ness;
char dir[1024];
trpgTexTable *texTable;
std::vector<int> texFileIDs;
trpgwAppFile *texFile;
std::vector<int> geotypFileIDs;
trpgwAppFile *geotypFile;
bool separateGeoTypical;
int maxTexFileLen;
trpgEndian ness;
char dir[1024];
trpgTexTable *texTable;
std::vector<int> texFileIDs;
trpgwAppFile *texFile;
std::vector<int> geotypFileIDs;
trpgwAppFile *geotypFile;
bool separateGeoTypical;
int maxTexFileLen;
};
/* Paging Archive
This is a writeable paging archive.
It organizes where things get written and how.
{group:Archive Writing}
*/
This is a writeable paging archive.
It organizes where things get written and how.
{group:Archive Writing}
*/
TX_EXDECL class TX_CLDECL trpgwArchive : public trpgCheckable {
public:
// Tiles can be stored as individual files (External) or grouped together (Local)
enum TileMode {TileLocal,TileExternal,TileExternalSaved};
// Tiles can be stored as individual files (External) or grouped together (Local)
enum TileMode {TileLocal,TileExternal,TileExternalSaved};
// real constructor work done in Init(...) now for quasi-virtual ctor action.
// Add data to an existing archive
trpgwArchive(char *baseDir,char *name,trpg2dPoint &ll,trpg2dPoint &ur, int majorVer=TRPG_VERSION_MAJOR, int minorVer=TRPG_VERSION_MINOR);
virtual void Init(char *baseDir,char *name,trpg2dPoint &ll,trpg2dPoint &ur, int majorVer=TRPG_VERSION_MAJOR, int minorVer=TRPG_VERSION_MINOR);
// Start an archive from scratch.
trpgwArchive(trpgEndian ness=LittleEndian,TileMode tileMode=TileLocal,int majorVer=TRPG_VERSION_MAJOR, int minorVer=TRPG_VERSION_MINOR);
virtual void Init(trpgEndian ness=LittleEndian,TileMode tileMode=TileLocal,int majorVer=TRPG_VERSION_MAJOR, int minorVer=TRPG_VERSION_MINOR);
// dummy constructor, does nothing so subclasses can have more control
trpgwArchive(int ) {;};
virtual ~trpgwArchive(void);
// real constructor work done in Init(...) now for quasi-virtual ctor action.
// Add data to an existing archive
trpgwArchive(char *baseDir,char *name,trpg2dPoint &ll,trpg2dPoint &ur, int majorVer=TRPG_VERSION_MAJOR, int minorVer=TRPG_VERSION_MINOR);
virtual void Init(char *baseDir,char *name,trpg2dPoint &ll,trpg2dPoint &ur, int majorVer=TRPG_VERSION_MAJOR, int minorVer=TRPG_VERSION_MINOR);
// Start an archive from scratch.
trpgwArchive(trpgEndian ness=LittleEndian,TileMode tileMode=TileLocal,int majorVer=TRPG_VERSION_MAJOR, int minorVer=TRPG_VERSION_MINOR);
virtual void Init(trpgEndian ness=LittleEndian,TileMode tileMode=TileLocal,int majorVer=TRPG_VERSION_MAJOR, int minorVer=TRPG_VERSION_MINOR);
// dummy constructor, does nothing so subclasses can have more control
trpgwArchive(int ) {;};
virtual ~trpgwArchive(void);
// Set the maximum length for a tile file (if using them)
// This is only a suggestion for when to stop appending
virtual void SetMaxTileFileLength(int len);
// Set the maximum length for a tile file (if using them)
// This is only a suggestion for when to stop appending
virtual void SetMaxTileFileLength(int len);
// Set functions. Have to fill all these out before writing
virtual bool SetHeader(const trpgHeader &);
virtual bool SetMaterialTable(const trpgMatTable &);
virtual bool SetTextureTable(const trpgTexTable &);
virtual bool SetModelTable(const trpgModelTable &);
virtual bool SetLightTable(const trpgLightTable &);
virtual bool SetRangeTable(const trpgRangeTable &);
virtual bool SetLabelPropertyTable(const trpgLabelPropertyTable &);
virtual bool SetSupportStyleTable(const trpgSupportStyleTable &);
virtual bool SetTextStyleTable(const trpgTextStyleTable &);
// Set functions. Have to fill all these out before writing
virtual bool SetHeader(const trpgHeader &);
virtual bool SetMaterialTable(const trpgMatTable &);
virtual bool SetTextureTable(const trpgTexTable &);
virtual bool SetModelTable(const trpgModelTable &);
virtual bool SetLightTable(const trpgLightTable &);
virtual bool SetRangeTable(const trpgRangeTable &);
virtual bool SetLabelPropertyTable(const trpgLabelPropertyTable &);
virtual bool SetSupportStyleTable(const trpgSupportStyleTable &);
virtual bool SetTextStyleTable(const trpgTextStyleTable &);
// Get functions. If we're doing a regenerate we need to get at these
virtual trpgHeader *GetHeader();
virtual trpgMatTable *GetMatTable();
virtual trpgTexTable *GetTextureTable();
virtual trpgModelTable *GetModelTable();
virtual trpgLightTable *GetLightTable();
virtual trpgRangeTable *GetRangeTable();
virtual trpgLabelPropertyTable *GetLabelPropertyTable();
virtual trpgTextStyleTable *GetTextStyleTable();
virtual trpgSupportStyleTable *GetSupportStyleTable();
// Get functions. If we're doing a regenerate we need to get at these
virtual trpgHeader *GetHeader();
virtual trpgMatTable *GetMatTable();
virtual trpgTexTable *GetTextureTable();
virtual trpgModelTable *GetModelTable();
virtual trpgLightTable *GetLightTable();
virtual trpgRangeTable *GetRangeTable();
virtual trpgLabelPropertyTable *GetLabelPropertyTable();
virtual trpgTextStyleTable *GetTextStyleTable();
virtual trpgSupportStyleTable *GetSupportStyleTable();
virtual bool IncrementTileFile(void);
virtual bool DesignateTileFile(int);
virtual bool IncrementTileFile(void);
virtual bool DesignateTileFile(int);
// Write functions.
// For now, the header is written last.
// Write functions.
// For now, the header is written last.
virtual bool OpenFile(const char *,const char *);
virtual void CloseFile(void);
virtual bool WriteHeader(void);
virtual bool CheckpointHeader(void);
virtual bool WriteTile(unsigned int,unsigned int,unsigned int,float zmin,float zmax,
const trpgMemWriteBuffer *,const trpgMemWriteBuffer *, int32& fileId, int32& fileOffset);
// virtual bool WriteModel(unsigned int,trpgMemWriteBuffer &);
virtual bool OpenFile(const char *,const char *);
virtual void CloseFile(void);
virtual bool WriteHeader(void);
virtual bool CheckpointHeader(void);
virtual bool WriteTile(unsigned int,unsigned int,unsigned int,float zmin,float zmax,
const trpgMemWriteBuffer *,const trpgMemWriteBuffer *, int32& fileId, int32& fileOffset);
// virtual bool WriteModel(unsigned int,trpgMemWriteBuffer &);
bool isValid(void) const;
const char *getErrMess() const;
char* getDir(void){return dir;};
virtual trpgwImageHelper* GetNewWImageHelper(trpgEndian ness,char *dir,trpgTexTable &);
virtual trpgwAppFile* GetNewWAppFile(trpgEndian inNess,const char *fileName,bool reuse=false);
virtual trpgr_Archive* GetArchiveReader() {return new trpgr_Archive();};
virtual int32 WriteHeaderData(const char *dataPtr,int32 length,FILE *filehandle);
virtual int32 GetMagicNumber() {return TRPG_MAGIC;};
bool isValid(void) const;
const char *getErrMess() const;
char* getDir(void){return dir;};
virtual trpgwImageHelper* GetNewWImageHelper(trpgEndian ness,char *dir,trpgTexTable &);
virtual trpgwAppFile* GetNewWAppFile(trpgEndian inNess,const char *fileName,bool reuse=false);
virtual trpgr_Archive* GetArchiveReader() {return new trpgr_Archive();};
virtual int32 WriteHeaderData(const char *dataPtr,int32 length,FILE *filehandle);
virtual int32 GetMagicNumber() {return TRPG_MAGIC;};
protected:
// Set if we're adding to an existing archive
bool isRegenerate;
// Set if we're adding to an existing archive
bool isRegenerate;
// Used to keep track of which tiles are in which file
class TileFileEntry {
public:
int x,y,lod; // Identifying info for tile
float zmin,zmax;
int32 offset; // Offset into file
};
class TileFile {
public:
int id;
std::vector<TileFileEntry> tiles;
};
// Used to keep track of which tiles are in which file
class TileFileEntry {
public:
int x,y,lod; // Identifying info for tile
float zmin,zmax;
int32 offset; // Offset into file
};
class TileFile {
public:
int id;
std::vector<TileFileEntry> tiles;
};
trpgEndian ness,cpuNess;
int majorVersion, minorVersion;
// Fed in from the outside
char dir[1024]; // Directory where we're doing all this
trpgEndian ness,cpuNess;
int majorVersion, minorVersion;
// Fed in from the outside
char dir[1024]; // Directory where we're doing all this
// These are passed in
// These are passed in
trpgHeader header;
trpgMatTable matTable;
trpgTexTable texTable;
trpgModelTable modelTable;
trpgLightTable lightTable;
trpgRangeTable rangeTable;
trpgTextStyleTable textStyleTable;
trpgSupportStyleTable supportStyleTable;
trpgLabelPropertyTable labelPropertyTable;
trpgHeader header;
trpgMatTable matTable;
trpgTexTable texTable;
trpgModelTable modelTable;
trpgLightTable lightTable;
trpgRangeTable rangeTable;
trpgTextStyleTable textStyleTable;
trpgSupportStyleTable supportStyleTable;
trpgLabelPropertyTable labelPropertyTable;
trpgTileTable tileTable;
trpgTileTable tileTable;
int numLod;
TileMode tileMode;
int numLod;
TileMode tileMode;
trpgwAppFile *tileFile;
int tileFileCount;
trpgwAppFile *tileFile;
int tileFileCount;
std::vector<TileFile> tileFiles;
std::vector<TileFile> tileFiles;
std::vector<TileFileEntry> externalTiles;
int maxTileFileLen;
int maxTileFileLen;
// This offset is used when we're adding to an existing archive
trpg2iPoint addOffset;
// This offset is used when we're adding to an existing archive
trpg2iPoint addOffset;
FILE *fp;
FILE *fp;
bool firstHeaderWrite;
bool firstHeaderWrite;
mutable char errMess[512];
mutable char errMess[512];
};
#endif