TXP plugin changes submitted by Boris Bralo.

This commit is contained in:
Robert Osfield
2002-03-09 10:52:01 +00:00
parent ab5603e3d4
commit c67950561e
7 changed files with 2809 additions and 0 deletions

View File

@@ -0,0 +1,283 @@
/* ************************
Copyright Terrain Experts Inc.
Terrain Experts Inc (TERREX) reserves all rights to this source code
unless otherwise specified in writing by the President of TERREX.
This copyright may be updated in the future, in which case that version
supercedes this one.
-------------------
Terrex Experts Inc.
4400 East Broadway #314
Tucson, AZ 85711
info@terrex.com
Tel: (520) 323-7990
************************
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
/* trpage_compat.cpp
This file and the accompanying trpage_compat.h contain objects and procedures
used to maintain compatibility between versions of TerraPage. In particular, the
ability to read older versions of TerraPage and newer applications.
*/
#include "trpage_geom.h"
#include "trpage_read.h"
#include "trpage_compat.h"
/* Old short Material definition from 1.0.
{secret}
*/
class trpgShortMaterial {
public:
// Full trpgMaterial definition this one is based on
int baseMat;
// Currently the only thing a short material overrides is texture
std::vector<int> texids;
};
trpgMatTable1_0::trpgMatTable1_0(const trpgMatTable &inTbl)
{
*((trpgMatTable *)this) = inTbl;
}
bool trpgMatTable1_0::Read(trpgReadBuffer &buf)
{
trpgMaterial mat;
trpgToken matTok;
int32 len;
bool status;
int i,j,k;
std::vector<trpgShortMaterial> shortTable;
std::vector<trpgMaterial> baseMats;
try {
buf.Get(numTable);
buf.Get(numMat);
if (numTable <= 0 || numMat < 0) throw 1;
// Short material tables are always full size
shortTable.resize(numTable*numMat);
// Look for short material table
buf.GetToken(matTok,len);
if (matTok == TRPGSHORTMATTABLE) {
int32 numTex,texId;
buf.PushLimit(len);
for (i=0;i<numTable;i++)
for (j=0;j<numMat;j++) {
trpgShortMaterial &smat = shortTable[i*numMat+j];
buf.Get(smat.baseMat);
buf.Get(numTex);
for (k=0;k<numTex;k++) {
buf.Get(texId);
smat.texids.push_back(texId);
}
}
buf.PopLimit();
// Now read the base materials
int32 numBaseMat;
buf.Get(numBaseMat);
if (numBaseMat < 0) throw 1;
baseMats.resize(numBaseMat);
for (i=0;i<numBaseMat;i++) {
buf.GetToken(matTok,len);
if (matTok != TRPGMATERIAL) throw 1;
buf.PushLimit(len);
mat.Reset();
status = mat.Read(buf);
buf.PopLimit();
if (!status) throw 1;
baseMats[i] = mat;
}
}
}
catch (...) {
return false;
}
// Now convert to the new style material table
for (i=0;i<shortTable.size();i++) {
trpgShortMaterial &shortMat = shortTable[i];
trpgMaterial &baseMat = baseMats[shortMat.baseMat];
matTables.push_back(baseMat);
trpgMaterial &newMat = matTables[matTables.size()-1];
newMat.SetNumTexture(shortMat.texids.size());
for (j=0;j<shortMat.texids.size();j++) {
int texId;
trpgTextureEnv texEnv;
baseMat.GetTexture(j,texId,texEnv);
newMat.SetTexture(j,shortMat.texids[j],texEnv);
}
}
valid = true;
return true;
}
bool trpgMatTable1_0::Write(trpgWriteBuffer &buf)
{
if (!isValid())
return false;
// Create one short material for every material
std::vector<trpgShortMaterial> shortMats;
shortMats.resize(numTable*numMat);
// Iterate over the existing materials
int i;
for (i=0;i<numTable*numMat;i++) {
trpgMaterial &mat = matTables[i];
// Fill in the short material
trpgShortMaterial &sMat = shortMats[i];
int numTex;
mat.GetNumTexture(numTex);
for (int j=0;j<numTex;j++) {
int texId;
trpgTextureEnv texEnv;
mat.GetTexture(j,texId,texEnv);
sMat.texids.push_back(texId);
sMat.baseMat = i;
}
}
// Write the 1.0 material table
buf.Begin(TRPGMATTABLE2);
buf.Add(numTable);
buf.Add(numMat);
// Write the short materials
buf.Begin(TRPGSHORTMATTABLE);
for (i=0;i<shortMats.size();i++) {
trpgShortMaterial &sMat = shortMats[i];
buf.Add(sMat.baseMat);
buf.Add((int)(sMat.texids.size()));
int j;
for (j=0;j<sMat.texids.size();j++)
buf.Add(sMat.texids[j]);
}
buf.End();
// Write the regular materials
buf.Add(numTable*numMat);
for (i=0;i<numTable*numMat;i++) {
trpgMaterial &mat = 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);
}
// Close Mat Table
buf.End();
return true;
}
trpgTexture1_0 trpgTexture1_0::operator = (const trpgTexture &inTex)
{
*((trpgTexture *)this) = inTex;
return *this;
}
bool trpgTexture1_0::Read(trpgReadBuffer &buf)
{
mode = External;
try {
char texName[1024];
buf.Get(texName,1023);
SetName(texName);
buf.Get(useCount);
}
catch (...) {
return false;
}
return true;
}
bool trpgTexture1_0::Write(trpgWriteBuffer &buf)
{
// Can only deal with external textures in 1.0
if (mode != External)
return false;
// Write the name and use count
buf.Add(name);
buf.Add(useCount);
return true;
}
trpgTexTable1_0::trpgTexTable1_0(const trpgTexTable &inTbl)
{
*((trpgTexTable *)this) = inTbl;
}
bool trpgTexTable1_0::Read(trpgReadBuffer &buf)
{
int32 numTex;
try {
buf.Get(numTex);
texList.resize(numTex);
for (unsigned int i=0;i<numTex;i++) {
trpgTexture1_0 tex1_0;
tex1_0.Read(buf);
texList[i] = tex1_0;
}
}
catch (...) {
return false;
}
valid = true;
return true;
}
bool trpgTexTable1_0::Write(trpgWriteBuffer &buf)
{
int32 numTex;
if (!isValid())
return false;
buf.Begin(TRPGTEXTABLE);
numTex = texList.size();
buf.Add(numTex);
for (unsigned int i=0;i<texList.size();i++) {
trpgTexture1_0 tex1_0;
tex1_0 = texList[i];
if (!tex1_0.Write(buf))
return false;
}
buf.End();
return true;
}
trpgTileTable1_0::trpgTileTable1_0(const trpgTileTable &inTable)
{
// Nothing to copy for now
}
bool trpgTileTable1_0::Write(trpgWriteBuffer &buf)
{
try {
buf.Begin(TRPGTILETABLE);
buf.Add("");
buf.End();
}
catch (...) {
return false;
}
return true;
}

View File

@@ -0,0 +1,96 @@
/* ************************
Copyright Terrain Experts Inc.
Terrain Experts Inc (TERREX) reserves all rights to this source code
unless otherwise specified in writing by the President of TERREX.
This copyright may be updated in the future, in which case that version
supercedes this one.
-------------------
Terrex Experts Inc.
4400 East Broadway #314
Tucson, AZ 85711
info@terrex.com
Tel: (520) 323-7990
************************
*/
#ifndef _trpage_compat_h_
#define _trpage_compat_h_
/* trpage_compat.h
This file and the accompanying trpage_compat.cpp contain objects and procedures
used to maintain compatibility between versions of TerraPage. In particular, the
ability to read older versions of TerraPage and newer applications.
*/
/* Material Table 1.0.
This class is used to read old 1.0 material tables and convert them
into the 2.0 material table we're inheriting from. Users should
never directly interact with this class.
{secret}
*/
class trpgMatTable1_0 : public trpgMatTable {
public:
trpgMatTable1_0() { };
trpgMatTable1_0(const trpgMatTable &);
/* This read method overrides the one from trpgMatTable and knows
how to read the old school material tables.
*/
bool Read(trpgReadBuffer &);
/* This write method can write a 2.0 material table as 1.0
style for backward compatibility.
*/
bool Write(trpgWriteBuffer &);
protected:
};
/* Texture Table 1.0.
This class is used to read old 1.0 texture tables and convert them
into 2.0 texture tables. Users should never directly interact with
this class.
{secret}
*/
class trpgTexTable1_0 : public trpgTexTable {
public:
trpgTexTable1_0() { };
trpgTexTable1_0(const trpgTexTable &);
/* This read method overrides the one from trpgTexTable and
knows how to read the old style texture table.
*/
bool Read(trpgReadBuffer &);
/* The write method can write a 2.0 texture table as 1.0
style for backward compatibility.
*/
bool Write(trpgWriteBuffer &);
protected:
};
/* Texture 1.0.
Knows how to read an old style texture.
{secret}
*/
class trpgTexture1_0 : public trpgTexture {
public:
// Assignment operator from a regular trpgTexture
trpgTexture1_0 operator = (const trpgTexture &);
// Knows how to read old style textures
bool Read(trpgReadBuffer &);
// Can write old style textures
bool Write(trpgWriteBuffer &);
protected:
};
/* Tile Table 1.0
Knows how to write an old style tile table.
{secret}
*/
class trpgTileTable1_0 : public trpgTileTable {
public:
trpgTileTable1_0(const trpgTileTable &);
// Can write old style tile table
bool Write(trpgWriteBuffer &);
};
#endif

