** src/Cockpit/panel.cxx
- delete table in destructor ** src/FDM/flight.cxx - bind engine properties in FGInterface::bind, and publish properties for all engines rather than just engine 0 ** src/Main/fg_props.cxx - removed all engine properties; now bound in FGInterface::bind ** src/Sounds/fg_fx.cxx - support multiple engine and cranking sounds ** src/Sounds/fg_fx.hxx - support multiple engine and cranking sounds
This commit is contained in:
parent
4b4394774b
commit
e1ac99d5c9
5 changed files with 134 additions and 179 deletions
|
@ -520,6 +520,7 @@ FGPanelTransformation::FGPanelTransformation ()
|
|||
|
||||
FGPanelTransformation::~FGPanelTransformation ()
|
||||
{
|
||||
delete table;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -386,6 +386,36 @@ FGInterface::bind ()
|
|||
&FGInterface::get_Climb_Rate); // read-only
|
||||
fgTie("/velocities/side-slip-rad", this,
|
||||
&FGInterface::get_Beta); // read-only
|
||||
|
||||
// Powerplant
|
||||
for (int i = 0; i < get_num_engines(); i++) {
|
||||
char buf[64];
|
||||
|
||||
sprintf(buf, "/engines/engine[%d]/rpm", i);
|
||||
fgTie(buf, get_engine(i), &FGEngInterface::get_RPM);
|
||||
|
||||
sprintf(buf, "/engines/engine[%d]/egt-degf", i);
|
||||
fgTie(buf, get_engine(i), &FGEngInterface::get_EGT);
|
||||
|
||||
sprintf(buf, "/engines/engine[%d]/cht-degf", i);
|
||||
fgTie(buf, get_engine(i), &FGEngInterface::get_CHT);
|
||||
|
||||
sprintf(buf, "/engines/engine[%d]/oil-temperature-degf", i);
|
||||
fgTie(buf, get_engine(i), &FGEngInterface::get_Oil_Temp);
|
||||
|
||||
sprintf(buf, "/engines/engine[%d]/mp-osi", i);
|
||||
fgTie(buf, get_engine(i), &FGEngInterface::get_Manifold_Pressure);
|
||||
|
||||
sprintf(buf, "/engines/engine[%d]/fuel-flow-gph", i);
|
||||
fgTie(buf, get_engine(i), &FGEngInterface::get_Fuel_Flow);
|
||||
|
||||
sprintf(buf, "/engines/engine[%d]/running", i);
|
||||
fgTie(buf, get_engine(i), &FGEngInterface::get_Running_Flag);
|
||||
|
||||
sprintf(buf, "/engines/engine[%d]/cranking", i);
|
||||
fgTie(buf, get_engine(i), &FGEngInterface::get_Cranking_Flag);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -420,6 +450,25 @@ FGInterface::unbind ()
|
|||
fgUntie("/velocities/wBody-fps");
|
||||
fgUntie("/velocities/vertical-speed-fps");
|
||||
fgUntie("/velocities/side-slip-rad");
|
||||
for (int i = 0; i < get_num_engines(); i++) {
|
||||
char buf[64];
|
||||
sprintf(buf, "/engines/engine[%d]/rpm", i);
|
||||
fgUntie(buf);
|
||||
sprintf(buf, "/engines/engine[%d]/egt-degf", i);
|
||||
fgUntie(buf);
|
||||
sprintf(buf, "/engines/engine[%d]/cht-degf", i);
|
||||
fgUntie(buf);
|
||||
sprintf(buf, "/engines/engine[%d]/oil-temperature-degf", i);
|
||||
fgUntie(buf);
|
||||
sprintf(buf, "/engines/engine[%d]/mp-osi", i);
|
||||
fgUntie(buf);
|
||||
sprintf(buf, "/engines/engine[%d]/fuel-flow-gph", i);
|
||||
fgUntie(buf);
|
||||
sprintf(buf, "/engines/engine[%d]/running", i);
|
||||
fgUntie(buf);
|
||||
sprintf(buf, "/engines/engine[%d]/cranking", i);
|
||||
fgUntie(buf);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -528,112 +528,6 @@ getHeadingMag ()
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the current engine0 rpm
|
||||
*/
|
||||
static double
|
||||
getRPM ()
|
||||
{
|
||||
if ( current_aircraft.fdm_state->get_num_engines() > 0 ) {
|
||||
return current_aircraft.fdm_state->get_engine(0)->get_RPM();
|
||||
} else {
|
||||
return 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the current engine0 EGT.
|
||||
*/
|
||||
static double
|
||||
getEGT ()
|
||||
{
|
||||
if ( current_aircraft.fdm_state->get_num_engines() > 0 ) {
|
||||
return current_aircraft.fdm_state->get_engine(0)->get_EGT();
|
||||
} else {
|
||||
return 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the current engine0 CHT.
|
||||
*/
|
||||
static double
|
||||
getCHT ()
|
||||
{
|
||||
if ( current_aircraft.fdm_state->get_num_engines() > 0 ) {
|
||||
return current_aircraft.fdm_state->get_engine(0)->get_CHT();
|
||||
} else {
|
||||
return 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the current engine0 Oil Temp.
|
||||
*/
|
||||
static double
|
||||
getOilTemp ()
|
||||
{
|
||||
if ( current_aircraft.fdm_state->get_num_engines() > 0 ) {
|
||||
return current_aircraft.fdm_state->get_engine(0)->get_Oil_Temp();
|
||||
} else {
|
||||
return 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the current engine0 Manifold Pressure.
|
||||
*/
|
||||
static double
|
||||
getMP ()
|
||||
{
|
||||
if ( current_aircraft.fdm_state->get_num_engines() > 0 ) {
|
||||
return current_aircraft.fdm_state->get_engine(0)->get_Manifold_Pressure();
|
||||
} else {
|
||||
return 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the current engine0 fuel flow
|
||||
*/
|
||||
static double
|
||||
getFuelFlow ()
|
||||
{
|
||||
if ( current_aircraft.fdm_state->get_num_engines() > 0 ) {
|
||||
return current_aircraft.fdm_state->get_engine(0)->get_Fuel_Flow();
|
||||
} else {
|
||||
return 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the current engine0 running flag
|
||||
*/
|
||||
static bool
|
||||
getRunningFlag ()
|
||||
{
|
||||
if ( current_aircraft.fdm_state->get_num_engines() > 0 ) {
|
||||
return current_aircraft.fdm_state->get_engine(0)->get_Running_Flag();
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the current engine0 cranking flag
|
||||
*/
|
||||
static bool
|
||||
getCrankingFlag ()
|
||||
{
|
||||
if ( current_aircraft.fdm_state->get_num_engines() > 0 ) {
|
||||
return current_aircraft.fdm_state->get_engine(0)->get_Cranking_Flag();
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the fuel level in tank 1
|
||||
*/
|
||||
|
@ -1220,16 +1114,6 @@ fgInitProps ()
|
|||
// Orientation
|
||||
fgTie("/orientation/heading-magnetic-deg", getHeadingMag);
|
||||
|
||||
// Engine
|
||||
fgTie("/engines/engine[0]/rpm", getRPM);
|
||||
fgTie("/engines/engine[0]/egt-degf", getEGT);
|
||||
fgTie("/engines/engine[0]/cht-degf", getCHT);
|
||||
fgTie("/engines/engine[0]/oil-temperature-degf", getOilTemp);
|
||||
fgTie("/engines/engine[0]/mp-osi", getMP);
|
||||
fgTie("/engines/engine[0]/fuel-flow-gph", getFuelFlow);
|
||||
fgTie("/engines/engine[0]/running", getRunningFlag, setRunningFlag);
|
||||
fgTie("/engines/engine[0]/cranking", getCrankingFlag, setCrankingFlag);
|
||||
|
||||
//consumables
|
||||
fgTie("/consumables/fuel/tank[0]/level-gal_us",
|
||||
getTank1Fuel, setTank1Fuel, false);
|
||||
|
|
|
@ -27,30 +27,44 @@
|
|||
// FIXME: remove direct dependencies
|
||||
#include <FDM/flight.hxx>
|
||||
|
||||
static const char * engine_names[FGFX::MAX_ENGINES] = {
|
||||
"engine0",
|
||||
"engine1"
|
||||
};
|
||||
|
||||
static const char * crank_names[FGFX::MAX_ENGINES] = {
|
||||
"crank0",
|
||||
"crank1"
|
||||
};
|
||||
|
||||
|
||||
FGFX::FGFX ()
|
||||
: _old_flap_position(0),
|
||||
_engine(0),
|
||||
_crank(0),
|
||||
_wind(0),
|
||||
_stall(0),
|
||||
_rumble(0),
|
||||
_flaps(0),
|
||||
_squeal(0),
|
||||
_click(0),
|
||||
_engine_running_prop(0),
|
||||
_engine_cranking_prop(0),
|
||||
_stall_warning_prop(0),
|
||||
_flaps_prop(0)
|
||||
{
|
||||
for (int i = 0; i < MAX_ENGINES; i++) {
|
||||
_engine[i] = 0;
|
||||
_crank[i] = 0;
|
||||
_engine_running_prop[i] = 0;
|
||||
_engine_cranking_prop[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
FGFX::~FGFX ()
|
||||
{
|
||||
// FIXME: is this right, or does the
|
||||
// sound manager assume pointer ownership?
|
||||
delete _engine;
|
||||
delete _crank;
|
||||
for (int i = 0; i < MAX_ENGINES; i++) {
|
||||
delete _engine[i];
|
||||
delete _crank[i];
|
||||
}
|
||||
delete _wind;
|
||||
delete _stall;
|
||||
delete _rumble;
|
||||
|
@ -67,20 +81,21 @@ FGFX::init ()
|
|||
FGSoundMgr * mgr = globals->get_soundmgr();
|
||||
|
||||
//
|
||||
// Create and add the engine sound
|
||||
// Create and add engine-related sounds.
|
||||
//
|
||||
_engine =
|
||||
new FGSimpleSound(fgGetString("/sim/sounds/engine", "Sounds/wasp.wav"));
|
||||
mgr->add(_engine, "engine");
|
||||
for (int i = 0; i < MAX_ENGINES; i++) {
|
||||
// Engine
|
||||
_engine[i] =
|
||||
new FGSimpleSound(fgGetString("/sim/sounds/engine", "Sounds/wasp.wav"));
|
||||
mgr->add(_engine[i], engine_names[i]);
|
||||
|
||||
//
|
||||
// Create and add the cranking sound.
|
||||
//
|
||||
_crank = new FGSimpleSound(fgGetString("/sim/sounds/cranking",
|
||||
"Sounds/cranking.wav"));
|
||||
_crank->set_pitch(1.25);
|
||||
_crank->set_volume(0.175);
|
||||
mgr->add(_crank, "crank");
|
||||
// Starter
|
||||
_crank[i] = new FGSimpleSound(fgGetString("/sim/sounds/cranking",
|
||||
"Sounds/cranking.wav"));
|
||||
_crank[i]->set_pitch(1.25);
|
||||
_crank[i]->set_volume(0.175);
|
||||
mgr->add(_crank[i], crank_names[i]);
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
|
@ -132,8 +147,13 @@ FGFX::init ()
|
|||
// Grab some properties.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
_engine_running_prop = fgGetNode("/engines/engine[0]/running", true);
|
||||
_engine_cranking_prop = fgGetNode("/engines/engine[0]/cranking", true);
|
||||
for (int i = 0; i < MAX_ENGINES; i++) {
|
||||
char buf[100];
|
||||
sprintf(buf, "/engines/engine[%d]/running", i);
|
||||
_engine_running_prop[i] = fgGetNode(buf, true);
|
||||
sprintf(buf, "/engines/engine[%d]/cranking", i);
|
||||
_engine_cranking_prop[i] = fgGetNode(buf, true);
|
||||
}
|
||||
_stall_warning_prop = fgGetNode("/sim/aircraft/alarms/stall-warning", true);
|
||||
_flaps_prop = fgGetNode("/controls/flaps", true);
|
||||
}
|
||||
|
@ -157,53 +177,53 @@ FGFX::update ()
|
|||
////////////////////////////////////////////////////////////////////
|
||||
// Update the engine sound.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
for (int i = 0; i < MAX_ENGINES; i++) {
|
||||
|
||||
if (cur_fdm_state->get_num_engines() > 0 && _engine_running_prop->getBoolValue()) {
|
||||
if (cur_fdm_state->get_num_engines() > 0 &&
|
||||
_engine_running_prop[i]->getBoolValue()) {
|
||||
// pitch corresponds to rpm
|
||||
// volume corresponds to manifold pressure
|
||||
|
||||
double rpm_factor;
|
||||
if ( cur_fdm_state->get_num_engines() > 0 )
|
||||
rpm_factor = cur_fdm_state->get_engine(0)->get_RPM() / 2500.0;
|
||||
else
|
||||
rpm_factor = 1.0;
|
||||
double rpm_factor;
|
||||
if ( cur_fdm_state->get_num_engines() > 0 )
|
||||
rpm_factor = cur_fdm_state->get_engine(i)->get_RPM() / 2500.0;
|
||||
else
|
||||
rpm_factor = 1.0;
|
||||
|
||||
double pitch = 0.3 + rpm_factor * 3.0;
|
||||
double pitch = 0.3 + rpm_factor * 3.0;
|
||||
|
||||
// don't run at absurdly slow rates -- not realistic
|
||||
// and sounds bad to boot. :-)
|
||||
if (pitch < 0.7)
|
||||
pitch = 0.7;
|
||||
if (pitch > 5.0)
|
||||
pitch = 5.0;
|
||||
// don't run at absurdly slow rates -- not realistic
|
||||
// and sounds bad to boot. :-)
|
||||
if (pitch < 0.7)
|
||||
pitch = 0.7;
|
||||
if (pitch > 5.0)
|
||||
pitch = 5.0;
|
||||
|
||||
double mp_factor;
|
||||
if ( cur_fdm_state->get_num_engines() > 0 )
|
||||
mp_factor = cur_fdm_state->get_engine(0)->get_Manifold_Pressure() / 100;
|
||||
else
|
||||
mp_factor = 0.3;
|
||||
double mp_factor;
|
||||
if ( cur_fdm_state->get_num_engines() > 0 )
|
||||
mp_factor =
|
||||
cur_fdm_state->get_engine(i)->get_Manifold_Pressure() / 100;
|
||||
else
|
||||
mp_factor = 0.3;
|
||||
|
||||
double volume = 0.15 + mp_factor / 2.0;
|
||||
double volume = 0.15 + mp_factor / 2.0;
|
||||
|
||||
if (volume < 0.15)
|
||||
volume = 0.15;
|
||||
if (volume > 0.5)
|
||||
volume = 0.5;
|
||||
if (volume < 0.15)
|
||||
volume = 0.15;
|
||||
if (volume > 0.5)
|
||||
volume = 0.5;
|
||||
|
||||
_engine->set_pitch( pitch );
|
||||
_engine->set_volume( volume );
|
||||
set_playing("engine", true);
|
||||
} else {
|
||||
set_playing("engine", false);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Update the cranking sound.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
_engine[i]->set_pitch( pitch );
|
||||
_engine[i]->set_volume( volume );
|
||||
set_playing(engine_names[i], true);
|
||||
} else {
|
||||
set_playing(engine_names[i], false);
|
||||
}
|
||||
|
||||
// FIXME
|
||||
set_playing("crank", _engine_cranking_prop->getBoolValue());
|
||||
set_playing(crank_names[i], _engine_cranking_prop[i]->getBoolValue());
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -47,6 +47,11 @@ class FGFX : public FGSubsystem
|
|||
|
||||
public:
|
||||
|
||||
enum {
|
||||
MAX_ENGINES = 2, // TODO: increase later
|
||||
MAX_GEAR = 20,
|
||||
};
|
||||
|
||||
FGFX ();
|
||||
virtual ~FGFX ();
|
||||
|
||||
|
@ -59,17 +64,13 @@ private:
|
|||
|
||||
void set_playing (const char * soundName, bool state = true);
|
||||
|
||||
enum {
|
||||
MAX_GEAR = 20
|
||||
};
|
||||
|
||||
double _old_flap_position;
|
||||
|
||||
bool _gear_on_ground[MAX_GEAR];
|
||||
|
||||
// looped sounds
|
||||
FGSimpleSound * _engine;
|
||||
FGSimpleSound * _crank;
|
||||
FGSimpleSound * _engine[MAX_ENGINES];
|
||||
FGSimpleSound * _crank[MAX_ENGINES];
|
||||
FGSimpleSound * _wind;
|
||||
FGSimpleSound * _stall;
|
||||
FGSimpleSound * _rumble;
|
||||
|
@ -80,8 +81,8 @@ private:
|
|||
FGSimpleSound * _click;
|
||||
|
||||
// Cached property nodes.
|
||||
const SGPropertyNode * _engine_running_prop;
|
||||
const SGPropertyNode * _engine_cranking_prop;
|
||||
const SGPropertyNode * _engine_running_prop[MAX_ENGINES];
|
||||
const SGPropertyNode * _engine_cranking_prop[MAX_ENGINES];
|
||||
const SGPropertyNode * _stall_warning_prop;
|
||||
const SGPropertyNode * _flaps_prop;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue