Added Paging TerraPage loader and osgTXP library.

This commit is contained in:
Don BURNS
2002-11-24 21:36:05 +00:00
parent 89b2575ffe
commit 12e922bc3c
55 changed files with 2578 additions and 175 deletions

View File

@@ -93,6 +93,7 @@ DEMOS_DIRS = \
osgparticle\
osgprerender\
osgshadowtexture\
osgtxp\
osgreflect\
osgscribe\
osgsequence\

View File

@@ -119,7 +119,7 @@ make_osg()
print_attr $INST_PLUGINS 755 >> $TOPDIR/dist/RPM/OpenSceneGraph.spec
print_attr $INST_DEMOS 755 >> $TOPDIR/dist/RPM/OpenSceneGraph.spec
rpm -bb --clean $TOPDIR/dist/RPM/OpenSceneGraph.spec
rpmbuild -bb --clean $TOPDIR/dist/RPM/OpenSceneGraph.spec
mv /usr/src/redhat/RPMS/i386/OpenSceneGraph-$REV-$REL.i386.rpm dist/RPM
}

View File

@@ -1,11 +1,11 @@
Summary: A C++ scene graph API on OpenGL for real time graphics
Name: OpenSceneGraph
Version: 0.9.1
Version: 0.9.2
Release: 1
Copyright: LGPL
Group: Graphics
Source: OpenSceneGraph-0.9.1.tar.gz
Source: OpenSceneGraph-0.9.2.tar.gz
URL: http://www.openscenegraph.org
Packager: Don Burns
@@ -26,7 +26,7 @@ graphics rendering, protability, and extensibility
%install
cd /usr/src/redhat/BUILD/OpenSceneGraph-0.9.1
cd /usr/src/redhat/BUILD/OpenSceneGraph-0.9.2
tar cvf - . | tar xvfC - /
# ---------------------
@@ -37,14 +37,17 @@ tar cvf - . | tar xvfC - /
%attr(755, root, root) /usr/local/lib/libosgGA.so
%attr(755, root, root) /usr/local/lib/libosgGLUT.so
%attr(755, root, root) /usr/local/lib/libosgParticle.so
%attr(755, root, root) /usr/local/lib/libosgSim.so
%attr(755, root, root) /usr/local/lib/libosg.so
%attr(755, root, root) /usr/local/lib/libosgText.so
%attr(755, root, root) /usr/local/lib/libosgUtil.so
%attr(755, root, root) /usr/local/lib/osgPlugins/osgdb_3ds.so
%attr(755, root, root) /usr/local/lib/osgPlugins/osgdb_ac.so
%attr(755, root, root) /usr/local/lib/osgPlugins/osgdb_bmp.so
%attr(755, root, root) /usr/local/lib/osgPlugins/osgdb_dw.so
%attr(755, root, root) /usr/local/lib/osgPlugins/osgdb_dx.so
%attr(755, root, root) /usr/local/lib/osgPlugins/osgdb_flt.so
%attr(755, root, root) /usr/local/lib/osgPlugins/osgdb_geo.so
%attr(755, root, root) /usr/local/lib/osgPlugins/osgdb_gif.so
%attr(755, root, root) /usr/local/lib/osgPlugins/osgdb_iv.so
%attr(755, root, root) /usr/local/lib/osgPlugins/osgdb_jpeg.so
@@ -64,6 +67,8 @@ tar cvf - . | tar xvfC - /
%attr(755, root, root) /usr/local/lib/osgPlugins/osgdb_tiff.so
%attr(755, root, root) /usr/local/lib/osgPlugins/osgdb_txp.so
%attr(755, root, root) /usr/local/lib/osgPlugins/osgdb_zip.so
%attr(755, root, root) /usr/share/OpenSceneGraph/bin/memleaks.log
%attr(755, root, root) /usr/share/OpenSceneGraph/bin/osganimate
%attr(755, root, root) /usr/share/OpenSceneGraph/bin/osgbillboard
%attr(755, root, root) /usr/share/OpenSceneGraph/bin/osgcallback
%attr(755, root, root) /usr/share/OpenSceneGraph/bin/osgclip
@@ -71,11 +76,14 @@ tar cvf - . | tar xvfC - /
%attr(755, root, root) /usr/share/OpenSceneGraph/bin/osgconv
%attr(755, root, root) /usr/share/OpenSceneGraph/bin/osgcopy
%attr(755, root, root) /usr/share/OpenSceneGraph/bin/osgcube
%attr(755, root, root) /usr/share/OpenSceneGraph/bin/osgcubemap
%attr(755, root, root) /usr/share/OpenSceneGraph/bin/osggeodemo
%attr(755, root, root) /usr/share/OpenSceneGraph/bin/osggeometry
%attr(755, root, root) /usr/share/OpenSceneGraph/bin/osghangglide
%attr(755, root, root) /usr/share/OpenSceneGraph/bin/osghud
%attr(755, root, root) /usr/share/OpenSceneGraph/bin/osgimpostor
%attr(755, root, root) /usr/share/OpenSceneGraph/bin/osglight
%attr(755, root, root) /usr/share/OpenSceneGraph/bin/osglightpoint
%attr(755, root, root) /usr/share/OpenSceneGraph/bin/osgmultitexture
%attr(755, root, root) /usr/share/OpenSceneGraph/bin/osgoccluder
%attr(755, root, root) /usr/share/OpenSceneGraph/bin/osgparticle
@@ -83,7 +91,10 @@ tar cvf - . | tar xvfC - /
%attr(755, root, root) /usr/share/OpenSceneGraph/bin/osgreflect
%attr(755, root, root) /usr/share/OpenSceneGraph/bin/osgscribe
%attr(755, root, root) /usr/share/OpenSceneGraph/bin/osgsequence
%attr(755, root, root) /usr/share/OpenSceneGraph/bin/osgshadowtexture
%attr(755, root, root) /usr/share/OpenSceneGraph/bin/osgshape
%attr(755, root, root) /usr/share/OpenSceneGraph/bin/osgstereoimage
%attr(755, root, root) /usr/share/OpenSceneGraph/bin/osgteapot
%attr(755, root, root) /usr/share/OpenSceneGraph/bin/osgtext
%attr(755, root, root) /usr/share/OpenSceneGraph/bin/osgtexture
%attr(755, root, root) /usr/share/OpenSceneGraph/bin/osgtexture1D

View File

@@ -1,11 +1,11 @@
Summary: A C++ scene graph API on OpenGL for real time graphics
Name: OpenSceneGraph_dev
Version: 0.9.1
Version: 0.9.2
Release: 1
Copyright: LGPL
Group: Graphics
Source: OpenSceneGraph_dev-0.9.1.tar.gz
Source: OpenSceneGraph_dev-0.9.2.tar.gz
URL: http://www.openscenegraph.org
Packager: Don Burns
@@ -26,7 +26,7 @@ graphics rendering, protability, and extensibility
%install
cd /usr/src/redhat/BUILD/OpenSceneGraph_dev-0.9.1
cd /usr/src/redhat/BUILD/OpenSceneGraph_dev-0.9.2
tar cvf - . | tar xvfC - /
# ---------------------
@@ -41,6 +41,7 @@ tar cvf - . | tar xvfC - /
%attr(755, root, root) /usr/local/include/osg/BoundingBox
%attr(755, root, root) /usr/local/include/osg/BoundingSphere
%attr(755, root, root) /usr/local/include/osg/BoundsChecking
%attr(755, root, root) /usr/local/include/osg/buffered_value
%attr(755, root, root) /usr/local/include/osg/Camera
%attr(755, root, root) /usr/local/include/osg/ClearNode
%attr(755, root, root) /usr/local/include/osg/ClipNode
@@ -96,9 +97,10 @@ tar cvf - . | tar xvfC - /
%attr(755, root, root) /usr/local/include/osg/Point
%attr(755, root, root) /usr/local/include/osg/PolygonMode
%attr(755, root, root) /usr/local/include/osg/PolygonOffset
%attr(755, root, root) /usr/local/include/osg/PolygonStipple
%attr(755, root, root) /usr/local/include/osg/Polytope
%attr(755, root, root) /usr/local/include/osg/PositionAttitudeTransform
%attr(755, root, root) /usr/local/include/osg/Primitive
%attr(755, root, root) /usr/local/include/osg/PrimitiveSet
%attr(755, root, root) /usr/local/include/osg/Projection
%attr(755, root, root) /usr/local/include/osg/Quat
%attr(755, root, root) /usr/local/include/osg/Referenced
@@ -106,6 +108,8 @@ tar cvf - . | tar xvfC - /
%attr(755, root, root) /usr/local/include/osg/Sequence
%attr(755, root, root) /usr/local/include/osg/ShadeModel
%attr(755, root, root) /usr/local/include/osg/ShadowVolumeOccluder
%attr(755, root, root) /usr/local/include/osg/Shape
%attr(755, root, root) /usr/local/include/osg/ShapeDrawable
%attr(755, root, root) /usr/local/include/osg/State
%attr(755, root, root) /usr/local/include/osg/StateAttribute
%attr(755, root, root) /usr/local/include/osg/StateSet
@@ -146,6 +150,7 @@ tar cvf - . | tar xvfC - /
%attr(755, root, root) /usr/local/include/osgDB/Registry
%attr(755, root, root) /usr/local/include/osgDB/Version
%attr(755, root, root) /usr/local/include/osgDB/WriteFile
%attr(755, root, root) /usr/local/include/osgGA/AnimationPathManipulator
%attr(755, root, root) /usr/local/include/osgGA/CameraManipulator
%attr(755, root, root) /usr/local/include/osgGA/DriveManipulator
%attr(755, root, root) /usr/local/include/osgGA/Export
@@ -193,20 +198,30 @@ tar cvf - . | tar xvfC - /
%attr(755, root, root) /usr/local/include/osgParticle/Shooter
%attr(755, root, root) /usr/local/include/osgParticle/VariableRateCounter
%attr(755, root, root) /usr/local/include/osgParticle/Version
%attr(755, root, root) /usr/local/include/osgSim/BlinkSequence
%attr(755, root, root) /usr/local/include/osgSim/Export
%attr(755, root, root) /usr/local/include/osgSim/LightPoint
%attr(755, root, root) /usr/local/include/osgSim/LightPointDrawable
%attr(755, root, root) /usr/local/include/osgSim/LightPointNode
%attr(755, root, root) /usr/local/include/osgSim/Sector
%attr(755, root, root) /usr/local/include/osgSim/Version
%attr(755, root, root) /usr/local/include/osgText/Export
%attr(755, root, root) /usr/local/include/osgText/Font
%attr(755, root, root) /usr/local/include/osgText/Paragraph
%attr(755, root, root) /usr/local/include/osgText/Text
%attr(755, root, root) /usr/local/include/osgText/Version
%attr(755, root, root) /usr/local/include/osgUtil/AppVisitor
%attr(755, root, root) /usr/local/include/osgUtil/CubeMapGenerator
%attr(755, root, root) /usr/local/include/osgUtil/CullVisitor
%attr(755, root, root) /usr/local/include/osgUtil/DepthSortedBin
%attr(755, root, root) /usr/local/include/osgUtil/DisplayListVisitor
%attr(755, root, root) /usr/local/include/osgUtil/DisplayRequirementsVisitor
%attr(755, root, root) /usr/local/include/osgUtil/Export
%attr(755, root, root) /usr/local/include/osgUtil/HalfWayMapGenerator
%attr(755, root, root) /usr/local/include/osgUtil/HighlightMapGenerator
%attr(755, root, root) /usr/local/include/osgUtil/InsertImpostorsVisitor
%attr(755, root, root) /usr/local/include/osgUtil/IntersectVisitor
%attr(755, root, root) /usr/local/include/osgUtil/Optimizer
%attr(755, root, root) /usr/local/include/osgUtil/ReflectionMapGenerator
%attr(755, root, root) /usr/local/include/osgUtil/RenderBin
%attr(755, root, root) /usr/local/include/osgUtil/RenderGraph
%attr(755, root, root) /usr/local/include/osgUtil/RenderLeaf
@@ -219,80 +234,5 @@ tar cvf - . | tar xvfC - /
%attr(755, root, root) /usr/local/include/osgUtil/TransformCallback
%attr(755, root, root) /usr/local/include/osgUtil/TriStripVisitor
%attr(755, root, root) /usr/local/include/osgUtil/Version
%attr(755, root, root) /usr/share/OpenSceneGraph/src/demos/osgbillboard/Makefile
%attr(755, root, root) /usr/share/OpenSceneGraph/src/demos/osgbillboard/osgbillboard.cpp
%attr(755, root, root) /usr/share/OpenSceneGraph/src/demos/osgcallback/Makefile
%attr(755, root, root) /usr/share/OpenSceneGraph/src/demos/osgcallback/osgcallback.cpp
%attr(755, root, root) /usr/share/OpenSceneGraph/src/demos/osgclip/Makefile
%attr(755, root, root) /usr/share/OpenSceneGraph/src/demos/osgclip/osgclip.cpp
%attr(755, root, root) /usr/share/OpenSceneGraph/src/demos/osgcluster/broadcaster.cpp
%attr(755, root, root) /usr/share/OpenSceneGraph/src/demos/osgcluster/broadcaster.h
%attr(755, root, root) /usr/share/OpenSceneGraph/src/demos/osgcluster/Makefile
%attr(755, root, root) /usr/share/OpenSceneGraph/src/demos/osgcluster/osgcluster.cpp
%attr(755, root, root) /usr/share/OpenSceneGraph/src/demos/osgcluster/receiver.cpp
%attr(755, root, root) /usr/share/OpenSceneGraph/src/demos/osgcluster/receiver.h
%attr(755, root, root) /usr/share/OpenSceneGraph/src/demos/osgconv/Makefile
%attr(755, root, root) /usr/share/OpenSceneGraph/src/demos/osgconv/OrientationConverter.cpp
%attr(755, root, root) /usr/share/OpenSceneGraph/src/demos/osgconv/OrientationConverter.h
%attr(755, root, root) /usr/share/OpenSceneGraph/src/demos/osgconv/osgconv.cpp
%attr(755, root, root) /usr/share/OpenSceneGraph/src/demos/osgcopy/Makefile
%attr(755, root, root) /usr/share/OpenSceneGraph/src/demos/osgcopy/osgcopy.cpp
%attr(755, root, root) /usr/share/OpenSceneGraph/src/demos/osgcube/Makefile
%attr(755, root, root) /usr/share/OpenSceneGraph/src/demos/osgcube/osgcube.cpp
%attr(755, root, root) /usr/share/OpenSceneGraph/src/demos/osggeometry/Makefile
%attr(755, root, root) /usr/share/OpenSceneGraph/src/demos/osggeometry/osggeometry.cpp
%attr(755, root, root) /usr/share/OpenSceneGraph/src/demos/osghangglide/base.cpp
%attr(755, root, root) /usr/share/OpenSceneGraph/src/demos/osghangglide/GliderManipulator.cpp
%attr(755, root, root) /usr/share/OpenSceneGraph/src/demos/osghangglide/GliderManipulator.h
%attr(755, root, root) /usr/share/OpenSceneGraph/src/demos/osghangglide/hat.cpp
%attr(755, root, root) /usr/share/OpenSceneGraph/src/demos/osghangglide/hat.h
%attr(755, root, root) /usr/share/OpenSceneGraph/src/demos/osghangglide/Makefile
%attr(755, root, root) /usr/share/OpenSceneGraph/src/demos/osghangglide/osghangglide.cpp
%attr(755, root, root) /usr/share/OpenSceneGraph/src/demos/osghangglide/ReaderWriterFLY.cpp
%attr(755, root, root) /usr/share/OpenSceneGraph/src/demos/osghangglide/sky.cpp
%attr(755, root, root) /usr/share/OpenSceneGraph/src/demos/osghangglide/tank.cpp
%attr(755, root, root) /usr/share/OpenSceneGraph/src/demos/osghangglide/terrain_coords.h
%attr(755, root, root) /usr/share/OpenSceneGraph/src/demos/osghangglide/terrain.cpp
%attr(755, root, root) /usr/share/OpenSceneGraph/src/demos/osghangglide/terrain_normals.h
%attr(755, root, root) /usr/share/OpenSceneGraph/src/demos/osghangglide/terrain_texcoords.h
%attr(755, root, root) /usr/share/OpenSceneGraph/src/demos/osghangglide/trees.cpp
%attr(755, root, root) /usr/share/OpenSceneGraph/src/demos/osghud/Makefile
%attr(755, root, root) /usr/share/OpenSceneGraph/src/demos/osghud/osghud.cpp
%attr(755, root, root) /usr/share/OpenSceneGraph/src/demos/osgimpostor/Makefile
%attr(755, root, root) /usr/share/OpenSceneGraph/src/demos/osgimpostor/osgimpostor.cpp
%attr(755, root, root) /usr/share/OpenSceneGraph/src/demos/osglight/Makefile
%attr(755, root, root) /usr/share/OpenSceneGraph/src/demos/osglight/osglight.cpp
%attr(755, root, root) /usr/share/OpenSceneGraph/src/demos/osgmultitexture/Makefile
%attr(755, root, root) /usr/share/OpenSceneGraph/src/demos/osgmultitexture/osgmultitexture.cpp
%attr(755, root, root) /usr/share/OpenSceneGraph/src/demos/osgoccluder/Makefile
%attr(755, root, root) /usr/share/OpenSceneGraph/src/demos/osgoccluder/osgoccluder.cpp
%attr(755, root, root) /usr/share/OpenSceneGraph/src/demos/osgparticle/Makefile
%attr(755, root, root) /usr/share/OpenSceneGraph/src/demos/osgparticle/osgparticle.cpp
%attr(755, root, root) /usr/share/OpenSceneGraph/src/demos/osgprerender/Makefile
%attr(755, root, root) /usr/share/OpenSceneGraph/src/demos/osgprerender/osgprerender.cpp
%attr(755, root, root) /usr/share/OpenSceneGraph/src/demos/osgreflect/Makefile
%attr(755, root, root) /usr/share/OpenSceneGraph/src/demos/osgreflect/osgreflect.cpp
%attr(755, root, root) /usr/share/OpenSceneGraph/src/demos/osgscribe/Makefile
%attr(755, root, root) /usr/share/OpenSceneGraph/src/demos/osgscribe/osgscribe.cpp
%attr(755, root, root) /usr/share/OpenSceneGraph/src/demos/osgsequence/Makefile
%attr(755, root, root) /usr/share/OpenSceneGraph/src/demos/osgsequence/osgsequence.cpp
%attr(755, root, root) /usr/share/OpenSceneGraph/src/demos/osgstereoimage/Makefile
%attr(755, root, root) /usr/share/OpenSceneGraph/src/demos/osgstereoimage/osgstereoimage.cpp
%attr(755, root, root) /usr/share/OpenSceneGraph/src/demos/osgtext/main.cpp
%attr(755, root, root) /usr/share/OpenSceneGraph/src/demos/osgtext/Makefile
%attr(755, root, root) /usr/share/OpenSceneGraph/src/demos/osgtexture1D/Makefile
%attr(755, root, root) /usr/share/OpenSceneGraph/src/demos/osgtexture1D/osgtexture1D.cpp
%attr(755, root, root) /usr/share/OpenSceneGraph/src/demos/osgtexture2D/Makefile
%attr(755, root, root) /usr/share/OpenSceneGraph/src/demos/osgtexture2D/osgtexture2D.cpp
%attr(755, root, root) /usr/share/OpenSceneGraph/src/demos/osgtexture3D/Makefile
%attr(755, root, root) /usr/share/OpenSceneGraph/src/demos/osgtexture3D/osgtexture3D.cpp
%attr(755, root, root) /usr/share/OpenSceneGraph/src/demos/osgunittests/Makefile
%attr(755, root, root) /usr/share/OpenSceneGraph/src/demos/osgunittests/osgunittests.cpp
%attr(755, root, root) /usr/share/OpenSceneGraph/src/demos/osgversion/Makefile
%attr(755, root, root) /usr/share/OpenSceneGraph/src/demos/osgversion/osgversion.cpp
%attr(755, root, root) /usr/share/OpenSceneGraph/src/demos/osgviews/Makefile
%attr(755, root, root) /usr/share/OpenSceneGraph/src/demos/osgviews/osgviews.cpp
%attr(755, root, root) /usr/share/OpenSceneGraph/src/demos/sgv/Makefile
%attr(755, root, root) /usr/share/OpenSceneGraph/src/demos/sgv/sgv.cpp
%attr(755, root, root) /usr/share/OpenSceneGraph/src/Make/makedefs
%attr(755, root, root) /usr/share/OpenSceneGraph/src/Make/makerules

29
include/osgTXP/Export.h Normal file
View File

@@ -0,0 +1,29 @@
//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
#include <osg/MemoryManager>
#endif

View File

@@ -25,10 +25,13 @@
#include "trpage_sys.h"
#include "trpage_read.h"
#include <osgTXP/trpage_sys.h>
#include <osgTXP/trpage_read.h>
#include <osgTXP/trpage_managers.h>
#include "TrPageParser.h"
#include <osgTXP/TrPageParser.h>
#include <osgTXP/Export.h>
#include <string>
#include <vector>
@@ -37,7 +40,7 @@
namespace txp
{
/// main class for loading terrapage archives
class TrPageArchive : public trpgr_Archive
class OSGTXP_EXPORT TrPageArchive : public trpgr_Archive
{
public:
TrPageArchive();
@@ -67,12 +70,26 @@ namespace txp
*/
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 &center);
protected:
/// This class does most of the actual parsing.
std::auto_ptr<TrPageParser> parse;
@@ -81,6 +98,7 @@ namespace txp
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

View File

@@ -31,13 +31,22 @@
#include <osg/Group>
#include <osg/StateSet>
#include <vector>
#include "trpage_read.h"
#include <osgTXP/trpage_read.h>
#include <osgTXP/Export.h>
namespace txp
{
class TrPageArchive;
class TrPageParser : public trpgSceneParser
// 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);
@@ -62,18 +71,17 @@ namespace txp
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 group list
// 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; }
std::vector< osg::Group *> *GetGroupList() { return &groupList; }
// Set the maximum number of groups (once per archive)
void SetMaxGroupID(int);
/// TXP 2.0 - local materials
void LoadLocalMaterials();
void SetMaxGroupID(int maxGroupID);
protected:
bool StartChildren(void *);
bool EndChildren(void *);
@@ -88,7 +96,7 @@ namespace txp
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::Group *> groupList;
std::vector<osg::ref_ptr<osg::Node> >* models;
};

View File

@@ -0,0 +1,59 @@
/* **************************************************************************
* 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 _TRPAGEVIEWER_H_
#define _TRPAGEVIEWER_H_
#include <osg/Light>
#include <osg/NodeVisitor>
#include <osg/Geode>
#include <osg/Timer>
#include <osg/DisplaySettings>
#include <osgGLUT/Viewer>
#include <osgUtil/SceneView>
#include <osgGLUT/Window>
#include <string>
#include <osgTXP/Export.h>
#include <osgTXP/trPagePageManager.h>
namespace txp
{
/* Paging Viewer
Variant of the regular viewer which knows to call
the Page Manager at the beginning of each app() phase.
*/
class OSGTXP_EXPORT PagingViewer : public osgGLUT::Viewer {
public:
PagingViewer();
bool Init(OSGPageManager *,txp::OSGPageManager::ThreadMode = txp::OSGPageManager::ThreadNone);
// called on each frame redraw..return the time in ms for each operation.
virtual float app(unsigned int viewport);
// The default Viewer resets the cameras at the beginning of the run()
// This is annoying.
bool run();
protected:
OSGPageManager *pageManage;
};
};
#endif

View File

@@ -0,0 +1,35 @@
#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

View File

@@ -0,0 +1,154 @@
/* **************************************************************************
* 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>
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;
#endif
#if !defined(ThreadID)
/*
// Stubs to make it compile
typedef int ThreadID;
typedef int ThreadMutex;
typedef int ThreadEvent;
*/
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

View File

@@ -21,10 +21,10 @@
These are the objects that get read from and written to archives.
*/
#include "trpage_sys.h"
#include <osgTXP/trpage_sys.h>
#include "trpage_io.h"
#include "trpage_swap.h"
#include <osgTXP/trpage_io.h>
#include <osgTXP/trpage_swap.h>
// Forward declarations

View File

@@ -20,7 +20,7 @@
Token definitions and basic classes.
*/
#include "trpage_sys.h"
#include <osgTXP/trpage_sys.h>
// Macros we may need
#ifndef MIN

View File

@@ -0,0 +1,378 @@
/* ************************
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

View File

@@ -16,7 +16,7 @@
#ifndef trpage_print_h_
#define trpage_print_h_
#include "trpage_read.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).

View File

@@ -21,9 +21,9 @@
Classes used to represent read objects for paging files.
*/
#include "trpage_sys.h"
#include <osgTXP/trpage_sys.h>
#include "trpage_geom.h"
#include <osgTXP/trpage_geom.h>
/* Callback base class
Called when a given token is found.

View File

@@ -26,7 +26,7 @@
for how to read TerraPage format into your own scene graph.
*/
#include "trpage_geom.h"
#include <osgTXP/trpage_geom.h>
/*
{group:Demonstration Scene Graph}

View File

@@ -20,9 +20,9 @@
Byte swapping utility functions.
*/
#include "trpage_sys.h"
#include <osgTXP/trpage_sys.h>
#include "trpage_io.h"
#include <osgTXP/trpage_io.h>
// Byte swap and return a short
// {group:Byte Ordering Utilities}

View File

@@ -101,7 +101,7 @@ typedef int64 trpgllong;
// These are used to export classes from a DLL
// Definitely Windows specific
#include "trpage_ident.h"
#include "trdll.h"
#include <osgTXP/trpage_ident.h>
#include <osgTXP/trdll.h>
#endif

View File

@@ -0,0 +1,33 @@
/* ************************
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

View File

@@ -21,9 +21,9 @@
Classes that are used to write paging archives.
*/
#include "trpage_sys.h"
#include "trpage_io.h"
#include "trpage_swap.h"
#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.

18
src/Demos/osgtxp/Makefile Normal file
View File

@@ -0,0 +1,18 @@
TOPDIR = ../../..
include $(TOPDIR)/Make/makedefs
CXXFILES =\
osgtxp.cpp\
LIBS += $(OSG_LIBS) $(GLUT_LIB) $(GL_LIBS) $(X_LIBS) $(OTHER_LIBS)
LIBS += -losgTXP
INSTFILES = \
$(CXXFILES)\
Makefile.inst=Makefile
EXEC = osgtxp
include $(TOPDIR)/Make/makerules

170
src/Demos/osgtxp/osgtxp.cpp Normal file
View File

@@ -0,0 +1,170 @@
#include <osg/GL>
#include <osgGLUT/glut>
#include <osgGLUT/Viewer>
#include <osg/Node>
#include <osg/Notify>
#include <osgUtil/Optimizer>
#include <osgDB/Registry>
#include <osgDB/ReadFile>
#include <osgGA/TrackballManipulator>
#include <osgGA/FlightManipulator>
#include <osgGA/DriveManipulator>
#include <osgTXP/TrPageArchive.h>
#include <osgTXP/TrPageViewer.h>
void write_usage(std::ostream& out,const std::string& name)
{
out << std::endl;
out <<"usage:"<< std::endl;
out <<" "<<name<<" [options] infile1 [infile2 ...]"<< std::endl;
out << std::endl;
out <<"options:"<< std::endl;
out <<" -l libraryName - load plugin of name libraryName"<< std::endl;
out <<" i.e. -l osgdb_pfb"<< std::endl;
out <<" Useful for loading reader/writers which can load"<< std::endl;
out <<" other file formats in addition to its extension."<< std::endl;
out <<" -e extensionName - load reader/wrter plugin for file extension"<< std::endl;
out <<" i.e. -e pfb"<< std::endl;
out <<" Useful short hand for specifying full library name as"<< std::endl;
out <<" done with -l above, as it automatically expands to"<< std::endl;
out <<" the full library name appropriate for each platform."<< std::endl;
out <<std::endl;
out <<" -stereo - switch on stereo rendering, using the default of,"<< std::endl;
out <<" ANAGLYPHIC or the value set in the OSG_STEREO_MODE "<< std::endl;
out <<" environmental variable. See doc/stereo.html for "<< std::endl;
out <<" further details on setting up accurate stereo "<< std::endl;
out <<" for your system. "<< std::endl;
out <<" -stereo ANAGLYPHIC - switch on anaglyphic(red/cyan) stereo rendering."<< std::endl;
out <<" -stereo QUAD_BUFFER - switch on quad buffered stereo rendering."<< std::endl;
out <<std::endl;
out <<" -stencil - use a visual with stencil buffer enabled, this "<< std::endl;
out <<" also allows the depth complexity statistics mode"<< std::endl;
out <<" to be used (press 'p' three times to cycle to it)."<< std::endl;
out <<" -f - start with a full screen, borderless window." << std::endl;
out << std::endl;
}
using namespace txp;
int main( int argc, char **argv )
{
// initialize the GLUT
glutInit( &argc, argv );
if (argc<2)
{
write_usage(std::cout,argv[0]);
return 0;
}
// create the commandline args.
std::vector<std::string> commandLine;
for(int i=1;i<argc;++i) commandLine.push_back(argv[i]);
// initialize the viewer.
PagingViewer *viewer = new PagingViewer();
viewer->setWindowTitle(argv[0]);
// configure the viewer from the commandline arguments, and eat any
// parameters that have been matched.
viewer->readCommandLine(commandLine);
// configure the plugin registry from the commandline arguments, and
// eat any parameters that have been matched.
osgDB::readCommandLine(commandLine);
// Initialize the TXP database
bool loadAll = false;
bool threadIt = false;
std::string fileName;
for(std::vector<std::string>::iterator itr=commandLine.begin();
itr!=commandLine.end();
++itr)
{
if ((*itr)[0]!='-')
{
fileName = (*itr);
} else {
// Look for switches we want
if (!strcasecmp((*itr).c_str(),"-loadall")) {
loadAll = true;
continue;
}
if (!strcasecmp((*itr).c_str(),"-thread")) {
threadIt = true;
continue;
}
}
}
if (fileName.empty()) {
fprintf(stderr,"No TerraPage file specified on command line.\n");
return 1;
}
// Open the TXP database
TrPageArchive *txpArchive = new TrPageArchive();
if (!txpArchive->OpenFile(fileName.c_str())) {
fprintf(stderr,"Couldn't load TerraPage archive %s.\n",fileName.c_str());
return 1;
}
// Note: Should be checking the return values
txpArchive->LoadMaterials();
// txpArchive->LoadModels();
// Might need a page manager if we're paging
OSGPageManager *pageManager = new OSGPageManager(txpArchive);
osg::Group *rootNode=NULL;
if (loadAll) {
// Load the whole scenegraph
rootNode = txpArchive->LoadAllTiles();
if (!rootNode) {
fprintf(stderr,"Couldn't load whole TerraPage archive %s.\n",fileName.c_str());
return 1;
}
// add a viewport to the viewer and attach the scene graph.
viewer->addViewport( rootNode );
} else {
viewer->Init(pageManager,(threadIt ? txp::OSGPageManager::ThreadFree : txp::OSGPageManager::ThreadNone));
rootNode = new osg::Group();
viewer->addViewport(rootNode);
}
// run optimization over the scene graph
// osgUtil::Optimizer optimzer;
// optimzer.optimize(rootnode);
// register trackball, flight and drive.
viewer->registerCameraManipulator(new osgGA::TrackballManipulator);
viewer->registerCameraManipulator(new osgGA::FlightManipulator);
viewer->registerCameraManipulator(new osgGA::DriveManipulator);
// Recenter the camera to the middle of the database
osg::Vec3 center;
txpArchive->GetCenter(center); center[2] += 200;
osgUtil::SceneView *sceneView = viewer->getViewportSceneView(0);
osg::Camera *camera = sceneView->getCamera();
osg::Vec3 eyePt = center;
eyePt[0] -= 1000;
osg::Vec3 upVec( 0, 0, 1 );
camera->setLookAt(eyePt,center,upVec);
// open the viewer window.
viewer->open();
// fire up the event loop.
viewer->run();
// Close things down
delete pageManager;
delete txpArchive;
delete viewer;
return 0;
}

View File

@@ -23,15 +23,24 @@ CXXFILES =\
trpage_compat.cpp\
trpage_light.cpp\
trpage_pparse.cpp\
trpage_print.cpp
trpage_print.cpp\
trpage_managers.cpp\
trPagePageManager.cpp\
trpage_print_parse.cpp\
trpage_util.cpp\
TrPageViewer.cpp\
INC += -I$(THISDIR)
INC += -I$(THISDIR)
LIBS += $(OSG_LIBS) $(OTHER_LIBS)
TARGET_BASENAME = txp
PLUGIN_TARGET_BASENAME = txp
include $(TOPDIR)/Make/cygwin_plugin_def
PLUGIN = $(PLUGIN_PREFIX)$(TARGET_BASENAME).$(PLUGIN_EXT)
PLUGIN = $(PLUGIN_PREFIX)$(PLUGIN_TARGET_BASENAME).$(PLUGIN_EXT)
LIB_TARGET_BASENAME=osgTXP
LIB = $(LIB_PREFIX)$(LIB_TARGET_BASENAME).$(LIB_EXT)
include $(TOPDIR)/Make/makerules

View File

@@ -1,5 +1,5 @@
#include "ReaderWriterTXP.h"
#include "TrPageArchive.h"
#include <osgTXP/TrPageArchive.h>
#include <osg/Group>
#include <osg/Object>

View File

@@ -26,7 +26,7 @@
#ifndef READER_WRITER_TXP_H
#define READER_WRITER_TXP_H
#include "trpage_sys.h"
#include <osgTXP/trpage_sys.h>
#include <osg/Object>
#include <osg/Node>

View File

@@ -1,5 +1,9 @@
#include "TrPageArchive.h"
#include "TrPageParser.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <osgTXP/TrPageArchive.h>
#include <osgTXP/TrPageParser.h>
#include <osg/AlphaFunc>
#include <osg/Group>
@@ -19,14 +23,12 @@
#include <osgDB/WriteFile>
#include <osgDB/FileNameUtils>
#include "trpage_geom.h"
#include "trpage_read.h"
#include "trpage_write.h"
#include "trpage_scene.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 <stdlib.h>
#include <stdio.h>
#include <string.h>
using namespace txp;
using namespace osg;
@@ -39,7 +41,8 @@ using namespace osg;
TrPageArchive::TrPageArchive()
: trpgr_Archive()
, parse(new TrPageParser(this))
, parse(new TrPageParser(this))
, buf(GetEndian())
{
}
@@ -85,6 +88,29 @@ bool TrPageArchive::OpenFile(const char* file)
return true;
}
/* Calculate the center of the database (including Z)
*/
void TrPageArchive::GetCenter(Vec3 &center)
{
trpg2dPoint sw,ne;
const trpgHeader *head = GetHeader();
const trpgTileTable *tileTable = GetTileTable();
head->GetExtents(sw,ne);
trpg2dPoint tileSize;
head->GetTileSize(0,tileSize);
center[0] = (ne.x+sw.x)/2.0;
center[1] = (ne.y+sw.y)/2.0;
trpg2iPoint loc;
loc.x = int((center[0]-sw.x)/tileSize.x);
loc.y = int((center[1]-sw.y)/tileSize.y);
trpgwAppAddress foo;
float zmin,zmax;
tileTable->GetTile(loc.x, loc.y,0,foo,zmin,zmax);
center[2] = (zmin+zmax)/2.0;
}
// load textures and materials
// TODO : multitexturing
void TrPageArchive::LoadMaterials()
@@ -174,6 +200,8 @@ void TrPageArchive::LoadMaterials()
// TODO : multitextuting
// also note that multitexturing in terrapage can came from two sides
// - multiple textures per material, and multiple materials per geometry
// Note: Only in theory. The only type you'll encounter is multiple
// materials per polygon.
if( numMatTex )
{
Material *osg_material = new Material;
@@ -337,6 +365,7 @@ bool TrPageArchive::LoadModels()
return true;
}
// Group* TrPageArchive::LoadTile(int x,int y,int lod,int &parentID,vector<GroupIDInfo> **groupList)
Group* TrPageArchive::LoadTile(int x,int y,int lod,int &parentID)
{
trpgMemReadBuffer buf(GetEndian());
@@ -352,10 +381,71 @@ Group* TrPageArchive::LoadTile(int x,int y,int lod,int &parentID)
// This is where you would page in textures and models
}
// Also return the list of IDs and their groups we read in for this tile
// *groupList = parse->GetGroupList();
// That's it
return tile;
}
// Group* TrPageArchive::LoadTile(Group *rootNode,trpgPageManager *pageManage,trpgManagedTile *tile,vector<)
Group* TrPageArchive::LoadTile(Group *rootNode,
trpgPageManager * /*pageManage*/,
trpgManagedTile *tile,osg::Group **parentNode)
{
int x,y,lod;
tile->GetTileLoc(x,y,lod);
std::vector<osg::Group *> *groupList = parse->GetGroupList();
// Fetch the tile data (but don't parse it)
if (!ReadTile(x,y,lod,buf))
return NULL;
// Now parse it
Group *gTile = parse->ParseScene(buf, m_gstates, m_models);
if (gTile && rootNode) {
// Hook it into its parent
int parentID = parse->GetParentID();
if (parentID >= 0) {
(*groupList)[parentID]->addChild(gTile);
} else
rootNode->addChild(gTile);
// Note: Need to page in the textures
// They're being forced in during the parse right now
}
if (parentNode) {
int parentID = parse->GetParentID();
if (parentID >= 0)
*parentNode = (*groupList)[parentID];
else
*parentNode = rootNode;
}
// Add the tile to the local data in the managed tile
tile->SetLocalData(gTile);
return gTile;
}
bool TrPageArchive::UnLoadTile(trpgPageManager * /*pageManage*/,
trpgManagedTile *tile)
{
// The local tile data will have the group we need
Group *gTile = (Group *)tile->GetLocalData();
if (gTile) {
// Remove it from the parent list
// We're only expecting on parent
const Group::ParentList &pList = gTile->getParents();
if (pList.size() != 1)
return false;
pList[0]->removeChild(gTile);
} else
return false;
return true;
}
//----------------------------------------------------------------------------
Group* TrPageArchive::LoadAllTiles()
{
@@ -372,6 +462,7 @@ Group* TrPageArchive::LoadAllTiles()
trpg2iPoint tileSize;
// The group list is used to map parent IDs to pfGroup nodes
//std::vector<Group *> groupList;
std::vector<Group *> *groupList = parse->GetGroupList();
for (int nl=0;nl<numLod;nl++)
@@ -401,7 +492,7 @@ Group* TrPageArchive::LoadAllTiles()
else
{
// Added below some other node
(*groupList)[parentID]->addChild(tile);
(*groupList)[parentID]->addChild(tile);
}
}
}

View File

@@ -19,7 +19,7 @@
* All Rights Reserved.
*
*****************************************************************************/
#include "trpage_sys.h"
#include <osgTXP/trpage_sys.h>
#include <osg/AlphaFunc>
#include <osg/Group>
#include <osg/Material>
@@ -35,8 +35,8 @@
#include <osg/Notify>
#include "TrPageParser.h"
#include "TrPageArchive.h"
#include <osgTXP/TrPageParser.h>
#include <osgTXP/TrPageArchive.h>
/*
#include <stdlib.h>
#include <stdio.h>
@@ -121,6 +121,7 @@ Texture2D* txp::GetLocalTexture(trpgrImageHelper& image_helper, trpgLocalMateria
if(gltype!=(GLenum)-1)
{
osg_texture = new Texture2D();
osg_texture->setInternalFormatMode(internalFormat);
Image* image = new Image;
@@ -132,7 +133,7 @@ Texture2D* txp::GetLocalTexture(trpgrImageHelper& image_helper, trpgLocalMateria
{
int32 size = s.x*s.y*depth;
// int32 size = const_cast<trpgTexture*>(tex)->MipLevelSize(1) ;
data = (char*)::malloc(size);
data = (char *)::malloc(size);
if(locmat)
image_helper.GetImageForLocalMat(locmat,data,size);
@@ -148,7 +149,7 @@ Texture2D* txp::GetLocalTexture(trpgrImageHelper& image_helper, trpgLocalMateria
int32 size = tex->CalcTotalSize();
trpgTexture* tmp_tex = const_cast<trpgTexture*>(tex);
data = (char*)::malloc(size);
data = (char *)::malloc(size);
if(locmat)
image_helper.GetImageForLocalMat(locmat,data,size);
@@ -172,6 +173,8 @@ Texture2D* txp::GetLocalTexture(trpgrImageHelper& image_helper, trpgLocalMateria
image->setMipmapData(mipmaps);
}
// delete [] data;
// image->unref();
// AAAARRRGH! TOOK ME 2 DAYS TO FIGURE IT OUT
// EVERY IMAGE HAS TO HAVE UNIQUE NAME FOR OPTIMIZER NOT TO OPTIMIZE IT OFF
//
@@ -216,7 +219,7 @@ void* geomRead::Parse(trpgToken /*tok*/,trpgReadBuffer &buf)
Vec3Array* vertices = new Vec3Array(numVert);
// Get vertices
geom.GetVertices(&(vertices->front()));
geom.GetVertices((float *)&(vertices->front()));
// Turn the trpgGeometry into something Performer can understand
Geometry *geometry = 0L;
@@ -431,6 +434,7 @@ void* billboardRead::Parse(trpgToken /*tok*/,trpgReadBuffer &buf)
Group* osg_Group = new Group;
int type;
bill.GetType(type);
// Note: Must deal with the billboard type here
if( type == trpgBillboard::Group )
{
// Create a new Performer group
@@ -489,7 +493,8 @@ void* lodRead::Parse(trpgToken /*tok*/,trpgReadBuffer &buf)
Vec3 osg_Center;
osg_Center[0] = center.x; osg_Center[1] = center.y; osg_Center[2] = center.z;
osg_Lod->setCenter(osg_Center);
osg_Lod->setRange(0,minRange,maxRange);
osg_Lod->setRange(0,0.0, minRange);
osg_Lod->setRange(1,minRange, maxRange );
// Our LODs are binary so we need to add a group under this LOD and attach stuff
// to that instead of the LOD
@@ -535,7 +540,12 @@ void *modelRefRead::Parse(trpgToken /*tok*/,trpgReadBuffer &buf)
);
// Note: Array check before you do this
Node *osg_Model = (*parse->GetModels())[modelID].get();
Node *osg_Model = NULL;
std::vector<osg::ref_ptr<osg::Node> >*modelList = parse->GetModels();
if( modelList->size() > size_t(modelID) )
{
//(*parse->GetModels())[modelID].get();
osg_Model = (*modelList)[modelID].get();
// Create the SCS and position the model
if (osg_Model) {
MatrixTransform *scs = new MatrixTransform();
@@ -546,6 +556,7 @@ void *modelRefRead::Parse(trpgToken /*tok*/,trpgReadBuffer &buf)
if (top)
top->addChild(scs);
}
}
return (void *) 1;
}

View File

@@ -0,0 +1,188 @@
#if defined(_MSC_VER)
#pragma warning( disable : 4786 )
#endif
#include <osg/GL>
#include <osgGLUT/glut>
#include <stdlib.h>
#if (!defined(WIN32) && !defined(macintosh)) || defined(__CYGWIN__)
#include <unistd.h>
#include <sys/time.h>
#endif
#include <stdio.h>
#include <osg/Math>
#include <osg/Statistics>
#include <string>
#include <osgGLUT/Viewer>
#include <osgGLUT/GLUTEventAdapter>
#include <osg/Switch>
#include <osg/Billboard>
#include <osg/LOD>
#include <osg/Light>
#include <osg/LightSource>
#include <osg/Geode>
#include <osg/Group>
#include <osg/NodeVisitor>
#include <osg/LineSegment>
#include <osg/PolygonMode>
#include <osg/Texture2D>
#include <osg/LightModel>
#include <osg/ShadeModel>
#include <osg/Notify>
#include <osg/CollectOccludersVisitor>
#include <osg/Fog>
#include <osgDB/WriteFile>
#include <osgUtil/IntersectVisitor>
#include <osgUtil/DisplayListVisitor>
#include <osgUtil/SmoothingVisitor>
#include <osgUtil/TriStripVisitor>
#include <osgUtil/DisplayRequirementsVisitor>
#include <osgGA/TrackballManipulator>
#include <osgGA/FlightManipulator>
#include <osgGA/DriveManipulator>
#include <osg/Version>
#include <osgUtil/Version>
#ifdef WIN32
#define USE_FLTK
#define USE_GLUT
#endif
#include <osgTXP/TrPageArchive.h>
#include <osgTXP/TrPageViewer.h>
/*
#if defined(WIN32) && !defined(__CYGWIN__)
#include <sys/timeb.h>
#else
#endif
*/
using namespace osg;
using namespace osgUtil;
using namespace osgGLUT;
using namespace osgGA;
using namespace std;
using namespace txp;
PagingViewer::PagingViewer() : Viewer()
{
pageManage = NULL;
}
bool PagingViewer::Init(OSGPageManager *in_manage,OSGPageManager::ThreadMode threadMode)
{
pageManage = in_manage;
// Start up the thread if needed
if (threadMode != OSGPageManager::ThreadNone) {
ThreadID newThread;
pageManage->StartThread(threadMode,newThread);
}
return true;
}
/* App call
This replaces the app() call for the base viewer.
In this one, we ask the page manager to load stuff in.
*/
float PagingViewer::app(unsigned int viewport)
{
osg::Timer_t beforeApp = _timer.tick();
// update the camera manipulator.
osg::ref_ptr<GLUTEventAdapter> ea = osgNew GLUTEventAdapter;
ea->adaptFrame(_frameStamp->getReferenceTime());
#if 0 // This is the old way...
if (_viewportList[viewport]._eventHandler.valid() && _viewportList[viewport]._eventHandler->handle(*ea,*this))
{
// event handler handle this call.
}
else if (_viewportList[viewport]._cameraManipulator->handle(*ea,*this))
{
// osg::notify(osg::INFO) << "Handled update frame"<< std::endl;
}
#else // this is the new way
bool handled = false;
for (EventHandlerList::iterator eh = _viewportList[viewport]._eventHandlerList.begin(); eh != _viewportList[viewport]._eventHandlerList.end();
eh++ )
{
if ( eh->valid() )
{
if ( (*eh)->handle(*ea,*this) )
{
handled = true;
break;
}
}
}
// if ( !handled ) {
_viewportList[viewport]._cameraManipulator->handle(*ea,*this);
// }
#endif
// Update the paging
if (pageManage) {
int numTile = 1;
osgUtil::SceneView *sceneView = getViewportSceneView(viewport);
osg::Camera *camera = sceneView->getCamera();
const Vec3 &eyePt = camera->getEyePoint();
double eyeX = eyePt[0];
double eyeY = eyePt[1];
/* If we're in ThreadFree mode, merge in whatever may be ready.
If we're in non-thread mode, load in the given number of tiles (maximum).
*/
if (pageManage->GetThreadMode() == OSGPageManager::ThreadFree) {
pageManage->MergeUpdateThread((osg::Group *)sceneView->getSceneData());
pageManage->UpdatePositionThread(eyeX,eyeY);
} else {
pageManage->UpdateNoThread((osg::Group *)sceneView->getSceneData(),eyeX,eyeY,numTile);
}
}
// do app traversal.
getViewportSceneView(viewport)->setFrameStamp(_frameStamp.get());
getViewportSceneView(viewport)->app();
osg::Timer_t beforeCull = _timer.tick();
#if 0
// We're going for 66ms per frame
float targetFrameTime = 30;
static osg::Timer_t lastCull = 0;
if (lastCull > 0) {
float deltaT = _timer.delta_m(lastCull,beforeCull);
int extraTime = targetFrameTime - deltaT;
if (extraTime > 0)
Sleep(extraTime);
}
lastCull = beforeCull;
#endif
return _timer.delta_m(beforeApp,beforeCull);
}
bool PagingViewer::run()
{
updateFrameTick();
return Window::run();
}

View File

@@ -0,0 +1,413 @@
#include <stdlib.h>
#include <stdio.h>
#if defined(_WIN32)
#include <windows.h>
#include <conio.h>
#else
#include <unistd.h>
#include <pthread.h>
#endif
#include <osgTXP/TrPageArchive.h>
#include <osgTXP/trPagePageManager.h>
#include <osgTXP/trpage_print.h>
#include <osg/Group>
#include <osg/Object>
#include <osg/Node>
#include <osg/Notify>
#include <osgDB/Registry>
#include <osgDB/FileUtils>
#include <iostream>
using namespace txp;
using namespace osg;
OSGPageManager::OSGPageManager(TrPageArchive *in_arch,trpgPageManager *in_pageManage)
{
archive = in_arch;
pageManage = in_pageManage;
if (!in_arch)
throw 1;
if (pageManage)
pageManageOurs = false;
else {
pageManage = new trpgPageManager();
pageManage->SetPageDistFactor(1.2);
pageManage->Init(archive);
pageManageOurs = true;
}
// Location info we'll need later
const trpgHeader *head = archive->GetHeader();
trpg2dPoint sw,ne;
head->GetExtents(sw,ne);
originX = sw.x;
originY = sw.y;
threadMode = ThreadNone;
}
OSGPageManager::~OSGPageManager()
{
if (threadMode != ThreadNone)
EndThread();
if (pageManageOurs)
delete pageManage;
pageManage = NULL;
}
/* Update
Bring the paging up to date based on the given location.
The location is in TerraPage's coordinate system, but must
still be adjusted to the SW corner.
*/
bool OSGPageManager::UpdateNoThread(osg::Group *rootNode,double locX,double locY,int numTile)
{
// Adjust to TerraPage coordinates
double lx = locX-originX;
double ly = locY-originY;
/* Do that paging thing:
- Tell the manager the new location
- Iterate over the unloads
- Iterate over the loads
*/
trpg2dPoint loc;
loc.x = lx;
loc.y = ly;
if (pageManage->SetLocation(loc)) {
// printf("Location (%f,%f) resulted in changes.",loc.x,loc.y);
// trpgFilePrintBuffer printBuf(stdout);
// pageManage->Print(printBuf);
}
// Do the unloads
trpgManagedTile *tile=NULL;
while ((tile = pageManage->GetNextUnload())) {
archive->UnLoadTile(pageManage,tile);
pageManage->AckUnload();
};
// Decide how many loads to do per frame
int loadCount=0;
// Do the loads
while ((tile = pageManage->GetNextLoad())) {
archive->LoadTile(rootNode,pageManage,tile);
pageManage->AckLoad();
loadCount++;
if (numTile > 0 && loadCount >= numTile)
break;
};
return true;
}
// Mutex lock function
// --- Either thread ---
void osgLockMutex(ThreadMutex &mtx)
{
#if defined (_WIN32)
WaitForSingleObject( mtx, INFINITE);
#else
pthread_mutex_lock( &mtx );
#endif
}
// Mutex unlock function
// --- Either thread ---
void osgUnLockMutex(ThreadMutex &mtx)
{
#if defined (_WIN32)
ReleaseMutex(mtx);
#else
pthread_mutex_unlock( &mtx );
#endif
}
// Wait for Event
// --- Either thread (only used in paging thread) ---
void osgWaitEvent(ThreadEvent &ev)
{
#if defined (_WIN32)
WaitForSingleObject( ev, INFINITE);
#else
ev.wait();
#endif
}
// Set Event (i.e. notify the other thread something's up)
// --- Either thread (only used in main thread) ---
void osgSetEvent(ThreadEvent &ev)
{
#if defined (_WIN32)
SetEvent(ev);
#else
ev.release();
#endif
}
// Windows specific thread function.
// This just fires up our own loop
// --- Paging Thread ---
#if defined (_WIN32)
DWORD WINAPI ThreadFunc( LPVOID lpParam )
{
OSGPageManager *myPager = (OSGPageManager *)lpParam;
myPager->ThreadLoop();
return 0;
}
#else // Pthreads, cause Pthreads is a POSIX standard and is EVERYWHERE else
void *ThreadFunc( void *data )
{
OSGPageManager *myPager = static_cast<OSGPageManager *>(data);
myPager->ThreadLoop();
return 0L;
}
#endif
/* Start Thread
This initialized
--- Main Thread ---
*/
bool OSGPageManager::StartThread(ThreadMode mode,ThreadID &newThread)
{
positionValid = false;
#if defined(_WIN32)
// Create the event we'll use to wake up the pager thread when the location changes
locationChangeEvent = CreateEvent(NULL,false,false,"Location Change Event");
// Create the mutexes we'll need later
changeListMutex = CreateMutex(NULL,false,"Change List Mutex");
locationMutex = CreateMutex(NULL,false,"Location Mutex");
{
// Create the thread
DWORD dwThreadId=0;
LPVOID dwThrdParam = (LPVOID) this;
newThread = CreateThread(
NULL, // default security attributes
0, // use default stack size
ThreadFunc, // thread function
dwThrdParam, // argument to thread function
0, // use default creation flags
&dwThreadId); // returns the thread identifier
}
// Note: Should be optional
// Set the priority low so this is only called when the other thread is idle
// if (!SetThreadPriority(newThread,THREAD_PRIORITY_IDLE))
// fprintf(stderr,"Couldn't set paging thread priority.\n");
// Was successfull
if (newThread != NULL)
threadMode = mode;
#endif
//locationChangeEvent is self-initialized.
pthread_mutex_init( &changeListMutex, 0L );
pthread_mutex_init( &locationMutex, 0L );
if( pthread_create( &newThread, 0L, ThreadFunc, (void *)this ) == 0 )
threadMode = mode;
return threadMode != ThreadNone;
}
/* End Thread
Note: Do this
*/
bool OSGPageManager::EndThread()
{
#ifdef WIN32
#else
// Need a handle to the thread ID here.
//pthread_cancel( ?newThread? );
#endif
return true;
}
/* Thread Loop
This method is the main loop for the pager when it's
working in its own thread.
--- Paging Thread ---
*/
bool OSGPageManager::ThreadLoop()
{
// Note: Only works for free running thread
if (threadMode != ThreadFree)
throw 1;
bool done = false;
bool pagingActive = false;
while (!done) {
/* Here's how we do it:
Wait for position change
Update manager w/ position
Form delete list
Load tile (if needed)
Add tile to merge list
*/
// Position has already changed or we'll wait for it to do so
osgWaitEvent(locationChangeEvent);
double myLocX,myLocY;
{
osgLockMutex(locationMutex);
myLocX = locX;
myLocY = locY;
osgUnLockMutex(locationMutex);
}
// Pass the new location on to page manager
trpg2dPoint loc;
loc.x = myLocX;
loc.y = myLocY;
if (pageManage->SetLocation(loc) || pagingActive) {
// If there were changes, process them
// Form the delete list first
trpgManagedTile *tile=NULL;
std::vector<osg::Group *> unhook;
while (tile = pageManage->GetNextUnload()) {
unhook.push_back((Group *)tile->GetLocalData());
pageManage->AckUnload();
}
// Tell the main thread to unhook tiles
// and get the groups to delete as well.
std::vector <osg::Group *> nextDelete;
{
osgLockMutex(changeListMutex);
// Add to the unhook list
for (unsigned int ti=0;ti<unhook.size();ti++)
toUnhook.push_back(unhook[ti]);
// Also get the list of deletions while we're here
nextDelete = toDelete;
toDelete.clear();
osgUnLockMutex(changeListMutex);
}
// Unreference whatever we're supposed to delete
for (unsigned int gi=0;gi<nextDelete.size();gi++)
nextDelete[gi]->unref();
// Now do a single load
tile = pageManage->GetNextLoad();
osg::Group *tileGroup=NULL;
pagingActive = false;
if (tile) {
osg::Group *parentNode = NULL;
tileGroup = archive->LoadTile(NULL,pageManage,tile,&parentNode);
pageManage->AckLoad();
if (tileGroup) {
// Make an extra reference to it because we want it back for deletion
tileGroup->ref();
} else {
int x,y,lod;
tile->GetTileLoc(x,y,lod);
fprintf(stderr,"Failed to load tile (%d,%d,%d)\n",x,y,lod);
}
// Now add this tile to the merge list
if (tileGroup) {
osgLockMutex(changeListMutex);
toMerge.push_back(tileGroup);
toMergeParent.push_back(parentNode);
osgUnLockMutex(changeListMutex);
}
// We're not necessarily done paging, we're just handing control back
// It's likely we'll be back here
pagingActive = true;
}
}
}
return true;
}
/* Update Position Thread
This method updates the location for the paging thread to use.
--- Main Thread ---
*/
void OSGPageManager::UpdatePositionThread(double inLocX,double inLocY)
{
// Update the position
{
// Get the location mutex
osgLockMutex(locationMutex);
positionValid = true;
locX = inLocX-originX;
locY = inLocY-originY;
osgUnLockMutex(locationMutex);
}
// Notify the paging thread there's been a position update
osgSetEvent(locationChangeEvent);
}
/* Merge Updates
Merge in the new tiles and unhook the ones we'll be deleting.
Actually, we'll hand these back to the paging thread for deletion.
--- Main Thread ---
*/
bool OSGPageManager::MergeUpdateThread(osg::Group *rootNode)
{
std::vector<osg::Group *> mergeList;
std::vector<osg::Group *> mergeParentList;
std::vector<osg::Group *> unhookList;
// Make local copies of the merge and unhook lists
{
osgLockMutex(changeListMutex);
mergeList = toMerge;
mergeParentList = toMergeParent;
unhookList = toUnhook;
toMerge.clear();
toMergeParent.clear();
toUnhook.clear();
osgUnLockMutex(changeListMutex);
}
// Do the unhooking first
for (unsigned int ui=0;ui<unhookList.size();ui++) {
osg::Group *unhookMe = unhookList[ui];
// Look for its parent(s)
// Only expecting one, but it doesn't matter
const osg::Node::ParentList &parents = unhookMe->getParents();
for (unsigned int pi=0;pi<parents.size();pi++) {
osg::Group *parent = parents[pi];
parent->removeChild(unhookMe);
}
}
// Put the unhooked things on the list to delete
{
osgLockMutex(changeListMutex);
for (unsigned int di=0;di<unhookList.size();di++)
toDelete.push_back(unhookList[di]);
osgUnLockMutex(changeListMutex);
}
// Do the merging last
{
for (unsigned int mi=0;mi<mergeList.size();mi++) {
osg::Group *mergeMe = mergeList[mi];
osg::Group *parent = mergeParentList[mi];
if (parent)
parent->addChild(mergeMe);
else
rootNode->addChild(mergeMe);
}
}
return true;
}

