]> git.mxchange.org Git - flightgear.git/commitdiff
Bernie Bright:
authorcurt <curt>
Sun, 25 Aug 2002 20:56:16 +0000 (20:56 +0000)
committercurt <curt>
Sun, 25 Aug 2002 20:56:16 +0000 (20:56 +0000)
Here is a FGIO class derived from FGSubsystem that replaces the fgIOInit()
and fgIOProcess() functions.  The FGIO::update(double delta) doesn't use the
delta argument yet.  I suspect it could be used as a replacement for the
calculated interval value but I'm not familiar enough with that piece of code
just yet.

I've also added two "command properties" to fg_commands.cxx that select the
next or previous view.  Writing any value to these properties triggers the
corresponding action.  As an example I modified my keyboard.xml:

 <key n="118">
  <name>v</name>
  <desc>Next view</desc>
  <binding>
   <command>property-assign</command>
   <property>/command/view/next</property>
   <value type="bool">true</value>
  </binding>
 </key>

 <key n="86">
  <name>V</name>
  <desc>Prev view</desc>
  <binding>
   <command>property-assign</command>
   <property>/command/view/prev</property>
   <value type="bool">true</value>
  </binding>
 </key>

And of course these actions can also be triggered from external scripts via
the props server.

src/GUI/gui_funcs.cxx
src/Main/fg_commands.cxx
src/Main/fg_init.cxx
src/Main/fg_io.cxx
src/Main/fg_io.hxx
src/Main/globals.cxx
src/Main/globals.hxx
src/Main/main.cxx

index c3a05ed65a1c416d5c4e3cf1a5180753f8180d83..6640b1f709449469f91b1e3e158759c0760cf670 100644 (file)
@@ -387,7 +387,7 @@ void goodBye(puObject *)
 #endif
 
     // close all external I/O connections
-    fgIOShutdownAll();
+    globals->get_io()->shutdown_all();
 
     exit(0);
 }
index f834ee7b003aa8082e185227a8aeecd43b58fe70..e616571fd7d39f639d72952e269fe13e3a5fa231 100644 (file)
@@ -261,6 +261,35 @@ do_preferences_load (const SGPropertyNode * arg, SGCommandState ** state)
 }
 
 
+static void
+fix_hud_visibility()
+{
+  if ( !strcmp(fgGetString("/sim/flight-model"), "ada") ) {
+      globals->get_props()->setBoolValue( "/sim/hud/visibility", true );
+      if ( globals->get_viewmgr()->get_current() == 1 ) {
+          globals->get_props()->setBoolValue( "/sim/hud/visibility", false );
+      }
+  }
+}
+
+void
+do_view_next( bool )
+{
+    globals->get_current_view()->setHeadingOffset_deg(0.0);
+    globals->get_viewmgr()->next_view();
+    fix_hud_visibility();
+  global_tile_mgr.refresh_view_timestamps();
+}
+
+void
+do_view_prev( bool )
+{
+    globals->get_current_view()->setHeadingOffset_deg(0.0);
+    globals->get_viewmgr()->prev_view();
+    fix_hud_visibility();
+  global_tile_mgr.refresh_view_timestamps();
+}
+
 /**
  * Built-in command: cycle view.
  */
@@ -269,18 +298,12 @@ do_view_cycle (const SGPropertyNode * arg, SGCommandState ** state)
 {
   globals->get_current_view()->setHeadingOffset_deg(0.0);
   globals->get_viewmgr()->next_view();
-  if ( !strcmp(fgGetString("/sim/flight-model"), "ada") ) {
-      globals->get_props()->setBoolValue( "/sim/hud/visibility", true );
-      if ( globals->get_viewmgr()->get_current() == 1 ) {
-          globals->get_props()->setBoolValue( "/sim/hud/visibility", false );
-      }
-  }
+  fix_hud_visibility();
   global_tile_mgr.refresh_view_timestamps();
 //   fgReshape(fgGetInt("/sim/startup/xsize"), fgGetInt("/sim/startup/ysize"));
   return true;
 }
 
-
 /**
  * Built-in command: capture screen.
  */
@@ -665,6 +688,10 @@ fgInitCommands ()
     globals->get_commands()->addCommand(built_ins[i].name,
                                        built_ins[i].command);
   }
