1#pragma once
2#include "../Viewscreen/RainAir.h"
3#include <algorithm>
4
5namespace WiperFrameFixture
6{
9struct Logger {
enum class Level { Warn }; };
10struct Vehicle { WindshieldWipers::Motion wipers;
bool isSimulator =
false; };
13struct Camera { bool outside = false; };
14struct Propulsion { float staticDensity = 1.f; };
15struct Viewscreen { bool hasAnimatedWipers = false; Camera* camera; Propulsion* ptrPropulsion; };
18{
20 Viewscreen* viewscreen;
21 Bus* bus;
22};
23
24
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{
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]; }
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]); }
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
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;
88 Sound sound{&game, {raw[0], raw[1]}, {glass[0], glass[1]}, {duration, duration}};
91 const auto supply = [&](int health, bool selected, float power, bool engine)
92 {
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));
112 Check(Seconds(sound.Selected(0)) == ductPosition && Seconds(sound.Selected(1)) == rushPosition,
113 "steady playback does not seek or restart either independent layer");
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");
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");
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");
131 supply(127, false, 1.f, true); Check(silent(), "simulator exit cannot replay deselected protection");
132 }
133 sound.CameraChange(true);
135
136
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);
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;
153 for (float invalid : {-1.f, std::numeric_limits<float>::quiet_NaN(), std::numeric_limits<float>::infinity()})
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;
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");
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;
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;
181 Check(silent() && sound.
bleedAirGain == 0.f,
"inactive or invalid updates stop all rain-air playback immediately");
183 }
184 supply(127, true, 1.f, true);
186 sound.
FrameMoveWipers(.02f); Check(silent(),
"parked blades replace active pneumatic playback without a stale rush");
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}
RainAir::State RainAirStatus
void Stop(SOUNDS soundEnum) const
void FrameMoveWipers(float elapsedTime)
s_network_objects playerships[MAX_SCAN]
float ExteriorGain(float relativePressure)
State Evaluate(int equipment, bool selected, bool operating, float power, bool engineAvailable)
Point Mix(Point a, Point b, float t)
float PlaybackRate(float duration, float cyclesPerSecond)
@ Game
Use the game audio system.
static constexpr float rate
void Update(float elapsed, bool enabled, bool powered=true)
WindshieldWipers::Motion wipers