Moved the include/osgTXP back into src/osgPlugins/txp as a seperate include directory is no longer required.
Removed the osgtxp demo as it is no longer required.
This commit is contained in:
@@ -1,27 +0,0 @@
|
||||
//C++ header - Open Scene Graph - Copyright (C) 1998-2002 Robert Osfield
|
||||
//Distributed under the terms of the GNU Library General Public License (LGPL)
|
||||
//as published by the Free Software Foundation.
|
||||
|
||||
#ifndef OSGTXP_EXPORT_
|
||||
#define OSGTXP_EXPORT_ 1
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#pragma warning( disable : 4244 )
|
||||
#pragma warning( disable : 4251 )
|
||||
#pragma warning( disable : 4267 )
|
||||
#pragma warning( disable : 4275 )
|
||||
#pragma warning( disable : 4290 )
|
||||
#pragma warning( disable : 4786 )
|
||||
#endif
|
||||
|
||||
#if defined(_MSC_VER) || defined(__CYGWIN__) || defined(__MINGW32__) || defined( __BCPLUSPLUS__) || defined( __MWERKS__)
|
||||
# ifdef OSGTXP_LIBRARY
|
||||
# define OSGTXP_EXPORT __declspec(dllexport)
|
||||
# else
|
||||
# define OSGTXP_EXPORT __declspec(dllimport)
|
||||
# endif /* OSGTXP_LIBRARY */
|
||||
#else
|
||||
# define OSGTXP_EXPORT
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,105 +0,0 @@
|
||||
/* **************************************************************************
|
||||
* OpenSceneGraph loader for Terrapage format database
|
||||
* by Boris Bralo 2002
|
||||
*
|
||||
* based on/modifed sgl (Scene Graph Library) loader by Bryan Walsh
|
||||
*
|
||||
* This loader is based on/modified from Terrain Experts Performer Loader,
|
||||
* and was ported to SGL by Bryan Walsh / bryanw at earthlink dot net
|
||||
*
|
||||
* That loader is redistributed under the terms listed on Terrain Experts
|
||||
* website (www.terrex.com/www/pages/technology/technologypage.htm)
|
||||
*
|
||||
* "TerraPage is provided as an Open Source format for use by anyone...
|
||||
* We supply the TerraPage C++ source code free of charge. Anyone
|
||||
* can use it and redistribute it as needed (including our competitors).
|
||||
* We do, however, ask that you keep the TERREX copyrights intact."
|
||||
*
|
||||
* Copyright Terrain Experts Inc. 1999.
|
||||
* All Rights Reserved.
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef _TRPAGEARCHIVE_H_
|
||||
#define _TRPAGEARCHIVE_H_
|
||||
|
||||
|
||||
|
||||
#include <osgTXP/trpage_sys.h>
|
||||
#include <osgTXP/trpage_read.h>
|
||||
#include <osgTXP/trpage_managers.h>
|
||||
|
||||
#include <osgTXP/TrPageParser.h>
|
||||
|
||||
#include <osgTXP/Export.h>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <memory> // for auto_ptr
|
||||
|
||||
namespace txp
|
||||
{
|
||||
/// main class for loading terrapage archives
|
||||
class OSGTXP_EXPORT TrPageArchive : public trpgr_Archive
|
||||
{
|
||||
public:
|
||||
TrPageArchive();
|
||||
|
||||
~TrPageArchive();
|
||||
|
||||
// open archive file
|
||||
virtual bool OpenFile(const char* file);
|
||||
|
||||
/// Load and create textures and materials
|
||||
void LoadMaterials();
|
||||
|
||||
// Load and create models, usualy OpenFlight models
|
||||
bool LoadModels();
|
||||
|
||||
/** Load a TXP tile and
|
||||
@param x Tile location input - x dimension.
|
||||
@param y Tile location input - y dimension.
|
||||
@param lod Tile LOD level input.
|
||||
@return The parent ID of this tile to let you hook it into the scene
|
||||
graph.
|
||||
|
||||
x, y dimensions are not coordinates, they are tile numbers. For example,
|
||||
for combination 10, 1 and lod number 2 terrapage opens file tile_10_1_2.tpt
|
||||
in directory of the archive. This is THE method which shoud be used once
|
||||
paging is implemented.
|
||||
|
||||
*/
|
||||
osg::Group *LoadTile(int x,int y,int lod,int &parent);
|
||||
|
||||
/* This version is used during the paging and takes a Managed Tile
|
||||
instead of location. These are used to keep track of what to
|
||||
page in and out.
|
||||
*/
|
||||
osg::Group *LoadTile(osg::Group *rootNode,trpgPageManager *,trpgManagedTile *,osg::Group **parentNode=NULL);
|
||||
|
||||
/* Unload Tile
|
||||
This is called to get rid of a tile from the scenegraph
|
||||
*/
|
||||
bool UnLoadTile(trpgPageManager *,trpgManagedTile *);
|
||||
|
||||
/** Load all the tiles . No paging.
|
||||
@return The parent of the complete scene graph.
|
||||
*/
|
||||
osg::Group *LoadAllTiles();
|
||||
|
||||
// Calculate the center
|
||||
void GetCenter(osg::Vec3 ¢er);
|
||||
|
||||
protected:
|
||||
/// This class does most of the actual parsing.
|
||||
std::auto_ptr<TrPageParser> parse;
|
||||
// Texture, material, and model lists.
|
||||
std::vector< osg::ref_ptr<osg::Texture2D> > m_textures;
|
||||
std::vector< osg::ref_ptr<osg::StateSet> > m_gstates;
|
||||
std::vector< osg::ref_ptr<osg::Node> > m_models;
|
||||
std::string m_alternate_path;
|
||||
trpgMemReadBuffer buf;
|
||||
};
|
||||
}; // end namespace
|
||||
|
||||
#endif
|
||||
@@ -1,170 +0,0 @@
|
||||
/* **************************************************************************
|
||||
* OpenSceneGraph loader for Terrapage format database
|
||||
* by Boris Bralo 2002
|
||||
*
|
||||
* based on/modifed sgl (Scene Graph Library) loader by Bryan Walsh
|
||||
*
|
||||
* This loader is based on/modified from Terrain Experts Performer Loader,
|
||||
* and was ported to SGL by Bryan Walsh / bryanw at earthlink dot net
|
||||
*
|
||||
* That loader is redistributed under the terms listed on Terrain Experts
|
||||
* website (www.terrex.com/www/pages/technology/technologypage.htm)
|
||||
*
|
||||
* "TerraPage is provided as an Open Source format for use by anyone...
|
||||
* We supply the TerraPage C++ source code free of charge. Anyone
|
||||
* can use it and redistribute it as needed (including our competitors).
|
||||
* We do, however, ask that you keep the TERREX copyrights intact."
|
||||
*
|
||||
* Copyright Terrain Experts Inc. 1999.
|
||||
* All Rights Reserved.
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef _TRPAGEPARSER_H_
|
||||
#define _TRPAGEPARSER_H_
|
||||
|
||||
#include <osg/Vec3>
|
||||
#include <osg/Vec2>
|
||||
#include <osg/StateSet>
|
||||
#include <osg/ref_ptr>
|
||||
#include <osg/Texture2D>
|
||||
#include <osg/Group>
|
||||
#include <osg/StateSet>
|
||||
#include <vector>
|
||||
#include <osgTXP/trpage_read.h>
|
||||
|
||||
#include <osgTXP/Export.h>
|
||||
|
||||
namespace txp
|
||||
{
|
||||
class TrPageArchive;
|
||||
|
||||
// Group ID Info
|
||||
// Used to keep track of which groups are which IDs for parents
|
||||
typedef struct {
|
||||
osg::Group *group;
|
||||
int id;
|
||||
} GroupIDInfo;
|
||||
|
||||
class OSGTXP_EXPORT TrPageParser : public trpgSceneParser
|
||||
{
|
||||
public:
|
||||
TrPageParser(TrPageArchive* parent);
|
||||
~TrPageParser();
|
||||
|
||||
osg::Group *ParseScene(trpgReadBuffer & buf,
|
||||
std::vector<osg::ref_ptr<osg::StateSet> > & materials_,
|
||||
std::vector<osg::ref_ptr<osg::Node> > & node );
|
||||
|
||||
// Return the parent of a recently parsed tile
|
||||
int GetParentID() { return parentID; }
|
||||
void SetParentID(int id) { parentID = id; }
|
||||
// Return a reference to the tile header (after a tile has been read)
|
||||
trpgTileHeader *GetTileHeaderRef();
|
||||
|
||||
// Return the current top node (used during parsing)
|
||||
osg::Group *GetCurrTop();
|
||||
|
||||
// Return the current material list (passed in to ParseScene())
|
||||
std::vector<osg::ref_ptr<osg::StateSet> >* GetMaterials() { return materials; }
|
||||
// new to TerraPage 2.0 - local materials
|
||||
std::vector<osg::ref_ptr<osg::StateSet> >* GetLocalMaterials() { return &local_materials; }
|
||||
std::vector<osg::ref_ptr<osg::Node> >* GetModels() { return models; }
|
||||
|
||||
// Add the Group to the current group list
|
||||
bool AddToGroupList(int id,osg::Group *);
|
||||
|
||||
// Return the group list
|
||||
std::vector< osg::Group *> *GetGroupList() { return &groupList; }
|
||||
|
||||
/// TXP 2.0 - local materials
|
||||
void LoadLocalMaterials();
|
||||
|
||||
void SetMaxGroupID(int maxGroupID);
|
||||
|
||||
protected:
|
||||
bool StartChildren(void *);
|
||||
bool EndChildren(void *);
|
||||
|
||||
protected:
|
||||
TrPageArchive* parent_;
|
||||
osg::Group *currTop; // Current parent group
|
||||
osg::Group *top; // Top group
|
||||
trpgTileHeader tileHead; // Dump tile header here
|
||||
// If there was an attach node, this is
|
||||
// the tile's parent ID. -1 otherwise
|
||||
int parentID;
|
||||
std::vector<osg::ref_ptr<osg::StateSet> >* materials;
|
||||
std::vector<osg::ref_ptr<osg::StateSet> > local_materials;
|
||||
std::vector<osg::Group *> groupList;
|
||||
std::vector<osg::ref_ptr<osg::Node> >* models;
|
||||
};
|
||||
|
||||
osg::Texture2D* GetLocalTexture(trpgrImageHelper& image_helper, trpgLocalMaterial* locmat, const trpgTexture* tex);
|
||||
|
||||
//! callback functions for various scene graph elements
|
||||
class geomRead : public trpgr_Callback {
|
||||
public:
|
||||
geomRead(TrPageParser *in_parse);
|
||||
~geomRead();
|
||||
void *Parse(trpgToken tok,trpgReadBuffer &buf);
|
||||
protected:
|
||||
TrPageParser *parse;
|
||||
};
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
class groupRead : public trpgr_Callback {
|
||||
public:
|
||||
groupRead(TrPageParser *in_parse);
|
||||
void *Parse(trpgToken tok,trpgReadBuffer &buf);
|
||||
protected:
|
||||
TrPageParser *parse;
|
||||
};
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
class attachRead : public trpgr_Callback {
|
||||
public:
|
||||
attachRead(TrPageParser*in_parse);
|
||||
void *Parse(trpgToken tok,trpgReadBuffer &buf);
|
||||
protected:
|
||||
TrPageParser*parse;
|
||||
};
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
class billboardRead : public trpgr_Callback {
|
||||
public:
|
||||
billboardRead(TrPageParser*in_parse);
|
||||
void *Parse(trpgToken tok,trpgReadBuffer &buf);
|
||||
protected:
|
||||
TrPageParser*parse;
|
||||
};
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
class lodRead : public trpgr_Callback {
|
||||
public:
|
||||
lodRead(TrPageParser*in_parse);
|
||||
void *Parse(trpgToken tok,trpgReadBuffer &buf);
|
||||
protected:
|
||||
TrPageParser*parse;
|
||||
};
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
class modelRefRead : public trpgr_Callback {
|
||||
public:
|
||||
modelRefRead(TrPageParser*in_parse);
|
||||
void *Parse(trpgToken tok,trpgReadBuffer &buf);
|
||||
protected:
|
||||
TrPageParser*parse;
|
||||
};
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
class tileHeaderRead : public trpgr_Callback {
|
||||
public:
|
||||
tileHeaderRead(TrPageParser*in_parse);
|
||||
void *Parse(trpgToken tok,trpgReadBuffer &buf);
|
||||
protected:
|
||||
TrPageParser*parse;
|
||||
};
|
||||
|
||||
} // namespace txp
|
||||
#endif
|
||||
@@ -1,35 +0,0 @@
|
||||
#ifndef WAIT_BLOCK_H
|
||||
#define WAIT_BLOCK_H
|
||||
#ifndef WIN32
|
||||
#include <pthread.h>
|
||||
|
||||
namespace osgTXP {
|
||||
|
||||
struct WaitBlock{
|
||||
pthread_mutex_t mut;
|
||||
pthread_cond_t cond;
|
||||
|
||||
WaitBlock()
|
||||
{
|
||||
pthread_mutex_init( &mut, 0L );
|
||||
pthread_cond_init( &cond, 0L );
|
||||
}
|
||||
|
||||
void wait()
|
||||
{
|
||||
pthread_mutex_lock( &mut );
|
||||
pthread_cond_wait( &cond, &mut);
|
||||
pthread_mutex_unlock(&mut);
|
||||
}
|
||||
|
||||
void release()
|
||||
{
|
||||
pthread_mutex_lock( &mut );
|
||||
pthread_cond_broadcast( &cond );
|
||||
pthread_mutex_unlock( &mut );
|
||||
}
|
||||
};
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -1,145 +0,0 @@
|
||||
/* **************************************************************************
|
||||
* OpenSceneGraph loader for Terrapage format database
|
||||
*
|
||||
* That loader is redistributed under the terms listed on Terrain Experts
|
||||
* website (www.terrex.com/www/pages/technology/technologypage.htm)
|
||||
*
|
||||
* "TerraPage is provided as an Open Source format for use by anyone...
|
||||
* We supply the TerraPage C++ source code free of charge. Anyone
|
||||
* can use it and redistribute it as needed (including our competitors).
|
||||
* We do, however, ask that you keep the TERREX copyrights intact."
|
||||
*
|
||||
* Copyright Terrain Experts Inc. 1999.
|
||||
* All Rights Reserved.
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef _TRPAGEMANAGER_H_
|
||||
#define _TRPAGEMANAGER_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
#ifndef WIN32
|
||||
#include <pthread.h>
|
||||
#endif
|
||||
|
||||
#include <osg/Group>
|
||||
#include <osg/Object>
|
||||
#include <osg/Node>
|
||||
#include <osgTXP/Export.h>
|
||||
|
||||
#include <osgTXP/trpage_geom.h>
|
||||
#include <osgTXP/trpage_read.h>
|
||||
#include <osgTXP/trpage_write.h>
|
||||
#include <osgTXP/trpage_scene.h>
|
||||
#include <osgTXP/trpage_managers.h>
|
||||
#include <osgTXP/WaitBlock.h>
|
||||
#include <osgTXP/TrPageArchive.h>
|
||||
|
||||
namespace txp
|
||||
{
|
||||
/* Thread Identifier
|
||||
Fill this in for your specific platform.
|
||||
Should be water ID you use for threads.
|
||||
*/
|
||||
#if defined(_WIN32)
|
||||
typedef HANDLE ThreadID;
|
||||
typedef HANDLE ThreadMutex;
|
||||
typedef HANDLE ThreadEvent;
|
||||
#else
|
||||
typedef pthread_t ThreadID;
|
||||
typedef pthread_mutex_t ThreadMutex;
|
||||
typedef osgTXP::WaitBlock ThreadEvent;
|
||||
#endif
|
||||
|
||||
/* OSG Page Manager
|
||||
This class handles the paging into
|
||||
*/
|
||||
class OSGTXP_EXPORT OSGPageManager {
|
||||
public:
|
||||
/* Need a group to put things under and the archive to page.
|
||||
Also, optionally, a Page Manager (if you've made changes
|
||||
to the default one).
|
||||
*/
|
||||
OSGPageManager(TrPageArchive *,trpgPageManager *pageManage = NULL);
|
||||
~OSGPageManager();
|
||||
|
||||
/* Unthreaded update
|
||||
Update viewer position and load a maximum of numTile before
|
||||
returning.
|
||||
Also unloads everything that needs it.
|
||||
Don't call this in threaded mode.
|
||||
*/
|
||||
bool UpdateNoThread(osg::Group *,double locX,double locY,int numTile=-1);
|
||||
|
||||
/* Thread routines
|
||||
The thread will run in and around this object. It can
|
||||
run in one of two modes:
|
||||
ThreadFree -
|
||||
ThreadSync -
|
||||
*/
|
||||
typedef enum {ThreadNone,ThreadFree,ThreadSync} ThreadMode;
|
||||
|
||||
// Retrieve the current threading mode
|
||||
ThreadMode GetThreadMode() { return threadMode; }
|
||||
|
||||
// ----- Main thread routines -----
|
||||
// ----- Only call these from the main thread ----
|
||||
// Create a new thread in the given mode.
|
||||
bool StartThread(ThreadMode,ThreadID &newThread);
|
||||
|
||||
/* If we're in ThreadFree mode, merge everything the paging
|
||||
thread has read in up to this point into the main scenegraph.
|
||||
*/
|
||||
bool MergeUpdateThread(osg::Group *);
|
||||
|
||||
// Shut down the current paging thread.
|
||||
bool EndThread();
|
||||
|
||||
// Update the viewer position
|
||||
void UpdatePositionThread(double locX,double locY);
|
||||
|
||||
// ----- Paging Thread Routines ----
|
||||
// ----- Only call these from the paging thread ----
|
||||
|
||||
// Called by the thread start function
|
||||
// Don't call this yourself
|
||||
bool ThreadLoop();
|
||||
|
||||
protected:
|
||||
// Page Manager we'll use is ours (i.e. delete it at the end)
|
||||
bool pageManageOurs;
|
||||
trpgPageManager *pageManage;
|
||||
// Archive to page from
|
||||
TrPageArchive *archive;
|
||||
// Database origin
|
||||
double originX,originY;
|
||||
|
||||
/* Thread specific data.
|
||||
*/
|
||||
|
||||
// ID of created thread and whether it's valid
|
||||
ThreadMode threadMode;
|
||||
ThreadID threadID;
|
||||
|
||||
// Used to notify the paging thread when the location changes
|
||||
ThreadEvent locationChangeEvent;
|
||||
|
||||
// Lock for the location and location itself
|
||||
ThreadMutex locationMutex;
|
||||
bool positionValid;
|
||||
double locX,locY;
|
||||
|
||||
// Lock for the change lists (merge, unhook, delete)
|
||||
ThreadMutex changeListMutex;
|
||||
// Merge list is filled in by the paging thread.
|
||||
std::vector<osg::Group *> toMerge;
|
||||
std::vector<osg::Group *> toMergeParent;
|
||||
// Unhook list is filled in by the paging thread
|
||||
std::vector<osg::Group *> toUnhook;
|
||||
// Main thread moves groups to the delete list as soon as they are unhooked
|
||||
std::vector<osg::Group *> toDelete;
|
||||
};
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,125 +0,0 @@
|
||||
/* ************************
|
||||
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
|
||||
************************
|
||||
*/
|
||||
|
||||
/* trdll.h
|
||||
Windows Only
|
||||
|
||||
This header file defines the declaration macros for DLLs.
|
||||
*/
|
||||
|
||||
// Export/import declaration for classes and functions
|
||||
// Use EXDECL class CPPDECL ... for a class
|
||||
// Use CPPDECL foo *bar(bletch) for a stand-alone C++ function
|
||||
// Use CDECL foo *bar(bletch) for a C function
|
||||
// __COMP_DLL must be defined explicitly in Build->Settings->Code Generation
|
||||
// __CURR_DLL must be defined in each header in a DLL
|
||||
#ifdef TX_CLDECL
|
||||
#undef TX_CLDECL
|
||||
#undef TX_EXDECL
|
||||
#undef TX_CDECL
|
||||
#undef TX_CPPDECL
|
||||
#undef TX_DODECL
|
||||
#endif
|
||||
// Work through cases
|
||||
// If we're not compiling a DLL, or compiling the wrong DLL do import
|
||||
// declarations (0), otherwise do export declarations (1)
|
||||
#if !defined (__COMP_DLL)
|
||||
// {secret}
|
||||
#define TX_DODECL 0
|
||||
#else
|
||||
#if __COMP_DLL == __CURR_DLL
|
||||
#define TX_DODECL 1
|
||||
#else
|
||||
#define TX_DODECL 0
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// #if !defined (__CURR_DLL) || __COMP_DLL != __CURR_DLL
|
||||
#if TX_DODECL == 0
|
||||
// Modified by Paul J. Metzger (pjm@rbd.com) to support static link libraries.
|
||||
// Here's the original code:
|
||||
// #define TX_CLDECL __declspec( dllimport )
|
||||
// #define TX_EXDECL
|
||||
// #ifdef __cplusplus
|
||||
// #define TX_CDECL extern "C" __declspec(dllimport)
|
||||
// #else
|
||||
// #define TX_CDECL extern __declspec(dllimport)
|
||||
// #endif
|
||||
// #define TX_CPPDECL extern __declspec(dllimport)
|
||||
|
||||
#ifndef TX_CLDECL
|
||||
// Class declaration. Goes after "class" to handle DLL export in windows.
|
||||
#define TX_CLDECL
|
||||
// Goes before "class" to handle DLL export in windows
|
||||
#define TX_EXDECL /* no-op */
|
||||
// Exports a C++ function properly in a windows DLL
|
||||
#define TX_CPPDECL /* no-op */
|
||||
// Exports a C function properly in a windows DLL
|
||||
#define TX_CDECL /* no-op */
|
||||
// {secret}
|
||||
#ifndef TXDUMMY_DLL_MAIN
|
||||
#define TXDUMMY_DLL_MAIN /* no-op */
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#else
|
||||
#define TX_CLDECL __declspec( dllexport )
|
||||
#define TX_EXDECL
|
||||
#define TX_CPPDECL extern __declspec(dllexport)
|
||||
#ifdef __cplusplus
|
||||
#define TX_CDECL extern "C" __declspec(dllexport)
|
||||
#else
|
||||
#define TX_CDECL extern __declspec(dllexport)
|
||||
#endif
|
||||
|
||||
// The following is a DLL Main function for DLLs that wouldn't otherwise
|
||||
// have one. It's needed to initialize the run time library.
|
||||
// This should appear once within every DLL
|
||||
|
||||
// commented out by Boris Bralo for osg
|
||||
|
||||
/*
|
||||
#ifndef TXDUMMY_DLL_MAIN
|
||||
#define TXDUMMY_DLL_MAIN \
|
||||
extern "C" { \
|
||||
BOOL WINAPI _CRT_INIT (HINSTANCE hDLL, DWORD dwReason, LPVOID lpReserved); \
|
||||
BOOL APIENTRY DllMain (HINSTANCE hDLL, DWORD dwReason, LPVOID lpReserved) \
|
||||
{ \
|
||||
switch (dwReason) \
|
||||
{ \
|
||||
case DLL_PROCESS_ATTACH: \
|
||||
{ \
|
||||
if (!_CRT_INIT (hDLL, dwReason, lpReserved)) \
|
||||
return FALSE; \
|
||||
break; \
|
||||
} \
|
||||
\
|
||||
case DLL_PROCESS_DETACH: \
|
||||
{ \
|
||||
break; \
|
||||
} \
|
||||
} \
|
||||
return TRUE; \
|
||||
} \
|
||||
}
|
||||
#endif
|
||||
*/
|
||||
#endif
|
||||
|
||||
#ifndef txdll_h_
|
||||
// {secret}
|
||||
#define txdll_h_
|
||||
|
||||
#endif
|
||||
@@ -1,96 +0,0 @@
|
||||
/* ************************
|
||||
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
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,20 +0,0 @@
|
||||
/* ************************
|
||||
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
|
||||
************************
|
||||
*/
|
||||
|
||||
#ifdef __CURR_DLL
|
||||
#undef __CURR_DLL
|
||||
#endif
|
||||
// {secret}
|
||||
#define __CURR_DLL 7931
|
||||
@@ -1,615 +0,0 @@
|
||||
/* ************************
|
||||
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_io_h_
|
||||
#define _trpage_io_h_
|
||||
|
||||
/* trpage_io.h
|
||||
Token definitions and basic classes.
|
||||
*/
|
||||
|
||||
#include <osgTXP/trpage_sys.h>
|
||||
|
||||
// Macros we may need
|
||||
#ifndef MIN
|
||||
// {secret}
|
||||
#define MIN(x,y) (((x) < (y)) ? (x) : (y))
|
||||
#endif
|
||||
#ifndef MAX
|
||||
// {secret}
|
||||
#define MAX(x,y) (((x) > (y)) ? (x) : (y))
|
||||
#endif
|
||||
|
||||
// File header Magic Number
|
||||
#define TRPG_MAGIC 9480372
|
||||
|
||||
// Current TerraPage major version
|
||||
#define TRPG_VERSION_MAJOR 2
|
||||
// Current TerraPage minor version
|
||||
#define TRPG_VERSION_MINOR 0
|
||||
|
||||
// Non-existent token
|
||||
// {secret}
|
||||
#define TRPG_NOTOKEN 0
|
||||
|
||||
// 16 bit token definition value. These are values such as TRPGTEXTABLE or TRPG_ATTACH, etc...
|
||||
typedef short trpgToken;
|
||||
|
||||
// Tokens for paging data structures
|
||||
// Update the MINTOKEN and MAXTOKEN when you add tokens
|
||||
// {secret}
|
||||
#define TRPG_MINTOKEN 100
|
||||
// {secret}
|
||||
#define TRPG_PUSH 100
|
||||
// {secret}
|
||||
#define TRPG_POP 101
|
||||
|
||||
// {secret}
|
||||
#define TRPGHEADER 200
|
||||
// {secret}
|
||||
#define TRPGHEAD_LODINFO 201
|
||||
|
||||
// {secret}
|
||||
#define TRPGMATTABLE 300
|
||||
// Added 11/14/98 - New material table
|
||||
// {secret}
|
||||
#define TRPGMATTABLE2 301
|
||||
// Added 11/14/98
|
||||
// {secret}
|
||||
#define TRPGSHORTMATTABLE 302
|
||||
|
||||
// {secret}
|
||||
#define TRPGMATERIAL 400
|
||||
// {secret}
|
||||
#define TRPGMAT_BASIC 401
|
||||
// {secret}
|
||||
#define TRPGMAT_SHADE 402
|
||||
// {secret}
|
||||
// {secret}
|
||||
#define TRPGMAT_SIZES 403
|
||||
// {secret}
|
||||
#define TRPGMAT_CULL 404
|
||||
// {secret}
|
||||
#define TRPGMAT_ALPHA 405
|
||||
// {secret}
|
||||
#define TRPGMAT_NORMAL 406
|
||||
// {secret}
|
||||
#define TRPGMAT_TEXTURE 407
|
||||
// {secret}
|
||||
#define TRPGMAT_BUMP 408
|
||||
|
||||
// {secret}
|
||||
#define TRPGMAT_TEXENV 500
|
||||
// {secret}
|
||||
#define TRPGMAT_TXENV_MODE 501
|
||||
// {secret}
|
||||
#define TRPGMAT_TXENV_FILTER 502
|
||||
// {secret}
|
||||
#define TRPGMAT_TXENV_WRAP 503
|
||||
// {secret}
|
||||
#define TRPGMAT_TXENV_BORDER 504
|
||||
|
||||
// {secret}
|
||||
#define TRPGTEXTABLE 600
|
||||
// {secret}
|
||||
#define TRPGTEXTABLE2 601
|
||||
// {secret}
|
||||
#define TRPGTEXTURE 650
|
||||
|
||||
// {secret}
|
||||
#define TRPGMODELREF 700
|
||||
|
||||
// {secret}
|
||||
#define TRPGMODELTABLE 800
|
||||
|
||||
// {secret}
|
||||
#define TRPGTILETABLE 900
|
||||
// {secret}
|
||||
#define TRPG_TILE_ENTRY 901
|
||||
// {secret}
|
||||
#define TRPGTILETABLE2 902
|
||||
|
||||
// {secret}
|
||||
#define TRPGTILEHEADER 1000
|
||||
// {secret}
|
||||
#define TRPG_TILE_MATLIST 1001
|
||||
// {secret}
|
||||
#define TRPG_TILE_MODELLIST 1002
|
||||
// {secret}
|
||||
#define TRPG_TILE_DATE 1003
|
||||
// {secret}
|
||||
#define TRPGLOCALMATERIAL 1004
|
||||
// {secret}
|
||||
#define TRPG_TILE_LOCMATLIST 1005
|
||||
|
||||
|
||||
// Lights support added by Nick
|
||||
// {secret}
|
||||
#define TRPGLIGHTTABLE 1100
|
||||
// {secret}
|
||||
#define TRPGLIGHTATTR 1150
|
||||
// {secret}
|
||||
#define TRPGLIGHTATTR_BASIC 1151
|
||||
// {secret}
|
||||
#define TRPGLIGHTATTR_RASCAL 1152
|
||||
// {secret}
|
||||
#define TRPGLIGHTATTR_CALLIGRAPHIC 1153
|
||||
// {secret}
|
||||
#define TRPGLIGHTATTR_PERFORMER 1154
|
||||
// {secret}
|
||||
#define TRPGLIGHTATTR_ANIMATION 1155
|
||||
// {secret}
|
||||
#define TRPGLIGHT 1160
|
||||
#define TRPG_LIGHT 1160
|
||||
|
||||
// {secret}
|
||||
#define TRPGRANGETABLE 1200
|
||||
// {secret}
|
||||
#define TRPG_RANGE 1201
|
||||
|
||||
|
||||
// {secret}
|
||||
#define TRPG_GROUP 2001
|
||||
// {secret}
|
||||
#define TRPG_BILLBOARD 2002
|
||||
// {secret}
|
||||
#define TRPG_LOD 2003
|
||||
// {secret}
|
||||
#define TRPG_TRANSFORM 2004
|
||||
// {secret}
|
||||
#define TRPG_MODELREF 2005
|
||||
// {secret}
|
||||
#define TRPG_LAYER 2006
|
||||
|
||||
// {secret}
|
||||
#define TRPG_GEOMETRY 3000
|
||||
// {secret}
|
||||
#define TRPG_GEOM_PRIM 3001
|
||||
// {secret}
|
||||
#define TRPG_GEOM_MATERIAL 3002
|
||||
// {secret}
|
||||
#define TRPG_GEOM_VERT32 3003
|
||||
// {secret}
|
||||
#define TRPG_GEOM_VERT64 3004
|
||||
// {secret}
|
||||
#define TRPG_GEOM_NORM32 3005
|
||||
// {secret}
|
||||
#define TRPG_GEOM_NORM64 3006
|
||||
// {secret}
|
||||
#define TRPG_GEOM_COLOR 3007
|
||||
// {secret}
|
||||
#define TRPG_GEOM_TEX32 3008
|
||||
// {secret}
|
||||
#define TRPG_GEOM_TEX64 3009
|
||||
// {secret}
|
||||
#define TRPG_GEOM_EFLAG 3010
|
||||
|
||||
// {secret}
|
||||
#define TRPG_ATTACH 4000
|
||||
|
||||
// {secret}
|
||||
#define TRPG_MAXTOKEN 4000
|
||||
|
||||
// Basic data types
|
||||
|
||||
/* 64 bit disk reference value. */
|
||||
typedef trpgllong trpgDiskRef;
|
||||
// {secret}
|
||||
typedef int trpgMatRef;
|
||||
|
||||
/* Double precision 2 dimensional point. */
|
||||
TX_EXDECL class TX_CLDECL trpg2dPoint {
|
||||
public:
|
||||
double x, y;
|
||||
trpg2dPoint (void) { };
|
||||
trpg2dPoint (double in_x,double in_y) { x = in_x; y = in_y; };
|
||||
};
|
||||
/* Integer 2 dimensional point. This is used primarily as a 2D index value. */
|
||||
TX_EXDECL class TX_CLDECL trpg2iPoint {
|
||||
public:
|
||||
int x,y;
|
||||
trpg2iPoint (void) { };
|
||||
trpg2iPoint (int in_x,int in_y) {x = in_x; y = in_y;};
|
||||
};
|
||||
/* Double precision 3 dimensional point. */
|
||||
TX_EXDECL class TX_CLDECL trpg3dPoint {
|
||||
public:
|
||||
double x,y,z;
|
||||
trpg3dPoint(void) { };
|
||||
trpg3dPoint(double in_x,double in_y,double in_z) {x = in_x; y = in_y; z = in_z;}
|
||||
bool operator==(const trpg3dPoint& pt ) {
|
||||
if ( x != pt.x ) return false;
|
||||
if ( y != pt.y ) return false;
|
||||
if ( z != pt.z ) return false;
|
||||
return true;
|
||||
};
|
||||
bool operator!=(const trpg3dPoint& pt ) { return !operator==(pt); };
|
||||
};
|
||||
/* Simple red, green, blue color definition */
|
||||
TX_EXDECL class TX_CLDECL trpgColor {
|
||||
public:
|
||||
trpgColor(float64 r,float64 g,float64 b) {red = r; green = g; blue = b;}
|
||||
trpgColor(void) { };
|
||||
bool operator==(const trpgColor& color) {
|
||||
if ( color.red != red ) return false;
|
||||
if ( color.green != green ) return false;
|
||||
if ( color.blue != blue ) return false;
|
||||
return true;
|
||||
};
|
||||
bool operator!=(const trpgColor& color) { return !operator==(color); };
|
||||
float64 red,green,blue;
|
||||
};
|
||||
|
||||
// Used to specify machine endianess
|
||||
typedef enum {LittleEndian,BigEndian} trpgEndian;
|
||||
|
||||
/* This is a base class for an abstract buffer type.
|
||||
It contains the virtual methods for writing
|
||||
data to an abstract device. The device implementation is up
|
||||
to the subclass. trpgReadBuffer performs the similar function
|
||||
for reading.
|
||||
{group:Low Level I/O}
|
||||
*/
|
||||
TX_EXDECL class TX_CLDECL trpgWriteBuffer {
|
||||
public:
|
||||
virtual ~trpgWriteBuffer(void) { };
|
||||
/* The add functions must be filled in by the child class
|
||||
They add data of the appropriate type to the current buffer. */
|
||||
virtual void Add(int32) = 0;
|
||||
virtual void Add(int64) = 0;
|
||||
virtual void Add(const char *) = 0;
|
||||
virtual void Add(float32) = 0;
|
||||
virtual void Add(float64) = 0;
|
||||
#if (bool != int32)
|
||||
virtual void Add(bool) = 0;
|
||||
#endif
|
||||
virtual void Add(uint8) = 0;
|
||||
#if (trpgDiskRef != int64)
|
||||
virtual void Add(trpgDiskRef) = 0;
|
||||
#endif
|
||||
virtual void Add(trpgToken) = 0;
|
||||
/* Child class method. Returns the buffer to an original state. */
|
||||
virtual void Reset(void) = 0;
|
||||
// See trpgMemWriteBuffer for details
|
||||
virtual void Begin(trpgToken) = 0;
|
||||
// See trpgMemWriteBuffer for details
|
||||
virtual void End(void) = 0;
|
||||
// See trpgMemWriteBuffer for details
|
||||
virtual void Push(void) = 0;
|
||||
// See trpgMemWriteBuffer for details
|
||||
virtual void Pop(void) = 0;
|
||||
|
||||
// Some add functions are helpers for composite values that call the basic add functions
|
||||
virtual void Add(const trpg2iPoint &);
|
||||
virtual void Add(const trpg2dPoint &);
|
||||
virtual void Add(const trpg3dPoint &);
|
||||
virtual void Add(const trpgColor &);
|
||||
|
||||
/* Endianness is something the child class buffer type must set and use.
|
||||
This function returns the endiannes of the current buffer. */
|
||||
virtual trpgEndian GetEndian(void) { return ness; }
|
||||
|
||||
protected:
|
||||
// Target endianness of the buffer. This should be set by the subclass on creation.
|
||||
trpgEndian ness;
|
||||
// Endianness of the machine we're running on.
|
||||
trpgEndian cpuNess;
|
||||
};
|
||||
|
||||
/* The Memory Write Buffer is an implementation of the Write Buffer that
|
||||
uses chunks of memory. It contains implementations of the all the virtual
|
||||
methods straight to memory. This is used primarily in writing archives and
|
||||
tiles.
|
||||
{group:Low Level I/O}
|
||||
*/
|
||||
TX_EXDECL class TX_CLDECL trpgMemWriteBuffer : public trpgWriteBuffer {
|
||||
public:
|
||||
/* The constructor takes an endianness for this buffer.
|
||||
Data will automatically be converted to that as it goes in. */
|
||||
trpgMemWriteBuffer(trpgEndian);
|
||||
virtual ~trpgMemWriteBuffer(void);
|
||||
// Return the current length of buffer
|
||||
virtual int length(void) const;
|
||||
// Return the raw data (if you want to write to disk, for example)
|
||||
virtual const char *getData(void) const;
|
||||
// Allocate the given amount of space for the buffer
|
||||
virtual void setLength(unsigned int);
|
||||
|
||||
// Add a 32 bit integer to the buffer
|
||||
virtual void Add(int32);
|
||||
// Add a 64 bit integer to the buffer
|
||||
virtual void Add(int64);
|
||||
/* Add an arbitrary length string to the buffer.
|
||||
This writes both the length and the string itself.
|
||||
*/
|
||||
virtual void Add(const char *);
|
||||
// Add a 32 bit float to the buffer
|
||||
virtual void Add(float32);
|
||||
// Add a 64 bit float to the buffer
|
||||
virtual void Add(float64);
|
||||
#if (bool != int32)
|
||||
// Add a boolean value to the buffer. It will become at least one byte.
|
||||
virtual void Add(bool);
|
||||
#endif
|
||||
// Add an unsigned character to the buffer
|
||||
virtual void Add(uint8);
|
||||
#if (trpgDiskRef != int64)
|
||||
// Add a 64 bit disk reference to the buffer
|
||||
virtual void Add(trpgDiskRef);
|
||||
#endif
|
||||
// Add a token (16 bit) to the buffer
|
||||
virtual void Add(trpgToken);
|
||||
// Reset this buffer. This will set the current length to zero, but will not deallocate memory
|
||||
virtual void Reset(void);
|
||||
/* Start defining an tokenized object. The token is put into the buffer stream
|
||||
and the position of a size value following it is kept. When End() is called
|
||||
the buffer will rewind to that value and save the size. This method ensures
|
||||
that token data can be skipped if necessary. */
|
||||
virtual void Begin(trpgToken);
|
||||
/* This method is called at the end of a tokenized object. See Begin for details. */
|
||||
virtual void End(void);
|
||||
/* Adds the TRPG_PUSH token to the current buffer. This is done by objects
|
||||
that have children as they're being written. See Pop as well. */
|
||||
virtual void Push(void);
|
||||
/* Adds the TRPG_POP token to the current buffer. This is done by objects
|
||||
that have defined children. See Push. */
|
||||
virtual void Pop(void);
|
||||
|
||||
protected:
|
||||
virtual void append(unsigned int,const char *);
|
||||
virtual void set(unsigned int pos,unsigned int len,const char *);
|
||||
int curLen;
|
||||
int totLen;
|
||||
char *data;
|
||||
std::vector<int> lengths;
|
||||
};
|
||||
|
||||
/* This is a virtual base class for reading data from a device.
|
||||
The device implementation is left as an excercise to the sub class.
|
||||
This class contains methods for getting data that must be filled in
|
||||
as well as helper methods that call those.
|
||||
{group:Low Level I/O}
|
||||
*/
|
||||
TX_EXDECL class TX_CLDECL trpgReadBuffer {
|
||||
public:
|
||||
virtual ~trpgReadBuffer(void) { };
|
||||
/* The Get methods are utility routines that all call the GetData method.
|
||||
Only that method need be filled in by a subclass. */
|
||||
virtual bool Get(int32 &);
|
||||
virtual bool Get(int64 &);
|
||||
virtual bool Get(char *,int);
|
||||
virtual bool Get(float32 &);
|
||||
virtual bool Get(float64 &);
|
||||
#if (bool != int32)
|
||||
virtual bool Get(bool &);
|
||||
#endif
|
||||
virtual bool Get(uint8 &);
|
||||
#if (trpgDiskRef != int64)
|
||||
virtual bool Get(trpgDiskRef &);
|
||||
#endif
|
||||
virtual bool Get(trpgToken &);
|
||||
|
||||
/* These methods return references to arrays of data of the given types.
|
||||
These are all utility routines and depend upon GetDataRef. */
|
||||
virtual bool GetArray(int,float32 **);
|
||||
virtual bool GetArray(int,float64 **);
|
||||
virtual bool GetArray(int,int32 **);
|
||||
virtual bool GetArray(int,trpgColor **);
|
||||
virtual bool GetArray(int,char **);
|
||||
|
||||
virtual bool Get(trpg2iPoint &);
|
||||
virtual bool Get(trpg2dPoint &);
|
||||
virtual bool Get(trpg3dPoint &);
|
||||
virtual bool Get(trpgColor &);
|
||||
virtual bool GetToken(trpgToken &,int32 &);
|
||||
|
||||
/* Force the buffer to only allow the next N bytes to be read.
|
||||
The limits are stack based. That is, this limit is the current one
|
||||
until it's popped off the stack. Then it reverts to the previous one.
|
||||
Any bytes read in the mean time count against all limits. */
|
||||
virtual void PushLimit(int);
|
||||
/* Revert to the limit before this one. Typically this would happen when
|
||||
a tokenized object has been read. */
|
||||
virtual void PopLimit(void);
|
||||
/* Skip to the end of the current limit. This is done by a parser when
|
||||
reading a tokenized object from the buffer to make sure that the next
|
||||
object can be safely read even if the current one wasn't. */
|
||||
virtual bool SkipToLimit(void);
|
||||
|
||||
// Buffer is empty
|
||||
virtual bool isEmpty(void) = 0;
|
||||
|
||||
protected:
|
||||
trpgEndian ness; // Endianness of the source we're reading
|
||||
trpgEndian cpuNess; // Endiannees of the CPU
|
||||
/* Virtual raw data retrieval function that must be implemented by a subclass.
|
||||
It must return a given number of bytes in the array passed in. */
|
||||
virtual bool GetData(char *,int)=0;
|
||||
/* Virtual raw data reference retrieval function. The difference between
|
||||
this method and GetData is that this is supposed to return a pointer
|
||||
to a given amount of bytes. This assumes some sort of memory caching
|
||||
mechanism in the subclass. */
|
||||
virtual bool GetDataRef(char **,int)=0;
|
||||
/* This virtual method must be filled in by the subclass so that SkipToLimit
|
||||
will work correctly. */
|
||||
virtual bool Skip(int) = 0;
|
||||
/* A utility function for subclasses to use to see if they would exceed an
|
||||
outside imposed limit by reading the given number of bytes. */
|
||||
virtual bool TestLimit(int);
|
||||
/* Utility function that must be called after a successfull read to update
|
||||
the outside imposed read limits. */
|
||||
virtual void UpdateLimits(int);
|
||||
std::vector<int> limits;
|
||||
};
|
||||
|
||||
/* This class implements a read buffer that uses a chunk of memory.
|
||||
Typically, raw data will be dumped into this class, then it will be
|
||||
passed to a parser for object based reading.
|
||||
{group:Low Level I/O}
|
||||
*/
|
||||
TX_EXDECL class TX_CLDECL trpgMemReadBuffer : public trpgReadBuffer {
|
||||
public:
|
||||
// Memory read buffers must be initialized with an endianness
|
||||
trpgMemReadBuffer(trpgEndian);
|
||||
~trpgMemReadBuffer(void);
|
||||
// Return true if we're out of data
|
||||
bool isEmpty(void);
|
||||
// Sets the size of this read buffer.
|
||||
void SetLength(int);
|
||||
/* Return a pointer to the raw data cache for this object. Data will
|
||||
be dumped straight into here (from disk, for example) and then parsed
|
||||
by something that takes a trpgReadBuffer as input. */
|
||||
char *GetDataPtr(void);
|
||||
protected:
|
||||
bool GetData(char *,int); // Retrieve the given amount of data
|
||||
bool GetDataRef(char **,int); // Retrieve a pointer to the given array
|
||||
bool Skip(int); // Skip over the given amount
|
||||
int len; // Data Length
|
||||
int totLen; // Total allocated length
|
||||
int pos; // Current position
|
||||
char *data;
|
||||
};
|
||||
|
||||
/* A Checkable is purely a base class used by other classes that
|
||||
need validity checks associated with them. By default, the
|
||||
checkable will return false for isValid unless the valid flag is set.
|
||||
*/
|
||||
TX_EXDECL class TX_CLDECL trpgCheckable {
|
||||
public:
|
||||
trpgCheckable(void);
|
||||
virtual ~trpgCheckable(void);
|
||||
// Returns the state of the valid flag, or can be overriden by a subclass to do a more complex check.
|
||||
bool isValid(void) const;
|
||||
protected:
|
||||
/* Set this flag to true if your checkable structure doesn't have a complex
|
||||
check it needs to do. */
|
||||
bool valid;
|
||||
};
|
||||
|
||||
class trpgPrintBuffer;
|
||||
/* The Read/Writeable is a class that knows how to read itself from a trpgReadBuffer
|
||||
and write itself to a trpgWriteBuffer. This includes all the node and header
|
||||
data in TerraPage. These classes are intended as marshalling points for reading
|
||||
and writing data, not as data containers in and of themselves. If you find
|
||||
yourself keeping a lot of classes derived from trpgReadWriteable around, you're
|
||||
probably misusing them.
|
||||
|
||||
The classes derived from this one will have a lot of methods that begin with
|
||||
"Set", "Get", and "Add". These will almost always return a bool value. This
|
||||
is used to indicate whether the given call succeeded. In the case of "Set" and "Add" calls
|
||||
this should always work if it possibly can. An out of range index might make it
|
||||
fail, for example. "Get" calls will always fail if the object you're getting from
|
||||
is not valid. Be sure to do an isValid check as soon as you've read or filled out
|
||||
one of these objects.
|
||||
{group:Read/Write Classes}
|
||||
*/
|
||||
TX_EXDECL class TX_CLDECL trpgReadWriteable : public trpgCheckable {
|
||||
public:
|
||||
/* The Write method is a virtual that must be filled in by the subclass.
|
||||
It takes a trpgWriteBuffer and should return true on success. */
|
||||
virtual bool Write(trpgWriteBuffer &) = 0;
|
||||
/* The Read method should be overriden by a subclass. It should read
|
||||
the contents of the given trpgReadBuffer up to the current limit
|
||||
into itself. It must return true on success. */
|
||||
virtual bool Read(trpgReadBuffer &) { return false;};
|
||||
/* Every read/writeable must be able to reset itself to a pristine state
|
||||
so that, for example, multiple objects of the same type can be read into
|
||||
it, one after the other. */
|
||||
virtual void Reset(void) = 0;
|
||||
/* The print method is optional. If it's not there, it won't do anything.
|
||||
*/
|
||||
virtual bool Print(trpgPrintBuffer &) const { return true; }
|
||||
protected:
|
||||
};
|
||||
|
||||
/* Pointer into a trpgwAppFile. The full name of the file
|
||||
is based on the context (e.g. texture vs. tile)
|
||||
{group:Archive Writing}
|
||||
*/
|
||||
TX_EXDECL class TX_CLDECL trpgwAppAddress {
|
||||
public:
|
||||
// Which file
|
||||
int32 file;
|
||||
// Offset within the file
|
||||
// Note: This is not a 64 bit value
|
||||
int32 offset;
|
||||
};
|
||||
|
||||
/* Archive File.
|
||||
This class represents an appendable file archive used for
|
||||
consolidating tiles and textures.
|
||||
{group:Archive Writing}
|
||||
*/
|
||||
TX_EXDECL class TX_CLDECL trpgwAppFile {
|
||||
public:
|
||||
trpgwAppFile(trpgEndian,const char *);
|
||||
virtual ~trpgwAppFile(void);
|
||||
virtual bool Append(const trpgMemWriteBuffer *,const trpgMemWriteBuffer *);
|
||||
virtual bool Append(const char *,int size);
|
||||
virtual int64 Pos(void) const;
|
||||
virtual int GetLengthWritten();
|
||||
|
||||
bool isValid(void) const;
|
||||
protected:
|
||||
bool valid;
|
||||
trpgEndian ness,cpuNess;
|
||||
FILE *fp;
|
||||
int lengthSoFar;
|
||||
};
|
||||
|
||||
/* Archive File - Read version.
|
||||
This class represents an appendable file archive from the
|
||||
read perspective. This is the same type of file written by
|
||||
trpgwAppFile.
|
||||
*/
|
||||
TX_EXDECL class TX_CLDECL trpgrAppFile {
|
||||
public:
|
||||
trpgrAppFile(trpgEndian,const char *);
|
||||
virtual ~trpgrAppFile(void);
|
||||
virtual bool Read(trpgMemReadBuffer *,int32 offset);
|
||||
virtual bool Read(char *data,int32 offset,uint32 dataSize);
|
||||
|
||||
bool isValid(void) const;
|
||||
protected:
|
||||
bool valid;
|
||||
trpgEndian ness,cpuNess;
|
||||
FILE *fp;
|
||||
};
|
||||
|
||||
/* Archive File Cache.
|
||||
This class keeps
|
||||
*/
|
||||
TX_EXDECL class TX_CLDECL trpgrAppFileCache {
|
||||
public:
|
||||
trpgrAppFileCache(const char *prefix,const char *ext,int noFiles=32);
|
||||
~trpgrAppFileCache(void);
|
||||
trpgrAppFile *GetFile(trpgEndian ness,int id);
|
||||
protected:
|
||||
// Prefix name and extension
|
||||
char baseName[1024],ext[20];
|
||||
|
||||
class OpenFile {
|
||||
public:
|
||||
OpenFile(void);
|
||||
int id; // ID of open file
|
||||
trpgrAppFile *afile;
|
||||
int lastUsed; // When the file was last accessed
|
||||
};
|
||||
|
||||
std::vector<OpenFile> files;
|
||||
int timeCount; // Incremented for every access
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,378 +0,0 @@
|
||||
/* ************************
|
||||
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_managers_h_
|
||||
#define _trpage_managers_h_
|
||||
|
||||
#include <deque>
|
||||
|
||||
/* This file contains class definitions for managers
|
||||
that help you keep track of data related to
|
||||
paging. For instance, which tiles to load
|
||||
in at any given time and what textures you need
|
||||
to read for a given tile.
|
||||
*/
|
||||
|
||||
class trpgPageManager;
|
||||
|
||||
/* Managed Tiles are used by the trpgPageManager to keep
|
||||
track of which tiles are loaded and what textures (and
|
||||
models) they need loaded into memory with them.
|
||||
*/
|
||||
TX_EXDECL class TX_CLDECL trpgManagedTile {
|
||||
friend class trpgPageManager;
|
||||
public:
|
||||
trpgManagedTile(void);
|
||||
|
||||
// Called to clear any info out of this tile
|
||||
void Reset(void);
|
||||
|
||||
/* Call this when you hit a tile header in your own
|
||||
Scene parser callback. The managed tile
|
||||
can then keep track of which textures and models
|
||||
go with this tile.
|
||||
*/
|
||||
bool ParseTileHeader(trpgReadBuffer &);
|
||||
|
||||
// Check if the tile is loaded (e.g. the header read in)
|
||||
bool IsLoaded(void);
|
||||
|
||||
/* Set the tile location. This resets any internal
|
||||
state we may be keeping.
|
||||
*/
|
||||
bool SetTileLoc(int x,int y,int lod);
|
||||
|
||||
// Get the tile location
|
||||
bool GetTileLoc(int &x,int &y,int &lod);
|
||||
|
||||
// Return a pointer to the tile header
|
||||
const trpgTileHeader *GetTileHead(void);
|
||||
|
||||
/* Return a pointer to the list of locally defined
|
||||
materials. As soon as the tile header is read by
|
||||
ParseTileHeader (which you call) you'll want to get
|
||||
this list and load the pageable textures. You can
|
||||
use SetMatData to keep track of our internal texture
|
||||
structures.
|
||||
*/
|
||||
const std::vector<trpgLocalMaterial> *GetLocMatList(void) const;
|
||||
|
||||
/* Returns a pointer to a single local material, if within
|
||||
the valid range of local materials for this tile.
|
||||
*/
|
||||
const trpgLocalMaterial *GetLocMaterial(int id) const;
|
||||
|
||||
/* Set Local Data for managed tile. The local data would
|
||||
probably be a pointer to the top of the scene graph you're
|
||||
using to represent just this tile.
|
||||
*/
|
||||
void SetLocalData(void *);
|
||||
|
||||
/* Returns the local data you set with SetLocalData.
|
||||
*/
|
||||
void *GetLocalData(void) const;
|
||||
|
||||
/* Associates a void * with one of the materials referenced
|
||||
within this tile. The idea here is that you'll want
|
||||
to load the texture for a given local material and then
|
||||
pass your own internal texture structure into here as
|
||||
a void *. That way, the trpgPageManager will keep track
|
||||
of which textures you should unload when this tile goes
|
||||
out of range.
|
||||
*/
|
||||
bool SetMatData(int id,void *);
|
||||
|
||||
/* Gets the void * data you associated with a given local
|
||||
material index. See SetMatData for more information.
|
||||
*/
|
||||
void *GetMatData(int id) const;
|
||||
|
||||
/* Add Group ID to this tile. This is called by the page
|
||||
manager to keep track of which group IDs belong to this tile.
|
||||
We use this information to NULL out the appropriate positions
|
||||
in the group map help by the page manager.
|
||||
*/
|
||||
void AddGroupID(int id);
|
||||
|
||||
/* Retrieve the list of group IDs for this tile.
|
||||
*/
|
||||
const std::vector<int> *GetGroupIDs(void) const;
|
||||
|
||||
/* Print the current status and information about this managed
|
||||
Tile.
|
||||
*/
|
||||
void Print(trpgPrintBuffer &);
|
||||
protected:
|
||||
// Set if a tile is currently loaded
|
||||
bool isLoaded;
|
||||
// Tile location info
|
||||
int x,y,lod;
|
||||
// Tile Header associated with this tile
|
||||
trpgTileHeader tileHead;
|
||||
// Data to keep associated with each individual local material index
|
||||
std::vector<void *> localMatData;
|
||||
// Used to keep track of group IDs in this tile
|
||||
std::vector<int> groupIDs;
|
||||
// Local data (probably the top of the local scene graph)
|
||||
void *localData;
|
||||
|
||||
// Note: Should do models too if anyone wanted them.
|
||||
};
|
||||
|
||||
/* The Page Manager is a helper class that can be used
|
||||
to keep track of: (1) which tiles need to be loaded
|
||||
into memory for a given viewer position, (2) which tiles
|
||||
are currently loaded and (3) which tiles need to be unloaded
|
||||
when the viewer position moves. The tile list this
|
||||
class generates is guaranteed to be in the right order
|
||||
for loading. You would use this class if you're implementing
|
||||
a TerraPage reader for your visual run-time system.
|
||||
*/
|
||||
TX_EXDECL class TX_CLDECL trpgPageManager {
|
||||
public:
|
||||
trpgPageManager(void);
|
||||
virtual ~trpgPageManager(void);
|
||||
|
||||
// Initialize with an archive
|
||||
virtual void Init(trpgr_Archive *);
|
||||
|
||||
/* Set Paging Distance
|
||||
This is the extra distance outside the visible range
|
||||
we want to page. The defaults will be valid. You would
|
||||
set this if you want to pull tiles in earlier. Be sure
|
||||
to call it before you call Init(), however.
|
||||
*/
|
||||
virtual bool SetPageDistFactor(double);
|
||||
|
||||
/* Updates the current location for paging purposes.
|
||||
Returns true if any load or unloads need to happen.
|
||||
*/
|
||||
virtual bool SetLocation(trpg2dPoint &);
|
||||
|
||||
/* Get next tile to load.
|
||||
The paging manager is keeping track of which tiles
|
||||
need to be loaded and in what order. This method
|
||||
returns a pointer to the next one. The user is
|
||||
expected to call AckLoad() after the tile is loaded.
|
||||
*/
|
||||
virtual trpgManagedTile *GetNextLoad(void);
|
||||
/* Acknowledge Tile Load.
|
||||
This method should be called when a tile has been
|
||||
loaded by the caller. This method is used in conjunction
|
||||
with GetNextLoad().
|
||||
*/
|
||||
virtual void AckLoad(void);
|
||||
|
||||
/* Add Group ID to map.
|
||||
This should be called when the user encounters a group-like
|
||||
object while processing the scene graph data from a tile.
|
||||
The groupId is given by TerraPage and the data should be
|
||||
the corresponding group object that the user creates in
|
||||
their own scenegraph toolkit. This information can then
|
||||
be retrieved later by GetGroupData().
|
||||
*/
|
||||
virtual void AddGroupID(trpgManagedTile *,int groupID,void *data);
|
||||
|
||||
/* Get Group Data fetches the data cached by the user and
|
||||
associated with the given groupID. This would be used in
|
||||
conjunction with trpgAttach nodes to implement geometry paging.
|
||||
*/
|
||||
virtual void *GetGroupData(int groupID);
|
||||
|
||||
/* Get next tile to unload.
|
||||
The paging manager keeps track of which tiles need
|
||||
to be unloaded based on a change of location. It's
|
||||
best if you unload tiles before loading them, but
|
||||
that's really up to you.
|
||||
*/
|
||||
virtual trpgManagedTile *GetNextUnload(void);
|
||||
/* Acknowledge a tile unload.
|
||||
You should call this after you've "unloaded" a tile
|
||||
and all its associated textures.
|
||||
*/
|
||||
virtual void AckUnload(void);
|
||||
|
||||
/* Stop paging entirely. Call this right before you want to
|
||||
shut down paging. Everything active will wind up on the
|
||||
unload lists. Then you can unload those tiles and move on.
|
||||
*/
|
||||
virtual bool Stop(void);
|
||||
|
||||
// Print current status and content information
|
||||
virtual void Print(trpgPrintBuffer &);
|
||||
|
||||
protected:
|
||||
trpgr_Archive *archive;
|
||||
|
||||
// Center of paging
|
||||
trpg2dPoint pagePt;
|
||||
|
||||
/* Information associated with each terrain level of
|
||||
detail as related to paging.
|
||||
*/
|
||||
class LodPageInfo {
|
||||
friend class trpgPageManager;
|
||||
public:
|
||||
LodPageInfo(void);
|
||||
virtual ~LodPageInfo(void);
|
||||
|
||||
/* Initializes the class with its current LOD.
|
||||
It figures out all the rest.
|
||||
*/
|
||||
virtual bool Init(trpgr_Archive *, int myLod, double scale);
|
||||
|
||||
/* Reset the location. This forces a recalculation
|
||||
of what to load and unload if the cell has changed
|
||||
or if this is the first SetLocation.
|
||||
The location passed in must be relative to the southwest
|
||||
corner of the TerraPage archive.
|
||||
*/
|
||||
virtual bool SetLocation(trpg2dPoint &);
|
||||
|
||||
// Return the next tile to load for this terrain lod
|
||||
virtual trpgManagedTile *GetNextLoad(void);
|
||||
// Acknowledge the load. Move the active tile to the
|
||||
// loaded list.
|
||||
virtual void AckLoad(void);
|
||||
// Return the next tile to unload for this terrain lod
|
||||
virtual trpgManagedTile *GetNextUnload(void);
|
||||
// Acknowledge the unload. Move the active tile to the
|
||||
// free list.
|
||||
virtual void AckUnload(void);
|
||||
// Called to stop paging. Everything active is dumped on
|
||||
// the unload list.
|
||||
virtual bool Stop(void);
|
||||
// Print current status and content information
|
||||
virtual void Print(trpgPrintBuffer &);
|
||||
protected:
|
||||
virtual void Clean(void);
|
||||
virtual void Update(void);
|
||||
|
||||
// Check if the given tile is within the area we care about
|
||||
bool isWithin(trpgManagedTile *,trpg2iPoint &sw,trpg2iPoint &ne);
|
||||
|
||||
bool valid;
|
||||
|
||||
// Terrain LOD we're responsible for
|
||||
int lod;
|
||||
|
||||
/* Adjusted (e.g. paranoid) distance outward from
|
||||
which to page this terrain LOD. This takes into
|
||||
account the distance in the header as well as
|
||||
any factor the user may have added.
|
||||
*/
|
||||
double pageDist;
|
||||
|
||||
/* Max tiles we could have loaded in at any given time.
|
||||
This is just a guess because it's up to the user
|
||||
to load (and, more importantly) unload.
|
||||
*/
|
||||
int maxNumTiles;
|
||||
|
||||
// Size of a single cell. Copied from the archive.
|
||||
trpg2dPoint cellSize;
|
||||
|
||||
// Number of tiles (cells) in each direction
|
||||
trpg2iPoint lodSize;
|
||||
|
||||
/* Area of interest size in cells
|
||||
This is a linear distance "ahead" of the center cell.
|
||||
*/
|
||||
trpg2iPoint aoiSize;
|
||||
|
||||
/* Our effective paging location sits at the middle
|
||||
of this cell. We don't recalculate unless the
|
||||
cell changes. */
|
||||
trpg2iPoint cell;
|
||||
|
||||
// List of tiles to load
|
||||
std::deque<trpgManagedTile *> load;
|
||||
// List of tiles to unload
|
||||
std::deque<trpgManagedTile *> unload;
|
||||
// List of currently loaded tiles
|
||||
std::deque<trpgManagedTile *> current;
|
||||
|
||||
// Used by Update. Here because we want to avoid memory allocs, if possible.
|
||||
std::vector<bool> tmpCurrent;
|
||||
|
||||
// Set if a load is in progress
|
||||
// Load w/o ACK
|
||||
bool activeLoad;
|
||||
// Set if an unload is in progress
|
||||
// Unload w/o ACK
|
||||
bool activeUnload;
|
||||
|
||||
// List of tile pointers we can reuse
|
||||
std::deque<trpgManagedTile *> freeList;
|
||||
};
|
||||
|
||||
// Per terrain lod paging information
|
||||
std::vector<LodPageInfo> pageInfo;
|
||||
|
||||
// Enumerated type for lastLoad
|
||||
typedef enum {Load,Unload,None} LoadType;
|
||||
/* Information about what the pending load/unload operation
|
||||
is. It's up to the user to complete and acknowledge it.
|
||||
*/
|
||||
LoadType lastLoad;
|
||||
// LOD for the pending load/unload requested operation
|
||||
int lastLod;
|
||||
// Tile to be loaded/unloaded
|
||||
trpgManagedTile *lastTile;
|
||||
|
||||
// Optional scaling factor
|
||||
double scale;
|
||||
|
||||
// Mapping from group IDs to user defined data
|
||||
typedef std::map<int,void *> ManageGroupMap;
|
||||
ManageGroupMap groupMap;
|
||||
|
||||
bool valid;
|
||||
};
|
||||
|
||||
/* Page Manager Tester. This class tests a given paging manager
|
||||
by applying likely
|
||||
*/
|
||||
TX_EXDECL class TX_CLDECL trpgPageManageTester {
|
||||
public:
|
||||
trpgPageManageTester();
|
||||
virtual ~trpgPageManageTester();
|
||||
|
||||
/* Initialize the tester with a paging manager
|
||||
and an archive.
|
||||
*/
|
||||
void Init(trpgPrintBuffer *,trpgPageManager *,trpgr_Archive *);
|
||||
|
||||
/* Feeds the paging manager coordinates starting from
|
||||
the lower left to upper right of the database in the
|
||||
given increment.
|
||||
*/
|
||||
void Fly_LL_to_UR(double dist=100.0);
|
||||
|
||||
/* Jumps around randomly within the archive loading and
|
||||
unloading as needed.
|
||||
*/
|
||||
void RandomTest(int no=100,int seed=-1);
|
||||
|
||||
protected:
|
||||
// Does the work of "load" and "unloading"
|
||||
void ProcessChanges();
|
||||
|
||||
trpgPageManager *manager;
|
||||
trpgr_Archive *archive;
|
||||
trpgPrintBuffer *printBuf;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,106 +0,0 @@
|
||||
/* ************************
|
||||
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 <osgTXP/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
|
||||
@@ -1,218 +0,0 @@
|
||||
/* ************************
|
||||
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 _txpage_read_h_
|
||||
// {secret}
|
||||
#define _txpage_read_h_
|
||||
|
||||
/* txpage_read.h
|
||||
Classes used to represent read objects for paging files.
|
||||
*/
|
||||
|
||||
#include <osgTXP/trpage_sys.h>
|
||||
|
||||
#include <osgTXP/trpage_geom.h>
|
||||
|
||||
/* Callback base class
|
||||
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; };
|
||||
};
|
||||
|
||||
/* Paging Token
|
||||
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
|
||||
};
|
||||
|
||||
/* Parse class for paging data structures.
|
||||
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;
|
||||
|
||||
// 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;
|
||||
private:
|
||||
// Note: Just how slow is a map<> anyway?
|
||||
// This usage is self-contained and could be replaced with an array
|
||||
#if defined(_WIN32)
|
||||
typedef std::map<trpgToken,trpgr_Token> tok_map;
|
||||
#else
|
||||
typedef std::map<trpgToken,trpgr_Token,std::less<trpgToken> > tok_map;
|
||||
#endif
|
||||
tok_map tokenMap;
|
||||
trpgr_Token defCb; // Call this when no others are called
|
||||
};
|
||||
|
||||
/* Image Read Helper.
|
||||
Used to help read Local and Tile Local textures into
|
||||
memory (in OpenGL format). You're on your own for External
|
||||
textures.
|
||||
If you want to add additional ways to read textures, feel free
|
||||
to subclass this object.
|
||||
*/
|
||||
TX_EXDECL class TX_CLDECL trpgrImageHelper {
|
||||
public:
|
||||
trpgrImageHelper(trpgEndian ness,char *dir,const trpgMatTable &,const trpgTexTable &);
|
||||
virtual ~trpgrImageHelper(void);
|
||||
|
||||
/* Fetch the bytes for the given texture.
|
||||
This is only valid for Local textures.
|
||||
*/
|
||||
virtual bool GetLocalGL(const trpgTexture *,char *data,int32 dataSize);
|
||||
|
||||
/* Fetch the bytes for the given mip level of a given texture.
|
||||
This is only valid for Local textures.
|
||||
*/
|
||||
virtual bool GetMipLevelLocalGL(int miplevel, const trpgTexture *,char *data,int32 dataSize);
|
||||
|
||||
/* Do the lookups to figure out the correct material
|
||||
and Template (or Local) texture for a given Local Material.
|
||||
You'll need this for sizes (among other things).
|
||||
This routine also calculates the total size, including mipmaps if they're there.
|
||||
*/
|
||||
virtual bool GetImageInfoForLocalMat(const trpgLocalMaterial *locMat,
|
||||
const trpgMaterial **retMat,const trpgTexture **retTex,
|
||||
int &totSize);
|
||||
|
||||
/* Fetch the bytes for the given Local Material (and
|
||||
associated texture). This is for Tile Local and
|
||||
Global textures.
|
||||
Data is a pre-allocated buffer for the data and
|
||||
dataSize is the size of that buffer.
|
||||
*/
|
||||
virtual bool GetImageForLocalMat(const trpgLocalMaterial *locMat,char *data,int dataSize);
|
||||
|
||||
/* Same as the one above, just fetch single mip levels
|
||||
*/
|
||||
virtual bool GetMipLevelForLocalMat(int miplevel, const trpgLocalMaterial *locMat,char *data,int dataSize);
|
||||
|
||||
/* Determine the full path of the image in the given
|
||||
trpgTexture class.
|
||||
Only useful for External images.
|
||||
*/
|
||||
virtual bool GetImagePath(const trpgTexture *,char *,int len);
|
||||
|
||||
protected:
|
||||
char dir[1024];
|
||||
trpgEndian ness;
|
||||
const trpgMatTable *matTable;
|
||||
const trpgTexTable *texTable;
|
||||
|
||||
trpgrAppFileCache *texCache;
|
||||
};
|
||||
|
||||
/* 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}
|
||||
*/
|
||||
TX_EXDECL class TX_CLDECL trpgr_Archive : public trpgCheckable {
|
||||
public:
|
||||
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 &);
|
||||
|
||||
// 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;
|
||||
virtual const trpgLightTable *GetLightTable(void) const;
|
||||
virtual const trpgRangeTable *GetRangeTable(void) const;
|
||||
|
||||
// Utility routine to calculate the MBR of a given tile
|
||||
virtual bool trpgGetTileMBR(uint32 x,uint32 y,uint32 lod,
|
||||
trpg3dPoint &ll,trpg3dPoint &ur) const;
|
||||
|
||||
trpgEndian GetEndian(void) const;
|
||||
char* getDir(void){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;
|
||||
trpgLightTable lightTable;
|
||||
trpgRangeTable rangeTable;
|
||||
|
||||
trpgrAppFileCache *tileCache;
|
||||
};
|
||||
|
||||
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}
|
||||
*/
|
||||
TX_EXDECL class TX_CLDECL trpgSceneParser : public trpgr_Parser {
|
||||
friend class trpgSceneHelperPush;
|
||||
friend class trpgSceneHelperPop;
|
||||
friend class trpgSceneHelperDefault;
|
||||
public:
|
||||
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;};
|
||||
|
||||
// List of objects whose children we're working on
|
||||
std::vector<void *> parents;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,238 +0,0 @@
|
||||
/* ************************
|
||||
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 _txpage_scene_h_
|
||||
// {secret}
|
||||
#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.
|
||||
*/
|
||||
|
||||
#include <osgTXP/trpage_geom.h>
|
||||
|
||||
/*
|
||||
{group:Demonstration Scene Graph}
|
||||
*/
|
||||
TX_EXDECL class TX_CLDECL trpgMBR {
|
||||
public:
|
||||
trpgMBR(void);
|
||||
~trpgMBR(void) { };
|
||||
bool isValid(void) const;
|
||||
void Reset(void);
|
||||
void AddPoint(const trpg3dPoint &);
|
||||
void AddPoint(double,double,double);
|
||||
void GetMBR(trpg3dPoint &ll,trpg3dPoint &ur) const;
|
||||
trpg3dPoint GetLL(void) const;
|
||||
trpg3dPoint GetUR(void) const;
|
||||
void Union(const trpgMBR &);
|
||||
// bool Overlap(const trpgMBR &) const;
|
||||
bool Overlap(const trpg2dPoint &ll, const trpg2dPoint &ur) const;
|
||||
// bool Within(const trpg3dPoint &) const
|
||||
bool Within(const trpg2dPoint &) const;
|
||||
protected:
|
||||
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}
|
||||
TX_EXDECL class TX_CLDECL trpgReadNode {
|
||||
public:
|
||||
virtual ~trpgReadNode(void) { };
|
||||
virtual bool isGroupType(void) = 0;
|
||||
virtual int GetType(void) { return type; }
|
||||
virtual trpgMBR GetMBR(void) const { return trpgMBR(); }
|
||||
protected:
|
||||
int type;
|
||||
};
|
||||
|
||||
// Read Group Base
|
||||
// Base class for all group nodes
|
||||
// {group:Demonstration Scene Graph}
|
||||
TX_EXDECL class TX_CLDECL trpgReadGroupBase : public trpgReadNode {
|
||||
public:
|
||||
virtual ~trpgReadGroupBase(void);
|
||||
void AddChild(trpgReadNode *);
|
||||
bool isGroupType(void) { return true; }
|
||||
int GetNumChildren(void) { return children.size(); }
|
||||
trpgReadNode *GetChild(int i) { return children[i]; }
|
||||
trpgMBR GetMBR(void) const;
|
||||
void unRefChild(int i);
|
||||
void unRefChildren(void);
|
||||
protected:
|
||||
trpgMBR mbr;
|
||||
void DeleteChildren(void);
|
||||
std::vector<trpgReadNode *> children;
|
||||
};
|
||||
|
||||
// Read Geometry
|
||||
// The leaf for this scene graph
|
||||
// {group:Demonstration Scene Graph}
|
||||
TX_EXDECL class TX_CLDECL trpgReadGeometry : public trpgReadNode {
|
||||
public:
|
||||
trpgReadGeometry(void) { type = TRPG_GEOMETRY; }
|
||||
~trpgReadGeometry(void) { };
|
||||
bool isGroupType(void) { return false; }
|
||||
trpgGeometry *GetData(void) { return &data; }
|
||||
trpgMBR GetMBR(void) const;
|
||||
protected:
|
||||
trpgMBR mbr;
|
||||
trpgGeometry data;
|
||||
};
|
||||
|
||||
// Read Tile Header
|
||||
// One per tile. Info about what materials and models are used
|
||||
// {group:Demonstration Scene Graph}
|
||||
TX_EXDECL class TX_CLDECL trpgReadTileHeader : public trpgReadNode {
|
||||
public:
|
||||
trpgReadTileHeader(void) { type = TRPGTILEHEADER; }
|
||||
~trpgReadTileHeader(void) { };
|
||||
bool isGroupType(void) { return false; }
|
||||
trpgTileHeader *GetData(void) { return &data; }
|
||||
trpgMBR GetMBR(void) const { trpgMBR mbr; return mbr; };
|
||||
protected:
|
||||
trpgTileHeader data;
|
||||
};
|
||||
|
||||
// Read Group
|
||||
// Simple group structure
|
||||
// {group:Demonstration Scene Graph}
|
||||
TX_EXDECL class TX_CLDECL trpgReadGroup : public trpgReadGroupBase {
|
||||
public:
|
||||
trpgReadGroup(void) { type = TRPG_GROUP; }
|
||||
~trpgReadGroup(void) { };
|
||||
trpgGroup *GetData(void) { return &data; }
|
||||
protected:
|
||||
trpgGroup data;
|
||||
};
|
||||
|
||||
// Read Attach
|
||||
// Should be the top of a higher LOD tile
|
||||
// {group:Demonstration Scene Graph}
|
||||
TX_EXDECL class TX_CLDECL trpgReadAttach : public trpgReadGroupBase {
|
||||
public:
|
||||
trpgReadAttach(void) { type = TRPG_ATTACH; }
|
||||
~trpgReadAttach(void) { };
|
||||
trpgAttach *GetData(void) { return &data; }
|
||||
protected:
|
||||
trpgAttach data;
|
||||
};
|
||||
|
||||
// Read billboard
|
||||
// {group:Demonstration Scene Graph}
|
||||
TX_EXDECL class TX_CLDECL trpgReadBillboard : public trpgReadGroupBase {
|
||||
public:
|
||||
trpgReadBillboard(void) { type = TRPG_BILLBOARD; }
|
||||
~trpgReadBillboard(void) { };
|
||||
trpgBillboard *GetData(void) { return &data; }
|
||||
protected:
|
||||
trpgBillboard data;
|
||||
};
|
||||
|
||||
// Read LOD
|
||||
// {group:Demonstration Scene Graph}
|
||||
TX_EXDECL class TX_CLDECL trpgReadLod : public trpgReadGroupBase {
|
||||
public:
|
||||
trpgReadLod(void) { type = TRPG_LOD; }
|
||||
~trpgReadLod(void) { };
|
||||
trpgLod *GetData(void) { return &data; }
|
||||
protected:
|
||||
trpgLod data;
|
||||
};
|
||||
|
||||
// Read Layer
|
||||
// {group:Demonstration Scene Graph}
|
||||
TX_EXDECL class TX_CLDECL trpgReadLayer : public trpgReadGroupBase {
|
||||
public:
|
||||
trpgReadLayer(void) { type = TRPG_LAYER; }
|
||||
~trpgReadLayer(void) { };
|
||||
trpgLayer *GetData(void) { return &data; }
|
||||
protected:
|
||||
trpgLayer data;
|
||||
};
|
||||
|
||||
// Read Transform
|
||||
// {group:Demonstration Scene Graph}
|
||||
TX_EXDECL class TX_CLDECL trpgReadTransform : public trpgReadGroupBase {
|
||||
public:
|
||||
trpgReadTransform(void) { type = TRPG_TRANSFORM; }
|
||||
~trpgReadTransform(void) { };
|
||||
trpgTransform *GetData(void) { return &data; }
|
||||
protected:
|
||||
trpgTransform data;
|
||||
};
|
||||
|
||||
// Read Model Reference
|
||||
// {group:Demonstration Scene Graph}
|
||||
TX_EXDECL class TX_CLDECL trpgReadModelRef : public trpgReadGroupBase {
|
||||
public:
|
||||
trpgReadModelRef(void) { type = TRPG_MODELREF; }
|
||||
~trpgReadModelRef(void) { };
|
||||
trpgModelRef *GetData(void) { return &data; }
|
||||
protected:
|
||||
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}
|
||||
TX_EXDECL class TX_CLDECL trpgSceneGraphParser : public trpgSceneParser {
|
||||
public:
|
||||
#if defined(_WIN32)
|
||||
typedef std::map<int,trpgReadGroupBase *> GroupMap;
|
||||
#else
|
||||
typedef std::map<int,trpgReadGroupBase *,std::less<int> > GroupMap;
|
||||
#endif
|
||||
trpgSceneGraphParser(void);
|
||||
virtual ~trpgSceneGraphParser(void) { };
|
||||
// Call this instead of Parse()
|
||||
// Deleting it is your responsibility
|
||||
trpgReadNode *ParseScene(trpgReadBuffer &,GroupMap &);
|
||||
trpgReadGroupBase *GetCurrTop(void); // Get the current parent object
|
||||
trpgReadTileHeader *GetTileHeaderRef(void);
|
||||
|
||||
// For use by the helpers only
|
||||
GroupMap *GetGroupMap(void);
|
||||
protected:
|
||||
bool StartChildren(void *);
|
||||
bool EndChildren(void *);
|
||||
trpgReadNode *currTop; // Current parent group
|
||||
trpgReadNode *top; // Top of everything
|
||||
GroupMap *gmap;
|
||||
trpgReadTileHeader tileHead; // Tile header gets read into here
|
||||
};
|
||||
|
||||
/* 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}
|
||||
TX_CPPDECL bool trpgTestArchive(trpgr_Archive &);
|
||||
|
||||
#endif
|
||||
@@ -1,68 +0,0 @@
|
||||
/* ************************
|
||||
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_swap_h_
|
||||
#define trpage_swap_h_
|
||||
|
||||
/* trpage_swap.h
|
||||
Byte swapping utility functions.
|
||||
*/
|
||||
|
||||
#include <osgTXP/trpage_sys.h>
|
||||
|
||||
#include <osgTXP/trpage_io.h>
|
||||
|
||||
// Byte swap and return a short
|
||||
// {group:Byte Ordering Utilities}
|
||||
short trpg_byteswap_short( short number );
|
||||
// Byte swap and return an integer
|
||||
// {group:Byte Ordering Utilities}
|
||||
int trpg_byteswap_int( int number );
|
||||
// Byte swap and return a long
|
||||
// {group:Byte Ordering Utilities}
|
||||
long trpg_byteswap_long( long number );
|
||||
// Byte swap and return a 64 bit long
|
||||
// {group:Byte Ordering Utilities}
|
||||
trpgllong trpg_byteswap_llong ( trpgllong number );
|
||||
// Byte swap a float value into 4 characters. We do it this way to avoid floating point exceptions.
|
||||
// {group:Byte Ordering Utilities}
|
||||
void trpg_byteswap_float_to_4bytes( float number, char result[4] );
|
||||
// Byte swap a double value into 8 characters. We do it this way to avoid floating point exceptions.
|
||||
// {group:Byte Ordering Utilities}
|
||||
void trpg_byteswap_double_to_8bytes( double number, char result[8] );
|
||||
// Swap 4 bytes into a float and return it
|
||||
// {group:Byte Ordering Utilities}
|
||||
float trpg_byteswap_4bytes_to_float( const char result[4] );
|
||||
// Swap 8 bytes into a double and return it
|
||||
// {group:Byte Ordering Utilities}
|
||||
double trpg_byteswap_8bytes_to_double( const char result[8] );
|
||||
// Determine the current CPU's byte ordering
|
||||
// {group:Byte Ordering Utilities}
|
||||
trpgEndian trpg_cpu_byte_order(void);
|
||||
|
||||
// Swap two chars
|
||||
// {group:Byte Ordering Utilities}
|
||||
void trpg_swap_two ( const char *in, char *out );
|
||||
// Swap 4 chars
|
||||
// {group:Byte Ordering Utilities}
|
||||
void trpg_swap_four ( const char *in, char *out );
|
||||
// Swap 8 chars
|
||||
// {group:Byte Ordering Utilities}
|
||||
void trpg_swap_eight ( const char *in, char *out );
|
||||
// Swap sixteen chars
|
||||
// {group:Byte Ordering Utilities}
|
||||
void trpg_swap_sixteen ( const char *in, char *out );
|
||||
|
||||
#endif
|
||||
@@ -1,107 +0,0 @@
|
||||
/* ************************
|
||||
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_sys.h
|
||||
System specific declarations.
|
||||
*/
|
||||
|
||||
#ifndef trpage_sys_h_
|
||||
#define trpage_sys_h_
|
||||
|
||||
#ifndef PATHSEPARATOR
|
||||
#ifdef macintosh
|
||||
#define PATHSEPARATOR ":"
|
||||
#else
|
||||
#define PATHSEPARATOR "/"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(_WIN32)
|
||||
/* *********************
|
||||
System Specific Section.
|
||||
This is currently set up for win32.
|
||||
*********************
|
||||
*/
|
||||
|
||||
#include <windows.h>
|
||||
#include <stdio.h>
|
||||
|
||||
// Microsoft Developer warnings that annoy me
|
||||
#pragma warning ( disable : 4251)
|
||||
#pragma warning ( disable : 4275)
|
||||
#pragma warning ( disable : 4786)
|
||||
|
||||
// Somewhat system independent file deletion macro
|
||||
#define TRPGDELETEFILE(file) DeleteFile((file))
|
||||
|
||||
#ifndef int64
|
||||
// 64 bit long value. Need this for really big files.
|
||||
typedef __int64 int64;
|
||||
#endif
|
||||
|
||||
#else // Unix
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
// Delete a file
|
||||
#define TRPGDELETEFILE(file) remove((file))
|
||||
|
||||
#ifndef int64
|
||||
typedef long long int64;
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
// Basic data types
|
||||
#ifndef uint8
|
||||
typedef unsigned char uint8;
|
||||
#endif
|
||||
#ifndef int32
|
||||
typedef int int32;
|
||||
#endif
|
||||
#ifndef uint32
|
||||
typedef unsigned int uint32;
|
||||
#endif
|
||||
#ifndef float32
|
||||
typedef float float32;
|
||||
#endif
|
||||
#ifndef float64
|
||||
typedef double float64;
|
||||
#endif
|
||||
|
||||
// Note: replace this with your own STL implementation
|
||||
// You can use the Microsoft provided one by deleting the first #include
|
||||
#ifdef USEROGUE
|
||||
#include <txRogueWave.h>
|
||||
#endif
|
||||
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
#if defined(_WIN32) // PJM
|
||||
// Had to take this out because of an iostream conflict
|
||||
// Now referencing everything by std::
|
||||
// using namespace std;
|
||||
#endif
|
||||
|
||||
// We use long longs for addresses within a paging file
|
||||
typedef int64 trpgllong;
|
||||
|
||||
// These are used to export classes from a DLL
|
||||
// Definitely Windows specific
|
||||
#include <osgTXP/trpage_ident.h>
|
||||
#include <osgTXP/trdll.h>
|
||||
|
||||
#endif
|
||||
@@ -1,33 +0,0 @@
|
||||
/* ************************
|
||||
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_sys.h
|
||||
System specific declarations.
|
||||
*/
|
||||
|
||||
#ifndef trpage_util_h_
|
||||
#define trpage_util_h_
|
||||
#include <stdlib.h>
|
||||
#include <osgTXP/trpage_read.h>
|
||||
#include <osgTXP/trpage_write.h>
|
||||
#include <osgTXP/trpage_scene.h>
|
||||
|
||||
TX_EXDECL class TX_CLDECL trpgUtil {
|
||||
public:
|
||||
enum {DoReport = 1<<0,DoCopy = 1<<1, DoTileOpt = 1<<2};
|
||||
int merge(trpgr_Archive &inArch1,trpgr_Archive &inArch2,trpgwArchive &outArch, int flags = 0);
|
||||
};
|
||||
#endif
|
||||
|
||||
@@ -1,301 +0,0 @@
|
||||
/* ************************
|
||||
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 _txpage_write_h_
|
||||
// {secret}
|
||||
#define _txpage_write_h_
|
||||
|
||||
/* trpage_write.h
|
||||
Classes that are used to write paging archives.
|
||||
*/
|
||||
|
||||
#include <osgTXP/trpage_sys.h>
|
||||
#include <osgTXP/trpage_io.h>
|
||||
#include <osgTXP/trpage_swap.h>
|
||||
|
||||
/* Geometry Stats
|
||||
Used with a Geometry Helper to keep track of what go built.
|
||||
{group:Archive Writing}
|
||||
*/
|
||||
TX_EXDECL class TX_CLDECL trpgwGeomStats {
|
||||
public:
|
||||
trpgwGeomStats(void);
|
||||
~trpgwGeomStats(void);
|
||||
|
||||
int totalTri; // Total # of triangles
|
||||
|
||||
int totalQuad; // Total # of quads
|
||||
|
||||
// Add up to totalTri
|
||||
int totalStripTri; // triangles in strips
|
||||
int totalFanTri; // triangles in fans
|
||||
int totalBagTri; // loose triangles
|
||||
|
||||
int numStrip; // Number of distinct strips
|
||||
int numFan; // Number of distinct fans
|
||||
|
||||
int stripStat[15]; // Strip length stats
|
||||
int fanStat[15]; // Fan length stats
|
||||
|
||||
int stripGeom; // Number of seperate trpgGeometry nodes for strips
|
||||
int fanGeom; // Same for fans
|
||||
int bagGeom; // Same for bags
|
||||
|
||||
int stateChanges; // Number of distinct material switches
|
||||
|
||||
// Helper functions
|
||||
inline void AddStripStat(int val) { stripStat[MIN(14,val)]++; totalStripTri += val; totalTri += val; numStrip++;}
|
||||
inline void AddFanStat(int val) { fanStat[MIN(14,val)]++; totalFanTri += val; totalTri += val; numFan++;}
|
||||
inline void AddBagStat(int val) { totalBagTri += val; totalTri += val;}
|
||||
inline void AddQuadStat(int val) { totalQuad++; }
|
||||
};
|
||||
|
||||
/* Geometry Helper
|
||||
Collects up geometry and tries to form triangle strips, fans,
|
||||
and groups of triangles.
|
||||
Right now this looks for a very careful ordering. If that ordering
|
||||
isn't there you won't get useful tristrips or fans. You can, however
|
||||
use this class as a starting point and build something more akin
|
||||
to the geometry builder in Performer.
|
||||
{group:Archive Writing}
|
||||
*/
|
||||
TX_EXDECL class TX_CLDECL trpgwGeomHelper {
|
||||
public:
|
||||
trpgwGeomHelper(void);
|
||||
virtual ~trpgwGeomHelper(void);
|
||||
enum {UseDouble,UseFloat};
|
||||
trpgwGeomHelper(trpgWriteBuffer *,int dataType=UseDouble);
|
||||
void init(trpgWriteBuffer *,int dataType=UseDouble);
|
||||
virtual void SetMode(int); // Takes a trpgGeometry primitive type (triangle by default)
|
||||
virtual void Reset(void);
|
||||
// Start/End polygon definition
|
||||
virtual void StartPolygon(void);
|
||||
virtual void EndPolygon(void);
|
||||
virtual void ResetPolygon(void); // If you change your mind about the current poly
|
||||
// Set the current state
|
||||
// Note: Currently you *must* set all of these
|
||||
virtual void SetColor(trpgColor &);
|
||||
virtual void SetTexCoord(trpg2dPoint &);
|
||||
virtual void SetNormal(trpg3dPoint &);
|
||||
virtual void SetMaterial(int32);
|
||||
// Pull the state info together and add a vertex
|
||||
virtual void AddVertex(trpg3dPoint &);
|
||||
|
||||
// Dump whatever we're doing and move on
|
||||
virtual void FlushGeom(void);
|
||||
|
||||
// Get the Min and Max Z values
|
||||
virtual void GetZMinMax(double &min,double &max);
|
||||
|
||||
// Get statistics for whatever we built
|
||||
trpgwGeomStats *GetStats(void) { return &stats; }
|
||||
protected:
|
||||
int mode;
|
||||
int dataType;
|
||||
trpgWriteBuffer *buf;
|
||||
|
||||
/* Builds strips and fans from the triangle array.
|
||||
We (TERREX) are assuming a certain ordering in our vertex array
|
||||
because we do this optimization elsewhere. This won't work well
|
||||
for anyone else. What you will need to do if you want good
|
||||
performance is to implement a more generic form of this method.
|
||||
All you should have to do is override Optimize(). You've
|
||||
got the triangle arrays and a guarantee that the triangles
|
||||
have the same material. All you really need is a decent fan/strip
|
||||
algorithm.
|
||||
*/
|
||||
virtual void Optimize(void);
|
||||
|
||||
// Reset Triangle arrays
|
||||
virtual void ResetTri(void);
|
||||
|
||||
// Collections of geometry
|
||||
trpgGeometry strips,fans,bags;
|
||||
|
||||
// Temporary data arrays for triangles/quads
|
||||
int32 matTri;
|
||||
std::vector<trpg2dPoint> tex;
|
||||
std::vector<trpg3dPoint> norm,vert;
|
||||
// Data arrays for a polygon
|
||||
int32 matPoly;
|
||||
std::vector<trpg2dPoint> polyTex;
|
||||
std::vector<trpg3dPoint> polyNorm,polyVert;
|
||||
// Single points
|
||||
trpg2dPoint tmpTex;
|
||||
trpg3dPoint tmpNorm;
|
||||
trpgColor tmpCol;
|
||||
|
||||
// Geometry status built up as we go
|
||||
trpgwGeomStats stats;
|
||||
|
||||
// Keeps track of min and max z values
|
||||
double zmin,zmax;
|
||||
};
|
||||
|
||||
/* Image Write Helper.
|
||||
Used to manage textures being added to a TerraPage archive.
|
||||
It can write Local and Tile Local textures and also manages
|
||||
the names of External textures (but you have to write those yourself).
|
||||
*/
|
||||
TX_EXDECL class TX_CLDECL trpgwImageHelper {
|
||||
public:
|
||||
trpgwImageHelper(trpgEndian ness,char *dir,trpgTexTable &);
|
||||
virtual ~trpgwImageHelper(void);
|
||||
|
||||
// Adds an entry to the texture table for an external texture
|
||||
virtual bool AddExternal(char *name,int &texID);
|
||||
|
||||
/* Adds an entry to the texture table for a local texture and
|
||||
writes the data for that texture out to one of our texture
|
||||
archive files.
|
||||
*/
|
||||
virtual bool AddLocal(char *name,trpgTexture::ImageType type,int sizeX,int sizeY,bool isMipmap,char *data,int &texID);
|
||||
|
||||
/* Write a Tile Local texture out to one of our texture archive files.
|
||||
Also creates a texture template, if necessary.
|
||||
Caller is responsible for creating the Tile Local material and
|
||||
placing it in the appropriate tile.
|
||||
*/
|
||||
virtual bool AddTileLocal(char *name,trpgTexture::ImageType type,int sizeX,int sizeY,bool isMipmap,char *data, int &texID,trpgwAppAddress &addr);
|
||||
|
||||
/* Sets the maximum advised length for a texture archive file.
|
||||
Once the length is exceeded, the image write helper will move
|
||||
on to the next tex file.
|
||||
*/
|
||||
virtual void SetMaxTexFileLength(int len);
|
||||
|
||||
/* Texture archive files are managed by this class and will
|
||||
be created as needed. This method will increment to
|
||||
the next texture file.
|
||||
Note: This may create more files than we really need.
|
||||
*/
|
||||
virtual bool IncrementTextureFile(void);
|
||||
|
||||
/* Close the current texture file and go on to one with the
|
||||
given base name. This is used for regenerate.
|
||||
*/
|
||||
virtual bool DesignateTextureFile(int);
|
||||
|
||||
protected:
|
||||
// Write the given texture data into one our local archives
|
||||
bool WriteToArchive(const trpgTexture &tex,char *data,trpgwAppAddress &addr);
|
||||
|
||||
trpgEndian ness;
|
||||
char dir[1024];
|
||||
trpgTexTable *texTable;
|
||||
std::vector<int> texFileIDs;
|
||||
trpgwAppFile *texFile;
|
||||
int maxTexFileLen;
|
||||
};
|
||||
|
||||
/* Paging Archive
|
||||
This is a writeable paging archive.
|
||||
It organizes where things get written and how.
|
||||
{group:Archive Writing}
|
||||
*/
|
||||
TX_EXDECL class TX_CLDECL trpgwArchive : public trpgCheckable {
|
||||
public:
|
||||
// Tiles can be stored as individual files (External) or grouped together (Local)
|
||||
typedef enum {TileLocal,TileExternal} TileMode;
|
||||
|
||||
// Add data to an existing archive
|
||||
trpgwArchive(char *baseDir,char *name);
|
||||
// Start an archive from scratch.
|
||||
trpgwArchive(trpgEndian ness=LittleEndian,TileMode tileMode=TileLocal,int version=2);
|
||||
virtual ~trpgwArchive(void);
|
||||
|
||||
// Set the maximum length for a tile file (if using them)
|
||||
// This is only a suggestion for when to stop appending
|
||||
virtual void SetMaxTileFileLength(int len);
|
||||
|
||||
// Set functions. Have to fill all these out before writing
|
||||
virtual bool SetHeader(const trpgHeader &);
|
||||
virtual bool SetMaterialTable(const trpgMatTable &);
|
||||
virtual bool SetTextureTable(const trpgTexTable &);
|
||||
virtual bool SetModelTable(const trpgModelTable &);
|
||||
virtual bool SetLightTable(const trpgLightTable &);
|
||||
virtual bool SetRangeTable(const trpgRangeTable &);
|
||||
|
||||
// Get functions. If we're doing a regenerate we need to get at these
|
||||
virtual trpgHeader *GetHeader();
|
||||
virtual trpgMatTable *GetMatTable();
|
||||
virtual trpgTexTable *GetTextureTable();
|
||||
virtual trpgModelTable *GetModelTable();
|
||||
virtual trpgLightTable *GetLightTable();
|
||||
virtual trpgRangeTable *GetRangeTable();
|
||||
|
||||
virtual bool IncrementTileFile(void);
|
||||
virtual bool DesignateTileFile(int);
|
||||
|
||||
// Write functions.
|
||||
// For now, the header is written last.
|
||||
|
||||
virtual bool OpenFile(const char *,const char *);
|
||||
virtual void CloseFile(void);
|
||||
virtual bool WriteHeader(void);
|
||||
virtual bool WriteTile(unsigned int,unsigned int,unsigned int,float zmin,float zmax,
|
||||
const trpgMemWriteBuffer *,const trpgMemWriteBuffer *);
|
||||
// virtual bool WriteModel(unsigned int,trpgMemWriteBuffer &);
|
||||
|
||||
bool isValid(void) const;
|
||||
char* getDir(void){return dir;};
|
||||
|
||||
// Used to keep track of which tiles are in which file
|
||||
class TileFileEntry {
|
||||
public:
|
||||
int x,y,lod; // Identifying info for tile
|
||||
float zmin,zmax;
|
||||
uint32 offset; // Offset into file
|
||||
};
|
||||
protected:
|
||||
// Set if we're adding to an existing archive
|
||||
bool isRegenerate;
|
||||
|
||||
class TileFile {
|
||||
public:
|
||||
int id;
|
||||
std::vector<TileFileEntry> tiles;
|
||||
};
|
||||
|
||||
trpgEndian ness,cpuNess;
|
||||
int version;
|
||||
// Fed in from the outside
|
||||
char dir[1024]; // Directory where we're doing all this
|
||||
|
||||
// These are passed in
|
||||
|
||||
trpgHeader header;
|
||||
trpgMatTable matTable;
|
||||
trpgTexTable texTable;
|
||||
trpgModelTable modelTable;
|
||||
trpgLightTable lightTable;
|
||||
trpgRangeTable rangeTable;
|
||||
|
||||
trpgTileTable tileTable;
|
||||
|
||||
int numX,numY,numLod;
|
||||
TileMode tileMode;
|
||||
|
||||
trpgwAppFile *tileFile;
|
||||
int tileFileCount;
|
||||
|
||||
std::vector<TileFile> tileFiles;
|
||||
|
||||
int maxTileFileLen;
|
||||
|
||||
FILE *fp;
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user