diff --git a/src/osgPlugins/txp/TileMapper.cpp b/src/osgPlugins/txp/TileMapper.cpp index c2569266e..1dbd97e13 100644 --- a/src/osgPlugins/txp/TileMapper.cpp +++ b/src/osgPlugins/txp/TileMapper.cpp @@ -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" diff --git a/src/osgPlugins/txp/TileMapper.h b/src/osgPlugins/txp/TileMapper.h index 6d284e040..5de39eba0 100644 --- a/src/osgPlugins/txp/TileMapper.h +++ b/src/osgPlugins/txp/TileMapper.h @@ -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) { diff --git a/src/osgPlugins/txp/trdll.h b/src/osgPlugins/txp/trdll.h index 7e0a00054..63ab42c3f 100644 --- a/src/osgPlugins/txp/trdll.h +++ b/src/osgPlugins/txp/trdll.h @@ -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 diff --git a/src/osgPlugins/txp/trpage_basic.cpp b/src/osgPlugins/txp/trpage_basic.cpp index 552eb628e..0ad0565e8 100644 --- a/src/osgPlugins/txp/trpage_basic.cpp +++ b/src/osgPlugins/txp/trpage_basic.cpp @@ -14,8 +14,8 @@ */ /* trpage_basic.cpp - Methods for checkable base class. - */ + Methods for checkable base class. + */ #include #include @@ -23,22 +23,22 @@ #include /* 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; } diff --git a/src/osgPlugins/txp/trpage_compat.cpp b/src/osgPlugins/txp/trpage_compat.cpp index b4fbd943b..8110a1793 100644 --- a/src/osgPlugins/txp/trpage_compat.cpp +++ b/src/osgPlugins/txp/trpage_compat.cpp @@ -56,65 +56,65 @@ bool trpgMatTable1_0::Read(trpgReadBuffer &buf) std::vector 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 shortMats; @@ -134,21 +134,21 @@ bool trpgMatTable1_0::Write(trpgWriteBuffer &buf) MaterialMapType::iterator itr = materialMap.begin(); for ( ; itr != materialMap.end( ); itr++) { - //for (i=0;isecond; //matTables[i]; - // Fill in the short material - trpgShortMaterial &sMat = shortMats[i]; - sMat.baseMat = 0; - int numTex; - mat.GetNumTexture(numTex); - for (int j=0;jsecond; //matTables[i]; + // Fill in the short material + trpgShortMaterial &sMat = shortMats[i]; + sMat.baseMat = 0; + int numTex; + mat.GetNumTexture(numTex); + for (int j=0;j(shortMats.size());i++) { - trpgShortMaterial &sMat = shortMats[i]; - buf.Add(sMat.baseMat); - buf.Add((int)(sMat.texids.size())); - unsigned int j; - for (j=0;jsecond; //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;isecond; - 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; diff --git a/src/osgPlugins/txp/trpage_compat.h b/src/osgPlugins/txp/trpage_compat.h index d15767146..b128deace 100644 --- a/src/osgPlugins/txp/trpage_compat.h +++ b/src/osgPlugins/txp/trpage_compat.h @@ -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 diff --git a/src/osgPlugins/txp/trpage_geom.cpp b/src/osgPlugins/txp/trpage_geom.cpp index 7d0a59568..11e86e3b8 100644 --- a/src/osgPlugins/txp/trpage_geom.cpp +++ b/src/osgPlugins/txp/trpage_geom.cpp @@ -14,11 +14,11 @@ */ /* trpage_geom.cpp - Methods for the trpgGeometry class. - This includes read and write methods. - You should only need to change something in here if you want to modify - what trpgGeometry contains. - */ + Methods for the trpgGeometry class. + This includes read and write methods. + You should only need to change something in here if you want to modify + what trpgGeometry contains. + */ #include #include @@ -36,9 +36,9 @@ // Constructor trpgGeometry::trpgGeometry() { - primType = Polygons; - normBind = Overall; - numPrim = 0; + primType = Polygons; + normBind = Overall; + numPrim = 0; } trpgGeometry::~trpgGeometry() { @@ -47,143 +47,143 @@ trpgGeometry::~trpgGeometry() // Reset function void trpgGeometry::Reset() { - primType = Polygons; - numPrim = 0; - primLength.resize(0); - materials.resize(0); - vertDataFloat.resize(0); - vertDataDouble.resize(0); - normBind = Overall; - normDataFloat.resize(0); - normDataDouble.resize(0); - colors.resize(0); - texData.resize(0); - edgeFlags.resize(0); + primType = Polygons; + numPrim = 0; + primLength.resize(0); + materials.resize(0); + vertDataFloat.resize(0); + vertDataDouble.resize(0); + normBind = Overall; + normDataFloat.resize(0); + normDataDouble.resize(0); + colors.resize(0); + texData.resize(0); + edgeFlags.resize(0); } // Set functions void trpgGeometry::SetPrimType(PrimType type) { - primType = type; + primType = type; } void trpgGeometry::SetPrimLengths(int num,const int *len) { - if (num < 0) - return; + if (num < 0) + return; - numPrim = num; - for (int i=0;i= (int)materials.size()) - return; + if (which < 0 || which >= (int)materials.size()) + return; - materials[which] = (isLocal ? -(mat+1) : mat); + materials[which] = (isLocal ? -(mat+1) : mat); } void trpgGeometry::SetMaterials(int32 num,const int32 *mat) { - materials.resize(num); - for (int i=0;i(pt.x)); vertDataFloat.push_back(static_cast(pt.y)); vertDataFloat.push_back(static_cast(pt.z)); - } else { - vertDataDouble.push_back(pt.x); - vertDataDouble.push_back(pt.y); - vertDataDouble.push_back(pt.z); - } + } else { + vertDataDouble.push_back(pt.x); + vertDataDouble.push_back(pt.y); + vertDataDouble.push_back(pt.z); + } } void trpgGeometry::SetNormals(int num,BindType bind,const float32 *data) { - if (num < 0) - return; + if (num < 0) + return; - normBind = bind; - normDataFloat.resize(0); - normDataDouble.resize(0); - for (int i=0;i<3*num;i++) - normDataFloat.push_back(data[i]); + normBind = bind; + normDataFloat.resize(0); + normDataDouble.resize(0); + for (int i=0;i<3*num;i++) + normDataFloat.push_back(data[i]); } void trpgGeometry::SetNormals(int num,BindType bind,const float64 *data) { - if (num <0) - return; + if (num <0) + return; - normBind = bind; - normDataFloat.resize(0); - normDataDouble.resize(0); - for (int i=0;i<3*num;i++) - normDataDouble.push_back(data[i]); + normBind = bind; + normDataFloat.resize(0); + normDataDouble.resize(0); + for (int i=0;i<3*num;i++) + normDataDouble.push_back(data[i]); } void trpgGeometry::AddNormal(DataType type,trpg3dPoint &pt) { - if (type == FloatData) { + if (type == FloatData) { normDataFloat.push_back(static_cast(pt.x)); normDataFloat.push_back(static_cast(pt.y)); normDataFloat.push_back(static_cast(pt.z)); - } else { - normDataDouble.push_back(pt.x); - normDataDouble.push_back(pt.y); - normDataDouble.push_back(pt.z); - } + } else { + normDataDouble.push_back(pt.x); + normDataDouble.push_back(pt.y); + normDataDouble.push_back(pt.z); + } } // Constructor trpgColorInfo::trpgColorInfo() @@ -194,24 +194,24 @@ trpgColorInfo::~trpgColorInfo() } void trpgColorInfo::Reset() { - bind = 0; - type = 0; - data.resize(0); + bind = 0; + type = 0; + data.resize(0); } void trpgGeometry::SetColors(int num,ColorType type,BindType bind,const trpgColor *data) { - trpgColorInfo ci; + trpgColorInfo ci; - if (num < 0) - return; + if (num < 0) + return; - // Set up color list - ci.type = type; - ci.bind = bind; - for (int i=0;i= (int)texData.size())) - return; - trpgTexData *td = &texData[n]; + if ((n<0) || (n >= (int)texData.size())) + return; + trpgTexData *td = &texData[n]; - if (type == FloatData) { + if (type == FloatData) { td->floatData.push_back(static_cast(pt.x)); td->floatData.push_back(static_cast(pt.y)); - } else { - td->doubleData.push_back(pt.x); - td->doubleData.push_back(pt.y); - } + } else { + td->doubleData.push_back(pt.x); + td->doubleData.push_back(pt.y); + } } void trpgGeometry::AddTexCoord(DataType type,std::vector &pts) { - if (texData.size() != pts.size()) - return; + if (texData.size() != pts.size()) + return; - for (unsigned int loop = 0; loop < pts.size(); loop++ ) { - trpgTexData *td = &texData[loop]; + for (unsigned int loop = 0; loop < pts.size(); loop++ ) { + trpgTexData *td = &texData[loop]; - if (type == FloatData) { + if (type == FloatData) { td->floatData.push_back(static_cast(pts[loop].x)); td->floatData.push_back(static_cast(pts[loop].y)); - } else { - td->doubleData.push_back(pts[loop].x); - td->doubleData.push_back(pts[loop].y); - } - } + } else { + td->doubleData.push_back(pts[loop].x); + td->doubleData.push_back(pts[loop].y); + } + } } void trpgGeometry::AddTexCoords(BindType bind) { - trpgTexData td; - td.bind = bind; - texData.push_back(td); + trpgTexData td; + td.bind = bind; + texData.push_back(td); } void trpgGeometry::SetEdgeFlags(int num,const char *flags) { - if (num < 0) - return; + if (num < 0) + return; - edgeFlags.resize(0); - for (int i=0;i= (int)materials.size()) return false; - m = materials[id]; - if (m < 0) { - m = -m - 1; - isLocal = true; - } - return true; + isLocal = false; + if (!isValid() || id < 0 || id >= (int)materials.size()) return false; + m = materials[id]; + if (m < 0) { + m = -m - 1; + isLocal = true; + } + return true; } bool trpgGeometry::GetNumVertex(int &v) const { - if (!isValid()) return false; - int nvf = vertDataFloat.size(); - int nvd = vertDataDouble.size(); - v = MAX(nvf,nvd); - v = v / 3; - return true; + if (!isValid()) return false; + int nvf = vertDataFloat.size(); + int nvd = vertDataDouble.size(); + v = MAX(nvf,nvd); + v = v / 3; + return true; } bool trpgGeometry::GetVertices(float32 *v) const { - unsigned int i; + unsigned int i; - if (!isValid()) return false; - if (vertDataFloat.size() != 0) - for (i=0;i(vertDataDouble[i]); - return true; + return true; } bool trpgGeometry::GetVertices(float64 *v) const { - unsigned int i; + unsigned int i; - if (!isValid()) return false; - if (vertDataFloat.size() != 0) - for (i=0;i= (int)vertDataFloat.size() && idMax >= (int)vertDataDouble.size())) - return false; - if (vertDataFloat.size() > vertDataDouble.size()) { - pt.x = vertDataFloat[id]; - pt.y = vertDataFloat[id+1]; - pt.z = vertDataFloat[id+2]; - } else { - pt.x = vertDataDouble[id]; - pt.y = vertDataDouble[id+1]; - pt.z = vertDataDouble[id+2]; - } - return true; + int id = 3*n; + int idMax = 3*n+2; + if (id < 0 || (idMax >= (int)vertDataFloat.size() && idMax >= (int)vertDataDouble.size())) + return false; + if (vertDataFloat.size() > vertDataDouble.size()) { + pt.x = vertDataFloat[id]; + pt.y = vertDataFloat[id+1]; + pt.z = vertDataFloat[id+2]; + } else { + pt.x = vertDataDouble[id]; + pt.y = vertDataDouble[id+1]; + pt.z = vertDataDouble[id+2]; + } + return true; } bool trpgGeometry::GetNumNormal(int32 &n) const { - if (!isValid()) return false; - if (normDataFloat.size() != 0) - n = normDataFloat.size(); - if (normDataDouble.size() != 0) - n = normDataDouble.size(); - n = n / 3; - return true; + if (!isValid()) return false; + if (normDataFloat.size() != 0) + n = normDataFloat.size(); + if (normDataDouble.size() != 0) + n = normDataDouble.size(); + n = n / 3; + return true; } bool trpgGeometry::GetNormals(float32 *v) const { - unsigned int i; + unsigned int i; - if (!isValid()) return false; - if (normDataFloat.size() != 0) - for (i=0;i(normDataDouble[i]); - return true; + return true; } bool trpgGeometry::GetNormals(float64 *v) const { - unsigned int i; + unsigned int i; - if (!isValid()) return false; - if (normDataFloat.size() != 0) - for (i=0;i= (int)colors.size()) return false; - *ci = colors[id]; - return true; + if (!isValid() || id < 0 || id >= (int)colors.size()) return false; + *ci = colors[id]; + return true; } bool trpgGeometry::GetNumTexCoordSets(int &n) const { - if (!isValid()) return false; - n = texData.size(); - return true; + if (!isValid()) return false; + n = texData.size(); + return true; } bool trpgGeometry::GetTexCoordSet(int id,trpgTexData *tx) const { - if (!isValid() || id < 0 || id >= (int)texData.size()) return false; - *tx = texData[id]; - return true; + if (!isValid() || id < 0 || id >= (int)texData.size()) return false; + *tx = texData[id]; + return true; } const trpgTexData *trpgGeometry::GetTexCoordSet(int id) const { @@ -464,202 +464,202 @@ const trpgTexData *trpgGeometry::GetTexCoordSet(int id) const } bool trpgGeometry::GetNumEdgeFlag(int &n) const { - if (!isValid()) return false; - n = edgeFlags.size(); - return true; + if (!isValid()) return false; + n = edgeFlags.size(); + return true; } bool trpgGeometry::GetEdgeFlags(char *e) const { - if (!isValid()) return false; - for (unsigned int i=0;i 0) { - buf.Begin(TRPG_GEOM_MATERIAL); - buf.Add((int32)materials.size()); - for (i=0;i 0) { + buf.Begin(TRPG_GEOM_MATERIAL); + buf.Add((int32)materials.size()); + for (i=0;i 0) { - buf.Begin(TRPG_GEOM_VERT32); - int32 num = vertDataFloat.size()/3; - buf.Add(num); + /* Vertices + Float and Double should never both be here + Num vertex + Vertex data + */ + if (vertDataFloat.size() > 0) { + buf.Begin(TRPG_GEOM_VERT32); + int32 num = vertDataFloat.size()/3; + buf.Add(num); for (i=0;i<(unsigned int)3*num;i++) - buf.Add(vertDataFloat[i]); - buf.End(); - } - if (vertDataDouble.size() > 0) { - buf.Begin(TRPG_GEOM_VERT64); - int32 num = vertDataDouble.size()/3; - buf.Add(num); + buf.Add(vertDataFloat[i]); + buf.End(); + } + if (vertDataDouble.size() > 0) { + buf.Begin(TRPG_GEOM_VERT64); + int32 num = vertDataDouble.size()/3; + buf.Add(num); for (i=0;i<(unsigned int)3*num;i++) - buf.Add(vertDataDouble[i]); - buf.End(); - } + buf.Add(vertDataDouble[i]); + buf.End(); + } - /* Normals - Normal binding - Num normals - Normal data - */ - if (normDataFloat.size() > 0) { - buf.Begin(TRPG_GEOM_NORM32); - buf.Add((int32)normBind); - int32 num = normDataFloat.size()/3; - buf.Add(num); + /* Normals + Normal binding + Num normals + Normal data + */ + if (normDataFloat.size() > 0) { + buf.Begin(TRPG_GEOM_NORM32); + buf.Add((int32)normBind); + int32 num = normDataFloat.size()/3; + buf.Add(num); for (i=0;i<(unsigned int)3*num;i++) - buf.Add(normDataFloat[i]); - buf.End(); - } - if (normDataDouble.size() > 0) { - buf.Begin(TRPG_GEOM_NORM64); - buf.Add((int32)normBind); - int32 num = normDataDouble.size()/3; - buf.Add(num); + buf.Add(normDataFloat[i]); + buf.End(); + } + if (normDataDouble.size() > 0) { + buf.Begin(TRPG_GEOM_NORM64); + buf.Add((int32)normBind); + int32 num = normDataDouble.size()/3; + buf.Add(num); for (i=0;i<(unsigned int)3*num;i++) - buf.Add(normDataDouble[i]); - buf.End(); - } + buf.Add(normDataDouble[i]); + buf.End(); + } - /* Colors - Color binding - Num colors - Colors - */ - if (colors.size() > 0) { - for (i=0;i 0) { + for (i=0;i 0) { - buf.Begin(TRPG_GEOM_EFLAG); - buf.Add((int32)edgeFlags.size()); - for (i=0;i 0) { + buf.Begin(TRPG_GEOM_EFLAG); + buf.Add((int32)edgeFlags.size()); + for (i=0;iSetPrimType((trpgGeometry::PrimType)primType); - buf.Get(num); - if (num < 0) throw 1; - geom->SetNumPrims(num); - buf.Get(hasPrimLen); - if (hasPrimLen) { - buf.GetArray(num,&iData); + try { + switch (tok) { + case TRPG_GEOM_PRIM: + buf.Get(primType); + geom->SetPrimType((trpgGeometry::PrimType)primType); + buf.Get(num); + if (num < 0) throw 1; + geom->SetNumPrims(num); + buf.Get(hasPrimLen); + if (hasPrimLen) { + buf.GetArray(num,&iData); if (ALIGNMENT_WORKAROUND) { int32 *aligned; @@ -669,13 +669,13 @@ void *geomCB::Parse(trpgToken tok,trpgReadBuffer &buf) free (aligned); } else - geom->SetPrimLengths(num,iData); - } - break; - case TRPG_GEOM_MATERIAL: - buf.Get(num); - if (num < 0) throw 1; - buf.GetArray(num,&iData); + geom->SetPrimLengths(num,iData); + } + break; + case TRPG_GEOM_MATERIAL: + buf.Get(num); + if (num < 0) throw 1; + buf.GetArray(num,&iData); if (ALIGNMENT_WORKAROUND) { int32 *aligned; @@ -685,12 +685,12 @@ void *geomCB::Parse(trpgToken tok,trpgReadBuffer &buf) free (aligned); } else - geom->SetMaterials(num,iData); - break; - case TRPG_GEOM_VERT32: - buf.Get(num); - if (num < 0) throw 1; - buf.GetArray(3*num,&fData); + geom->SetMaterials(num,iData); + break; + case TRPG_GEOM_VERT32: + buf.Get(num); + if (num < 0) throw 1; + buf.GetArray(3*num,&fData); if (ALIGNMENT_WORKAROUND) { float32 *aligned; @@ -700,12 +700,12 @@ void *geomCB::Parse(trpgToken tok,trpgReadBuffer &buf) free (aligned); } else - geom->SetVertices(num,fData); - break; - case TRPG_GEOM_VERT64: - buf.Get(num); - if (num < 0) throw 1; - buf.GetArray(3*num,&dData); + geom->SetVertices(num,fData); + break; + case TRPG_GEOM_VERT64: + buf.Get(num); + if (num < 0) throw 1; + buf.GetArray(3*num,&dData); if (ALIGNMENT_WORKAROUND) { float64 *aligned; @@ -715,14 +715,14 @@ void *geomCB::Parse(trpgToken tok,trpgReadBuffer &buf) free (aligned); } else - geom->SetVertices(num,dData); - break; - case TRPG_GEOM_NORM32: - buf.Get(bind); - buf.Get(num); - if (num < 0) throw 1; - buf.GetArray(3*num,&fData); - if (ALIGNMENT_WORKAROUND) + geom->SetVertices(num,dData); + break; + case TRPG_GEOM_NORM32: + buf.Get(bind); + buf.Get(num); + if (num < 0) throw 1; + buf.GetArray(3*num,&fData); + if (ALIGNMENT_WORKAROUND) { float32 *aligned; aligned = (float32 *)calloc (3*num, sizeof(float32)); @@ -731,13 +731,13 @@ void *geomCB::Parse(trpgToken tok,trpgReadBuffer &buf) free (aligned); } else - geom->SetNormals(num,(trpgGeometry::BindType)bind,fData); - break; - case TRPG_GEOM_NORM64: - buf.Get(bind); - buf.Get(num); - if (num < 0) throw 1; - buf.GetArray(3*num,&dData); + geom->SetNormals(num,(trpgGeometry::BindType)bind,fData); + break; + case TRPG_GEOM_NORM64: + buf.Get(bind); + buf.Get(num); + if (num < 0) throw 1; + buf.GetArray(3*num,&dData); if (ALIGNMENT_WORKAROUND) { float64 *aligned; @@ -747,14 +747,14 @@ void *geomCB::Parse(trpgToken tok,trpgReadBuffer &buf) free (aligned); } else - geom->SetNormals(num,(trpgGeometry::BindType)bind,dData); - break; - case TRPG_GEOM_COLOR: - buf.Get(num); - if (num < 0) throw 1; - buf.Get(type); - buf.Get(bind); - buf.GetArray(num,&cData); + geom->SetNormals(num,(trpgGeometry::BindType)bind,dData); + break; + case TRPG_GEOM_COLOR: + buf.Get(num); + if (num < 0) throw 1; + buf.Get(type); + buf.Get(bind); + buf.GetArray(num,&cData); if (ALIGNMENT_WORKAROUND) { trpgColor *aligned; @@ -764,13 +764,13 @@ void *geomCB::Parse(trpgToken tok,trpgReadBuffer &buf) free (aligned); } else - geom->SetColors(num,(trpgGeometry::ColorType)type,(trpgGeometry::BindType)bind,cData); - break; - case TRPG_GEOM_TEX32: - buf.Get(bind); - buf.Get(num); - if (num < 0) throw 1; - buf.GetArray(2*num,&fData); + geom->SetColors(num,(trpgGeometry::ColorType)type,(trpgGeometry::BindType)bind,cData); + break; + case TRPG_GEOM_TEX32: + buf.Get(bind); + buf.Get(num); + if (num < 0) throw 1; + buf.GetArray(2*num,&fData); if (ALIGNMENT_WORKAROUND) { float32 *aligned; @@ -780,13 +780,13 @@ void *geomCB::Parse(trpgToken tok,trpgReadBuffer &buf) free (aligned); } else - geom->SetTexCoords(num,(trpgGeometry::BindType)bind,fData); - break; - case TRPG_GEOM_TEX64: - buf.Get(bind); - buf.Get(num); - if (num < 0) throw 1; - buf.GetArray(2*num,&dData); + geom->SetTexCoords(num,(trpgGeometry::BindType)bind,fData); + break; + case TRPG_GEOM_TEX64: + buf.Get(bind); + buf.Get(num); + if (num < 0) throw 1; + buf.GetArray(2*num,&dData); if (ALIGNMENT_WORKAROUND) { float64 *aligned; @@ -796,44 +796,44 @@ void *geomCB::Parse(trpgToken tok,trpgReadBuffer &buf) free (aligned); } else - geom->SetTexCoords(num,(trpgGeometry::BindType)bind,dData); - break; - case TRPG_GEOM_EFLAG: - buf.Get(num); - if (num < 0) throw 1; - buf.GetArray(num,&charData); - geom->SetEdgeFlags(num,charData); - break; - default: - // Skip - break; - } - } - catch (...) { - return NULL; - } + geom->SetTexCoords(num,(trpgGeometry::BindType)bind,dData); + break; + case TRPG_GEOM_EFLAG: + buf.Get(num); + if (num < 0) throw 1; + buf.GetArray(num,&charData); + geom->SetEdgeFlags(num,charData); + break; + default: + // Skip + break; + } + } + catch (...) { + return NULL; + } - return geom; + return geom; } // Read Geometry bool trpgGeometry::Read(trpgReadBuffer &buf) { - trpgr_Parser parse; - geomCB gcb; + trpgr_Parser parse; + geomCB gcb; - gcb.geom = this; - parse.AddCallback(TRPG_GEOM_PRIM,&gcb,false); - parse.AddCallback(TRPG_GEOM_MATERIAL,&gcb,false); - parse.AddCallback(TRPG_GEOM_VERT32,&gcb,false); - parse.AddCallback(TRPG_GEOM_VERT64,&gcb,false); - parse.AddCallback(TRPG_GEOM_NORM32,&gcb,false); - parse.AddCallback(TRPG_GEOM_NORM64,&gcb,false); - parse.AddCallback(TRPG_GEOM_COLOR,&gcb,false); - parse.AddCallback(TRPG_GEOM_TEX32,&gcb,false); - parse.AddCallback(TRPG_GEOM_TEX64,&gcb,false); - parse.AddCallback(TRPG_GEOM_EFLAG,&gcb,false); - parse.Parse(buf); + gcb.geom = this; + parse.AddCallback(TRPG_GEOM_PRIM,&gcb,false); + parse.AddCallback(TRPG_GEOM_MATERIAL,&gcb,false); + parse.AddCallback(TRPG_GEOM_VERT32,&gcb,false); + parse.AddCallback(TRPG_GEOM_VERT64,&gcb,false); + parse.AddCallback(TRPG_GEOM_NORM32,&gcb,false); + parse.AddCallback(TRPG_GEOM_NORM64,&gcb,false); + parse.AddCallback(TRPG_GEOM_COLOR,&gcb,false); + parse.AddCallback(TRPG_GEOM_TEX32,&gcb,false); + parse.AddCallback(TRPG_GEOM_TEX64,&gcb,false); + parse.AddCallback(TRPG_GEOM_EFLAG,&gcb,false); + parse.Parse(buf); - return isValid(); + return isValid(); } diff --git a/src/osgPlugins/txp/trpage_geom.h b/src/osgPlugins/txp/trpage_geom.h index 21e7d527b..5648441fb 100644 --- a/src/osgPlugins/txp/trpage_geom.h +++ b/src/osgPlugins/txp/trpage_geom.h @@ -52,79 +52,79 @@ TX_EXDECL class TX_CLDECL trpgHeader : public trpgReadWriteable ~trpgHeader(void); // Set the TerraPage version info. - void SetVersion(int major,int minor); + void SetVersion(int major,int minor); // Set the database version info. - void SetDbVersion(int major,int minor); + void SetDbVersion(int major,int minor); /* Set the tile size for the given LOD. See GetTileSize for more info. Each LOD must have its size set, otherwise the trpgHeader won't be valid. You must set the number of LODs with SetNumLods first. You should use the AddLod method if you can, which handles all of this. */ - void SetTileSize(int lod,const trpg2dPoint &size); + void SetTileSize(int lod,const trpg2dPoint &size); // Origin defaults to 0,0,0 - void SetOrigin(const trpg3dPoint &); + void SetOrigin(const trpg3dPoint &); // 2D archive extents. Must be set. - void SetExtents(const trpg2dPoint &sw,const trpg2dPoint &ne); + void SetExtents(const trpg2dPoint &sw,const trpg2dPoint &ne); typedef enum {DatabaseLocal,Absolute,TileLocal} trpgTileType; // How the coordinates are treated with respect to real world values. - void SetTileOriginType(trpgTileType); + void SetTileOriginType(trpgTileType); /* Number of terrain LODs. If you use this method when building a database you have to use the SetLodRange and SetLodSize methods on each LOD as well. It's better to use AddLod instead of calling these three methods. */ - void SetNumLods(int); + void SetNumLods(int); /* Number of tiles (x,y) for each LOD. The single argument version assumes lod = 0, num lods = 1. */ - void SetLodSize(int lod,const trpg2iPoint &); - void SetLodSize(const trpg2iPoint *); + void SetLodSize(int lod,const trpg2iPoint &); + void SetLodSize(const trpg2iPoint *); /* Set the range for the given terrain LOD. The single argument version assumes lod = 0, num lods = 1. */ - void SetLodRange(int,float64); - void SetLodRange(const float64 *); + void SetLodRange(int,float64); + void SetLodRange(const float64 *); // Increase the number of terrain LODs, adding a new one with the given size and range - void AddLod(const trpg2iPoint &size,const trpg2dPoint &ext,float64 range); + void AddLod(const trpg2iPoint &size,const trpg2dPoint &ext,float64 range); // Set details for an LOD, resizing if necessary - void SetLod(const trpg2iPoint &size,const trpg2dPoint &ext,float64 range,unsigned int lod); + void SetLod(const trpg2iPoint &size,const trpg2dPoint &ext,float64 range,unsigned int lod); // Keep track of the maximum assigned group IDs (for tile paging) - void SetMaxGroupID(int); + void SetMaxGroupID(int); /* Instead of keeping a count of all the group IDs you added and then calling SetMaxGroupID, you can call this function and it will return the next valid groupID to you. It will also keep track of the maximum. */ - int AddGroupID(void); + int AddGroupID(void); // Validity check - bool isValid(void) const; + bool isValid(void) const; // Resets the contents back to empty - void Reset(void); + void Reset(void); // TerraVista version information is two integers. - bool GetVersion(int &,int &) const; + bool GetVersion(int &,int &) const; // Database version information is user defined. Put whatever you want here. - bool GetDbVersion(int &,int &) const; + bool GetDbVersion(int &,int &) const; /* This is the extents, in X/Y of a single tile. All tiles within an LOD should be the same size (although this is not enforced). It's also assumed that a given tile lives entirely within its own extents (as calculated with this value), although that's not enforced either. */ - bool GetTileSize(int,trpg2dPoint &) const; + bool GetTileSize(int,trpg2dPoint &) const; /* The meaning of the database origin varies depending on the value returned by GetTileOriginType. If the database is Absolute, then this value will be the lower left corner. If the database is DatabaseLocal or TileLocal you can use this value to determine the real world coordinates. Just add origin + coordinate. */ - bool GetOrigin(trpg3dPoint &) const; + bool GetOrigin(trpg3dPoint &) const; /* These are the 2D extents that the database covers. You can use this information to determine where the middle is, for example. */ - bool GetExtents(trpg2dPoint &sw,trpg2dPoint &ne) const; + bool GetExtents(trpg2dPoint &sw,trpg2dPoint &ne) const; /* The tile origin type tells you the coordinate system of each database tile. There are three type: * Absolute - All coordinate values are absolute. No translation is required. @@ -135,13 +135,13 @@ TX_EXDECL class TX_CLDECL trpgHeader : public trpgReadWriteable can do Double coordinates if necessary, as well). To determine the real world coordinate value do: tileID*tileSize + coord. */ - bool GetTileOriginType(trpgTileType &) const; + bool GetTileOriginType(trpgTileType &) const; /* Group IDs are used by TerraPage to hook level of detail structures together. A TerraPage database can have an arbitrary number of terrain LODs, each stored seperately. To hook them together we use trpgAttach nodes and number each group & LOD node. This returns the maximum group ID in the file, which is important to know if you're keeping an array of them. */ - bool GetMaxGroupID(int &) const; + bool GetMaxGroupID(int &) const; /* A TerraPage archive can contain any number of terrain LODs (a typical number is 4). Each of these terrain LODs is accessed seperately (as are the tiles within them). @@ -153,12 +153,12 @@ TX_EXDECL class TX_CLDECL trpgHeader : public trpgReadWriteable the gaming area for all of the lods. trpgAttach node are no longer used, instead see trpgChildRef */ - bool GetNumLods(int32 &) const; + bool GetNumLods(int32 &) const; /* A terrain LOD conceptually covers the entire database and is broken up into some X x Y set of tiles. We make no assumptions about the number of tiles in each terrain LOD. That's entirely up to the writer. This returns the number of tiles in 2D for a given terrain LOD. */ - bool GetLodSize(int32,trpg2iPoint &) const; + bool GetLodSize(int32,trpg2iPoint &) const; /* It's up to the TerraPage archive writer to make their terrain LOD structure work by using trpgAttach nodes. The scheme they're using may be quad-tree or replacement LOD or something where the highest LOD isn't even terrain. @@ -166,56 +166,56 @@ TX_EXDECL class TX_CLDECL trpgHeader : public trpgReadWriteable when tiles for a given LOD must be pulled in. This returns that range in database coordinates (usually meters). */ - bool GetLodRange(int32,float64 &) const; + bool GetLodRange(int32,float64 &) const; // Read/Write functions // Writes this class to a write buffer - bool Write(trpgWriteBuffer &); + bool Write(trpgWriteBuffer &); // Reads this class from a read buffer - bool Read(trpgReadBuffer &); + bool Read(trpgReadBuffer &); // Prints this class to a print buffer - bool Print(trpgPrintBuffer &) const; + bool Print(trpgPrintBuffer &) const; // {secret} - bool ReadLodInfo(trpgReadBuffer &); + bool ReadLodInfo(trpgReadBuffer &); void SetMaster(bool isMaster) { - if((verMajor >= TRPG_NOMERGE_VERSION_MAJOR) && (verMinor >=TRPG_NOMERGE_VERSION_MINOR)) - { - if(isMaster) - flags |= ISMASTER;//set the master flag - else - flags &= ~ISMASTER;//clear the master flag - } + if((verMajor >= TRPG_NOMERGE_VERSION_MAJOR) && (verMinor >=TRPG_NOMERGE_VERSION_MINOR)) + { + if(isMaster) + flags |= ISMASTER;//set the master flag + else + flags &= ~ISMASTER;//clear the master flag } - bool GetIsMaster() const + } + bool GetIsMaster() const { - return ((flags & ISMASTER)==ISMASTER); + return ((flags & ISMASTER)==ISMASTER); } - void SetLocal(bool isLocal) + void SetLocal(bool isLocal) { - if((verMajor >= TRPG_NOMERGE_VERSION_MAJOR) && (verMinor >=TRPG_NOMERGE_VERSION_MINOR)) - { - if(isLocal) - flags |= ISLOCAL;//set the local flag - else - flags &= ~ISLOCAL;//clear the local flag - } + if((verMajor >= TRPG_NOMERGE_VERSION_MAJOR) && (verMinor >=TRPG_NOMERGE_VERSION_MINOR)) + { + if(isLocal) + flags |= ISLOCAL;//set the local flag + else + flags &= ~ISLOCAL;//clear the local flag } - bool GetIsLocal() const - { - return ((flags & ISLOCAL)==ISLOCAL); } - void SetBlocks(int rows,int cols) + bool GetIsLocal() const { - this->rows = rows; - this->cols = cols; + return ((flags & ISLOCAL)==ISLOCAL); } - void GetBlocks(int &rows,int &cols) + void SetBlocks(int rows,int cols) { - rows = this->rows; - cols = this->cols; + this->rows = rows; + this->cols = cols; + } + void GetBlocks(int &rows,int &cols) + { + rows = this->rows; + cols = this->cols; } protected: int verMinor,verMajor; @@ -230,8 +230,8 @@ TX_EXDECL class TX_CLDECL trpgHeader : public trpgReadWriteable std::vector lodSizes; std::vector lodRanges; int32 flags; - int32 rows; - int32 cols; + int32 rows; + int32 cols; }; /* The Texture Environment is used by the trpgMaterial to define texture @@ -256,21 +256,21 @@ TX_EXDECL class TX_CLDECL trpgTextureEnv : public trpgReadWriteable // Environment mode values enum {Alpha,Blend,Decal,Modulate,AddDetail,ModulateDetail}; // Set the application mode for the texture. - void SetEnvMode(int); + void SetEnvMode(int); // Values used by SetMinFilter and SetMagFilter enum {Point, Linear, MipmapPoint, MipmapLinear, - MipmapBilinear, MipmapTrilinear, Nearest}; + MipmapBilinear, MipmapTrilinear, Nearest}; // Set the Minification filter for a texture - void SetMinFilter(int); + void SetMinFilter(int); // Set the Magnification filter for a texture - void SetMagFilter(int); + void SetMagFilter(int); // Values used by SetWrap enum {Clamp,Repeat}; // Set the texture wrapping for S and T, respectively - void SetWrap(int,int); + void SetWrap(int,int); // Set the texture border color - void SetBorderColor(const trpgColor &); + void SetBorderColor(const trpgColor &); /* The environment mode controls how the texture is applied. It can take the following values: @@ -281,32 +281,32 @@ TX_EXDECL class TX_CLDECL trpgTextureEnv : public trpgReadWriteable AddDetail - See openGL spec for definition. ModulateDetail - See openGL spec for definition. */ - bool GetEnvMode(int32 &) const; + bool GetEnvMode(int32 &) const; /* The Minification and Magnification filters control how texture mipmap levels are used. We support the values: Point, Linear, MipmapPoint, MipmapLinear, MipmapBilinear, MipmapTrilinear, Nearest */ - bool GetMinFilter(int32 &) const; + bool GetMinFilter(int32 &) const; // Get the magnification filter - bool GetMagFilter(int32 &) const; + bool GetMagFilter(int32 &) const; /* Wrapping controls how textures are used near the edges. There are two valid values: Clamp, Repeat. */ - bool GetWrap(int &,int &) const; + bool GetWrap(int &,int &) const; /* This maps straight into the OpenGL definition of border color. */ - bool GetBorderColor(trpgColor &) const; + bool GetBorderColor(trpgColor &) const; // Validity check - bool isValid(void) const; + bool isValid(void) const; // Resets the contents back to empty - void Reset(void); + void Reset(void); // Writes this class to a write buffer - bool Write(trpgWriteBuffer &); + bool Write(trpgWriteBuffer &); // Reads this class from a read buffer - bool Read(trpgReadBuffer &); + bool Read(trpgReadBuffer &); // Prints this class to a print buffer - bool Print(trpgPrintBuffer &) const; + bool Print(trpgPrintBuffer &) const; protected: int envMode; @@ -349,109 +349,109 @@ TX_EXDECL class TX_CLDECL trpgMaterial : public trpgReadWriteable trpgMaterial(void); ~trpgMaterial(void); // Set base material color - void SetColor(const trpgColor &); + void SetColor(const trpgColor &); // Ambient color - void SetAmbient(const trpgColor &); + void SetAmbient(const trpgColor &); // Diffuse color (the most commonly used) - void SetDiffuse(const trpgColor &); + void SetDiffuse(const trpgColor &); // Specular color used in lighting - void SetSpecular(const trpgColor &); + void SetSpecular(const trpgColor &); // Emissive color used in lighting - void SetEmission(const trpgColor &); + void SetEmission(const trpgColor &); // Shininess used in lighting - void SetShininess(float64); + void SetShininess(float64); enum {Smooth,Flat}; // Shading model - void SetShadeModel(int); + void SetShadeModel(int); // Point size - void SetPointSize(float64); + void SetPointSize(float64); // Line width - void SetLineWidth(float64); + void SetLineWidth(float64); enum {Front,Back,FrontAndBack}; // Cull mode. See GetCullMode - void SetCullMode(int); + void SetCullMode(int); #ifdef Always // None and Always appear to be defined on the SGI // in such a way as to interfere with a local enum // declaration within a class enum {trNone,trAlways,Equal,GreaterThanOrEqual,GreaterThan, - LessThanOrEqual,LessThan,Never,NotEqual}; + LessThanOrEqual,LessThan,Never,NotEqual}; #else enum {None,Always,Equal,GreaterThanOrEqual,GreaterThan, - LessThanOrEqual,LessThan,Never,NotEqual}; + LessThanOrEqual,LessThan,Never,NotEqual}; #endif // Alpha Function. See GetAlphaFunc - void SetAlphaFunc(int); + void SetAlphaFunc(int); // Alpha Ref value. See GetAlphaRef - void SetAlphaRef(float64); + void SetAlphaRef(float64); // Alpha value for any polygon using this material - void SetAlpha(float64); + void SetAlpha(float64); // Generate normals automatically from geometry - void SetAutoNormal(bool); + void SetAutoNormal(bool); /* Set the total number of textures used by this trpgMaterial. This works with SetTexture. We recommend that you used AddTexture instead of these two methods. */ - void SetNumTexture(int); + void SetNumTexture(int); /* Works with SetNumTexture. This method sets the texture ID and texture environment for the given texture instance in this material. Use AddTexture instead, if you can. */ - void SetTexture(int no,int id,const trpgTextureEnv &); + void SetTexture(int no,int id,const trpgTextureEnv &); /* This method takes a texture ID that refers to a trpgTexTable and a trpgTextureEnv which specifies the application information relating to this texture instance. It returns the reference number (i.e. the 3rd texture in this material, etc...) */ - int AddTexture(int,const trpgTextureEnv &); + int AddTexture(int,const trpgTextureEnv &); // Number of tiles this material is used in - void SetNumTiles(int); + void SetNumTiles(int); // Adds a count to the number of tiles this material is used in and returns that number - int AddTile(void); + int AddTile(void); // Sets bump map status (color etc... isn't important) - void SetIsBumpMap(bool); + void SetIsBumpMap(bool); // Set an attribute (e.g. fid/smc) enum {TR_FID,TR_SMC,TR_STP,TR_SWC}; - void SetAttr(int attrCode,int val); + void SetAttr(int attrCode,int val); // Return the current color - bool GetColor(trpgColor &) const; + bool GetColor(trpgColor &) const; // Returns the ambient color - bool GetAmbient(trpgColor &) const; + bool GetAmbient(trpgColor &) const; // Returns the diffuse color (the most commonly used color) - bool GetDiffuse(trpgColor &) const; + bool GetDiffuse(trpgColor &) const; // Specular color used for lighting - bool GetSpecular(trpgColor &) const; + bool GetSpecular(trpgColor &) const; // Emissive color used for lighting - bool GetEmission(trpgColor &) const; + bool GetEmission(trpgColor &) const; // Shininess used for lighting - bool GetShininess(float64 &) const; + bool GetShininess(float64 &) const; // The shading model can be either Smooth or Flat - bool GetShadeModel(int &) const; + bool GetShadeModel(int &) const; // Point size - bool GetPointSize(float64 &) const; + bool GetPointSize(float64 &) const; // Line width - bool GetLineWidth(float64 &) const; + bool GetLineWidth(float64 &) const; /* Cull mode determines whether geometry will be rejected if it's Front facing, Back facing, or neither (FrontAndBack) */ - bool GetCullMode(int &) const; + bool GetCullMode(int &) const; /* This controls what alpha values in a texture mean. It can take the values: None,Always,Equal,GreaterThanOrEqual,GreaterThan, LessThanOrEqual,LessThan,Never,NotEqual */ - bool GetAlphaFunc(int &) const; + bool GetAlphaFunc(int &) const; /* The Alpha Ref is a value used in some of the Alpha Functions */ - bool GetAlphaRef(float64 &) const; + bool GetAlphaRef(float64 &) const; // Whether or not to generate normals from geometry - bool GetAutoNormal(bool &) const; + bool GetAutoNormal(bool &) const; // A single Alpha value that applies to any polygons using this material - bool GetAlpha(float64 &) const; + bool GetAlpha(float64 &) const; /* One of the useful things about TerraPage is that it contains enough information to page textures & materials as well as terrain. This is part of that. It returns the number of tiles this material is used in. The trpgTexture has @@ -459,12 +459,12 @@ TX_EXDECL class TX_CLDECL trpgMaterial : public trpgReadWriteable this if you have some costly material definition in your hardware and so have to swap them in and out. */ - bool GetNumTile(int &) const; + bool GetNumTile(int &) const; /* There can be multiple textures per material. This returns the number. The first is the base texture, so just use that if you can only do 1 texture per poly. */ - bool GetNumTexture(int &) const; + bool GetNumTexture(int &) const; /* TerraPage supports multiple textures per polygon. Some hardware can do this, some can't. If you can support it, here's how this works. This method returns the texture definition for the Nth texture used in this material. @@ -473,27 +473,27 @@ TX_EXDECL class TX_CLDECL trpgMaterial : public trpgReadWriteable Multiple materials can also appear per trpgGeometry, so be aware that there are two ways to have multiple textures per polygon. */ - bool GetTexture(int no,int &id,trpgTextureEnv &) const; + bool GetTexture(int no,int &id,trpgTextureEnv &) const; // Return whether or not this material is a bump map - bool GetIsBumpMap(bool &) const; + bool GetIsBumpMap(bool &) const; // Get an attribute (e.g. fid/smc) - bool GetAttr(int attrCode,int &val) const; + bool GetAttr(int attrCode,int &val) const; // Validity check - bool isValid(void) const; + bool isValid(void) const; // Resets the contents back to empty - void Reset(void); + void Reset(void); // Writes this class to a write buffer - bool Write(trpgWriteBuffer &); + bool Write(trpgWriteBuffer &); // Reads this class from a read buffer - bool Read(trpgReadBuffer &); + bool Read(trpgReadBuffer &); // Prints this class to a print buffer - bool Print(trpgPrintBuffer &) const; + bool Print(trpgPrintBuffer &) const; // Note: Need to do equality operator - + protected: bool isBump; trpgColor color; @@ -514,10 +514,10 @@ TX_EXDECL class TX_CLDECL trpgMaterial : public trpgReadWriteable int32 numTile; struct _attrSet { - int fid; - int smc; - int stp; - int swc; + int fid; + int smc; + int stp; + int swc; } attrSet; std::vector texids; std::vector texEnvs; @@ -542,89 +542,89 @@ TX_EXDECL class TX_CLDECL trpgLightAttr : public trpgReadWriteable // Light Flags enum { - // Light flags - trpg_Day = 0x0001, - trpg_Dusk = 0x0002, - trpg_Night = 0x0004, - trpg_Directional = 0x0008, - trpg_BackColor = 0x0010, - trpg_Reflective = 0x0020, + // Light flags + trpg_Day = 0x0001, + trpg_Dusk = 0x0002, + trpg_Night = 0x0004, + trpg_Directional = 0x0008, + trpg_BackColor = 0x0010, + trpg_Reflective = 0x0020, - // Animation flags - trpg_Flashing = 0x0100, - trpg_Rotating = 0x0200, - trpg_ClockWise = 0x0400, - trpg_AnimationMask = 0x0f00, + // Animation flags + trpg_Flashing = 0x0100, + trpg_Rotating = 0x0200, + trpg_ClockWise = 0x0400, + trpg_AnimationMask = 0x0f00, - // Performer light flags - trpg_Perspective = 0x1000, - trpg_Fade = 0x2000, - trpg_ZBuffer = 0x4000, - trpg_FogPunch = 0x8000, - trpg_PerformerMask = 0xf000 + // Performer light flags + trpg_Perspective = 0x1000, + trpg_Fade = 0x2000, + trpg_ZBuffer = 0x4000, + trpg_FogPunch = 0x8000, + trpg_PerformerMask = 0xf000 } LightFlags; // Light Type typedef enum { - trpg_Raster, - trpg_Calligraphic, - trpg_RASCAL + trpg_Raster, + trpg_Calligraphic, + trpg_RASCAL } LightType; // Light Directionality typedef enum { - trpg_Omnidirectional, - trpg_Bidirectional, - trpg_Unidirectional + trpg_Omnidirectional, + trpg_Bidirectional, + trpg_Unidirectional } LightDirectionality; // Light Quality typedef enum { - trpg_Off, - trpg_Low, - trpg_Medium, - trpg_High, - trpg_Undefined + trpg_Off, + trpg_Low, + trpg_Medium, + trpg_High, + trpg_Undefined } LightQuality; // Struct for Performer Lights struct PerformerAttr { - PerformerAttr() : flags(0),minPixelSize(0),maxPixelSize(0),actualSize(0), - transparentPixelSize(0),transparentFallofExp(0),transparentScale(0), - transparentClamp(0),fogScale(0) {}; - int32 flags; - float64 minPixelSize; - float64 maxPixelSize; - float64 actualSize; - float64 transparentPixelSize; - float64 transparentFallofExp; - float64 transparentScale; - float64 transparentClamp; - float64 fogScale; + PerformerAttr() : flags(0),minPixelSize(0),maxPixelSize(0),actualSize(0), + transparentPixelSize(0),transparentFallofExp(0),transparentScale(0), + transparentClamp(0),fogScale(0) {}; + int32 flags; + float64 minPixelSize; + float64 maxPixelSize; + float64 actualSize; + float64 transparentPixelSize; + float64 transparentFallofExp; + float64 transparentScale; + float64 transparentClamp; + float64 fogScale; }; // Struct for Animated Lights struct AnimationAttr { - AnimationAttr() : period(0),phaseDelay(0),timeOn(0),vector(trpg3dPoint(0,0,0)),flags(0) {}; - float64 period; - float64 phaseDelay; - float64 timeOn; - trpg3dPoint vector; - int32 flags; + AnimationAttr() : period(0),phaseDelay(0),timeOn(0),vector(trpg3dPoint(0,0,0)),flags(0) {}; + float64 period; + float64 phaseDelay; + float64 timeOn; + trpg3dPoint vector; + int32 flags; }; // Struct for Calligraphic Lights struct CalligraphicAttr { - CalligraphicAttr() : drawOrder(0),minDefocus(0),maxDefocus(0) {} ; - int32 drawOrder; - float64 minDefocus; - float64 maxDefocus; + CalligraphicAttr() : drawOrder(0),minDefocus(0),maxDefocus(0) {} ; + int32 drawOrder; + float64 minDefocus; + float64 maxDefocus; }; // Setters @@ -717,7 +717,7 @@ TX_EXDECL class TX_CLDECL trpgLightAttr : public trpgReadWriteable // Set the transparent scale for Performer Lights void SetPerformerTpScale( float64 ); - + // Set the transparent clamp for Performer Lights void SetPerformerTpClamp( float64 ); @@ -811,28 +811,28 @@ TX_EXDECL class TX_CLDECL trpgLightAttr : public trpgReadWriteable protected: struct DataSet { - LightType type; - LightDirectionality directionality; - trpgColor frontColor; - float64 frontIntensity; - trpgColor backColor; - float64 backIntensity; - trpg3dPoint normal; - int32 smc; - int32 fid; - int32 flags; - float64 horizontalLobeAngle; - float64 verticalLobeAngle; - float64 lobeRollAngle; - float64 lobeFalloff; - float64 ambientIntensity; - LightQuality quality; - LightQuality randomIntensity; - float64 rascalSignificance; - CalligraphicAttr calligraphicAttr; - PerformerAttr performerAttr; - AnimationAttr animationAttr; - char *commentStr; + LightType type; + LightDirectionality directionality; + trpgColor frontColor; + float64 frontIntensity; + trpgColor backColor; + float64 backIntensity; + trpg3dPoint normal; + int32 smc; + int32 fid; + int32 flags; + float64 horizontalLobeAngle; + float64 verticalLobeAngle; + float64 lobeRollAngle; + float64 lobeFalloff; + float64 ambientIntensity; + LightQuality quality; + LightQuality randomIntensity; + float64 rascalSignificance; + CalligraphicAttr calligraphicAttr; + PerformerAttr performerAttr; + AnimationAttr animationAttr; + char *commentStr; } data; }; @@ -892,8 +892,8 @@ TX_EXDECL class TX_CLDECL trpgLight : public trpgReadWriteable protected: // Here we store the light locations - std::vector lightPoints; - int index; + std::vector lightPoints; + int index; }; /* The Light Table is stored in the TerraPage header and consolidates @@ -919,7 +919,7 @@ TX_EXDECL class TX_CLDECL trpgLightTable : public trpgReadWriteable first. This is convenient for writers who aren't keeping track of their own light attrib internally. */ - int FindAddLightAttr(const trpgLightAttr&); + int FindAddLightAttr(const trpgLightAttr&); // Returns the number of light attrib in this table bool GetNumLightAttrs(int &) const; @@ -944,7 +944,7 @@ TX_EXDECL class TX_CLDECL trpgLightTable : public trpgReadWriteable // operator trpgLightTable & operator = (const trpgLightTable &); - + typedef std::map LightMapType; LightMapType *getLightMap() { return &lightMap; } protected: @@ -970,39 +970,39 @@ TX_EXDECL class TX_CLDECL trpgRange : public trpgReadWriteable trpgRange(const trpgRange &); // Set the name and subName (can be NULL) - void SetCategory(const char *cat,const char *subCat); + void SetCategory(const char *cat,const char *subCat); /* Get the name and subName Name should be the major category (e.g. "trees") SubName should be the minor category (e.g. "big trees") */ - void GetCategory(char *cat,int maxCatLen,char *subCat,int maxSubCatLen) const; + void GetCategory(char *cat,int maxCatLen,char *subCat,int maxSubCatLen) const; // Set the lod info - void SetLodInfo(double in,double out); + void SetLodInfo(double in,double out); // Get the lod info (this will be duplicated in the trpgLod node) // However, you may want to change these values yourself during a run - void GetLodInfo(double &in,double &out) const; + void GetLodInfo(double &in,double &out) const; // Set the priority - void SetPriority(int); + void SetPriority(int); /* Get the priority. Priority is a hint to the run-time system as to the relative importance of range limited features. Features with lower priorities should be sacrified before those with higher priorities. */ - void GetPriority(int &) const; + void GetPriority(int &) const; // Writes this class to a write buffer - bool Write(trpgWriteBuffer &); + bool Write(trpgWriteBuffer &); // Reads this class from a read buffer - bool Read(trpgReadBuffer &); + bool Read(trpgReadBuffer &); // Prints this class to a print buffer - bool Print(trpgPrintBuffer &) const; + bool Print(trpgPrintBuffer &) const; // Reset back to a clean state void Reset(void); @@ -1023,7 +1023,7 @@ TX_EXDECL class TX_CLDECL trpgRange : public trpgReadWriteable /* The Range Table is new to 2.0. The goal is to provide information about certain classes of features within a TerraPage database. It's intended to solve the following problem. - + Let's say that you have an Image Generator that must draw a given TerraPage database at 60Hz. However, it's only hitting 30Hz reliably. Often, some feature set (e.g. bushes) must be sacrified in order to reach the target frame rate. @@ -1046,7 +1046,7 @@ TX_EXDECL class TX_CLDECL trpgRange : public trpgReadWriteable allow run-time systems to tell users what they're dropping (or allow them to pick). The priority is there to tell systems what to get rid of first (according to the user who build the TerraPage archive). - + Priorities are relative to each other within the Range Table. There can be duplicates and there may be holes in the numbering. @@ -1059,30 +1059,30 @@ TX_EXDECL class TX_CLDECL trpgRangeTable : public trpgReadWriteable ~trpgRangeTable(void); // Get the given range info - bool GetRange(int id,trpgRange &) const; + bool GetRange(int id,trpgRange &) const; // Get the number of entries in the table - int GetNumRanges() {return int(rangeMap.size());} + int GetNumRanges() {return int(rangeMap.size());} // Set the range info for the given ID - bool SetRange(int id,trpgRange &); + bool SetRange(int id,trpgRange &); // Add a new range and return the ID - int AddRange(trpgRange &); + int AddRange(trpgRange &); // Find a matching range and return it or add a new one if needed - int FindAddRange(trpgRange &); + int FindAddRange(trpgRange &); // Writes this class to a write buffer - bool Write(trpgWriteBuffer &); + bool Write(trpgWriteBuffer &); // Reads this class from a read buffer - bool Read(trpgReadBuffer &); + bool Read(trpgReadBuffer &); // Prints this class to a print buffer - bool Print(trpgPrintBuffer &) const; + bool Print(trpgPrintBuffer &) const; // Resets the contents back to empty - void Reset(void); + void Reset(void); // Assignment operator trpgRangeTable & operator = (const trpgRangeTable &); @@ -1108,7 +1108,7 @@ TX_EXDECL class TX_CLDECL trpgRangeTable : public trpgReadWriteable If you're doing a TerraPage reader you'll get a trpgMatTable from the trpgr_Archive. This is your central index for materials. If you can handle the multiple channels/sub-tables then you can access those as you need. If you can't, just use 0 for the sub-table index where appropriate. - + If you're doing a TerraPage writer you'll need to build up a trpgMatTable to pass to trpgwArchive. If you're only doing a single sub-table (i.e. visible materials only) just use AddMaterial and add them as you go. The trpgMaterial object you build up @@ -1124,25 +1124,25 @@ TX_EXDECL class TX_CLDECL trpgMatTable : public trpgReadWriteable /* If you intend to have more than one material sub-table you'll need to set this first before doing anything else. */ - void SetNumTable(int); + void SetNumTable(int); /* This sets the total number of materials. Each sub-table will have this many of its own materials. If you call this function you can't use AddMaterial. */ - void SetNumMaterial(int); + void SetNumMaterial(int); /* Sets a material definition for the given sub-table material ID combination. If you only have one sub-table you can use AddMaterial instead. The two argument version assumes subTable = 0 */ - //void SetMaterial(int subTable,int mat,const trpgMaterial &); - void SetMaterial(int,const trpgMaterial &); - + //void SetMaterial(int subTable,int mat,const trpgMaterial &); + void SetMaterial(int,const trpgMaterial &); + /* This function should be used if you only have a single material sub-table. It searches for a matching material and then adds a new one if it doesn't find a match. The new (or old) ID is returned. */ - int AddMaterial(const trpgMaterial &,bool lookForExisting=true); + int AddMaterial(const trpgMaterial &,bool lookForExisting=true); // The following method is unused currently @@ -1150,24 +1150,24 @@ TX_EXDECL class TX_CLDECL trpgMatTable : public trpgReadWriteable It searches for a matching material and then adds a new one if it doesn't find a match. The new (or old) ID is returned. */ - //int AddMaterialInSubtable(const trpgMaterial &,int table,bool lookForExisting=true); + //int AddMaterialInSubtable(const trpgMaterial &,int table,bool lookForExisting=true); /* Return the number of sub-tables. This will, most commonly, be 1. Any value more than 1 means the archive has alternate material definitions (think IR or Radar versions). */ - bool GetNumTable(int &) const; + bool GetNumTable(int &) const; /* The number of materials per sub-table. Each sub-table has the same number of materials. So there will be N x M number of materials total, but you'll only see M of them at any given time. */ - bool GetNumMaterial(int &) const; + bool GetNumMaterial(int &) const; /* Returns the material definition for the given subTable and the given material ID. The most common subTable will be 0 (visual). The material ID comes from the value(s) in trpgGeometry. */ - bool GetMaterial(int subTable,int matID,trpgMaterial &) const; + bool GetMaterial(int subTable,int matID,trpgMaterial &) const; /* This is a convenience method for getting a reference to a trpgMaterial object. The reason you might want to do this is if you don't want to create a full @@ -1177,16 +1177,16 @@ TX_EXDECL class TX_CLDECL trpgMatTable : public trpgReadWriteable const trpgMaterial *GetMaterialRef(int,int) const; // Validity check - bool isValid(void) const; + bool isValid(void) const; // Resets the contents back to empty - void Reset(void); + void Reset(void); // Writes this class to a write buffer - bool Write(trpgWriteBuffer &); + bool Write(trpgWriteBuffer &); // Reads this class from a read buffer - bool Read(trpgReadBuffer &); + bool Read(trpgReadBuffer &); // Prints this class to a print buffer - bool Print(trpgPrintBuffer &) const; + bool Print(trpgPrintBuffer &) const; protected: @@ -1251,40 +1251,40 @@ TX_EXDECL class TX_CLDECL trpgTexture : public trpgReadWriteable */ typedef enum { - trpg_RGB8, - trpg_RGBA8, - trpg_INT8, - trpg_INTA8, - trpg_FXT1, - trpg_Filler, // This is not a texture format. It's here to keep the numbering consistent - trpg_RGBX, // MCM no longer - trpg_Unknown, - trpg_DDS, - trpg_DXT1, - trpg_DXT3, - trpg_DXT5, - // This is a bit ugly, but we can't change the size of the texture record without - // breaking existing readers. So there will be multiple MCM types to indicate the number - // of bands and the nature of the extra channels, if any - trpg_MCM5, - trpg_MCM6R, - trpg_MCM6A, - trpg_MCM7RA, - trpg_MCM7AR + trpg_RGB8, + trpg_RGBA8, + trpg_INT8, + trpg_INTA8, + trpg_FXT1, + trpg_Filler, // This is not a texture format. It's here to keep the numbering consistent + trpg_RGBX, // MCM no longer + trpg_Unknown, + trpg_DDS, + trpg_DXT1, + trpg_DXT3, + trpg_DXT5, + // This is a bit ugly, but we can't change the size of the texture record without + // breaking existing readers. So there will be multiple MCM types to indicate the number + // of bands and the nature of the extra channels, if any + trpg_MCM5, + trpg_MCM6R, + trpg_MCM6A, + trpg_MCM7RA, + trpg_MCM7AR } ImageType; // Set the texture name. - void SetName(const char *); + void SetName(const char *); /* This is the texture name. You pass in a string of a pre-defined length and it returns the texture name in that. */ - bool GetName(char *retStr,int strLen) const; + bool GetName(char *retStr,int strLen) const; /* Sets the number of tiles this texture is used in. This hint is used by readers to determine texture pageability. */ - void SetNumTile(int); + void SetNumTile(int); /* Instead of calling SetNumTile after you've built a database, you can call AddTile as you encounter each texture reference (per tile). */ - void AddTile(void); + void AddTile(void); /* This tells you the number of tiles this texture is used in. You can use this to do texture paging (if you can support it). It's a pretty @@ -1294,83 +1294,83 @@ TX_EXDECL class TX_CLDECL trpgTexture : public trpgReadWriteable Template texture, it will be set to the total number of uses of the template (which should be fairly large). */ - bool GetNumTile(int &) const; + bool GetNumTile(int &) const; // Retrieve the image mode for this texture. See ImageMode for details. - bool GetImageMode(ImageMode &) const; + bool GetImageMode(ImageMode &) const; // Retrieve the image type for this texture. See ImageType for details. // This method is only used if ImageMode is Local or Template - bool GetImageType(ImageType &) const; + bool GetImageType(ImageType &) const; // Retrieve the size of this image. Valid only for Local and Template textures. - bool GetImageSize(trpg2iPoint &) const; + bool GetImageSize(trpg2iPoint &) const; // Get the location of a Local image - bool GetImageAddr(trpgwAppAddress &) const; + bool GetImageAddr(trpgwAppAddress &) const; // Figure out the image depth from the type - bool GetImageDepth(int32 &depth) const; + bool GetImageDepth(int32 &depth) const; // Determine whether this image (must be Local or Template) has all its mipmaps - bool GetIsMipmap(bool &) const; + bool GetIsMipmap(bool &) const; // Set the image mode of this texture. Used by writers only. - void SetImageMode(ImageMode); + void SetImageMode(ImageMode); // Set the image type of this texture. See GetImageType for details. - void SetImageType(ImageType); + void SetImageType(ImageType); // Set the image size of this texture. See GetImageSize for details - void SetImageSize(const trpg2iPoint &); + void SetImageSize(const trpg2iPoint &); // Set the image location (For Local images only) - void SetImageAddr(const trpgwAppAddress &); + void SetImageAddr(const trpgwAppAddress &); // Set whether or not this is a full set of mipmaps - void SetIsMipmap(bool); + void SetIsMipmap(bool); // Set the storage sizes for all mipmap levels - // void SetStorageSizes(vector &); + // void SetStorageSizes(vector &); // Get the storage sizes for all mipmap levels. - // bool GetStorageSizes(const vector *) const; + // bool GetStorageSizes(const vector *) const; // Set the number of mipmap levels - void SetNumMipmap(int); + void SetNumMipmap(int); // Set the number of layers used in an RGBX image - void SetNumLayer(int); + void SetNumLayer(int); // Get the number of layers used in an RGBX image. RGBX images are typically for // sensors and contain arbitrary data which is not visual. - bool GetNumLayer(int &) const; + bool GetNumLayer(int &) const; /* Utility to figure out the number of mipmap levels this image would have. Only really necessary for Local or Template images. */ - int32 CalcNumMipmaps() const; + int32 CalcNumMipmaps() const; // Calculate the total size of this texture - int32 CalcTotalSize() const; + int32 CalcTotalSize() const; // Returns the size of a given mip level - int32 MipLevelSize(int miplevel); + int32 MipLevelSize(int miplevel); // Returns the offset of the mip level in the whole texture data buffer - int32 MipLevelOffset(int miplevel); + int32 MipLevelOffset(int miplevel); // Validity check - bool isValid(void) const; + bool isValid(void) const; // Resets the contents back to empty - void Reset(void); + void Reset(void); // Writes this class to a write buffer - bool Write(trpgWriteBuffer &); + bool Write(trpgWriteBuffer &); // Reads this class from a read buffer - bool Read(trpgReadBuffer &); + bool Read(trpgReadBuffer &); // Prints this class to a print buffer - bool Print(trpgPrintBuffer &) const; + bool Print(trpgPrintBuffer &) const; trpgTexture & operator = (const trpgTexture &); int operator == (const trpgTexture &) const; @@ -1446,26 +1446,26 @@ TX_EXDECL class TX_CLDECL trpgTexTable : public trpgReadWriteable combination with SetTexture. If you can, you should use AddTexture and FindAddTexture instead. */ - void SetNumTextures(int); + void SetNumTextures(int); /* Adds the given texture to the table and increments the total texture count. If you use this, you should not use SetNumTextures and SetTexture. */ - int AddTexture(const trpgTexture &); + int AddTexture(const trpgTexture &); /* This is the same as AddTexture except that it searches for a matching texture first. This is convenient for writers who aren't keeping track of their own textures internally. */ - int FindAddTexture(const trpgTexture &); + int FindAddTexture(const trpgTexture &); /* This sets the given texture ID to be the trpgTexture passed in. It's used in combination with SetNumTextures. Use AddTexture or FindAddTexture instead if you can. */ - void SetTexture(int texID,const trpgTexture &); + void SetTexture(int texID,const trpgTexture &); // Returns the number of textures in this table - bool GetNumTextures(int &) const; + bool GetNumTextures(int &) const; // This returns the trpgTexture corresponding to the given ID (from a trpgMaterial) - bool GetTexture(int texID,trpgTexture &) const; + bool GetTexture(int texID,trpgTexture &) const; /* Does the same thing as GetTexture only it returns a pointer instead. You would use this if you don't want a new trpgTexture created for you. Assume the value it returns is only good until the next GetTextureRef call. @@ -1473,34 +1473,34 @@ TX_EXDECL class TX_CLDECL trpgTexTable : public trpgReadWriteable const trpgTexture *GetTextureRef(int) const; // Validity check - bool isValid(void) const; + bool isValid(void) const; // Resets the contents back to empty - void Reset(void); + void Reset(void); // Writes this class to a write buffer - bool Write(trpgWriteBuffer &); + bool Write(trpgWriteBuffer &); // Reads this class from a read buffer - bool Read(trpgReadBuffer &); + bool Read(trpgReadBuffer &); // Prints this class to a print buffer - bool Print(trpgPrintBuffer &) const; + bool Print(trpgPrintBuffer &) const; trpgTexTable & operator = (const trpgTexTable &); const trpgTexture *FindByName(const char *name, int &texid) const; - void SetCurrentBlock(int row, int col) + void SetCurrentBlock(int row, int col) { - currentRow = row; - currentCol = col; + currentRow = row; + currentCol = col; } //bool dumpGeoTypicalTextures(trpgwImageHelper *ihelper); typedef std::map TextureMapType; TextureMapType *getTextureMap() { - return &textureMap; + return &textureMap; } protected: - + TextureMapType textureMap; //These are used to initialize the row/col values for //multi-archive archives @@ -1545,46 +1545,46 @@ TX_EXDECL class TX_CLDECL trpgModel : public trpgReadWriteable // Sets the name of the external model file and sets this model to External type. // 5.28.04 - It will not set the model to be as of external type. Use the method // from below to set the type of the model - void SetName(const char *); + void SetName(const char *); // Sets the on-disk reference to an internal model and sets this model to Internal type. // 5.28.04 - It will not set the model to be as of internal type. Use the method // from below to set the type of the model - void SetReference(trpgDiskRef); + void SetReference(trpgDiskRef); // Sets the model type - void SetType(int); + void SetType(int); /* Models are reference counted (per-tile). It's up to the writer to set this value. */ - void SetNumTiles(int); + void SetNumTiles(int); /* TerraPage writers can use AddTile (starts at 0) every time they use this model in a tile. Note that this is not for every instance within a tile. So if you use a model 40 times within a tile, you call AddTile once. This is used instead of SetNumTiles. */ - void AddTile(void); + void AddTile(void); /* Returns the type (Local or External) of this model */ - bool GetType(int &); + bool GetType(int &); /* If the model is external, this returns the file name of that model. You pass in a string and a length and it copies the filename into that. */ - bool GetName(char *ret,int strLen) const; + bool GetName(char *ret,int strLen) const; /* If the model is internal, this returns the disk reference to it. At some future data you'll be able to simply read these out of an archive. */ - bool GetReference(trpgDiskRef &) const; + bool GetReference(trpgDiskRef &) const; /* Models are reference counted, like trpgTexture objects. You can use this value to determine whether or not you should page models. */ - bool GetNumTiles(int &) const; + bool GetNumTiles(int &) const; // Validity check - bool isValid(void) const; + bool isValid(void) const; // Resets the contents back to empty - void Reset(void); + void Reset(void); // Writes this class to a write buffer - bool Write(trpgWriteBuffer &); + bool Write(trpgWriteBuffer &); // Reads this class from a read buffer - bool Read(trpgReadBuffer &, bool); + bool Read(trpgReadBuffer &, bool); // Prints this class to a print buffer - bool Print(trpgPrintBuffer &) const; + bool Print(trpgPrintBuffer &) const; trpgModel & operator = (const trpgModel &); @@ -1622,22 +1622,22 @@ TX_EXDECL class TX_CLDECL trpgModelTable : public trpgReadWriteable /* Set the total number of models in the table. Use this in conjunction with SetModel. If you can, use AddModel isntead of either of these. */ - void SetNumModels(int); + void SetNumModels(int); /* Add the given model to the table. Makes a copy of the model you pass in and returns the new model ID which you'll need to reference in trpgModelRef. */ - int AddModel(trpgModel &); + int AddModel(trpgModel &); /* Look for a given model. If it's not there, add it. */ - int FindAddModel(trpgModel &); + int FindAddModel(trpgModel &); /* Sets the model definition corresponding to the given ID. Use this in conjunction with SetNumModels. */ - void SetModel(int,const trpgModel &); + void SetModel(int,const trpgModel &); // Returns the number of models in this table - bool GetNumModels(int &) const; + bool GetNumModels(int &) const; /* Returns the Nth model. trpgModelRef objects point into this table and that is where the model ID comes from. */ - bool GetModel(int modID,trpgModel &) const; + bool GetModel(int modID,trpgModel &) const; /* The same as GetModel only it returns a pointer to the trpgModel instead. Use this if you don't want to create a copy of the model. @@ -1646,25 +1646,25 @@ TX_EXDECL class TX_CLDECL trpgModelTable : public trpgReadWriteable trpgModel *GetModelRef(int); // Validity check - bool isValid(void) const; + bool isValid(void) const; // Resets the contents back to empty - void Reset(void); + void Reset(void); // Writes this class to a write buffer - bool Write(trpgWriteBuffer &); + bool Write(trpgWriteBuffer &); // Reads this class from a read buffer - bool Read(trpgReadBuffer &); + bool Read(trpgReadBuffer &); // Prints this class to a print buffer - bool Print(trpgPrintBuffer &) const; + bool Print(trpgPrintBuffer &) const; bool FindByName(const char *name, unsigned int &mId); typedef std::map ModelMapType; ModelMapType *GetModelMap() { - return &modelsMap; + return &modelsMap; } protected: - + ModelMapType modelsMap; }; @@ -1689,56 +1689,56 @@ TX_EXDECL class TX_CLDECL trpgTileTable : public trpgReadWriteable ~trpgTileTable(void); // Set the tile storage mode: external or local - void SetMode(TileMode); + void SetMode(TileMode); // Set the total number of LODs // For version 2.1 only lod 0 is stored in the table - void SetNumLod(int numLod); + void SetNumLod(int numLod); // Set the number of tiles in each dimenion for each terrain LOD // This must agree with trpgHeader - void SetNumTiles(int numX,int numY,int lod); + void SetNumTiles(int numX,int numY,int lod); // Set the external address of a given tile as well as its Z value - void SetTile(int x,int y,int lod,trpgwAppAddress &,float32 min,float32 max); + void SetTile(int x,int y,int lod,trpgwAppAddress &,float32 min,float32 max); // Local or external tiles - bool GetMode(TileMode &) const; + bool GetMode(TileMode &) const; // Get the disk reference (local) - bool GetTile(int x,int y,int lod,trpgwAppAddress &,float32 &min,float32 &max) const; + bool GetTile(int x,int y,int lod,trpgwAppAddress &,float32 &min,float32 &max) const; // Validity check - bool isValid(void) const; + bool isValid(void) const; // Reads this class from a read buffer - void Reset(void); + void Reset(void); // Writes this class to a write buffer - bool Write(trpgWriteBuffer &); + bool Write(trpgWriteBuffer &); // Reads this class from a read buffer - bool Read(trpgReadBuffer &); + bool Read(trpgReadBuffer &); // Prints this class to a print buffer - bool Print(trpgPrintBuffer &) const; + bool Print(trpgPrintBuffer &) const; /** * SetCurrentBlock is used in two cases: * 1. When building a block specific tile archive (MMB and non-MMB). (local is TRUE) * 2. When merging several blocks into memory for visualization. (local is FALSE) **/ - void SetCurrentBlock(int row, int col, bool local) + void SetCurrentBlock(int row, int col, bool local) { - currentRow = row; - currentCol = col; - localBlock = local; + currentRow = row; + currentCol = col; + localBlock = local; } protected: TileMode mode; class LodInfo { - public: - int numX,numY; - // Tile addresses into external Appendable files - std::vector addr; - // Elevation of the midpoint of each tile - // This is used for calculating bounding boxes - std::vector elev_min; - std::vector elev_max; + public: + int numX,numY; + // Tile addresses into external Appendable files + std::vector addr; + // Elevation of the midpoint of each tile + // This is used for calculating bounding boxes + std::vector elev_min; + std::vector elev_max; }; std::vector lodInfo; //These are used to initialize the row/col values for @@ -1767,7 +1767,7 @@ TX_EXDECL class TX_CLDECL trpgLocalMaterial : public trpgReadWriteable ~trpgLocalMaterial(void); // Set the base material for this local material - void SetBaseMaterial(int32 matSubTable,int32 matID); + void SetBaseMaterial(int32 matSubTable,int32 matID); /* Get the base material for this local material. Base materials define the colors, specularity, texture environments, and in @@ -1782,68 +1782,68 @@ TX_EXDECL class TX_CLDECL trpgLocalMaterial : public trpgReadWriteable textures per polygon makes my head hurt in general). // 2003-06-17. Your prophecy (my headache) has come true. MD */ - bool GetBaseMaterial(int32 &matSubTable,int32 &matID) const; + bool GetBaseMaterial(int32 &matSubTable,int32 &matID) const; class SubImageInfo { public: - int32 sx,sy; // Source (sx,sy) in pixels - int32 ex,ey; // Source (ex,ey) in pixels - int32 destWidth,destHeight; // Size of destination image (in pixels) + int32 sx,sy; // Source (sx,sy) in pixels + int32 ex,ey; // Source (ex,ey) in pixels + int32 destWidth,destHeight; // Size of destination image (in pixels) }; // Set the sub image info (only for writers) - void SetSubImageInfo(const SubImageInfo &); + void SetSubImageInfo(const SubImageInfo &); /* Get the sub image info. This is valid only for Global images (you can check what a given Local Material is by looking at the base material's texture). */ - bool GetSubImageInfo(SubImageInfo &) const; + bool GetSubImageInfo(SubImageInfo &) const; // Set the address info (only for writers) - void SetAddr(const trpgwAppAddress &); + void SetAddr(const trpgwAppAddress &); // Set address info for one of multiple local textures - void SetNthAddr(unsigned int subtable, const trpgwAppAddress &); + void SetNthAddr(unsigned int subtable, const trpgwAppAddress &); /* Get the address (location in an archive) for an image. This is valid for Local images only. You can determine what a Local Material refers to by looking in its base material's texture. */ - bool GetAddr(trpgwAppAddress &) const; + bool GetAddr(trpgwAppAddress &) const; // Get address info for one of multiple local textures - bool GetNthAddr(unsigned int subtable, trpgwAppAddress &) const; + bool GetNthAddr(unsigned int subtable, trpgwAppAddress &) const; // Get the number of local images associated with this local material // Tile Local Images only - bool GetNumLocals(int &) const; + bool GetNumLocals(int &) const; // Set the storage sizes for all mipmap levels - // bool SetStorageSizes(vector &); + // bool SetStorageSizes(vector &); // Get the storage sizes for all mipmap levels. - // bool GetStorageSizes(const vector *) const; + // bool GetStorageSizes(const vector *) const; // Validity check - bool isValid(void) const; + bool isValid(void) const; // Reads this class from a read buffer - void Reset(void); + void Reset(void); // Writes this class to a write buffer - bool Write(trpgWriteBuffer &); + bool Write(trpgWriteBuffer &); // Reads this class from a read buffer - bool Read(trpgReadBuffer &); + bool Read(trpgReadBuffer &); // Prints this class to a print buffer - bool Print(trpgPrintBuffer &) const; + bool Print(trpgPrintBuffer &) const; protected: int32 baseMatTable,baseMat; // These are valid for Global images int32 sx,sy,ex,ey,destWidth,destHeight; // Storage sizes for each mipmap level. Important for compressed textures. - // vector storageSize; + // vector storageSize; // This is valid only for Tile Local images std::vector addr; }; @@ -1886,7 +1886,7 @@ TX_EXDECL class TX_CLDECL trpgLocalMaterial : public trpgReadWriteable If you want to page models, you can do so by looking at the list of model IDs used in a tile. - + If you're doing a TerraPage writer you will need to construct one of these for each tile that you build (remember that tiles are per-terrain LOD). You'll want to call AddMaterial for every material that you use in a tile and AddModel @@ -1902,73 +1902,73 @@ TX_EXDECL class TX_CLDECL trpgTileHeader : public trpgReadWriteable ~trpgTileHeader(void); /* Add the given material reference to this tile if it's not already there. The ID passed in refers to a trpgMatTable. */ - void AddMaterial(int); + void AddMaterial(int); /* Add the given model reference to this tile if it's not already there. The ID passed in refers to a trpgModelTable. */ - void AddModel(int); + void AddModel(int); /* Add the given local material to the list of local materials in this tile. Local materials are used to page sub-pieces of very large images and are referenced by trpgGeometry nodes (in their material indices) within a given tile. Local materials can't be referenced across tiles. */ - void AddLocalMaterial(trpgLocalMaterial &); + void AddLocalMaterial(trpgLocalMaterial &); // {secret} - void SetDate(int32); + void SetDate(int32); /* Set the given material reference to the given value. It's easier to use AddMaterial(), if possible. */ - void SetMaterial(int no,int id); + void SetMaterial(int no,int id); /* Set the given model reference (in this tile) to the given value It's easier to use AddModel(), if possible. */ - void SetModel(int no,int id); + void SetModel(int no,int id); // Returns the number of materials used in this tile - bool GetNumMaterial(int32 &) const; + bool GetNumMaterial(int32 &) const; /* Return the material ID of the Nth material reference. The ID returned points into a trpgMatTable. */ - bool GetMaterial(int32 nth,int32 &matID) const; + bool GetMaterial(int32 nth,int32 &matID) const; // This is the number of models used in this tile - bool GetNumModel(int32 &) const; + bool GetNumModel(int32 &) const; /* Gets the model ID of the Nth model reference. The ID returned points into a trpgModelTable. */ - bool GetModel(int32 nth,int32 &modID) const; + bool GetModel(int32 nth,int32 &modID) const; // Returns the number of local materials in this tile - bool GetNumLocalMaterial(int32 &) const; + bool GetNumLocalMaterial(int32 &) const; /* Return the given local material. Local materials are used to page sub-pieces of extremely large images. The Local Material list within a tile is distinct from the list of materials used within a tile. Local materials will be referenced by trpgGeometry nodes within a given tile. */ - bool GetLocalMaterial(int32 nth,trpgLocalMaterial &locMat) const; + bool GetLocalMaterial(int32 nth,trpgLocalMaterial &locMat) const; /* Return a pointer to the list of locally defined materials. See GetLocalMaterial for an explantion of local materials. */ const std::vector *GetLocalMaterialList(void) const; // {secret} - bool GetDate(int32 &) const; + bool GetDate(int32 &) const; // Validity check - bool isValid(void) const; + bool isValid(void) const; // Resets the contents back to empty - void Reset(void); + void Reset(void); // Writes this class to a write buffer - bool Write(trpgWriteBuffer &); + bool Write(trpgWriteBuffer &); // Reads this class from a read buffer - bool Read(trpgReadBuffer &); + bool Read(trpgReadBuffer &); // Prints this class to a print buffer - bool Print(trpgPrintBuffer &) const; - void SetBlockNo(int row, int col) + bool Print(trpgPrintBuffer &) const; + void SetBlockNo(int row, int col) { - this->row = row; - this->col = col; + this->row = row; + this->col = col; } - void GetBlockNo(int &row, int &col) + void GetBlockNo(int &row, int &col) { - row = this->row; - col = this->col; + row = this->row; + col = this->col; } protected: std::vector matList; @@ -2079,30 +2079,30 @@ TX_EXDECL class TX_CLDECL trpgGeometry : public trpgReadWriteable trpgGeometry(void); ~trpgGeometry(void); typedef enum {Points,LineStrips,LineLoops,Lines,Polygons,TriStrips, - TriFans,Triangles,QuadStrips,Quads} PrimType; + TriFans,Triangles,QuadStrips,Quads} PrimType; // Set the primitive type for the geometry node - void SetPrimType(PrimType type); + void SetPrimType(PrimType type); /* Some primitive types require lengths. These include TriStrips and TriFans, but not Triangles, for example. */ - void SetPrimLengths(int,const int *); + void SetPrimLengths(int,const int *); /* Add a primitive length on to the end of the current primLength array. Use this if you're adding geometry one vertex at a time. */ - void AddPrimLength(int); + void AddPrimLength(int); /* This just increments the number of primitives in the structure. Use this if you're adding geometry one vertex at a time for a Triangle array, for example. */ - void AddPrim(void); + void AddPrim(void); /* Set the total number of primitives. You would use this only when the PrimType does not require primitive lengths (e.g. Triangles, but not TriStrips). Use SetPrimLengths() or AddPrimLength() in that case. */ - void SetNumPrims(int); // Only when there are no primitive lengths + void SetNumPrims(int); // Only when there are no primitive lengths /* This function sets the total number of materials applied to this group of geometry. If you're only using one material, trpgGeometry defaults to 1, so you can just do a SetMaterial() and ignore this. */ - void SetNumMaterial(int); + void SetNumMaterial(int); /* Set the given material instance (in this trpgGeometry node) to the given material ID. The material ID is an index into a trpgMatTable. You would need to do a SetNumMaterial() call first, before any number of SetMaterial() @@ -2113,18 +2113,18 @@ TX_EXDECL class TX_CLDECL trpgGeometry : public trpgReadWriteable GetMaterial, however you must set them as negative so that GetMaterial can set its isLocal bit on return. */ - void SetMaterial(int which,int matID,bool isLocal=false); + void SetMaterial(int which,int matID,bool isLocal=false); /* This is the same as repeated SetMaterial() calls. */ - void SetMaterials(int32 numMat,const int32 *matIDs); + void SetMaterials(int32 numMat,const int32 *matIDs); /* This adds the given material ID to the end of the material list. You can use this instead of SetNumMaterial() and SetMaterial(). */ - int AddMaterial(int matID); + int AddMaterial(int matID); // These are primitive types used within the trpgGeometry structure. enum {VertexFloat,VertexDouble,NormalFloat,NormalDouble, - Color,TextureFloat,TextureDouble,EdgeFlag}; + Color,TextureFloat,TextureDouble,EdgeFlag}; /* Used to tell some of the trpgGeometry methods what kind of data they're getting */ @@ -2135,13 +2135,13 @@ TX_EXDECL class TX_CLDECL trpgGeometry : public trpgReadWriteable The num passed in is the number of vertices, not the number of individual floats or doubles (as with GetNumVertex). */ - void SetVertices(int num,const float32 *); - void SetVertices(int num,const float64 *); + void SetVertices(int num,const float32 *); + void SetVertices(int num,const float64 *); /* This method will add a vertex to the end of the appropriate data array (either float or double, but never both). You would use this method if you were building up a trpgGeometry structure vertex by vertex. */ - void AddVertex(DataType type,trpg3dPoint &); + void AddVertex(DataType type,trpg3dPoint &); /* Binding type used by colors, normals, and textures (just PerPrim). */ typedef enum {Overall,PerPrim,PerVertex} BindType; @@ -2152,13 +2152,13 @@ TX_EXDECL class TX_CLDECL trpgGeometry : public trpgReadWriteable num is the number of individual normals, not float values, unlike the GetNumNormal() call. */ - void SetNormals(int num,BindType bind,const float32 *); - void SetNormals(int num,BindType bind,const float64 *); + void SetNormals(int num,BindType bind,const float32 *); + void SetNormals(int num,BindType bind,const float64 *); /* This method is used to add normals one by one of the given type. You would use this if you were adding geometry one vertex at a time in conjuntion with AddVertex(). */ - void AddNormal(DataType type,trpg3dPoint &); + void AddNormal(DataType type,trpg3dPoint &); /* This constant is used to select the type of a color array passed to SetColors(). */ @@ -2168,7 +2168,7 @@ TX_EXDECL class TX_CLDECL trpgGeometry : public trpgReadWriteable these color arrays as you like, they're simply stored in an array for later use. */ - void SetColors(int num,ColorType type,BindType bind,const trpgColor *); + void SetColors(int num,ColorType type,BindType bind,const trpgColor *); /* The SetTexCoords() methods set a list of texture coordinates. This essentially builds a trpgTexData class and pushes it onto the current list of texture coordinate sets. Choose the appropriate method based @@ -2177,31 +2177,31 @@ TX_EXDECL class TX_CLDECL trpgGeometry : public trpgReadWriteable bind should be PerPrim in all cases. */ - void SetTexCoords(int num,BindType bind,const float32 *); - void SetTexCoords(int num,BindType bind,const float64 *); + void SetTexCoords(int num,BindType bind,const float32 *); + void SetTexCoords(int num,BindType bind,const float64 *); /* This is the same as SetTexCoords(0,bind,NULL) */ - void AddTexCoords(BindType bind); + void AddTexCoords(BindType bind); /* This method adds a texture coordinate to array n. You would use this if you were adding vertices one at a time. */ - void AddTexCoord(DataType type,trpg2dPoint &,int n=0); + void AddTexCoord(DataType type,trpg2dPoint &,int n=0); /* This method adds a texture coordinate to each trpgTexData. You would use this if you were adding vertices one at a time with multiple materials. */ - void AddTexCoord(DataType type,std::vector &pts); + void AddTexCoord(DataType type,std::vector &pts); /* Edge flags are used by some primitives in OpenGL. We don't typically use them, but they can be read and written with TerraPage. */ - void SetEdgeFlags(int num,const char *); + void SetEdgeFlags(int num,const char *); /* Returns the primitive type for this trpgGeometry structure. */ - bool GetPrimType(PrimType &type) const; + bool GetPrimType(PrimType &type) const; /* Number of primitives in this structure. Primitives are things like a single triangle, a triangle strip or fan. Some primitives require a primitive length array. */ - bool GetNumPrims(int &num) const; + bool GetNumPrims(int &num) const; /* This returns the primitive length array. Some primitive types, like TriStrips or TriFans (but not Triangles) require a primitive length array to tell you how to break up the vertex/normal/texture/color @@ -2209,67 +2209,67 @@ TX_EXDECL class TX_CLDECL trpgGeometry : public trpgReadWriteable of a certain length (returned by GetNumPrims()) and will only be valid for some primitive types. */ - bool GetPrimLengths(int *lenArray) const; + bool GetPrimLengths(int *lenArray) const; /* TerraPage supports multiple materials per geometry set. This method tells you how many are applied to this structure. There will always be at least one. */ - bool GetNumMaterial(int &num) const; + bool GetNumMaterial(int &num) const; /* Returns the material ID for a material instance. num is the nth material instance. matId is an index into a trpgMatTable. isLocal is true if the given material is local to this tile. Local materials are only used to page small pieces of a larger image. */ - bool GetMaterial(int num,int32 &matID,bool &isLocal) const; + bool GetMaterial(int num,int32 &matID,bool &isLocal) const; /* This returns num_vertex. The function returns the length of the vertex array dived by 3, which is the total number of vertices. */ - bool GetNumVertex(int &num) const; + bool GetNumVertex(int &num) const; /* The GetVertices() methods return a list of vertices in the given form (32 or 64 bit floating point). These functions will convert to the appropriate format, just ask for the one you need. The length of the vertex array is determined by GetNumVertex(), which returns 3* the number of vertices. */ - bool GetVertices(float32 *) const; - bool GetVertices(float64 *) const; + bool GetVertices(float32 *) const; + bool GetVertices(float64 *) const; /* This method lets you get an individual vertex. The number of vertices can be determined by GetNumVertex()/3. */ - bool GetVertex(int id,trpg3dPoint &) const; + bool GetVertex(int id,trpg3dPoint &) const; /* GetNumNormal() returns the number of normals. See GetNumVertex() for an explanation of why. */ - bool GetNumNormal(int &num) const; + bool GetNumNormal(int &num) const; /* Much, like GetVertices(), these methods will copy the contents of the normal array into the array passed in. They will convert the contents to the appropriate format (32 or 64 bit floating point). The length of the input array can be determined by GetNumNormal(). */ - bool GetNormals(float32 *) const; - bool GetNormals(float64 *) const; + bool GetNormals(float32 *) const; + bool GetNormals(float64 *) const; /* This returns the number of color sets in the trpgGeometry structure. There can be one color set per ColorType. Color sets are either per vertex, per primitive, or per geometry unit (i.e. only one) arrays of color data. */ - bool GetNumColorSets(int &num) const; + bool GetNumColorSets(int &num) const; /* This method fills out the trpgColorInfo class that you pass in. The number of color sets is determined by GetNumColorSets and the structure you passed can be reused (to save memory). */ - bool GetColorSet(int id,trpgColorInfo *) const; + bool GetColorSet(int id,trpgColorInfo *) const; /* Returns the number of texture coordinate sets. There could (and should) be one texture coordinate set per material applied to this geometry. Tex Coord sets can be retrieved with GetTexCoordSet. */ - bool GetNumTexCoordSets(int &) const; + bool GetNumTexCoordSets(int &) const; /* This method returns the texture coordinate set specified by the given index. GetNumTexCoordSets determines the total number of texture coordinate sets. */ - bool GetTexCoordSet(int id,trpgTexData *) const; + bool GetTexCoordSet(int id,trpgTexData *) const; /* This method returns this trpgGeometry's texture coordinate set specified by the given index. GetNumTexCoordSets determines the total number of texture coordinate sets. @@ -2278,22 +2278,22 @@ TX_EXDECL class TX_CLDECL trpgGeometry : public trpgReadWriteable /* Returns the number of edge flags in this geometry node. Edge flags are used on certain primitive types, but are rather rare. */ - bool GetNumEdgeFlag(int &num) const; + bool GetNumEdgeFlag(int &num) const; /* This returns the edge flags for the current set of primitives. */ - bool GetEdgeFlags(char *) const; + bool GetEdgeFlags(char *) const; // Returns true if the trpgGeometry structure is valid - bool isValid(void) const; + bool isValid(void) const; // Resets the contents back to empty - void Reset(void); + void Reset(void); // Write self to a buffer - bool Write(trpgWriteBuffer &); + bool Write(trpgWriteBuffer &); // Read self from a buffer. Check isValid() afterwards - bool Read(trpgReadBuffer &); + bool Read(trpgReadBuffer &); // Prints this class to a print buffer - bool Print(trpgPrintBuffer &) const; + bool Print(trpgPrintBuffer &) const; protected: int primType; @@ -2341,36 +2341,36 @@ TX_EXDECL class TX_CLDECL trpgGroup : public trpgReadWriteable { public: trpgGroup(void); - virtual ~trpgGroup(void); + virtual ~trpgGroup(void); // Resets the contents back to empty - virtual void Reset(void); + virtual void Reset(void); /* Set the total number of children this group will have */ - virtual void SetNumChild(int); + virtual void SetNumChild(int); // Starting from 0, increments the number of children - virtual int AddChild(void); + virtual int AddChild(void); /* The writer is supposed to set this value to the number of children. */ - virtual bool GetNumChild(int &) const; + virtual bool GetNumChild(int &) const; /* Set the group ID */ - virtual void SetID(int); + virtual void SetID(int); // Returns the group ID - virtual bool GetID(int &) const; + virtual bool GetID(int &) const; /* Set the group name */ - void SetName(const char* ); + void SetName(const char* ); // Returns the group name - const char* GetName(void) const; + const char* GetName(void) const; // Validity check - virtual bool isValid(void) const; + virtual bool isValid(void) const; // Writes this class to a write buffer - virtual bool Write(trpgWriteBuffer &); + virtual bool Write(trpgWriteBuffer &); // Reads this class from a read buffer - bool Read(trpgReadBuffer &); + bool Read(trpgReadBuffer &); // Prints this class to a print buffer - bool Print(trpgPrintBuffer &) const; + bool Print(trpgPrintBuffer &) const; protected: int id; @@ -2444,30 +2444,30 @@ TX_EXDECL class TX_CLDECL trpgAttach : public trpgGroup trpgAttach(void); ~trpgAttach(void); // Resets the contents back to empty - void Reset(void); + void Reset(void); // Set the parent of the group/LOD/whatever to attach to when loaded in - void SetParentID(int); + void SetParentID(int); // Retrieve the parent ID we'll need to attach this thing into the scene graph - bool GetParentID(int &) const; + bool GetParentID(int &) const; /* The writer is supposed to set this value to a unique position with relation to its parent group. */ - void SetChildPos(int); + void SetChildPos(int); /* The child position is a hint as to which child this is in its parent group. That is, if there are 3 children, of which this is one, then it could be at child position 0, 1, or 3 in its parent. You can safely ignore this if you want to just this node to its parent's list of children. */ - bool GetChildPos(int &) const; + bool GetChildPos(int &) const; // Validity check - bool isValid(void) const; + bool isValid(void) const; // Writes this class to a write buffer - bool Write(trpgWriteBuffer &); + bool Write(trpgWriteBuffer &); // Reads this class from a read buffer - bool Read(trpgReadBuffer &); + bool Read(trpgReadBuffer &); // Prints this class to a print buffer - bool Print(trpgPrintBuffer &) const; + bool Print(trpgPrintBuffer &) const; protected: int parentID,childPos; @@ -2479,7 +2479,7 @@ TX_EXDECL class TX_CLDECL trpgChildRef : public trpgReadWriteable trpgChildRef(); ~trpgChildRef(); // Resets the contents back to empty - void Reset(); + void Reset(); // Set the tile grid location void SetTileLoc(int gx,int gy,int glod); @@ -2497,13 +2497,13 @@ TX_EXDECL class TX_CLDECL trpgChildRef : public trpgReadWriteable // Validity check - bool isValid(void) const; + bool isValid(void) const; // Writes this class to a write buffer - bool Write(trpgWriteBuffer &); + bool Write(trpgWriteBuffer &); // Reads this class from a read buffer - bool Read(trpgReadBuffer &); + bool Read(trpgReadBuffer &); // Prints this class to a print buffer - bool Print(trpgPrintBuffer &) const; + bool Print(trpgPrintBuffer &) const; protected: // Grid Location @@ -2537,14 +2537,14 @@ TX_EXDECL class TX_CLDECL trpgBillboard : public trpgGroup ~trpgBillboard(void); enum {Individual,Group}; // Set the type. See GetType for details. - void SetType(int); + void SetType(int); // Set the center. - void SetCenter(const trpg3dPoint &); + void SetCenter(const trpg3dPoint &); enum {Axial,World,Eye}; // Set the rotation mode. - void SetMode(int); + void SetMode(int); // Set the rotation axis if mode == Axial - void SetAxis(const trpg3dPoint &); + void SetAxis(const trpg3dPoint &); /* The type controls how the billboard node relates to its children. There are two modes: (1) Group - This is the obvious one. Everything below @@ -2555,29 +2555,29 @@ TX_EXDECL class TX_CLDECL trpgBillboard : public trpgGroup account the unique center of each one and rotate it around that. If you have some optimization scheme where you can deal with groups of billboards (ala Performer) it is valid to do so in the Individual case. */ - bool GetType(int &) const; + bool GetType(int &) const; /* Center of the thing to be rotated. For Group this does the obvious thing. For Individual it should be the center of the group of things you want to rotate. This has no use if you're going to rotate each primitive seperately, but if you've got some sort of optimized scheme for doing so (ala Performer) this information is useful. */ - bool GetCenter(trpg3dPoint &) const; + bool GetCenter(trpg3dPoint &) const; /* The mode will be one of: (1) Axial - rotate around the Axis. This is the normal one for tree. (2) Eye - Always rotate toward the eye point. (3) world. */ - bool GetMode(int &) const; + bool GetMode(int &) const; /* The axis used when GetMode returns Axial. */ - bool GetAxis(trpg3dPoint &) const; + bool GetAxis(trpg3dPoint &) const; // Resets the contents back to empty - void Reset(void); + void Reset(void); // Writes this class to a write buffer - bool Write(trpgWriteBuffer &); + bool Write(trpgWriteBuffer &); // Reads this class from a read buffer - bool Read(trpgReadBuffer &); + bool Read(trpgReadBuffer &); // Prints this class to a print buffer - bool Print(trpgPrintBuffer &) const; + bool Print(trpgPrintBuffer &) const; protected: int type; int mode; @@ -2629,45 +2629,45 @@ TX_EXDECL class TX_CLDECL trpgLod : public trpgReadWriteable trpgLod(void); ~trpgLod(void); // Set the calculated center - void SetCenter(const trpg3dPoint &); + void SetCenter(const trpg3dPoint &); // Set the number of children hint - void SetNumChild(int); + void SetNumChild(int); // Set the LOD information - void SetLOD(double in,double out,double width); + void SetLOD(double in,double out,double width); // Center of this LOD. Distance from the viewer is calculated from this. - bool GetCenter(trpg3dPoint &) const; + bool GetCenter(trpg3dPoint &) const; // Number of children hint. - bool GetNumChild(int &) const; + bool GetNumChild(int &) const; // LOD specific information. in and out can be switched. width is // the transition range for doing fading. - bool GetLOD(double &in,double &out,double &width) const; + bool GetLOD(double &in,double &out,double &width) const; // Set the group ID - void SetID(int); + void SetID(int); // Group IDs are used here the same way as in trpgGroup - bool GetID(int &) const; + bool GetID(int &) const; /* Set the lod name */ - void SetName(const char* ); + void SetName(const char* ); // Returns the lod name const char* GetName(void) const; // Set the range Index - void SetRangeIndex(int ri); + void SetRangeIndex(int ri); // Get the range index - bool GetRangeIndex(int &ri) const; + bool GetRangeIndex(int &ri) const; // Resets the contents back to empty - void Reset(void); + void Reset(void); // Writes this class to a write buffer - bool Write(trpgWriteBuffer &); + bool Write(trpgWriteBuffer &); // Reads this class from a read buffer - bool Read(trpgReadBuffer &); + bool Read(trpgReadBuffer &); // Prints this class to a print buffer - bool Print(trpgPrintBuffer &) const; + bool Print(trpgPrintBuffer &) const; protected: int numRange; @@ -2703,14 +2703,14 @@ TX_EXDECL class TX_CLDECL trpgLayer : public trpgGroup trpgLayer(void); ~trpgLayer(void); // Writes this class to a write buffer - bool Write(trpgWriteBuffer &); + bool Write(trpgWriteBuffer &); // Reads this class from a read buffer - bool Read(trpgReadBuffer &); + bool Read(trpgReadBuffer &); // Prints this class to a print buffer - bool Print(trpgPrintBuffer &) const; + bool Print(trpgPrintBuffer &) const; // Resets the contents back to empty - void Reset(void); + void Reset(void); protected: }; @@ -2726,20 +2726,20 @@ TX_EXDECL class TX_CLDECL trpgTransform : public trpgGroup ~trpgTransform(void); // Set the 4x4 matrix - void SetMatrix(const float64 *); + void SetMatrix(const float64 *); // Get the 4x4 matrix - bool GetMatrix(float64 *) const; + bool GetMatrix(float64 *) const; // Writes this class to a write buffer - bool Write(trpgWriteBuffer &); + bool Write(trpgWriteBuffer &); // Reads this class from a read buffer - bool Read(trpgReadBuffer &); + bool Read(trpgReadBuffer &); // Prints this class to a print buffer - bool Print(trpgPrintBuffer &) const; + bool Print(trpgPrintBuffer &) const; // Resets the contents back to empty - void Reset(void); + void Reset(void); protected: float64 m[4][4]; }; @@ -2769,24 +2769,24 @@ TX_EXDECL class TX_CLDECL trpgModelRef : public trpgReadWriteable trpgModelRef(void); ~trpgModelRef(void); // Set the model ID. Must come from a trpgModelTable - void SetModel(int); + void SetModel(int); // Set the 4x4 rotate/translate/scale matrix - void SetMatrix(const float64 *); + void SetMatrix(const float64 *); // Model ID pointing into a trpgModelTable - bool GetModel(int32 &) const; + bool GetModel(int32 &) const; // Positional matrix. Works just like a trpgTransform. - bool GetMatrix(float64 *) const; + bool GetMatrix(float64 *) const; // Writes this class to a write buffer - bool Write(trpgWriteBuffer &); + bool Write(trpgWriteBuffer &); // Reads this class from a read buffer - bool Read(trpgReadBuffer &); + bool Read(trpgReadBuffer &); // Prints this class to a print buffer - bool Print(trpgPrintBuffer &) const; + bool Print(trpgPrintBuffer &) const; // Resets the contents back to empty - void Reset(void); + void Reset(void); protected: int modelRef; float64 m[4][4]; @@ -2807,44 +2807,44 @@ TX_EXDECL class TX_CLDECL trpgTextStyle : public trpgReadWriteable bool operator == (const trpgTextStyle&) const; // Set the material ID. Should point into trpgMatTable - void SetMaterial(int); + void SetMaterial(int); // Get the material ID. Points into trpgMatTable - int GetMaterial(void) const; + int GetMaterial(void) const; // Set the font description - void SetFont(std::string &); + void SetFont(std::string &); // Get the font description const std::string *GetFont(void) const; // Set bold to on/off - void SetBold(bool); + void SetBold(bool); // Return value of bold status - bool GetBold(void) const; + bool GetBold(void) const; // Set italic on/off - void SetItalic(bool); + void SetItalic(bool); // Return value of italic status - bool GetItalic(void) const; + bool GetItalic(void) const; // Set underline on/off - void SetUnderline(bool); + void SetUnderline(bool); // Return value of underline status - bool GetUnderline(void) const; + bool GetUnderline(void) const; // Set character size: MUST BE IN METER - void SetCharacterSize(float32); + void SetCharacterSize(float32); // Get character (e.g. font) size - float32 GetCharacterSize(void) const; + float32 GetCharacterSize(void) const; // Write this class to a write buffer - bool Write(trpgWriteBuffer &); + bool Write(trpgWriteBuffer &); // Reads this class from a read buffer - bool Read(trpgReadBuffer &); + bool Read(trpgReadBuffer &); // Prints this class to a print buffer - bool Print(trpgPrintBuffer &) const; + bool Print(trpgPrintBuffer &) const; // Reset the contents back to empty - void Reset(void); + void Reset(void); // Return object validity bool isValid(void) const; @@ -2866,32 +2866,32 @@ TX_EXDECL class TX_CLDECL trpgTextStyleTable : public trpgReadWriteable ~trpgTextStyleTable(void); // Add a single text style - int AddStyle(const trpgTextStyle &); + int AddStyle(const trpgTextStyle &); - int FindAddStyle(const trpgTextStyle &); + int FindAddStyle(const trpgTextStyle &); // Figure out how many text styles there are - int GetNumStyle(void) const; + int GetNumStyle(void) const; // Return a reference to the given style const trpgTextStyle *GetStyleRef(int) const; // Validity check - bool isValid(void) const; + bool isValid(void) const; // Reset the contents back to empty - void Reset(void); + void Reset(void); // Write this class to a write buffer - bool Write(trpgWriteBuffer &); + bool Write(trpgWriteBuffer &); // Read this class from a read buffer - bool Read(trpgReadBuffer &); + bool Read(trpgReadBuffer &); // Print this class to a print buffer - bool Print(trpgPrintBuffer &) const; + bool Print(trpgPrintBuffer &) const; typedef std::map StyleMapType; const StyleMapType *getStyleMap()const { return &styleMap; } protected: //std::vector styles; - + StyleMapType styleMap; }; @@ -2912,30 +2912,30 @@ TX_EXDECL class TX_CLDECL trpgSupportStyle : public trpgReadWriteable typedef enum {Line,Cylinder,MaxSupportType} SupportType; // Set the support type. Get GetSupportType() for more information - void SetType(SupportType); + void SetType(SupportType); /* Return the support types. Supports are geometry that run from the bottom middle of the label object to some point in space. Most likely that point is somewhere on the ground, but not necessarily. How the support is drawn is controlled both by the support type and the material ID for the support. */ - SupportType GetType(void) const; + SupportType GetType(void) const; // Set the material ID. Should point into trpgMatTable - void SetMaterial(int); + void SetMaterial(int); // Get the material ID. Points into trpgMatTable - int GetMaterial(void) const; + int GetMaterial(void) const; // Write this class to a write buffer - bool Write(trpgWriteBuffer &); + bool Write(trpgWriteBuffer &); // Reads this class from a read buffer - bool Read(trpgReadBuffer &); + bool Read(trpgReadBuffer &); // Prints this class to a print buffer - bool Print(trpgPrintBuffer &) const; + bool Print(trpgPrintBuffer &) const; // Reset the contents back to empty - void Reset(void); + void Reset(void); // Return object validity bool isValid(void) const; @@ -2955,27 +2955,27 @@ TX_EXDECL class TX_CLDECL trpgSupportStyleTable : public trpgReadWriteable ~trpgSupportStyleTable(void); // Add a single text style - int AddStyle(const trpgSupportStyle &); + int AddStyle(const trpgSupportStyle &); - int FindAddStyle(const trpgSupportStyle &); + int FindAddStyle(const trpgSupportStyle &); // Figure out how many text styles there are - int GetNumStyle(void) const; + int GetNumStyle(void) const; // Return a reference to the given style const trpgSupportStyle *GetStyleRef(int) const; // Validity check - bool isValid(void) const; + bool isValid(void) const; // Reset the contents back to empty - void Reset(void); + void Reset(void); // Write this class to a write buffer - bool Write(trpgWriteBuffer &); + bool Write(trpgWriteBuffer &); // Read this class from a read buffer - bool Read(trpgReadBuffer &); + bool Read(trpgReadBuffer &); // Print this class to a print buffer - bool Print(trpgPrintBuffer &) const; + bool Print(trpgPrintBuffer &) const; protected: //std::vector styles; @@ -3000,7 +3000,7 @@ TX_EXDECL class TX_CLDECL trpgLabelProperty : public trpgReadWriteable bool operator == (const trpgLabelProperty&) const; // Set the label type. See GetType() for more information. - void SetType(LabelType); + void SetType(LabelType); /* Return the label type. This controls the geometry for the label. Panel labels are simple polygons. Cube labels should display the text on every side with single sided polygons. @@ -3008,27 +3008,27 @@ TX_EXDECL class TX_CLDECL trpgLabelProperty : public trpgReadWriteable That is, they will always be pointed directly toward the user. Vertical billboards rotate toward the user, but have an axis along +Z. */ - LabelType GetType(void) const; + LabelType GetType(void) const; // Set the font style ID. Should point into trpgTextStyleTable - void SetFontStyle(int); + void SetFontStyle(int); // Get the font style ID. Points into trpgTextStyleTable - int GetFontStyle(void) const; + int GetFontStyle(void) const; // Set the support style ID. Should point into trpgSupportTable - void SetSupport(int); + void SetSupport(int); // Get the font style ID. Points into trpgSupportTable - int GetSupport(void) const; - + int GetSupport(void) const; + // Write this class to a write buffer - bool Write(trpgWriteBuffer &); + bool Write(trpgWriteBuffer &); // Reads this class from a read buffer - bool Read(trpgReadBuffer &); + bool Read(trpgReadBuffer &); // Prints this class to a print buffer - bool Print(trpgPrintBuffer &) const; + bool Print(trpgPrintBuffer &) const; // Reset the contents back to empty - void Reset(void); + void Reset(void); // Return object validity bool isValid(void) const; @@ -3049,28 +3049,28 @@ TX_EXDECL class TX_CLDECL trpgLabelPropertyTable : public trpgReadWriteable ~trpgLabelPropertyTable(void); // Add a single label property - int AddProperty(const trpgLabelProperty &); + int AddProperty(const trpgLabelProperty &); // Find or Add a single label property int FindAddProperty(const trpgLabelProperty& property); // Figure out how many properties there are - int GetNumProperty(void) const; + int GetNumProperty(void) const; // Return a reference to the given property const trpgLabelProperty *GetPropertyRef(int) const; // Validity check - bool isValid(void) const; + bool isValid(void) const; // Reset the contents back to empty - void Reset(void); + void Reset(void); // Write this class to a write buffer - bool Write(trpgWriteBuffer &); + bool Write(trpgWriteBuffer &); // Read this class from a read buffer - bool Read(trpgReadBuffer &); + bool Read(trpgReadBuffer &); // Print this class to a print buffer - bool Print(trpgPrintBuffer &) const; + bool Print(trpgPrintBuffer &) const; protected: //std::vector properties; @@ -3091,17 +3091,17 @@ TX_EXDECL class TX_CLDECL trpgLabel : public trpgReadWriteable { bool isValid(void) const; - + typedef enum {Left,Center,Right,MaxAlignmentType} AlignmentType; // Set the label property ID. This is an index into a tprgLabelPropertyTable - void SetProperty(int); - int GetProperty() const; + void SetProperty(int); + int GetProperty() const; // Set the text for this label. See GetText() for more information - void SetText(const std::string &); + void SetText(const std::string &); /* Return the text for this label. The text may contain basic formatting such as newlines and tabs. Expect to see those as \n and \t respectively. Eventually, this text might contain HTML formatting, but we do not use @@ -3111,16 +3111,16 @@ TX_EXDECL class TX_CLDECL trpgLabel : public trpgReadWriteable { const std::string *GetText(void) const; // Set the text alignment. See GetAlignmentType() for more information. - void SetAlignment(AlignmentType); + void SetAlignment(AlignmentType); /* Return the alignement type. This controls the alignement of the text with respect to the label geometry. */ - AlignmentType GetAlignment(void) const; + AlignmentType GetAlignment(void) const; // Set the number of spaces between tabs - void SetTab(int); + void SetTab(int); // Get the number of spaces between tabs - int GetTab(void) const; + int GetTab(void) const; // Set the text scaling value: font size * scale = real world text size in meter void SetScale(float32); @@ -3132,7 +3132,7 @@ TX_EXDECL class TX_CLDECL trpgLabel : public trpgReadWriteable { float32 GetThickness() const; // Set the description for this label. Set GetDesc() for more information - void SetDesc(const std::string &); + void SetDesc(const std::string &); /* Return the description for this label. Descriptions should contain no formatting. They are a description of what the label represents and may appear if a user interacts with the label, but should not be drawn in 3D. @@ -3141,7 +3141,7 @@ TX_EXDECL class TX_CLDECL trpgLabel : public trpgReadWriteable { const std::string *GetDesc(void) const; // Set the URL for this label. See GetURL() for more information. - void SetURL(const std::string &); + void SetURL(const std::string &); /* Return the URL for this label. The URL would invoke some sort of web browser if the user of the 3D application clicks on the label. May be empty. @@ -3149,16 +3149,16 @@ TX_EXDECL class TX_CLDECL trpgLabel : public trpgReadWriteable { const std::string *GetURL(void) const; // Set the number of spaces between tabs - void SetTabSize(int); + void SetTabSize(int); // Get the number of spaces between tabs - int GetTabSize(void) const; + int GetTabSize(void) const; // Set the location of the label. void SetLocation(const trpg3dPoint &); const trpg3dPoint& GetLocation() const; // Add a support. See GetSupports() for more information - void AddSupport(const trpg3dPoint &); + void AddSupport(const trpg3dPoint &); /* Return the support array. Supports are linear features that run from the middle bottom of the label to some set of points in the database. These will often be on the ground, but need not be. Support display @@ -3167,14 +3167,14 @@ TX_EXDECL class TX_CLDECL trpgLabel : public trpgReadWriteable { const std::vector *GetSupports(void) const; // Writes this class to a write buffer - bool Write(trpgWriteBuffer &); + bool Write(trpgWriteBuffer &); // Reads this class from a read buffer - bool Read(trpgReadBuffer &); + bool Read(trpgReadBuffer &); // Prints this class to a print buffer - bool Print(trpgPrintBuffer &) const; + bool Print(trpgPrintBuffer &) const; // Resets the contents back to empty - void Reset(void); + void Reset(void); protected: int propertyId; diff --git a/src/osgPlugins/txp/trpage_header.cpp b/src/osgPlugins/txp/trpage_header.cpp index 93268733c..deae87b95 100644 --- a/src/osgPlugins/txp/trpage_header.cpp +++ b/src/osgPlugins/txp/trpage_header.cpp @@ -18,22 +18,22 @@ #include /* 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 #include /* 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) - return; + if (no < 0 || no >= numLods) + return; - lodRanges[no] = r; + lodRanges[no] = r; } void trpgHeader::SetLodRange(const float64 *r) { - for (int i=0;i(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(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= 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 @@ -41,7 +41,7 @@ typedef long TeAttrHdl; #endif // File header Magic Number -#define TRPG_MAGIC 9480372 +#define TRPG_MAGIC 9480372 // Current TerraPage major version #define TRPG_VERSION_MAJOR 2 @@ -55,7 +55,7 @@ typedef long TeAttrHdl; // Non-existent token // {secret} -#define TRPG_NOTOKEN 0 +#define TRPG_NOTOKEN 0 // 16 bit token definition value. These are values such as TRPGTEXTABLE or TRPG_ATTACH, etc... typedef short trpgToken; @@ -63,132 +63,132 @@ typedef short trpgToken; // Tokens for paging data structures // Update the MINTOKEN and MAXTOKEN when you add tokens // {secret} -#define TRPG_MINTOKEN 100 +#define TRPG_MINTOKEN 100 // {secret} -#define TRPG_PUSH 100 +#define TRPG_PUSH 100 // {secret} -#define TRPG_POP 101 +#define TRPG_POP 101 // {secret} -#define TRPGHEADER 200 +#define TRPGHEADER 200 // {secret} -#define TRPGHEAD_LODINFO 201 +#define TRPGHEAD_LODINFO 201 // {secret} -#define TRPGMATTABLE 300 +#define TRPGMATTABLE 300 // Added 11/14/98 - New material table // {secret} -#define TRPGMATTABLE2 301 +#define TRPGMATTABLE2 301 // Added 11/14/98 // {secret} -#define TRPGSHORTMATTABLE 302 +#define TRPGSHORTMATTABLE 302 // {secret} -#define TRPGMATERIAL 400 +#define TRPGMATERIAL 400 // {secret} -#define TRPGMAT_BASIC 401 +#define TRPGMAT_BASIC 401 // {secret} -#define TRPGMAT_SHADE 402 +#define TRPGMAT_SHADE 402 // {secret} // {secret} -#define TRPGMAT_SIZES 403 +#define TRPGMAT_SIZES 403 // {secret} -#define TRPGMAT_CULL 404 +#define TRPGMAT_CULL 404 // {secret} -#define TRPGMAT_ALPHA 405 +#define TRPGMAT_ALPHA 405 // {secret} -#define TRPGMAT_NORMAL 406 +#define TRPGMAT_NORMAL 406 // {secret} -#define TRPGMAT_TEXTURE 407 +#define TRPGMAT_TEXTURE 407 // {secret} -#define TRPGMAT_BUMP 408 +#define TRPGMAT_BUMP 408 // {secret} -#define TRPGMAT_ATTR 409 +#define TRPGMAT_ATTR 409 // {secret} -#define TRPGMAT_HANDLE 410 +#define TRPGMAT_HANDLE 410 // {secret} -#define TRPGMAT_TEXENV 500 +#define TRPGMAT_TEXENV 500 // {secret} -#define TRPGMAT_TXENV_MODE 501 +#define TRPGMAT_TXENV_MODE 501 // {secret} #define TRPGMAT_TXENV_FILTER 502 // {secret} -#define TRPGMAT_TXENV_WRAP 503 +#define TRPGMAT_TXENV_WRAP 503 // {secret} #define TRPGMAT_TXENV_BORDER 504 // {secret} -#define TRPGTEXTABLE 600 +#define TRPGTEXTABLE 600 // {secret} -#define TRPGTEXTABLE2 601 +#define TRPGTEXTABLE2 601 // {secret} -#define TRPGTEXTURE 650 +#define TRPGTEXTURE 650 // {secret} -#define TRPGMODELREF 700 +#define TRPGMODELREF 700 // {secret} -#define TRPGMODELREF2 701 +#define TRPGMODELREF2 701 // {secret} -#define TRPGMODELTABLE 800 +#define TRPGMODELTABLE 800 // {secret} -#define TRPGTILETABLE 900 +#define TRPGTILETABLE 900 // {secret} -#define TRPG_TILE_ENTRY 901 +#define TRPG_TILE_ENTRY 901 // {secret} -#define TRPGTILETABLE2 902 +#define TRPGTILETABLE2 902 // {secret} -#define TRPGTILEHEADER 1000 +#define TRPGTILEHEADER 1000 // {secret} -#define TRPG_TILE_MATLIST 1001 +#define TRPG_TILE_MATLIST 1001 // {secret} -#define TRPG_TILE_MODELLIST 1002 +#define TRPG_TILE_MODELLIST 1002 // {secret} -#define TRPG_TILE_DATE 1003 +#define TRPG_TILE_DATE 1003 // {secret} -#define TRPGLOCALMATERIAL 1004 +#define TRPGLOCALMATERIAL 1004 // {secret} -#define TRPG_TILE_LOCMATLIST 1005 +#define TRPG_TILE_LOCMATLIST 1005 // Lights support added by Nick // {secret} -#define TRPGLIGHTTABLE 1100 +#define TRPGLIGHTTABLE 1100 // {secret} -#define TRPGLIGHTATTR 1150 +#define TRPGLIGHTATTR 1150 // {secret} -#define TRPGLIGHTATTR_BASIC 1151 +#define TRPGLIGHTATTR_BASIC 1151 // {secret} -#define TRPGLIGHTATTR_RASCAL 1152 +#define TRPGLIGHTATTR_RASCAL 1152 // {secret} -#define TRPGLIGHTATTR_CALLIGRAPHIC 1153 +#define TRPGLIGHTATTR_CALLIGRAPHIC 1153 // {secret} -#define TRPGLIGHTATTR_PERFORMER 1154 +#define TRPGLIGHTATTR_PERFORMER 1154 // {secret} -#define TRPGLIGHTATTR_ANIMATION 1155 +#define TRPGLIGHTATTR_ANIMATION 1155 // {secret} -#define TRPGLIGHTATTR_COMMENT 1156 +#define TRPGLIGHTATTR_COMMENT 1156 // {secret} -#define TRPGLIGHTATTR_HANDLE 1157 +#define TRPGLIGHTATTR_HANDLE 1157 // {secret} -#define TRPGLIGHT 1160 +#define TRPGLIGHT 1160 // {secret} -#define TRPG_LIGHT 1160 +#define TRPG_LIGHT 1160 // {secret} -#define TRPGRANGETABLE 1200 +#define TRPGRANGETABLE 1200 // {secret} -#define TRPG_RANGE 1201 +#define TRPG_RANGE 1201 // Label and style support added 12-02 // {secret} -#define TRPG_TEXT_STYLE_TABLE 1300 +#define TRPG_TEXT_STYLE_TABLE 1300 // {secret} -#define TRPG_TEXT_STYLE 1301 +#define TRPG_TEXT_STYLE 1301 // {secret} -#define TRPG_TEXT_STYLE_BASIC 1302 +#define TRPG_TEXT_STYLE_BASIC 1302 // {secret} #define TRPG_SUPPORT_STYLE_TABLE 1310 @@ -206,53 +206,53 @@ typedef short trpgToken; // {secret} -#define TRPG_LABEL 1330 +#define TRPG_LABEL 1330 // {secret} -#define TRPG_GROUP 2001 +#define TRPG_GROUP 2001 // {secret} -#define TRPG_BILLBOARD 2002 +#define TRPG_BILLBOARD 2002 // {secret} -#define TRPG_LOD 2003 +#define TRPG_LOD 2003 // {secret} -#define TRPG_TRANSFORM 2004 +#define TRPG_TRANSFORM 2004 // {secret} -#define TRPG_MODELREF 2005 +#define TRPG_MODELREF 2005 // {secret} -#define TRPG_LAYER 2006 +#define TRPG_LAYER 2006 // {secret} -#define TRPG_GEOMETRY 3000 +#define TRPG_GEOMETRY 3000 // {secret} -#define TRPG_GEOM_PRIM 3001 +#define TRPG_GEOM_PRIM 3001 // {secret} -#define TRPG_GEOM_MATERIAL 3002 +#define TRPG_GEOM_MATERIAL 3002 // {secret} -#define TRPG_GEOM_VERT32 3003 +#define TRPG_GEOM_VERT32 3003 // {secret} -#define TRPG_GEOM_VERT64 3004 +#define TRPG_GEOM_VERT64 3004 // {secret} -#define TRPG_GEOM_NORM32 3005 +#define TRPG_GEOM_NORM32 3005 // {secret} -#define TRPG_GEOM_NORM64 3006 +#define TRPG_GEOM_NORM64 3006 // {secret} -#define TRPG_GEOM_COLOR 3007 +#define TRPG_GEOM_COLOR 3007 // {secret} -#define TRPG_GEOM_TEX32 3008 +#define TRPG_GEOM_TEX32 3008 // {secret} -#define TRPG_GEOM_TEX64 3009 +#define TRPG_GEOM_TEX64 3009 // {secret} -#define TRPG_GEOM_EFLAG 3010 +#define TRPG_GEOM_EFLAG 3010 // {secret} -#define TRPG_ATTACH 4000 +#define TRPG_ATTACH 4000 // {secret} -#define TRPG_CHILDREF 5000 +#define TRPG_CHILDREF 5000 // {secret} -#define TRPG_MAXTOKEN 5000 +#define TRPG_MAXTOKEN 5000 // Basic data types @@ -264,169 +264,169 @@ typedef int trpgMatRef; /* Double precision 2 dimensional point. */ TX_EXDECL class TX_CLDECL trpg2dPoint { public: - double x, y; - trpg2dPoint (void) { }; - trpg2dPoint (double in_x,double in_y) { x = in_x; y = in_y; }; - bool operator==(const trpg2dPoint& pt ) const { - if ( x != pt.x ) return false; - if ( y != pt.y ) return false; - return true; - }; - bool operator!=(const trpg2dPoint& pt ) const { return !operator==(pt); }; + double x, y; + trpg2dPoint (void) { }; + trpg2dPoint (double in_x,double in_y) { x = in_x; y = in_y; }; + bool operator==(const trpg2dPoint& pt ) const { + if ( x != pt.x ) return false; + if ( y != pt.y ) return false; + return true; + }; + bool operator!=(const trpg2dPoint& pt ) const { return !operator==(pt); }; }; /* Integer 2 dimensional point. This is used primarily as a 2D index value. */ TX_EXDECL class TX_CLDECL trpg2iPoint { public: - int x,y; - trpg2iPoint (void) { }; - trpg2iPoint (int in_x,int in_y) {x = in_x; y = in_y;}; + int x,y; + trpg2iPoint (void) { }; + trpg2iPoint (int in_x,int in_y) {x = in_x; y = in_y;}; }; /* Double precision 3 dimensional point. */ TX_EXDECL class TX_CLDECL trpg3dPoint { public: - double x,y,z; - trpg3dPoint(void) { }; - trpg3dPoint(double in_x,double in_y,double in_z) {x = in_x; y = in_y; z = in_z;} - bool operator==(const trpg3dPoint& pt ) const { - if ( x != pt.x ) return false; - if ( y != pt.y ) return false; - if ( z != pt.z ) return false; - return true; - }; - bool operator!=(const trpg3dPoint& pt ) const { return !operator==(pt); }; + double x,y,z; + trpg3dPoint(void) { }; + trpg3dPoint(double in_x,double in_y,double in_z) {x = in_x; y = in_y; z = in_z;} + bool operator==(const trpg3dPoint& pt ) const { + if ( x != pt.x ) return false; + if ( y != pt.y ) return false; + if ( z != pt.z ) return false; + return true; + }; + bool operator!=(const trpg3dPoint& pt ) const { return !operator==(pt); }; }; /* Simple red, green, blue color definition */ TX_EXDECL class TX_CLDECL trpgColor { public: - trpgColor(float64 r,float64 g,float64 b) {red = r; green = g; blue = b;} - trpgColor(void) { }; - bool operator==(const trpgColor& color) { - if ( color.red != red ) return false; - if ( color.green != green ) return false; - if ( color.blue != blue ) return false; - return true; - }; - bool operator!=(const trpgColor& color) { return !operator==(color); }; - float64 red,green,blue; + trpgColor(float64 r,float64 g,float64 b) {red = r; green = g; blue = b;} + trpgColor(void) { }; + bool operator==(const trpgColor& color) { + if ( color.red != red ) return false; + if ( color.green != green ) return false; + if ( color.blue != blue ) return false; + return true; + }; + bool operator!=(const trpgColor& color) { return !operator==(color); }; + float64 red,green,blue; }; // Used to specify machine endianess typedef enum {LittleEndian,BigEndian} trpgEndian; -/* This is a base class for an abstract buffer type. - It contains the virtual methods for writing - data to an abstract device. The device implementation is up - to the subclass. trpgReadBuffer performs the similar function - for reading. - {group:Low Level I/O} - */ +/* This is a base class for an abstract buffer type. + It contains the virtual methods for writing + data to an abstract device. The device implementation is up + to the subclass. trpgReadBuffer performs the similar function + for reading. + {group:Low Level I/O} + */ TX_EXDECL class TX_CLDECL trpgWriteBuffer { public: - virtual ~trpgWriteBuffer(void) { }; - /* The add functions must be filled in by the child class - They add data of the appropriate type to the current buffer. */ - virtual void Add(int32) = 0; - virtual void Add(int64) = 0; - virtual void Add(const char *) = 0; - virtual void Add(float32) = 0; - virtual void Add(float64) = 0; + virtual ~trpgWriteBuffer(void) { }; + /* The add functions must be filled in by the child class + They add data of the appropriate type to the current buffer. */ + virtual void Add(int32) = 0; + virtual void Add(int64) = 0; + virtual void Add(const char *) = 0; + virtual void Add(float32) = 0; + virtual void Add(float64) = 0; //#if (bool != int32) - virtual void Add(bool) = 0; + virtual void Add(bool) = 0; //#endif - virtual void Add(uint8) = 0; + virtual void Add(uint8) = 0; #if (trpgDiskRef != int64) - virtual void Add(trpgDiskRef) = 0; + virtual void Add(trpgDiskRef) = 0; #endif - virtual void Add(trpgToken) = 0; - /* Child class method. Returns the buffer to an original state. */ - virtual void Reset(void) = 0; - // See trpgMemWriteBuffer for details - virtual void Begin(trpgToken) = 0; - // See trpgMemWriteBuffer for details - virtual void End(void) = 0; - // See trpgMemWriteBuffer for details - virtual void Push(void) = 0; - // See trpgMemWriteBuffer for details - virtual void Pop(void) = 0; + virtual void Add(trpgToken) = 0; + /* Child class method. Returns the buffer to an original state. */ + virtual void Reset(void) = 0; + // See trpgMemWriteBuffer for details + virtual void Begin(trpgToken) = 0; + // See trpgMemWriteBuffer for details + virtual void End(void) = 0; + // See trpgMemWriteBuffer for details + virtual void Push(void) = 0; + // See trpgMemWriteBuffer for details + virtual void Pop(void) = 0; - // Some add functions are helpers for composite values that call the basic add functions - virtual void Add(const trpg2iPoint &); - virtual void Add(const trpg2dPoint &); - virtual void Add(const trpg3dPoint &); - virtual void Add(const trpgColor &); - virtual void Add(const std::string &); + // Some add functions are helpers for composite values that call the basic add functions + virtual void Add(const trpg2iPoint &); + virtual void Add(const trpg2dPoint &); + virtual void Add(const trpg3dPoint &); + virtual void Add(const trpgColor &); + virtual void Add(const std::string &); - /* Endianness is something the child class buffer type must set and use. - This function returns the endiannes of the current buffer. */ - virtual trpgEndian GetEndian(void) { return ness; } + /* Endianness is something the child class buffer type must set and use. + This function returns the endiannes of the current buffer. */ + virtual trpgEndian GetEndian(void) { return ness; } protected: - // Target endianness of the buffer. This should be set by the subclass on creation. - trpgEndian ness; - // Endianness of the machine we're running on. - trpgEndian cpuNess; + // Target endianness of the buffer. This should be set by the subclass on creation. + trpgEndian ness; + // Endianness of the machine we're running on. + trpgEndian cpuNess; }; /* The Memory Write Buffer is an implementation of the Write Buffer that - uses chunks of memory. It contains implementations of the all the virtual - methods straight to memory. This is used primarily in writing archives and - tiles. - {group:Low Level I/O} - */ + uses chunks of memory. It contains implementations of the all the virtual + methods straight to memory. This is used primarily in writing archives and + tiles. + {group:Low Level I/O} + */ TX_EXDECL class TX_CLDECL trpgMemWriteBuffer : public trpgWriteBuffer { public: - /* The constructor takes an endianness for this buffer. - Data will automatically be converted to that as it goes in. */ - trpgMemWriteBuffer(trpgEndian); - virtual ~trpgMemWriteBuffer(void); - // Return the current length of buffer - virtual int length(void) const; - // Return the raw data (if you want to write to disk, for example) - virtual const char *getData(void) const; - // Allocate the given amount of space for the buffer - virtual void setLength(unsigned int); + /* The constructor takes an endianness for this buffer. + Data will automatically be converted to that as it goes in. */ + trpgMemWriteBuffer(trpgEndian); + virtual ~trpgMemWriteBuffer(void); + // Return the current length of buffer + virtual int length(void) const; + // Return the raw data (if you want to write to disk, for example) + virtual const char *getData(void) const; + // Allocate the given amount of space for the buffer + virtual void setLength(unsigned int); - // Add a 32 bit integer to the buffer - virtual void Add(int32); - // Add a 64 bit integer to the buffer - virtual void Add(int64); - /* Add an arbitrary length string to the buffer. - This writes both the length and the string itself. - */ - virtual void Add(const char *); - // Same as const char * version - virtual void Add(std::string &); - // Add a 32 bit float to the buffer - virtual void Add(float32); - // Add a 64 bit float to the buffer - virtual void Add(float64); + // Add a 32 bit integer to the buffer + virtual void Add(int32); + // Add a 64 bit integer to the buffer + virtual void Add(int64); + /* Add an arbitrary length string to the buffer. + This writes both the length and the string itself. + */ + virtual void Add(const char *); + // Same as const char * version + virtual void Add(std::string &); + // Add a 32 bit float to the buffer + virtual void Add(float32); + // Add a 64 bit float to the buffer + virtual void Add(float64); //#if (bool != int32) - // Add a boolean value to the buffer. It will become at least one byte. - virtual void Add(bool); + // Add a boolean value to the buffer. It will become at least one byte. + virtual void Add(bool); //#endif - // Add an unsigned character to the buffer - virtual void Add(uint8); + // Add an unsigned character to the buffer + virtual void Add(uint8); #if (trpgDiskRef != int64) - // Add a 64 bit disk reference to the buffer - virtual void Add(trpgDiskRef); + // Add a 64 bit disk reference to the buffer + virtual void Add(trpgDiskRef); #endif - // Add a token (16 bit) to the buffer - virtual void Add(trpgToken); - // Reset this buffer. This will set the current length to zero, but will not deallocate memory - virtual void Reset(void); - /* Start defining an tokenized object. The token is put into the buffer stream - and the position of a size value following it is kept. When End() is called - the buffer will rewind to that value and save the size. This method ensures - that token data can be skipped if necessary. */ - virtual void Begin(trpgToken); - /* This method is called at the end of a tokenized object. See Begin for details. */ - virtual void End(void); - /* Adds the TRPG_PUSH token to the current buffer. This is done by objects - that have children as they're being written. See Pop as well. */ - virtual void Push(void); - /* Adds the TRPG_POP token to the current buffer. This is done by objects - that have defined children. See Push. */ - virtual void Pop(void); + // Add a token (16 bit) to the buffer + virtual void Add(trpgToken); + // Reset this buffer. This will set the current length to zero, but will not deallocate memory + virtual void Reset(void); + /* Start defining an tokenized object. The token is put into the buffer stream + and the position of a size value following it is kept. When End() is called + the buffer will rewind to that value and save the size. This method ensures + that token data can be skipped if necessary. */ + virtual void Begin(trpgToken); + /* This method is called at the end of a tokenized object. See Begin for details. */ + virtual void End(void); + /* Adds the TRPG_PUSH token to the current buffer. This is done by objects + that have children as they're being written. See Pop as well. */ + virtual void Push(void); + /* Adds the TRPG_POP token to the current buffer. This is done by objects + that have defined children. See Push. */ + virtual void Pop(void); /* Take out the pop from the end of the buffer, if there is one */ /* Will return true if a pop was actually taken out */ virtual bool UnPop(); @@ -435,291 +435,291 @@ public: virtual bool UnPush(); protected: - virtual void append(unsigned int,const char *); - virtual void set(unsigned int pos,unsigned int len,const char *); - int curLen; - int totLen; - char *data; - std::vector lengths; + virtual void append(unsigned int,const char *); + virtual void set(unsigned int pos,unsigned int len,const char *); + int curLen; + int totLen; + char *data; + std::vector lengths; }; /* This is a virtual base class for reading data from a device. - The device implementation is left as an excercise to the sub class. - This class contains methods for getting data that must be filled in - as well as helper methods that call those. - {group:Low Level I/O} - */ + The device implementation is left as an excercise to the sub class. + This class contains methods for getting data that must be filled in + as well as helper methods that call those. + {group:Low Level I/O} + */ TX_EXDECL class TX_CLDECL trpgReadBuffer { public: - virtual ~trpgReadBuffer(void) { }; - /* The Get methods are utility routines that all call the GetData method. - Only that method need be filled in by a subclass. */ - virtual bool Get(int32 &); - virtual bool Get(int64 &); - virtual bool Get(char *,int); - virtual bool Get(std::string &); - virtual bool Get(float32 &); - virtual bool Get(float64 &); + virtual ~trpgReadBuffer(void) { }; + /* The Get methods are utility routines that all call the GetData method. + Only that method need be filled in by a subclass. */ + virtual bool Get(int32 &); + virtual bool Get(int64 &); + virtual bool Get(char *,int); + virtual bool Get(std::string &); + virtual bool Get(float32 &); + virtual bool Get(float64 &); //#if (bool != int32) - virtual bool Get(bool &); + virtual bool Get(bool &); //#endif - virtual bool Get(uint8 &); + virtual bool Get(uint8 &); #if (trpgDiskRef != int64) - virtual bool Get(trpgDiskRef &); + virtual bool Get(trpgDiskRef &); #endif - virtual bool Get(trpgToken &); + virtual bool Get(trpgToken &); - /* These methods return references to arrays of data of the given types. - These are all utility routines and depend upon GetDataRef. */ - virtual bool GetArray(int,float32 **); - virtual bool GetArray(int,float64 **); - virtual bool GetArray(int,int32 **); - virtual bool GetArray(int,trpgColor **); - virtual bool GetArray(int,char **); + /* These methods return references to arrays of data of the given types. + These are all utility routines and depend upon GetDataRef. */ + virtual bool GetArray(int,float32 **); + virtual bool GetArray(int,float64 **); + virtual bool GetArray(int,int32 **); + virtual bool GetArray(int,trpgColor **); + virtual bool GetArray(int,char **); - virtual bool Get(trpg2iPoint &); - virtual bool Get(trpg2dPoint &); - virtual bool Get(trpg3dPoint &); - virtual bool Get(trpgColor &); - virtual bool GetToken(trpgToken &,int32 &); + virtual bool Get(trpg2iPoint &); + virtual bool Get(trpg2dPoint &); + virtual bool Get(trpg3dPoint &); + virtual bool Get(trpgColor &); + virtual bool GetToken(trpgToken &,int32 &); - /* Force the buffer to only allow the next N bytes to be read. - The limits are stack based. That is, this limit is the current one - until it's popped off the stack. Then it reverts to the previous one. - Any bytes read in the mean time count against all limits. */ - virtual void PushLimit(int); - /* Revert to the limit before this one. Typically this would happen when - a tokenized object has been read. */ - virtual void PopLimit(void); - /* Skip to the end of the current limit. This is done by a parser when - reading a tokenized object from the buffer to make sure that the next - object can be safely read even if the current one wasn't. */ - virtual bool SkipToLimit(void); + /* Force the buffer to only allow the next N bytes to be read. + The limits are stack based. That is, this limit is the current one + until it's popped off the stack. Then it reverts to the previous one. + Any bytes read in the mean time count against all limits. */ + virtual void PushLimit(int); + /* Revert to the limit before this one. Typically this would happen when + a tokenized object has been read. */ + virtual void PopLimit(void); + /* Skip to the end of the current limit. This is done by a parser when + reading a tokenized object from the buffer to make sure that the next + object can be safely read even if the current one wasn't. */ + virtual bool SkipToLimit(void); - // Buffer is empty - virtual bool isEmpty(void) = 0; + // Buffer is empty + virtual bool isEmpty(void) = 0; - // MD: making this public to unravel trpgModel read problem. - /* A utility function for subclasses to use to see if they would exceed an - outside imposed limit by reading the given number of bytes. */ - virtual bool TestLimit(int); + // MD: making this public to unravel trpgModel read problem. + /* A utility function for subclasses to use to see if they would exceed an + outside imposed limit by reading the given number of bytes. */ + virtual bool TestLimit(int); protected: - trpgEndian ness; // Endianness of the source we're reading - trpgEndian cpuNess; // Endiannees of the CPU - /* Virtual raw data retrieval function that must be implemented by a subclass. - It must return a given number of bytes in the array passed in. */ - virtual bool GetData(char *,int)=0; - /* Virtual raw data reference retrieval function. The difference between - this method and GetData is that this is supposed to return a pointer - to a given amount of bytes. This assumes some sort of memory caching - mechanism in the subclass. */ - virtual bool GetDataRef(char **,int)=0; - /* This virtual method must be filled in by the subclass so that SkipToLimit - will work correctly. */ - virtual bool Skip(int) = 0; - /* Utility function that must be called after a successfull read to update - the outside imposed read limits. */ - virtual void UpdateLimits(int); - std::vector limits; + trpgEndian ness; // Endianness of the source we're reading + trpgEndian cpuNess; // Endiannees of the CPU + /* Virtual raw data retrieval function that must be implemented by a subclass. + It must return a given number of bytes in the array passed in. */ + virtual bool GetData(char *,int)=0; + /* Virtual raw data reference retrieval function. The difference between + this method and GetData is that this is supposed to return a pointer + to a given amount of bytes. This assumes some sort of memory caching + mechanism in the subclass. */ + virtual bool GetDataRef(char **,int)=0; + /* This virtual method must be filled in by the subclass so that SkipToLimit + will work correctly. */ + virtual bool Skip(int) = 0; + /* Utility function that must be called after a successfull read to update + the outside imposed read limits. */ + virtual void UpdateLimits(int); + std::vector limits; }; /* This class implements a read buffer that uses a chunk of memory. - Typically, raw data will be dumped into this class, then it will be - passed to a parser for object based reading. - {group:Low Level I/O} - */ + Typically, raw data will be dumped into this class, then it will be + passed to a parser for object based reading. + {group:Low Level I/O} + */ TX_EXDECL class TX_CLDECL trpgMemReadBuffer : public trpgReadBuffer { public: - // Memory read buffers must be initialized with an endianness - trpgMemReadBuffer(trpgEndian); - ~trpgMemReadBuffer(void); + // Memory read buffers must be initialized with an endianness + trpgMemReadBuffer(trpgEndian); + ~trpgMemReadBuffer(void); // Return true if we're out of data - bool isEmpty(void); - // Sets the size of this read buffer. - void SetLength(int); - // Gets the size of the buffer. - int GetLength(void) { return len; } - /* Return a pointer to the raw data cache for this object. Data will - be dumped straight into here (from disk, for example) and then parsed - by something that takes a trpgReadBuffer as input. */ - char *GetDataPtr(void); + bool isEmpty(void); + // Sets the size of this read buffer. + void SetLength(int); + // Gets the size of the buffer. + int GetLength(void) { return len; } + /* Return a pointer to the raw data cache for this object. Data will + be dumped straight into here (from disk, for example) and then parsed + by something that takes a trpgReadBuffer as input. */ + char *GetDataPtr(void); protected: - bool GetData(char *,int); // Retrieve the given amount of data - bool GetDataRef(char **,int); // Retrieve a pointer to the given array - bool Skip(int); // Skip over the given amount - int len; // Data Length - int totLen; // Total allocated length - int pos; // Current position - char *data; + bool GetData(char *,int); // Retrieve the given amount of data + bool GetDataRef(char **,int); // Retrieve a pointer to the given array + bool Skip(int); // Skip over the given amount + int len; // Data Length + int totLen; // Total allocated length + int pos; // Current position + char *data; }; /* A Checkable is purely a base class used by other classes that - need validity checks associated with them. By default, the - checkable will return false for isValid unless the valid flag is set. - */ + need validity checks associated with them. By default, the + checkable will return false for isValid unless the valid flag is set. + */ TX_EXDECL class TX_CLDECL trpgCheckable { public: - trpgCheckable(void); - virtual ~trpgCheckable(void); - // Returns the state of the valid flag, or can be overriden by a subclass to do a more complex check. - bool isValid(void) const; - - virtual TeAttrHdl GetHandle() const { - return handle; - } - virtual void SetHandle(TeAttrHdl hdl) { - writeHandle = true; - handle = hdl; - } + trpgCheckable(void); + virtual ~trpgCheckable(void); + // Returns the state of the valid flag, or can be overriden by a subclass to do a more complex check. + bool isValid(void) const; + + virtual TeAttrHdl GetHandle() const { + return handle; + } + virtual void SetHandle(TeAttrHdl hdl) { + writeHandle = true; + handle = hdl; + } protected: - /* Set this flag to true if your checkable structure doesn't have a complex - check it needs to do. */ - bool valid; - TeAttrHdl handle; - bool writeHandle; + /* Set this flag to true if your checkable structure doesn't have a complex + check it needs to do. */ + bool valid; + TeAttrHdl handle; + bool writeHandle; }; class trpgPrintBuffer; /* The Read/Writeable is a class that knows how to read itself from a trpgReadBuffer and write itself to a trpgWriteBuffer. This includes all the node and header - data in TerraPage. These classes are intended as marshalling points for reading - and writing data, not as data containers in and of themselves. If you find - yourself keeping a lot of classes derived from trpgReadWriteable around, you're - probably misusing them. + data in TerraPage. These classes are intended as marshalling points for reading + and writing data, not as data containers in and of themselves. If you find + yourself keeping a lot of classes derived from trpgReadWriteable around, you're + probably misusing them. - The classes derived from this one will have a lot of methods that begin with - "Set", "Get", and "Add". These will almost always return a bool value. This - is used to indicate whether the given call succeeded. In the case of "Set" and "Add" calls - this should always work if it possibly can. An out of range index might make it - fail, for example. "Get" calls will always fail if the object you're getting from - is not valid. Be sure to do an isValid check as soon as you've read or filled out - one of these objects. - {group:Read/Write Classes} - */ + The classes derived from this one will have a lot of methods that begin with + "Set", "Get", and "Add". These will almost always return a bool value. This + is used to indicate whether the given call succeeded. In the case of "Set" and "Add" calls + this should always work if it possibly can. An out of range index might make it + fail, for example. "Get" calls will always fail if the object you're getting from + is not valid. Be sure to do an isValid check as soon as you've read or filled out + one of these objects. + {group:Read/Write Classes} + */ TX_EXDECL class TX_CLDECL trpgReadWriteable : public trpgCheckable { public: - trpgReadWriteable() { errMess[0] = '\0';} + trpgReadWriteable() { errMess[0] = '\0';} - /* The Write method is a virtual that must be filled in by the subclass. - It takes a trpgWriteBuffer and should return true on success. */ - virtual bool Write(trpgWriteBuffer &) = 0; - /* The Read method should be overriden by a subclass. It should read - the contents of the given trpgReadBuffer up to the current limit - into itself. It must return true on success. */ - virtual bool Read(trpgReadBuffer &) { return false;}; - /* Every read/writeable must be able to reset itself to a pristine state - so that, for example, multiple objects of the same type can be read into - it, one after the other. */ - virtual void Reset(void) = 0; - /* The print method is optional. If it's not there, it won't do anything. - */ - virtual bool Print(trpgPrintBuffer &) const { return true; } + /* The Write method is a virtual that must be filled in by the subclass. + It takes a trpgWriteBuffer and should return true on success. */ + virtual bool Write(trpgWriteBuffer &) = 0; + /* The Read method should be overriden by a subclass. It should read + the contents of the given trpgReadBuffer up to the current limit + into itself. It must return true on success. */ + virtual bool Read(trpgReadBuffer &) { return false;}; + /* Every read/writeable must be able to reset itself to a pristine state + so that, for example, multiple objects of the same type can be read into + it, one after the other. */ + virtual void Reset(void) = 0; + /* The print method is optional. If it's not there, it won't do anything. + */ + virtual bool Print(trpgPrintBuffer &) const { return true; } - const char *getErrMess() const {if(errMess[0] == '\0') return 0;else return &errMess[0];} + const char *getErrMess() const {if(errMess[0] == '\0') return 0;else return &errMess[0];} protected: - mutable char errMess[512]; + mutable char errMess[512]; }; /* Pointer into a trpgwAppFile. The full name of the file - is based on the context (e.g. texture vs. tile) - {group:Archive Writing} + is based on the context (e.g. texture vs. tile) + {group:Archive Writing} */ TX_EXDECL class TX_CLDECL trpgwAppAddress { public: - trpgwAppAddress() {file = -1; offset = -1; row = -1; col = -1;}; - // Which file - int32 file; - // Offset within the file - // Note: This is not a 64 bit value - int32 offset; - // Row and col are used for TerraPage 2.3 archives, so we - // can know which block to get the appropriate file from - int32 row; - int32 col; + trpgwAppAddress() {file = -1; offset = -1; row = -1; col = -1;}; + // Which file + int32 file; + // Offset within the file + // Note: This is not a 64 bit value + int32 offset; + // Row and col are used for TerraPage 2.3 archives, so we + // can know which block to get the appropriate file from + int32 row; + int32 col; }; /* Archive File. - This class represents an appendable file archive used for - consolidating tiles and textures. - {group:Archive Writing} + This class represents an appendable file archive used for + consolidating tiles and textures. + {group:Archive Writing} */ TX_EXDECL class TX_CLDECL trpgwAppFile { public: - trpgwAppFile() {valid=false;}; - trpgwAppFile(trpgEndian,const char *,bool reuse=false); - virtual ~trpgwAppFile(void); - virtual bool Append(const trpgMemWriteBuffer *,const trpgMemWriteBuffer *); - virtual bool Append(const char *,int size); - virtual int64 Pos(void) const; - virtual int GetLengthWritten(); - virtual bool Flush(void); - virtual void Init(trpgEndian,const char *,bool reuse=false); + trpgwAppFile() {valid=false;}; + trpgwAppFile(trpgEndian,const char *,bool reuse=false); + virtual ~trpgwAppFile(void); + virtual bool Append(const trpgMemWriteBuffer *,const trpgMemWriteBuffer *); + virtual bool Append(const char *,int size); + virtual int64 Pos(void) const; + virtual int GetLengthWritten(); + virtual bool Flush(void); + virtual void Init(trpgEndian,const char *,bool reuse=false); - bool isValid(void) const; + bool isValid(void) const; protected: - bool valid; - trpgEndian ness,cpuNess; - FILE *fp; - int lengthSoFar; + bool valid; + trpgEndian ness,cpuNess; + FILE *fp; + int lengthSoFar; }; /* Archive File - Read version. - This class represents an appendable file archive from the - read perspective. This is the same type of file written by - trpgwAppFile. + This class represents an appendable file archive from the + read perspective. This is the same type of file written by + trpgwAppFile. */ TX_EXDECL class TX_CLDECL trpgrAppFile { public: - trpgrAppFile() {valid=false;}; - trpgrAppFile(trpgEndian,const char *); - // real construction is here - virtual void Init(trpgEndian,const char *); - virtual ~trpgrAppFile(void); - virtual bool Read(trpgMemReadBuffer *,int32 offset); - virtual bool Read(char *data,int32 baseOffset,int32 objOffset,int32 dataSize); + trpgrAppFile() {valid=false;}; + trpgrAppFile(trpgEndian,const char *); + // real construction is here + virtual void Init(trpgEndian,const char *); + virtual ~trpgrAppFile(void); + virtual bool Read(trpgMemReadBuffer *,int32 offset); + virtual bool Read(char *data,int32 baseOffset,int32 objOffset,int32 dataSize); - bool isValid(void) const; + bool isValid(void) const; protected: - bool valid; - trpgEndian ness,cpuNess; - FILE *fp; + bool valid; + trpgEndian ness,cpuNess; + FILE *fp; }; /* Archive File Cache. - This class keeps + This class keeps */ TX_EXDECL class TX_CLDECL trpgrAppFileCache { public: - trpgrAppFileCache(){;}; - trpgrAppFileCache(const char *prefix,const char *ext,int noFiles=32); - // real construction is here - virtual void Init(const char *prefix,const char *ext,int noFiles); - virtual ~trpgrAppFileCache(void); - virtual trpgrAppFile *GetFile(trpgEndian ness,int id,int col,int row); - virtual trpgrAppFile *GetFile(trpgEndian ness,int id); - virtual trpgrAppFile *GetNewRAppFile(trpgEndian ness, const char *fileName); + trpgrAppFileCache(){;}; + trpgrAppFileCache(const char *prefix,const char *ext,int noFiles=32); + // real construction is here + virtual void Init(const char *prefix,const char *ext,int noFiles); + virtual ~trpgrAppFileCache(void); + virtual trpgrAppFile *GetFile(trpgEndian ness,int id,int col,int row); + virtual trpgrAppFile *GetFile(trpgEndian ness,int id); + virtual trpgrAppFile *GetNewRAppFile(trpgEndian ness, const char *fileName); protected: - // Prefix name and extension - char baseName[1024],ext[20]; + // Prefix name and extension + char baseName[1024],ext[20]; - class OpenFile { - public: - OpenFile(void); - int id; // ID of open file - int row; - int col; - trpgrAppFile *afile; - int lastUsed; // When the file was last accessed - }; + class OpenFile { + public: + OpenFile(void); + int id; // ID of open file + int row; + int col; + trpgrAppFile *afile; + int lastUsed; // When the file was last accessed + }; - std::vector files; - int timeCount; // Incremented for every access + std::vector files; + int timeCount; // Incremented for every access }; #endif diff --git a/src/osgPlugins/txp/trpage_label.cpp b/src/osgPlugins/txp/trpage_label.cpp index af5a62528..5f440364e 100644 --- a/src/osgPlugins/txp/trpage_label.cpp +++ b/src/osgPlugins/txp/trpage_label.cpp @@ -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 *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 #include @@ -34,886 +34,886 @@ #endif /****** - Lights Attribute + Lights Attribute ******/ trpgLightAttr::trpgLightAttr(void) { - data.commentStr = NULL; - Reset(); + data.commentStr = NULL; + Reset(); } trpgLightAttr::trpgLightAttr(const trpgLightAttr& in): trpgReadWriteable(in) { - data.commentStr = NULL; - operator=(in); + data.commentStr = NULL; + operator=(in); } trpgLightAttr::~trpgLightAttr(void) { - if (data.commentStr) - delete [] data.commentStr; - data.commentStr = NULL; + if (data.commentStr) + delete [] data.commentStr; + data.commentStr = NULL; } // Setters void trpgLightAttr::SetType( trpgLightAttr::LightType in_type ) { - data.type = in_type; + data.type = in_type; } void trpgLightAttr::SetDirectionality( trpgLightAttr::LightDirectionality in_directionality ) { - data.directionality = in_directionality; + data.directionality = in_directionality; } void trpgLightAttr::SetFrontColor( trpgColor in_frontColor ) { - data.frontColor = in_frontColor; + data.frontColor = in_frontColor; } void trpgLightAttr::SetFrontIntensity( float64 in_frontIntensity ) { - data.frontIntensity = in_frontIntensity; + data.frontIntensity = in_frontIntensity; } void trpgLightAttr::SetBackColor( trpgColor in_backColor ) { - data.backColor = in_backColor; + data.backColor = in_backColor; } void trpgLightAttr::SetBackIntensity( float64 in_backIntensity ) { - data.backIntensity = in_backIntensity; + data.backIntensity = in_backIntensity; } void trpgLightAttr::SetNormal( trpg3dPoint in_normal ) { - data.normal = in_normal; + data.normal = in_normal; } void trpgLightAttr::SetSMC( int32 in_smc ) { - data.smc = in_smc; + data.smc = in_smc; } void trpgLightAttr::SetFID( int32 in_fid ) { - data.fid = in_fid; + data.fid = in_fid; } void trpgLightAttr::SetFlags( int32 in_flags ) { - data.flags = in_flags; + data.flags = in_flags; } void trpgLightAttr::SetHLobeAngle( float64 in_hLobeAngle ) { - data.horizontalLobeAngle = in_hLobeAngle; + data.horizontalLobeAngle = in_hLobeAngle; } void trpgLightAttr::SetVLobeAngle( float64 in_vLobeAngle ) { - data.verticalLobeAngle = in_vLobeAngle; + data.verticalLobeAngle = in_vLobeAngle; } void trpgLightAttr::SetLobeRollAngle( float64 in_lobeRollAngle ) { - data.lobeRollAngle = in_lobeRollAngle; + data.lobeRollAngle = in_lobeRollAngle; } void trpgLightAttr::SetLobeFalloff( float64 in_lobeFalloff ) { - data.lobeFalloff = in_lobeFalloff; + data.lobeFalloff = in_lobeFalloff; } void trpgLightAttr::SetAmbient( float64 in_ambientIntensity ) { - data.ambientIntensity = in_ambientIntensity; + data.ambientIntensity = in_ambientIntensity; } void trpgLightAttr::SetQuality( trpgLightAttr::LightQuality in_quality ) { - data.quality = in_quality; + data.quality = in_quality; } void trpgLightAttr::SetRascalSignificance( float64 in_rascalSignificance ) { - data.rascalSignificance = in_rascalSignificance; + data.rascalSignificance = in_rascalSignificance; } void trpgLightAttr::SetRandomIntensity( trpgLightAttr::LightQuality in_randomIntensity ) { - data.randomIntensity = in_randomIntensity; + data.randomIntensity = in_randomIntensity; } void trpgLightAttr::SetCalligraphicAttr( trpgLightAttr::CalligraphicAttr& in_calligraphicAttr ) { - data.calligraphicAttr = in_calligraphicAttr; + data.calligraphicAttr = in_calligraphicAttr; } void trpgLightAttr::SetCalligraphicDrawOrder( int32 in_drawOrder ) { - data.calligraphicAttr.drawOrder = in_drawOrder; + data.calligraphicAttr.drawOrder = in_drawOrder; } void trpgLightAttr::SetCalligraphicMinDefocus( float64 in_minDefocus ) { - data.calligraphicAttr.minDefocus = in_minDefocus; + data.calligraphicAttr.minDefocus = in_minDefocus; } void trpgLightAttr::SetCalligraphicMaxDefocus( float64 in_maxDefocus ) { - data.calligraphicAttr.maxDefocus = in_maxDefocus; + data.calligraphicAttr.maxDefocus = in_maxDefocus; } void trpgLightAttr::SetPerformerAttr( trpgLightAttr::PerformerAttr& in_performerAttr ) { - data.performerAttr = in_performerAttr; + data.performerAttr = in_performerAttr; } void trpgLightAttr::SetPerformerFlags( int32 in_flags ) { - data.performerAttr.flags = in_flags & trpgLightAttr::trpg_PerformerMask; - data.flags |= data.performerAttr.flags; + data.performerAttr.flags = in_flags & trpgLightAttr::trpg_PerformerMask; + data.flags |= data.performerAttr.flags; } void trpgLightAttr::SetPerformerMinPixelSize( float64 in_minPxSize ) { - data.performerAttr.minPixelSize = in_minPxSize; + data.performerAttr.minPixelSize = in_minPxSize; } void trpgLightAttr::SetPerformerMaxPixelSize( float64 in_maxPxSize ) { - data.performerAttr.maxPixelSize = in_maxPxSize; + data.performerAttr.maxPixelSize = in_maxPxSize; } void trpgLightAttr::SetPerformerActualSize( float64 in_actualSize ) { - data.performerAttr.actualSize = in_actualSize; + data.performerAttr.actualSize = in_actualSize; } void trpgLightAttr::SetPerformerTpPixelSize( float64 in_tpPixelSize ) { - data.performerAttr.transparentPixelSize = in_tpPixelSize; + data.performerAttr.transparentPixelSize = in_tpPixelSize; } void trpgLightAttr::SetPerformerTpFalloffExp( float64 in_tpFalloffExp ) { - data.performerAttr.transparentFallofExp = in_tpFalloffExp; + data.performerAttr.transparentFallofExp = in_tpFalloffExp; } void trpgLightAttr::SetPerformerTpScale( float64 in_tpScale ) { - data.performerAttr.transparentScale = in_tpScale; + data.performerAttr.transparentScale = in_tpScale; } void trpgLightAttr::SetPerformerTpClamp( float64 in_tpClamp ) { - data.performerAttr.transparentClamp = in_tpClamp; + data.performerAttr.transparentClamp = in_tpClamp; } void trpgLightAttr::SetPerformerFogScale( float64 in_fogScale ) { - data.performerAttr.fogScale = in_fogScale; + data.performerAttr.fogScale = in_fogScale; } void trpgLightAttr::SetAnimationAttr( trpgLightAttr::AnimationAttr& in_animationAttr ) { - data.animationAttr = in_animationAttr; + data.animationAttr = in_animationAttr; } void trpgLightAttr::SetAnimationPeriod( float64 in_period ) { - data.animationAttr.period = in_period; + data.animationAttr.period = in_period; } void trpgLightAttr::SetAnimationPhaseDelay( float64 in_phaseDelay ) { - data.animationAttr.phaseDelay = in_phaseDelay; + data.animationAttr.phaseDelay = in_phaseDelay; } void trpgLightAttr::SetAnimationTimeOn( float64 in_timeOn ) { - data.animationAttr.timeOn = in_timeOn; + data.animationAttr.timeOn = in_timeOn; } void trpgLightAttr::SetAnimationVector( trpg3dPoint in_vector ) { - data.animationAttr.vector = in_vector; + data.animationAttr.vector = in_vector; } void trpgLightAttr::SetAnimationFlags( int32 flags ) { - data.animationAttr.flags = flags & trpgLightAttr::trpg_AnimationMask; - data.flags |= data.animationAttr.flags; + data.animationAttr.flags = flags & trpgLightAttr::trpg_AnimationMask; + data.flags |= data.animationAttr.flags; } void trpgLightAttr::SetComment(const char *inStr) { - if (!inStr) - return; + if (!inStr) + return; - if (data.commentStr) - delete [] data.commentStr; - data.commentStr = new char[strlen(inStr)+1]; - strcpy(data.commentStr,inStr); + if (data.commentStr) + delete [] data.commentStr; + data.commentStr = new char[strlen(inStr)+1]; + strcpy(data.commentStr,inStr); } // Getters void trpgLightAttr::GetType( trpgLightAttr::LightType& out_type ) { - out_type = data.type; + out_type = data.type; } void trpgLightAttr::GetDirectionality( trpgLightAttr::LightDirectionality& out_directionality ) { - out_directionality = data.directionality; + out_directionality = data.directionality; } void trpgLightAttr::GetFrontColor( trpgColor& out_frontColor ) { - out_frontColor = data.frontColor; + out_frontColor = data.frontColor; } void trpgLightAttr::GetFrontIntensity( float64& out_frontIntensity ) { - out_frontIntensity = data.frontIntensity; + out_frontIntensity = data.frontIntensity; } void trpgLightAttr::GetBackColor( trpgColor& out_backColor ) { - out_backColor = data.backColor; + out_backColor = data.backColor; } void trpgLightAttr::GetBackIntensity( float64& out_backIntensity ) { - out_backIntensity = data.backIntensity; + out_backIntensity = data.backIntensity; } void trpgLightAttr::GetNormal( trpg3dPoint& out_normal ) { - out_normal = data.normal; + out_normal = data.normal; } void trpgLightAttr::GetSMC( int32& out_smc ) { - out_smc = data.smc; + out_smc = data.smc; } void trpgLightAttr::GetFID( int32& out_fid ) { - out_fid = data.fid; + out_fid = data.fid; } void trpgLightAttr::GetFlags( int32& out_flags ) { - out_flags = data.flags; + out_flags = data.flags; } void trpgLightAttr::GetHLobeAngle( float64& out_hLobeAngle ) { - out_hLobeAngle = data.horizontalLobeAngle; + out_hLobeAngle = data.horizontalLobeAngle; } void trpgLightAttr::GetVLobeAngle( float64& out_vLobeAngle ) { - out_vLobeAngle = data.verticalLobeAngle; + out_vLobeAngle = data.verticalLobeAngle; } void trpgLightAttr::GetLobeRollAngle( float64& out_lobeRollAngle ) { - out_lobeRollAngle = data.lobeRollAngle; + out_lobeRollAngle = data.lobeRollAngle; } void trpgLightAttr::GetLobeFalloff( float64& out_lobeFalloff ) { - out_lobeFalloff = data.lobeFalloff; + out_lobeFalloff = data.lobeFalloff; } void trpgLightAttr::GetAmbient( float64& out_ambientIntensity ) { - out_ambientIntensity = data.ambientIntensity; + out_ambientIntensity = data.ambientIntensity; } void trpgLightAttr::GetQuality( trpgLightAttr::LightQuality& out_quality ) { - out_quality = data.quality; + out_quality = data.quality; } void trpgLightAttr::GetRascalSignificance( float64& out_rascalSignificance ) { - out_rascalSignificance = data.rascalSignificance; + out_rascalSignificance = data.rascalSignificance; } void trpgLightAttr::GetRandomIntensity( trpgLightAttr::LightQuality& out_randomIntensity ) { - out_randomIntensity = data.randomIntensity; + out_randomIntensity = data.randomIntensity; } void trpgLightAttr::GetCalligraphicAttr( trpgLightAttr::CalligraphicAttr& out_calligraphicAttr ) { - out_calligraphicAttr = data.calligraphicAttr; + out_calligraphicAttr = data.calligraphicAttr; } void trpgLightAttr::GetCalligraphicDrawOrder( int32& out_drawOrder ) { - out_drawOrder = data.calligraphicAttr.drawOrder; + out_drawOrder = data.calligraphicAttr.drawOrder; } void trpgLightAttr::GetCalligraphicMinDefocus( float64& out_minDefocus ) { - out_minDefocus = data.calligraphicAttr.minDefocus; + out_minDefocus = data.calligraphicAttr.minDefocus; } void trpgLightAttr::GetCalligraphicMaxDefocus( float64& out_maxDefocus ) { - out_maxDefocus = data.calligraphicAttr.maxDefocus; + out_maxDefocus = data.calligraphicAttr.maxDefocus; } void trpgLightAttr::GetPerformerAttr( trpgLightAttr::PerformerAttr& out_performerAttr ) { - out_performerAttr = data.performerAttr; + out_performerAttr = data.performerAttr; } void trpgLightAttr::GetPerformerFlags( int32& out_flags ) { - out_flags = data.performerAttr.flags; + out_flags = data.performerAttr.flags; } void trpgLightAttr::GetPerformerMinPixelSize( float64& out_minPxSize ) { - out_minPxSize = data.performerAttr.minPixelSize; + out_minPxSize = data.performerAttr.minPixelSize; } void trpgLightAttr::GetPerformerMaxPixelSize( float64& out_maxPxSize ) { - out_maxPxSize = data.performerAttr.maxPixelSize; + out_maxPxSize = data.performerAttr.maxPixelSize; } void trpgLightAttr::GetPerformerActualSize( float64& out_actualSize ) { - out_actualSize = data.performerAttr.actualSize; + out_actualSize = data.performerAttr.actualSize; } void trpgLightAttr::GetPerformerTpPixelSize( float64& out_tpPixelSize ) { - out_tpPixelSize = data.performerAttr.transparentPixelSize; + out_tpPixelSize = data.performerAttr.transparentPixelSize; } void trpgLightAttr::GetPerformerTpFalloffExp( float64& out_tpFalloffExp ) { - out_tpFalloffExp = data.performerAttr.transparentFallofExp; + out_tpFalloffExp = data.performerAttr.transparentFallofExp; } void trpgLightAttr::GetPerformerTpScale( float64& out_tpScale ) { - out_tpScale = data.performerAttr.transparentScale; + out_tpScale = data.performerAttr.transparentScale; } void trpgLightAttr::GetPerformerTpClamp( float64& out_tpClamp ) { - out_tpClamp = data.performerAttr.transparentClamp; + out_tpClamp = data.performerAttr.transparentClamp; } void trpgLightAttr::GetPerformerFogScale( float64& out_fogScale ) { - out_fogScale = data.performerAttr.fogScale; + out_fogScale = data.performerAttr.fogScale; } void trpgLightAttr::GetAnimationAttr( trpgLightAttr::AnimationAttr& out_animationAttr ) { - out_animationAttr = data.animationAttr; + out_animationAttr = data.animationAttr; } void trpgLightAttr::GetAnimationPeriod( float64& out_period ) { - out_period = data.animationAttr.period; + out_period = data.animationAttr.period; } void trpgLightAttr::GetAnimationPhaseDelay( float64& out_phaseDelay ) { - out_phaseDelay = data.animationAttr.phaseDelay; + out_phaseDelay = data.animationAttr.phaseDelay; } void trpgLightAttr::GetAnimationTimeOn( float64& out_timeOn ) { - out_timeOn = data.animationAttr.timeOn; + out_timeOn = data.animationAttr.timeOn; } void trpgLightAttr::GetAnimationVector( trpg3dPoint& out_vector ) { - out_vector = data.animationAttr.vector; + out_vector = data.animationAttr.vector; } void trpgLightAttr::GetAnimationFlags( int32& flags ) { - flags = data.animationAttr.flags; + flags = data.animationAttr.flags; } const char *trpgLightAttr::GetComment() { - return data.commentStr; + return data.commentStr; } // Writes this class to a write buffer bool trpgLightAttr::Write(trpgWriteBuffer &buf) { - buf.Begin(TRPGLIGHTATTR); + buf.Begin(TRPGLIGHTATTR); - buf.Begin(TRPGLIGHTATTR_BASIC); - buf.Add((int)data.type); - buf.Add((int)data.directionality); - buf.Add(data.frontColor); - buf.Add(data.frontIntensity); - buf.Add(data.backColor); - buf.Add(data.backIntensity); - buf.Add(data.normal); - buf.Add(data.smc); - buf.Add(data.fid); - buf.Add(data.flags); - buf.Add(data.horizontalLobeAngle); - buf.Add(data.verticalLobeAngle); - buf.Add(data.lobeRollAngle); - buf.Add(data.lobeFalloff); - buf.Add(data.ambientIntensity); - buf.Add((int)data.quality); - buf.Add((int)data.randomIntensity); - buf.End(); + buf.Begin(TRPGLIGHTATTR_BASIC); + buf.Add((int)data.type); + buf.Add((int)data.directionality); + buf.Add(data.frontColor); + buf.Add(data.frontIntensity); + buf.Add(data.backColor); + buf.Add(data.backIntensity); + buf.Add(data.normal); + buf.Add(data.smc); + buf.Add(data.fid); + buf.Add(data.flags); + buf.Add(data.horizontalLobeAngle); + buf.Add(data.verticalLobeAngle); + buf.Add(data.lobeRollAngle); + buf.Add(data.lobeFalloff); + buf.Add(data.ambientIntensity); + buf.Add((int)data.quality); + buf.Add((int)data.randomIntensity); + buf.End(); - buf.Begin(TRPGLIGHTATTR_RASCAL); - buf.Add(data.rascalSignificance); - buf.End(); + buf.Begin(TRPGLIGHTATTR_RASCAL); + buf.Add(data.rascalSignificance); + buf.End(); - buf.Begin(TRPGLIGHTATTR_CALLIGRAPHIC); - buf.Add(data.calligraphicAttr.drawOrder); - buf.Add(data.calligraphicAttr.minDefocus); - buf.Add(data.calligraphicAttr.maxDefocus); - buf.End(); + buf.Begin(TRPGLIGHTATTR_CALLIGRAPHIC); + buf.Add(data.calligraphicAttr.drawOrder); + buf.Add(data.calligraphicAttr.minDefocus); + buf.Add(data.calligraphicAttr.maxDefocus); + buf.End(); - buf.Begin(TRPGLIGHTATTR_PERFORMER); - buf.Add(data.performerAttr.actualSize); - buf.Add(data.performerAttr.fogScale); - buf.Add(data.performerAttr.minPixelSize); - buf.Add(data.performerAttr.maxPixelSize); - buf.Add(data.performerAttr.transparentClamp); - buf.Add(data.performerAttr.transparentFallofExp); - buf.Add(data.performerAttr.transparentPixelSize); - buf.Add(data.performerAttr.transparentScale); - buf.End(); + buf.Begin(TRPGLIGHTATTR_PERFORMER); + buf.Add(data.performerAttr.actualSize); + buf.Add(data.performerAttr.fogScale); + buf.Add(data.performerAttr.minPixelSize); + buf.Add(data.performerAttr.maxPixelSize); + buf.Add(data.performerAttr.transparentClamp); + buf.Add(data.performerAttr.transparentFallofExp); + buf.Add(data.performerAttr.transparentPixelSize); + buf.Add(data.performerAttr.transparentScale); + buf.End(); - buf.Begin(TRPGLIGHTATTR_ANIMATION); - buf.Add(data.animationAttr.period); - buf.Add(data.animationAttr.phaseDelay); - buf.Add(data.animationAttr.timeOn); - buf.Add(data.animationAttr.vector); - buf.End(); + buf.Begin(TRPGLIGHTATTR_ANIMATION); + buf.Add(data.animationAttr.period); + buf.Add(data.animationAttr.phaseDelay); + buf.Add(data.animationAttr.timeOn); + buf.Add(data.animationAttr.vector); + buf.End(); - if (data.commentStr) { - buf.Begin(TRPGLIGHTATTR_COMMENT); - buf.Add(data.commentStr); - buf.End(); - } + if (data.commentStr) { + buf.Begin(TRPGLIGHTATTR_COMMENT); + buf.Add(data.commentStr); + buf.End(); + } - if(writeHandle) { - buf.Begin(TRPGLIGHTATTR_HANDLE); - buf.Add((int)handle); - buf.End(); - } - buf.End(); + if(writeHandle) { + buf.Begin(TRPGLIGHTATTR_HANDLE); + buf.Add((int)handle); + buf.End(); + } + buf.End(); - return true; + return true; } /* LightAttr CB - Used to parse tokens for a light attribute. - */ + Used to parse tokens for a light attribute. + */ class lightAttrCB : public trpgr_Callback { public: - void * Parse(trpgToken,trpgReadBuffer &); - trpgLightAttr *lightAttr; + void * Parse(trpgToken,trpgReadBuffer &); + trpgLightAttr *lightAttr; }; void * lightAttrCB::Parse(trpgToken tok,trpgReadBuffer &buf) { - int type_data; - int directionality_data; - trpgColor color_data;; - float64 float64_data; - trpg3dPoint point_data;; - int32 int32_data; - int quality_data; - char commentStr[1024]; + int type_data; + int directionality_data; + trpgColor color_data;; + float64 float64_data; + trpg3dPoint point_data;; + int32 int32_data; + int quality_data; + char commentStr[1024]; - try { - switch (tok) { - case TRPGLIGHTATTR_BASIC: - buf.Get(type_data); - lightAttr->SetType((trpgLightAttr::LightType)type_data); - buf.Get(directionality_data); - lightAttr->SetDirectionality((trpgLightAttr::LightDirectionality)directionality_data); - buf.Get(color_data); - lightAttr->SetFrontColor(color_data); - buf.Get(float64_data); - lightAttr->SetFrontIntensity(float64_data); - buf.Get(color_data); - lightAttr->SetBackColor(color_data); - buf.Get(float64_data); - lightAttr->SetBackIntensity(float64_data); - buf.Get(point_data); - lightAttr->SetNormal(point_data); - buf.Get(int32_data); - lightAttr->SetSMC(int32_data); - buf.Get(int32_data); - lightAttr->SetFID(int32_data); - buf.Get(int32_data); - lightAttr->SetFlags(int32_data); - lightAttr->SetPerformerFlags(int32_data); - lightAttr->SetAnimationFlags(int32_data); - buf.Get(float64_data); - lightAttr->SetHLobeAngle(float64_data); - buf.Get(float64_data); - lightAttr->SetVLobeAngle(float64_data); - buf.Get(float64_data); - lightAttr->SetLobeRollAngle(float64_data); - buf.Get(float64_data); - lightAttr->SetLobeFalloff(float64_data); - buf.Get(float64_data); - lightAttr->SetAmbient(float64_data); - buf.Get(quality_data); - lightAttr->SetQuality((trpgLightAttr::LightQuality)quality_data); - buf.Get(quality_data); - lightAttr->SetRandomIntensity((trpgLightAttr::LightQuality)quality_data); - break; - case TRPGLIGHTATTR_RASCAL: - buf.Get(float64_data); - lightAttr->SetRascalSignificance(float64_data); - break; - case TRPGLIGHTATTR_PERFORMER: - buf.Get(float64_data); - lightAttr->SetPerformerActualSize(float64_data); - buf.Get(float64_data); - lightAttr->SetPerformerFogScale(float64_data); - buf.Get(float64_data); - lightAttr->SetPerformerMinPixelSize(float64_data); - buf.Get(float64_data); - lightAttr->SetPerformerMaxPixelSize(float64_data); - buf.Get(float64_data); - lightAttr->SetPerformerTpClamp(float64_data); - buf.Get(float64_data); - lightAttr->SetPerformerTpFalloffExp(float64_data); - buf.Get(float64_data); - lightAttr->SetPerformerTpPixelSize(float64_data); - buf.Get(float64_data); - lightAttr->SetPerformerTpScale(float64_data); - break; - case TRPGLIGHTATTR_CALLIGRAPHIC: - buf.Get(int32_data); - lightAttr->SetCalligraphicDrawOrder(int32_data); - buf.Get(float64_data); - lightAttr->SetCalligraphicMinDefocus(float64_data); - buf.Get(float64_data); - lightAttr->SetCalligraphicMaxDefocus(float64_data); - break; - case TRPGLIGHTATTR_ANIMATION: - buf.Get(float64_data); - lightAttr->SetAnimationPeriod(float64_data); - buf.Get(float64_data); - lightAttr->SetAnimationPhaseDelay(float64_data); - buf.Get(float64_data); - lightAttr->SetAnimationTimeOn(float64_data); - buf.Get(point_data); - lightAttr->SetAnimationVector(point_data); - break; - case TRPGLIGHTATTR_COMMENT: - buf.Get(commentStr,1024); - lightAttr->SetComment(commentStr); - break; - case TRPGLIGHTATTR_HANDLE: - int hdl; - buf.Get(hdl); - lightAttr->SetHandle(hdl); - break; - default: - break; - } - } - catch (...) { - return NULL; - } + try { + switch (tok) { + case TRPGLIGHTATTR_BASIC: + buf.Get(type_data); + lightAttr->SetType((trpgLightAttr::LightType)type_data); + buf.Get(directionality_data); + lightAttr->SetDirectionality((trpgLightAttr::LightDirectionality)directionality_data); + buf.Get(color_data); + lightAttr->SetFrontColor(color_data); + buf.Get(float64_data); + lightAttr->SetFrontIntensity(float64_data); + buf.Get(color_data); + lightAttr->SetBackColor(color_data); + buf.Get(float64_data); + lightAttr->SetBackIntensity(float64_data); + buf.Get(point_data); + lightAttr->SetNormal(point_data); + buf.Get(int32_data); + lightAttr->SetSMC(int32_data); + buf.Get(int32_data); + lightAttr->SetFID(int32_data); + buf.Get(int32_data); + lightAttr->SetFlags(int32_data); + lightAttr->SetPerformerFlags(int32_data); + lightAttr->SetAnimationFlags(int32_data); + buf.Get(float64_data); + lightAttr->SetHLobeAngle(float64_data); + buf.Get(float64_data); + lightAttr->SetVLobeAngle(float64_data); + buf.Get(float64_data); + lightAttr->SetLobeRollAngle(float64_data); + buf.Get(float64_data); + lightAttr->SetLobeFalloff(float64_data); + buf.Get(float64_data); + lightAttr->SetAmbient(float64_data); + buf.Get(quality_data); + lightAttr->SetQuality((trpgLightAttr::LightQuality)quality_data); + buf.Get(quality_data); + lightAttr->SetRandomIntensity((trpgLightAttr::LightQuality)quality_data); + break; + case TRPGLIGHTATTR_RASCAL: + buf.Get(float64_data); + lightAttr->SetRascalSignificance(float64_data); + break; + case TRPGLIGHTATTR_PERFORMER: + buf.Get(float64_data); + lightAttr->SetPerformerActualSize(float64_data); + buf.Get(float64_data); + lightAttr->SetPerformerFogScale(float64_data); + buf.Get(float64_data); + lightAttr->SetPerformerMinPixelSize(float64_data); + buf.Get(float64_data); + lightAttr->SetPerformerMaxPixelSize(float64_data); + buf.Get(float64_data); + lightAttr->SetPerformerTpClamp(float64_data); + buf.Get(float64_data); + lightAttr->SetPerformerTpFalloffExp(float64_data); + buf.Get(float64_data); + lightAttr->SetPerformerTpPixelSize(float64_data); + buf.Get(float64_data); + lightAttr->SetPerformerTpScale(float64_data); + break; + case TRPGLIGHTATTR_CALLIGRAPHIC: + buf.Get(int32_data); + lightAttr->SetCalligraphicDrawOrder(int32_data); + buf.Get(float64_data); + lightAttr->SetCalligraphicMinDefocus(float64_data); + buf.Get(float64_data); + lightAttr->SetCalligraphicMaxDefocus(float64_data); + break; + case TRPGLIGHTATTR_ANIMATION: + buf.Get(float64_data); + lightAttr->SetAnimationPeriod(float64_data); + buf.Get(float64_data); + lightAttr->SetAnimationPhaseDelay(float64_data); + buf.Get(float64_data); + lightAttr->SetAnimationTimeOn(float64_data); + buf.Get(point_data); + lightAttr->SetAnimationVector(point_data); + break; + case TRPGLIGHTATTR_COMMENT: + buf.Get(commentStr,1024); + lightAttr->SetComment(commentStr); + break; + case TRPGLIGHTATTR_HANDLE: + int hdl; + buf.Get(hdl); + lightAttr->SetHandle(hdl); + break; + default: + break; + } + } + catch (...) { + return NULL; + } - return lightAttr; + return lightAttr; } // Reads this class from a read buffer bool trpgLightAttr::Read(trpgReadBuffer &buf) { - Reset(); + Reset(); - trpgr_Parser parse; - lightAttrCB lightAttrCb; + trpgr_Parser parse; + lightAttrCB lightAttrCb; - // Light attribute is just a bunch of unordered tokens. - // Interface to it with a generic parser - lightAttrCb.lightAttr = this; - parse.AddCallback(TRPGLIGHTATTR_BASIC,&lightAttrCb,false); - parse.AddCallback(TRPGLIGHTATTR_PERFORMER,&lightAttrCb,false); - parse.AddCallback(TRPGLIGHTATTR_RASCAL,&lightAttrCb,false); - parse.AddCallback(TRPGLIGHTATTR_CALLIGRAPHIC,&lightAttrCb,false); - parse.AddCallback(TRPGLIGHTATTR_ANIMATION,&lightAttrCb,false); - parse.AddCallback(TRPGLIGHTATTR_COMMENT,&lightAttrCb,false); - parse.AddCallback(TRPGLIGHTATTR_HANDLE,&lightAttrCb,false); - parse.Parse(buf); + // Light attribute is just a bunch of unordered tokens. + // Interface to it with a generic parser + lightAttrCb.lightAttr = this; + parse.AddCallback(TRPGLIGHTATTR_BASIC,&lightAttrCb,false); + parse.AddCallback(TRPGLIGHTATTR_PERFORMER,&lightAttrCb,false); + parse.AddCallback(TRPGLIGHTATTR_RASCAL,&lightAttrCb,false); + parse.AddCallback(TRPGLIGHTATTR_CALLIGRAPHIC,&lightAttrCb,false); + parse.AddCallback(TRPGLIGHTATTR_ANIMATION,&lightAttrCb,false); + parse.AddCallback(TRPGLIGHTATTR_COMMENT,&lightAttrCb,false); + parse.AddCallback(TRPGLIGHTATTR_HANDLE,&lightAttrCb,false); + parse.Parse(buf); - return isValid(); + return isValid(); } bool trpgLightAttr::isValid(void) const { - return true; + return true; } trpgLightAttr& trpgLightAttr::operator = (const trpgLightAttr& in) { - data = in.data; - if (in.data.commentStr) { - data.commentStr = new char[strlen(in.data.commentStr)+1]; - strcpy(data.commentStr,in.data.commentStr); - } - handle = in.handle; - writeHandle = in.writeHandle; - return *this; + data = in.data; + if (in.data.commentStr) { + data.commentStr = new char[strlen(in.data.commentStr)+1]; + strcpy(data.commentStr,in.data.commentStr); + } + handle = in.handle; + writeHandle = in.writeHandle; + return *this; } bool trpgLightAttr::operator == (const trpgLightAttr& in) { - // this doesn't work, so do it a hard way - // return memcmp( &data,&in.data,sizeof(data) ) == 0; + // this doesn't work, so do it a hard way + // return memcmp( &data,&in.data,sizeof(data) ) == 0; - if ( data.type != in.data.type ) - return false; - if ( data.directionality != in.data.directionality ) - return false; - if ( data.frontColor != in.data.frontColor ) - return false; - if ( data.frontIntensity != in.data.frontIntensity ) - return false; - if ( data.backColor != in.data.backColor ) - return false; - if ( data.backIntensity != in.data.backIntensity ) - return false; - if ( data.normal != in.data.normal ) - return false; - if ( data.smc != in.data.smc ) - return false; - if ( data.fid != in.data.fid ) - return false; - if ( data.flags != in.data.flags ) - return false; - if ( data.horizontalLobeAngle != in.data.horizontalLobeAngle ) - return false; - if ( data.verticalLobeAngle != in.data.verticalLobeAngle ) - return false; - if ( data.lobeRollAngle != in.data.lobeRollAngle ) - return false; - if ( data.lobeFalloff != in.data.lobeFalloff ) - return false; - if ( data.ambientIntensity != in.data.ambientIntensity ) - return false; - if ( data.quality != in.data.quality ) - return false; - if ( data.randomIntensity != in.data.randomIntensity ) - return false; - if ( data.rascalSignificance != in.data.rascalSignificance ) - return false; - if ( data.calligraphicAttr.drawOrder != in.data.calligraphicAttr.drawOrder ) - return false; - if ( data.calligraphicAttr.minDefocus != in.data.calligraphicAttr.minDefocus ) - return false; - if ( data.calligraphicAttr.maxDefocus != in.data.calligraphicAttr.maxDefocus ) - return false; - if ( data.performerAttr.flags != in.data.performerAttr.flags ) - return false; - if ( data.performerAttr.minPixelSize != in.data.performerAttr.minPixelSize ) - return false; - if ( data.performerAttr.maxPixelSize != in.data.performerAttr.maxPixelSize ) - return false; - if ( data.performerAttr.actualSize != in.data.performerAttr.actualSize ) - return false; - if ( data.performerAttr.transparentPixelSize != in.data.performerAttr.transparentPixelSize ) - return false; - if ( data.performerAttr.transparentFallofExp != in.data.performerAttr.transparentFallofExp ) - return false; - if ( data.performerAttr.transparentScale != in.data.performerAttr.transparentScale ) - return false; - if ( data.performerAttr.transparentClamp != in.data.performerAttr.transparentClamp ) - return false; - if ( data.performerAttr.fogScale != in.data.performerAttr.fogScale ) - return false; - if ( data.animationAttr.period != in.data.animationAttr.period ) - return false; - if ( data.animationAttr.phaseDelay != in.data.animationAttr.phaseDelay ) - return false; - if ( data.animationAttr.timeOn != in.data.animationAttr.timeOn ) - return false; - if ( data.animationAttr.vector != in.data.animationAttr.vector ) - return false; - if ( data.animationAttr.flags != in.data.animationAttr.flags ) - return false; - if ( (data.commentStr && !in.data.commentStr) || - (!data.commentStr && in.data.commentStr)) - return false; - if (data.commentStr && in.data.commentStr && strcmp(data.commentStr,in.data.commentStr)) - return false; - if (handle != in.handle) - return false; - if (writeHandle != in.writeHandle) - return false; - return true; + if ( data.type != in.data.type ) + return false; + if ( data.directionality != in.data.directionality ) + return false; + if ( data.frontColor != in.data.frontColor ) + return false; + if ( data.frontIntensity != in.data.frontIntensity ) + return false; + if ( data.backColor != in.data.backColor ) + return false; + if ( data.backIntensity != in.data.backIntensity ) + return false; + if ( data.normal != in.data.normal ) + return false; + if ( data.smc != in.data.smc ) + return false; + if ( data.fid != in.data.fid ) + return false; + if ( data.flags != in.data.flags ) + return false; + if ( data.horizontalLobeAngle != in.data.horizontalLobeAngle ) + return false; + if ( data.verticalLobeAngle != in.data.verticalLobeAngle ) + return false; + if ( data.lobeRollAngle != in.data.lobeRollAngle ) + return false; + if ( data.lobeFalloff != in.data.lobeFalloff ) + return false; + if ( data.ambientIntensity != in.data.ambientIntensity ) + return false; + if ( data.quality != in.data.quality ) + return false; + if ( data.randomIntensity != in.data.randomIntensity ) + return false; + if ( data.rascalSignificance != in.data.rascalSignificance ) + return false; + if ( data.calligraphicAttr.drawOrder != in.data.calligraphicAttr.drawOrder ) + return false; + if ( data.calligraphicAttr.minDefocus != in.data.calligraphicAttr.minDefocus ) + return false; + if ( data.calligraphicAttr.maxDefocus != in.data.calligraphicAttr.maxDefocus ) + return false; + if ( data.performerAttr.flags != in.data.performerAttr.flags ) + return false; + if ( data.performerAttr.minPixelSize != in.data.performerAttr.minPixelSize ) + return false; + if ( data.performerAttr.maxPixelSize != in.data.performerAttr.maxPixelSize ) + return false; + if ( data.performerAttr.actualSize != in.data.performerAttr.actualSize ) + return false; + if ( data.performerAttr.transparentPixelSize != in.data.performerAttr.transparentPixelSize ) + return false; + if ( data.performerAttr.transparentFallofExp != in.data.performerAttr.transparentFallofExp ) + return false; + if ( data.performerAttr.transparentScale != in.data.performerAttr.transparentScale ) + return false; + if ( data.performerAttr.transparentClamp != in.data.performerAttr.transparentClamp ) + return false; + if ( data.performerAttr.fogScale != in.data.performerAttr.fogScale ) + return false; + if ( data.animationAttr.period != in.data.animationAttr.period ) + return false; + if ( data.animationAttr.phaseDelay != in.data.animationAttr.phaseDelay ) + return false; + if ( data.animationAttr.timeOn != in.data.animationAttr.timeOn ) + return false; + if ( data.animationAttr.vector != in.data.animationAttr.vector ) + return false; + if ( data.animationAttr.flags != in.data.animationAttr.flags ) + return false; + if ( (data.commentStr && !in.data.commentStr) || + (!data.commentStr && in.data.commentStr)) + return false; + if (data.commentStr && in.data.commentStr && strcmp(data.commentStr,in.data.commentStr)) + return false; + if (handle != in.handle) + return false; + if (writeHandle != in.writeHandle) + return false; + return true; } bool trpgLightAttr::operator != (const trpgLightAttr& in) { - return !operator==(in); + return !operator==(in); } void trpgLightAttr::Reset(void) { - errMess[0] = '\0'; - data.type = trpg_Raster; - data.directionality = trpg_Omnidirectional; - data.frontColor = trpgColor(0,0,0); - data.frontIntensity = 0; - data.backColor = trpgColor(0,0,0); - data.backIntensity = 0; - data.normal = trpg3dPoint(0,0,1); - data.smc = 0; - data.fid = 0; - data.flags = 0; - data.horizontalLobeAngle = 0; - data.verticalLobeAngle = 0; - data.lobeRollAngle = 0; - data.lobeFalloff = 0; - data.ambientIntensity = 0; - data.quality = trpg_Low; - data.randomIntensity = trpg_Low; - data.rascalSignificance = 0; - data.calligraphicAttr.drawOrder = 0; - data.calligraphicAttr.minDefocus = 0; - data.calligraphicAttr.maxDefocus = 0; - data.performerAttr.flags = 0; - data.performerAttr.minPixelSize = 0; - data.performerAttr.maxPixelSize = 0; - data.performerAttr.actualSize = 0; - data.performerAttr.transparentPixelSize = 0; - data.performerAttr.transparentFallofExp = 0; - data.performerAttr.transparentScale = 0; - data.performerAttr.transparentClamp = 0; - data.performerAttr.fogScale = 0; - data.animationAttr.period = 0; - data.animationAttr.phaseDelay = 0; - data.animationAttr.timeOn = 0; - data.animationAttr.vector = trpg3dPoint(0,0,1); - data.animationAttr.flags = 0; - if (data.commentStr) - delete [] data.commentStr; - data.commentStr = NULL; - handle = -1; - writeHandle = false; + errMess[0] = '\0'; + data.type = trpg_Raster; + data.directionality = trpg_Omnidirectional; + data.frontColor = trpgColor(0,0,0); + data.frontIntensity = 0; + data.backColor = trpgColor(0,0,0); + data.backIntensity = 0; + data.normal = trpg3dPoint(0,0,1); + data.smc = 0; + data.fid = 0; + data.flags = 0; + data.horizontalLobeAngle = 0; + data.verticalLobeAngle = 0; + data.lobeRollAngle = 0; + data.lobeFalloff = 0; + data.ambientIntensity = 0; + data.quality = trpg_Low; + data.randomIntensity = trpg_Low; + data.rascalSignificance = 0; + data.calligraphicAttr.drawOrder = 0; + data.calligraphicAttr.minDefocus = 0; + data.calligraphicAttr.maxDefocus = 0; + data.performerAttr.flags = 0; + data.performerAttr.minPixelSize = 0; + data.performerAttr.maxPixelSize = 0; + data.performerAttr.actualSize = 0; + data.performerAttr.transparentPixelSize = 0; + data.performerAttr.transparentFallofExp = 0; + data.performerAttr.transparentScale = 0; + data.performerAttr.transparentClamp = 0; + data.performerAttr.fogScale = 0; + data.animationAttr.period = 0; + data.animationAttr.phaseDelay = 0; + data.animationAttr.timeOn = 0; + data.animationAttr.vector = trpg3dPoint(0,0,1); + data.animationAttr.flags = 0; + if (data.commentStr) + delete [] data.commentStr; + data.commentStr = NULL; + handle = -1; + writeHandle = false; } /************** - Light + Light */ trpgLight::trpgLight(void) { - index = -1; + index = -1; } trpgLight::trpgLight(const trpgLight &in): trpgReadWriteable(in) { - operator=(in); + operator=(in); } trpgLight::~trpgLight(void) { - Reset(); + Reset(); } // Set the index pointing into the Light Table void trpgLight::SetAttrIndex(int ix) { - index = ix; + index = ix; } // Add a new location this light is located at void trpgLight::AddVertex(trpg3dPoint pt) { - lightPoints.push_back(pt); + lightPoints.push_back(pt); } // Returns the number of locations, this light is located at void trpgLight::GetNumVertices(uint32 &nvertices) const { - nvertices = lightPoints.size(); + nvertices = lightPoints.size(); } // Returns the location at a given index bool trpgLight::GetVertex(uint32 ix, trpg3dPoint &pt) const { - if (ix < lightPoints.size() ) { - pt = lightPoints[ix]; - return true; - } - else - return false; + if (ix < lightPoints.size() ) { + pt = lightPoints[ix]; + return true; + } + else + return false; } bool trpgLight::GetVertices(trpg3dPoint *pts) const { - unsigned int i; + unsigned int i; - if (!isValid()) return false; + if (!isValid()) return false; - if (lightPoints.size() != 0) - for (i=0;isecond.isValid()) - { - if(itr->second.getErrMess()) - strcpy(errMess, itr->second.getErrMess()); - return false; - } - } + LightMapType::const_iterator itr = lightMap.begin(); + for ( ; itr != lightMap.end( ); itr++) + { + if (!itr->second.isValid()) + { + if(itr->second.getErrMess()) + strcpy(errMess, itr->second.getErrMess()); + return false; + } + } - return true; + return true; } // Set functions int trpgLightTable::AddLightAttr(const trpgLightAttr& inLight) { - int handle = inLight.GetHandle(); - if(handle==-1) { - handle = lightMap.size(); - } - lightMap[handle] = inLight; - return handle; + int handle = inLight.GetHandle(); + if(handle==-1) { + handle = lightMap.size(); + } + lightMap[handle] = inLight; + return handle; } int trpgLightTable::FindAddLightAttr(const trpgLightAttr& inLight) { - LightMapType::iterator itr = lightMap.begin(); - for ( ; itr != lightMap.end( ); itr++) { - if(itr->second==inLight) - return itr->first; - } - return AddLightAttr(inLight); + LightMapType::iterator itr = lightMap.begin(); + for ( ; itr != lightMap.end( ); itr++) { + if(itr->second==inLight) + return itr->first; + } + return AddLightAttr(inLight); } // Copy operator trpgLightTable &trpgLightTable::operator = (const trpgLightTable &in) { - Reset(); + Reset(); - LightMapType::const_iterator itr = in.lightMap.begin(); - for ( ; itr != in.lightMap.end( ); itr++) { - AddLightAttr(itr->second); - } - //for (int i=0;isecond); + } + //for (int i=0;isecond.Write(buf); - //for (unsigned int i=0;isecond.Write(buf); + //for (unsigned int i=0;isecond; + return &itr->second; } bool trpgLightTable::Read(trpgReadBuffer &buf) { - int32 numLights; - trpgToken lightTok; - int32 len; + int32 numLights; + trpgToken lightTok; + int32 len; - try { - buf.Get(numLights); - for (int i=0;i diff --git a/src/osgPlugins/txp/trpage_managers.cpp b/src/osgPlugins/txp/trpage_managers.cpp index e23e52c66..c5dd99656 100644 --- a/src/osgPlugins/txp/trpage_managers.cpp +++ b/src/osgPlugins/txp/trpage_managers.cpp @@ -25,7 +25,7 @@ #include /* Managed Tile class. - Check the header file for details. + Check the header file for details. */ trpgManagedTile::trpgManagedTile() @@ -40,7 +40,7 @@ void trpgManagedTile::Reset() { // Null out the local material data for (unsigned int i=0;i= (int)childLocationInfo.size()) - throw std::invalid_argument( + throw std::invalid_argument( "trpgManagedTile::GetChildLocationInfo(): index argument out of bound."); @@ -156,7 +156,7 @@ const TileLocationInfo& trpgManagedTile::GetChildLocationInfo(int childIdx) cons bool trpgManagedTile::GetChildTileLoc(int childIdx, int &x,int &y,int &lod) const { if(childIdx < 0 || childIdx >= (int)childLocationInfo.size()) - throw std::invalid_argument( + throw std::invalid_argument( "trpgManagedTile::GetChildTileLoc(): index argument out of bound."); TileLocationInfo const& info = childLocationInfo[childIdx]; @@ -170,7 +170,7 @@ bool trpgManagedTile::GetChildTileLoc(int childIdx, int &x,int &y,int &lod) cons const trpgwAppAddress& trpgManagedTile::GetChildTileAddress(int childIdx) const { if(childIdx < 0 || childIdx >= (int)childLocationInfo.size()) - throw std::invalid_argument( + throw std::invalid_argument( "trpgManagedTile::GetChildTileAddress(): index argument out of bound."); return childLocationInfo[childIdx].addr; } @@ -191,7 +191,7 @@ const trpgLocalMaterial *trpgManagedTile::GetLocMaterial(int id) const matList = tileHead.GetLocalMaterialList(); if (id <0 || id >= (int)matList->size()) - return NULL; + return NULL; return &(*matList)[id]; } @@ -209,7 +209,7 @@ void *trpgManagedTile::GetLocalData() const bool trpgManagedTile::SetMatData(int id,void *info) { if (id < 0 || id >= (int)localMatData.size()) - return false; + return false; localMatData[id] = info; @@ -219,7 +219,7 @@ bool trpgManagedTile::SetMatData(int id,void *info) void *trpgManagedTile::GetMatData(int id) const { if (id < 0 || id >= (int)localMatData.size()) - return NULL; + return NULL; return localMatData[id]; } @@ -263,19 +263,19 @@ void trpgPageManager::LodPageInfo::Clean() // Clean up managed tile structures unsigned int i; for (i=0;i= 1) - maxNumTiles = (int)(1.15*(2*aoiSize.x+1)*(2*aoiSize.y+1)/freeListDivider); + maxNumTiles = (int)(1.15*(2*aoiSize.x+1)*(2*aoiSize.y+1)/freeListDivider); else - maxNumTiles = (int)(1.15*(2*aoiSize.x+1)*(2*aoiSize.y+1)); + maxNumTiles = (int)(1.15*(2*aoiSize.x+1)*(2*aoiSize.y+1)); // Allocate 'em for (int i=0;i 0) { - activeLoad = true; - return load[0]; + activeLoad = true; + return load[0]; } return NULL; @@ -383,8 +383,8 @@ trpgManagedTile *trpgPageManager::LodPageInfo::GetNextLoad() void trpgPageManager::LodPageInfo::AckLoad() { if (activeLoad) { - current.push_back(load[0]); - load.pop_front(); + current.push_back(load[0]); + load.pop_front(); } activeLoad = false; } @@ -393,15 +393,15 @@ trpgManagedTile *trpgPageManager::LodPageInfo::GetNextUnload() { // Can only unload one tile at a time if (activeUnload) - return NULL; + return NULL; // Clear any NULLs at the beginning while (unload.size() && !unload[0]) - unload.pop_front(); + unload.pop_front(); if (unload.size() > 0) { - activeUnload = true; - return unload[0]; + activeUnload = true; + return unload[0]; } return NULL; @@ -410,10 +410,10 @@ trpgManagedTile *trpgPageManager::LodPageInfo::GetNextUnload() void trpgPageManager::LodPageInfo::AckUnload() { if (activeUnload) { - trpgManagedTile *tile = unload[0]; - tile->Reset(); - freeList.push_back(tile); - unload.pop_front(); + trpgManagedTile *tile = unload[0]; + tile->Reset(); + freeList.push_back(tile); + unload.pop_front(); } activeUnload = false; } @@ -424,11 +424,11 @@ bool trpgPageManager::LodPageInfo::isWithin(trpgManagedTile *tile,trpg2iPoint &s tile->GetTileLoc(tileX,tileY,tileLod); if (tileX >= sw.x && tileX <= ne.x && - tileY >= sw.y && + tileY >= sw.y && tileY <= ne.y) - return true; + return true; else - return false; + return false; } bool trpgPageManager::LodPageInfo::Stop() @@ -436,13 +436,13 @@ bool trpgPageManager::LodPageInfo::Stop() // Empty the load list unsigned int i; for (i=0;i 0); @@ -450,7 +450,7 @@ bool trpgPageManager::LodPageInfo::Stop() void trpgPageManager::LodPageInfo::AddChildrenToLoadList(std::vector& parentList) { if(parentList.size() == 0) - return; + return; // Area coverage, in cell unit trpg2iPoint sw,ne; @@ -458,7 +458,7 @@ void trpgPageManager::LodPageInfo::AddChildrenToLoadList(std::vectorGetTileLoc(tileX,tileY,tileLod); - tmpCurrent[(tileY-sw.y)*dx + (tileX-sw.x)] = true; - } + trpgManagedTile *tile = current[i]; + if (tile) { + int tileX,tileY,tileLod; + tile->GetTileLoc(tileX,tileY,tileLod); + tmpCurrent[(tileY-sw.y)*dx + (tileX-sw.x)] = true; + } } for (unsigned int i=0;iGetTileLoc(tileX,tileY,tileLod); - tmpCurrent[(tileY-sw.y)*dx + (tileX-sw.x)] = true; - } + trpgManagedTile *tile = load[i]; + if (tile) { + int tileX,tileY,tileLod; + tile->GetTileLoc(tileX,tileY,tileLod); + tmpCurrent[(tileY-sw.y)*dx + (tileX-sw.x)] = true; + } } for(unsigned int parentIdx = 0; parentIdx < parentList.size(); ++parentIdx) { - trpgManagedTile* parentTile = parentList[parentIdx]; - unsigned int nbChildren = parentTile->GetNbChildren(); + trpgManagedTile* parentTile = parentList[parentIdx]; + unsigned int nbChildren = parentTile->GetNbChildren(); - for(unsigned int childIdx = 0; childIdx < nbChildren; ++childIdx) { + for(unsigned int childIdx = 0; childIdx < nbChildren; ++childIdx) { - const TileLocationInfo& childLoc = parentTile->GetChildLocationInfo(childIdx); + const TileLocationInfo& childLoc = parentTile->GetChildLocationInfo(childIdx); - // a sanity check: if the lod is not the same then this - // parent is not at the right place - if(childLoc.lod != lod) - break; + // a sanity check: if the lod is not the same then this + // parent is not at the right place + if(childLoc.lod != lod) + break; - // Make sure it is within - if (childLoc.x >= sw.x && - childLoc.x <= ne.x && - childLoc.y >= sw.y && - childLoc.y <= ne.y) { + // Make sure it is within + if (childLoc.x >= sw.x && + childLoc.x <= ne.x && + childLoc.y >= sw.y && + childLoc.y <= ne.y) { - // Is it alread there ? - if(!tmpCurrent[(childLoc.y - sw.y)*dx + (childLoc.x - sw.x)]) { + // Is it alread there ? + if(!tmpCurrent[(childLoc.y - sw.y)*dx + (childLoc.x - sw.x)]) { - // Not there, add it - AddToLoadList(childLoc.x, childLoc.y, childLoc.addr); - } - } - } + // Not there, add it + AddToLoadList(childLoc.x, childLoc.y, childLoc.addr); + } + } + } } } @@ -527,32 +527,32 @@ bool trpgPageManager::LodPageInfo::AddToLoadList(int x, int y, const trpgwAppAdd sw.y = cell.y - aoiSize.y; ne.x = cell.x + aoiSize.x; ne.y = cell.y + aoiSize.y; - sw.x = MAX(0,sw.x); + sw.x = MAX(0,sw.x); sw.y = MAX(0,sw.y); ne.x = MIN(lodSize.x-1,ne.x); ne.y = MIN(lodSize.y-1,ne.y); if (x >= sw.x && - x <= ne.x && - y >= sw.y && - y <= ne.y) { + x <= ne.x && + y >= sw.y && + y <= ne.y) { - trpgManagedTile *tile = 0; - if(freeList.size() > 0){ + trpgManagedTile *tile = 0; + if(freeList.size() > 0){ - tile = freeList[0]; - freeList.pop_front(); - } - else - tile = new trpgManagedTile(); - tile->SetTileLoc(x, y, lod); - tile->SetTileAddress(addr); - load.push_back(tile); - - return true; + tile = freeList[0]; + freeList.pop_front(); } else - return false; + tile = new trpgManagedTile(); + tile->SetTileLoc(x, y, lod); + tile->SetTileAddress(addr); + load.push_back(tile); + + return true; + } + else + return false; } /* Update does the major work of figuring out what to load and @@ -567,7 +567,7 @@ void trpgPageManager::LodPageInfo::Update() // in cell coordinates sw.x = cell.x - aoiSize.x; sw.y = cell.y - aoiSize.y; ne.x = cell.x + aoiSize.x; ne.y = cell.y + aoiSize.y; - sw.x = MAX(0,sw.x); sw.y = MAX(0,sw.y); + sw.x = MAX(0,sw.x); sw.y = MAX(0,sw.y); ne.x = MIN(lodSize.x-1,ne.x); ne.y = MIN(lodSize.y-1,ne.y); /* Load list - @@ -576,10 +576,10 @@ void trpgPageManager::LodPageInfo::Update() */ unsigned int i; for (i=0;i= 1) { - // Version 2.1, we update only lod 0 since the tile table - // will only contain lod 0. All tiles from other lod must be - // update through the trpgPageManager::AckLoad(tile info) - if(lod != 0) - doUpdate = false; + // Version 2.1, we update only lod 0 since the tile table + // will only contain lod 0. All tiles from other lod must be + // update through the trpgPageManager::AckLoad(tile info) + if(lod != 0) + doUpdate = false; } if(doUpdate) { - // Sort the currently loaded stuff into a spatial array - // so we can figure out what needs to be loaded in addition. - int dx,dy; - dx = ne.x - sw.x+1; dy = ne.y - sw.y+1; - tmpCurrent.resize(dx*dy); - for (i=0;iGetTileLoc(tileX,tileY,tileLod); - tmpCurrent[(tileY-sw.y)*dx + (tileX-sw.x)] = true; - } - } + // Sort the currently loaded stuff into a spatial array + // so we can figure out what needs to be loaded in addition. + int dx,dy; + dx = ne.x - sw.x+1; dy = ne.y - sw.y+1; + tmpCurrent.resize(dx*dy); + for (i=0;iGetTileLoc(tileX,tileY,tileLod); + tmpCurrent[(tileY-sw.y)*dx + (tileX-sw.x)] = true; + } + } // Now figure out which ones are missing and add them // to the load list - for (int x=0;x 0) { - tile = freeList[0]; - freeList.pop_front(); - } else - tile = new trpgManagedTile(); - tile->SetTileLoc(x+sw.x,y+sw.y,lod); - trpgwAppAddress addr; - float32 zmin, zmax; + for (int x=0;x 0) { + tile = freeList[0]; + freeList.pop_front(); + } else + tile = new trpgManagedTile(); + tile->SetTileLoc(x+sw.x,y+sw.y,lod); + trpgwAppAddress addr; + float32 zmin, zmax; - if(tileTable && tileTable->GetTile(x+sw.x, y+sw.y, lod, addr, zmin, zmax)) - tile->SetTileAddress(addr); + if(tileTable && tileTable->GetTile(x+sw.x, y+sw.y, lod, addr, zmin, zmax)) + tile->SetTileAddress(addr); - load.push_back(tile); - } - } - } + load.push_back(tile); + } + } + } } // That's it. All the rest is handled by the caller @@ -678,7 +678,7 @@ void trpgPageManager::LodPageInfo::Update() void trpgPageManager::LodPageInfo::GetLoadedTileWithin(double pagingDistance, std::vector& tileList) { trpg2iPoint aoi_size((int)(pagingDistance/cellSize.x) +1, - (int)(pagingDistance/cellSize.y) +1); + (int)(pagingDistance/cellSize.y) +1); // Calculate the area that we must check, in parent cell coordinate trpg2iPoint sw, ne; @@ -686,7 +686,7 @@ void trpgPageManager::LodPageInfo::GetLoadedTileWithin(double pagingDistance, st sw.y = cell.y - aoi_size.y; ne.x = cell.x + aoi_size.x; ne.y = cell.y + aoi_size.y; - sw.x = MAX(0,sw.x); + sw.x = MAX(0,sw.x); sw.y = MAX(0,sw.y); ne.x = MIN(lodSize.x-1,ne.x); ne.y = MIN(lodSize.y-1,ne.y); @@ -694,8 +694,8 @@ void trpgPageManager::LodPageInfo::GetLoadedTileWithin(double pagingDistance, st tileList.clear(); for (unsigned i=0; i Print(buf); + if (load[i]) + load[i]->Print(buf); buf.DecreaseIndent(); sprintf(line,"Unloads: (activeUnload = %s)",(activeUnload ? "yes" : "no")); buf.prnLine(line); buf.IncreaseIndent(); for (i=0;iPrint(buf); + if (unload[i]) + unload[i]->Print(buf); buf.DecreaseIndent(); buf.prnLine("Currently loaded:"); buf.IncreaseIndent(); for (i=0;iPrint(buf); + if (current[i]) + current[i]->Print(buf); buf.DecreaseIndent(); sprintf(line,"Free list size = %d", (int)freeList.size()); buf.prnLine(line); @@ -769,10 +769,10 @@ void trpgPageManager::Init(trpgr_Archive *inArch) valid = true; pageInfo.resize(numLod); for (int i=0;i 3) - pageInfo[i].Init(archive,i,scale, 4); - else - pageInfo[i].Init(archive,i,scale); + if(i > 3) + pageInfo[i].Init(archive,i,scale, 4); + else + pageInfo[i].Init(archive,i,scale); } } @@ -797,16 +797,16 @@ void trpgPageManager::Init(trpgr_Archive *inArch, int maxLod) head->GetVersion(majorVersion, minorVersion); if(maxLod > numLod) - maxLod = numLod; + maxLod = numLod; // Reset the terrain LOD paging classes. valid = true; pageInfo.resize(maxLod); for (int i=0;i 3) - pageInfo[i].Init(archive,i,scale, 4); - else - pageInfo[i].Init(archive,i,scale); + if(i > 3) + pageInfo[i].Init(archive,i,scale, 4); + else + pageInfo[i].Init(archive,i,scale); } } @@ -814,7 +814,7 @@ bool trpgPageManager::SetPageDistFactor(double inFact) { // A scaling factor less than 1 will break the archive display. if (inFact <= 1.0) - return false; + return false; scale = inFact; @@ -825,42 +825,42 @@ bool trpgPageManager::SetLocation(trpg2dPoint &pt) { // Do a basic sanity check if (!valid || (pagePt.x == pt.x && pagePt.y == pt.y)) - return false; + return false; pagePt = pt; // Call each terrain LOD and let if figure out if something // has changed. bool change = false; for (unsigned int i=0;i= 1 && change) { - // Version 2.1 and over - // Since we don't have a tile table for lod > 0, - // we must rely on the parent to see if children - // tiles have to be loaded: - // First we get the list of parent tiles that falls - // in the area of interest of the children, - // Second we add to the load list all the parent's - // children that are no already part of the list + // Version 2.1 and over + // Since we don't have a tile table for lod > 0, + // we must rely on the parent to see if children + // tiles have to be loaded: + // First we get the list of parent tiles that falls + // in the area of interest of the children, + // Second we add to the load list all the parent's + // children that are no already part of the list - for(unsigned int lodIdx = 1; lodIdx < pageInfo.size(); ++lodIdx) { + for(unsigned int lodIdx = 1; lodIdx < pageInfo.size(); ++lodIdx) { - LodPageInfo& parentInfo = pageInfo[lodIdx -1]; - LodPageInfo& childInfo = pageInfo[lodIdx]; + LodPageInfo& parentInfo = pageInfo[lodIdx -1]; + LodPageInfo& childInfo = pageInfo[lodIdx]; - // Get the list of parents tile that are currently - // loaded in the children aoi - std::vector parentList; - parentInfo.GetLoadedTileWithin(childInfo.GetPageDistance(), parentList); + // Get the list of parents tile that are currently + // loaded in the children aoi + std::vector parentList; + parentInfo.GetLoadedTileWithin(childInfo.GetPageDistance(), parentList); - // Add the children of those parents to the load list - // of the children info, if they are not already there - childInfo.AddChildrenToLoadList(parentList); - } + // Add the children of those parents to the load list + // of the children info, if they are not already there + childInfo.AddChildrenToLoadList(parentList); + } } @@ -871,22 +871,22 @@ trpgManagedTile *trpgPageManager::GetNextLoad() { // If we're already doing something, let them know about it if (lastLoad != None) - throw 1; + throw 1; // Look for anything that needs loaded // Start with lowest LOD, work up to highest trpgManagedTile *tile = NULL; for (unsigned int i=0;ilocation.lod; + lastLoad = Load; + lastTile = tile; + lastLod = tile->location.lod; } return tile; @@ -901,25 +901,25 @@ void trpgPageManager::AckLoad(std::vector const& children) { // If we're not in the middle of a load, register our displeasure if (lastLoad != Load) - throw 1; + throw 1; if(majorVersion >= 2 && minorVersion >=1) { - if(children.size() > 0) - { - LodPageInfo& childInfo = pageInfo[lastLod+1]; - for(unsigned int idx = 0; idx < children.size(); ++idx) - { - TileLocationInfo const&childLocInfo = children[idx]; - if(childLocInfo.lod != lastLod+1) - continue; // Something wrong here - childInfo.AddToLoadList(childLocInfo.x, childLocInfo.y, childLocInfo.addr); + if(children.size() > 0) + { + LodPageInfo& childInfo = pageInfo[lastLod+1]; + for(unsigned int idx = 0; idx < children.size(); ++idx) + { + TileLocationInfo const&childLocInfo = children[idx]; + if(childLocInfo.lod != lastLod+1) + continue; // Something wrong here + childInfo.AddToLoadList(childLocInfo.x, childLocInfo.y, childLocInfo.addr); - // Also save info in parent tile - lastTile->SetChildLocationInfo(idx, childLocInfo); + // Also save info in parent tile + lastTile->SetChildLocationInfo(idx, childLocInfo); - } - } + } + } } pageInfo[lastLod].AckLoad(); @@ -937,7 +937,7 @@ void *trpgPageManager::GetGroupData(int groupID) { ManageGroupMap::const_iterator p = groupMap.find(groupID); if (p != groupMap.end()) - return (*p).second; + return (*p).second; return NULL; } @@ -946,22 +946,22 @@ trpgManagedTile *trpgPageManager::GetNextUnload() { // If we're already doing something, let them know about it if (lastLoad != None) - throw 1; + throw 1; // Look for anything that needs unloaded // Start with highest LOD, work down to lowest trpgManagedTile *tile = NULL; for (int i=pageInfo.size()-1;i>=0;i--) { - LodPageInfo &info = pageInfo[i]; - if ((tile = info.GetNextUnload())) - break; + LodPageInfo &info = pageInfo[i]; + if ((tile = info.GetNextUnload())) + break; } // Found one. Now the user has to unload it. if (tile) { - lastLoad = Unload; - lastTile = tile; - lastLod = tile->location.lod; + lastLoad = Unload; + lastTile = tile; + lastLod = tile->location.lod; } return tile; @@ -971,14 +971,14 @@ void trpgPageManager::AckUnload() { // If we're not in the middle of an unload, let 'em know. if (lastLoad != Unload) - throw 1; + throw 1; // Remove this tile's group IDs from the map const std::vector *groupIDs = lastTile->GetGroupIDs(); for (unsigned int i=0;isize();i++) { - ManageGroupMap::iterator p = groupMap.find((*groupIDs)[i]); - if (p != groupMap.end()) - groupMap.erase(p); + ManageGroupMap::iterator p = groupMap.find((*groupIDs)[i]); + if (p != groupMap.end()) + groupMap.erase(p); } LodPageInfo &info = pageInfo[lastLod]; @@ -991,7 +991,7 @@ bool trpgPageManager::Stop() { bool res=false; for (unsigned int i=0;i= childList.size()) - throw std::invalid_argument( + throw std::invalid_argument( "trpgPageManageTester::ChildRefCB::GetChild(): index argument out of bound."); else - return childList[idx]; + return childList[idx]; } /* Page Manager Tester @@ -1067,7 +1067,7 @@ void trpgPageManageTester::Init(trpgPrintBuffer *pBuf,trpgPageManager *pMan,trpg printBuf = pBuf; if (!archive->isValid()) - throw 1; + throw 1; const trpgHeader *header = archive->GetHeader(); header->GetVersion(majorVersion, minorVersion); @@ -1081,11 +1081,11 @@ void trpgPageManageTester::Init(trpgPrintBuffer *pBuf,trpgPageManager *pMan,trpg void trpgPageManageTester::RandomTest(int num,int seed) { if (!manager || !archive || !printBuf) - throw 1; + throw 1; // Seed the random number generator so we can replicate runs if (seed != -1) - srand(seed); + srand(seed); // Need the extents trpg2dPoint ll,ur,lod0Size; @@ -1101,20 +1101,20 @@ void trpgPageManageTester::RandomTest(int num,int seed) int i; char line[1024]; for (i=0;iSetLocation(pt); - sprintf(line,"Jumped to (%f,%f). Tiles to load/unload = %s",pt.x,pt.y, - (changes ? "yes" : "no")); printBuf->prnLine(line); + // Jump to the point + bool changes = manager->SetLocation(pt); + sprintf(line,"Jumped to (%f,%f). Tiles to load/unload = %s",pt.x,pt.y, + (changes ? "yes" : "no")); printBuf->prnLine(line); - // Process the results - ProcessChanges(); + // Process the results + ProcessChanges(); } // Ask the page manager for its final status @@ -1128,7 +1128,7 @@ void trpgPageManageTester::Fly_LL_to_UR(double dist) char line[1024]; if (!manager || !archive || !printBuf) - throw 1; + throw 1; // Need the extents trpg2dPoint ll,ur,lod0Size; @@ -1144,15 +1144,15 @@ void trpgPageManageTester::Fly_LL_to_UR(double dist) // Fly the path trpg2dPoint loc; loc = ll; do { - loc.x += dist; loc.y += dist; + loc.x += dist; loc.y += dist; - // Jump to next point - bool changes = manager->SetLocation(loc); - sprintf(line,"Moved to (%f,%f). Tiles to load/unload = %s",loc.x,loc.y, - (changes ? "yes" : "no")); printBuf->prnLine(line); + // Jump to next point + bool changes = manager->SetLocation(loc); + sprintf(line,"Moved to (%f,%f). Tiles to load/unload = %s",loc.x,loc.y, + (changes ? "yes" : "no")); printBuf->prnLine(line); - // Process new location - ProcessChanges(); + // Process new location + ProcessChanges(); } while (loc.x < ur.x && loc.y < ur.y); // Ask the page manager for its final status @@ -1171,9 +1171,9 @@ void trpgPageManageTester::ProcessChanges() printBuf->prnLine("Tiles to unload:"); printBuf->IncreaseIndent(); while ((unloadTile = manager->GetNextUnload())) { - unloadTile->GetTileLoc(x,y,lod); - sprintf(line,"x = %d, y = %d, lod = %d",x,y,lod); printBuf->prnLine(line); - manager->AckUnload(); + unloadTile->GetTileLoc(x,y,lod); + sprintf(line,"x = %d, y = %d, lod = %d",x,y,lod); printBuf->prnLine(line); + manager->AckUnload(); } printBuf->DecreaseIndent(); @@ -1182,45 +1182,45 @@ void trpgPageManageTester::ProcessChanges() printBuf->prnLine("Tiles to load:"); printBuf->IncreaseIndent(); while ((loadTile = manager->GetNextLoad())) { - loadTile->GetTileLoc(x,y,lod); - sprintf(line,"x = %d, y = %d, lod = %d",x,y,lod); printBuf->prnLine(line); + loadTile->GetTileLoc(x,y,lod); + sprintf(line,"x = %d, y = %d, lod = %d",x,y,lod); printBuf->prnLine(line); - if(majorVersion == 2 && minorVersion >= 1) - { - // Version 2.1 and over - // We need to parse the loaded tile to get all of its children info - const trpgwAppAddress& tileAddress = loadTile->GetTileAddress(); - trpgMemReadBuffer buf(archive->GetEndian()); - if(archive->ReadTile(tileAddress, buf)) - { - childRefCB.Reset(); - if(tileParser.Parse(buf)) - { - // childRefCB should now have alist of trpgChildRef found in the tile - unsigned int nbChildRef = childRefCB.GetNbChildren(); - if(nbChildRef > 0) - { - std::vector locInfoList; - for(unsigned int idx = 0; idx < nbChildRef; ++idx) - { - const trpgChildRef& childRef = childRefCB.GetChildRef(idx); - locInfoList.push_back(TileLocationInfo()); - TileLocationInfo& locInfo = locInfoList.back(); - childRef.GetTileLoc(locInfo.x, locInfo.y, locInfo.lod); - childRef.GetTileAddress(locInfo.addr); - } + if(majorVersion == 2 && minorVersion >= 1) + { + // Version 2.1 and over + // We need to parse the loaded tile to get all of its children info + const trpgwAppAddress& tileAddress = loadTile->GetTileAddress(); + trpgMemReadBuffer buf(archive->GetEndian()); + if(archive->ReadTile(tileAddress, buf)) + { + childRefCB.Reset(); + if(tileParser.Parse(buf)) + { + // childRefCB should now have alist of trpgChildRef found in the tile + unsigned int nbChildRef = childRefCB.GetNbChildren(); + if(nbChildRef > 0) + { + std::vector locInfoList; + for(unsigned int idx = 0; idx < nbChildRef; ++idx) + { + const trpgChildRef& childRef = childRefCB.GetChildRef(idx); + locInfoList.push_back(TileLocationInfo()); + TileLocationInfo& locInfo = locInfoList.back(); + childRef.GetTileLoc(locInfo.x, locInfo.y, locInfo.lod); + childRef.GetTileAddress(locInfo.addr); + } - manager->AckLoad(locInfoList); - } - else - manager->AckLoad(); - } - } - else - manager->AckLoad(); - } - else - manager->AckLoad(); + manager->AckLoad(locInfoList); + } + else + manager->AckLoad(); + } + } + else + manager->AckLoad(); + } + else + manager->AckLoad(); } printBuf->DecreaseIndent(); } diff --git a/src/osgPlugins/txp/trpage_managers.h b/src/osgPlugins/txp/trpage_managers.h index cfd89e307..ed1a260a6 100644 --- a/src/osgPlugins/txp/trpage_managers.h +++ b/src/osgPlugins/txp/trpage_managers.h @@ -19,10 +19,10 @@ #include /* 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 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& 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& 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& 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& 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 load; - // List of tiles to unload - std::deque unload; - // List of currently loaded tiles - std::deque current; + // List of tiles to load + std::deque load; + // List of tiles to unload + std::deque unload; + // List of currently loaded tiles + std::deque current; - // Used by Update. Here because we want to avoid memory allocs, if possible. - std::vector tmpCurrent; + // Used by Update. Here because we want to avoid memory allocs, if possible. + std::vector 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 freeList; + // List of tile pointers we can reuse + std::deque freeList; - // TerraPage version - int majorVersion, minorVersion; + // TerraPage version + int majorVersion, minorVersion; - const trpgTileTable *tileTable; + const trpgTileTable *tileTable; }; // Per terrain lod paging information diff --git a/src/osgPlugins/txp/trpage_material.cpp b/src/osgPlugins/txp/trpage_material.cpp index 466948198..2fd9c354e 100644 --- a/src/osgPlugins/txp/trpage_material.cpp +++ b/src/osgPlugins/txp/trpage_material.cpp @@ -55,13 +55,13 @@ void trpgMatTable::Reset() bool trpgMatTable::isValid() const { if(materialMap.size()==0) - return false; + return false; // get an iterator for the materialMap MaterialMapType::const_iterator itr = materialMap.begin(); for ( ; itr != materialMap.end( ); itr++) { - if(!(*itr).second.isValid()) { - return false; - } + if(!(*itr).second.isValid()) { + return false; + } } return true; @@ -71,7 +71,7 @@ bool trpgMatTable::isValid() const void trpgMatTable::SetNumTable(int no) { if ((no < 0) || (no==numTable)) - return; + return; numTable = no; } void trpgMatTable::SetNumMaterial(int /*no*/) @@ -82,7 +82,7 @@ void trpgMatTable::SetNumMaterial(int /*no*/) void trpgMatTable::SetMaterial(int nm,const trpgMaterial &mat) -{ +{ materialMap[nm] = mat; numMat = materialMap.size(); } @@ -92,7 +92,7 @@ void trpgMatTable::SetMaterial(int nm,const trpgMaterial &mat) int trpgMatTable::AddMaterial(const trpgMaterial &mat,bool lookForExisting) { trpgMaterial cmat = mat; // necessary? - + // having a shadeModel of 999 indicates that the entry is free. I thought this would // work fine, until I realized that evidently most of the time the shademodel isn't set // at all. Now my kludge takes so much work it's almost worth doing it right. @@ -101,61 +101,61 @@ int trpgMatTable::AddMaterial(const trpgMaterial &mat,bool lookForExisting) int baseMat=0; bool spaceInTable=false; - //int offset=baseMat; - + //int offset=baseMat; + if (lookForExisting) { - // Look for a matching base material minus the textures - //for (baseMat = 0;baseMat < numMat;baseMat++) { - MaterialMapType::const_iterator itr = materialMap.begin(); - for ( ; itr != materialMap.end( ); itr++) { - baseMat = itr->first; - const trpgMaterial &bm = itr->second; - if (bm.shadeModel==999) { - // this is an 'empty' entry. Means we won't find it, either. - spaceInTable=true; - break; - } + // Look for a matching base material minus the textures + //for (baseMat = 0;baseMat < numMat;baseMat++) { + MaterialMapType::const_iterator itr = materialMap.begin(); + for ( ; itr != materialMap.end( ); itr++) { + baseMat = itr->first; + const trpgMaterial &bm = itr->second; + if (bm.shadeModel==999) { + // this is an 'empty' entry. Means we won't find it, either. + spaceInTable=true; + break; + } - // Compare structures - if (CEQ(cmat.color,bm.color) && CEQ(cmat.ambient,bm.ambient) && - CEQ(cmat.diffuse,bm.diffuse) && CEQ(cmat.specular,bm.specular) && - CEQ(cmat.emission,bm.emission) && cmat.shininess == bm.shininess && - cmat.shadeModel == bm.shadeModel && cmat.pointSize == bm.pointSize && - cmat.lineWidth == bm.lineWidth && cmat.cullMode == bm.cullMode && - cmat.alphaFunc == bm.alphaFunc && cmat.alphaRef == bm.alphaRef && - cmat.attrSet.fid == bm.attrSet.fid && cmat.attrSet.smc == bm.attrSet.smc && - cmat.attrSet.stp == bm.attrSet.stp && cmat.attrSet.swc == bm.attrSet.swc && - cmat.autoNormal == bm.autoNormal && cmat.texEnvs.size() == bm.texEnvs.size()) { - // Test the texture envs - bool isSame=true; + // Compare structures + if (CEQ(cmat.color,bm.color) && CEQ(cmat.ambient,bm.ambient) && + CEQ(cmat.diffuse,bm.diffuse) && CEQ(cmat.specular,bm.specular) && + CEQ(cmat.emission,bm.emission) && cmat.shininess == bm.shininess && + cmat.shadeModel == bm.shadeModel && cmat.pointSize == bm.pointSize && + cmat.lineWidth == bm.lineWidth && cmat.cullMode == bm.cullMode && + cmat.alphaFunc == bm.alphaFunc && cmat.alphaRef == bm.alphaRef && + cmat.attrSet.fid == bm.attrSet.fid && cmat.attrSet.smc == bm.attrSet.smc && + cmat.attrSet.stp == bm.attrSet.stp && cmat.attrSet.swc == bm.attrSet.swc && + cmat.autoNormal == bm.autoNormal && cmat.texEnvs.size() == bm.texEnvs.size()) { + // Test the texture envs + bool isSame=true; unsigned int i; - for (i=0;i(&(*itr).second); + MaterialMapType::const_iterator itr = materialMap.find((nt*numMat)+nm); + if(itr == materialMap.end()) + return false; + return const_cast(&(*itr).second); } bool trpgMatTable::Read(trpgReadBuffer &buf) { - trpgMaterial mat; - trpgToken matTok; - int32 len; - bool status; - int i,j; - int nMat,nTable; + trpgMaterial mat; + trpgToken matTok; + int32 len; + bool status; + int i,j; + int nMat,nTable; - try { - buf.Get(nTable); - buf.Get(nMat); - if (nTable <= 0 || nMat < 0) throw 1; - // Read the materials - for (i=0;iSetEnvMode(envMode); - break; - case TRPGMAT_TXENV_FILTER: - buf.Get(minFilter); - buf.Get(magFilter); - tenv->SetMinFilter(minFilter); - tenv->SetMagFilter(magFilter); - break; - case TRPGMAT_TXENV_WRAP: - buf.Get(wrapS); - buf.Get(wrapT); - tenv->SetWrap(wrapS,wrapT); - break; - case TRPGMAT_TXENV_BORDER: - buf.Get(borderCol); - tenv->SetBorderColor(borderCol); - break; - default: - // Don't know this token. Skip - break; - } + switch (tok) { + case TRPGMAT_TXENV_MODE: + buf.Get(envMode); + tenv->SetEnvMode(envMode); + break; + case TRPGMAT_TXENV_FILTER: + buf.Get(minFilter); + buf.Get(magFilter); + tenv->SetMinFilter(minFilter); + tenv->SetMagFilter(magFilter); + break; + case TRPGMAT_TXENV_WRAP: + buf.Get(wrapS); + buf.Get(wrapT); + tenv->SetWrap(wrapS,wrapT); + break; + case TRPGMAT_TXENV_BORDER: + buf.Get(borderCol); + tenv->SetBorderColor(borderCol); + break; + default: + // Don't know this token. Skip + break; + } } catch (...) { - return NULL; + return NULL; } return tenv; @@ -499,11 +499,11 @@ bool trpgMaterial::isValid() const { // Only thing we really care about is texture if (numTex < 0) - return false; + return false; for (int i=0;i= texids.size()) - return; + return; texids[no] = id; texEnvs[no] = env; @@ -606,17 +606,17 @@ void trpgMaterial::SetAttr(int attrCode,int val) { switch (attrCode) { case TR_FID: - attrSet.fid = val; - break; + attrSet.fid = val; + break; case TR_SMC: - attrSet.smc = val; - break; + attrSet.smc = val; + break; case TR_STP: - attrSet.stp = val; - break; + attrSet.stp = val; + break; case TR_SWC: - attrSet.swc = val; - break; + attrSet.swc = val; + break; } return; @@ -626,7 +626,7 @@ void trpgMaterial::SetAttr(int attrCode,int val) bool trpgMaterial::Write(trpgWriteBuffer &buf) { if (!isValid()) - return false; + return false; buf.Begin(TRPGMATERIAL); @@ -669,8 +669,8 @@ bool trpgMaterial::Write(trpgWriteBuffer &buf) buf.Begin(TRPGMAT_TEXTURE); buf.Add(numTex); for (int i=0;i= 2.3, handle will be set to a unique identifier. **/ if(writeHandle) { - buf.Begin(TRPGMAT_HANDLE); - buf.Add((int)handle); - buf.End(); + buf.Begin(TRPGMAT_HANDLE); + buf.Add((int)handle); + buf.End(); } buf.End(); @@ -800,7 +800,7 @@ bool trpgMaterial::GetNumTexture(int &no) const bool trpgMaterial::GetTexture(int no,int &id,trpgTextureEnv &te) const { if (!isValid() || no < 0 || no >= numTex) - return false; + return false; id = texids[no]; te = texEnvs[no]; return true; @@ -821,19 +821,19 @@ bool trpgMaterial::GetAttr(int attrCode,int &ret) const { switch (attrCode) { case TR_FID: - ret = attrSet.fid; - break; + ret = attrSet.fid; + break; case TR_SMC: - ret = attrSet.smc; - break; + ret = attrSet.smc; + break; case TR_STP: - ret = attrSet.stp; - break; + ret = attrSet.stp; + break; case TR_SWC: - ret = attrSet.swc; - break; + ret = attrSet.swc; + break; default: - return false; + return false; } return true; @@ -866,105 +866,105 @@ void * materialCB::Parse(trpgToken tok,trpgReadBuffer &buf) int i; try { - switch (tok) { - case TRPGMAT_BASIC: - buf.Get(color); - mat->SetColor(color); - buf.Get(color); - mat->SetAmbient(color); - buf.Get(color); - mat->SetDiffuse(color); - buf.Get(color); - mat->SetSpecular(color); - buf.Get(color); - mat->SetEmission(color); - buf.Get(shininess); - mat->SetShininess(shininess); - buf.Get(numtile); - mat->SetNumTiles(numtile); - break; - case TRPGMAT_SHADE: - buf.Get(shadeModel); - mat->SetShadeModel(shadeModel); - break; - case TRPGMAT_SIZES: - buf.Get(size); - mat->SetPointSize(size); - buf.Get(size); - mat->SetLineWidth(size); - break; - case TRPGMAT_CULL: - buf.Get(cullMode); - mat->SetCullMode(cullMode); - break; - case TRPGMAT_ALPHA: - buf.Get(alphaFunc); - buf.Get(alphaRef); - buf.Get(alpha); - mat->SetAlphaFunc(alphaFunc); - mat->SetAlphaRef(alphaRef); - mat->SetAlpha(alpha); - break; - case TRPGMAT_NORMAL: - { - int32 tmp; - buf.Get(tmp); - if (tmp) - autoNormal = true; - else - autoNormal = false; - mat->SetAutoNormal(autoNormal); - } - break; - case TRPGMAT_TEXTURE: - buf.Get(numTex); - for (i=0;iSetColor(color); + buf.Get(color); + mat->SetAmbient(color); + buf.Get(color); + mat->SetDiffuse(color); + buf.Get(color); + mat->SetSpecular(color); + buf.Get(color); + mat->SetEmission(color); + buf.Get(shininess); + mat->SetShininess(shininess); + buf.Get(numtile); + mat->SetNumTiles(numtile); + break; + case TRPGMAT_SHADE: + buf.Get(shadeModel); + mat->SetShadeModel(shadeModel); + break; + case TRPGMAT_SIZES: + buf.Get(size); + mat->SetPointSize(size); + buf.Get(size); + mat->SetLineWidth(size); + break; + case TRPGMAT_CULL: + buf.Get(cullMode); + mat->SetCullMode(cullMode); + break; + case TRPGMAT_ALPHA: + buf.Get(alphaFunc); + buf.Get(alphaRef); + buf.Get(alpha); + mat->SetAlphaFunc(alphaFunc); + mat->SetAlphaRef(alphaRef); + mat->SetAlpha(alpha); + break; + case TRPGMAT_NORMAL: + { + int32 tmp; + buf.Get(tmp); + if (tmp) + autoNormal = true; + else + autoNormal = false; + mat->SetAutoNormal(autoNormal); + } + break; + case TRPGMAT_TEXTURE: + buf.Get(numTex); + for (i=0;iAddTexture(texId,texEnv); - } - break; - case TRPGMAT_BUMP: - { - int32 tmp; - buf.Get(tmp); - bool isBump = (tmp) ? true : false; - mat->SetIsBumpMap(isBump); - } - break; - case TRPGMAT_ATTR: - { - int tmp; - buf.Get(tmp); - mat->SetAttr(trpgMaterial::TR_FID,tmp); - buf.Get(tmp); - mat->SetAttr(trpgMaterial::TR_SMC,tmp); - buf.Get(tmp); - mat->SetAttr(trpgMaterial::TR_STP,tmp); - buf.Get(tmp); - mat->SetAttr(trpgMaterial::TR_SWC,tmp); - } - break; - case TRPGMAT_HANDLE: - { - int hdl; - buf.Get(hdl); - mat->SetHandle(hdl); - } - break; - default: - break; - } + mat->AddTexture(texId,texEnv); + } + break; + case TRPGMAT_BUMP: + { + int32 tmp; + buf.Get(tmp); + bool isBump = (tmp) ? true : false; + mat->SetIsBumpMap(isBump); + } + break; + case TRPGMAT_ATTR: + { + int tmp; + buf.Get(tmp); + mat->SetAttr(trpgMaterial::TR_FID,tmp); + buf.Get(tmp); + mat->SetAttr(trpgMaterial::TR_SMC,tmp); + buf.Get(tmp); + mat->SetAttr(trpgMaterial::TR_STP,tmp); + buf.Get(tmp); + mat->SetAttr(trpgMaterial::TR_SWC,tmp); + } + break; + case TRPGMAT_HANDLE: + { + int hdl; + buf.Get(hdl); + mat->SetHandle(hdl); + } + break; + default: + break; + } } catch (...) { - return NULL; + return NULL; } return mat; @@ -1050,7 +1050,7 @@ void trpgTexture::Reset() type = trpg_Unknown; numLayer = -1; if (name) - delete [] name; + delete [] name; name = NULL; useCount = 0; sizeX = sizeY = -1; @@ -1073,15 +1073,15 @@ bool trpgTexture::isValid() const { switch (mode) { case External: - return (name != NULL); + return (name != NULL); case Local: - return (type != trpg_Unknown && sizeX != -1 && sizeY != -1); + return (type != trpg_Unknown && sizeX != -1 && sizeY != -1); case Global: - return (type != trpg_Unknown); + return (type != trpg_Unknown); case Template: - return (type != trpg_Unknown && sizeX != -1 && sizeY != -1); + return (type != trpg_Unknown && sizeX != -1 && sizeY != -1); default: - return false; + return false; } } @@ -1090,11 +1090,11 @@ bool trpgTexture::isValid() const void trpgTexture::SetName(const char *inName) { if (name) - delete [] name; + delete [] name; name = NULL; if (!inName) - return; + return; name = new char[strlen(inName)+1]; strcpy(name,inName); @@ -1104,7 +1104,7 @@ void trpgTexture::SetName(const char *inName) bool trpgTexture::GetName(char *outName,int outLen) const { if (!isValid()) - return false; + return false; int len = (name) ? strlen(name) : 0; strncpy(outName,name,MIN(len,outLen)+1); @@ -1141,7 +1141,7 @@ void trpgTexture::SetImageSize(const trpg2iPoint &inSize) bool trpgTexture::GetImageSize(trpg2iPoint &outSize) const { if (mode != Local && mode != Template) - return false; + return false; outSize.x = sizeX; outSize.y = sizeY; @@ -1159,7 +1159,7 @@ bool trpgTexture::GetIsMipmap(bool &ret) const bool trpgTexture::GetImageAddr(trpgwAppAddress &outAddr) const { if (mode != Local) - return false; + return false; outAddr = addr; @@ -1173,46 +1173,46 @@ bool trpgTexture::GetImageDepth(int32 &depth) const { switch (type) { case trpg_RGB8: - depth = 3; - break; + depth = 3; + break; case trpg_RGBA8: - depth = 4; - break; + depth = 4; + break; case trpg_INT8: - depth = 1; - break; + depth = 1; + break; case trpg_INTA8: - depth = 2; - break; + depth = 2; + break; case trpg_FXT1: - depth = 3; - break; + depth = 3; + break; case trpg_RGBX: - depth = numLayer; - break; + depth = numLayer; + break; case trpg_DXT1: - depth = 3; - break; + depth = 3; + break; case trpg_DXT3: - depth = 3; - break; + depth = 3; + break; case trpg_DXT5: - depth = 3; - break; + depth = 3; + break; case trpg_MCM5: - depth = 5; - break; + depth = 5; + break; case trpg_MCM6R: case trpg_MCM6A: - depth = 6; - break; + depth = 6; + break; case trpg_MCM7RA: case trpg_MCM7AR: - depth = 7; - break; + depth = 7; + break; default: - depth = -1; - break; + depth = -1; + break; } return true; @@ -1226,7 +1226,7 @@ void trpgTexture::SetNumLayer(int layers) bool trpgTexture::GetNumLayer(int &layers) const { if (!isValid()) - return false; + return false; GetImageDepth(layers); return true; } @@ -1243,7 +1243,7 @@ void trpgTexture::AddTile() bool trpgTexture::GetNumTile(int &num) const { if (!isValid()) - return false; + return false; num = useCount; return true; } @@ -1255,7 +1255,7 @@ trpgTexture &trpgTexture::operator = (const trpgTexture &in) type = in.type; if (in.name) - SetName(in.name); + SetName(in.name); useCount = in.useCount; @@ -1267,7 +1267,7 @@ trpgTexture &trpgTexture::operator = (const trpgTexture &in) isMipmap = in.isMipmap; addr = in.addr; - + writeHandle = in.writeHandle; handle = in.handle; @@ -1278,28 +1278,28 @@ trpgTexture &trpgTexture::operator = (const trpgTexture &in) int trpgTexture::operator == (const trpgTexture &in) const { if (mode != in.mode) - return 0; + return 0; switch (mode) { case External: - if (!in.name && !name) - return 1; - if (!in.name || !name) - return 0; - return (!strcmp(in.name,name)); - break; + if (!in.name && !name) + return 1; + if (!in.name || !name) + return 0; + return (!strcmp(in.name,name)); + break; case Local: - if (type == in.type && sizeX == in.sizeX && sizeY == in.sizeY && - isMipmap == in.isMipmap && - addr.file == in.addr.file && addr.offset == in.addr.offset && - addr.row == in.addr.row && addr.col==in.addr.col ) - return 1; - break; + if (type == in.type && sizeX == in.sizeX && sizeY == in.sizeY && + isMipmap == in.isMipmap && + addr.file == in.addr.file && addr.offset == in.addr.offset && + addr.row == in.addr.row && addr.col==in.addr.col ) + return 1; + break; case Global: case Template: - if (type == in.type && sizeX == in.sizeX && sizeY == in.sizeY && - isMipmap == in.isMipmap) - return 1; + if (type == in.type && sizeX == in.sizeX && sizeY == in.sizeY && + isMipmap == in.isMipmap) + return 1; } return 0; @@ -1318,8 +1318,8 @@ int32 trpgTexture::CalcNumMipmaps() const // Now look for the highest bit int p2; for (p2=0;p2<32;p2++) - if ((1<= 0 && miplevel < CalcNumMipmaps() ) { - if ( !storageSize.size() ) - CalcMipLevelSizes(); - return storageSize[miplevel]; + if ( !storageSize.size() ) + CalcMipLevelSizes(); + return storageSize[miplevel]; } return 0; @@ -1353,9 +1353,9 @@ int32 trpgTexture::MipLevelSize(int miplevel) int32 trpgTexture::MipLevelOffset(int miplevel) { if ( miplevel > 0 && miplevel < CalcNumMipmaps() ) { - if ( !levelOffset.size() ) - CalcMipLevelSizes(); - return levelOffset[miplevel]; + if ( !levelOffset.size() ) + CalcMipLevelSizes(); + return levelOffset[miplevel]; } return 0; @@ -1380,7 +1380,7 @@ bool trpgTexture::Write(trpgWriteBuffer &buf) buf.Add(addr.offset); buf.Add((int32)isMipmap); if(writeHandle) { - buf.Add((int32)handle); + buf.Add((int32)handle); } buf.End(); @@ -1393,42 +1393,42 @@ bool trpgTexture::Read(trpgReadBuffer &buf) char texName[1024]; try { - buf.Get(texName,1023); - SetName(texName); - buf.Get(useCount); + buf.Get(texName,1023); + SetName(texName); + buf.Get(useCount); - mode = External; - // New in 2.0 from here down - unsigned char bval; - buf.Get(bval); mode = (trpgTexture::ImageMode)bval; - buf.Get(bval); type = (trpgTexture::ImageType)bval; - GetImageDepth(numLayer); // heh - buf.Get(sizeX); - buf.Get(sizeY); - buf.Get(addr.file); - buf.Get(addr.offset); - int32 ival; - buf.Get(ival); - // Read the handle if we can.. - try { + mode = External; + // New in 2.0 from here down + unsigned char bval; + buf.Get(bval); mode = (trpgTexture::ImageMode)bval; + buf.Get(bval); type = (trpgTexture::ImageType)bval; + GetImageDepth(numLayer); // heh + buf.Get(sizeX); + buf.Get(sizeY); + buf.Get(addr.file); + buf.Get(addr.offset); + int32 ival; + buf.Get(ival); + // Read the handle if we can.. + try { int32 tempHandle; - if(buf.Get(tempHandle)) + if(buf.Get(tempHandle)) { - writeHandle = true; + writeHandle = true; handle = tempHandle; } else { - handle = -1; - } - } - catch (...) { - handle = -1; - } - isMipmap = (ival) ? true : false; + handle = -1; + } } catch (...) { - return false; + handle = -1; + } + isMipmap = (ival) ? true : false; + } + catch (...) { + return false; } if (!isValid()) return false; @@ -1452,51 +1452,51 @@ void trpgTexture::CalcMipLevelSizes() switch (type) { case trpg_DXT1: - isDXT = true; - block_size = 8; - break; + isDXT = true; + block_size = 8; + break; case trpg_DXT3: case trpg_DXT5: - isDXT = true; - block_size = 16; - break; + isDXT = true; + block_size = 16; + break; case trpg_RGB8: - pad_size = 4; - pixel_size = 3; - break; + pad_size = 4; + pixel_size = 3; + break; case trpg_RGBA8: - pad_size = 4; - pixel_size = 4; - break; + pad_size = 4; + pixel_size = 4; + break; case trpg_RGBX: - pad_size = 4; - pixel_size = numLayer; - break; + pad_size = 4; + pixel_size = numLayer; + break; case trpg_MCM5: - pad_size = 4; - pixel_size = 5; - break; + pad_size = 4; + pixel_size = 5; + break; case trpg_MCM6R: case trpg_MCM6A: - pad_size = 4; - pixel_size = 6; - break; + pad_size = 4; + pixel_size = 6; + break; case trpg_MCM7RA: case trpg_MCM7AR: - pad_size = 4; - pixel_size = 7; - break; + pad_size = 4; + pixel_size = 7; + break; case trpg_INT8: - pad_size = 4; - pixel_size = 1; - break; + pad_size = 4; + pixel_size = 1; + break; case trpg_INTA8: - pad_size = 4; - pixel_size = 2; - break; + pad_size = 4; + pixel_size = 2; + break; case trpg_FXT1: - isFXT = true; - break; + isFXT = true; + break; default: break; } @@ -1510,85 +1510,85 @@ void trpgTexture::CalcMipLevelSizes() if ( isDXT ) { // DXT compressed - int num_x_blocks = ((sizeX/4)+(sizeX%4?1:0)); - int num_y_blocks = ((sizeY/4)+(sizeY%4?1:0)); + int num_x_blocks = ((sizeX/4)+(sizeX%4?1:0)); + int num_y_blocks = ((sizeY/4)+(sizeY%4?1:0)); - level_size = num_x_blocks * num_y_blocks * block_size; - storageSize.push_back(level_size); + level_size = num_x_blocks * num_y_blocks * block_size; + storageSize.push_back(level_size); - for ( int i = 1; i < num_miplevels; i++ ) { - level_offset += level_size; - levelOffset.push_back(level_offset); + for ( int i = 1; i < num_miplevels; i++ ) { + level_offset += level_size; + levelOffset.push_back(level_offset); - num_x_blocks /= 2; - num_y_blocks /= 2; - num_x_blocks = MAX(1,num_x_blocks); - num_y_blocks = MAX(1,num_y_blocks); + num_x_blocks /= 2; + num_y_blocks /= 2; + num_x_blocks = MAX(1,num_x_blocks); + num_y_blocks = MAX(1,num_y_blocks); - level_size = num_x_blocks * num_y_blocks * block_size; - storageSize.push_back(level_size); - } + level_size = num_x_blocks * num_y_blocks * block_size; + storageSize.push_back(level_size); + } - return; + return; } if ( isFXT) { - // bits per pixel and size - int bpp = 4; - int x = sizeX; - int y = sizeY; - - int nummiplevels = (isMipmap ? CalcNumMipmaps() : 1); - for (int i = 0; i < nummiplevels; i++) { - if (i > 0) - levelOffset.push_back(level_offset); + // bits per pixel and size + int bpp = 4; + int x = sizeX; + int y = sizeY; + + int nummiplevels = (isMipmap ? CalcNumMipmaps() : 1); + for (int i = 0; i < nummiplevels; i++) { + if (i > 0) + levelOffset.push_back(level_offset); - x = ( x + 0x7 ) & ~0x7; - y = ( y + 0x3 ) & ~0x3; + x = ( x + 0x7 ) & ~0x7; + y = ( y + 0x3 ) & ~0x3; - // Number of bytes - level_size = ( x * y * bpp ) >> 3; - storageSize.push_back(level_size); - level_offset += level_size; + // Number of bytes + level_size = ( x * y * bpp ) >> 3; + storageSize.push_back(level_size); + level_offset += level_size; - if (x > 1) x /= 2; - if (y > 1) y /= 2; - } + if (x > 1) x /= 2; + if (y > 1) y /= 2; + } - return; + return; } { - int x_size = sizeX; - int y_size = sizeY; + int x_size = sizeX; + int y_size = sizeY; - // Pad to a given size, if necessary - int row_size = x_size * pixel_size; - if (pad_size > 0) { - int left = row_size%pad_size; - if (left) - row_size += pad_size - left; - } + // Pad to a given size, if necessary + int row_size = x_size * pixel_size; + if (pad_size > 0) { + int left = row_size%pad_size; + if (left) + row_size += pad_size - left; + } - level_size = row_size * y_size; - storageSize.push_back(level_size); - for ( int i = 1; i < num_miplevels; i++ ) { - level_offset += level_size; - levelOffset.push_back(level_offset); + level_size = row_size * y_size; + storageSize.push_back(level_size); + for ( int i = 1; i < num_miplevels; i++ ) { + level_offset += level_size; + levelOffset.push_back(level_offset); - x_size /= 2; - y_size /= 2; - x_size = MAX(1,x_size); - y_size = MAX(1,y_size); + x_size /= 2; + y_size /= 2; + x_size = MAX(1,x_size); + y_size = MAX(1,y_size); - row_size = x_size * pixel_size; - if (pad_size > 0) { - int left = row_size%pad_size; - if (left) - row_size += pad_size - left; - } - level_size = row_size * y_size; - storageSize.push_back(level_size); - } + row_size = x_size * pixel_size; + if (pad_size > 0) { + int left = row_size%pad_size; + if (left) + row_size += pad_size - left; + } + level_size = row_size * y_size; + storageSize.push_back(level_size); + } } } @@ -1628,16 +1628,16 @@ bool trpgTexTable::isValid() const { if (!textureMap.size()) { - strcpy(errMess, "Texture table list is empty"); - return false; + strcpy(errMess, "Texture table list is empty"); + return false; } TextureMapType::const_iterator itr = textureMap.begin(); - for ( ; itr != textureMap.end( ); itr++) { - if(!itr->second.isValid()) { - strcpy(errMess, "A texture in the texture table is invalid"); - return false; - } + for ( ; itr != textureMap.end( ); itr++) { + if(!itr->second.isValid()) { + strcpy(errMess, "A texture in the texture table is invalid"); + return false; + } } return true; } @@ -1647,37 +1647,37 @@ bool trpgTexTable::isValid() const void trpgTexTable::SetNumTextures(int /*no*/) { // obsolete. This method doesn't need to do anything since we're using a map instead of a vector. - // texList.resize(no); + // texList.resize(no); } int trpgTexTable::AddTexture(const trpgTexture &inTex) { - + TeAttrHdl hdl = inTex.GetHandle(); if(hdl==-1) { - // if no handle is specified, we will use an index as the handle (just like before 2.3) - hdl = textureMap.size(); + // if no handle is specified, we will use an index as the handle (just like before 2.3) + hdl = textureMap.size(); } TextureMapType::iterator itr = textureMap.find(hdl); // Don't overwrite the texture if it was already there if(itr==textureMap.end()) - textureMap[hdl] = inTex; + textureMap[hdl] = inTex; return hdl; } int trpgTexTable::FindAddTexture(const trpgTexture &inTex) { TextureMapType::iterator itr = textureMap.begin(); for ( ; itr != textureMap.end( ); itr++) { - trpgTexture tx = itr->second; - if(tx == inTex) { - return itr->first; - } + trpgTexture tx = itr->second; + if(tx == inTex) { + return itr->first; + } } return AddTexture(inTex); } void trpgTexTable::SetTexture(int id,const trpgTexture &inTex) { if (id < 0) - return; + return; textureMap[id] = inTex; } @@ -1687,9 +1687,9 @@ trpgTexTable &trpgTexTable::operator = (const trpgTexTable &in) Reset(); TextureMapType::const_iterator itr = in.textureMap.begin(); for ( ; itr != in.textureMap.end( ); itr++) { - trpgTexture tex = itr->second; - in.GetTexture(itr->first,tex); - AddTexture(tex); + trpgTexture tex = itr->second; + in.GetTexture(itr->first,tex); + AddTexture(tex); } return *this; @@ -1701,14 +1701,14 @@ bool trpgTexTable::Write(trpgWriteBuffer &buf) int32 numTex; if (!isValid()) - return false; + return false; buf.Begin(TRPGTEXTABLE2); numTex = textureMap.size(); buf.Add(numTex); TextureMapType::iterator itr = textureMap.begin(); for ( ; itr != textureMap.end( ); itr++) { - itr->second.Write(buf); + itr->second.Write(buf); } buf.End(); @@ -1729,12 +1729,12 @@ bool trpgTexTable::GetNumTextures(int &no) const bool trpgTexTable::GetTexture(int id,trpgTexture &ret) const { if (!isValid()) - return false; + return false; if (id < 0) - return false; + return false; TextureMapType::const_iterator itr = textureMap.find(id); - if(itr == textureMap.end()) { - return false; + if(itr == textureMap.end()) { + return false; } ret = itr->second; @@ -1743,10 +1743,10 @@ bool trpgTexTable::GetTexture(int id,trpgTexture &ret) const const trpgTexture *trpgTexTable::GetTextureRef(int id) const { if (id < 0) - return false; + return false; TextureMapType::const_iterator itr = textureMap.find(id); - if(itr == textureMap.end()) { - return false; + if(itr == textureMap.end()) { + return false; } const trpgTexture *ret = &(itr->second); return ret; @@ -1756,14 +1756,14 @@ const trpgTexture *trpgTexTable::FindByName(const char *name, int &texid) const { TextureMapType::const_iterator itr = textureMap.begin(); for ( ; itr != textureMap.end( ); itr++) { - char thisName[1024]; - thisName[0] = '\0'; - itr->second.GetName(thisName,1023); - if(strcasecmp(thisName,name)==0) - { - texid = itr->first; - return &(itr->second); - } + char thisName[1024]; + thisName[0] = '\0'; + itr->second.GetName(thisName,1023); + if(strcasecmp(thisName,name)==0) + { + texid = itr->first; + return &(itr->second); + } } return false; @@ -1776,29 +1776,29 @@ bool trpgTexTable::Read(trpgReadBuffer &buf) int32 len; try { - buf.Get(numTex); - - for (int i=0;i=2.3) - if((currentRow!=-1)&&(currentCol!=-1)) { - trpgwAppAddress taddr; - tex.GetImageAddr(taddr); - taddr.col = currentCol; - taddr.row = currentRow; - tex.SetImageAddr(taddr); - } - AddTexture(tex); - buf.PopLimit(); - if (!status) throw 1; - } + buf.Get(numTex); + + for (int i=0;i=2.3) + if((currentRow!=-1)&&(currentCol!=-1)) { + trpgwAppAddress taddr; + tex.GetImageAddr(taddr); + taddr.col = currentCol; + taddr.row = currentRow; + tex.SetImageAddr(taddr); + } + AddTexture(tex); + buf.PopLimit(); + if (!status) throw 1; + } } catch (...) { - return false; + return false; } return true; @@ -1835,7 +1835,7 @@ void trpgLocalMaterial::Reset() { baseMat = -1; sx = sy = ex = ey = destWidth = destHeight = 0; -// storageSize.resize(0); +// storageSize.resize(0); addr.resize(1); addr[0].file = 0; addr[0].offset = 0; @@ -1940,7 +1940,7 @@ bool trpgLocalMaterial::isValid() const bool trpgLocalMaterial::Write(trpgWriteBuffer &buf) { if (!isValid()) - return false; + return false; buf.Begin(TRPGLOCALMATERIAL); @@ -1958,11 +1958,11 @@ bool trpgLocalMaterial::Write(trpgWriteBuffer &buf) // and in case there's more... int numAddrs=(int)(addr.size()); if (numAddrs>1) { - buf.Add(numAddrs-1); // suppressed due to breaking old readers. - for (int i=1;i #include /* 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 /* *************************** - 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; diff --git a/src/osgPlugins/txp/trpage_pparse.cpp b/src/osgPlugins/txp/trpage_pparse.cpp index 4e67093ac..066055d80 100644 --- a/src/osgPlugins/txp/trpage_pparse.cpp +++ b/src/osgPlugins/txp/trpage_pparse.cpp @@ -18,8 +18,8 @@ #include /* 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 @@ -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(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;iGetLocalMaterial(i,locMat); - const trpgMaterial *baseMat; - const trpgTexture *baseTex; - int totSize; - trpgrImageHelper *imageHelp = parse->GetImageHelp(); - int numImages=1; - locMat.GetNumLocals(numImages); - for (int imgN=0;imgNGetNthImageInfoForLocalMat(&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;iGetLocalMaterial(i,locMat); + const trpgMaterial *baseMat; + const trpgTexture *baseTex; + int totSize; + trpgrImageHelper *imageHelp = parse->GetImageHelp(); + int numImages=1; + locMat.GetNumLocals(numImages); + for (int imgN=0;imgNGetNthImageInfoForLocalMat(&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(baseTex))->MipLevelOffset(j); - int mipSize = (const_cast(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(baseTex))->MipLevelOffset(j); + int mipSize = (const_cast(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;nlGetHeader()->GetLodSize(nl,tileSize); - // Iterate over the tiles - for (x=tileSize.x-1;x>=0;x--) - for (y=0;yReadTile(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;nlGetHeader()->GetLodSize(nl,tileSize); + // Iterate over the tiles + for (x=tileSize.x-1;x>=0;x--) + for (y=0;yReadTile(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; } diff --git a/src/osgPlugins/txp/trpage_range.cpp b/src/osgPlugins/txp/trpage_range.cpp index 70d77a34f..7d866df4e 100644 --- a/src/osgPlugins/txp/trpage_range.cpp +++ b/src/osgPlugins/txp/trpage_range.cpp @@ -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 #include @@ -26,334 +26,334 @@ #include /* ******************* - 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;isecond; - 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;ifirst] = 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 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 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;}; diff --git a/src/osgPlugins/txp/trpage_scene.cpp b/src/osgPlugins/txp/trpage_scene.cpp index a1b7d0e82..7956241ae 100644 --- a/src/osgPlugins/txp/trpage_scene.cpp +++ b/src/osgPlugins/txp/trpage_scene.cpp @@ -19,473 +19,473 @@ #include /* 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 #include /* **************** - 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= (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(&mbr); - trpgMBR kmbr; - // Ask the kids - for (unsigned int i=0;iGetMBR(); - cmbr->Union(kmbr); - } - return *cmbr; - } + if (mbr.isValid()) + return mbr; + else { + // Calculate and cache a new MBR + trpgMBR *cmbr = const_cast(&mbr); + trpgMBR kmbr; + // Ask the kids + for (unsigned int i=0;iGetMBR(); + 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(&mbr); + trpgMBR *pmbr = const_cast(&mbr); - int numVert,i; - trpg3dPoint pt; - data.GetNumVertex(numVert); - numVert /= 3; - for (i=0;iAddPoint(pt); - } + int numVert,i; + trpg3dPoint pt; + data.GetNumVertex(numVert); + numVert /= 3; + for (i=0;iAddPoint(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; } diff --git a/src/osgPlugins/txp/trpage_scene.h b/src/osgPlugins/txp/trpage_scene.h index 69ee53c95..f1e34ebdd 100644 --- a/src/osgPlugins/txp/trpage_scene.h +++ b/src/osgPlugins/txp/trpage_scene.h @@ -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 /* - {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 children; + trpgMBR mbr; + void DeleteChildren(void); + std::vector 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 GroupMap; + typedef std::map GroupMap; #else - typedef std::map< int,trpgReadGroupBase *,std::less > GroupMap; + typedef std::map< int,trpgReadGroupBase *,std::less > 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 diff --git a/src/osgPlugins/txp/trpage_swap.h b/src/osgPlugins/txp/trpage_swap.h index 82671f722..d13abfb28 100644 --- a/src/osgPlugins/txp/trpage_swap.h +++ b/src/osgPlugins/txp/trpage_swap.h @@ -17,7 +17,7 @@ #define trpage_swap_h_ /* trpage_swap.h - Byte swapping utility functions. + Byte swapping utility functions. */ #include @@ -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 ); diff --git a/src/osgPlugins/txp/trpage_sys.h b/src/osgPlugins/txp/trpage_sys.h index 898245ee5..d58d16bf5 100644 --- a/src/osgPlugins/txp/trpage_sys.h +++ b/src/osgPlugins/txp/trpage_sys.h @@ -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 diff --git a/src/osgPlugins/txp/trpage_tile.cpp b/src/osgPlugins/txp/trpage_tile.cpp index ec58f6ec0..7db2fdf68 100644 --- a/src/osgPlugins/txp/trpage_tile.cpp +++ b/src/osgPlugins/txp/trpage_tile.cpp @@ -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 #include /* 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(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(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 0) { + for (int x=0;x= static_cast(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(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(lodInfo.size())) return false; - if (mode == External) - return false; + if (lod < 0 || lod >= static_cast(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= static_cast(matList.size())) - return; - matList[no] = id; + if (no < 0 || no >= static_cast(matList.size())) + return; + matList[no] = id; } void trpgTileHeader::SetModel(int no,int id) { - if (no < 0 || no >= static_cast(modelList.size())) - return; - modelList[no] = id; + if (no < 0 || no >= static_cast(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= static_cast(locMats.size())) - return false; + return false; retMat = locMats[id]; @@ -412,78 +412,78 @@ const std::vector *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(matList.size())) - return false; - mat = matList[id]; - return true; + if (!isValid() || id < 0 || id >= static_cast(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(modelList.size())) - return false; - m = modelList[id]; - return true; + if (!isValid() || id < 0 || id >= static_cast(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;iAddMaterial(id); - } - break; - case TRPG_TILE_MODELLIST: - buf.Get(no); - if (no < 0) throw 1; - for (i=0;iAddModel(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 *locMats; - locMats = const_cast *> (head->GetLocalMaterialList()); - locMats->resize(numLocMat); - for (i=0;iGetBlockNo(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;iAddModel(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 *locMats; + locMats = const_cast *> (head->GetLocalMaterialList()); + locMats->resize(numLocMat); + for (i=0;iGetBlockNo(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(); } diff --git a/src/osgPlugins/txp/trpage_util.cpp b/src/osgPlugins/txp/trpage_util.cpp index 772679565..b611e1174 100644 --- a/src/osgPlugins/txp/trpage_util.cpp +++ b/src/osgPlugins/txp/trpage_util.cpp @@ -16,8 +16,8 @@ #include /* 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. diff --git a/src/osgPlugins/txp/trpage_util.h b/src/osgPlugins/txp/trpage_util.h index bf1091f7b..783544e27 100644 --- a/src/osgPlugins/txp/trpage_util.h +++ b/src/osgPlugins/txp/trpage_util.h @@ -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 diff --git a/src/osgPlugins/txp/trpage_write.h b/src/osgPlugins/txp/trpage_write.h index bd22e3ed5..eab83320b 100644 --- a/src/osgPlugins/txp/trpage_write.h +++ b/src/osgPlugins/txp/trpage_write.h @@ -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 #include @@ -27,333 +27,333 @@ #include /* 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 matTri; - std::vector tex; - std::vector norm,vert; - // Data arrays for a polygon - std::vector matPoly; - std::vector polyTex; - std::vector polyNorm,polyVert; - // Single points - std::vector tmpTex; - trpg3dPoint tmpNorm; - trpgColor tmpCol; + // Temporary data arrays for triangles/quads + std::vector matTri; + std::vector tex; + std::vector norm,vert; + // Data arrays for a polygon + std::vector matPoly; + std::vector polyTex; + std::vector polyNorm,polyVert; + // Single points + std::vector 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 texFileIDs; - trpgwAppFile *texFile; - std::vector geotypFileIDs; - trpgwAppFile *geotypFile; - bool separateGeoTypical; - int maxTexFileLen; + trpgEndian ness; + char dir[1024]; + trpgTexTable *texTable; + std::vector texFileIDs; + trpgwAppFile *texFile; + std::vector 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 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 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 tileFiles; + std::vector tileFiles; std::vector 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