Fixes to TXP loader for Cygwin and Ming builds.

This commit is contained in:
Robert Osfield
2002-02-10 10:42:55 +00:00
parent 634ef7e3a6
commit 86620891af
6 changed files with 256 additions and 240 deletions

View File

@@ -1,23 +1,26 @@
#!smake
SHELL = /bin/sh
OSGHOME = $(shell cd ../../..; pwd)
include $(OSGHOME)/Make/makedefs
C++FILES = \
ReaderWriterTXP.cpp\
TrPageArchive.cpp\
TrPageParser.cpp\
trpage_basic.cpp\
trpage_geom.cpp\
trpage_header.cpp\
trpage_tile.cpp\
trpage_readbuf.cpp\
trpage_rarchive.cpp\
trpage_writebuf.cpp\
trpage_warchive.cpp\
trpage_parse.cpp\
trpage_nodes.cpp\
trpage_model.cpp\
trpage_material.cpp\
ReaderWriterTXP.cpp\
TrPageArchive.cpp\
TrPageParser.cpp\
trpage_basic.cpp\
trpage_geom.cpp\
trpage_header.cpp\
trpage_tile.cpp\
trpage_readbuf.cpp\
trpage_rarchive.cpp\
trpage_writebuf.cpp\
trpage_warchive.cpp\
trpage_parse.cpp\
trpage_nodes.cpp\
trpage_model.cpp\
trpage_material.cpp\
trpage_swap.cpp
TARGET_BASENAME = osgdb_txp

View File

@@ -28,7 +28,7 @@
#include "trpage_geom.h"
#include "trpage_read.h"
#if defined(_WIN32)
#if defined(_WIN32) && !defined(__GNUC__)
#define ALIGNMENT_WORKAROUND false
#else
#define ALIGNMENT_WORKAROUND true

View File

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

View File