+
+  typedef bool (*dummy)();
+  fgTie( "/command/view/next", dummy(0), do_view_next );
+  fgTie( "/command/view/prev", dummy(0), do_view_prev );
 }
 
 // end of fg_commands.cxx
index 2a2c999989129035e9fa671e97235b43904a2c51..e816adaa6b3d397d91e0b31956c2867b6d8be594 100644 (file)
@@ -1029,9 +1029,8 @@ bool fgInitSubsystems( void ) {
     // Initialize I/O subsystem.
     ////////////////////////////////////////////////////////////////////
 
-#if ! defined( macintosh )
-    fgIOInit();
-#endif
+    globals->get_io()->init();
+    globals->get_io()->bind();
 
     // Initialize the 2D panel.
     string panel_path = fgGetString("/sim/panel/path",
index f2f7370ff595c1018184f7e9e063afef2a148f32..273e73fc5df966b5a97b307e7de284a42d73bfac 100644 (file)
 SG_USING_STD(string);
 
 
-// define the global I/O channel list
-io_container global_io_list;
+FGIO::FGIO()
+{
+}
+
+#include STL_ALGORITHM
+SG_USING_STD(for_each);
+
+static void delete_ptr( FGProtocol* p ) { delete p; }
+
+FGIO::~FGIO()
+{
+    shutdown_all();
+    for_each( io_channels.begin(), io_channels.end(), delete_ptr );
+}
 
 
 // configure a port based on the config string
-static FGProtocol *parse_port_config( const string& config )
+FGProtocol*
+FGIO::parse_port_config( const string& config )
 {
     SG_LOG( SG_IO, SG_INFO, "Parse I/O channel request: " << config );
 
@@ -197,12 +210,13 @@ static FGProtocol *parse_port_config( const string& config )
 
 // step through the port config streams (from fgOPTIONS) and setup
 // serial port channels for each
-void fgIOInit() {
+void
+FGIO::init()
+{
     // SG_LOG( SG_IO, SG_INFO, "I/O Channel initialization, " << 
     //         globals->get_channel_options_list()->size() << " requests." );
 
     FGProtocol *p;
-    string_list *channel_options_list = globals->get_channel_options_list();
 
     // we could almost do this in a single step except pushing a valid
     // port onto the port list copies the structure and destroys the
@@ -210,11 +224,14 @@ void fgIOInit() {
 
     // parse the configuration strings and store the results in the
     // appropriate FGIOChannel structures
-    for ( int i = 0; i < (int)channel_options_list->size(); ++i ) {
-       p = parse_port_config( (*channel_options_list)[i] );
+    vector< string >::iterator i = globals->get_channel_options_list()->begin();
+    vector< string >::iterator end = globals->get_channel_options_list()->end();
+    for (; i != end; ++i )
+    {
+       p = parse_port_config( *i );
        if ( p != NULL ) {
            p->open();
-           global_io_list.push_back( p );
+           io_channels.push_back( p );
            if ( !p->is_enabled() ) {
                SG_LOG( SG_IO, SG_ALERT, "I/O Channel config failed." );
                exit(-1);
@@ -227,7 +244,9 @@ void fgIOInit() {
 
 
 // process any serial port work
-void fgIOProcess() {
+void
+FGIO::update( double delta_time_sec )
+{
     // cout << "processing I/O channels" << endl;
 
     static int inited = 0;
@@ -245,9 +264,11 @@ void fgIOProcess() {
        last = current;
     }
 
-    for ( unsigned int i = 0; i < global_io_list.size(); ++i ) {
-       // cout << "  channel = " << i << endl;
-       FGProtocol* p = global_io_list[i];
+    vector< FGProtocol* >::iterator i = io_channels.begin();
+    vector< FGProtocol* >::iterator end = io_channels.end();
+    for (; i != end; ++i )
+    {
+       FGProtocol* p = *i;
 
        if ( p->is_enabled() ) {
            p->dec_count_down( interval );
@@ -260,18 +281,31 @@ void fgIOProcess() {
 }
 
 
-// shutdown all I/O connections
-void fgIOShutdownAll() {
+void
+FGIO::shutdown_all() {
     FGProtocol *p;
 
     // cout << "processing I/O channels" << endl;
 
-    for ( int i = 0; i < (int)global_io_list.size(); ++i ) {
-       // cout << "  channel = " << i << endl;
-       p = global_io_list[i];
+    vector< FGProtocol* >::iterator i = io_channels.begin();
+    vector< FGProtocol* >::iterator end = io_channels.end();
+    for (; i != end; ++i )
+    {
+       p = *i;
 
        if ( p->is_enabled() ) {
            p->close();
        }
     }
 }
+
+void
+FGIO::bind()
+{
+}
+
+void
+FGIO::unbind()
+{
+}
+
index 0550fdb022ad9ba8a376df584b5b099acd0fe6ed..3f81f94177cdc2e2cc97e862edae218a9a1dc2be 100644 (file)
 
 
 #include <simgear/compiler.h>
+#include <vector>
+#include STL_STRING
 
+#include "fgfs.hxx"
 
-// initialize I/O channels based on command line options (if any)
-void fgIOInit();
+SG_USING_STD(vector);
+SG_USING_STD(string);
 
+class FGProtocol;
 
-// process any I/O work
-void fgIOProcess();
+class FGIO : public FGSubsystem
+{
+public:
+    FGIO();
+    ~FGIO();
 
+    void init();
+    void bind();
+    void unbind();
+    void update( double dt );
 
-// shutdown all I/O connections
-void fgIOShutdownAll();
+    void shutdown_all();
+
+private:
+
+    FGProtocol* parse_port_config( const string& cfgstr );
+
+private:
+
+    // define the global I/O channel list
+    //io_container global_io_list;
+    vector< FGProtocol* > io_channels;
+};
 
 
 #endif // _FG_IO_HXX
index 125bfc39b1a631e563bedc5c63e2beaf30194338..6d1a7bf340a80f22870f444cdc88fc61798e742c 100644 (file)
@@ -29,7 +29,7 @@
 #include "viewmgr.hxx"
 
 #include "fg_props.hxx"
-
+#include "fg_io.hxx"
 
 \f
 ////////////////////////////////////////////////////////////////////////
@@ -51,7 +51,8 @@ FGGlobals::FGGlobals() :
     logger(0),
     props(new SGPropertyNode),
     initial_state(0),
-    commands(new SGCommandMgr)
+    commands(new SGCommandMgr),
+    io(new FGIO)
 {
 }
 
@@ -62,6 +63,7 @@ FGGlobals::~FGGlobals()
   delete initial_state;
   delete props;
   delete commands;
+  delete io;
 }
 
 
index 50123defc1a7acda5f1c6b37f3c6d508b4852411..605a52b86c28b67b1bc3bf241340079919a1ea4f 100644 (file)
@@ -46,6 +46,7 @@ typedef vector<string> string_list;
 // anyway.
 
 class SGEphemeris;
+
 class SGMagVar;
 class SGRoute;
 class SGTime;
@@ -70,7 +71,7 @@ class FGTextureLoader;
 class FGAircraftModel;
 class FGModelMgr;
 class FGScenery;
-
+class FGIO;
 
 /**
  * Bucket for subsystem pointers representing the sim's state.
@@ -172,6 +173,8 @@ private:
     // FlightGear scenery manager
     FGScenery *scenery;
 
+    FGIO* io;
+
 public:
 
     FGGlobals();
@@ -298,6 +301,8 @@ public:
     inline FGScenery * get_scenery () const { return scenery; }
     inline void set_scenery ( FGScenery *s ) { scenery = s; }
 
+    FGIO* get_io() const { return io; }
+
     /**
      * Save the current state as the initial state.
      */
index a28675965a4479d09e6dbe5a3a2dc5d71902fe86..52a488382549abc97d748cdbf9dfdefb00f601b4 100644 (file)
@@ -89,7 +89,8 @@ SG_USING_STD(endl);
 
 #include <ATC/ATCmgr.hxx>
 #include <ATC/ATCdisplay.hxx>
-#include <ATC/AIMgr.hxx>
+//#include <ATC/AIMgr.hxx>
+
 
 #include <Autopilot/newauto.hxx>
 
@@ -1071,10 +1072,8 @@ static void fgMainLoop( void ) {
                "Elapsed time is zero ... we're zinging" );
     }
 
-#if ! defined( macintosh )
     // Do any I/O channel work that might need to be done
-    fgIOProcess();
-#endif
+    globals->get_io()->update( delta_time_sec );
 
     // see if we need to load any deferred-load textures
     material_lib.load_next_deferred();