Skip to content

Commit

Permalink
Implemented indy91's changes to fix main engine sounds and bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
CaptainSwag101 committed Jan 12, 2023
1 parent 513c6de commit d694a99
Show file tree
Hide file tree
Showing 26 changed files with 155 additions and 91 deletions.
44 changes: 43 additions & 1 deletion Orbitersdk/samples/ProjectApollo/src_csm/satsystems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3891,7 +3891,7 @@ bool Saturn::GetCMRCSStateCommanded(THRUSTER_HANDLE th) {
}


void Saturn::RCSSoundTimestep() {
void Saturn::EnginesSoundTimestep() {

// In case of disabled Orbiter attitude thruster groups OrbiterSound plays no
// engine sound, so this needs to be done manually
Expand Down Expand Up @@ -3933,4 +3933,46 @@ void Saturn::RCSSoundTimestep() {
} else {
RCSSustainSound.stop();
}


//Main engine sound
THGROUP_HANDLE thg;
switch (stage)
{
case PRELAUNCH_STAGE:
case LAUNCH_STAGE_ONE:
thg = thg_1st;
break;
case LAUNCH_STAGE_TWO:
case LAUNCH_STAGE_TWO_ISTG_JET:
thg = thg_2nd;
break;
case LAUNCH_STAGE_SIVB:
case STAGE_ORBIT_SIVB:
thg = thg_3rd;
break;
case CSM_LEM_STAGE:
thg = thg_sps;
break;
default:
thg = NULL;
break;
}

if (thg)
{
double lvl;
if (lvl = GetThrusterGroupLevel(thg))
{
EngineS.play(LOOP, static_cast<int>(lvl * 255));
}
else
{
EngineS.stop();
}
}
else
{
EngineS.stop();
}
}
10 changes: 3 additions & 7 deletions Orbitersdk/samples/ProjectApollo/src_csm/saturn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -514,11 +514,6 @@ Saturn::Saturn(OBJHANDLE hObj, int fmodel) : ProjectApolloConnectorVessel (hObj,
InitMissionManagementMemory();
pMission = paGetDefaultMission();

//
// VESSELSOUND initialisation
//
soundlib.InitSoundLib(oapiGetVesselInterface(hObj), SOUND_DIRECTORY);

cws.MonitorVessel(this);
dockingprobe.RegisterVessel(this);

Expand Down Expand Up @@ -3306,10 +3301,10 @@ void Saturn::GenericTimestep(double simt, double simdt, double mjd)
}

//
// Play RCS sound in case of Orbiter's attitude control is disabled
// Play engines sound in case of Orbiter's attitude control is disabled
//

RCSSoundTimestep();
EnginesSoundTimestep();
}

void StageTransform(VESSEL *vessel, VESSELSTATUS *vs, VECTOR3 ofs, VECTOR3 vel)
Expand Down Expand Up @@ -4545,6 +4540,7 @@ void Saturn::LoadDefaultSounds()
soundlib.LoadSound(RCSSustainSound, RCSSUSTAIN_SOUND, INTERNAL_ONLY);
soundlib.LoadSound(HatchOpenSound, HATCHOPEN_SOUND, INTERNAL_ONLY);
soundlib.LoadSound(HatchCloseSound, HATCHCLOSE_SOUND, INTERNAL_ONLY);
soundlib.LoadDefaultSound(EngineS, MAIN_ENGINES_SOUND, INTERNAL_ONLY);

