Compare commits
19
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0ce0684dae | ||
|
|
377eb4782a | ||
|
|
f1a79e6b9f | ||
|
|
007a1e4659 | ||
|
|
fcb873b6dd | ||
|
|
a66d1ad855 | ||
|
|
76a5950f19 | ||
|
|
b7a91bdb03 | ||
|
|
e4bbc5c50b | ||
|
|
b481ccd749 | ||
|
|
e7b9e55599 | ||
|
|
05eaa7135f | ||
|
|
d063b319e8 | ||
|
|
be4fd56660 | ||
|
|
a406a3c00b | ||
|
|
c7295da5eb | ||
|
|
505f561e1c | ||
|
|
7bd8477fa1 | ||
|
|
36ef15940e |
@@ -22,7 +22,7 @@ PROJECT_NAME = SimGear
|
||||
# This could be handy for archiving the generated documentation or
|
||||
# if some version control system is used.
|
||||
|
||||
PROJECT_NUMBER = 0.0.15
|
||||
PROJECT_NUMBER = 0.0.16
|
||||
|
||||
# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute)
|
||||
# base path where the generated documentation will be put.
|
||||
|
||||
@@ -77,7 +77,6 @@ dist-hook:
|
||||
$(HOME)/projects/FlightGear-0.7/admin/am2dsp.pl --lib)
|
||||
pwd
|
||||
echo "copying simgear/metar"
|
||||
(cd $(top_srcdir); tar cf - simgear/metar) | (cd $(distdir); tar xvf -)
|
||||
echo "other stuff"
|
||||
@list='@subdirs@'; \
|
||||
target=distclean; \
|
||||
|
||||
@@ -1,5 +1,29 @@
|
||||
New in 0.0.16
|
||||
* July 12, 2001
|
||||
* Various changes to the property manager implimentation to better support
|
||||
dumping out the desired portions of the property tree to file.
|
||||
* Don't compile the metakit demos by default (causes problems for Irix)'
|
||||
* Other various tweaks for Irix.
|
||||
* Added a virtual destructor to XMLVisitor to fix a warning message.
|
||||
* Check for valid hostname lookup in sg_socket.cxx
|
||||
* Add a function to return modified julian date without creating an
|
||||
entire SGTime class. This avoids an extraneous warning about not
|
||||
being able to find a timezone.
|
||||
* Created a mailing list for cvs commit messages.
|
||||
* Fixed a potential array under/over run bug in interpolator.cxx
|
||||
* Removed all references to SGValue from the property manager. Added
|
||||
support for an "archive" bit in the property manager to control
|
||||
which values get written out.
|
||||
* Added SGCommandState class so that commands can compile and save
|
||||
copies of their arguments for efficiency if they are called multiple
|
||||
times.
|
||||
* Added Brian Baul's "tr" tiled rendering low level support library.
|
||||
This along with some higher level code in flightgear allows us to do
|
||||
ultra-hires tiled screen dumps suitable for large format printers.
|
||||
(Norman Vine)
|
||||
|
||||
New in 0.0.15
|
||||
* June 22, 2001
|
||||
* June 20, 2001
|
||||
* Various bug fixes, tweaks, and optimizations.
|
||||
* Added a command manager (analogous to the property manager)
|
||||
* Better Irix Mips support.
|
||||
|
||||
+17
-33
@@ -41,7 +41,7 @@ RSC=rc.exe
|
||||
# PROP Intermediate_Dir "Release"
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /YX /FD /c
|
||||
# ADD CPP /nologo /W3 /GX /O2 /I "\usr\include" /D "NDEBUG" /D "WIN32" /D "_MBCS" /D "HAVE_CONFIG_H" /FD /c
|
||||
# ADD CPP /nologo /W3 /GX /O2 /I "." /I ".." /I ".\SimGear" /D "NDEBUG" /D "WIN32" /D "_MBCS" /D "HAVE_CONFIG_H" /FD /c
|
||||
# ADD BASE RSC /l 0x409 /d "NDEBUG"
|
||||
# ADD RSC /l 0x409 /d "NDEBUG"
|
||||
BSC32=bscmake.exe
|
||||
@@ -64,7 +64,7 @@ LINK32=link.exe -lib
|
||||
# PROP Intermediate_Dir "Debug"
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /W3 /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /YX /FD /GZ /c
|
||||
# ADD CPP /nologo /W3 /GX /ZI /Od /I "\usr\include" /D "_DEBUG" /D "WIN32" /D "_MBCS" /D "HAVE_CONFIG_H" /FR /FD /GZ /c
|
||||
# ADD CPP /nologo /W3 /GX /ZI /Od /I "." /I ".." /I ".\SimGear" /D "_DEBUG" /D "WIN32" /D "_MBCS" /D "HAVE_CONFIG_H" /FR /FD /GZ /c
|
||||
# ADD BASE RSC /l 0x409 /d "_DEBUG"
|
||||
# ADD RSC /l 0x409 /d "_DEBUG"
|
||||
BSC32=bscmake.exe
|
||||
@@ -80,18 +80,6 @@ LINK32=link.exe -lib
|
||||
|
||||
# Name "SimGear - Win32 Release"
|
||||
# Name "SimGear - Win32 Debug"
|
||||
# Begin Group "Source Files"
|
||||
|
||||
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
|
||||
# End Group
|
||||
# Begin Group "Header Files"
|
||||
|
||||
# PROP Default_Filter "h;hpp;hxx;hm;inl"
|
||||
# End Group
|
||||
# Begin Group "Resource Files"
|
||||
|
||||
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
|
||||
# End Group
|
||||
# Begin Group "Lib_sgbucket"
|
||||
|
||||
# PROP Default_Filter ""
|
||||
@@ -973,6 +961,21 @@ SOURCE=.\simgear\screen\screen-dump.cxx
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\simgear\screen\tr.cxx
|
||||
|
||||
!IF "$(CFG)" == "SimGear - Win32 Release"
|
||||
|
||||
# PROP Intermediate_Dir "Release\Lib_sgscreen"
|
||||
|
||||
!ELSEIF "$(CFG)" == "SimGear - Win32 Debug"
|
||||
|
||||
# PROP Intermediate_Dir "Debug\Lib_sgscreen"
|
||||
|
||||
!ENDIF
|
||||
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\simgear\screen\win32-printer.h
|
||||
|
||||
!IF "$(CFG)" == "SimGear - Win32 Release"
|
||||
@@ -1113,25 +1116,6 @@ SOURCE=.\simgear\sky\stars.cxx
|
||||
|
||||
!ENDIF
|
||||
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Lib_sgthreads"
|
||||
|
||||
# PROP Default_Filter ""
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\simgear\threads\SGThread.cxx
|
||||
|
||||
!IF "$(CFG)" == "SimGear - Win32 Release"
|
||||
|
||||
# PROP Intermediate_Dir "Release\Lib_sgthreads"
|
||||
|
||||
!ELSEIF "$(CFG)" == "SimGear - Win32 Debug"
|
||||
|
||||
# PROP Intermediate_Dir "Debug\Lib_sgthreads"
|
||||
|
||||
!ENDIF
|
||||
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Lib_sgtiming"
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
exclude_dir = threads
|
||||
include_path = .
|
||||
include_path = ..
|
||||
include_path = .\SimGear
|
||||
#include_path = \usr\include
|
||||
+1
-1
@@ -6,7 +6,7 @@ dnl $Id$
|
||||
AC_INIT(simgear/bucket/newbucket.cxx)
|
||||
|
||||
dnl Initialize the automake stuff
|
||||
AM_INIT_AUTOMAKE(SimGear, 0.0.15)
|
||||
AM_INIT_AUTOMAKE(SimGear, 0.0.16)
|
||||
|
||||
dnl Specify KAI C++ compiler and flags.
|
||||
dnl Borrowed with slight modification from blitz distribution.
|
||||
|
||||
@@ -29,6 +29,7 @@ socktest_LDADD = \
|
||||
$(top_builddir)/simgear/io/libsgio.a \
|
||||
$(top_builddir)/simgear/debug/libsgdebug.a \
|
||||
$(top_builddir)/simgear/misc/libsgmisc.a \
|
||||
$(top_builddir)/simgear/xml/libsgxml.a \
|
||||
-lz
|
||||
|
||||
lowtest_SOURCES = lowtest.cxx
|
||||
@@ -43,4 +44,5 @@ decode_binobj_LDADD = \
|
||||
$(top_builddir)/simgear/bucket/libsgbucket.a \
|
||||
$(top_builddir)/simgear/misc/libsgmisc.a \
|
||||
$(top_builddir)/simgear/debug/libsgdebug.a \
|
||||
-lz
|
||||
$(top_builddir)/simgear/xml/libsgxml.a \
|
||||
-lz
|
||||
|
||||
@@ -23,6 +23,8 @@
|
||||
// $Id$
|
||||
|
||||
|
||||
#include <string.h> // for memcpy()
|
||||
|
||||
#include "lowlevel.hxx"
|
||||
|
||||
|
||||
|
||||
@@ -132,6 +132,10 @@ SGSocket::SocketType SGSocket::make_client_socket () {
|
||||
|
||||
// get the hosts official name/info
|
||||
hp = gethostbyname( hostname.c_str() );
|
||||
if (hp == NULL) {
|
||||
SG_LOG( SG_IO, SG_ALERT, "Error: hostname lookup failed" );
|
||||
return INVALID_SOCKET;
|
||||
}
|
||||
|
||||
// Connect this socket to the host and the port specified on the
|
||||
// command line
|
||||
|
||||
@@ -83,8 +83,9 @@ double SGInterpTable::interpolate(double x) const
|
||||
int i;
|
||||
double y;
|
||||
|
||||
if (size == 0.0)
|
||||
if (size == 0.0) {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
i = 0;
|
||||
|
||||
@@ -96,14 +97,14 @@ double SGInterpTable::interpolate(double x) const
|
||||
|
||||
// printf ("i = %d ", i);
|
||||
|
||||
if ( (i == 0) && (x < table[0].ind) ) {
|
||||
if ( i <= 0 ) {
|
||||
SG_LOG( SG_MATH, SG_DEBUG,
|
||||
"interpolate(): lookup error, x to small = " << x );
|
||||
return table[0].dep;
|
||||
}
|
||||
|
||||
// cout << " table[size-1].ind = " << table[size-1].ind << endl;
|
||||
if ( x > table[size-1].ind ) {
|
||||
if ( i >= size ) {
|
||||
SG_LOG( SG_MATH, SG_DEBUG,
|
||||
"interpolate(): lookup error, x to big = " << x );
|
||||
return table[size-1].dep;
|
||||
|
||||
+88
-57
@@ -7,6 +7,36 @@
|
||||
#include "commands.hxx"
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// Implementation of SGCommandState class.
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
SGCommandState::SGCommandState ()
|
||||
: _args(0)
|
||||
{
|
||||
}
|
||||
|
||||
SGCommandState::SGCommandState (const SGPropertyNode * args)
|
||||
: _args(0)
|
||||
{
|
||||
setArgs(args);
|
||||
}
|
||||
|
||||
SGCommandState::~SGCommandState ()
|
||||
{
|
||||
delete _args;
|
||||
}
|
||||
|
||||
void
|
||||
SGCommandState::setArgs (const SGPropertyNode * args)
|
||||
{
|
||||
delete _args;
|
||||
_args = new SGPropertyNode();
|
||||
copyProperties(args, _args);
|
||||
}
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// Implementation of SGCommandMgr class.
|
||||
@@ -50,83 +80,84 @@ SGCommandMgr::getCommandNames () const
|
||||
}
|
||||
|
||||
bool
|
||||
SGCommandMgr::execute (const string &name, const SGPropertyNode * arg) const
|
||||
SGCommandMgr::execute (const string &name, const SGPropertyNode * arg,
|
||||
SGCommandState ** state) const
|
||||
{
|
||||
command_t command = getCommand(name);
|
||||
if (command == 0)
|
||||
return false;
|
||||
else
|
||||
return (*command)(arg);
|
||||
return (*command)(arg, state);
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
SGCommandMgr::execute (const string &name) const
|
||||
{
|
||||
// FIXME
|
||||
SGPropertyNode node;
|
||||
return execute(name, &node);
|
||||
}
|
||||
// bool
|
||||
// SGCommandMgr::execute (const string &name) const
|
||||
// {
|
||||
// // FIXME
|
||||
// SGPropertyNode node;
|
||||
// return execute(name, &node);
|
||||
// }
|
||||
|
||||
|
||||
bool
|
||||
SGCommandMgr::execute (const string &name, bool value) const
|
||||
{
|
||||
// FIXME
|
||||
SGPropertyNode node;
|
||||
node.setBoolValue(value);
|
||||
return execute(name, &node);
|
||||
}
|
||||
// bool
|
||||
// SGCommandMgr::execute (const string &name, bool value) const
|
||||
// {
|
||||
// // FIXME
|
||||
// SGPropertyNode node;
|
||||
// node.setBoolValue(value);
|
||||
// return execute(name, &node);
|
||||
// }
|
||||
|
||||
|
||||
bool
|
||||
SGCommandMgr::execute (const string &name, int value) const
|
||||
{
|
||||
// FIXME
|
||||
SGPropertyNode node;
|
||||
node.setIntValue(value);
|
||||
return execute(name, &node);
|
||||
}
|
||||
// bool
|
||||
// SGCommandMgr::execute (const string &name, int value) const
|
||||
// {
|
||||
// // FIXME
|
||||
// SGPropertyNode node;
|
||||
// node.setIntValue(value);
|
||||
// return execute(name, &node);
|
||||
// }
|
||||
|
||||
|
||||
bool
|
||||
SGCommandMgr::execute (const string &name, long value) const
|
||||
{
|
||||
// FIXME
|
||||
SGPropertyNode node;
|
||||
node.setLongValue(value);
|
||||
return execute(name, &node);
|
||||
}
|
||||
// bool
|
||||
// SGCommandMgr::execute (const string &name, long value) const
|
||||
// {
|
||||
// // FIXME
|
||||
// SGPropertyNode node;
|
||||
// node.setLongValue(value);
|
||||
// return execute(name, &node);
|
||||
// }
|
||||
|
||||
|
||||
bool
|
||||
SGCommandMgr::execute (const string &name, float value) const
|
||||
{
|
||||
// FIXME
|
||||
SGPropertyNode node;
|
||||
node.setFloatValue(value);
|
||||
return execute(name, &node);
|
||||
}
|
||||
// bool
|
||||
// SGCommandMgr::execute (const string &name, float value) const
|
||||
// {
|
||||
// // FIXME
|
||||
// SGPropertyNode node;
|
||||
// node.setFloatValue(value);
|
||||
// return execute(name, &node);
|
||||
// }
|
||||
|
||||
|
||||
bool
|
||||
SGCommandMgr::execute (const string &name, double value) const
|
||||
{
|
||||
// FIXME
|
||||
SGPropertyNode node;
|
||||
node.setDoubleValue(value);
|
||||
return execute(name, &node);
|
||||
}
|
||||
// bool
|
||||
// SGCommandMgr::execute (const string &name, double value) const
|
||||
// {
|
||||
// // FIXME
|
||||
// SGPropertyNode node;
|
||||
// node.setDoubleValue(value);
|
||||
// return execute(name, &node);
|
||||
// }
|
||||
|
||||
|
||||
bool
|
||||
SGCommandMgr::execute (const string &name, string value) const
|
||||
{
|
||||
// FIXME
|
||||
SGPropertyNode node;
|
||||
node.setStringValue(value);
|
||||
return execute(name, &node);
|
||||
}
|
||||
// bool
|
||||
// SGCommandMgr::execute (const string &name, string value) const
|
||||
// {
|
||||
// // FIXME
|
||||
// SGPropertyNode node;
|
||||
// node.setStringValue(value);
|
||||
// return execute(name, &node);
|
||||
// }
|
||||
|
||||
|
||||
// end of commands.cxx
|
||||
|
||||
+133
-90
@@ -24,15 +24,55 @@ SG_USING_STD(map);
|
||||
SG_USING_STD(vector);
|
||||
|
||||
|
||||
/**
|
||||
* Stored state for a command.
|
||||
*
|
||||
* <p>This class allows a command to cache parts of its state between
|
||||
* invocations with the same parameters. Nearly every command that
|
||||
* actually uses this will subclass it in some way. The command
|
||||
* allocates the structure, but it is up to the caller to delete it
|
||||
* when it is no longer necessary, unless the command deletes it
|
||||
* and replaces the value with 0 or another command-state object
|
||||
* first.</p>
|
||||
*
|
||||
* <p>Note that this class is for caching only; all of the information
|
||||
* in it must be recoverable by other means, since the state could
|
||||
* arbitrarily disappear between invocations if the caller decides to
|
||||
* delete it.</p>
|
||||
*
|
||||
* <p>By default, the command state includes a place to keep a copy of
|
||||
* the parameters.</p>
|
||||
*
|
||||
* @author David Megginson, david@megginson.com
|
||||
*/
|
||||
class SGCommandState
|
||||
{
|
||||
public:
|
||||
SGCommandState ();
|
||||
SGCommandState (const SGPropertyNode * args);
|
||||
virtual ~SGCommandState ();
|
||||
virtual void setArgs (const SGPropertyNode * args);
|
||||
virtual const SGPropertyNode * getArgs () const { return _args; }
|
||||
private:
|
||||
SGPropertyNode * _args;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Manage commands.
|
||||
*
|
||||
* <p>This class allows the application to register and unregister
|
||||
* commands, and provides shortcuts for executing them. Commands
|
||||
* are simple functions that take a const pointer to an SGPropertyNode
|
||||
* as an argument and return a bool value indicating success or failure.
|
||||
* The property node may be ignored, or it may contain values that
|
||||
* the command uses as parameters.</p>
|
||||
* commands, and provides shortcuts for executing them. Commands are
|
||||
* simple functions that take a const pointer to an SGPropertyNode and
|
||||
* a pointer to a pointer variable (which should be 0 initially) where
|
||||
* the function can store compiled copies of its arguments, etc. to
|
||||
* avoid expensive recalculations. If the command deletes the
|
||||
* SGCommandState, it must replace it with a new pointer or 0;
|
||||
* otherwise, the caller is free to delete and zero the pointer at any
|
||||
* time and the command will start fresh with the next invocation.
|
||||
* The command must return a bool value indicating success or failure.
|
||||
* The property node may be ignored, or it may contain values that the
|
||||
* command uses as parameters.</p>
|
||||
*
|
||||
* <p>There are convenience methods for invoking a command function
|
||||
* with no arguments or with a single, primitive argument.</p>
|
||||
@@ -46,7 +86,8 @@ public:
|
||||
/**
|
||||
* Type for a command function.
|
||||
*/
|
||||
typedef bool (*command_t) (const SGPropertyNode * arg);
|
||||
typedef bool (*command_t) (const SGPropertyNode * arg,
|
||||
SGCommandState ** state);
|
||||
|
||||
|
||||
/**
|
||||
@@ -105,104 +146,106 @@ public:
|
||||
* @return true if the command is present and executes successfully,
|
||||
* false otherwise.
|
||||
*/
|
||||
virtual bool execute (const string &name, const SGPropertyNode * arg) const;
|
||||
virtual bool execute (const string &name,
|
||||
const SGPropertyNode * arg,
|
||||
SGCommandState ** state) const;
|
||||
|
||||
|
||||
/**
|
||||
* Execute a command with no argument.
|
||||
*
|
||||
* The command function will receive a pointer to a property node
|
||||
* with no value and no children.
|
||||
*
|
||||
* @param name The name of the command.
|
||||
* @return true if the command is present and executes successfully,
|
||||
* false otherwise.
|
||||
*/
|
||||
virtual bool execute (const string &name) const;
|
||||
// /**
|
||||
// * Execute a command with no argument.
|
||||
// *
|
||||
// * The command function will receive a pointer to a property node
|
||||
// * with no value and no children.
|
||||
// *
|
||||
// * @param name The name of the command.
|
||||
// * @return true if the command is present and executes successfully,
|
||||
// * false otherwise.
|
||||
// */
|
||||
// virtual bool execute (const string &name) const;
|
||||
|
||||
|
||||
/**
|
||||
* Execute a command with a single bool argument.
|
||||
*
|
||||
* The command function will receive a pointer to a property node
|
||||
* with a bool value and no children.
|
||||
*
|
||||
* @param name The name of the command.
|
||||
* @param arg The bool argument to the command.
|
||||
* @return true if the command is present and executes successfully,
|
||||
* false otherwise.
|
||||
*/
|
||||
virtual bool execute (const string &name, bool arg) const;
|
||||
// /**
|
||||
// * Execute a command with a single bool argument.
|
||||
// *
|
||||
// * The command function will receive a pointer to a property node
|
||||
// * with a bool value and no children.
|
||||
// *
|
||||
// * @param name The name of the command.
|
||||
// * @param arg The bool argument to the command.
|
||||
// * @return true if the command is present and executes successfully,
|
||||
// * false otherwise.
|
||||
// */
|
||||
// virtual bool execute (const string &name, bool arg) const;
|
||||
|
||||
|
||||
/**
|
||||
* Execute a command with a single int argument.
|
||||
*
|
||||
* The command function will receive a pointer to a property node
|
||||
* with a int value and no children.
|
||||
*
|
||||
* @param name The name of the command.
|
||||
* @param arg The int argument to the command.
|
||||
* @return true if the command is present and executes successfully,
|
||||
* false otherwise.
|
||||
*/
|
||||
virtual bool execute (const string &name, int arg) const;
|
||||
// /**
|
||||
// * Execute a command with a single int argument.
|
||||
// *
|
||||
// * The command function will receive a pointer to a property node
|
||||
// * with a int value and no children.
|
||||
// *
|
||||
// * @param name The name of the command.
|
||||
// * @param arg The int argument to the command.
|
||||
// * @return true if the command is present and executes successfully,
|
||||
// * false otherwise.
|
||||
// */
|
||||
// virtual bool execute (const string &name, int arg) const;
|
||||
|
||||
|
||||
/**
|
||||
* Execute a command with a single long argument.
|
||||
*
|
||||
* The command function will receive a pointer to a property node
|
||||
* with a long value and no children.
|
||||
*
|
||||
* @param name The name of the command.
|
||||
* @param arg The long argument to the command.
|
||||
* @return true if the command is present and executes successfully,
|
||||
* false otherwise.
|
||||
*/
|
||||
virtual bool execute (const string &name, long arg) const;
|
||||
// /**
|
||||
// * Execute a command with a single long argument.
|
||||
// *
|
||||
// * The command function will receive a pointer to a property node
|
||||
// * with a long value and no children.
|
||||
// *
|
||||
// * @param name The name of the command.
|
||||
// * @param arg The long argument to the command.
|
||||
// * @return true if the command is present and executes successfully,
|
||||
// * false otherwise.
|
||||
// */
|
||||
// virtual bool execute (const string &name, long arg) const;
|
||||
|
||||
|
||||
/**
|
||||
* Execute a command with a single float argument.
|
||||
*
|
||||
* The command function will receive a pointer to a property node
|
||||
* with a float value and no children.
|
||||
*
|
||||
* @param name The name of the command.
|
||||
* @param arg The float argument to the command.
|
||||
* @return true if the command is present and executes successfully,
|
||||
* false otherwise.
|
||||
*/
|
||||
virtual bool execute (const string &name, float arg) const;
|
||||
// /**
|
||||
// * Execute a command with a single float argument.
|
||||
// *
|
||||
// * The command function will receive a pointer to a property node
|
||||
// * with a float value and no children.
|
||||
// *
|
||||
// * @param name The name of the command.
|
||||
// * @param arg The float argument to the command.
|
||||
// * @return true if the command is present and executes successfully,
|
||||
// * false otherwise.
|
||||
// */
|
||||
// virtual bool execute (const string &name, float arg) const;
|
||||
|
||||
|
||||
/**
|
||||
* Execute a command with a single double argument.
|
||||
*
|
||||
* The command function will receive a pointer to a property node
|
||||
* with a double value and no children.
|
||||
*
|
||||
* @param name The name of the command.
|
||||
* @param arg The double argument to the command.
|
||||
* @return true if the command is present and executes successfully,
|
||||
* false otherwise.
|
||||
*/
|
||||
virtual bool execute (const string &name, double arg) const;
|
||||
// /**
|
||||
// * Execute a command with a single double argument.
|
||||
// *
|
||||
// * The command function will receive a pointer to a property node
|
||||
// * with a double value and no children.
|
||||
// *
|
||||
// * @param name The name of the command.
|
||||
// * @param arg The double argument to the command.
|
||||
// * @return true if the command is present and executes successfully,
|
||||
// * false otherwise.
|
||||
// */
|
||||
// virtual bool execute (const string &name, double arg) const;
|
||||
|
||||
|
||||
/**
|
||||
* Execute a command with a single string argument.
|
||||
*
|
||||
* The command function will receive a pointer to a property node
|
||||
* with a string value and no children.
|
||||
*
|
||||
* @param name The name of the command.
|
||||
* @param arg The string argument to the command.
|
||||
* @return true if the command is present and executes successfully,
|
||||
* false otherwise.
|
||||
*/
|
||||
virtual bool execute (const string &name, string arg) const;
|
||||
// /**
|
||||
// * Execute a command with a single string argument.
|
||||
// *
|
||||
// * The command function will receive a pointer to a property node
|
||||
// * with a string value and no children.
|
||||
// *
|
||||
// * @param name The name of the command.
|
||||
// * @param arg The string argument to the command.
|
||||
// * @return true if the command is present and executes successfully,
|
||||
// * false otherwise.
|
||||
// */
|
||||
// virtual bool execute (const string &name, string arg) const;
|
||||
|
||||
|
||||
private:
|
||||
|
||||
+546
-930
File diff suppressed because it is too large
Load Diff
+557
-189
@@ -32,9 +32,9 @@ SG_USING_STD(ostream);
|
||||
#undef ALIAS
|
||||
#endif
|
||||
|
||||
#ifdef UNKNOWN
|
||||
#pragma warn A sloppy coder has defined UNKNOWN as a macro!
|
||||
#undef UNKNOWN
|
||||
#ifdef UNSPECIFIED
|
||||
#pragma warn A sloppy coder has defined UNSPECIFIED as a macro!
|
||||
#undef UNSPECIFIED
|
||||
#endif
|
||||
|
||||
#ifdef BOOL
|
||||
@@ -473,78 +473,579 @@ private:
|
||||
|
||||
|
||||
/**
|
||||
* A cooked value.
|
||||
*
|
||||
* This is the value that property-list clients see. It is a
|
||||
* persistent layer over the possibly-changing raw value; once a
|
||||
* client gets an SGValue from the property manager, the pointer
|
||||
* will be good for the life of the property manager itself, no
|
||||
* matter how often the pointer is tied or untied.
|
||||
* A node in a property tree.
|
||||
*/
|
||||
class SGValue
|
||||
class SGPropertyNode
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
|
||||
/**
|
||||
* Property value types.
|
||||
*/
|
||||
enum Type {
|
||||
NONE,
|
||||
ALIAS,
|
||||
BOOL,
|
||||
INT,
|
||||
LONG,
|
||||
FLOAT,
|
||||
DOUBLE,
|
||||
STRING,
|
||||
UNKNOWN
|
||||
UNSPECIFIED
|
||||
};
|
||||
SGValue ();
|
||||
SGValue (const SGValue &value);
|
||||
~SGValue ();
|
||||
|
||||
|
||||
/**
|
||||
* Access mode attributes.
|
||||
*
|
||||
* <p>The ARCHIVE attribute is strictly advisory, and controls
|
||||
* whether the property should normally be saved and restored.</p>
|
||||
*/
|
||||
enum Attribute {
|
||||
READ = 1,
|
||||
WRITE = 2,
|
||||
ARCHIVE = 4
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
*/
|
||||
SGPropertyNode ();
|
||||
|
||||
|
||||
/**
|
||||
* Copy constructor.
|
||||
*/
|
||||
SGPropertyNode (const SGPropertyNode &node);
|
||||
|
||||
|
||||
/**
|
||||
* Destructor.
|
||||
*/
|
||||
virtual ~SGPropertyNode ();
|
||||
|
||||
|
||||
|
||||
//
|
||||
// Basic properties.
|
||||
//
|
||||
|
||||
/**
|
||||
* Test whether this node contains a primitive leaf value.
|
||||
*/
|
||||
bool hasValue () const { return (_type != NONE); }
|
||||
|
||||
|
||||
/**
|
||||
* Get the node's simple (XML) name.
|
||||
*/
|
||||
const string &getName () const { return _name; }
|
||||
|
||||
|
||||
/**
|
||||
* Get the node's integer index.
|
||||
*/
|
||||
const int getIndex () const { return _index; }
|
||||
|
||||
|
||||
/**
|
||||
* Get a non-const pointer to the node's parent.
|
||||
*/
|
||||
SGPropertyNode * getParent () { return _parent; }
|
||||
|
||||
|
||||
/**
|
||||
* Get a const pointer to the node's parent.
|
||||
*/
|
||||
const SGPropertyNode * getParent () const { return _parent; }
|
||||
|
||||
|
||||
//
|
||||
// Children.
|
||||
//
|
||||
|
||||
|
||||
/**
|
||||
* Get the number of child nodes.
|
||||
*/
|
||||
const int nChildren () const { return _children.size(); }
|
||||
|
||||
|
||||
/**
|
||||
* Get a child node by position (*NOT* index).
|
||||
*/
|
||||
SGPropertyNode * getChild (int position);
|
||||
|
||||
|
||||
/**
|
||||
* Get a const child node by position (*NOT* index).
|
||||
*/
|
||||
const SGPropertyNode * getChild (int position) const;
|
||||
|
||||
|
||||
/**
|
||||
* Get a child node by name and index.
|
||||
*/
|
||||
SGPropertyNode * getChild (const string &name, int index = 0,
|
||||
bool create = false);
|
||||
|
||||
|
||||
/**
|
||||
* Get a const child node by name and index.
|
||||
*/
|
||||
const SGPropertyNode * getChild (const string &name, int index = 0) const;
|
||||
|
||||
|
||||
/**
|
||||
* Get a vector of all children with the specified name.
|
||||
*/
|
||||
vector<SGPropertyNode *> getChildren (const string &name);
|
||||
|
||||
|
||||
/**
|
||||
* Get a vector all all children (const) with the specified name.
|
||||
*/
|
||||
vector<const SGPropertyNode *> getChildren (const string &name) const;
|
||||
|
||||
|
||||
//
|
||||
// Alias support.
|
||||
//
|
||||
|
||||
|
||||
/**
|
||||
* Alias this node's leaf value to another's.
|
||||
*/
|
||||
bool alias (SGPropertyNode * target);
|
||||
|
||||
|
||||
/**
|
||||
* Alias this node's leaf value to another's by relative path.
|
||||
*/
|
||||
bool alias (const string &path);
|
||||
|
||||
|
||||
/**
|
||||
* Remove any alias for this node.
|
||||
*/
|
||||
bool unalias ();
|
||||
|
||||
|
||||
/**
|
||||
* Test whether the node's leaf value is aliased to another's.
|
||||
*/
|
||||
bool isAlias () const { return (_type == ALIAS); }
|
||||
|
||||
|
||||
/**
|
||||
* Get a non-const pointer to the current alias target, if any.
|
||||
*/
|
||||
SGPropertyNode * getAliasTarget ();
|
||||
|
||||
|
||||
/**
|
||||
* Get a const pointer to the current alias target, if any.
|
||||
*/
|
||||
const SGPropertyNode * getAliasTarget () const;
|
||||
|
||||
|
||||
//
|
||||
// Path information.
|
||||
//
|
||||
|
||||
|
||||
/**
|
||||
* Get the path to this node from the root.
|
||||
*/
|
||||
string getPath (bool simplify = false) const;
|
||||
|
||||
|
||||
/**
|
||||
* Get a pointer to the root node.
|
||||
*/
|
||||
SGPropertyNode * getRootNode ();
|
||||
|
||||
|
||||
/**
|
||||
* Get a const pointer to the root node.
|
||||
*/
|
||||
const SGPropertyNode * getRootNode () const;
|
||||
|
||||
|
||||
/**
|
||||
* Get a pointer to another node by relative path.
|
||||
*/
|
||||
SGPropertyNode * getNode (const string &relative_path, bool create = false);
|
||||
|
||||
|
||||
/**
|
||||
* Get a const pointer to another node by relative path.
|
||||
*/
|
||||
const SGPropertyNode * getNode (const string &relative_path) const;
|
||||
|
||||
|
||||
//
|
||||
// Access Mode.
|
||||
//
|
||||
|
||||
/**
|
||||
* Check a single mode attribute for the property node.
|
||||
*/
|
||||
bool getAttribute (Attribute attr) const { return (_attr & attr); }
|
||||
|
||||
|
||||
/**
|
||||
* Set a single mode attribute for the property node.
|
||||
*/
|
||||
void setAttribute (Attribute attr, bool state) {
|
||||
(state ? _attr |= attr : _attr &= ~attr);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get all of the mode attributes for the property node.
|
||||
*/
|
||||
int getAttributes () const { return _attr; }
|
||||
|
||||
|
||||
/**
|
||||
* Set all of the mode attributes for the property node.
|
||||
*/
|
||||
void setAttributes (int attr) { _attr = attr; }
|
||||
|
||||
|
||||
//
|
||||
// Leaf Value (primitive).
|
||||
//
|
||||
|
||||
|
||||
/**
|
||||
* Get the type of leaf value, if any, for this node.
|
||||
*/
|
||||
Type getType () const;
|
||||
|
||||
SGValue * getAlias ();
|
||||
const SGValue * getAlias () const;
|
||||
bool alias (SGValue * alias);
|
||||
bool unalias ();
|
||||
bool isAlias () const { return _type == ALIAS; }
|
||||
|
||||
/**
|
||||
* Get a bool value for this node.
|
||||
*/
|
||||
bool getBoolValue () const;
|
||||
|
||||
|
||||
/**
|
||||
* Get an int value for this node.
|
||||
*/
|
||||
int getIntValue () const;
|
||||
|
||||
|
||||
/**
|
||||
* Get a long int value for this node.
|
||||
*/
|
||||
long getLongValue () const;
|
||||
|
||||
|
||||
/**
|
||||
* Get a float value for this node.
|
||||
*/
|
||||
float getFloatValue () const;
|
||||
|
||||
|
||||
/**
|
||||
* Get a double value for this node.
|
||||
*/
|
||||
double getDoubleValue () const;
|
||||
|
||||
|
||||
/**
|
||||
* Get a string value for this node.
|
||||
*/
|
||||
string getStringValue () const;
|
||||
|
||||
bool setBoolValue (bool value);
|
||||
bool setIntValue (int value);
|
||||
bool setLongValue (long value);
|
||||
bool setFloatValue (float value);
|
||||
bool setDoubleValue (double value);
|
||||
bool setStringValue (string value);
|
||||
bool setUnknownValue (string value);
|
||||
|
||||
|
||||
/**
|
||||
* Set a bool value for this node.
|
||||
*/
|
||||
bool setBoolValue (bool value);
|
||||
|
||||
|
||||
/**
|
||||
* Set an int value for this node.
|
||||
*/
|
||||
bool setIntValue (int value);
|
||||
|
||||
|
||||
/**
|
||||
* Set a long int value for this node.
|
||||
*/
|
||||
bool setLongValue (long value);
|
||||
|
||||
|
||||
/**
|
||||
* Set a float value for this node.
|
||||
*/
|
||||
bool setFloatValue (float value);
|
||||
|
||||
|
||||
/**
|
||||
* Set a double value for this node.
|
||||
*/
|
||||
bool setDoubleValue (double value);
|
||||
|
||||
|
||||
/**
|
||||
* Set a string value for this node.
|
||||
*/
|
||||
bool setStringValue (string value);
|
||||
|
||||
|
||||
/**
|
||||
* Set a value of unspecified type for this node.
|
||||
*/
|
||||
bool setUnspecifiedValue (string value);
|
||||
|
||||
|
||||
//
|
||||
// Data binding.
|
||||
//
|
||||
|
||||
|
||||
/**
|
||||
* Test whether this node is bound to an external data source.
|
||||
*/
|
||||
bool isTied () const { return _tied; }
|
||||
|
||||
|
||||
/**
|
||||
* Bind this node to an external bool source.
|
||||
*/
|
||||
bool tie (const SGRawValue<bool> &rawValue, bool useDefault = true);
|
||||
|
||||
|
||||
/**
|
||||
* Bind this node to an external int source.
|
||||
*/
|
||||
bool tie (const SGRawValue<int> &rawValue, bool useDefault = true);
|
||||
|
||||
|
||||
/**
|
||||
* Bind this node to an external long int source.
|
||||
*/
|
||||
bool tie (const SGRawValue<long> &rawValue, bool useDefault = true);
|
||||
|
||||
|
||||
/**
|
||||
* Bind this node to an external float source.
|
||||
*/
|
||||
bool tie (const SGRawValue<float> &rawValue, bool useDefault = true);
|
||||
|
||||
|
||||
/**
|
||||
* Bind this node to an external double source.
|
||||
*/
|
||||
bool tie (const SGRawValue<double> &rawValue, bool useDefault = true);
|
||||
|
||||
|
||||
/**
|
||||
* Bind this node to an external string source.
|
||||
*/
|
||||
bool tie (const SGRawValue<string> &rawValue, bool useDefault = true);
|
||||
|
||||
|
||||
/**
|
||||
* Unbind this node from any external data source.
|
||||
*/
|
||||
bool untie ();
|
||||
|
||||
|
||||
//
|
||||
// Convenience methods using paths.
|
||||
// TODO: add attribute methods
|
||||
//
|
||||
|
||||
|
||||
/**
|
||||
* Get another node's type.
|
||||
*/
|
||||
Type getType (const string &relative_path) const;
|
||||
|
||||
|
||||
/**
|
||||
* Test whether another node has a leaf value.
|
||||
*/
|
||||
bool hasValue (const string &relative_path) const;
|
||||
|
||||
|
||||
/**
|
||||
* Get another node's value as a bool.
|
||||
*/
|
||||
bool getBoolValue (const string &relative_path,
|
||||
bool defaultValue = false) const;
|
||||
|
||||
|
||||
/**
|
||||
* Get another node's value as an int.
|
||||
*/
|
||||
int getIntValue (const string &relative_path,
|
||||
int defaultValue = 0) const;
|
||||
|
||||
|
||||
/**
|
||||
* Get another node's value as a long int.
|
||||
*/
|
||||
long getLongValue (const string &relative_path,
|
||||
long defaultValue = 0L) const;
|
||||
|
||||
|
||||
/**
|
||||
* Get another node's value as a float.
|
||||
*/
|
||||
float getFloatValue (const string &relative_path,
|
||||
float defaultValue = 0.0) const;
|
||||
|
||||
|
||||
/**
|
||||
* Get another node's value as a double.
|
||||
*/
|
||||
double getDoubleValue (const string &relative_path,
|
||||
double defaultValue = 0.0L) const;
|
||||
|
||||
|
||||
/**
|
||||
* Get another node's value as a string.
|
||||
*/
|
||||
string getStringValue (const string &relative_path,
|
||||
string defaultValue = "") const;
|
||||
|
||||
|
||||
/**
|
||||
* Set another node's value as a bool.
|
||||
*/
|
||||
bool setBoolValue (const string &relative_path, bool value);
|
||||
|
||||
|
||||
/**
|
||||
* Set another node's value as an int.
|
||||
*/
|
||||
bool setIntValue (const string &relative_path, int value);
|
||||
|
||||
|
||||
/**
|
||||
* Set another node's value as a long int.
|
||||
*/
|
||||
bool setLongValue (const string &relative_path, long value);
|
||||
|
||||
|
||||
/**
|
||||
* Set another node's value as a float.
|
||||
*/
|
||||
bool setFloatValue (const string &relative_path, float value);
|
||||
|
||||
|
||||
/**
|
||||
* Set another node's value as a double.
|
||||
*/
|
||||
bool setDoubleValue (const string &relative_path, double value);
|
||||
|
||||
|
||||
/**
|
||||
* Set another node's value as a string.
|
||||
*/
|
||||
bool setStringValue (const string &relative_path, string value);
|
||||
|
||||
|
||||
/**
|
||||
* Set another node's value with no specified type.
|
||||
*/
|
||||
bool setUnspecifiedValue (const string &relative_path, string value);
|
||||
|
||||
|
||||
/**
|
||||
* Test whether another node is bound to an external data source.
|
||||
*/
|
||||
bool isTied (const string &relative_path) const;
|
||||
|
||||
|
||||
/**
|
||||
* Bind another node to an external bool source.
|
||||
*/
|
||||
bool tie (const string &relative_path, const SGRawValue<bool> &rawValue,
|
||||
bool useDefault = true);
|
||||
|
||||
|
||||
/**
|
||||
* Bind another node to an external int source.
|
||||
*/
|
||||
bool tie (const string &relative_path, const SGRawValue<int> &rawValue,
|
||||
bool useDefault = true);
|
||||
|
||||
|
||||
/**
|
||||
* Bind another node to an external long int source.
|
||||
*/
|
||||
bool tie (const string &relative_path, const SGRawValue<long> &rawValue,
|
||||
bool useDefault = true);
|
||||
|
||||
|
||||
/**
|
||||
* Bind another node to an external float source.
|
||||
*/
|
||||
bool tie (const string &relative_path, const SGRawValue<float> &rawValue,
|
||||
bool useDefault = true);
|
||||
|
||||
|
||||
/**
|
||||
* Bind another node to an external double source.
|
||||
*/
|
||||
bool tie (const string &relative_path, const SGRawValue<double> &rawValue,
|
||||
bool useDefault = true);
|
||||
|
||||
|
||||
/**
|
||||
* Bind another node to an external string source.
|
||||
*/
|
||||
bool tie (const string &relative_path, const SGRawValue<string> &rawValue,
|
||||
bool useDefault = true);
|
||||
|
||||
|
||||
/**
|
||||
* Unbind another node from any external data source.
|
||||
*/
|
||||
bool untie (const string &relative_path);
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
/**
|
||||
* Protected constructor for making new nodes on demand.
|
||||
*/
|
||||
SGPropertyNode (const string &name, int index, SGPropertyNode * parent);
|
||||
|
||||
|
||||
private:
|
||||
|
||||
enum {
|
||||
ALIAS = -1
|
||||
};
|
||||
|
||||
/**
|
||||
* Clear any existing value and set the type to NONE.
|
||||
*/
|
||||
void clear_value ();
|
||||
|
||||
int _type;
|
||||
string _name;
|
||||
int _index;
|
||||
SGPropertyNode * _parent;
|
||||
vector<SGPropertyNode *> _children;
|
||||
|
||||
|
||||
Type _type;
|
||||
bool _tied;
|
||||
int _attr;
|
||||
|
||||
// The right kind of pointer...
|
||||
union {
|
||||
SGValue * alias;
|
||||
SGPropertyNode * alias;
|
||||
SGRawValue<bool> * bool_val;
|
||||
SGRawValue<int> * int_val;
|
||||
SGRawValue<long> * long_val;
|
||||
@@ -553,163 +1054,6 @@ private:
|
||||
SGRawValue<string> * string_val;
|
||||
} _value;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* A node in a property tree.
|
||||
*/
|
||||
class SGPropertyNode
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Property value types.
|
||||
*
|
||||
* Right now, this duplicates SGValue::Type, but SGValue will be
|
||||
* disappearing soon.
|
||||
*/
|
||||
enum Type {
|
||||
BOOL,
|
||||
INT,
|
||||
LONG,
|
||||
FLOAT,
|
||||
DOUBLE,
|
||||
STRING,
|
||||
UNKNOWN
|
||||
};
|
||||
|
||||
SGPropertyNode ();
|
||||
virtual ~SGPropertyNode ();
|
||||
|
||||
// Basic properties.
|
||||
bool hasValue () const { return (_value != 0); }
|
||||
SGValue * getValue () { return _value; }
|
||||
SGValue * getValue (bool create);
|
||||
const SGValue * getValue () const { return _value; }
|
||||
const string &getName () const { return _name; }
|
||||
const int getIndex () const { return _index; }
|
||||
SGPropertyNode * getParent () { return _parent; }
|
||||
const SGPropertyNode * getParent () const { return _parent; }
|
||||
|
||||
// Alias support.
|
||||
bool alias (SGPropertyNode * target);
|
||||
bool alias (const string &path);
|
||||
bool unalias ();
|
||||
bool isAlias () const;
|
||||
SGPropertyNode * getAliasTarget ();
|
||||
const SGPropertyNode * getAliasTarget () const;
|
||||
|
||||
// Children.
|
||||
const int nChildren () const { return _children.size(); }
|
||||
SGPropertyNode * getChild (int position);
|
||||
const SGPropertyNode * getChild (int position) const;
|
||||
SGPropertyNode * getChild (const string &name, int index = 0,
|
||||
bool create = false);
|
||||
const SGPropertyNode * getChild (const string &name, int index = 0) const;
|
||||
|
||||
vector<SGPropertyNode *> getChildren (const string &name);
|
||||
vector<const SGPropertyNode *> getChildren (const string &name) const;
|
||||
|
||||
// Path information.
|
||||
string getPath (bool simplify = false) const;
|
||||
|
||||
// Relative or absolute paths.
|
||||
SGPropertyNode * getRootNode ();
|
||||
const SGPropertyNode * getRootNode () const;
|
||||
SGPropertyNode * getNode (const string &relative_path, bool create = false);
|
||||
const SGPropertyNode * getNode (const string &relative_path) const;
|
||||
|
||||
// Value-related stuff.
|
||||
Type getType () const;
|
||||
|
||||
bool getBoolValue () const;
|
||||
int getIntValue () const;
|
||||
long getLongValue () const;
|
||||
float getFloatValue () const;
|
||||
double getDoubleValue () const;
|
||||
string getStringValue () const;
|
||||
|
||||
bool setBoolValue (bool value);
|
||||
bool setIntValue (int value);
|
||||
bool setLongValue (long value);
|
||||
bool setFloatValue (float value);
|
||||
bool setDoubleValue (double value);
|
||||
bool setStringValue (string value);
|
||||
bool setUnknownValue (string value);
|
||||
|
||||
bool isTied () const;
|
||||
|
||||
bool tie (const SGRawValue<bool> &rawValue, bool useDefault = true);
|
||||
bool tie (const SGRawValue<int> &rawValue, bool useDefault = true);
|
||||
bool tie (const SGRawValue<long> &rawValue, bool useDefault = true);
|
||||
bool tie (const SGRawValue<float> &rawValue, bool useDefault = true);
|
||||
bool tie (const SGRawValue<double> &rawValue, bool useDefault = true);
|
||||
bool tie (const SGRawValue<string> &rawValue, bool useDefault = true);
|
||||
|
||||
bool untie ();
|
||||
|
||||
// Values from paths.
|
||||
Type getType (const string &relative_path) const;
|
||||
|
||||
bool getBoolValue (const string &relative_path,
|
||||
bool defaultValue = false) const;
|
||||
int getIntValue (const string &relative_path,
|
||||
int defaultValue = 0) const;
|
||||
long getLongValue (const string &relative_path,
|
||||
long defaultValue = 0L) const;
|
||||
float getFloatValue (const string &relative_path,
|
||||
float defaultValue = 0.0) const;
|
||||
double getDoubleValue (const string &relative_path,
|
||||
double defaultValue = 0.0L) const;
|
||||
string getStringValue (const string &relative_path,
|
||||
string defaultValue = "") const;
|
||||
|
||||
bool setBoolValue (const string &relative_path, bool value);
|
||||
bool setIntValue (const string &relative_path, int value);
|
||||
bool setLongValue (const string &relative_path, long value);
|
||||
bool setFloatValue (const string &relative_path, float value);
|
||||
bool setDoubleValue (const string &relative_path, double value);
|
||||
bool setStringValue (const string &relative_path, string value);
|
||||
bool setUnknownValue (const string &relative_path, string value);
|
||||
|
||||
bool isTied (const string &relative_path) const;
|
||||
|
||||
bool tie (const string &relative_path, const SGRawValue<bool> &rawValue,
|
||||
bool useDefault = true);
|
||||
bool tie (const string &relative_path, const SGRawValue<int> &rawValue,
|
||||
bool useDefault = true);
|
||||
bool tie (const string &relative_path, const SGRawValue<long> &rawValue,
|
||||
bool useDefault = true);
|
||||
bool tie (const string &relative_path, const SGRawValue<float> &rawValue,
|
||||
bool useDefault = true);
|
||||
bool tie (const string &relative_path, const SGRawValue<double> &rawValue,
|
||||
bool useDefault = true);
|
||||
bool tie (const string &relative_path, const SGRawValue<string> &rawValue,
|
||||
bool useDefault = true);
|
||||
|
||||
bool untie (const string &relative_path);
|
||||
|
||||
protected:
|
||||
|
||||
SGPropertyNode (const string &name, int index, SGPropertyNode * parent);
|
||||
|
||||
private:
|
||||
|
||||
bool hasValue (const string &relative_path) const;
|
||||
SGValue * getValue (const string &relative_path, bool create = false);
|
||||
const SGValue * getValue (const string &relative_path) const;
|
||||
|
||||
SGPropertyNode (const SGPropertyNode &node) {}
|
||||
|
||||
SGValue * _value;
|
||||
string _name;
|
||||
int _index;
|
||||
SGPropertyNode * _parent;
|
||||
vector<SGPropertyNode *> _children;
|
||||
mutable SGPropertyNode * _target;
|
||||
|
||||
};
|
||||
|
||||
@@ -719,11 +1063,35 @@ private:
|
||||
// I/O functions.
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
/**
|
||||
* Read properties from an XML input stream.
|
||||
*/
|
||||
bool readProperties (istream &input, SGPropertyNode * start_node,
|
||||
const string &base = "");
|
||||
|
||||
|
||||
/**
|
||||
* Read properties from an XML file.
|
||||
*/
|
||||
bool readProperties (const string &file, SGPropertyNode * start_node);
|
||||
|
||||
|
||||
/**
|
||||
* Write properties to an XML output stream.
|
||||
*/
|
||||
bool writeProperties (ostream &output, const SGPropertyNode * start_node);
|
||||
|
||||
|
||||
/**
|
||||
* Write properties to an XML file.
|
||||
*/
|
||||
bool writeProperties (const string &file, const SGPropertyNode * start_node);
|
||||
|
||||
|
||||
/**
|
||||
* Copy properties from one node to another.
|
||||
*/
|
||||
bool copyProperties (const SGPropertyNode *in, SGPropertyNode *out);
|
||||
|
||||
|
||||
|
||||
+147
-60
@@ -30,6 +30,8 @@ SG_USING_STD(string);
|
||||
SG_USING_STD(vector);
|
||||
SG_USING_STD(map);
|
||||
|
||||
#define DEFAULT_MODE (SGPropertyNode::READ|SGPropertyNode::WRITE)
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
@@ -57,21 +59,22 @@ private:
|
||||
|
||||
struct State
|
||||
{
|
||||
State () : node(0), type("") {}
|
||||
State (SGPropertyNode * _node, const char * _type)
|
||||
: node(_node), type(_type) {}
|
||||
State () : node(0), type(""), mode(DEFAULT_MODE) {}
|
||||
State (SGPropertyNode * _node, const char * _type, int _mode)
|
||||
: node(_node), type(_type), mode(_mode) {}
|
||||
SGPropertyNode * node;
|
||||
string type;
|
||||
int mode;
|
||||
map<string,int> counters;
|
||||
};
|
||||
|
||||
State &state () { return _state_stack[_state_stack.size() - 1]; }
|
||||
|
||||
void push_state (SGPropertyNode * node, const char * type) {
|
||||
void push_state (SGPropertyNode * node, const char * type, int mode) {
|
||||
if (type == 0)
|
||||
_state_stack.push_back(State(node, "unknown"));
|
||||
_state_stack.push_back(State(node, "unspecified", mode));
|
||||
else
|
||||
_state_stack.push_back(State(node, type));
|
||||
_state_stack.push_back(State(node, type, mode));
|
||||
_level++;
|
||||
_data = "";
|
||||
}
|
||||
@@ -103,6 +106,26 @@ PropsVisitor::endXML ()
|
||||
_state_stack.resize(0);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check a yes/no flag, with default.
|
||||
*/
|
||||
static bool
|
||||
checkFlag (const char * flag, bool defaultState = true)
|
||||
{
|
||||
if (flag == 0)
|
||||
return defaultState;
|
||||
else if (string(flag) == "y")
|
||||
return true;
|
||||
else if (string(flag) == "n")
|
||||
return false;
|
||||
else {
|
||||
SG_LOG(SG_INPUT, SG_ALERT, "Unrecognized flag value '" << flag
|
||||
<< "', assuming yes");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
PropsVisitor::startElement (const char * name, const XMLAttributes &atts)
|
||||
{
|
||||
@@ -114,44 +137,63 @@ PropsVisitor::startElement (const char * name, const XMLAttributes &atts)
|
||||
name << "; expected PropertyList");
|
||||
_ok = false;
|
||||
}
|
||||
push_state(_root, "");
|
||||
push_state(_root, "", DEFAULT_MODE);
|
||||
}
|
||||
|
||||
else {
|
||||
|
||||
const char * attval;
|
||||
// Get the index.
|
||||
const char * att_n = atts.getValue("n");
|
||||
attval = atts.getValue("n");
|
||||
int index = 0;
|
||||
if (att_n != 0) {
|
||||
index = atoi(att_n);
|
||||
if (attval != 0) {
|
||||
index = atoi(attval);
|
||||
st.counters[name] = SG_MAX2(st.counters[name], index+1);
|
||||
} else {
|
||||
index = st.counters[name];
|
||||
st.counters[name]++;
|
||||
}
|
||||
|
||||
// Check for an alias.
|
||||
// Got the index, so grab the node.
|
||||
SGPropertyNode * node = st.node->getChild(name, index, true);
|
||||
const char * att_alias = atts.getValue("alias");
|
||||
if (att_alias != 0) {
|
||||
if (!node->alias(att_alias))
|
||||
SG_LOG(SG_INPUT, SG_ALERT, "Failed to set alias to " << att_alias);
|
||||
|
||||
// Get the access-mode attributes,
|
||||
// but don't set yet (in case they
|
||||
// prevent us from recording the value).
|
||||
int mode = 0;
|
||||
|
||||
attval = atts.getValue("read");
|
||||
if (checkFlag(attval, true))
|
||||
mode |= SGPropertyNode::READ;
|
||||
attval = atts.getValue("write");
|
||||
if (checkFlag(attval, true))
|
||||
mode |= SGPropertyNode::WRITE;
|
||||
attval = atts.getValue("archive");
|
||||
if (checkFlag(attval, false))
|
||||
mode |= SGPropertyNode::ARCHIVE;
|
||||
|
||||
// Check for an alias.
|
||||
attval = atts.getValue("alias");
|
||||
if (attval != 0) {
|
||||
if (!node->alias(attval))
|
||||
SG_LOG(SG_INPUT, SG_ALERT, "Failed to set alias to " << attval);
|
||||
}
|
||||
|
||||
// Check for an include.
|
||||
const char * att_include = atts.getValue("include");
|
||||
if (att_include != 0) {
|
||||
attval = atts.getValue("include");
|
||||
if (attval != 0) {
|
||||
SGPath path(SGPath(_base).dir());
|
||||
cerr << "Base is " << _base << endl;
|
||||
cerr << "Dir is " << SGPath(_base).dir() << endl;
|
||||
path.append(att_include);
|
||||
path.append(attval);
|
||||
if (!readProperties(path.str(), node)) {
|
||||
SG_LOG(SG_INPUT, SG_ALERT, "Failed to read include file "
|
||||
<< att_include);
|
||||
<< attval);
|
||||
_ok = false;
|
||||
}
|
||||
}
|
||||
|
||||
push_state(node, atts.getValue("type"));
|
||||
push_state(node, atts.getValue("type"), mode);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -179,12 +221,12 @@ PropsVisitor::endElement (const char * name)
|
||||
ret = st.node->setDoubleValue(strtod(_data.c_str(), 0));
|
||||
} else if (st.type == "string") {
|
||||
ret = st.node->setStringValue(_data);
|
||||
} else if (st.type == "unknown") {
|
||||
ret = st.node->setUnknownValue(_data);
|
||||
} else if (st.type == "unspecified") {
|
||||
ret = st.node->setUnspecifiedValue(_data);
|
||||
} else {
|
||||
SG_LOG(SG_INPUT, SG_ALERT, "Unknown data type " << st.type
|
||||
<< " assuming 'unknown'");
|
||||
ret = st.node->setUnknownValue(_data);
|
||||
SG_LOG(SG_INPUT, SG_ALERT, "Unrecognized data type " << st.type
|
||||
<< " assuming 'unspecified'");
|
||||
ret = st.node->setUnspecifiedValue(_data);
|
||||
}
|
||||
if (!ret)
|
||||
SG_LOG(SG_INPUT, SG_ALERT, "readProperties: Failed to set "
|
||||
@@ -192,6 +234,11 @@ PropsVisitor::endElement (const char * name)
|
||||
<< _data << "\" with type " << st.type);
|
||||
}
|
||||
|
||||
// Set the access-mode attributes now,
|
||||
// once the value has already been
|
||||
// assigned.
|
||||
st.node->setAttributes(st.mode);
|
||||
|
||||
pop_state();
|
||||
}
|
||||
|
||||
@@ -277,24 +324,24 @@ static const char *
|
||||
getTypeName (SGPropertyNode::Type type)
|
||||
{
|
||||
switch (type) {
|
||||
case SGValue::UNKNOWN:
|
||||
return "unknown";
|
||||
case SGValue::BOOL:
|
||||
case SGPropertyNode::UNSPECIFIED:
|
||||
return "unspecified";
|
||||
case SGPropertyNode::BOOL:
|
||||
return "bool";
|
||||
case SGValue::INT:
|
||||
case SGPropertyNode::INT:
|
||||
return "int";
|
||||
case SGValue::LONG:
|
||||
case SGPropertyNode::LONG:
|
||||
return "long";
|
||||
case SGValue::FLOAT:
|
||||
case SGPropertyNode::FLOAT:
|
||||
return "float";
|
||||
case SGValue::DOUBLE:
|
||||
case SGPropertyNode::DOUBLE:
|
||||
return "double";
|
||||
case SGValue::STRING:
|
||||
case SGPropertyNode::STRING:
|
||||
return "string";
|
||||
}
|
||||
|
||||
// keep the compiler from squawking
|
||||
return "unknown";
|
||||
return "unspecified";
|
||||
}
|
||||
|
||||
|
||||
@@ -331,22 +378,71 @@ doIndent (ostream &output, int indent)
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
writeAtts (ostream &output, const SGPropertyNode * node)
|
||||
{
|
||||
int index = node->getIndex();
|
||||
|
||||
if (index != 0)
|
||||
output << " n=\"" << index << '"';
|
||||
|
||||
#if 0
|
||||
if (!node->getAttribute(SGPropertyNode::READ))
|
||||
output << " read=\"n\"";
|
||||
|
||||
if (!node->getAttribute(SGPropertyNode::WRITE))
|
||||
output << " write=\"n\"";
|
||||
|
||||
if (node->getAttribute(SGPropertyNode::ARCHIVE))
|
||||
output << " archive=\"y\"";
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test whether a node is archivable or has archivable descendants.
|
||||
*/
|
||||
static bool
|
||||
isArchivable (const SGPropertyNode * node)
|
||||
{
|
||||
// FIXME: it's inefficient to do this all the time
|
||||
if (node->getAttribute(SGPropertyNode::ARCHIVE))
|
||||
return true;
|
||||
else {
|
||||
int nChildren = node->nChildren();
|
||||
for (int i = 0; i < nChildren; i++)
|
||||
if (isArchivable(node->getChild(i)))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
static bool
|
||||
writeNode (ostream &output, const SGPropertyNode * node, int indent)
|
||||
{
|
||||
// Don't write the node or any of
|
||||
// its descendants unless it is
|
||||
// allowed to be archived.
|
||||
if (!isArchivable(node))
|
||||
return true; // Everything's OK, but we won't write.
|
||||
|
||||
const string &name = node->getName();
|
||||
int index = node->getIndex();
|
||||
int nChildren = node->nChildren();
|
||||
|
||||
// If there is a literal value,
|
||||
// write it first.
|
||||
if (node->hasValue()) {
|
||||
if (node->hasValue() && node->getAttribute(SGPropertyNode::ARCHIVE)) {
|
||||
doIndent(output, indent);
|
||||
output << '<' << name << " n=\"" << index << '"';
|
||||
if (node->isAlias() && node->getAliasTarget() != 0)
|
||||
output << " alias=\"" << node->getAliasTarget()->getPath() << "\"/>";
|
||||
else {
|
||||
if (node->getType() != SGPropertyNode::UNKNOWN)
|
||||
output << '<' << name;
|
||||
writeAtts(output, node);
|
||||
if (node->isAlias() && node->getAliasTarget() != 0) {
|
||||
output << " alias=\"" << node->getAliasTarget()->getPath()
|
||||
<< "\"/>" << endl;
|
||||
} else {
|
||||
if (node->getType() != SGPropertyNode::UNSPECIFIED)
|
||||
output << " type=\"" << getTypeName(node->getType()) << '"';
|
||||
output << '>';
|
||||
writeData(output, node->getStringValue());
|
||||
@@ -358,9 +454,8 @@ writeNode (ostream &output, const SGPropertyNode * node, int indent)
|
||||
// next.
|
||||
if (nChildren > 0 || node->isAlias()) {
|
||||
doIndent(output, indent);
|
||||
output << '<' << name << " n=\"" << index << '"';
|
||||
if (node->isAlias() && node->getAliasTarget() != 0)
|
||||
output << " alias=\"" << node->getAliasTarget()->getPath() << '"';
|
||||
output << '<' << name;
|
||||
writeAtts(output, node);
|
||||
output << '>' << endl;
|
||||
for (int i = 0; i < nChildren; i++)
|
||||
writeNode(output, node->getChild(i), indent + INDENT_STEP);
|
||||
@@ -368,14 +463,6 @@ writeNode (ostream &output, const SGPropertyNode * node, int indent)
|
||||
output << "</" << name << '>' << endl;
|
||||
}
|
||||
|
||||
// If there were no children and no
|
||||
// value, at least note the presence
|
||||
// of the node.
|
||||
// if (nChildren == 0 && !node->isAlias() && !node->hasValue()) {
|
||||
// doIndent(output, indent);
|
||||
// output << '<' << name << " n=\"" << index << "\"/>" << endl;
|
||||
// }
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -449,36 +536,36 @@ copyProperties (const SGPropertyNode *in, SGPropertyNode *out)
|
||||
// if any.
|
||||
if (in->hasValue()) {
|
||||
switch (in->getType()) {
|
||||
case SGValue::BOOL:
|
||||
case SGPropertyNode::BOOL:
|
||||
if (!out->setBoolValue(in->getBoolValue()))
|
||||
retval = false;
|
||||
break;
|
||||
case SGValue::INT:
|
||||
case SGPropertyNode::INT:
|
||||
if (!out->setIntValue(in->getIntValue()))
|
||||
retval = false;
|
||||
break;
|
||||
case SGValue::LONG:
|
||||
case SGPropertyNode::LONG:
|
||||
if (!out->setLongValue(in->getLongValue()))
|
||||
retval = false;
|
||||
break;
|
||||
case SGValue::FLOAT:
|
||||
case SGPropertyNode::FLOAT:
|
||||
if (!out->setFloatValue(in->getFloatValue()))
|
||||
retval = false;
|
||||
break;
|
||||
case SGValue::DOUBLE:
|
||||
case SGPropertyNode::DOUBLE:
|
||||
if (!out->setDoubleValue(in->getDoubleValue()))
|
||||
retval = false;
|
||||
break;
|
||||
case SGValue::STRING:
|
||||
case SGPropertyNode::STRING:
|
||||
if (!out->setStringValue(in->getStringValue()))
|
||||
retval = false;
|
||||
break;
|
||||
case SGValue::UNKNOWN:
|
||||
if (!out->setUnknownValue(in->getStringValue()))
|
||||
case SGPropertyNode::UNSPECIFIED:
|
||||
if (!out->setUnspecifiedValue(in->getStringValue()))
|
||||
retval = false;
|
||||
break;
|
||||
default:
|
||||
throw string("Unknown SGValue type");
|
||||
throw string("Unrecognized SGPropertyNode type");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+79
-79
@@ -50,13 +50,13 @@ static double getNum (int index) { return 1.0 / index; }
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static void
|
||||
show_values (const SGValue * value)
|
||||
show_values (const SGPropertyNode * node)
|
||||
{
|
||||
cout << "Bool: " << value->getBoolValue() << endl;
|
||||
cout << "Int: " << value->getIntValue() << endl;
|
||||
cout << "Float: " << value->getFloatValue() << endl;
|
||||
cout << "Double: " << value->getDoubleValue() << endl;
|
||||
cout << "String: " << value->getStringValue() << endl;
|
||||
cout << "Bool: " << node->getBoolValue() << endl;
|
||||
cout << "Int: " << node->getIntValue() << endl;
|
||||
cout << "Float: " << node->getFloatValue() << endl;
|
||||
cout << "Double: " << node->getDoubleValue() << endl;
|
||||
cout << "String: " << node->getStringValue() << endl;
|
||||
}
|
||||
|
||||
|
||||
@@ -68,7 +68,7 @@ show_values (const SGValue * value)
|
||||
static void
|
||||
test_value ()
|
||||
{
|
||||
SGValue * value;
|
||||
SGPropertyNode * node;
|
||||
|
||||
cout << endl << "Value" << endl << endl;
|
||||
|
||||
@@ -77,81 +77,81 @@ test_value ()
|
||||
//
|
||||
|
||||
cout << "Testing coercion from bool (expect true)" << endl;
|
||||
value = new SGValue;
|
||||
value->setBoolValue(true);
|
||||
show_values(value);
|
||||
delete value;
|
||||
node = new SGPropertyNode;
|
||||
node->setBoolValue(true);
|
||||
show_values(node);
|
||||
delete node;
|
||||
cout << endl;
|
||||
|
||||
cout << "Testing coercion from int (expect 128)" << endl;
|
||||
value = new SGValue;
|
||||
value->setIntValue(128);
|
||||
show_values(value);
|
||||
delete value;
|
||||
node = new SGPropertyNode;
|
||||
node->setIntValue(128);
|
||||
show_values(node);
|
||||
delete node;
|
||||
cout << endl;
|
||||
|
||||
cout << "Testing coercion from float (expect 1.0/3.0)" << endl;
|
||||
value = new SGValue;
|
||||
value->setFloatValue(1.0/3.0);
|
||||
show_values(value);
|
||||
delete value;
|
||||
node = new SGPropertyNode;
|
||||
node->setFloatValue(1.0/3.0);
|
||||
show_values(node);
|
||||
delete node;
|
||||
cout << endl;
|
||||
|
||||
cout << "Testing coercion from double (expect 1.0/3.0)" << endl;
|
||||
value = new SGValue;
|
||||
value->setDoubleValue(1.0/3.0);
|
||||
show_values(value);
|
||||
delete value;
|
||||
node = new SGPropertyNode;
|
||||
node->setDoubleValue(1.0/3.0);
|
||||
show_values(node);
|
||||
delete node;
|
||||
cout << endl;
|
||||
|
||||
cout << "Testing coercion from string (expect 10e4)" << endl;
|
||||
value = new SGValue;
|
||||
value->setStringValue("10e4");
|
||||
show_values(value);
|
||||
delete value;
|
||||
node = new SGPropertyNode;
|
||||
node->setStringValue("10e4");
|
||||
show_values(node);
|
||||
delete node;
|
||||
cout << endl;
|
||||
|
||||
cout << "Testing coercion from unknown (expect -10e-4)" << endl;
|
||||
value = new SGValue;
|
||||
value->setUnknownValue("-10e-4");
|
||||
show_values(value);
|
||||
delete value;
|
||||
cout << "Testing coercion from unspecified (expect -10e-4)" << endl;
|
||||
node = new SGPropertyNode;
|
||||
node->setUnspecifiedValue("-10e-4");
|
||||
show_values(node);
|
||||
delete node;
|
||||
cout << endl;
|
||||
|
||||
//
|
||||
// Test coercion for setters.
|
||||
//
|
||||
|
||||
value = new SGValue;
|
||||
node = new SGPropertyNode;
|
||||
|
||||
cout << "Testing coercion to bool from bool (expect false)" << endl;
|
||||
value->setBoolValue(false);
|
||||
show_values(value);
|
||||
node->setBoolValue(false);
|
||||
show_values(node);
|
||||
cout << endl;
|
||||
|
||||
cout << "Testing coercion to bool from int (expect 1)" << endl;
|
||||
value->setIntValue(1);
|
||||
show_values(value);
|
||||
node->setIntValue(1);
|
||||
show_values(node);
|
||||
cout << endl;
|
||||
|
||||
cout << "Testing coercion to bool from float (expect 1.1)" << endl;
|
||||
value->setFloatValue(1.1);
|
||||
show_values(value);
|
||||
node->setFloatValue(1.1);
|
||||
show_values(node);
|
||||
cout << endl;
|
||||
|
||||
cout << "Testing coercion to bool from double (expect 1.1)" << endl;
|
||||
value->setDoubleValue(1.1);
|
||||
show_values(value);
|
||||
node->setDoubleValue(1.1);
|
||||
show_values(node);
|
||||
cout << endl;
|
||||
|
||||
cout << "Testing coercion to bool from string (expect 1e10)" << endl;
|
||||
value->setStringValue("1e10");
|
||||
show_values(value);
|
||||
node->setStringValue("1e10");
|
||||
show_values(node);
|
||||
cout << endl;
|
||||
|
||||
cout << "Testing coercion to bool from unknown (expect 1e10)" << endl;
|
||||
value->setUnknownValue("1e10");
|
||||
show_values(value);
|
||||
cout << "Testing coercion to bool from unspecified (expect 1e10)" << endl;
|
||||
node->setUnspecifiedValue("1e10");
|
||||
show_values(node);
|
||||
cout << endl;
|
||||
|
||||
// Test tying to a pointer.
|
||||
@@ -159,67 +159,67 @@ test_value ()
|
||||
static int myValue = 10;
|
||||
|
||||
cout << "Testing tying to a pointer (expect 10)" << endl;
|
||||
if (!value->tie(SGRawValuePointer<int>(&myValue)))
|
||||
if (!node->tie(SGRawValuePointer<int>(&myValue), false))
|
||||
cout << "*** FAILED TO TIE VALUE!!!" << endl;
|
||||
show_values(value);
|
||||
show_values(node);
|
||||
cout << endl;
|
||||
|
||||
cout << "Changing base variable (expect -5)" << endl;
|
||||
myValue = -5;
|
||||
show_values(value);
|
||||
if (!value->untie())
|
||||
cout << "*** FAIELD TO UNTIE VALUE!!!" << endl;
|
||||
show_values(node);
|
||||
if (!node->untie())
|
||||
cout << "*** FAILED TO UNTIE VALUE!!!" << endl;
|
||||
cout << endl;
|
||||
|
||||
|
||||
// Test tying to static functions.
|
||||
|
||||
cout << "Create a new int value (expect 10)" << endl;
|
||||
value->setIntValue(10);
|
||||
show_values(value);
|
||||
node->setIntValue(10);
|
||||
show_values(node);
|
||||
cout << endl;
|
||||
|
||||
cout << "Testing tying to static getter (expect 100)" << endl;
|
||||
if (!value->tie(SGRawValueFunctions<int>(get100)))
|
||||
if (!node->tie(SGRawValueFunctions<int>(get100)))
|
||||
cout << "*** FAILED TO TIE VALUE!!!" << endl;
|
||||
show_values(value);
|
||||
show_values(node);
|
||||
cout << endl;
|
||||
|
||||
cout << "Try changing value with no setter (expect 100)" << endl;
|
||||
if (value->setIntValue(200))
|
||||
if (node->setIntValue(200))
|
||||
cout << "*** setIntValue did not return false!!!" << endl;
|
||||
show_values(value);
|
||||
show_values(node);
|
||||
cout << endl;
|
||||
|
||||
cout << "Untie value (expect 100)" << endl;
|
||||
if (!value->untie())
|
||||
if (!node->untie())
|
||||
cout << "*** FAILED TO UNTIE VALUE!!!" << endl;
|
||||
show_values(value);
|
||||
show_values(node);
|
||||
cout << endl;
|
||||
|
||||
cout << "Try changing value (expect 200)" << endl;
|
||||
if (!value->setIntValue(200))
|
||||
if (!node->setIntValue(200))
|
||||
cout << "*** setIntValue RETURNED FALSE!!!" << endl;
|
||||
show_values(value);
|
||||
show_values(node);
|
||||
cout << endl;
|
||||
|
||||
// Test tying to indexed static functions.
|
||||
|
||||
cout << "Create a new int value (expect 10)" << endl;
|
||||
value->setIntValue(10);
|
||||
show_values(value);
|
||||
node->setIntValue(10);
|
||||
show_values(node);
|
||||
cout << endl;
|
||||
|
||||
cout << "Testing tying to indexed static getter (0.3333...)" << endl;
|
||||
if (!value->tie(SGRawValueFunctionsIndexed<double>(3, getNum)))
|
||||
if (!node->tie(SGRawValueFunctionsIndexed<double>(3, getNum)))
|
||||
cout << "*** FAILED TO TIE VALUE!!!" << endl;
|
||||
show_values(value);
|
||||
show_values(node);
|
||||
cout << endl;
|
||||
|
||||
cout << "Untie value (expect 0.3333...)" << endl;
|
||||
if (!value->untie())
|
||||
if (!node->untie())
|
||||
cout << "*** FAILED TO UNTIE VALUE!!!" << endl;
|
||||
show_values(value);
|
||||
show_values(node);
|
||||
cout << endl;
|
||||
|
||||
|
||||
@@ -230,39 +230,39 @@ test_value ()
|
||||
SGRawValueMethods<class Stuff,float> tiedstuff(stuff,
|
||||
&Stuff::getStuff,
|
||||
&Stuff::setStuff);
|
||||
if (!value->tie(tiedstuff, false))
|
||||
if (!node->tie(tiedstuff, false))
|
||||
cout << "*** FAILED TO TIE VALUE!!!" << endl;
|
||||
show_values(value);
|
||||
show_values(node);
|
||||
cout << endl;
|
||||
|
||||
cout << "Try untying from object (expect 199)" << endl;
|
||||
if (!value->untie())
|
||||
if (!node->untie())
|
||||
cout << "*** FAILED TO UNTIE VALUE!!!" << endl;
|
||||
show_values(value);
|
||||
show_values(node);
|
||||
cout << endl;
|
||||
|
||||
cout << "Try tying to an indexed method (expect 199)" << endl;
|
||||
if (!value->tie(SGRawValueMethodsIndexed<class Stuff, float>
|
||||
if (!node->tie(SGRawValueMethodsIndexed<class Stuff, float>
|
||||
(stuff, 2, &Stuff::getStuff, &Stuff::setStuff)))
|
||||
cout << "*** FAILED TO TIE VALUE!!!" << endl;
|
||||
show_values(value);
|
||||
show_values(node);
|
||||
cout << endl;
|
||||
|
||||
value->untie();
|
||||
node->untie();
|
||||
|
||||
cout << "Change value (expect 50)" << endl;
|
||||
if (!value->setIntValue(50))
|
||||
if (!node->setIntValue(50))
|
||||
cout << "*** FAILED TO SET VALUE!!!" << endl;
|
||||
show_values(value);
|
||||
show_values(node);
|
||||
cout << endl;
|
||||
|
||||
cout << "Try tying to an object with defaults (expect 50)" << endl;
|
||||
if (!value->tie(tiedstuff, true))
|
||||
if (!node->tie(tiedstuff, true))
|
||||
cout << "*** FAILED TO TIE VALUE!!!" << endl;
|
||||
show_values(value);
|
||||
show_values(node);
|
||||
cout << endl;
|
||||
|
||||
delete value;
|
||||
delete node;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ waytest_LDADD = \
|
||||
$(top_builddir)/simgear/math/libsgmath.a \
|
||||
$(top_builddir)/simgear/debug/libsgdebug.a \
|
||||
$(top_builddir)/simgear/misc/libsgmisc.a \
|
||||
$(top_builddir)/simgear/xml/libsgxml.a \
|
||||
-lz
|
||||
|
||||
routetest_SOURCES = routetest.cxx
|
||||
@@ -26,4 +27,4 @@ routetest_SOURCES = routetest.cxx
|
||||
routetest_LDADD = \
|
||||
$(top_builddir)/simgear/route/libsgroute.a \
|
||||
$(top_builddir)/simgear/math/libsgmath.a \
|
||||
$(top_builddir)/simgear/debug/libsgdebug.a
|
||||
$(top_builddir)/simgear/debug/libsgdebug.a
|
||||
|
||||
@@ -2,11 +2,12 @@ includedir = @includedir@/screen
|
||||
|
||||
lib_LIBRARIES = libsgscreen.a
|
||||
|
||||
include_HEADERS = screen-dump.hxx
|
||||
include_HEADERS = screen-dump.hxx tr.h
|
||||
|
||||
libsgscreen_a_SOURCES = \
|
||||
GLBitmaps.cxx GLBitmaps.h \
|
||||
screen-dump.cxx \
|
||||
tr.cxx \
|
||||
win32-printer.h
|
||||
|
||||
INCLUDES += -I$(top_srcdir)
|
||||
|
||||
@@ -0,0 +1,509 @@
|
||||
/* $Id$ */
|
||||
|
||||
/*
|
||||
* $Log$
|
||||
* Revision 1.2 2001/06/27 02:48:01 curt
|
||||
* Fixed a type conversion bug that could trip up some of the pickier compilers
|
||||
* out there.
|
||||
*
|
||||
* Revision 1.1 2001/06/26 15:19:39 curt
|
||||
* Added tr.cxx / tr.h, Brian Paul's LGPL'd tiled rendering support libs for
|
||||
* rendering ultra high res "tiled" screen shots.
|
||||
*
|
||||
* Revision 1.9 1998/01/29 16:56:54 brianp
|
||||
* allow trOrtho() and trFrustum() to be called at any time, minor clean-up
|
||||
*
|
||||
* Revision 1.8 1998/01/28 19:47:39 brianp
|
||||
* minor clean-up for C++
|
||||
*
|
||||
* Revision 1.7 1997/07/21 17:34:38 brianp
|
||||
* added tile borders
|
||||
*
|
||||
* Revision 1.6 1997/07/21 15:47:35 brianp
|
||||
* renamed all "near" and "far" variables
|
||||
*
|
||||
* Revision 1.5 1997/04/26 21:23:25 brianp
|
||||
* added trRasterPos3f function
|
||||
*
|
||||
* Revision 1.4 1997/04/26 19:59:36 brianp
|
||||
* set CurrentTile to -1 before first tile and after last tile
|
||||
*
|
||||
* Revision 1.3 1997/04/22 23:51:15 brianp
|
||||
* added WIN32 header stuff, removed tabs
|
||||
*
|
||||
* Revision 1.2 1997/04/19 23:26:10 brianp
|
||||
* many API changes
|
||||
*
|
||||
* Revision 1.1 1997/04/18 21:53:05 brianp
|
||||
* Initial revision
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* Tiled Rendering library
|
||||
* Version 1.1
|
||||
* Copyright (C) Brian Paul
|
||||
*/
|
||||
|
||||
|
||||
#include <assert.h>
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#ifdef WIN32
|
||||
#include <windows.h>
|
||||
#endif
|
||||
#include <GL/gl.h>
|
||||
#include <GL/glu.h>
|
||||
#include <plib/ssg.h>
|
||||
#include "tr.h"
|
||||
|
||||
|
||||
#define DEFAULT_TILE_WIDTH 256
|
||||
#define DEFAULT_TILE_HEIGHT 256
|
||||
#define DEFAULT_TILE_BORDER 0
|
||||
|
||||
|
||||
struct _TRctx {
|
||||
/* Final image parameters */
|
||||
GLint ImageWidth, ImageHeight;
|
||||
GLenum ImageFormat, ImageType;
|
||||
GLvoid *ImageBuffer;
|
||||
|
||||
/* Tile parameters */
|
||||
GLint TileWidth, TileHeight;
|
||||
GLint TileWidthNB, TileHeightNB;
|
||||
GLint TileBorder;
|
||||
GLenum TileFormat, TileType;
|
||||
GLvoid *TileBuffer;
|
||||
|
||||
/* Projection parameters */
|
||||
GLboolean Perspective;
|
||||
GLdouble Left;
|
||||
GLdouble Right;
|
||||
GLdouble Bottom;
|
||||
GLdouble Top;
|
||||
GLdouble Near;
|
||||
GLdouble Far;
|
||||
|
||||
/* Misc */
|
||||
TRenum RowOrder;
|
||||
GLint Rows, Columns;
|
||||
GLint CurrentTile;
|
||||
GLint CurrentTileWidth, CurrentTileHeight;
|
||||
GLint CurrentRow, CurrentColumn;
|
||||
|
||||
GLint ViewportSave[4];
|
||||
};
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Misc setup including computing number of tiles (rows and columns).
|
||||
*/
|
||||
static void Setup(TRcontext *tr)
|
||||
{
|
||||
if (!tr)
|
||||
return;
|
||||
|
||||
tr->Columns = (tr->ImageWidth + tr->TileWidthNB - 1) / tr->TileWidthNB;
|
||||
tr->Rows = (tr->ImageHeight + tr->TileHeightNB - 1) / tr->TileHeightNB;
|
||||
tr->CurrentTile = 0;
|
||||
|
||||
assert(tr->Columns >= 0);
|
||||
assert(tr->Rows >= 0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
TRcontext *trNew(void)
|
||||
{
|
||||
TRcontext *tr = (TRcontext *) calloc(1, sizeof(TRcontext));
|
||||
if (tr) {
|
||||
tr->TileWidth = DEFAULT_TILE_WIDTH;
|
||||
tr->TileHeight = DEFAULT_TILE_HEIGHT;
|
||||
tr->TileBorder = DEFAULT_TILE_BORDER;
|
||||
tr->RowOrder = TR_BOTTOM_TO_TOP;
|
||||
tr->CurrentTile = -1;
|
||||
}
|
||||
return (TRcontext *) tr;
|
||||
}
|
||||
|
||||
|
||||
void trDelete(TRcontext *tr)
|
||||
{
|
||||
if (tr)
|
||||
free(tr);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void trTileSize(TRcontext *tr, GLint width, GLint height, GLint border)
|
||||
{
|
||||
if (!tr)
|
||||
return;
|
||||
|
||||
assert(border >= 0);
|
||||
assert(width >= 1);
|
||||
assert(height >= 1);
|
||||
assert(width >= 2*border);
|
||||
assert(height >= 2*border);
|
||||
|
||||
tr->TileBorder = border;
|
||||
tr->TileWidth = width;
|
||||
tr->TileHeight = height;
|
||||
tr->TileWidthNB = width - 2 * border;
|
||||
tr->TileHeightNB = height - 2 * border;
|
||||
Setup(tr);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void trTileBuffer(TRcontext *tr, GLenum format, GLenum type, GLvoid *image)
|
||||
{
|
||||
if (!tr)
|
||||
return;
|
||||
|
||||
tr->TileFormat = format;
|
||||
tr->TileType = type;
|
||||
tr->TileBuffer = image;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void trImageSize(TRcontext *tr, GLint width, GLint height)
|
||||
{
|
||||
if (!tr)
|
||||
return;
|
||||
|
||||
tr->ImageWidth = width;
|
||||
tr->ImageHeight = height;
|
||||
Setup(tr);
|
||||
}
|
||||
|
||||
|
||||
void trImageBuffer(TRcontext *tr, GLenum format, GLenum type, GLvoid *image)
|
||||
{
|
||||
if (!tr)
|
||||
return;
|
||||
|
||||
tr->ImageFormat = format;
|
||||
tr->ImageType = type;
|
||||
tr->ImageBuffer = image;
|
||||
}
|
||||
|
||||
|
||||
GLint trGet(TRcontext *tr, TRenum param)
|
||||
{
|
||||
if (!tr)
|
||||
return 0;
|
||||
switch (param) {
|
||||
case TR_TILE_WIDTH:
|
||||
return tr->TileWidth;
|
||||
case TR_TILE_HEIGHT:
|
||||
return tr->TileHeight;
|
||||
case TR_TILE_BORDER:
|
||||
return tr->TileBorder;
|
||||
case TR_IMAGE_WIDTH:
|
||||
return tr->ImageWidth;
|
||||
case TR_IMAGE_HEIGHT:
|
||||
return tr->ImageHeight;
|
||||
case TR_ROWS:
|
||||
return tr->Rows;
|
||||
case TR_COLUMNS:
|
||||
return tr->Columns;
|
||||
case TR_CURRENT_ROW:
|
||||
if (tr->CurrentTile<0)
|
||||
return -1;
|
||||
else
|
||||
return tr->CurrentRow;
|
||||
case TR_CURRENT_COLUMN:
|
||||
if (tr->CurrentTile<0)
|
||||
return -1;
|
||||
else
|
||||
return tr->CurrentColumn;
|
||||
case TR_CURRENT_TILE_WIDTH:
|
||||
return tr->CurrentTileWidth;
|
||||
case TR_CURRENT_TILE_HEIGHT:
|
||||
return tr->CurrentTileHeight;
|
||||
case TR_ROW_ORDER:
|
||||
return (GLint) tr->RowOrder;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
GLdouble trGetD(TRcontext *tr, TRenum param)
|
||||
{
|
||||
if (!tr)
|
||||
return 0.0;
|
||||
switch (param) {
|
||||
case TR_LEFT:
|
||||
return tr->Left;
|
||||
case TR_RIGHT:
|
||||
return tr->Right;
|
||||
case TR_BOTTOM:
|
||||
return tr->Bottom;
|
||||
case TR_TOP:
|
||||
return tr->Top;
|
||||
case TR_NEAR:
|
||||
return tr->Near;
|
||||
case TR_FAR:
|
||||
return tr->Far;
|
||||
default:
|
||||
return 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
void trRowOrder(TRcontext *tr, TRenum order)
|
||||
{
|
||||
if (!tr)
|
||||
return;
|
||||
|
||||
if (order==TR_TOP_TO_BOTTOM || order==TR_BOTTOM_TO_TOP)
|
||||
tr->RowOrder = order;
|
||||
}
|
||||
|
||||
|
||||
void trOrtho(TRcontext *tr,
|
||||
GLdouble left, GLdouble right,
|
||||
GLdouble bottom, GLdouble top,
|
||||
GLdouble zNear, GLdouble zFar)
|
||||
{
|
||||
if (!tr)
|
||||
return;
|
||||
|
||||
tr->Perspective = GL_FALSE;
|
||||
tr->Left = left;
|
||||
tr->Right = right;
|
||||
tr->Bottom = bottom;
|
||||
tr->Top = top;
|
||||
tr->Near = zNear;
|
||||
tr->Far = zFar;
|
||||
}
|
||||
|
||||
|
||||
void trFrustum(TRcontext *tr,
|
||||
GLdouble left, GLdouble right,
|
||||
GLdouble bottom, GLdouble top,
|
||||
GLdouble zNear, GLdouble zFar)
|
||||
{
|
||||
if (!tr)
|
||||
return;
|
||||
|
||||
tr->Perspective = GL_TRUE;
|
||||
tr->Left = left;
|
||||
tr->Right = right;
|
||||
tr->Bottom = bottom;
|
||||
tr->Top = top;
|
||||
tr->Near = zNear;
|
||||
tr->Far = zFar;
|
||||
}
|
||||
|
||||
|
||||
void trPerspective(TRcontext *tr,
|
||||
GLdouble fovy, GLdouble aspect,
|
||||
GLdouble zNear, GLdouble zFar )
|
||||
{
|
||||
GLdouble xmin, xmax, ymin, ymax;
|
||||
ymax = zNear * tan(fovy * 3.14159265 / 360.0);
|
||||
ymin = -ymax;
|
||||
xmin = ymin * aspect;
|
||||
xmax = ymax * aspect;
|
||||
trFrustum(tr, xmin, xmax, ymin, ymax, zNear, zFar);
|
||||
}
|
||||
|
||||
|
||||
void trBeginTile(TRcontext *tr)
|
||||
{
|
||||
GLint matrixMode;
|
||||
GLint tileWidth, tileHeight, border;
|
||||
GLdouble left, right, bottom, top;
|
||||
|
||||
if (!tr)
|
||||
return;
|
||||
|
||||
if (tr->CurrentTile <= 0) {
|
||||
Setup(tr);
|
||||
/* Save user's viewport, will be restored after last tile rendered */
|
||||
glGetIntegerv(GL_VIEWPORT, tr->ViewportSave);
|
||||
}
|
||||
|
||||
/* which tile (by row and column) we're about to render */
|
||||
if (tr->RowOrder==TR_BOTTOM_TO_TOP) {
|
||||
tr->CurrentRow = tr->CurrentTile / tr->Columns;
|
||||
tr->CurrentColumn = tr->CurrentTile % tr->Columns;
|
||||
}
|
||||
else if (tr->RowOrder==TR_TOP_TO_BOTTOM) {
|
||||
tr->CurrentRow = tr->Rows - (tr->CurrentTile / tr->Columns) - 1;
|
||||
tr->CurrentColumn = tr->CurrentTile % tr->Columns;
|
||||
}
|
||||
else {
|
||||
/* This should never happen */
|
||||
abort();
|
||||
}
|
||||
assert(tr->CurrentRow < tr->Rows);
|
||||
assert(tr->CurrentColumn < tr->Columns);
|
||||
|
||||
border = tr->TileBorder;
|
||||
|
||||
/* Compute actual size of this tile with border */
|
||||
if (tr->CurrentRow < tr->Rows-1)
|
||||
tileHeight = tr->TileHeight;
|
||||
else
|
||||
tileHeight = tr->ImageHeight - (tr->Rows-1) * (tr->TileHeightNB) + 2 * border;
|
||||
|
||||
if (tr->CurrentColumn < tr->Columns-1)
|
||||
tileWidth = tr->TileWidth;
|
||||
else
|
||||
tileWidth = tr->ImageWidth - (tr->Columns-1) * (tr->TileWidthNB) + 2 * border;
|
||||
|
||||
/* Save tile size, with border */
|
||||
tr->CurrentTileWidth = tileWidth;
|
||||
tr->CurrentTileHeight = tileHeight;
|
||||
|
||||
glViewport(0, 0, tileWidth, tileHeight); /* tile size including border */
|
||||
|
||||
/* save current matrix mode */
|
||||
glGetIntegerv(GL_MATRIX_MODE, &matrixMode);
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
|
||||
/* compute projection parameters */
|
||||
left = tr->Left + (tr->Right - tr->Left)
|
||||
* (tr->CurrentColumn * tr->TileWidthNB - border) / tr->ImageWidth;
|
||||
right = left + (tr->Right - tr->Left) * tileWidth / tr->ImageWidth;
|
||||
bottom = tr->Bottom + (tr->Top - tr->Bottom)
|
||||
* (tr->CurrentRow * tr->TileHeightNB - border) / tr->ImageHeight;
|
||||
top = bottom + (tr->Top - tr->Bottom) * tileHeight / tr->ImageHeight;
|
||||
|
||||
ssgSetFrustum ( left, right, bottom, top, tr->Near, tr->Far );
|
||||
|
||||
/* restore user's matrix mode */
|
||||
glMatrixMode( (GLenum)matrixMode );
|
||||
}
|
||||
|
||||
|
||||
|
||||
int trEndTile(TRcontext *tr)
|
||||
{
|
||||
GLint prevRowLength, prevSkipRows, prevSkipPixels /*, prevAlignment */;
|
||||
|
||||
if (!tr)
|
||||
return 0;
|
||||
|
||||
assert(tr->CurrentTile>=0);
|
||||
|
||||
/* be sure OpenGL rendering is finished */
|
||||
glFlush();
|
||||
|
||||
/* save current glPixelStore values */
|
||||
glGetIntegerv(GL_PACK_ROW_LENGTH, &prevRowLength);
|
||||
glGetIntegerv(GL_PACK_SKIP_ROWS, &prevSkipRows);
|
||||
glGetIntegerv(GL_PACK_SKIP_PIXELS, &prevSkipPixels);
|
||||
/*glGetIntegerv(GL_PACK_ALIGNMENT, &prevAlignment);*/
|
||||
|
||||
if (tr->TileBuffer) {
|
||||
GLint srcX = tr->TileBorder;
|
||||
GLint srcY = tr->TileBorder;
|
||||
GLint srcWidth = tr->TileWidthNB;
|
||||
GLint srcHeight = tr->TileHeightNB;
|
||||
glReadPixels(srcX, srcY, srcWidth, srcHeight,
|
||||
tr->TileFormat, tr->TileType, tr->TileBuffer);
|
||||
}
|
||||
|
||||
if (tr->ImageBuffer) {
|
||||
GLint srcX = tr->TileBorder;
|
||||
GLint srcY = tr->TileBorder;
|
||||
GLint srcWidth = tr->CurrentTileWidth - 2 * tr->TileBorder;
|
||||
GLint srcHeight = tr->CurrentTileHeight - 2 * tr->TileBorder;
|
||||
GLint destX = tr->TileWidthNB * tr->CurrentColumn;
|
||||
GLint destY = tr->TileHeightNB * tr->CurrentRow;
|
||||
|
||||
/* setup pixel store for glReadPixels */
|
||||
glPixelStorei(GL_PACK_ROW_LENGTH, tr->ImageWidth);
|
||||
glPixelStorei(GL_PACK_SKIP_ROWS, destY);
|
||||
glPixelStorei(GL_PACK_SKIP_PIXELS, destX);
|
||||
/*glPixelStorei(GL_PACK_ALIGNMENT, 1);*/
|
||||
|
||||
/* read the tile into the final image */
|
||||
glReadPixels(srcX, srcY, srcWidth, srcHeight,
|
||||
tr->ImageFormat, tr->ImageType, tr->ImageBuffer);
|
||||
}
|
||||
|
||||
/* restore previous glPixelStore values */
|
||||
glPixelStorei(GL_PACK_ROW_LENGTH, prevRowLength);
|
||||
glPixelStorei(GL_PACK_SKIP_ROWS, prevSkipRows);
|
||||
glPixelStorei(GL_PACK_SKIP_PIXELS, prevSkipPixels);
|
||||
/*glPixelStorei(GL_PACK_ALIGNMENT, prevAlignment);*/
|
||||
|
||||
/* increment tile counter, return 1 if more tiles left to render */
|
||||
tr->CurrentTile++;
|
||||
if (tr->CurrentTile >= tr->Rows * tr->Columns) {
|
||||
/* restore user's viewport */
|
||||
glViewport(tr->ViewportSave[0], tr->ViewportSave[1],
|
||||
tr->ViewportSave[2], tr->ViewportSave[3]);
|
||||
tr->CurrentTile = -1; /* all done */
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Replacement for glRastePos3f() which avoids the problem with invalid
|
||||
* raster pos.
|
||||
*/
|
||||
void trRasterPos3f(TRcontext *tr, GLfloat x, GLfloat y, GLfloat z)
|
||||
{
|
||||
if (tr->CurrentTile<0) {
|
||||
/* not doing tile rendering right now. Let OpenGL do this. */
|
||||
glRasterPos3f(x, y, z);
|
||||
}
|
||||
else {
|
||||
GLdouble modelview[16], proj[16];
|
||||
GLint viewport[4];
|
||||
GLdouble winX, winY, winZ;
|
||||
|
||||
/* Get modelview, projection and viewport */
|
||||
glGetDoublev(GL_MODELVIEW_MATRIX, modelview);
|
||||
glGetDoublev(GL_PROJECTION_MATRIX, proj);
|
||||
viewport[0] = 0;
|
||||
viewport[1] = 0;
|
||||
viewport[2] = tr->CurrentTileWidth;
|
||||
viewport[3] = tr->CurrentTileHeight;
|
||||
|
||||
/* Project object coord to window coordinate */
|
||||
if (gluProject(x, y, z, modelview, proj, viewport, &winX, &winY, &winZ)){
|
||||
|
||||
/* set raster pos to window coord (0,0) */
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glPushMatrix();
|
||||
glLoadIdentity();
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glPushMatrix();
|
||||
glLoadIdentity();
|
||||
glOrtho(0.0, tr->CurrentTileWidth,
|
||||
0.0, tr->CurrentTileHeight, 0.0, 1.0);
|
||||
glRasterPos3f(0.0, 0.0, -winZ);
|
||||
|
||||
/* Now use empty bitmap to adjust raster position to (winX,winY) */
|
||||
{
|
||||
GLubyte bitmap[1] = {0};
|
||||
glBitmap(1, 1, 0.0, 0.0, winX, winY, bitmap);
|
||||
}
|
||||
|
||||
/* restore original matrices */
|
||||
glPopMatrix(); /*proj*/
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glPopMatrix();
|
||||
}
|
||||
#ifdef DEBUG
|
||||
if (glGetError())
|
||||
printf("GL error!\n");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,170 @@
|
||||
/* $Id$ */
|
||||
|
||||
/*
|
||||
* $Log$
|
||||
* Revision 1.1 2001/06/26 15:19:39 curt
|
||||
* Added tr.cxx / tr.h, Brian Paul's LGPL'd tiled rendering support libs for
|
||||
* rendering ultra high res "tiled" screen shots.
|
||||
*
|
||||
* Revision 1.5 1997/07/21 17:34:07 brianp
|
||||
* added tile borders, incremented version to 1.1
|
||||
*
|
||||
* Revision 1.4 1997/07/21 15:47:35 brianp
|
||||
* renamed all "near" and "far" variables
|
||||
*
|
||||
* Revision 1.3 1997/04/26 21:23:25 brianp
|
||||
* added trRasterPos3f function
|
||||
*
|
||||
* Revision 1.2 1997/04/19 23:26:10 brianp
|
||||
* many API changes
|
||||
*
|
||||
* Revision 1.1 1997/04/18 21:53:05 brianp
|
||||
* Initial revision
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* Tiled Rendering library
|
||||
* Version 1.1
|
||||
* Copyright (C) Brian Paul
|
||||
*
|
||||
*
|
||||
* This library allows one to render arbitrarily large images with OpenGL.
|
||||
* The basic idea is to break the image into tiles which are rendered one
|
||||
* at a time. The tiles are assembled together to form the final, large
|
||||
* image. Tiles and images can be of any size.
|
||||
*
|
||||
* Basic usage:
|
||||
*
|
||||
* 1. Allocate a tile rendering context:
|
||||
* TRcontext t = trNew();
|
||||
*
|
||||
* 2. Specify the final image buffer and tile size:
|
||||
* GLubyte image[W][H][4]
|
||||
* trImageSize(t, W, H);
|
||||
* trImageBuffer(t, GL_RGBA, GL_UNSIGNED_BYTE, (GLubyte *) image);
|
||||
*
|
||||
* 3. Setup your projection:
|
||||
* trFrustum(t, left, right, bottom top, near, far);
|
||||
* or
|
||||
* trOrtho(t, left, right, bottom top, near, far);
|
||||
* or
|
||||
* trPerspective(t, fovy, aspect, near, far);
|
||||
*
|
||||
* 4. Render the tiles:
|
||||
* do {
|
||||
* trBeginTile(t);
|
||||
* DrawMyScene();
|
||||
* } while (trEndTile(t));
|
||||
*
|
||||
* You provide the DrawMyScene() function which calls glClear() and
|
||||
* draws all your stuff.
|
||||
*
|
||||
* 5. The image array is now complete. Display it, write it to a file, etc.
|
||||
*
|
||||
* 6. Delete the tile rendering context when finished:
|
||||
* trDelete(t);
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef TR_H
|
||||
#define TR_H
|
||||
|
||||
|
||||
#include <GL/gl.h>
|
||||
|
||||
|
||||
//#ifdef __cplusplus
|
||||
//extern "C" {
|
||||
//#endif
|
||||
|
||||
|
||||
#define TR_VERSION "1.1"
|
||||
#define TR_MAJOR_VERSION 1
|
||||
#define TR_MINOR_VERSION 1
|
||||
|
||||
|
||||
typedef struct _TRctx TRcontext;
|
||||
|
||||
|
||||
typedef enum {
|
||||
TR_TILE_WIDTH = 100,
|
||||
TR_TILE_HEIGHT,
|
||||
TR_TILE_BORDER,
|
||||
TR_IMAGE_WIDTH,
|
||||
TR_IMAGE_HEIGHT,
|
||||
TR_ROWS,
|
||||
TR_COLUMNS,
|
||||
TR_CURRENT_ROW,
|
||||
TR_CURRENT_COLUMN,
|
||||
TR_CURRENT_TILE_WIDTH,
|
||||
TR_CURRENT_TILE_HEIGHT,
|
||||
TR_ROW_ORDER,
|
||||
TR_TOP_TO_BOTTOM,
|
||||
TR_BOTTOM_TO_TOP,
|
||||
TR_LEFT,
|
||||
TR_RIGHT,
|
||||
TR_BOTTOM,
|
||||
TR_TOP,
|
||||
TR_NEAR,
|
||||
TR_FAR
|
||||
} TRenum;
|
||||
|
||||
|
||||
|
||||
extern TRcontext *trNew(void);
|
||||
|
||||
extern void trDelete(TRcontext *tr);
|
||||
|
||||
|
||||
extern void trTileSize(TRcontext *tr, GLint width, GLint height, GLint border);
|
||||
|
||||
extern void trTileBuffer(TRcontext *tr, GLenum format, GLenum type,
|
||||
GLvoid *image);
|
||||
|
||||
|
||||
extern void trImageSize(TRcontext *tr, GLint width, GLint height);
|
||||
|
||||
extern void trImageBuffer(TRcontext *tr, GLenum format, GLenum type,
|
||||
GLvoid *image);
|
||||
|
||||
|
||||
extern void trRowOrder(TRcontext *tr, TRenum order);
|
||||
|
||||
|
||||
extern GLint trGet(TRcontext *tr, TRenum param);
|
||||
extern GLdouble trGetD(TRcontext *tr, TRenum param);
|
||||
|
||||
|
||||
extern void trOrtho(TRcontext *tr,
|
||||
GLdouble left, GLdouble right,
|
||||
GLdouble bottom, GLdouble top,
|
||||
GLdouble zNear, GLdouble zFar);
|
||||
|
||||
extern void trFrustum(TRcontext *tr,
|
||||
GLdouble left, GLdouble right,
|
||||
GLdouble bottom, GLdouble top,
|
||||
GLdouble zNear, GLdouble zFar);
|
||||
|
||||
extern void trPerspective(TRcontext *tr,
|
||||
GLdouble fovy, GLdouble aspect,
|
||||
GLdouble zNear, GLdouble zFar );
|
||||
|
||||
|
||||
extern void trBeginTile(TRcontext *tr);
|
||||
|
||||
extern int trEndTile(TRcontext *tr);
|
||||
|
||||
|
||||
extern void trRasterPos3f(TRcontext *tr, GLfloat x, GLfloat y, GLfloat z);
|
||||
|
||||
|
||||
|
||||
//#ifdef __cplusplus
|
||||
//}
|
||||
//#endif
|
||||
|
||||
|
||||
#endif
|
||||
+69
-24
@@ -117,11 +117,15 @@ SGTime::SGTime() {
|
||||
SGTime::~SGTime()
|
||||
{
|
||||
if ( tzContainer != NULL ) {
|
||||
delete tzContainer;
|
||||
TimezoneContainer *tmp = tzContainer;
|
||||
tzContainer = NULL;
|
||||
delete tmp;
|
||||
}
|
||||
|
||||
if ( zonename != NULL ) {
|
||||
delete zonename;
|
||||
char *tmp = zonename;
|
||||
zonename = NULL;
|
||||
delete tmp;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -188,6 +192,7 @@ static double sidereal_course( time_t cur_time, struct tm *gmt, double lng )
|
||||
// Update the time related variables
|
||||
void SGTime::update( double lon, double lat, long int warp ) {
|
||||
double gst_precise, gst_course;
|
||||
|
||||
#ifdef _MSC_VER
|
||||
tm * gmt = &m_gmt;
|
||||
#endif
|
||||
@@ -213,11 +218,8 @@ void SGTime::update( double lon, double lat, long int warp ) {
|
||||
<< gmt->tm_hour << ":" << gmt->tm_min << ":"
|
||||
<< gmt->tm_sec );
|
||||
|
||||
// calculate modified Julian date
|
||||
// t->mjd = cal_mjd ((int)(t->gmt->tm_mon+1), (double)t->gmt->tm_mday,
|
||||
// (int)(t->gmt->tm_year + 1900));
|
||||
mjd = sgTimeCalcMJD( (int)(gmt->tm_mon+1), (double)gmt->tm_mday,
|
||||
(int)(gmt->tm_year + 1900) );
|
||||
// calculate modified Julian date starting with current
|
||||
mjd = sgTimeCurrentMJD( warp );
|
||||
|
||||
// add in partial day
|
||||
mjd += (gmt->tm_hour / 24.0) + (gmt->tm_min / (24.0 * 60.0)) +
|
||||
@@ -256,23 +258,24 @@ void SGTime::update( double lon, double lat, long int warp ) {
|
||||
|
||||
|
||||
// Given lon/lat, update timezone information and local_offset
|
||||
void SGTime::updateLocal( double lon, double lat, const string& root )
|
||||
{
|
||||
time_t currGMT;
|
||||
time_t aircraftLocalTime;
|
||||
GeoCoord location( SGD_RADIANS_TO_DEGREES * lat, SGD_RADIANS_TO_DEGREES * lon );
|
||||
GeoCoord* nearestTz = tzContainer->getNearest(location);
|
||||
SGPath zone( root );
|
||||
zone.append ( nearestTz->getDescription() );
|
||||
if ( zonename ) {
|
||||
delete zonename;
|
||||
}
|
||||
zonename = strdup( zone.c_str() );
|
||||
currGMT = sgTimeGetGMT( gmtime(&cur_time) );
|
||||
aircraftLocalTime = sgTimeGetGMT( (fgLocaltime(&cur_time, zone.c_str())) );
|
||||
local_offset = aircraftLocalTime - currGMT;
|
||||
// cout << "Using " << local_offset << " as local time offset Timezone is "
|
||||
// << zonename << endl;
|
||||
void SGTime::updateLocal( double lon, double lat, const string& root ) {
|
||||
time_t currGMT;
|
||||
time_t aircraftLocalTime;
|
||||
GeoCoord location( SGD_RADIANS_TO_DEGREES * lat, SGD_RADIANS_TO_DEGREES * lon );
|
||||
GeoCoord* nearestTz = tzContainer->getNearest(location);
|
||||
SGPath zone( root );
|
||||
zone.append ( nearestTz->getDescription() );
|
||||
if ( zonename ) {
|
||||
char *ptr = zonename;
|
||||
zonename = NULL;
|
||||
delete ptr;
|
||||
}
|
||||
zonename = strdup( zone.c_str() );
|
||||
currGMT = sgTimeGetGMT( gmtime(&cur_time) );
|
||||
aircraftLocalTime = sgTimeGetGMT( (fgLocaltime(&cur_time, zone.c_str())) );
|
||||
local_offset = aircraftLocalTime - currGMT;
|
||||
// cout << "Using " << local_offset << " as local time offset Timezone is "
|
||||
// << zonename << endl;
|
||||
}
|
||||
|
||||
|
||||
@@ -327,6 +330,48 @@ double sgTimeCalcMJD(int mn, double dy, int yr) {
|
||||
}
|
||||
|
||||
|
||||
// return the current modified Julian date (number of days elapsed
|
||||
// since 1900 jan 0.5), mjd.
|
||||
double sgTimeCurrentMJD( long int warp ) {
|
||||
#ifdef _MSC_VER
|
||||
struct tm m_gmt; // copy of system gmtime(&time_t) structure
|
||||
#else
|
||||
struct tm *gmt;
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
tm * gmt = &m_gmt;
|
||||
#endif
|
||||
|
||||
// get current Unix calendar time (in seconds)
|
||||
// warp += warp_delta;
|
||||
time_t cur_time = time(NULL) + warp;
|
||||
SG_LOG( SG_EVENT, SG_DEBUG,
|
||||
" Current Unix calendar time = " << cur_time
|
||||
<< " warp = " << warp );
|
||||
|
||||
// get GMT break down for current time
|
||||
#ifdef _MSC_VER
|
||||
memcpy( gmt, gmtime(&cur_time), sizeof(tm) );
|
||||
#else
|
||||
gmt = gmtime(&cur_time);
|
||||
#endif
|
||||
SG_LOG( SG_EVENT, SG_DEBUG,
|
||||
" Current GMT = " << gmt->tm_mon+1 << "/"
|
||||
<< gmt->tm_mday << "/" << (1900 + gmt->tm_year) << " "
|
||||
<< gmt->tm_hour << ":" << gmt->tm_min << ":"
|
||||
<< gmt->tm_sec );
|
||||
|
||||
// calculate modified Julian date
|
||||
// t->mjd = cal_mjd ((int)(t->gmt->tm_mon+1), (double)t->gmt->tm_mday,
|
||||
// (int)(t->gmt->tm_year + 1900));
|
||||
double mjd = sgTimeCalcMJD( (int)(gmt->tm_mon+1), (double)gmt->tm_mday,
|
||||
(int)(gmt->tm_year + 1900) );
|
||||
|
||||
return mjd;
|
||||
}
|
||||
|
||||
|
||||
// given an mjd, calculate greenwich mean sidereal time, gst
|
||||
double sgTimeCalcGST( double mjd ) {
|
||||
double gst;
|
||||
|
||||
@@ -231,12 +231,20 @@ inline time_t sgTimeGetGMT(struct tm* the_time) {
|
||||
* @return modified julian date */
|
||||
double sgTimeCalcMJD(int mn, double dy, int yr);
|
||||
|
||||
/**
|
||||
* \relates SGTime
|
||||
* Given an optional offset from current time calculate the current
|
||||
* modified julian date.
|
||||
* @param warp number of seconds to offset from current time (0 if no offset)
|
||||
* @return current modified Julian date (number of days elapsed
|
||||
* since 1900 jan 0.5), mjd. */
|
||||
double sgTimeCurrentMJD( long int warp );
|
||||
|
||||
/**
|
||||
* \relates SGTime
|
||||
* Given an mjd, calculate greenwich mean sidereal time, gst
|
||||
* @param mjd modified julian date
|
||||
* @return greenwich mean sidereal time (gst)
|
||||
*/
|
||||
* @return greenwich mean sidereal time (gst) */
|
||||
double sgTimeCalcGST( double mjd );
|
||||
|
||||
/**
|
||||
|
||||
@@ -240,6 +240,12 @@ class XMLVisitor
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Virtual destructor.
|
||||
*/
|
||||
virtual ~XMLVisitor () {}
|
||||
|
||||
|
||||
/**
|
||||
* Callback for the start of an XML document.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user