View File

@@ -20,7 +20,7 @@
#include <stdlib.h>
#include <stdio.h>
#include "trpage_io.h"
#include <osgTXP/trpage_io.h>
/* Checkable
This is just a class that checks validity.

View File

@@ -24,9 +24,9 @@
*/
#include "trpage_geom.h"
#include "trpage_read.h"
#include "trpage_compat.h"
#include <osgTXP/trpage_geom.h>
#include <osgTXP/trpage_read.h>
#include <osgTXP/trpage_compat.h>
/* Old short Material definition from 1.0.
{secret}

View File

@@ -24,8 +24,8 @@
#include <stdio.h>
#include <string.h>
#include "trpage_geom.h"
#include "trpage_read.h"
#include <osgTXP/trpage_geom.h>
#include <osgTXP/trpage_read.h>
#include <osg/Vec3>

View File

@@ -23,8 +23,8 @@
to the header definition.
*/
#include "trpage_geom.h"
#include "trpage_read.h"
#include <osgTXP/trpage_geom.h>
#include <osgTXP/trpage_read.h>
/* Write Header class
Fill it in and write it out.

View File

@@ -24,8 +24,8 @@
#include <stdio.h>
#include <string.h>
#include "trpage_geom.h"
#include "trpage_read.h"
#include <osgTXP/trpage_geom.h>
#include <osgTXP/trpage_read.h>
#if defined(_WIN32)
#define ALIGNMENT_WORKAROUND false

View File

@@ -26,6 +26,6 @@
#include <stdlib.h>
#include <stdio.h>
#include "trdll.h"
#include <osgTXP/trdll.h>
TXDUMMY_DLL_MAIN

View File

@@ -0,0 +1,810 @@
/* ************************
Copyright Terrain Experts Inc.
Terrain Experts Inc (TERREX) reserves all rights to this source code
unless otherwise specified in writing by the President of TERREX.
This copyright may be updated in the future, in which case that version
supercedes this one.
-------------------
Terrex Experts Inc.
4400 East Broadway #314
Tucson, AZ 85711
info@terrex.com
Tel: (520) 323-7990
************************
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <osgTXP/trpage_sys.h>
#include <osgTXP/trpage_geom.h>
#include <osgTXP/trpage_read.h>
#include <osgTXP/trpage_print.h>
#include <osgTXP/trpage_managers.h>
/* Managed Tile class.
Check the header file for details.
*/
trpgManagedTile::trpgManagedTile()
{
isLoaded = false;
x = y = -1;
lod = -1;
localData = NULL;
}
void trpgManagedTile::Reset()
{
// Null out the local material data
for (int i=0;i<int(localMatData.size());i++)
localMatData[i] = NULL;
groupIDs.resize(0);
isLoaded = false;
x = y = -1;
lod = -1;
localData = NULL;
}
bool trpgManagedTile::ParseTileHeader(trpgReadBuffer &buf)
{
isLoaded = false;
if (!tileHead.Read(buf))
return false;
int numLoc;
tileHead.GetNumLocalMaterial(numLoc);
localMatData.resize(numLoc);
// The tile considers itself loaded with just
// the header. This isn't true as far as the paging
// manager is concerned.
isLoaded = true;
return true;
}
bool trpgManagedTile::IsLoaded()
{
return isLoaded;
}
bool trpgManagedTile::SetTileLoc(int inX,int inY,int inLod)
{
x = inX; y = inY;
if (inLod < 0)
return false;
lod = inLod;
return true;
}
bool trpgManagedTile::GetTileLoc(int &retx,int &rety,int &retLod)
{
retx = x; rety = y; retLod = lod;
return true;
}
const trpgTileHeader *trpgManagedTile::GetTileHead()
{
return &tileHead;
}
const std::vector<trpgLocalMaterial> *trpgManagedTile::GetLocMatList() const
{
return tileHead.GetLocalMaterialList();
}
const trpgLocalMaterial *trpgManagedTile::GetLocMaterial(int id) const
{
const std::vector<trpgLocalMaterial> *matList;
matList = tileHead.GetLocalMaterialList();
if (id <0 || id >= int(matList->size()))
return NULL;
return &(*matList)[id];
}
void trpgManagedTile::SetLocalData(void *inData)
{
localData = inData;
}
void *trpgManagedTile::GetLocalData() const
{
return localData;
}
bool trpgManagedTile::SetMatData(int id,void *info)
{
if (id < 0 || id >= int(localMatData.size()))
return false;
localMatData[id] = info;
return true;
}
void *trpgManagedTile::GetMatData(int id) const
{
if (id < 0 || id >= int(localMatData.size()))
return NULL;
return localMatData[id];
}
void trpgManagedTile::AddGroupID(int id)
{
groupIDs.push_back(id);
}
const std::vector<int> *trpgManagedTile::GetGroupIDs() const
{
return &groupIDs;
}
void trpgManagedTile::Print(trpgPrintBuffer &buf)
{
char line[1024];
sprintf(line,"x = %d, y = %d, lod = %d",x,y,lod); buf.prnLine(line);
// Note: Should print the rest too, probably.
}
/* Page Manager LOD Page Info class.
Used by the page manager to keep track of paging information
for a single terrain LOD. See the header file for details.
*/
trpgPageManager::LodPageInfo::LodPageInfo()
{
valid = false;
pageDist = 0.0;
cell.x = cell.y = -100;
}
trpgPageManager::LodPageInfo::~LodPageInfo()
{
Clean();
}
void trpgPageManager::LodPageInfo::Clean()
{
// Clean up managed tile structures
int i;
for (i=0;i<int(load.size());i++)
if (load[i])
delete load[i];
load.resize(0);
for (i=0;i<int(unload.size());i++)
if (unload[i])
delete unload[i];
unload.resize(0);
for (i=0;i<int(current.size());i++)
if (current[i])
delete current[i];
current.resize(0);
for (i=0;i<int(freeList.size());i++)
delete freeList[i];
freeList.resize(0);
activeLoad = false;
activeUnload = false;
}
bool trpgPageManager::LodPageInfo::Init(trpgr_Archive *archive, int myLod, double scale)
{
Clean();
lod = myLod;
// In theory we could have a negative scale, but I don't
// really want to deal with that.
if (scale < 0) scale = 0.0;
// Need some size and shape info about our terrain LOD
const trpgHeader *head = archive->GetHeader();
head->GetTileSize(lod,cellSize);
head->GetLodRange(lod,pageDist);
head->GetLodSize(lod,lodSize);
pageDist *= scale;
// Area of interest size (in cells)
aoiSize.x = (int)(pageDist/cellSize.x);
aoiSize.y = (int)(pageDist/cellSize.y);
/* Make a guess as to how many tiles we might have loaded
in at any given time. Give ourselves 15% extra room.
From the area of interest in cells, we can guess the max
number of tiles (aka cells) we'll have loaded in at once.
Note that the AOI size is only ahead, so it must be doubled.
*/
maxNumTiles = (int)(1.15*(2*aoiSize.x+1)*(2*aoiSize.y+1));
// Allocate 'em
for (int i=0;i<maxNumTiles;i++) {
trpgManagedTile *tile = new trpgManagedTile();
freeList.push_back(tile);
}
// We still don't have a position yet
valid = true;
return true;
}
bool trpgPageManager::LodPageInfo::SetLocation(trpg2dPoint &loc)
{
// Calculate the cell this falls into
trpg2iPoint newCell;
newCell.x = (int)(loc.x/cellSize.x);
newCell.y = (int)(loc.y/cellSize.y);
// Snap to the database border
if (newCell.x < 0) newCell.x = 0;
if (newCell.y < 0) newCell.y = 0;
if (newCell.x >= lodSize.x) newCell.x = lodSize.x-1;
if (newCell.y >= lodSize.y) newCell.y = lodSize.y-1;
// Nothing to page. Done.
if (newCell.x == cell.x && newCell.y == cell.y)
return false;
// Cell has changed. Update.
cell = newCell;
Update();
return true;
}
trpgManagedTile *trpgPageManager::LodPageInfo::GetNextLoad()
{
// Can only load one tile at a time
if (activeLoad)
return NULL;
// Clear any NULLs at the beginning
while (load.size() && !load[0])
load.pop_front();
if (load.size() > 0) {
activeLoad = true;
return load[0];
}
return NULL;
}
void trpgPageManager::LodPageInfo::AckLoad()
{
if (activeLoad) {
current.push_back(load[0]);
load.pop_front();
}
activeLoad = false;
}
trpgManagedTile *trpgPageManager::LodPageInfo::GetNextUnload()
{
// Can only unload one tile at a time
if (activeUnload)
return NULL;
// Clear any NULLs at the beginning
while (unload.size() && !unload[0])
unload.pop_front();
if (unload.size() > 0) {
activeUnload = true;
return unload[0];
}
return NULL;
}
void trpgPageManager::LodPageInfo::AckUnload()
{
if (activeUnload) {
trpgManagedTile *tile = unload[0];
tile->Reset();
freeList.push_back(tile);
unload.pop_front();
}
activeUnload = false;
}
bool trpgPageManager::LodPageInfo::isWithin(trpgManagedTile *tile,trpg2iPoint &sw,trpg2iPoint &ne)
{
int tileX,tileY,tileLod;
tile->GetTileLoc(tileX,tileY,tileLod);
if (tileX >= sw.x && tileX <= ne.x &&
tileY >= sw.y && tileY <= ne.y)
return true;
return false;
}
bool trpgPageManager::LodPageInfo::Stop()
{
// Empty the load list
int i;
for (i=0;i<int(load.size());i++)
freeList.push_back(load[i]);
load.resize(0);
// Move the current tiles to the unload list
for (i=0;i<int(current.size());i++)
if (current[i])
unload.push_back(current[i]);
current.resize(0);
return (unload.size() > 0);
}
/* Update does the major work of figuring out what to load and
what to unload.
*/
void trpgPageManager::LodPageInfo::Update()
{
trpg2iPoint sw,ne;
// Figure out the lower left and upper right corners
// in cell coordinates
sw.x = cell.x - aoiSize.x; sw.y = cell.y - aoiSize.y;
ne.x = cell.x + aoiSize.x; ne.y = cell.y + aoiSize.y;
sw.x = MAX(0,sw.x); sw.y = MAX(0,sw.y);
ne.x = MIN(lodSize.x-1,ne.x); ne.y = MIN(lodSize.y-1,ne.y);
/* Load list -
Some of the tiles we're supposed to load may now be
out of range. Take them off the load list.
*/
int i;
for (i=0;i<int(load.size());i++) {
if (load[i] && !isWithin(load[i],sw,ne)) {
freeList.push_back(load[i]);
load[i] = NULL;
}
}
/* Unload list -
Some of the tiles we were planning on unloading may now
be in view again. Move them back to current.
*/
for (i=0;i<int(unload.size());i++) {
if (unload[i] && isWithin(unload[i],sw,ne)) {
current.push_back(unload[i]);
unload[i] = NULL;
}
}
/* Current list -
We need to figure out a few things here.
1) What's in the current list that should be paged out.
2) What's already paged, sorted into tmpCurrent.
3) What's missing from tmpCurrent and should be paged in.
*/
// Look for tiles to page out
// Move them to the unload list
for (i=0;i<int(current.size());i++) {
if (current[i] && !isWithin(current[i],sw,ne)) {
unload.push_back(current[i]);
current[i] = NULL;
}
}
// Clean the NULLs out of the current list
int curPos = 0;
for (i=0;i<int(current.size());i++) {
if (current[i]) {
current[curPos] = current[i];
curPos++;
}
}
current.resize(curPos);
// Sort the currently loaded stuff into a spatial array
// so we can figure out what needs to be loaded in addition.
int dx,dy;
dx = ne.x - sw.x+1; dy = ne.y - sw.y+1;
tmpCurrent.resize(dx*dy);
for (i=0;i<int(tmpCurrent.size());i++) tmpCurrent[i] = false;
for (i=0;i<int(current.size());i++) {
trpgManagedTile *tile = current[i];
if (tile) {
int tileX,tileY,tileLod;
tile->GetTileLoc(tileX,tileY,tileLod);
tmpCurrent[(tileY-sw.y)*dx + (tileX-sw.x)] = true;
}
}
// Now figure out which ones are missing and add them
// to the load list
for (int x=0;x<dx;x++) {
for (int y=0;y<dy;y++) {
if (!tmpCurrent[y*dx + x]) {
// Allocate a new tile
trpgManagedTile *tile = NULL;
if (freeList.size() > 0) {
tile = freeList[0];
freeList.pop_front();
} else
tile = new trpgManagedTile();
tile->SetTileLoc(x+sw.x,y+sw.y,lod);
load.push_back(tile);
}
}
}
// That's it. All the rest is handled by the caller
// iterating through the tiles to load and unload.
}
void trpgPageManager::LodPageInfo::Print(trpgPrintBuffer &buf)
{
char line[1024];
int i;
sprintf(line,"lod = %d, valid = %s",lod,(valid ? "yes" : "no")); buf.prnLine(line);
sprintf(line,"pageDist = %f, maxNumTiles = %d",pageDist,maxNumTiles); buf.prnLine(line);
sprintf(line,"cellSize = (%f,%f)",cellSize.x,cellSize.y); buf.prnLine(line);
sprintf(line,"cell = (%d,%d), aoiSize = (%d,%d), lodSize = (%d,%d)",cell.x,cell.y,aoiSize.x,aoiSize.y,lodSize.x,lodSize.y); buf.prnLine(line);
sprintf(line,"Loads: (activeLoad = %s)",(activeLoad ? "yes" : "no")); buf.prnLine(line);
buf.IncreaseIndent();
for (i=0;i<int(load.size());i++)
if (load[i])
load[i]->Print(buf);
buf.DecreaseIndent();
sprintf(line,"Unloads: (activeUnload = %s)",(activeUnload ? "yes" : "no")); buf.prnLine(line);
buf.IncreaseIndent();
for (i=0;i<int(unload.size());i++)
if (unload[i])
unload[i]->Print(buf);
buf.DecreaseIndent();
buf.prnLine("Currently loaded:");
buf.IncreaseIndent();
for (i=0;i<int(current.size());i++)
if (current[i])
current[i]->Print(buf);
buf.DecreaseIndent();
sprintf(line,"Free list size = %d",freeList.size()); buf.prnLine(line);
}
/* Page Manager methods
These are methods of the main trpgPageManager. Check the header
file for more detailed information.
*/
trpgPageManager::trpgPageManager()
{
scale = 1.0;
valid = false;
// This should be sufficiently unlikely
pagePt.x = -1e20; pagePt.y = -1e20;
}
trpgPageManager::~trpgPageManager()
{
}
void trpgPageManager::Init(trpgr_Archive *inArch)
{
archive = inArch;
// We're resetting everything. In general, Init should only
// be called once, but it'll work fine if you call it more than once.
lastLoad = None;
lastTile = NULL;
lastLod = -1;
// Need to know the number of terrain LODs
const trpgHeader *head = archive->GetHeader();
int numLod;
head->GetNumLods(numLod);
// Reset the terrain LOD paging classes.
valid = true;
pageInfo.resize(numLod);
for (int i=0;i<numLod;i++) {
pageInfo[i].Init(archive,i,scale);
}
}
bool trpgPageManager::SetPageDistFactor(double inFact)
{
// A scaling factor less than 1 will break the archive display.
if (inFact <= 1.0)
return false;
scale = inFact;
return true;
}
bool trpgPageManager::SetLocation(trpg2dPoint &pt)
{
// Do a basic sanity check
if (!valid || (pagePt.x == pt.x && pagePt.y == pt.y))
return false;
pagePt = pt;
// Call each terrain LOD and let if figure out if something
// has changed.
bool change = false;
for (int i=0;i<int(pageInfo.size());i++) {
if (pageInfo[i].SetLocation(pt))
change = true;
}
return change;
}
trpgManagedTile *trpgPageManager::GetNextLoad()
{
// If we're already doing something, let them know about it
if (lastLoad != None)
throw 1;
// Look for anything that needs loaded
// Start with lowest LOD, work up to highest
trpgManagedTile *tile = NULL;
for (int i=0;i<int(pageInfo.size());i++) {
LodPageInfo &info = pageInfo[i];
if ((tile = info.GetNextLoad()))
break;
}
// Found one. Now the user has to load it.
if (tile) {
lastLoad = Load;
lastTile = tile;
lastLod = tile->lod;
}
return tile;
}
void trpgPageManager::AckLoad()
{
// If we're not in the middle of a load, register our displeasure
if (lastLoad != Load)
throw 1;
LodPageInfo &info = pageInfo[lastLod];
info.AckLoad();
lastLoad = None;
lastTile = NULL;
}
void trpgPageManager::AddGroupID(trpgManagedTile *tile,int groupID,void *data)
{
groupMap[groupID] = data;
tile->AddGroupID(groupID);
}
void *trpgPageManager::GetGroupData(int groupID)
{
ManageGroupMap::const_iterator p = groupMap.find(groupID);
if (p != groupMap.end())
return (*p).second;
return NULL;
}
trpgManagedTile *trpgPageManager::GetNextUnload()
{
// If we're already doing something, let them know about it
if (lastLoad != None)
throw 1;
// Look for anything that needs unloaded
// Start with highest LOD, work down to lowest
trpgManagedTile *tile = NULL;
for (int i=pageInfo.size()-1;i>=0;i--) {
LodPageInfo &info = pageInfo[i];
if ((tile = info.GetNextUnload()))
break;
}
// Found one. Now the user has to unload it.
if (tile) {
lastLoad = Unload;
lastTile = tile;
lastLod = tile->lod;
}
return tile;
}
void trpgPageManager::AckUnload()
{
// If we're not in the middle of an unload, let 'em know.
if (lastLoad != Unload)
throw 1;
// Remove this tile's group IDs from the map
const std::vector<int> *groupIDs = lastTile->GetGroupIDs();
int i;
for (i=0;i<int(groupIDs->size());i++) {
ManageGroupMap::iterator p = groupMap.find((*groupIDs)[i]);
if (p != groupMap.end())
groupMap.erase(p);
}
LodPageInfo &info = pageInfo[lastLod];
info.AckUnload();
lastLoad = None;
lastTile = NULL;
}
bool trpgPageManager::Stop()
{
bool res=false;
int i;
for (i=0;i<int(pageInfo.size());i++)
res |= pageInfo[i].Stop();
lastLoad = None;
return res;
}
void trpgPageManager::Print(trpgPrintBuffer &buf)
{
char line[1024];
sprintf(line,"Paging pos = (%f,%f), scale = %f",pagePt.x,pagePt.y,scale); buf.prnLine(line);
buf.prnLine("Terrain LODs:");
int i;
for (i=0;i<int(pageInfo.size());i++) {
sprintf(line,"----Terrain lod %d---",i); buf.prnLine(line);
buf.IncreaseIndent();
pageInfo[i].Print(buf);
buf.DecreaseIndent();
}
}
/* Page Manager Tester
These methods are used to test the Paging Manager.
*/
trpgPageManageTester::trpgPageManageTester()
{
manager = NULL;
archive = NULL;
}
trpgPageManageTester::~trpgPageManageTester()
{
}
void trpgPageManageTester::Init(trpgPrintBuffer *pBuf,trpgPageManager *pMan,trpgr_Archive *inArch)
{
archive = inArch;
manager = pMan;
printBuf = pBuf;
if (!archive->isValid())
throw 1;
// Start up the paging manager
manager->Init(archive);
}
void trpgPageManageTester::RandomTest(int num,int seed)
{
if (!manager || !archive || !printBuf)
throw 1;
// Seed the random number generator so we can replicate runs
if (seed != -1)
srand(seed);
// Need the extents
trpg2dPoint ll,ur,lod0Size;
const trpgHeader *head = archive->GetHeader();
head->GetExtents(ll,ur);
head->GetTileSize(0,lod0Size);
// Give ourselves some space around the extents
ll.x -= lod0Size.x/2.0; ll.y -= lod0Size.y/2.0;
ur.x += lod0Size.x/2.0; ur.y += lod0Size.y/2.0;
// Jump around
int i;
char line[1024];
for (i=0;i<num;i++) {
// Generate a point
double randNum1 = rand()/(double)RAND_MAX;
double randNum2 = rand()/(double)RAND_MAX;
trpg2dPoint pt;
pt.x = (ur.x - ll.x)*randNum1;
pt.y = (ur.y - ll.y)*randNum2;
// Jump to the point
bool changes = manager->SetLocation(pt);
sprintf(line,"Jumped to (%f,%f). Tiles to load/unload = %s",pt.x,pt.y,
(changes ? "yes" : "no")); printBuf->prnLine(line);
// Process the results
ProcessChanges();
}
// Ask the page manager for its final status
manager->Print(*printBuf);
manager->Stop();
}
void trpgPageManageTester::Fly_LL_to_UR(double dist)
{
char line[1024];
if (!manager || !archive || !printBuf)
throw 1;
// Need the extents
trpg2dPoint ll,ur,lod0Size;
const trpgHeader *head = archive->GetHeader();
head->GetExtents(ll,ur);
head->GetTileSize(0,lod0Size);
// Give ourselves some space around the extents
ll.x -= lod0Size.x/2.0; ll.y -= lod0Size.y/2.0;
ur.x += lod0Size.x/2.0; ur.y += lod0Size.y/2.0;
// Fly the path
trpg2dPoint loc; loc = ll;
do {
loc.x += dist; loc.y += dist;
// Jump to next point
bool changes = manager->SetLocation(loc);
sprintf(line,"Moved to (%f,%f). Tiles to load/unload = %s",loc.x,loc.y,
(changes ? "yes" : "no")); printBuf->prnLine(line);
// Process new location
ProcessChanges();
} while (loc.x < ur.x && loc.y < ur.y);
// Ask the page manager for its final status
manager->Print(*printBuf);
manager->Stop();
}
void trpgPageManageTester::ProcessChanges()
{
char line[1024];
int x,y,lod;
// Look for unloads to process
trpgManagedTile *unloadTile;
printBuf->prnLine("Tiles to unload:");
printBuf->IncreaseIndent();
while ((unloadTile = manager->GetNextUnload())) {
unloadTile->GetTileLoc(x,y,lod);
sprintf(line,"x = %d, y = %d, lod = %d",x,y,lod); printBuf->prnLine(line);
manager->AckUnload();
}
printBuf->DecreaseIndent();
// Look for loads to process
trpgManagedTile *loadTile;
printBuf->prnLine("Tiles to load:");
printBuf->IncreaseIndent();
while ((loadTile = manager->GetNextLoad())) {
loadTile->GetTileLoc(x,y,lod);
sprintf(line,"x = %d, y = %d, lod = %d",x,y,lod); printBuf->prnLine(line);
manager->AckLoad();
}
printBuf->DecreaseIndent();
}

