#endif
// close all external I/O connections
- fgIOShutdownAll();
+ globals->get_io()->shutdown_all();
exit(0);
}
}
+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.
*/
{
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.
*/
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
// 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",
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 );
// 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
// 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);
// process any serial port work
-void fgIOProcess() {
+void
+FGIO::update( double delta_time_sec )
+{
// cout << "processing I/O channels" << endl;
static int inited = 0;
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 );
}
-// 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()
+{
+}
+
#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
#include "viewmgr.hxx"
#include "fg_props.hxx"
-
+#include "fg_io.hxx"
\f
////////////////////////////////////////////////////////////////////////
logger(0),
props(new SGPropertyNode),
initial_state(0),
- commands(new SGCommandMgr)
+ commands(new SGCommandMgr),
+ io(new FGIO)
{
}
delete initial_state;
delete props;
delete commands;
+ delete io;
}
// anyway.
class SGEphemeris;
+
class SGMagVar;
class SGRoute;
class SGTime;
class FGAircraftModel;
class FGModelMgr;
class FGScenery;
-
+class FGIO;
/**
* Bucket for subsystem pointers representing the sim's state.
// FlightGear scenery manager
FGScenery *scenery;
+ FGIO* io;
+
public:
FGGlobals();
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.
*/
#include <ATC/ATCmgr.hxx>
#include <ATC/ATCdisplay.hxx>
-#include <ATC/AIMgr.hxx>
+//#include <ATC/AIMgr.hxx>
+
#include <Autopilot/newauto.hxx>
"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();