]> git.mxchange.org Git - flightgear.git/blob - src/Main/main.cxx
Threaded tile paging:
[flightgear.git] / src / Main / main.cxx
1 // main.cxx -- top level sim routines
2 //
3 // Written by Curtis Olson for OpenGL, started May 1997.
4 //
5 // Copyright (C) 1997 - 1999  Curtis L. Olson  - curt@flightgear.org
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 // General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 //
21 // $Id$
22
23
24 #ifdef HAVE_CONFIG_H
25 #  include <config.h>
26 #endif
27
28 #ifdef SG_MATH_EXCEPTION_CLASH
29 #  include <math.h>
30 #endif
31
32 #ifdef HAVE_WINDOWS_H
33 #  include <windows.h>
34 #  include <float.h>
35 #endif
36
37 #include <GL/glut.h>
38 #include <GL/gl.h>
39
40 #include <stdio.h>
41 #include <string.h>
42 #include <string>
43
44 #ifdef HAVE_STDLIB_H
45 #   include <stdlib.h>
46 #endif
47
48 #ifdef HAVE_SYS_STAT_H
49 #  include <sys/stat.h>         // for stat()
50 #endif
51
52 #ifdef HAVE_UNISTD_H
53 #  include <unistd.h>           // for stat()
54 #endif
55
56 #include <plib/pu.h>
57 #include <plib/ssg.h>
58
59 #include <simgear/constants.h>  // for VERSION
60 #include <simgear/debug/logstream.hxx>
61 #include <simgear/math/polar3d.hxx>
62 #include <simgear/math/sg_random.h>
63 #include <simgear/misc/sg_path.hxx>
64 #include <simgear/sky/sky.hxx>
65 #include <simgear/timing/sg_time.hxx>
66 #include <simgear/timing/lowleveltime.h>
67
68 #include <Include/general.hxx>
69
70 #include <Aircraft/aircraft.hxx>
71
72 #include <Autopilot/newauto.hxx>
73 #include <Cockpit/cockpit.hxx>
74 #include <Cockpit/radiostack.hxx>
75 #include <Cockpit/steam.hxx>
76
77 #include <FDM/UIUCModel/uiuc_aircraftdir.h>
78 #include <GUI/gui.h>
79 #include <GUI/sgVec3Slider.hxx>
80 #include <Joystick/joystick.hxx>
81 #ifdef FG_NETWORK_OLK
82 #include <NetworkOLK/network.h>
83 #endif
84 #include <Objects/matlib.hxx>
85 #include <Scenery/scenery.hxx>
86 #include <Scenery/tilemgr.hxx>
87 #ifdef ENABLE_AUDIO_SUPPORT
88 #  include <Sound/soundmgr.hxx>
89 #  include <Sound/morse.hxx>
90 #endif
91 #include <Time/event.hxx>
92 #include <Time/fg_timer.hxx>
93 #include <Time/light.hxx>
94 #include <Time/sunpos.hxx>
95 #include <Time/tmp.hxx>
96
97 // begin - added Venky
98 //    $$$ begin - added VS Renganathan
99 #include <simgear/misc/sgstream.hxx>
100 #include <FDM/flight.hxx>
101 #include <FDM/ADA.hxx>
102 void fgLoadDCS (void);
103 void fgUpdateDCS (void);
104 ssgSelector *ship_sel=NULL;
105 // upto 32 instances of a same object can be loaded.
106 ssgTransform *ship_pos[32];
107 double obj_lat[32],obj_lon[32],obj_alt[32];
108 int objc=0;
109 //    $$$ end - added VS Renganathan
110 // end - added Venky
111
112 #ifndef FG_OLD_WEATHER
113 #  include <WeatherCM/FGLocalWeatherDatabase.h>
114 #else
115 #  include <Weather/weather.hxx>
116 #endif
117
118 #include "version.h"
119
120 #include "bfi.hxx"
121 #include "fg_init.hxx"
122 #include "fg_io.hxx"
123 #include "globals.hxx"
124 #include "keyboard.hxx"
125 #include "splash.hxx"
126
127 #ifdef macintosh
128 #  include <console.h>          // -dw- for command line dialog
129 #endif
130
131
132 // This is a record containing a bit of global housekeeping information
133 FGGeneral general;
134
135 // Specify our current idle function state.  This is used to run all
136 // our initializations out of the glutIdleLoop() so that we can get a
137 // splash screen up and running right away.
138 static int idle_state = 0;
139 static long global_multi_loop;
140
141 // attempt to avoid a large bounce at startup
142 static bool initial_freeze = true;
143
144 // forward declaration
145 void fgReshape( int width, int height );
146
147 // Global structures for the Audio library
148 #ifdef ENABLE_AUDIO_SUPPORT
149    static FGSimpleSound *s1;
150    static FGSimpleSound *s2;
151 #endif
152
153
154 // ssg variables
155 ssgRoot *scene = NULL;
156 ssgBranch *terrain = NULL;
157
158 // aircraft model stuff
159 ssgSelector *acmodel_selector = NULL;
160 ssgTransform *acmodel_pos = NULL;
161 ssgSelector *prop_selector = NULL;
162 ssgSelector *flaps_selector = NULL;
163 int acmodel_npropsettings;
164 int acmodel_proprpms[4][2];  // different propeller settings
165
166 ssgRoot *lighting = NULL;
167 ssgBranch *ground = NULL;
168 ssgBranch *airport = NULL;
169
170 #ifdef FG_NETWORK_OLK
171 ssgSelector *fgd_sel = NULL;
172 ssgTransform *fgd_pos = NULL;
173 #endif
174
175 // current fdm/position used for view
176 FGInterface cur_view_fdm;
177
178 // Sky structures
179 SGSky *thesky;
180
181 // hack
182 sgMat4 copy_of_ssgOpenGLAxisSwapMatrix =
183 {
184   {  1.0f,  0.0f,  0.0f,  0.0f },
185   {  0.0f,  0.0f, -1.0f,  0.0f },
186   {  0.0f,  1.0f,  0.0f,  0.0f },
187   {  0.0f,  0.0f,  0.0f,  1.0f }
188 } ;
189
190 // The following defines flightgear options. Because glutlib will also
191 // want to parse its own options, those options must not be included here
192 // or they will get parsed by the main program option parser. Hence case
193 // is significant for any option added that might be in conflict with
194 // glutlib's parser.
195 //
196 // glutlib parses for:
197 //    -display
198 //    -direct   (invalid in Win32)
199 //    -geometry
200 //    -gldebug
201 //    -iconized
202 //    -indirect (invalid in Win32)
203 //    -synce
204 //
205 // Note that glutlib depends upon strings while this program's
206 // option parser wants only initial characters followed by numbers
207 // or pathnames.
208 //
209
210
211 ssgSimpleState *default_state;
212 ssgSimpleState *hud_and_panel;
213 ssgSimpleState *menus;
214
215 void fgBuildRenderStates( void ) {
216     default_state = new ssgSimpleState;
217     default_state->ref();
218     default_state->disable( GL_TEXTURE_2D );
219     default_state->enable( GL_CULL_FACE );
220     default_state->enable( GL_COLOR_MATERIAL );
221     default_state->setColourMaterial( GL_AMBIENT_AND_DIFFUSE );
222     default_state->setMaterial( GL_EMISSION, 0, 0, 0, 1 );
223     default_state->setMaterial( GL_SPECULAR, 0, 0, 0, 1 );
224     default_state->disable( GL_BLEND );
225     default_state->disable( GL_ALPHA_TEST );
226     default_state->disable( GL_LIGHTING );
227
228     hud_and_panel = new ssgSimpleState;
229     hud_and_panel->ref();
230     hud_and_panel->disable( GL_CULL_FACE );
231     hud_and_panel->disable( GL_TEXTURE_2D );
232     hud_and_panel->disable( GL_LIGHTING );
233     hud_and_panel->enable( GL_BLEND );
234
235     menus = new ssgSimpleState;
236     menus->ref();
237     menus->disable( GL_CULL_FACE );
238     menus->disable( GL_TEXTURE_2D );
239     menus->enable( GL_BLEND );
240 }
241
242 // fgFindNode -- a function that finds a named node in an ssg graph
243 ssgEntity *fgFindNode( ssgEntity *node, const char *name ) {
244   if ( node->getName() != NULL && strcmp( name, node->getName() ) == 0 ) {
245     return node;
246   } else if ( node->isAKindOf( ssgTypeBranch() ) ) {
247     ssgEntity *kid = ((ssgBranch*)node)->getKid(0);
248     while (kid != NULL) {
249       ssgEntity *n = fgFindNode(kid, name);
250       if (n != NULL)
251         return n;
252
253       kid = ((ssgBranch*)node)->getNextKid();
254     }
255   }
256
257   return NULL;
258 }
259
260 // fgInitVisuals() -- Initialize various GL/view parameters
261 void fgInitVisuals( void ) {
262     fgLIGHT *l;
263
264     l = &cur_light_params;
265
266 #ifndef GLUT_WRONG_VERSION
267     // Go full screen if requested ...
268     if ( fgGetBool("/sim/startup/fullscreen") ) {
269         glutFullScreen();
270     }
271 #endif
272
273     // If enabled, normal vectors specified with glNormal are scaled
274     // to unit length after transformation.  See glNormal.
275     // glEnable( GL_NORMALIZE );
276
277     glEnable( GL_LIGHTING );
278     glEnable( GL_LIGHT0 );
279     glLightfv( GL_LIGHT0, GL_POSITION, l->sun_vec );
280
281     sgVec3 sunpos;
282     sgSetVec3( sunpos, l->sun_vec[0], l->sun_vec[1], l->sun_vec[2] );
283     ssgGetLight( 0 ) -> setPosition( sunpos );
284
285     // glFogi (GL_FOG_MODE, GL_LINEAR);
286     glFogi (GL_FOG_MODE, GL_EXP2);
287     if ( (fgGetString("/sim/rendering/fog") == "disabled") || 
288          (!fgGetBool("/sim/rendering/shading"))) {
289         // if fastest fog requested, or if flat shading force fastest
290         glHint ( GL_FOG_HINT, GL_FASTEST );
291     } else if ( fgGetString("/sim/rendering/fog") == "nicest" ) {
292         glHint ( GL_FOG_HINT, GL_NICEST );
293     }
294     if ( fgGetBool("/sim/rendering/wireframe") ) {
295         // draw wire frame
296         glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
297     }
298
299     // This is the default anyways, but it can't hurt
300     glFrontFace ( GL_CCW );
301
302     // Just testing ...
303     // glEnable(GL_POINT_SMOOTH);
304     // glEnable(GL_LINE_SMOOTH);
305     // glEnable(GL_POLYGON_SMOOTH);      
306 }
307
308
309 // Update all Visuals (redraws anything graphics related)
310 void fgRenderFrame( void ) {
311     // Update the BFI.
312     FGBFI::update();
313
314     fgLIGHT *l = &cur_light_params;
315     static double last_visibility = -9999;
316
317     static GLfloat fog_exp_density;
318     static GLfloat fog_exp2_density;
319     static GLfloat fog_exp2_punch_through;
320     
321     // double angle;
322     // GLfloat black[4] = { 0.0, 0.0, 0.0, 1.0 };
323     // GLfloat white[4] = { 1.0, 1.0, 1.0, 1.0 };
324     // GLfloat terrain_color[4] = { 0.54, 0.44, 0.29, 1.0 };
325     // GLfloat mat_shininess[] = { 10.0 };
326     GLbitfield clear_mask;
327     
328     if ( idle_state != 1000 ) {
329         // still initializing, draw the splash screen
330         if ( fgGetBool("/sim/startup/splash-screen") ) {
331             fgSplashUpdate(0.0);
332         }
333     } else {
334         // idle_state is now 1000 meaning we've finished all our
335         // initializations and are running the main loop, so this will
336         // now work without seg faulting the system.
337
338         // printf("Ground = %.2f  Altitude = %.2f\n", scenery.cur_elev, 
339         //        FG_Altitude * SG_FEET_TO_METER);
340     
341         // this is just a temporary hack, to make me understand Pui
342         // timerText -> setLabel (ctime (&t->cur_time));
343         // end of hack
344
345         // calculate our current position in cartesian space
346         scenery.center = scenery.next_center;
347         // printf("scenery center = %.2f %.2f %.2f\n", scenery.center.x(),
348         //        scenery.center.y(), scenery.center.z());
349
350         FGViewerRPH *pilot_view =
351             (FGViewerRPH *)globals->get_viewmgr()->get_view( 0 );
352
353         pilot_view->set_geod_view_pos( cur_fdm_state->get_Longitude(), 
354                                        cur_fdm_state->get_Lat_geocentric(), 
355                                        cur_fdm_state->get_Altitude() *
356                                        SG_FEET_TO_METER );
357         pilot_view->set_sea_level_radius( cur_fdm_state->
358                                           get_Sea_level_radius() *
359                                           SG_FEET_TO_METER ); 
360         pilot_view->set_rph( cur_fdm_state->get_Phi(),
361                              cur_fdm_state->get_Theta(),
362                              cur_fdm_state->get_Psi() );
363
364         FGViewerLookAt *chase_view =
365             (FGViewerLookAt *)globals->get_viewmgr()->get_view( 1 );
366
367         sgVec3 po;              // chase view pilot_offset
368         sgVec3 wup;             // chase view world up
369         sgSetVec3( po, 0.0, 0.0, 100.0 );
370         sgCopyVec3( wup, pilot_view->get_world_up() );
371         sgMat4 CXFM;            // chase view + pilot offset xform
372         sgMakeRotMat4( CXFM,
373                        chase_view->get_view_offset() * SGD_RADIANS_TO_DEGREES -
374                        cur_fdm_state->get_Psi() * SGD_RADIANS_TO_DEGREES,
375                        wup );
376         sgVec3 npo;             // new pilot offset after rotation
377         sgVec3 *pPO = PilotOffsetGet();
378         sgXformVec3( po, *pPO, pilot_view->get_UP() );
379         sgXformVec3( npo, po, CXFM );
380
381         chase_view->set_geod_view_pos( cur_fdm_state->get_Longitude(), 
382                                        cur_fdm_state->get_Lat_geocentric(), 
383                                        cur_fdm_state->get_Altitude() *
384                                        SG_FEET_TO_METER );
385         chase_view->set_sea_level_radius( cur_fdm_state->
386                                           get_Sea_level_radius() *
387                                           SG_FEET_TO_METER );
388         chase_view->set_pilot_offset( npo[0], npo[1], npo[2] );
389         chase_view->set_view_forward( pilot_view->get_view_pos() ); 
390         chase_view->set_view_up( wup );
391
392 #if 0
393         sgMat4 rph;
394         sgCopyMat4( rph, pilot_view->get_VIEW() );
395         cout << "RPH Matrix = " << endl;
396         int i, j;
397         for ( i = 0; i < 4; i++ ) {
398             for ( j = 0; j < 4; j++ ) {
399                 printf("%10.4f ", rph[i][j]);
400             }
401             cout << endl;
402         }
403
404         sgMat4 la;
405         sgCopyMat4( la, chase_view->get_VIEW() );
406         cout << "LookAt Matrix = " << endl;
407         for ( i = 0; i < 4; i++ ) {
408             for ( j = 0; j < 4; j++ ) {
409                 printf("%10.4f ", la[i][j]);
410             }
411             cout << endl;
412         }
413 #endif
414
415         // update view port
416         fgReshape( fgGetInt("/sim/startup/xsize"),
417                    fgGetInt("/sim/startup/ysize") );
418
419 #if 0
420         // swing and a miss
421
422         if ( ! fgPanelVisible() ) {
423             xglViewport( 0, 0 ,
424                          (GLint)(fgGetInt("/sim/startup/xsize")),
425                          (GLint)(fgGetInt("/sim/startup/ysize")) );
426         } else {
427             int view_h =
428                 int( (current_panel->getViewHeight() -
429                       current_panel->getYOffset())
430                      * (fgGetInt("/sim/startup/ysize") / 768.0) );
431             glViewport( 0, 
432                         (GLint)(fgGetInt("/sim/startup/ysize") - view_h),
433                         (GLint)(fgGetInt("/sim/startup/xsize")),
434                         (GLint)(view_h) );
435         }
436 #endif
437
438         // set the sun position
439         glLightfv( GL_LIGHT0, GL_POSITION, l->sun_vec );
440
441         clear_mask = GL_DEPTH_BUFFER_BIT;
442         if ( fgGetBool("/sim/rendering/wireframe") ) {
443             clear_mask |= GL_COLOR_BUFFER_BIT;
444         }
445
446         if ( fgGetBool("/sim/rendering/skyblend") ) {
447             if ( fgGetBool("/sim/rendering/textures") ) {
448                 // glClearColor(black[0], black[1], black[2], black[3]);
449                 glClearColor(l->adj_fog_color[0], l->adj_fog_color[1], 
450                              l->adj_fog_color[2], l->adj_fog_color[3]);
451                 clear_mask |= GL_COLOR_BUFFER_BIT;
452             }
453         } else {
454             glClearColor(l->sky_color[0], l->sky_color[1], 
455                          l->sky_color[2], l->sky_color[3]);
456             clear_mask |= GL_COLOR_BUFFER_BIT;
457         }
458         glClear( clear_mask );
459
460         // Tell GL we are switching to model view parameters
461
462         // I really should create a derived ssg node or use a call
463         // back or something so that I can draw the sky within the
464         // ssgCullAndDraw() function, but for now I just mimic what
465         // ssg does to set up the model view matrix
466         glMatrixMode(GL_MODELVIEW);
467         glLoadIdentity();
468         ssgSetCamera( (sgVec4 *)globals->get_current_view()->get_VIEW() );
469
470         // set the opengl state to known default values
471         default_state->force();
472
473         // update fog params if visibility has changed
474 #ifndef FG_OLD_WEATHER
475         thesky->set_visibility( WeatherDatabase->getWeatherVisibility() );
476 #else
477         thesky->set_visibility( current_weather.get_visibility() );
478 #endif
479
480         thesky->modify_vis( cur_fdm_state->get_Altitude() * SG_FEET_TO_METER,
481                             ( global_multi_loop * 
482                               fgGetInt("/sim/speed-up") ) /
483                             (double)fgGetInt("/sim/model-hz") );
484
485         double actual_visibility = thesky->get_visibility();
486         // cout << "actual visibility = " << actual_visibility << endl;
487
488         if ( actual_visibility != last_visibility ) {
489             last_visibility = actual_visibility;
490
491             // cout << "----> updating fog params" << endl;
492                 
493             // for GL_FOG_EXP
494             fog_exp_density = -log(0.01) / actual_visibility;
495     
496             // for GL_FOG_EXP2
497             fog_exp2_density = sqrt( -log(0.01) ) / actual_visibility;
498             fog_exp2_punch_through = sqrt( -log(0.01) ) / 
499                 ( actual_visibility * 1.5 );
500         }
501
502         // Set correct opengl fog density
503         glFogf (GL_FOG_DENSITY, fog_exp2_density);
504
505         // update the sky dome
506         if ( fgGetBool("/sim/rendering/skyblend") ) {
507             /* cout << "thesky->repaint() sky_color = "
508                  << cur_light_params.sky_color[0] << " "
509                  << cur_light_params.sky_color[1] << " "
510                  << cur_light_params.sky_color[2] << " "
511                  << cur_light_params.sky_color[3] << endl;
512             cout << "    fog = "
513                  << cur_light_params.fog_color[0] << " "
514                  << cur_light_params.fog_color[1] << " "
515                  << cur_light_params.fog_color[2] << " "
516                  << cur_light_params.fog_color[3] << endl;
517             cout << "    sun_angle = " << cur_light_params.sun_angle
518                  << "    moon_angle = " << cur_light_params.moon_angle
519                  << endl; */
520             thesky->repaint( cur_light_params.sky_color,
521                              cur_light_params.adj_fog_color,
522                              cur_light_params.sun_angle,
523                              cur_light_params.moon_angle,
524                              globals->get_ephem()->getNumPlanets(),
525                              globals->get_ephem()->getPlanets(),
526                              globals->get_ephem()->getNumStars(),
527                              globals->get_ephem()->getStars() );
528  
529             /* cout << "thesky->reposition( view_pos = " << view_pos[0] << " "
530                  << view_pos[1] << " " << view_pos[2] << endl;
531             cout << "    zero_elev = " << zero_elev[0] << " "
532                  << zero_elev[1] << " " << zero_elev[2]
533                  << " lon = " << cur_fdm_state->get_Longitude()
534                  << " lat = " << cur_fdm_state->get_Latitude() << endl;
535             cout << "    sun_rot = " << cur_light_params.sun_rotation
536                  << " gst = " << SGTime::cur_time_params->getGst() << endl;
537             cout << "    sun ra = " << globals->get_ephem()->getSunRightAscension()
538                  << " sun dec = " << globals->get_ephem()->getSunDeclination() 
539                  << " moon ra = " << globals->get_ephem()->getMoonRightAscension()
540                  << " moon dec = " << globals->get_ephem()->getMoonDeclination() << endl; */
541
542             thesky->reposition( globals->get_current_view()->get_view_pos(),
543                                 globals->get_current_view()->get_zero_elev(),
544                                 globals->get_current_view()->get_world_up(),
545                                 cur_fdm_state->get_Longitude(),
546                                 cur_fdm_state->get_Latitude(),
547                                 cur_fdm_state->get_Altitude() * SG_FEET_TO_METER,
548                                 cur_light_params.sun_rotation,
549                                 globals->get_time_params()->getGst(),
550                                 globals->get_ephem()->getSunRightAscension(),
551                                 globals->get_ephem()->getSunDeclination(),
552                                 50000.0,
553                                 globals->get_ephem()->getMoonRightAscension(),
554                                 globals->get_ephem()->getMoonDeclination(),
555                                 50000.0 );
556         }
557
558         glEnable( GL_DEPTH_TEST );
559         if ( fgGetString("/sim/rendering/fog") != (string)"disabled" ) {
560             glEnable( GL_FOG );
561             glFogi( GL_FOG_MODE, GL_EXP2 );
562             glFogfv( GL_FOG_COLOR, l->adj_fog_color );
563         }
564
565         // set sun/lighting parameters
566         ssgGetLight( 0 ) -> setPosition( l->sun_vec );
567
568         // GL_LIGHT_MODEL_AMBIENT has a default non-zero value so if
569         // we only update GL_AMBIENT for our lights we will never get
570         // a completely dark scene.  So, we set GL_LIGHT_MODEL_AMBIENT
571         // explicitely to black.
572         GLfloat black[4] = { 0.0, 0.0, 0.0, 1.0 };
573         GLfloat white[4] = { 1.0, 1.0, 1.0, 1.0 };
574         glLightModelfv( GL_LIGHT_MODEL_AMBIENT, black );
575
576         ssgGetLight( 0 ) -> setColour( GL_AMBIENT, l->scene_ambient );
577         ssgGetLight( 0 ) -> setColour( GL_DIFFUSE, l->scene_diffuse );
578         // ssgGetLight( 0 ) -> setColour( GL_SPECULAR, l->scene_white );
579
580         // texture parameters
581         // glEnable( GL_TEXTURE_2D );
582         glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ) ;
583         glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST ) ;
584
585         // glMatrixMode( GL_PROJECTION );
586         // glLoadIdentity();
587         float fov = globals->get_current_view()->get_fov();
588         ssgSetFOV(fov, fov * globals->get_current_view()->get_win_ratio());
589
590         double agl = current_aircraft.fdm_state->get_Altitude() * SG_FEET_TO_METER
591             - scenery.cur_elev;
592
593         // SG_LOG( SG_ALL, SG_INFO, "visibility is " 
594         //         << current_weather.get_visibility() );
595             
596         if ( agl > 10.0 ) {
597             ssgSetNearFar( 10.0f, 120000.0f );
598         } else {
599             ssgSetNearFar( 0.5f, 120000.0f );
600         }
601
602         if ( globals->get_viewmgr()->get_current() == 0 ) {
603             // disable aircraft model
604             acmodel_selector->select(0);
605         } else { 
606             // enable aircraft model and set up its position and orientation
607             acmodel_selector->select(1);
608
609             FGViewerRPH *pilot_view =
610                 (FGViewerRPH *)globals->get_viewmgr()->get_view( 0 );
611
612             sgMat4 sgTRANS;
613             sgMakeTransMat4( sgTRANS, pilot_view->get_view_pos() );
614
615             sgVec3 ownship_up;
616             sgSetVec3( ownship_up, 0.0, 0.0, 1.0);
617
618             sgMat4 sgROT;
619             sgMakeRotMat4( sgROT, -90.0, ownship_up );
620
621             // sgMat4 sgTMP;
622             // sgMat4 sgTUX;
623             // sgMultMat4( sgTMP, sgROT, pilot_view.VIEW_ROT );
624             // sgMultMat4( sgTUX, sgTMP, sgTRANS );
625
626             // sgTUX = ( sgROT * pilot_view.VIEW_ROT ) * sgTRANS
627             sgMat4 sgTUX;
628             sgCopyMat4( sgTUX, sgROT );
629             sgPostMultMat4( sgTUX, pilot_view->get_VIEW_ROT() );
630             sgPostMultMat4( sgTUX, sgTRANS );
631         
632             sgCoord tuxpos;
633             sgSetCoord( &tuxpos, sgTUX );
634             acmodel_pos->setTransform( &tuxpos );
635
636             // set up moving parts
637             if (flaps_selector != NULL) {
638               flaps_selector->select( (controls.get_flaps() > 0.5f) ? 1 : 2 );
639             }
640
641             if (prop_selector != NULL) {
642               int propsel_mask = 0;
643               for (int i = 0; i < acmodel_npropsettings; i++) {
644                 if (FGBFI::getRPM() >= acmodel_proprpms[i][0] &&
645                     FGBFI::getRPM() <= acmodel_proprpms[i][1]) {
646                   propsel_mask |= 1 << i;
647                 }
648               }
649               prop_selector->select(propsel_mask);
650             }
651         }
652
653         // $$$ begin - added VS Renganthan 17 Oct 2K
654         fgUpdateDCS();
655         // $$$ end - added VS Renganthan 17 Oct 2K
656
657 # ifdef FG_NETWORK_OLK
658         if ( fgGetBool("/sim/networking/network-olk") ) {
659             sgCoord fgdpos;
660             other = head->next;             /* put listpointer to start  */
661             while ( other != tail) {        /* display all except myself */
662                 if ( strcmp( other->ipadr, fgd_mcp_ip) != 0) {
663                     other->fgd_sel->select(1);
664                     sgSetCoord( &fgdpos, other->sgFGD_COORD );
665                     other->fgd_pos->setTransform( &fgdpos );
666                 }
667                 other = other->next;
668             }
669
670             // fgd_sel->select(1);
671             // sgCopyMat4( sgTUX, current_view.sgVIEW);
672             // sgCoord fgdpos;
673             // sgSetCoord( &fgdpos, sgFGD_VIEW );
674             // fgd_pos->setTransform( &fgdpos);
675         }
676 # endif
677
678         // position tile nodes and update range selectors
679         global_tile_mgr.prep_ssg_nodes();
680
681         if ( fgGetBool("/sim/rendering/skyblend") ) {
682             // draw the sky backdrop
683
684             // we need a white diffuse light for the phase of the moon
685             ssgGetLight( 0 ) -> setColour( GL_DIFFUSE, white );
686
687             thesky->preDraw();
688
689             // return to the desired diffuse color
690             ssgGetLight( 0 ) -> setColour( GL_DIFFUSE, l->scene_diffuse );
691         }
692
693         // draw the ssg scene
694         glEnable( GL_DEPTH_TEST );
695         ssgCullAndDraw( scene );
696
697         // change state for lighting here
698
699         // draw lighting
700         // Set punch through fog density
701         glFogf (GL_FOG_DENSITY, fog_exp2_punch_through);
702
703         ssgCullAndDraw( lighting );
704
705         if ( fgGetBool("/sim/rendering/skyblend") ) {
706             // draw the sky cloud layers
707             thesky->postDraw( cur_fdm_state->get_Altitude() * SG_FEET_TO_METER );
708         }
709
710         // display HUD && Panel
711         glDisable( GL_FOG );
712         glDisable( GL_DEPTH_TEST );
713         // glDisable( GL_CULL_FACE );
714         // glDisable( GL_TEXTURE_2D );
715
716         // update the controls subsystem
717         controls.update();
718
719         hud_and_panel->apply();
720         fgCockpitUpdate();
721
722         // update the panel subsystem
723         if (current_panel != 0)
724           current_panel->update();
725
726         // We can do translucent menus, so why not. :-)
727         menus->apply();
728         glBlendFunc ( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ) ;
729         puDisplay();
730         // glDisable ( GL_BLEND ) ;
731
732         // glEnable( GL_FOG );
733     }
734
735     glutSwapBuffers();
736 }
737
738
739 // Update internal time dependent calculations (i.e. flight model)
740 void fgUpdateTimeDepCalcs() {
741     static bool inited = false;
742
743     fgLIGHT *l = &cur_light_params;
744     int i;
745
746     long multi_loop = 1;
747
748     if ( !globals->get_freeze() && !initial_freeze ) {
749         // conceptually, this could be done for each fdm instance ...
750
751         if ( !inited ) {
752             cur_fdm_state->stamp();
753             inited = true;
754         }
755
756         SGTimeStamp current;
757         current.stamp();
758         long elapsed = current - cur_fdm_state->get_time_stamp();
759         cur_fdm_state->set_time_stamp( current );
760         elapsed += cur_fdm_state->get_remainder();
761         // cout << "elapsed = " << elapsed << endl;
762         // cout << "dt = " << cur_fdm_state->get_delta_t() << endl;
763         multi_loop = (long)(((double)elapsed * 0.000001) /
764                                cur_fdm_state->get_delta_t() );
765         cur_fdm_state->set_multi_loop( multi_loop );
766         long remainder = elapsed - (long)( (multi_loop*1000000) *
767                                      cur_fdm_state->get_delta_t() );
768         cur_fdm_state->set_remainder( remainder );
769         // cout << "remainder = " << remainder << endl;
770
771         // chop max interations to something reasonable if the sim was
772         // delayed for an excesive amount of time
773         if ( multi_loop > 2.0 / cur_fdm_state->get_delta_t() ) {
774             multi_loop = (int)(2.0 / cur_fdm_state->get_delta_t());
775             cur_fdm_state->set_remainder( 0 );
776         }
777
778         // cout << "multi_loop = " << multi_loop << endl;
779         for ( i = 0; i < multi_loop * fgGetInt("/sim/speed-up"); ++i ) {
780             // run Autopilot system
781             current_autopilot->run();
782
783             // update autopilot
784             cur_fdm_state->update( 1 );
785         }
786         FGSteam::update( multi_loop * fgGetInt("/sim/speed-up") );
787     } else {
788         cur_fdm_state->update( 0 );
789         FGSteam::update( 0 );
790
791         //if ( global_tile_mgr.queue_size() == 0 ) {
792             initial_freeze = false;
793             //}
794     }
795
796     if ( fgGetString("/sim/view-mode") == "pilot" ) {
797         cur_view_fdm = *cur_fdm_state;
798         // do nothing
799     }
800
801     // update the view angle
802     FGViewer *v = globals->get_current_view();
803     for ( i = 0; i < multi_loop; i++ ) {
804         if ( fabs(v->get_goal_view_offset() - v->get_view_offset()) < 0.05 ) {
805             v->set_view_offset( v->get_goal_view_offset() );
806             break;
807         } else {
808             // move current_view.view_offset towards
809             // current_view.goal_view_offset
810             if ( v->get_goal_view_offset() > v->get_view_offset() )
811             {
812                 if ( v->get_goal_view_offset() - v->get_view_offset() < SGD_PI ){
813                     v->inc_view_offset( 0.01 );
814                 } else {
815                     v->inc_view_offset( -0.01 );
816                 }
817             } else {
818                 if ( v->get_view_offset() - v->get_goal_view_offset() < SGD_PI ){
819                     v->inc_view_offset( -0.01 );
820                 } else {
821                     v->inc_view_offset( 0.01 );
822                 }
823             }
824             if ( v->get_view_offset() > SGD_2PI ) {
825                 v->inc_view_offset( -SGD_2PI );
826             } else if ( v->get_view_offset() < 0 ) {
827                 v->inc_view_offset( SGD_2PI );
828             }
829         }
830     }
831
832     double tmp = -(l->sun_rotation + SGD_PI) 
833         - (cur_fdm_state->get_Psi() -
834            globals->get_current_view()->get_view_offset() );
835     while ( tmp < 0.0 ) {
836         tmp += SGD_2PI;
837     }
838     while ( tmp > SGD_2PI ) {
839         tmp -= SGD_2PI;
840     }
841     /* printf("Psi = %.2f, viewoffset = %.2f sunrot = %.2f rottosun = %.2f\n",
842            FG_Psi * SGD_RADIANS_TO_DEGREES, current_view.view_offset * SGD_RADIANS_TO_DEGREES, 
843            -(l->sun_rotation+SGD_PI) * SGD_RADIANS_TO_DEGREES, tmp * SGD_RADIANS_TO_DEGREES); */
844     l->UpdateAdjFog();
845
846     // Update solar system
847     globals->get_ephem()->update( globals->get_time_params()->getMjd(),
848                                   globals->get_time_params()->getLst(),
849                                   cur_fdm_state->get_Latitude() );
850
851     // Update radio stack model
852     current_radiostack->update();
853 }
854
855
856 void fgInitTimeDepCalcs( void ) {
857     // initialize timer
858
859     // #ifdef HAVE_SETITIMER
860     //   fgTimerInit( 1.0 / fgGetInt("/sim/model-hz"), 
861     //                fgUpdateTimeDepCalcs );
862     // #endif HAVE_SETITIMER
863 }
864
865
866 static const double alt_adjust_ft = 3.758099;
867 static const double alt_adjust_m = alt_adjust_ft * SG_FEET_TO_METER;
868
869
870 // What should we do when we have nothing else to do?  Let's get ready
871 // for the next move and update the display?
872 static void fgMainLoop( void ) {
873     static long remainder = 0;
874     long elapsed;
875 #ifdef FANCY_FRAME_COUNTER
876     int i;
877     double accum;
878 #else
879     static time_t last_time = 0;
880     static int frames = 0;
881 #endif // FANCY_FRAME_COUNTER
882
883     SGTime *t = globals->get_time_params();
884
885     SG_LOG( SG_ALL, SG_DEBUG, "Running Main Loop");
886     SG_LOG( SG_ALL, SG_DEBUG, "======= ==== ====");
887
888 #ifdef FG_NETWORK_OLK
889     if ( fgGetBool("/sim/networking/network-olk") ) {
890         if ( net_is_registered == 0 ) {      // We first have to reg. to fgd
891             // printf("FGD: Netupdate\n");
892             fgd_send_com( "A", FGFS_host);   // Send Mat4 data
893             fgd_send_com( "B", FGFS_host);   // Recv Mat4 data
894         }
895     }
896 #endif
897
898 #if defined( ENABLE_PLIB_JOYSTICK )
899     // Read joystick and update control settings
900     if ( fgGetString("/sim/control-mode") == "joystick" )
901     {
902         fgJoystickRead();
903     }
904 #elif defined( ENABLE_GLUT_JOYSTICK )
905     // Glut joystick support works by feeding a joystick handler
906     // function to glut.  This is taken care of once in the joystick
907     // init routine and we don't have to worry about it again.
908 #endif
909
910 #ifdef FG_OLD_WEATHER
911     current_weather.Update();
912 #endif
913
914     // Fix elevation.  I'm just sticking this here for now, it should
915     // probably move eventually
916
917     /* printf("Before - ground = %.2f  runway = %.2f  alt = %.2f\n",
918            scenery.cur_elev,
919            cur_fdm_state->get_Runway_altitude() * SG_FEET_TO_METER,
920            cur_fdm_state->get_Altitude() * SG_FEET_TO_METER); */
921
922     if ( scenery.cur_elev > -9990 ) {
923         if ( cur_fdm_state->get_Altitude() * SG_FEET_TO_METER < 
924              (scenery.cur_elev + alt_adjust_m - 3.0) ) {
925             // now set aircraft altitude above ground
926             printf("(*) Current Altitude = %.2f < %.2f forcing to %.2f\n", 
927                    cur_fdm_state->get_Altitude() * SG_FEET_TO_METER,
928                    scenery.cur_elev + alt_adjust_m - 3.0,
929                    scenery.cur_elev + alt_adjust_m );
930             fgFDMForceAltitude( fgGetString("/sim/flight-model"), 
931                                 scenery.cur_elev + alt_adjust_m );
932
933             SG_LOG( SG_ALL, SG_DEBUG, 
934                     "<*> resetting altitude to " 
935                     << cur_fdm_state->get_Altitude() * SG_FEET_TO_METER
936                     << " meters" );
937         }
938     }
939
940     /* printf("Adjustment - ground = %.2f  runway = %.2f  alt = %.2f\n",
941            scenery.cur_elev,
942            cur_fdm_state->get_Runway_altitude() * SG_FEET_TO_METER,
943            cur_fdm_state->get_Altitude() * SG_FEET_TO_METER); */
944
945     // update "time"
946     if ( globals->get_warp_delta() != 0 ) {
947         globals->inc_warp( globals->get_warp_delta() );
948     }
949
950     t->update( cur_fdm_state->get_Longitude(),
951                cur_fdm_state->get_Latitude(),
952                globals->get_warp() );
953
954     if ( globals->get_warp_delta() != 0 ) {
955         fgUpdateSkyAndLightingParams();
956     }
957
958     // update magvar model
959     globals->get_mag()->update( cur_fdm_state->get_Longitude(),
960                                 cur_fdm_state->get_Latitude(),
961                                 cur_fdm_state->get_Altitude()* SG_FEET_TO_METER,
962                                 globals->get_time_params()->getJD() );
963
964     // Get elapsed time (in usec) for this past frame
965     elapsed = fgGetTimeInterval();
966     SG_LOG( SG_ALL, SG_DEBUG, 
967             "Elapsed time interval is = " << elapsed 
968             << ", previous remainder is = " << remainder );
969
970     // Calculate frame rate average
971 #ifdef FANCY_FRAME_COUNTER
972     /* old fps calculation */
973     if ( elapsed > 0 ) {
974         double tmp;
975         accum = 0.0;
976         for ( i = FG_FRAME_RATE_HISTORY - 2; i >= 0; i-- ) {
977             tmp = general.get_frame(i);
978             accum += tmp;
979             // printf("frame[%d] = %.2f\n", i, g->frames[i]);
980             general.set_frame(i+1,tmp);
981         }
982         tmp = 1000000.0 / (float)elapsed;
983         general.set_frame(0,tmp);
984         // printf("frame[0] = %.2f\n", general.frames[0]);
985         accum += tmp;
986         general.set_frame_rate(accum / (float)FG_FRAME_RATE_HISTORY);
987         // printf("ave = %.2f\n", general.frame_rate);
988     }
989 #else
990     if ( (t->get_cur_time() != last_time) && (last_time > 0) ) {
991         general.set_frame_rate( frames );
992         SG_LOG( SG_ALL, SG_DEBUG, 
993                 "--> Frame rate is = " << general.get_frame_rate() );
994         frames = 0;
995     }
996     last_time = t->get_cur_time();
997     ++frames;
998 #endif
999
1000     // Run flight model
1001
1002     // Calculate model iterations needed for next frame
1003     elapsed += remainder;
1004
1005     global_multi_loop = (long)(((double)elapsed * 0.000001) * 
1006                               fgGetInt("/sim/model-hz"));
1007     remainder = elapsed - ( (global_multi_loop*1000000) / 
1008                             fgGetInt("/sim/model-hz") );
1009     SG_LOG( SG_ALL, SG_DEBUG, 
1010             "Model iterations needed = " << global_multi_loop
1011             << ", new remainder = " << remainder );
1012         
1013     // chop max interations to something reasonable if the sim was
1014     // delayed for an excesive amount of time
1015     if ( global_multi_loop > 2.0 * fgGetInt("/sim/model-hz") ) {
1016         global_multi_loop = (int)(2.0 * fgGetInt("/sim/model-hz") );
1017         remainder = 0;
1018     }
1019
1020     // flight model
1021     if ( global_multi_loop > 0 ) {
1022         fgUpdateTimeDepCalcs();
1023     } else {
1024         SG_LOG( SG_ALL, SG_DEBUG, 
1025                 "Elapsed time is zero ... we're zinging" );
1026     }
1027
1028 #if ! defined( macintosh )
1029     // Do any I/O channel work that might need to be done
1030     fgIOProcess();
1031 #endif
1032
1033     // see if we need to load any new scenery tiles
1034     global_tile_mgr.update( cur_fdm_state->get_Longitude()
1035                             * SGD_RADIANS_TO_DEGREES,
1036                             cur_fdm_state->get_Latitude()
1037                             * SGD_RADIANS_TO_DEGREES );
1038
1039     // see if we need to load any deferred-load textures
1040     material_lib.load_next_deferred();
1041
1042     // Process/manage pending events
1043     global_events.Process();
1044
1045     // Run audio scheduler
1046 #ifdef ENABLE_AUDIO_SUPPORT
1047     if ( fgGetBool("/sim/sound") && globals->get_soundmgr()->is_working() ) {
1048         if ( fgGetString("/sim/aircraft") == "c172" ) {
1049             // pitch corresponds to rpm
1050             // volume corresponds to manifold pressure
1051
1052             // cout << "AUDIO working = "
1053             //      << globals->get_soundmgr()->is_working() << endl;
1054
1055             double rpm_factor;
1056             if ( cur_fdm_state->get_engine(0) != NULL ) {
1057                 rpm_factor = cur_fdm_state->get_engine(0)->get_RPM() / 2500.0;
1058             } else {
1059                 rpm_factor = 1.0;
1060             }
1061             // cout << "rpm = " << cur_fdm_state->get_engine(0)->get_RPM()
1062             //      << endl;
1063
1064             double pitch = 0.3 + rpm_factor * 3.0;
1065         
1066             // don't run at absurdly slow rates -- not realistic
1067             // and sounds bad to boot.  :-)
1068             if (pitch < 0.7) { pitch = 0.7; }
1069             if (pitch > 5.0) { pitch = 5.0; }
1070
1071             double mp_factor;
1072             if ( cur_fdm_state->get_engine(0) != NULL ) {
1073                 mp_factor = 
1074                     cur_fdm_state->get_engine(0)->get_Manifold_Pressure() / 100;
1075             } else {
1076                 mp_factor = 0.3;
1077             }
1078             /* cout << "mp = " 
1079                  << cur_fdm_state->get_engine(0)->get_Manifold_Pressure()
1080                  << endl; */
1081
1082             double volume = 0.15 + mp_factor / 2.0;
1083
1084             if ( volume < 0.15 ) { volume = 0.15; }
1085             if ( volume > 0.5 ) { volume = 0.5; }
1086             // cout << "volume = " << volume << endl;
1087
1088             s1->set_pitch( pitch );
1089             s1->set_volume( volume );
1090         } else {
1091             double param = controls.get_throttle( 0 ) * 2.0 + 1.0;
1092             s1->set_pitch( param );
1093             s1->set_volume( param );
1094         }
1095
1096         globals->get_soundmgr()->update();
1097     }
1098 #endif
1099
1100     // redraw display
1101     fgRenderFrame();
1102
1103     SG_LOG( SG_ALL, SG_DEBUG, "" );
1104 }
1105
1106
1107 // This is the top level master main function that is registered as
1108 // our idle funciton
1109 //
1110
1111 // The first few passes take care of initialization things (a couple
1112 // per pass) and once everything has been initialized fgMainLoop from
1113 // then on.
1114
1115 static void fgIdleFunction ( void ) {
1116     // printf("idle state == %d\n", idle_state);
1117
1118     if ( idle_state == 0 ) {
1119         // Initialize the splash screen right away
1120         if ( fgGetBool("/sim/startup/splash-screen") ) {
1121             fgSplashInit();
1122         }
1123         
1124         idle_state++;
1125     } else if ( idle_state == 1 ) {
1126         // Start the intro music
1127 #if !defined(WIN32)
1128         if ( fgGetBool("/sim/startup/intro-music") ) {
1129             string lockfile = "/tmp/mpg123.running";
1130             SGPath mp3file( globals->get_fg_root() );
1131             mp3file.append( "Sounds/intro.mp3" );
1132
1133             string command = "(touch " + lockfile + "; mpg123 "
1134                 + mp3file.str() + "> /dev/null 2>&1; /bin/rm "
1135                 + lockfile + ") &";
1136             SG_LOG( SG_GENERAL, SG_INFO, 
1137                     "Starting intro music: " << mp3file.str() );
1138             system ( command.c_str() );
1139         }
1140 #endif
1141
1142         idle_state++;
1143     } else if ( idle_state == 2 ) {
1144         // These are a few miscellaneous things that aren't really
1145         // "subsystems" but still need to be initialized.
1146
1147 #ifdef USE_GLIDE
1148         if ( strstr ( general.get_glRenderer(), "Glide" ) ) {
1149             grTexLodBiasValue ( GR_TMU0, 1.0 ) ;
1150         }
1151 #endif
1152
1153         idle_state++;
1154     } else if ( idle_state == 3 ) {
1155         // This is the top level init routine which calls all the
1156         // other subsystem initialization routines.  If you are adding
1157         // a subsystem to flightgear, its initialization call should
1158         // located in this routine.
1159         if( !fgInitSubsystems()) {
1160             SG_LOG( SG_GENERAL, SG_ALERT,
1161                     "Subsystem initializations failed ..." );
1162             exit(-1);
1163         }
1164
1165         idle_state++;
1166     } else if ( idle_state == 4 ) {
1167         // setup OpenGL view parameters
1168         fgInitVisuals();
1169
1170         idle_state++;
1171     } else if ( idle_state == 5 ) {
1172
1173         idle_state++;
1174     } else if ( idle_state == 6 ) {
1175         // Initialize audio support
1176 #ifdef ENABLE_AUDIO_SUPPORT
1177
1178 #if !defined(WIN32)
1179         if ( fgGetBool("/sim/startup/intro-music") ) {
1180             // Let's wait for mpg123 to finish
1181             string lockfile = "/tmp/mpg123.running";
1182             struct stat stat_buf;
1183
1184             SG_LOG( SG_GENERAL, SG_INFO, 
1185                     "Waiting for mpg123 player to finish ..." );
1186             while ( stat(lockfile.c_str(), &stat_buf) == 0 ) {
1187                 // file exist, wait ...
1188                 sleep(1);
1189                 SG_LOG( SG_GENERAL, SG_INFO, ".");
1190             }
1191             SG_LOG( SG_GENERAL, SG_INFO, "");
1192         }
1193 #endif // WIN32
1194
1195         if ( fgGetBool("/sim/sound") ) {
1196             globals->get_soundmgr()->init();
1197
1198             s1 = new FGSimpleSound( fgGetString("/sim/sounds/engine",
1199                                                 "Sounds/wasp.wav") );
1200             globals->get_soundmgr()->add( s1, "engine loop" );
1201             globals->get_soundmgr()->play_looped( "engine loop" );
1202             SG_LOG( SG_GENERAL, SG_INFO,
1203                     "Rate = " << s1->get_sample()->getRate()
1204                     << "  Bps = " << s1->get_sample()->getBps()
1205                     << "  Stereo = " << s1->get_sample()->getStereo() );
1206
1207             s2 = new FGSimpleSound( "Sounds/corflaps.wav" );
1208             // FGMorse mmm;
1209             // mmm.init();
1210             // s2 = mmm.make_ident( "JLI" );
1211             s2->set_volume( 0.3 );
1212             globals->get_soundmgr()->add( s2, "flaps" );
1213         }
1214 #endif
1215
1216         // sleep(1);
1217         idle_state = 1000;
1218
1219         cout << "Panel visible = " << fgPanelVisible() << endl;
1220         fgReshape( fgGetInt("/sim/startup/xsize"),
1221                    fgGetInt("/sim/startup/ysize") );
1222     } 
1223
1224     if ( idle_state == 1000 ) {
1225         // We've finished all our initialization steps, from now on we
1226         // run the main loop.
1227
1228         fgMainLoop();
1229     } else {
1230         if ( fgGetBool("/sim/startup/splash-screen") ) {
1231             fgSplashUpdate(0.0);
1232         }
1233     }
1234 }
1235
1236 // options.cxx needs to see this for toggle_panel()
1237 // Handle new window size or exposure
1238 void fgReshape( int width, int height ) {
1239     // for all views
1240     for ( int i = 0; i < globals->get_viewmgr()->size(); ++i ) {
1241         if ( ! fgPanelVisible() || idle_state != 1000 ) {
1242             globals->get_viewmgr()->get_view(i)->
1243                 set_win_ratio( (float)height / (float)width );
1244         } else {
1245             int view_h =
1246                 int((current_panel->getViewHeight() -
1247                      current_panel->getYOffset())
1248                     * (height / 768.0)) + 1;
1249             globals->get_viewmgr()->get_view(i)->
1250                 set_win_ratio( (float)view_h / (float)width );
1251         }
1252     }
1253
1254     if ( ! fgPanelVisible() || idle_state != 1000 ) {
1255         glViewport(0, 0 , (GLint)(width), (GLint)(height) );
1256     } else {
1257         int view_h =
1258             int((current_panel->getViewHeight() - current_panel->getYOffset())
1259                 * (height / 768.0)) + 1;
1260         glViewport(0, (GLint)(height - view_h),
1261                    (GLint)(width), (GLint)(view_h) );
1262     }
1263
1264     fgSetInt("/sim/startup/xsize", width);
1265     fgSetInt("/sim/startup/ysize", height);
1266
1267     float fov = globals->get_current_view()->get_fov();
1268     ssgSetFOV(fov, fov * globals->get_current_view()->get_win_ratio());
1269
1270     fgHUDReshape();
1271 }
1272
1273
1274 // Initialize GLUT and define a main window
1275 int fgGlutInit( int *argc, char **argv ) {
1276
1277 #if !defined( macintosh )
1278     // GLUT will extract all glut specific options so later on we only
1279     // need wory about our own.
1280     glutInit(argc, argv);
1281 #endif
1282
1283     // Define Display Parameters
1284     glutInitDisplayMode( GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE );
1285
1286     SG_LOG( SG_GENERAL, SG_INFO, "Opening a window: " <<
1287             fgGetInt("/sim/startup/xsize") << "x"
1288             << fgGetInt("/sim/startup/ysize") );
1289
1290     // Define initial window size
1291     glutInitWindowSize( fgGetInt("/sim/startup/xsize"),
1292                         fgGetInt("/sim/startup/ysize") );
1293
1294     // Initialize windows
1295     if ( !fgGetBool("/sim/startup/game-mode")) {
1296         // Open the regular window
1297         glutCreateWindow("FlightGear");
1298 #ifndef GLUT_WRONG_VERSION
1299     } else {
1300         // Open the cool new 'game mode' window
1301         char game_mode_str[256];
1302         sprintf( game_mode_str, "width=%d height=%d bpp=%d",
1303                  fgGetInt("/sim/startup/xsize"),
1304                  fgGetInt("/sim/startup/ysize"),
1305                  fgGetInt("/sim/rendering/bits-per-pixel"));
1306
1307         SG_LOG( SG_GENERAL, SG_INFO, 
1308                 "game mode params = " << game_mode_str );
1309         glutGameModeString( game_mode_str );
1310         glutEnterGameMode();
1311 #endif
1312     }
1313
1314     // This seems to be the absolute earliest in the init sequence
1315     // that these calls will return valid info.  Too bad it's after
1316     // we've already created and sized out window. :-(
1317     general.set_glVendor( (char *)glGetString ( GL_VENDOR ) );
1318     general.set_glRenderer( (char *)glGetString ( GL_RENDERER ) );
1319     general.set_glVersion( (char *)glGetString ( GL_VERSION ) );
1320     SG_LOG( SG_GENERAL, SG_INFO, general.get_glRenderer() );
1321
1322     GLint tmp;
1323     glGetIntegerv( GL_MAX_TEXTURE_SIZE, &tmp );
1324     general.set_glMaxTexSize( tmp );
1325     SG_LOG ( SG_GENERAL, SG_INFO, "Max texture size = " << tmp );
1326
1327     glGetIntegerv( GL_DEPTH_BITS, &tmp );
1328     general.set_glDepthBits( tmp );
1329     SG_LOG ( SG_GENERAL, SG_INFO, "Depth buffer bits = " << tmp );
1330
1331     return 1;
1332 }
1333
1334
1335 // Initialize GLUT event handlers
1336 int fgGlutInitEvents( void ) {
1337     // call fgReshape() on window resizes
1338     glutReshapeFunc( fgReshape );
1339
1340     // call GLUTkey() on keyboard event
1341     glutKeyboardFunc( GLUTkey );
1342     glutSpecialFunc( GLUTspecialkey );
1343
1344     // call guiMouseFunc() whenever our little rodent is used
1345     glutMouseFunc ( guiMouseFunc );
1346     glutMotionFunc (guiMotionFunc );
1347     glutPassiveMotionFunc (guiMotionFunc );
1348
1349     // call fgMainLoop() whenever there is
1350     // nothing else to do
1351     glutIdleFunc( fgIdleFunction );
1352
1353     // draw the scene
1354     glutDisplayFunc( fgRenderFrame );
1355
1356     return(1);
1357 }
1358
1359
1360 // Main ...
1361 int main( int argc, char **argv ) {
1362
1363 #if defined( macintosh )
1364     freopen ("stdout.txt", "w", stdout );
1365     freopen ("stderr.txt", "w", stderr );
1366     argc = ccommand( &argv );
1367 #endif
1368
1369 #ifdef HAVE_BC5PLUS
1370     _control87(MCW_EM, MCW_EM);  /* defined in float.h */
1371 #endif
1372
1373     // set default log levels
1374     sglog().setLogLevels( SG_ALL, SG_INFO );
1375
1376     string version;
1377 #ifdef FLIGHTGEAR_VERSION
1378     version = FLIGHTGEAR_VERSION;
1379 #else
1380     version = "unknown version";
1381 #endif
1382     SG_LOG( SG_GENERAL, SG_INFO, "FlightGear:  Version "
1383             << version << endl );
1384
1385     // Allocate global data structures.  This needs to happen before
1386     // we parse command line options
1387
1388     SGPropertyNode *props = new SGPropertyNode;
1389     globals = new FGGlobals;
1390     globals->set_props( props );
1391
1392     // seed the random number generater
1393     sg_srandom_time();
1394
1395     SGRoute *route = new SGRoute;
1396     globals->set_route( route );
1397
1398 #ifdef ENABLE_AUDIO_SUPPORT
1399     FGSoundMgr *soundmgr = new FGSoundMgr;
1400     globals->set_soundmgr( soundmgr );
1401 #endif
1402
1403     FGViewMgr *viewmgr = new FGViewMgr;
1404     globals->set_viewmgr( viewmgr );
1405
1406     FGViewerRPH *pv = new FGViewerRPH;
1407     globals->get_viewmgr()->add_view( pv );
1408
1409     FGViewerLookAt *chase = new FGViewerLookAt;
1410     globals->get_viewmgr()->add_view( chase );
1411
1412     string_list *col = new string_list;
1413     globals->set_channel_options_list( col );
1414
1415     // set current view to 0 (first) which is our main pilot view
1416     globals->set_current_view( globals->get_viewmgr()->get_view( 0 ) );
1417
1418     // Scan the config file(s) and command line options to see if
1419     // fg_root was specified (ignore all other options for now)
1420     fgInitFGRoot(argc, argv);
1421
1422     // Initialize the Aircraft directory to "" (UIUC)
1423     aircraft_dir = "";
1424
1425     // Load the configuration parameters
1426     if ( !fgInitConfig(argc, argv) ) {
1427         SG_LOG( SG_GENERAL, SG_ALERT, "Config option parsing failed ..." );
1428         exit(-1);
1429     }
1430
1431     // Initialize the Window/Graphics environment.
1432     if( !fgGlutInit(&argc, argv) ) {
1433         SG_LOG( SG_GENERAL, SG_ALERT, "GLUT initialization failed ..." );
1434         exit(-1);
1435     }
1436
1437     // Initialize the various GLUT Event Handlers.
1438     if( !fgGlutInitEvents() ) {
1439         SG_LOG( SG_GENERAL, SG_ALERT, 
1440                 "GLUT event handler initialization failed ..." );
1441         exit(-1);
1442     }
1443  
1444     // Initialize ssg (from plib).  Needs to come before we do any
1445     // other ssg stuff, but after opengl/glut has been initialized.
1446     ssgInit();
1447
1448     // Initialize the user interface (we need to do this before
1449     // passing off control to glut and before fgInitGeneral to get our
1450     // fonts !!!
1451     guiInit();
1452
1453     // set current_options lon/lat if an airport id is specified
1454     // cout << "3. airport_id = " << fgGetString("/sim/startup/airport-id") << endl;
1455     if ( fgGetString("/sim/startup/airport-id").length() ) {
1456         // fgSetPosFromAirportID( fgGetString("/sim/startup/airport-id") );
1457         fgSetPosFromAirportIDandHdg( fgGetString("/sim/startup/airport-id"),
1458                                      fgGetDouble("/orientation/heading") );
1459     }
1460
1461     // Initialize time
1462     SGPath zone( globals->get_fg_root() );
1463     zone.append( "Timezone" );
1464     SGTime *t = new SGTime( fgGetDouble("/position/longitude") * SGD_DEGREES_TO_RADIANS,
1465                             fgGetDouble("/position/latitude") * SGD_DEGREES_TO_RADIANS,
1466                             zone.str() );
1467
1468     // Handle potential user specified time offsets
1469     time_t cur_time = t->get_cur_time();
1470     time_t currGMT = sgTimeGetGMT( gmtime(&cur_time) );
1471     time_t systemLocalTime = sgTimeGetGMT( localtime(&cur_time) );
1472     time_t aircraftLocalTime = 
1473         sgTimeGetGMT( fgLocaltime(&cur_time, t->get_zonename() ) );
1474
1475     // Okay, we now have six possible scenarios
1476     int offset = fgGetInt("/sim/startup/time-offset");
1477     const string &offset_type = fgGetString("/sim/startup/time-offset-type");
1478     if (offset_type == "system-offset") {
1479         globals->set_warp( offset );
1480     } else if (offset_type == "gmt-offset") {
1481         globals->set_warp( offset - (currGMT - systemLocalTime) );
1482     } else if (offset_type == "latitude-offset") {
1483         globals->set_warp( offset - (aircraftLocalTime - systemLocalTime) );
1484     } else if (offset_type == "system") {
1485         globals->set_warp( offset - cur_time );
1486     } else if (offset_type == "gmt") {
1487         globals->set_warp( offset - currGMT );
1488     } else if (offset_type == "latitude") {
1489         globals->set_warp( offset - (aircraftLocalTime - systemLocalTime) - 
1490                            cur_time ); 
1491     } else {
1492         SG_LOG( SG_GENERAL, SG_ALERT,
1493                 "Unsupported offset type " << offset_type );
1494         exit( -1 );
1495     }
1496
1497     SG_LOG( SG_GENERAL, SG_INFO, "After time init, warp = " 
1498             << globals->get_warp() );
1499
1500     globals->set_warp_delta( 0 );
1501
1502     t->update( 0.0, 0.0, globals->get_warp() );
1503
1504     globals->set_time_params( t );
1505
1506     // Do some quick general initializations
1507     if( !fgInitGeneral()) {
1508         SG_LOG( SG_GENERAL, SG_ALERT, 
1509                 "General initializations failed ..." );
1510         exit(-1);
1511     }
1512
1513     SGPath modelpath( globals->get_fg_root() );
1514     ssgModelPath( (char *)modelpath.c_str() );
1515   
1516     // Scene graph root
1517     scene = new ssgRoot;
1518     scene->setName( "Scene" );
1519
1520     lighting = new ssgRoot;
1521     lighting->setName( "Lighting" );
1522
1523     // Initialize the sky
1524     SGPath ephem_data_path( globals->get_fg_root() );
1525     ephem_data_path.append( "Astro" );
1526     SGEphemeris *ephem = new SGEphemeris( ephem_data_path.c_str() );
1527     ephem->update( globals->get_time_params()->getMjd(),
1528                    globals->get_time_params()->getLst(),
1529                    0.0 );
1530     globals->set_ephem( ephem );
1531
1532     thesky = new SGSky;
1533
1534     SGPath sky_tex_path( globals->get_fg_root() );
1535     sky_tex_path.append( "Textures" );
1536     sky_tex_path.append( "Sky" );
1537     thesky->texture_path( sky_tex_path.str() );
1538
1539     thesky->build( 550.0, 550.0,
1540                    globals->get_ephem()->getNumPlanets(), 
1541                    globals->get_ephem()->getPlanets(), 60000.0,
1542                    globals->get_ephem()->getNumStars(),
1543                    globals->get_ephem()->getStars(), 60000.0 );
1544
1545     if ( fgGetBool("/environment/clouds/status") ) {
1546         thesky->add_cloud_layer( 2000.0, 200.0, 50.0, 40000.0,
1547                                  SG_CLOUD_OVERCAST );
1548         thesky->add_cloud_layer( 2600.0, 200.0, 50.0, 40000.0,
1549                                  SG_CLOUD_MOSTLY_CLOUDY );
1550         thesky->add_cloud_layer( 3000.0, 200.0, 50.0, 40000.0,
1551                                  SG_CLOUD_MOSTLY_SUNNY );
1552         thesky->add_cloud_layer( 6000.0, 20.0, 10.0, 40000.0,
1553                                  SG_CLOUD_CIRRUS );
1554     }
1555
1556     // Initialize MagVar model
1557     SGMagVar *magvar = new SGMagVar();
1558     globals->set_mag( magvar );
1559
1560     // Terrain branch
1561     terrain = new ssgBranch;
1562     terrain->setName( "Terrain" );
1563     scene->addKid( terrain );
1564
1565     // Lighting
1566     ground = new ssgBranch;
1567     ground->setName( "Ground Lighting" );
1568     lighting->addKid( ground );
1569
1570     airport = new ssgBranch;
1571     airport->setName( "Airport Lighting" );
1572     lighting->addKid( airport );
1573
1574     // temporary visible aircraft "own ship"
1575     acmodel_selector = new ssgSelector;
1576     acmodel_pos = new ssgTransform;
1577
1578     // Get the model location, and load textures from the same
1579     // directory.  Use an absolute path for the model to avoid
1580     // incompatibilities in different versions of PLIB.
1581     string acmodel_path =
1582         fgGetString("/sim/model/path", "Models/Geometry/glider.ac");
1583     SGPath full_model = globals->get_fg_root();
1584     full_model.append(acmodel_path);
1585
1586 #if !defined( PLIB_1_2_X )
1587     // this should be redundant ... but it breaks for relative paths
1588     // w/ plib-1.2.0
1589     ssgModelPath( (char *)full_model.dir().c_str() );
1590 #endif
1591
1592     ssgTexturePath( (char *)full_model.dir().c_str() );
1593     ssgEntity *acmodel_obj = ssgLoad( (char *)full_model.c_str() );
1594     if( !acmodel_obj ) {
1595         // fall back to default
1596         acmodel_obj = ssgLoad( (char *)"glider.ac" );
1597         if( !acmodel_obj ) {
1598             SG_LOG( SG_GENERAL, SG_ALERT, "FAILED to LOAD an AC model! ..." );
1599             exit(-1);
1600         }
1601     }
1602
1603     // find moving parts (if this is an MDL model)
1604     flaps_selector = (ssgSelector*)fgFindNode( acmodel_obj, "FLAPS" );
1605     prop_selector  = (ssgSelector*)fgFindNode( acmodel_obj, "PROP"  );
1606
1607     acmodel_npropsettings = 0;
1608     if (prop_selector != NULL) {
1609       for (ssgEntity* kid = prop_selector->getKid(0); kid != NULL;
1610            kid = prop_selector->getNextKid()) {
1611         int prop_low, prop_high;
1612         if ( sscanf(kid->getName(), "PROP_%d_%d", 
1613                     &prop_low, &prop_high) == 2 ) {
1614           prop_low  = (int)((float)prop_low  * (5000.0f / 32767.0f));
1615           prop_high = (int)((float)prop_high * (5000.0f / 32767.0f));
1616           acmodel_proprpms[acmodel_npropsettings][0] = prop_low ;
1617           acmodel_proprpms[acmodel_npropsettings][1] = prop_high;
1618           acmodel_npropsettings++;
1619
1620           SG_LOG( SG_GENERAL, SG_INFO, "PROPELLER SETTING " << prop_low <<
1621                   " " << prop_high );
1622         }
1623       }
1624     }
1625
1626     // align the model properly for FGFS
1627     ssgTransform *acmodel_align = new ssgTransform;
1628     acmodel_align->addKid(acmodel_obj);
1629     sgMat4 rot_matrix;
1630     sgMat4 off_matrix;
1631     sgMat4 res_matrix;
1632     float h_rot = fgGetFloat("/sim/model/h-rotation", 0.0);
1633     float p_rot = fgGetFloat("/sim/model/p-rotation", 0.0);
1634     float r_rot = fgGetFloat("/sim/model/r-rotation", 0.0);
1635     float x_off = fgGetFloat("/sim/model/x-offset", 0.0);
1636     float y_off = fgGetFloat("/sim/model/y-offset", 0.0);
1637     float z_off = fgGetFloat("/sim/model/z-offset", 0.0);
1638     sgMakeRotMat4(rot_matrix, h_rot, p_rot, r_rot);
1639     sgMakeTransMat4(off_matrix, x_off, y_off, z_off);
1640     sgMultMat4(res_matrix, off_matrix, rot_matrix);
1641     acmodel_align->setTransform(res_matrix);
1642
1643     acmodel_pos->addKid( acmodel_align );
1644     acmodel_selector->addKid( acmodel_pos );
1645     //ssgFlatten( acmodel_obj );
1646     //ssgStripify( acmodel_selector );
1647     acmodel_selector->clrTraversalMaskBits( SSGTRAV_HOT );
1648     scene->addKid( acmodel_selector );
1649
1650     // $$$ begin - added VS Renganthan 17 Oct 2K
1651     fgLoadDCS();
1652     // $$$ end - added VS Renganthan 17 Oct 2K
1653
1654 #ifdef FG_NETWORK_OLK
1655     // Do the network intialization
1656     if ( fgGetBool("/sim/networking/network-olk") ) {
1657         printf("Multipilot mode %s\n", fg_net_init( scene ) );
1658     }
1659 #endif
1660
1661     // build our custom render states
1662     fgBuildRenderStates();
1663
1664     // pass control off to the master GLUT event handler
1665     glutMainLoop();
1666
1667     // we never actually get here ... but to avoid compiler warnings,
1668     // etc.
1669     return 0;
1670 }
1671
1672
1673 // $$$ end - added VS Renganathan, 15 Oct 2K
1674 //         - added Venky         , 12 Nov 2K
1675
1676 void fgLoadDCS(void) {
1677
1678     ssgEntity *ship_obj = NULL;
1679     // double bz[3];
1680     // int j=0;
1681     char obj_filename[25];
1682
1683     for ( int k = 0; k < 32; k++ ) {
1684         ship_pos[k]=NULL;
1685     }
1686
1687     SGPath tile_path( globals->get_fg_root());
1688     tile_path.append( "Scenery" );
1689     tile_path.append( "Objects.txt" );
1690     sg_gzifstream in( tile_path.str() );
1691     if ( ! in.is_open() ) {
1692         SG_LOG( SG_TERRAIN, SG_ALERT, "Cannot open file: " << tile_path.str() );
1693     } else {
1694
1695         SGPath modelpath( globals->get_fg_root() );
1696         modelpath.append( "Models" );
1697         modelpath.append( "Geometry" );
1698   
1699         SGPath texturepath( globals->get_fg_root() );
1700         texturepath.append( "Models" );
1701         texturepath.append( "Textures" );
1702  
1703         ssgModelPath( (char *)modelpath.c_str() );
1704         ssgTexturePath( (char *)texturepath.c_str() );
1705
1706         ship_sel = new ssgSelector;
1707
1708         char c;
1709         while ( ! in.eof() ) {
1710             in >> ::skipws;
1711             if ( in.get( c ) && c == '#' ) { 
1712                 in >> skipeol;
1713             } else { 
1714                 in.putback(c);
1715                 in >> obj_filename >> obj_lat[objc] >> obj_lon[objc] >> obj_alt[objc];
1716                 /* cout << endl << obj_filename << " " << obj_lat[objc] << " " << obj_lon[objc] <<  " " << obj_alt[objc] << endl;
1717                    int chj=getchar();*/
1718                 
1719                 obj_lon[objc] *=SGD_DEGREES_TO_RADIANS;
1720                 obj_lat[objc] *=SGD_DEGREES_TO_RADIANS;
1721                 
1722                 ship_pos[objc] = new ssgTransform;
1723        
1724                 // type "repeat" in objects.txt to load one more
1725                 // instance of the last object.
1726
1727                 if ( strcmp(obj_filename,"repeat") != 0) {
1728                     ship_obj = ssgLoadOBJ( obj_filename );
1729                 }
1730       
1731                 if ( ship_obj != NULL ) {
1732                     ship_pos[objc]->addKid( ship_obj ); // add object to transform node
1733                     ship_sel->addKid( ship_pos[objc] ); // add transform node to selector
1734                 } else {
1735                     SG_LOG( SG_TERRAIN, SG_ALERT, "Cannot open file: "
1736                             << obj_filename );
1737                 }
1738             
1739                 objc++;
1740
1741                 if (in.eof()) break;
1742             }
1743         } // while
1744
1745         SG_LOG ( SG_TERRAIN, SG_ALERT, "Finished object processing." );
1746
1747         ship_sel->clrTraversalMaskBits( SSGTRAV_HOT );
1748         scene->addKid( ship_sel ); //add selector node to root node 
1749     }
1750
1751     return;
1752  }
1753
1754
1755 void fgUpdateDCS (void) {
1756
1757     // double eye_lat,eye_lon,eye_alt;
1758     // static double obj_head;
1759     double sl_radius,obj_latgc;
1760     // float nresultmat[4][4];
1761     // sgMat4 Trans,rothead,rotlon,rot180,rotlat,resultmat1,resultmat2,resultmat3;
1762     double bz[3];
1763
1764     // Instantaneous Geodetic Lat/Lon/Alt of moving object
1765     FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
1766     
1767     // Deck should be the first object in objects.txt in case of fdm=ada
1768
1769     if (fgGetString("/sim/flight-model") == "ada") {
1770         obj_lon[0] = fdm->get_aux5()*SGD_DEGREES_TO_RADIANS;
1771         obj_lat[0] = fdm->get_aux6()*SGD_DEGREES_TO_RADIANS;
1772         obj_alt[0] = fdm->get_aux7();
1773     }
1774     
1775     for ( int m = 0; m < objc; m++ ) {
1776         //cout << endl <<  obj_lat[m]*SGD_RADIANS_TO_DEGREES << " " << obj_lon[m]*SGD_RADIANS_TO_DEGREES << " " << obj_alt[m] << " " << objc << endl;
1777         //int v=getchar();
1778
1779         //Geodetic to Geocentric angles for rotation
1780         sgGeodToGeoc(obj_lat[m],obj_alt[m],&sl_radius,&obj_latgc);
1781
1782         //moving object gbs-posn in cartesian coords
1783         Point3D obj_posn = Point3D( obj_lon[m],obj_lat[m],obj_alt[m]);
1784         Point3D obj_pos = sgGeodToCart( obj_posn );
1785
1786         // Translate moving object w.r.t eye
1787         Point3D Objtrans = obj_pos-scenery.center;
1788         bz[0]=Objtrans.x();
1789         bz[1]=Objtrans.y();
1790         bz[2]=Objtrans.z();
1791
1792        // rotate dynamic objects for lat,lon & alt and other motion about its axes
1793         
1794         sgMat4 sgTRANS;
1795         sgMakeTransMat4( sgTRANS, bz[0],bz[1],bz[2]);
1796
1797         sgVec3 ship_fwd,ship_rt,ship_up;
1798         sgSetVec3( ship_fwd, 1.0, 0.0, 0.0);//east,roll
1799         sgSetVec3( ship_rt, 0.0, 1.0, 0.0);//up,pitch
1800         sgSetVec3( ship_up, 0.0, 0.0, 1.0); //north,yaw
1801
1802         sgMat4 sgROT_lon, sgROT_lat, sgROT_hdg;
1803         sgMakeRotMat4( sgROT_lon, obj_lon[m]*SGD_RADIANS_TO_DEGREES, ship_up );
1804         sgMakeRotMat4( sgROT_lat, 90-obj_latgc*SGD_RADIANS_TO_DEGREES, ship_rt );
1805         sgMakeRotMat4( sgROT_hdg, 180.0, ship_up );
1806         
1807         sgMat4 sgTUX;
1808         sgCopyMat4( sgTUX, sgROT_hdg );
1809         sgPostMultMat4( sgTUX, sgROT_lat );
1810         sgPostMultMat4( sgTUX, sgROT_lon );
1811         sgPostMultMat4( sgTUX, sgTRANS );
1812
1813         sgCoord shippos;
1814         sgSetCoord(&shippos, sgTUX );
1815         ship_pos[m]->setTransform( &shippos );
1816     }
1817     if ( ship_sel != NULL ) {
1818         ship_sel->select(0xFFFFFFFF);
1819     }
1820 }
1821
1822 // $$$ end - added VS Renganathan, 15 Oct 2K
1823 //           added Venky         , 12 Nov 2K