View File

@@ -23,8 +23,8 @@
You should only modify this code if you want to add data to these classes.
*/
#include "trpage_geom.h"
#include "trpage_read.h"
#include <osgTXP/trpage_geom.h>
#include <osgTXP/trpage_read.h>
/* Write Material Table class
Keeps track of the materials that have been added.

View File

@@ -22,8 +22,8 @@
You should only modify this code if you want to add data to these classes.
*/
#include "trpage_geom.h"
#include "trpage_read.h"
#include <osgTXP/trpage_geom.h>
#include <osgTXP/trpage_read.h>
/* Write Model class
Represents a model reference.

View File

@@ -24,8 +24,8 @@
of these classes.
*/
#include "trpage_geom.h"
#include "trpage_read.h"
#include <osgTXP/trpage_geom.h>
#include <osgTXP/trpage_read.h>
/* Write Group
Basic group.

View File

@@ -30,7 +30,7 @@
for the rest of the tokens that you want.
*/
#include "trpage_read.h"
#include <osgTXP/trpage_read.h>
/* ***************************
Paging token callback structure

View File

@@ -22,8 +22,8 @@
archive for the purpose of printing it out.
*/
#include "trpage_print.h"
#include "trpage_scene.h"
#include <osgTXP/trpage_print.h>
#include <osgTXP/trpage_scene.h>
/* Set up the callbacks for the scene graph parser.
In our case this is just one read helper with

View File

@@ -23,7 +23,7 @@
within a TerraPage archive.
*/
#include "trpage_print.h"
#include <osgTXP/trpage_print.h>
/* ******************************************
Print Buffer implementation

View File

@@ -22,8 +22,8 @@
#include <stdio.h>
#include <string.h>
#include "trpage_geom.h"
#include "trpage_read.h"
#include <osgTXP/trpage_geom.h>
#include <osgTXP/trpage_read.h>
/* *******************
Range Methods

View File

@@ -22,8 +22,8 @@
The Read Archive is used to read a paging archive from disk.
*/
#include "trpage_read.h"
#include "trpage_compat.h"
#include <osgTXP/trpage_read.h>
#include <osgTXP/trpage_compat.h>
// Constructor
trpgr_Archive::trpgr_Archive()