Sctdw.setFlags(SOUNDFLAG_1XONLY|SOUNDFLAG_COMMS);
}
Expand Down
3 changes: 2 additions & 1 deletion Orbitersdk/samples/ProjectApollo/src_csm/saturn.h
Original file line number Diff line number Diff line change
Expand Up @@ -4234,7 +4234,7 @@ class Saturn: public ProjectApolloConnectorVessel, public PanelSwitchListener {
void DestroyStages(double simt);
void FireSeperationThrusters(THRUSTER_HANDLE *pth);
void LoadDefaultSounds();
void RCSSoundTimestep();
void EnginesSoundTimestep();
void LoadVC();
void UpdateVC(VECTOR3 meshdir);
void DefineCMAttachments();
Expand Down Expand Up @@ -4286,6 +4286,7 @@ class Saturn: public ProjectApolloConnectorVessel, public PanelSwitchListener {
Sound RCSSustainSound;
Sound HatchOpenSound;
Sound HatchCloseSound;
Sound EngineS;

///
/// Drogue deployment message.
Expand Down
2 changes: 0 additions & 2 deletions Orbitersdk/samples/ProjectApollo/src_csm/sm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,6 @@ SM::SM (OBJHANDLE hObj, int fmodel) : VESSEL2(hObj, fmodel)
{
InitSM();
DefineAnimations();

soundlib.InitSoundLib(oapiGetVesselInterface(hObj), SOUND_DIRECTORY);
}

SM::~SM()
Expand Down
2 changes: 0 additions & 2 deletions Orbitersdk/samples/ProjectApollo/src_launch/Crawler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,6 @@ Crawler::Crawler(OBJHANDLE hObj, int fmodel) : VESSEL2 (hObj, fmodel) {
meshidxPanel = 0;
meshidxPanelReverse = 0;

soundlib.InitSoundLib(oapiGetVesselInterface(hObj), SOUND_DIRECTORY);

panelMeshoffset = _V(0,0,0);
panelMeshidx = 0;
}
Expand Down
2 changes: 0 additions & 2 deletions Orbitersdk/samples/ProjectApollo/src_launch/Floodlight.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@ Floodlight::Floodlight(OBJHANDLE hObj, int fmodel) : VESSEL2 (hObj, fmodel) {
exhaustsEnabled = false;
currentExhaust = 0;
configMode = 0;

soundlib.InitSoundLib(oapiGetVesselInterface(hObj), SOUND_DIRECTORY);
}

Floodlight::~Floodlight() {
Expand Down
2 changes: 0 additions & 2 deletions Orbitersdk/samples/ProjectApollo/src_launch/LC34.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,6 @@ LC34::LC34(OBJHANDLE hObj, int fmodel) : VESSEL2 (hObj, fmodel) {
}
liftoffStreamLevel = 0;

soundlib.InitSoundLib(oapiGetVesselInterface(hObj), SOUND_DIRECTORY);

//meshoffsetMSS = _V(0,0,0);

IuUmb = new IUUmbilical(this);
Expand Down
2 changes: 0 additions & 2 deletions Orbitersdk/samples/ProjectApollo/src_launch/LC37.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,6 @@ LC37::LC37(OBJHANDLE hObj, int fmodel) : VESSEL2 (hObj, fmodel) {
}
liftoffStreamLevel = 0;

soundlib.InitSoundLib(oapiGetVesselInterface(hObj), SOUND_DIRECTORY);

//meshoffsetMSS = _V(0,0,0);

IuUmb = new IUUmbilical(this);
Expand Down
2 changes: 0 additions & 2 deletions Orbitersdk/samples/ProjectApollo/src_launch/ML.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,6 @@ ML::ML(OBJHANDLE hObj, int fmodel) : VESSEL2 (hObj, fmodel) {
}
liftoffStreamLevel = 0;

soundlib.InitSoundLib(oapiGetVesselInterface(hObj), SOUND_DIRECTORY);

sat = NULL;

IuUmb = new IUUmbilical(this);
Expand Down
2 changes: 0 additions & 2 deletions Orbitersdk/samples/ProjectApollo/src_launch/MSS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,6 @@ MSS::MSS(OBJHANDLE hObj, int fmodel) : VESSEL2 (hObj, fmodel) {
moveLVToPad = false;
touchdownPointHeight = -67.25; // park height
hLV = 0;

soundlib.InitSoundLib(oapiGetVesselInterface(hObj), SOUND_DIRECTORY);
}

MSS::~MSS() {
Expand Down
4 changes: 2 additions & 2 deletions Orbitersdk/samples/ProjectApollo/src_launch/VAB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,6 @@ VAB::VAB(OBJHANDLE hObj, int fmodel) : VESSEL2 (hObj, fmodel) {
for (int j = 0; j < 8; j++)
mgroupCrane2[i][j] = 0;
}

soundlib.InitSoundLib(oapiGetVesselInterface(hObj), SOUND_DIRECTORY);
}

VAB::~VAB() {
Expand Down Expand Up @@ -530,6 +528,8 @@ void VAB::clbkPostCreation() {
if (lav && !LVVisible) {
SetSaturnMeshVisibilityMode(lav->GetBuildStatus(), MESHVIS_NEVER);
}

soundlib.InitSoundLib(this, SOUND_DIRECTORY);
}

void VAB::clbkPreStep(double simt, double simdt, double mjd) {
Expand Down
61 changes: 33 additions & 28 deletions Orbitersdk/samples/ProjectApollo/src_lm/LEM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -478,9 +478,6 @@ LEM::LEM(OBJHANDLE hObj, int fmodel) : Payload (hObj, fmodel),
InitMissionManagementMemory();
pMission = paGetDefaultMission();

// VESSELSOUND initialisation
soundlib.InitSoundLib(oapiGetVesselInterface(hObj), SOUND_DIRECTORY);

// Switch to compatible dock mode
SetDockMode(0);

Expand Down Expand Up @@ -660,23 +657,7 @@ void LEM::Init()
NextFlashUpdate = MINUS_INFINITY;
PanelFlashOn = false;

//
// Initial sound setup
//

soundlib.SoundOptionOnOff(PLAYCOUNTDOWNWHENTAKEOFF, FALSE);
soundlib.SoundOptionOnOff(PLAYCABINAIRCONDITIONING, FALSE);
soundlib.SoundOptionOnOff(DISPLAYTIMER, FALSE);
/// \todo Disabled for now because of the LEVA and the descent stage vessel
/// Enable before CSM docking
soundlib.SoundOptionOnOff(PLAYRADARBIP, FALSE);

// Disable Rolling, landing, speedbrake, crash sound. This causes issues in Orbiter 2016.
soundlib.SoundOptionOnOff(PLAYLANDINGANDGROUNDSOUND, FALSE);

strncpy(AudioLanguage, "English", 64);
soundlib.SetLanguage(AudioLanguage);
SoundsLoaded = false;

exhaustTex = oapiRegisterExhaustTexture("ProjectApollo/Exhaust_atrcs");

Expand Down Expand Up @@ -719,10 +700,6 @@ void LEM::Init()
void LEM::DoFirstTimestep()
{
checkControl.linktoVessel(this);
// Load sounds in case of dynamic creation, otherwise during clbkLoadStageEx
if (!SoundsLoaded) {
LoadDefaultSounds();
}

#ifdef DIRECTSOUNDENABLED
NextEventTime = 0.0;
Expand Down Expand Up @@ -766,6 +743,7 @@ void LEM::LoadDefaultSounds()
soundlib.LoadSound(GlycolPumpSound, "GlycolPump.wav", INTERNAL_ONLY);
soundlib.LoadSound(SuitFanSound, "LMSuitFan.wav", INTERNAL_ONLY);
soundlib.LoadSound(CrewDeadSound, CREWDEAD_SOUND);
soundlib.LoadDefaultSound(EngineS, MAIN_ENGINES_SOUND, INTERNAL_ONLY);

// Configure sound options where needed
SuitFanSound.setFadeTime(5);
Expand All @@ -777,9 +755,8 @@ void LEM::LoadDefaultSounds()
// MODIF X15 manage landing sound
#ifdef DIRECTSOUNDENABLED
sevent.LoadMissionLandingSoundArray(soundlib,"sound.csv");
sevent.InitDirectSound(soundlib);
sevent.InitDirectSound();
#endif
SoundsLoaded = true;
}

int LEM::clbkConsumeBufferedKey(DWORD key, bool down, char *keystate) {
Expand Down Expand Up @@ -1340,10 +1317,10 @@ void LEM::clbkPostStep(double simt, double simdt, double mjd)
UpdateMassAndCoG();

//
// Play RCS sound in case of Orbiter's attitude control is disabled
// Play engine sound in case of Orbiter's attitude control is disabled
//

RCSSoundTimestep();
EngineSoundTimestep();

if (stage == 0 || pMission->LMHasLegs() == false) {

Expand Down Expand Up @@ -1894,6 +1871,20 @@ void LEM::clbkPostCreation()
soundlib.InitSoundLib(this, SOUND_DIRECTORY);
LoadDefaultSounds();
this->CWEA.LoadSounds();

//
// Initial sound setup
//

soundlib.SoundOptionOnOff(PLAYCOUNTDOWNWHENTAKEOFF, FALSE);
soundlib.SoundOptionOnOff(PLAYCABINAIRCONDITIONING, FALSE);
soundlib.SoundOptionOnOff(DISPLAYTIMER, FALSE);
/// \todo Disabled for now because of the LEVA and the descent stage vessel
/// Enable before CSM docking
soundlib.SoundOptionOnOff(PLAYRADARBIP, FALSE);

// Disable Rolling, landing, speedbrake, crash sound. This causes issues in Orbiter 2016.
soundlib.SoundOptionOnOff(PLAYLANDINGANDGROUNDSOUND, FALSE);
}

void LEM::clbkVisualCreated(VISHANDLE vis, int refcount)
Expand Down Expand Up @@ -2301,7 +2292,7 @@ void LEM::SetRCSJetLevelPrimary(int jet, double level) {
SetThrusterLevel(th_rcs[jet], level);
}

void LEM::RCSSoundTimestep() {
void LEM::EngineSoundTimestep() {

// In case of disabled Orbiter attitude thruster groups OrbiterSound plays no
// engine sound, so this needs to be done manually
Expand All @@ -2326,6 +2317,20 @@ void LEM::RCSSoundTimestep() {
else {
RCSSustainSound.stop();
}

//APS/DPS sound
if (th_hover[0])
{
double lvl;
if (lvl = GetThrusterLevel(th_hover[0]))
{
EngineS.play(LOOP, static_cast<int>(lvl * 255));
}
else
{
EngineS.stop();
}
}
}

void LEM::UpdateMassAndCoG()
Expand Down
5 changes: 2 additions & 3 deletions Orbitersdk/samples/ProjectApollo/src_lm/LEM.h
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,7 @@ class LEM : public Payload, public PanelSwitchListener {
void DefineVCAnimations();
void DoFirstTimestep();
void LoadDefaultSounds();
void RCSSoundTimestep();
void EngineSoundTimestep();
// void GetDockStatus();
void JostleViewpoint(double amount);
void AddDust();
Expand Down Expand Up @@ -1583,8 +1583,6 @@ class LEM : public Payload, public PanelSwitchListener {
#define VIEWANGLE 30

int viewpos;

bool SoundsLoaded;

bool Crewed;
bool AutoSlow;
Expand Down Expand Up @@ -1773,6 +1771,7 @@ class LEM : public Payload, public PanelSwitchListener {
FadeInOutSound GlycolPumpSound;
FadeInOutSound SuitFanSound;
Sound CrewDeadSound;
Sound EngineS;

//
// Connectors.
Expand Down
6 changes: 5 additions & 1 deletion Orbitersdk/samples/ProjectApollo/src_moon/LRV.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,6 @@ void LRV::DoFirstTimestep()

if (StateSet) {
// Probably a better way but I'm not familiar with the API
soundlib.InitSoundLib(oapiGetVesselInterface(GetHandle()), SOUND_DIRECTORY);
SetMissionPath();

//
Expand Down Expand Up @@ -886,6 +885,11 @@ void LRV::clbkPreStep (double SimT, double SimDT, double mjd)
// sprintf(oapiDebugString(), "touchdownPointHeight %f", touchdownPointHeight);
}

void LRV::clbkPostCreation()
{
soundlib.InitSoundLib(this, SOUND_DIRECTORY);
}

void LRV::DoAnimations ()
{
TRACESETUP("DoAnimations");
Expand Down
2 changes: 2 additions & 0 deletions Orbitersdk/samples/ProjectApollo/src_moon/LRV.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ class LRV: public VESSEL2 {
///
void clbkPreStep (double SimT, double SimDT, double mjd);

void clbkPostCreation();

///
/// \brief Orbiter keyboard input function.
/// \param kstate Key state.
Expand Down
6 changes: 5 additions & 1 deletion Orbitersdk/samples/ProjectApollo/src_moon/leva.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,6 @@ void LEVA::DoFirstTimestep()
//

if (StateSet) {
soundlib.InitSoundLib(oapiGetVesselInterface(GetHandle()), SOUND_DIRECTORY);
SetMissionPath();

//
Expand Down Expand Up @@ -646,6 +645,11 @@ void LEVA::clbkPreStep (double SimT, double SimDT, double mjd)
// sprintf(oapiDebugString(), "touchdownPointHeight %f", touchdownPointHeight);
}

void LEVA::clbkPostCreation()
{
soundlib.InitSoundLib(this, SOUND_DIRECTORY);
}

void LEVA::clbkLoadStateEx(FILEHANDLE scn, void *vs)
{
char *line;
Expand Down
2 changes: 2 additions & 0 deletions Orbitersdk/samples/ProjectApollo/src_moon/leva.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ class LEVA: public VESSEL2 {
///
void clbkPreStep (double SimT, double SimDT, double mjd);

void clbkPostCreation();

///
/// \brief Orbiter keyboard input function.
/// \param kstate Key state.
Expand Down
Loading

0 comments on commit d694a99

Please sign in to comment.