View File

@@ -0,0 +1,973 @@
/* ************************
Copyright Terrain Experts Inc.
Terrain Experts Inc (TERREX) reserves all rights to this source code
unless otherwise specified in writing by the President of TERREX.
This copyright may be updated in the future, in which case that version
supercedes this one.
-------------------
Terrex Experts Inc.
4400 East Broadway #314
Tucson, AZ 85711
info@terrex.com
Tel: (520) 323-7990
************************
*/
/* trpage_light.cpp
Methods for the trpgLightAttr, trpgLight and trpgLightTable classes.
This includes read and write methods.
You should only need to change something in here if you want to modify
what any of the classes contains.
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "trpage_geom.h"
#include "trpage_read.h"
#if defined(_WIN32)
#define ALIGNMENT_WORKAROUND false
#else
#define ALIGNMENT_WORKAROUND true
#endif
/******
Lights Attribute
******/
trpgLightAttr::trpgLightAttr(void)
{
Reset();
}
trpgLightAttr::trpgLightAttr(const trpgLightAttr &in)
{
operator=(in);
}
trpgLightAttr::~trpgLightAttr(void)
{
}
// Setters
void trpgLightAttr::SetType( trpgLightAttr::LightType in_type )
{
data.type = in_type;
}
void trpgLightAttr::SetDirectionality( trpgLightAttr::LightDirectionality in_directionality )
{
data.directionality = in_directionality;
}
void trpgLightAttr::SetFrontColor( trpgColor in_frontColor )
{
data.frontColor = in_frontColor;
}
void trpgLightAttr::SetFrontIntensity( float64 in_frontIntensity )
{
data.frontIntensity = in_frontIntensity;
}
void trpgLightAttr::SetBackColor( trpgColor in_backColor )
{
data.backColor = in_backColor;
}
void trpgLightAttr::SetBackIntensity( float64 in_backIntensity )
{
data.backIntensity = in_backIntensity;
}
void trpgLightAttr::SetNormal( trpg3dPoint in_normal )
{
data.normal = in_normal;
}
void trpgLightAttr::SetSMC( int32 in_smc )
{
data.smc = in_smc;
}
void trpgLightAttr::SetFID( int32 in_fid )
{
data.fid = in_fid;
}
void trpgLightAttr::SetFlags( int32 in_flags )
{
data.flags = in_flags;
}
void trpgLightAttr::SetHLobeAngle( float64 in_hLobeAngle )
{
data.horizontalLobeAngle = in_hLobeAngle;
}
void trpgLightAttr::SetVLobeAngle( float64 in_vLobeAngle )
{
data.verticalLobeAngle = in_vLobeAngle;
}
void trpgLightAttr::SetLobeRollAngle( float64 in_lobeRollAngle )
{
data.lobeRollAngle = in_lobeRollAngle;
}
void trpgLightAttr::SetLobeFalloff( float64 in_lobeFalloff )
{
data.lobeFalloff = in_lobeFalloff;
}
void trpgLightAttr::SetAmbient( float64 in_ambientIntensity )
{
data.ambientIntensity = in_ambientIntensity;
}
void trpgLightAttr::SetQuality( trpgLightAttr::LightQuality in_quality )
{
data.quality = in_quality;
}
void trpgLightAttr::SetRascalSignificance( float64 in_rascalSignificance )
{
data.rascalSignificance = in_rascalSignificance;
}
void trpgLightAttr::SetRandomIntensity( trpgLightAttr::LightQuality in_randomIntensity )
{
data.randomIntensity = in_randomIntensity;
}
void trpgLightAttr::SetCalligraphicAttr( trpgLightAttr::CalligraphicAttr& in_calligraphicAttr )
{
data.calligraphicAttr = in_calligraphicAttr;
}
void trpgLightAttr::SetCalligraphicDrawOrder( int32 in_drawOrder )
{
data.calligraphicAttr.drawOrder = in_drawOrder;
}
void trpgLightAttr::SetCalligraphicMinDefocus( float64 in_minDefocus )
{
data.calligraphicAttr.minDefocus = in_minDefocus;
}
void trpgLightAttr::SetCalligraphicMaxDefocus( float64 in_maxDefocus )
{
data.calligraphicAttr.maxDefocus = in_maxDefocus;
}
void trpgLightAttr::SetPerformerAttr( trpgLightAttr::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;
}
void trpgLightAttr::SetPerformerMinPixelSize( float64 in_minPxSize )
{
data.performerAttr.minPixelSize = in_minPxSize;
}
void trpgLightAttr::SetPerformerMaxPixelSize( float64 in_maxPxSize )
{
data.performerAttr.maxPixelSize = in_maxPxSize;
}
void trpgLightAttr::SetPerformerActualSize( float64 in_actualSize )
{
data.performerAttr.actualSize = in_actualSize;
}
void trpgLightAttr::SetPerformerTpPixelSize( float64 in_tpPixelSize )
{
data.performerAttr.transparentPixelSize = in_tpPixelSize;
}
void trpgLightAttr::SetPerformerTpFalloffExp( float64 in_tpFalloffExp )
{
data.performerAttr.transparentFallofExp = in_tpFalloffExp;
}
void trpgLightAttr::SetPerformerTpScale( float64 in_tpScale )
{
data.performerAttr.transparentScale = in_tpScale;
}
void trpgLightAttr::SetPerformerTpClamp( float64 in_tpClamp )
{
data.performerAttr.transparentClamp = in_tpClamp;
}
void trpgLightAttr::SetPerformerFogScale( float64 in_fogScale )
{
data.performerAttr.fogScale = in_fogScale;
}
void trpgLightAttr::SetAnimationAttr( trpgLightAttr::AnimationAttr& in_animationAttr )
{
data.animationAttr = in_animationAttr;
}
void trpgLightAttr::SetAnimationPeriod( float64 in_period )
{
data.animationAttr.period = in_period;
}
void trpgLightAttr::SetAnimationPhaseDelay( float64 in_phaseDelay )
{
data.animationAttr.phaseDelay = in_phaseDelay;
}
void trpgLightAttr::SetAnimationTimeOn( float64 in_timeOn )
{
data.animationAttr.timeOn = in_timeOn;
}
void trpgLightAttr::SetAnimationVector( trpg3dPoint in_vector )
{
data.animationAttr.vector = in_vector;
}
void trpgLightAttr::SetAnimationFlags( int32 flags )
{
data.animationAttr.flags = flags & trpgLightAttr::trpg_AnimationMask;
data.flags |= data.animationAttr.flags;
}
// Getters
void trpgLightAttr::GetType( trpgLightAttr::LightType& out_type )
{
out_type = data.type;
}
void trpgLightAttr::GetDirectionality( trpgLightAttr::LightDirectionality& out_directionality )
{
out_directionality = data.directionality;
}
void trpgLightAttr::GetFrontColor( trpgColor& out_frontColor )
{
out_frontColor = data.frontColor;
}
void trpgLightAttr::GetFrontIntensity( float64& out_frontIntensity )
{
out_frontIntensity = data.frontIntensity;
}
void trpgLightAttr::GetBackColor( trpgColor& out_backColor )
{
out_backColor = data.backColor;
}
void trpgLightAttr::GetBackIntensity( float64& out_backIntensity )
{
out_backIntensity = data.backIntensity;
}
void trpgLightAttr::GetNormal( trpg3dPoint& out_normal )
{
out_normal = data.normal;
}
void trpgLightAttr::GetSMC( int32& out_smc )
{
out_smc = data.smc;
}
void trpgLightAttr::GetFID( int32& out_fid )
{
out_fid = data.fid;
}
void trpgLightAttr::GetFlags( int32& out_flags )
{
out_flags = data.flags;
}
void trpgLightAttr::GetHLobeAngle( float64& out_hLobeAngle )
{
out_hLobeAngle = data.horizontalLobeAngle;
}
void trpgLightAttr::GetVLobeAngle( float64& out_vLobeAngle )
{
out_vLobeAngle = data.verticalLobeAngle;
}
void trpgLightAttr::GetLobeRollAngle( float64& out_lobeRollAngle )
{
out_lobeRollAngle = data.lobeRollAngle;
}
void trpgLightAttr::GetLobeFalloff( float64& out_lobeFalloff )
{
out_lobeFalloff = data.lobeFalloff;
}
void trpgLightAttr::GetAmbient( float64& out_ambientIntensity )
{
out_ambientIntensity = data.ambientIntensity;
}
void trpgLightAttr::GetQuality( trpgLightAttr::LightQuality& out_quality )
{
out_quality = data.quality;
}
void trpgLightAttr::GetRascalSignificance( float64& out_rascalSignificance )
{
out_rascalSignificance = data.rascalSignificance;
}
void trpgLightAttr::GetRandomIntensity( trpgLightAttr::LightQuality& out_randomIntensity )
{
out_randomIntensity = data.randomIntensity;
}
void trpgLightAttr::GetCalligraphicAttr( trpgLightAttr::CalligraphicAttr& out_calligraphicAttr )
{
out_calligraphicAttr = data.calligraphicAttr;
}
void trpgLightAttr::GetCalligraphicDrawOrder( int32& out_drawOrder )
{
out_drawOrder = data.calligraphicAttr.drawOrder;
}
void trpgLightAttr::GetCalligraphicMinDefocus( float64& out_minDefocus )
{
out_minDefocus = data.calligraphicAttr.minDefocus;
}
void trpgLightAttr::GetCalligraphicMaxDefocus( float64& out_maxDefocus )
{
out_maxDefocus = data.calligraphicAttr.maxDefocus;
}
void trpgLightAttr::GetPerformerAttr( trpgLightAttr::PerformerAttr& out_performerAttr )
{
out_performerAttr = data.performerAttr;
}
void trpgLightAttr::GetPerformerFlags( int32& out_flags )
{
out_flags = data.performerAttr.flags;
}
void trpgLightAttr::GetPerformerMinPixelSize( float64& out_minPxSize )
{
out_minPxSize = data.performerAttr.minPixelSize;
}
void trpgLightAttr::GetPerformerMaxPixelSize( float64& out_maxPxSize )
{
out_maxPxSize = data.performerAttr.maxPixelSize;
}
void trpgLightAttr::GetPerformerActualSize( float64& out_actualSize )
{
out_actualSize = data.performerAttr.actualSize;
}
void trpgLightAttr::GetPerformerTpPixelSize( float64& out_tpPixelSize )
{
out_tpPixelSize = data.performerAttr.transparentPixelSize;
}
void trpgLightAttr::GetPerformerTpFalloffExp( float64& out_tpFalloffExp )
{
out_tpFalloffExp = data.performerAttr.transparentFallofExp;
}
void trpgLightAttr::GetPerformerTpScale( float64& out_tpScale )
{
out_tpScale = data.performerAttr.transparentScale;
}
void trpgLightAttr::GetPerformerTpClamp( float64& out_tpClamp )
{
out_tpClamp = data.performerAttr.transparentClamp;
}
void trpgLightAttr::GetPerformerFogScale( float64& out_fogScale )
{
out_fogScale = data.performerAttr.fogScale;
}
void trpgLightAttr::GetAnimationAttr( trpgLightAttr::AnimationAttr& out_animationAttr )
{
out_animationAttr = data.animationAttr;
}
void trpgLightAttr::GetAnimationPeriod( float64& out_period )
{
out_period = data.animationAttr.period;
}
void trpgLightAttr::GetAnimationPhaseDelay( float64& out_phaseDelay )
{
out_phaseDelay = data.animationAttr.phaseDelay;
}
void trpgLightAttr::GetAnimationTimeOn( float64& out_timeOn )
{
out_timeOn = data.animationAttr.timeOn;
}
void trpgLightAttr::GetAnimationVector( trpg3dPoint& out_vector )
{
out_vector = data.animationAttr.vector;
}
void trpgLightAttr::GetAnimationFlags( int32& flags )
{
flags = data.animationAttr.flags;
}
// Writes this class to a write buffer
bool trpgLightAttr::Write(trpgWriteBuffer &buf)
{
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_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_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.End();
return true;
}
/* LightAttr CB
Used to parse tokens for a light attribute.
*/
class lightAttrCB : public trpgr_Callback {
public:
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;
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;
default:
break;
}
}
catch (...) {
return NULL;
}
return lightAttr;
}
// Reads this class from a read buffer
bool trpgLightAttr::Read(trpgReadBuffer &buf)
{
Reset();
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.Parse(buf);
return isValid();
}
bool trpgLightAttr::isValid(void) const
{
return true;
}
trpgLightAttr& trpgLightAttr::operator = (const trpgLightAttr& in)
{
data = in.data;
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;
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;
return true;
}
bool trpgLightAttr::operator != (const trpgLightAttr& in)
{
return !operator==(in);
}
void trpgLightAttr::Reset(void)
{
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;
}
/**************
Light
*/
trpgLight::trpgLight(void)
{
index = -1;
}
trpgLight::trpgLight(const trpgLight &in)
{
operator=(in);
}
trpgLight::~trpgLight(void)
{
Reset();
}
// Set the index pointing into the Light Table
void trpgLight::SetAttrIndex(int ix)
{
index = ix;
}
// Add a new location this light is located at
void trpgLight::AddVertex(trpg3dPoint pt)
{
lightPoints.push_back(pt);
}
// Returns the number of locations, this light is located at
void trpgLight::GetNumVertices(uint32 &nvertices) const
{
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;
}
bool trpgLight::GetVertices(trpg3dPoint *pts) const
{
int i;
if (!isValid()) return false;
if (lightPoints.size() != 0)
for (i=0;i<lightPoints.size();i++)
pts[i] = lightPoints[i];
return true;
}
bool trpgLight::GetVertices(float64 *fts) const
{
int i;
int j = 0;
if (!isValid()) return false;
if (lightPoints.size() != 0)
for (i=0;i<lightPoints.size();i++) {
fts[j++] = lightPoints[i].x;
fts[j++] = lightPoints[i].y;
fts[j++] = lightPoints[i].z;
}
return true;
}
bool trpgLight::GetVertices(float32 *fts) const
{
int i;
int j = 0;
if (!isValid()) return false;
if (lightPoints.size() != 0)
for (i=0;i<lightPoints.size();i++) {
fts[j++] = (float32)lightPoints[i].x;
fts[j++] = (float32)lightPoints[i].y;
fts[j++] = (float32)lightPoints[i].z;
}
return true;
}
// Returns the index of the Light Attributes in the Light Table
void trpgLight::GetAttrIndex(int &ix) const
{
ix = index;
}
// Validity check
bool trpgLight::isValid(void) const
{
return true;
}
// Resets the contents back to empty
void trpgLight::Reset(void)
{
lightPoints.clear();
index =-1;
}
// Writes this class to a write buffer
bool trpgLight::Write(trpgWriteBuffer &buf)
{
int numVertices = lightPoints.size();
if (!isValid())
return false;
buf.Begin(TRPGLIGHT);
buf.Add(index);
buf.Add(numVertices);
for (unsigned int i=0;i<lightPoints.size();i++)
buf.Add(lightPoints[i]);
buf.End();
return true;
}
// Reads this class from a read buffer
bool trpgLight::Read(trpgReadBuffer &buf)
{
Reset();
int numVertices;
buf.Get(index);
buf.Get(numVertices);
for ( int i = 0; i < numVertices; i++ ) {
trpg3dPoint vx;
buf.Get(vx);
lightPoints.push_back(vx);
}
return isValid();
}
// operator
trpgLight& trpgLight::operator = (const trpgLight &in)
{
Reset();
index = in.index;
for ( int i = 0; i < in.lightPoints.size(); i++ )
lightPoints.push_back(in.lightPoints[i]);
return *this;
}
/* Light Attributes Table
Just a list of light attribs so we can index.
*/
// Constructor
trpgLightTable::trpgLightTable()
{
}
trpgLightTable::trpgLightTable(const trpgLightTable &in)
{
*this = in;
}
// Reset function
void trpgLightTable::Reset()
{
lightList.clear();
}
// Destructor
trpgLightTable::~trpgLightTable()
{
Reset();
}
// Validity check
bool trpgLightTable::isValid() const
{
for (unsigned int i=0;i<lightList.size();i++)
if (!lightList[i].isValid())
return false;
return true;
}
// Set functions
int trpgLightTable::AddLightAttr(const trpgLightAttr& inLight)
{
lightList.push_back(inLight);
return lightList.size()-1;
}
int trpgLightTable::FindAddLightAttr(const trpgLightAttr& inLight)
{
for (int i=0;i<lightList.size();i++)
if (lightList[i] == inLight)
return i;
return AddLightAttr(inLight);
}
// Copy operator
trpgLightTable &trpgLightTable::operator = (const trpgLightTable &in)
{
Reset();
for (int i=0;i<in.lightList.size();i++)
AddLightAttr(in.lightList[i]);
return *this;
}
// Write Light table
bool trpgLightTable::Write(trpgWriteBuffer &buf)
{
int32 numLights;
if (!isValid())
return false;
buf.Begin(TRPGLIGHTTABLE);
numLights = lightList.size();
buf.Add(numLights);
for (unsigned int i=0;i<lightList.size();i++)
lightList[i].Write(buf);
buf.End();
return true;
}
/* ***********
Read Light Table
***********
*/
// Get functions
bool trpgLightTable::GetNumLightAttrs(int &no) const
{
if (!isValid()) return false;
no = lightList.size();
return true;
}
const trpgLightAttr* trpgLightTable::GetLightAttrRef(int id) const
{
if (id < 0 || id >= lightList.size()) return NULL;
return &lightList[id];
}
bool trpgLightTable::Read(trpgReadBuffer &buf)
{
int32 numLights;
trpgToken lightTok;
int32 len;
try {
buf.Get(numLights);
lightList.resize(numLights);
for (unsigned int i=0;i<numLights;i++) {
buf.GetToken(lightTok,len);
if (lightTok != TRPGLIGHTATTR) throw 1;
buf.PushLimit(len);
trpgLightAttr &light = lightList[i];
bool status = light.Read(buf);
buf.PopLimit();
if (!status) throw 1;
}
}
catch (...) {
return false;
}
return true;
}

View File

@@ -0,0 +1,210 @@
/* ************************
Copyright Terrain Experts Inc.
Terrain Experts Inc (TERREX) reserves all rights to this source code
unless otherwise specified in writing by the President of TERREX.
This copyright may be updated in the future, in which case that version
supercedes this one.
-------------------
Terrex Experts Inc.
4400 East Broadway #314
Tucson, AZ 85711
info@terrex.com
Tel: (520) 323-7990
************************
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
/* trpage_pparse.cpp
This file contains classes that can parse a TerraPage
archive for the purpose of printing it out.
*/
#include "trpage_print.h"
#include "trpage_scene.h"
/* Set up the callbacks for the scene graph parser.
In our case this is just one read helper with
a switch statement.
*/
trpgPrintGraphParser::trpgPrintGraphParser(trpgPrintBuffer *inBuf)
{
printBuf = inBuf;
// Register the readers
AddCallback(TRPG_GEOMETRY,new ReadHelper(printBuf));
AddCallback(TRPG_GROUP,new ReadHelper(printBuf));
AddCallback(TRPG_ATTACH,new ReadHelper(printBuf));
AddCallback(TRPG_BILLBOARD,new ReadHelper(printBuf));
AddCallback(TRPG_LOD,new ReadHelper(printBuf));
AddCallback(TRPG_TRANSFORM,new ReadHelper(printBuf));
AddCallback(TRPG_MODELREF,new ReadHelper(printBuf));
AddCallback(TRPG_LAYER,new ReadHelper(printBuf));
AddCallback(TRPG_LIGHT,new ReadHelper(printBuf));
AddCallback(TRPGTILEHEADER,new ReadHelper(printBuf));
}
/* Start Children is called when the parser hits a Push
in the read buffer. We just want to indent further when
that happens.
*/
bool trpgPrintGraphParser::StartChildren(void *)
{
printBuf->IncreaseIndent();
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.
*/
bool trpgPrintGraphParser::EndChildren(void *)
{
printBuf->DecreaseIndent();
return true;
}
/* Read Helper parse method sets up the correct class depending
on the token and asks it to read and print itself.
*/
void *trpgPrintGraphParser::ReadHelper::Parse(trpgToken tok,trpgReadBuffer &buf)
{
trpgReadWriteable *obj = NULL;
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_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 TRPGTILEHEADER:
obj = new trpgTileHeader();
break;
};
if (obj) {
if (obj->Read(buf))
obj->Print(*pBuf);
delete obj;
}
// 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.
There are two versions of this function. The first takes
a file name and the second an opened archive where the header
has already been read.
*/
bool trpgPrintArchive(char *filename,trpgPrintBuffer &pBuf,int flags)
{
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);
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;
}
bool status = trpgPrintArchive(&archive,pBuff,flags);
return status;
}
#endif
bool trpgPrintArchive(trpgr_Archive *archive,trpgPrintBuffer &pBuf,int flags)
{
char ls[1024];
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);
pBuf.prnLine();
// Now do the tiles
if (!archive->isValid()) return false;
// Parser that prints out a tile scene graph
trpgPrintGraphParser parser(&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;
for (nl=0;nl<numLod;nl++) {
archive->GetHeader()->GetLodSize(nl,tileSize);
// Iterate over the tiles
for (x=tileSize.x-1;x>=0;x--)
for (y=0;y<tileSize.y;y++) {
sprintf(ls,"Tile (lod) (x,y) = (%d) (%d,%d)",nl,x,y);
pBuf.prnLine(ls);
if (archive->ReadTile(x,y,nl,buf)) {
if (flags & TRPGPRN_BODY) {
pBuf.IncreaseIndent();
// Parse it (also prints it
parser.Parse(buf);
pBuf.DecreaseIndent();
}
} else
pBuf.prnLine(" Couldn't read tile.");
}
}
return true;
}

View File

@@ -0,0 +1,838 @@
/* ************************
Copyright Terrain Experts Inc.
Terrain Experts Inc (TERREX) reserves all rights to this source code
unless otherwise specified in writing by the President of TERREX.
This copyright may be updated in the future, in which case that version
supercedes this one.
-------------------
Terrex Experts Inc.
4400 East Broadway #314
Tucson, AZ 85711
info@terrex.com
Tel: (520) 323-7990
************************
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
/* trpage_print.cpp
Print out the contents of a TerraPage archive.
This module provides an example of how to access each of the classes
within a TerraPage archive.
*/
#include "trpage_print.h"
/* ******************************************
Print Buffer implementation
The print buffer is a way to dump debugging data out
to a file (or console). You can make your own subclass
of trpgPrintBuffer if you have specific needs.
******************************************
*/
trpgPrintBuffer::trpgPrintBuffer()
{
curIndent = 0;
indentStr[0] = 0;
}
// Increase the current indent
void trpgPrintBuffer::IncreaseIndent(int amount)
{
curIndent+=amount;
updateIndent();
}
// Decrease the current indent
void trpgPrintBuffer::DecreaseIndent(int amount)
{
curIndent-=amount;
curIndent = MAX(0,curIndent);
updateIndent();
}
// Reprint the indent string
void trpgPrintBuffer::updateIndent()
{
int i;
for (i=0;i<MIN(199,curIndent);i++)
indentStr[i] = ' ';
indentStr[i] = 0;
}
// Constructors for File Print Buffer
trpgFilePrintBuffer::trpgFilePrintBuffer(FILE *inFp)
{
isMine = false;
fp = inFp;
valid = true;
}
trpgFilePrintBuffer::trpgFilePrintBuffer(char *file)
{
isMine = true;
fp = fopen(file,"w");
valid = fp != NULL;
}
// Destructor for File Print Buffer
trpgFilePrintBuffer::~trpgFilePrintBuffer()
{
if (isMine && fp)
fclose(fp);
fp = NULL;
valid = false;
}
// Print out a line of text
bool trpgFilePrintBuffer::prnLine(char *str)
{
if (!fp)
return false;
if (str) {
fprintf(fp,indentStr);
fprintf(fp,str);
fprintf(fp,"\n");
} else
fprintf(fp,"\n");
return true;
}
/* *************************************
Print Methods for TerraPage constructs
All the print methods for every TerraPage object that
is readable/writeable are here. These are used for
debugging.
*************************************
*/
/* Print out the header information.
*/
bool trpgHeader::Print(trpgPrintBuffer &buf) const
{
char ls[1024];
buf.prnLine("----Archive Header----");
buf.IncreaseIndent();
sprintf(ls,"verMinor = %d, verMajor = %d",verMinor,verMajor); buf.prnLine(ls);
sprintf(ls,"dbVerMinor = %d, dbVerMajor = %d",dbVerMinor,dbVerMajor); buf.prnLine(ls);
sprintf(ls,"maxGroupID = %d",maxGroupID); buf.prnLine(ls);
sprintf(ls,"sw = (%f,%f), ne = (%f,%f)",sw.x,sw.y,ne.x,ne.y); buf.prnLine(ls);
sprintf(ls,"tileType = %d, origin = (%f,%f,%f)",tileType,origin.x,origin.y,origin.z); buf.prnLine(ls);
sprintf(ls,"numLods = %d",numLods); buf.prnLine(ls);
buf.IncreaseIndent();
for (int i=0;i<numLods;i++) {
sprintf(ls,"tileSize = (%f,%f), lodSizes = (%d,%d), lodRanges = %f",tileSize[i].x,tileSize[i].y,lodSizes[i].x,lodSizes[i].y,lodRanges[i]); buf.prnLine(ls);
}
buf.DecreaseIndent(2);
buf.prnLine("");
return true;
}
/* Print out texture environment information
*/
bool trpgTextureEnv::Print(trpgPrintBuffer &buf) const
{
char ls[1024];
buf.prnLine("----Texture Environment----");
buf.IncreaseIndent();
sprintf(ls,"envMode = %d",envMode); buf.prnLine(ls);
sprintf(ls,"minFilter = %d, magFilter = %d",minFilter,magFilter); buf.prnLine(ls);
sprintf(ls,"wrapS = %d, wrapT = %d",wrapS,wrapT); buf.prnLine(ls);
buf.DecreaseIndent();
buf.prnLine("");
return true;
}
/* Print out the material information
*/
bool trpgMaterial::Print(trpgPrintBuffer &buf) const
{
char ls[1024];
buf.prnLine("----Material----");
buf.IncreaseIndent();
sprintf(ls,"isBumpMap = %d",(int)isBump);
sprintf(ls,"color = (%f,%f,%f)",color.red,color.green,color.blue); buf.prnLine(ls);
sprintf(ls,"ambient = (%f,%f,%f)",ambient.red,ambient.green,ambient.blue); buf.prnLine(ls);
sprintf(ls,"diffuse = (%f,%f,%f)",diffuse.red,diffuse.green,diffuse.blue); buf.prnLine(ls);
sprintf(ls,"specular = (%f,%f,%f)",specular.red,specular.green,specular.blue); buf.prnLine(ls);
sprintf(ls,"emission = (%f,%f,%f)",emission.red,emission.green,emission.blue); buf.prnLine(ls);
sprintf(ls,"shininess = %f, shadeModel = %d",shininess,shadeModel); buf.prnLine(ls);
sprintf(ls,"pointSize = %f, lineWidth = %f",pointSize,lineWidth); buf.prnLine(ls);
sprintf(ls,"cullMode = %d, alphaFunc = %d",cullMode,alphaFunc); buf.prnLine(ls);
sprintf(ls,"alpha = %f, alphaRef = %f",alpha,alphaRef); buf.prnLine(ls);
sprintf(ls,"autoNormal = %d",autoNormal); buf.prnLine(ls);
sprintf(ls,"numTile = %d",numTile); buf.prnLine(ls);
sprintf(ls,"numTex = %d",numTex); buf.prnLine(ls);
buf.IncreaseIndent();
for (int i=0;i<numTex;i++) {
sprintf(ls,"texID[%d] = %d",i,texids[i]); buf.prnLine(ls);
buf.IncreaseIndent();
texEnvs[i].Print(buf);
buf.DecreaseIndent();
}
buf.DecreaseIndent(2);
buf.prnLine();
return true;
}
/* Print out the material tables.
*/
bool trpgMatTable::Print(trpgPrintBuffer &buf) const
{
char ls[1024];
buf.prnLine("----Material Table----");
buf.IncreaseIndent();
sprintf(ls,"numTable = %d",numTable); buf.prnLine(ls);
sprintf(ls,"numMat = %d",numMat); buf.prnLine(ls);
buf.IncreaseIndent();
for (int j=0;j<numTable;j++) {
sprintf(ls,"----Sub Table %d----",j); buf.prnLine(ls);
buf.IncreaseIndent();
for (int i=0;i<numMat;i++) {
const trpgMaterial *mat;
sprintf(ls,"Material %d",i); buf.prnLine(ls);
mat = (const_cast<trpgMatTable *>(this))->GetMaterialRef(j,i);
mat->Print(buf);
}
buf.DecreaseIndent();
}
buf.DecreaseIndent(2);
return true;
}
/* Print out texture.
*/
bool trpgTexture::Print(trpgPrintBuffer &buf) const
{
char ls[1024];
buf.prnLine("----Texture----");
buf.IncreaseIndent();
sprintf(ls,"mode = %d, type = %d",mode,type); buf.prnLine(ls);
sprintf(ls,"Name = %s",name); buf.prnLine(ls);
sprintf(ls,"useCount = %d",useCount); buf.prnLine(ls);
sprintf(ls,"sizeX = %d, sizeY = %d",sizeX,sizeY); buf.prnLine(ls);
sprintf(ls,"ismipmap = %d",isMipmap); buf.prnLine(ls);
sprintf(ls,"addr.file = %d, addr.offset = %d",addr.file,addr.offset); buf.prnLine(ls);
buf.DecreaseIndent();
buf.prnLine();
return true;
}
/* Print out texture table
*/
bool trpgTexTable::Print(trpgPrintBuffer &buf) const
{
char ls[1024];
buf.prnLine("----Texture Table----");
buf.IncreaseIndent();
for (int i=0;i<texList.size();i++) {
sprintf(ls,"Texture %d",i); buf.prnLine(ls);
texList[i].Print(buf);
}
buf.DecreaseIndent();
buf.prnLine();
return true;
}
/* Print out model table
*/
bool trpgModelTable::Print(trpgPrintBuffer &buf) const
{
char ls[1024];
buf.prnLine("----Model Table----");
buf.IncreaseIndent();
for (int i=0;i<models.size();i++) {
sprintf(ls,"Model %d",i); buf.prnLine(ls);
models[i].Print(buf);
}
buf.DecreaseIndent();
buf.prnLine();
return true;
}
/* Print out a model
*/
bool trpgModel::Print(trpgPrintBuffer &buf) const
{
char ls[1024];
buf.prnLine("----Model----");
buf.IncreaseIndent();
sprintf(ls,"type = %d",type); buf.prnLine(ls);
if (name) {
sprintf(ls,"name = %s",name); buf.prnLine(ls);
}
sprintf(ls,"diskRef = %d",(int)diskRef), buf.prnLine(ls);
sprintf(ls,"useCount = %d",useCount); buf.prnLine(ls);
buf.DecreaseIndent();
buf.prnLine();
return true;
}
/* Print out a tile header
*/
bool trpgTileHeader::Print(trpgPrintBuffer &buf) const
{
char ls[1024];
buf.prnLine("----Tile Header----");
buf.IncreaseIndent();
sprintf(ls,"matList size = %d",matList.size()); buf.prnLine(ls);
buf.IncreaseIndent();
int i;
for (i=0;i<matList.size();i++) {
sprintf(ls,"matList[%d] = %d",i,matList[i]); buf.prnLine(ls);
}
buf.DecreaseIndent();
sprintf(ls,"modelList size = %d",modelList.size()); buf.prnLine(ls);
buf.IncreaseIndent();
for (i=0;i<modelList.size();i++) {
sprintf(ls,"modelList[%d] = %d",i,modelList[i]); buf.prnLine(ls);
}
buf.DecreaseIndent();
sprintf(ls,"local material list size = %d",locMats.size()); buf.prnLine(ls);
buf.IncreaseIndent();
for (i=0;i<locMats.size();i++)
locMats[i].Print(buf);
buf.DecreaseIndent();
buf.DecreaseIndent();
buf.prnLine();
return true;
}
/* Print out color info
*/
bool trpgColorInfo::Print(trpgPrintBuffer &buf) const
{
char ls[1024];
buf.prnLine("----Color Info----");
buf.IncreaseIndent();
sprintf(ls,"type = %d, bind = %d",type,bind); buf.prnLine(ls);
sprintf(ls,"colorData size = %d",data.size());
buf.IncreaseIndent();
for (int i=0;i<data.size();i++) {
sprintf(ls,"color[%d] = (%f,%f,%f)",i,data[i].red,data[i].blue,data[i].green); buf.prnLine(ls);
}
buf.DecreaseIndent(2);
buf.prnLine();
return true;
}
/* Print out tex data info
*/
bool trpgTexData::Print(trpgPrintBuffer &buf) const
{
char ls[1024];
buf.prnLine("----Tex Data----");
buf.IncreaseIndent();
sprintf(ls,"bind = %d",bind); buf.prnLine(ls);
if (floatData.size()) {
sprintf(ls,"tex coords (float) = %d",floatData.size()); buf.prnLine(ls);
buf.IncreaseIndent();
for (int i=0;i<floatData.size()/2;i++) {
sprintf(ls,"tex coord[%d] = (%f,%f)",i,floatData[i*2+0],floatData[i*2+1]); buf.prnLine(ls);
}
buf.DecreaseIndent();
} else {
if (doubleData.size()) {
sprintf(ls,"tex coords (double) = %d",doubleData.size());
buf.IncreaseIndent();
for (int i=0;i<doubleData.size()/2;i++) {
sprintf(ls,"tex coord[%d] = (%f,%f)",i,doubleData[i*2+0],doubleData[i*2+1]), buf.prnLine(ls);
}
buf.DecreaseIndent();
}
}
buf.DecreaseIndent();
buf.prnLine();
return true;
}
/* Print out geometry data
*/
bool trpgGeometry::Print(trpgPrintBuffer &buf) const
{
char ls[1024];
buf.prnLine("----Geometry Node----");
buf.IncreaseIndent();
sprintf(ls,"Material size = %d",materials.size()); buf.prnLine(ls);
buf.IncreaseIndent();
ls[0] = 0;
int i;
for (i=0;i<materials.size();i++) {
char locStr[100];
sprintf(locStr,"%d ",materials[i]);
strcat(ls,locStr);
}
buf.prnLine(ls);
buf.DecreaseIndent();
sprintf(ls,"primType = %d, numPrim = %d",primType,numPrim); buf.prnLine(ls);
sprintf(ls,"primLength size = %d",primLength.size()); buf.prnLine(ls);
buf.IncreaseIndent();
ls[0] = 0;
for (i=0;i<primLength.size();i++) {
char locStr[100];
sprintf(locStr,"%d ",primLength[i]);
strcat(ls,locStr);
}
buf.prnLine(ls);
buf.DecreaseIndent();
if (vertDataFloat.size()) {
sprintf(ls,"vert data (float) length = %d",vertDataFloat.size());
buf.prnLine(ls);
buf.IncreaseIndent();
for (i=0;i<vertDataFloat.size();i++) {
sprintf(ls,"(%f, %f, %f)",vertDataFloat[3*i],vertDataFloat[3*i+1],vertDataFloat[3*i+2]);
buf.prnLine(ls);
}
buf.DecreaseIndent();
} else {
if (vertDataDouble.size()) {
sprintf(ls,"vert data (double) length = %d",vertDataDouble.size());
buf.prnLine(ls);
buf.IncreaseIndent();
for (i=0;i<vertDataDouble.size();i++) {
sprintf(ls,"(%f, %f, %f)",vertDataDouble[3*i],vertDataDouble[3*i+1],vertDataDouble[3*i+2]);
buf.prnLine(ls);
}
buf.DecreaseIndent();
}
}
sprintf(ls,"normBind = %d",normBind); buf.prnLine(ls);
if (normDataFloat.size()) {
sprintf(ls,"norm data (float) length = %d",normDataFloat.size());
buf.prnLine(ls);
buf.IncreaseIndent();
for (i=0;i<normDataFloat.size()/3;i++) {
sprintf(ls,"(%f, %f, %f)",normDataFloat[3*i],normDataFloat[3*i+1],normDataFloat[3*i+2]);
buf.prnLine(ls);
}
buf.DecreaseIndent();
} else {
if (normDataDouble.size()) {
sprintf(ls,"norm data (double) length = %d",normDataDouble.size());
buf.prnLine(ls);
buf.IncreaseIndent();
for (i=0;i<normDataDouble.size()/3;i++) {
sprintf(ls,"(%f, %f, %f)",normDataDouble[3*i],normDataDouble[3*i+1],normDataDouble[3*i+2]);
buf.prnLine(ls);
}
buf.DecreaseIndent();
}
}
sprintf(ls,"color info size = %d",colors.size()); buf.prnLine(ls);
buf.IncreaseIndent();
for (i=0;i<colors.size();i++) {
colors[i].Print(buf);
}
buf.DecreaseIndent();
sprintf(ls,"tex data size = %d",texData.size());
buf.IncreaseIndent();
for (i=0;i<texData.size();i++) {
texData[i].Print(buf);
}
buf.DecreaseIndent();
// Note: Do edge flags
buf.DecreaseIndent();
buf.prnLine();
return true;
}
/* Print group info
*/
bool trpgGroup::Print(trpgPrintBuffer &buf) const
{
char ls[1024];
buf.prnLine("----Group Node----");
buf.IncreaseIndent();
sprintf(ls,"id = %d, numChild = %d",id,numChild); buf.prnLine(ls);
sprintf(ls,"name = %s", name ? name : "noname" ); buf.prnLine(ls);
buf.DecreaseIndent();
buf.prnLine();
return true;
}
/* Print Attach info
*/
bool trpgAttach::Print(trpgPrintBuffer &buf) const
{
char ls[1024];
buf.prnLine("----Attach Node----");
buf.IncreaseIndent();
sprintf(ls,"id = %d, parentID = %d, childPos = %d",id,parentID,childPos); buf.prnLine(ls);
sprintf(ls,"name = %s", name ? name : "noname" ); buf.prnLine(ls);
buf.DecreaseIndent();
buf.prnLine();
return true;
}
/* Print billboard info
*/
bool trpgBillboard::Print(trpgPrintBuffer &buf) const
{
char ls[1024];
buf.prnLine("----Billboard Node----");
buf.IncreaseIndent();
sprintf(ls,"id = %d, type = %d, mode = %d",id,type,mode); buf.prnLine(ls);
sprintf(ls,"center = (%f,%f,%f)",center.x,center.y,center.z); buf.prnLine(ls);
sprintf(ls,"axis = (%f,%f,%f)",axis.x,axis.y,axis.z); buf.prnLine(ls);
sprintf(ls,"name = %s", name ? name : "noname" ); buf.prnLine(ls);
buf.DecreaseIndent();
buf.prnLine();
return true;
}
/* Print LOD info
*/
bool trpgLod::Print(trpgPrintBuffer &buf) const
{
char ls[1024];
buf.prnLine("----LOD Node----");
buf.IncreaseIndent();
sprintf(ls,"id = %d",id); buf.prnLine(ls);
sprintf(ls,"numRange (hint) = %d",numRange); buf.prnLine(ls);
sprintf(ls,"switchIn = %f, switchOut = %f, width = %f",switchIn,switchOut,width); buf.prnLine(ls);
sprintf(ls,"center = (%f,%f,%f)",center.x,center.y,center.z);
sprintf(ls,"name = %s", name ? name : "noname" ); buf.prnLine(ls);
sprintf(ls,"rangeIndex = %d",rangeIndex); buf.prnLine(ls);
buf.DecreaseIndent();
buf.prnLine();
return true;
}
/* Print Layer info
*/
bool trpgLayer::Print(trpgPrintBuffer &buf) const
{
char ls[1024];
buf.prnLine("----Layer Node----");
buf.IncreaseIndent();
sprintf(ls,"id = %d",id); buf.prnLine(ls);
sprintf(ls,"name = %s", name ? name : "noname" ); buf.prnLine(ls);
buf.DecreaseIndent();
buf.prnLine();
return true;
}
/* Print Transform
*/
bool trpgTransform::Print(trpgPrintBuffer &buf) const
{
char ls[1024];
buf.prnLine("----Transform Node----");
buf.IncreaseIndent();
sprintf(ls,"id = %d",id); buf.prnLine(ls);
buf.IncreaseIndent();
for (int i=0;i<4;i++) {
sprintf(ls,"%f %f %f %f",m[i][0],m[i][1],m[i][2],m[i][3]);
buf.prnLine(ls);
}
sprintf(ls,"name = %s", name ? name : "noname" ); buf.prnLine(ls);
buf.DecreaseIndent(2);
buf.prnLine();
return true;
}
/* Print Model Reference
*/
bool trpgModelRef::Print(trpgPrintBuffer &buf) const
{
char ls[1024];
buf.prnLine("----Model Reference Node----");
buf.IncreaseIndent();
sprintf(ls,"modelRef = %d",modelRef); buf.prnLine(ls);
buf.IncreaseIndent();
for (int i=0;i<4;i++) {
sprintf(ls,"%f %f %f %f",m[i][0],m[i][1],m[i][2],m[i][3]);
buf.prnLine(ls);
}
buf.DecreaseIndent(2);
buf.prnLine();
return true;
}
/* Tile Table Print
*/
bool trpgTileTable::Print(trpgPrintBuffer &buf) const
{
char ls[1024];
buf.prnLine("----Tile Table----");
buf.IncreaseIndent();
sprintf(ls,"mode = %d",mode); buf.prnLine(ls);
sprintf(ls,"numLod = %d",lodInfo.size()); buf.prnLine(ls);
for (int i=0;i<lodInfo.size();i++) {
const LodInfo &li = lodInfo[i];
sprintf(ls,"LOD %d, numX = %d, numY = %d",i,li.numX,li.numY); buf.prnLine(ls);
buf.prnLine("File ID, Offset, Zmin, Zmax");
buf.IncreaseIndent();
for (int j=0;j<li.addr.size();j++) {
sprintf(ls,"%d %d %f %f",li.addr[j].file,li.addr[j].offset,li.elev_min[j],li.elev_max[j]); buf.prnLine(ls);
}
buf.DecreaseIndent();
}
buf.DecreaseIndent();
buf.prnLine();
return true;
}
/* Local Material Print
*/
bool trpgLocalMaterial::Print(trpgPrintBuffer &buf) const
{
char ls[1024];
buf.prnLine("----Local Material Definition----");
buf.IncreaseIndent();
sprintf(ls,"baseMat = %d",baseMat); buf.prnLine(ls);
sprintf(ls,"(sx,sy) -> (ex,ey) = (%d,%d) -> (%d,%d)",sx,sy,ex,ey); buf.prnLine(ls);
sprintf(ls,"dest (width,height) = (%d,%d)",destWidth,destHeight); buf.prnLine(ls);
sprintf(ls,"addr (file,offset) = (%d,%d)",addr.file,addr.offset); buf.prnLine(ls);
buf.DecreaseIndent();
buf.prnLine();
return true;
}
/* Light Attribute Print
*/
bool trpgLightAttr::Print(trpgPrintBuffer &buf) const
{
char ls[1024];
const char* strType[] = {"Raster","Calligraphic","RASCAL"};
const char* strDirect[] = {"Omnidirectional","Bidirectional","Unidirectional"};
const char* strQuality[] = {"Off","Low","Medium","High","Undefined"};
buf.prnLine("----Light Attribute----");
buf.IncreaseIndent();
sprintf(ls,"type = %s",strType[(int)(data.type)]); buf.prnLine(ls);
sprintf(ls,"directionality = %s",strDirect[(int)(data.directionality)]);buf.prnLine(ls);
sprintf(ls,"front color (RGB) = %.2lf, %.2lf, %.2lf",
data.frontColor.red, data.frontColor.green,data.frontColor.blue ); buf.prnLine(ls);
sprintf(ls,"front intensity = %.2lf", data.frontIntensity ); buf.prnLine(ls);
sprintf(ls,"back color (RGB) = %.2lf, %.2lf, %.2lf",
data.backColor.red, data.backColor.green,data.backColor.blue ); buf.prnLine(ls);
sprintf(ls,"back intensity = %.2lf", data.backIntensity ); buf.prnLine(ls);
sprintf(ls,"normal (xyz) = %.2lf,%.2lf,%.2lf",
data.normal.x,data.normal.y,data.normal.z ); buf.prnLine(ls);
sprintf(ls,"smc = %d",data.smc); buf.prnLine(ls);
sprintf(ls,"fid = %d",data.fid); buf.prnLine(ls);
sprintf(ls,"visible at DAY = %s",
(data.flags & trpgLightAttr::trpg_Day ? "yes" : "no") ); buf.prnLine(ls);
sprintf(ls,"visible at DUSK = %s",
(data.flags & trpgLightAttr::trpg_Dusk ? "yes" : "no") ); buf.prnLine(ls);
sprintf(ls,"visible at NIGHT = %s",
(data.flags & trpgLightAttr::trpg_Night ? "yes" : "no") ); buf.prnLine(ls);
sprintf(ls,"enable directionality = %s",
(data.flags & trpgLightAttr::trpg_Directional ? "yes" : "no" )); buf.prnLine(ls);
sprintf(ls,"enable back color = %s",
(data.flags & trpgLightAttr::trpg_BackColor ? "yes" : "no" )); buf.prnLine(ls);
sprintf(ls,"horizontal lobe angle = %.2lf",data.horizontalLobeAngle); buf.prnLine(ls);
sprintf(ls,"vertical lobe angle = %.2lf",data.verticalLobeAngle); buf.prnLine(ls);
sprintf(ls,"lobe roll angle = %.2lf",data.lobeRollAngle); buf.prnLine(ls);
sprintf(ls,"lobe falloff = %.2lf",data.lobeFalloff); buf.prnLine(ls);
sprintf(ls,"ambient intensity = %.2lf",data.ambientIntensity); buf.prnLine(ls);
sprintf(ls,"reflective only = %s",
(data.flags & trpgLightAttr::trpg_Reflective ? "yes" : "no") ); buf.prnLine(ls);
sprintf(ls,"quality = %s", strQuality[(int)(data.quality)]); buf.prnLine(ls);
sprintf(ls,"significance for RASCAL lights = %.2lf",
data.rascalSignificance ); buf.prnLine(ls);
sprintf(ls,"calligraphic draw order = %d",
data.calligraphicAttr.drawOrder ); buf.prnLine(ls);
sprintf(ls,"calligraphic lights maximum defocus = %f",
data.calligraphicAttr.maxDefocus ); buf.prnLine(ls);
sprintf(ls,"calligraphic lights minimum defocus = %f",
data.calligraphicAttr.minDefocus ); buf.prnLine(ls);
sprintf(ls,"randomize intensity = %s",
strQuality[(int)(data.randomIntensity)]); buf.prnLine(ls);
sprintf(ls,"performer perspective mode = %s",
(data.flags & trpgLightAttr::trpg_Perspective ? "yes" : "no" ) ); buf.prnLine(ls);
sprintf(ls,"performer fade = %s",
(data.flags & trpgLightAttr::trpg_Fade ? "yes" : "no" ) ); buf.prnLine(ls);
sprintf(ls,"performer fog punch = %s",
(data.flags & trpgLightAttr::trpg_FogPunch ? "yes" : "no" ) ); buf.prnLine(ls);
sprintf(ls,"performer range mode enable Z buffer = %s",
(data.flags & trpgLightAttr::trpg_ZBuffer ? "yes" : "no" ) ); buf.prnLine(ls);
sprintf(ls,"performer maximum pixel size = %.2lf",
data.performerAttr.maxPixelSize ); buf.prnLine(ls);
sprintf(ls,"performer minimum pixel size = %.2lf",
data.performerAttr.minPixelSize ); buf.prnLine(ls);
sprintf(ls,"performer actual size = %.2lf",
data.performerAttr.actualSize ); buf.prnLine(ls);
sprintf(ls,"performer transparent pixel size = %.2lf",
data.performerAttr.transparentPixelSize ); buf.prnLine(ls);
sprintf(ls,"performer transparent falloff exponent = %.2lf",
data.performerAttr.transparentFallofExp ); buf.prnLine(ls);
sprintf(ls,"performer transparent scale = %.2lf",
data.performerAttr.transparentScale ); buf.prnLine(ls);
sprintf(ls,"performer transparent clamp = %.2lf",
data.performerAttr.transparentClamp ); buf.prnLine(ls);
sprintf(ls,"performer fog scale = %.2lf",
data.performerAttr.fogScale ); buf.prnLine(ls);
sprintf(ls,"animation period = %.2lf",data.animationAttr.period); buf.prnLine(ls);
sprintf(ls,"animation phase delay = %.2lf",
data.animationAttr.phaseDelay ); buf.prnLine(ls);
sprintf(ls,"animation time on = %.2lf",data.animationAttr.timeOn); buf.prnLine(ls);
sprintf(ls,"animation vector (ijk) = %.2lf, %.2lf, %.2lf",
data.animationAttr.vector.x,data.animationAttr.vector.y,
data.animationAttr.vector.z); buf.prnLine(ls);
sprintf(ls,"animation - flashing = %s",
(data.flags & trpgLightAttr::trpg_Flashing ? "yes" : "no" )); buf.prnLine(ls);
sprintf(ls,"animation - rotating = %s",
(data.flags & trpgLightAttr::trpg_Rotating ? "yes" : "no" )); buf.prnLine(ls);
sprintf(ls,"animation - counter clockwise = %s",
(data.flags & trpgLightAttr::trpg_ClockWise ? "yes" : "no" )); buf.prnLine(ls);
buf.DecreaseIndent();
buf.prnLine();
return true;
}
/* Print out light table
*/
bool trpgLightTable::Print(trpgPrintBuffer &buf) const
{
char ls[1024];
buf.prnLine("----Light Table----");
buf.IncreaseIndent();
for (int i=0;i<lightList.size();i++) {
sprintf(ls,"Light %d",i); buf.prnLine(ls);
lightList[i].Print(buf);
}
buf.DecreaseIndent();
buf.prnLine();
return true;
}
/* Print out a light node
*/
bool trpgLight::Print(trpgPrintBuffer &buf) const
{
char ls[1024];
buf.prnLine("----Light----");
buf.IncreaseIndent();
sprintf(ls,"Light Index = %d",index); buf.prnLine(ls);
sprintf(ls,"# Light Locations = %d",lightPoints.size() ); buf.prnLine(ls);
buf.DecreaseIndent();
buf.prnLine();
return true;
}
/* Print out a single range
*/
bool trpgRange::Print(trpgPrintBuffer &buf) const
{
char ls[1024];
buf.IncreaseIndent();
sprintf(ls,"category = %s, subCategory = %s",category,subCategory); buf.prnLine(ls);
sprintf(ls,"inLod = %f, outLod = %f",inLod,outLod); buf.prnLine(ls);
sprintf(ls,"priority = %d",priority); buf.prnLine(ls);
buf.DecreaseIndent();
return true;
}
/* Print out the whole range table
*/
bool trpgRangeTable::Print(trpgPrintBuffer &buf) const
{
char ls[1024];
buf.prnLine("----Range Table----");
buf.IncreaseIndent();
for (int i=0;i<rangeList.size();i++) {
sprintf(ls,"----Range %d----",i); buf.prnLine(ls);
rangeList[i].Print(buf);
}
buf.DecreaseIndent();
return true;
}