View File

@@ -28,8 +28,8 @@
implement a trpgDiskReadBuffer as a subclass of trpgReadBuffer.
*/
#include "trpage_io.h"
#include "trpage_swap.h"
#include <osgTXP/trpage_io.h>
#include <osgTXP/trpage_swap.h>
/* **********************
Read buffer base class functions

View File

@@ -34,8 +34,8 @@
to read into a scene graph. You'll need to replace the helpers, primarily.
*/
#include "trpage_read.h"
#include "trpage_scene.h"
#include <osgTXP/trpage_read.h>
#include <osgTXP/trpage_scene.h>
/* ****************
MBR Calculation and handling

View File

@@ -20,7 +20,7 @@
Byte swapping utility functions.
*/
#include "trpage_swap.h"
#include <osgTXP/trpage_swap.h>
/*
** func: swap_two( in, out )

View File

@@ -23,8 +23,8 @@
the front of an archive) or the Tile Header (at the beginning of each tile).
*/
#include "trpage_geom.h"
#include "trpage_read.h"
#include <osgTXP/trpage_geom.h>
#include <osgTXP/trpage_read.h>
/* Write Tile Table
Keeps track of tiles written to disk.

View File

@@ -0,0 +1,27 @@
/* ************************
Copyright Terrain Experts Inc.
Terrain Experts Inc (TERREX) reserves all rights to this source code
unless otherwise specified in writing by the President of TERREX.
This copyright may be updated in the future, in which case that version
supercedes this one.
-------------------
Terrex Experts Inc.
4400 East Broadway #314
Tucson, AZ 85711
info@terrex.com
Tel: (520) 323-7990
************************
*/
#include <osgTXP/trpage_util.h>
/* trpage_util.cpp
This source file implements various utility routines for paging archive
*/
/* The merge routine used to be in here.
However, merge isn't actually general enough to be part of the library.
Only portable code should be in the TerraPage API.
Instead, there's a Windows specific program that merges TerraPage archives in
the merge/ directory of this distribution.
*/

View File

@@ -28,10 +28,10 @@
again, subclass and override if you need to change them.
*/
#include "trpage_geom.h"
#include "trpage_write.h"
#include "trpage_compat.h"
#include "trpage_read.h"
#include <osgTXP/trpage_geom.h>
#include <osgTXP/trpage_write.h>
#include <osgTXP/trpage_compat.h>
#include <osgTXP/trpage_read.h>
// Constructor
trpgwArchive::trpgwArchive(trpgEndian inNess,TileMode inTileMode,int inVersion)

View File

@@ -29,8 +29,8 @@
is required.
*/
#include "trpage_io.h"
#include "trpage_swap.h"
#include <osgTXP/trpage_io.h>
#include <osgTXP/trpage_swap.h>
/* **********************
Memory Write Buffer functions