@@ -19,137 +19,137 @@
#define _txpage_read_h_
/* txpage_read.h
Classes used to represent read objects for paging files.
*/
Classes used to represent read objects for paging files.
*/
#include "trpage_sys.h"
#include "trpage_geom.h"
/* Callback base class
Called when a given token is found.
{group:Archive Reading}
*/
Called when a given token is found.
{group:Archive Reading}
*/
TX_EXDECL class TX_CLDECL trpgr_Callback {
public:
virtual ~trpgr_Callback(void) { };
virtual void *Parse(trpgToken,trpgReadBuffer &) { return (void *)1; };
virtual ~trpgr_Callback(void) { };
virtual void *Parse(trpgToken,trpgReadBuffer &) { return (void *)1; };
};
/* Paging Token
Stores callback info associated with a given token.
{group:Archive Reading}
*/
Stores callback info associated with a given token.
{group:Archive Reading}
*/
TX_EXDECL class TX_CLDECL trpgr_Token {
public:
trpgr_Token(void);
trpgr_Token(int,trpgr_Callback *,bool destroy=true);
~trpgr_Token(void);
void init(int,trpgr_Callback *,bool destroy=true);
int Token; // Constant token value
trpgr_Callback *cb; // Callback when we hit this token
bool destroy; // Should we call delete on the callback or not
void Destruct(void); // Not quite like delete
trpgr_Token(void);
trpgr_Token(int,trpgr_Callback *,bool destroy=true);
~trpgr_Token(void);
void init(int,trpgr_Callback *,bool destroy=true);
int Token; // Constant token value
trpgr_Callback *cb; // Callback when we hit this token
bool destroy; // Should we call delete on the callback or not
void Destruct(void); // Not quite like delete
};
/* Parse class for paging data structures.
This executes callbacks
{group:Archive Reading}
*/
This executes callbacks
{group:Archive Reading}
*/
TX_EXDECL class TX_CLDECL trpgr_Parser {
public:
trpgr_Parser(void);
virtual ~trpgr_Parser(void);
bool isValid(void) const;
trpgr_Parser(void);
virtual ~trpgr_Parser(void);
bool isValid(void) const;
// Add and remove token callbacks
virtual void AddCallback(trpgToken,trpgr_Callback *,bool destroy = true);
virtual void AddCallback(trpgToken,trpgReadWriteable *);
virtual void RemoveCallback(trpgToken);
virtual void SetDefaultCallback(trpgr_Callback *,bool destroy = true);
// Parse a read buffer
virtual bool Parse(trpgReadBuffer &);
virtual bool TokenIsValid(trpgToken); // Check token validity
// Add and remove token callbacks
virtual void AddCallback(trpgToken,trpgr_Callback *,bool destroy = true);
virtual void AddCallback(trpgToken,trpgReadWriteable *);
virtual void RemoveCallback(trpgToken);
virtual void SetDefaultCallback(trpgr_Callback *,bool destroy = true);
// Parse a read buffer
virtual bool Parse(trpgReadBuffer &);
virtual bool TokenIsValid(trpgToken); // Check token validity
protected:
void *lastObject;
void *lastObject;
private:
// Note: Just how slow is a map<> anyway?
// This usage is self-contained and could be replaced with an array
#if defined(_WIN32)
// Note: Just how slow is a map<> anyway?
// This usage is self-contained and could be replaced with an array
#if defined(_WIN32) && !defined(__GNUC__)
typedef map<trpgToken,trpgr_Token> tok_map;
#else
typedef map<trpgToken,trpgr_Token,less<trpgToken> > tok_map;
#endif
tok_map tokenMap;
trpgr_Token defCb; // Call this when no others are called
tok_map tokenMap;
trpgr_Token defCb; // Call this when no others are called
};
/* Paging Archive (read version)
This just reads the first bits of the file (and the header)
and lets you parse from there.
{group:Archive Reading}
*/
This just reads the first bits of the file (and the header)
and lets you parse from there.
{group:Archive Reading}
*/
TX_EXDECL class TX_CLDECL trpgr_Archive : public trpgCheckable {
public:
trpgr_Archive(void);
virtual ~trpgr_Archive(void);
trpgr_Archive(void);
virtual ~trpgr_Archive(void);
virtual void SetDirectory(const char *);
virtual bool OpenFile(const char *); // Open File
virtual void CloseFile(void);
virtual bool ReadHeader(void); // Read header (materials, tile table. etc..)
virtual bool ReadTile(uint32 x, uint32 y, uint32 lod,trpgMemReadBuffer &);
virtual void SetDirectory(const char *);
virtual bool OpenFile(const char *); // Open File
virtual void CloseFile(void);
virtual bool ReadHeader(void); // Read header (materials, tile table. etc..)
virtual bool ReadTile(uint32 x, uint32 y, uint32 lod,trpgMemReadBuffer &);
// Get access to header info
virtual const trpgHeader *GetHeader(void) const;
virtual const trpgMatTable *GetMaterialTable(void) const;
virtual const trpgTexTable *GetTexTable(void) const;
virtual const trpgModelTable *GetModelTable(void) const;
virtual const trpgTileTable *GetTileTable(void) const;
// Get access to header info
virtual const trpgHeader *GetHeader(void) const;
virtual const trpgMatTable *GetMaterialTable(void) const;
virtual const trpgTexTable *GetTexTable(void) const;
virtual const trpgModelTable *GetModelTable(void) const;
virtual const trpgTileTable *GetTileTable(void) const;
// Utility routine to calculate the MBR of a given point
virtual bool trpgGetTileMBR(uint32 x,uint32 y,uint32 lod,
trpg2dPoint &ll,trpg2dPoint &ur) const;
// Utility routine to calculate the MBR of a given point
virtual bool trpgGetTileMBR(uint32 x,uint32 y,uint32 lod,
trpg2dPoint &ll,trpg2dPoint &ur) const;
trpgEndian GetEndian() const;
char* getDir(){return dir;};
trpgEndian GetEndian() const;
char* getDir(){return dir;};
protected:
bool headerRead;
trpgEndian ness;
FILE *fp;
int fid;
// Header info
char dir[1024];
trpgHeader header;
trpgMatTable materialTable;
trpgTexTable texTable;
trpgModelTable modelTable;
trpgTileTable tileTable;
bool headerRead;
trpgEndian ness;
FILE *fp;
int fid;
// Header info
char dir[1024];
trpgHeader header;
trpgMatTable materialTable;
trpgTexTable texTable;
trpgModelTable modelTable;
trpgTileTable tileTable;
};
class trpgSceneHelperPush;
class trpgSceneHelperPop;
class trpgSceneHelperDefault;
/* Scene Parser
This class assists in parsing a scene graph structure (tiles and models).
To use it, do an archive ReadTile and pass the resulting Read Buffer to this
parser.
{group:Archive Reading}
*/
This class assists in parsing a scene graph structure (tiles and models).
To use it, do an archive ReadTile and pass the resulting Read Buffer to this
parser.
{group:Archive Reading}
*/
TX_EXDECL class TX_CLDECL trpgSceneParser : public trpgr_Parser {
friend class trpgSceneHelperPush;
friend class trpgSceneHelperPop;
friend class trpgSceneHelperDefault;
friend class trpgSceneHelperPush;
friend class trpgSceneHelperPop;
friend class trpgSceneHelperDefault;
public:
trpgSceneParser(void);
virtual ~trpgSceneParser(void);
trpgSceneParser(void);
virtual ~trpgSceneParser(void);
protected:
// Start defining children for the given object
virtual bool StartChildren(void *) { return true;};
virtual bool EndChildren(void *) { return true;};
// Start defining children for the given object
virtual bool StartChildren(void *) { return true;};
virtual bool EndChildren(void *) { return true;};
// List of objects whose children we're working on
vector<void *> parents;
// List of objects whose children we're working on
vector<void *> parents;
};
#endif