View File

@@ -0,0 +1,106 @@
/* ************************
Copyright Terrain Experts Inc.
Terrain Experts Inc (TERREX) reserves all rights to this source code
unless otherwise specified in writing by the President of TERREX.
This copyright may be updated in the future, in which case that version
supercedes this one.
-------------------
Terrex Experts Inc.
4400 East Broadway #314
Tucson, AZ 85711
info@terrex.com
Tel: (520) 323-7990
************************
*/
#ifndef trpage_print_h_
#define trpage_print_h_
#include "trpage_read.h"
/* Print Buffer for TerraPage. Subclasses of this object
are used to print out to stdout or disk (or whatever).
You won't create one of these directly, instead you'll create
something which inherits from it.
*/
TX_EXDECL class TX_CLDECL trpgPrintBuffer {
public:
trpgPrintBuffer(void);
virtual ~trpgPrintBuffer(void) { };
// Check if print buffer is valid
virtual bool isValid(void) { return true; }
// The main print function. Subclasses must fill this in.
virtual bool prnLine(char *str=NULL)=0;
// This increases the current indentation by the amount given (defaults to one)
virtual void IncreaseIndent(int amount=1);
// Decreases the current indentation by the amount given (defaults to one)
virtual void DecreaseIndent(int amount=1);
protected:
void updateIndent(void);
int curIndent;
char indentStr[200];
};
/* File print buffer for TerraPage. The file print buffer writes
debugging output to a file.
*/
TX_EXDECL class TX_CLDECL trpgFilePrintBuffer : public trpgPrintBuffer {
public:
// This class can be constructed with either a FILE pointer or a file name
trpgFilePrintBuffer(FILE *);
trpgFilePrintBuffer(char *);
~trpgFilePrintBuffer(void);
// Check if file print buffer is valid (i.e. if file was opened)
bool isValid(void) { return valid; };
// For a file printer buffer, this writes a string out to a file
bool prnLine(char *str = NULL);
protected:
bool valid;
bool isMine;
FILE *fp;
};
/* The Print Graph Parser is a scene graph parser that
prints out the scene graph as it goes. It's simpler
than the scene example in trpage_scene.cpp since it
isn't trying to build up a working scene graph.
*/
TX_EXDECL class TX_CLDECL trpgPrintGraphParser : public trpgSceneParser {
public:
trpgPrintGraphParser(trpgPrintBuffer *);
virtual ~trpgPrintGraphParser(void) { };
/* The read helper class is the callback for all the various
token (node) types. Normally we would use a number of
these, probably one per token. However, since we're just
printing we can use a switch statement instead.
*/
class ReadHelper : public trpgr_Callback {
public:
ReadHelper(trpgPrintBuffer *inBuf) {pBuf = inBuf;};
void *Parse(trpgToken,trpgReadBuffer &buf);
protected:
trpgPrintBuffer *pBuf;
};
protected:
bool StartChildren(void *);
bool EndChildren(void *);
trpgPrintBuffer *printBuf;
};
// Print utitility for while archive
#define TRPGPRN_ALL -1
#define TRPGPRN_HEADER (1<<0)
#define TRPGPRN_BODY (1<<1)
TX_CPPDECL bool trpgPrintArchive(char *filename,trpgPrintBuffer &pBuf,int flags=TRPGPRN_ALL);
TX_CPPDECL bool trpgPrintArchive(trpgr_Archive *,trpgPrintBuffer &pBuf,int flags=TRPGPRN_ALL);
#endif

