Rise
The Vieneo Province
Loading...
Searching...
No Matches
Tests/DorDisconnectTests.cpp

Source at documentation-generation time. See Test catalog for fixture associations.

1// The production disconnect and TVM input functions are extracted at build time.
2// Only the sound device, logger and surrounding game state are test doubles.
3#include "../Modules/OrbitState.h"
4#include "../Rendering/ClientMath.h"
5#include "../Modules/OrbitEntryAudio.h"
6#include <cstdlib>
7#include <climits>
8#include <iostream>
9#include <vector>
10
11constexpr int MAX_ENGINES=4, SOUND_APCAVALRY=42, REF_ONGROUND=-2;
12struct Bus {
13 struct Afcs {
16 bool DorOn=false, TvmOn=false, AutothrottleEngaged=false;
17 float DesiredClosingSpeed=0;
21 } AFCS;
23 float HeadingTrueDegrees=0;
24 void AddCommand(const Command&,bool) {}
27};
28struct { bool groundvehicle=false, isSimulator=false; int reference=-1, vehicleId=1; } playerships[1];
29struct { float power=1; bool spaceCapable=true; } ourcockpit;
30struct Logger { void AddToCallStack(const char*) {} } logger;
31struct Sound { std::vector<int> played; void Play(int id) { played.push_back(id); } } sound;
32struct GameClass {
33 Bus* bus;
34 Logger* logger;
35 Sound* sound;
36 bool TurnOffDOR(bool preserveGuidance=false) const;
37 bool TurnOffTVM() const;
38 void AutopilotDisconnect() const {} // DOR and TVM do not engage the autopilot.
39};
40#include "DorDisconnectProduction.generated.h"
41
42int checks=0;
43void Check(bool ok, const char* message) {
44 ++checks;
45 if(!ok) { std::cerr<<"FAIL: "<<message<<'\n'; std::exit(1); }
46}
47int main() {
48 Bus bus; GameClass game{&bus,&logger,&sound};
49 // No flight-phase or simulator exclusion: test airborne, landed, and a
50 // vehicle reset to a ground vehicle, at full, boundary and absent power.
51 for(float power:{1.f,.5f,0.f}) for(bool simulator:{false,true})
52 for(int state=0;state<3;++state) for(auto phase:{Orbital::Phase::Complete,Orbital::Phase::Abort}) {
53 ourcockpit.power=power; playerships[0].isSimulator=simulator;
54 playerships[0].groundvehicle=state==2;
55 playerships[0].reference=state==0?-1:REF_ONGROUND;
56 bus.AFCS.DorOn=true; bus.AFCS.DesiredClosingSpeed=10;
57 bus.orbit.guidance.phase=phase;
58 bus.orbit.guidance.status=phase==Orbital::Phase::Complete?L"DOR COMPLETE":L"DOR: PLAN CHANGED";
59 const auto reason=bus.orbit.guidance.status;
60 for(int i=0;i<MAX_ENGINES;++i) { bus.EngineThrustLever[i]=.8f; bus.ThrustReverserCommand[i]=true; }
61 sound.played.clear();
62 Check(game.TurnOffDOR(true),"active DOR disconnects");
63 Check(!bus.AFCS.DorOn&&bus.AFCS.DesiredClosingSpeed==0,"disconnect clears control state");
64 Check(bus.orbit.guidance.phase==phase&&bus.orbit.guidance.status==reason,"automatic stop retains result");
65 for(int i=0;i<MAX_ENGINES;++i)
66 Check(bus.EngineThrustLever[i]==0&&!bus.ThrustReverserCommand[i],"all engine commands reset");
67 Check(sound.played==std::vector<int>{SOUND_APCAVALRY},"one existing disconnect sound");
68 for(int i=0;i<100;++i) Check(!game.TurnOffDOR(),"repeated off is silent");
69 Check(sound.played.size()==1&&bus.orbit.guidance.status==reason,"no repeat or lost reason");
70 bus.AFCS.DorOn=true;
71 Check(game.TurnOffDOR(),"manual takeover re-arms sound");
72 Check(sound.played.size()==2&&bus.orbit.guidance.phase==Orbital::Phase::Off,"manual takeover clears guidance");
73 }
75 for(const auto* reason:{L"DOR: DEPARTURE COAST UNSAFE",L"DOR: NO CLEAR CORRECTION",
76 L"DOR: FINAL ORBIT UNSAFE",L"DOR: CORRECTION MARGIN LOST",L"DOR: COAST CLEARANCE LOST"}) {
77 bus.AFCS.DorOn=true; sound.played.clear();
79 bus.orbit.guidance.status=reason;
80 for(auto& thrust:bus.EngineThrustLever) thrust=.5f;
81 Check(game.TurnOffDOR(true),"clearance abort disconnects");
82 Check(!bus.AFCS.DorOn&&bus.orbit.guidance.status==reason,"clearance reason survives disconnect");
83 for(auto thrust:bus.EngineThrustLever) Check(thrust==0,"clearance abort stops engine commands");
84 Check(sound.played==std::vector<int>{SOUND_APCAVALRY},"clearance abort sounds once");
85 Check(!game.TurnOffDOR(true)&&sound.played.size()==1,"clearance abort cannot replay sound");
86 }
87 bus.AFCS.DorOn=true; bus.AFCS.TvmOn=false; sound.played.clear();
88 TvmCycle(&game,true);
89 Check(bus.AFCS.DorOn&&sound.played.empty(),"key repeat does not disengage");
90 TvmCycle(&game,false);
91 Check(!bus.AFCS.DorOn&&bus.AFCS.TvmOn,"TVM hand-off preserves new mode");
92 Check(sound.played==std::vector<int>{SOUND_APCAVALRY},"TVM hand-off plays once");
93 // Regaining power while already off must not replay the disconnect.
95 Check(sound.played.size()==1,"no stale sound on power restoration");
96 bus.AFCS.DorOn=false;bus.AFCS.AutothrottleEngaged=true;sound.played.clear();
97 for(int i=0;i<MAX_ENGINES;++i) {bus.EngineThrustLever[i]=.8f;bus.ThrustReverserCommand[i]=true;}
98 Check(game.TurnOffDOR(),"entry speed hold can be cancelled after DOR handoff");
99 Check(!bus.AFCS.AutothrottleEngaged,"cancel clears entry speed hold");
100 for(int i=0;i<MAX_ENGINES;++i) Check(bus.EngineThrustLever[i]==0&&!bus.ThrustReverserCommand[i],"speed-hold cancel resets engines");
101 Check(sound.played==std::vector<int>{SOUND_APCAVALRY},"speed-hold cancel sounds once");
102 Check(!game.TurnOffDOR()&&sound.played.size()==1,"repeated speed-hold cancel is silent");
103 for(auto throttle:{EntryThrottleLeft,EntryThrottleRight}) {
104 bus.AFCS.AutothrottleEngaged=false;throttle(&game,100);
105 bus.AFCS.AutothrottleEngaged=true;const auto sounds=sound.played.size();
106 for(int value=101;value<=140;++value) throttle(&game,value);
107 Check(bus.AFCS.AutothrottleEngaged,"throttle noise inside engagement deadband does not cancel");
108 throttle(&game,141);
109 Check(!bus.AFCS.AutothrottleEngaged&&sound.played.size()==sounds+1,"slow cumulative throttle movement cancels once");
110 throttle(&game,142);Check(sound.played.size()==sounds+1,"subsequent manual movement is silent");
111 }
112 bus.AFCS.TvmOn=false;
116 for(bool simulator:{false,true}) for(float power:{0.f,1.f}) for(int reference:{REF_ONGROUND,-1,9})
118 playerships[0].isSimulator=simulator;ourcockpit.power=power;
119 playerships[0].reference=reference; bus.orbit.request.route=route;
120 bus.AFCS.TvmOn=true;bus.AFCS.DesiredClosingSpeed=.125f;bus.EngineThrustLever[0]=.3f;
121 const auto sounds=sound.played.size();
122 DorCycle(&game,false);
123 Check(!bus.AFCS.DorOn&&!bus.orbit.guidance.valid&&!bus.orbit.guidance.thrust,"surface preview cannot engage or issue thrust");
124 Check(bus.orbit.guidance.status==L"DOR: PLAN ONLY / ATM HANDOFF","surface preview explains refusal");
125 Check(sound.played.size()==sounds+1&&sound.played.back()==SOUND_APCAVALRY,"refused PLAN ONLY engagement sounds once");
126 Check(bus.AFCS.TvmOn&&bus.AFCS.DesiredClosingSpeed==.125f&&bus.EngineThrustLever[0]==.3f,
127 "refusal never enables DOR or disrupts existing controls");
128 for(int repeat=0;repeat<10;++repeat) DorCycle(&game,true);
129 Check(sound.played.size()==sounds+1&&!bus.AFCS.DorOn,"held key cannot repeat the refusal sound or engage DOR");
130 }
132 bus.orbit.snapshot.plan.ascent=true;bus.orbit.snapshot.plan.valid=true;
134 bus.AFCS.DorOn=bus.AFCS.TvmOn=bus.AFCS.AutothrottleEngaged=false;
135 DorCycle(&game,false);
136 Check(bus.AFCS.DorOn&&!bus.AFCS.TvmOn,"DOR key permits a ground RENDEZVOUS ascent leg");
137 Check(bus.AFCS.CurrentLateralMode==Bus::Afcs::Heading,"ground mission preserves departure heading setup");
138 DorCycle(&game,false);Check(!bus.AFCS.DorOn,"second key press cancels ground mission");
139 std::cout<<"PASS: "<<checks<<" DOR disconnect checks\n";
140}
#define MAX_ENGINES
@ REF_ONGROUND
Definition ServerTypes.h:43
@ SOUND_APCAVALRY
Definition Sound.h:171
Definition Bus.h:20
float EngineThrustLever[MAX_ENGINES]
Definition Bus.h:357
struct Bus::Afcs AFCS
float HeadingTrueDegrees
Definition Bus.h:41
void AddCommand(const Command &command, bool onlyOne)
Definition Bus.cpp:5
Orbital::BusState orbit
Definition Bus.h:481
bool ThrustReverserCommand[MAX_ENGINES]
Definition Bus.h:72
std::unique_ptr< Bus > bus
Definition GameClass.h:108
std::unique_ptr< Sound > sound
Definition GameClass.h:104
bool TurnOffTVM() const
bool TurnOffDOR(bool preserveGuidance=false) const
std::unique_ptr< Logger > logger
Definition GameClass.h:109
void AutopilotDisconnect() const
void AddToCallStack(const char *msg)
Definition Logger.cpp:355
Definition Sound.h:369
float Play(SOUNDS soundEnum, float volume=1.0f)
Definition Sound.cpp:802
s_network_objects playerships[MAX_SCAN]
Definition globals.cpp:112
Scockpit ourcockpit
Definition globals.cpp:114
LateralModes
Definition Bus.h:110
@ Navigation
Definition Bus.h:115
@ LateralMode_Off
Definition Bus.h:112
@ Heading
Definition Bus.h:114
float DesiredHeadingRadians
Definition Bus.h:133
VerticalModes
so I guess we allow them to fly until they get to x degrees off
Definition Bus.h:95
@ VerticalMode_Off
Definition Bus.h:97
bool DorOn
Definition Bus.h:148
bool AutothrottleEngaged
Definition Bus.h:88
bool TvmOn
Definition Bus.h:151
enum Bus::Afcs::LateralModes CurrentLateralMode
float DesiredClosingSpeed
Definition Bus.h:152
enum Bus::Afcs::VerticalModes CurrentVerticalMode
std::wstring status
Definition OrbitState.h:315
TargetKind targetKind
Definition OrbitState.h:255
float power
Definition globals.h:599