View File

@@ -19,221 +19,221 @@
#define _txpage_scene_h_
/* trpage_scene.h
Scene Graph definition.
This is a small scene graph we use for testing.
It's not intended to replace the scene graph you may already be using.
You do not need to translate from this scene graph structure to your own,
at run-time. Instead, use this file and trpage_scene.cpp as a guideline
for how to read TerraPage format into your own scene graph.
Scene Graph definition.
This is a small scene graph we use for testing.
It's not intended to replace the scene graph you may already be using.
You do not need to translate from this scene graph structure to your own,
at run-time. Instead, use this file and trpage_scene.cpp as a guideline
for how to read TerraPage format into your own scene graph.
*/
#include "trpage_geom.h"
/*
{group:Demonstration Scene Graph}
*/
{group:Demonstration Scene Graph}
*/
TX_EXDECL class TX_CLDECL trpgMBR {
public:
trpgMBR(void);
~trpgMBR(void) { };
bool isValid() const;
void Reset();
void AddPoint(const trpg3dPoint &);
void AddPoint(double,double,double);
void GetMBR(trpg3dPoint &ll,trpg3dPoint &ur) const;
trpg3dPoint GetLL() const;
trpg3dPoint GetUR() 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() const;
void Reset();
void AddPoint(const trpg3dPoint &);
void AddPoint(double,double,double);
void GetMBR(trpg3dPoint &ll,trpg3dPoint &ur) const;
trpg3dPoint GetLL() const;
trpg3dPoint GetUR() 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() { };
virtual bool isGroupType() = 0;
virtual int GetType() { return type; }
virtual trpgMBR GetMBR() const { return trpgMBR(); }
virtual ~trpgReadNode() { };
virtual bool isGroupType() = 0;
virtual int GetType() { return type; }
virtual trpgMBR GetMBR() 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 AddChild(trpgReadNode *);
bool isGroupType() { return true; }
int GetNumChildren() { return children.size(); }
trpgReadNode *GetChild(int i) { return children[i]; }
trpgMBR GetMBR() const;
void unRefChild(int i);
void unRefChildren();
virtual ~trpgReadGroupBase();
void AddChild(trpgReadNode *);
bool isGroupType() { return true; }
int GetNumChildren() { return children.size(); }
trpgReadNode *GetChild(int i) { return children[i]; }
trpgMBR GetMBR() const;
void unRefChild(int i);
void unRefChildren();
protected:
trpgMBR mbr;
void DeleteChildren();
vector<trpgReadNode *> children;
trpgMBR mbr;
void DeleteChildren();
vector<trpgReadNode *> children;
};
// Read Geometry
// The leaf for this scene graph
// {group:Demonstration Scene Graph}
// {group:Demonstration Scene Graph}
TX_EXDECL class TX_CLDECL trpgReadGeometry : public trpgReadNode {
public:
trpgReadGeometry() { type = TRPG_GEOMETRY; }
~trpgReadGeometry() { };
bool isGroupType() { return false; }
trpgGeometry *GetData() { return &data; }
trpgMBR GetMBR() const;
trpgReadGeometry() { type = TRPG_GEOMETRY; }
~trpgReadGeometry() { };
bool isGroupType() { return false; }
trpgGeometry *GetData() { return &data; }
trpgMBR GetMBR() 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() { type = TRPGTILEHEADER; }
~trpgReadTileHeader() { };
bool isGroupType() { return false; }
trpgTileHeader *GetData() { return &data; }
trpgMBR GetMBR() const { trpgMBR mbr; return mbr; };
trpgReadTileHeader() { type = TRPGTILEHEADER; }
~trpgReadTileHeader() { };
bool isGroupType() { return false; }
trpgTileHeader *GetData() { return &data; }
trpgMBR GetMBR() 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() { type = TRPG_GROUP; }
~trpgReadGroup() { };
trpgGroup *GetData() { return &data; }
trpgReadGroup() { type = TRPG_GROUP; }
~trpgReadGroup() { };
trpgGroup *GetData() { 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() { type = TRPG_ATTACH; }
~trpgReadAttach() { };
trpgAttach *GetData() { return &data; }
trpgReadAttach() { type = TRPG_ATTACH; }
~trpgReadAttach() { };
trpgAttach *GetData() { return &data; }
protected:
trpgAttach data;
trpgAttach data;
};
// Read billboard
// {group:Demonstration Scene Graph}
// {group:Demonstration Scene Graph}
TX_EXDECL class TX_CLDECL trpgReadBillboard : public trpgReadGroupBase {
public:
trpgReadBillboard() { type = TRPG_BILLBOARD; }
~trpgReadBillboard() { };
trpgBillboard *GetData() { return &data; }
trpgReadBillboard() { type = TRPG_BILLBOARD; }
~trpgReadBillboard() { };
trpgBillboard *GetData() { 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() { type = TRPG_LOD; }
~trpgReadLod() { };
trpgLod *GetData() { return &data; }
trpgReadLod() { type = TRPG_LOD; }
~trpgReadLod() { };
trpgLod *GetData() { 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() { type = TRPG_LAYER; }
~trpgReadLayer() { };
trpgLayer *GetData() { return &data; }
trpgReadLayer() { type = TRPG_LAYER; }
~trpgReadLayer() { };
trpgLayer *GetData() { 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() { type = TRPG_TRANSFORM; }
~trpgReadTransform() { };
trpgTransform *GetData() { return &data; }
trpgReadTransform() { type = TRPG_TRANSFORM; }
~trpgReadTransform() { };
trpgTransform *GetData() { 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() { type = TRPG_MODELREF; }
~trpgReadModelRef() { };
trpgModelRef *GetData() { return &data; }
trpgReadModelRef() { type = TRPG_MODELREF; }
~trpgReadModelRef() { };
trpgModelRef *GetData() { 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 map<int,trpgReadGroupBase *> GroupMap;
#if defined(_WIN32) && !defined(__GNUC__)
typedef map<int,trpgReadGroupBase *> GroupMap;
#else
typedef map<int,trpgReadGroupBase *,less<int> > GroupMap;
typedef map<int,trpgReadGroupBase *,less<int> > GroupMap;
#endif
trpgSceneGraphParser();
~trpgSceneGraphParser() { };
// Call this instead of Parse()
// Deleting it is your responsibility
trpgReadNode *ParseScene(trpgReadBuffer &,GroupMap &);
trpgReadGroupBase *GetCurrTop(); // Get the current parent object
trpgReadTileHeader *GetTileHeaderRef();
trpgSceneGraphParser();
~trpgSceneGraphParser() { };
// Call this instead of Parse()
// Deleting it is your responsibility
trpgReadNode *ParseScene(trpgReadBuffer &,GroupMap &);
trpgReadGroupBase *GetCurrTop(); // Get the current parent object
trpgReadTileHeader *GetTileHeaderRef();
// For use by the helpers only
GroupMap *GetGroupMap();
// For use by the helpers only
GroupMap *GetGroupMap();
protected:
bool StartChildren(void *);
bool EndChildren(void *);
trpgReadNode *currTop; // Current parent group
trpgReadNode *top; // Top of everything
GroupMap *gmap;
trpgReadTileHeader tileHead; // Tile header gets read into here
bool StartChildren(void *);
bool EndChildren(void *);
trpgReadNode *currTop; // Current parent group
trpgReadNode *top; // Top of everything
GroupMap *gmap;
trpgReadTileHeader tileHead; // Tile header gets read into here
};
/* Test Archive
Utility function that loads and tests all tiles.
The only reason you'd want to call this is to test a TerraPage archive
you'd written.
*/
// {group:Demonstration Scene Graph}
Utility function that loads and tests all tiles.
The only reason you'd want to call this is to test a TerraPage archive
you'd written.
*/
// {group:Demonstration Scene Graph}
TX_CPPDECL bool trpgTestArchive(trpgr_Archive &);
#endif

View File

@@ -15,18 +15,18 @@
*/
/* trpage_sys.h
System specific declarations.
*/
System specific declarations.
*/
#ifndef trpage_sys_h_
#define trpage_sys_h_
#if defined(_WIN32)
/* *********************
System Specific Section.
This is currently set up for win32.
*********************
*/
#if defined(_WIN32) && !defined(__CYGWIN__)
/* *********************
System Specific Section.
This is currently set up for win32.
*********************
*/
#include <windows.h>
@@ -39,10 +39,19 @@
#define TRPGDELETEFILE(file) DeleteFile((file))
#ifndef int64
// 64 bit long value. Need this for really big files.
typedef __int64 int64;
// 64 bit long value. Need this for really big files.
// #ifdef __CYGWIN__
// typedef long long int64;
// #else
typedef __int64 int64;
// #endif
#endif
#ifdef __MINGW32__
#include <stdio.h>
#endif
#else // Unix
#include <stdio.h>
@@ -76,6 +85,10 @@ typedef int64_t int64;
#elif defined(__ghs__) && defined(__LL_Is_64)
typedef long long int64;
#elif defined(__CYGWIN__)
typedef long long int64;
#include <windows.h>
#else
typedef int int64; // DON'T KNOW WHAT TO DO
#endif