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: <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.
This commit is contained in:
parent
4f00d9a959
commit
df6989a37a
8 changed files with 128 additions and 41 deletions
|
@ -387,7 +387,7 @@ void goodBye(puObject *)
|
|||
#endif
|
||||
|
||||
// close all external I/O connections
|
||||
fgIOShutdownAll();
|
||||
globals->get_io()->shutdown_all();
|
||||
|
||||
exit(0);
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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()
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -26,18 +26,39 @@
|
|||
|
||||
|
||||
#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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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.
|
||||
*/
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Add table
Reference in a new issue