Rise
The Vieneo Province
Loading...
Searching...
No Matches
Tests/WiperFrameFixture.h

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

1#pragma once
2#include "../Viewscreen/RainAir.h"
3#include <algorithm>
4
5namespace WiperFrameFixture
6{
8enum class GameState { STATUS_GAME, Other };
9struct Logger { enum class Level { Warn }; };
10struct Vehicle { WindshieldWipers::Motion wipers; bool isSimulator = false; };
11inline Vehicle playerships[1];
12inline bool g_bEnabled = true, dead = false;
13struct Camera { bool outside = false; };
14struct Propulsion { float staticDensity = 1.f; };
15struct Viewscreen { bool hasAnimatedWipers = false; Camera* camera; Propulsion* ptrPropulsion; };
16struct Bus { RainAir::State RainAirStatus = RainAir::State::Off; };
17struct Game
18{
19 GameState displaystage = GameState::STATUS_GAME;
20 Viewscreen* viewscreen;
21 Bus* bus;
22};
23// Existing generic atmosphere reference is unchanged; production routing below
24// determines whether each stem uses it, the normalized curve, or no attenuation.
25inline float GetAtmosphericSoundPressureGain(float pressure)
26{
27 return std::isfinite(pressure) && pressure > 0.f ? std::sqrt(pressure * 2630.397f / 1013.25f) : 0.f;
28}
29struct Sound
30{
31 Game* game;
32 HSTREAM sound_stream[2], sound_streamFx[2];
33 float sound_length[2];
34 bool sound_fxEnabled[2] = {};
35 float headPanScalar = .25f, bleedAirGain = 0.f;
36 struct Voice
37 {
38 bool loop = false, restart = false, fromOutside = false, partOfHull = false;
39 float pitch = 0, volume = 0, pan = 0;
40 } voices[2];
41 void FrameMoveWipers(float elapsedTime);
42 void Trace(const char*, Logger::Level) { Check(false, "blade audio synchronization succeeds"); }
43 HSTREAM Selected(int sound) const { return sound_fxEnabled[sound] ? sound_streamFx[sound] : sound_stream[sound]; }
44 bool Playing(int sound) const
45 {
46 return BASS_ChannelIsActive(sound_stream[sound]) == BASS_ACTIVE_PLAYING
47 || BASS_ChannelIsActive(sound_streamFx[sound]) == BASS_ACTIVE_PLAYING;
48 }
49 void Stop(SOUNDS sound) { BASS_ChannelStop(sound_stream[sound]); BASS_ChannelStop(sound_streamFx[sound]); }
50 float Mix(SOUNDS soundEnum) const
51 {
52 float volume = voices[soundEnum].volume;
53 const bool fromOutside = voices[soundEnum].fromOutside, partOfHull = voices[soundEnum].partOfHull;
54#include "WiperAtmosphere.generated.h"
55 return volume;
56 }
57 void PlayEx(SOUNDS sound, bool looping, float gain, float rate, float stereoPan, bool reset,
58 bool exterior, bool hull)
59 {
60 voices[sound] = {looping, reset, exterior, hull, rate, gain, stereoPan};
61 Check(BASS_ChannelSetAttribute(Selected(sound), BASS_ATTRIB_VOL, Mix(sound)) != FALSE, "apply production layer gain");
62 Check(BASS_ChannelSetAttribute(Selected(sound), BASS_ATTRIB_FREQ, 48000.f * rate) != FALSE, "apply playback rate");
63 Check(BASS_ChannelPlay(Selected(sound), FALSE) != FALSE, "normal immediate playback for each layer or blade stream");
64 }
65 void CameraChange(bool filtered)
66 {
67 // Mirror the existing independent raw/glass stream handoff.
68 for (int i = 0; i < 2; ++i)
69 {
70 const HSTREAM before = Selected(i);
71 const QWORD position = BASS_ChannelGetPosition(before, BASS_POS_BYTE);
72 BASS_ChannelPause(before);
73 sound_fxEnabled[i] = filtered;
74 BASS_ChannelSetPosition(Selected(i), position, BASS_POS_BYTE);
75 }
76 game->viewscreen->camera->outside = !filtered;
77 }
78};
79#include "WiperFrame.generated.h"
80
81inline void Run(const HSTREAM raw[2], const HSTREAM glass[2], float duration)
82{
83 Camera camera;
84 Propulsion propulsion;
85 Viewscreen view{false, &camera, &propulsion};
86 Bus bus;
87 Game game{GameState::STATUS_GAME, &view, &bus};
88 Sound sound{&game, {raw[0], raw[1]}, {glass[0], glass[1]}, {duration, duration}};
89 auto& duct = sound.voices[SOUND_WINDSHIELDWIPERS];
90 auto& rush = sound.voices[SOUND_RAINAIRRUSH];
91 const auto supply = [&](int health, bool selected, float power, bool engine)
92 {
93 bus.RainAirStatus = RainAir::Evaluate(health, selected, !playerships[0].isSimulator, power, engine);
94 sound.FrameMoveWipers(.02f);
95 };
96 const auto silent = [&]() { return !sound.Playing(0) && !sound.Playing(1); };
97 for (bool fx : {false, true})
98 {
99 sound.CameraChange(fx);
100 Check(BASS_ChannelSetPosition(sound.Selected(0), BASS_ChannelSeconds2Bytes(sound.Selected(0), duration * .4), BASS_POS_BYTE) != FALSE, "position duct recording");
101 Check(BASS_ChannelSetPosition(sound.Selected(1), 0, BASS_POS_BYTE) != FALSE, "start rush at a different position");
102 supply(127, true, 1.f, true);
103 Check(sound.Playing(0) && sound.Playing(1), "normal playback starts both rain-air layers");
104 Check(std::fabs(Seconds(sound.Selected(0)) - duration * .4) < .0001 && Seconds(sound.Selected(1)) == 0.,
105 "independent layer positions are preserved without coordinated seeks");
106 Check(duct.loop && rush.loop && !duct.restart && !rush.restart && duct.pitch == 1.f && rush.pitch == 1.f
107 && duct.volume > 0.f && duct.volume < .02f && duct.volume == rush.volume, "both layers share authored pitch and fade");
108 Check(duct.fromOutside && duct.partOfHull && rush.fromOutside && !rush.partOfHull,
109 "duct is attached to the hull and rush uses exterior propagation");
110 const double ductPosition = Seconds(sound.Selected(0)), rushPosition = Seconds(sound.Selected(1));
111 sound.FrameMoveWipers(.02f);
112 Check(Seconds(sound.Selected(0)) == ductPosition && Seconds(sound.Selected(1)) == rushPosition,
113 "steady playback does not seek or restart either independent layer");
114 sound.FrameMoveWipers(1.5f);
115 Check(duct.volume == 1.f && rush.volume == 1.f, "both fades reach full volume");
116 supply(127, false, 1.f, true);
117 Check(!silent() && duct.volume < 1.f && duct.volume == rush.volume, "switch off fades both layers together");
118 sound.FrameMoveWipers(1.5f);
119 Check(silent() && sound.bleedAirGain == 0.f, "fade out stops both layers and camera variants");
120 supply(0, true, 1.f, true); Check(silent(), "failed equipment stays silent");
121 supply(-1, true, 1.f, true); Check(silent(), "absent equipment stays silent");
122 supply(127, true, 0.f, true); Check(silent(), "no control power stays silent");
123 supply(127, true, 1.f, false); Check(silent(), "no engine supply stays silent");
124 supply(127, true, 1.f, true); Check(!silent(), "restored supply resumes both loops");
125 playerships[0].isSimulator = true;
126 sound.FrameMoveWipers(.02f);
127 Check(silent() && sound.bleedAirGain == 0.f,
128 "simulator entry clears both loops and fade even with stale active bus state");
129 supply(127, true, 1.f, true); Check(silent(), "received selection stays silent inside simulator");
130 playerships[0].isSimulator = false;
131 supply(127, false, 1.f, true); Check(silent(), "simulator exit cannot replay deselected protection");
132 }
133 sound.CameraChange(true);
134 supply(127, true, 1.f, true); sound.FrameMoveWipers(1.5f);
135 // Ground/hover, atmospheric cruise, ascent, suborbital coast, orbit and
136 // re-entry share one continuous atmosphere curve, independent of airspeed/AFCS.
137 for (float altitudeKm : {0.f, 15.f, 50.f, 100.f, 937.f, 100.f, 50.f, 15.f, 0.f})
138 {
139 propulsion.staticDensity = std::exp(-altitudeKm / 7.5f);
140 sound.FrameMoveWipers(.02f);
141 Check(sound.Mix(SOUND_WINDSHIELDWIPERS) == 1.f, "cockpit duct remains audible at every altitude");
142 const float expected = std::exp(-altitudeKm / 15.f);
143 Check(std::fabs(sound.Mix(SOUND_RAINAIRRUSH) - expected) < .000001f, "rush follows normalized atmospheric fade in both directions");
144 Check(sound.Playing(0) && sound.Playing(1), "silent orbital rush keeps playing for re-entry");
145 }
146 propulsion.staticDensity = 0.f;
147 sound.FrameMoveWipers(.02f);
148 Check(sound.Mix(SOUND_WINDSHIELDWIPERS) == 1.f && sound.Mix(SOUND_RAINAIRRUSH) == 0.f, "vacuum cockpit retains duct only");
149 sound.CameraChange(false); sound.FrameMoveWipers(.02f);
150 Check(sound.Mix(SOUND_WINDSHIELDWIPERS) == 0.f && sound.Mix(SOUND_RAINAIRRUSH) == 0.f, "vacuum exterior camera is silent");
151 sound.CameraChange(true); sound.FrameMoveWipers(.02f);
152 Check(sound.Mix(SOUND_WINDSHIELDWIPERS) == 1.f, "return to cockpit restores duct playback");
153 for (float invalid : {-1.f, std::numeric_limits<float>::quiet_NaN(), std::numeric_limits<float>::infinity()})
154 Check(RainAirAudio::ExteriorGain(invalid) == 0.f, "invalid atmosphere cannot create audible rush");
155 Check(RainAirAudio::ExteriorGain(2.f) == 1.f, "rush never exceeds approved surface mix");
156 propulsion.staticDensity = 1.f;
157 for (int fps : {30, 144})
158 {
160 const float dt = 1.f / fps; const int frames = fps * 3 / 2;
162 for (int i = 0; i < frames; ++i) sound.FrameMoveWipers(dt);
163 Check(std::fabs(duct.volume - 1.f) < .00001f && duct.volume == rush.volume, "1.5-second fade at 30/144 FPS");
165 Check(std::fabs(duct.volume - .5f) < .00001f, "half fade out");
167 Check(std::fabs(duct.volume - .6f) < .00001f && duct.volume == rush.volume, "mid-fade reversal preserves both layer levels");
169 for (int i = 0; i <= frames; ++i) sound.FrameMoveWipers(dt);
170 Check(silent() && sound.bleedAirGain == 0.f, "supply loss fades both streams to stopped");
171 }
172 for (int gate = 0; gate < 7; ++gate)
173 {
174 supply(127, true, 1.f, true);
175 if (gate == 0) dead = true;
176 if (gate == 1) g_bEnabled = false;
177 if (gate == 2) game.displaystage = GameState::Other;
178 const float elapsed = gate == 3 ? 0.f : gate == 4 ? -1.f : gate == 5
179 ? std::numeric_limits<float>::quiet_NaN() : gate == 6 ? std::numeric_limits<float>::infinity() : .02f;
180 sound.FrameMoveWipers(elapsed);
181 Check(silent() && sound.bleedAirGain == 0.f, "inactive or invalid updates stop all rain-air playback immediately");
182 dead = false; g_bEnabled = true; game.displaystage = GameState::STATUS_GAME;
183 }
184 supply(127, true, 1.f, true);
185 view.hasAnimatedWipers = true;
186 sound.FrameMoveWipers(.02f); Check(silent(), "parked blades replace active pneumatic playback without a stale rush");
187 playerships[0].wipers.Update(.1f, true);
188 sound.FrameMoveWipers(.02f);
189 Check(sound.Playing(0) && !sound.Playing(1) && duct.pitch == WiperAudio::PlaybackRate(duration, playerships[0].wipers.rate),
190 "moving blades retain their stroke-synchronized playback without the rush stem");
192 std::cout << "PASS: production two-layer dispatch and atmosphere routing, independent playback/camera changes, orbit/re-entry, fades, supply loss, simulator transitions and blade precedence.\n";
193}
194}
GameState
Definition GameState.h:4
@ STATUS_GAME
Definition GameState.h:9
SOUNDS
Definition Sound.h:23
@ SOUND_RAINAIRRUSH
Definition Sound.h:34
@ SOUND_WINDSHIELDWIPERS
Definition Sound.h:33
@ SOUND_ENUMERATION
Definition Sound.h:344
RainAir::State RainAirStatus
Definition Bus.h:488
Level
Definition Logger.h:23
void Stop(SOUNDS soundEnum) const
Definition Sound.cpp:3397
void FrameMoveWipers(float elapsedTime)
Definition Sound.cpp:1849
float bleedAirGain
Definition Sound.h:373
bool hasAnimatedWipers
Definition Viewscreen.h:410
DeathType dead
Definition globals.cpp:37
s_network_objects playerships[MAX_SCAN]
Definition globals.cpp:112
bool g_bEnabled
Definition globals.cpp:96
float ExteriorGain(float relativePressure)
State Evaluate(int equipment, bool selected, bool operating, float power, bool engineAvailable)
Definition RainAir.h:10
Point Mix(Point a, Point b, float t)
float PlaybackRate(float duration, float cyclesPerSecond)
Definition WiperAudio.h:7
@ Game
Use the game audio system.
Definition discordpp.h:505
static constexpr float rate
void Update(float elapsed, bool enabled, bool powered=true)
WindshieldWipers::Motion wipers
Definition globals.h:535