1
0
Fork 0

Portability changes and updates from Bernie Bright.

This commit is contained in:
curt 1999-01-07 20:25:32 +00:00
parent e8d0a16e41
commit 9a8b4dab10
8 changed files with 186 additions and 91 deletions

View file

@ -26,11 +26,23 @@
# include <config.h> # include <config.h>
#endif #endif
#include <string.h> #include <string>
#include <stdio.h>
#ifdef HAVE_STDLIB_H #include "Include/compiler.h"
#include <stdlib.h>
#include STL_ALGORITHM
#include STL_FUNCTIONAL
#ifdef FG_HAVE_STD_INCLUDES
# include <cstdio>
# ifdef HAVE_STDLIB_H
# include <cstdlib>
# endif
#else
# include <stdio.h>
# ifdef HAVE_STDLIB_H
# include <stdlib.h>
# endif
#endif #endif
#if defined( HAVE_WINDOWS_H ) && defined(__MWERKS__) #if defined( HAVE_WINDOWS_H ) && defined(__MWERKS__)
@ -39,30 +51,24 @@
// contains milliseconds // contains milliseconds
#endif #endif
#if defined( linux ) || defined( __FreeBSD__ )
# define _G_NO_EXTERN_TEMPLATES
#endif
#include "Include/fg_stl_config.h"
#include STL_ALGORITHM
#include STL_FUNCTIONAL
#include <Debug/logstream.hxx> #include <Debug/logstream.hxx>
#include "event.hxx" #include "event.hxx"
FG_USING_STD(for_each);
FG_USING_STD(mem_fun);
fgEVENT_MGR global_events; fgEVENT_MGR global_events;
fgEVENT::fgEVENT( const string& desc, fgEVENT::fgEVENT( const string& desc,
const fgCallback& cb, const fgCallback& cb,
EventState _status, EventState evt_status,
int _interval ) int evt_interval )
: description(desc), : description(desc),
event_cb(cb.clone()), event_cb(cb.clone()),
status(_status), status(evt_status),
interval(_interval), interval(evt_interval),
cum_time(0), cum_time(0),
min_time(100000), min_time(100000),
max_time(0), max_time(0),
@ -70,14 +76,10 @@ fgEVENT::fgEVENT( const string& desc,
{ {
} }
#if 0
fgEVENT::fgEVENT( const fgEVENT& evt ) fgEVENT::fgEVENT( const fgEVENT& evt )
: description(evt.description), : description(evt.description),
#ifdef _FG_NEED_AUTO_PTR
// Ugly - cast away const until proper auto_ptr implementation.
event_cb((auto_ptr<fgCallback>&)(evt.event_cb)),
#else
event_cb(evt.event_cb), event_cb(evt.event_cb),
#endif
status(evt.status), status(evt.status),
interval(evt.interval), interval(evt.interval),
last_run(evt.last_run), last_run(evt.last_run),
@ -90,9 +92,30 @@ fgEVENT::fgEVENT( const fgEVENT& evt )
{ {
} }
fgEVENT&
fgEVENT::operator= ( const fgEVENT& evt )
{
if ( this != &evt )
{
description = evt.description;
event_cb = evt.event_cb;
status = evt.status;
interval = evt.interval;
last_run = evt.last_run;
current = evt.current;
next_run = evt.next_run;
cum_time = evt.cum_time;
min_time = evt.min_time;
max_time = evt.max_time;
count = evt.count;
}
return *this;
}
#endif
fgEVENT::~fgEVENT() fgEVENT::~fgEVENT()
{ {
// cout << "fgEVENT::~fgEVENT" << endl; delete event_cb;
} }
void void
@ -167,12 +190,12 @@ fgEVENT_MGR::Register( const string& desc,
fgEVENT::EventState status, fgEVENT::EventState status,
int interval ) int interval )
{ {
fgEVENT e( desc, cb, status, interval ); fgEVENT* e = new fgEVENT( desc, cb, status, interval );
FG_LOG( FG_EVENT, FG_INFO, "Registering event: " << desc ); FG_LOG( FG_EVENT, FG_INFO, "Registering event: " << desc );
// Actually run the event // Actually run the event
e.run(); e->run();
// Now add to event_table // Now add to event_table
event_table.push_back(e); event_table.push_back(e);
@ -206,10 +229,18 @@ fgEVENT_MGR::PrintStats()
FG_LOG( FG_EVENT, FG_INFO, "Event Stats" ); FG_LOG( FG_EVENT, FG_INFO, "Event Stats" );
FG_LOG( FG_EVENT, FG_INFO, "-----------" ); FG_LOG( FG_EVENT, FG_INFO, "-----------" );
ConstEventIterator first = event_table.begin();
ConstEventIterator last = event_table.end();
while ( first != last )
{
(*first)->PrintStats();
++first;
}
#if 0 // msvc++ 6.0 barfs at mem_fun()
for_each( event_table.begin(), for_each( event_table.begin(),
event_table.end(), event_table.end(),
mem_fun_ref( &fgEVENT::PrintStats )); mem_fun( &fgEVENT::PrintStats ) );
#endif
FG_LOG( FG_EVENT, FG_INFO, ""); FG_LOG( FG_EVENT, FG_INFO, "");
} }
@ -236,7 +267,7 @@ void fgEVENT_MGR::Process( void ) {
// while ( current != last ) { // while ( current != last ) {
for ( i = 0; i < size; i++ ) { for ( i = 0; i < size; i++ ) {
// e = *current++; // e = *current++;
e_ptr = &event_table[i]; e_ptr = event_table[i];
if ( e_ptr->status == fgEVENT::FG_EVENT_READY ) { if ( e_ptr->status == fgEVENT::FG_EVENT_READY ) {
FG_LOG( FG_EVENT, FG_DEBUG, FG_LOG( FG_EVENT, FG_DEBUG,
" Item " << i << " current " << cur_time.get_seconds() " Item " << i << " current " << cur_time.get_seconds()
@ -261,10 +292,22 @@ void fgEVENT_MGR::Process( void ) {
// Destructor // Destructor
fgEVENT_MGR::~fgEVENT_MGR( void ) { fgEVENT_MGR::~fgEVENT_MGR( void ) {
EventIterator first = event_table.begin();
EventIterator last = event_table.end();
for ( ; first != last; ++first )
{
delete (*first);
}
run_queue.erase( run_queue.begin(), run_queue.end() );
event_table.erase( event_table.begin(), event_table.end() );
} }
// $Log$ // $Log$
// Revision 1.14 1999/01/07 20:25:32 curt
// Portability changes and updates from Bernie Bright.
//
// Revision 1.13 1998/12/04 01:32:46 curt // Revision 1.13 1998/12/04 01:32:46 curt
// Converted "struct fg_timestamp" to "class fgTIMESTAMP" and added some // Converted "struct fg_timestamp" to "class fgTIMESTAMP" and added some
// convenience inline operators. // convenience inline operators.

View file

@ -31,29 +31,16 @@
#endif #endif
#if defined ( __sun__ ) || defined ( __sgi ) #include "Include/compiler.h"
extern "C" void *memmove(void *, const void *, size_t); #include "Include/fg_callback.hxx"
extern "C" void *memset(void *, int, size_t);
#endif
#include <deque> // STL double ended queue #include <deque> // STL double ended queue
#include <list> // STL list #include <list> // STL list
#include <string> #include <string>
#include "Include/fg_stl_config.h" FG_USING_STD(deque);
FG_USING_STD(list);
#ifdef FG_NEED_AUTO_PTR FG_USING_STD(string);
# include "Include/auto_ptr.hxx"
#else
# include <memory>
#endif
#include "Include/fg_callback.hxx"
#ifdef NEEDNAMESPACESTD
using namespace std;
#endif
#include "fg_time.hxx" #include "fg_time.hxx"
#include "timestamp.hxx" #include "timestamp.hxx"
@ -69,14 +56,14 @@ public:
FG_EVENT_QUEUED = 2 FG_EVENT_QUEUED = 2
}; };
friend class fgEVENT_MGR;
fgEVENT() {} // Required by deque<>. fgEVENT() {} // Required by deque<>.
fgEVENT( const string& desc, fgEVENT( const string& desc,
const fgCallback& cb, const fgCallback& cb,
EventState _status, EventState evt_status,
int _interval ); int evt_interval );
fgEVENT( const fgEVENT& evt );
~fgEVENT(); ~fgEVENT();
@ -85,14 +72,17 @@ public:
// void PrintStats() const; // void PrintStats() const;
int PrintStats() const; int PrintStats() const;
public: private:
// not defined
fgEVENT( const fgEVENT& evt );
fgEVENT& operator= ( const fgEVENT& evt );
private:
string description; string description;
// The callback object. // The callback object.
// We wrap it in an auto_ptr<> because deque<> calls our copy ctor fgCallback* event_cb;
// and dtor when inserting and removing.
auto_ptr<fgCallback> event_cb;
EventState status; // status flag EventState status; // status flag
@ -112,10 +102,16 @@ public:
class fgEVENT_MGR { class fgEVENT_MGR {
// Event table // Event table
deque < fgEVENT > event_table; typedef deque < fgEVENT* > EventContainer;
typedef EventContainer::iterator EventIterator;
typedef EventContainer::const_iterator ConstEventIterator;
EventContainer event_table;
// Run Queue // Run Queue
list < fgEVENT * > run_queue; typedef list < fgEVENT * > RunContainer;
RunContainer run_queue;
public: public:
@ -170,6 +166,9 @@ extern fgEVENT_MGR global_events;
// $Log$ // $Log$
// Revision 1.15 1999/01/07 20:25:33 curt
// Portability changes and updates from Bernie Bright.
//
// Revision 1.14 1998/12/05 14:21:28 curt // Revision 1.14 1998/12/05 14:21:28 curt
// Moved struct fg_timestamp to class fgTIMESTAMP and moved it's definition // Moved struct fg_timestamp to class fgTIMESTAMP and moved it's definition
// to it's own file, timestamp.hxx. // to it's own file, timestamp.hxx.

View file

@ -27,10 +27,18 @@
# include <config.h> # include <config.h>
#endif #endif
#include <math.h> #include "Include/compiler.h"
#include <stdio.h> #ifdef FG_HAVE_STD_INCLUDES
#include <stdlib.h> # include <cmath>
#include <time.h> # include <cstdio>
# include <cstdlib>
# include <ctime>
#else
# include <math.h>
# include <stdio.h>
# include <stdlib.h>
# include <time.h>
#endif
#ifdef HAVE_SYS_TIMEB_H #ifdef HAVE_SYS_TIMEB_H
# include <sys/timeb.h> // for ftime() and struct timeb # include <sys/timeb.h> // for ftime() and struct timeb
@ -264,12 +272,9 @@ time_t get_start_gmt(int year) {
long int offset = -(timezone / 3600 - daylight); long int offset = -(timezone / 3600 - daylight);
FG_LOG( FG_EVENT, FG_DEBUG, FG_LOG( FG_EVENT, FG_DEBUG, " Raw time zone offset = " << timezone );
" Raw time zone offset = " << timezone ); FG_LOG( FG_EVENT, FG_DEBUG, " Daylight Savings = " << daylight );
FG_LOG( FG_EVENT, FG_DEBUG, FG_LOG( FG_EVENT, FG_DEBUG, " Local hours from GMT = " << offset );
" Daylight Savings = " << daylight );
FG_LOG( FG_EVENT, FG_DEBUG,
" Local hours from GMT = " << offset);
long int start_gmt = start - timezone + (daylight * 3600); long int start_gmt = start - timezone + (daylight * 3600);
@ -280,24 +285,28 @@ time_t get_start_gmt(int year) {
# endif // ! defined ( MK_TIME_IS_GMT ) # endif // ! defined ( MK_TIME_IS_GMT )
} }
static char*
format_time( const struct tm* p, char* buf )
{
sprintf( buf, "%d/%d/%2d %d:%02d:%02d",
p->tm_mon, p->tm_mday, p->tm_year,
p->tm_hour, p->tm_min, p->tm_sec);
return buf;
}
// return a courser but cheaper estimate of sidereal time // return a courser but cheaper estimate of sidereal time
double sidereal_course(fgTIME *t, double lng) { double sidereal_course(fgTIME *t, double lng) {
struct tm *gmt; struct tm *gmt;
time_t start_gmt, now; time_t start_gmt, now;
double diff, part, days, hours, lst; double diff, part, days, hours, lst;
char tbuf[64];
gmt = t->gmt; gmt = t->gmt;
now = t->cur_time; now = t->cur_time;
start_gmt = get_start_gmt(gmt->tm_year); start_gmt = get_start_gmt(gmt->tm_year);
FG_LOG( FG_EVENT, FG_DEBUG, FG_LOG( FG_EVENT, FG_DEBUG, " COURSE: GMT = " << format_time(gmt, tbuf) );
" COURSE: GMT = " FG_LOG( FG_EVENT, FG_DEBUG, " March 21 noon (GMT) = " << start_gmt );
<< gmt->tm_mon << "/" << gmt->tm_mday << "/" << gmt->tm_year
<< " "
<< gmt->tm_hour << ":" << gmt->tm_min << ":" << gmt->tm_sec );
FG_LOG( FG_EVENT, FG_DEBUG, " March 21 noon (GMT) = " << start_gmt);
diff = (now - start_gmt) / (3600.0 * 24.0); diff = (now - start_gmt) / (3600.0 * 24.0);
@ -389,6 +398,9 @@ void fgTimeUpdate(FGState *f, fgTIME *t) {
// $Log$ // $Log$
// Revision 1.28 1999/01/07 20:25:34 curt
// Portability changes and updates from Bernie Bright.
//
// Revision 1.27 1998/12/11 20:26:55 curt // Revision 1.27 1998/12/11 20:26:55 curt
// #include tweaks. // #include tweaks.
// //

View file

@ -41,7 +41,13 @@
#endif #endif
#include <GL/glut.h> #include <GL/glut.h>
#include <time.h>
#include "Include/compiler.h"
#ifdef FG_HAVE_STD_INCLUDES
# include <ctime>
#else
# include <time.h>
#endif
#include <Flight/flight.hxx> #include <Flight/flight.hxx>
@ -99,6 +105,9 @@ void fgTimeUpdate(FGState *f, fgTIME *t);
// $Log$ // $Log$
// Revision 1.12 1999/01/07 20:25:35 curt
// Portability changes and updates from Bernie Bright.
//
// Revision 1.11 1998/12/05 15:54:29 curt // Revision 1.11 1998/12/05 15:54:29 curt
// Renamed class fgFLIGHT to class FGState as per request by JSB. // Renamed class fgFLIGHT to class FGState as per request by JSB.
// //

View file

@ -33,12 +33,20 @@
#include <GL/glut.h> #include <GL/glut.h>
#include <XGL/xgl.h> #include <XGL/xgl.h>
#ifdef __BORLANDC__ #include "Include/compiler.h"
#ifdef FG_MATH_EXCEPTION_CLASH
# define exception c_exception # define exception c_exception
#endif #endif
#include <math.h>
#include <string.h> #ifdef FG_HAVE_STD_INCLUDES
# include <cmath>
#else
# include <math.h>
#endif
#include <string>
FG_USING_STD(string);
#include <Aircraft/aircraft.hxx> #include <Aircraft/aircraft.hxx>
#include <Debug/logstream.hxx> #include <Debug/logstream.hxx>
@ -65,25 +73,23 @@ fgLIGHT::fgLIGHT( void ) {
// initialize lighting tables // initialize lighting tables
void fgLIGHT::Init( void ) { void fgLIGHT::Init( void ) {
string path, ambient, diffuse, sky;
FG_LOG( FG_EVENT, FG_INFO, FG_LOG( FG_EVENT, FG_INFO,
"Initializing Lighting interpolation tables." ); "Initializing Lighting interpolation tables." );
// build the path name to the ambient lookup table // build the path name to the ambient lookup table
path = current_options.get_fg_root(); string path = current_options.get_fg_root();
ambient = path + "/Lighting/ambient"; string ambient = path + "/Lighting/ambient";
diffuse = path + "/Lighting/diffuse"; string diffuse = path + "/Lighting/diffuse";
sky = path + "/Lighting/sky"; string sky = path + "/Lighting/sky";
// initialize ambient table // initialize ambient table
ambient_tbl = new fgINTERPTABLE((char *)ambient.c_str()); ambient_tbl = new fgINTERPTABLE( ambient );
// initialize diffuse table // initialize diffuse table
diffuse_tbl = new fgINTERPTABLE((char *)diffuse.c_str()); diffuse_tbl = new fgINTERPTABLE( diffuse );
// initialize sky table // initialize sky table
sky_tbl = new fgINTERPTABLE((char *)sky.c_str()); sky_tbl = new fgINTERPTABLE( sky );
} }
@ -214,6 +220,9 @@ fgLIGHT::~fgLIGHT( void ) {
// $Log$ // $Log$
// Revision 1.25 1999/01/07 20:25:36 curt
// Portability changes and updates from Bernie Bright.
//
// Revision 1.24 1998/12/09 18:50:35 curt // Revision 1.24 1998/12/09 18:50:35 curt
// Converted "class fgVIEW" to "class FGView" and updated to make data // Converted "class fgVIEW" to "class FGView" and updated to make data
// members private and make required accessor functions. // members private and make required accessor functions.

View file

@ -39,9 +39,17 @@
# include <config.h> # include <config.h>
#endif #endif
#include <math.h> #include "Include/compiler.h"
#include <stdio.h> #ifdef FG_HAVE_STD_INCLUDES
#include <time.h> # include <cmath>
# include <cstdio>
# include <ctime>
#else
# include <math.h>
# include <stdio.h>
# include <time.h>
#endif
//#include <Astro/orbits.hxx> //#include <Astro/orbits.hxx>
#include <Astro/solarsystem.hxx> #include <Astro/solarsystem.hxx>
@ -427,6 +435,9 @@ void fgUpdateSunPos( void ) {
// $Log$ // $Log$
// Revision 1.19 1999/01/07 20:25:37 curt
// Portability changes and updates from Bernie Bright.
//
// Revision 1.18 1998/12/09 18:50:36 curt // Revision 1.18 1998/12/09 18:50:36 curt
// Converted "class fgVIEW" to "class FGView" and updated to make data // Converted "class fgVIEW" to "class FGView" and updated to make data
// members private and make required accessor functions. // members private and make required accessor functions.

View file

@ -44,8 +44,12 @@
# error This library requires C++ # error This library requires C++
#endif #endif
#include "Include/compiler.h"
#include <time.h> #ifdef FG_HAVE_STD_INCLUDES
# include <ctime>
#else
# include <time.h>
#endif
/* update the cur_time_params structure with the current sun position */ /* update the cur_time_params structure with the current sun position */
void fgUpdateSunPos( void ); void fgUpdateSunPos( void );

View file

@ -40,7 +40,12 @@
# include <windows.h> # include <windows.h>
#endif #endif
#include <time.h> #include "Include/compiler.h"
#ifdef FG_HAVE_STD_INCLUDES
# include <ctime>
#else
# include <time.h>
#endif
#ifdef HAVE_SYS_TIMEB_H #ifdef HAVE_SYS_TIMEB_H
# include <sys/timeb.h> // for ftime() and struct timeb # include <sys/timeb.h> // for ftime() and struct timeb
@ -158,6 +163,9 @@ inline long operator - (const fgTIMESTAMP& a, const fgTIMESTAMP& b)
// $Log$ // $Log$
// Revision 1.3 1999/01/07 20:25:39 curt
// Portability changes and updates from Bernie Bright.
//
// Revision 1.2 1998/12/11 20:26:56 curt // Revision 1.2 1998/12/11 20:26:56 curt
// #include tweaks. // #include tweaks.
// //