From df6989a37ac7d864f540d874067d7157446ab6a7 Mon Sep 17 00:00:00 2001 From: curt Date: Sun, 25 Aug 2002 20:56:16 +0000 Subject: [PATCH] Bernie Bright: 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: v Next view property-assign /command/view/next true V Prev view property-assign /command/view/prev true And of course these actions can also be triggered from external scripts via the props server. --- src/GUI/gui_funcs.cxx | 2 +- src/Main/fg_commands.cxx | 41 +++++++++++++++++++----- src/Main/fg_init.cxx | 5 ++- src/Main/fg_io.cxx | 68 ++++++++++++++++++++++++++++++---------- src/Main/fg_io.hxx | 33 +++++++++++++++---- src/Main/globals.cxx | 6 ++-- src/Main/globals.hxx | 7 ++++- src/Main/main.cxx | 7 ++--- 8 files changed, 128 insertions(+), 41 deletions(-) diff --git a/src/GUI/gui_funcs.cxx b/src/GUI/gui_funcs.cxx index c3a05ed65..6640b1f70 100644 --- a/src/GUI/gui_funcs.cxx +++ b/src/GUI/gui_funcs.cxx @@ -387,7 +387,7 @@ void goodBye(puObject *) #endif // close all external I/O connections - fgIOShutdownAll(); + globals->get_io()->shutdown_all(); exit(0); } diff --git a/src/Main/fg_commands.cxx b/src/Main/fg_commands.cxx index f834ee7b0..e616571fd 100644 --- a/src/Main/fg_commands.cxx +++ b/src/Main/fg_commands.cxx @@ -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 diff --git a/src/Main/fg_init.cxx b/src/Main/fg_init.cxx index 2a2c99998..e816adaa6 100644 --- a/src/Main/fg_init.cxx +++ b/src/Main/fg_init.cxx @@ -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", diff --git a/src/Main/fg_io.cxx b/src/Main/fg_io.cxx index f2f7370ff..273e73fc5 100644 --- a/src/Main/fg_io.cxx +++ b/src/Main/fg_io.cxx @@ -62,12 +62,25 @@ 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() +{ +} + diff --git a/src/Main/fg_io.hxx b/src/Main/fg_io.hxx index 0550fdb02..3f81f9417 100644 --- a/src/Main/fg_io.hxx +++ b/src/Main/fg_io.hxx @@ -26,18 +26,39 @@ #include +#include +#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 diff --git a/src/Main/globals.cxx b/src/Main/globals.cxx index 125bfc39b..6d1a7bf34 100644 --- a/src/Main/globals.cxx +++ b/src/Main/globals.cxx @@ -29,7 +29,7 @@ #include "viewmgr.hxx" #include "fg_props.hxx" - +#include "fg_io.hxx" //////////////////////////////////////////////////////////////////////// @@ -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; } diff --git a/src/Main/globals.hxx b/src/Main/globals.hxx index 50123defc..605a52b86 100644 --- a/src/Main/globals.hxx +++ b/src/Main/globals.hxx @@ -46,6 +46,7 @@ typedef vector 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. */ diff --git a/src/Main/main.cxx b/src/Main/main.cxx index a28675965..52a488382 100644 --- a/src/Main/main.cxx +++ b/src/Main/main.cxx @@ -89,7 +89,8 @@ SG_USING_STD(endl); #include #include -#include +//#include + #include @@ -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(); -- 2.39.5