# include <stdlib.h>
#endif
-#include <sys/stat.h> /* for stat() */
+#ifdef HAVE_SYS_STAT_H
+# include <sys/stat.h> /* for stat() */
+#endif
#ifdef HAVE_UNISTD_H
# include <unistd.h> /* for stat() */
#endif
#include <Include/fg_constants.h> // for VERSION
-#include <Include/general.h>
+#include <Include/general.hxx>
#include <Aircraft/aircraft.hxx>
#include <Astro/sky.hxx>
#include "options.hxx"
#include "splash.hxx"
#include "views.hxx"
+#include "fg_serial.hxx"
-// This is a record containing global housekeeping information
-fgGENERAL general;
+// This is a record containing a bit of global housekeeping information
+FGGeneral general;
// Specify our current idle function state. This is used to run all
// our initializations out of the glutIdleLoop() so that we can get a
// Update internal time dependent calculations (i.e. flight model)
-void fgUpdateTimeDepCalcs(int multi_loop) {
- FGState *f = current_aircraft.fdm_state;
+void fgUpdateTimeDepCalcs(int multi_loop, int remainder) {
+ FGInterface *f = current_aircraft.fdm_state;
fgLIGHT *l = &cur_light_params;
fgTIME *t = &cur_time_params;
FGView *v = ¤t_view;
fgAPRun();
// printf("updating flight model x %d\n", multi_loop);
- fgFlightModelUpdate( current_options.get_flight_model(),
- cur_fdm_state, multi_loop );
+ fgFDMUpdate( current_options.get_flight_model(),
+ cur_fdm_state, multi_loop, remainder );
} else {
- fgFlightModelUpdate( current_options.get_flight_model(),
- cur_fdm_state, 0 );
+ fgFDMUpdate( current_options.get_flight_model(),
+ cur_fdm_state, 0, remainder );
}
// update the view angle
void fgInitTimeDepCalcs( void ) {
// initialize timer
-#ifdef HAVE_SETITIMER
- fgTimerInit( 1.0 / DEFAULT_TIMER_HZ, fgUpdateTimeDepCalcs );
-#endif HAVE_SETITIMER
-
+ // #ifdef HAVE_SETITIMER
+ // fgTimerInit( 1.0 / DEFAULT_TIMER_HZ, fgUpdateTimeDepCalcs );
+ // #endif HAVE_SETITIMER
}
static const double alt_adjust_ft = 3.758099;
// What should we do when we have nothing else to do? Let's get ready
// for the next move and update the display?
static void fgMainLoop( void ) {
- FGState *f;
- fgGENERAL *g;
+ FGInterface *f;
fgTIME *t;
- static int remainder = 0;
- int elapsed, multi_loop;
- int i;
- double accum;
+ static long remainder = 0;
+ long elapsed, multi_loop;
+ // int i;
+ // double accum;
+ static time_t last_time = 0;
+ static int frames = 0;
f = current_aircraft.fdm_state;
- g = &general;
t = &cur_time_params;
FG_LOG( FG_ALL, FG_DEBUG, "Running Main Loop");
FG_LOG( FG_ALL, FG_DEBUG, "======= ==== ====");
+#if defined( ENABLE_LINUX_JOYSTICK )
+ // Read joystick and update control settings
+ fgJoystickRead();
+#elif defined( ENABLE_GLUT_JOYSTICK )
+ // Glut joystick support works by feeding a joystick handler
+ // function to glut. This is taken care of once in the joystick
+ // init routine and we don't have to worry about it again.
+#endif
+
current_weather.Update();
// Fix elevation. I'm just sticking this here for now, it should
f->get_Altitude() * FEET_TO_METER,
scenery.cur_elev + alt_adjust_m - 3.0,
scenery.cur_elev + alt_adjust_m );
- fgFlightModelSetAltitude( current_options.get_flight_model(),
- cur_fdm_state,
- scenery.cur_elev + alt_adjust_m );
+ fgFDMForceAltitude( current_options.get_flight_model(),
+ scenery.cur_elev + alt_adjust_m );
FG_LOG( FG_ALL, FG_DEBUG,
"<*> resetting altitude to "
<< f->get_Altitude() * FEET_TO_METER << " meters" );
}
- f->set_Runway_altitude( scenery.cur_elev * METER_TO_FEET );
+ fgFDMSetGroundElevation( current_options.get_flight_model(),
+ scenery.cur_elev ); // meters
}
/* printf("Adjustment - ground = %.2f runway = %.2f alt = %.2f\n",
// update "time"
fgTimeUpdate(f, t);
-#if defined( ENABLE_LINUX_JOYSTICK )
- // Read joystick and update control settings
- fgJoystickRead();
-#elif defined( ENABLE_GLUT_JOYSTICK )
- // Glut joystick support works by feeding a joystick handler
- // function to glut. This is taken care of once in the joystick
- // init routine and we don't have to worry about it again.
-#endif
-
- // Get elapsed time for this past frame
+ // Get elapsed time (in usec) for this past frame
elapsed = fgGetTimeInterval();
- FG_LOG( FG_ALL, FG_BULK,
- "Time interval is = " << elapsed
+ FG_LOG( FG_ALL, FG_DEBUG,
+ "Elapsed time interval is = " << elapsed
<< ", previous remainder is = " << remainder );
// Calculate frame rate average
- if ( elapsed > 0.0 ) {
+ if ( (t->cur_time != last_time) && (last_time > 0) ) {
+ general.set_frame_rate( frames );
+ FG_LOG( FG_ALL, FG_DEBUG,
+ "--> Frame rate is = " << general.get_frame_rate() );
+ frames = 0;
+ }
+ last_time = t->cur_time;
+ ++frames;
+
+ /* old fps calculation
+ if ( elapsed > 0 ) {
accum = 0.0;
for ( i = FG_FRAME_RATE_HISTORY - 2; i >= 0; i-- ) {
accum += g->frames[i];
g->frame_rate = accum / (float)FG_FRAME_RATE_HISTORY;
// printf("ave = %.2f\n", g->frame_rate);
}
-
- // Calculate model iterations needed for next frame
- FG_LOG( FG_ALL, FG_DEBUG,
- "--> Frame rate is = " << g->frame_rate );
- elapsed += remainder;
-
- multi_loop = (int)(((float)elapsed * 0.001) * DEFAULT_MODEL_HZ);
- remainder = elapsed - ((multi_loop*1000) / DEFAULT_MODEL_HZ);
- FG_LOG( FG_ALL, FG_BULK,
- "Model iterations needed = " << multi_loop
- << ", new remainder = " << remainder );
-
- /* printf("right before fm - ground = %.2f runway = %.2f alt = %.2f\n",
- scenery.cur_elev,
- FG_Runway_altitude * FEET_TO_METER,
- FG_Altitude * FEET_TO_METER); */
+ */
// Run flight model
if ( ! use_signals ) {
+ // Calculate model iterations needed for next frame
+ elapsed += remainder;
+
+ multi_loop = (int)(((double)elapsed * 0.000001) * DEFAULT_MODEL_HZ);
+ remainder = elapsed - ((multi_loop*1000000) / DEFAULT_MODEL_HZ);
+ FG_LOG( FG_ALL, FG_DEBUG,
+ "Model iterations needed = " << multi_loop
+ << ", new remainder = " << remainder );
+
// flight model
- fgUpdateTimeDepCalcs(multi_loop);
+ if ( multi_loop > 0 ) {
+ fgUpdateTimeDepCalcs(multi_loop, remainder);
+ } else {
+ FG_LOG( FG_ALL, FG_INFO, "Elapsed time is zero ... we're zinging" );
+ }
}
- /* printf("After fm - ground = %.2f runway = %.2f alt = %.2f\n",
- scenery.cur_elev,
- FG_Runway_altitude * FEET_TO_METER,
- FG_Altitude * FEET_TO_METER); */
-
// Do any serial port work that might need to be done
fgSerialProcess();
// then on.
static void fgIdleFunction ( void ) {
- fgGENERAL *g;
- g = &general;
-
// printf("idle state == %d\n", idle_state);
if ( idle_state == 0 ) {
// "subsystems" but still need to be initialized.
#ifdef USE_GLIDE
- if ( strstr ( g->glRenderer, "Glide" ) ) {
+ if ( strstr ( general.get_glRenderer(), "Glide" ) ) {
grTexLodBiasValue ( GR_TMU0, 1.0 ) ;
}
#endif
audio_sched = new slScheduler ( 8000 );
audio_mixer = new smMixer;
- audio_mixer -> setMasterVolume ( 50 ) ; /* 80% of max volume. */
+ audio_mixer -> setMasterVolume ( 80 ) ; /* 80% of max volume. */
audio_sched -> setSafetyMargin ( 1.0 ) ;
string slfile = current_options.get_fg_root() + "/Sounds/wasp.wav";
xglutCreateWindow("Flight Gear");
} else {
// Open the cool new 'game mode' window
- string game_mode_params = "width=" + current_options.get_xsize();
- game_mode_params += "height=" + current_options.get_ysize();
- game_mode_params += " bpp=16";
- cout << "game mode params = " << game_mode_params;
- glutGameModeString( game_mode_params.c_str() );
+ char game_mode_str[256];
+ sprintf( game_mode_str, "width=%d height=%d bpp=16",
+ current_options.get_xsize(),
+ current_options.get_ysize() );
+
+ FG_LOG( FG_GENERAL, FG_INFO,
+ "game mode params = " << game_mode_str );
+ glutGameModeString( game_mode_str );
glutEnterGameMode();
}
// This seems to be the absolute earliest in the init sequence
// that these calls will return valid info. Too bad it's after
// we've already created and sized out window. :-(
- general.glVendor = (char *)glGetString ( GL_VENDOR );
- general.glRenderer = (char *)glGetString ( GL_RENDERER );
- general.glVersion = (char *)glGetString ( GL_VERSION );
+ general.set_glVendor( (char *)glGetString ( GL_VENDOR ) );
+ general.set_glRenderer( (char *)glGetString ( GL_RENDERER ) );
+ general.set_glVersion( (char *)glGetString ( GL_VERSION ) );
- FG_LOG ( FG_GENERAL, FG_INFO, general.glRenderer );
+ FG_LOG ( FG_GENERAL, FG_INFO, general.get_glRenderer() );
#if 0
// try to determine if we should adjust the initial default
// Main ...
int main( int argc, char **argv ) {
- FGState *f;
+ FGInterface *f;
f = current_aircraft.fdm_state;
// Something must have gone horribly wrong with the command
// line parsing or maybe the user just requested help ... :-)
current_options.usage();
- // FG_LOG( FG_GENERAL, FG_ALERT, "\nExiting ...");
- cout << endl << "Exiting ..." << endl;
+ FG_LOG( FG_GENERAL, FG_ALERT, "\nExiting ...");
+ // cout << endl << "Exiting ..." << endl;
exit(-1);
}
// $Log$
+// Revision 1.85 1999/02/05 21:29:08 curt
+// Modifications to incorporate Jon S. Berndts flight model code.
+//
+// Revision 1.84 1999/02/02 20:13:34 curt
+// MSVC++ portability changes by Bernie Bright:
+//
+// Lib/Serial/serial.[ch]xx: Initial Windows support - incomplete.
+// Simulator/Astro/stars.cxx: typo? included <stdio> instead of <cstdio>
+// Simulator/Cockpit/hud.cxx: Added Standard headers
+// Simulator/Cockpit/panel.cxx: Redefinition of default parameter
+// Simulator/Flight/flight.cxx: Replaced cout with FG_LOG. Deleted <stdio.h>
+// Simulator/Main/fg_init.cxx:
+// Simulator/Main/GLUTmain.cxx:
+// Simulator/Main/options.hxx: Shuffled <fg_serial.hxx> dependency
+// Simulator/Objects/material.hxx:
+// Simulator/Time/timestamp.hxx: VC++ friend kludge
+// Simulator/Scenery/tile.[ch]xx: Fixed using std::X declarations
+// Simulator/Main/views.hxx: Added a constant
+//
+// Revision 1.83 1999/01/27 04:49:17 curt
+// Game mode fixes from Norman Vine.
+// Initial altitude setting tweaks and fixes (especially for when starting
+// below sea level.)
+//
+// Revision 1.82 1999/01/20 13:42:24 curt
+// Tweaked FDM interface.
+// Testing check sum support for NMEA serial output.
+//
+// Revision 1.81 1999/01/19 20:57:03 curt
+// MacOS portability changes contributed by "Robert Puyol" <puyol@abvent.fr>
+//
+// Revision 1.80 1999/01/09 13:37:40 curt
+// Convert fgTIMESTAMP to FGTimeStamp which holds usec instead of ms.
+//
+// Revision 1.79 1999/01/08 03:23:56 curt
+// Beginning work on compensating for sim time vs. real world time "jitter".
+//
+// Revision 1.78 1999/01/07 20:25:08 curt
+// Updated struct fgGENERAL to class FGGeneral.
+//
+// Revision 1.77 1998/12/18 23:40:55 curt
+// New frame rate counting mechanism.
+//
// Revision 1.76 1998/12/11 20:26:26 curt
// Fixed view frustum culling accuracy bug so we can look out the sides and
// back without tri-stripes dropping out.