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>
#endif
#include <string.h>
#include <stdio.h>
#include <string>
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#include "Include/compiler.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
#if defined( HAVE_WINDOWS_H ) && defined(__MWERKS__)
@ -39,30 +51,24 @@
// contains milliseconds
#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 "event.hxx"
FG_USING_STD(for_each);
FG_USING_STD(mem_fun);
fgEVENT_MGR global_events;
fgEVENT::fgEVENT( const string& desc,
const fgCallback& cb,
EventState _status,
int _interval )
EventState evt_status,
int evt_interval )
: description(desc),
event_cb(cb.clone()),
status(_status),
interval(_interval),
status(evt_status),
interval(evt_interval),
cum_time(0),
min_time(100000),
max_time(0),
@ -70,14 +76,10 @@ fgEVENT::fgEVENT( const string& desc,
{
}
#if 0
fgEVENT::fgEVENT( const fgEVENT& evt )
: 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),
#endif
status(evt.status),
interval(evt.interval),
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()
{
// cout << "fgEVENT::~fgEVENT" << endl;
delete event_cb;
}
void
@ -167,12 +190,12 @@ fgEVENT_MGR::Register( const string& desc,
fgEVENT::EventState status,
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 );
// Actually run the event
e.run();
e->run();
// Now add to event_table
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, "-----------" );
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(),
event_table.end(),
mem_fun_ref( &fgEVENT::PrintStats ));
mem_fun( &fgEVENT::PrintStats ) );
#endif
FG_LOG( FG_EVENT, FG_INFO, "");
}
@ -236,7 +267,7 @@ void fgEVENT_MGR::Process( void ) {
// while ( current != last ) {
for ( i = 0; i < size; i++ ) {
// e = *current++;
e_ptr = &event_table[i];
e_ptr = event_table[i];
if ( e_ptr->status == fgEVENT::FG_EVENT_READY ) {
FG_LOG( FG_EVENT, FG_DEBUG,
" Item " << i << " current " << cur_time.get_seconds()
@ -261,10 +292,22 @@ void fgEVENT_MGR::Process( void ) {
// Destructor
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$
// 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
// Converted "struct fg_timestamp" to "class fgTIMESTAMP" and added some
// convenience inline operators.

View file

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

View file

@ -27,10 +27,18 @@
# include <config.h>
#endif
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "Include/compiler.h"
#ifdef FG_HAVE_STD_INCLUDES
# include <cmath>
# 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
# 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);
FG_LOG( FG_EVENT, FG_DEBUG,
" Raw time zone offset = " << timezone );
FG_LOG( FG_EVENT, FG_DEBUG,
" Daylight Savings = " << daylight );
FG_LOG( FG_EVENT, FG_DEBUG,
" Local hours from GMT = " << offset);
FG_LOG( FG_EVENT, FG_DEBUG, " Raw time zone offset = " << timezone );
FG_LOG( FG_EVENT, FG_DEBUG, " Daylight Savings = " << daylight );
FG_LOG( FG_EVENT, FG_DEBUG, " Local hours from GMT = " << offset );
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 )
}
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
double sidereal_course(fgTIME *t, double lng) {
struct tm *gmt;
time_t start_gmt, now;
double diff, part, days, hours, lst;
char tbuf[64];
gmt = t->gmt;
now = t->cur_time;
start_gmt = get_start_gmt(gmt->tm_year);
FG_LOG( FG_EVENT, FG_DEBUG,
" COURSE: 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);
FG_LOG( FG_EVENT, FG_DEBUG, " COURSE: GMT = " << format_time(gmt, tbuf) );
FG_LOG( FG_EVENT, FG_DEBUG, " March 21 noon (GMT) = " << start_gmt );
diff = (now - start_gmt) / (3600.0 * 24.0);
@ -389,6 +398,9 @@ void fgTimeUpdate(FGState *f, fgTIME *t) {
// $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
// #include tweaks.
//

View file

@ -41,7 +41,13 @@
#endif
#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>
@ -99,6 +105,9 @@ void fgTimeUpdate(FGState *f, fgTIME *t);
// $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
// Renamed class fgFLIGHT to class FGState as per request by JSB.
//

View file

@ -33,12 +33,20 @@
#include <GL/glut.h>
#include <XGL/xgl.h>
#ifdef __BORLANDC__
#include "Include/compiler.h"
#ifdef FG_MATH_EXCEPTION_CLASH
# define exception c_exception
#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 <Debug/logstream.hxx>
@ -65,25 +73,23 @@ fgLIGHT::fgLIGHT( void ) {
// initialize lighting tables
void fgLIGHT::Init( void ) {
string path, ambient, diffuse, sky;
FG_LOG( FG_EVENT, FG_INFO,
"Initializing Lighting interpolation tables." );
// build the path name to the ambient lookup table
path = current_options.get_fg_root();
ambient = path + "/Lighting/ambient";
diffuse = path + "/Lighting/diffuse";
sky = path + "/Lighting/sky";
string path = current_options.get_fg_root();
string ambient = path + "/Lighting/ambient";
string diffuse = path + "/Lighting/diffuse";
string sky = path + "/Lighting/sky";
// initialize ambient table
ambient_tbl = new fgINTERPTABLE((char *)ambient.c_str());
ambient_tbl = new fgINTERPTABLE( ambient );
// initialize diffuse table
diffuse_tbl = new fgINTERPTABLE((char *)diffuse.c_str());
diffuse_tbl = new fgINTERPTABLE( diffuse );
// initialize sky table
sky_tbl = new fgINTERPTABLE((char *)sky.c_str());
sky_tbl = new fgINTERPTABLE( sky );
}
@ -214,6 +220,9 @@ fgLIGHT::~fgLIGHT( void ) {
// $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
// Converted "class fgVIEW" to "class FGView" and updated to make data
// members private and make required accessor functions.

View file

@ -39,9 +39,17 @@
# include <config.h>
#endif
#include <math.h>
#include <stdio.h>
#include <time.h>
#include "Include/compiler.h"
#ifdef FG_HAVE_STD_INCLUDES
# include <cmath>
# include <cstdio>
# include <ctime>
#else
# include <math.h>
# include <stdio.h>
# include <time.h>
#endif
//#include <Astro/orbits.hxx>
#include <Astro/solarsystem.hxx>
@ -427,6 +435,9 @@ void fgUpdateSunPos( void ) {
// $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
// Converted "class fgVIEW" to "class FGView" and updated to make data
// members private and make required accessor functions.

View file

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

View file

@ -40,7 +40,12 @@
# include <windows.h>
#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
# include <sys/timeb.h> // for ftime() and struct timeb
@ -158,6 +163,9 @@ inline long operator - (const fgTIMESTAMP& a, const fgTIMESTAMP& b)
// $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
// #include tweaks.
//