From Terrex and Andrew Sampsom and Don Tidrow and Robert Osfield,

email comments from Andew Sampson,

"I've contacted Terrex, and obtained the 2.2 version
of their trpage library.  The library included a
fork of OSG 0.9.8's txp plugin, modified to load 2.1+
txp DBs.

I've done the work of incorporating the changes made
to OSG's txp plugin since 0.9.8 into Terrex's fork.
The forked version is now up-to-date with the changes
made to OSG 0.9.9 and 1.0.

Terrex made a lot of changes (especially differences
in whitespace), so the diff between the forked version

and OSG 1.0's txp plugin is yucky.  I did my best, but

keep in mind that this is the result of a 4-way merge
(kinda... terrex-0.9.8, stock-0.9.8, stock-0.9.9,
stock-1.0).

I really want to see this forked version merged back
into the main OSG branch.  The new features offered by

this version of the plugin (2.1+ support, variable
LOD support, bug fixes) are worth the trouble."

--

Don Tidrow then took this code and added his work.

--

Robert Osfield then fixed all the warnings that abound in the trpage code base.
This commit is contained in:
Robert Osfield
2006-06-27 10:07:42 +00:00
parent 240fc9ebee
commit 261f4a3b1c
50 changed files with 11399 additions and 8113 deletions

View File

@@ -14,9 +14,9 @@
*/
/* trpage_range.cpp
Methods for the Range Table. Consult trpg_geom.h for details
on what this is and how it works.
*/
Methods for the Range Table. Consult trpg_geom.h for details
on what this is and how it works.
*/
#include <stdlib.h>
#include <stdio.h>
@@ -26,290 +26,328 @@
#include <trpage_read.h>
/* *******************
Range Methods
Range Methods
*******************
*/
trpgRange::trpgRange(void)
{
category = NULL;
subCategory = NULL;
Reset();
category = NULL;
subCategory = NULL;
Reset();
}
trpgRange::~trpgRange(void)
{
Reset();
Reset();
}
trpgRange::trpgRange(const trpgRange &in):
trpgReadWriteable(in)
{
category = NULL;
subCategory = NULL;
*this = in;
category = NULL;
subCategory = NULL;
*this = in;
}
void trpgRange::Reset(void)
{
errMess[0] = '\0';
if (category)
delete [] category;
category = NULL;
if (subCategory)
delete [] subCategory;
subCategory = NULL;
errMess[0] = '\0';
if (category)
delete [] category;
category = NULL;
if (subCategory)
delete [] subCategory;
subCategory = NULL;
inLod = outLod = 0.0;
priority = 0;
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;
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;
}
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 : ""));
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);
valid = true;
}
try {
buf.Get(inLod);
buf.Get(outLod);
buf.Get(priority);
buf.Get(catStr,1024);
buf.Get(subStr,1024);
SetCategory(catStr,subStr);
catch (...) {
return false;
}
// Read the handle if we can..
try {
if(!buf.Get((int32 &)handle)) {
handle = -1;
}
}
catch (...) {
handle = -1;
}
valid = true;
}
return isValid();
catch (...) {
return false;
}
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)
{
rangeList.resize(0);
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 >= (int)rangeList.size())
return false;
if (id < 0)// || id >= rangeList.size())
return false;
ret = rangeList[id];
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 >= (int)rangeList.size())
return false;
if (id < 0)// || id >= rangeList.size())
return false;
rangeList[id] = inRange;
rangeMap[id] = inRange;
return true;
return true;
}
int trpgRangeTable::AddRange(trpgRange &range)
{
rangeList.push_back(range);
int handle = range.GetHandle();
if(handle==-1) {
handle = rangeMap.size();
}
rangeMap[handle] = range;
return handle;
return rangeList.size()-1;
}
int trpgRangeTable::FindAddRange(trpgRange &range)
{
for (unsigned int i=0;i<rangeList.size();i++) {
if (range == rangeList[i])
return i;
}
RangeMapType::iterator itr = rangeMap.begin();
for ( ; itr != rangeMap.end( ); itr++) {
if(itr->second==range)
return itr->first;
}
return AddRange(range);
#if 0
for (int i=0;i<rangeList.size();i++) {
if (range == rangeList[i])
return i;
}
#endif
return AddRange(range);
}
bool trpgRangeTable::Write(trpgWriteBuffer &buf)
{
if (!isValid())
return false;
if (!isValid())
return false;
buf.Begin(TRPGRANGETABLE);
buf.Add((int32)rangeList.size());
buf.Begin(TRPGRANGETABLE);
buf.Add((int32)rangeMap.size());
for (unsigned int i=0;i<rangeList.size();i++) {
trpgRange &range = rangeList[i];
range.Write(buf);
}
RangeMapType::iterator itr = rangeMap.begin();
for ( ; itr != rangeMap.end( ); itr++) {
trpgRange &range = itr->second;
range.Write(buf);
}
buf.End();
buf.End();
return true;
return true;
}
bool trpgRangeTable::Read(trpgReadBuffer &buf)
{
int32 numRange;
trpgToken tok;
int32 len;
valid = false;
int32 numRange;
trpgToken tok;
int32 len;
valid = false;
try {
buf.Get(numRange);
if (numRange < 0) throw 1;
for (int i=0;i<numRange;i++) {
// Read in the individual range
buf.GetToken(tok,len);
if (tok != TRPG_RANGE) throw 1;
buf.PushLimit(len);
trpgRange range;
bool status = range.Read(buf);
buf.PopLimit();
if (!status) throw 1;
rangeList.push_back(range);
}
try {
buf.Get(numRange);
if (numRange < 0) throw 1;
for (int i=0;i<numRange;i++) {
// Read in the individual range
buf.GetToken(tok,len);
if (tok != TRPG_RANGE) throw 1;
buf.PushLimit(len);
trpgRange range;
bool status = range.Read(buf);
buf.PopLimit();
if (!status) throw 1;
AddRange(range);
}
valid = true;
}
valid = true;
}
catch (...) {
return false;
}
catch (...) {
return false;
}
return isValid();
return isValid();
}
trpgRangeTable & trpgRangeTable::operator = (const trpgRangeTable &inTab)
{
Reset();
Reset();
RangeMapType::const_iterator itr = inTab.rangeMap.begin();
for ( ; itr != inTab.rangeMap.end( ); itr++)
rangeMap[itr->first] = itr->second;
for (unsigned int i=0;i<inTab.rangeList.size();i++)
rangeList.push_back(inTab.rangeList[i]);
return *this;
#if 0
for (int i=0;i<inTab.rangeList.size();i++)
rangeList.push_back(inTab.rangeList[i]);
#endif
return *this;
}