View File

@@ -0,0 +1,303 @@
/* ************************
Copyright Terrain Experts Inc.
Terrain Experts Inc (TERREX) reserves all rights to this source code
unless otherwise specified in writing by the President of TERREX.
This copyright may be updated in the future, in which case that version
supercedes this one.
-------------------
Terrex Experts Inc.
4400 East Broadway #314
Tucson, AZ 85711
info@terrex.com
Tel: (520) 323-7990
************************
*/
/* trpage_range.cpp
Methods for the Range Table. Consult trpg_geom.h for details
on what this is and how it works.
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "trpage_geom.h"
#include "trpage_read.h"
/* *******************
Range Methods
*******************
*/
trpgRange::trpgRange(void)
{
category = NULL;
subCategory = NULL;
Reset();
}
trpgRange::~trpgRange(void)
{
Reset();
}
trpgRange::trpgRange(const trpgRange &in)
{
*this = in;
}
void trpgRange::Reset(void)
{
if (category)
delete [] category;
category = NULL;
if (subCategory)
delete [] subCategory;
subCategory = NULL;
inLod = outLod = 0.0;
priority = 0;
}
void trpgRange::SetCategory(char *cat,char *subCat)
{
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);
}
}
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;
}
void trpgRange::SetLodInfo(double in,double out)
{
inLod = in;
outLod = out;
}
void trpgRange::GetLodInfo(double &in,double &out) const
{
in = inLod;
out = outLod;
}
void trpgRange::SetPriority(int prior)
{
priority = prior;
}
void trpgRange::GetPriority(int &prior) const
{
prior = priority;
}
trpgRange & trpgRange::operator = (const trpgRange &other)
{
Reset();
inLod = other.inLod;
outLod = other.outLod;
SetCategory(other.category,other.subCategory);
priority = other.priority;
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 (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;
}
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 : ""));
buf.End();
return true;
}
bool trpgRange::Read(trpgReadBuffer &buf)
{
char catStr[1024],subStr[1024];
Reset();
valid = false;
try {
buf.Get(inLod);
buf.Get(outLod);
buf.Get(priority);
buf.Get(catStr,1024);
buf.Get(subStr,1024);
SetCategory(catStr,subStr);
valid = true;
}
catch (...) {
return false;
}
return isValid();
}
/* ***************
Range Table methods
***************
*/
trpgRangeTable::trpgRangeTable(void)
{
valid = true;
}
trpgRangeTable::~trpgRangeTable(void)
{
// vector cleans up itself
}
void trpgRangeTable::Reset(void)
{
rangeList.resize(0);
valid = true;
}
bool trpgRangeTable::GetRange(int id,trpgRange &ret) const
{
if (!isValid())
return false;
if (id < 0 || id >= rangeList.size())
return false;
ret = rangeList[id];
return true;
}
bool trpgRangeTable::SetRange(int id,trpgRange &inRange)
{
if (!isValid())
return false;
if (id < 0 || id >= rangeList.size())
return false;
rangeList[id] = inRange;
return true;
}
int trpgRangeTable::AddRange(trpgRange &range)
{
rangeList.push_back(range);
return rangeList.size()-1;
}
int trpgRangeTable::FindAddRange(trpgRange &range)
{
for (int i=0;i<rangeList.size();i++) {
if (range == rangeList[i])
return i;
}
return AddRange(range);
}
bool trpgRangeTable::Write(trpgWriteBuffer &buf)
{
if (!isValid())
return false;
buf.Begin(TRPGRANGETABLE);
buf.Add((int32)rangeList.size());
for (int i=0;i<rangeList.size();i++) {
trpgRange &range = rangeList[i];
range.Write(buf);
}
buf.End();
return true;
}
bool trpgRangeTable::Read(trpgReadBuffer &buf)
{
int32 numRange;
valid = false;
try {
buf.Get(numRange);
if (numRange < 0) throw 1;
for (int i=0;i<numRange;i++) {
trpgRange range;
if (!range.Read(buf)) throw 1;
rangeList.push_back(range);
}
valid = true;
}
catch (...) {
return false;
}
return isValid();
}
trpgRangeTable & trpgRangeTable::operator = (const trpgRangeTable &inTab)
{
Reset();
for (int i=0;i<inTab.rangeList.size();i++)
rangeList.push_back(rangeList[i]);
return *this;
}